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

v1 source realm

package router handles token swaps through GnoSwap liquidity pools.

Readme View source

Router

Swap routing engine for optimal trade execution across pools.

Overview

Router handles swap execution across multiple pools, finding optimal paths and managing slippage protection for traders.

Configuration

  • Router Fee: 15 bps (0.15%) by default on output tokens; configurable by admin/governance from 0 through 1000 bps (0–10%)
  • Max Hops: 3 pools per route
  • Deadline Buffer: 5-30 minutes recommended for live swaps

Core Functions

ExactInSwapRoute

Swaps an exact input amount for output, subject to a minimum net output.

  • Fixed input, variable output
  • The returned output is after the router fee
  • Reverts if output < amountOutMin
  • Supports multi-hop routing

ExactOutSwapRoute

Swaps for a requested final user output amount with maximum input. The amountOut target is post-router-fee: the router requests the corresponding gross pool output, deducts the fee, then validates and transfers the net output.

  • With no single-hop price limit, targets the requested post-fee output within the implementation's small per-hop rounding tolerance
  • A nonzero single-hop price limit may stop early and return a partial output
  • Reverts if input > amountInMax
  • Calculates path backwards

DrySwapRoute

Simulates a swap without execution.

  • Frontend price quotes
  • Slippage calculation
  • Path validation
  • No deadline check or token transfer

Technical Details

Route Format vs Pool Format - IMPORTANT DISTINCTION

Route Format (Swap Direction)

