Enso 백서

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

addresses of tokens to receive | Yes | | `amountIn` | Amount of `tokenIn` to deposit in wei (with full decimals) | Yes | | `primaryAddress` | Address of the protocol contract to interact with | Yes | | `receiver` | Address to receive the output tokens if not the caller | No | ## Lending Actions ### `flashloan` Borrows tokens from a lending protocol without upfront collateral, executes callback actions atomically, and repays the debt within the same transaction. <Info> Flashloans have dedicated documentation. See the [Flashloans Reference](/pages/build/reference/flashloans) for supported protocols, chain availability, parameters, and examples. </Info> ### `borrow` Borrows a token from a lending protocol using a deposited token as collateral. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "aave-v3", action: "deposit", args: { tokenIn: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH address tokenOut: "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8", // aWETH address (optional) amountIn: "1000000000000000000", // Amount in wei (1 WETH) primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 pool receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", // Optional: Receiver address }, }, { protocol: "aave-v3", action: "borrow", args: { collateral: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH address (collateral) tokenOut: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC address (to borrow) amountOut: "1000000000", // Amount to borrow in wei (1000 USDC with 6 decimals) primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 pool }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `collateral` | Address of the token used as collateral. Can be an array for multiple collateral tokens | Yes | | `tokenOut` | Address of the token to borrow | Yes | | `amountOut` | Amount to borrow in wei (with full decimals) | Yes | | `primaryAddress` | Address of the lending pool contract | Yes | ### `repay` Repays a loan on a lending protocol. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "aave-v3", action: "deposit", args: { tokenIn: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH address tokenOut: "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8", // aWETH address (optional) amountIn: "1000000000000000000", // Amount in wei (1 WETH) primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 pool receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", // Optional: Receiver address }, }, { protocol: "aave-v3", action: "borrow", args: { collateral: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH address (collateral) tokenOut: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC address (to borrow) amountOut: "1000000000", // Amount to borrow in wei (1000 USDC with 6 decimals) primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", // Aave V3 pool }, }, // Step 3: Now repay the borrowed USDT { protocol: "aave-v3", action: "repay", args: { tokenIn: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC amountIn: "1000000000", // 100 USDC primaryAddress: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `tokenIn` | Address of token to repay | Yes | | `amountIn` | Amount to repay in wei (with full decimals) | Yes | | `primaryAddress` | Address of the lending pool contract | Yes | | `onBehalfOf` | Address to repay debt for | Yes | ### `repay` on Behalf of Another address Repay parameter `onBehalfOf` enables you to repay a loan on behalf of a given address: ```js theme={null} const bundleData = await client.getBundleData( { chainId: 1, // Mainnet fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045" as Address, routingStrategy: "delegate", }, [ // 3. Repay the ETH debt { protocol: "compound-v2", action: "repay", args: { tokenIn: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", // ETH amountIn: "300000000000000000", primaryAddress: "0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5", // cETH contract onBehalfOf: "0x80fCBfbC698Aca3B3BCB83ceB13301a639A39832", }, }, ], ); console.log(bundleData); ``` ## Yield Farming Actions ### `harvest` Harvests rewards from yield-generating positions. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "curve-gauge", action: "harvest", args: { token: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", // Token address (LP token or gauge token) primaryAddress: "0x182B723a58739a9c974cFDB385ceaDb237453c28", // Curve gauge address }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of token to harvest rewards for | Yes | | `primaryAddress` | Address of the contract to interact with (e.g., gauge, farm) | Yes | ## Token Management Actions ### `approve` Approves a spender to use tokens. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "erc20", action: "approve", args: { token: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH address spender: "0xe592427a0aece92de3edee1f18e0157c05861564", // Spender address (e.g., Uniswap router) amount: "1000000000000000000000000", // Amount to approve in wei (1M WETH) }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the token to approve | Yes | | `spender` | Address of the spender (protocol or router) | Yes | | `amount` | Amount to approve in wei (with full decimals) | Yes | ### `transfer` Transfers tokens to a specified address. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "erc20", action: "transfer", args: { token: "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", // OMG token address receiver: "0x80eba3855878739f4710233a8a19d89bdd2ffb8e", // Recipient address amount: "1000000000000000000", // Amount to transfer in wei (1 OMG) }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the token to transfer | Yes | | `receiver` | Address of the recipient | Yes | | `amount` | Amount to transfer in wei (with full decimals) | Yes | For NFT transfers see [`erc721:transfer`](#erc721-transfer) below. ### `transferFrom` Transfers tokens from a specified address to another address. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "balance", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", }, }, { protocol: "erc20", action: "transferfrom", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // OMG token address sender: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", // Sender address receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", // Recipient address amount: "1000000000000000000", // Amount to transfer in wei (1 OMG) }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the token to transfer | Yes | | `sender` | Address of the sender | Yes | | `receiver` | Address of the recipient | Yes | | `amount` | Amount to transfer in wei (with full decimals) | Yes | For NFT transfers see [`erc721:transferFrom`](#erc721-transferfrom) below. ### `erc721:transfer` ERC-721 doesn't expose a `transfer(to, tokenId)` selector — this is a UX alias that emits a `transferFrom(walletAddress(), receiver, tokenId)` call. Unlike `erc721:transferFrom`, this action's input schema does **not** accept `sender`; the sender is always the executing wallet at runtime. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "erc721", action: "transfer", args: { token: "0x15da4c7db6404b92894d5214FAc92057Fb8a263d", // NFT collection address receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", // Recipient tokenId: "715", // Token id to transfer }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the ERC-721 collection | Yes | | `receiver` | Address of the recipient | Yes | | `tokenId` | The ERC-721 token id to transfer | Yes | ### `erc721:approve` Approves a spender to operate on a single ERC-721 token id. Mirrors `erc20:approve` but with `tokenId` in place of `amount`. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "erc721", action: "approve", args: { token: "0x15da4c7db6404b92894d5214FAc92057Fb8a263d", // NFT collection address spender: "0x000000000000000000000000000000000000dEaD", // Spender address tokenId: "715", // Token id to approve }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the ERC-721 collection | Yes | | `spender` | Address allowed to operate on the token id | Yes | | `tokenId` | The ERC-721 token id to approve | Yes | <Note> ERC-721 `approve(spender, tokenId)` requires `msg.sender` to be the owner of the token id (or an approved operator). The effective `msg.sender` inside a bundle depends on `routingStrategy` — for `router`, that is the shared `EnsoShortcuts` contract; for `delegate` / `ensowallet-v2`, the per-user wallet. The token id must be owned by whichever address `msg.sender` resolves to at execution time. </Note> ### `erc721:transferFrom` Transfers an ERC-721 token id between two addresses. Mirrors `erc20:transferfrom` but takes `tokenId` instead of `amount`, and `sender` is optional — when omitted it defaults to the executing wallet. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "erc721", action: "transferfrom", args: { token: "0x15da4c7db6404b92894d5214FAc92057Fb8a263d", // NFT collection address receiver: "0x93621DCA56fE26Cdee86e4F6B18E116e9758Ff11", // Recipient tokenId: "715", // Token id to transfer }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the ERC-721 collection | Yes | | `receiver` | Address of the recipient | Yes | | `tokenId` | The ERC-721 token id to transfer | Yes | | `sender` | Address holding the token id. Defaults to the executing wallet when omitted. | No | When `sender` is external to the executing wallet, the API returns an ERC-721 approval as a `requiredApproval` entry in `preTransactions`. The token id must be static, and the routing strategy must use a wallet scoped to the user. Shared `router` strategies reject external-sender ERC-721 transfers. ### `permitTransferFrom` Approves and transfers a token that supports permit in a single step using a signature. A permit signature needs to be generated offchain and passed to the API. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "permit2", action: "permittransferfrom", args: { token: "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07", // Token address amount: "1000000000000000000", // Amount in wei (1 token) sender: "0xb67f3CE46bB9E1a1127796c27f38DbaB9f643ec0", // Sender address receiver: "0x35a2839b617F7da6534d636f22945f6Cb6137130", // Receiver address nonce: "1", // Nonce to prevent replay attacks deadline: "1710150268", // Timestamp deadline for signature validity signature: "0x...", // Permit signature }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the token to transfer. Can be an array for multiple tokens | Yes | | `amount` | Amount to transfer in wei (with full decimals). Can be an array for multiple tokens | Yes | | `sender` | Address of the sender | Yes | | `receiver` | Address of the recipient | Yes | | `nonce` | Nonce value to prevent signature replay | Yes | | `deadline` | Timestamp after which the signature is invalid | Yes | | `signature` | The EIP-2612 permit signature | Yes | ## Utility Actions ### `balance` Gets the balance of a token for the caller's address. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "balance", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Address of the token to check balance | Yes | <Info> The balance action supports advanced parameters for checking external account balances and building routes with estimated amounts. See the [Advanced Balance Reference](/pages/build/reference/balance) for details, risk considerations, and examples. </Info> ### `split` Routes one input amount into more than one `tokenOut`. It returns an array with one amount per output token; downstream actions must select each value with `index`. This is not an arbitrary percentage splitter. See [Chaining actions](#chaining-actions) for a complete `split -> depositclmm` example. A `split` must feed a compatible later deposit flow; it is not a terminal transfer action. | Parameter | Description | Required | | - | - | - | | `tokenIn` | Address of the token to split | Yes | | `tokenOut` | Array of token addresses for the split outputs | Yes | | `amountIn` | Base-unit amount or previous output reference | Yes | | `receiver` | Address to receive the split tokens | No | ### `merge` Routes more than one input token into a single output amount. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "merge", args: { tokenIn: [ "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC "0x6b175474e89094c44da98b954eedeac495271d0f", // DAI ], tokenOut: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // Combined WETH amountIn: [ "2000000", // 2 USDC "3000000000000000000", // 3 DAI ], receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `tokenIn` | Array of input token addresses | Yes | | `tokenOut` | Address of the output token | Yes | | `amountIn` | Base-unit amount for each corresponding input token | Yes | | `receiver` | Address to receive the merged tokens | No | ### `call` Makes an arbitrary contract call for interactions not covered by a public action. The return shape follows the supplied ABI, and output references can be used inside nested argument objects. <Warning> Arbitrary calls can transfer assets or grant permissions. Verify the target, ABI, calldata, and returned transaction before signing. See the [custom contract call guide](/pages/build/examples/custom-call-bundle). </Warning> For arithmetic over prior outputs, prefer the documented [Math Actions](#math-actions). ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "call", args: { address: "0xD0aF6F692bFa10d6a535A3A321Dc8377F4EeEF12", // Contract address method: "percentMul", // Method name abi: "function percentMul(uint256,uint256) external", // ABI signature args: [ "1000000000000000000", // 1 ETH (first argument) "7000", // 70% (second argument) ], }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `address` | Address of the contract to call | Yes | | `method` | Name of the method to call | Yes | | `abi` | ABI signature of the method | Yes | | `args` | Array of arguments to pass to the method | Yes | | `tokenIn` | Input token address (when tokens are involved in the call) | No | | `tokenOut` | Output token address (when tokens are involved in the call) | No | | `value` | ETH value to send with the transaction in wei | No | ### `fee` Calculates and deducts a fee from a specified amount, sending the fee to a designated receiver. This action is typically prepended to bridge operations to facilitate fee collection. The `fee` action calculates the fee as `amount * (bps/10000)` and sends this amount to the `receiver`. It returns `amount - fee`, which can be used in subsequent actions via `useOutputOfCallAt`. <Tip> To earn a fee on your users' trades, configure [Fees](/pages/build/reference/fees) in the developer portal. </Tip> ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "fee", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", amount: "1000000000000", bps: "500", receiver: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Token address to apply the fee to | Yes | | `amount` | Amount to apply the fee to (with full decimals) or a return value from a previous action | Yes | | `bps` | Fee percentage in basis points (1 bps = 0.01%, 100 bps = 1%) | Yes | | `receiver` | Address to receive the fee | Yes | ### `ensofee` Calculates and deducts Enso's protocol fee from a specified amount. The `ensofee` action calculates the fee as `amount * (bps/10000)` and sends this amount to Enso. It returns `amount - fee`, which can be used in subsequent actions via `useOutputOfCallAt`. ```typescript theme={null} const bundle = await client.getBundleData( { chainId: 1, fromAddress: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", routingStrategy: "delegate", }, [ { protocol: "enso", action: "ensofee", args: { token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC amount: "1000000000", // 1000 USDC bps: "25", // 0.25% fee (25 basis points) }, }, ], ); ``` | Parameter | Description | Required | | - | - | - | | `token` | Token address to apply the fee to | Yes | | `amount` | Amount to apply the fee to (with full decimals) or a return value from a previous action | Yes | | `bps` | Fee percentage in basis points (1 bps = 0.01%, 100 bps = 1%) | Yes | ## Math Actions Math actions perform on-chain arithmetic operations over values from previous actions. These are useful for computing amounts dynamically within a bundle — for example, dividing a routed amount to distribute across multiple recipients. All math actions use protocol `math` and take two operands: `amountA` and `amountB`. Each operand can be a static value or a reference to a previous action's output via `useOutputOfCallAt`. ### `add` Returns `amountA + amountB`. ### `sub` Returns `amountA - amountB`. ### `mul` Returns `amountA * amountB`. ### `div` Returns `amountA / amountB` (integer division). ### `min` Returns the smaller of `amountA` and `amountB`. ### `max` Returns the larger of `amountA` and `amountB`. **Example: Route then divide output by 2 and transfer halves to two addresses** ```typescript theme={null} const bundle = await client.getBundleDa
프로젝트로 돌아가기