eth

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package eth implements the bridge interfaces to support routering.

Index

Constants

View Source
const (
	ERC20TokenType = "ERC20"
)

token types (should be all upper case)

Variables

View Source
var (
	// v5 LogAnyCall(address,address,bytes,address,uint256)
	LogAnyCallV5Topic = common.FromHex("0x9ca1de98ebed0a9c38ace93d3ca529edacbbe199cf1b6f0f416ae9b724d4a81c")
	AnyExecV5FuncHash = common.FromHex("0xb4c5dbd0")

	// v6 LogAnyCall(address,address,bytes,address,uint256,uint256,string,uint256)
	LogAnyCallV6Topic = common.FromHex("0xa17aef042e1a5dd2b8e68f0d0d92f9a6a0b35dc25be1d12c0cb3135bfd8951c9")
	AnyExecV6FuncHash = common.FromHex("0x4a578150")
	// anyFallback(address,bytes)
	AnyExecV6FallbackFuncHash = common.FromHex("0xa35fe8bf")

	// v7 LogAnyCall(address,address,bytes,uint256,uint256,string,uint256,bytes)
	LogAnyCallV7Topic = common.FromHex("0x17dac14bf31c4070ebb2dc182fc25ae5df58f14162a7f24a65b103e22385af0d")
	// v7 LogAnyCall(address,string,bytes,uint256,uint256,string,uint256,bytes)
	LogAnyCallV7Topic2 = common.FromHex("0x36850177870d3e3dca07a29dcdc3994356392b81c60f537c1696468b1a01e61d")
	AnyExecV7FuncHash  = common.FromHex("0xd7328bad")

	// anycall usdc
	LogMessageSentTopic = common.FromHex("0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036")
)

anycall lot topics and func hashes

View Source
var (
	ForceAnySwapInAutoTokenVersion             = uint64(10001)
	ForceAnySwapInTokenVersion                 = uint64(10002)
	ForceAnySwapInUnderlyingTokenVersion       = uint64(10003)
	ForceAnySwapInNativeTokenVersion           = uint64(10004)
	ForceAnySwapInAndCallTokenVersion          = uint64(10005)
	ForceAnySwapInUnerlyingAndCallTokenVersion = uint64(10006)

	// anySwapIn(bytes32 txs, address token, address to, uint amount, uint fromChainID)
	AnySwapInFuncHash = common.FromHex("0x825bb13c")
	// anySwapInUnderlying(bytes32 txs, address token, address to, uint amount, uint fromChainID)
	AnySwapInUnderlyingFuncHash = common.FromHex("0x3f88de89")
	// anySwapInNative(bytes32 txs, address token, address to, uint amount, uint fromChainID)
	AnySwapInNativeFuncHash = common.FromHex("0x21974f28")
	// anySwapInAuto(bytes32 txs, address token, address to, uint amount, uint fromChainID)
	AnySwapInAutoFuncHash = common.FromHex("0x0175b1c4")

	// anySwapIn(string swapID, address token, address to, uint256 amount, uint256 fromChainID)
	MixPoolAnySwapInFuncHash = common.FromHex("0x8619c43d")

	// anySwapIn(string,(bytes32,address,address,uint256,uint256))
	AnySwapInFuncHashV7 = common.FromHex("0x8fef8489")
	// anySwapInUnderlying(string,(bytes32,address,address,uint256,uint256))
	AnySwapInUnderlyingFuncHashV7 = common.FromHex("0x9ff1d3e8")
	// anySwapInNative(string,(bytes32,address,address,uint256,uint256))
	AnySwapInNativeFuncHashV7 = common.FromHex("0x5de26385")
	// anySwapInAuto(string,(bytes32,address,address,uint256,uint256))
	AnySwapInAutoFuncHashV7 = common.FromHex("0x81aa7a81")
	// anySwapInAndExec(string,(bytes32,address,address,uint256,uint256),address,bytes)
	AnySwapInAndExecFuncHashV7 = common.FromHex("0xf9ca3a5d")
	// anySwapInUnderlyingAndExec(string,(bytes32,address,address,uint256,uint256),address,bytes)
	AnySwapInUnderlyingAndExecFuncHashV7 = common.FromHex("0xcc95060a")
)

