Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mock slasher #325

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 100 additions & 1 deletion core/chainio/el_reader.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,113 @@
package chainio

import (
"errors"
"fmt"

"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
"github.com/Layr-Labs/eigensdk-go/chainio/utils"
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
gethcommon "github.com/ethereum/go-ethereum/common"

avsdirectory "github.com/Layr-Labs/eigensdk-go/contracts/bindings/AVSDirectory"
delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager"
strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager"
)


func TypedErr(e interface{}) error {
switch t := e.(type) {
case error:
return t
case string:
return errors.New(t)
default:
return nil
}
}
type EigenlayerContractBindings struct {
SlasherAddr gethcommon.Address
StrategyManagerAddr gethcommon.Address
DelegationManagerAddr gethcommon.Address
AvsDirectoryAddr gethcommon.Address
Slasher *slasher.ContractISlasher
DelegationManager *delegationmanager.ContractDelegationManager
StrategyManager *strategymanager.ContractStrategyManager
AvsDirectory *avsdirectory.ContractAVSDirectory
}

func WrapError(mainErr interface{}, subErr interface{}) error {
var main, sub error
main = TypedErr(mainErr)
sub = TypedErr(subErr)
// Some times the wrap will wrap a nil error
if main == nil && sub == nil {
return nil
}

if main == nil && sub != nil {
return sub
}

if main != nil && sub == nil {
return main
}

return fmt.Errorf("%w: %w", main, sub)
}

// Since v2.0.0, the slasher is not part of the bindings which is causing an issue
// Until we update the bindings, we need to mock the slasher

func NewEigenlayerContractBindings(
delegationManagerAddr gethcommon.Address,
avsDirectoryAddr gethcommon.Address,
ethclient eth.Client,
logger logging.Logger,
) (*EigenlayerContractBindings, error) {
contractDelegationManager, err := delegationmanager.NewContractDelegationManager(delegationManagerAddr, ethclient)
if err != nil {
return nil, WrapError("Failed to create DelegationManager contract", err)
}

slasherAddr := gethcommon.Address{}
contractSlasher, err := slasher.NewContractISlasher(slasherAddr, ethclient)
if err != nil {
return nil, WrapError("Failed to fetch Slasher contract", err)
}

strategyManagerAddr, err := contractDelegationManager.StrategyManager(&bind.CallOpts{})
if err != nil {
return nil, WrapError("Failed to fetch StrategyManager address", err)
}
contractStrategyManager, err := strategymanager.NewContractStrategyManager(strategyManagerAddr, ethclient)
if err != nil {
return nil, WrapError("Failed to fetch StrategyManager contract", err)
}

avsDirectory, err := avsdirectory.NewContractAVSDirectory(avsDirectoryAddr, ethclient)
if err != nil {
return nil, WrapError("Failed to fetch AVSDirectory contract", err)
}

return &EigenlayerContractBindings{
SlasherAddr: slasherAddr,
StrategyManagerAddr: strategyManagerAddr,
DelegationManagerAddr: delegationManagerAddr,
AvsDirectoryAddr: avsDirectoryAddr,
Slasher: contractSlasher,
StrategyManager: contractStrategyManager,
DelegationManager: contractDelegationManager,
AvsDirectory: avsDirectory,
}, nil
}



func BuildElReader(
registryCoordinatorAddress common.Address,
operatorStateRetrieverAddress common.Address,
Expand All @@ -30,7 +129,7 @@ func BuildElReader(
return nil, err
}

elContractBindings, err := utils.NewEigenlayerContractBindings(
elContractBindings, err := NewEigenlayerContractBindings(
delegationManagerAddr,
avsDirectoryAddr,
ethHttpClient,
Expand Down
Loading