UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

72 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParallelWalletGenerator = void 0; const ethers_1 = require("ethers"); const hardhatHelpers_1 = require("../utils/hardhatHelpers"); class ParallelWalletGenerator { constructor(mainSigner, minFundingAmount = '0.1', provider) { this.currentIndex = 0; this.wallets = new Map(); this.nonceTracker = new Map(); this.provider = provider || new ethers_1.ethers.providers.JsonRpcProvider(process.env.RPC_URL); this.minFundingAmount = ethers_1.ethers.utils.parseEther(minFundingAmount); this.mainSigner = mainSigner; } /** * Get the main signer used for initialization */ getMainSigner() { return this.mainSigner; } /** * Get wallet for specific module with nonce management */ async getWalletForModule(moduleName) { if (!this.wallets.has(moduleName)) { const provider = await (0, hardhatHelpers_1.getProvider)(); // Generate new wallet with unique entropy const entropy = ethers_1.ethers.utils.randomBytes(32); const wallet = ethers_1.ethers.Wallet.createRandom({ entropy }).connect(provider); // Initialize nonce for this wallet const nonce = await wallet.getTransactionCount("pending"); this.nonceTracker.set(wallet.address, nonce); this.wallets.set(moduleName, wallet); } return this.wallets.get(moduleName); } /** * Get next nonce for a wallet */ async getNextNonce(walletAddress) { const currentNonce = this.nonceTracker.get(walletAddress) || 0; const nextNonce = currentNonce + 1; this.nonceTracker.set(walletAddress, nextNonce); return currentNonce; } getWalletAddresses() { return Array.from(this.wallets.values()).map(wallet => wallet.address); } /** * Reset wallet and nonce state, including currentIndex */ reset() { this.wallets.clear(); this.nonceTracker.clear(); this.currentIndex = 0; } /** * Get next wallet for parallel deployment */ getNextWallet() { const entropy = ethers_1.ethers.utils.randomBytes(32); const wallet = ethers_1.ethers.Wallet.createRandom({ entropy }).connect(this.provider); // Track nonce for this new wallet this.nonceTracker.set(wallet.address, 0); // Store wallet with an index-based key const key = `wallet_${this.currentIndex++}`; this.wallets.set(key, wallet); return wallet; } } exports.ParallelWalletGenerator = ParallelWalletGenerator; //# sourceMappingURL=parallelWalletGenerator.js.map