dexsdk

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

README

dex-sdk

Go Reference

A dex(Decentralized Exchange) that supports the uniswap v2 contract variant

  • BSC(Pancake Swap V2)
  • ETH(Uniswap V2)

Installation

go version >= 1.18 Latest version

go get github.com/Jonescy/dex-sdk

Or Special version

go get github.com/Jonescy/dex-sdk@<version tag>

Usage

More example see examples/

Contribution

Please make sure your contributions adhere to our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Pull requests need to be based on and opened against the master branch.
  • Commit messages should be prefixed with the operation and package(s) they modify.
    • E.g. "fix(examples/fetchPrice), del: make trace configs optional"

All issues and PR these welcome to contribute it, thanks.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InsufficientAmountError = errors.New("insufficient amount")
	TokenExistError         = errors.New("pair not this token")
)

InsufficientAmountError errors

View Source
var BigFive = decimal.NewFromInt(5)
View Source
var BigOne = decimal.NewFromInt(1)
View Source
var BigTen = decimal.NewFromInt(10)
View Source
var BigZero = decimal.NewFromInt(0)
View Source
var FactoryAddressMap = map[ChainId]string{
	BscMain: "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
	BscTest: "0x6725f303b657a9451d8ba641348b6761a6cc7a17",
	EthMain: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
}
View Source
var FeesDenominator = decimal.NewFromInt(10000)
View Source
var FeesNumerator = decimal.NewFromInt(9975)
View Source
var InitCodeHash = map[ChainId]string{
	BscMain: "0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5",
	BscTest: "0xd0d4c4cd0848c93cb4fd1f498d7013ee6bfb25783ea21593d5834f5d250ece66",
	EthMain: "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",
}
View Source
var MinimumLiquidity = decimal.NewFromInt(1000)
View Source
var PairAddressCache = map[string]common.Address{}

PairAddressCache cache already query pair

Functions

func FormatEther

func FormatEther(wei decimal.Decimal) string

func GetAddress

func GetAddress(tokenA, tokenB Token) common.Address

GetAddress get Pair address can without Pair Constructor

func NewCaller added in v0.1.3

func NewCaller(link string) (*ethclient.Client, error)

func ParseEther

func ParseEther(i interface{}) decimal.Decimal

Types

type ChainId

type ChainId int64

ChainId Public Blockchain Known Identify

const (
	EthMain ChainId = 1  // ethereum mainnet
	Ropsten ChainId = 3  // ethereum Ropsten testnet
	Rinkeby ChainId = 4  // ethereum Rinkeby testnet
	Goerli  ChainId = 5  // ethereum Goerli testnet
	Kovan   ChainId = 42 // ethereum Kovan testnet

	BscMain ChainId = 56 // bsc mainnet
	BscTest ChainId = 97 // bsc testnet

	OkcMain ChainId = 66 // okc mainnet
	OkcTest ChainId = 65 // okc testnet

	HecoMain ChainId = 128 // heco mainnet
	HecoTest ChainId = 256 // heco testnet

	PolygonMain ChainId = 137   // polygon mainnet
	Mumbai      ChainId = 80001 // polygon mumbai testnet

	Ganache ChainId = 8545 // local testnet
)

func (ChainId) Explorer

func (chain ChainId) Explorer() string

Explorer of the chain id

func (ChainId) IsTestnet

func (chain ChainId) IsTestnet() bool

IsTestnet ...

func (ChainId) String

func (chain ChainId) String() string

String Name of the Chain id

func (ChainId) Symbol

func (chain ChainId) Symbol() string

Symbol of the chain id

type Desc

type Desc struct {
	Name   string `json:"name" yaml:"name"`     // obj name
	Symbol string `json:"symbol" yaml:"symbol"` // obj symbol
}

Desc Blockchain Object Description

type Fetcher

type Fetcher struct {
	ChainId ChainId
	// contains filtered or unexported fields
}

func NewFetcher

func NewFetcher(b bind.ContractBackend, chainId ChainId) Fetcher

func (Fetcher) GetKLast added in v0.1.3

