-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
4,604 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
1,956 changes: 1,956 additions & 0 deletions
1,956
chainio/clients/eigenpod/bindings/IEigenPodManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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/Layr-Labs/eigensdk-go/utils" | ||
|
||
"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, utils.WrapError("failed to create EigenPod contract bindings", 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, utils.WrapError("failed to create EigenPod manager contract bindings", err) | ||
} | ||
|
||
eigenPodManagerChainReader := newManagerChainReader( | ||
&eigenPodManagerBindings.IEigenPodManagerCaller, | ||
client, | ||
logger, | ||
) | ||
|
||
eigenPodManagerChainWriter := newManagerChainWriter( | ||
eigenPodManagerBindings.IEigenPodManager, | ||
client, | ||
logger, | ||
txMgr, | ||
) | ||
|
||
return eigenPodManagerChainReader, eigenPodManagerChainWriter, eigenPodManagerBindings, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
# This script generates Go bindings for the EigenPods contracts | ||
# The reason this script is separate from the bindings generation in the ~/contracts directory | ||
# is because they are in a separate branch in eigenlayer-contracts and to unblock the development | ||
# of the EigenPods client, we need to generate the bindings for the contracts in the feat/partial-withdrawal-batching branch. | ||
# Once eigenlayer-contracts repo is stable and features are on single branch, we can move the bindings back to normal process | ||
|
||
TMP_DIR=$(mktemp -d) | ||
BINDINGS_DIR=bindings | ||
|
||
cleanup_bindings_dir() { | ||
echo "Cleaning up the bindings directory" | ||
rm -rf ${BINDINGS_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" | ||
current_dir=$(pwd) | ||
cd "${TMP_DIR}" && make bindings | ||
# shellcheck disable=SC2164 | ||
cd "$current_dir" | ||
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 | ||
clone | ||
generate_bindings | ||
cleanup | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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/Layr-Labs/eigensdk-go/utils" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// ChainReader is a reader for the EigenPod contract. | ||
// We want it to be different from the ManagerChainReader since as a user, | ||
// I only need this reader to manage my EigenPod. So there's no need for ManagerChainReader | ||
type ChainReader struct { | ||
logger logging.Logger | ||
ethClient eth.HttpBackend | ||
*bindings.IEigenPodCaller | ||
} | ||
|
||
// ManagerChainReader is a reader for the EigenPodManager contract. | ||
// We want it to be different from the ChainReader since as a user, this is only | ||
// needed to get overall state of all the EigenPods in the system. | ||
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( | ||
eigenPodAddress common.Address, | ||
ethClient eth.HttpBackend, | ||
logger logging.Logger, | ||
) (*ChainReader, error) { | ||
pod, err := NewContractCallerBindings(eigenPodAddress, ethClient) | ||
if err != nil { | ||
return nil, utils.WrapError("Failed to create EigenPod contract", err) | ||
} | ||
|
||
return newChainReader(pod.IEigenPodCaller, ethClient, logger), nil | ||
} | ||
|
||
func NewManagerReader( | ||
eigenPodManagerAddress common.Address, | ||
ethClient eth.HttpBackend, | ||
logger logging.Logger, | ||
) (*ManagerChainReader, error) { | ||
manager, err := NewManagerContractCallerBindings(eigenPodManagerAddress, ethClient) | ||
if err != nil { | ||
return nil, utils.WrapError("Failed to create EigenPodManager contract", err) | ||
} | ||
|
||
return newManagerChainReader(manager.IEigenPodManagerCaller, ethClient, logger), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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/Layr-Labs/eigensdk-go/utils" | ||
|
||
"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( | ||
eigenPodAddress common.Address, | ||
ethClient eth.HttpBackend, | ||
txMgr txmgr.TxManager, | ||
logger logging.Logger, | ||
) (*ChainWriter, error) { | ||
pod, err := bindings.NewIEigenPod(eigenPodAddress, ethClient) | ||
if err != nil { | ||
return nil, utils.WrapError("Failed to create EigenPod contract", err) | ||
} | ||
|
||
return newChainWriter(pod, ethClient, logger, txMgr), nil | ||
} | ||
|
||
func NewManagerWriter( | ||
eigenPodManagerAddress common.Address, | ||
ethClient eth.HttpBackend, | ||
txMgr txmgr.TxManager, | ||
logger logging.Logger, | ||
) (*ManagerChainWriter, error) { | ||
manager, err := bindings.NewIEigenPodManager(eigenPodManagerAddress, ethClient) | ||
if err != nil { | ||
return nil, utils.WrapError("Failed to create EigenPodManager contract", err) | ||
} | ||
|
||
return newManagerChainWriter(manager, ethClient, logger, txMgr), nil | ||
} | ||
|
||
// TODO(madhur): Add methods to ChainWriter and ManagerChainWriter to interact with the contracts. |