From fb9ed184052dfc686311d2df9518a3028b4c7059 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 16 Dec 2024 17:06:28 -0800 Subject: [PATCH 1/2] feat: add caller address for unsigned tx --- pkg/internal/common/flags/general.go | 7 +++++++ .../allocations/set_allocation_delay.go | 13 ++++++++++--- pkg/operator/allocations/show.go | 3 ++- pkg/operator/allocations/types.go | 2 ++ pkg/operator/allocations/update.go | 19 +++++++++++++------ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pkg/internal/common/flags/general.go b/pkg/internal/common/flags/general.go index 517bffc8..c24f55fd 100644 --- a/pkg/internal/common/flags/general.go +++ b/pkg/internal/common/flags/general.go @@ -125,4 +125,11 @@ var ( Usage: "Optional delegation manager address. This can be used if you are testing against your own deployment of eigenlayer contracts", EnvVars: []string{"DELEGATION_MANAGER_ADDRESS"}, } + + CallerAddressFlag = cli.StringFlag{ + Name: "caller-address", + Aliases: []string{"ca"}, + Usage: "This is the address of the caller who is calling the contract function. If it is not provided, the operator address will be used as the caller address", + EnvVars: []string{"CALLER_ADDRESS"}, + } ) diff --git a/pkg/operator/allocations/set_allocation_delay.go b/pkg/operator/allocations/set_allocation_delay.go index 87b64d8e..dd68f5ef 100644 --- a/pkg/operator/allocations/set_allocation_delay.go +++ b/pkg/operator/allocations/set_allocation_delay.go @@ -62,7 +62,7 @@ func setDelayAction(cCtx *cli.Context, p utils.Prompter) error { return nil } eLWriter, err := common.GetELWriter( - config.operatorAddress, + config.callerAddress, config.signerConfig, ethClient, elcontracts.Config{ @@ -83,7 +83,7 @@ func setDelayAction(cCtx *cli.Context, p utils.Prompter) error { } common.PrintTransactionInfo(receipt.TxHash.String(), config.chainID) } else { - noSendTxOpts := common.GetNoSendTxOpts(config.operatorAddress) + noSendTxOpts := common.GetNoSendTxOpts(config.callerAddress) _, _, contractBindings, err := elcontracts.BuildClients(elcontracts.Config{ DelegationManagerAddress: config.delegationManagerAddress, }, ethClient, nil, logger, nil) @@ -94,7 +94,7 @@ func setDelayAction(cCtx *cli.Context, p utils.Prompter) error { // since balance of contract can be 0, as it can be called by an EOA // to claim. So we hardcode the gas limit to 150_000 so that we can // create unsigned tx without gas limit estimation from contract bindings - if common.IsSmartContractAddress(config.operatorAddress, ethClient) { + if common.IsSmartContractAddress(config.callerAddress, ethClient) { // address is a smart contract noSendTxOpts.GasLimit = 150_000 } @@ -142,6 +142,7 @@ func getSetAllocationDelayFlags() []cli.Flag { &flags.VerboseFlag, &flags.OperatorAddressFlag, &flags.DelegationManagerAddressFlag, + &flags.CallerAddressFlag, } allFlags := append(baseFlags, flags.GetSignerFlags()...) sort.Sort(cli.FlagsByName(allFlags)) @@ -168,6 +169,11 @@ func readAndValidateAllocationDelayConfig(c *cli.Context, logger logging.Logger) broadcast := c.Bool(flags.BroadcastFlag.Name) operatorAddress := c.String(flags.OperatorAddressFlag.Name) + callerAddress := c.String(flags.CallerAddressFlag.Name) + if common.IsEmptyString(callerAddress) { + callerAddress = operatorAddress + } + chainID := utils.NetworkNameToChainId(network) logger.Debugf("Using chain ID: %s", chainID.String()) @@ -204,5 +210,6 @@ func readAndValidateAllocationDelayConfig(c *cli.Context, logger logging.Logger) signerConfig: signerConfig, delegationManagerAddress: gethcommon.HexToAddress(delegationManagerAddress), allocationDelay: uint32(allocationDelayUint), + callerAddress: gethcommon.HexToAddress(callerAddress), }, nil } diff --git a/pkg/operator/allocations/show.go b/pkg/operator/allocations/show.go index 27208dbc..876398ba 100644 --- a/pkg/operator/allocations/show.go +++ b/pkg/operator/allocations/show.go @@ -150,6 +150,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error { slashableMagnitudeHolders := make(SlashableMagnitudeHolders, 0) dergisteredOpsets := make(DeregsiteredOperatorSets, 0) for strategy, allocations := range allAllocations { + logger.Debugf("Strategy: %s, Allocations: %v", strategy, allocations) strategyShares := operatorDelegatedSharesMap[strategy] for _, alloc := range allocations { currentShares, currentSharesPercentage := getSharesFromMagnitude( @@ -193,7 +194,7 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error { } for key, val := range operatorDelegatedSharesMap { - fmt.Printf("Strategy Address: %s, Shares %s\n", key, val.String()) + fmt.Printf("Strategy Address: %s, Shares %s\n", key, common.FormatNumberWithUnderscores(val.String())) } currBlockNumber, err := ethClient.BlockNumber(ctx) diff --git a/pkg/operator/allocations/types.go b/pkg/operator/allocations/types.go index 2ceb1ac0..e6bbd1fb 100644 --- a/pkg/operator/allocations/types.go +++ b/pkg/operator/allocations/types.go @@ -93,6 +93,7 @@ type updateConfig struct { avsAddress gethcommon.Address strategyAddress gethcommon.Address delegationManagerAddress gethcommon.Address + callerAddress gethcommon.Address operatorSetId uint32 bipsToAllocate uint64 signerConfig *types.SignerConfig @@ -119,6 +120,7 @@ type allocationDelayConfig struct { signerConfig *types.SignerConfig allocationDelay uint32 delegationManagerAddress gethcommon.Address + callerAddress gethcommon.Address } type showConfig struct { diff --git a/pkg/operator/allocations/update.go b/pkg/operator/allocations/update.go index 2f196c24..6cf4469b 100644 --- a/pkg/operator/allocations/update.go +++ b/pkg/operator/allocations/update.go @@ -94,7 +94,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error { } logger.Info("Broadcasting magnitude allocation update...") eLWriter, err := common.GetELWriter( - config.operatorAddress, + config.callerAddress, config.signerConfig, ethClient, elcontracts.Config{ @@ -119,7 +119,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error { } common.PrintTransactionInfo(receipt.TxHash.String(), config.chainID) } else { - noSendTxOpts := common.GetNoSendTxOpts(config.operatorAddress) + noSendTxOpts := common.GetNoSendTxOpts(config.callerAddress) _, _, contractBindings, err := elcontracts.BuildClients(elcontracts.Config{ DelegationManagerAddress: config.delegationManagerAddress, }, ethClient, nil, logger, nil) @@ -130,7 +130,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error { // since balance of contract can be 0, as it can be called by an EOA // to claim. So we hardcode the gas limit to 150_000 so that we can // create unsigned tx without gas limit estimation from contract bindings - if common.IsSmartContractAddress(config.operatorAddress, ethClient) { + if common.IsSmartContractAddress(config.callerAddress, ethClient) { // address is a smart contract noSendTxOpts.GasLimit = 150_000 } @@ -189,6 +189,7 @@ func getUpdateFlags() []cli.Flag { &flags.CSVFileFlag, &flags.DelegationManagerAddressFlag, &flags.SilentFlag, + &flags.CallerAddressFlag, &BipsToAllocateFlag, } allFlags := append(baseFlags, flags.GetSignerFlags()...) @@ -439,14 +440,19 @@ func readAndValidateUpdateFlags(cCtx *cli.Context, logger logging.Logger) (*upda broadcast := cCtx.Bool(flags.BroadcastFlag.Name) isSilent := cCtx.Bool(flags.SilentFlag.Name) - operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name)) + operatorAddress := cCtx.String(flags.OperatorAddressFlag.Name) + callerAddress := cCtx.String(flags.CallerAddressFlag.Name) + if common.IsEmptyString(callerAddress) { + callerAddress = operatorAddress + } + avsAddress := gethcommon.HexToAddress(cCtx.String(flags.AVSAddressFlag.Name)) strategyAddress := gethcommon.HexToAddress(cCtx.String(flags.StrategyAddressFlag.Name)) operatorSetId := uint32(cCtx.Uint64(flags.OperatorSetIdFlag.Name)) bipsToAllocate := cCtx.Uint64(BipsToAllocateFlag.Name) logger.Debugf( "Operator address: %s, AVS address: %s, Strategy address: %s, Bips to allocate: %d", - operatorAddress.Hex(), + operatorAddress, avsAddress.Hex(), strategyAddress.Hex(), bipsToAllocate, @@ -478,7 +484,8 @@ func readAndValidateUpdateFlags(cCtx *cli.Context, logger logging.Logger) (*upda output: output, outputType: outputType, broadcast: broadcast, - operatorAddress: operatorAddress, + operatorAddress: gethcommon.HexToAddress(operatorAddress), + callerAddress: gethcommon.HexToAddress(callerAddress), avsAddress: avsAddress, strategyAddress: strategyAddress, bipsToAllocate: bipsToAllocate, From f1099946fd8c9e5e519b2cd1d508a423cd5e6fa5 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 16 Dec 2024 19:46:59 -0800 Subject: [PATCH 2/2] add log message --- pkg/operator/allocations/set_allocation_delay.go | 1 + pkg/operator/allocations/update.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/operator/allocations/set_allocation_delay.go b/pkg/operator/allocations/set_allocation_delay.go index dd68f5ef..fedfc127 100644 --- a/pkg/operator/allocations/set_allocation_delay.go +++ b/pkg/operator/allocations/set_allocation_delay.go @@ -171,6 +171,7 @@ func readAndValidateAllocationDelayConfig(c *cli.Context, logger logging.Logger) callerAddress := c.String(flags.CallerAddressFlag.Name) if common.IsEmptyString(callerAddress) { + logger.Infof("Caller address not provided. Using operator address (%s) as caller address", operatorAddress) callerAddress = operatorAddress } diff --git a/pkg/operator/allocations/update.go b/pkg/operator/allocations/update.go index 6cf4469b..5585a1c9 100644 --- a/pkg/operator/allocations/update.go +++ b/pkg/operator/allocations/update.go @@ -443,6 +443,7 @@ func readAndValidateUpdateFlags(cCtx *cli.Context, logger logging.Logger) (*upda operatorAddress := cCtx.String(flags.OperatorAddressFlag.Name) callerAddress := cCtx.String(flags.CallerAddressFlag.Name) if common.IsEmptyString(callerAddress) { + logger.Infof("Caller address not provided. Using operator address (%s) as caller address", operatorAddress) callerAddress = operatorAddress }