Skip to content

Commit e957e15

Browse files
committed
more allocations
1 parent 686f136 commit e957e15

File tree

8 files changed

+183
-44
lines changed

8 files changed

+183
-44
lines changed

pkg/internal/common/eth.go

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66
"strings"
77

8+
"github.com/ethereum/go-ethereum/common"
89
"github.com/ethereum/go-ethereum/core/types"
910
)
1011

@@ -45,3 +46,12 @@ func GetTxFeeDetails(tx *types.Transaction) *TxFeeDetails {
4546
GasFeeCapGwei: gasFeeCapGwei,
4647
}
4748
}
49+
50+
func ConvertStringSliceToGethAddressSlice(addresses []string) []common.Address {
51+
gethAddresses := make([]common.Address, 0, len(addresses))
52+
for _, address := range addresses {
53+
parsed := common.HexToAddress(address)
54+
gethAddresses = append(gethAddresses, parsed)
55+
}
56+
return gethAddresses
57+
}

pkg/operator/allocations/initializedelay.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func initializeDelayAction(cCtx *cli.Context, p utils.Prompter) error {
102102
noSendTxOpts.GasLimit = 150_000
103103
}
104104

105-
unsignedTx, err := contractBindings.AvsDirectory.InitializeAllocationDelay(noSendTxOpts, config.allocationDelay)
105+
unsignedTx, err := contractBindings.DelegationManager.InitializeAllocationDelay(noSendTxOpts, config.allocationDelay)
106106
if err != nil {
107107
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
108108
}

pkg/operator/allocations/show.go

+99-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,115 @@
11
package allocations
22

33
import (
4+
"sort"
5+
6+
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
7+
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
48
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
59
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
10+
11+
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
12+
"github.com/Layr-Labs/eigensdk-go/logging"
13+
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
14+
15+
"github.com/ethereum/go-ethereum/accounts/abi/bind"
16+
gethcommon "github.com/ethereum/go-ethereum/common"
17+
"github.com/ethereum/go-ethereum/ethclient"
18+
619
"github.com/urfave/cli/v2"
720
)
821

922
func ShowCmd(p utils.Prompter) *cli.Command {
1023
showCmd := &cli.Command{
11-
Name: "show",
12-
Usage: "Show allocations",
13-
UsageText: "show",
14-
After: telemetry.AfterRunAction(),
24+
Name: "show",
25+
Usage: "Show allocations",
26+
After: telemetry.AfterRunAction(),
1527
Description: `
1628
Command to show allocations
1729
`,
30+
Flags: getShowFlags(),
31+
Action: func(cCtx *cli.Context) error {
32+
return showAction(cCtx, p)
33+
},
1834
}
1935
return showCmd
2036
}
37+
38+
func showAction(cCtx *cli.Context, p utils.Prompter) error {
39+
ctx := cCtx.Context
40+
logger := common.GetLogger(cCtx)
41+
42+
config, err := readAndValidateShowConfig(cCtx, &logger)
43+
if err != nil {
44+
return err
45+
}
46+
cCtx.App.Metadata["network"] = config.chainID.String()
47+
48+
ethClient, err := ethclient.Dial(config.rpcUrl)
49+
if err != nil {
50+
return eigenSdkUtils.WrapError("failed to create new eth client", err)
51+
}
52+
53+
avsDirectoryAddress, err := utils.GetAVSDirectoryAddress(config.chainID)
54+
if err != nil {
55+
return err
56+
}
57+
58+
// Temp to test modify allocations
59+
avsDirectoryAddress = "0x8BffE5a668DB26bc5Ce8dC9C0096fB634747b62A"
60+
61+
elReader, err := elcontracts.NewReaderFromConfig(
62+
elcontracts.Config{
63+
AvsDirectoryAddress: gethcommon.HexToAddress(avsDirectoryAddress),
64+
},
65+
ethClient,
66+
logger,
67+
)
68+
if err != nil {
69+
return eigenSdkUtils.WrapError("failed to create new reader from config", err)
70+
}
71+
72+
// for each strategy address, get the allocatable magnitude
73+
for _, strategyAddress := range config.strategyAddresses {
74+
allocatableMagnitude, err := elReader.GetAllocatableMagnitude(&bind.CallOpts{Context: ctx}, strategyAddress, config.operatorAddress)
75+
if err != nil {
76+
return eigenSdkUtils.WrapError("failed to get allocatable magnitude", err)
77+
}
78+
logger.Debug("Allocatable magnitude for strategy", strategyAddress, ":", allocatableMagnitude)
79+
}
80+
81+
82+
return nil
83+
}
84+
85+
func readAndValidateShowConfig(cCtx *cli.Context, logger *logging.Logger) (*showConfig, error) {
86+
network := cCtx.String(flags.NetworkFlag.Name)
87+
rpcUrl := cCtx.String(flags.ETHRpcUrlFlag.Name)
88+
environment := cCtx.String(flags.EnvironmentFlag.Name)
89+
operatorAddress := gethcommon.HexToAddress(cCtx.String(flags.OperatorAddressFlag.Name))
90+
avsAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.AVSAddressesFlag.Name))
91+
strategyAddresses := common.ConvertStringSliceToGethAddressSlice(cCtx.StringSlice(flags.StrategyAddressesFlag.Name))
92+
93+
return &showConfig{
94+
network: network,
95+
rpcUrl: rpcUrl,
96+
environment: environment,
97+
operatorAddress: operatorAddress,
98+
avsAddresses: avsAddresses,
99+
strategyAddresses: strategyAddresses,
100+
}, nil
101+
}
102+
103+
func getShowFlags() []cli.Flag {
104+
baseFlags := []cli.Flag{
105+
&flags.OperatorAddressFlag,
106+
&flags.AVSAddressesFlag,
107+
&flags.StrategyAddressesFlag,
108+
&flags.NetworkFlag,
109+
&flags.EnvironmentFlag,
110+
&flags.ETHRpcUrlFlag,
111+
}
112+
113+
sort.Sort(cli.FlagsByName(baseFlags))
114+
return baseFlags
115+
}

