Skip to content

Commit

Permalink
feat: add eigenpod bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Jul 29, 2024
1 parent 7c76ea7 commit ad8090d
Show file tree
Hide file tree
Showing 8 changed files with 4,590 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

bindings: ## generates contract bindings
cd contracts && rm -rf bindings/* && ./generate-bindings.sh
cd contracts && rm -rf bindings/* && ./generate-bindings.sh

eigenpod-bindings: ## generates contract bindings for eigenpod
cd chainio/clients/eigenpod && ./generate.sh

mocks: ## generates mocks
go install go.uber.org/mock/[email protected]
Expand Down
84 changes: 84 additions & 0 deletions chainio/clients/eigenpod/bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package eigenpod

import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eigenpod/bindings"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"

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

type ContractBindings struct {
Address common.Address
*bindings.IEigenPod
}

type ContractCallerBindings struct {
Address common.Address
*bindings.IEigenPodCaller
}

type ManagerContractBindings struct {
Address common.Address
*bindings.IEigenPodManager
}

type ManagerContractCallerBindings struct {
Address common.Address
*bindings.IEigenPodManagerCaller
}

func NewContractBindings(
address common.Address,
ethClient eth.HttpBackend,
) (*ContractBindings, error) {
pod, err := bindings.NewIEigenPod(address, ethClient)
if err != nil {
return nil, err
}
return &ContractBindings{
Address: address,
IEigenPod: pod,
}, nil
}

func NewContractCallerBindings(
address common.Address,
ethClient eth.HttpBackend,
) (*ContractCallerBindings, error) {
pod, err := bindings.NewIEigenPodCaller(address, ethClient)
if err != nil {
return nil, err
}
return &ContractCallerBindings{
Address: address,
IEigenPodCaller: pod,
}, nil
}

func NewManagerContractBindings(
address common.Address,
ethClient eth.HttpBackend,
) (*ManagerContractBindings, error) {
manager, err := bindings.NewIEigenPodManager(address, ethClient)
if err != nil {
return nil, err
}
return &ManagerContractBindings{
Address: address,
IEigenPodManager: manager,
}, nil
}

func NewManagerContractCallerBindings(
address common.Address,
ethClient eth.HttpBackend,
) (*ManagerContractCallerBindings, error) {
manager, err := bindings.NewIEigenPodManagerCaller(address, ethClient)
if err != nil {
return nil, err
}
return &ManagerContractCallerBindings{
Address: address,
IEigenPodManagerCaller: manager,
}, nil
}
2,268 changes: 2,268 additions & 0 deletions chainio/clients/eigenpod/bindings/IEigenPod.go

Large diffs are not rendered by default.

1,956 changes: 1,956 additions & 0 deletions chainio/clients/eigenpod/bindings/IEigenPodManager.go

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions chainio/clients/eigenpod/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package eigenpod

import (
"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/ethereum/go-ethereum/common"
)

func BuildEigenPodClients(
address common.Address,
client eth.HttpBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainReader, *ChainWriter, *ContractBindings, error) {
eigenPodBindings, err := NewContractBindings(address, client)
if err != nil {
return nil, nil, nil, err
}

eigenPodChainReader := newChainReader(
&eigenPodBindings.IEigenPodCaller,
client,
logger,
)

eigenPodChainWriter := newChainWriter(
eigenPodBindings.IEigenPod,
client,
logger,
txMgr,
)

return eigenPodChainReader, eigenPodChainWriter, eigenPodBindings, nil
}

func BuildEigenPodManagerClients(
address common.Address,
client eth.HttpBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ManagerChainReader, *ManagerChainWriter, *ManagerContractBindings, error) {
eigenPodManagerBindings, err := NewManagerContractBindings(address, client)
if err != nil {
return nil, nil, nil, err
}

eigenPodManagerChainReader := newManagerChainReader(
&eigenPodManagerBindings.IEigenPodManagerCaller,
client,
logger,
)

eigenPodManagerChainWriter := newManagerChainWriter(
eigenPodManagerBindings.IEigenPodManager,
client,
logger,
txMgr,
)

return eigenPodManagerChainReader, eigenPodManagerChainWriter, eigenPodManagerBindings, nil
}
57 changes: 57 additions & 0 deletions chainio/clients/eigenpod/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

TMP_DIR=tmp
BINDINGS_DIR=bindings

cleanup_bindings_dir() {
echo "Cleaning up the bindings directory"
rm -rf ${BINDINGS_DIR}
}

create_tmp_dir() {
echo "Creating a temporary directory"
mkdir -p ${TMP_DIR}
}

clone() {
echo "Cloning the EigenLayer contracts repository"
git clone -b feat/partial-withdrawal-batching --depth=1 [email protected]:Layr-Labs/eigenlayer-contracts.git ${TMP_DIR}
}

generate_bindings() {
echo "Generating bindings for the EigenPods contracts"
cd ${TMP_DIR} && make bindings
cd ..
mkdir -p ${BINDINGS_DIR}
generate_go ${TMP_DIR}/out/IEigenPod.sol/IEigenPod.json IEigenPod
generate_go ${TMP_DIR}/out/IEigenPodManager.sol/IEigenPodManager.json IEigenPodManager
}

generate_go() {
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "jq is required but not installed. Please install jq (brew install jq)."
exit 1
fi

temp_file=$(mktemp)
echo "Generating Go bindings for the $1 contract"
jq '.abi' "$1" > "$temp_file" && mv "$temp_file" "$1"

abigen --abi "$1" --pkg bindings --type "$2" --out "$BINDINGS_DIR"/"$2".go
}

cleanup() {
echo "Cleaning up the temporary directory"
rm -rf ${TMP_DIR}
}

main() {
cleanup_bindings_dir
create_tmp_dir
clone
generate_bindings
cleanup
}

main
74 changes: 74 additions & 0 deletions chainio/clients/eigenpod/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package eigenpod

import (
"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/logging"
"github.com/ethereum/go-ethereum/common"
)

type ChainReader struct {
logger logging.Logger
ethClient eth.HttpBackend
*bindings.IEigenPodCaller
}

type ManagerChainReader struct {
logger logging.Logger
ethClient eth.HttpBackend
*bindings.IEigenPodManagerCaller
}

func newChainReader(
eigenPod *bindings.IEigenPodCaller,
ethClient eth.HttpBackend,
logger logging.Logger,
) *ChainReader {
logger = logger.With(logging.ComponentKey, "eigenpod/reader")

return &ChainReader{
logger: logger,
ethClient: ethClient,
IEigenPodCaller: eigenPod,
}
}

func newManagerChainReader(
manager *bindings.IEigenPodManagerCaller,
ethClient eth.HttpBackend,
logger logging.Logger,
) *ManagerChainReader {
logger = logger.With(logging.ComponentKey, "eigenpodmanager/reader")

return &ManagerChainReader{
logger: logger,
ethClient: ethClient,
IEigenPodManagerCaller: manager,
}
}

func NewReader(
address common.Address,
ethClient eth.HttpBackend,
logger logging.Logger,
) (*ChainReader, error) {
pod, err := NewContractCallerBindings(address, ethClient)
if err != nil {
return nil, err
}

return newChainReader(pod.IEigenPodCaller, ethClient, logger), nil
}

func NewManagerReader(
address common.Address,
ethClient eth.HttpBackend,
logger logging.Logger,
) (*ManagerChainReader, error) {
manager, err := NewManagerContractCallerBindings(address, ethClient)
if err != nil {
return nil, err
}

return newManagerChainReader(manager.IEigenPodManagerCaller, ethClient, logger), nil
}
85 changes: 85 additions & 0 deletions chainio/clients/eigenpod/writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package eigenpod

import (
"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/ethereum/go-ethereum/common"
)

type ChainWriter struct {
logger logging.Logger
ethClient eth.HttpBackend
eigenPod *bindings.IEigenPod
txMgr txmgr.TxManager
}

type ManagerChainWriter struct {
logger logging.Logger
ethClient eth.HttpBackend
manager *bindings.IEigenPodManager
txMgr txmgr.TxManager
}

func newChainWriter(
eigenPod *bindings.IEigenPod,
ethClient eth.HttpBackend,
logger logging.Logger,
txMgr txmgr.TxManager,
) *ChainWriter {
logger = logger.With(logging.ComponentKey, "eigenpod/writer")

return &ChainWriter{
logger: logger,
ethClient: ethClient,
eigenPod: eigenPod,
txMgr: txMgr,
}
}

func newManagerChainWriter(
manager *bindings.IEigenPodManager,
ethClient eth.HttpBackend,
logger logging.Logger,
txMgr txmgr.TxManager,
) *ManagerChainWriter {
logger = logger.With(logging.ComponentKey, "eigenpodmanager/writer")

return &ManagerChainWriter{
logger: logger,
ethClient: ethClient,
manager: manager,
txMgr: txMgr,
}
}

func NewWriter(
address common.Address,
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ChainWriter, error) {
pod, err := bindings.NewIEigenPod(address, ethClient)
if err != nil {
return nil, err
}

return newChainWriter(pod, ethClient, logger, txMgr), nil
}

func NewManagerWriter(
address common.Address,
ethClient eth.HttpBackend,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*ManagerChainWriter, error) {
manager, err := bindings.NewIEigenPodManager(address, ethClient)
if err != nil {
return nil, err
}

return newManagerChainWriter(manager, ethClient, logger, txMgr), nil
}

// TODO(madhur): Add methods to ChainWriter and ManagerChainWriter to interact with the contracts.

0 comments on commit ad8090d

Please sign in to comment.