@ensofinance/sdk

中文文档
2.7.1发布于 2026/11/10MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2万

SDK for interacting with the Enso API

原始使用文档
文档目录22 节
  1. Introduction
  2. Installation
  3. Quick Start
  4. Routing Strategies
  5. Core Features
  6. Token Approvals
  7. Automated Routing
  8. Wallet Balances
  9. Bundled Transactions
  10. Bridging Pool Address
  11. CCTP Helpers
  12. Non-Tokenized Positions
  13. Token Data
  14. Token Pricing
  15. Protocol Support
  16. Handling Large Numbers
  17. Supported Actions
  18. Supported Networks
  19. API Reference
  20. Main Client Methods
  21. Contributing
  22. License

NPM Version X (formerly Twitter) Follow

Enso SDK

The Enso SDK provides a set of tools and methods to interact with the Enso shortcuts. It includes functionalities for automated swap routing, multichain routing, token approvals, quoting, and balance checking.

Introduction

The Enso API offers two powerful routing components:

  1. Route API: Finds the optimal execution path across multiple DeFi protocols including liquidity pools, lending platforms, automated market makers, yield optimizers, and more. It automatically determines the best path between two tokens or positions.

  2. Bundle API: Enables building custom route creators for complex multi-step DeFi operations by composing sequences of actions. This is perfect for advanced use cases like yield farming, leveraged positions, and portfolio rebalancing.

Installation

npm install @ensofinance/sdk

or

yarn add @ensofinance/sdk

Quick Start

import { EnsoClient } from "@ensofinance/sdk";

// Initialize the client with your API key
const ensoClient = new EnsoClient({
  apiKey: "YOUR_API_KEY",
});

// Get the best route from one token to another
const routeData = await ensoClient.getRouteData({
  fromAddress: "0xYourAddress",
  chainId: 1,
  amountIn: ["1000000000000000000"],
  tokenIn: ["0xTokenInAddress"],
  tokenOut: ["0xTokenOutAddress"],
  routingStrategy: "router",
});

// Execute the transaction with your web3 provider
// const tx = await web3.eth.sendTransaction(routeData.tx);

Routing Strategies

Routing strategies available for public SDK use:

  • router - Uses a single contract which acts as a universal router
  • delegate - Returns calldata in the form of delegateCalls for smart accounts
  • ensowallet-v2 - Returns calldata for deploying an Enso smart account, and executing all the logic inside of the smart account in the same transaction

Core Features

Token Approvals

Get approval data to allow token spending when using router as routingStrategy (not needed when using delegate):

// Example: Approving USDC for spending
const approvalData = await ensoClient.getApprovalData({
  fromAddress: "0xYourAddress",
  tokenAddress: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
  chainId: 1,
  amount: "1000000000", // 1000 USDC (6 decimals)
  routingStrategy: "router",
});

Automated Routing

Get the optimal execution data for a route between tokens:

const routeData = await ensoClient.getRouteData({
  fromAddress: "0xYourAddress",
  receiver: "0xReceiverAddress", // Optional, defaults to fromAddress
  chainId: 1,
  amountIn: ["1000000000000000000"],
  tokenIn: ["0xTokenInAddress"],
  tokenOut: ["0xTokenOutAddress"],
  slippage: "50", // 0.5%
  routingStrategy: "router",
});

Wallet Balances

Get token balances for a wallet:

// Example: Get all token balances for an Ethereum address
const balances = await ensoClient.getBalances({
  eoaAddress: "0xYourAddress",
  chainId: 1, // Ethereum mainnet
  useEoa: true, // Default is true - get balances for the EOA, not the Enso wallet
});

Bundled Transactions

Bundle multiple DeFi actions into a single transaction and use results between transactions.

// Example: Convert ETH to USDC, deposit into Aave V3, then send the aUSDC to the user
const bundleData = await ensoClient.getBundleData(
  {
    fromAddress: "0xYourAddress",
    chainId: 1,
    routingStrategy: "router",
  },
  [
    {
      protocol: "enso",
      action: "route",
      args: {
        tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", // ETH
        tokenOut: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
        amountIn: "1000000000000000000", // 1 ETH
        slippage: "100", // 1%
      },
    },
    {
      protocol: "aave-v3",
      action: "deposit",
      args: {
        tokenIn: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
        tokenOut: "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c", // aUSDC v3
        amountIn: {
          useOutputOfCallAt: 0, // Use output from the first action
        },
        primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 pool
      },
    },
    {
      // With `router`, deposit outputs stay in the router until transferred out
      protocol: "erc20",
      action: "transfer",
      args: {
        token: "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c", // aUSDC v3
        receiver: "0xYourAddress",
        amount: {
          useOutputOfCallAt: 1, // Use output from the deposit
        },
      },
    },
  ],
);

Bridging Pool Address

Use getLayerZeroPool to get the correct pool information, and use it as primaryAddress for the bridge action.

const poolInfo = await client.getLayerZeroPool({
  chainId: 42161, // Arbitrum
  destinationChainId: 999, // HyperEVM
  token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", // USDT
});

