tokens

package
v3.0.0-...-e8b7a4c Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

How to research a blockchain and add cross-chain bridge or router supporting

1. retrieve blockchain resources

blockchain full nodes (mainnet, testnet, devnet, etc.)

blockchain basics
	chainid (some blockchains has no chainID, we can assign them a stub one)
	consensus (PoW, PoS, PoA, etc.)
	algorithm of signing(ec256k1, ed25519, etc.)
	address and public key format(hex, base58, etc.))
		storage model
		balance query
	native token (eg. ETH)
	system token/asset (eg. ERC20, BEP20, etc.)
		standard interface
		balance query
	cross-chain mechanism
		use memo (specify a custom memo in deposit transaction)
		use smart contracts (AnyswapRouter, AnyswapERC20, or others)
	smart contract
		is smart contract supportable?
		smart contract development language: solidity, wasm or others?
		how to write custom smart contract like AnyswapRouter and AnyswapERC20?
			owner/minter
			mint/burn
			deposit/withdraw
			swapin/swapout
		how to deploy smart contract?
		how to use rpc calling to get contract infos (eg. decimals, underlying, etc)?
		how to generate cross-chain related logs, and how to verify these logs?


blockchain explorer (verifing smart contracts)

developer documents (concept, rpc api, etc.)

sdk tools (nodejs, golang, rust, c++, java, etc.)

wallet usage (metamask, browser, plugin, app, etc.)

blockchain ecology (supported exchanges, dex exchanges, uniswap, exist cross-chain projects, tvl, etc.)

commnication channels (wecahat, telagram, facebook, twitter, email, etc.)

2. add cross-chain bridge or router supporting

2.1 verify swapout tx from this blockchain

common considerations

initial height (ignore tx before initial height)

stable height (tx maybe rollbacked)

success status (tx myabe failed)

filtered logs (tx maybe have no corresponding logs)

parse memos if use memo cross-chain mechanism
2.2 send swapin tx to this blockchain

common considerations

account nonce or sequence (if support, then use it to prevent duplicate sending tx)

algorithm of signing (ec, ed, etc.)

sign content (message hash, message content, messge content with prefix or suffix, etc.)

mpc sign public key (we may need convert blockchain specifically encoded public key to mpc sign public key)

calc signed transaction hash (calc offline instead of get result from rpc calling as rpc maybe timeout)

Documentation

Overview

Package tokens defines the common interfaces and supported bridges in sub directories.

Index

Constants

View Source
const (
	MaxStandardTokenVersion = uint64(10000)
	MinWrapperTokenVersion  = uint64(20000)
)

token version boundaries

View Source
const (
	CurveAnycallSubType = "curve"
	AnycallSubTypeV5    = "v5" // for curve
	AnycallSubTypeV6    = "v6" // for hundred
	AnycallSubTypeV7    = "v7" // add callback
)

SwapSubType constants

Variables

