utils

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 36 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ValidatorStatusInactive  = 0
	ValidatorStatusActive    = 1
	ValidatorStatusWithdrawn = 2
)
View Source
const (
	BLSWithdrawalPrefix         = 0
	ETH1WithdrawalPrefix        = 1
	CompoundingWithdrawalPrefix = 2
)
View Source
const FAR_FUTURE_EPOCH = math.MaxUint64

(https://github.com/Layr-Labs/eigenlayer-contracts/blob/d148952a2942a97a218a2ab70f9b9f1792796081/src/contracts/libraries/BeaconChainProofs.sol#L64)

Variables

View Source
var (
	ErrNoEigenPod               = errors.New("no eigenpod associated with owner")
	ErrBeaconClientNotSupported = errors.New("could not instantiate beacon chain client")
	ErrValidatorNotFound        = errors.New("validator not found")
)
View Source
var (
	CONSOLIDATION_PREDEPLOY = common.HexToAddress("0x0000BBdDc7CE488642fb579F8B00f3a590007251")
	WITHDRAWAL_PREDEPLOY    = common.HexToAddress("0x00000961Ef480Eb55e80D19ad83579A64c007002")

	// 2**256 - 1
	EXCESS_INHIBITOR = new(big.Int).Sub(
		new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil),
		big.NewInt(1),
	)

	// Consolidation constants
	MAX_CONSOLIDATION_REQUESTS_PER_BLOCK      = big.NewInt(2)
	MIN_CONSOLIDATION_REQUEST_FEE             = big.NewInt(1)
	CONSOLIDATION_REQUEST_FEE_UPDATE_FRACTION = big.NewInt(17)

	// Withdrawal constants
	MAX_WITHDRAWAL_REQUESTS_PER_BLOCK      = big.NewInt(16)
	MIN_WITHDRAWAL_REQUEST_FEE             = big.NewInt(1)
	WITHDRAWAL_REQUEST_FEE_UPDATE_FRACTION = big.NewInt(17)
)

Constants defined in predeploy EIPs: - EIP-7521: https://eips.ethereum.org/EIPS/eip-7251#constants - EIP-7002: https://eips.ethereum.org/EIPS/eip-7002#configuration

Functions

func AllZero

func AllZero(s []byte) bool

func CastValidatorFields

func CastValidatorFields(proof [][]eigenpodproofs.Bytes32) [][][32]byte

golang was a mistake. these types are literally identical :'(

func Chunk

func Chunk[T any](arr []T, chunkSize uint64) [][]T

func ContextWithTracing

func ContextWithTracing(ctx context.Context, callbacks *TracerCallbacks) context.Context

func CurrentConsolidationFee

func CurrentConsolidationFee(client *ethclient.Client) (*big.Int, error)

CurrentConsolidationFee queries the EIP-7521 predeploy to get the current per-request fee in wei

func CurrentWithdrawalFee

func CurrentWithdrawalFee(client *ethclient.Client) (*big.Int, error)

CurrentWithdrawalFee queries the EIP-7002 predeploy to get the current per-request fee in wei

func FetchMultipleOnchainValidatorInfoMulticalls

func FetchMultipleOnchainValidatorInfoMulticalls(eigenpodAddress string, allValidators []*phase0.Validator) ([]*multicall.MultiCallMetaData[EigenPod.IEigenPodTypesValidatorInfo], error)

func ForkVersions

func ForkVersions() map[uint64]string

this is a mapping from <chainId, genesis_fork_version>.

func GetBeaconHeadState

func GetBeaconHeadState(ctx context.Context, beaconClient BeaconClient) (*spec.VersionedBeaconState, error)

func GetCheckpointTimestampAndBeaconState

func GetCheckpointTimestampAndBeaconState(
	ctx context.Context,
	eigenpodAddress string,
	eth *ethclient.Client,
	beaconClient BeaconClient,
) (uint64, *spec.VersionedBeaconState, error)

Fetch and return the current checkpoint timestamp for the pod If the checkpoint exists (timestamp != 0), also return the beacon state for the checkpoint If the checkpoint does not exist (timestamp == 0), return the head beacon state (i.e. the state we would use "if we start a checkpoint now")

func GetCurrentCheckpoint

func GetCurrentCheckpoint(eigenpodAddress string, client *ethclient.Client) (uint64, error)

func GetCurrentCheckpointBlockRoot

func GetCurrentCheckpointBlockRoot(eigenpodAddress string, eth *ethclient.Client) (*[32]byte, error)

func GetEigenPodValidatorsByIndex

func GetEigenPodValidatorsByIndex(
	eigenpodAddress string,
	beaconState *spec.VersionedBeaconState,
) (map[uint64]*phase0.Validator, error)

GetEigenPodValidatorsByIndex looks up all validators for an eigenpod and returns a map from validator index to validator info

func GetEthClient

func GetEthClient(ctx context.Context, node string) (*ethclient.Client, *big.Int, error)

