Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add eigenpod write methods #314

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion chainio/clients/eigenpod/writer.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package eigenpod

import (
"context"
"math/big"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/eigenpod/bindings"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/utils"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

type ChainWriter struct {
Expand Down Expand Up @@ -84,4 +88,87 @@ func NewManagerWriter(
return newManagerChainWriter(manager, ethClient, logger, txMgr), nil
}

// TODO(madhur): Add methods to ChainWriter and ManagerChainWriter to interact with the contracts.
func (w *ChainWriter) VerifyWithdrawalCredentials(
ctx context.Context,
beaconTimestamp uint64,
stateRootProof bindings.BeaconChainProofsStateRootProof,
validatorIndices []*big.Int,
validatorFieldsProofs [][]byte,
validatorFields [][][32]byte,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be nice to document what this is. Or define named types for self-documenting code.

) (*types.Receipt, error) {
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}

tx, err := w.eigenPod.VerifyWithdrawalCredentials(
noSendTxOpts,
beaconTimestamp,
stateRootProof,
validatorIndices,
validatorFieldsProofs,
validatorFields,
)
if err != nil {
return nil, utils.WrapError("failed to create tx", err)
}

receipt, err := w.txMgr.Send(ctx, tx)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}

return receipt, nil
}

func (w *ChainWriter) VerifyCheckpointProofs(
ctx context.Context,
balanceContainerProof bindings.BeaconChainProofsBalanceContainerProof,
balanceProof []bindings.BeaconChainProofsBalanceProof,
) (*types.Receipt, error) {
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}

tx, err := w.eigenPod.VerifyCheckpointProofs(
noSendTxOpts,
balanceContainerProof,
balanceProof,
)
if err != nil {
return nil, utils.WrapError("failed to create tx", err)
}

receipt, err := w.txMgr.Send(ctx, tx)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}

return receipt, nil
}

func (w *ChainWriter) StartCheckpoint(
ctx context.Context,
revertIfNoBalance bool,
) (*types.Receipt, error) {
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}

tx, err := w.eigenPod.StartCheckpoint(
noSendTxOpts,
revertIfNoBalance,
)
if err != nil {
return nil, utils.WrapError("failed to create tx", err)
}

receipt, err := w.txMgr.Send(ctx, tx)
if err != nil {
return nil, utils.WrapError("failed to send tx", err)
}

return receipt, nil
}