Routes in the router follow swap direction ordering: tokenIn:tokenOut:fee

  • First token = Input token (what you're swapping FROM)
  • Second token = Output token (what you're swapping TO)
  • This represents the actual flow of the swap

Example for swapping GNS to WUGNOT:

gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000

Pool Format (Alphabetical)

Pools are identified using alphabetical ordering: token0:token1:fee

  • token0 < token1 (lexicographically sorted)
  • This is the canonical pool identifier

Example pool identifier (same pool as above):

gno.land/r/gnoland/wugnot.wugnot:gno.land/r/gnoswap/gns.GNS:3000  # gnoland/wugnot < gnoswap/gns alphabetically

Key Difference

  • Router routes: Follow your swap direction (BAR→BAZ means bar:baz in route)
  • Pool identifiers: Always alphabetically sorted (might be bar:baz or baz:bar)
  • The router automatically handles the conversion between these formats

Native Token Route Specification

IMPORTANT: Router swap functions do not accept native ugnot directly.

  • Token Parameters: Use token keys (pkgPath.SYMBOL) such as "gno.land/r/gnoland/wugnot.wugnot"
  • Route Paths: Also use token keys (pkgPath.SYMBOL) such as "gno.land/r/gnoland/wugnot.wugnot"

This matches the current implementation:

  • Pools operate on token contract paths, including wrapped GNOT (wugnot)
  • Router swap entrypoints reject native-coin handling
  • Native-token refund and unwrap flows are not part of the current router implementation

Route String Format

Single-hop format:

tokenIn:tokenOut:fee

Multi-hop format (using POOL separator):

tokenIn:tokenB:fee1*POOL*tokenB:tokenC:fee2*POOL*tokenC:tokenOut:fee3

Single-hop example:

# Swapping GNS to WUGNOT
Route: gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000
# Router interprets: tokenIn=gns, tokenOut=wugnot, fee=3000

Multi-hop example (GNS → WUGNOT → TOKEN_C):

# Each segment follows swap direction, connected by *POOL*
gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000*POOL*gno.land/r/gnoland/wugnot.wugnot:gno.land/r/<namespace>/token_c.TOKEN_C:500

Quote Distribution

Split large trades across routes to minimize impact:

  • quoteArr: positive percentage per route, with one quote for each route
  • Quotes must sum to 100; at most 7 routes are accepted
  • Example: "30,70" = 30% route1, 70% route2

Native Token Handling

The current router implementation does not handle native ugnot directly. It rejects native-coin handling and routes swaps only through token keys (pkgPath.SYMBOL) such as wrapped GNOT (wugnot).

Token Identifier Requirements

  • Use token keys (pkgPath.SYMBOL) such as gno.land/r/gnoland/wugnot.wugnot for both inputs/outputs and route specifications.
  • Do not pass "ugnot" as inputToken or outputToken to router swap functions.

Approval and Transfer Requirements

  • Approve the router to spend the token contract you are swapping from.
  • If you want wrapped GNOT exposure, use the wugnot token contract path directly.
  • Native-token refund and unwrap flows are not part of the current router implementation.

For live liquidity-changing swaps:

  • Set amountOutMin = expected * (1 - slippage%)
  • 0.5-1% for stable pairs
  • 1-3% for volatile pairs
  • Reverts if the net output is below the minimum

Usage

These snippets call the public domain proxy from a realm function with a current cur token. Import the proxy package and qualify its function names in integrating code.

Basic Token Swaps

 1// Simple exact input swap
 2amountIn, amountOut := ExactInSwapRoute(
 3    cross(cur),
 4    "gno.land/r/gnoswap/gns.GNS",       // input token
 5    "gno.land/r/gnoland/wugnot.wugnot", // output token
 6    "1000000",                 // amount (6 decimals)
 7    "gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000", // route
 8    "100",                     // 100% through route
 9    "950000",                  // min output
10    time.Now().Unix() + 300,   // deadline
11    "g1referrer...",           // referral
12)
13
14// Multi-hop swap
15ExactInSwapRoute(
16    cross(cur),
17    "gno.land/r/gnoswap/gns.GNS",
18    "gno.land/r/<namespace>/token_c.TOKEN_C",
19    "1000000",
20    "gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000*POOL*gno.land/r/gnoland/wugnot.wugnot:gno.land/r/<namespace>/token_c.TOKEN_C:3000",
21    "100",
22    "900000",
23    deadline,
24    "",
25)
26
27// Split route for large trades
28ExactInSwapRoute(
29    cross(cur),
30    "gno.land/r/gnoswap/gns.GNS",
31    "gno.land/r/gnoland/wugnot.wugnot",
32    "10000000000",
33    "gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:500,gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000",
34    "60,40",  // 60% through 0.05%, 40% through 0.3%
35    "9500000000",
36    deadline,
37    "",
38)

Single-hop functions support partial execution through a nonzero sqrtPriceLimitX96:

 1// Partial swap with price limit - may not consume full input amount
 2amountIn, amountOut := ExactInSingleSwapRoute(
 3    cross(cur),
 4    "gno.land/r/gnoswap/gns.GNS",       // input token
 5    "gno.land/r/gnoland/wugnot.wugnot", // output token
 6    "1000000",                 // max amount to swap
 7    "gno.land/r/gnoswap/gns.GNS:gno.land/r/gnoland/wugnot.wugnot:3000", // single route
 8    "950000",                  // min output
 9    "1000000000000000000",     // sqrtPriceLimitX96 (price limit)
10    deadline,
11    "",
12)
13// If the price limit is reached, only a partial amount is swapped. For exact-in
14// this can consume less input; exact-out can deliver less than its target.
15// amountOutMin or amountInMax remains enforced, respectively.

Important Developer Notes

Common Integration Pitfalls

  1. Native Token Assumptions: Passing "ugnot" to router swap functions will fail because router entrypoints reject native-coin handling.

  2. Route vs Token Identifier Confusion: Using "ugnot" in route strings instead of "gno.land/r/gnoland/wugnot.wugnot" will cause transactions to fail since no pools exist for the "ugnot" identifier.

  3. Wrong Token Path:

    • Use gno.land/r/gnoland/wugnot.wugnot when swapping wrapped GNOT
    • Do not pass native ugnot to router swap functions
    • Route strings must stay in swap-direction order and use token contract paths

Frontend Integration Checklist

  • Implement WUGNOT approval before wrapped-GNOT swaps
  • Use token keys (pkgPath.SYMBOL) such as "gno.land/r/gnoland/wugnot.wugnot" for both parameters and routes
  • Test both partial and full swap scenarios
  • Implement proper error handling for failed approvals

Both single-hop functions support partial execution when sqrtPriceLimitX96 is nonzero:

  • Exact-in may consume less than the specified input amount
  • Exact-out may deliver less than the requested post-fee output
  • The relevant amount limit (amountOutMin or amountInMax) still applies
  • Remaining input tokens stay with the user because the router uses token contract transfers
  • A zero limit uses the global tick-math boundary and preserves full exact semantics

Security

  • Path validation checks syntax, endpoints, hop continuity, and pool existence; it does not reject circular routes
  • Deadline prevents stale live transactions
  • Slippage limits protect against unfavorable execution
  • The router fee rate is configurable; the current rate is fixed during one execution
  • WUGNOT approval requirement prevents unauthorized token transfers

Overview

package router handles token swaps through GnoSwap liquidity pools.

The router provides user-facing swap functions with slippage protection, multi-hop routing, and both exact-input and exact-output swap modes.

Live exact-input calls enforce a minimum output and deadline. Live exact-output calls enforce a maximum input and deadline. DrySwapRoute is read-only and has no deadline or transfer.

Constants 6

const POOL_SEPARATOR

1const (
2	POOL_SEPARATOR = "*POOL*"
3)
source

swap can be done by multiple pools to separate each pool, we use POOL_SEPARATOR

const Unknown, ExactIn, ExactOut

 1const (
 2	Unknown SwapType = rawUnknown
 3	// ExactIn represents a swap type where the input amount is exact and the output amount may vary.
 4	// Used when a user wants to swap a specific amount of input tokens.
 5	ExactIn SwapType = rawExactIn
 6
 7	// ExactOut represents a swap type where the output amount is exact and the input amount may vary.
 8	// Used when a user wants to swap a specific amount of output tokens.
 9	ExactOut SwapType = rawExactOut
10)
source

Functions 7

func BuildSingleHopRoutePath

Action
1func BuildSingleHopRoutePath(tokenA, tokenB string, fee uint32) string
source

BuildSingleHopRoutePath formats one route-direction single-hop path.

Parameters:

  • tokenA: input token contract path
  • tokenB: output token contract path
  • fee: pool fee tier appended as a decimal value

Returns:

  • routePath: tokenA:tokenB:fee formatted route string; panics for empty or identical tokens

func NewRouterV1

Action
1func NewRouterV1(
2	routerStore router.IRouterStore,
3) router.IRouter
source

NewRouterV1 creates a router v1 implementation backed by routerStore.

Parameters:

  • routerStore: storage implementation used for swap-fee and pending protocol-fee state

Returns:

  • router: initialized IRouter implementation backed by routerStore

func NewExactInParams

Action
1func NewExactInParams(
2	baseParams BaseSwapParams,
3	amountIn int64,
4	amountOutMin int64,
5) ExactInParams
source

NewExactInParams creates parameters for an exact-input swap.

Parameters:

  • baseParams: shared token, route, quote, price-limit, and deadline settings
  • amountIn: exact input amount in token units; must be positive before execution
  • amountOutMin: minimum acceptable output amount in token units

Returns:

  • params: exact-input parameters combining baseParams and amount limits

func NewExactInSwapOperation

Action
1func NewExactInSwapOperation(r *routerV1, pp ExactInParams) *ExactInSwapOperation
source

NewExactInSwapOperation creates an exact-input operation for router execution.

Parameters:

  • r: router implementation used to execute pool swaps
  • pp: exact-input amount and route settings

Returns:

  • operation: initialized ExactInSwapOperation

func NewExactOutParams

Action
1func NewExactOutParams(
2	baseParams BaseSwapParams,
3	amountOut int64,
4	amountInMax int64,
5) ExactOutParams
source

NewExactOutParams creates parameters for an exact-output swap.

Parameters:

  • baseParams: shared token, route, quote, price-limit, and deadline settings
  • amountOut: requested output amount in token units; must be positive before execution
  • amountInMax: maximum acceptable input amount in token units

Returns:

  • params: exact-output parameters combining baseParams and amount limits

func NewExactOutSwapOperation

Action
1func NewExactOutSwapOperation(r *routerV1, pp ExactOutParams) *ExactOutSwapOperation
source

NewExactOutSwapOperation creates an exact-output operation for router execution.

Parameters:

  • r: router implementation used to execute pool swaps
  • pp: exact-output amount and route settings

Returns:

  • operation: initialized ExactOutSwapOperation

func NewRouteParser

Action
1func NewRouteParser() *RouteParser
source

NewRouteParser creates a parser for comma-separated route and quote strings.

Returns:

  • parser: new RouteParser instance

Types 16

type BaseSwapParams

struct
1type BaseSwapParams struct {
2	InputToken        string
3	OutputToken       string
4	RouteArr          string
5	QuoteArr          string
6	SqrtPriceLimitX96 *u256.Uint
7	Deadline          int64
8}
source

type ExactInParams

struct
1type ExactInParams struct {
2	BaseSwapParams
3	AmountIn     int64
4	AmountOutMin int64
5}
source

ExactInParams contains parameters for exact input swaps.

type ExactInSwapOperation

struct
1type ExactInSwapOperation struct {
2	baseSwapOperation
3	params ExactInParams
4	router *routerV1
5}
source

Methods on ExactInSwapOperation

func Process

method on ExactInSwapOperation
1func (op *ExactInSwapOperation) Process(_ int, rlm realm) (*SwapResult, error)
source

Process executes the validated exact-input operation in the propagated realm.

Parameters:

  • _: leading operation discriminator; callers pass 0
  • rlm: propagated current realm context used for pool swaps

Returns:

  • result: aggregate swap amounts and route metadata, or nil on processing error
  • err: nil on success; pool or route execution error otherwise

func Validate

method on ExactInSwapOperation
1func (op *ExactInSwapOperation) Validate() error
source

Validate checks the exact-input amount and parses route/quote allocations.

Returns:

  • err: nil when amount, routes, and quotes are valid; validation error otherwise

type ExactOutParams

struct
1type ExactOutParams struct {
2	BaseSwapParams
3	AmountOut   int64
4	AmountInMax int64
5}
source

ExactOutParams contains parameters for exact output swaps.

type ExactOutSwapOperation

struct
1type ExactOutSwapOperation struct {
2	router *routerV1
3	baseSwapOperation
4	params ExactOutParams
5}
source

ExactOutSwapOperation handles swaps where the output amount is specified.

Methods on ExactOutSwapOperation

func Process

method on ExactOutSwapOperation
1func (op *ExactOutSwapOperation) Process(_ int, rlm realm) (*SwapResult, error)
source

Process executes the validated exact-output operation in the propagated realm.

Parameters:

  • _: leading operation discriminator; callers pass 0
  • rlm: propagated current realm context used for pool swaps

Returns:

  • result: aggregate swap amounts and route metadata, or nil on processing error
  • err: nil on success; pool or route execution error otherwise

func Validate

method on ExactOutSwapOperation
1func (op *ExactOutSwapOperation) Validate() error
source

Validate checks the exact-output amount and parses route/quote allocations.

Returns:

  • err: nil when amount, routes, and quotes are valid; validation error otherwise

type RouteParser

struct
1type RouteParser struct{}
source

RouteParser handles parsing and validation of routes and quotes

Methods on RouteParser

func ParseRoutes

method on RouteParser
1func (p *RouteParser) ParseRoutes(routes, quotes string) ([]string, []string, error)
source

ParseRoutes splits route and quote strings and validates their pairing.

Parameters:

  • routes: comma-separated route paths
  • quotes: comma-separated route allocation percentages

Returns:

  • routePaths: parsed route path strings
  • quoteValues: parsed quote strings corresponding one-to-one with routePaths
  • err: nil when routes, counts, and quote sum are valid; validation error otherwise

func ValidateQuoteSum

method on RouteParser
1func (p *RouteParser) ValidateQuoteSum(quotes []string) error
source

ValidateQuoteSum verifies that each quote is positive, at most 100, and totals 100.

Parameters:

  • quotes: route allocation percentage strings

Returns:

  • err: nil when all quotes parse and total 100; invalid value or sum error otherwise

func ValidateRoutesAndQuotes

method on RouteParser
1func (p *RouteParser) ValidateRoutesAndQuotes(routes, quotes []string) error
source

ValidateRoutesAndQuotes checks route count, route/quote cardinality, and quote sum.

Parameters:

  • routes: parsed route path strings
  • quotes: parsed quote percentage strings

Returns:

  • err: nil when one to seven routes match quote count and quotes sum to 100; validation error otherwise

type RouterOperation

interface
 1type RouterOperation interface {
 2	// Validate checks operation parameters before processing.
 3	//
 4	// Returns:
 5	//   - err: nil when operation input is valid; validation error otherwise
 6	Validate() error
 7	// Process executes the operation in the propagated realm context.
 8	//
 9	// Parameters:
10	//   - _: leading operation discriminator; callers pass 0
11	//   - rlm: propagated current realm context used for pool interaction
12	//
13	// Returns:
14	//   - result: swap amounts and route metadata, or nil when processing fails
15	//   - err: nil on success; execution error otherwise
16	Process(_ int, rlm realm) (*SwapResult, error)
17}
source

type SingleSwapParams

struct
 1type SingleSwapParams struct {
 2	tokenIn  string // token to spend
 3	tokenOut string // token to receive
 4	fee      uint32 // fee of the pool used to swap
 5
 6	// Amount specified for the swap:
 7	//  - Positive: exact input amount (tokenIn)
 8	//  - Negative: exact output amount (tokenOut)
 9	amountSpecified int64
10
11	sqrtPriceLimitX96 *u256.Uint // sqrtPriceLimitX96 for the swap, empty string or zero string means no limit
12}
source

SingleSwapParams contains parameters for executing a single pool swap. It represents the simplest form of swap that occurs within a single liquidity pool.

Methods on SingleSwapParams

func Fee

method on SingleSwapParams
1func (p SingleSwapParams) Fee() uint32
source

Fee returns the pool fee tier.

Returns:

  • fee: fee tier encoded as the pool's uint32 fee value

func SqrtPriceLimitX96

method on SingleSwapParams
1func (p SingleSwapParams) SqrtPriceLimitX96() *u256.Uint
source

SqrtPriceLimitX96 returns the optional Q64.96 square-root price limit. A nil stored limit is normalized to the zero value, which callers interpret as no explicit limit.

Returns:

  • limit: configured Q64.96 price limit, or a zero uint when no limit was supplied

func TokenIn

method on SingleSwapParams
1func (p SingleSwapParams) TokenIn() string
source

TokenIn returns the input token contract path.

Returns:

  • tokenIn: token spent by this single-pool swap

func TokenOut

method on SingleSwapParams
1func (p SingleSwapParams) TokenOut() string
source

TokenOut returns the output token contract path.

Returns:

  • tokenOut: token received by this single-pool swap

type SwapCallbackData

struct
1type SwapCallbackData struct {
2	tokenIn  string  // token to spend
3	tokenOut string  // token to receive
4	fee      uint32  // fee of the pool used to swap
5	payer    address // address to spend the token
6}
source

SwapCallbackData contains the callback data required for swap execution. This type is used to pass necessary information during the swap callback process, ensuring proper token transfers and pool data updates.

type SwapParams

struct
1type SwapParams struct {
2	SingleSwapParams
3	recipient address // address to receive the token
4}
source

SwapParams contains parameters for executing a multi-hop swap operation.

Methods on SwapParams

func Fee

method on SwapParams
1func (p SwapParams) Fee() uint32
source

Fee returns the pool fee tier.

Returns:

  • fee: fee tier encoded as the pool's uint32 fee value

func Recipient

method on SwapParams
1func (p SwapParams) Recipient() address
source

Recipient returns the address that receives swap output.

Returns:

  • recipient: configured output recipient address

func TokenIn

method on SwapParams
1func (p SwapParams) TokenIn() string
source

TokenIn returns the input token contract path.

Returns:

  • tokenIn: token spent by this multi-hop swap parameters object

func TokenOut

method on SwapParams
1func (p SwapParams) TokenOut() string
source

TokenOut returns the output token contract path.

Returns:

  • tokenOut: token received by this multi-hop swap parameters object

type SwapParamsI

interface
 1type SwapParamsI interface {
 2	// TokenIn returns the input token path required by swap processing.
 3	//
 4	// Returns:
 5	//   - tokenIn: token spent by the swap
 6	TokenIn() string
 7	// TokenOut returns the output token path required by swap processing.
 8	//
 9	// Returns:
10	//   - tokenOut: token received by the swap
11	TokenOut() string
12	// Fee returns the pool fee tier required by swap processing.
13	//
14	// Returns:
15	//   - fee: pool fee tier
16	Fee() uint32
17}
source

SwapParamsI defines the common interface for swap parameters.

type SwapProcessor

struct
1type SwapProcessor struct {
2	router *routerV1
3}
source

SwapProcessor handles the execution of swap operations

Methods on SwapProcessor

func AddSwapResults

method on SwapProcessor
1func (p *SwapProcessor) AddSwapResults(
2	resultAmountIn, resultAmountOut, amountIn, amountOut int64,
3) (int64, int64, error)
source

AddSwapResults adds one route's amounts to accumulated totals using overflow-safe arithmetic.

Parameters:

  • resultAmountIn: accumulated input before this route
  • resultAmountOut: accumulated output before this route
  • amountIn: current route input amount
  • amountOut: current route output amount

Returns:

  • newAmountIn: accumulated input after adding amountIn
  • newAmountOut: accumulated output after adding amountOut
  • err: always nil; overflow is raised by safe arithmetic rather than returned

func ProcessMultiSwap

method on SwapProcessor
1func (p *SwapProcessor) ProcessMultiSwap(
2	swapType SwapType,
3	route string,
4	numHops int,
5	amountSpecified int64,
6) (int64, int64, error)
source

ProcessMultiSwap simulates a multi-hop route in the requested direction.

Parameters:

  • swapType: ExactIn for forward execution or ExactOut for backward quoting
  • route: multi-hop path with POOL_SEPARATOR between hops
  • numHops: number of pools in route
  • amountSpecified: signed input or output amount for the route

Returns:

  • amountIn: input amount the route would consume
  • amountOut: output amount the route would produce
  • err: nil on successful simulation; invalid swap-type error or downstream dry-swap validation error otherwise (pool query failures panic)

func ProcessSingleSwap

method on SwapProcessor
1func (p *SwapProcessor) ProcessSingleSwap(route string, amountSpecified int64) (amountIn, amountOut int64, err error)
source

ProcessSingleSwap simulates one pool hop without executing transfers.

Parameters:

  • route: single pool path formatted as TOKEN0:TOKEN1:FEE
  • amountSpecified: signed input or output amount for the hop

Returns:

  • amountIn: input amount the pool would receive
  • amountOut: output amount the pool would send
  • err: always nil when the dry pool call returns; malformed paths or pool failures panic in the underlying helpers

func ValidateSwapResults

method on SwapProcessor
1func (p *SwapProcessor) ValidateSwapResults(
2	swapType SwapType,
3	resultAmountIn, resultAmountOut int64,
4	amountSpecified, amountLimit int64,
5	swapCount int64,
6) (amountIn, amountOut int64, err error)
source

ValidateSwapResults checks simulated amounts against exactness and slippage constraints.

Parameters:

  • swapType: ExactIn or ExactOut validation direction
  • resultAmountIn: simulated aggregate input amount
  • resultAmountOut: simulated aggregate output amount after router fee
  • amountSpecified: caller's exact input or output target
  • amountLimit: minimum output or maximum input slippage bound
  • swapCount: number of pool hops used for exact-output tolerance

Returns:

  • amountIn: resultAmountIn when validation reaches the return path
  • amountOut: resultAmountOut when validation reaches the return path
  • err: nil when liquidity, exactness, and slippage checks pass; relevant validation error otherwise

type SwapResult

struct
1type SwapResult struct {
2	Routes          []string
3	Quotes          []string
4	AmountIn        int64
5	AmountOut       int64
6	AmountSpecified int64
7}
source

SwapResult encapsulates the outcome of a swap operation.

type SwapRouteParams

struct
 1type SwapRouteParams struct {
 2	inputToken        string
 3	outputToken       string
 4	routeArr          string
 5	quoteArr          string
 6	deadline          int64
 7	typ               SwapType
 8	exactAmount       int64      // amountIn for ExactIn, amountOut for ExactOut
 9	limitAmount       int64      // amountOutMin for ExactIn, amountInMax for ExactOut
10	sqrtPriceLimitX96 *u256.Uint // if sqrtPriceLimitX96 is zero string, it will be set to MIN_PRICE or MAX_PRICE
11}
source

SwapRouteParams contains all parameters needed for swap route execution

Methods on SwapRouteParams

func ExactAmount

method on SwapRouteParams
1func (p *SwapRouteParams) ExactAmount() int64
source

ExactAmount returns the requested exact input or output amount.

Returns:

  • amount: exactAmount configured for the route

func ExpectedExactAmountByFee

method on SwapRouteParams
1func (p *SwapRouteParams) ExpectedExactAmountByFee(feeBps uint64) int64
source

ExpectedExactAmountByFee returns the amount needed by pool execution after router-fee adjustment.

Parameters:

  • feeBps: router fee in basis points

Returns:

  • amount: exact input amount for ExactIn, or gross pool amount for ExactOut

func IsSetSqrtPriceLimitX96

method on SwapRouteParams
1func (p *SwapRouteParams) IsSetSqrtPriceLimitX96() bool
source

IsSetSqrtPriceLimitX96 reports whether a nonzero caller price limit is configured.

Returns:

  • set: true when sqrtPriceLimitX96 is non-nil and nonzero

func SwapCount

method on SwapRouteParams
1func (p *SwapRouteParams) SwapCount() int64
source

SwapCount counts pool hops across all comma-separated routes.

Returns:

  • count: total number of pool swaps represented by routeArr

type SwapType

ident
1type SwapType string
source

Methods on SwapType

func String

method on SwapType
1func (s SwapType) String() string
source

String returns the wire-format string for a SwapType.

Returns:

  • swapType: EXACT_IN or EXACT_OUT for known values, or an empty string for Unknown

type SwapValidator

struct
1type SwapValidator struct{}
source

SwapValidator provides validation methods for swap operations

Imports 23

Source Files 21