View Source
var (
	AggregateIdentifier = "aggregate"

	// StubChainIDBase stub chainID base value
	StubChainIDBase = big.NewInt(1000000000000)
)
View Source
var (
	ErrNotImplemented         = errors.New("not implemented")
	ErrSwapTypeNotSupported   = errors.New("swap type not supported")
	ErrUnknownSwapSubType     = errors.New("unknown swap sub type")
	ErrNoBridgeForChainID     = errors.New("no bridge for chain id")
	ErrSwapTradeNotSupport    = errors.New("swap trade not support")
	ErrNonceNotSupport        = errors.New("nonce not support")
	ErrNotFound               = errors.New("not found")
	ErrTxNotFound             = errors.New("tx not found")
	ErrDepositNotFound        = errors.New("deposit not found")
	ErrTxNotStable            = errors.New("tx not stable")
	ErrLogIndexOutOfRange     = errors.New("log index out of range")
	ErrTxWithWrongReceipt     = errors.New("tx with wrong receipt")
	ErrTxWithWrongReceiver    = errors.New("tx with wrong receiver")
	ErrTxWithWrongContract    = errors.New("tx with wrong contract")
	ErrTxWithWrongTopics      = errors.New("tx with wrong log topics")
	ErrSwapoutLogNotFound     = errors.New("swapout log not found or removed")
	ErrSwapoutPatternMismatch = errors.New("swapout pattern mismatch")
	ErrTxWithRemovedLog       = errors.New("tx with removed log")
	ErrWrongBindAddress       = errors.New("wrong bind address")
	ErrWrongRawTx             = errors.New("wrong raw tx")
	ErrUnsupportedFuncHash    = errors.New("unsupported method func hash")
	ErrWrongCountOfMsgHashes  = errors.New("wrong count of msg hashed")
	ErrMsgHashMismatch        = errors.New("message hash mismatch")
	ErrSwapInBlacklist        = errors.New("swap is in black list")
	ErrTxBeforeInitialHeight  = errors.New("transaction before initial block height")
	ErrEstimateGasFailed      = errors.New("estimate gas failed")
	ErrRPCQueryError          = errors.New("rpc query error")
	ErrMissDynamicFeeConfig   = errors.New("miss dynamic fee config")
	ErrFromChainIDMismatch    = errors.New("from chainID mismatch")
	ErrSameFromAndToChainID   = errors.New("from and to chainID are same")
	ErrMissMPCPublicKey       = errors.New("miss mpc public key config")
	ErrMissRouterInfo         = errors.New("miss router info")
	ErrRouterVersionMismatch  = errors.New("router version mismatch")
	ErrSenderMismatch         = errors.New("sender mismatch")
	ErrTxWithWrongSender      = errors.New("tx with wrong sender")
	ErrToChainIDMismatch      = errors.New("to chainID mismatch")
	ErrTxWithWrongStatus      = errors.New("tx with wrong status")
	ErrUnknownSwapoutType     = errors.New("unknown swapout type")
	ErrEmptyTokenID           = errors.New("empty tokenID")
	ErrNoEnoughReserveBudget  = errors.New("no enough reserve budget")
	ErrTxWithNoPayment        = errors.New("tx with no payment")
	ErrTxIsNotValidated       = errors.New("tx is not validated")
	ErrPauseSwapInto          = errors.New("maintain: pause swap into")
	ErrBuildTxErrorAndDelay   = errors.New("[build tx error]")
	ErrSwapoutIDNotExist      = errors.New("swapoutID not exist")
	ErrValidPublicKey         = errors.New("valid public key error")
	ErrBroadcastTx            = errors.New("broadcast tx error")
	ErrSimulateTx             = errors.New("simulate tx error")
	ErrTxWithWrongMemo        = errors.New("tx with wrong memo")
	ErrFallbackNotSupport     = errors.New("app does not support fallback")
	ErrQueryTokenBalance      = errors.New("query token balance error")
	ErrTokenBalanceNotEnough  = errors.New("token balance not enough")
	ErrGetLatestBlockNumber   = errors.New("get latest block number error")
	ErrGetAccountNonce        = errors.New("get account nonce error")
	ErrGetUnderlying          = errors.New("get underlying address error")
	ErrGetMPC                 = errors.New("get mpc address error")
	ErrTokenDecimals          = errors.New("get token decimals error")
	ErrGetLatestBlockHash     = errors.New("get latest block hash error")
	ErrTxResultType           = errors.New("tx type is not TransactionResult")
	ErrGetNodeInfo            = errors.New("err to get node info")
	ErrPayloadType            = errors.New("payload type error")
	ErrGetOutPutIDs           = errors.New("get output id error")
	ErrGetOutPutByID          = errors.New("get output by id error")
	ErrCommitMessage          = errors.New("commit message error")
	ErrProofOfWork            = errors.New("proof of work error")
	ErrBalanceNoKeepAlive     = errors.New("balance can't keep alive")
	ErrSwapValueTooLess       = errors.New("swap value must bigger than 1000000")
	ErrCheckBalance           = errors.New("check balance error")
	ErrInputAndOutputLength   = errors.New("input and output must bigger than one")
	ErrTxWithWrongAssetLength = errors.New("tx with wrong asset length")
	ErrOutputLength           = errors.New("output lenght is zero")
	ErrMpcAddrMissMatch       = errors.New("receiver addr not match mpc addr")
	ErrMetadataKeyMissMatch   = errors.New("metadata key not match 123")
	ErrAdaSwapOutAmount       = errors.New("swap ada amount too small")
	ErrTokenBalancesNotEnough = errors.New("token balance not enough")
	ErrBalanceNotEnough       = errors.New("balance not enough")
	ErrAdaBalancesNotEnough   = errors.New("ada balance not enough")
	ErrOutputIndexSort        = errors.New("output not order by index asc")
	ErrCmdArgVerify           = errors.New("cmd args verify fails")
	ErrAggregateTx            = errors.New("aggregate tx fails")
	ErrNilSwapValue           = errors.New("swap value is nil")
	ErrMessageSentNotFound    = errors.New("message sent not found")
	ErrNoAttestationServer    = errors.New("no attesttation server")
	ErrGetAttestationFailed   = errors.New("get attesttation failed")
	ErrTxWithoutSigner        = errors.New("tx without signer")
	ErrReswapNotSupport       = errors.New("reswap not support")
	ErrTxWithZeroValue        = errors.New("tx with zero value")
	ErrGetBlockNumberByID     = errors.New("get block number by id error")
	ErrSendTx                 = errors.New("send tx fails")
	ErrGetAccount             = errors.New("get account fails")
)

