-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-accounts.ts
63 lines (56 loc) · 2.21 KB
/
deploy-accounts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import dotenv from "dotenv";
import { writeFileSync } from "fs";
import { Account } from "starknet";
import { DeployAccountParams, deployAccountWithoutGuardian } from "../lib";
dotenv.config({ override: true });
// Be careful running this script might override your existing accounts located at .env.v3Accounts.json and .env.v2Accounts.json
// Update theses
const accountClassHash = process.env.ARGENT_CLASS_HASH;
const ethFundingAmount = BigInt(1e16);
const strkFundingAmount = BigInt(1e17);
// Fixed constants
const selfDeploy = true;
const amountV3accounts = 8;
const amountV2accounts = 2;
console.log(`About to deploy ${amountV3accounts} accounts using TX_V3`);
const v3Accounts = await deployAccounts(amountV3accounts, {
useTxV3: true,
fundingAmount: strkFundingAmount,
selfDeploy,
classHash: accountClassHash,
});
writeFileSync("./.env.v3Accounts.json", JSON.stringify(v3Accounts)); // Be careful this might override your existing accounts
console.log(`About to deploy ${amountV2accounts} accounts using TX_V2`);
const v2Accounts = await deployAccounts(amountV2accounts, {
useTxV3: false,
fundingAmount: ethFundingAmount,
selfDeploy,
classHash: accountClassHash,
});
writeFileSync("./.env.v2Accounts.json", JSON.stringify(v2Accounts)); // Be careful this might override your existing accounts
// Every account is deployed one after the other (thus blocking) to avoid any issue when funding them
// Improvement possible: we could group this under a big multicall
async function deployAccounts(amountAccountToDeploy: number, params: DeployAccountParams): Promise<Account[]> {
const accounts: Account[] = [];
for (let i = 0; i < amountAccountToDeploy; i++) {
console.log(`Deploying account #${i}`);
const account = await safeDeployAccount(params);
if (account) {
accounts.push(account);
}
}
return accounts;
}
async function safeDeployAccount(params: DeployAccountParams, retry = 0): Promise<Account | undefined> {
try {
const { account } = await deployAccountWithoutGuardian(params);
return account;
} catch (e) {
console.log(`Failing to deploy, retrying... (${retry})`);
if (retry >= 3) {
console.log(e);
return;
}
return safeDeployAccount(params, retry + 1);
}
}