swap.gno
DrySwap
func DrySwap(
token0Path string,
token1Path string,
fee uint32,
zeroForOne bool,
amountSpecified string,
sqrtPriceLimitX96 string
) (string, string, error)DrySwap simulates a swap without executing it, returning the expected output.
This is a read-only operation that does not modify pool state. Used by router for multi-hop swap simulations and by clients for price quotes.
Parameters
token0Path
string
Path of the first token in the pool pair.
token1Path
string
Path of the second token in the pool pair.
fee
uint32
Fee tier identifying the pool.
zeroForOne
bool
True to sell token0 for token1; false to sell token1 for token0.
amountSpecified
string
Decimal signed amount; positive requests exact input and negative requests exact output.
sqrtPriceLimitX96
string
Price boundary in Q64.96 fixed-point form at which the simulation must stop.
Return Values
amount0
string
Simulated signed token0 delta, as a decimal string; "0" on an unsuccessful simulation.
amount1
string
Simulated signed token1 delta, as a decimal string; "0" on an unsuccessful simulation.
error
error
Nil when the simulation succeeds; non-nil when validation, computation, or pool-balance checks fail.
SetSwapEndHook
SetSwapEndHook sets the hook to be called at the end of a swap.
Parameters
cur
realm
Current realm context; callers use cross(cur) when crossing into this realm.
hook
func(realm, string) error
Callback invoked with the current realm and pool path after swap settlement; its error is propagated to abort the swap.
SetSwapStartHook
SetSwapStartHook sets the hook to be called at the start of a swap.
Parameters
cur
realm
Current realm context; callers use cross(cur) when crossing into this realm.
hook
func(realm, string, int64)
Callback invoked with the current realm, pool path, and swap timestamp before swap computation.
SetTickCrossHook
SetTickCrossHook sets the hook to be called when a tick is crossed during a swap.
Parameters
cur
realm
Current realm context; callers use cross(cur) when crossing into this realm.
hook
func(realm, string, int32, bool, int64)
Callback invoked with the current realm, pool path, crossed tick index, swap direction, and block timestamp.
Swap
Swap executes a token swap in the pool.
Halt check: reverts while the Pool halt scope is active.
Parameters
cur
realm
Current realm context; callers use cross(cur) when crossing into this realm.
token0Path
string
Path of the first token in the pool pair.
token1Path
string
Path of the second token in the pool pair.
fee
uint32
Fee tier identifying the pool.
recipient
address
Address receiving output tokens.
zeroForOne
bool
True to sell token0 for token1; false to sell token1 for token0.
amountSpecified
string
Decimal signed amount; positive requests exact input and negative requests exact output.
sqrtPriceLimitX96
string
Price boundary in Q64.96 fixed-point form at which the swap must stop.
swapCallback
func(realm, int64, int64, *CallbackMarker) error
Callback invoked with the current realm, signed token deltas, and a callback marker; it must settle the input token and return a non-nil error to abort settlement.
Return Values
amount0
string
Signed token0 delta for the swap, as a decimal string.
amount1
string
Signed token1 delta for the swap, as a decimal string.
Last updated