lamarge runs on Tokio, needs Rust 1.94.1 or later and is licensed MIT OR Apache-2.0. TLS is rustls with the platform verifier: slim and distroless images need system CA roots. HTTP requests honour HTTPS_PROXY; the event feed’s WebSocket connects directly. API reference: docs.rs/lamarge. Source and examples: snowbl-capital/lamarge-sdk-rs.
Before a signer sees anything, the crate:
- checks every
to_signitem against your request and the deployment values it pins; - saves the signatures of takes, transfers, withdrawals, maker capital and wallet permits in your
Journalbefore submitting them, and reuses them when the same request runs again; venue setup steps (setup permits included), closes and quote publications are not journalled and may sign again after an interruption; - keeps client IDs stable across retries.
Client and signer
Environment::Production,Environment::Development, orEnvironment::Custom { api_url, app_origin }.sign_inchecks/v1/venuesagainst the pinned deployments, then signs the challenge for the environment’s app origin.Session::exportreturns aSavedSession;Client::resume_sessionresumes it.- A signer is any
alloy_signer::Signer: a local key, a KMS key, a Ledger. - The crate reads Lighter’s public API directly to check account owners before a Lighter take (
Client::lighter_account_ownerreads one).Client::builder(environment).lighter_reads(carrier)sends those reads through yourLighterReads, from your address and within your rate budget; the crate keeps its deadline and refuses any non-2xx answer asError::VenueApiwith its status. ClientBuilder::http_exchangesends every API request through yourHttpExchange, andstream_connectoropens the event WebSocket’s connection through yourStreamConnector. Requests keep the crate’s deadline, retries and answer cap, with TLS left to your exchange; the crate runs TLS and the WebSocket over the connector’s stream.- Amounts are base units of each venue’s token:
Amount::parse_venue(&venue, "250"). - An enum value a newer server adds decodes as
Unknown.
Takes and transfers
takereserves at market, checks the payment againstterms(amounts, parts, fee, recipient, windows, the pinned escrow; Lighter’s own owner of a delivering account), signs, saves and submits it. Persist the whole request (it is serializable) before the first call: running it again resumes the take, never paying a fill past its reservation again.transferfunds the take first: from Hyperliquid or Polymarket margin only the paying address’s shortfall is withdrawn, signed with the take when the funding plan says so; from GMX margin the payer sends its owntransferOutto its address, throughtransfer_with’sTransactionSender, once; with.funding(Funding::Wallet)nothing is withdrawn and the escrow’s permit is signed first if needed; from Lighter or Aster the take pays directly. The same request resumes from the journal, also after a stale preparation or an expired take was replaced.TransferRequest::conversion(ConversionTerms)funds a wallet-funded transfer from Polymarket with native USDC converted to pUSD first, throughtransfer_with’sTransactionSender(anapproveonly when the allowance is short, then the conversion);Session::conversion_previewtells, before any is asked, whether anapproveis needed, how many transactions follow and whether the wallet’s balance covers the conversion.route/route_withrun aRouteRequestfromfromthroughviatotoin two transfers, the second paying what the first left onvia, as a transfer fromvia: taken take by take through Hyperliquid or Polymarket, the signer onviasigns a withdrawal from there, whateverfromis; withRouteRequest::groupeda route whose first take pays inside Lighter or Aster through an escrow venue (groupable) is signed and committed at once, or ends inError::RouteNotCommitted.Recipient::Wallet(address)delivers by plain transfer on the receiving escrow chain;Recipient::Accountinto the account linked there.withdrawmoves aWithdrawalRequestamount out of Hyperliquid, Polymarket or Aster, or sends it to another account (WithdrawTo); an Aster withdrawal goes to BSC, or with.chain(42161)/.chain(1)to Arbitrum or Ethereum (each with its own limit and fee at Aster, listed bywithdrawals().chains(&VenueId::Aster)), Aster’s fee on top, relayed in an envelope the session signs too;WithdrawTo::VenueWallet(wallet)names the linked Polymarket wallet, never read from the API;.dex(Dex::Xyz)pays a Hyperliquid withdrawal or send from a standard account’s trade.xyz balance. The same request returns the outcome, never a second withdrawal.direct_transfer(&DirectRequest, &sender)runs a direct transfer, as the TypeScript SDK’sdirectTransfer:DirectRequest::depositfrom the session’s wallet into its own chain’s venue (on Polymarket, native USDC converted to at least itsconversion_minimumof pUSD), orDirectRequest::gmx_withdrawal. It checks the operation against the request and the pinned deployment, reads the venue’s capability and the funds, sends anapproveonly when the allowance is short, then the deposit ortransferOut, fenced first and never asked again while its outcome is unknown; a deposit the wallet refused is asked again under its same nonce.DirectOutcome::Waitingsays what it waits for; run the same request again.inspect_direct_transactionchecks a transaction’s chain, contract and calldata in an isolated signer asinspectDirectTransactiondoes; it does not see the native value, so refuse a non-zero value yourself.
Moves and bridges
A move sendsamount_in to one destination: LaMarge’s makers fill what they can, an external bridge (Relay) carries the rest. move_funds_with runs it to its end, as the TypeScript SDK’s moveFunds.
- The plan is the move’s first quote (
move_plan), journalled under itsclient_move_idand read back by every later run; the same id with other terms is refused. - LaMarge’s part runs first, one take or a route through a venue between, attached to the move. A route’s second transfer pays from the venue between: through Hyperliquid or Polymarket, its signer signs a withdrawal from there, whatever the move’s origin, and a refusal stops the move with the funds in that account. The bridge for the rest starts once it ran, and once its payment executed when the bridge leaves a wallet. A Polymarket origin first withdraws the rest to the payer’s wallet there, under the move; a GMX origin by the payer’s own
transferOut, recorded as a direct operation (directs()), checked against the pinned GMX deployment, fenced before the sender is asked and sent once. - A LaMarge part that ends unpaid frees its share: what its funding withdrawal moved is bridged from the wallet, the rest from the origin. A bridge refused for a lasting reason (
insufficient_liquidity,below_minimum,unsupported,slippage,hyperliquid_mode,disabled), or a venue settled inside itself (Lighter, Aster), leaves its amount unallocated; the move is closed with it and the first reason. - Every part is counted against
amount_inin the journal before it is created; a part from the wallet only within what the move’s withdrawals put there. - A
HyperCorebridge’s nonce mapping and send are each journalled once signed and submitted again, never signed anew. A wallet bridge’sapproveand deposit go through yourTransactionSender: theapproveonly when the allowance is short, the deposit after the bridge is fenced, never asked again while its outcome is unknown. - Run the same request again after
MoveOutcome::Pending:Payment,Withdrawal,Bridge,RouteorTransfer(reason)says what it waits for.
sign_bridge(HyperCore origin) andbridge_deposit(wallet origin) check the order againstBridgeTermsand the pinned Relay contracts.for_movetakes the part’s floor as its share of the move’smin_out, and a Polymarket, GMX or Aster account’s credit as that floor, at least the venue’s minimum. A Lighter recipient’s owner is read on Lighter’s API.sign_bridgesigns Relay’s nonce mapping and theSendAssetto Relay’s depository, then submits both.bridge_depositreturns theapprove(only when the allowance is short) and the deposit: callbridges().fence(id)before prompting, send them yourself, report each hash withreport_transaction, orreport_unsentwhen the wallet refused before broadcasting. Never send a deposit again after an unknown outcome.- Keep the move’s budget yourself, from your own records: the parts that may still debit (bridges not
failedorexpired, each transfer at its take’samount_in, withdrawals feeding a bridge) stay within the move’samount_in, and each part’s floor is at least its share ofmin_out, rounded up. The server refuses bridges beyondamount_in; the crate does not track them.
Market making
Two keys on two hosts, as in market making: the financial key provisions capital, the quote key quotes.operatorcomes from the deployment values you reviewed, never from the API.add_capitalchecks the preparation before the financial key signs it; the same request resumes it. Pools on Hyperliquid, Polymarket and GMX; GMX funds from the wallet only.publish_linesrebuilds each pool’s quote set from your quote lines before the quote key signs: every pool switches at once.recipientsnames your linked address on each venue you buy on.cancel_allpulls every pool’s quotes;Maker::close_ordersreleases capital.- Deliveries inside a venue:
lighter::LighterDelivererandaster::AsterDeliverer(bothdelivery::VenueDeliverer) accept requested deliveries, send each paid fill’s transfer once, persisted in aJournalbefore it is sent, and report it (Fills::accept,Fills::deliver). Run them on every change of the quoter’s fills;blocked()tells the pool to stop quoting while an outcome stays unknown. Lighter’s API key stays in yourLighterSigner; the owner’s message is checked against the transfer the key signed before the owner signs it. Venue requests go through yourHttpExchange. refund_payment(fill, reader)gives a taker’s payment back early for a fill abandoned inside its venue, once yourChainReaderreads the lock from the pinned escrow the consent names;protocol::check_escrow_withdrawalchecks an order’s available-balance withdrawal.
Event feed
subscribe takes a snapshot, then yields each page of events over the WebSocket, replays over HTTP between connections and yields a new snapshot (Change::Resync) when the journal moved past the cursor. Client::events is the public feed; Session::events and Quoter::events are private, follow session renewals and end with Error::SignedOut on sign-out.
Attestations and proofs
A signer holding a taker’s key apart from the app checks that a request comes from LaMarge:attestation::verify_attestation(&request, address, &attestation, attestation::ATTESTERS.production, now) returns a take’s terms, or a setup step. protocol::check_escrow_proof_typed checks a signed quote set, funding or payment against every v5 deployment, retired ones included. protocol::transfer_hash and read_transfer_tx_info read a sent Lighter transfer back.