router contract's func hashs

View Source
var (
	// LogNFT721SwapOut(address,address,address,uint256,uint256,uint256);
	LogNFT721SwapOutTopic = common.FromHex("0x0d45b0b9f5add3e1bb841982f1fa9303628b0b619b000cb1f9f1c3903329a4c7")
	// LogNFT1155SwapOut(addressindexedtoken,address,address,uint256,uint256,uint256,uint256)
	LogNFT1155SwapOutTopic = common.FromHex("0x5058b8684cf36ffd9f66bc623fbc617a44dd65cf2273306d03d3104af0995cb0")
	// LogNFT1155SwapOutBatch(address,address,address,uint256[],uint256[],uint256,uint256)
	LogNFT1155SwapOutBatchTopic = common.FromHex("0xaa428a5ab688b49b415401782c170d216b33b15711d30cf69482f570eca8db38")
)

nft swap log topics and func hashes

View Source
var (
	// LogAnySwapOut(address token, address from, address to, uint amount, uint fromChainID, uint toChainID);
	LogAnySwapOutTopic = common.FromHex("0x97116cf6cd4f6412bb47914d6db18da9e16ab2142f543b86e207c24fbd16b23a")
	// LogAnySwapOut(address token, address from, string to, uint amount, uint fromChainID, uint toChainID);
	LogAnySwapOut2Topic = common.FromHex("0x409e0ad946b19f77602d6cf11d59e1796ddaa4828159a0b4fb7fa2ff6b161b79")
	// LogAnySwapOutMixPool(address token, address from, string to, uint256 amount, uint256 fromChainID, uint256 toChainID)
	LogAnySwapOutMixPoolTopic = common.FromHex("0xb89f5e0fee14552a1edac7c525bc18eb2c5fad996def47de882b82fdea286fd7")
	// LogAnySwapOut(bytes32 swapoutID, address token, address from, string receiver, uint256 amount, uint256 toChainID)
	LogAnySwapOutV7Topic = common.FromHex("0x0d969ae475ff6fcaf0dcfa760d4d8607244e8d95e9bf426f8d5d69f9a3e525af")
	// LogAnySwapOutAndCall(bytes32 swapoutID, address token, address from, string receiver, uint256 amount, uint256 toChainID, string anycallProxy, bytes data)
	LogAnySwapOutAndCallV7Topic = common.FromHex("0x968608314ec29f6fd1a9f6ef9e96247a4da1a683917569706e2d2b60ca7c0a6d")

	// PauseSwapIntoTokenVersion pause swap into a dest token which is configed with this version
	// usage: when we replace an old token with a new one,
	// but the old token has some swapouts not processed,
	// then we can replace temply to the old token and with this special version,
	// after old token swapouts are processed, we should replace back to the new token config.
	PauseSwapIntoTokenVersion = uint64(90000)

	LogTokenTransferTopics = []common.Hash{

		common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
	}
)

router contract's log topics

View Source
var (
	// LogNFT721SwapOut(address,address,address,uint256,uint256,uint256,bytes);
	LogNFT721SwapOutWithDataTopic = common.FromHex("0x8ef0d7d8b96825500b3d692d995a543110f8a93f16b7be5d23b5960fd4363bdc")
)

nft swap with data log topics and func hashes

Functions

func GetSwapInAndExecFuncHashV7 added in v3.6.1

func GetSwapInAndExecFuncHashV7(tokenCfg *tokens.TokenConfig) []byte

GetSwapInAndExecFuncHashV7 get swapin and call func hash

func GetSwapInFuncHash1 added in v3.6.1

