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 v1 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: 0.15% on all swaps
  • Max Hops: 3 pools per route
  • Deadline Buffer: 5-30 minutes recommended

Core Functions

ExactInSwapRoute

Swaps exact input amount for minimum output.

  • Fixed input, variable output
  • Reverts if output < amountOutMin
  • Supports multi-hop routing

ExactOutSwapRoute

Swaps for exact output amount with maximum input.

  • Fixed output, variable input
  • Reverts if input > amountInMax
  • Calculates path backwards

DrySwapRoute

Simulates swap without execution.

  • Frontend price quotes
  • Slippage calculation
  • Gas estimation
  • Path validation

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 BAR to BAZ:

gno.land/r/demo/bar:gno.land/r/demo/baz: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/demo/bar:gno.land/r/demo/baz:3000  # if bar < baz 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: When using native GNOT tokens, there's a critical distinction between token identifiers and route paths:

  • Token Parameters: Use "ugnot" for inputToken and outputToken parameters
  • Route Paths: Must use "gno.land/r/gnoland/wugnot" in route strings

This dual-identifier system exists because:

  • Pools only operate on wrapped tokens (WUGNOT)
  • Router functions accept native token identifiers for user convenience
  • Internal processing automatically converts between native and wrapped forms

Correct Usage Example:

 1// CORRECT: inputToken="ugnot", route uses wugnot path
 2ExactInSwapRoute(
 3    "ugnot",                                    // input token identifier
 4    "gno.land/r/demo/bar",                    // output token
 5    "1000000",
 6    "gno.land/r/gnoland/wugnot:gno.land/r/demo/bar:3000", // route uses wugnot
 7    "100", "950000", deadline, ""
 8)
 9
10// INCORRECT: using "ugnot" in route will fail
11ExactInSwapRoute(
12    "ugnot", "gno.land/r/demo/bar", "1000000",
13    "ugnot:gno.land/r/demo/bar:3000",          // Wrong: pools don't exist for "ugnot"
14    "100", "950000", deadline, ""
15)

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 BAR to BAZ
Route: gno.land/r/demo/bar:gno.land/r/demo/baz:3000
# Router interprets: tokenIn=bar, tokenOut=baz, fee=3000

Multi-hop example (BAR → BAZ → QUX):

# Each segment follows swap direction, connected by *POOL*
gno.land/r/demo/bar:gno.land/r/demo/baz:3000*POOL*gno.land/r/demo/baz:gno.land/r/demo/qux:500

Quote Distribution

Split large trades across routes to minimize impact:

  • quoteArr: Percentage per route (must sum to 100)
  • Example: "30,70" = 30% route1, 70% route2

GNOT Handling

The Router automatically handles native GNOT token operations through wrapping/unwrapping mechanisms:

Token Identifier Requirements

  • Input Token: Use "ugnot" to specify native GNOT as input token
  • Output Token: Use "ugnot" to specify native GNOT as output token
  • Routes: Must always use wrapped token path "gno.land/r/gnoland/wugnot" in route specifications

Native Token Send Requirements

When using native GNOT tokens, you must send the appropriate amount of native ugnot with your function call:

  • ExactInSwapRoute: Send exactly amountIn amount of ugnot
  • ExactInSingleSwapRoute: Send exactly amountIn amount of ugnot
  • ExactOutSwapRoute: Send exactly amountInMax amount of ugnot
  • ExactOutSingleSwapRoute: Send exactly amountInMax amount of ugnot

Slippage Protection

  • Set amountOutMin = expected * (1 - slippage%)
  • 0.5-1% for stable pairs
  • 1-3% for volatile pairs
  • Reverts if exceeded

Usage

Basic Token Swaps

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

Single Swap with Partial Execution

