Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove multicall.go in favor of jbrower95/multicall-go #155

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 18 additions & 59 deletions cli/commands/computeCheckpointableValue.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"strings"

"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/multicall"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/onchain"
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/utils"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
multicall "github.com/jbrower95/multicall-go"
)

type TComputeCheckpointableValueCommandArgs struct {
Expand Down Expand Up @@ -54,17 +54,11 @@ func queryAllEigenpodsOnNetwork(args TQueryAllEigenpodsOnNetworkArgs) ([]string,
}, map[string]int{}))

fmt.Printf("Querying %d addresses to see if they may be eigenpods\n", len(interestingWithdrawalAddresses))
podOwners, err := multicall.DoMultiCallManyReportingFailures[*common.Address](*args.Mc, utils.Map(interestingWithdrawalAddresses, func(address string, index uint64) *multicall.MultiCallMetaData[*common.Address] {
callMeta, err := multicall.MultiCall(
podOwners, err := multicall.DoManyAllowFailures(args.Mc, utils.Map(interestingWithdrawalAddresses, func(address string, index uint64) *multicall.MultiCallMetaData[common.Address] {
callMeta, err := multicall.Describe[common.Address](
common.HexToAddress(address),
args.EigenpodAbi,
func(data []byte) (*common.Address, error) {
res, err := args.EigenpodAbi.Unpack("podOwner", data)
if err != nil {
return nil, err
}
return abi.ConvertType(res[0], new(common.Address)).(*common.Address), nil
}, "podOwner",
"podOwner",
)
core.PanicOnError("failed to form mc", err)
return callMeta
Expand All @@ -89,20 +83,13 @@ func queryAllEigenpodsOnNetwork(args TQueryAllEigenpodsOnNetworkArgs) ([]string,
// array[eigenpods given the owner]
fmt.Printf("Querying %d addresses on (EigenPodManager=%s) to see if it knows about these eigenpods\n", len(addressesWithPodOwners), args.PodManagerAddress)

eigenpodForOwner, err := multicall.DoMultiCallManyReportingFailures(
*args.Mc,
utils.Map(addressesWithPodOwners, func(address string, i uint64) *multicall.MultiCallMetaData[*common.Address] {
eigenpodForOwner, err := multicall.DoManyAllowFailures(
args.Mc,
utils.Map(addressesWithPodOwners, func(address string, i uint64) *multicall.MultiCallMetaData[common.Address] {
claimedOwner := *podToPodOwner[address]
call, err := multicall.MultiCall(
call, err := multicall.Describe[common.Address](
common.HexToAddress(args.PodManagerAddress),
args.PodManagerAbi,
func(data []byte) (*common.Address, error) {
res, err := args.PodManagerAbi.Unpack("ownerToPod", data)
if err != nil {
return nil, err
}
return abi.ConvertType(res[0], new(common.Address)).(*common.Address), nil
},
"ownerToPod",
claimedOwner,
)
Expand All @@ -118,9 +105,6 @@ func queryAllEigenpodsOnNetwork(args TQueryAllEigenpodsOnNetworkArgs) ([]string,
}), nil
}

//go:embed multicallAbi.json
var multicallAbi string

func ComputeCheckpointableValueCommand(args TComputeCheckpointableValueCommandArgs) error {
ctx := context.Background()

Expand Down Expand Up @@ -186,29 +170,12 @@ func ComputeCheckpointableValueCommand(args TComputeCheckpointableValueCommandAr
// podBalanceGwei = address(pod).balanceGwei - pod.withdrawableRestakedExecutionLayerGwei
// and
// checkpoint.balanceDeltasGwei = sumBeaconBalancesGwei - sumRestakedBalancesGwei
multicallAbiRef, err := abi.JSON(strings.NewReader(multicallAbi))
core.PanicOnError("failed to load multicall abi", err)

fmt.Printf("Loading Eigenpod ETH balances....\n")
podNativeEthBalances, err := multicall.DoMultiCallMany(
*mc,
utils.Map(allEigenpods, func(eigenpod string, index uint64) *multicall.MultiCallMetaData[*big.Int] {
call, err := multicall.MultiCall(
common.HexToAddress("0xcA11bde05977b3631167028862bE2a173976CA11"),
multicallAbiRef,
func(b []byte) (*big.Int, error) {
res, err := multicallAbiRef.Unpack("getEthBalance", b)
if err != nil {
return nil, err
}
out := abi.ConvertType(res[0], new(big.Int)).(*big.Int)
return out, nil
},
"getEthBalance",
common.HexToAddress(eigenpod),
)
core.PanicOnError("failed to form multicall", err)
return call
podNativeEthBalances, err := multicall.DoMany(
mc,
utils.Map(allEigenpods, func(eigenpod string, index uint64) *multicall.MultiCallMetaData[big.Int] {
return mc.GetBalance(common.HexToAddress(eigenpod))
})...,
)
if err != nil || podNativeEthBalances == nil {
Expand All @@ -217,20 +184,12 @@ func ComputeCheckpointableValueCommand(args TComputeCheckpointableValueCommandAr
}

fmt.Printf("Loading EigenPod.withdrawableRestakedExecutionLayerGwei....\n")
withdrawableRestakedExecutionLayerGwei, err := multicall.DoMultiCallMany(
*mc,
withdrawableRestakedExecutionLayerGwei, err := multicall.DoMany(
mc,
utils.Map(allEigenpods, func(eigenpod string, index uint64) *multicall.MultiCallMetaData[uint64] {
call, err := multicall.MultiCall(
call, err := multicall.Describe[uint64](
common.HexToAddress(eigenpod),
eigenpodAbi,
func(b []byte) (uint64, error) {
res, err := eigenpodAbi.Unpack("withdrawableRestakedExecutionLayerGwei", b)
if err != nil {
return 0, err
}
out := abi.ConvertType(res[0], new(uint64)).(*uint64)
return *out, nil
},
"withdrawableRestakedExecutionLayerGwei",
)
core.PanicOnError("failed to form multicall", err)
Expand All @@ -244,7 +203,7 @@ func ComputeCheckpointableValueCommand(args TComputeCheckpointableValueCommandAr

allPendingExecutionWei := utils.Map(allEigenpods, func(eigenpod string, index uint64) *big.Int {
podCurrentNativeWei := (*podNativeEthBalances)[index]
podWithdrawableRestakedExecutionLayerWei := core.IGweiToWei(new(big.Int).SetUint64((*withdrawableRestakedExecutionLayerGwei)[index]))
podWithdrawableRestakedExecutionLayerWei := core.IGweiToWei(new(big.Int).SetUint64(*(*withdrawableRestakedExecutionLayerGwei)[index]))
return new(big.Int).Sub(podCurrentNativeWei, podWithdrawableRestakedExecutionLayerWei)
})

Expand Down Expand Up @@ -277,12 +236,12 @@ func ComputeCheckpointableValueCommand(args TComputeCheckpointableValueCommandAr
return validators
}, []ValidatorPodPair{})

allValidatorInfoRequests := utils.Map(allEigenlayerValidatorsWithPod, func(validatorPodPair ValidatorPodPair, index uint64) *multicall.MultiCallMetaData[*onchain.IEigenPodValidatorInfo] {
allValidatorInfoRequests := utils.Map(allEigenlayerValidatorsWithPod, func(validatorPodPair ValidatorPodPair, index uint64) *multicall.MultiCallMetaData[onchain.IEigenPodValidatorInfo] {
res, err := core.FetchMultipleOnchainValidatorInfoMulticalls(validatorPodPair.Pod, []*phase0.Validator{validatorPodPair.Validator.Validator})
core.PanicOnError("failed to form mc", err)
return res[0]
})
allValidatorInfo, err := multicall.DoMultiCallMany(*mc, allValidatorInfoRequests...)
allValidatorInfo, err := multicall.DoMany(mc, allValidatorInfoRequests...)
core.PanicOnError("failed to multicall validator info", err)

i := 0
Expand Down
Loading
Loading