entities

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: MIT Imports: 7 Imported by: 0

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 WETH9 = map[uint]*Token{
	1:  NewNativeToken(1, common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), 18, "WETH", "Wrapped Ether"),
	3:  NewNativeToken(3, common.HexToAddress("0xc778417E063141139Fce010982780140Aa0cD5Ab"), 18, "WETH", "Wrapped Ether"),
	4:  NewNativeToken(4, common.HexToAddress("0xc778417E063141139Fce010982780140Aa0cD5Ab"), 18, "WETH", "Wrapped Ether"),
	5:  NewNativeToken(5, common.HexToAddress("0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6"), 18, "WETH", "Wrapped Ether"),
	42: NewNativeToken(42, common.HexToAddress("0xd0A1E359811322d97991E03f863a0C30C2cF029C"), 18, "WETH", "Wrapped Ether"),

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

	42161:  NewNativeToken(42161, common.HexToAddress("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"), 18, "WETH", "Wrapped Ether"),
	421611: NewNativeToken(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 Currency

type Currency struct {
	IsNative bool   // Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
	IsToken  bool   // Returns whether the currency is a token that is usable in Uniswap without wrapping
	ChainID  uint   // The chain ID on which this currency resides
	Decimals uint   // The decimals used in representing currency amounts
	Symbol   string // The symbol of the currency, i.e. a short textual non-unique identifier
	Name     string // The name of the currency, i.e. a descriptive textual non-unique identifier
}

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

func NewBaseCurrency

func NewBaseCurrency(chainID uint, decimals uint, symbol string, name string) *Currency

NewBaseCurrency constructs an instance of the `BaseCurrency`.

func NewNativeCurrency

func NewNativeCurrency(chainID uint, decimals uint, symbol string, name string) *Currency

NewNativeCurrency constructs an instrance of the `NativeCurrency`

func NewTokenCurrency

func NewTokenCurrency(chainID uint, decimals uint, symbol string, name string) *Currency

NewTokenCurrency constructs an instance of the `TokenCurrency`

func (*Currency) Equal

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

Equal returns whether the currency is equal to the other currency

type CurrencyAmount

type CurrencyAmount struct {
	*Fraction
	Currency     *Currency
	DecimalScale *big.Int
}

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) 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

type Ether

type Ether struct {
	*Currency
}

func EtherOnChain

func EtherOnChain(chainID uint) *Ether

func (*Ether) Equals

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

Equals compares two Ethers for equality

func (*Ether) Wrapped

func (e *Ether) Wrapped() *Token

type Fraction

type Fraction struct {
	Numerator   *big.Int
	Denominator *big.Int
}

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 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 {
	*Currency
	Address common.Address // The contract address on the chain on which this token lives
}

Represents an ERC20 token with a unique address and some metadata.

func NewNativeToken

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

NewNativeToken creates a new native token with the given currency and address.

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) Equals

func (t *Token) Equals(other *Token) bool

func (*Token) SortsBefore

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

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