Documentation
¶
Index ¶
- Constants
- Variables
- func AddCallToMulticaller(mc *batch.MultiCaller, contract *Contract, output any, method string, ...)
- func AddQueryablesToMulticall(mc *batch.MultiCaller, queryables ...IQueryable)
- func EthToGwei(eth float64) float64
- func EthToWei(eth float64) *big.Int
- func GweiToEth(gwei float64) float64
- func GweiToWei(gwei float64) *big.Int
- func QueryAllFields(object any, mc *batch.MultiCaller)
- func WeiToEth(wei *big.Int) float64
- func WeiToGwei(wei *big.Int) float64
- type Contract
- type IExecutionClient
- type IQueryable
- type QueryManager
- func (q *QueryManager) BatchQuery(count int, batchSize int, query func(*batch.MultiCaller, int) error, ...) error
- func (q *QueryManager) FlexBatchQuery(count int, batchSize int, query func(*batch.MultiCaller, int) error, ...) error
- func (q *QueryManager) FlexQuery(query func(*batch.MultiCaller) error, opts *bind.CallOpts, ...) ([]bool, error)
- func (q *QueryManager) Query(query func(*batch.MultiCaller) error, opts *bind.CallOpts, ...) error
- type QuotedBigInt
- type SimulationResult
- type TransactionInfo
- type TransactionManager
- func (t *TransactionManager) BatchExecuteTransactions(txSubmissions []*TransactionSubmission, opts *bind.TransactOpts) ([]*types.Transaction, error)
- func (t *TransactionManager) CreateTransactionInfo(contract *Contract, method string, opts *bind.TransactOpts, parameters ...any) (*TransactionInfo, error)
- func (t *TransactionManager) CreateTransactionInfoRaw(to common.Address, data []byte, opts *bind.TransactOpts) *TransactionInfo
- func (t *TransactionManager) ExecuteTransaction(txInfo *TransactionInfo, opts *bind.TransactOpts) (*types.Transaction, error)
- func (t *TransactionManager) ExecuteTransactionRaw(to common.Address, data []byte, value *big.Int, opts *bind.TransactOpts) (*types.Transaction, error)
- func (t *TransactionManager) GetSafeGasLimit(estimate uint64) (uint64, error)
- func (t *TransactionManager) SignTransaction(txInfo *TransactionInfo, opts *bind.TransactOpts) (*types.Transaction, error)
- func (t *TransactionManager) SimulateTransaction(client IExecutionClient, to common.Address, opts *bind.TransactOpts, ...) SimulationResult
- func (t *TransactionManager) WaitForTransaction(tx *types.Transaction) error
- func (t *TransactionManager) WaitForTransactionByHash(hash common.Hash) error
- func (t *TransactionManager) WaitForTransactions(txs []*types.Transaction) error
- func (t *TransactionManager) WaitForTransactionsByHash(hashes []common.Hash) error
- type TransactionSubmission
Constants ¶
const ( // Amount of wei in 1 ETH WeiPerEth float64 = 1e18 // Amount of wei in 1 gwei WeiPerGwei float64 = 1e9 // Amount of gwei in 1 ETH GweiPerEth float64 = WeiPerEth / WeiPerGwei )
Conversion factors
const ( // The block gas limit (gwei) GasLimit uint64 = 30000000 // Default value for the safe gas limit buffer, in gwei DefaultSafeGasBuffer uint64 = 0 // Default value for the safe gas limit multiplier DefaultSafeGasMultiplier float64 = 1.5 )
Variables ¶
var (
WeiPerGweiFloat *big.Float = big.NewFloat(WeiPerGwei)
)
Functions ¶
func AddCallToMulticaller ¶ added in v0.2.0
func AddCallToMulticaller(mc *batch.MultiCaller, contract *Contract, output any, method string, args ...any)
Simple convenience method to add a contract call to a multicaller
func AddQueryablesToMulticall ¶
func AddQueryablesToMulticall(mc *batch.MultiCaller, queryables ...IQueryable)
Adds a collection of IQueryable calls to a multicall
func EthToWei ¶
Convert a floating-point ETH amount to a wei amount (a native uint256 value on the execution layer)
func GweiToWei ¶
Convert a floating-point gwei amount to a wei amount (a native uint256 value on the execution layer)
func QueryAllFields ¶
func QueryAllFields(object any, mc *batch.MultiCaller)
Adds all of the object's fields that implement IQueryable to the provided multicaller
Types ¶
type Contract ¶
type Contract struct { // A human-readable name of the contract Name string // The contract's address Address common.Address // The contract's ABI ABI *abi.ABI // The underlying bound contract ContractImpl *bind.BoundContract }
Contract is a wrapper for go-ethereum bound contracts
type IExecutionClient ¶
type IExecutionClient interface { // CodeAt returns the code of the given account. This is needed to differentiate // between contract internal errors and the local chain being out of sync. CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) // CallContract executes an Ethereum contract call with the specified data as the // input. CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) // HeaderByHash returns the block header with the given hash. HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) // HeaderByNumber returns a block header from the current canonical chain. If number is // nil, the latest known header is returned. HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) // PendingCodeAt returns the code of the given account in the pending state. PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) // PendingNonceAt retrieves the current pending nonce associated with an account. PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) // SuggestGasPrice retrieves the currently suggested gas price to allow a timely // execution of a transaction. SuggestGasPrice(ctx context.Context) (*big.Int, error) // SuggestGasTipCap retrieves the currently suggested 1559 priority fee to allow // a timely execution of a transaction. SuggestGasTipCap(ctx context.Context) (*big.Int, error) // EstimateGas tries to estimate the gas needed to execute a specific // transaction based on the current pending state of the backend blockchain. // There is no guarantee that this is the true gas limit requirement as other // transactions may be added or removed by miners, but it should provide a basis // for setting a reasonable default. EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) // SendTransaction injects the transaction into the pending pool for execution. SendTransaction(ctx context.Context, tx *types.Transaction) error // FilterLogs executes a log filter operation, blocking during execution and // returning all the results in one batch. // // TODO(karalabe): Deprecate when the subscription one can return past data too. FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) // SubscribeFilterLogs creates a background log filtering operation, returning // a subscription immediately, which can be used to stream the found events. SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) // TransactionReceipt returns the receipt of a transaction by transaction hash. // Note that the receipt is not available for pending transactions. TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) // BlockNumber returns the most recent block number BlockNumber(ctx context.Context) (uint64, error) // BalanceAt returns the wei balance of the given account. // The block number can be nil, in which case the balance is taken from the latest known block. BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) // TransactionByHash returns the transaction with the given hash. TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) // NonceAt returns the account nonce of the given account. // The block number can be nil, in which case the nonce is taken from the latest known block. NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) // SyncProgress retrieves the current progress of the sync algorithm. If there's // no sync currently running, it returns nil. SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) // Get the client's chain ID. ChainID(ctx context.Context) (*big.Int, error) }
This is the common interface for execution clients that implement most of Geth's core functionality.
type IQueryable ¶
type IQueryable interface { // Adds the struct's values to the provided multicall query before it runs AddToQuery(mc *batch.MultiCaller) }
Represents structs that can have their values queried during a multicall
type QueryManager ¶
type QueryManager struct {
// contains filtered or unexported fields
}
Manages multicall-capable queries to the Execution layer.
func NewQueryManager ¶
func NewQueryManager(client IExecutionClient, multicallAddress common.Address, concurrentCallLimit int) *QueryManager
Creates a new query manager. concurrentCallLimit should be the maximum number of batches to query in parallel for batch calls. Negative values mean no limit.
func (*QueryManager) BatchQuery ¶
func (q *QueryManager) BatchQuery(count int, batchSize int, query func(*batch.MultiCaller, int) error, opts *bind.CallOpts) error
Create and execute a multicall query that is too big for one call and must be run in batches
func (*QueryManager) FlexBatchQuery ¶
func (q *QueryManager) FlexBatchQuery(count int, batchSize int, query func(*batch.MultiCaller, int) error, handleResult func(bool, int) error, opts *bind.CallOpts) error
Create and execute a multicall query that is too big for one call and must be run in batches. Use this if one of the calls is allowed to fail without interrupting the others; the returned result array provides information about the success of each call.
func (*QueryManager) FlexQuery ¶
func (q *QueryManager) FlexQuery(query func(*batch.MultiCaller) error, opts *bind.CallOpts, queryables ...IQueryable) ([]bool, error)
Run a multicall query that doesn't perform any return type allocation Use this if one of the calls is allowed to fail without interrupting the others; the returned result array provides information about the success of each call. The 'query' function is an optional general-purpose function you can use to add whatever you want to the multicall before running it. The 'queryables' can be used to simply list a collection of IQueryable objects, each of which will run 'AddToQuery()' on the multicall for convenience.
func (*QueryManager) Query ¶
func (q *QueryManager) Query(query func(*batch.MultiCaller) error, opts *bind.CallOpts, queryables ...IQueryable) error
Run a multicall query that doesn't perform any return type allocation. The 'query' function is an optional general-purpose function you can use to add whatever you want to the multicall before running it. The 'queryables' can be used to simply list a collection of IQueryable objects, each of which will run 'AddToQuery()' on the multicall for convenience.
type QuotedBigInt ¶ added in v0.2.0
Quoted big ints
func (QuotedBigInt) MarshalJSON ¶ added in v0.2.0
func (i QuotedBigInt) MarshalJSON() ([]byte, error)
Serialize the big.Int to JSON
func (*QuotedBigInt) ToInt ¶ added in v0.2.0
func (i *QuotedBigInt) ToInt() *big.Int
Converts the QuotedBigInt to the native type
func (*QuotedBigInt) UnmarshalJSON ¶ added in v0.2.0
func (i *QuotedBigInt) UnmarshalJSON(data []byte) error
Deserialize the big.Int from JSON
type SimulationResult ¶
type SimulationResult struct { // True if the transaction was simulated, false if it was not IsSimulated bool `json:"isSimulated"` // The raw amount of gas, in gwei, the transaction took during simulation EstimatedGasLimit uint64 `json:"estimatedGasLimit"` // A safe gas limit to use for the transaction, in gwei, with a reasonable safety buffer to account for variances from simulation SafeGasLimit uint64 `json:"safeGasLimit"` // Any error / revert that occurred during simulation, indicating the transaction may fail if submitted SimulationError string `json:"simulationError"` }
Information about a transaction's simulation
type TransactionInfo ¶
type TransactionInfo struct { // The transaction's data Data []byte `json:"data"` // The address to send the transaction to To common.Address `json:"to"` // The ETH value, in wei, to send along with the transaction Value *big.Int `json:"value"` // Info about the transaction's simulation SimulationResult SimulationResult `json:"simulationResult"` }
Information of a candidate transaction
type TransactionManager ¶
type TransactionManager struct {
// contains filtered or unexported fields
}
A simple calculator to bolster gas estimates to safe values, checking against the Ethereum gas block limit.
func NewTransactionManager ¶
func NewTransactionManager(client IExecutionClient, safeGasBuffer uint64, safeGasMultiplier float64) (*TransactionManager, error)
Creates a new transaction manager, which can simulate and execute transactions. The simulator determines if transactions will complete without reversion and provides a safe gas limit suggestion. The formula for safe gas calculation is estimate * multiplier + buffer, where the buffer is in gwei.
func (*TransactionManager) BatchExecuteTransactions ¶
func (t *TransactionManager) BatchExecuteTransactions(txSubmissions []*TransactionSubmission, opts *bind.TransactOpts) ([]*types.Transaction, error)
Signs and submits a bundle of transactions to the network that are all sent from the same address. The values for each TX will be in each TX info; the value specified in the opts argument is not used. The GasFeeCap and GasTipCap from opts will be used for all transactions. NOTE: this assumes the bundle is meant to be submitted sequentially, so the nonce of each one will be incremented. Assign the Nonce in the opts tto the nonce you want to use for the first transaction.
func (*TransactionManager) CreateTransactionInfo ¶
func (t *TransactionManager) CreateTransactionInfo(contract *Contract, method string, opts *bind.TransactOpts, parameters ...any) (*TransactionInfo, error)
Create a new TransactionInfo binding for a contract method and simulate its execution
func (*TransactionManager) CreateTransactionInfoRaw ¶
func (t *TransactionManager) CreateTransactionInfoRaw(to common.Address, data []byte, opts *bind.TransactOpts) *TransactionInfo
Create a new serializable TransactionInfo from raw data and simuate its execution
func (*TransactionManager) ExecuteTransaction ¶
func (t *TransactionManager) ExecuteTransaction(txInfo *TransactionInfo, opts *bind.TransactOpts) (*types.Transaction, error)
Signs and submits a transaction to the network. The nonce and gas fee info in the provided opts will be used. The value will come from the provided txInfo. It will *not* use the value in the provided opts.
func (*TransactionManager) ExecuteTransactionRaw ¶
func (t *TransactionManager) ExecuteTransactionRaw(to common.Address, data []byte, value *big.Int, opts *bind.TransactOpts) (*types.Transaction, error)
Create a transaction from serialized info, signs it, and submits it to the network if requested in opts. Note the value in opts is not used; set it in the value argument instead.
func (*TransactionManager) GetSafeGasLimit ¶
func (t *TransactionManager) GetSafeGasLimit(estimate uint64) (uint64, error)
Calculates a gas limit for a gas estimate with the provided safety buffer: estimate * multiplier + buffer. Returns an error if the calculate safe gas limit is higher than the Ethereum block limit.
func (*TransactionManager) SignTransaction ¶
func (t *TransactionManager) SignTransaction(txInfo *TransactionInfo, opts *bind.TransactOpts) (*types.Transaction, error)
Signs a transaction but does not submit it to the network. Use this if you want to sign something offline and submit it later, or submit it as part of a bundle.
func (*TransactionManager) SimulateTransaction ¶
func (t *TransactionManager) SimulateTransaction(client IExecutionClient, to common.Address, opts *bind.TransactOpts, input []byte) SimulationResult
Simulates the transaction, getting the expected and safe gas limits in gwei.
func (*TransactionManager) WaitForTransaction ¶
func (t *TransactionManager) WaitForTransaction(tx *types.Transaction) error
Wait for a transaction to get included in blocks
func (*TransactionManager) WaitForTransactionByHash ¶
func (t *TransactionManager) WaitForTransactionByHash(hash common.Hash) error
Wait for a transaction to get included in blocks
func (*TransactionManager) WaitForTransactions ¶
func (t *TransactionManager) WaitForTransactions(txs []*types.Transaction) error
Wait for a set of transactions to get included in blocks
func (*TransactionManager) WaitForTransactionsByHash ¶
func (t *TransactionManager) WaitForTransactionsByHash(hashes []common.Hash) error
Wait for a set of transactions to get included in blocks
type TransactionSubmission ¶
type TransactionSubmission struct { // The transaction info TxInfo *TransactionInfo `json:"txInfo"` // The gas limit to use when submitting this transaction GasLimit uint64 `json:"gasLimit"` }
Information for submitting a candidate transaction to the network
func CreateTxSubmissionFromInfo ¶
func CreateTxSubmissionFromInfo(txInfo *TransactionInfo, err error) (*TransactionSubmission, error)
Create a transaction submission directly from serialized info (and the error provided by the transaction info constructor), using the SafeGasLimit as the GasLimit for the submission automatically.