Enso 백서

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

ryAddress: compoundCEth, }, }, ], ); ``` ```bash theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "aave-v3", "action": "redeem", "args": { "tokenIn": "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8", "tokenOut": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "amountIn": "1000000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "wrapped-native", "action": "redeem", "args": { "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "tokenOut": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "amountIn": { "useOutputOfCallAt": 0 }, "primaryAddress": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" } }, { "protocol": "compound-v2", "action": "deposit", "args": { "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "tokenOut": "0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5", "amountIn": { "useOutputOfCallAt": 1 }, "primaryAddress": "0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5" } } ]' | jq ``` </CodeGroup> <div /> ### Leveraged Positions Creating leveraged positions through multiple actions **Example**: Creating a 2x ETH position using Aave * **Input**: 1 WETH initial collateral * **Final Result**: WETH worth of collateral in Aave * **Process**: 1. Deposit 1 WETH as collateral in Aave 2. Borrow \~1,000 USDC against the WETH collateral 3. Swap the borrowed 1,000 USDC back to \~0.35 WETH 4. Deposit the additional WETH back into Aave as more collateral <CodeGroup> ```ts SDK theme={null} const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token and Protocol Addresses const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; const aWETH = "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8"; const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; const aaveV3Pool = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"; // Define amounts const initialDeposit = parseUnits("1", 18); const borrowAmount = parseUnits("1000", 6); const bundle = await ensoClient.getBundleData( { chainId, fromAddress, routingStrategy: "delegate", }, [ { protocol: "aave-v3", action: "deposit", args: { tokenIn: WETH, tokenOut: aWETH, amountIn: initialDeposit, primaryAddress: aaveV3Pool, }, }, { protocol: "aave-v3", action: "borrow", args: { collateral: WETH, tokenOut: USDC, amountOut: borrowAmount, primaryAddress: aaveV3Pool, }, }, { protocol: "enso", action: "route", args: { tokenIn: USDC, tokenOut: WETH, amountIn: { useOutputOfCallAt: 1 }, slippage: "100", }, }, { protocol: "aave-v3", action: "deposit", args: { tokenIn: WETH, tokenOut: aWETH, amountIn: { useOutputOfCallAt: 2 }, primaryAddress: aaveV3Pool, }, }, ], ); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "aave-v3", "action": "deposit", "args": { "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "tokenOut": "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8", "amountIn": "1000000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "aave-v3", "action": "borrow", "args": { "collateral": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "tokenOut": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "amountOut": "1000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "tokenOut": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "amountIn": { "useOutputOfCallAt": 1 }, "slippage": "100" } }, { "protocol": "aave-v3", "action": "deposit", "args": { "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "tokenOut": "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8", "amountIn": { "useOutputOfCallAt": 2 }, "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } } ]' | jq ``` </CodeGroup> <div /> ### Zap into multiple LPs Multi-step entry into or exit from liquid staking tokens with additional operations. **Example**: Creating diversified LP and LST positions with 1 ETH * **Input**: 1 ETH split evenly * **Slippage**: 3% for each conversion * **Process**: 1. Convert 0.5 ETH to stETH/ETH Curve LP tokens 2. Convert 0.5 ETH to BAL/WETH Balancer LP tokens <CodeGroup> ```ts SDK theme={null} import { parseUnits } from "ethers/lib/utils"; const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const ETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; const curve_stETH_ETH_Lp = "0x06325440D014e39736583c165C2963BA99fAf14E"; const balancer_BAL_WETH_Lp = "0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56"; // Define amount const amountIn = parseUnits("0.5", 18); const bundle = await ensoClient.getBundleData( { chainId, fromAddress, routingStrategy: "delegate", }, [ { protocol: "enso", action: "route", args: { tokenIn: ETH, tokenOut: curve_stETH_ETH_Lp, amountIn: amountIn, slippage: "300", }, }, { protocol: "enso", action: "route", args: { tokenIn: ETH, tokenOut: balancer_BAL_WETH_Lp, amountIn: amountIn, slippage: "300", }, }, ]); ``` ```bash theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "tokenOut": "0x06325440D014e39736583c165C2963BA99fAf14E", "amountIn": "500000000000000000", "slippage": "300" } }, { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "tokenOut": "0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56", "amountIn": "500000000000000000", "slippage": "300" } } ]' | jq ``` </CodeGroup> <div /> ### Yield Compounding Flow Automate yield compounding by harvesting rewards, swapping, and redepositing in a single transaction. **Example**: Compounding Curve gauge rewards back into the stETH/ETH pool * **Input**: Existing position in stETH/ETH Curve gauge * **Slippage**: 3% * **Process**: 1. Harvest accumulated wstETH rewards from the Curve gauge 2. Convert wstETH rewards to stETH 3. Deposit stETH back into the stETH/ETH Curve pool <CodeGroup> ```ts SDK theme={null} // Token and Protocol Addresses const rewardToken_wstETH = "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0"; const depositToken_stETH = "0xae7ab96520de3a18e5e111b5eaab095312d7fe84"; const lpToken_curve_stETH_ETH = "0x06325440d014e39736583c165c2963ba99faf14e"; const curveGauge = "0x182B723a58739a9c974cFDB385ceaDb237453c28"; const curvePool = "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022"; const bundle = await ensoClient.getBundleData( { chainId, fromAddress, receiver: fromAddress, routingStrategy: "delegate", }, [ { protocol: "curve-gauge", action: "harvest", args: { token: rewardToken_wstETH, primaryAddress: curveGauge, }, }, { protocol: "enso", action: "route", args: { tokenIn: rewardToken_wstETH, tokenOut: depositToken_stETH, amountIn: { useOutputOfCallAt: 0 }, slippage: "300", }, }, { protocol: "curve", action: "deposit", args: { tokenIn: depositToken_stETH, tokenOut: lpToken_curve_stETH_ETH, amountIn: { useOutputOfCallAt: 1 }, primaryAddress: curvePool, }, }, ], ); ``` ```bash theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate&receiver=0xd8da6bf26964af9d7eed9e03e53415d37aa96045' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "curve-gauge", "action": "harvest", "args": { "token": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", "primaryAddress": "0x182B723a58739a9c974cFDB385ceaDb237453c28" } }, { "protocol": "enso", "action": "route", "args": { "tokenIn": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0", "tokenOut": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84", "amountIn": { "useOutputOfCallAt": 0 }, "slippage": "300" } }, { "protocol": "curve", "action": "deposit", "args": { "tokenIn": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84", "tokenOut": "0x06325440d014e39736583c165c2963ba99faf14e", "amountIn": { "useOutputOfCallAt": 1 }, "primaryAddress": "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022" } } ] ' | jq ``` </CodeGroup> ### Liquid Staking Derivative Looping Create a leveraged position with liquid staking tokens through recursive borrowing and depositing in a lending protocol. **Example**: Implement a multi-loop leveraged position on Lido Staked ETH (wstETH) using Aave V3 as the lending platform. * **Input**: 10 wstETH * **Final Result**: \~18.32 wstETH deposited with \~8.32 wstETH borrowed (1.83x leverage) * **Process**: 1. Deposit 10 wstETH as collateral into Aave V3 2. Borrow 5.4 wstETH against your deposited collateral 3. Deposit the borrowed wstETH back as additional collateral 4. Borrow 2.916 wstETH against your increased collateral 5. Deposit this amount back again as additional collateral <CodeGroup> ```typescript SDK theme={null} import { parseUnits } from "ethers/lib/utils"; const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token and Protocol Addresses const wstETH = "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"; const aWstETH = "0x0B925eD163218f6662a35E0F0371Ac234F9E9371"; const aaveV3Pool = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2"; // Define amounts const initialDeposit = parseUnits("10", 18); const firstBorrow = parseUnits("5.4", 18); const secondBorrow = parseUnits("2.916", 18); const bundle = await ensoClient.getBundleData( { chainId, fromAddress, routingStrategy: "delegate", }, [ { protocol: "aave-v3", action: "deposit", args: { tokenIn: wstETH, tokenOut: aWstETH, amountIn: initialDeposit, primaryAddress: aaveV3Pool, }, }, { protocol: "aave-v3", action: "borrow", args: { collateral: wstETH, tokenOut: wstETH, amountOut: firstBorrow, primaryAddress: aaveV3Pool, }, }, { protocol: "aave-v3", action: "deposit", args: { tokenIn: wstETH, tokenOut: aWstETH, amountIn: firstBorrow, primaryAddress: aaveV3Pool, }, }, { protocol: "aave-v3", action: "borrow", args: { collateral: wstETH, tokenOut: wstETH, amountOut: secondBorrow, primaryAddress: aaveV3Pool, }, }, { protocol: "aave-v3", action: "deposit", args: { tokenIn: wstETH, tokenOut: aWstETH, amountIn: secondBorrow, primaryAddress: aaveV3Pool, }, }, ], ); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "aave-v3", "action": "deposit", "args": { "tokenIn": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "tokenOut": "0x0B925eD163218f6662a35E0F0371Ac234F9E9371", "amountIn": "10000000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "aave-v3", "action": "borrow", "args": { "collateral": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "tokenOut": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "amountOut": "5400000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "aave-v3", "action": "deposit", "args": { "tokenIn": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "tokenOut": "0x0B925eD163218f6662a35E0F0371Ac234F9E9371", "amountIn": "5400000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "aave-v3", "action": "borrow", "args": { "collateral": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "tokenOut": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "amountOut": "2916000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } }, { "protocol": "aave-v3", "action": "deposit", "args": { "tokenIn": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", "tokenOut": "0x0B925eD163218f6662a35E0F0371Ac234F9E9371", "amountIn": "2916000000000000000", "primaryAddress": "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2" } } ]' | jq ``` </CodeGroup> <div /> ### Cross-Chain Route-Bridge Execute a route and bridge tokens to another chain in a single transaction using the route-bridge functionality. **Example**: Bridging 1 ETH from Ethereum to Optimism and converting to USDT * **Input**: 1 ETH on Ethereum * **Output**: USDT on Optimism * **Process**: 1. Route 1 ETH to USDT on Ethereum 2. Bridge the resulting USDT to Optimism 3. Receive USDT on Optimism <Warning> **Important**: When using `destinationChainId`, you **must** include `refundReceiver` to handle any potential refunds from failed bridge operations. </Warning> <CodeGroup> ```ts SDK theme={null} const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const ETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; const USDT_optimism = "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58"; // Define amount const amountIn = parseUnits("1", 18); // 1 ETH const bundle = await ensoClient.getBundleData( { chainId, fromAddress, routingStrategy: "delegate", }, [ { protocol: "enso", action: "route", args: { tokenIn: ETH, // ETH on Ethereum tokenOut: USDT_optimism, // USDT on Optimism amountIn: amountIn, destinationChainId: 10, // Optimism refundReceiver: fromAddress, // Required for route-bridge }, }, ], ); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/bundle?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&routingStrategy=delegate' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '[ { "protocol": "enso", "action": "route", "args": { "tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "tokenOut": "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58", "amountIn": "1000000000000000000", "destinationChainId": 10, } } ]' | jq ``` </CodeGroup> <div> <p>Updated </p> </div> # Authentication Source: https://docs.enso.build/pages/build/get-started/authentication Obtain Enso API key to access the Enso API. ## Obtain API Key 1. Create an API key in the [Enso Developer Portal](https://developers.enso.build). 2. Store it in an environment variable. Never commit the key to source control. ## Authenticate requests Pass your API key using either: * The `Authorization: Bearer <API_KEY>` header. * The `apikey=<API_KEY>` query parameter. ## Test your API key Use the authenticated account endpoint to verify the key without building a transaction: <Tabs> <Tab title="Authorization header"> ```bash theme={null} curl \ -H "Authorization: Bearer $ENSO_API_KEY" \ "https://api.enso.build/api/v1/account/accountId" ``` </Tab> <Tab title="Query parameter"> ```bash theme={null} curl \ "https://api.enso.build/api/v1/account/accountId?apikey=$ENSO_API_KEY" ``` </Tab> </Tabs> Next, choose between the [Route API and Bundle API](/pages/build/get-started/overview#route-api-vs-bundle-api). ## Rate Limiting API calls are limited to 10 RPS (600 requests per minute). It can be increased on demand. If you exceed the limit, you'll receive a `429 Too Many Requests` error. If your monthly API credits quota is exceeded, requests also return `429 Too Many Requests`. Rate limit and quota errors include a `portalUrl` field that points to the Developer Portal for key management and plan upgrades. ## Auth Errors Invalid API keys return `401 Unauthorized` with `error: "invalid_api_key"`. Retired legacy keys return `401 Unauthorized` with `error: "legacy_key_retired"`. Both responses include a `portalUrl` field so clients can direct users to create or recover an API key in the Developer Portal. <div> <p>Updated </p> </div> # Get Balances Source: https://docs.enso.build/pages/build/get-started/balances Get balances of tokens in a wallet address. ## Balances Information The `/balances` endpoint returns all wallet balances across protocols and networks Enso supports. **API Reference:** [GET `/v1/wallet/balances`](/api-reference/defi/wallet-balances) ```json theme={null} [ { "token": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "amount": "7568910913750864", "decimals": 18, "price": 2559.27, "name": "ETH", "symbol": "ETH", "logoUri": "https://static.debank.com/image/coin/logo_url/eth/6443cdccced33e204d90cb723c632917.png" }, { "token": "0x030ba81f1c18d280636f32af80b9aad02cf0854e", "amount": "2455429", "decimals": 18, "price": 2509.83, "name": "Aave interest bearing WETH", "symbol": "aWETH", "logoUri": "https://static.debank.com/image/eth_token/logo_url/0x030ba81f1c18d280636f32af80b9aad02cf0854e/b6910e236da889f08602435e79c08f98.png" } ] ``` ## Example Request <CodeGroup> ```ts EnsoSDK theme={null} import { EnsoClient } from '@ensofinance/sdk'; // Initialize the client with your API key const enso = new EnsoClient({ apiKey: 'YOUR_API_KEY' // Replace with your actual API key }); // Get user balances across all protocols on a specific chain async function getUserBalances(chainId: number, address: string) { try { const balances = await enso.getBalances({ chainId, eoaAddress: address, useEoa: true // Get balances for EOA; set to false for Enso Smart Wallet }); console.log(`Balances for ${address} on chain ${chainId}:`, balances); return balances; } catch (error) { console.error('Error fetching user balances:', error); throw error; } } // Get user balances on Ethereum getUserBalances(1, '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'); ``` ```bash cURL theme={null} curl -X GET \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $ENSO_API_KEY" \ "https://api.enso.build/api/v1/wallet/balances?chainId=1&eoaAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&useEoa=true" \ | jq ``` </CodeGroup> # Bridge Transaction Status Source: https://docs.enso.build/pages/build/get-started/bridge-status Track the status of crosschain bridge transactions across Stargate, CCIP, Relay, and CCTP After submitting a crosschain transaction via the [Route](/pages/build/get-started/route) or [Bundle](/pages/build/get-started/bundling-actions) API, the bridge delivery is asynchronous. Enso provides protocol-specific status endpoints to track delivery progress on the destination chain. ## Quick Reference | Bridge Protocol | Status Endpoint | Status Field | | - | - | - | | CCIP | `GET /api/v1/ccip/bridge/check` | `status` | | CCTP | `GET /api/v1/cctp/bridge/check` | `status` | | Relay | `GET /api/v1/relay/bridge/check` | `status` | | Stargate | `GET /api/v1/stargate/bridge/check` | `status` | All endpoints accept two query parameters: * `chainId` — source chain ID (number) * `txHash` — source transaction hash (string, `0x` + 64 hex characters) <Warning> **Rate limit**: All bridge status endpoints are limited to **1 request per 10 seconds** per API key (or per IP if unauthenticated). Exceeding this returns HTTP 429. Enforce a minimum 10-second interval between polls. </Warning> ## Status Lifecycle Bridge transactions progress through a unified status lifecycle: ```mermaid theme={null} stateDiagram-v2 [*] --> pending pending --> inflight : Bridge picks up message inflight --> delivered : Des
프로젝트로 돌아가기