@lamarge/sdk runs in browsers, Bun and Node 22.12 or later. It ships ESM only, depends on @noble/hashes (keccak256 for Polymarket operations), takes viem as an optional peer dependency and is MIT licensed. Source: snowbl-capital/lamarge-sdk-ts. Before a signer sees anything, the SDK:
  • checks every to_sign item against your request and the deployment values it pins;
  • stores each payment, funding and withdrawal signature, so a restart submits it again instead of signing anew;
  • keeps client IDs stable across retries.

Client and signer

  • client.call reaches any operation by the operationId its API reference page shows. Path, query and body are typed.
  • signIn checks the chains, permit domains and settlement /v1/venues names against the pinned deployments, then signs the challenge for your app’s origin. The client then carries the session.
  • A credential goes in createClient({ apiUrl, token: "mk_…" }).
  • A signer is an address with signMessage and signTypedData: a viem LocalAccount, a KMS key through viem’s toAccount, or a browser wallet’s two methods. An optional prepare(chainId) readies a browser wallet (switches its network) before an Aster transfer is issued again and signed, so the transfer’s life starts once the wallet is ready. Paying from GMX, converting native USDC on Polygon or sending a direct transfer, it also needs sendTransaction({ chainId, to, data }, sent): it calls sent(hash) once broadcast, resolves with the hash once mined and rejects a refusal or a revert. A transferOut broadcast is not sent again for ten minutes; a LocalAccount only signs, so give it a viem wallet client’s sendTransaction and waitForTransactionReceipt on Arbitrum.
  • Answers are typed, not validated: an enum value a newer server adds still type-checks.

Accounts

  • linkAccount links an account. An address other than the master signs the link challenge once the SDK checked it names that venue.
  • setUpVenue runs each setup step the venue does not show yet, checks it, signs it and waits until the venue shows it. onProgress names each step as it starts and while it is confirming.
  • asterAgentName and lighterKeyIndex pin your deployment’s slots (ENVIRONMENT_SLOTS: LaMarge and 254 in production, LaMargeDev and 253 in dev). Registering another environment’s slot would replace that environment’s agent or key.
  • An Aster agent approval lists at most eight public addresses or ranges, each no wider than IPv4 /24 or IPv6 /64.

Taker script

Signs in, sets up both accounts, then transfers 250 USDC from Hyperliquid to Polymarket. Rerun it after any interruption: it resumes the same transfer.
transfer returns the take’s fills once the payment is accepted; each fill then settles on its own. Follow them with changes or GET /v1/takes/{id}.

Transfers

  • funding: "wallet" pays only from the signer’s escrow-token wallet and available balance (wallet funding); a shortfall stops before anything is signed. A master signer needs no linked account on from. A resumed transfer keeps the funding it was created with. On Polygon it pays pUSD unless the request has conversion.
  • funding: "venue" first withdraws what is short from the venue account. Lighter and Aster always pay from their account: use "venue". From GMX that withdrawal is the signer’s own transferOut transaction (the plan’s transfer_out request), paid in ETH on Arbitrum; a signer without sendTransaction stops before anything is signed.
  • Persist client_transfer_id, the transfer ID onIntent names and the store. The same request with transfer_id resumes it: a stored signature is submitted again, never replaced. memoryStore() is lost with the process.
  • TransferPending.reason: arrival_unconfirmed or authorization_unconfirmed (funds or permit not seen within arrivalWaitMs) and unknown (withdrawal outcome): run again later. refused: the venue refused the withdrawal.
  • max_fee_bps accepts the pair’s taker fee up to that many basis points, as the book’s taker_fee_bps shows it (fees). Without it, the take pays no fee.
  • destination: "wallet" transfers the take’s output to recipient, any address on to’s escrow chain, instead of the linked account (wallet delivery); nothing is read or required about an account on to. The SDK checks the wallet tag of each swap_id, the signed receiveRecipient, the pinned wallet token and the take’s minimum_received before signing. On a route it applies to the last take.
  • beforeSigning, on transfer, take, route, withdraw and setUpVenue, runs your own checks on each request after the SDK’s and before it is first signed. One that throws signs nothing.
  • lock, on transfer, take and route, wraps each take from its first read to its submission. Share it across your processes or tabs.
  • take alone prepares a take, checks and signs its payment, and submits it. checkQuote and minimumTake read a book as the server matches it, fee included.

Amount limits and slippage

