Enso 백서

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

s32) ``` To implement the tracking, you'll need to analyze the `ShortcutExecuted` events emitted by the Enso smart contract executing your transaction. This event contains two key pieces of information: * Use `accountId`, uniquely associated with your account, to identify all requests made through your project's integration with Enso. * Use the `requestId` (a unique identifier for each request) where the higher 16 bytes represent contain the `referralCode`. <div> <p>Updated </p> </div> # Non-tokenized Position Routing Source: https://docs.enso.build/pages/build/examples/route-nontokenized Get route calldata into non-tokenized positions The [GET `shortcuts/route/nontokenized`](/api-reference/defi-shortcuts/routing-to-a-non-tokenized-position) endpoint constructs an optimal conversion route. This API allows entering a non-tokenized DeFi position (e.g. Hyperliquid spot, Morpho etc.) from any ERC20 or native token. ## Authentication 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. ## API Parameters ### Required Parameters | Parameter | Type | Description | Example | | - | - | - | - | | `chainId` | number | Chain ID of the network to execute the transaction on | `999` | | `fromAddress` | string | The address making the request | `0xd8da6bf26964af9d7eed9e03e53415d37aa96045` | | `tokenIn` | string | Ethereum address of the token to swap from. For ETH, use `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` | `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` | | `positionOut` | string | Position ID or address of the position to receive | `0x30a0da8cabf25a31805d9f3eca9005540e419f408beecf5cf715c67f3958ee55` or `0x200000000000000000000000000000000000010C` | | `amountIn` | string | Amount of tokenIn to swap in wei | `100000000000000000000` | | `receiver` | string | Ethereum address of the receiver of the positionOut | `0xd8da6bf26964af9d7eed9e03e53415d37aa96045` | <Note> The `positionId` serves as a unique identifier for each position within the protocol. When a protocol represents positions using a bytes32 identifier in its smart contracts (for example, Morpho), this existing identifier is adopted as the `positionId`. In cases where no native bytes32 identifier exists, the system automatically generates a unique `positionId` for the position. `address` can also be used as `positionOut`, but it might represent multiple positions (like Morpho) and request will return an error. </Note> ### Optional Parameters | Parameter | Type | Description | Default | Example | | - | - | - | - | - | | `routingStrategy` | string | Routing strategy to use (`router`, `delegate`, `delegate-legacy`) | `"router"` | `"delegate"` | | `slippage` | string | Slippage in basis points (1/10000) | `"50"` (0.5%) | `"300"` (3%) | | `referralCode` | string | Referral code for on-chain event tracking | - | `"0123456789ABCDEF"` | | `destinationChainId` | number | Chain ID to bridge to and receive nontokenized position | - | `10` | | `spender` | string | Ethereum address of the spender of the tokenIn | - | `0xd8da6bf26964af9d7eed9e03e53415d37aa96045` | | `refundReceiver` | string | Ethereum address to receive any dust tokens produced during execution | - | `0xd8da6bf26964af9d7eed9e03e53415d37aa96045` | ## Response Schema The API returns a non-tokenized route with the following fields: | Field | Type | Description | | - | - | - | | `createdAt` | number | Block number the transaction was created on | | `gas` | string | Gas estimate for the transaction | | `amountDeposited` | string | Amount of value allocated to the position after the transaction completes | | `priceImpact` | number \| null | Price impact in basis points (1/10000). Returns null if calculation is unavailable | | `tx` | Transaction | The transaction object with `to`, `data`, and other fields | | `route` | Hop\[] | The route the shortcut will use | | `feeAmount` | string\[] | Array of fee amounts charged | | `ensoFeeAmount` | string\[] | Array of Enso platform fees charged | | `userOp` | UserOperation | The ERC-4337 user operation object (if applicable) | ## Discovering Non-Tokenized Positions To find available non-tokenized positions for routing, use the **GET `/api/v1/nontokenized`** endpoint to query the registry of supported non-tokenized positions. ### Query Parameters | Parameter | Type | Description | Example | | - | - | - | - | | `project` | string | The overarching project or platform | `"hypercore"` | | `protocolSlug` | string | The specific standard integration or version | `"hypercore-spot"` | | `chainId` | number | Chain ID of the network | `999` | | `address` | string\[] | Ethereum addresses of that represent the position | `["0x200000000000000000000000000000000000010C"]` | | `primaryAddress` | string\[] | Ethereum addresses for contract interaction | `["0x200000000000000000000000000000000000010C"]` | | `positionId` | string\[] | Identifier of the positions | `["0x30a0da8cabf25a31805d9f3eca9005540e419f408beecf5cf715c67f3958ee55"]` | | `page` | number | Pagination page number (1000 results per page) | `1` | | `cursor` | number | Cursor for pagination | `0` | ### Response Schema The API returns an array of non-tokenized positions with the following fields: | Field | Type | Description | | - | - | - | | `chainId` | number | Chain ID of the network of the position | | `protocol` | string | The specific standard integration or version | | `address` | string | Ethereum address of the non-tokenized position | | `primaryAddress` | string | Ethereum address for contract interaction | | `underlyingTokens` | TokenModel\[] | Underlying tokens of the position (may be null) | ### Example Usage ```bash theme={null} # Get all non-tokenized positions on HyperEVM chain curl -X GET \ "https://api.enso.build/api/v1/nontokenized?chainId=999" \ -H "Authorization: Bearer $ENSO_API_KEY" | jq # Get specific positions for Hypercore curl -X GET \ "https://api.enso.build/api/v1/nontokenized?protocolSlug=hypercore-spot" \ -H "Authorization: Bearer $ENSO_API_KEY" | jq # Get positions by specific address/id curl -X GET \ "https://api.enso.build/api/v1/nontokenized?address=0x200000000000000000000000000000000000010C" \ -H "Authorization: Bearer $ENSO_API_KEY" | jq # Get positions of Morpho on Ethereum curl -X GET \ "https://api.enso.build/api/v1/nontokenized?protocolSlug=morpho-markets-v1&chainId=1" \ -H "Authorization: Bearer $ENSO_API_KEY" | jq ``` <Note> For best routing results, it is strongly recommended to use the `positionId` as the `positionOut` parameter when requesting a route. The `address` parameter is supported as an alternative, but may resolve to multiple positions (such as with Morpho protocols), which will result in an error response. </Note> ## Example: Depositing into Hypercore Here's an example of how to route funds to deposit into a Hypercore position: **Example**: Depositing 100 HYPE into a Hypercore USDT * **Input**: 100 HYPE * **Output**: Hypercore USDT position * **Chain**: 999 (HyperEVM) <CodeGroup> ```bash cURL theme={null} curl -X GET \ 'https://api.enso.build/api/v1/shortcuts/route/nontokenized?chainId=999&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&positionOut=0x200000000000000000000000000000000000010C&amountIn=100000000000000000000&receiver=0xd8da6bf26964af9d7eed9e03e53415d37aa96045' \ -H "Authorization: Bearer $ENSO_API_KEY" | jq ``` </CodeGroup> Key parameters: * `chainId`: 999 (HyperEVM) * `tokenIn`: `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` (HYPE) * `positionOut`: `0x200000000000000000000000000000000000010C` (Hypercore USDT position) * `amountIn`: `100000000000000000000` (100 HYPE in wei) * `receiver`: The address that will receive the position ## Example: Depositing into cbBTC/USDC Morpho market Here's an example of how to route funds to deposit into a cbBTC/USDC Morpho market: **Example**: Depositing 1 ETH into a Morpho market * **Input**: 1 ETH * **Output**: cbBTC/USDC Morpho Market [0x30a0da8cabf25a31805d9f3eca9005540e419f408beecf5cf715c67f3958ee55](https://app.morpho.org/ethereum/market/0x64d65c9a2d91c36d56fbc42d69e979335320169b3df63bf92789e2c8883fcc64/cbbtc-usdc) * **Chain**: 1 (Ethereum) <CodeGroup> ```bash cURL theme={null} curl -X GET \ 'https://api.enso.build/api/v1/shortcuts/route/nontokenized?chainId=1&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&positionOut=0x64d65c9a2d91c36d56fbc42d69e979335320169b3df63bf92789e2c8883fcc64&amountIn=1000000000000000000&receiver=0xd8da6bf26964af9d7eed9e03e53415d37aa96045' \ -H "Authorization: Bearer $ENSO_API_KEY" | jq ``` </CodeGroup> Key parameters: * `chainId`: 1 (Ethereum) * `tokenIn`: `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` (ETH) * `positionOut`: `0x30a0da8cabf25a31805d9f3eca9005540e419f408beecf5cf715c67f3958ee55` (cbBTC/USDC Morpho Market ID) * `amountIn`: `1000000000000000000` (1 ETH in wei) * `receiver`: The address that will receive the position ## Example: Cross-Chain Bridge to Hypercore Here's an example of how to bridge funds from Ethereum to a Hypercore position: **Example**: Bridging 0.5 ETH from Ethereum to HYPE Hypercore position * **Input**: 0.5 ETH (Ethereum) * **Output**: HYPE Hypercore position * **Source Chain**: 1 (Ethereum) * **Destination Chain**: 999 (HyperEVM) <CodeGroup> ```bash cURL theme={null} curl -X GET \ 'https://api.enso.build/api/v1/shortcuts/route/nontokenized?chainId=1&destinationChainId=999&fromAddress=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&positionOut=0x2222222222222222222222222222222222222222&amountIn=500000000000000000&receiver=0xd8da6bf26964af9d7eed9e03e53415d37aa96045' \ -H "Authorization: Bearer $ENSO_API_KEY" | jq ``` </CodeGroup> Key parameters for cross-chain routing: * `chainId`: 1 (Ethereum - source chain) * `destinationChainId`: 999 (HyperEVM - destination chain) * `tokenIn`: `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` (ETH on Ethereum) * `positionOut`: `0x2222222222222222222222222222222222222222` (HYPE position on HyperEVM) * `amountIn`: `500000000000000000` (0.5 ETH in wei) * `referralCode`: `0123456789ABCDEF` (optional referral tracking) * `receiver`: The address that will receive the position on the destination chain ## Next steps * Explore the [Shortcuts Library](/pages/build/examples/shortcuts) for common DeFi workflows. * Check out the [API Reference](/api-reference/defi-shortcuts/routing-to-a-non-tokenized-position) for full parameter details <div> <p>Updated </p> </div> # Shortcuts Library Source: https://docs.enso.build/pages/build/examples/shortcuts Explore shortcuts for common DeFi workflows. The Enso Shortcuts system offers two powerful APIs for building DeFi workflows: * **Automated Routing**: The [POST `shortcuts/route`](/api-reference/defi-shortcuts/optimal-route-between-two-tokens) API calculates optimized multi-step paths for entering/exiting DeFi positions or swapping ERC20 tokens. It automatically creates a path between two positions specified in the request. * **Bundling DeFi Actions**: The [POST `shortcuts/bundle`](/api-reference/defi-shortcuts/bundle-a-list-of-actions) API lets you orchestrate DeFi workflows by composing multi-step sequences of [Actions](/pages/build/reference/actions) of your choosing. <Tip> **Would `route` do the job?** <br /> The `route` API might be the simpler way to route your assets. Before using the bundle API, check if `route` would work using [happypath](https://happypath.enso.build). </Tip> Both APIs return a transaction object with calldata representing your workflow, ready to be submitted to [`EnsoShortcutRouter`](https://etherscan.io/address/0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E#code) for execution. ## 1. Automated Routing The POST `route` API is suitable for single-path operations with automatic optimization. ### Token Swaps Optimize conversions between tokens by leveraging automated routing across DEXs. **Example**: Swapping 1 ETH to USDC with the best execution price and 0.5% slippage * **Input**: 1 ETH * **Slippage**: 0.5% * **Output**: USDC worth of 1 ETH <CodeGroup> ```ts Typescript SDK theme={null} import { parseUnits } from "ethers/lib/utils"; const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const ETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; // Define amount const amountInEth = parseUnits("1", 18); // 1 ETH const route = await ensoClient.getRouteData({ chainId, fromAddress, receiver: fromAddress, routingStrategy: "router", tokenIn: [ETH], tokenOut: [USDC], amountIn: [amountInEth], slippage: "50" // 0.5% }); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/route' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '{ "chainId": 1, "fromAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "routingStrategy": "router", "receiver": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "spender": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "tokenIn": ["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"], "tokenOut": ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"], "amountIn": ["1000000000000000000"], "slippage": "50" }' | jq ``` </CodeGroup> <div /> ### Multi-Token Deposits Deposit multiple tokens simultaneously into a liquidity pool to receive LP tokens in a single transaction. **Example**: Depositig 10 DAI + 10 USDC + 10 USDT to 3Crv LP tokens (Curve 3pool) in one step * **Input**: 10 DAI, 10 USDC, 10 USDT * **Slippage**: 0.5% * **Output**: 3Crv LP tokens <CodeGroup> ```ts SDK theme={null} const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; const receiver = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"; // Token Addresses const DAI = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; const USDT = "0xdAC17F958D2ee523a2206206994597C13D831ec7"; const curve3poolLp = "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"; // Define amounts const amountInDAI = parseUnits("10", 18); const amountInUSDC = parseUnits("10", 6); const amountInUSDT = parseUnits("10", 6); const route = await ensoClient.getRouteData({ chainId, fromAddress, receiver, routingStrategy: "delegate", tokenIn: [DAI, USDC, USDT], tokenOut: [curve3poolLp], amountIn: [ amountInDAI, amountInUSDC, amountInUSDT, ], slippage: "50" // 0.5% }); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/route' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '{ "chainId": 1, "fromAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "routingStrategy": "delegate", "receiver": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "tokenIn": [ "0x6B175474E89094C44Da98b954EedeAC495271d0F", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "0xdAC17F958D2ee523a2206206994597C13D831ec7" ], "tokenOut": ["0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"], "amountIn": [ "10000000000000000000", "10000000", "10000000" ], "slippage": "50" }' | jq ``` </CodeGroup> ### LST Staking Entry Transform base tokens directly into staked liquid staking positions with a single call. **Example**: Converting 1 ETH to stETH (Lido Staked ETH) in one step * **Input**: 1 ETH * **Slippage**: 0.5% * **Output**: stETH <CodeGroup> ```typescript SDK theme={null} import { parseUnits } from "ethers/lib/utils"; const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const ETH = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"; const stETH = "0xae7ab96520de3a18e5e111b5eaab095312d7fe84"; // Define amount const amountIn = parseUnits("1", 18); // 1 ETH const route = await ensoClient.getRouteData({ chainId, fromAddress, receiver: fromAddress, routingStrategy: "router", tokenIn: [ETH], tokenOut: [stETH], amountIn: [amountIn], slippage: "50" // 0.5% }); ``` ```bash theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/route' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '{ "chainId": 1, "fromAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "routingStrategy": "router", "receiver": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "spender": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "tokenIn": ["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"], "tokenOut": ["0xae7ab96520de3a18e5e111b5eaab095312d7fe84"], "amountIn": ["1000000000000000000"], "slippage": "50" }' | jq ``` </CodeGroup> <div /> ### Yield Position Entry Enter yield-generating positions from base assets. **Example**: Moving from 1 WETH to a Yearn vault (yvWETH) * **Input**: 1 WETH Output: yvWETH (exact amount depends on the vault's share price) * **Slippage**: 0.5% <CodeGroup> ```ts SDK theme={null} const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; const yvWETH = "0xa258c4606ca8206d8aa700ce2143d7db854d168c"; // Define amount const amountIn = parseUnits("1", 18); // 1 WETH const route = await ensoClient.getRouteData({ chainId, fromAddress, receiver: fromAddress, routingStrategy: "router", tokenIn: [WETH], tokenOut: [yvWETH], amountIn: [amountIn], slippage: "50" // 0.5% }); ``` ```bash theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/route' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '{ "chainId": 1, "fromAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "routingStrategy": "router", "receiver": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "spender": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "tokenIn": ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"], "tokenOut": ["0xa258c4606ca8206d8aa700ce2143d7db854d168c"], "amountIn": ["1000000000000000000"], "slippage": "50" }' | jq ``` </CodeGroup> <div /> ### Position Exit (Single Token) Exit completely from a DeFi position back to a single base token. **Example**: Converting 1 yvWETH (Yearn ETH vault) back to WETH * **Input**: 1 yvWETH * **Output**: WETH (actual amount depends on accrued yield) * **Slippage**: 0.5% <CodeGroup> ```typescript SDK theme={null} import { parseUnits } from "ethers/lib/utils"; const chainId = 1; // Ethereum const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"; // Token Addresses const yvWETH = "0xa258c4606ca8206d8aa700ce2143d7db854d168c"; const WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; // Define amount const amountIn = parseUnits("1", 18); // 1 yvWETH const route = await ensoClient.getRouteData({ chainId, fromAddress, receiver: fromAddress, routingStrategy: "router", tokenIn: [yvWETH], tokenOut: [WETH], amountIn: [amountIn], slippage: "50" // 0.5% }); ``` ```bash cURL theme={null} curl -X POST \ 'https://api.enso.build/api/v1/shortcuts/route' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $ENSO_API_KEY" \ -d '{ "chainId": 1, "fromAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "routingStrategy": "router", "receiver": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "spender": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045", "tokenIn": ["0xa258c4606ca8206d8aa700ce2143d7db854d168c"], "tokenOut": ["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"], "amountIn": ["1000000000000000000"], "slippage": "50" }' ``` </CodeGroup> <div /> ### LP Position Entry Enter into LP token positions with automatic routing and slippage protection. **Example**: Going from 1 ETH to ETH/USDC Uniswap LP tokens * **Output**:
프로젝트로 돌아가기