diff --git a/cli/commands/completeAllWithdrawals.go b/cli/commands/completeAllWithdrawals.go index 98481ba..ef0140f 100644 --- a/cli/commands/completeAllWithdrawals.go +++ b/cli/commands/completeAllWithdrawals.go @@ -5,18 +5,19 @@ import ( "fmt" "math/big" - . "github.com/samber/lo" + lo "github.com/samber/lo" "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod" "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IDelegationManager" "github.com/Layr-Labs/eigenpod-proofs-generation/cli/core" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethclient" ) type TCompleteWithdrawalArgs struct { - EthNode string - BeaconNode string - EigenPod string + EthNode string + EigenPod string + Sender string } func DelegationManager(chainId *big.Int) common.Address { @@ -35,7 +36,13 @@ func DelegationManager(chainId *big.Int) common.Address { func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error { ctx := context.Background() - eth, _, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode, false /* isVerbose */) + + eth, err := ethclient.DialContext(ctx, args.EthNode) + core.PanicOnError("failed to reach eth node", err) + + chainId, err := eth.ChainID(nil) + core.PanicOnError("failed to load chainId", err) + curBlockNumber, err := eth.BlockNumber(nil) pod, err := EigenPod.NewEigenPod(common.HexToAddress(args.EigenPod), eth) @@ -58,7 +65,7 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error { beaconETHStrategy := common.HexToAddress("0xbeaC0eeEeeeeEEeEeEEEEeeEEeEeeeEeeEEBEaC0") - eligibleWithdrawals := Map(queuedWithdrawals.Withdrawals, func(withdrawal IDelegationManager.IDelegationManagerTypesWithdrawal, index int) *IDelegationManager.IDelegationManagerTypesWithdrawal { + eligibleWithdrawals := lo.Map(queuedWithdrawals.Withdrawals, func(withdrawal IDelegationManager.IDelegationManagerTypesWithdrawal, index int) *IDelegationManager.IDelegationManagerTypesWithdrawal { isBeaconWithdrawal := len(withdrawal.Strategies) == 1 && withdrawal.Strategies[0].Cmp(beaconETHStrategy) == 0 isExecutable := curBlockNumber <= uint64(withdrawal.StartBlock+minDelay) if isBeaconWithdrawal && isExecutable { @@ -68,7 +75,7 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error { }) var runningSum uint64 = 0 - affordedWithdrawals := Map(eligibleWithdrawals, func(withdrawal *IDelegationManager.IDelegationManagerTypesWithdrawal, index int) *IDelegationManager.IDelegationManagerTypesWithdrawal { + affordedWithdrawals := lo.Map(eligibleWithdrawals, func(withdrawal *IDelegationManager.IDelegationManagerTypesWithdrawal, index int) *IDelegationManager.IDelegationManagerTypesWithdrawal { if withdrawal == nil { return nil } @@ -81,7 +88,7 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error { }) // filter out any nils. - affordedWithdrawals = Filter(affordedWithdrawals, func(withdrawal *IDelegationManager.IDelegationManagerTypesWithdrawal, index int) bool { + affordedWithdrawals = lo.Filter(affordedWithdrawals, func(withdrawal *IDelegationManager.IDelegationManagerTypesWithdrawal, index int) bool { return withdrawal != nil }) @@ -95,15 +102,15 @@ func CompleteAllWithdrawalsCommand(args TCompleteWithdrawalArgs) error { core.PanicIfNoConsent("Would you like to continue?") - withdrawals := Map(affordedWithdrawals, func(w *IDelegationManager.IDelegationManagerTypesWithdrawal, i int) IDelegationManager.IDelegationManagerTypesWithdrawal { + withdrawals := lo.Map(affordedWithdrawals, func(w *IDelegationManager.IDelegationManagerTypesWithdrawal, i int) IDelegationManager.IDelegationManagerTypesWithdrawal { return *w }) - tokens := Map(withdrawals, func(_ IDelegationManager.IDelegationManagerTypesWithdrawal, _ int) []common.Address { + tokens := lo.Map(withdrawals, func(_ IDelegationManager.IDelegationManagerTypesWithdrawal, _ int) []common.Address { return []common.Address{common.BigToAddress(big.NewInt(0))} }) - receiveAsTokens := Map(withdrawals, func(_ IDelegationManager.IDelegationManagerTypesWithdrawal, _ int) bool { + receiveAsTokens := lo.Map(withdrawals, func(_ IDelegationManager.IDelegationManagerTypesWithdrawal, _ int) bool { return true }) diff --git a/cli/commands/queueWithdrawal.go b/cli/commands/queueWithdrawal.go index 8e365b3..04e9f19 100644 --- a/cli/commands/queueWithdrawal.go +++ b/cli/commands/queueWithdrawal.go @@ -5,21 +5,26 @@ import ( "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IDelegationManager" "github.com/Layr-Labs/eigenpod-proofs-generation/cli/core" + "github.com/ethereum/go-ethereum/ethclient" "github.com/pkg/errors" ) type TQueueWithdrawallArgs struct { - EthNode string - BeaconNode string - EigenPod string + EthNode string + EigenPod string + Sender string } func QueueWithdrawalCommand(args TQueueWithdrawallArgs) error { ctx := context.Background() - eth, _, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode, false /* isVerbose */) - core.PanicOnError("failed to dial nodes", err) - _dm, err := IDelegationManager.NewIDelegationManager(DelegationManager(chainId), eth) + eth, err := ethclient.DialContext(ctx, args.EthNode) + core.PanicOnError("failed to reach eth node", err) + + chainId, err := eth.ChainID(nil) + core.PanicOnError("failed to load chainId", err) + + _, err = IDelegationManager.NewIDelegationManager(DelegationManager(chainId), eth) core.PanicOnError("failed to reach delegation manager", err) // TODO: wait for G's conversion function from deposit[ed] shares to depositShares diff --git a/cli/commands/showWithdrawals.go b/cli/commands/showWithdrawals.go index 55dc181..b8c03d7 100644 --- a/cli/commands/showWithdrawals.go +++ b/cli/commands/showWithdrawals.go @@ -5,7 +5,7 @@ import ( "math/big" "time" - . "github.com/samber/lo" + lo "github.com/samber/lo" "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/EigenPod" "github.com/Layr-Labs/eigenlayer-contracts/pkg/bindings/IDelegationManager" @@ -58,7 +58,7 @@ func ShowWithdrawalsCommand(args TShowWithdrawalArgs) error { withdrawalInfo := []TWithdrawalInfo{} for i, shares := range allWithdrawals.Shares { - withdrawalTotalValueWei := Reduce(shares, func(accum *big.Int, item *big.Int, i int) *big.Int { + withdrawalTotalValueWei := lo.Reduce(shares, func(accum *big.Int, item *big.Int, i int) *big.Int { return new(big.Int).Add(item, accum) }, big.NewInt(0)) diff --git a/cli/main.go b/cli/main.go index 3be831b..47c9060 100644 --- a/cli/main.go +++ b/cli/main.go @@ -202,14 +202,14 @@ func main() { Usage: "Completes all withdrawals", Flags: []cli.Flag{ ExecNodeFlag, - BeaconNodeFlag, PodAddressFlag, + SenderPkFlag, }, Action: func(_ *cli.Context) error { return commands.CompleteAllWithdrawalsCommand(commands.TCompleteWithdrawalArgs{ - EthNode: node, - BeaconNode: beacon, - EigenPod: eigenpodAddress, + EthNode: node, + EigenPod: eigenpodAddress, + Sender: sender, }) }, }, @@ -219,14 +219,14 @@ func main() { Usage: "Queues a withdrawal", Flags: []cli.Flag{ ExecNodeFlag, - BeaconNodeFlag, PodAddressFlag, + SenderPkFlag, }, Action: func(_ *cli.Context) error { return commands.QueueWithdrawalCommand(commands.TQueueWithdrawallArgs{ - EthNode: node, - BeaconNode: beacon, - EigenPod: eigenpodAddress, + EthNode: node, + EigenPod: eigenpodAddress, + Sender: sender, }) }, }, @@ -236,14 +236,12 @@ func main() { Usage: "Shows all pending withdrawals", Flags: []cli.Flag{ ExecNodeFlag, - BeaconNodeFlag, PodAddressFlag, }, Action: func(_ *cli.Context) error { return commands.ShowWithdrawalsCommand(commands.TShowWithdrawalArgs{ - EthNode: node, - BeaconNode: beacon, - EigenPod: eigenpodAddress, + EthNode: node, + EigenPod: eigenpodAddress, }) }, },