common errors

View Source
var (
	ErrTxWithWrongValue  = errors.New("tx with wrong value")
	ErrTxWithWrongPath   = errors.New("swap trade tx with wrong path")
	ErrMissTokenConfig   = errors.New("miss token config")
	ErrNoUnderlyingToken = errors.New("no underlying token")
	ErrVerifyTxUnsafe    = errors.New("[tx maybe unsafe]")
	ErrSwapoutForbidden  = errors.New("swapout forbidden")
)

errors should register in router swap

Functions

func CalcSwapValue

func CalcSwapValue(tokenID, fromChainID, toChainID string, value *big.Int, fromDecimals, toDecimals uint8, originFrom, originTxTo string) *big.Int

CalcSwapValue calc swap value (get rid of fee and convert by decimals)

func CheckTokenSwapValue

func CheckTokenSwapValue(swapInfo *SwapTxInfo, fromDecimals, toDecimals uint8) bool

CheckTokenSwapValue check swap value is in right range

func ConvertTokenValue

func ConvertTokenValue(fromValue *big.Int, fromDecimals, toDecimals uint8) *big.Int

ConvertTokenValue convert token value

func GetBigValueThreshold

func GetBigValueThreshold(tokenID, fromChainID, toChainID string, fromDecimals uint8) *big.Int

GetBigValueThreshold get big value threshold

func InitRouterSwapType

func InitRouterSwapType(swapTypeStr string)

InitRouterSwapType init router swap type

func IsAnyCallRouter

func IsAnyCallRouter() bool

IsAnyCallRouter is anycall router

func IsERC20Router

func IsERC20Router() bool

IsERC20Router is erc20 router

func IsNFTRouter

func IsNFTRouter() bool

IsNFTRouter is nft router

func IsNativeCoin

func IsNativeCoin(name string) bool

IsNativeCoin is native coin

func IsRPCQueryOrNotFoundError

func IsRPCQueryOrNotFoundError(err error) bool

IsRPCQueryOrNotFoundError is rpc or not found error

func IsValidAnycallSubType

func IsValidAnycallSubType(subType string) bool

IsValidAnycallSubType is valid anycall subType

func RPCCall

func RPCCall(result interface{}, urls []string, method string, params ...interface{}) (err error)

RPCCall common RPC calling

func RPCCallWithTimeout

