-
Notifications
You must be signed in to change notification settings - Fork 106
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
1 parent
42ce84f
commit f8cd8dc
Showing
8 changed files
with
183 additions
and
44 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
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
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 |
---|---|---|
@@ -1,20 +1,115 @@ | ||
package allocations | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common" | ||
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags" | ||
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry" | ||
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils" | ||
|
||
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts" | ||
"github.com/Layr-Labs/eigensdk-go/logging" | ||
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
gethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func ShowCmd(p utils.Prompter) *cli.Command { | ||
showCmd := &cli.Command{ | ||
Name: "show", | ||
Usage: "Show allocations", | ||
UsageText: "show", | ||
After: telemetry.AfterRunAction(), | ||
Name: "show", | ||
Usage: "Show allocations", | ||
After: telemetry.AfterRunAction(), | ||
Description: ` | ||
Command to show allocations | ||
`, | ||
Flags: getShowFlags(), | ||
Action: func(cCtx *cli.Context) error { | ||
return showAction(cCtx, p) | ||
}, | ||
} | ||
return showCmd | ||
} | ||
|
||
func showAction(cCtx *cli.Context, p utils.Prompter) error { | ||
ctx := cCtx.Context | ||
logger := common.GetLogger(cCtx) | ||
|
||
config, err := readAndValidateShowConfig(cCtx, &logger) | ||
if err != nil { | ||
return err | ||
} | ||
cCtx.App.Metadata["network"] = config.chainID.String() | ||
|
||
ethClient, err := ethclient.Dial(config.rpcUrl) | ||
if err != nil { | ||
return eigenSdkUtils.WrapError("failed to create new eth client", err) | ||
} | ||
|
||
avsDirectoryAddress, err := utils.GetAVSDirectoryAddress(config.chainID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Temp to test modify allocations | ||
avsDirectoryAddress = "0x8BffE5a668DB26bc5Ce8dC9C0096fB634747b62A" | ||
|
||
elReader, err := elcontracts.NewReaderFromConfig( | ||
elcontracts.Config{ | ||
AvsDirectoryAddress: gethcommon.HexToAddress(avsDirectoryAddress), | ||
}, | ||
ethClient, | ||
logger, | ||
) | ||
if err != nil { | ||
return eigenSdkUtils.WrapError("failed to create new reader from config", err) | ||
} | ||
|
||
// for each strategy address, get the allocatable magnitude | ||
for _, strategyAddress := range config.strategyAddresses { | ||
allocatableMagnitude, err := elReader.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, strategyAddress, config.operatorAddress) | ||
if err != nil { | ||
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err) | ||
} | ||
logger.Debug("Allocatable magnitude for strategy", strategyAddress, ":", allocatableMagnitude) | ||
} | ||
|
||
|
||
return nil | ||
} | ||
|
||
func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*showConfig, error) { | ||
network := cCtx.String(flags.NetworkFlag.Name) | ||
rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name) | ||
environment := cCtx.String(flags.EnvironmentFlag.Name) | ||
operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name)) | ||
avsAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.AVSAddressesFlag.Name)) | ||
strategyAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.StrategyAddressesFlag.Name)) | ||
|
||
return &showConfig{ | ||
network: network, | ||
rpcUrl: rpcUrl, | ||
environment: environment, | ||
operatorAddress: operatorAddress, | ||
avsAddresses: avsAddresses, | ||
strategyAddresses: strategyAddresses, | ||
}, nil | ||
} | ||
|
||
func getShowFlags() []cli.Flag { | ||
baseFlags := []cli.Flag{ | ||
&flags.OperatorAddressFlag, | ||
&flags.AVSAddressesFlag, | ||
&flags.StrategyAddressesFlag, | ||
&flags.NetworkFlag, | ||
&flags.EnvironmentFlag, | ||
&flags.ETHRpcUrlFlag, | ||
} | ||
|
||
sort.Sort(cli.FlagsByName(baseFlags)) | ||
return baseFlags | ||
} |
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
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
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
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
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