Skip to content

Commit

Permalink
Merge branch 'dev' into feat-improve-bls-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
taturosati authored Aug 7, 2024
2 parents 6440d21 + 108520f commit ed0b830
Show file tree
Hide file tree
Showing 46 changed files with 3,575 additions and 2,426 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
GO_LINES_IGNORED_DIRS=contracts
GO_PACKAGES=./chainio/... ./crypto/... ./logging/... \
./types/... ./utils/... ./signer/... ./cmd/... \
./signerv2/...
./signerv2/... ./aws/... ./internal/... ./metrics/... \
./nodeapi/... ./cmd/... ./services/... ./testutils/...
GO_FOLDERS=$(shell echo ${GO_PACKAGES} | sed -e "s/\.\///g" | sed -e "s/\/\.\.\.//g")
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
![Go Coverage](https://github.com/Layr-Labs/eigensdk-go/wiki/coverage.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/Layr-Labs/eigensdk-go)](https://goreportcard.com/report/github.com/Layr-Labs/eigensdk-go)

<p align="center"><b>
🚧 Under active development. EIGENSDK-GO is rapidly being upgraded, features are being added, interfaces will have breaking changes 🚧
</b><p>

**Do not use it in Production, testnet only.**


## EigenSDK
This SDK provides a set of primitive Go modules for developing AVSs used in EigenLayer
This SDK provides a set of primitive Go modules for developing AVSs on EigenLayer.

## Installation
```
Expand Down Expand Up @@ -39,7 +36,10 @@ Follow the [contribution guidelines](CONTRIBUTING.md) to contribute to eigensdk-

## Branches

For consistency with [eigenlayer-middleware](https://github.com/Layr-Labs/eigenlayer-middleware) and [eigenlayer-contracts](https://github.com/Layr-Labs/eigenlayer-contracts) repos, we no longer use the master branch and instead use dev as the default branch, which will track as closely as possible the dev branch of eigenlayer-middleware (which in turn tracks the dev branch of eigenlayer-contracts). This convention will also be followed for other important branches. For eg, the m2-mainnet branch of this repo will track the m2-mainnet branch of eigenlayer-middleware (which tracks the unfortunately named mainnet branch of eigenlayer-contracts), and same with the testnet-holesky branch.
For consistency with [eigenlayer-middleware](https://github.com/Layr-Labs/eigenlayer-middleware) and [eigenlayer-contracts](https://github.com/Layr-Labs/eigenlayer-contracts) repos, we no longer use the `master` branch and instead use `dev` as the default branch, which will track as closely as possible the `dev` branch of eigenlayer-middleware (which in turn tracks the `dev` branch of eigenlayer-contracts). This convention will also be followed for other important branches. For eg, the m2-mainnet branch of this repo will track the m2-mainnet branch of eigenlayer-middleware (which tracks the unfortunately named mainnet branch of eigenlayer-contracts), and same with the testnet-holesky branch.

## Security Bugs
Please report security vulnerabilities to [email protected]. Do NOT report security bugs via Github Issues.
Please report security vulnerabilities to [email protected]. Do NOT report security bugs via Github Issues.

## Disclaimer
🚧 EigenSDK-go is under active development and has not been audited. EigenSDK-go is rapidly being upgraded, features may be added, removed or otherwise improved or modified and interfaces will have breaking changes. EigenSDK-go should be used only for testing purposes and not in production. EigenSDK-go is provided "as is" and Eigen Labs, Inc. does not guarantee its functionality or provide support for its use in production. 🚧
10 changes: 5 additions & 5 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
Expand All @@ -29,7 +29,7 @@ type ContractBindings struct {
Slasher *slasher.ContractISlasher
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractAVSDirectory
AvsDirectory *avsdirectory.ContractIAVSDirectory
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
}

Expand All @@ -46,7 +46,7 @@ func NewBindingsFromConfig(
contractStrategyManager *strategymanager.ContractStrategyManager
slasherAddr gethcommon.Address
strategyManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractAVSDirectory
avsDirectory *avsdirectory.ContractIAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
)

Expand Down Expand Up @@ -80,7 +80,7 @@ func NewBindingsFromConfig(
if isZeroAddress(cfg.AvsDirectoryAddress) {
logger.Debug("AVSDirectory address not provided, the calls to the contract will not work")
} else {
avsDirectory, err = avsdirectory.NewContractAVSDirectory(cfg.AvsDirectoryAddress, client)
avsDirectory, err = avsdirectory.NewContractIAVSDirectory(cfg.AvsDirectoryAddress, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func NewEigenlayerContractBindings(
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
}

avsDirectory, err := avsdirectory.NewContractAVSDirectory(avsDirectoryAddr, ethclient)
avsDirectory, err := avsdirectory.NewContractIAVSDirectory(avsDirectoryAddr, ethclient)
if err != nil {
return nil, utils.WrapError("Failed to fetch AVSDirectory contract", err)
}
Expand Down
1 change: 1 addition & 0 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func BuildClients(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.StrategyManagerAddr,
elChainReader,
client,
Expand Down
7 changes: 3 additions & 4 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher"
Expand All @@ -33,7 +33,7 @@ type ChainReader struct {
slasher slasher.ContractISlasherCalls
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractAVSDirectory
avsDirectory *avsdirectory.ContractIAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
ethClient eth.HttpBackend
}
Expand All @@ -42,7 +42,7 @@ func NewChainReader(
slasher slasher.ContractISlasherCalls,
delegationManager *delegationmanager.ContractDelegationManager,
strategyManager *strategymanager.ContractStrategyManager,
avsDirectory *avsdirectory.ContractAVSDirectory,
avsDirectory *avsdirectory.ContractIAVSDirectory,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
logger logging.Logger,
ethClient eth.HttpBackend,
Expand Down Expand Up @@ -143,7 +143,6 @@ func (r *ChainReader) GetOperatorDetails(opts *bind.CallOpts, operator types.Ope

return types.Operator{
Address: operator.Address,
EarningsReceiverAddress: operatorDetails.DeprecatedEarningsReceiver.Hex(),
StakerOptOutWindowBlocks: operatorDetails.StakerOptOutWindowBlocks,
DelegationApproverAddress: operatorDetails.DelegationApprover.Hex(),
}, nil
Expand Down
81 changes: 77 additions & 4 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"

"github.com/Layr-Labs/eigensdk-go/utils"

"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -15,6 +13,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/txmgr"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
erc20 "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IERC20"
rewardscoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IRewardsCoordinator"
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/metrics"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/Layr-Labs/eigensdk-go/utils"
)

type Reader interface {
Expand All @@ -36,6 +36,7 @@ type ChainWriter struct {
delegationManager *delegationmanager.ContractDelegationManager
strategyManager *strategymanager.ContractStrategyManager
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
avsDirectory *avsdirectory.ContractIAVSDirectory
strategyManagerAddr gethcommon.Address
elChainReader Reader
ethClient eth.HttpBackend
Expand All @@ -48,6 +49,7 @@ func NewChainWriter(
delegationManager *delegationmanager.ContractDelegationManager,
strategyManager *strategymanager.ContractStrategyManager,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
avsDirectory *avsdirectory.ContractIAVSDirectory,
strategyManagerAddr gethcommon.Address,
elChainReader Reader,
ethClient eth.HttpBackend,
Expand All @@ -63,6 +65,7 @@ func NewChainWriter(
strategyManager: strategyManager,
strategyManagerAddr: strategyManagerAddr,
rewardsCoordinator: rewardsCoordinator,
avsDirectory: avsDirectory,
elChainReader: elChainReader,
logger: logger,
ethClient: ethClient,
Expand Down Expand Up @@ -103,6 +106,7 @@ func BuildELChainWriter(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand Down Expand Up @@ -141,6 +145,7 @@ func NewWriterFromConfig(
elContractBindings.DelegationManager,
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.StrategyManagerAddr,
elChainReader,
ethClient,
Expand All @@ -157,7 +162,9 @@ func (w *ChainWriter) RegisterAsOperator(ctx context.Context, operator types.Ope

w.logger.Infof("registering operator %s to EigenLayer", operator.Address)
opDetails := delegationmanager.IDelegationManagerOperatorDetails{
DeprecatedEarningsReceiver: gethcommon.HexToAddress(operator.EarningsReceiverAddress),
// Earning receiver has been deprecated, so we just use the operator address as a dummy value
// Any reward related setup is via RewardsCoordinator contract
DeprecatedEarningsReceiver: gethcommon.HexToAddress(operator.Address),
StakerOptOutWindowBlocks: operator.StakerOptOutWindowBlocks,
DelegationApprover: gethcommon.HexToAddress(operator.DelegationApproverAddress),
}
Expand Down Expand Up @@ -189,7 +196,9 @@ func (w *ChainWriter) UpdateOperatorDetails(

w.logger.Infof("updating operator details of operator %s to EigenLayer", operator.Address)
opDetails := delegationmanager.IDelegationManagerOperatorDetails{
DeprecatedEarningsReceiver: gethcommon.HexToAddress(operator.EarningsReceiverAddress),
// Earning receiver has been deprecated, so we just use the operator address as a dummy value
// Any reward related setup is via RewardsCoordinator contract
DeprecatedEarningsReceiver: gethcommon.HexToAddress(operator.Address),
DelegationApprover: gethcommon.HexToAddress(operator.DelegationApproverAddress),
StakerOptOutWindowBlocks: operator.StakerOptOutWindowBlocks,
}
Expand Down Expand Up @@ -339,3 +348,67 @@ func (w *ChainWriter) ProcessClaim(

return receipt, nil
}

func (w *ChainWriter) ForceDeregisterFromOperatorSets(
ctx context.Context,
operator gethcommon.Address,
avs gethcommon.Address,
operatorSetIds []uint32,
operatorSignature avsdirectory.ISignatureUtilsSignatureWithSaltAndExpiry,
) (*gethtypes.Receipt, error) {
if w.avsDirectory == nil {
return nil, errors.New("AVSDirectory contract not provided")
}

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.avsDirectory.ForceDeregisterFromOperatorSets(
noSendTxOpts,
operator,
avs,
operatorSetIds,
operatorSignature,
)

if err != nil {
return nil, utils.WrapError("failed to create ForceDeregisterFromOperatorSets 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) SetOperatorCommissionBips(
ctx context.Context,
operatorSet rewardscoordinator.IAVSDirectoryOperatorSet,
rewardType uint8,
commissionBips uint16,
) (*gethtypes.Receipt, error) {
if w.rewardsCoordinator == nil {
return nil, errors.New("RewardsCoordinator contract not provided")
}

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, utils.WrapError("failed to get no send tx opts", err)
}

tx, err := w.rewardsCoordinator.SetOperatorCommissionBips(noSendTxOpts, operatorSet, rewardType, commissionBips)
if err != nil {
return nil, utils.WrapError("failed to create SetOperatorCommissionBips tx", err)
}

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

return receipt, nil
}
Loading

0 comments on commit ed0b830

Please sign in to comment.