rates

package
v1.13.13 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 27 Imported by: 2

Documentation

Index

Constants

View Source
const Pow128 = "340282366920938463463374607431768211456" // 2^128

Variables

This section is empty.

Functions

func InitCalculator added in v1.0.0

func InitCalculator(source ratesSource) *calculator

Types

type AddressKey added in v1.3.6

type AddressKey struct {
	Prefix    tlb.Uint3
	Workchain tlb.Uint8
	Hash      tlb.Bits256
}

AddressKey is an address that can be used as a key in hashmap

func (AddressKey) Compare added in v1.3.6

func (a AddressKey) Compare(other any) (int, bool)

func (AddressKey) Equal added in v1.3.6

func (a AddressKey) Equal(other any) bool

func (AddressKey) FixedSize added in v1.3.6

func (a AddressKey) FixedSize() int

type AffluentAsset added in v1.3.13

type AffluentAsset struct {
	LastUpdatedTime    int64
	StoredInterestRate float64
	TotalSupply        float64
	TotalBorrow        float64
	SupplyShare        float64
	BorrowShare        float64
	AssetAddress       tlb.MsgAddress
}

func (*AffluentAsset) SimulateAccrueInterest added in v1.3.13

func (a *AffluentAsset) SimulateAccrueInterest(currentTime int64, protocolFeeRate float64)

type Asset added in v1.3.0

type Asset struct {
	Account      ton.AccountID
	Decimals     int
	Reserve      float64
	Weight       float64 // Additional parameter for weighted pools invariants
	HoldersCount int
}

Asset represents an asset used in jetton price calculations within pools

type ExecutionResult added in v1.3.0

type ExecutionResult struct {
	Success  bool `json:"success"`
	ExitCode int  `json:"exit_code"`
	Stack    []struct {
		Type  string `json:"type"`
		Cell  string `json:"cell"`
		Slice string `json:"slice"`
		Num   string `json:"num"`
	} `json:"stack"`
}

ExecutionResult represents a result from a smart contract call

type Invariant added in v1.3.0

type Invariant int
const (
	XYInv           Invariant = iota
	X3YInv          Invariant = iota
	StableSwapInv   Invariant = iota
	WXYInv          Invariant = iota // xy with weight
	WStableSwapInv  Invariant = iota // stable swap with weight
	WRStableSwapInv Invariant = iota // stable swap with weight and rate
	SqrtPInv        Invariant = iota
)

List of available pools' invariants

type JSONAffluentAsset added in v1.3.13

type JSONAffluentAsset struct {
	LastUpdatedTime    int64          `json:"last_updated_time"`
	StoredInterestRate string         `json:"stored_interest_rate"`
	TotalSupply        string         `json:"total_supply"`
	TotalBorrow        string         `json:"total_borrow"`
	SupplyShare        string         `json:"supply_share"`
	BorrowShare        string         `json:"borrow_share"`
	AssetAddress       tlb.MsgAddress `json:"asset_address"`
}

type JSONGetPoolData added in v1.3.13

type JSONGetPoolData struct {
	Success  bool `json:"success"`
	ExitCode int  `json:"exit_code"`
	Decoded  struct {
		ProtocolFeeRate tlb.Int257          `json:"protocol_fee_rate"`
		Assets          []JSONAffluentAsset `json:"assets"`
	} `json:"decoded"`
}

type LpAsset added in v1.3.0

type LpAsset struct {
	Account     ton.AccountID
	Decimals    int
	TotalSupply *big.Int // The total supply of the liquidity provider asset
	Assets      []Asset  // A slice of Asset included in the liquidity pool
}

LpAsset represents a liquidity provider asset that holds a collection of assets in a pool

type Market added in v1.2.0

type Market struct {
	ID       int64
	Name     string // Name of the service used for price calculation
	UsdPrice float64
	URL      string
	// Converter for calculating the coin from market to USD price
	MarketPriceConverter func(respBody []byte) (float64, error)
	// Converter for calculating fiat prices
	FiatPriceConverter func(respBody []byte) (map[string]float64, error)
	// Converter for calculating jetton prices within pools
	PoolResponseConverter func(respBody []byte) ([]Pool, []LpAsset, error)
	DateUpdate            time.Time
}

type Metadata added in v1.3.13

type Metadata struct {
	Metadata struct {
		Symbol   string `json:"symbol"`
		Decimals string `json:"decimals"`
	} `json:"metadata"`
}

type Mock added in v1.1.0

type Mock struct {
	// TonApiToken the token for TonApi to increase HTTP limits is obtained from https://tonconsole.com/tonapi
	TonApiToken string
	// URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database)
	StonFiV1ResultUrl, StonFiV2ResultUrl, StonFiV2StableSwapResultUrl, SwapCoffeeResultUrl, BidaskResultUrl string
	// URL to the CSV file from the analytics service https://tonconsole.com/analytics (data is sourced from the TonApi analytics database)
	DedustResultUrl string
}

func (*Mock) GetCurrentMarketsTonPrice added in v1.2.0

func (m *Mock) GetCurrentMarketsTonPrice() ([]Market, error)

GetCurrentMarketsTonPrice shows the TON to USD price on different markets

func (*Mock) GetCurrentMarketsTrxPrice added in v1.3.1

func (m *Mock) GetCurrentMarketsTrxPrice() ([]Market, error)

GetCurrentMarketsTrxPrice shows the TRX to USD price on different markets

func (*Mock) GetCurrentRates added in v1.1.0

func (m *Mock) GetCurrentRates() (map[string]float64, error)

GetCurrentRates fetches current jetton and fiat rates

func (Mock) GetMarketsTonPrice added in v1.2.0

func (m Mock) GetMarketsTonPrice() ([]Market, error)

func (Mock) GetRates added in v1.1.0

func (m Mock) GetRates(date int64) (map[string]float64, error)

GetRates cannot request data for a specific date in the open source version It will always return data for the current day

func (Mock) GetRatesChart added in v1.1.0

func (m Mock) GetRatesChart(token string, currency string, pointsCount int, startDate *int64, endDate *int64) ([]Point, error)

GetRatesChart cannot be used to request charts for jettons in the open source version To use this method, you must save today's data from GetRates and then override the method

type Point added in v1.3.0

type Point struct {
	Timestamp int64
	Price     float64
}

type Pool

type Pool struct {
	Assets    []Asset
	Invariant Invariant // Pool's invariant (x*y, x^3*y + x*y^3 etc.)
	Amp       float64   // Additional parameter for stable swap (iterative) pool invariants
	Rate      float64   // Additional parameter for rated pools invariants
	SqrtP     big.Float // Additional parameter for sqrt price pools invariants
}

Pool represents a collection of assets in a pool

Jump to

Keyboard shortcuts

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