swap.gno
Swap
func Swap(
cur realm,
token0Path string,
token1Path string,
fee uint32,
recipient address,
zeroForOne bool,
amountSpecified string,
sqrtPriceLimitX96 string,
payer address,
swapCallback func(realm, int64, int64, *CallbackMarker) error
) (string, string)Swap swaps tokens from a pool from token0 to token1, or vice versa. This function can only be called by the Router contract, not by users.
Parameters
cur
realm
Pass cross as argument.
token0Path
string
The path of token0 of the desired pool.
token1Path
string
The path of token1 of the desired pool.
fee
uint32
The fee tier of the desired pool.
recipient
address
The address that will receive the output of the swap.
zeroForOne
bool
The direction of the swap. Set to true for swapping token0 to token1, and false for vice versa.
amountSpecified
string
The amount of tokens to swap. Set to a positive value for an exact input, and a negative value for an exact output.
sqrtPriceLimitX96
string
The maximum price to accept for the swap.
payer
address
The address from which to send the output tokens. (Relates to the Router contract)
swapCallback
func(realm, int64, int64, *CallbackMarker) error
The callback function for token transfer.
Return Values
amount0
string
The change in the amount of token0 as the result of the swap.
amount1
string
The change in the amount of token1 as the result of the swap.
DrySwap
DrySwap simulates a swap without executing it, returning the expected output.
Parameters
token0Path
string
path of the first token
token1Path
string
path of the second token
fee
uint32
pool fee tier
zeroForOne
bool
true if swapping token0 for token1
amountSpecified
string
amount to swap
sqrtPriceLimitX96
string
price limit for the swap
Return Values
amount0Delta
string
amount of token0 delta
amount1Delta
string
amount of token1 delta
ok
bool
swap success status
SetSwapEndHook
SetSwapEndHook sets the hook to be called at the end of a swap.
Parameters
cur
realm
Pass cross as argument.
hook
func(realm, string) error
callback invoked after a swap completes for a pool path
SetSwapStartHook
SetSwapStartHook sets the hook to be called at the start of a swap.
Parameters
cur
realm
Pass cross as argument.
hook
func(realm, string, int64)
callback invoked before a swap starts for a pool path
SetTickCrossHook
SetTickCrossHook sets the hook to be called when a tick is crossed during a swap.
Parameters
cur
realm
Pass cross as argument.
hook
func(realm, string, int32, bool, int64)
callback invoked when a swap crosses a tick within a pool
Last updated