func GetSwapInFuncHash1(tokenCfg *tokens.TokenConfig) []byte

GetSwapInFuncHash1 get swapin func hash

func GetSwapInFuncHashV7 added in v3.6.1

func GetSwapInFuncHashV7(tokenCfg *tokens.TokenConfig) []byte

GetSwapInFuncHashV7 get swapin func hash

func PublicKeyToAddress added in v3.6.0

func PublicKeyToAddress(pubKey string) (string, error)

PublicKeyToAddress public key to address

func VerifyMPCPubKey added in v3.5.0

func VerifyMPCPubKey(mpcAddress, mpcPubkey string) error

VerifyMPCPubKey verify mpc address and public key is matching

Types

type Bridge

type Bridge struct {
	CustomConfig
	*base.NonceSetterBase
	Signer        types.Signer
	SignerChainID *big.Int
	// contains filtered or unexported fields
}

Bridge eth bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) CallContract

func (b *Bridge) CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)

CallContract call eth_call

func (*Bridge) ChainID

func (b *Bridge) ChainID() (*big.Int, error)

ChainID call eth_chainId Notice: eth_chainId return 0x0 for mainnet which is wrong (use net_version instead)

func (*Bridge) EstimateGas

func (b *Bridge) EstimateGas(from, to string, value *big.Int, data []byte) (uint64, error)

EstimateGas call eth_estimateGas

func (*Bridge) FeeHistory added in v3.3.0

func (b *Bridge) FeeHistory(blockCount int, rewardPercentiles []float64) (*types.FeeHistoryResult, error)

FeeHistory call eth_feeHistory

func (*Bridge) GetBalance

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

GetBalance call eth_getBalance

func (*Bridge) GetBaseFee added in v3.3.0

func (b *Bridge) GetBaseFee(blockCount int) (*big.Int, error)

GetBaseFee get base fee

func (*Bridge) GetBlockByNumber

func (b *Bridge) GetBlockByNumber(number *big.Int) (*types.RPCBlock, error)

GetBlockByNumber call eth_getBlockByNumber

func (*Bridge) GetBlockConfirmations added in v3.6.1

func (b *Bridge) GetBlockConfirmations(receipt *types.RPCTxReceipt) (uint64, error)

GetBlockConfirmations some chain may override this method

func (*Bridge) GetCode

func (b *Bridge) GetCode(contract string) (code []byte, err error)

GetCode call eth_getCode

func (*Bridge) GetContractCodeHash added in v3.5.0

func (b *Bridge) GetContractCodeHash(contract common.Address) common.Hash

GetContractCodeHash get contract code hash

func (*Bridge) GetContractLogs

func (b *Bridge) GetContractLogs(contractAddresses common.Address, logTopics []common.Hash, blockHeight uint64) ([]*types.RPCLog, error)

GetContractLogs get contract logs

func (*Bridge) GetEIP1167Master added in v3.5.0

func (b *Bridge) GetEIP1167Master(proxy common.Address) (master common.Address)

GetEIP1167Master get eip1167 master address

func (*Bridge) GetErc20Balance

func (b *Bridge) GetErc20Balance(contract, address string) (*big.Int, error)

GetErc20Balance get erc20 balacne of address

func (*Bridge) GetErc20BalanceAtHeight added in v3.6.1

func (b *Bridge) GetErc20BalanceAtHeight(contract, address, blockNumber string) (*big.Int, error)

GetErc20BalanceAtHeight get erc20 balacne of address at specified height

func (*Bridge) GetErc20Decimals

func (b *Bridge) GetErc20Decimals(contract string) (uint8, error)

GetErc20Decimals get erc20 decimals

func (*Bridge) GetErc20TotalSupply

func (b *Bridge) GetErc20TotalSupply(contract string) (*big.Int, error)

GetErc20TotalSupply get erc20 total supply of address