const stargatePoolInfo = await client.getStargatePool({
  chainId: 42161,
  destinationChainId: 999,
  token: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
});

CCTP Helpers

Use CCTP helpers to discover the TokenMessengerV2 contract and fetch a claim transaction when a CCTP transfer is claimable.

const tokenMessenger = await client.getCctpTokenMessenger({
  chainId: 1,
});

const claim = await client.getCctpClaimTransaction({
  chainId: 42161,
  txHash: "0xTransactionHash",
});

Non-Tokenized Positions

Route to a non-tokenized position. positionOut is a positionId from getNonTokenizedPositions:

// Example: Supplying USDC to a Morpho Blue market
const nonTokenizedRoute = await ensoClient.getRouteNonTokenized({
  fromAddress: "0xYourAddress",
  chainId: 1,
  tokenIn: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"], // USDC
  positionOut:
    "0x30a0da8cabf25a31805d9f3eca9005540e419f408beecf5cf715c67f3958ee55", // Morpho USDC/PENDLE-LPT market
  amountIn: ["1000000000"], // 1000 USDC
  receiver: "0xYourAddress",
  slippage: "300", // 3%
  routingStrategy: "delegate",
});

Token Data

Get paginated information about tokens:

// Example: Get details about wstETH including metadata
const tokenData = await ensoClient.getTokenData({
  chainId: 1,
  address: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", // wstETH
  includeMetadata: true,
  type: "defi", // Filter by token type - can be "defi" or "base"
});

Token Pricing

Get token price data:

// Example: Get current price of WETH
const priceData = await ensoClient.getPriceData({
  chainId: 1,
  address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
});

// Example: Get prices for multiple tokens
const multiPriceData = await ensoClient.getMultiplePriceData({
  chainId: 1,
  addresses: [
    "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
    "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
  ],
});

Protocol Support

Get information about supported protocols:

// Get all protocols
const protocols = await ensoClient.getProtocolData();

// Get protocols for a specific chain
const ethereumProtocols = await ensoClient.getProtocolData({ chainId: 1 });

// Get a specific protocol
const aaveProtocol = await ensoClient.getProtocolData({ slug: "aave-v3" });

Handling Large Numbers

The SDK properly handles large numbers common in blockchain transactions:

// Using string representation for large numbers (recommended)
const largeAmount = "1000000000000000000000000"; // 1 million tokens with 18 decimals

// You can also use JavaScript numbers for smaller values
const smallAmount = 1000000; // 1 USDC with 6 decimals

Supported Actions

The Bundle API supports a variety of actions for interacting with DeFi protocols.

For an up-to-date reference of all available actions and their parameters, you can call:

// Get all available actions
const actions = await ensoClient.getActions();

// Get actions for a specific protocol
const aaveActions = await ensoClient.getActionsBySlug("aave-v3");

Supported Networks

To get information about supported networks:

// Get all supported networks
const networks = await ensoClient.getNetworks();

// Get a specific network
const ethereumNetwork = await ensoClient.getNetworks({
  chainId: "1",
  name: "Ethereum",
});

API Reference

For detailed information about all available methods and parameters, see our API Reference Documentation.

Main Client Methods

MethodDescription
getApprovalDataGet token approval transaction data
getRouteDataGet optimal routing between tokens
getBalancesGet wallet token balances
getTokenDataGet token information
getPriceDataGet token price data
getMultiplePriceDataGet prices for multiple tokens
getProtocolDataGet protocol information
getBundleDataBundle multiple actions into a single transaction
getRouteNonTokenizedGet optimal routing to a non-tokenized position
getIporShortcutGet transaction data for IPOR operations
getStandardsGet available standards for bundling
getActionsGet actions that can be bundled
getNonTokenizedPositionsGet non-tokenized positions
getProjectsGet supported projects
getProtocolsByProjectGet protocols within a project
getNetworksGet supported networks
getAggregatorsGet supported aggregators
getLayerZeroPoolGet LayerZero/Stargate pool data
getStargatePoolGet Stargate pool data
getCcipRouterGet CCIP router address
getBridgeStatusGet bridge transaction status
getCctpTokenMessengerGet CCTP TokenMessengerV2 address
getCctpClaimTransactionGet CCTP claim transaction status/data

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

版本与发布记录

@ensofinance/sdk 共发布 54 个版本,首次发布于 2024/12/25;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.7.1latest2026/11/103 天前
2.7.02026/11/085 天前
2.6.12026/11/0211 天前
2.6.02026/09/251 个月前
2.5.02026/07/144 个月前
2.4.12026/05/195 个月前

其他发布通道:beta → 1.1.0-beta.8。

关于 @ensofinance/sdk 的常见问题

@ensofinance/sdk 是什么?

SDK for interacting with the Enso API

如何安装 @ensofinance/sdk?

在项目目录运行 npm install @ensofinance/sdk,或使用 pnpm add / yarn add / bun add。

@ensofinance/sdk 支持 TypeScript 吗?

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

@ensofinance/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ensofinance/sdk 可以商用吗?

@ensofinance/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ensofinance/sdk 的下载量有多少?

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

@ensofinance/sdk 还在维护吗?

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