@liqpro/liq-onchain

中文文档
0.83.0发布于 2026/11/02TypeScriptES Module

Onchain helpers for the Liq perpetuals exchange — deposits, collateral, accounts, positions, and settlement via viem.

原始使用文档
文档目录12 节
  1. Overview
  2. Key Exports
  3. LiqOnchain (façade)
  4. Builders (standalone, no wallet required)
  5. Sending a plan
  6. Signing
  7. ABIs
  8. Oracle helpers
  9. Chain helpers
  10. Install
  11. Dependencies
  12. Build

@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. signOrder (EIP-712) is exported too, but only as an @internal transit for @liq/react. The only runtime dependencies are @liq/core and viem.

Key Exports

LiqOnchain (façade)

Instantiated with OnchainConfig ({ chainId, walletClient, publicClient }). Exposes:

PropertyDescription
.accountsCreate SNX account NFTs, set book mode
.collateralRead available + locked margins
.depositUSDC → sUSDC → modifyCollateral flow
.positionsRead open positions from PerpsMarketProxy
.delegateGasless relay reads: delegate address, state(user)
.settlementCall settleBookOrders()

Builders (standalone, no wallet required)

  • DepositBuilder / WithdrawBuilder — build(): TxPlan returns the deposit / withdraw steps; each step's forwarderSafe flag says whether it can ride a wallet-sender batch
  • executeTypedData(chainId, user, { calls, nonce, deadline }) — the signTypedData arguments of a relayed batch
  • claimFaucetCall(faucetAddress, token) — the faucet claim as one PlanStep (forwarderSafe: false); sent by whichever sender the plan uses, wallet included
  • onchain.deposit.repay(debtWei) — the repay legs of a withdraw as a builder whose build() returns a TxPlan (WithdrawBuilder.afterRepay)
  • tokenTransferPlan(token, amount, recipients) — a TxPlan of one direct ERC-20 transfer per recipient (forwarderSafe: false: transfer reads msg.sender); token is the { token, decimals } pair a getCollateral result 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 land
  • walletSender(config) — batches a contiguous forwarderSafe run of steps into one TrustedMulticallForwarder.aggregate3 call; a step marked forwarderSafe: false (a bare ERC-20 approve) goes as its own transaction
  • relaySender(config) — sends the whole plan as one Delegate7702.execute batch through the gasless relay (ADR-0063)
  • landedOrThrow(outcome, what) — the outcome as a throw: returns LandedTx[] when the plan landed, throws PlanRevertedError (or the sender/transport's own error) otherwise

Signing

signOrder is exported only as an @internal transit for @liq/react's useOrderSubmission; it is not a stable API (ADR-0012, 0.62.0 update).

ABIs

  • perpsMarketProxyAbi, perpsAccountProxyAbi, bookOrderModuleAbi
  • spotMarketProxyAbi, trustedMulticallForwarderAbi, isolatedMarginManagerAbi, erc20Abi
  • Legacy aliases: PERPS_MARKET_PROXY_ABI, ERC20_ABI

Oracle helpers

  • OnchainMarketsService.getChainlinkFeedAddress(nodeId) — resolves a price node's Chainlink-type (RedStone) feed address, or null when that node isn't type 3

Chain helpers

  • getViemChain(chainId) — returns viem Chain object for a given chain ID

Install

pnpm add @liq/onchain

Dependencies

  • @liq/core — chain config, contract addresses, shared types
  • viem — onchain interaction (read/write contracts, wallet client)

Build

moon run liq-onchain:build    # tsup → dist/

版本与发布记录

@liqpro/liq-onchain 共发布 53 个版本,首次发布于 2026/06/14;过去 12 个月发布了 53 个版本。

版本发布日期距今
0.83.0latest2026/11/021 天前
0.80.02026/10/295 天前
0.79.02026/10/277 天前
0.78.02026/10/2410 天前
0.77.02026/10/2410 天前
0.74.02026/10/2113 天前

关于 @liqpro/liq-onchain 的常见问题

@liqpro/liq-onchain 是什么?

在线帮助Liq永久交换-存款,抵押品,账户,头寸,并通过视频结算。

如何安装 @liqpro/liq-onchain?

在项目目录运行 npm install @liqpro/liq-onchain,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:viem(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@liqpro/liq-onchain 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@liqpro/liq-onchain 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@liqpro/liq-onchain 可以商用吗?

@liqpro/liq-onchain 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@liqpro/liq-onchain 还在维护吗?

最新版本 0.83.0 发布于 2026/11/02(1 天前);至今共发布 53 个版本,其中过去 12 个月发布了 53 个;首次发布于 2026/06/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。