Documentation ¶
Index ¶
- Variables
- func CalcSwapValue(fromToken, toToken *TokenConfig, value *big.Int) *big.Int
- func CheckTokenSwapValue(fromToken, toToken *TokenConfig, value *big.Int) bool
- func ShouldRegisterRouterSwapForError(err error) bool
- func ToBits(valueStr string, decimals uint8) *big.Int
- func VerifyMPCPubKey(mpcAddress, mpcPubkey string) error
- type AllExtras
- type AnyCallSwapInfo
- type BuildTxArgs
- type ChainConfig
- func (c *ChainConfig) CheckConfig() error
- func (c *ChainConfig) GetRouterFactory() string
- func (c *ChainConfig) GetRouterMPC() string
- func (c *ChainConfig) GetRouterMPCPubkey() string
- func (c *ChainConfig) SetRouterFactory(factory string)
- func (c *ChainConfig) SetRouterMPC(mpc string)
- func (c *ChainConfig) SetRouterMPCPubkey(pubkey string)
- type CrossChainBridgeBase
- func (b *CrossChainBridgeBase) GetBigValueThreshold(token string) *big.Int
- func (b *CrossChainBridgeBase) GetChainConfig() *ChainConfig
- func (b *CrossChainBridgeBase) GetGatewayConfig() *GatewayConfig
- func (b *CrossChainBridgeBase) GetTokenConfig(token string) *TokenConfig
- 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 EthExtraArgs
- type GatewayConfig
- type IBridge
- type IBridgeConfg
- type IMPCSign
- type NonceSetter
- type RegisterArgs
- type RouterSwapInfo
- type SwapArgs
- type SwapInfo
- type SwapTxInfo
- type SwapType
- type TokenConfig
- type TxStatus
- type VerifyArgs
Constants ¶
This section is empty.
Variables ¶
var ( ErrSwapTypeNotSupported = errors.New("swap type not supported") ErrNoBridgeForChainID = errors.New("no bridge for chain id") ErrWrongRegisterArgs = errors.New("wrong register arguments") ErrWrongVerifyArgs = errors.New("wrong verify arguments") 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") 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") // 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(fromToken, toToken *TokenConfig, value *big.Int) *big.Int
CalcSwapValue calc swap value (get rid of fee and convert by decimals)
func CheckTokenSwapValue ¶
func CheckTokenSwapValue(fromToken, toToken *TokenConfig, value *big.Int) bool
CheckTokenSwapValue check swap value is in right range
func ShouldRegisterRouterSwapForError ¶
ShouldRegisterRouterSwapForError return true if this error should record in database
func VerifyMPCPubKey ¶
VerifyMPCPubKey verify mpc address and public key is matching
Types ¶
type AllExtras ¶
type AllExtras struct {
EthExtra *EthExtraArgs `json:"ethExtra,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"` Value *big.Int `json:"value,omitempty"` OriginValue *big.Int `json:"originValue,omitempty"` SwapValue *big.Int `json:"swapValue,omitempty"` Memo string `json:"memo,omitempty"` Input *hexutil.Bytes `json:"input,omitempty"` Extra *AllExtras `json:"extra,omitempty"` ReplaceNum uint64 `json:"replaceNum,omitempty"` }
BuildTxArgs struct
func (*BuildTxArgs) GetExtraArgs ¶
func (args *BuildTxArgs) GetExtraArgs() *BuildTxArgs
GetExtraArgs get extra args
func (*BuildTxArgs) GetTxNonce ¶
func (args *BuildTxArgs) GetTxNonce() uint64
GetTxNonce get 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() error
CheckConfig check chain config
func (*ChainConfig) GetRouterFactory ¶
func (c *ChainConfig) GetRouterFactory() string
GetRouterFactory get factory address of router contract
func (*ChainConfig) GetRouterMPC ¶
func (c *ChainConfig) GetRouterMPC() string
GetRouterMPC get router mpc
func (*ChainConfig) GetRouterMPCPubkey ¶
func (c *ChainConfig) GetRouterMPCPubkey() string
GetRouterMPCPubkey get router mpc public key
func (*ChainConfig) SetRouterFactory ¶
func (c *ChainConfig) SetRouterFactory(factory string)
SetRouterFactory set factory address of router contract
func (*ChainConfig) SetRouterMPC ¶
func (c *ChainConfig) SetRouterMPC(mpc string)
SetRouterMPC set router mpc
func (*ChainConfig) SetRouterMPCPubkey ¶
func (c *ChainConfig) SetRouterMPCPubkey(pubkey string)
SetRouterMPCPubkey set router mpc public key
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) GetBigValueThreshold ¶
func (b *CrossChainBridgeBase) GetBigValueThreshold(token string) *big.Int
GetBigValueThreshold get big value threshold
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) GetTokenConfig ¶
func (b *CrossChainBridgeBase) GetTokenConfig(token string) *TokenConfig
GetTokenConfig get token 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 EthExtraArgs ¶
type EthExtraArgs struct { Gas *uint64 `json:"gas,omitempty"` GasPrice *big.Int `json:"gasPrice,omitempty"` Nonce *uint64 `json:"nonce,omitempty"` Deadline int64 `json:"deadline,omitempty"` }
EthExtraArgs struct
type GatewayConfig ¶
GatewayConfig struct
type IBridge ¶
type IBridge interface { IBridgeConfg IMPCSign 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 GetLatestBlockNumber() (uint64, error) GetLatestBlockNumberOf(url string) (uint64, error) GetBigValueThreshold(token string) *big.Int IsValidAddress(address string) bool }
IBridge interface
type IBridgeConfg ¶
type IBridgeConfg interface { GetGatewayConfig() *GatewayConfig GetChainConfig() *ChainConfig GetTokenConfig(tokenAddr string) *TokenConfig 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) }
IBridgeConfg 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 NonceSetter ¶
type NonceSetter interface { GetPoolNonce(address, height string) (uint64, error) SetNonce(pairID string, value uint64) AdjustNonce(pairID string, value uint64) (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 RouterSwapInfo ¶
type RouterSwapInfo 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"` }
RouterSwapInfo struct
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"` }
SwapArgs struct
type SwapInfo ¶
type SwapInfo struct { *RouterSwapInfo `json:"routerSwapInfo,omitempty"` *AnyCallSwapInfo `json:"anycallSwapInfo,omitempty"` }
SwapInfo struct
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 TokenConfig ¶
type TokenConfig struct { TokenID string Decimals uint8 ContractAddress string ContractVersion uint64 MaximumSwap *big.Int MinimumSwap *big.Int BigValueThreshold *big.Int SwapFeeRatePerMillion uint64 MaximumSwapFee *big.Int MinimumSwapFee *big.Int // contains filtered or unexported fields }
TokenConfig struct
func (*TokenConfig) CheckConfig ¶
func (c *TokenConfig) CheckConfig() error
CheckConfig check token config nolint:gocyclo // check all together
func (*TokenConfig) GetUnderlying ¶
func (c *TokenConfig) GetUnderlying() common.Address
GetUnderlying get underlying
func (*TokenConfig) SetUnderlying ¶
func (c *TokenConfig) SetUnderlying(underlying common.Address)
SetUnderlying set underlying
type TxStatus ¶
type TxStatus struct { Receipt interface{} `json:"receipt,omitempty"` Confirmations uint64 `json:"confirmations"` BlockHeight uint64 `json:"blockHeight"` BlockHash string `json:"blockHash"` BlockTime uint64 `json:"blockTime"` }
TxStatus struct
type VerifyArgs ¶
type VerifyArgs struct { SwapType SwapType `json:"swaptype,omitempty"` LogIndex int `json:"logIndex,omitempty"` AllowUnstable bool `json:"allowUnstable,omitempty"` }
VerifyArgs struct