func RPCCallWithTimeout(timeout int, result interface{}, urls []string, method string, params ...interface{}) (err error)

RPCCallWithTimeout common RPC calling with specified timeout

func SetFeeConfigs

func SetFeeConfigs(feeCfgs *sync.Map)

SetFeeConfigs set fee configs

func SetOnchainCustomConfig

func SetOnchainCustomConfig(chainID, tokenID string, config *OnchainCustomConfig)

SetOnchainCustomConfig set onchain custom config

func SetSwapConfigs

func SetSwapConfigs(swapCfgs *sync.Map)

SetSwapConfigs set swap configs

func ShouldRegisterRouterSwapForError

func ShouldRegisterRouterSwapForError(err error) bool

ShouldRegisterRouterSwapForError return true if this error should record in database

func ToBits

func ToBits(valueStr string, decimals uint8) *big.Int

ToBits calc

func WrapRPCQueryError

func WrapRPCQueryError(err error, method string, params ...interface{}) error

WrapRPCQueryError wrap rpc error

Types

type AllExtras

type AllExtras struct {
	Gas         *uint64       `json:"gas,omitempty"`
	GasPrice    *big.Int      `json:"gasPrice,omitempty"`
	GasTipCap   *big.Int      `json:"gasTipCap,omitempty"`
	GasFeeCap   *big.Int      `json:"gasFeeCap,omitempty"`
	Sequence    *uint64       `json:"sequence,omitempty"`
	ReplaceNum  uint64        `json:"replaceNum,omitempty"`
	Fee         *string       `json:"fee,omitempty"`
	RawTx       hexutil.Bytes `json:"rawTx,omitempty"`
	BlockHash   *string       `json:"blockHash,omitempty"`
	BlockID     *string       `json:"blockID,omitempty"`
	BlockNumber *uint64       `json:"blockNumber,omitempty"`
	TTL         *uint64       `json:"ttl,omitempty"`
	BridgeFee   *big.Int      `json:"bridgeFee,omitempty"`
}

AllExtras struct

type AnyCallSwapInfo

type AnyCallSwapInfo struct {
	CallFrom string        `json:"callFrom"`
	CallTo   string        `json:"callTo"`
	CallData hexutil.Bytes `json:"callData"`
	Fallback string        `json:"fallback,omitempty"`
	Flags    string        `json:"flags,omitempty"`
	AppID    string        `json:"appid,omitempty"`
	Nonce    string        `json:"nonce,omitempty"`
	ExtData  hexutil.Bytes `json:"extdata,omitempty"`

	Message     hexutil.Bytes `json:"message,omitempty"`
	Attestation hexutil.Bytes `json:"attestation,omitempty"`
}

AnyCallSwapInfo struct

type BuildTxArgs

type BuildTxArgs struct {
	SwapArgs    `json:"swapArgs,omitempty"`
	From        string         `json:"from,omitempty"`
	To          string         `json:"to,omitempty"`
	OriginFrom  string         `json:"originFrom,omitempty"`
	OriginTxTo  string         `json:"originTxTo,omitempty"`
	OriginValue *big.Int       `json:"originValue,omitempty"`
	SwapValue   *big.Int       `json:"swapValue,omitempty"`
	Value       *big.Int       `json:"value,omitempty"`
	Memo        string         `json:"memo,omitempty"`
	Selector    string         `json:"selector,omitempty"`
	Input       *hexutil.Bytes `json:"input,omitempty"`
	Extra       *AllExtras     `json:"extra,omitempty"`
}

BuildTxArgs struct

func (*BuildTxArgs) GetExtraArgs

func (args *BuildTxArgs) GetExtraArgs() *BuildTxArgs

GetExtraArgs get extra args

func (*BuildTxArgs) GetReplaceNum

func (args *BuildTxArgs) GetReplaceNum() uint64

GetReplaceNum get rplace swap count

func (*BuildTxArgs) GetTxNonce

