In order to call
flash, we will need the flash parameters for the initial call, as well as any parameters we want to pass through to the callback.
FlashParams struct will contain the token addresses and amounts we wish to pull out of the pool, as well as the three fee tiers used to determine which pool we are withdrawing from, and which we will be swapping with.
FlashCallbackData struct will contain the data we want to send to the callback. This includes
poolKey, which expresses the sorted tokens with the matched fee tier, returned by the PoolAddress library.
Now we'll start our function by assigning the relevant parameters from the
Flashparams (which we have declared in memory as
params) to our variable
Next we will declare
pool as type [IUniswapV3Pool], which allows us to call
flash on our desired pool contract.
Finally, we call
flash on our previously declared
pool. In the last parameter, we abi.encode the
FlashCallbackData, which will be decoded in the callback and used to inform the next steps of the transaction.
The full function: