entities

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 8 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Ownership Information

Taken and modified from https://github.com/daoleno/uniswap-sdk-core

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDifferentChain = errors.New("different chain")
	ErrSameAddress    = errors.New("same address")
)
View Source
var (
	ErrDifferentCurrencies = errors.New("different currencies")
)
View Source
var MaxUint256, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)
View Source
var OneHundred = NewFraction(big.NewInt(100), big.NewInt(1))
View Source
var USDC = map[uint]*Token{
	1: NewToken(1, common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"), 6, "USDC", "USDC Coin"),
}

Known USDC implementation addresses

View Source
var USDT = map[uint]*Token{
	1: NewToken(1, common.HexToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7"), 6, "USDT", "USDT Coin"),
}

Known USDT implementation addresses

View Source
var WETH9 = map[uint]*Token{
	1:  NewToken(1, common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), 18, "WETH", "Wrapped Ether"),
	3:  NewToken(3, common.HexToAddress("0xc778417E063141139Fce010982780140Aa0cD5Ab"), 18, "WETH", "Wrapped Ether"),
	4:  NewToken(4, common.HexToAddress("0xc778417E063141139Fce010982780140Aa0cD5Ab"), 18, "WETH", "Wrapped Ether"),
	5:  NewToken(5, common.HexToAddress("0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"), 18, "WETH", "Wrapped Ether"),
	42: NewToken(42, common.HexToAddress("0xd0A1E359811322d97991E03f863a0C30C2cF029C"), 18, "WETH", "Wrapped Ether"),

	10: NewToken(10, common.HexToAddress("0x4200000000000000000000000000000000000006"), 18, "WETH", "Wrapped Ether"),
	69: NewToken(69, common.HexToAddress("0x4200000000000000000000000000000000000006"), 18, "WETH", "Wrapped Ether"),

	42161:  NewToken(42161, common.HexToAddress("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"), 18, "WETH", "Wrapped Ether"),
	421611: NewToken(421611, common.HexToAddress("0xB47e6A5f8b33b3F17603C83a0535A9dcD7E32681"), 18, "WETH", "Wrapped Ether"),
}

Known WETH9 implementation addresses, used in our implementation of Ether#wrapped

Functions

This section is empty.

Types

type BaseCurrency

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

BaseCurrency is an abstract struct, do not use it directly

func (*BaseCurrency) ChainId

func (c *BaseCurrency) ChainId() uint

func (*BaseCurrency) Decimals

func (c *BaseCurrency) Decimals() uint

func (*BaseCurrency) Equal

func (c *BaseCurrency) Equal(other Currency) bool

Equal returns whether the currency is equal to the other currency

func (*BaseCurrency) IsNative

func (c *BaseCurrency) IsNative() bool

func (*BaseCurrency) IsToken

func (c *BaseCurrency) IsToken() bool

func (*BaseCurrency) MarshalJSON

func (c *BaseCurrency) MarshalJSON() ([]byte, error)

MarshalJSON custom method to marshal BaseCurrency to JSON.

func (*BaseCurrency) Name

func (c *BaseCurrency) Name() string

func (*BaseCurrency) Symbol

func (c *BaseCurrency) Symbol() string

func (*BaseCurrency) UnmarshalJSON

func (c *BaseCurrency) UnmarshalJSON(data []byte) error

func (*BaseCurrency) Wrapped

func (c *BaseCurrency) Wrapped() *Token

type Currency

type Currency interface {
	IsNative() bool
	IsToken() bool
	ChainId() uint
	Decimals() uint
	Symbol() string
	Name() string
	Equal(other Currency) bool
	Wrapped() *Token
}

Currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies

func NewNative

func NewNative(wrapped *Token, symbol, name string) Currency

type CurrencyAmount

type CurrencyAmount struct {
	*Fraction    `json:"fraction"`
	Currency     Currency `json:"currency"`
	DecimalScale *big.Int `json:"decimalScale"`
}

func FromFractionalAmount

func FromFractionalAmount(currency Currency, numerator *big.Int, denominator *big.Int) *CurrencyAmount

*

  • Construct a currency amount with a denominator that is not equal to 1
  • @param currency the currency
  • @param numerator the numerator of the fractional token amount
  • @param denominator the denominator of the fractional token amount

func FromRawAmount

func FromRawAmount(currency Currency, rawAmount *big.Int) *CurrencyAmount

*

  • Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
  • @param currency the currency in the amount
  • @param rawAmount the raw token or ether amount

func (*CurrencyAmount) Add

func (ca *CurrencyAmount) Add(other *CurrencyAmount) *CurrencyAmount

Add adds two currency amounts together

func (*CurrencyAmount) Divide

func (ca *CurrencyAmount) Divide(other *Fraction) *CurrencyAmount

Divide divides one currency amount by another

func (*CurrencyAmount) Multiply

func (ca *CurrencyAmount) Multiply(other *Fraction) *CurrencyAmount

Multiply multiplies two currency amounts

func (*CurrencyAmount) Subtract

func (ca *CurrencyAmount) Subtract(other *CurrencyAmount) *CurrencyAmount

Subtract subtracts one currency amount from another

func (*CurrencyAmount) ToExact

func (ca *CurrencyAmount) ToExact() string

ToExact returns the currency amount as a string with the specified number of digits after the decimal

func (*CurrencyAmount) ToExactRaw

func (ca *CurrencyAmount) ToExactRaw() decimal.Decimal

ToExact returns the currency amount as a string with the specified number of digits after the decimal

func (*CurrencyAmount) ToFixed

func (ca *CurrencyAmount) ToFixed(decimalPlaces int32) string

ToFixed returns the currency amount as a string with the specified number of digits after the decimal

func (*CurrencyAmount) ToSignificant

func (ca *CurrencyAmount) ToSignificant(significantDigits int32) string

ToSignificant returns the currency amount as a string with the most significant digits

func (*CurrencyAmount) UnmarshalJSON

func (c *CurrencyAmount) UnmarshalJSON(data []byte) error

func (*CurrencyAmount) Wrapped

func (ca *CurrencyAmount) Wrapped() *CurrencyAmount

type Ether

type Ether struct {
	*BaseCurrency
}

Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets

func EtherOnChain

func EtherOnChain(chainId uint) *Ether

func (*Ether) Equal

func (e *Ether) Equal(other Currency) bool

func (*Ether) Wrapped

func (e *Ether) Wrapped() *Token

type Fraction

type Fraction struct {
	Numerator   *big.Int `json:"numerator"`
	Denominator *big.Int `json:"denominator"`
}

func NewFraction

func NewFraction(numerator, denominator *big.Int) *Fraction

NewFraction creates a new fraction

func (*Fraction) Add

func (f *Fraction) Add(other *Fraction) *Fraction

Add adds two fractions

func (*Fraction) Divide

func (f *Fraction) Divide(other *Fraction) *Fraction

Divide divides two fractions

func (*Fraction) EqualTo

func (f *Fraction) EqualTo(other *Fraction) bool

EqualTo returns true if the fraction is equal to the other fraction

func (*Fraction) GreaterThan

func (f *Fraction) GreaterThan(other *Fraction) bool

GreaterThan returns true if the fraction is greater than the other fraction

func (*Fraction) Invert

func (f *Fraction) Invert() *Fraction

Invert inverts the fraction

func (*Fraction) LessThan

func (f *Fraction) LessThan(other *Fraction) bool

LessThan returns true if the fraction is less than the other fraction

func (*Fraction) Multiply

func (f *Fraction) Multiply(other *Fraction) *Fraction

Multiply multiplies two fractions

func (*Fraction) Quotient

func (f *Fraction) Quotient() *big.Int

Quotient performs floor division

func (*Fraction) Remainder

func (f *Fraction) Remainder() *Fraction

Remainder remainders after floor division

func (*Fraction) Subtract

func (f *Fraction) Subtract(other *Fraction) *Fraction

Subtract subtracts two fractions

func (*Fraction) ToFixed

func (f *Fraction) ToFixed(decimalPlaces int32) string

ToFixed returns a fixed string representation of the fraction

func (*Fraction) ToSignificant

func (f *Fraction) ToSignificant(significantDigits int32) string

ToSignificant returns a significant string representation of the fraction Example: NewFraction(big.NewInt(125), big.NewInt(1)).ToSignificant(2) // output: "130"

type Native

type Native struct {
	*BaseCurrency
	// contains filtered or unexported fields
}

func (*Native) Equal

func (n *Native) Equal(other Currency) bool

func (*Native) Wrapped

func (n *Native) Wrapped() *Token

type Percent

type Percent struct {
	*Fraction
}

func NewPercent

func NewPercent(numerator, denominator *big.Int) *Percent

NewPercent creates a new Percent

func (*Percent) Add

func (p *Percent) Add(other *Percent) *Percent

Add adds two Percent

func (*Percent) Divide

func (p *Percent) Divide(other *Percent) *Percent

Divide divides two Percent

func (*Percent) Multiply

func (p *Percent) Multiply(other *Percent) *Percent

Multiply multiplies two Percent

func (*Percent) Subtract

func (p *Percent) Subtract(other *Percent) *Percent

Subtract subtracts two Percent

func (*Percent) ToFixed

func (p *Percent) ToFixed(decimalPlaces int32) string

ToFixedFigures converts a Percent to a string with a given number of fixed figures

func (*Percent) ToSignificant

func (p *Percent) ToSignificant(significantDigits int32) string

ToSignificant converts a Percent to a string with a given number of significant figures

type Price

type Price struct {
	*Fraction
	BaseCurrency  Currency  // input i.e. denominator
	QuoteCurrency Currency  // output i.e. numerator
	Scalar        *Fraction // used to adjust the raw fraction w/r/t the decimals of the {base,quote}Token
}

func NewPrice

func NewPrice(baseCurrency, quoteCurrency Currency, denominator, numerator *big.Int) *Price

Construct a price, either with the base and quote currency amount, or the args

func (*Price) Invert

func (p *Price) Invert() *Price

Invert flips the price, switching the base and quote currency

func (*Price) Multiply

func (p *Price) Multiply(other *Price) (*Price, error)

Multiply Multiplies the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency

func (*Price) Quote

func (p *Price) Quote(currencyAmount *CurrencyAmount) (*CurrencyAmount, error)

Quote returns the amount of quote currency corresponding to a given amount of the base currency

func (*Price) ToFixed

func (p *Price) ToFixed(decimalPlaces int32) string

func (*Price) ToSignificant

func (p *Price) ToSignificant(significantDigits int32) string

type Rounding

type Rounding int
const (
	RoundDown Rounding = iota
	RoundHalfUp
	RoundUp
)

type Token

type Token struct {
	*BaseCurrency
	Address common.Address `json:"address"` // The contract address on the chain on which this token lives
}

Token represents an ERC20 token with a unique address and some metadata.

func NewToken

func NewToken(chainID uint, address common.Address, decimals uint, symbol string, name string) *Token

NewToken creates a new token with the given currency and address.

func (*Token) Equal

func (t *Token) Equal(other Currency) bool

Equal *

  • Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
  • @param other token to compare

func (*Token) SortsBefore

func (t *Token) SortsBefore(other *Token) (bool, error)

SortsBefore *

  • Returns true if the address of this token sorts before the address of the other token
  • @param other other token to compare
  • @throws if the tokens have the same address
  • @throws if the tokens are on different chains

func (*Token) Wrapped

func (t *Token) Wrapped() *Token

type TradeType

type TradeType int
const (
	ExactInput TradeType = iota
	ExactOutput
)

Jump to

Keyboard shortcuts

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