func (args *BuildTxArgs) GetTxNonce() uint64

GetTxNonce get tx nonce

func (*BuildTxArgs) GetUniqueSwapIdentifier

func (args *BuildTxArgs) GetUniqueSwapIdentifier() string

GetUniqueSwapIdentifier get unique swap identifier

func (*BuildTxArgs) SetTxNonce

func (args *BuildTxArgs) SetTxNonce(nonce uint64)

SetTxNonce set tx nonce

type ChainConfig

type ChainConfig struct {
	ChainID        string
	BlockChain     string
	RouterContract string
	RouterVersion  string
	Confirmations  uint64
	InitialHeight  uint64
	Extra          string
	// contains filtered or unexported fields
}

ChainConfig struct

func (*ChainConfig) CheckConfig

func (c *ChainConfig) CheckConfig() (err error)

CheckConfig check chain config

func (*ChainConfig) GetChainID

func (c *ChainConfig) GetChainID() *big.Int

GetChainID get chainID of number

type CrossChainBridgeBase

type CrossChainBridgeBase struct {
	ChainConfig    *ChainConfig
	GatewayConfig  *GatewayConfig
	TokenConfigMap *sync.Map // key is token address

	RPCClientTimeout int

	UseFastMPC                bool
	DontCheckAddressMixedCase bool
}

CrossChainBridgeBase base bridge

func NewCrossChainBridgeBase

func NewCrossChainBridgeBase() *CrossChainBridgeBase

NewCrossChainBridgeBase new base bridge

func (*CrossChainBridgeBase) GetBalance

func (b *CrossChainBridgeBase) GetBalance(account string) (*big.Int, error)

GetBalance get balance is used for checking budgets to prevent DOS attacking

func (*CrossChainBridgeBase) GetChainConfig

func (b *CrossChainBridgeBase) GetChainConfig() *ChainConfig

GetChainConfig get chain config

func (*CrossChainBridgeBase) GetGatewayConfig

func (b *CrossChainBridgeBase) GetGatewayConfig() *GatewayConfig

GetGatewayConfig get gateway config

func (*CrossChainBridgeBase) GetRouterContract

func (b *CrossChainBridgeBase) GetRouterContract(token string) string

GetRouterContract get router contract

func (*CrossChainBridgeBase) GetRouterVersion

func (b *CrossChainBridgeBase) GetRouterVersion(token string) string

GetRouterVersion get router version

func (*CrossChainBridgeBase) GetTokenConfig

func (b *CrossChainBridgeBase) GetTokenConfig(token string) *TokenConfig

GetTokenConfig get token config

func (*CrossChainBridgeBase) InitAfterConfig

func (b *CrossChainBridgeBase) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*CrossChainBridgeBase) InitRouterInfo

func (b *CrossChainBridgeBase) InitRouterInfo(routerContract, routerVersion string) (err error)

InitRouterInfo init router info

func (*CrossChainBridgeBase) SetChainConfig

func (b *CrossChainBridgeBase) SetChainConfig(chainCfg *ChainConfig)

SetChainConfig set chain config

func (*CrossChainBridgeBase) SetGatewayConfig

func (b *CrossChainBridgeBase) SetGatewayConfig(gatewayCfg *GatewayConfig)

SetGatewayConfig set gateway config

func (*CrossChainBridgeBase) SetTokenConfig

func (b *CrossChainBridgeBase) SetTokenConfig(token string, tokenCfg *TokenConfig)

SetTokenConfig set token config

type ERC20SwapInfo

type ERC20SwapInfo struct {
	Token     string `json:"token"`
	TokenID   string `json:"tokenID"`
	SwapoutID string `json:"swapoutID,omitempty"`

	CallProxy string        `json:"callProxy,omitempty"`
	CallData  hexutil.Bytes `json:"callData,omitempty"`
}

ERC20SwapInfo struct

type FeeConfig

type FeeConfig struct {
	MaximumSwapFee        *big.Int
	MinimumSwapFee        *big.Int
	SwapFeeRatePerMillion uint64
}

