swap_single.gno
0.94 Kb · 38 lines
1package router
2
3import (
4 prbac "gno.land/p/gnoswap/rbac/v1"
5 u256 "gno.land/p/gnoswap/uint256/v1"
6
7 "gno.land/r/gnoswap/access/v1"
8)
9
10// singleSwap executes a swap within a single pool using the provided parameters.
11// It processes a token swap within two assets using a specific fee tier and
12// automatically sets the recipient to the caller's address.
13func (r *routerV1) singleSwap(_ int, rlm realm, p *SingleSwapParams) (int64, int64) {
14 assertSingleSwap(p)
15
16 caller := rlm.Previous().Address()
17 recipient := access.MustGetAddress(prbac.ROLE_ROUTER.String())
18
19 return r.swapInner(
20 0,
21 rlm,
22 p.amountSpecified,
23 recipient,
24 p.SqrtPriceLimitX96(),
25 newSwapCallbackData(p, caller),
26 )
27}
28
29// singleDrySwap simulates a single-token swap operation without executing it.
30func (r *routerV1) singleDrySwap(p *SingleSwapParams) (int64, int64) {
31 assertSingleSwap(p)
32
33 return r.swapDryInner(
34 p.amountSpecified,
35 u256.Zero(),
36 newDrySwapCallbackData(p),
37 )
38}