func (f Fetcher) GetKLast(address common.Address) (*big.Int, error)

func (Fetcher) GetReverses

func (f Fetcher) GetReverses(token0, token1 Token) (Pair, error)

GetReverses currently support bsc

func (Fetcher) GetTokenInfo added in v0.1.3

func (f Fetcher) GetTokenInfo(address common.Address) (Token, error)

func (Fetcher) GetTotalSupply added in v0.1.3

func (f Fetcher) GetTotalSupply(address common.Address) (*big.Int, error)

type Pair

type Pair struct {
	LiquidityToken Token
	TokenAmounts   [2]TokenAmount
}

Pair trading pair

func NewPair

func NewPair(token0, token1 TokenAmount) Pair

NewPair Pair Constructor

func (Pair) GetInputAmount

func (p Pair) GetInputAmount(outputAmount TokenAmount) (TokenAmount, Pair, error)

GetInputAmount provide output amount calc input amount

func (Pair) GetLiquidityAmount added in v0.1.3

func (p Pair) GetLiquidityAmount(token Token, totalSupply *big.Int, liquidity TokenAmount, feeOn bool, kLast *big.Int) (TokenAmount, error)

GetLiquidityAmount get liquidity amount

func (Pair) GetLiquidityMinted

func (p Pair) GetLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB TokenAmount) (TokenAmount, error)

GetLiquidityMinted calc lp has been minted

func (Pair) GetOutputAmount

func (p Pair) GetOutputAmount(inputAmount TokenAmount) (TokenAmount, Pair, error)

GetOutputAmount provide input amount calc output amount

func (Pair) Reverse0

func (p Pair) Reverse0() TokenAmount

func (Pair) Reverse1

func (p Pair) Reverse1() TokenAmount

func (Pair) ReverseOf

func (p Pair) ReverseOf(token Token) TokenAmount

func (Pair) String

func (p Pair) String() string

func (Pair) Token0

func (p Pair) Token0() Token

func (Pair) Token1

func (p Pair) Token1() Token

type Token

type Token struct {
	Desc
	Decimals int8    `json:"decimals" yaml:"decimals"` // token decimals
	Address  string  `json:"address" yaml:"address"`   // token address
	ChainId  ChainId `json:"chainId" yaml:"chainId"`   // token chain id enum
}

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

func NewToken

func NewToken(address string, decimals int8, chainId ChainId, desc ...string) Token

NewToken Token Constructor

func (Token) Equals

func (t Token) Equals(other Token) bool

Equals judgment condition is unique address

func (Token) SortsBefore

func (t Token) SortsBefore(other Token) bool

SortsBefore check is sort before new object

func (Token) ToAddress

func (t Token) ToAddress() common.Address

ToAddress convert to ethereum common.Address

type TokenAmount

type TokenAmount struct {
	Token
	Raw decimal.Decimal
}

func NewTokenAmount

func NewTokenAmount(token Token, amount decimal.Decimal) TokenAmount

func (TokenAmount) Add

func (ta TokenAmount) Add(other TokenAmount) TokenAmount

func (TokenAmount) Sub

func (ta TokenAmount) Sub(other TokenAmount) TokenAmount

type Tokens

type Tokens struct {
	List []Token
	// contains filtered or unexported fields
}

Tokens list of unique token

func NewTokenList

func NewTokenList(list ...Token) Tokens

NewTokenList Tokens Constructor

func (Tokens) AppendAndSort

func (list Tokens) AppendAndSort(tokens ...Token)

AppendAndSort Append new token to list

func (Tokens) IsExist

func (list Tokens) IsExist(token Token) bool

IsExist check token is exist

func (*Tokens) Marshal

func (list *Tokens) Marshal() ([]byte, error)

Marshal ...

func (Tokens) Sort

func (list Tokens) Sort()

Sort ...

func (*Tokens) Unmarshal

func (list *Tokens) Unmarshal(bs []byte) error

Unmarshal ...

Directories

Path Synopsis
abi
examples

Jump to

Keyboard shortcuts

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