Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proxy.gno

6.58 Kb · 162 lines
  1package router
  2
  3// ExactInSwapRoute executes a multi-hop swap for an exact input amount.
  4//
  5// Parameters:
  6//   - cur: current realm context; callers use cross(cur) when crossing into this realm
  7//   - inputToken: input token path
  8//   - outputToken: output token path
  9//   - amountIn: exact input amount
 10//   - routeArr: encoded route
 11//   - quoteArr: encoded quotes
 12//   - amountOutMin: minimum output amount
 13//   - deadline: transaction deadline
 14//   - referrer: referral address
 15//
 16// Returns:
 17//   - amountIn: input amount consumed
 18//   - amountOut: net output amount delivered after the router fee
 19//
 20// Halt check: reverts while the Router halt scope is active.
 21func ExactInSwapRoute(cur realm, inputToken string, outputToken string, amountIn string, routeArr string, quoteArr string, amountOutMin string, deadline int64, referrer string) (string, string) {
 22	return getImplementation().ExactInSwapRoute(0, cur, inputToken, outputToken, amountIn, routeArr, quoteArr, amountOutMin, deadline, referrer)
 23}
 24
 25// ExactInSingleSwapRoute executes a single-hop swap for an exact input amount.
 26//
 27// Parameters:
 28//   - cur: current realm context; callers use cross(cur) when crossing into this realm
 29//   - inputToken: input token path
 30//   - outputToken: output token path
 31//   - amountIn: exact input amount
 32//   - routeArr: encoded route
 33//   - amountOutMin: minimum output amount
 34//   - sqrtPriceLimitX96: Q64.96 price limit
 35//   - deadline: transaction deadline
 36//   - referrer: referral address
 37//
 38// Returns:
 39//   - amountIn: input amount consumed (a nonzero price limit may stop early)
 40//   - amountOut: net output amount delivered after the router fee
 41//
 42// Halt check: reverts while the Router halt scope is active.
 43func ExactInSingleSwapRoute(cur realm, inputToken string, outputToken string, amountIn string, routeArr string, amountOutMin string, sqrtPriceLimitX96 string, deadline int64, referrer string) (string, string) {
 44	return getImplementation().ExactInSingleSwapRoute(0, cur, inputToken, outputToken, amountIn, routeArr, amountOutMin, sqrtPriceLimitX96, deadline, referrer)
 45}
 46
 47// ExactOutSwapRoute executes a multi-hop swap for a requested post-fee output
 48// target.
 49//
 50// Parameters:
 51//   - cur: current realm context; callers use cross(cur) when crossing into this realm
 52//   - inputToken: input token path
 53//   - outputToken: output token path
 54//   - amountOut: requested net output target
 55//   - routeArr: encoded route
 56//   - quoteArr: encoded quotes
 57//   - amountInMax: maximum input amount
 58//   - deadline: transaction deadline
 59//   - referrer: referral address
 60//
 61// Returns:
 62//   - amountIn: input amount consumed
 63//   - amountOut: net output delivered after the router fee
 64//
 65// Halt check: reverts while the Router halt scope is active.
 66func ExactOutSwapRoute(cur realm, inputToken string, outputToken string, amountOut string, routeArr string, quoteArr string, amountInMax string, deadline int64, referrer string) (string, string) {
 67	return getImplementation().ExactOutSwapRoute(0, cur, inputToken, outputToken, amountOut, routeArr, quoteArr, amountInMax, deadline, referrer)
 68}
 69
 70// ExactOutSingleSwapRoute executes a single-hop swap for a requested post-fee
 71// output target.
 72//
 73// Parameters:
 74//   - cur: current realm context; callers use cross(cur) when crossing into this realm
 75//   - inputToken: input token path
 76//   - outputToken: output token path
 77//   - amountOut: requested net output target
 78//   - routeArr: encoded route
 79//   - amountInMax: maximum input amount
 80//   - sqrtPriceLimitX96: Q64.96 price limit
 81//   - deadline: transaction deadline
 82//   - referrer: referral address
 83//
 84// Returns:
 85//   - amountIn: input amount consumed (a nonzero price limit may stop early)
 86//   - amountOut: net output delivered after the router fee; it may be below
 87//     the requested target when the limit is reached
 88//
 89// Halt check: reverts while the Router halt scope is active.
 90func ExactOutSingleSwapRoute(cur realm, inputToken string, outputToken string, amountOut string, routeArr string, amountInMax string, sqrtPriceLimitX96 string, deadline int64, referrer string) (string, string) {
 91	return getImplementation().ExactOutSingleSwapRoute(0, cur, inputToken, outputToken, amountOut, routeArr, amountInMax, sqrtPriceLimitX96, deadline, referrer)
 92}
 93
 94// DrySwapRoute simulates a swap route without changing state.
 95//
 96// Parameters:
 97//   - inputToken: input token path
 98//   - outputToken: output token path
 99//   - specifiedAmount: exact input or output amount
100//   - swapTypeStr: `EXACT_IN` or `EXACT_OUT`
101//   - strRouteArr: encoded route
102//   - quoteArr: encoded quotes
103//   - tokenAmountLimit: minimum output or maximum input amount
104//
105// Returns:
106//   - amountIn: estimated input amount
107//   - amountOut: estimated output amount
108//   - err: non-nil when route validation or simulation fails
109func DrySwapRoute(
110	inputToken, outputToken string,
111	specifiedAmount string,
112	swapTypeStr string,
113	strRouteArr, quoteArr string,
114	tokenAmountLimit string,
115) (string, string, error) {
116	return getImplementation().DrySwapRoute(inputToken, outputToken, specifiedAmount, swapTypeStr, strRouteArr, quoteArr, tokenAmountLimit)
117}
118
119// SwapCallback transfers amounts owed by a pool during a swap.
120//
121// Parameters:
122//   - cur: current realm context; callers use cross(cur) when crossing into this realm
123//   - token0Path: token0 path
124//   - token1Path: token1 path
125//   - amount0Delta: token0 amount owed to or by the pool
126//   - amount1Delta: token1 amount owed to or by the pool
127//   - payer: address that supplies positive deltas
128//
129// Returns:
130//   - err: non-nil when payment validation or transfer fails
131//
132// Halt check: reverts while the Router halt scope is active.
133func SwapCallback(cur realm, token0Path string, token1Path string, amount0Delta int64, amount1Delta int64, payer address) error {
134	return getImplementation().SwapCallback(0, cur, token0Path, token1Path, amount0Delta, amount1Delta, payer)
135}
136
137// GetSwapFee returns the current router fee rate.
138//
139// Returns:
140//   - fee: fee rate in basis points
141func GetSwapFee() uint64 {
142	return getImplementation().GetSwapFee()
143}
144
145// SetSwapFee sets the router fee rate.
146//
147// Parameters:
148//   - cur: current realm context; callers use cross(cur) when crossing into this realm
149//   - fee: fee rate in basis points
150//
151// Halt check: reverts while the Router or ProtocolFee halt scope is active.
152func SetSwapFee(cur realm, fee uint64) {
153	getImplementation().SetSwapFee(0, cur, fee)
154}
155
156// GetPendingProtocolFees returns a copy of uncollected protocol fees by token.
157//
158// Returns:
159//   - fees: pending protocol fee amount keyed by token path
160func GetPendingProtocolFees() map[string]int64 {
161	return cloneStringInt64Map(getImplementation().GetPendingProtocolFees())
162}