Skip to content

Commit

Permalink
rm unnecessary args
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Dec 17, 2024
1 parent e5cf07c commit 3e88a7c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
29 changes: 18 additions & 11 deletions cli/commands/completeAllWithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
})

Expand All @@ -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
})

Expand Down
17 changes: 11 additions & 6 deletions cli/commands/queueWithdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/showWithdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))

Expand Down
22 changes: 10 additions & 12 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
},
},
Expand All @@ -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,
})
},
},
Expand All @@ -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,
})
},
},
Expand Down

0 comments on commit 3e88a7c

Please sign in to comment.