evm

package
v0.0.0-...-aaa40be Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_GAS_PRICE = 20_000_000_000
View Source
const DEFAULT_GAS_TIP = 3_000_000_000

Variables

View Source
var DefaultMaxTipCapGwei uint64 = 5
View Source
var ERC20 abi.ABI

Functions

func BuildERC20Payload

func BuildERC20Payload(to xc.Address, amount xc.AmountBlockchain) ([]byte, error)

func CheckError

func CheckError(err error) xclient.ClientError

func GweiToWei

func GweiToWei(gwei uint64) xc.AmountBlockchain

func HexToAddress

func HexToAddress(address xc.Address) (common.Address, error)

HexToAddress returns a go-ethereum Address decoded Crosschain address (hex string).

func NewAddressBuilder

func NewAddressBuilder(asset xc.ITask) (xc.AddressBuilder, error)

NewAddressBuilder creates a new EVM AddressBuilder

func NewSigner

func NewSigner(asset xc.ITask) (xc.Signer, error)

NewSigner creates a new EVM Signer

func NewTxBuilder

func NewTxBuilder(asset xc.ITask) (xc.TxBuilder, error)

NewTxBuilder creates a new EVM TxBuilder

func ReplaceIncompatiableEvmResponses

func ReplaceIncompatiableEvmResponses(body []byte) []byte

func TrimPrefixes

func TrimPrefixes(addressOrTxHash string) string

Types

type AddressBuilder

type AddressBuilder struct {
}

AddressBuilder for EVM

func (AddressBuilder) GetAddressFromPublicKey

func (ab AddressBuilder) GetAddressFromPublicKey(publicKeyBytes []byte) (xc.Address, error)

GetAddressFromPublicKey returns an Address given a public key

func (AddressBuilder) GetAllPossibleAddressesFromPublicKey

func (ab AddressBuilder) GetAllPossibleAddressesFromPublicKey(publicKeyBytes []byte) ([]xc.PossibleAddress, error)

GetAllPossibleAddressesFromPublicKey returns all PossubleAddress(es) given a public key

type Client

type Client struct {
	Asset       xc.ITask
	EthClient   *ethclient.Client
	ChainId     *big.Int
	Interceptor *utils.HttpInterceptor
}

Client for EVM

func NewClient

func NewClient(asset xc.ITask) (*Client, error)

NewClient returns a new EVM Client

func (*Client) DefaultMaxGasLimit

func (client *Client) DefaultMaxGasLimit() uint64

func (*Client) FetchBalance

func (client *Client) FetchBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

Fetch the balance of the asset that this client is configured for

func (*Client) FetchLegacyTxInfo

func (client *Client) FetchLegacyTxInfo(ctx context.Context, txHashStr xc.TxHash) (xc.LegacyTxInfo, error)

FetchLegacyTxInfo returns tx info for a EVM tx

func (*Client) FetchNativeBalance

func (client *Client) FetchNativeBalance(ctx context.Context, address xc.Address) (xc.AmountBlockchain, error)

Fetch the balance of the native asset that this client is configured for

func (*Client) FetchTxInfo

func (client *Client) FetchTxInfo(ctx context.Context, txHashStr xc.TxHash) (xclient.TxInfo, error)

func (*Client) FetchTxInput

func (client *Client) FetchTxInput(ctx context.Context, from xc.Address, to xc.Address) (xc.TxInput, error)

FetchTxInput returns tx input for a EVM tx

func (*Client) GetNonce

func (client *Client) GetNonce(ctx context.Context, from xc.Address) (uint64, error)

func (*Client) SimulateGasWithLimit

func (client *Client) SimulateGasWithLimit(ctx context.Context, txBuilder xc.TxBuilder, from xc.Address, to xc.Address, txInput xc.TxInput) (uint64, error)

Simulate a transaction to get the estimated gas limit

func (*Client) SubmitTx

func (client *Client) SubmitTx(ctx context.Context, tx xc.Tx) error

SubmitTx submits a EVM tx

func (*Client) TraceEthMovements

func (client *Client) TraceEthMovements(ctx context.Context, txHash common.Hash) (SourcesAndDests, error)

func (*Client) TraceTransaction

func (client *Client) TraceTransaction(ctx context.Context, txHash common.Hash) (*TraceTransactionResult, error)

Implements debug_traceTransaction, which is supported on GETH and most RPC providers, but likely not implemented on public nodes. This will reveal ETH transfers in internal transactions and removes the need for us to manually parse "multi transfers".