pkg/operator/allocations/types.go

+12
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ type allocationDelayConfig struct {
7373
allocationDelay uint32
7474
avsDirectoryAddress gethcommon.Address
7575
}
76+
77+
type showConfig struct {
78+
network string
79+
rpcUrl string
80+
environment string
81+
chainID *big.Int
82+
output string
83+
outputType string
84+
operatorAddress gethcommon.Address
85+
avsAddresses []gethcommon.Address
86+
strategyAddresses []gethcommon.Address
87+
}

pkg/operator/allocations/update.go

+17-30
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import (
2828
)
2929

3030
type elChainReader interface {
31-
GetLatestTotalMagnitude(
31+
GetTotalMagnitudes(
3232
opts *bind.CallOpts,
33-
operator gethcommon.Address,
34-
strategy gethcommon.Address,
35-
) (uint64, error)
33+
operatorAddress gethcommon.Address,
34+
strategyAddresses []gethcommon.Address,
35+
) ([]uint64, error)
3636
GetAllocatableMagnitude(
3737
opts *bind.CallOpts,
3838
operator gethcommon.Address,
@@ -218,10 +218,10 @@ func generateAllocationsParams(
218218

219219
var err error
220220
if len(config.csvFilePath) == 0 {
221-
magnitude, err := elReader.GetLatestTotalMagnitude(
221+
magnitude, err := elReader.GetTotalMagnitudes(
222222
&bind.CallOpts{Context: ctx},
223223
config.operatorAddress,
224-
config.strategyAddress,
224+
[]gethcommon.Address{config.strategyAddress},
225225
)
226226
if err != nil {
227227
return nil, eigenSdkUtils.WrapError("failed to get latest total magnitude", err)
@@ -237,11 +237,11 @@ func generateAllocationsParams(
237237
logger.Debugf("Total Magnitude: %d", magnitude)
238238
logger.Debugf("Allocatable Magnitude: %d", allocatableMagnitude)
239239
logger.Debugf("Bips to allocate: %d", config.bipsToAllocate)
240-
magnitudeToUpdate := calculateMagnitudeToUpdate(magnitude, config.bipsToAllocate)
240+
magnitudeToUpdate := calculateMagnitudeToUpdate(magnitude[0], config.bipsToAllocate)
241241
logger.Debugf("Magnitude to update: %d", magnitudeToUpdate)
242242
malloc := contractIAVSDirectory.IAVSDirectoryMagnitudeAllocation{
243243
Strategy: config.strategyAddress,
244-
ExpectedTotalMagnitude: magnitude,
244+
ExpectedTotalMagnitude: magnitude[0],
245245
OperatorSets: []contractIAVSDirectory.IAVSDirectoryOperatorSet{
246246
{
247247
Avs: config.avsAddress,
@@ -280,7 +280,7 @@ func computeAllocations(
280280
}
281281

282282
strategies := getUniqueStrategies(allocations)
283-
strategyTotalMagnitudes, err := parallelGetMagnitudes(strategies, operatorAddress, elReader)
283+
strategyTotalMagnitudes, err := getMagnitudes(strategies, operatorAddress, elReader)
284284
if err != nil {
285285
return nil, nil, eigenSdkUtils.WrapError("failed to get total magnitudes", err)
286286
}
@@ -346,33 +346,20 @@ func parallelGetAllocatableMagnitudes(
346346
return strategyAllocatableMagnitudes, nil
347347
}
348348

349-
func parallelGetMagnitudes(
349+
func getMagnitudes(
350350
strategies []gethcommon.Address,
351351
operatorAddress gethcommon.Address,
352352
reader elChainReader,
353353
) (map[gethcommon.Address]uint64, error) {
354354
strategyTotalMagnitudes := make(map[gethcommon.Address]uint64, len(strategies))
355-
var wg sync.WaitGroup
356-
errChan := make(chan error, len(strategies))
357-
358-
for _, s := range strategies {
359-
wg.Add(1)
360-
go func(strategy gethcommon.Address) {
361-
defer wg.Done()
362-
magnitude, err := reader.GetLatestTotalMagnitude(&bind.CallOpts{}, operatorAddress, strategy)
363-
if err != nil {
364-
errChan <- err
365-
return
366-
}
367-
strategyTotalMagnitudes[strategy] = magnitude
368-
}(s)
355+
totalMagnitudes, err := reader.GetTotalMagnitudes(&bind.CallOpts{Context: context.Background()}, operatorAddress, strategies)
356+
if err != nil {
357+
return nil, err
369358
}
370-
371-
wg.Wait()
372-
close(errChan)
373-
374-
if len(errChan) > 0 {
375-
return nil, <-errChan // Return the first error encountered
359+
i := 0
360+
for _, strategy := range strategies {
361+
strategyTotalMagnitudes[strategy] = totalMagnitudes[i]
362+
i++
376363
}
377364

378365
return strategyTotalMagnitudes, nil

pkg/operator/allocations/update_test.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package allocations
22

33
import (
44
"context"
5+
"errors"
56
"math"
67
"os"
78
"testing"
@@ -13,7 +14,7 @@ import (
1314

1415
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1516
gethcommon "github.com/ethereum/go-ethereum/common"
16-
17+
1718
"github.com/stretchr/testify/assert"
1819
)
1920

@@ -37,21 +38,26 @@ func newFakeElChainReader(
3738
}
3839
}
3940

40-
func (f *fakeElChainReader) GetLatestTotalMagnitude(
41+
func (f *fakeElChainReader) GetTotalMagnitudes(
4142
opts *bind.CallOpts,
4243
operator gethcommon.Address,
43-
strategy gethcommon.Address,
44-
) (uint64, error) {
44+
strategyAddresses []gethcommon.Address,
45+
) ([]uint64, error) {
4546
stratMap, ok := f.totalMagnitudeMap[operator]
4647
if !ok {
47-
return initialMagnitude, nil
48+
return []uint64{}, errors.New("operator not found")
4849
}
4950

50-
magnitude, ok := stratMap[strategy]
51-
if !ok {
52-
return initialMagnitude, nil
51+
// iterate over strategyAddresses and return the corresponding magnitudes
52+
magnitudes := make([]uint64, 0, len(strategyAddresses))
53+
for _, strategy := range strategyAddresses {
54+
magnitude, ok := stratMap[strategy]
55+
if !ok {
56+
magnitude = 0
57+
}
58+
magnitudes = append(magnitudes, magnitude)
5359
}
54-
return magnitude, nil
60+
return magnitudes, nil
5561
}
5662

5763
func (f *fakeElChainReader) GetAllocatableMagnitude(

pkg/operator/config/create.go

+26
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"math/big"
88
"os"
9+
"strconv"
910

1011
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
1112
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
@@ -157,6 +158,31 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
157158
}
158159
config.EthRPCUrl = rpcUrl
159160

161+
// Prompt for allocation delay
162+
allocationDelay, err := p.InputInteger("Enter your allocation delay (in seconds, default is 17.5 days):", "1512000", "",
163+
func(i int64) error {
164+
if i < 0 {
165+
return errors.New("allocation delay should be non-negative")
166+
}
167+
return nil
168+
},
169+
)
170+
if err != nil {
171+
return types.OperatorConfig{}, err
172+
}
173+
174+
// confirm again
175+
confirm, err := p.Confirm("Are you sure you want to set the allocation delay to " + strconv.FormatInt(allocationDelay, 10) + " seconds? This cannot be changed once set.")
176+
if err != nil {
177+
return types.OperatorConfig{}, err
178+
}
179+
180+
if confirm {
181+
config.AllocationDelay = uint32(allocationDelay)
182+
} else {
183+
return types.OperatorConfig{}, errors.New("operator cancelled")
184+
}
185+
160186
// Prompt for network & set chainId
161187
chainId, err := p.Select("Select your network:", []string{"mainnet", "holesky", "local"})
162188
if err != nil {

pkg/types/operator_config.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type OperatorConfig struct {
2828
EthRPCUrl string `yaml:"eth_rpc_url"`
2929
ChainId big.Int `yaml:"chain_id"`
3030
SignerConfig SignerConfig
31+
AllocationDelay uint32 `yaml:"allocation_delay"`
3132
}
3233

3334
func (o *OperatorConfig) MarshalYAML() (interface{}, error) {
@@ -64,6 +65,7 @@ func (o *OperatorConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
6465
SignerType SignerType `yaml:"signer_type"`
6566
Fireblocks FireblocksConfig `yaml:"fireblocks"`
6667
Web3 Web3SignerConfig `yaml:"web3"`
68+
AllocationDelay uint32 `yaml:"allocation_delay"`
6769
}
6870
if err := unmarshal(&aux); err != nil {
6971
return err
@@ -73,6 +75,7 @@ func (o *OperatorConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
7375
o.ELAVSDirectoryAddress = aux.ELAVSDirectoryAddress
7476
o.ELRewardsCoordinatorAddress = aux.ELRewardsCoordinatorAddress
7577
o.EthRPCUrl = aux.EthRPCUrl
78+
o.AllocationDelay = aux.AllocationDelay
7679

7780
chainId := new(big.Int)
7881
chainId.SetInt64(aux.ChainId)

0 commit comments

Comments
 (0)