Single swap functions support partial execution through price limits:

 1// Partial swap with price limit - may not consume full input amount
 2amountIn, amountOut := ExactInSingleSwapRoute(
 3    "gno.land/r/demo/bar",     // input token
 4    "gno.land/r/demo/baz",     // output token
 5    "1000000",                 // max amount to swap
 6    "gno.land/r/demo/bar:gno.land/r/demo/baz:3000", // single route
 7    "950000",                  // min output
 8    "1000000000000000000",     // sqrtPriceLimitX96 (price limit)
 9    deadline,
10    "",
11)
12// If price limit is reached, only partial amount is swapped
13// Remaining input tokens stay with user (no refund needed for GRC20 tokens)

Native GNOT Swaps with Refunds

When using native GNOT, automatic refunds handle unused amounts:

 1// STEP 1: Approve WUGNOT for potential refunds
 2wugnot.Approve(cross, routerAddress, 2000000) // Approve more than needed
 3
 4// STEP 2: ExactIn with native GNOT (send exactly amountIn)
 5amountIn, amountOut := ExactInSwapRoute(
 6    "ugnot",                    // native input
 7    "gno.land/r/demo/bar",     // output token
 8    "1000000",                 // send this amount of ugnot with call
 9    "gno.land/r/gnoland/wugnot:gno.land/r/demo/bar:3000",
10    "100", "950000", deadline, ""
11)
12// Any unused GNOT automatically refunded
13
14// STEP 3: ExactOut with native GNOT (send amountInMax)
15amountIn, amountOut := ExactOutSwapRoute(
16    "ugnot",                    // native input
17    "gno.land/r/demo/bar",     // output token
18    "1000000",                 // exact output desired
19    "gno.land/r/gnoland/wugnot:gno.land/r/demo/bar:3000",
20    "100",
21    "1200000",                 // send this max amount of ugnot with call
22    deadline, ""
23)
24// Excess GNOT (1200000 - actual_input_used) automatically refunded
25
26// STEP 4: Single swap with partial execution + refund
27amountIn, amountOut := ExactInSingleSwapRoute(
28    "ugnot",                    // native input
29    "gno.land/r/demo/bar",     // output token
30    "1000000",                 // send this amount of ugnot with call
31    "gno.land/r/gnoland/wugnot:gno.land/r/demo/bar:3000",
32    "950000",
33    "1000000000000000000",     // price limit may cause partial swap
34    deadline, ""
35)
36// Unswapped GNOT due to price limit automatically refunded

Important Developer Notes

Common Integration Pitfalls

  1. WUGNOT Approval Forgotten: Most transaction failures with native GNOT occur because developers forget to approve WUGNOT spending before calling router functions.

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

  3. Incorrect Native Token Send Amount:

    • ExactIn functions: Must send exactly amountIn of native gnot
    • ExactOut functions: Must send exactly amountInMax of native gnot
    • Sending wrong amounts will cause transaction reversion
  4. Missing Refund Handling: When integrating, remember that native GNOT refunds are automatic but require prior WUGNOT approval.

Frontend Integration Checklist

  • Implement WUGNOT approval before native GNOT swaps
  • Use correct token identifiers: "ugnot" for parameters, "gno.land/r/gnoland/wugnot" for routes
  • Send correct native token amounts with function calls
  • Handle automatic refunds in UI balance updates
  • Test both partial and full swap scenarios
  • Implement proper error handling for failed approvals

Single Swap Partial Execution

The ExactInSingleSwapRoute and ExactOutSingleSwapRoute functions support partial execution when sqrtPriceLimitX96 is set. This means:

  • Swap may consume less than the specified input amount
  • Price impact is limited by the price limit parameter
  • Remaining tokens are handled automatically (refunded for native GNOT, stay with user for GRC20)
  • This is useful for large trades to prevent excessive slippage

Security

  • Path validation prevents circular routes
  • Deadline prevents stale transactions
  • Slippage limits protect against MEV
  • Router fees immutable per swap
  • WUGNOT approval requirement prevents unauthorized token transfers

Overview

package v1 handles token swaps through GnoSwap liquidity pools.

The router provides user-facing swap functions with slippage protection, multi-hop routing, and automatic GNOT wrapping/unwrapping. It supports both exact input and exact output swap modes.

