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

fix: bulk fund wallets with massive amount #363

Merged
merged 1 commit into from
Sep 5, 2024
Merged
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
22 changes: 10 additions & 12 deletions cmd/fund/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"github.com/rs/zerolog/log"
)

// The initial balance of Ether to send to the Funder contract.
const funderContractBalanceInEth = 1_000.0

// runFunding deploys or instantiates a `Funder` contract to bulk fund randomly generated wallets.
// Wallets' addresses and private keys are saved to a file.
func runFunding(ctx context.Context) error {
Expand Down Expand Up @@ -52,13 +49,6 @@ func runFunding(ctx context.Context) error {
return err
}

// Deploy or instantiate the Funder contract.
var contract *funder.Funder
contract, err = deployOrInstantiateFunderContract(ctx, c, tops, privateKey)
if err != nil {
return err
}

// Derive or generate a set of wallets.
var addresses []common.Address
if params.WalletAddresses != nil && *params.WalletAddresses != nil {
Expand All @@ -78,6 +68,13 @@ func runFunding(ctx context.Context) error {
return err
}

// Deploy or instantiate the Funder contract.
var contract *funder.Funder
contract, err = deployOrInstantiateFunderContract(ctx, c, tops, privateKey, len(addresses))
if err != nil {
return err
}

// Fund wallets.
if err = fundWallets(ctx, c, tops, contract, addresses); err != nil {
return err
Expand Down Expand Up @@ -124,7 +121,7 @@ func initializeParams(ctx context.Context, c *ethclient.Client) (*ecdsa.PrivateK

// deployOrInstantiateFunderContract deploys or instantiates a Funder contract.
// If the pre-deployed address is specified, the contract will not be deployed.
func deployOrInstantiateFunderContract(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, privateKey *ecdsa.PrivateKey) (*funder.Funder, error) {
func deployOrInstantiateFunderContract(ctx context.Context, c *ethclient.Client, tops *bind.TransactOpts, privateKey *ecdsa.PrivateKey, numAddresses int) (*funder.Funder, error) {
// Deploy the contract if no pre-deployed address flag is provided.
var contractAddress common.Address
var err error
Expand All @@ -140,9 +137,10 @@ func deployOrInstantiateFunderContract(ctx context.Context, c *ethclient.Client,
log.Debug().Interface("address", contractAddress).Msg("Funder contract deployed")

// Fund the Funder contract.
// Calculate the total amount needed to fund the contract based on the number of addresses.
// Note: `funderContractBalanceInWei` reprensents the initial balance of the Funder contract.
// The contract needs initial funds to be able to fund wallets.
funderContractBalanceInWei := util.EthToWei(funderContractBalanceInEth)
funderContractBalanceInWei := new(big.Int).Mul(fundingAmountInWei, big.NewInt(int64(numAddresses)))
if err = util.SendTx(ctx, c, privateKey, &contractAddress, funderContractBalanceInWei, nil, uint64(30000)); err != nil {
return nil, err
}
Expand Down