Skip to main content
This reference targets SDK 0.2.0, which publishes the account and wallet-v2 APIs from f73ee41. Follow Installation for release and Gateway decoder compatibility.

Common conventions

  • Addresses are `0x${string}` values.
  • Contract integers use bigint; small enum/bitmap fields use number where stated.
  • A write returns a transaction hash. Await a receipt separately.
  • Every write accepts optional account and simulate; simulation is enabled by default.
  • Account methods accept optional accountCore; otherwise the configured address is used.
  • Spot methods always receive the market address.
  • clientOrderId is optional opaque correlation data, not an idempotency key.

Client construction

Returns: { account, spot } focused clients.
They accept the same shared config and return the same method objects exposed under createKuruClient.

Account client

authorizeAccountSignerBySig and revokeAccountSignerBySig add the live authorizer, nonce, deadline, and signature. Use the exported typed-data builders. Child creation uses the root’s next sequence, not a child-address consent signature. approveErc20 and allowance operate on the token. Native deposits attach value automatically. Writes return transaction hashes; check receipts separately. Request builders provide calldata without sending. Positive builder fees are ordinary root free balance. Builders use withdraw; there is no separate claim ledger.

Approved payout helpers

Use buildApprovedWithdrawalTypedData, buildFulfillApprovedWithdrawalRequest, buildInvalidateApprovedWithdrawalNonceRequest, and buildPreviewWithdrawalRequest. A capacity preview is not complete transaction validation. See WithdrawalLimiter.

Spot client

Market conversion

Read pricePrecision, sizePrecision, and tickSize from getMarketParams. Use viem’s parseUnits and formatUnits with the decimal exponent represented by each power-of-ten precision, then reject prices not divisible by tickSize. See Orders and Cancellation for a complete example.

Spot reads

Returns a seven-value tuple: price precision, size precision, tick size, minimum quote notional, maximum quote notional, taker fee PPS, maker fee PPS.
Returns [bid, ask] as numbers. Empty bid is 0xffff_ffff; empty ask is 0.
Returns bid price/size and ask price/size arrays. The onchain view applies stale-order visibility caps. Indexers maintaining their own book must apply the same rules.
Returns 0n for an empty slot. Use the value for optimistic concurrency and wallet expected-ID bindings.
Returns 0 when disabled or empty.
Returns inventory, shares, band edges, and fee-growth accumulators.
Returns owner ID, band edges, shares, and fee checkpoints.
Supplying userId applies that account’s effective fee policy. The estimate cannot predict hook side effects or intervening state changes.

Orders and swaps

Each order accepts side (buy/sell or enum), quantity, price, TIF, optional execution instruction, and optional minSizeAfterBlock. Inputs are normalized and range-checked before simulation.Returns the transaction hash. Decode TradesPacked and BookUpdatesPacked from the receipt for outcomes.
Empty slots are ignored. For race-sensitive systems, use current order IDs in application state or the trading-wallet expected-ID flow.
Passive positions are unaffected.
This export exists for authorized protocol operators. Ordinary applications should use cancelBySlots.
Construct packedOps with encodePackedReplaceOp(s) and encodePackedCancelOp; do not hand-build bit layouts in application code.
For buys, input is quote and output is base. For sells, input is base and output is quote. Always set slippage and deadline explicitly.
Every Spot write/read with overload selection also has a build*Request export. Request builders select the exact ABI overload and return unsent call data.

Order encoding

Trading-wallet signing

The wallet namespace prepares and signs contract-compatible EIP-712 payloads; it does not decide TP/SL or TWAP conditions.
Inputs include wallet address, chain ID, header, exact action payload, and expected order IDs. Returns normalized values, component hashes, typed data, and final digest without signing.
Adds triggerExpiry and opaque conditionHash. Array sizes, slot bindings, packed payload shape, integer ranges, and header invariants are validated locally.
Binds wallet, chain, account ID, auth epoch, nonce, deadline, and trigger ID.
Each accepts its intent input plus a WalletIntentSigner. The SDK normalizes the signature, recovers the signer, and rejects a signer that does not match the delegated wallet address.
Use the local adapter for LocalAccount; use the wallet-client adapter for injected/JSON-RPC wallets.
Use these when storing prepared intent metadata before obtaining a signature.
This surface handles delegation authorization only. Wallet intent signatures are separate EIP-712 messages.
Typed-data builders and hash helpers are exported individually for audit/replay: tradingWalletDomain, the corresponding build*TypedData functions, hashPackedOperations, hashExpectedOrderIds, hashCancelSlotIndexes, hashNativeOrders, and normalizeAndHashNativeOrders.

Relay client

The SDK contains a transport client and strict request serializers. See Relay for the signing-to-submission flow and Relay API documentation for canonical service endpoints and wire schemas.
authenticate performs the full challenge, personal-message signature, token exchange, wallet-match validation, and optional token retention.
Rejects malformed wire values before network I/O, resolves a live access token, validates response request ID, and returns RelayBroadcastResponse or throws KuruRelayError.
Each method assigns a UUIDv7 request ID when absent, serializes integers as canonical decimal strings, submits, and validates the broadcast response.
Token state is in-memory per client. Persist tokens only as appropriate for the application, honor expiresAt, and explicitly authenticate again when required; the SDK never refreshes a token implicitly.
Standalone builders mirror the high-level methods: buildExecuteReplaceBySlotRelayRequest, buildExecuteBatchRelayRequest, buildCreateReplaceTriggerRelayRequest, buildCreateBatchTriggerRelayRequest, buildCancelTriggerRelayRequest, and buildAuthorizeAccountSignerRelayRequest. Authentication adapters are createLocalAccountRelaySigner, createWalletClientRelaySigner, resolveRelayAuthenticationWallet, and signRelayChallenge.

Events

Accepts { address, data, topics }. The default ABI is combinedKuruAbi(). It throws when the log does not match; catch only when intentionally scanning mixed receipts.
Returns typed records with maker identity, flags, price, fill size, final resting size, fee snapshot, and trade ID. Invalid length throws.
Returns complete live/deletion records including RAB threshold and maker-fee snapshot.

Errors and utilities

Namespaces and ABI exports

The package root re-exports the public functions and types. Namespaced imports are also available as account, spot, tradingWallet, relay, events, products, and utils. Contract ABIs are exposed under abi and generated; CONTRACTS_COMMIT identifies the ABI source revision.

Additional wallet-v2 actions

Prepare typed intents with prepareCancelAllIntent, prepareCancelOrdersByIdIntent, prepareFokSwapIntent, prepareCreateFokSwapTriggerIntent, prepareCreateTwapIntent, prepareCancelTwapIntent, or prepareEmitSignedDataIntent. Sign with signPreparedWalletIntent and encode direct calls with buildWalletActionRequest. buildExecuteTwapSliceRequest and buildFinalizeTwapRequest encode keeper/lifecycle calls. These direct-contract builders do not add hosted Relay endpoints.

Relay encryption helpers

The Relay SDK provides requestEncryptionKey, encryptRelayPrivateKey, and decryptRelayPrivateKey for the service’s encrypted-key transport. Use the returned encryption key identifier and expiry when preparing a request. This is distinct from owner-signed EIP-712 action submission and is not required for the direct first-trade tutorial.