Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Nov 19, 2024
1 parent 40b56ca commit da65f57
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 44 deletions.
66 changes: 34 additions & 32 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ func (r *ChainReader) IsOperatorRegistered(
// GetStakerShares returns the amount of shares that a staker has in all of the strategies in which they have nonzero
// shares
func (r *ChainReader) GetStakerShares(
opts *bind.CallOpts,
ctx context.Context,
stakerAddress gethcommon.Address,
blockNumber *big.Int,
) ([]gethcommon.Address, []*big.Int, error) {
return r.delegationManager.GetDepositedShares(opts, stakerAddress)
return r.delegationManager.GetDepositedShares(&bind.CallOpts{Context: ctx}, stakerAddress)
}

// GetDelegatedOperator returns the operator that a staker has delegated to
func (r *ChainReader) GetDelegatedOperator(
opts *bind.CallOpts,
ctx context.Context,
stakerAddress gethcommon.Address,
blockNumber *big.Int,
) (gethcommon.Address, error) {
return r.delegationManager.DelegatedTo(opts, stakerAddress)
return r.delegationManager.DelegatedTo(&bind.CallOpts{Context: ctx}, stakerAddress)
}

func (r *ChainReader) GetOperatorDetails(
Expand Down Expand Up @@ -350,15 +350,15 @@ func (r *ChainReader) CheckClaim(
}

func (r *ChainReader) GetAllocatableMagnitude(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress gethcommon.Address,
strategyAddress gethcommon.Address,
) (uint64, error) {
if r.allocationManager == nil {
return 0, errors.New("AllocationManager contract not provided")
}

return r.allocationManager.GetAllocatableMagnitude(opts, operatorAddress, strategyAddress)
return r.allocationManager.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddress)
}

func (r *ChainReader) GetMaxMagnitudes(
Expand Down Expand Up @@ -402,36 +402,38 @@ func (r *ChainReader) GetAllocationInfo(
}

func (r *ChainReader) GetOperatorShares(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress gethcommon.Address,
strategyAddresses []gethcommon.Address,
) ([]*big.Int, error) {
if r.delegationManager == nil {
return nil, errors.New("DelegationManager contract not provided")
}

return r.delegationManager.GetOperatorShares(opts, operatorAddress, strategyAddresses)
return r.delegationManager.GetOperatorShares(&bind.CallOpts{
Context: ctx,
}, operatorAddress, strategyAddresses)
}

func (r *ChainReader) GetOperatorsShares(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress []gethcommon.Address,
strategyAddresses []gethcommon.Address,
) ([][]*big.Int, error) {
if r.delegationManager == nil {
return nil, errors.New("DelegationManager contract not provided")
}

return r.delegationManager.GetOperatorsShares(opts, operatorAddress, strategyAddresses)
return r.delegationManager.GetOperatorsShares(&bind.CallOpts{Context: ctx}, operatorAddress, strategyAddresses)
}

// GetNumOperatorSetsForOperator returns the number of operator sets that an operator is part of
// Doesn't include M2 AVSs
func (r *ChainReader) GetNumOperatorSetsForOperator(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress gethcommon.Address,
) (*big.Int, error) {
opSets, err := r.allocationManager.GetAllocatedSets(opts, operatorAddress)
opSets, err := r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress)
if err != nil {
return nil, err
}
Expand All @@ -441,30 +443,30 @@ func (r *ChainReader) GetNumOperatorSetsForOperator(
// GetOperatorSetsForOperator returns the list of operator sets that an operator is part of
// Doesn't include M2 AVSs
func (r *ChainReader) GetOperatorSetsForOperator(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress gethcommon.Address,
) ([]allocationmanager.OperatorSet, error) {
// TODO: we're fetching max int64 operatorSets here. What's the practical limit for timeout by RPC? do we need to
// paginate?
return r.allocationManager.GetAllocatedSets(opts, operatorAddress)
return r.allocationManager.GetAllocatedSets(&bind.CallOpts{Context: ctx}, operatorAddress)
}

// IsOperatorRegisteredWithOperatorSet returns if an operator is registered with a specific operator set
func (r *ChainReader) IsOperatorRegisteredWithOperatorSet(
opts *bind.CallOpts,
ctx context.Context,
operatorAddress gethcommon.Address,
operatorSet allocationmanager.OperatorSet,
) (bool, error) {
if operatorSet.Id == 0 {
// this is an M2 AVS
status, err := r.avsDirectory.AvsOperatorStatus(opts, operatorSet.Avs, operatorAddress)
status, err := r.avsDirectory.AvsOperatorStatus(&bind.CallOpts{Context: ctx}, operatorSet.Avs, operatorAddress)
if err != nil {
return false, err
}

return status == 1, nil
} else {
registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(opts, operatorAddress)
registeredOperatorSets, err := r.allocationManager.GetRegisteredSets(&bind.CallOpts{Context: ctx}, operatorAddress)
if err != nil {
return false, err
}
Expand All @@ -481,66 +483,66 @@ func (r *ChainReader) IsOperatorRegisteredWithOperatorSet(
// GetOperatorsForOperatorSet returns the list of operators in a specific operator set
// Not supported for M2 AVSs
func (r *ChainReader) GetOperatorsForOperatorSet(
opts *bind.CallOpts,
ctx context.Context,
operatorSet allocationmanager.OperatorSet,
) ([]gethcommon.Address, error) {
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
return r.allocationManager.GetMembers(opts, operatorSet)
return r.allocationManager.GetMembers(&bind.CallOpts{Context: ctx}, operatorSet)
}
}

// GetNumOperatorsForOperatorSet returns the number of operators in a specific operator set
func (r *ChainReader) GetNumOperatorsForOperatorSet(
opts *bind.CallOpts,
ctx context.Context,
operatorSet allocationmanager.OperatorSet,
) (*big.Int, error) {
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
return r.allocationManager.GetMemberCount(opts, operatorSet)
return r.allocationManager.GetMemberCount(&bind.CallOpts{Context: ctx}, operatorSet)
}
}

// GetStrategiesForOperatorSet returns the list of strategies that an operator set takes into account
// Not supported for M2 AVSs
func (r *ChainReader) GetStrategiesForOperatorSet(
opts *bind.CallOpts,
ctx context.Context,
operatorSet allocationmanager.OperatorSet,
) ([]gethcommon.Address, error) {
if operatorSet.Id == 0 {
return nil, errLegacyAVSsNotSupported
} else {
return r.allocationManager.GetStrategiesInOperatorSet(opts, operatorSet)
return r.allocationManager.GetStrategiesInOperatorSet(&bind.CallOpts{Context: ctx}, operatorSet)
}
}

// GetSlashableSharesForOperatorSets returns the strategies the operatorSets take into account, their
// operators, and the minimum amount of shares that are slashable by the operatorSets.
// Not supported for M2 AVSs
func (r *ChainReader) GetSlashableSharesForOperatorSets(
opts *bind.CallOpts,
ctx context.Context,
operatorSets []allocationmanager.OperatorSet,
) ([]OperatorSetStakes, error) {
operatorSetStakes := make([]OperatorSetStakes, len(operatorSets))
currentBlock, err := r.ethClient.BlockNumber(opts.Context)
currentBlock, err := r.ethClient.BlockNumber(ctx)
if err != nil {
return nil, err
}
for i, operatorSet := range operatorSets {
operators, err := r.GetOperatorsForOperatorSet(opts, operatorSet)
operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet)
if err != nil {
return nil, err
}

strategies, err := r.GetStrategiesForOperatorSet(opts, operatorSet)
strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet)
if err != nil {
return nil, err
}

slashableShares, err := r.allocationManager.GetMinimumSlashableStake(
opts,
&bind.CallOpts{Context: ctx},
allocationmanager.OperatorSet{
Id: operatorSet.Id,
Avs: operatorSet.Avs,
Expand Down Expand Up @@ -570,24 +572,24 @@ func (r *ChainReader) GetSlashableSharesForOperatorSets(
// Timestamp must be in the future. Used to underestimate future slashable stake.
// Not supported for M2 AVSs
func (r *ChainReader) GetDelegatedAndSlashableSharesForOperatorSetsBefore(
opts *bind.CallOpts,
ctx context.Context,
operatorSets []allocationmanager.OperatorSet,
futureBlock uint32,
) ([]OperatorSetStakes, error) {
operatorSetStakes := make([]OperatorSetStakes, len(operatorSets))
for i, operatorSet := range operatorSets {
operators, err := r.GetOperatorsForOperatorSet(opts, operatorSet)
operators, err := r.GetOperatorsForOperatorSet(ctx, operatorSet)
if err != nil {
return nil, err
}

strategies, err := r.GetStrategiesForOperatorSet(opts, operatorSet)
strategies, err := r.GetStrategiesForOperatorSet(ctx, operatorSet)
if err != nil {
return nil, err
}

slashableShares, err := r.allocationManager.GetMinimumSlashableStake(
opts,
&bind.CallOpts{Context: ctx},
allocationmanager.OperatorSet{
Id: operatorSet.Id,
Avs: operatorSet.Avs,
Expand Down
14 changes: 7 additions & 7 deletions chainio/clients/elcontracts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
"github.com/ethereum/go-ethereum/common"
)

type OperatorSetStakes struct {
OperatorSet allocationmanager.OperatorSet
Strategies []common.Address
Operators []common.Address
SlashableStakes [][]*big.Int
}

type PendingDeallocation struct {
MagnitudeDiff uint64
CompletableTimestamp uint32
Expand All @@ -19,10 +26,3 @@ type AllocationInfo struct {
OperatorSetId uint32
AvsAddress common.Address
}

type OperatorSetStakes struct {
OperatorSet allocationmanager.OperatorSet
Strategies []common.Address
Operators []common.Address
SlashableStakes [][]*big.Int
}
5 changes: 0 additions & 5 deletions metrics/collectors/economic/economic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package economic

import (
"context"
"errors"
"strconv"

Expand All @@ -15,10 +14,6 @@ import (
)

type eLReader interface {
<<<<<<< HEAD
OperatorIsFrozen(ctx context.Context, operatorAddr common.Address) (bool, error)
=======
>>>>>>> 158f064 (feat: modularize bindings generation)
}

type avsRegistryReader interface {
Expand Down

0 comments on commit da65f57

Please sign in to comment.