-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
208 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
## egnaddrs | ||
This tool is used to help debug and test eigenlayer/avs deployments and contract setups. | ||
|
||
### How to install | ||
#### Install from repository | ||
```bash | ||
go install github.com/Layr-Labs/eigensdk-go/cmd/egnaddrs@latest | ||
``` | ||
|
||
#### Install from local source | ||
If you have git cloned eigensdk-go to your machine, navigate to [cmd/egnaddrs](.) directory and run | ||
```bash | ||
go install | ||
``` | ||
|
||
### Usage | ||
|
||
Currently egnaddrs only supports deriving contract addresses starting from the registry-coordinator address. It then prints the following datastructure: | ||
|
||
```bash | ||
$$$ egnaddrs --registry-coordinator 0x9E545E3C0baAB3E08CdfD552C960A1050f373042 | ||
{ | ||
"avs": { | ||
"bls-pubkey-compendium (shared)": "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44", | ||
"bls-pubkey-registry": "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9", | ||
"index-registry": "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8", | ||
"registry-coordinator": "0x9E545E3C0baAB3E08CdfD552C960A1050f373042", | ||
"service-manager": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690", | ||
"stake-registry": "0x851356ae760d987E095750cCeb3bC6014560891C" | ||
}, | ||
"eigenlayer": { | ||
"delegation-manager": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", | ||
"slasher": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", | ||
"strategy-manager": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" | ||
}, | ||
"network": { | ||
"chain-id": "31337", | ||
"rpc-url": "http://localhost:8545" | ||
} | ||
} | ||
``` |
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,167 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/urfave/cli/v2" | ||
|
||
blspubkeyreg "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSPubkeyRegistry" | ||
blsregistrycoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/BLSRegistryCoordinatorWithIndices" | ||
slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/Slasher" | ||
) | ||
|
||
var ( | ||
RegistryCoordinatorAddrFlag = &cli.StringFlag{ | ||
Name: "registry-coordinator", | ||
Usage: "BLSRegistryCoordinatorWithIndices contract address", | ||
Required: true, | ||
} | ||
RpcUrlFlag = &cli.StringFlag{ | ||
Name: "rpc-url", | ||
Usage: "rpc url", | ||
Value: "http://localhost:8545", | ||
DefaultText: "http://localhost:8545", | ||
} | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "egnaddrs" | ||
app.Usage = "Used to help debug and test deployments and contract setups." | ||
// TODO: add a much more descriptive description | ||
app.Description = "Prints all reachable Eigenlayer and AVS contract addresses starting from any one contract." | ||
app.Action = printAddrs | ||
app.Flags = []cli.Flag{ | ||
RegistryCoordinatorAddrFlag, | ||
RpcUrlFlag, | ||
} | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
fmt.Println("Error: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
} | ||
|
||
func printAddrs(c *cli.Context) error { | ||
client, err := ethclient.Dial(c.String(RpcUrlFlag.Name)) | ||
if err != nil { | ||
return err | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
chainId, err := client.ChainID(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
registryCoordinatorAddr := common.HexToAddress(c.String(RegistryCoordinatorAddrFlag.Name)) | ||
eigenlayerContractAddrs, err := getEigenlayerContractAddrs(client, registryCoordinatorAddr) | ||
if err != nil { | ||
return err | ||
} | ||
avsContractAddrs, err := getAvsContractAddrs(client, registryCoordinatorAddr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
addrsDict := map[string]any{ | ||
"network": map[string]string{ | ||
"rpc-url": c.String(RpcUrlFlag.Name), | ||
"chain-id": chainId.String(), | ||
}, | ||
"eigenlayer": eigenlayerContractAddrs, | ||
"avs": avsContractAddrs, | ||
} | ||
addrsMarshaled, err := json.MarshalIndent(addrsDict, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(addrsMarshaled)) | ||
return nil | ||
} | ||
|
||
func getAvsContractAddrs(client *ethclient.Client, registryCoordinatorAddr common.Address) (map[string]string, error) { | ||
blsRegistryCoordinatorWithIndicesC, err := blsregistrycoordinator.NewContractBLSRegistryCoordinatorWithIndices(registryCoordinatorAddr, client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_ = blsRegistryCoordinatorWithIndicesC | ||
|
||
serviceManagerAddr, err := blsRegistryCoordinatorWithIndicesC.ServiceManager(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// 3 registries | ||
blsPubkeyRegistryAddr, err := blsRegistryCoordinatorWithIndicesC.BlsPubkeyRegistry(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
indexRegistryAddr, err := blsRegistryCoordinatorWithIndicesC.IndexRegistry(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
stakeRegistryAddr, err := blsRegistryCoordinatorWithIndicesC.StakeRegistry(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// pubkey compendium (shared avs contract) | ||
contractBlsPubkeyRegistry, err := blspubkeyreg.NewContractBLSPubkeyRegistry(blsPubkeyRegistryAddr, client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
blsPubKeyCompendiumAddr, err := contractBlsPubkeyRegistry.PubkeyCompendium(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addrsDict := map[string]string{ | ||
"service-manager": serviceManagerAddr.Hex(), | ||
"registry-coordinator": registryCoordinatorAddr.Hex(), | ||
"bls-pubkey-registry": blsPubkeyRegistryAddr.Hex(), | ||
"index-registry": indexRegistryAddr.Hex(), | ||
"stake-registry": stakeRegistryAddr.Hex(), | ||
"bls-pubkey-compendium (shared)": blsPubKeyCompendiumAddr.Hex(), | ||
} | ||
return addrsDict, nil | ||
} | ||
|
||
func getEigenlayerContractAddrs(client *ethclient.Client, registryCoordinatorAddr common.Address) (map[string]string, error) { | ||
blsRegistryCoordinatorWithIndicesC, err := blsregistrycoordinator.NewContractBLSRegistryCoordinatorWithIndices(registryCoordinatorAddr, client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
slasherAddr, err := blsRegistryCoordinatorWithIndicesC.Slasher(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
slasherC, err := slasher.NewContractSlasher(slasherAddr, client) | ||
if err != nil { | ||
return nil, err | ||
} | ||
delegationManagerAddr, err := slasherC.Delegation(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
strategyManagerAddr, err := slasherC.StrategyManager(&bind.CallOpts{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
addrsDict := map[string]string{ | ||
"slasher": slasherAddr.Hex(), | ||
"delegation-manager": delegationManagerAddr.Hex(), | ||
"strategy-manager": strategyManagerAddr.Hex(), | ||
} | ||
return addrsDict, nil | ||
} |