func (*Bridge) GetErc20TotalSupplyAtHeight added in v3.6.1

func (b *Bridge) GetErc20TotalSupplyAtHeight(contract, blockNumber string) (*big.Int, error)

GetErc20TotalSupplyAtHeight get erc20 total supply of address at specified height

func (*Bridge) GetFactoryAddress

func (b *Bridge) GetFactoryAddress(contractAddr string) (string, error)

GetFactoryAddress call "factory()"

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (maxHeight uint64, err error)

GetLatestBlockNumber call eth_blockNumber

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(url string) (latest uint64, err error)

GetLatestBlockNumberOf call eth_blockNumber

func (*Bridge) GetLogs

func (b *Bridge) GetLogs(filterQuery *types.FilterQuery) (result []*types.RPCLog, err error)

GetLogs call eth_getLogs

func (*Bridge) GetMPCAddress

func (b *Bridge) GetMPCAddress(contractAddr string) (string, error)

GetMPCAddress call "mpc()"

func (*Bridge) GetOwnerAddress

func (b *Bridge) GetOwnerAddress(contractAddr string) (string, error)

GetOwnerAddress call "owner()"

func (*Bridge) GetPairFor

func (b *Bridge) GetPairFor(factory, token0, token1 string) (string, error)

GetPairFor call "getPair(address,address)"

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, height string) (mdPoolNonce uint64, err error)

GetPoolNonce call eth_getTransactionCount

func (*Bridge) GetRouterSecurity added in v3.6.1

func (b *Bridge) GetRouterSecurity(contractAddr string) (string, error)

GetRouterSecurity call "routerSecurity()"

func (*Bridge) GetSignedTxHashOfKeyID added in v3.4.0

func (b *Bridge) GetSignedTxHashOfKeyID(sender, keyID string, rawTx interface{}) (txHash string, err error)

GetSignedTxHashOfKeyID get signed tx hash by keyID (called by oracle)

func (*Bridge) GetSignerChainID

func (b *Bridge) GetSignerChainID() (*big.Int, error)

GetSignerChainID default way to get signer chain id use chain ID first, if missing then use network ID instead. normally this way works, but sometimes it failed (eg. ETC), then we should overwrite this function NOTE: call after chain config setted

func (*Bridge) GetTokenBalance

func (b *Bridge) GetTokenBalance(tokenType, tokenAddress, accountAddress string) (*big.Int, error)

GetTokenBalance api

func (*Bridge) GetTokenConfig added in v3.6.1

func (b *Bridge) GetTokenConfig(tokenAddr string) *tokens.TokenConfig

GetTokenConfig get and check token config

func (*Bridge) GetTokenSupply

func (b *Bridge) GetTokenSupply(tokenType, tokenAddress string) (*big.Int, error)

GetTokenSupply impl

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (interface{}, error)

GetTransaction impl

func (*Bridge) GetTransactionByBlockNumberAndIndex added in v3.4.0

func (b *Bridge) GetTransactionByBlockNumberAndIndex(blockNumber *big.Int, txIndex uint) (result *types.RPCTransaction, err error)

GetTransactionByBlockNumberAndIndex get tx by block number and tx index

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (tx *types.RPCTransaction, err error)

GetTransactionByHash call eth_getTransactionByHash

func (*Bridge) GetTransactionReceipt

func (b *Bridge) GetTransactionReceipt(txHash string) (receipt *types.RPCTxReceipt, err error)

GetTransactionReceipt call eth_getTransactionReceipt

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (*tokens.TxStatus, error)

GetTransactionStatus impl

func (*Bridge) GetUnderlyingAddress

func (b *Bridge) GetUnderlyingAddress(contractAddr string) (string, error)

GetUnderlyingAddress call "underlying()"

func (*Bridge) GetVaultAddress

func (b *Bridge) GetVaultAddress(contractAddr string) (string, error)

GetVaultAddress call "vault()"

func (*Bridge) GetWNativeAddress added in v3.2.1