All swap functions include deadline checks and minimum output validation to protect users from unfavorable price movements.

Constants 7

const MIN_SQRT_RATIO, MAX_SQRT_RATIO

1const (
2	MIN_SQRT_RATIO string = "4295128739"                                        // same as TickMathGetSqrtRatioAtTick(MIN_TICK)
3	MAX_SQRT_RATIO string = "1461446703485210103287273052203988822378723970342" // same as TickMathGetSqrtRatioAtTick(MAX_TICK)
4)
source

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 _, Forward, Backward

 1const (
 2	_ SwapDirection = iota
 3	// Forward indicates a swap processing direction from the first pool to the last pool.
 4	// Used primarily for exactIn swaps where the input amount is known.
 5	Forward
 6
 7	// Backward indicates a swap processing direction from the last pool to the first pool.
 8	// Used primarily for exactOut swaps where the output amount is known and input amounts
 9	// Need to be calculated in reverse order.
10	Backward
11)
source

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

BuildSingleHopPath creates a single-hop route path string. Format: "tokenA:tokenB:fee"

Parameters: - tokenA: input token address - tokenB: output token address - fee: pool fee (e.g., 500, 3000, 10000)

Returns: - string: formatted single-hop route path

Example:

  • BuildSingleHopPath("gno.land/r/demo/wugnot", "gno.land/r/demo/usdc", 500) returns "gno.land/r/demo/wugnot:gno.land/r/demo/usdc:500"

func NewExactInParams

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

NewExactInParams creates a new ExactInParams instance.

func NewExactOutParams

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

NewExactOutParams creates a new ExactOutParams instance.

func NewExactOutSwapOperation

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

NewExactOutSwapOperation creates a new exact-out swap operation.

Types 24

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 DryMultiSwapExecutor

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

DryMultiSwapExecutor implements MultiSwapExecutor for dry run simulations.

Methods on DryMultiSwapExecutor

func Run

method on DryMultiSwapExecutor
1func (e *DryMultiSwapExecutor) Run(p SwapParams, data SwapCallbackData, _ address) (int64, int64)
source

Run performs a dry swap operation without changing state.

type DrySwapExecutor

struct
1type DrySwapExecutor struct {
2	router *routerV1
3	// payer is the user's address resolved at the entry point (DrySwapRoute),
4	// since dry-run paths do not have a realm value to read PreviousRealm from.
5	payer address
6}
source

DrySwapExecutor implements SwapExecutor for dry swaps.

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 exact-in swap operation.

func Validate

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

Validate validates the exact-in swap operation parameters.

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 exact-out swap operation.

func Validate

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

Validate ensures the exact-out swap parameters are valid.

type MultiSwapExecutor

interface
1type MultiSwapExecutor interface {
2	// Run performs the swap operation and returns pool received and pool output amounts.
3	Run(p SwapParams, data SwapCallbackData, recipient address) (int64, int64)
4}
source

MultiSwapExecutor defines the interface for multi-hop swap operation execution.

type MultiSwapProcessor

struct
1type MultiSwapProcessor struct {
2	executor   MultiSwapExecutor
3	direction  SwapDirection
4	router     *routerV1
5	isSimulate bool
6	// payer is the address used to identify the user. For real swaps it is the
7	// PreviousRealm address; for dry-run paths it is resolved at the entry point.
8	payer address
9}
source

MultiSwapProcessor handles the execution flow for multi-hop swaps.

type RealMultiSwapExecutor

struct
1type RealMultiSwapExecutor struct {
2	rlm    realm
3	router *routerV1
4}
source

RealMultiSwapExecutor implements MultiSwapExecutor for actual swap operations.

Methods on RealMultiSwapExecutor

func Run

method on RealMultiSwapExecutor
1func (e *RealMultiSwapExecutor) Run(p SwapParams, data SwapCallbackData, recipient address) (int64, int64)
source

Run performs a real swap operation with state changes.

type RealSwapExecutor