bookLimits(book, options) gives a direct book’s smallest take and its sweep up to budget (the whole book without it): minimum and maximum, each { pay, out, parts } in base units, or null when nothing fits. It counts maker minimums, minimum (the delivery floor), the fill cap and the fee, and leaves out expired levels and own orders. A payment from Lighter or Aster (fee.onDelivery) takes one part; others up to maxParts, 8 by default.
  • The result is a snapshot that reserves nothing; amounts between minimum and maximum can fall in a gap left by minimum fills. Requote the chosen amount before signing.
  • slippageMinimum(out, bps) rounds out less bps (an integer from 0 to 10,000) down: a min_out.
  • Venue withdrawal fees are apart; on Aster, keep room for its debit rounded up to six decimals. A wallet delivery’s least output is the prepared take’s minimum_received.
  • For a two-take route, GET /v1/routes with amount_in your budget answers what the route can spend now (amount_in, capped when below your budget) and amount_out, the intermediate venue and your own orders accounted for. min_out applies to the budget you ask and scales down with a capped input: pass slippageMinimum(referenceOut, bps). It gives no route minimum.

Polygon native USDC

Where chain.wallet_funding.conversion is set, a wallet-funded transfer from Polymarket pays from native USDC (how it works):
  • The signer needs sendTransaction and POL for gas. When the allowance is short it approves exactly amount_in of USDC to the escrow, then sends convertDeposit; beforeSigning sees each as kind: "conversion", step approve or convert, with amount (USDC) and minOut (pUSD).
  • The take starts once LaMarge reads the conversion final. Resume with the same transfer_id and conversion: an unknown wallet answer never sends a second conversion, even from a fresh store.
  • Refunds and anything converted above amount_in stay in the available balance in pUSD.

Routes

route runs a two-take plan from GET /v1/routes as two transfers:
  1. The first, under your client_transfer_id, names the route’s end in then.
  2. Once it delivered on the intermediate venue, the second, under client_transfer_id + .2, pays what the server leaves to continue (continuable).
  • viaSigner signs on the intermediate venue when its linked account is another address.
  • Taken take by take, the second transfer signs from the intermediate venue: through Hyperliquid or Polymarket, beforeSigning sees its funding withdrawal (kind: "withdrawal", venue the intermediate venue) before its take, also when the route started from Lighter or Aster.
  • The same request with transfer_id, the first transfer’s ID, resumes the route.
  • grouped: true signs a grouped route at once. An unavailable, aborted or expired attempt throws RouteAbandoned (reason, transferId, commitBy, lateByMs). Rerun with grouped: false to continue take by take.

Moves and bridges

moveFunds moves amount_in from one endpoint to another as one move: LaMarge’s makers first, as far as they fill at the floor rate min_out / amount_in, an external bridge for the rest.
  • An endpoint is { venue }, an account, or { venue: "wallet", chain_id, token }: USDC on HyperEVM (999) or Arbitrum (42161), pUSD or native USDC on Polygon (137), USDT on BSC (56). To Lighter, recipient is the account index, which Lighter must show owned by the signer or lighterOwner.
  • The move follows its first quote. Its LaMarge part runs as transfer or route, the root transfer attached by move_id. The bridge starts once that part’s debit is fixed: from Hyperliquid, after the first take’s payment is accepted; from a wallet, once that payment executed (PAID). With sequential: true, a two-take route ends first, so one wallet never has a bridge request open while the route’s second take asks for its own; a second take no book pays at the floor then stops the run with MovePending route, the bridge starting on the next run. A Polymarket origin first withdraws to the signer, a GMX one sends its transferOut, both attached to the move; the bridge then leaves that wallet.
  • Every part counts against amount_in in the store before it starts, until its final state shows nothing debited. A LaMarge take that ends unpaid frees its share; what its funding withdrawal already moved is bridged from the wallet, never withdrawn again.
  • movePlan(client, request, store) returns the plan the move follows, its first quote kept in the store: read it before moveFunds to choose the signer of the account between a LaMarge route’s takes (viaSigner). That signer signs the route’s second take and, through Hyperliquid or Polymarket, a withdrawal from there, whatever the move’s origin. A refusal stops the move with the funds in that account.
  • What no part carries closes the move as unallocated, with its reason (below_minimum, insufficient_liquidity…).
  • Persist client_move_id and the store; the same request resumes. MovePending.reason: payment, withdrawal (funds not yet in the wallet), route (with sequential, a second take waiting for liquidity), or bridge (an approval of unknown outcome, or an unsigned quote expiring), as TransferPending from the LaMarge part: run again later.
  • bridge(client, signer, moveId, { terms, client_bridge_id, amount_in, from_wallet }, { store }) runs one bridge. It rebuilds and checks the provider’s order against terms (checkBridgeOrder in @lamarge/sdk/protocol), then signs a HyperCore origin’s nonce mapping and SendAsset, or sends a wallet’s approve and deposit. beforeSigning sees each as kind: "bridge", step sign, approve or deposit, with the venue the funds leave. The mapping is signed for Ethereum (chain 1), the send for HyperEVM’s 999; each is stored as soon as given, so a run interrupted between them asks only for the send (mapped: true).
  • A wallet origin needs sendTransaction and gas; it approves exactly amount_in only when short, and a deposit whose outcome is unknown is never sent again.
  • waitForBridge(client, id) reads a bridge until it is final.

