@ekubo/yul-router-sdk

中文文档
0.8.0发布于 2026/09/30TypeScriptES Module零依赖构建来源已验证近 30 天下载 3801

Constructs swap transaction calldata and price quotation calldata for the Ekubo Yul Router on EVM chains

原始使用文档
文档目录6 节
  1. Installation
  2. Constructing a swap transaction
  3. Obtaining a price quotation
  4. Hop types
  5. Also exported
  6. License

@ekubo/yul-router-sdk

Builds the packed swap calldata for the Ekubo Yul Router on EVM chains, and the calldata for reading a price quotation for that same route.

The router takes custom packed calldata rather than a conventional ABI-encoded function call. This SDK is what produces those bytes: you describe a route as a list of hops, and it returns the 0x… calldata to send to the router address.

Installation

npm install @ekubo/yul-router-sdk
# or
bun add @ekubo/yul-router-sdk

viem is a peer dependency.

Constructing a swap transaction

encodeRoutes(...) / generateCalldata(...) take a set of multi-hops and return the calldata for the swap. Every multi-hop starts from the same specifiedToken and ends at the same calculatedToken; the router executes them all under one Core lock, aggregates the amounts, applies a single slippage check, and settles once.

import { generateCalldata, YUL_ROUTER_ADDRESS } from "@ekubo/yul-router-sdk";

const data = generateCalldata({
  multiHops: [
    {
      specifiedAmount: 10n ** 18n,
      hops: [{ poolKey, sqrtRatioLimit: MIN_SQRT_RATIO }],
    },
  ],
  specifiedToken: tokenIn,
  calculatedToken: tokenOut,
  calculatedAmountThreshold: minimumOut, // required; guards slippage
  recipient,
});

// Send with any EVM client:
await walletClient.sendTransaction({ to: YUL_ROUTER_ADDRESS, data, value });

calculatedAmountThreshold is mandatory — a positive minimum output for exact-input routes, a negative maximum input for exact-output. Omitting it throws rather than silently encoding an unbounded slippage threshold.

Exact-input amounts are positive; exact-output amounts are negative.

Obtaining a price quotation

generateQuoteCalldata(...) / encodeQuoteCalldata(...) produce the calldata for the router's quote(bytes) entrypoint, which runs the identical route inside a Core lock and returns the resulting amounts without settling. No token balance and no approval are required, and all pool and extension state changes are rolled back.

import { generateQuoteCalldata } from "@ekubo/yul-router-sdk";

const data = generateQuoteCalldata({ multiHops, specifiedToken, calculatedToken });
const { data: result } = await publicClient.call({ to: YUL_ROUTER_ADDRESS, data });
// decodes to (specifiedToken, calculatedToken, specifiedAmount, calculatedAmount)

Direct execution, forwarding, and quoting all return the same four-word tuple for the same route and starting state, so a quotation and the swap built from it stay byte-for-byte comparable.

Hop types

HopUse
CoreHopA swap against an Ekubo Core pool
ForwardedHopA swap routed through an extension's forward callback
SignedExclusiveSwapHopA swap filled against a signed exclusive quote
WrapperHopA token wrap or unwrap step

Also exported

  • encodeRoute(...) — encode a single route body
  • encodeSignedSwapMeta(...) — encode the metadata for a signed exclusive swap
  • encodePoolBalanceUpdate(...) — encode a pool balance delta
  • calldataSize(...) — byte length of encoded calldata
  • YUL_ROUTER_ADDRESS, YUL_ROUTER_ABI, and the sqrt-ratio and threshold bounds

License

See the repository.

版本与发布记录

@ekubo/yul-router-sdk 共发布 9 个版本,首次发布于 2026/07/06;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.0latest2026/09/301 个月前
0.7.12026/08/083 个月前
0.7.02026/08/083 个月前
0.6.02026/07/283 个月前
0.5.02026/07/243 个月前
0.4.02026/07/163 个月前

关于 @ekubo/yul-router-sdk 的常见问题

@ekubo/yul-router-sdk 是什么?

Constructs swap transaction calldata and price quotation calldata for the Ekubo Yul Router on EVM chains

如何安装 @ekubo/yul-router-sdk?

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

@ekubo/yul-router-sdk 支持 TypeScript 吗?

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

@ekubo/yul-router-sdk 支持 ESM 还是 CommonJS?

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

@ekubo/yul-router-sdk 可以商用吗?

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

@ekubo/yul-router-sdk 的下载量有多少?

根据 npm 官方下载统计,@ekubo/yul-router-sdk 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,801 次,日均约 127 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ekubo/yul-router-sdk 还在维护吗?

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