Documentation ¶
Index ¶
- Variables
- type Currency
- type CurrencyAmount
- func (ca *CurrencyAmount) Add(other *CurrencyAmount) *CurrencyAmount
- func (ca *CurrencyAmount) Divide(other *Fraction) *CurrencyAmount
- func (ca *CurrencyAmount) Multiply(other *Fraction) *CurrencyAmount
- func (ca *CurrencyAmount) Subtract(other *CurrencyAmount) *CurrencyAmount
- func (ca *CurrencyAmount) ToExact() string
- func (ca *CurrencyAmount) ToFixed(decimalPlaces int32) string
- func (ca *CurrencyAmount) ToSignificant(significantDigits int32) string
- type Ether
- type Fraction
- func (f *Fraction) Add(other *Fraction) *Fraction
- func (f *Fraction) Divide(other *Fraction) *Fraction
- func (f *Fraction) EqualTo(other *Fraction) bool
- func (f *Fraction) GreaterThan(other *Fraction) bool
- func (f *Fraction) Invert() *Fraction
- func (f *Fraction) LessThan(other *Fraction) bool
- func (f *Fraction) Multiply(other *Fraction) *Fraction
- func (f *Fraction) Quotient() *big.Int
- func (f *Fraction) Remainder() *Fraction
- func (f *Fraction) Subtract(other *Fraction) *Fraction
- func (f *Fraction) ToFixed(decimalPlaces int32) string
- func (f *Fraction) ToSignificant(significantDigits int32) string
- type Percent
- func (p *Percent) Add(other *Percent) *Percent
- func (p *Percent) Divide(other *Percent) *Percent
- func (p *Percent) Multiply(other *Percent) *Percent
- func (p *Percent) Subtract(other *Percent) *Percent
- func (p *Percent) ToFixed(decimalPlaces int32) string
- func (p *Percent) ToSignificant(significantDigits int32) string
- type Price
- type Rounding
- type Token
- type TradeType
Constants ¶
This section is empty.
Variables ¶
var ( ErrDifferentChain = errors.New("different chain") ErrSameAddress = errors.New("same address") )
var (
ErrDifferentCurrencies = errors.New("different currencies")
)
var MaxUint256, _ = new(big.Int).SetString("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)
var OneHundred = NewFraction(big.NewInt(100), big.NewInt(1))
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 ¶
NewBaseCurrency constructs an instance of the `BaseCurrency`.
func NewNativeCurrency ¶
NewNativeCurrency constructs an instrance of the `NativeCurrency`
func NewTokenCurrency ¶
NewTokenCurrency constructs an instance of the `TokenCurrency`
type CurrencyAmount ¶
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 ¶
type Fraction ¶
func NewFraction ¶
NewFraction creates a new fraction
func (*Fraction) GreaterThan ¶
GreaterThan returns true if the fraction is greater than the other fraction
func (*Fraction) ToSignificant ¶
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 ¶
NewPercent creates a new Percent
func (*Percent) ToFixed ¶
ToFixedFigures converts a Percent to a string with a given number of fixed figures
func (*Percent) ToSignificant ¶
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 (*Price) Multiply ¶
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) ToSignificant ¶
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.