FeeConfig struct

func GetFeeConfig

func GetFeeConfig(tokenID, fromChainID, toChainID string) *FeeConfig

GetFeeConfig get fee config

func (*FeeConfig) CheckConfig

func (c *FeeConfig) CheckConfig() error

CheckConfig check fee config

type GatewayConfig

type GatewayConfig struct {
	APIAddress         []string
	APIAddressExt      []string `json:",omitempty"`
	EVMAPIAddress      []string `json:",omitempty"`
	FinalizeAPIAddress []string `json:",omitempty"`
	GRPCAPIAddress     []string `json:",omitempty"`

	// internal usage
	AdjustContext interface{} `toml:"-" json:"-"`

	// adjust gateway related
	OriginAllGatewayURLs []string `toml:"-" json:"-"`
	AllGatewayURLs       []string `toml:"-" json:"-"`
}

GatewayConfig struct

func (*GatewayConfig) IsEmpty

func (c *GatewayConfig) IsEmpty() bool

IsEmpty is not configed

type IBridge

type IBridge interface {
	IBridgeConfg
	IMPCSign

	InitRouterInfo(routerContract, routerVersion string) error
	InitAfterConfig()

	RegisterSwap(txHash string, args *RegisterArgs) ([]*SwapTxInfo, []error)
	VerifyTransaction(txHash string, ars *VerifyArgs) (*SwapTxInfo, error)
	BuildRawTransaction(args *BuildTxArgs) (rawTx interface{}, err error)
	SendTransaction(signedTx interface{}) (txHash string, err error)

	GetTransaction(txHash string) (interface{}, error)
	GetTransactionStatus(txHash string) (*TxStatus, error)
	GetLatestBlockNumber() (uint64, error)
	GetLatestBlockNumberOf(url string) (uint64, error)

	IsValidAddress(address string) bool
	PublicKeyToAddress(pubKeyHex string) (string, error)

	// GetBalance get balance is used for checking budgets
	// to prevent DOS attacking (used in any`call)
	GetBalance(account string) (*big.Int, error)
}

IBridge interface

type IBridgeConfg

type IBridgeConfg interface {
	GetGatewayConfig() *GatewayConfig
	GetChainConfig() *ChainConfig
	GetTokenConfig(tokenAddr string) *TokenConfig

	GetRouterContract(token string) string
	GetRouterVersion(token string) string

	SetChainConfig(chainCfg *ChainConfig)
	SetGatewayConfig(gatewayCfg *GatewayConfig)
	SetTokenConfig(token string, tokenCfg *TokenConfig)
}

IBridgeConfg interface implemented by 'CrossChainBridgeBase'

type IMPCSign

type IMPCSign interface {
	VerifyMsgHash(rawTx interface{}, msgHash []string) error
	MPCSignTransaction(rawTx interface{}, args *BuildTxArgs) (signedTx interface{}, txHash string, err error)
}

IMPCSign interface

type ISwapTrade

type ISwapTrade interface {
	GetPairFor(factory, token0, token1 string) (string, error)
}

ISwapTrade interface

type NFTSwapInfo

type NFTSwapInfo struct {
	Token   string        `json:"token"`
	TokenID string        `json:"tokenID"`
	IDs     []*big.Int    `json:"ids"`
	Amounts []*big.Int    `json:"amounts"`
	Batch   bool          `json:"batch"`
	Data    hexutil.Bytes `json:"data,omitempty"`
}

NFTSwapInfo struct

type NonceSetter

type NonceSetter interface {
	InitSwapNonce(br NonceSetter, address string, nonce uint64)

	// sequential
	GetPoolNonce(address, height string) (uint64, error)
	SetNonce(address string, value uint64)
	AdjustNonce(address string, value uint64) (nonce uint64)

	// parallel
	AllocateNonce(args *BuildTxArgs) (nonce uint64, err error)
	RecycleSwapNonce(sender string, nonce uint64)
}

