Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate UniV3 automatic routing support #375

Open
1 task
Tracked by #382 ...
LukSteib opened this issue Jul 25, 2022 · 4 comments
Open
1 task
Tracked by #382 ...

Investigate UniV3 automatic routing support #375

LukSteib opened this issue Jul 25, 2022 · 4 comments
Assignees

Comments

@LukSteib
Copy link
Contributor

Goal

Make use of uni v3 automatic routing feature

Context

For a lot of the collateral types we are supporting the uniswap v3 callee. However the routes for the token swap are not determined automatically.
Since uniswap provides an automatic routing feature this issue is meant to investigate whether/how we are able to support it and get rid of hardcoding the routes.

Tasks

  • Investigate how we might support univ3 automatic routing feature

Assets

@valiafetisov
Copy link
Contributor

valiafetisov commented Sep 15, 2022

Quick test of the auto-router revealed that it sometimes can split transactions into parts, which is not supported by the uniswapV3 callees (they expect path to be a list of tokens addresses + fees). The workaround obviously to swap auction partially, but that would mean two transactions and would require additional complications (eg minimum leftover checks). Also, most of the time the route is a direct exchange.

Next steps:

  • Check if it is possible to constrain automatic routing to not split the amount
  • Add exchange prices (+ routes) of automatic routing to the dashboard to see if it makes the difference