struct
1type RealSwapExecutor struct {
2	rlm    realm
3	router *routerV1
4}
source

RealSwapExecutor implements SwapExecutor for actual swaps.

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 parses route and quote strings into slices and validates them.

func ValidateQuoteSum

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

ValidateQuoteSum ensures all quotes add up to 100%.

func ValidateRoutesAndQuotes

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

ValidateRoutesAndQuotes ensures routes and quotes meet required criteria.

type RouterOperation

interface
1type RouterOperation interface {
2	Validate() error
3	Process(_ int, rlm realm) (*SwapResult, error)
4}
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.

func SqrtPriceLimitX96

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

SqrtPriceLimitX96 returns the sqrtPriceLimitX96 for the swap. If sqrtPriceLimitX96 is empty string, it will return zero.

func TokenIn

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

TokenIn returns the input token address.

func TokenOut

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

TokenOut returns the output token address.

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 SwapDirection

ident
1type SwapDirection int
source

SwapDirection represents the direction of swap execution in multi-hop swaps. It determines whether swaps are processed in forward order (first to last pool) or backward order (last to first pool).

type SwapExecutor

interface
1type SwapExecutor interface {
2	// execute performs the swap operation.
3	execute(p *SingleSwapParams) (int64, int64)
4}
source

SwapExecutor defines the interface for executing swaps.

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.

func Recipient

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

Recipient returns the recipient address.

func TokenIn

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

TokenIn returns the input token address.

func TokenOut

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

TokenOut returns the output token address.

type SwapParamsI

interface
1type SwapParamsI interface {
2	TokenIn() string
3	TokenOut() string
4	Fee() uint32
5}
source

SwapParamsI defines the common interface for swap parameters.

type SwapProcessor

struct
1type SwapProcessor struct {
2	router *routerV1
3	// payer identifies the user for dry-run simulations. It is resolved once at
4	// the entry point via unsafe.PreviousRealm since dry-run paths are
5	// read-only and carry no realm value to thread.
6	payer address
7}
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 safely adds swap result amounts, checking for overflow.

Parameters:

  • resultAmountIn, resultAmountOut: Accumulated results from previous routes
  • amountIn, amountOut: Results from current route

Returns:

  • newAmountIn: resultAmountIn + amountIn
  • newAmountOut: resultAmountOut + amountOut
  • err: Always nil (uses safe addition that panics on overflow)

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 handles a multi-hop swap simulation.

Parameters:

  • swapType: ExactIn or ExactOut
  • route: Multi-hop route with POOL_SEPARATOR
  • numHops: Number of hops in the route
  • amountSpecified: Input/output amount depending on swap type

Returns:

  • amountIn: Expected input amount
  • amountOut: Expected output amount
  • err: Error if swap simulation fails

func ProcessSingleSwap

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

ProcessSingleSwap handles a single-hop swap simulation.

Parameters:

  • route: Single pool path "TOKEN0:TOKEN1:FEE"
  • amountSpecified: Input/output amount depending on swap type

Returns:

  • amountIn: Expected input amount
  • amountOut: Expected output amount
  • err: Error if swap simulation fails

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, success bool)
source

ValidateSwapResults checks if the swap results meet the required constraints.

Parameters:

  • swapType: ExactIn or ExactOut
  • resultAmountIn, resultAmountOut: Swap simulation results
  • amountSpecified: User's specified exact amount
  • amountLimit: Slippage protection limit
  • swapCount: Number of swap operations (for tolerance)

Returns:

  • amountIn: Input amount (same as resultAmountIn)
  • amountOut: Output amount (same as resultAmountOut)
  • success: true if slippage constraints are met, false 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

func ExpectedExactAmountByFee

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

when exact out, calculate amount to fetch from pool including router fee

func SwapCount

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

type SwapType

ident
1type SwapType string
source

Methods on SwapType

func String

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

String returns the string representation of SwapType.

type SwapValidator

struct
1type SwapValidator struct{}
source

SwapValidator provides validation methods for swap operations

Imports 23

Source Files 20