Execute An Elastic Swap
Trade Directly Against An Elastic Pool
Obtaining pool addresses
It is necessary to specify which pools are to be used for the token swap. Read more about fetching pool addresses before proceeding.
Executing a swap
After getting a pool address from getPool(), you can call swap()
function to execute a swap.
swap()
swap()
Swap token0 -> token1, or vice versa. Note that swaps will either fully use up the specified swap quantity, or swap up to the specified price limit, depending on whichever condition is satisfied first.
Input
Field | Type | Explanation |
---|---|---|
|
| address to receive the swap output |
|
| swap quantity, which implicitly configures the swap as exact input (>0), or exact output (<0) |
|
| whether the swapQty is specified in token0 (true) or token1 (false) |
|
| sqrt price limit to reach |
|
| Data, if any, to be passed into the callback function |
Note
To specify an unlimited price limit for a swap, use the following values.
|
| Value |
| > 0 |
|
| < 0 |
|
| > 0 |
|
| < 0 |
|
Output
Field | Type | Explanation |
---|---|---|
|
| exact token0 qty sent to recipient if < 0. Minimally received quantity if > 0 |
|
| exact token1 qty sent to recipient if < 0. Minimally received quantity if > 0 |
Last updated