dex

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WarnThinLiquidity   = "THIN_LIQUIDITY"
	WarnPriceImpactHigh = "PRICE_IMPACT_HIGH"
)
View Source
const (
	ViaDevice = "device"
	ViaServer = "server"
)
View Source
const DefaultTimeout = 5 * time.Second
View Source
const ThinLiquidityRatio = 0.05

Variables

This section is empty.

Functions

func FormatUSD

func FormatUSD(v float64) string

func IsRouteUnsafe

func IsRouteUnsafe(r *Route) bool

func RawToHuman

func RawToHuman(raw string, decimals int) float64

func ReasonFor

func ReasonFor(c *Candidate, channel string) string

Types

type Candidate

type Candidate struct {
	Channel      string
	Via          string
	FromChain    string
	FromToken    string
	FromAddress  string
	ToChain      string
	ToToken      string
	ToAddress    string
	ToDecimals   int
	LiquidityUsd float64
	SourceIssuer string
}

func (*Candidate) CrossChain

func (c *Candidate) CrossChain() bool

type Engine

type Engine struct {
	Logf func(format string, args ...interface{})
}

func (*Engine) Quote

func (e *Engine) Quote(ctx context.Context, req *Request, cands []*Candidate, quote QuoteFn) *Response

type QuoteFn

type QuoteFn func(ctx context.Context, cand *Candidate, in *dexmodel.DexQuoteIn) (*dexmodel.DexQuoteOut, error)

type RateLimit

type RateLimit struct {
	QPS   float64
	Burst int
}

func (RateLimit) Apply

func (r RateLimit) Apply(req *httpc.Request)

type Request

type Request struct {
	FromAmount    string
	SlippageBps   int
	Timeout       time.Duration
	FromAmountUsd float64
	ToPriceUsd    float64
	FeeRate       string
	FeeReceiver   string
	ScamCheck     func(chain, token string) bool
}

type Response

type Response struct {
	Routes        []*Route `json:"routes"`
	Reason        string   `json:"reason,omitempty"`
	ReasonMessage string   `json:"reasonMessage,omitempty"`
}

type Route

type Route struct {
	Rank            int       `json:"rank"`
	Recommended     bool      `json:"recommended"`
	CrossChain      bool      `json:"crossChain"`
	FromChain       string    `json:"fromChain"`
	FromToken       string    `json:"fromToken"`
	ToChain         string    `json:"toChain"`
	ToToken         string    `json:"toToken"`
	ToDecimals      int       `json:"toDecimals"`
	SourceIssuer    string    `json:"sourceIssuer,omitempty"`
	ToAmount        string    `json:"toAmount"`
	ToAmountUsd     float64   `json:"toAmountUsd"`
	ExpectedFillUsd float64   `json:"expectedFillUsd,omitempty"`
	Channel         string    `json:"channel"`
	FeeUsd          float64   `json:"feeUsd,omitempty"`
	PriceImpactPct  float64   `json:"priceImpactPct,omitempty"`
	LiquidityUsd    float64   `json:"liquidityUsd,omitempty"`
	EstSeconds      int64     `json:"estSeconds,omitempty"`
	Warnings        []Warning `json:"warnings,omitempty"`
	Reason          string    `json:"reason,omitempty"`
}

type Warning

type Warning = dexmodel.DexWarning

Directories

Path Synopsis
Package pancakeswap wraps the PancakeSwap V3 subgraph on BNB Chain.
Package pancakeswap wraps the PancakeSwap V3 subgraph on BNB Chain.
Package uniswap wraps the Uniswap V3 subgraph on Ethereum mainnet.
Package uniswap wraps the Uniswap V3 subgraph on Ethereum mainnet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL