Skip to main content
The Enso SDK provides a set of tools and methods to interact with the Enso API. It includes functionalities for token approvals, routing, quoting, and balance checking. The Route API is a highly-efficient DeFi aggregation and smart order routing REST API. With it, developers can easily tap into optimized routes for DeFi tokens/positions and multi-token swaps across various chains.

View on GitHub

Installation

Install the Enso SDK using your preferred package manager:
npm

Quick Start

This example shows how to swap ETH directly to a Yearn vault position:

Core Concepts

The Enso SDK abstracts complex DeFi operations through several key components:
  1. EnsoClient: The main entry point for all SDK functionalities
  2. Routing Strategies: Different execution paths for transactions
  3. Bundle Actions: Compose multiple DeFi operations in a single transaction
  4. Approvals: Manage token allowances for DeFi interactions
  5. Token Data: Retrieve detailed information about tokens and protocols

Routing Strategies

There are 3 routing strategies available depending on your use case:
  • router - Uses a single contract which acts as a universal router
  • delegate - Returns calldata in the form of delegateCalls for smart accounts
  • delegate-legacy - Legacy version of delegate routing
  • router-legacy - Legacy version of router routing

Complete Methods Reference

Primary Methods

getRouteData(params: RouteParams)

Calculates the optimal route for token swaps or entering/exiting DeFi positions. Parameters:
  • fromAddress (Address): Ethereum address of the wallet to send the transaction from
  • receiver? (Address): Ethereum address of the receiver of the tokenOut
  • spender? (Address): Ethereum address of the spender of the tokenIn
  • chainId (number): Chain ID of the network to execute the transaction on
  • destinationChainId? (number): Chain ID of the destination network for cross-chain bridging
  • amountIn (Quantity[]): Amount of tokenIn to swap in wei
  • slippage? (Quantity): Slippage in basis points (1/10000)
  • minAmountOut? (Quantity[]): Minimum amount out in wei
  • tokenIn (Address[]): Ethereum address of the token to swap from
  • tokenOut (Address[]): Ethereum address of the token to swap to
  • routingStrategy (RoutingStrategy): Routing strategy to use
  • fee? (Quantity[]): Fee in basis points for each amountIn value
  • feeReceiver? (Address): Address that will receive the collected fee
  • ignoreAggregators? (string[]): List of swap aggregators to ignore
  • ignoreStandards? (string[]): List of standards to ignore
  • toEoa? (boolean): Flag indicating if gained tokenOut should be sent to EOA
  • referralCode? (string): Referral code included in on-chain event
Returns: Promise<RouteData>

getApprovalData(params: ApproveParams)

Generates transaction data for approving tokens to be spent by Enso contracts. Parameters:
  • fromAddress (Address): Ethereum address of the wallet to send the transaction from
  • tokenAddress (Address): ERC20 token address of the token to approve
  • chainId (number): Chain ID of the network to execute the transaction on
  • amount (Quantity): Amount of tokens to approve in wei
Returns: Promise<ApproveData>

getBundleData(params: BundleParams, actions: BundleAction[])

Constructs bundled transaction data for multiple DeFi operations in a single transaction. First argument (params):
  • chainId (number): Chain ID of the network to execute the transaction on
  • fromAddress (Address): Ethereum address of the wallet sending the transaction
  • routingStrategy (RoutingStrategy): Execution strategy
  • receiver? (Address): Default final-output receiver
  • spender? (Address): Account supplying input assets when supported
  • refundReceiver? (Address): Dust or applicable bridge-refund receiver
  • ignoreAggregators? (string[]): Swap aggregators to ignore
  • referralCode? (string): Referral code included in the on-chain event
Second argument (actions): ordered BundleAction[] request body. Returns: Promise<BundleData>

Data Retrieval Methods

getBalances(params: BalanceParams)

Retrieves token balances for a given wallet address. Parameters:
  • chainId? (number): Chain ID of the network to execute the transaction on
  • eoaAddress (Address): Address of the EOA to associate with the ensoWallet for balances
  • useEoa? (boolean): If true, returns balances for the provided eoaAddress instead of the associated ensoWallet
Returns: Promise<WalletBalance[]>

getTokenData(params: TokenParams)

Fetches detailed information about tokens, including DeFi tokens and their underlying assets. Parameters:
  • project? (string): The overarching project or platform associated with the DeFi token
  • protocolSlug? (string): The specific standard integration or version of the DeFi project
  • underlyingTokens? (MultiAddress): Underlying tokens of defi token
  • underlyingTokensExact? (MultiAddress): Exact composition of underlying tokens
  • primaryAddress? (MultiAddress): Ethereum addresses for contract interaction
  • address? (MultiAddress): Ethereum addresses of the tokens
  • chainId? (number): Chain ID of the network of the token
  • type? (TokenType): Type of token (‘defi’ | ‘base’)
  • apyFrom? (Quantity): Only include tokens with APY over this value
  • apyTo? (Quantity): Only include tokens with APY below this value
  • tvlFrom? (Quantity): Only include tokens with TVL over this value
  • tvlTo? (Quantity): Only include tokens with TVL below this value
  • page? (number): Pagination page number (pages are of length 1000)
  • cursor? (number): Cursor for pagination
  • includeMetadata? (boolean): Whether to include token metadata
  • name? (string[]): Names of the tokens
  • symbol? (string[]): Symbols of the tokens
Returns: Promise<PaginatedTokenData>

getPriceData(params: PriceParams)

Gets the current price data for a specific token. Parameters:
  • chainId (number): Chain ID of the network to search for
  • address (Address): Address of the token to search for
Returns: Promise<PriceData>

