Skip to content

Commit

Permalink
Add routingStrategy examples to docs (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbenwolf authored Feb 13, 2024
1 parent 0d0f455 commit 9fda672
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pages/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"index": "Welcome",
"introduction": "Introduction",
"examples": "Examples",
"routingStrategy-examples": "routingStrategy examples",
"router-api": "Router API",
"bundler-api": "Bundler API",
"metadata-api": "Metadata API",
Expand Down
4 changes: 0 additions & 4 deletions pages/examples/_meta.json

This file was deleted.

42 changes: 24 additions & 18 deletions pages/router-api/api-reference/route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,32 @@ https://api.enso.finance/api/v1/shortcuts/route?chainId=1&fromAddress=0xd8da6bf2

```json
{
"createdAt": 17685529,
"route": [
{
"action": "deposit",
"primary": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
"protocol": "lido",
"tokenIn": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"tokenOut": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
"positionInId": "1:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"positionOutId": "1:0xae7ab96520de3a18e5e111b5eaab095312d7fe84:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
}
],
"priceImpact": 0,
"gas": 380972,
"amountOut": "999999999999999999",
"gas": "399170",
"amountOut": "1000071289649193663",
"createdAt": 18684432,
"tx": {
"data": "0xffa2ca3bd8db9899f8ab9c791038422daf4d50db28b4905b8781b8b39dd3c08cfe0bec1d000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000000a70a082310100ffffffffff05ae7ab96520de3a18e5e111b5eaab095312d7fe8470a082310100ffffffffff06ae7ab96520de3a18e5e111b5eaab095312d7fe84a1903eab030102ffffffffffae7ab96520de3a18e5e111b5eaab095312d7fe8470a082310100ffffffffff02ae7ab96520de3a18e5e111b5eaab095312d7fe84b67d77c5010206ffffffff02ca99eaa38e8f37a168214a3a57c9a45a58563ed56e7a43a3010203ffffffff027e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120102ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b70a082310100ffffffffff00ae7ab96520de3a18e5e111b5eaab095312d7fe84b67d77c5010005ffffffff00742f2c5d96c0858d00860039c22d2805bed420e8a9059cbb010400ffffffffffae7ab96520de3a18e5e111b5eaab095312d7fe84000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000002000000000000000000000000089ba58cc0e8bcbc1108dbd6f33356a136a021c6200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000d7621dc5820ffff0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"to": "0x7fEA6786D291A87fC4C98aFCCc5A5d3cFC36bc7b",
"data": "0xb35d7e73000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000619198595a30081ffffffff81def1c0ded9bec7f1a1670819833240f027b25eff9bd3b227018102ffffffff016675a323dedb77822fcf39eaa9d682f6abe72555ddcd52200101ffffffffff017e7d64d987cab6eed08a191c4c2459daf2f8ed0ba9059cbb010301ffffffffffae7ab96520de3a18e5e111b5eaab095312d7fe846e7a43a3010104ffffffff017e7d64d987cab6eed08a191c4c2459daf2f8ed0b241c59120101ffffffffffff7e7d64d987cab6eed08a191c4c2459daf2f8ed0b000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000007e00000000000000000000000000000000000000000000000000000000000000820000000000000000000000000000000000000000000000000000000000000086000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000006c8415565b0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe840000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000d7660c0ce84cddf00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000480000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000040000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002e000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002e00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000001437572766500000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000d7660c0ce84cddf00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000080000000000000000000000000dc24316b9ae028f1497c275eb9192a3ea0f670223df021240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd00000000000000000000000010000000000000000000000000000000000000110000000000000000000000000000000022614e7e3e5a0b1418f1ed151abed9ab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000d7660c0ce84cddd",
"to": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"value": "1000000000000000000"
}
},
"route": [
{
"action": "apiswap",
"protocol": "enso",
"tokenIn": [
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
],
"tokenOut": [
"0xae7ab96520de3a18e5e111b5eaab095312d7fe84"
],
"positionInId": [
"1:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
],
"positionOutId": [
"1:0xae7ab96520de3a18e5e111b5eaab095312d7fe84:0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
]
}
]
}
```
18 changes: 9 additions & 9 deletions pages/router-api/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ Will return a response like this:

```json
{
"createdAt": 17692827,

"gas": 625417,
"amountOut": "1949890251706461962125",
"gas": "243255",
"amountOut": "922135437013688654",
"createdAt": 18684443,
"tx": {
"to": "0x7fEA6786D291A87fC4C98aFCCc5A5d3cFC36bc7b",
"data": "0xb35d7e73...",
"to": "0x80EbA3855878739F4710233A8a19d89Bdd2ffB8E",
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"value": "1000000000000000000",
"data": "0xffa2ca3b273...."
...
}}
"value": "1000000000000000000"
},
"route": [...]
}

```

Expand Down
5 changes: 5 additions & 0 deletions pages/routingStrategy-examples/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"router": "routingStrategy=router (recommended)",
"ensowallet": "routingStrategy=ensowallet",
"delegate": "routingStrategy=delegate"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ We are using the [Route endpoint](../../router-api/api-reference/overview) as th

```bash copy
curl -X 'GET' \
'https://api.enso.finance/api/v1/shortcuts/route?chainId=1&fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&receiver=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&spender=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&amountIn=1000000000000000000&slippage=300&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&tokenOut=0xe0d5f9da3613c047003b77caa31270abe3eda6b0&routingStrategy=router' \
'https://api.enso.finance/api/v1/shortcuts/route?chainId=1&fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&receiver=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&spender=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&amountIn=1000000000000000000&slippage=300&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&tokenOut=0xe0d5f9da3613c047003b77caa31270abe3eda6b0' \
-H 'accept: application/json'
```

Expand Down
44 changes: 44 additions & 0 deletions pages/routingStrategy-examples/router.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Callout } from "nextra/components";

# Enter a single position from 1 token

In this example, we will have a user or smart contract that has [1 WETH](https://etherscan.io/token/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2) in their Ethereum mainnet wallet, and wants to deposit 1 WETH into [Beefy Aura wstETH-ETH](https://etherscan.io/address/0xe0d5f9da3613c047003b77caa31270abe3eda6b0)

<Callout type="info" emoji="💡">
Beefy Aura wstETH-ETH token is multihopping over 4 DeFi protocols
</Callout>

## Step 1: Approve

The caller must approve the WETH first on the [router](../../concepts/routingOptions#router) so it can execute the bundle of transactions.

### Approve: Approve Transaction

Enso:

```bash copy
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=1000000000000000000000000000&routingStrategy=router"
```

Ethers:

```javascript
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 endpoint](../../router-api/api-reference/overview) as this it compares the best execution route for token amount out, and gas execution price. For example, it might be better to purchase stEth on a DEX than directly depositing it depending upon the exchange rate of that token on the secondary market.

```bash copy
curl -X 'GET' \
'https://api.enso.finance/api/v1/shortcuts/route?chainId=1&fromAddress=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&receiver=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&spender=0x57757E3D981446D585Af0D9Ae4d7DF6D64647806&amountIn=1000000000000000000&slippage=300&tokenIn=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&tokenOut=0xe0d5f9da3613c047003b77caa31270abe3eda6b0&routingStrategy=router' \
-H 'accept: application/json'
```

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

0 comments on commit 9fda672

Please sign in to comment.