NonceSetter interface (for eth-like)

type OnchainCustomConfig

type OnchainCustomConfig struct {
	AdditionalSrcChainSwapFeeRate uint64
	AdditionalSrcMinimumSwapFee   *big.Int
	AdditionalSrcMaximumSwapFee   *big.Int
}

OnchainCustomConfig onchain custom config (in router config)

func GetOnchainCustomConfig

func GetOnchainCustomConfig(chainID, tokenID string) *OnchainCustomConfig

GetOnchainCustomConfig get onchain custom config

type ReSwapable

type ReSwapable interface {
	SetTxTimeout(args *BuildTxArgs, txTimeout *uint64)
	GetCurrentThreshold() (*uint64, error)
	IsTxTimeout(txValue, currentValue *uint64) bool
	SetReswapMaxValueRate(rate uint64)
	SetTimeoutConfig(txTimeout uint64)
	GetTimeoutConfig() uint64
}

type RegisterArgs

type RegisterArgs struct {
	SwapType SwapType `json:"swaptype,omitempty"`
	LogIndex int      `json:"logIndex,omitempty"`
}

RegisterArgs struct

type StatusInterface

type StatusInterface interface {
	IsStatusOk() bool
}

StatusInterface interface

type SwapArgs

type SwapArgs struct {
	SwapInfo    `json:"swapinfo"`
	Identifier  string   `json:"identifier,omitempty"`
	SwapID      string   `json:"swapid,omitempty"`
	SwapType    SwapType `json:"swaptype,omitempty"`
	Bind        string   `json:"bind,omitempty"`
	LogIndex    int      `json:"logIndex"`
	FromChainID *big.Int `json:"fromChainID"`
	ToChainID   *big.Int `json:"toChainID"`
	Reswapping  bool     `json:"reswapping,omitempty"`
}

SwapArgs struct

type SwapConfig

type SwapConfig struct {
	MaximumSwap       *big.Int
	MinimumSwap       *big.Int
	BigValueThreshold *big.Int
}

SwapConfig struct

func GetSwapConfig

func GetSwapConfig(tokenID, fromChainID, toChainID string) *SwapConfig

GetSwapConfig get swap config

func (*SwapConfig) CheckConfig

func (c *SwapConfig) CheckConfig() error

CheckConfig check swap config

type SwapInfo

type SwapInfo struct {
	ERC20SwapInfo   *ERC20SwapInfo   `json:"routerSwapInfo,omitempty"`
	NFTSwapInfo     *NFTSwapInfo     `json:"nftSwapInfo,omitempty"`
	AnyCallSwapInfo *AnyCallSwapInfo `json:"anycallSwapInfo2,omitempty"`
}

SwapInfo struct

func (*SwapInfo) GetToken

func (s *SwapInfo) GetToken() string

GetToken get token

func (*SwapInfo) GetTokenID

func (s *SwapInfo) GetTokenID() string

GetTokenID get tokenID

type SwapTxInfo

type SwapTxInfo struct {
	SwapInfo    `json:"swapinfo"`
	SwapType    SwapType `json:"swaptype"`
	Hash        string   `json:"hash"`
	Height      uint64   `json:"height"`
	Timestamp   uint64   `json:"timestamp"`
	From        string   `json:"from"`
	TxTo        string   `json:"txto"`
	To          string   `json:"to"`
	Bind        string   `json:"bind"`
	Value       *big.Int `json:"value"`
	LogIndex    int      `json:"logIndex"`
	FromChainID *big.Int `json:"fromChainID"`
	ToChainID   *big.Int `json:"toChainID"`
}

SwapTxInfo struct

type SwapType

type SwapType uint32

SwapType type

const (
	UnknownSwapType SwapType = iota
	ERC20SwapType
	NFTSwapType
	AnyCallSwapType

	// special flags, do not use in register
	ERC20SwapTypeMixPool
	SapphireRPCType

	MaxValidSwapType
)

SwapType constants