getMultiplePriceData(params: MultiPriceParams)

Gets price data for multiple tokens. Parameters:
  • chainId (number): Chain ID of the network to search for
  • addresses (Address[]): Addresses of tokens to check prices for
Returns: Promise<PriceData[]>

Protocol and Standard Methods

getProtocolData(params?: ProtocolParams)

Retrieves information about DeFi protocols supported by Enso. Parameters:
  • chainId? (number | string): Chain ID of the network to search for
  • slug? (string): Slug of the project to search for
Returns: Promise<ProtocolData[]>

getStandards()

Returns standards available for bundling with protocol information and supported actions. Returns: Promise<StandardData[]>

getStandardBySlug(slug: string)

Returns a standard matching the given slug with supported actions and chains. Parameters:
  • slug (string): The protocol slug
Returns: Promise<StandardData[]>

getActions()

Returns all actions that can be bundled with the /shortcuts/bundle endpoint. Returns: Promise<ActionData[]>

getActionsBySlug(slug: string)

Gets actions for a specific protocol. Parameters:
  • slug (string): The protocol slug
Returns: Promise<ActionData[]>

Specialized Methods

getRouteNonTokenized(params: RouteNonTokenizedParams)

Gets execution data for best route to non-tokenized positions. Parameters:
  • chainId (number): Chain ID of the network to execute the transaction on
  • fromAddress (Address): Ethereum address of the wallet to send the transaction from
  • routingStrategy (‘delegate’ | ‘delegate-legacy’): Routing strategy to use
  • tokenIn (Address[]): Input tokens
  • positionOut (Address): Non-tokenized position to receive
  • slippage? (Quantity): Slippage in basis points
  • fee? (Quantity[]): Fee in basis points
  • feeReceiver? (Address): Fee receiver address
  • amountIn (Quantity[]): Amount to send
  • receiver (Address): Receiver address
  • spender? (Address): Spender address
  • referralCode? (string): Referral code
Returns: Promise<RouteData>

getIporShortcut(params, data: IporShortcutInputData)

Returns a transaction for IPOR shortcut operations. Parameters:
  • chainId? (number): Chain ID (optional)
  • fromAddress (string): Ethereum address of the wallet
  • data (IporShortcutInputData): IPOR shortcut input data
Returns: Promise<IporShortcutData>

getNonTokenizedPositions(params?: NonTokenizedParams)

Gets all non-tokenized positions with details. Parameters:
  • project? (string): The overarching project or platform
  • protocolSlug? (string): The specific standard integration
  • chainId? (number): Chain ID of the network
  • destinationChainId? (number): Destination chain ID for cross-chain bridging
  • address? (Address[]): Ethereum addresses of positions
  • primaryAddress? (Address[]): Ethereum addresses for contract interaction
  • page? (number): Pagination page number
  • cursor? (number): Cursor for pagination
Returns: Promise<PaginatedNonTokenizedPositionData>

Network and Utility Methods

getNetworks(params?: NetworkParams)

Returns networks supported by Enso. Parameters:
  • name? (string): Name of the network to search for
  • chainId? (string): Chain ID of the network to search for
Returns: Promise<ConnectedNetwork[]>

getProjects()

Returns supported projects or platforms associated with available protocols. Returns: Promise<Project[]>

getProtocolsByProject(project: string)

Returns all protocols available within the given project. Parameters:
  • project (string): The project name
Returns: Promise<ProtocolData[]>

getAggregators(chainId?: number)

Fetches aggregators supported by Enso. Parameters:
  • chainId? (number): Chain ID to filter aggregators for
Returns: Promise<string[]>

getVolume(chainId: number)

Returns total USD and transactions volume for the given chainId. Parameters:
  • chainId (number): Chain ID to get volume for
Returns: Promise<unknown>

getAccountId()

Gets the account ID associated with the API key. Returns: Promise<string>

Working with Large Numbers

The SDK properly handles large numbers common in blockchain transactions:
Always use base-unit strings for token amounts. Do not use JavaScript numbers.

Bundle actions

Start with the Bundle API guide, then use the Bundle Actions Reference for public composition actions. Query protocol metadata for current protocol-specific availability:
Common bundle actions include:
  • Route: Token swaps and conversions
  • Deposit: Deposit tokens into DeFi protocols
  • Redeem: Withdraw tokens from DeFi protocols
  • Approve: Token approvals
  • Borrow: Borrow tokens from lending protocols
  • Repay: Repay loans to lending protocols
  • Transfer: Transfer tokens between addresses
  • Bridge: Cross-chain token transfers

Error Handling

The SDK includes proper error handling with custom error types:

Best Practices

  1. Use String Representations: Always use string representations for token amounts to avoid precision issues with large numbers
  2. Handle Slippage: Set appropriate slippage values (in basis points) to protect against price movements
  3. Gas Estimation: Use the returned gas estimate to set appropriate gas limits
  4. Error Handling: Implement proper error handling for network issues and API errors
  5. Rate Limiting: Be mindful of API rate limits when making multiple requests

Next Steps

Explore these resources to fully leverage the Enso SDK:
  • Routing Strategies - Learn about the different routing options and when to use each one
  • Bundle API - Compose, build, approve, and execute ordered actions
  • Bundle Actions Reference - Review public action inputs, outputs, and chaining rules
  • Shortcuts - See practical examples of common DeFi operations implemented with the SDK
  • Non-tokenized Positions - Discover how to interact with non-tokenized DeFi positions like Aave borrows or Liquity CDPs
  • GitHub Repository - Access the source code, report issues, or contribute to the SDK
  • Developer Chat - Join our Telegram group for technical support and discussions

Updated