Skip to content

Commit

Permalink
fixup! fixup! Wallet and contract deploy utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrskv committed Jul 18, 2024
1 parent 13d4929 commit 2879580
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
23 changes: 9 additions & 14 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,21 @@ export async function setupWalletAndClient(
throw new Error("Accounts configuration is not an array of strings.");
}

const newWalletSalt = new Uint8Array(32);

let generatedWallet = false;
let privateKey: Hex;
if (networkConfig.accounts[0]) {
privateKey = ensure0xPrefix(networkConfig.accounts[0]);
} else {
generatedWallet = true;
privateKey = generatePrivateKey();

console.log(
`Private key not found in configuration.\nGenerated new private key: ${privateKey}`,
);
const privateKey = ensure0xPrefix(networkConfig.accounts[0]);
if (!privateKey) {
throw new Error("No private key configured for the network.");
}

const signer = new LocalECDSAKeySigner({ privateKey });
const pubKey = await signer.getPublicKey();

const newWalletSalt = new Uint8Array(32);
let generatedWallet = false;
let walletAddress = hre.config.walletAddress
? ensure0xPrefix(hre.config.walletAddress)
: undefined;
if (!walletAddress || generatedWallet) {
if (!walletAddress) {
walletAddress = uint8ArrayToHexString(
WalletV1.calculateWalletAddress({
pubKey,
Expand All @@ -81,6 +74,8 @@ export async function setupWalletAndClient(
}),
);

generatedWallet = true;

console.log(
`Wallet address not found in configuration.\nGenerated wallet address for current private key: ${walletAddress}`,
);
Expand All @@ -104,7 +99,7 @@ export async function setupWalletAndClient(
if (generatedWallet) {
wallet.salt = newWalletSalt;

await faucet.withdrawToWithRetry(walletAddress, 10_000_000n);
await faucet.withdrawToWithRetry(walletAddress, 1_000_000_000n);
await wallet.selfDeploy();

console.log("Deployed new wallet.");
Expand Down
20 changes: 0 additions & 20 deletions src/utils/deploy.ts

This file was deleted.

0 comments on commit 2879580

Please sign in to comment.