-
Notifications
You must be signed in to change notification settings - Fork 68
Description
The current version of YakRouter swap queries all adapters for their amounts before swapping. This ensures the correct amounts are used for swaps and saves user gas if the final amount-out is below the minimum amount-out specified by the user.
The queries however can be quite gas-intensive, for example:
- Querying Gondola DAI-ZDAI pool through adapter costs 84340 gas
- Querying Snob S3 pool through the adapter to swap DAI for USDT costs 99130 gas
- Querying Unilike pool through the adapter to swap DAI to WAVAX costs 13612 gas
To avoid such high gas costs queries could be removed and the swap amount for the next step could be derived from the token balance in the adapter. ER20.balanceOf costs 23k, so the gas reduction would be substantial.
The big downside of this approach is that if price moved on the user to the point that the trade would fail. Now the trade would fail with relatively low gas cost after all the queries are completed, but with this approach, trade would fail in the last step costing the user substantially more gas.