Uniswap v3 route
Vaibhav20201 opened this issue · comments
Need to add uniswap v3 flash support to the FLA. Chains to add on:-
- Polygon
- Arbitrum
- Optimism (Need to make a new folder for this)
Checkout the docs here.
In order to take flashloan using a uniswap v3 pool, we need the call the flash function of the pool. So, we will be needing the pool address. We kept this extra param for future use, which we will be using for this integration. We will be encoding the pool key in this param while calling the uniswap route from the frontend. On the contracts side, we need the decode and get the pool key. Pool key is a struct which contains token0 address, token1 address and fee tier of the pool.
In the route handler we will check that the length of the _tokens
param should be 1 or 2.
- If its 1,
_tokens[0]
should be either equal totoken0
ortoken1
from the pool key. - If its 2,
_tokens[0]
and_tokens[1]
should be equal totoken0
andtoken1
respectively
Now, we have to calculate the pool address from the pool key in the route handler (using the uniswap v3 lib, or we can simply define our own function for it) and call the flash function of the pool, by passing the respective amounts.
In the callback, we will get the amounts, send the to the user, expect them to be returned with fee, and return it to the pool.
Hey @Vaibhav20201! Rather than calculating the address on-chain, I think we should send it directly from the UI. We should calculate the pool key on the resolver side.
I was thinking on what was more gas efficient among the below two:-
-
If we pass the pool address, we will have to call the nft manager for token0 address, token1 address and fee, as we need them to verify things, also, we need to verify if the address we got is of a uniswap's pool for security.
-
If we pass the pool key we will have to calulate the pool address from it.