Enso 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 35쪽 중 14쪽

ta( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", }, [ { protocol: "enso", action: "route", args: { tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", amountIn: "1000000000000000000", slippage: "300", }, }, { protocol: "math", action: "div", args: { amountA: { useOutputOfCallAt: 0 }, amountB: "2", }, }, { protocol: "erc20", action: "transfer", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", amount: { useOutputOfCallAt: 1 }, receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", }, }, { protocol: "erc20", action: "transfer", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", amount: { useOutputOfCallAt: 1 }, receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `amountA` | First operand — a static uint256 value or a reference to a previous action's output | Yes | | `amountB` | Second operand — a static uint256 value or a reference to a previous action's output | Yes | ## Helpers Actions Helpers actions provide on-chain comparison and conditional logic, enabling bundles to branch based on runtime values. These are useful for building guard conditions, assertions, and conditional flows. All helpers actions use protocol `helpers`. ### Comparison Actions Compare two uint256 values and return a boolean result. The result can be referenced by subsequent actions. #### `isequal` Returns `true` if `amountA == amountB`. #### `islessthan` Returns `true` if `amountA < amountB`. #### `isequalorlessthan` Returns `true` if `amountA <= amountB`. #### `isgreaterthan` Returns `true` if `amountA > amountB`. #### `isequalorgreaterthan` Returns `true` if `amountA >= amountB`. | Parameter | Description | Required | | - | - | - | | `amountA` | First operand — a static uint256 value or a reference to a previous action's output | Yes | | `amountB` | Second operand — a static uint256 value or a reference to a previous action's output | Yes | ### `check` Asserts that a boolean condition is `true`. If the condition is `false`, the entire transaction reverts. Use this to enforce invariants — for example, ensuring an output amount meets a minimum threshold. | Parameter | Description | Required | | - | - | - | | `condition` | A boolean value or a reference to a comparison action's output | Yes | ### `not` Negates a boolean condition. Returns `true` if the input is `false`, and vice versa. | Parameter | Description | Required | | - | - | - | | `condition` | A boolean value or a reference to a comparison action's output | Yes | ### `toggle` Selects between two values based on a condition. Returns `amountA` if the condition is `true`, otherwise returns `amountB`. This is the on-chain equivalent of a ternary expression (`condition ? amountA : amountB`). | Parameter | Description | Required | | - | - | - | | `condition` | A boolean value or a reference to a comparison action's output | Yes | | `amountA` | The value to return if the condition is `true` | Yes | | `amountB` | The value to return if the condition is `false` | Yes | **Example: Check that a routed amount is above a minimum before proceeding** ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "route", args: { tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", tokenOut: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", amountIn: "1000000000000000000", slippage: "300", }, }, { protocol: "helpers", action: "isequalorgreaterthan", args: { amountA: { useOutputOfCallAt: 0 }, amountB: "1000000000", // minimum 1000 USDC }, }, { protocol: "helpers", action: "check", args: { condition: { useOutputOfCallAt: 1 }, }, }, ], ); ``` ## Protocol Support The Bundle API supports a wide range of protocols. Some common ones include: * `aave-v2`, `aave-v3`: Aave lending/borrowing * `balancer-v2`: Balancer liquidity pools * `curve`: Curve Finance stable swaps and gauges * `curve-gauge`: Curve gauges for staking * `erc20`: Standard token operations * `erc721`: Non-fungible token operations (`approve`, `transfer`, `transferfrom`) * `erc4626`: ERC4626 vaults * `enso`: General Enso operations including route, split, merge, balance, and arbitrary calls * `math`: On-chain arithmetic operations (`add`, `sub`, `mul`, `div`, `min`, `max`) * `helpers`: On-chain comparisons and conditional logic (`isequal`, `islessthan`, `isgreaterthan`, `check`, `not`, `toggle`) * `permit2`: Uniswap's Permit2 operations * `uniswap-v2`, `uniswap-v3`: Uniswap pools and routers * `yearn`: Yearn Finance vaults * `compound-v2`, `compound-v3`: Compound lending/borrowing * `stargate`: Cross-chain bridging For a complete list of supported protocols, use the Projects API endpoint: [GET `/standards`](/api-reference/integration/standards). <div> <p>Updated </p> </div> # Advanced Balance Source: https://docs.enso.build/pages/build/reference/balance Check balances of external accounts and build routes against estimated amounts using the Bundle API. The `balance` action supports advanced parameters for pulling tokens from external accounts and building routes against estimated token amounts. These parameters extend the [basic balance action](/pages/build/reference/actions#balance), which simply returns the on-chain balance of the caller's wallet. <Warning> This is an advanced feature intended for integrators who need to pull tokens from external accounts or pre-build routes before balances are available. Using `account` and `estimate` incorrectly can lead to **loss of funds**. Read the [risk considerations](#risk-considerations) below before integrating. </Warning> ## How It Works ```mermaid theme={null} sequenceDiagram participant User participant Enso API participant RPC Node participant Wallet User->>Enso API: POST /bundle with balance action (account) alt Without estimate Enso API->>RPC Node: Check token balance of account RPC Node-->>Enso API: Balance value Enso API->>Enso API: Build route with the balance else With estimate Enso API->>Enso API: Build route with the estimate end Enso API-->>User: Transaction data User->>Wallet: Submit bundle transaction ``` 1. You submit a `/bundle` request with a `balance` action that includes `account` (and optionally `estimate`) 2. The API performs an off-chain RPC call to check the account's token balance 3. If no `estimate` is provided and the balance is zero, the request returns an error 4. For **router** strategy: the token and amount are added to `tokensIn`/`amountsIn` 5. For **delegate** / **ensowallet** strategies: a `transferFrom` call is automatically inserted to pull tokens from the external account into the wallet 6. The API generates approval transactions that the `account` must sign for the spender contract before the bundle can execute ## Parameters | Parameter | Type | Description | Required | | - | - | - | - | | `token` | `AddressArg` | Address of the token to check balance | Yes | | `estimate` | `NumberArg` | Estimated balance amount in wei. Allows route building without an existing balance on the account. | No | | `account` | `AddressArg` | Address of an external account to check balance of. Defaults to the caller's wallet address when omitted. | No | <Note> When only `token` is provided (no `account` or `estimate`), the action behaves exactly as the basic balance check — returning the on-chain balance of the caller's wallet. See the [basic usage](/pages/build/reference/actions#balance). </Note> ## Behavior by Routing Strategy The advanced balance action behaves differently depending on the routing strategy and whether `estimate` is provided: ### Router * **With `account` only (no `estimate`):** The `account` must approve the **router contract**. * **With `account` and `estimate`:** The `account` must approve the **EnsoShortcuts contract**. The required approval transaction is returned in the bundle response. <Warning> **Dangerous: EnsoShortcuts contract approval.** When using `estimate` with the `router` strategy, the `account` must approve the EnsoShortcuts contract. If approval is not reset back to 0, anyone will be able to pull funds from the wallet. **You should revoke this approval within the same transaction** to minimize the window of exposure. Leaving the approval active after the transaction is a security risk. </Warning> ### Delegate / EnsoWallet | Strategy | Behavior when `account` is provided | | - | - | | `delegate` | Automatically inserts a `transferFrom` call to pull tokens from the account into the wallet. The account must approve the delegate contract. | | `ensowallet-v2` | Same as `delegate` — inserts a `transferFrom` call. The account must approve the EnsoWallet contract. | <Tip> See [Routing Strategies](/pages/build/reference/routing-strategies) for details on choosing a strategy. </Tip> ## Balance Estimates When `estimate` is provided alongside `account`, routes are built using the estimated amount rather than requiring the full on-chain balance: * The API uses the estimate for quoting and route optimization, enabling you to build transactions before the account has the full balance available <Warning> Routes built with `estimate` are only as accurate as the estimate itself. If the actual balance at execution time differs significantly from the estimate, the transaction may fail or produce suboptimal results. </Warning> ## Risk Considerations * **EnsoShortcuts contract approval** - When using `estimate` with the `router` strategy, the `account` must approve the EnsoShortcuts contract, which is the main execution contract where tokens will get pulled into. **Always revoke this approval in the same transaction.** The required approval is returned in the bundle response - pair it with a revoke action to avoid leaving a persistent approval. * **Estimate as max amount** - The `estimate` value should be treated as the **maximum amount** that will be pulled from the account. Swap aggregators used during routing may capture positive slippage, meaning the actual amount consumed can be up to the full estimate even if a smaller amount would have sufficed for the desired output. Set the estimate carefully to limit exposure. * **Estimate accuracy** - Using `estimate` means routes are optimized against projected amounts. Significant divergence between the estimate and the actual balance at execution time can cause transaction failure or poor execution prices. * **External account security** - This feature pulls tokens from an external account via `transferFrom`. Always verify the `account` address and its approval status before executing. ## Examples ### Balance with Account and Route This example checks the USDC balance of an external account with an estimate, then routes the USDC to USDT. <CodeGroup> ```typescript TypeScript SDK theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "router", }, [ { protocol: "enso", action: "balance", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC account: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", estimate: "1000000000", // 1000 USDC }, }, { protocol: "enso", action: "route", args: { tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC tokenOut: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT amountIn: { useOutputOfCallAt: 0 }, slippage: "300", }, }, ], ); ``` ```bash cURL theme={null} curl -X POST \ "https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=router" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "enso", "action": "balance", "args": { "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "account": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "estimate": "1000000000" } }, { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "amountIn": { "useOutputOfCallAt": 0 }, "slippage": "300" } } ]' ``` </CodeGroup> **What's happening step by step:** 1. **Balance** — Check the USDC balance of the external account, using `1000 USDC` as the estimate for route building 2. **Route** — Route the USDC to USDT using `useOutputOfCallAt: 0` to reference the balance from step 1 ### Balance with Account, TransferFrom, and Route This example checks the balance, explicitly transfers tokens from the external account, then routes. <CodeGroup> ```typescript TypeScript SDK theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "router", }, [ { protocol: "enso", action: "balance", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC account: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", estimate: "1000000000", // 1000 USDC }, }, { protocol: "erc20", action: "transferfrom", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC sender: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", receiver: "0x4Fe93ebC4Ce6Ae4f81601cC7Ce7139023919E003", // EnsoShortcuts amount: { useOutputOfCallAt: 0 }, }, }, { protocol: "enso", action: "route", args: { tokenIn: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC tokenOut: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT amountIn: { useOutputOfCallAt: 0 }, slippage: "300", }, }, ], ); ``` ```bash cURL theme={null} curl -X POST \ "https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=router" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "enso", "action": "balance", "args": { "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "account": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "estimate": "1000000000" } }, { "protocol": "erc20", "action": "transferfrom", "args": { "token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "sender": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "receiver": "0x4Fe93ebC4Ce6Ae4f81601cC7Ce7139023919E003", "amount": { "useOutputOfCallAt": 0 } } }, { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "tokenOut": "0xdAC17F958D2ee523a2206206994597C13D831ec7", "amountIn": { "useOutputOfCallAt": 0 }, "slippage": "300" } } ]' ``` </CodeGroup> **What's happening step by step:** 1. **Balance** — Check the USDC balance of the external account with a `1000 USDC` estimate 2. **TransferFrom** — Explicitly transfer USDC from the external account to the router, using `useOutputOfCallAt: 0` to reference the balance 3. **Route** — Route the USDC to USDT <Tip> When the balance action detects a following `transferFrom` for the same token and account, it optimizes the flow automatically. Use `useOutputOfCallAt` to dynamically chain action outputs. See [Chaining Actions](/pages/build/reference/actions#chaining-actions) for details. </Tip> <div> <p>Updated </p> </div> # Concepts Source: https://docs.enso.build/pages/build/reference/concepts Understand Enso's core concepts and how they work. ## Projects A project in Enso represents an overarching blockchain platform or financial service with multiple protocol implementations. Projects serve as the top-level categorization in Enso's data model, grouping related protocols Example: The "Aave" project encompasses protocols "aave-v2" and "aave-v3". **API Reference:** * [GET `/projects`](/api-reference/integration/projects) - Returns all available projects * [GET `/projects/protocols`](/api-reference/integration/protocols-in-a-project) - Returns protocols available for a specific project ## Protocols A protocol is a specific implementation or version of a project deployed on one or more blockchain networks. Each protocol has a unique identifier (slug), defined functionality, and standardized interfaces. For example, "uniswap-v3" specifies the exact smart contract implementations, supported chains, and available actions for that particular version of Uniswap. **API Reference:** * [GET `/projects/protocols`](/api-reference/integration/protocols-in-a-project) - Returns all supported protocols and their metadata * [GET `/integration/{slug}`](/api-reference/integration/standard-per-protocol) - Returns details for a specific protocol by slug ## Standards A standard defines the interface specifications and methods for interacting with protocols. Standards document the common patterns across similar protocols, including required inputs, function signatures, and expected outputs. This standardization layer enables Enso to abstract implementation details and *provide consistent interfaces* across varied DeFi protocols. **API Reference:** * [GET `/standards`](/api-reference/integration/standards) - Returns all available standards and their methods * [GET `/actions`](/api-reference/integration/supported-actions) - Returns all standardized actions available for protocols ## Actions An action is a discrete operation performed on a protocol (e.g., "deposit", "withdraw", "swap", "borrow"). Actions specify the required input parameters and expected outputs for each operation type. Enso's action abstraction allows developers to *execute the same conceptual operation* across different protocols without handling protocol-specific implementation details. Actions can be bundled into atomic multi-step transactions. **API Reference:** * [GET `/actions`](/api-reference/integration/supported-actions) - Returns all available actions and their input parameters * [POST `/shortcuts/bundle`](/api-reference/defi-shortcuts/bundle-a-list-of-actions) - Allows bundling multiple actions into a single transaction ## Tokens Enso recognizes two primary token types: 1. **Base Token**: Standard cryptocurrency assets without DeFi positioning (e.g., ETH, WETH, USDC, DAI). These tokens serve as the building blocks for DeFi operations. 2. **DeFi Token**: Tokens representing positions in DeFi protocols (e.g., yvWETH for Yearn-deposited WETH, aDAI for Aave-deposited DAI). These tokens contain metadata about their protocol association, underlying assets, APY, and TVL metrics. **API Reference:** * [GET `/tokens/tokens`](/api-reference/tokens/tokens) - Returns all supported tokens with filtering options for type, protocol, etc. * [GET `/defi/prices`](/api-reference/tokens/token-price) - Returns price data for a specific token Both token types include core properties (address, chainId, decimals, symbol, name, logoUri), with DeFi tokens containing additional protocol-specific metadata. <div> <p>Updated </p> </div> # Contracts and Deployments Source: https://docs.enso.build/pages/build/reference/deployments Enso contracts deployment addresses Contracts are grouped by the role they play in a transaction. | I need… | Contract | Section | | - | - | - | | The contract an EOA sends `router` transactions to | EnsoRouter | [V2 Contracts](#v2-contracts) | | The code a smart account runs with the `delegate` strategy | DelegateEnsoShortcuts | [V2 Contracts](#v2-contracts) | | The executor that holds assets mid-shortcut under `router` | EnsoShortcuts | [V2 Contracts](#v2-contracts) | | The factory and wallet behind the `ensowallet-v2` strategy | EnsoWalletV2Factory, EnsoWalletV2 | [EnsoWallet V2](#ensowallet-v2) | | The contract that receives flashloan callbacks | Flashloan adapter for your strategy |
프로젝트로 돌아가기