func GetExcessConsolidationRequests

func GetExcessConsolidationRequests(client *ethclient.Client) (*big.Int, error)

GetExcessConsolidationRequests reads EIP-7521 predeploy storage slot 0 to get the number of excess requests currently in the queue.

func GetExcessWithdrawalRequests

func GetExcessWithdrawalRequests(client *ethclient.Client) (*big.Int, error)

GetExcessConsolidationRequests reads EIP-7002 predeploy storage slot 0 to get the number of excess requests currently in the queue.

func GweiToEther

func GweiToEther(val *big.Float) *big.Float

func GweiToWei

func GweiToWei(val *big.Float) *big.Float

func IGweiToWei

func IGweiToWei(val *big.Int) *big.Int

func IsAwaitingWithdrawalCredentialProof

func IsAwaitingWithdrawalCredentialProof(validatorInfo EigenPod.IEigenPodTypesValidatorInfo, validator *phase0.Validator) bool

func IweiToEther

func IweiToEther(val *big.Int) *big.Float

func Panic

func Panic(message string)

func PanicIfNoConsent

func PanicIfNoConsent(prompt string)

func PanicOnError

func PanicOnError(message string, err error)

func SortByStatus

func SortByStatus(validators map[string]Validator) ([]Validator, []Validator, []Validator, []Validator)

func StartCheckpoint

func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKey string, chainId *big.Int, eth *ethclient.Client, forceCheckpoint bool, noSend bool) (*types.Transaction, error)

func StartCheckpointProofConsent

func StartCheckpointProofConsent() string

func SubmitCredentialsProofConsent

func SubmitCredentialsProofConsent(numTransactions int) string

func SubmitFullExitRequestConsent

func SubmitFullExitRequestConsent(
	numRequests int,
	currentQueueSize *big.Int,
	currentFee string,
	totalFee string,
	totalOverestimateFee string,
	isSimulatedStr string,
) string

func SubmitPartialExitRequestConsent

func SubmitPartialExitRequestConsent(
	numRequests int,
	currentQueueSize *big.Int,
	currentFee string,
	totalFee string,
	totalOverestimateFee string,
	isSimulatedStr string,
) string

func SubmitSourceToTargetRequestConsent

func SubmitSourceToTargetRequestConsent(
	numRequests int,
	currentQueueSize *big.Int,
	currentFee string,
	totalFee string,
	totalOverestimateFee string,
	targetValidator uint64,
	numSourceValidators int,
	isSimulatedStr string,
) string

func SubmitSwitchRequestConsent

func SubmitSwitchRequestConsent(
	numRequests int,
	currentQueueSize *big.Int,
	currentFee string,
	totalFee string,
	totalOverestimateFee string,
	isSimulatedStr string,
) string

func Uint64ArrayToBigIntArray

func Uint64ArrayToBigIntArray(nums []uint64) []*big.Int

func WeiToGwei

func WeiToGwei(val *big.Int) *big.Float

func WriteOutputToFileOrStdout

func WriteOutputToFileOrStdout(output []byte, out *string) error

Types

type BeaconClient

type BeaconClient interface {
	GetBeaconHeader(ctx context.Context, blockId string) (*v1.BeaconBlockHeader, error)
	GetBeaconState(ctx context.Context, stateId string) (*spec.VersionedBeaconState, error)
	GetValidator(ctx context.Context, index uint64) (*v1.Validator, error)
	GetGenesisForkVersion(ctx context.Context) (*phase0.Version, error)
}

func GetBeaconClient

func GetBeaconClient(beaconUri string, verbose bool) (BeaconClient, error)

func GetClients

func GetClients(ctx context.Context, node, beaconNodeUri string, enableLogs bool) (*ethclient.Client, BeaconClient, *big.Int, error)

func NewBeaconClient

func NewBeaconClient(endpoint string, verbose bool) (BeaconClient, context.CancelFunc, error)

type Checkpoint

type Checkpoint struct {
	ProofsRemaining uint64
	StartedAt       uint64
}

type ConsolidatableValidatorSet

type ConsolidatableValidatorSet struct {
	Sources []ValidatorWithIndex
	Targets []ValidatorWithIndex
}

type Owner

type Owner = struct {
	FromAddress        common.Address
	PublicKey          *ecdsa.PublicKey
	TransactionOptions *bind.TransactOpts
	IsDryRun           bool
}

func PrepareAccount

func PrepareAccount(owner *string, chainID *big.Int, noSend bool) (*Owner, error)

type Predeploy

type Predeploy struct {
	Address common.Address
	Caller  bind.ContractCaller
}

type PredeployFeeInfo

type PredeployFeeInfo struct {
	CurrentQueueSize *big.Int
	FeePerRequest    *big.Int
	TotalFee         *big.Int
	OverestimateFee  *big.Int
}

func EstimateConsolidationFeePerChunk

