Kind Realm (renderable)
Name v2
Namespace gnoswap / router
Exported functions 7
Module gno.land/r/gnoswap/router/v2
gno 0.9 assert.gno gno
⧉
1 package router 2 3 import ( 4 "errors" 5 "strings" 6 "time" 7 8 BuildSingleHopRoutePath (tokenA string, tokenB string, fee uint32) string
NewExactInParams (baseParams struct{InputToken string; OutputToken string; RouteArr string; QuoteArr string; SqrtPriceLimitX96 *gno.land/p/gnoswap/uint256/v1.Uint; Deadline int64}, amountIn int64, amountOutMin int64) struct{BaseSwapParams gno.land/r/gnoswap/router/v2.BaseSwapParams; AmountIn int64; AmountOutMin int64}
NewExactInSwapOperation (r *gno.land/r/gnoswap/router/v2.routerV1, pp struct{BaseSwapParams gno.land/r/gnoswap/router/v2.BaseSwapParams; AmountIn int64; AmountOutMin int64}) *gno.land/r/gnoswap/router/v2.ExactInSwapOperation
NewExactOutParams (baseParams struct{InputToken string; OutputToken string; RouteArr string; QuoteArr string; SqrtPriceLimitX96 *gno.land/p/gnoswap/uint256/v1.Uint; Deadline int64}, amountOut int64, amountInMax int64) struct{BaseSwapParams gno.land/r/gnoswap/router/v2.BaseSwapParams; AmountOut int64; AmountInMax int64}
NewExactOutSwapOperation (r *gno.land/r/gnoswap/router/v2.routerV1, pp struct{BaseSwapParams gno.land/r/gnoswap/router/v2.BaseSwapParams; AmountOut int64; AmountInMax int64}) *gno.land/r/gnoswap/router/v2.ExactOutSwapOperation
NewRouteParser () *gno.land/r/gnoswap/router/v2.RouteParser
NewRouterV1 (routerStore interface {GetPendingProtocolFee func(string) int64; GetPendingProtocolFees func() map[string]int64; GetSwapFee func() uint64; HasPendingProtocolFeesKey func() bool; HasSwapFeeKey func() bool; RemovePendingProtocolFee func(int, .uverse.realm, string) .uverse.error; SetPendingProtocolFee func(int, .uverse.realm, string, int64) .uverse.error; SetPendingProtocolFees func(int, .uverse.realm, map[string]int64) .uverse.error; SetSwapFee func(int, .uverse.realm, uint64) .uverse.error}) interface {DrySwapRoute func(string, string, string, string, string, string, string) (string, string, .uverse.error); ExactInSingleSwapRoute func(int, .uverse.realm, string, string, string, string, string, string, int64, string) (string, string); ExactInSwapRoute func(int, .uverse.realm, string, string, string, string, string, string, int64, string) (string, string); ExactOutSingleSwapRoute func(int, .uverse.realm, string, string, string, string, string, string, int64, string) (string, string); ExactOutSwapRoute func(int, .uverse.realm, string, string, string, string, string, string, int64, string) (string, string); GetPendingProtocolFees func() map[string]int64; GetSwapFee func() uint64; Render func(string) string; SetSwapFee func(int, .uverse.realm, uint64); SwapCallback func(int, .uverse.realm, string, string, int64, int64, .uverse.address) .uverse.error}
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
This realm does not provide renderable output (vm/qrender → NoRenderDeclError).
View on gnoweb ↗ vm/qrender output, sanitized (docs/render-security.md) and displayed in an empty-sandbox iframe — scripts, forms and popups cannot run. Links stay inert in-preview; right-click to open.
ufmt "gno.land/p/nt/ufmt/v0"
9
10 u256 "gno.land/p/gnoswap/uint256/v1"
11
12 "gno.land/r/gnoswap/pool"
13
14 "gno.land/r/gnoswap/common"
15 )
16
17 // assertIsNotExpired ensures the transaction deadline has not passed.
18 func assertIsNotExpired(deadline int64 ) {
19 now := time.Now().Unix()
20
21 if now > deadline {
22 panic(makeErrorWithDetails(
23 errExpired,
24 ufmt.Sprintf( "transaction too old, now(%d) > deadline(%d)" , now, deadline),
25 ))
26 }
27 }
28
29 func assertSingleSwap(p *SingleSwapParams) {
30 if p.tokenIn == p.tokenOut {
31 panic(errors.New(errSameTokenSwap))
32 }
33
34 common.MustRegistered(p.tokenIn, p.tokenOut)
35 }
36
37 func assertIsValidSqrtPriceLimitX96(sqrtPriceLimitX96 string ) {
38 if sqrtPriceLimitX96 == "" {
39 panic(makeErrorWithDetails(
40 errInvalidInput,
41 ufmt.Sprintf( "invalid sqrtPriceLimitX96: %s" , sqrtPriceLimitX96),
42 ))
43 }
44
45 _, err := u256.FromDecimal(sqrtPriceLimitX96)
46 if err != nil {
47 panic(makeErrorWithDetails(
48 errInvalidInput,
49 ufmt.Sprintf( "invalid sqrtPriceLimitX96: %s" , sqrtPriceLimitX96),
50 ))
51 }
52 }
53
54 func assertIsValidSingleSwapRouteArrPath(routePaths, inputToken, outputToken string ) {
55 if routePaths == "" {
56 panic(makeErrorWithDetails(
57 errInvalidInput,
58 ufmt.Sprintf( "invalid route: %s" , routePaths),
59 ))
60 }
61
62 if strings.Count(routePaths, "," ) > 0 {
63 panic(makeErrorWithDetails(
64 errInvalidInput,
65 ufmt.Sprintf( "invalid routePaths: %s" , routePaths),
66 ))
67 }
68
69 if strings.Count(routePaths, POOL_SEPARATOR) > 0 {
70 panic(makeErrorWithDetails(
71 errInvalidInput,
72 ufmt.Sprintf( "invalid routePaths: %s" , routePaths),
73 ))
74 }
75
76 assertIsValidRoutePaths(routePaths, inputToken, outputToken)
77 }
78
79 func assertIsValidRoutePaths(routePaths, inputToken, outputToken string ) {
80 err := validateRoutePaths(routePaths, inputToken, outputToken)
81 if err != nil {
82 panic(err)
83 }
84 }
85
86 func assertIsExistsPools(routePathArr string ) {
87 poolPaths, err := parsePoolPathsByRoutePathArr(routePathArr)
88 if err != nil {
89 panic(err)
90 }
91
92 for _, poolPath := range poolPaths {
93 if !pool.ExistsPoolPath(poolPath) {
94 panic(makeErrorWithDetails(
95 errInvalidInput,
96 ufmt.Sprintf( "pool does not exist: %s" , poolPath),
97 ))
98 }
99 }
100 }
101
102 func assertIsRouterImplementation(caller address) {
103 if caller != routerImplAddr {
104 panic(makeErrorWithDetails(
105 errUnAuthorizedCaller,
106 ufmt.Sprintf( "caller %s is not router implementation(%s)" , caller, routerImplAddr),
107 ))
108 }
109 }
110
111 // assertIsRouterProxyRealm ensures the swap context was forwarded by the router proxy.
112 func assertIsRouterProxyRealm(_ int , rlm realm) {
113 if rlm.PkgPath() != routerProxyPkgPath {
114 panic(makeErrorWithDetails(
115 errUnAuthorizedCaller,
116 ufmt.Sprintf( "swap context %s is not router proxy(%s)" , rlm.PkgPath(), routerProxyPkgPath),
117 ))
118 }
119 }
120
121 // assertHopFullyConsumed reverts when an exact-in hop consumed less input than specified.
122 func assertHopFullyConsumed(hopIndex int , specifiedAmount, consumedAmount int64 ) {
123 err := validateHopFullyConsumed(hopIndex, specifiedAmount, consumedAmount)
124 if err != nil {
125 panic(err)
126 }
127 }
128
129 func validateHopFullyConsumed(hopIndex int , specifiedAmount, consumedAmount int64 ) error {
130 if consumedAmount != specifiedAmount {
131 return makeErrorWithDetails(
132 errInsufficientLiquidity,
133 ufmt.Sprintf( "partial fill on hop(%d): requested=%d, consumed=%d" , hopIndex, specifiedAmount, consumedAmount),
134 )
135 }
136
137 return nil
138 }
139