func (*Client) TxPoolContentFrom

func (client *Client) TxPoolContentFrom(ctx context.Context, from common.Address) (*TxPoolResult, error)

Get current pending transaction queue for a given address

type EvmTxBuilder

type EvmTxBuilder struct {
}

supports evm after london merge

func (*EvmTxBuilder) BuildTxWithPayload

func (*EvmTxBuilder) BuildTxWithPayload(chain *xc.ChainConfig, to xc.Address, value xc.AmountBlockchain, data []byte, inputRaw xc.TxInput) (xc.Tx, error)

type GethTxBuilder

type GethTxBuilder interface {
	BuildTxWithPayload(chain *xc.ChainConfig, to xc.Address, value xc.AmountBlockchain, data []byte, input xc.TxInput) (xc.Tx, error)
}

type Signer

type Signer struct {
}

Signer for EVM

func (Signer) ImportPrivateKey

func (signer Signer) ImportPrivateKey(privateKey string) (xc.PrivateKey, error)

ImportPrivateKey imports an EVM private key

func (Signer) PublicKey

func (signer Signer) PublicKey(privateKey xc.PrivateKey) (xc.PublicKey, error)

func (Signer) Sign

func (signer Signer) Sign(privateKey xc.PrivateKey, data xc.TxDataToSign) (xc.TxSignature, error)

Sign an EVM tx

type SourcesAndDests

type SourcesAndDests struct {
	Sources      []*xc.LegacyTxInfoEndpoint
	Destinations []*xc.LegacyTxInfoEndpoint
}

type TraceTransactionArgs

type TraceTransactionArgs struct {
	Tracer string `json:"tracer"`
}

type TraceTransactionResult

type TraceTransactionResult struct {
	Gas     hexutil.Uint              `json:"gas"`
	GasUsed hexutil.Uint              `json:"gasUsed"`
	To      common.Address            `json:"to"`
	From    common.Address            `json:"from"`
	Input   hexutil.Bytes             `json:"input"`
	Value   hexutil.Big               `json:"value"`
	Type    TraceTransactionType      `json:"type"`
	Calls   []*TraceTransactionResult `json:"calls"`
}

func FlattenTraceResult

func FlattenTraceResult(result *TraceTransactionResult, traces []*TraceTransactionResult) []*TraceTransactionResult

Recurse through all of the traces and provide them as a linear set of traces.

type TraceTransactionType

type TraceTransactionType string
var CALL TraceTransactionType = "CALL"
var DELEGATE_CALL TraceTransactionType = "DELEGATECALL"

type Tx

type Tx struct {
	EthTx      *types.Transaction
	Signer     types.Signer
	Signatures []xc.TxSignature
}

Tx for EVM

func (*Tx) AddSignatures

func (tx *Tx) AddSignatures(signatures ...xc.TxSignature) error

AddSignatures adds a signature to Tx

func (Tx) Amount

func (tx Tx) Amount() xc.AmountBlockchain

Amount returns the tx amount

func (Tx) ContractAddress

func (tx Tx) ContractAddress() xc.ContractAddress

ContractAddress returns the contract address for a token transfer

func (Tx) Fee

func (tx Tx) Fee(baseFeeUint uint64, gasUsedUint uint64) xc.AmountBlockchain

Fee returns the fee associated to the tx

func (Tx) From

func (tx Tx) From() xc.Address

From is the sender of a transfer

func (Tx) GetSignatures

func (tx Tx) GetSignatures() []xc.TxSignature

func (Tx) Hash

func (tx Tx) Hash() xc.TxHash

Hash returns the tx hash or id

func (Tx) IsContract

func (tx Tx) IsContract() bool

IsContract returns whether a tx is a contract or native transfer

func (Tx) ParseERC20TransferTx

func (tx Tx) ParseERC20TransferTx(nativeAsset xc.NativeAsset) (SourcesAndDests, error)

ParseERC20TransferTx parses the tx payload as ERC20 transfer

func (*Tx) ParseTokenLogs

func (tx *Tx) ParseTokenLogs(receipt *types.Receipt, nativeAsset xc.NativeAsset) SourcesAndDests

ParseTransfer parses a tx and extracts higher-level transfer information

func (Tx) Serialize

func (tx Tx) Serialize() ([]byte, error)

Serialize returns the serialized tx

func (Tx) Sighashes

func (tx Tx) Sighashes() ([]xc.TxDataToSign, error)

