---
# System prepended metadata

title: Analysis on minimizing the routes on VaporDEX

---

# Analysis on minimizing the routes on VaporDEX

There was some complain from users about swap displaying routes with large hops. We investigated the issue and the below analysis is based on conclusion by us. Also, we will list further steps that can be taken for improvement. We have investigated [0x77bc0b4080435fb68f786383561fcdf35624c15601c91a898c48c8918f0c2625](https://snowtrace.io/tx/0x77bc0b4080435fb68f786383561fcdf35624c15601c91a898c48c8918f0c2625) transaction and our research is based on it.

# Some Useful links

Sender of transaction: `0x97bb19836e60E7DF1262b9D131074C64a1299EAc`
Address of USDC.e : `0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664`
Vapor Router address: `0xDef9ee39FD82ee57a1b789Bc877E2Cbd88fd5caE`
Yield-yak router address: `0xC4729E56b831d74bBc18797e0e17A295fA77488c` (Note: Vapor aggregator is heavily inspired from yield-yak)
Wrapped Avax address: `0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7`
DAI.e address: `0xd586E7F844cEa2F87f50152665BCbc2C279D8d70`
USDT.e address: `0xc7198437980c041c805A1EDcbA50c1Ce5db95118`
Platypus finance adapter: `0x0c2B27d3c27fAc1612da22346dC2FDA8A3402FCC`
TraderJOE adapter: `0x8250D72009Ac305cd17779E743CDDb171015109b`
Pangolin adapter: `0xf14FaBE507c9Cc6d1b632ec2033072484409fC48`

# Analysis
This analysis is done on forked mainnet of AVAX blockchain forked at block number`25376447`. The fork is made at the block number which is previous of the analysed transaction mined. Below is sample code snippet which was used for analysis:

```
function test_execution() public {
        //tx: https://snowtrace.io/tx/0x77bc0b4080435fb68f786383561fcdf35624c15601c91a898c48c8918f0c2625
        address[] memory paths = new address[](4);
        paths[0] = 0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664;
        paths[2] = 0xc7198437980c041c805A1EDcbA50c1Ce5db95118;
        paths[3] = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7; // wavax token
        paths[1] = 0xd586E7F844cEa2F87f50152665BCbc2C279D8d70; //dai token

        address[] memory adapters = new address[](3);
        adapters[0] = 0x0c2B27d3c27fAc1612da22346dC2FDA8A3402FCC; //platypus finance
        adapters[1] = 0x8250D72009Ac305cd17779E743CDDb171015109b; //traderJoe adapter
        adapters[2] = 0xf14FaBE507c9Cc6d1b632ec2033072484409fC48; //pangolin adapter
        Router.Trade memory trade = Router.Trade(
            16618624,
            986313643051843351,
            paths,
            adapters
        );
        address recipient = vm.addr(1);

        vm.startPrank(sender);
        usdc.approve(address(router), 1e18);
        router.swapNoSplitToAVAX(trade, recipient, 99000);

        console2.log(recipient.balance); //995290860566607986
    }
```

The above execution is done using the path and adapters suggested by Vapor router. There are 3 adapters and 4 path. I analysed by reducing adapters and path. If the reduced path results in more recipient balance, it would prove that some hops in route is redundant but it's not the case.

* With the use of just first adapter, the transaction will fail because `Platypus finance` doesn't have pool of     `USDC.e` and `WAVAX`.
* With the use of first two adapter, we would have got `993052785644375769` AVAX which is less than the user originally got.
* With use of the three adapters, we got `995290860566607986` AVAX.

So, from this, we came to conclusion that routes shown are for the benefit of user and trying to give them best possible value.

# Notes for the team(internal discussion)

* When the analysis is done using `yield-yak` router, it also shows the same path. This proves that there is not any mismatch in the algorithm that we are using.
* When the `maxSteps` are specified as `4`, our router as well as yieldYak router sometimes reverts the transaction with Out of Gas exception. Example shared in `Devs Chat` channel.
* Changing gas value on `findBestPathWithGas` doesn't give any alternate path. I feel that it is redundant. 
* We are [hardcoding](https://github.com/VaporFi/vaporverse/blob/staging/apps/vapordex/src/config/constants/aggregator.ts#L2) Gas price as 225 which is not suitable. We may need to change it based on the current demand. For ex: at the time of writing, Gas price is in range of (20-28) instead of 225.
* When we try to swap with yield-yak router, it reverts with unsafe math error. If time permits, I will deep dive into it but that's not the main priority.


