Skip to content

Commit

Permalink
slashing push
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Sep 18, 2024
1 parent b4118ca commit 5b87352
Show file tree
Hide file tree
Showing 16 changed files with 2,694 additions and 1,779 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lint: ## runs all linters

___BINDINGS___: ##

core_default := "DelegationManager IRewardsCoordinator ISlasher StrategyManager EigenPod EigenPodManager IStrategy IAVSDirectory"
core_default := "DelegationManager IRewardsCoordinator ISlasher StrategyManager EigenPod EigenPodManager IStrategy IAVSDirectory IAllocationManager"
core_location := "./lib/eigenlayer-middleware/lib/eigenlayer-contracts"
core_bindings_location := "../../../../bindings"

Expand Down
16 changes: 16 additions & 0 deletions chainio/clients/elcontracts/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAllocationManager"
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 @@ -26,11 +27,13 @@ type ContractBindings struct {
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
AllocationManagerAddr gethcommon.Address
Slasher *slasher.ContractISlasher
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractIAVSDirectory
RewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
AllocationManager *allocationmanager.ContractIAllocationManager
}

func NewBindingsFromConfig(
Expand All @@ -44,8 +47,10 @@ func NewBindingsFromConfig(
contractDelegationManager *delegationmanager.ContractDelegationManager
contractSlasher *slasher.ContractISlasher
contractStrategyManager *strategymanager.ContractStrategyManager
contractAllocationManager *allocationmanager.ContractIAllocationManager
slasherAddr gethcommon.Address
strategyManagerAddr gethcommon.Address
allocationManagerAddr gethcommon.Address
avsDirectory *avsdirectory.ContractIAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
)
Expand Down Expand Up @@ -75,6 +80,15 @@ func NewBindingsFromConfig(
if err != nil {
return nil, utils.WrapError("Failed to fetch StrategyManager contract", err)
}

allocationManagerAddr, err = contractDelegationManager.AllocationManager(&bind.CallOpts{})
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager address", err)
}
contractAllocationManager, err = allocationmanager.NewContractIAllocationManager(allocationManagerAddr, client)
if err != nil {
return nil, utils.WrapError("Failed to fetch AllocationManager contract", err)
}
}