The route proposed for ETH->DAI exchange with a 75/25 split
{
    "quote": {
        "numerator": [
            493212940,
            954817734,
            139168
        ],
        "denominator": [
            1
        ],
        "currency": {
            "chainId": 1,
            "decimals": 6,
            "symbol": "DAI",
            "name": "DAI",
            "isNative": false,
            "isToken": true,
            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
        },
        "decimalScale": [
            1000000
        ]
    },
    "quoteGasAdjusted": {
        "numerator": [
            486508844,
            365040236,
            852907799,
            346377111,
            376275412,
            1015694034,
            971107344,
            444290507,
            353639
        ],
        "denominator": [
            693144153,
            200424859,
            805762719,
            680605356,
            862652847,
            581091781,
            2
        ],
        "currency": {
            "chainId": 1,
            "decimals": 6,
            "symbol": "DAI",
            "name": "DAI",
            "isNative": false,
            "isToken": true,
            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
        },
        "decimalScale": [
            1000000
        ]
    },
    "estimatedGasUsed": {
        "type": "BigNumber",
        "hex": "0x04ab50"
    },
    "estimatedGasUsedQuoteToken": {
        "numerator": [
            0,
            0,
            0,
            0,
            0,
            0,
            651100160,
            350208749,
            14
        ],
        "denominator": [
            693144153,
            200424859,
            805762719,
            680605356,
            862652847,
            581091781,
            2
        ],
        "currency": {
            "chainId": 1,
            "decimals": 18,
            "symbol": "DAI",
            "name": "Dai Stablecoin",
            "isNative": false,
            "isToken": true,
            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
        },
        "decimalScale": [
            660865024,
            931322574
        ]
    },
    "estimatedGasUsedUSD": {
        "numerator": [
            357257216,
            698362921,
            5
        ],
        "denominator": [
            1
        ],
        "currency": {
            "chainId": 1,
            "decimals": 18,
            "symbol": "DAI",
            "name": "Dai Stablecoin",
            "isNative": false,
            "isToken": true,
            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
        },
        "decimalScale": [
            660865024,
            931322574
        ]
    },
    "gasPriceWei": {
        "type": "BigNumber",
        "hex": "0x031177a9f3"
    },
    "route": [
        {
            "protocol": "V3",
            "amount": {
                "numerator": [
                    95420416,
                    228744496,
                    6505
                ],
                "denominator": [
                    100
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "decimalScale": [
                    660865024,
                    931322574
                ]
            },
            "rawQuote": {
                "type": "BigNumber",
                "hex": "0x197ab81337c4b9b15d0c"
            },
            "sqrtPriceX96AfterList": [
                {
                    "type": "BigNumber",
                    "hex": "0x6181bfa29a4f2b35c6bac559395b"
                },
                {
                    "type": "BigNumber",
                    "hex": "0x10c6fecee72a430dd90a"
                }
            ],
            "initializedTicksCrossedList": [
                0,
                1
            ],
            "quoterGasEstimate": {
                "type": "BigNumber",
                "hex": "0x027078"
            },
            "quote": {
                "numerator": [
                    967925004,
                    541908754,
                    104363
                ],
                "denominator": [
                    1
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "percent": 75,
            "route": {
                "_midPrice": null,
                "pools": [
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        "fee": 500,
                        "sqrtRatioX96": [
                            64294299,
                            308023833,
                            250253231,
                            1597256
                        ],
                        "liquidity": [
                            1013935717,
                            1007273620,
                            10
                        ],
                        "tickCurrent": 202508,
                        "tickDataProvider": {}
                    },
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        "fee": 100,
                        "sqrtRatioX96": [
                            604253044,
                            991771229,
                            68719
                        ],
                        "liquidity": [
                            304660175,
                            522267547,
                            3825749
                        ],
                        "tickCurrent": -276324,
                        "tickDataProvider": {}
                    }
                ],
                "tokenPath": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "USDC",
                        "name": "USD//C",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ],
                "input": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "output": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "protocol": "V3"
            },
            "gasModel": {},
            "quoteToken": {
                "chainId": 1,
                "decimals": 6,
                "symbol": "DAI",
                "name": "DAI",
                "isNative": false,
                "isToken": true,
                "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
            },
            "tradeType": 0,
            "gasCostInToken": {
                "numerator": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    477331456,
                    38417365,
                    9
                ],
                "denominator": [
                    693144153,
                    200424859,
                    805762719,
                    680605356,
                    862652847,
                    581091781,
                    2
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "DAI",
                    "name": "Dai Stablecoin",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    660865024,
                    931322574
                ]
            },
            "gasCostInUSD": {
                "numerator": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    477331456,
                    38417365,
                    9
                ],
                "denominator": [
                    864343657,
                    561740939,
                    475101505,
                    1071116060,
                    1073741823,
                    817889279,
                    318059720,
                    2361
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "USDC",
                    "name": "USD//C",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "gasEstimate": {
                "type": "BigNumber",
                "hex": "0x02f1e8"
            },
            "quoteAdjustedForGas": {
                "numerator": [
                    714199340,
                    314486156,
                    1005540301,
                    355550150,
                    737833179,
                    719591663,
                    834232440,
                    882077263,
                    265197
                ],
                "denominator": [
                    693144153,
                    200424859,
                    805762719,
                    680605356,
                    862652847,
                    581091781,
                    2
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "poolAddresses": [
                "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640",
                "0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168"
            ],
            "tokenPath": [
                {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "USDC",
                    "name": "USD//C",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                },
                {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "DAI",
                    "name": "Dai Stablecoin",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                }
            ]
        },
        {
            "protocol": "V3",
            "amount": {
                "numerator": [
                    747634688,
                    434162106,
                    2168
                ],
                "denominator": [
                    100
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "decimalScale": [
                    660865024,
                    931322574
                ]
            },
            "rawQuote": {
                "type": "BigNumber",
                "hex": "0x087f56271f6ce3b47800"
            },
            "sqrtPriceX96AfterList": [
                {
                    "type": "BigNumber",
                    "hex": "0x0663e90b4b36c0d15e3e4d9b"
                }
            ],
            "initializedTicksCrossedList": [
                0
            ],
            "quoterGasEstimate": {
                "type": "BigNumber",
                "hex": "0x0114b1"
            },
            "quote": {
                "numerator": [
                    599029760,
                    412908979,
                    34805
                ],
                "denominator": [
                    1
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "percent": 25,
            "route": {
                "_midPrice": null,
                "pools": [
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        "fee": 500,
                        "sqrtRatioX96": [
                            759511334,
                            957269371,
                            640519041,
                            1
                        ],
                        "liquidity": [
                            628287100,
                            567841151,
                            1335228
                        ],
                        "tickCurrent": -73825,
                        "tickDataProvider": {}
                    }
                ],
                "tokenPath": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ],
                "input": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "output": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "protocol": "V3"
            },
            "gasModel": {},
            "quoteToken": {
                "chainId": 1,
                "decimals": 6,
                "symbol": "DAI",
                "name": "DAI",
                "isNative": false,
                "isToken": true,
                "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
            },
            "tradeType": 0,
            "gasCostInToken": {
                "numerator": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    173768704,
                    311791384,
                    5
                ],
                "denominator": [
                    693144153,
                    200424859,
                    805762719,
                    680605356,
                    862652847,
                    581091781,
                    2
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "DAI",
                    "name": "Dai Stablecoin",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    660865024,
                    931322574
                ]
            },
            "gasCostInUSD": {
                "numerator": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0,
                    173768704,
                    311791384,
                    5
                ],
                "denominator": [
                    864343657,
                    561740939,
                    475101505,
                    1071116060,
                    1073741823,
                    817889279,
                    318059720,
                    2361
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "USDC",
                    "name": "USD//C",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "gasEstimate": {
                "type": "BigNumber",
                "hex": "0x01b968"
            },
            "quoteAdjustedForGas": {
                "numerator": [
                    846051328,
                    50554079,
                    921109322,
                    1064568784,
                    712184056,
                    296102370,
                    136874904,
                    635955068,
                    88441
                ],
                "denominator": [
                    693144153,
                    200424859,
                    805762719,
                    680605356,
                    862652847,
                    581091781,
                    2
                ],
                "currency": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "decimalScale": [
                    1000000
                ]
            },
            "poolAddresses": [
                "0x60594a405d53811d3BC4766596EFD80fd545A270"
            ],
            "tokenPath": [
                {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "DAI",
                    "name": "Dai Stablecoin",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                }
            ]
        }
    ],
    "trade": {
        "swaps": [
            {
                "route": {
                    "_midPrice": null,
                    "pools": [
                        {
                            "token0": {
                                "chainId": 1,
                                "decimals": 6,
                                "symbol": "USDC",
                                "name": "USD//C",
                                "isNative": false,
                                "isToken": true,
                                "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                            },
                            "token1": {
                                "chainId": 1,
                                "decimals": 18,
                                "symbol": "WETH",
                                "name": "Wrapped Ether",
                                "isNative": false,
                                "isToken": true,
                                "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                            },
                            "fee": 500,
                            "sqrtRatioX96": [
                                64294299,
                                308023833,
                                250253231,
                                1597256
                            ],
                            "liquidity": [
                                1013935717,
                                1007273620,
                                10
                            ],
                            "tickCurrent": 202508,
                            "tickDataProvider": {}
                        },
                        {
                            "token0": {
                                "chainId": 1,
                                "decimals": 18,
                                "symbol": "DAI",
                                "name": "Dai Stablecoin",
                                "isNative": false,
                                "isToken": true,
                                "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                            },
                            "token1": {
                                "chainId": 1,
                                "decimals": 6,
                                "symbol": "USDC",
                                "name": "USD//C",
                                "isNative": false,
                                "isToken": true,
                                "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                            },
                            "fee": 100,
                            "sqrtRatioX96": [
                                604253044,
                                991771229,
                                68719
                            ],
                            "liquidity": [
                                304660175,
                                522267547,
                                3825749
                            ],
                            "tickCurrent": -276324,
                            "tickDataProvider": {}
                        }
                    ],
                    "tokenPath": [
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        }
                    ],
                    "input": {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    "output": {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "DAI",
                        "name": "DAI",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    },
                    "protocol": "V3",
                    "path": [
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        }
                    ]
                },
                "inputAmount": {
                    "numerator": [
                        95420416,
                        228744496,
                        6505
                    ],
                    "denominator": [
                        100
                    ],
                    "currency": {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    "decimalScale": [
                        660865024,
                        931322574
                    ]
                },
                "outputAmount": {
                    "numerator": [
                        967925004,
                        541908754,
                        104363
                    ],
                    "denominator": [
                        1
                    ],
                    "currency": {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "DAI",
                        "name": "DAI",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    },
                    "decimalScale": [
                        1000000
                    ]
                }
            },
            {
                "route": {
                    "_midPrice": null,
                    "pools": [
                        {
                            "token0": {
                                "chainId": 1,
                                "decimals": 18,
                                "symbol": "DAI",
                                "name": "Dai Stablecoin",
                                "isNative": false,
                                "isToken": true,
                                "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                            },
                            "token1": {
                                "chainId": 1,
                                "decimals": 18,
                                "symbol": "WETH",
                                "name": "Wrapped Ether",
                                "isNative": false,
                                "isToken": true,
                                "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                            },
                            "fee": 500,
                            "sqrtRatioX96": [
                                759511334,
                                957269371,
                                640519041,
                                1
                            ],
                            "liquidity": [
                                628287100,
                                567841151,
                                1335228
                            ],
                            "tickCurrent": -73825,
                            "tickDataProvider": {}
                        }
                    ],
                    "tokenPath": [
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        }
                    ],
                    "input": {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    "output": {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "DAI",
                        "name": "DAI",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    },
                    "protocol": "V3",
                    "path": [
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        }
                    ]
                },
                "inputAmount": {
                    "numerator": [
                        747634688,
                        434162106,
                        2168
                    ],
                    "denominator": [
                        100
                    ],
                    "currency": {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    "decimalScale": [
                        660865024,
                        931322574
                    ]
                },
                "outputAmount": {
                    "numerator": [
                        599029760,
                        412908979,
                        34805
                    ],
                    "denominator": [
                        1
                    ],
                    "currency": {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "DAI",
                        "name": "DAI",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    },
                    "decimalScale": [
                        1000000
                    ]
                }
            }
        ],
        "routes": [
            {
                "_midPrice": null,
                "pools": [
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        "fee": 500,
                        "sqrtRatioX96": [
                            64294299,
                            308023833,
                            250253231,
                            1597256
                        ],
                        "liquidity": [
                            1013935717,
                            1007273620,
                            10
                        ],
                        "tickCurrent": 202508,
                        "tickDataProvider": {}
                    },
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 6,
                            "symbol": "USDC",
                            "name": "USD//C",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                        },
                        "fee": 100,
                        "sqrtRatioX96": [
                            604253044,
                            991771229,
                            68719
                        ],
                        "liquidity": [
                            304660175,
                            522267547,
                            3825749
                        ],
                        "tickCurrent": -276324,
                        "tickDataProvider": {}
                    }
                ],
                "tokenPath": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "USDC",
                        "name": "USD//C",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ],
                "input": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "output": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "protocol": "V3",
                "path": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 6,
                        "symbol": "USDC",
                        "name": "USD//C",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ]
            },
            {
                "_midPrice": null,
                "pools": [
                    {
                        "token0": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "DAI",
                            "name": "Dai Stablecoin",
                            "isNative": false,
                            "isToken": true,
                            "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                        },
                        "token1": {
                            "chainId": 1,
                            "decimals": 18,
                            "symbol": "WETH",
                            "name": "Wrapped Ether",
                            "isNative": false,
                            "isToken": true,
                            "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                        },
                        "fee": 500,
                        "sqrtRatioX96": [
                            759511334,
                            957269371,
                            640519041,
                            1
                        ],
                        "liquidity": [
                            628287100,
                            567841151,
                            1335228
                        ],
                        "tickCurrent": -73825,
                        "tickDataProvider": {}
                    }
                ],
                "tokenPath": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ],
                "input": {
                    "chainId": 1,
                    "decimals": 18,
                    "symbol": "WETH",
                    "name": "Wrapped Ether",
                    "isNative": false,
                    "isToken": true,
                    "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                },
                "output": {
                    "chainId": 1,
                    "decimals": 6,
                    "symbol": "DAI",
                    "name": "DAI",
                    "isNative": false,
                    "isToken": true,
                    "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                },
                "protocol": "V3",
                "path": [
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "WETH",
                        "name": "Wrapped Ether",
                        "isNative": false,
                        "isToken": true,
                        "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
                    },
                    {
                        "chainId": 1,
                        "decimals": 18,
                        "symbol": "DAI",
                        "name": "Dai Stablecoin",
                        "isNative": false,
                        "isToken": true,
                        "address": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
                    }
                ]
            }
        ],
        "tradeType": 0
    },
    "methodParameters": {
        "calldata": "0x5ae401dc000000000000000000000000000000000000000000000000000000006322eed700000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000124b858183f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000000000000000000000003198b55d497293f733f2631755c766e11ce568f500000000000000000000000000000000000000000000000410d586a20a4c0000000000000000000000000000000000000000000000001729be9d1b6d05e70ec50000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20001f4a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000646b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000001f40000000000000000000000003198b55d497293f733f2631755c766e11ce568f50000000000000000000000000000000000000000000000015af1d78b58c400000000000000000000000000000000000000000000000007b9942390eea075845d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "value": "0x00"
    },
    "blockNumber": {
        "type": "BigNumber",
        "hex": "0xed176d"
    }
}
  • 75% WETH->USDC->DAI
  • 25% WETH->DAI

@valiafetisov
Copy link
Contributor

Ok, the number of splits can be controlled via maxSplits, see my commit here.

@LukSteib
Copy link
Contributor Author

Ok, the number of splits can be controlled via maxSplits, see my commit here.

What is the final outcome of this investigation? Is there a need for us to take action?

My current interpretation:

  • we can use the auto-router to determine the best possible swapping route (ie. moving away from having the hardcoded paths)
    • however we constrain the auto-router suggestion to not split routes
  • we can use the auto-router proposed swapping route (e.g. WETH-USDC-DAI) to pass as calldata to exchangeCallee

@valiafetisov
Copy link
Contributor

valiafetisov commented Sep 26, 2022

What is the final outcome of this investigation?

Your summary is correct. It seems that we will be able to both a) get the prices and also b) pass routing information to the callee. Proposed next step is to:

  • integrate a) into the dashboard to see if the prices or the routes differ (so it makes sense to integrate it)
  • create concept and the mock to show how to integrate this functionality
    • the question of how to work with multiply callees per collateral can be relative here (is it user-selectable?)
    • do we replace or make hardcoded routes selectable?
    • how do we display routes?
  • integrate a) and b) into the actual execution flow

Proposed concept is: automatic routing can be integrated as a "separate route" where we can have 1. Uniswap v3 hardcoded route; 2. Uniswap v3 automatic route with X slippage; 3. Uniswap v3 automatic route with Y slippage. Then, we fetch all prices and propose the most profitable in the UI, but a user can still select another one manually.

Note that "multiply callees per collateral" is a bigger feature that requires a refactoring (eg logic of the keeper will change), and can technically be done before or after "automatic routing". The only reason for the proposed order is the fallback mechanism that "multiply callees per collateral" provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants