contract

package
v0.93.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllCallersAllowed

func AllCallersAllowed[C any, ARGS any](contract C, opts *bind.CallOpts, caller common.Address, args ARGS) (bool, error)

func MaybeDeployContract

func MaybeDeployContract[ARGS any](
	b operations.Bundle,
	op *operations.Operation[DeployInput[ARGS], datastore.AddressRef, evm.Chain],
	chain evm.Chain,
	input DeployInput[ARGS],
	existingAddresses []datastore.AddressRef) (datastore.AddressRef, error)

MaybeDeployContract deploys the contract if no matching address already exists. If an existing AddressRef matches the type, version, and optional qualifier, it is returned without deploying.

func NewBatchOperationFromWrites

func NewBatchOperationFromWrites(outs []WriteOutput) (mcms_types.BatchOperation, error)

NewBatchOperationFromWrites constructs an MCMS BatchOperation from a slice of WriteOutputs. It filters out any WriteOutputs that have already been executed. Returns an error if the WriteOutputs target multiple chains. If all WriteOutputs are executed, it returns an empty BatchOperation and no error.

func NewDeploy

func NewDeploy[ARGS any](params DeployParams[ARGS]) *operations.Operation[DeployInput[ARGS], datastore.AddressRef, evm.Chain]

NewDeploy creates a new operation that deploys an EVM contract. Any interfacing with gethwrappers should happen in the deploy function.

func NewRead

func NewRead[ARGS any, RET any, C any](params ReadParams[ARGS, RET, C]) *operations.Operation[FunctionInput[ARGS], RET, cldf_evm.Chain]

NewRead creates a new read operation. Any interfacing with gethwrappers should live in the callContract function.

func NewWrite

func NewWrite[ARGS any, C any](params WriteParams[ARGS, C]) *operations.Operation[FunctionInput[ARGS], WriteOutput, evm.Chain]

NewWrite creates a new write operation. Any interfacing with gethwrappers should live in the callContract function. If the deployer key is an allowed caller, the transaction will be signed and sent. Otherwise, the MCMS transaction will be returned for alternative handling.

func NoCallersAllowed

func NoCallersAllowed[C any, ARGS any](contract C, opts *bind.CallOpts, caller common.Address, args ARGS) (bool, error)

NoCallersAllowed always returns false, forcing the write to be collected for a proposal rather than executed directly. Use this for operations that must execute atomically within an MCMS proposal alongside other owner-gated operations.

func OnlyOwner

func OnlyOwner[C ownableContract, ARGS any](contract C, opts *bind.CallOpts, caller common.Address, args ARGS) (bool, error)

Types

type Bytecode

type Bytecode struct {
	EVM      []byte
	ZkSyncVM []byte
}

Bytecode specifies the exact bytecode to deploy for each supported VM. Specifying multiple possible bytecodes allows callers to inject different bytecodes into the same deployment operation. So long as the constructor arguments and ABI remain the same, the bytecode can be swapped out.

func (Bytecode) Validate

func (b Bytecode) Validate(isZkSyncVM bool) error

type DeployInput

type DeployInput[ARGS any] struct {
	// ChainSelector is the selector for the chain on which the contract will be deployed.
	// Required to differentiate between operation runs with the same data targeting different chains.
	ChainSelector uint64 `json:"chainSelector"`
	// TypeAndVersion is the desired type and version of the contract to deploy.
	// The deployment operation must define bytecode for this type and version.
	TypeAndVersion deployment.TypeAndVersion `json:"typeAndVersion"`
	// Qualifier is an optional string to differentiate between multiple deployments of
	// the same contract type and version on the same chain. If provided, it is stored
	// in the AddressRef returned by the operation.
	Qualifier *string `json:"qualifier,omitempty"`
	// Args are the parameters passed to the contract constructor.
	Args ARGS `json:"args"`
}

DeployInput is the input structure for the Deploy operation.

type DeployParams

type DeployParams[ARGS any] struct {
	// Name is the name of the operation.
	Name string
	// Version is the version of the operation.
	Version *semver.Version
	// Description is a brief description of the operation.
	Description string
	// ContractMetadata is the metadata from which the ABI is parsed.
	ContractMetadata *bind.MetaData
	// BytecodeByTypeAndVersion is a map of bytecodes for different types and versions of the contract.
	// The key is the string representation of the type and version.
	BytecodeByTypeAndVersion map[string]Bytecode
	// Validate is an optional function to validate the constructor arguments before deployment.
	Validate func(input ARGS) error
}

DeployParams encapsulates all parameters required to create a deploy operation for an EVM contract.

type ExecInfo

type ExecInfo struct {
	// Hash is the transaction hash.
	Hash string
}

ExecInfo contains information about an executed transaction. Defined as a struct in case we want to add more fields in the future without breaking existing usage.

type FunctionInput

type FunctionInput[ARGS any] struct {
	// Address defines the contract to call.
	Address common.Address `json:"address"`
	// ChainSelector is the selector for the chain on which the contract resides.
	// Required to differentiate between operation runs with the same data targeting different chains.
	ChainSelector uint64 `json:"chainSelector"`
	// Args are the parameters passed to the contract call.
	Args ARGS `json:"args"`
}

FunctionInput is the input structure for all reads and writes.

type ReadParams

type ReadParams[ARGS any, RET any, C any] struct {
	// Name is the name of the operation.
	Name string
	// Version is the version of the operation.
	Version *semver.Version
	// Description is a brief description of the operation.
	Description string
	// ContractType is the type of contract to read from.
	ContractType cldf_deployment.ContractType
	// NewContract is a function that creates a new instance of the contract binding.
	NewContract func(address common.Address, backend bind.ContractBackend) (C, error)
	// CallContract is a function that calls the desired read function on the contract.
	CallContract func(contract C, opts *bind.CallOpts, input ARGS) (RET, error)
}

type WriteOutput

type WriteOutput struct {
	// ChainSelector is the selector of the target chain.
	ChainSelector uint64 `json:"chainSelector"`
	// Tx is the prepared transaction (in MCMS format).
	Tx mcms_types.Transaction `json:"tx"`
	// ExecInfo is populated if the write was executed, contains info about the executed transaction.
	ExecInfo *ExecInfo `json:"execInfo,omitempty"`
}

WriteOutput is the output of a write operation.

func (WriteOutput) Executed

func (o WriteOutput) Executed() bool

type WriteParams

type WriteParams[ARGS any, C any] struct {
	// Name is the name of the operation.
	Name string
	// Version is the version of the operation.
	Version *semver.Version
	// Description is a brief description of the operation.
	Description string
	// ContractType is the type of the target contract.
	ContractType deployment.ContractType
	// ContractABI is the ABI of the target contract.
	ContractABI string
	// NewContract is a function that creates a new instance of the contract binding.
	NewContract func(address common.Address, backend bind.ContractBackend) (C, error)
	// IsAllowedCaller is a function that checks if the caller is allowed to call the function.
	IsAllowedCaller func(contract C, opts *bind.CallOpts, caller common.Address, input ARGS) (bool, error)
	// Validate is a function that validates the input arguments.
	Validate func(input ARGS) error
	// CallContract is a function that calls the desired write method on the contract.
	CallContract func(contract C, opts *bind.TransactOpts, input ARGS) (*eth_types.Transaction, error)
}

Jump to

Keyboard shortcuts

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