Sighashes returns the tx payload to sign, aka sighash

func (Tx) To

func (tx Tx) To() xc.Address

To is the account receiving a transfer

type TxBuilder

type TxBuilder struct {
	Asset xc.ITask
	// contains filtered or unexported fields
}

TxBuilder for EVM

func (TxBuilder) BuildProxyPayload

func (txBuilder TxBuilder) BuildProxyPayload(contract xc.ContractAddress, to xc.Address, amount xc.AmountBlockchain) ([]byte, error)

func (TxBuilder) BuildTaskPayload

func (txBuilder TxBuilder) BuildTaskPayload(taskFrom xc.Address, taskTo xc.Address, taskAmount xc.AmountBlockchain, input *TxInput) (string, xc.AmountBlockchain, []byte, error)

func (TxBuilder) BuildTaskTx

func (txBuilder TxBuilder) BuildTaskTx(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

func (TxBuilder) BuildWormholePayload

func (txBuilder TxBuilder) BuildWormholePayload(taskFrom xc.Address, taskTo xc.Address, taskAmount xc.AmountBlockchain, txInput *TxInput) (string, xc.AmountBlockchain, []byte, error)

func (TxBuilder) BuildWormholeTransferTx

func (txBuilder TxBuilder) BuildWormholeTransferTx(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

func (TxBuilder) NewNativeTransfer

func (txBuilder TxBuilder) NewNativeTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

NewNativeTransfer creates a new transfer for a native asset

func (TxBuilder) NewTask

func (txBuilder TxBuilder) NewTask(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

func (TxBuilder) NewTokenTransfer

func (txBuilder TxBuilder) NewTokenTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

NewTokenTransfer creates a new transfer for a token asset

func (TxBuilder) NewTransfer

func (txBuilder TxBuilder) NewTransfer(from xc.Address, to xc.Address, amount xc.AmountBlockchain, input xc.TxInput) (xc.Tx, error)

NewTransfer creates a new transfer for an Asset, either native or token

func (TxBuilder) WithTxBuilder

func (txBuilder TxBuilder) WithTxBuilder(buider GethTxBuilder) xc.TxBuilder

type TxInput

type TxInput struct {
	xc.TxInputEnvelope
	utils.TxPriceInput
	Nonce    uint64 `json:"nonce,omitempty"`
	GasLimit uint64 `json:"gas_limit,omitempty"`
	// DynamicFeeTx
	GasTipCap xc.AmountBlockchain `json:"gas_tip_cap,omitempty"` // maxPriorityFeePerGas
	GasFeeCap xc.AmountBlockchain `json:"gas_fee_cap,omitempty"` // maxFeePerGas
	// GasPrice xc.AmountBlockchain `json:"gas_price,omitempty"` // wei per gas
	// Task params
	Params []string `json:"params,omitempty"`

	// For legacy implementation only
	GasPrice xc.AmountBlockchain `json:"gas_price,omitempty"` // wei per gas

	ChainId xc.AmountBlockchain `json:"chain_id,omitempty"`
}

TxInput for EVM

func NewTxInput

func NewTxInput() *TxInput

func (*TxInput) IndependentOf

func (input *TxInput) IndependentOf(other xc.TxInput) (independent bool)

func (*TxInput) SafeFromDoubleSend

func (input *TxInput) SafeFromDoubleSend(others ...xc.TxInput) (safe bool)

func (*TxInput) SetGasFeePriority

func (input *TxInput) SetGasFeePriority(other xc.GasFeePriority) error

type TxPoolPendingMap

type TxPoolPendingMap struct {
}

type TxPoolResult

type TxPoolResult struct {
	// map of nonce to txinfo
	Pending map[string]*TxPoolTxInfo `json:"pending"`
}

func (*TxPoolResult) InfoFor

func (result *TxPoolResult) InfoFor(address string) (*TxPoolTxInfo, bool)

return first pending tx for a given address (should only be 1 entry..)

func (*TxPoolResult) PendingCount

func (result *TxPoolResult) PendingCount() int

type TxPoolTxInfo

type TxPoolTxInfo struct {
	From                 string      `json:"from"`
	Gas                  hexutil.Big `json:"gas"`
	GasPrice             hexutil.Big `json:"gasPrice"`
	MaxFeePerGas         hexutil.Big `json:"maxFeePerGas"`
	MaxPriorityFeePerGas hexutil.Big `json:"maxPriorityFeePerGas"`
	Hash                 string      `json:"hash"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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