Withdrawals and refunds

With client and account from client and signer:
  • withdraw moves an exact amount from Hyperliquid, Polymarket or Aster to the signer, or from Polymarket to its venue wallet. An Aster withdrawal goes to BSC, or to the chain_id you pick from getWithdrawalChains (Arbitrum, Ethereum), each chain with its own limit and fee; Aster’s fee comes on top, and the signer also signs the envelope Aster relays it in. With to: "account" and recipient, it sends to another account on Hyperliquid, Polymarket or Aster. The same id returns the withdrawal or resubmits its signature; a refused one needs a new id.
  • refundPayment consents, as the maker, to return the payment of a fill abandoned on Lighter or Aster (outcomes). It signs only once the payment’s escrow, read through your viem PublicClient for that chain, shows the payment still locked. canRefundPayment (@lamarge/sdk/protocol) tells which fills qualify.

Market making

Two keys on two hosts. Maker holds the financial key and provisions capital. Quoter holds a credential and the quote key, and quotes, accepts and reports deliveries.

Provision

On the financial key’s host, once. This opens an Aster pool that receives on Hyperliquid; LaMarge must approve you first.
  • Take OPERATOR_ADDRESS from the deployment values and APP_ORIGIN from the addresses.
  • maker.link(venue, owner) links owner’s account; on Aster it also approves LaMarge’s agent for the API’s environment.
  • addCapital(input, credential, { store, owner }) checks the preparation before the financial key signs it. store keeps the signed preparation for a restart; owner is the address linked on Lighter or Aster that holds the pool. On an escrow venue, follow it with waitForFunding(order).

Quote and deliver

On the quoting host, with the credential, the quote key and the pool’s keys; never the master key.
  • new Quoter(client, credential, quoteSigner) checks that quoteSigner is the credential’s quote_signer.
  • publishLines(lines, recipients, validUntil) prepares the identity’s quote lines, rebuilds each pool’s quote set from your lines, signs and publishes them: every pool switches at once. recipients names your linked address on each venue you buy on.
  • prepareLines(lines, recipients, validUntil) returns the same checked drafts unsigned, for a quote key that signs elsewhere; publish their signatures with client.call("publishQuoteLines", …).
  • cancelAll() pulls every pool’s quotes. To pull one venue, publish its line with stock: "0".
  • accept(fillId) accepts a fill delivered on Lighter or Aster; deliver(fillId, txHash) reports its transfer.
  • AsterDeliverer and LighterDeliverer run over quoter.fillFeed(signal). Each run accepts new fills before maker_accept_by, delivers paid fills, the earliest deliver_by first, persists each transfer in the journal before sending it and reports it.
  • A deliverer accepts only while its journal saves and no delivery’s outcome is unknown. stopAccepting() before shutdown; then cancel quotes and run until outstanding() is zero.
  • blocked is true once deliveries have been stuck for 15 seconds: stop quoting that pool.
  • The bot around them is yours: one process per journal, its storage, prices and shutdown.

Event feed

changes takes a snapshot, then yields every page of events over the WebSocket, replays over HTTP between connections, and yields a new snapshot (resync) when the journal moved past the cursor. scope: "public" follows books and trades without a session.

Errors and retries

  • A refusal is a LaMargeError: status, code, reason, requestId, retryable, retryAfterMs, and venue and step for SETUP_REQUIRED (errors).
  • Reads, and writes the SDK replays with the identical body, retry at most twice after a network failure or a retryable answer: after Retry-After when given, else a random wait of up to 500 ms, then up to 1 s. A write is never rebuilt; a cancellation is never replayed.
  • createClient options: fetch for every request, Lighter’s reads included; timeoutMs per request, 30 s by default; retryRateLimited: false throws a 429 at once; maxAnswerBytes refuses a longer answer; sleep makes a retry wait on the caller’s clock.
  • Most calls take an AbortSignal; Maker and Quoter methods do not. take and transfer take a now clock for the payment windows.

Versions

Each version types the API of LaMarge’s main when it is released; production may serve part of it later. Before 1.0 a minor version may break. A newly pinned deployment ships as a minor version, and older versions refuse to sign against it.