@liqpro/liq-onchain
v0.56.0
Published
Onchain helpers for the Liq perpetuals exchange — deposits, collateral, accounts, positions, and settlement via viem.
Readme
@liq/onchain
Onchain helpers for the Liq perpetuals exchange — deposits, collateral, accounts, positions, and settlement via viem.
Overview
@liq/onchain provides the LiqOnchain façade and individual service classes for all onchain interactions: depositing USDC collateral, managing SNX accounts, reading open positions, and submitting settlement transactions to the Synthetix V3 PerpsMarketProxy. It also exports the canonical contract ABIs and EIP-712 signing utilities. The only runtime dependencies are @liq/core and viem.
Key Exports
LiqOnchain (façade)
Instantiated with OnchainConfig ({ chainId, walletClient, publicClient }). Exposes:
| Property | Service | Description |
| ------------- | ------------------------- | ---------------------------------------------------- |
| .accounts | AccountsService | Create SNX account NFTs, set book mode |
| .collateral | CollateralService | Read available + locked margins |
| .deposit | DepositService | USDC → sUSDC → modifyCollateral flow |
| .positions | OnchainPositionsService | Read open positions from PerpsMarketProxy |
| .delegate | Delegate7702Client | Gasless relay reads: delegate address, state(user) |
| .settlement | SettlementService | Call settleBookOrders() |
Builders (standalone, no wallet required)
DepositBuilder/WithdrawBuilder—build(): TxPlanreturns the deposit / withdraw steps; each step'sforwarderSafeflag says whether it can ride a wallet-sender batchexecuteTypedData(chainId, user, { calls, nonce, deadline })— thesignTypedDataarguments of a relayed batchclaimFaucetCall(faucetAddress, token)— the faucet claim as onePlanStep(forwarderSafe: false); sent by whichever sender the plan uses, wallet includedRepayBuilder.build()— the repay legs of a withdraw as aTxPlan(WithdrawBuilder.afterRepay)tokenTransferPlan(token, amount, recipients)— aTxPlanof one direct ERC-20transferper recipient (forwarderSafe: false:transferreadsmsg.sender);tokenis the{ token, decimals }pair agetCollateralresult already is, so the address and its decimals cannot drift apart
Sending a plan
A builder only returns a TxPlan (readonly PlanStep[]); turning it into transactions is the sender's job, picked at the call site:
executePlan(plan, { sender, publicClient })— sends the plan group by group, waits for each receipt, stops at the first that doesn't landwalletSender(config)— batches a contiguousforwarderSaferun of steps into oneTrustedMulticallForwarder.aggregate3call; a step markedforwarderSafe: false(a bare ERC-20approve) goes as its own transactionrelaySender(config)— sends the whole plan as oneDelegate7702.executebatch through the gasless relay (ADR-0063)landedOrThrow(outcome, what)— the outcome as a throw: returnsLandedTx[]when the plan landed, throwsPlanRevertedError(or the sender/transport's own error) otherwise
Signing utilities
signOrder(walletClient, domain, order)— EIP-712 sign an order messagebuildSigningArgs(chainId, verifyingContract, order)— buildsignTypedDataarguments
ABIs
perpsMarketProxyAbi,perpsAccountProxyAbi,bookOrderModuleAbispotMarketProxyAbi,trustedMulticallForwarderAbi,isolatedMarginManagerAbi,erc20Abi,oracleManagerProxyAbi- Legacy aliases:
PERPS_MARKET_PROXY_ABI,PERPS_ACCOUNT_PROXY_ABI,SPOT_MARKET_PROXY_ABI,ERC20_ABI,TRUSTED_MULTICALL_FORWARDER_ABI
Oracle helpers
OnchainMarketsService.getChainlinkFeedAddress(nodeId)— resolves a price node's Chainlink-type (RedStone) feed address, ornullwhen that node isn't type 3
Chain helpers
getViemChain(chainId)— returns viemChainobject for a given chain ID
Install
pnpm add @liq/onchainDependencies
@liq/core— chain config, contract addresses, shared typesviem— onchain interaction (read/write contracts, wallet client)
Build
moon run liq-onchain:build # tsup → dist/