func EstimateConsolidationFeePerChunk(
	client *ethclient.Client,
	requestChunks [][]EigenPod.IEigenPodTypesConsolidationRequest,
) ([]*PredeployFeeInfo, error)

EstimateConsolidationFeePerChunk estimates the consolidation fee required to submit multiple "chunks" of consolidation requests. This method assumes the requests are submitted in sequential blocks, with the system address updating the fee between each block.

The returned array is the "fee per request" for each chunk

func EstimateWithdrawalFeePerChunk

func EstimateWithdrawalFeePerChunk(
	client *ethclient.Client,
	requestChunks [][]EigenPod.IEigenPodTypesWithdrawalRequest,
) ([]*PredeployFeeInfo, error)

EstimateWithdrawalFeePerChunk estimates the withdrawal fee required to submit multiple "chunks" of withdrawal requests. This method assumes the requests are submitted in sequential blocks, with the system address updating the fee between each block.

The returned array is the "fee per request" for each chunk

func GetConsolidationFeeInfoForRequest

func GetConsolidationFeeInfoForRequest(
	client *ethclient.Client,
	request []EigenPod.IEigenPodTypesConsolidationRequest,
	overestimateFactor float64,
) (*PredeployFeeInfo, error)

GetConsolidationFeeInfoForRequest retrieves info on the current fees required to submit consolidation requests.

func GetWithdrawalFeeInfoForRequest

func GetWithdrawalFeeInfoForRequest(
	client *ethclient.Client,
	request []EigenPod.IEigenPodTypesWithdrawalRequest,
	overestimateFactor float64,
) (*PredeployFeeInfo, error)

GetWithdrawalFeeInfoForRequest retrieves info on the current fees required to submit withdrawal requests.

type TEigenKey

type TEigenKey string
const EIGEN_KEY TEigenKey = "com.eigen.tracer"

type TracerCallbacks

type TracerCallbacks struct {
	OnStartSection func(name string, metadata map[string]string)
	OnEndSection   func()
}

func GetContextTracingCallbacks

func GetContextTracingCallbacks(ctx context.Context) *TracerCallbacks

type Validator

type Validator struct {
	Slashed                             bool
	Index                               uint64
	Status                              int
	PublicKey                           string
	IsAwaitingActivationQueue           bool
	IsAwaitingWithdrawalCredentialProof bool
	EffectiveBalance                    uint64
	CurrentBalance                      uint64
	WithdrawalPrefix                    uint8
}

type ValidatorWithIndex

type ValidatorWithIndex = struct {
	Validator *phase0.Validator
	Index     uint64
}

func FindAllValidatorsForEigenpod

func FindAllValidatorsForEigenpod(eigenpodAddress string, beaconState *spec.VersionedBeaconState) ([]ValidatorWithIndex, error)

search through beacon state for validators whose withdrawal address is set to eigenpod.

type ValidatorWithMaybeOnchainInfo

type ValidatorWithMaybeOnchainInfo = struct {
	Info      *EigenPod.IEigenPodTypesValidatorInfo
	Validator *phase0.Validator
	Index     uint64
}

func FetchMultipleOnchainValidatorInfoWithFailures

func FetchMultipleOnchainValidatorInfoWithFailures(ctx context.Context, client *ethclient.Client, eigenpodAddress string, allValidators []ValidatorWithIndex) ([]ValidatorWithMaybeOnchainInfo, error)

type ValidatorWithOnchainInfo

type ValidatorWithOnchainInfo = struct {
	Info      EigenPod.IEigenPodTypesValidatorInfo
	Validator *phase0.Validator
	Index     uint64
}

func FetchMultipleOnchainValidatorInfo

func FetchMultipleOnchainValidatorInfo(ctx context.Context, client *ethclient.Client, eigenpodAddress string, allValidators []ValidatorWithIndex) ([]ValidatorWithOnchainInfo, error)

func SelectActiveValidators

func SelectActiveValidators(
	client *ethclient.Client,
	eigenpodAddress string,
	validators []ValidatorWithOnchainInfo,
) ([]ValidatorWithOnchainInfo, error)

func SelectAwaitingActivationValidators

func SelectAwaitingActivationValidators(
	client *ethclient.Client,
	eigenpodAddress string,
	validators []ValidatorWithOnchainInfo,
) ([]ValidatorWithOnchainInfo, error)

Validators whose deposits have been processed but are awaiting activation on the beacon chain If the validator has 32 ETH effective balance, they should

func SelectAwaitingCredentialValidators

func SelectAwaitingCredentialValidators(
	client *ethclient.Client,
	eigenpodAddress string,
	validators []ValidatorWithOnchainInfo,
) ([]ValidatorWithOnchainInfo, error)

func SelectCheckpointableValidators

func SelectCheckpointableValidators(
	client *ethclient.Client,
	eigenpodAddress string,
	validators []ValidatorWithOnchainInfo,
	lastCheckpoint uint64,
) ([]ValidatorWithOnchainInfo, error)

Jump to

Keyboard shortcuts

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