func (b *Bridge) GetWNativeAddress(contractAddr string) (string, error)

GetWNativeAddress call "wNATIVE()"

func (*Bridge) GetWrapperTokenAddress added in v3.6.1

func (b *Bridge) GetWrapperTokenAddress(contractAddr string) (string, error)

GetWrapperTokenAddress call "token()"

func (*Bridge) InitAfterConfig added in v3.5.0

func (b *Bridge) InitAfterConfig()

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

func (*Bridge) InitExtraCustoms added in v3.5.0

func (b *Bridge) InitExtraCustoms() error

InitExtraCustoms init extra customs

func (*Bridge) InitRouterInfo added in v3.5.0

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

InitRouterInfo init router info

func (*Bridge) IsContractAddress

func (b *Bridge) IsContractAddress(address string) (bool, error)

IsContractAddress is contract address

func (*Bridge) IsMinter

func (b *Bridge) IsMinter(contractAddr, minterAddr string) (bool, error)

IsMinter call "isMinter(address)"

func (*Bridge) IsSwapoutIDExist added in v3.6.1

func (b *Bridge) IsSwapoutIDExist(contractAddr, swapoutID string) (bool, error)

IsSwapoutIDExist call "isSwapoutIDExist(bytes32)"

func (*Bridge) IsUnderlyingMinted added in v3.6.1

func (b *Bridge) IsUnderlyingMinted(contractAddr string) (bool, error)

IsUnderlyingMinted call "underlyingIsMinted()"

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(address string) bool

IsValidAddress check address

func (*Bridge) MPCSignTransaction

func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)

MPCSignTransaction mpc sign raw tx

func (*Bridge) NeedsFinalizeAPIAddress added in v3.6.1

func (b *Bridge) NeedsFinalizeAPIAddress() bool

NeedsFinalizeAPIAddress need special finalize api

func (*Bridge) NetworkID

func (b *Bridge) NetworkID() (*big.Int, error)

NetworkID call net_version

func (*Bridge) PublicKeyToAddress added in v3.5.2

func (b *Bridge) PublicKeyToAddress(pubKey string) (string, error)

PublicKeyToAddress impl

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendSignedTransaction

func (b *Bridge) SendSignedTransaction(tx *types.Transaction) (txHash string, err error)

SendSignedTransaction call eth_sendRawTransaction

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)

SendTransaction send signed tx

func (*Bridge) SetTokenConfig added in v3.5.2

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set token config

func (*Bridge) SignTransactionWithPrivateKey added in v3.5.0

func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, priKey string) (signTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with private key (use for testing)

func (*Bridge) SuggestGasTipCap added in v3.3.0

func (b *Bridge) SuggestGasTipCap() (mdGasTipCap *big.Int, err error)

SuggestGasTipCap call eth_maxPriorityFeePerGas

func (*Bridge) SuggestPrice

func (b *Bridge) SuggestPrice() (*big.Int, error)

SuggestPrice call eth_gasPrice

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) error

VerifyMsgHash verify msg hash

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction api

type CustomConfig added in v3.5.1

type CustomConfig struct {
	// some chain's rpc is slow and need config a longer rpc timeout
	RPCClientTimeout int
	// eg. RSK chain do not check mixed case or not same as eth
	DontCheckAddressMixedCase bool
}

CustomConfig custom config

func NewCustomConfig added in v3.5.1

func NewCustomConfig() CustomConfig

NewCustomConfig new custom config

type USDCAttestation added in v3.6.2

type USDCAttestation struct {
	Attestation hexutil.Bytes `json:"attestation"`
	Status      string        `json:"status"`
}

USDCAttestation usdc attestation

func GetUSDCAttestation added in v3.6.2

func GetUSDCAttestation(messageHash common.Hash) (*USDCAttestation, error)

GetUSDCAttestation get usdc attestation

Directories

Path Synopsis
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