diff --git a/cmd/spamooor/main.go b/cmd/spamooor/main.go index 0bb20a6..5d54d33 100644 --- a/cmd/spamooor/main.go +++ b/cmd/spamooor/main.go @@ -105,8 +105,8 @@ func main() { RpcHosts: rpcHosts, WalletPrivkey: cliArgs.privkey, WalletCount: 100, - WalletPrefund: utils.EtherToWei(uint256.NewInt(3)), - WalletMinfund: utils.EtherToWei(uint256.NewInt(3)), + WalletPrefund: utils.WeiToEther(uint256.NewInt(10000000000000000)), + WalletMinfund: utils.WeiToEther(uint256.NewInt(10000000000000000)), Scenario: scenarioName, } err := scenario.Init(testerConfig) diff --git a/scenarios/univ3swaptx/univ3swaptx.go b/scenarios/univ3swaptx/univ3swaptx.go index d91de54..600ba50 100644 --- a/scenarios/univ3swaptx/univ3swaptx.go +++ b/scenarios/univ3swaptx/univ3swaptx.go @@ -131,27 +131,12 @@ func (s *Scenario) Setup(testerCfg *tester.Tester) error { s.logger.Infof("starting scenario: univ3tx") - // now we need to mint DAI and WETH for all child wallets - s.logger.Infof("minting Erc20 and WETH for child wallets...") - errorMap, err := s.MintTokenAndWethForChildWallets() - if err != nil { - s.logger.Errorf("could not mint Erc20 and WETH for child wallets: %v", err) - return err - } - - if len(errorMap) > 0 { - // print errors - for addr, errs := range errorMap { - for _, e := range errs { - s.logger.Errorf("error for wallet: %v: %v", addr.String(), e) - } - } - } - return nil } func (s *Scenario) Run() error { + s.logger.Info("running scenario: univ3tx") + txIdxCounter := uint64(0) counterMutex := sync.Mutex{} waitGroup := sync.WaitGroup{} @@ -218,7 +203,8 @@ func (s *Scenario) Run() error { func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client, error) { client := s.tester.GetClient(tester.SelectByIndex, int(txIdx)) - wallet := s.tester.GetWallet(tester.SelectByIndex, int(txIdx)) + //wallet := s.tester.GetWallet(tester.SelectByIndex, int(txIdx)) + wallet := s.tester.GetRootWallet() var feeCap *big.Int var tipCap *big.Int @@ -385,142 +371,6 @@ func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client, return tx, client, nil } -func (s *Scenario) MintTokenAndWethForChildWallets() (map[common.Address][]error, error) { - if s.options.MaxWallets == 0 { - return nil, fmt.Errorf("max wallets not set") - } - - client := s.tester.GetClient(tester.SelectByIndex, 0) - - rootWallet := s.tester.GetRootWallet() - rootWalletTransactor, err := rootWallet.GetTransactor(true, big.NewInt(0)) - if err != nil { - s.logger.Errorf("could not get transactor for root wallet: %v", err) - return nil, err - } - - tokenMintAmount := s.tokenMintAmount.Mul(s.tokenMintAmount, big.NewInt(1000000000)) - batchSize := uint64(100) - batchIndex := uint64(0) - - errorMapLock := sync.Mutex{} - errorMap := make(map[common.Address][]error) - - wg := sync.WaitGroup{} - // batch up the mints and deposits in order to not overwhelm the rpc - for { - wg.Add(1) - go func(batchIndex uint64, batchSize uint64, errorMap *map[common.Address][]error, errorMapLock *sync.Mutex) { - defer wg.Done() - finalBatchIndex := batchIndex + batchSize - - s.logger.Infof("funding child wallets: %v/%v", batchIndex, s.tester.GetTotalChildWallets()) - - wg1 := sync.WaitGroup{} - - for { - if batchIndex > uint64(s.tester.GetTotalChildWallets()) || batchIndex > finalBatchIndex { - break - } - - childWallet := s.tester.GetWallet(tester.SelectByIndex, int(batchIndex)) - - wg1.Add(1) - go func(errorMap *map[common.Address][]error, errorMapLock *sync.Mutex) { - defer wg1.Done() - - tokenContract, err := s.GetTokenContract() - if err != nil { - s.logger.Errorf("could not create Dai contract: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - wethContract, err := s.GetWethContract() - if err != nil { - s.logger.Errorf("could not create WETH contract: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - // transfer erc20 for child wallet - transferTx, err := tokenContract.Transfer(rootWalletTransactor, childWallet.GetAddress(), tokenMintAmount) - if err != nil { - s.logger.Errorf("could not transfer token for child wallet: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - // transfer weth - wethTransferTx, err := wethContract.Transfer(rootWalletTransactor, childWallet.GetAddress(), tokenMintAmount) - if err != nil { - s.logger.Errorf("could not transfer WETH for child wallet: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - _, _, err = txbuilder.SendAndAwaitTx(txbuilder.SendTxOpts{ - Gas: 0, - Wallet: rootWallet, - Tx: transferTx, - Client: client, - BaseFee: int64(s.options.BaseFee), - TipFee: int64(s.options.TipFee), - }) - if err != nil { - s.logger.Errorf("could not mint DAI for child wallet: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - _, _, err = txbuilder.SendAndAwaitTx(txbuilder.SendTxOpts{ - Gas: 0, - Wallet: rootWallet, - Tx: wethTransferTx, - Client: client, - BaseFee: int64(s.options.BaseFee), - TipFee: int64(s.options.TipFee), - }) - if err != nil { - s.logger.Errorf("could not transfer WETH for child wallet: %v", err) - errorMapLock.Lock() - (*errorMap)[childWallet.GetAddress()] = append((*errorMap)[childWallet.GetAddress()], err) - errorMapLock.Unlock() - return - } - - }(errorMap, errorMapLock) - batchIndex += 1 - } - wg1.Wait() - - }(batchIndex, batchSize, &errorMap, &errorMapLock) - - batchIndex += batchSize - - // we are done if this is true - if batchIndex >= uint64(s.tester.GetTotalChildWallets()) { - break - } - } - - wg.Wait() - - s.logger.Infof("minted Token for child wallets") - - return errorMap, nil -} - func (s *Scenario) awaitTx(txIdx uint64, tx *types.Transaction, client *txbuilder.Client, wallet *txbuilder.Wallet) { var awaitConfirmation bool = true defer func() { diff --git a/tester/tester.go b/tester/tester.go index eb91b38..8f3abc2 100644 --- a/tester/tester.go +++ b/tester/tester.go @@ -83,11 +83,15 @@ func (tester *Tester) Start(seed string) error { } // prepare wallets with Eth - err = tester.PrepareWallets(seed) - if err != nil { - return err + if tester.config.Scenario != "univ3swaptx" { + err = tester.PrepareWallets(seed) + if err != nil { + return err + } + go tester.watchWalletBalancesLoop() + } else { + tester.logger.Infof("univ3tx scenario does not require child wallet funding") } - go tester.watchWalletBalancesLoop() } return nil