func GetRouterSwapType

func GetRouterSwapType() SwapType

GetRouterSwapType get router swap type

func (SwapType) IsValidType

func (s SwapType) IsValidType() bool

IsValidType is valid swap type

func (SwapType) String

func (s SwapType) String() string

type TokenConfig

type TokenConfig struct {
	TokenID         string
	Decimals        uint8
	ContractAddress string
	ContractVersion uint64
	RouterContract  string
	RouterVersion   string
	Extra           string

	Checked bool `json:"-"`
	// contains filtered or unexported fields
}

TokenConfig struct

func (*TokenConfig) CheckConfig

func (c *TokenConfig) CheckConfig() error

CheckConfig check token config

func (*TokenConfig) GetUnderlying

func (c *TokenConfig) GetUnderlying() string

GetUnderlying get underlying

func (*TokenConfig) IsStandardTokenVersion

func (c *TokenConfig) IsStandardTokenVersion() bool

IsStandardTokenVersion is standard token version

func (*TokenConfig) IsWrapperTokenVersion

func (c *TokenConfig) IsWrapperTokenVersion() bool

IsWrapperTokenVersion is wrapper token version

func (*TokenConfig) SetUnderlying

func (c *TokenConfig) SetUnderlying(underlying string)

SetUnderlying set underlying

type TxStatus

type TxStatus struct {
	Receipt       interface{} `json:"receipt,omitempty"`
	Confirmations uint64      `json:"confirmations"`
	BlockHeight   uint64      `json:"block_height"`
	BlockHash     string      `json:"block_hash"`
	BlockTime     uint64      `json:"block_time,omitempty"`
}

TxStatus struct

func (*TxStatus) IsSwapTxOnChain

func (s *TxStatus) IsSwapTxOnChain() bool

IsSwapTxOnChain is tx onchain

func (*TxStatus) IsSwapTxOnChainAndFailed

func (s *TxStatus) IsSwapTxOnChainAndFailed() bool

IsSwapTxOnChainAndFailed to make failed of swaptx

type VerifyArgs

type VerifyArgs struct {
	SwapType      SwapType `json:"swaptype,omitempty"`
	LogIndex      int      `json:"logIndex,omitempty"`
	AllowUnstable bool     `json:"allowUnstable,omitempty"`
}

VerifyArgs struct

Directories

Path Synopsis
tweetnacl
tweetnacl-go is a port of Dan Bernstein's "crypto library in a 100 tweets" code to the Go language.
tweetnacl-go is a port of Dan Bernstein's "crypto library in a 100 tweets" code to the Go language.
btc
eth
Package eth implements the bridge interfaces to support routering.
Package eth implements the bridge interfaces to support routering.
abicoder
Package abicoder is simple tool to pack datas like solidity abi.
Package abicoder is simple tool to pack datas like solidity abi.
rubblelabs/ripple/config
Package config provides a simple way of signing submitting groups of transactions for the same account.
Package config provides a simple way of signing submitting groups of transactions for the same account.
rubblelabs/ripple/data
Package data aims to provides all the data types that are needed to build tools, clients and servers for use on the Ripple network.
Package data aims to provides all the data types that are needed to build tools, clients and servers for use on the Ripple network.
btc
Package eth test eth router by implementing `tokens.IBridge` interface.
Package eth test eth router by implementing `tokens.IBridge` interface.
eth
Package eth test eth router by implementing `tokens.IBridge` interface.
Package eth test eth router by implementing `tokens.IBridge` interface.
flow
Package eth test eth router by implementing `tokens.IBridge` interface.
Package eth test eth router by implementing `tokens.IBridge` interface.
stellar
Package eth test eth router by implementing `tokens.IBridge` interface.
Package eth test eth router by implementing `tokens.IBridge` interface.
abicoder
Package abicoder is simple tool to pack datas like solidity abi.
Package abicoder is simple tool to pack datas like solidity abi.

Jump to

Keyboard shortcuts

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