-
Notifications
You must be signed in to change notification settings - Fork 3
Description
File(s) affected: UniswapV3SwapConnectors.cdc
Description: Currently, the Uniswap v3 Swapper connector only facilitates swaps using swapExactInput , such that the user
defines the desired input and receives some unknown amount of output tokens. Uniswap v3 exposes another approach to swaps,
such that the user defines the desired output amount. There may be some integrations that rely on this behavior, for example paying
fees denoted in another asset. Currently, the only way to achieve this is to swap enough input tokens to exceed the desired output,
and then swapBack() the leftover amount, incurring additional fees.
Recommendation: Introduce an additional parameter that determines the desired limit, such as bool exactIn . Route the swap to
use swapExactInput or swapExactOutput depending on this flag, and take the intended limit from the quote.inAmount or
quote.outAmount . The other quoted amount then serves as slippage protection. Below is one possible approach:
access(all) fun swap(exactInput: bool, quote: {DeFiActions.Quote}?, inVault:
@{FungibleToken.Vault}): @{FungibleToken.Vault} {
// create quote if not provided
if exactInput {
quote ? quote! : self.quoteOut(forProvided: inVault.balance, reverse: false)
return <- self._swapExactIn(
exactVaultIn: <- inVault.withdraw(amount: quote.inAmount),
amountOutMin: quote.outAmount,
reverse: false
)
} else {
quote ?? panic("quote must be provided for exact output swaps")}}
return <- self._swapExactOut(
VaultIn: <- inVault,
amountOutExact: quote!.outAmount,
maxAmountIn: quote!.inAmount,
reverse: false
)
}
}