Routing Strategy Examples
enso wallet
Enter multiple positions from 1 token

Enter multiple positions from 1 token

In this example, we will have a user that has 3 WETH (opens in a new tab) in their Ethereum mainnet wallet, and wants to:

💡

Each of these action counts multiple hops

Step 1: Approve

The user must approve the WETH first on the contract so that the contract can execute the bundle of transactions.

Approve: Fetch address

Each user has their own respective routing contract which will be deployed, and executed in the same transaction when the execution transaction is submitted. This reduces the risks of approvals with a single-point of failure contract, and the user that is submitting the transaction is the owner of that contract not Enso, further reducing the risk.

curl -X 'GET' \
  -H "Content-Type: application/json" \
  'https://api.enso.finance/api/v1/wallet?chainId=1 \
  &fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806' \
 
chainid: "Chain ID to execute the approval on", // 1 = Ethereum Mainnet, [full networks](../networks)
fromAddress: "EOA address that is executing the approval", // 0x57757E3D981446D585Af0D9Ae4d7DF6D64647806

You will be returned with:

{
  "address": "0xD6A4217CF6A3587B4E33e9a59C52BF57469e713a", // Individual contract owned by the EOA
  "isDeployed": false
}

If the user has already used Enso through another integrator, then isDeployed will be true.

Approve: Approve Transaction

Enso:

curl -X 'GET' \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 1e02632d-6feb-4a75-a157-documentation" \
  'https://api.enso.finance/api/v1/wallet/approve?chainId=1& \
  fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806& \
  tokenAddress=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2& \
  amount=3000000000000000000000000000' \

Ethers:

await ERC20(0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2).approve(address, 5 Ether) // take decimals of the token you're approving into account

Step 2: Execute

Execute: Build actions

We are using the Route action inside of the Bundle endpoint as this action compares the best execution route for token amount out, and gas execution price. For example, it might be better to purchase yvWETH on a secondary exchange than directly depositing it depending upon the exchange rate of that token on the secondary market.

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 1e02632d-6feb-4a75-a157-documentation" \
  --data '[
  {
    "protocol": "enso",
    "action": "route",
    "args": {
      "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "tokenOut": "0xa258C4606Ca8206D8aA700cE2143D7db854D168c",
      "amountIn": "1000000000000000000"
    }
  },
  {
    "protocol": "enso",
    "action": "route",
    "args": {
      "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "tokenOut": "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56",
      "amountIn": "1000000000000000000"
    }
  },
  {
    "protocol": "enso",
    "action": "route",
    "args": {
      "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
      "tokenOut": "0xe0d5f9da3613c047003b77caa31270abe3eda6b0",
      "amountIn": "1000000000000000000"
    }
  }
]' \
  "https://api.enso.finance/api/v1/shortcuts/bundle?chainId=1&fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806"
 

You will be returned:

{
  "chainId": 1,
  "createdAt": 17707569,
  "bundle": [
    {
      "protocol": "enso",
      "action": "route",
      "args": {
        "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        "tokenOut": "0xa258C4606Ca8206D8aA700cE2143D7db854D168c",
        "amountIn": "1000000000000000000"
      }
    },
    {
      "protocol": "enso",
      "action": "route",
      "args": {
        "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        "tokenOut": "0xe0d5f9da3613c047003b77caa31270abe3eda6b0",
        "amountIn": "1000000000000000000"
      }
    },
    {
      "protocol": "enso",
      "action": "route",
      "args": {
        "tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
        "tokenOut": "0x6b175474e89094c44da98b954eedeac495271d0f",
        "amountIn": "1000000000000000000"
      }
    }
  ],
  "tx": {
    "data": "0xffa2ca3b2475e18fa8e2b6e9278146d2d1dfee8bf7e3cf6fb96a890fb6142c45f762b0b6000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000001a70a082310100ffffffffff0da258c4606ca8206d8aa700ce2143d7db854d168c095ea7b3010102ffffffffffc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2b6b55f250102ffffffffffffa258c4606ca8206d8aa700ce2143d7db854d168c70a082310100ffffffffff01a258c4606ca8206d8aa700ce2143d7db854d168cb67d77c501010dffffffff01ca99eaa38e8f37a168214a3a57c9a45a58563ed56e7a43a3010103ffffffff017e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120101ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b70a082310100ffffffffff0132296969ef14eb0c6d29669c550d4a0449130230095ea7b3010402ffffffffffc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2b95cac280105000086ffffffba12222222228d8ba445958a75a0704d566bf2c870a082310100ffffffffff0632296969ef14eb0c6d29669c550d4a0449130230b67d77c5010601ffffffff06ca99eaa38e8f37a168214a3a57c9a45a58563ed570a082310100ffffffffff01e0d5f9da3613c047003b77caa31270abe3eda6b0095ea7b3010706ffffffffff32296969ef14eb0c6d29669c550d4a0449130230b6b55f250106ffffffffffffe0d5f9da3613c047003b77caa31270abe3eda6b070a082310100ffffffffff06e0d5f9da3613c047003b77caa31270abe3eda6b0b67d77c5010601ffffffff06ca99eaa38e8f37a168214a3a57c9a45a58563ed56e7a43a3010608ffffffff067e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120106ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b70a082310100ffffffffff066b175474e89094c44da98b954eedeac495271d0f095ea7b3010902ffffffffffc02aaa39b223fe8d0a0e5c4f27ead9083c756cc219198595a30a8bffffffffffdef1c0ded9bec7f1a1670819833240f027b25eff70a082310100ffffffffff006b175474e89094c44da98b954eedeac495271d0fb67d77c5010006ffffffff00ca99eaa38e8f37a168214a3a57c9a45a58563ed56e7a43a301000cffffffff007e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120100ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000005c0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000680000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000008400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d6a4217cf6a3587b4e33e9a59c52bf57469e713a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a258c4606ca8206d8aa700ce2143d7db854d168c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000cedeb17c8c74fb20000000000000000000000000000000000000000000000000000000000000020000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8000000000000000000000000000000000000000000000000000000000000002032296969ef14eb0c6d29669c550d4a04491302300002000000000000000000800000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000cfcb97e8345b255000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000e0d5f9da3613c047003b77caa31270abe3eda6b000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000c8b0c6894a5241a0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001486af479b200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000065def525246d440ba000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000646b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000000000869584cd00000000000000000000000010000000000000000000000000000000000000110000000000000000000000000000000000000000000000b29fe7fa7664b433e90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000065def54241c289beae0000000000000000000000000000000000000000000000000000000000000000",
    "to": "0x7fEA6786D291A87fC4C98aFCCc5A5d3cFC36bc7b",
    "from": "0x57757E3D981446D585Af0D9Ae4d7DF6D64647806",
    "value": "0",
    "chainId": 1
  }
}

The data value contains the bundle calldata to be submitted to the user.