Documentation
¶
Overview ¶
Package tokens defines the common interfaces and supported bridges in sub directories.
Index ¶
- Constants
- Variables
- func CalcSwapValue(tokenID, toChainID string, value *big.Int, fromDecimals, toDecimals uint8, ...) *big.Int
- func CheckTokenSwapValue(swapInfo *SwapTxInfo, fromDecimals, toDecimals uint8) bool
- func ConvertTokenValue(fromValue *big.Int, fromDecimals, toDecimals uint8) *big.Int
- func GetBigValueThreshold(tokenID, toChainID string, fromDecimals uint8) *big.Int
- func InitRouterSwapType(swapTypeStr string)
- func IsAnyCallRouter() bool
- func IsERC20Router() bool
- func IsNFTRouter() bool
- func IsNativeCoin(name string) bool
- func IsRPCQueryOrNotFoundError(err error) bool
- func RPCCall(result interface{}, urls []string, method string, params ...interface{}) (err error)
- func RPCCallWithTimeout(timeout int, result interface{}, urls []string, method string, ...) (err error)
- func SetSwapConfigs(swapCfgs map[string]map[string]*SwapConfig)
- func ShouldRegisterRouterSwapForError(err error) bool
- func ToBits(valueStr string, decimals uint8) *big.Int
- func WrapRPCQueryError(err error, method string, params ...interface{}) error
- type AllExtras
- type AnyCallSwapInfo
- type BuildTxArgs
- type ChainConfig
- type CrossChainBridgeBase
- func (b *CrossChainBridgeBase) GetChainConfig() *ChainConfig
- func (b *CrossChainBridgeBase) GetGatewayConfig() *GatewayConfig
- func (b *CrossChainBridgeBase) GetRouterContract(token string) string
- func (b *CrossChainBridgeBase) GetTokenConfig(token string) *TokenConfig
- func (b *CrossChainBridgeBase) InitAfterConfig()
- func (b *CrossChainBridgeBase) RemoveTokenConfig(token string)
- func (b *CrossChainBridgeBase) SetChainConfig(chainCfg *ChainConfig)
- func (b *CrossChainBridgeBase) SetGatewayConfig(gatewayCfg *GatewayConfig)
- func (b *CrossChainBridgeBase) SetTokenConfig(token string, tokenCfg *TokenConfig)
- type CurveAnyCallSwapInfo
- type ERC20SwapInfo
- type EthExtraArgs
- type GatewayConfig
- type IBridge
- type IBridgeConfg
- type IBridgeConfigLoader
- type IMPCSign
- type ISwapTrade
- type NFTSwapInfo
- type NonceSetter
- type RegisterArgs
- type StatusInterface
- type SwapArgs
- type SwapConfig
- type SwapInfo
- type SwapTxInfo
- type SwapType
- type TokenConfig
- type TxStatus
- type VerifyArgs
Constants ¶
const (
CurveAnycallSubType = "curve"
)
SwapSubType constants
Variables ¶
var ( ErrNotImplemented = errors.New("not implemented") ErrSwapTypeNotSupported = errors.New("swap type not supported") ErrNoBridgeForChainID = errors.New("no bridge for chain id") ErrSwapTradeNotSupport = errors.New("swap trade not support") ErrNotFound = errors.New("not found") ErrTxNotFound = errors.New("tx not found") ErrTxNotStable = errors.New("tx not stable") ErrLogIndexOutOfRange = errors.New("log index out of range") ErrTxWithWrongReceipt = errors.New("tx with wrong receipt") ErrTxWithWrongContract = errors.New("tx with wrong contract") ErrTxWithWrongTopics = errors.New("tx with wrong log topics") ErrSwapoutLogNotFound = errors.New("swapout log not found or removed") 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") ErrMissMPCPublicKey = errors.New("miss mpc public key config") ErrMissRouterInfo = errors.New("miss router info") 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") // errors should register in router swap 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") )
common errors
Functions ¶
func CalcSwapValue ¶
func CalcSwapValue(tokenID, 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 ¶ added in v3.2.0
ConvertTokenValue convert token value
func GetBigValueThreshold ¶ added in v3.2.0
GetBigValueThreshold get big value threshold
func InitRouterSwapType ¶ added in v3.4.0
func InitRouterSwapType(swapTypeStr string)
InitRouterSwapType init router swap type
func IsAnyCallRouter ¶ added in v3.4.0
func IsAnyCallRouter() bool
IsAnyCallRouter is anycall router
func IsRPCQueryOrNotFoundError ¶ added in v3.4.0
IsRPCQueryOrNotFoundError is rpc or not found error
func RPCCallWithTimeout ¶ added in v3.4.0
func RPCCallWithTimeout(timeout int, result interface{}, urls []string, method string, params ...interface{}) (err error)
RPCCallWithTimeout common RPC calling with specified timeout
func SetSwapConfigs ¶ added in v3.2.0
func SetSwapConfigs(swapCfgs map[string]map[string]*SwapConfig)
SetSwapConfigs set swap configs
func ShouldRegisterRouterSwapForError ¶
ShouldRegisterRouterSwapForError return true if this error should record in database
func WrapRPCQueryError ¶ added in v3.4.0
WrapRPCQueryError wrap rpc error
Types ¶
type AllExtras ¶
type AllExtras struct {
EthExtra *EthExtraArgs `json:"ethExtra,omitempty"`
ReplaceNum uint64 `json:"replaceNum,omitempty"`
}
AllExtras struct
type AnyCallSwapInfo ¶
type AnyCallSwapInfo struct {
CallFrom string `json:"callFrom"`
CallTo []string `json:"callTo"`
CallData []hexutil.Bytes `json:"callData"`
Callbacks []string `json:"callbacks"`
CallNonces []*big.Int `json:"callNonces"`
}
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"`
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 ¶ added in v3.4.0
func (args *BuildTxArgs) GetReplaceNum() uint64
GetReplaceNum get rplace swap count
func (*BuildTxArgs) GetTxNonce ¶
func (args *BuildTxArgs) GetTxNonce() uint64
GetTxNonce get tx nonce
func (*BuildTxArgs) SetTxNonce ¶ added in v3.4.0
func (args *BuildTxArgs) SetTxNonce(nonce uint64)
SetTxNonce set tx nonce
type ChainConfig ¶
type ChainConfig struct {
ChainID string
BlockChain string
RouterContract string
Confirmations uint64
InitialHeight uint64
// contains filtered or unexported fields
}
ChainConfig struct
func (*ChainConfig) CheckConfig ¶
func (c *ChainConfig) CheckConfig() (err error)
CheckConfig check chain config
func (*ChainConfig) GetChainID ¶ added in v3.4.0
func (c *ChainConfig) GetChainID() *big.Int
GetChainID get chainID of number
type CrossChainBridgeBase ¶
type CrossChainBridgeBase struct {
ChainConfig *ChainConfig
GatewayConfig *GatewayConfig
TokenConfigMap map[string]*TokenConfig // key is token address
}
CrossChainBridgeBase base bridge
func NewCrossChainBridgeBase ¶
func NewCrossChainBridgeBase() *CrossChainBridgeBase
NewCrossChainBridgeBase new base bridge
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 ¶ added in v3.5.0
func (b *CrossChainBridgeBase) GetRouterContract(token string) string
GetRouterContract get router contract
func (*CrossChainBridgeBase) GetTokenConfig ¶
func (b *CrossChainBridgeBase) GetTokenConfig(token string) *TokenConfig
GetTokenConfig get token config
func (*CrossChainBridgeBase) InitAfterConfig ¶ added in v3.5.0
func (b *CrossChainBridgeBase) InitAfterConfig()
InitAfterConfig init variables (ie. extra members) after loading config
func (*CrossChainBridgeBase) RemoveTokenConfig ¶
func (b *CrossChainBridgeBase) RemoveTokenConfig(token string)
RemoveTokenConfig remove token config
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 CurveAnyCallSwapInfo ¶ added in v3.5.0
type CurveAnyCallSwapInfo struct {
CallFrom string `json:"callFrom"`
CallTo string `json:"callTo"`
CallData hexutil.Bytes `json:"callData"`
Fallback string `json:"fallback"`
}
CurveAnyCallSwapInfo struct
type ERC20SwapInfo ¶ added in v3.4.0
type ERC20SwapInfo struct {
ForNative bool `json:"forNative,omitempty"`
ForUnderlying bool `json:"forUnderlying,omitempty"`
Token string `json:"token"`
TokenID string `json:"tokenID"`
Path []string `json:"path,omitempty"`
AmountOutMin *big.Int `json:"amountOutMin,omitempty"`
}
ERC20SwapInfo struct
type EthExtraArgs ¶
type EthExtraArgs struct {
Gas *uint64 `json:"gas,omitempty"`
GasPrice *big.Int `json:"gasPrice,omitempty"`
GasTipCap *big.Int `json:"gasTipCap,omitempty"`
GasFeeCap *big.Int `json:"gasFeeCap,omitempty"`
Nonce *uint64 `json:"nonce,omitempty"`
Deadline int64 `json:"deadline,omitempty"`
}
EthExtraArgs struct
type GatewayConfig ¶
GatewayConfig struct
type IBridge ¶
type IBridge interface {
IBridgeConfg
IMPCSign
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
}
IBridge interface
type IBridgeConfg ¶
type IBridgeConfg interface {
GetGatewayConfig() *GatewayConfig
GetChainConfig() *ChainConfig
GetTokenConfig(tokenAddr string) *TokenConfig
GetRouterContract(token string) string
SetChainConfig(chainCfg *ChainConfig)
SetGatewayConfig(gatewayCfg *GatewayConfig)
SetTokenConfig(token string, tokenCfg *TokenConfig)
}
IBridgeConfg interface implemented by 'CrossChainBridgeBase'
type IBridgeConfigLoader ¶ added in v3.5.0
type IBridgeConfigLoader interface {
InitGatewayConfig(chainID *big.Int)
InitChainConfig(chainID *big.Int)
InitTokenConfig(tokenID string, chainID *big.Int)
ReloadChainConfig(chainID *big.Int)
ReloadTokenConfig(tokenID string, chainID *big.Int)
RemoveTokenConfig(tokenAddr string)
}
IBridgeConfigLoader interface
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 ¶ added in v3.2.1
ISwapTrade interface
type NFTSwapInfo ¶ added in v3.4.0
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 {
GetPoolNonce(address, height string) (uint64, error)
RecycleSwapNonce(sender string, nonce uint64)
}
NonceSetter interface (for eth-like)
type RegisterArgs ¶
type RegisterArgs struct {
SwapType SwapType `json:"swaptype,omitempty"`
LogIndex int `json:"logIndex,omitempty"`
}
RegisterArgs struct
type StatusInterface ¶ added in v3.5.0
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 ¶ added in v3.2.0
type SwapConfig struct {
MaximumSwap *big.Int
MinimumSwap *big.Int
BigValueThreshold *big.Int
SwapFeeRatePerMillion uint64
MaximumSwapFee *big.Int
MinimumSwapFee *big.Int
}
SwapConfig struct
func GetSwapConfig ¶ added in v3.2.0
func GetSwapConfig(tokenID, toChainID string) *SwapConfig
GetSwapConfig get swap config
func (*SwapConfig) CheckConfig ¶ added in v3.2.0
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:"anycallSwapInfo,omitempty"`
CurveAnyCallSwapInfo *CurveAnyCallSwapInfo `json:"anycallSwapInfo2,omitempty"`
}
SwapInfo struct
func (*SwapInfo) GetTokenID ¶ added in v3.4.0
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 MaxValidSwapType )
SwapType constants
func GetRouterSwapType ¶ added in v3.4.0
func GetRouterSwapType() SwapType
GetRouterSwapType get router swap type
func (SwapType) IsValidType ¶ added in v3.4.0
IsValidType is valid swap type
type TokenConfig ¶
type TokenConfig struct {
TokenID string
Decimals uint8
ContractAddress string
ContractVersion uint64
RouterContract string
// 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() common.Address
GetUnderlying get underlying
func (*TokenConfig) IsStandardTokenVersion ¶ added in v3.5.0
func (c *TokenConfig) IsStandardTokenVersion() bool
IsStandardTokenVersion is standard token version
func (*TokenConfig) SetUnderlying ¶
func (c *TokenConfig) SetUnderlying(underlying common.Address)
SetUnderlying set underlying
type TxStatus ¶
type TxStatus struct {
Sender string `json:"sender,omitempty"`
Receipt interface{} `json:"receipt,omitempty"`
Confirmations uint64 `json:"confirmations"`
BlockHeight uint64 `json:"blockHeight"`
BlockHash string `json:"blockHash"`
BlockTime uint64 `json:"blockTime"`
}
TxStatus struct
func (*TxStatus) IsSwapTxOnChainAndFailed ¶ added in v3.4.0
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 |
|---|---|
|
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. |
|
eth
Package eth test eth router by implementing `tokens.IBridge` interface.
|
Package eth test eth router by implementing `tokens.IBridge` interface. |