-
Notifications
You must be signed in to change notification settings - Fork 0
[API-4314] Velodrome swap adapter #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
|
|
||
| function _tickSpacing(PoolType poolType, address pool) internal view returns (int24) { | ||
| if (poolType == PoolType.V2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2 pool types are just concentrated liquidity pools with fixed tick spacing? also are these tick spacing numbers likely to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No V2 pools are like standard xyk pools, they don't even have tick spacing it's just a constant used, there's a comment explaining a few lines down
| function _swapV2Pool(address pool, address tokenIn, uint256 amountIn, uint256 amountOut) internal { | ||
| IERC20(tokenIn).safeTransfer(pool, amountIn); | ||
|
|
||
| bool zeroForOne = IPool(pool).token0() == tokenIn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this checking how the pool orders the tokens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pools just have a token0 and token1, when swapping on a V2 pool you have to specify an amount0Out and amount1Out so you need to figure out whether you are receiving token0 or token1
|
|
||
| bool zeroForOne = IPool(pool).token0() == tokenIn; | ||
|
|
||
| IPool(pool).swap(zeroForOne ? 0 : amountOut, zeroForOne ? amountOut : 0, address(this), ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume the second to last argument is the recipient of the swap, which will be swaprouter since this is invoked via delegate call?
what is the last argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. And the last argument is a data parameter that gets passed to a swap callback. This is typically used in flash loans, so not relevant to us
| revert("getAmountIn not supported for Velodrome"); | ||
| } | ||
|
|
||
| function _swapV2Pool(address pool, address tokenIn, uint256 amountIn, uint256 amountOut) internal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so high level -- this transfers the swap input to the velodrome pool contract and then the pool contract is called to execute the swap with the token balance it now has?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
| recipient: address(this), | ||
| deadline: block.timestamp, | ||
| amountIn: amountIn, | ||
| amountOutMinimum: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we not need to specify some real amount in accordance to the slippage preference of the end user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The slippage is checked at the end of all swaps in the entry point
Implements the
VelodromeAdapterfor swapping on Velodrome (and Aerodrome) pools.There are 3 types of pools supported by Velodrome:
Volatile,Stable, andConcentrated Liquidity.VolatileandStableuse the same interface, howeverConcentrated Liquiditydoes not.Quotes:
The Quoter contract supports all pool types
Swapping:
For swapping all Concentrated Liquidity swaps go through their SwapRouter contract, while Volatile and Stable swaps are executed directly on the pools.
Things to note
Don't require
getAmountOutandgetAmountInto beviewmethodsThe Velodrome Quoter contract works by actually executing a swap and then gracefully reverting while still returning the output amount. It is intended to be called by using the
CallContractRPC method to execute a contract call without submitting a transaction.Note: Multicall contracts work similarly
Because of this, the
IAdapterinterface had to be updated to not expectgetAmountOutandgetAmountInto also beviewmethods.The API will need to be updated to execute the queries this way.
No
getAmountInsupportThe Velodrome Quoter also does not support exact out quotes. There are CosmWasm dexes with the same problem and for those we just revert when calling
GetExactOut, so the same behavior is used here.