if isZeroAddress(cfg.AvsDirectoryAddress) {
Expand Down Expand Up @@ -106,6 +120,8 @@ func NewBindingsFromConfig(
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
RewardsCoordinator: rewardsCoordinator,
AllocationManager: contractAllocationManager,
AllocationManagerAddr: allocationManagerAddr,
}, nil
}
func isZeroAddress(address gethcommon.Address) bool {
Expand Down
3 changes: 3 additions & 0 deletions chainio/clients/elcontracts/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func BuildReadClients(
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
client,
)
Expand Down Expand Up @@ -59,6 +60,7 @@ func BuildClients(
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
client,
)
Expand All @@ -69,6 +71,7 @@ func BuildClients(
elContractBindings.StrategyManager,
elContractBindings.RewardsCoordinator,
elContractBindings.AvsDirectory,
elContractBindings.AllocationManager,
elContractBindings.StrategyManagerAddr,
elChainReader,
client,
Expand Down
77 changes: 60 additions & 17 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethcommon "github.com/ethereum/go-ethereum/common"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAVSDirectory"
allocationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/IAllocationManager"
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,9 +23,9 @@ import (
)

type Config struct {
DelegationManagerAddress common.Address
AvsDirectoryAddress common.Address
RewardsCoordinatorAddress common.Address
DelegationManagerAddress gethcommon.Address
AvsDirectoryAddress gethcommon.Address
RewardsCoordinatorAddress gethcommon.Address
}

type ChainReader struct {
Expand All @@ -35,6 +35,7 @@ type ChainReader struct {
strategyManager *strategymanager.ContractStrategyManager
avsDirectory *avsdirectory.ContractIAVSDirectory
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator
allocationManager *allocationmanager.ContractIAllocationManager
ethClient eth.HttpBackend
}

Expand All @@ -44,6 +45,7 @@ func NewChainReader(
strategyManager *strategymanager.ContractStrategyManager,
avsDirectory *avsdirectory.ContractIAVSDirectory,
rewardsCoordinator *rewardscoordinator.ContractIRewardsCoordinator,
allocationManager *allocationmanager.ContractIAllocationManager,
logger logging.Logger,
ethClient eth.HttpBackend,
) *ChainReader {
Expand All @@ -55,6 +57,7 @@ func NewChainReader(
strategyManager: strategyManager,
avsDirectory: avsDirectory,
rewardsCoordinator: rewardsCoordinator,
allocationManager: allocationManager,
logger: logger,
ethClient: ethClient,
}
Expand Down Expand Up @@ -83,6 +86,7 @@ func BuildELChainReader(
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
ethClient,
), nil
Expand All @@ -107,6 +111,7 @@ func NewReaderFromConfig(
elContractBindings.StrategyManager,
elContractBindings.AvsDirectory,
elContractBindings.RewardsCoordinator,
elContractBindings.AllocationManager,
logger,
ethClient,
), nil
Expand Down Expand Up @@ -154,11 +159,11 @@ func (r *ChainReader) GetStrategyAndUnderlyingToken(
) (*strategy.ContractIStrategy, gethcommon.Address, error) {
contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient)
if err != nil {
return nil, common.Address{}, utils.WrapError("Failed to fetch strategy contract", err)
return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err)
}
underlyingTokenAddr, err := contractStrategy.UnderlyingToken(opts)
if err != nil {
return nil, common.Address{}, utils.WrapError("Failed to fetch token contract", err)
return nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err)
}
return contractStrategy, underlyingTokenAddr, nil
}
Expand All @@ -170,15 +175,15 @@ func (r *ChainReader) GetStrategyAndUnderlyingERC20Token(
) (*strategy.ContractIStrategy, erc20.ContractIERC20Methods, gethcommon.Address, error) {
contractStrategy, err := strategy.NewContractIStrategy(strategyAddr, r.ethClient)
if err != nil {
return nil, nil, common.Address{}, utils.WrapError("Failed to fetch strategy contract", err)
return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch strategy contract", err)
}
underlyingTokenAddr, err := contractStrategy.UnderlyingToken(opts)
if err != nil {
return nil, nil, common.Address{}, utils.WrapError("Failed to fetch token contract", err)
return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err)
}
contractUnderlyingToken, err := erc20.NewContractIERC20(underlyingTokenAddr, r.ethClient)
if err != nil {
return nil, nil, common.Address{}, utils.WrapError("Failed to fetch token contract", err)
return nil, nil, gethcommon.Address{}, utils.WrapError("Failed to fetch token contract", err)
}
return contractStrategy, contractUnderlyingToken, underlyingTokenAddr, nil
}
Expand Down Expand Up @@ -298,21 +303,59 @@ func (r *ChainReader) GetAllocatableMagnitude(
operatorAddress gethcommon.Address,
strategyAddress gethcommon.Address,
) (uint64, error) {
if r.avsDirectory == nil {
return 0, errors.New("AVSDirectory contract not provided")
if r.allocationManager == nil {
return 0, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetAllocatableMagnitude(opts, operatorAddress, strategyAddress, 0)
}

func (r *ChainReader) GetTotalMagnitudes(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
strategyAddresses []gethcommon.Address,
) ([]uint64, error) {
if r.allocationManager == nil {
return []uint64{}, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetTotalMagnitudes(opts, operatorAddress, strategyAddresses)
}

func (r *ChainReader) GetCurrentSlashableMagnitudes(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
strategyAddresses []gethcommon.Address,
) ([]allocationmanager.OperatorSet, [][]uint64, error) {
if r.allocationManager == nil {
return []allocationmanager.OperatorSet{}, [][]uint64{}, errors.New("AllocationManager contract not provided")
}

return r.avsDirectory.GetAllocatableMagnitude(opts, operatorAddress, strategyAddress)
return r.allocationManager.GetCurrentSlashableMagnitudes(opts, operatorAddress, strategyAddresses)
}

func (r *ChainReader) GetLatestTotalMagnitude(
func (r *ChainReader) GetPendingAllocations(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
strategyAddress gethcommon.Address,
) (uint64, error) {
if r.avsDirectory == nil {
return 0, errors.New("AVSDirectory contract not provided")
operatorSets []allocationmanager.OperatorSet,
) ([]uint64, []uint32, error) {
if r.allocationManager == nil {
return []uint64{}, []uint32{}, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetPendingAllocations(opts, operatorAddress, strategyAddress, operatorSets)
}

func (r *ChainReader) GetPendingDeallocations(
opts *bind.CallOpts,
operatorAddress gethcommon.Address,
strategyAddress gethcommon.Address,
operatorSets []allocationmanager.OperatorSet,
) ([]allocationmanager.IAllocationManagerPendingFreeMagnitude, error) {
if r.allocationManager == nil {
return []allocationmanager.IAllocationManagerPendingFreeMagnitude{}, errors.New("AllocationManager contract not provided")
}

return r.avsDirectory.GetLatestTotalMagnitude(opts, operatorAddress, strategyAddress)
return r.allocationManager.GetPendingDeallocations(opts, operatorAddress, strategyAddress, operatorSets)
}
Loading

0 comments on commit 5b87352

Please sign in to comment.