gas

package
v0.0.0-...-0864b09 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gas provides LiquidLane route gas prediction and Chainlink-backed gas conversion facts.

It is intentionally limited to LiquidLane adapter swap accounting: callers provide expected swap demands plus a compact adapter liquidity snapshot, and the package returns route labels and route gas units. Solver-specific settlement and payload overhead, auction/executor gas limits, price updates, bids, and economics stay outside.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RouteUnits

func RouteUnits(routes []Route) uint64

func RoutesString

func RoutesString(routes []Route) string

func UnitsForRouteAt

func UnitsForRouteAt(route Route, first bool) uint64

Types

type AdapterDemand

type AdapterDemand struct {
	Demand

	Adapter common.Address
	Vault   common.Address
}

AdapterDemand is one expected swap output scoped to its LiquidLane adapter and shared vault.

type AdapterState

type AdapterState struct {
	Vault   common.Address              `json:"vault"`
	Acquire map[common.Address]*big.Int `json:"acquire"`
}

AdapterState contains liquidity owned by one adapter.

type Demand

type Demand struct {
	Collateral common.Address
	AmountOut  *big.Int
}

Demand is one expected loan-token output from a swap through a LiquidLane adapter.

type OracleConfig

type OracleConfig struct {
	NativeUSDFeed USDFeed
	TokenUSDFeeds map[common.Address]USDFeed
}

func ParseConfig

func ParseConfig(raw RawConfig) (OracleConfig, error)

ParseConfig validates the shared gas YAML without changing its gas.* field paths.

type OracleReader

type OracleReader struct {
	// contains filtered or unexported fields
}

func NewOracleReader

func NewOracleReader(c multicaller, cfg OracleConfig) (*OracleReader, error)

func (*OracleReader) Read

func (r *OracleReader) Read(ctx context.Context, tokens []Token) (*PriceSnapshot, error)

Read validates prices against the block timestamp returned in the same latest-state batch.

func (*OracleReader) Validate

func (r *OracleReader) Validate(ctx context.Context, tokens []Token) error

Validate checks configured tokens and the timed Multicall3 surface before quoting starts.

func (*OracleReader) ValidateTokens

func (r *OracleReader) ValidateTokens(tokens []Token) error

type Prediction

type Prediction struct {
	Units  uint64
	Routes []Route
}

func Predict

func Predict(demands []Demand, st *State) Prediction

Predict returns LiquidLane adapter route gas for the demands in order.

func PredictAdapters

func PredictAdapters(demands []AdapterDemand, snapshot *Snapshot) Prediction

PredictAdapters predicts swap routes for a multi-adapter transaction. Acquire balances are consumed per adapter while free and withdrawable liquidity is consumed once across adapters sharing a vault.

type PriceSnapshot

type PriceSnapshot struct {
	// BlockTime is the timestamp returned alongside prices in the same latest-state batch.
	BlockTime time.Time
	// contains filtered or unexported fields
}

func NewPriceSnapshot

func NewPriceSnapshot(rates map[common.Address]*big.Int) *PriceSnapshot

func (*PriceSnapshot) MarshalJSON

func (s *PriceSnapshot) MarshalJSON() ([]byte, error)

func (*PriceSnapshot) TokenOutPerNative

func (s *PriceSnapshot) TokenOutPerNative(token common.Address) *big.Int

type RawConfig

type RawConfig struct {
	NativeUSDFeed string         `yaml:"nativeUsdFeed"`
	NativeMaxAge  string         `yaml:"nativeMaxAge"`
	TokenUSDFeeds []RawTokenFeed `yaml:"tokenUsdFeeds"`
}

RawConfig is the shared YAML representation of LiquidLane gas oracle configuration.

type RawTokenFeed

type RawTokenFeed struct {
	Token  string `yaml:"token"`
	Feed   string `yaml:"feed"`
	MaxAge string `yaml:"maxAge"`
}

type Route

type Route uint8

Route describes the LiquidLane adapter path a swap is expected to take.

const (
	RouteUnknown Route = iota
	RouteAcquire
	RouteAllocate
	RouteDeallocate
)

func PredictRoutes

func PredictRoutes(demands []Demand, st *State) []Route

PredictRoutes estimates the adapter route for each demand in order.

func (Route) String

func (r Route) String() string

type Snapshot

type Snapshot struct {
	Adapters map[common.Address]*AdapterState `json:"adapters"`
	Vaults   map[common.Address]*VaultState   `json:"vaults"`
}

Snapshot separates adapter-local acquire balances from shared vault liquidity.

func WithReserveBps

func WithReserveBps(snapshot *Snapshot, reserveBps int) *Snapshot

WithReserveBps returns a conservative copy of snapshot with every mutable liquidity budget reduced.

type State

type State struct {
	FreeAssets   *big.Int
	Withdrawable *big.Int
	Acquire      map[common.Address]*big.Int
}

State is the minimal LiquidLane liquidity snapshot needed for route prediction.

type Token

type Token struct {
	Address  common.Address
	Decimals int
}

type USDFeed

type USDFeed struct {
	Address common.Address
	MaxAge  time.Duration
}

type VaultState

type VaultState struct {
	FreeAssets   *big.Int `json:"freeAssets"`
	Withdrawable *big.Int `json:"withdrawable"`
}

VaultState contains liquidity shared by every adapter backed by the vault.

Jump to

Keyboard shortcuts

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