Documentation
¶
Overview ¶
Package changesets provides reusable EVM changesets.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TransferNativeOp = operations.NewOperation( "transfer-native-op", semver.MustParse("1.0.0"), "Operation to transfer funds from the deployer key to another address", func(b operations.Bundle, deps TransferNativeDeps, input TransferNativeOpsInput) (TransferNativeOutput, error) { chain, ok := deps.Env.BlockChains.EVMChains()[input.ChainSel] if !ok { return TransferNativeOutput{}, fmt.Errorf("chain not found for selector %d", input.ChainSel) } nonce, err := chain.Client.NonceAt(b.GetContext(), chain.DeployerKey.From, nil) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not get latest nonce for deployer key: %w", err) } tipCap, err := chain.Client.SuggestGasTipCap(b.GetContext()) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not suggest gas tip cap: %w", err) } latestBlock, err := chain.Client.HeaderByNumber(b.GetContext(), nil) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not get latest block: %w", err) } baseFee := latestBlock.BaseFee feeCap := new(big.Int).Add( new(big.Int).Mul(baseFee, big.NewInt(2)), tipCap, ) account := input.Address gasLimit, err := chain.Client.EstimateGas(b.GetContext(), ethereum.CallMsg{ From: chain.DeployerKey.From, To: &account, Value: input.Amount, }) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not estimate gas for chain %d: %w", chain.Selector, err) } gasCost := new(big.Int).Mul(new(big.Int).SetUint64(gasLimit), feeCap) gasPlusValue := new(big.Int).Add(gasCost, input.Amount) bal, err := chain.Client.BalanceAt(b.GetContext(), chain.DeployerKey.From, nil) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not get balance for deployer key: %w", err) } if bal.Cmp(gasPlusValue) < 0 { return TransferNativeOutput{}, fmt.Errorf("deployer key balance %d is insufficient to cover transfer amount %d plus max gas cost %d", bal, input.Amount, gasCost) } baseTx := &gethtypes.DynamicFeeTx{ Nonce: nonce, GasTipCap: tipCap, GasFeeCap: feeCap, Gas: gasLimit, To: &account, Value: input.Amount, } tx := gethtypes.NewTx(baseTx) signedTx, err := chain.DeployerKey.Signer(chain.DeployerKey.From, tx) if err != nil { return TransferNativeOutput{}, fmt.Errorf("could not sign transaction for account %s: %w", account.Hex(), err) } err = chain.Client.SendTransaction(b.GetContext(), signedTx) if err != nil { return TransferNativeOutput{}, fmt.Errorf("failed to send transfer to %s on chain %d: %w", account.Hex(), chain.Selector, err) } _, err = chain.Confirm(signedTx) if err != nil { return TransferNativeOutput{}, fmt.Errorf("failed to confirm transfer to %s on chain %d (tx %s): %w", account.Hex(), chain.Selector, signedTx.Hash().Hex(), err) } return TransferNativeOutput{}, nil }, )
TransferNativeOp is the operation that performs the native token transfer.
var TransferNativeSeq = operations.NewSequence( "transfer-native-seq", semver.MustParse("1.0.0"), "Sequence to transfer native funds from the deployer key to another address", func(b operations.Bundle, deps TransferNativeDeps, input TransferNativeOpsInput) (TransferNativeOutput, error) { _, err := operations.ExecuteOperation( b, TransferNativeOp, TransferNativeDeps{ Env: deps.Env, }, input, ) if err != nil { return TransferNativeOutput{}, fmt.Errorf("failed to transfer funds: %w", err) } return TransferNativeOutput{}, nil }, )
TransferNativeSeq is the sequence that executes the native token transfer.
Functions ¶
This section is empty.
Types ¶
type TransferNative ¶
type TransferNative struct{}
TransferNative is a changeset that transfers native funds from the deployer key to another address.
func (TransferNative) Apply ¶
func (t TransferNative) Apply(e cldf.Environment, config TransferNativeInput) (cldf.ChangesetOutput, error)
Apply transfers native funds from the deployer key to the configured address on the given chain.
func (TransferNative) VerifyPreconditions ¶
func (t TransferNative) VerifyPreconditions(e cldf.Environment, config TransferNativeInput) error
VerifyPreconditions validates the input and simulates the transfer to ensure it will succeed.
type TransferNativeDeps ¶
type TransferNativeDeps struct {
Env *cldf.Environment
}
TransferNativeDeps holds the dependencies for the TransferNativeOp operation.
type TransferNativeInput ¶
type TransferNativeInput struct {
ChainSel uint64 `json:"chainSel" yaml:"chainSel"`
Address string `json:"address" yaml:"address"`
Amount *big.Int `json:"amount" yaml:"amount"`
}
TransferNativeInput holds the parameters for a native token transfer.
type TransferNativeOpsInput ¶
TransferNativeOpsInput is the input for the TransferNativeOp operation.
type TransferNativeOutput ¶
type TransferNativeOutput struct{}
TransferNativeOutput is the output for the TransferNativeOp operation.