For the complete documentation index, see llms.txt. This page is also available as Markdown.

WASM signer functions

Every user-facing function exported by the lighter-go WASM signer, with its arguments in order.

Source: wasm/main.go in elliottech/lighter-go. Build instructions: Quickstart: TypeScript + WASM.

Conventions

  • All functions are synchronous globals on globalThis.

  • Arguments are positional. Every argument is required; pass 0 for unused ones. undefined returns an error.

  • Return value is an object. Check error first:

type SignResult = {
  error?: string;
  txType: number;         // pass as tx_type to sendTx
  txInfo: string;         // JSON string; pass as tx_info to sendTx
  txHash: string;
  messageToSign?: string; // always present for ChangePubKey, Transfer, ApproveIntegrator (see below)
};
  • messageToSign is returned for every ChangePubKey, Transfer and ApproveIntegrator, but the server only requires the L1 signature in some cases (table below). When it's required, sign it with the owner's Ethereum wallet (personal_sign), then txInfo = JSON.stringify({ ...JSON.parse(txInfo), L1Sig: signature }). When it isn't, send txInfo as is and don't prompt the wallet.

  • The last two arguments of every Sign* function are always apiKeyIndex, accountIndex, and they select a client previously created with CreateClient.

  • skipNonce: 0 = strict nonce = previous + 1; 1 = allow any higher nonce. See Core concepts.

When an L1 signature is required

"Same owner" means both accounts belong to the same master account, i.e. the same master account and its sub-accounts.

Transaction
L1 signature required
Not required

ChangePubKey

Always

–

Transfer

Sender and receiver have different owners. This includes fast withdrawals, which are a transfer to the LP account.

Transfers between the same owner's accounts (e.g. master to sub-account)

ApproveIntegrator

Integrator has a different owner and at least one max fee is > 0

Zero-fee approvals and revokes; approving an account with the same owner

Everything else (orders, Withdraw, …)

Never; messageToSign isn't returned

–

Client & keys

Function
Arguments
Returns

GenerateAPIKey

–

{ privateKey, publicKey }

CreateClient

url, privateKey, chainId, apiKeyIndex, accountIndex: pass "" as url

{} or { error }

CheckClient

apiKeyIndex, accountIndex: don't use from WASM, see below

{} if key registered on-chain

CreateAuthToken

deadline (unix s, 0 = ~7h), apiKeyIndex, accountIndex

{ authToken }

SignChangePubKey

pubKeyHex, skipNonce, nonce, apiKeyIndex, accountIndex

tx + messageToSign

You can create several clients (one per apiKeyIndex/accountIndex pair) in the same WASM instance.

Orders

Function
Arguments

SignCreateOrder

marketIndex, clientOrderIndex, baseAmount, price, isAsk, orderType, timeInForce, reduceOnly, triggerPrice, orderExpiry, integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, apiKeyIndex, accountIndex

SignModifyOrder

marketIndex, index, baseAmount, price, triggerPrice, integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, orderVersion, apiKeyIndex, accountIndex

SignCancelOrder

marketIndex, orderIndex, skipNonce, nonce, apiKeyIndex, accountIndex

SignCancelAllOrders

timeInForce, time, cancelAllMarketIndex, skipNonce, nonce, apiKeyIndex, accountIndex

SignCreateGroupedOrders

groupingType, orders[], integratorAccountIndex, integratorTakerFee, integratorMakerFee, selfTradeBehaviorMode, selfTradeEqualityMode, skipNonce, nonce, apiKeyIndex, accountIndex

Enum values (order type, time in force, self-trade modes) are listed in Data Structures, Constants and Errors and Signing Transactions.

SignCreateGroupedOrders

orders is an array of objects:

groupingType: 1 one-triggers-the-other (OTO) · 2 one-cancels-the-other (OCO) · 3 OTOCO.

SignCancelAllOrders

  • timeInForce: 0 immediate · 1 scheduled (at time, ms) · 2 abort a scheduled cancel

  • cancelAllMarketIndex: a market ID, or 255 for all markets. Per-market cancel must be immediate.

Leverage & margin

Function
Arguments

SignUpdateLeverage

marketIndex, fraction, marginMode, skipNonce, nonce, apiKeyIndex, accountIndex – fraction = 10000 / leverage; marginMode 0 cross, 1 isolated

SignUpdateMargin

marketIndex, usdcAmount, direction, skipNonce, nonce, apiKeyIndex, accountIndex – direction 1 add, 0 remove

Funds

Function
Arguments

SignWithdraw

assetIndex, routeType, amount, skipNonce, nonce, apiKeyIndex, accountIndex

SignTransfer

toAccountIndex, assetIndex, fromRouteType, toRouteType, amount, usdcFee, memo, skipNonce, nonce, apiKeyIndex, accountIndex

routeType: 0 perps, 1 spot. memo: 32-byte hex string.

Accounts, pools & staking

Function
Arguments

SignCreateSubAccount

skipNonce, nonce, apiKeyIndex, accountIndex

SignCreatePublicPool

operatorFee, initialTotalShares, minOperatorShareRate, skipNonce, nonce, apiKeyIndex, accountIndex

SignUpdatePublicPool

publicPoolIndex, status, operatorFee, minOperatorShareRate, skipNonce, nonce, apiKeyIndex, accountIndex

SignMintShares

publicPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex

SignBurnShares

publicPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex

SignStakeAssets

stakingPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex

SignUnstakeAssets

stakingPoolIndex, shareAmount, skipNonce, nonce, apiKeyIndex, accountIndex

SignUpdateAccountConfig

accountTradingMode, skipNonce, nonce, apiKeyIndex, accountIndex

SignUpdateAccountAssetConfig

assetIndex, assetMarginMode, skipNonce, nonce, apiKeyIndex, accountIndex

Integrators

Function
Arguments

SignApproveIntegrator

integratorIndex, maxPerpsTakerFee, maxPerpsMakerFee, maxSpotTakerFee, maxSpotMakerFee, approvalExpiry, skipNonce, nonce, apiKeyIndex, accountIndex

Other languages

The same signer ships as a C shared library (.so / .dylib / .dll) for Python, Rust, Java and C++, plus a React Native build. See the lighter-go releases.

Last updated

Was this helpful?