This repository was archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdeploy.ts
More file actions
128 lines (116 loc) · 3.41 KB
/
Copy pathdeploy.ts
File metadata and controls
128 lines (116 loc) · 3.41 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { ethers } from "hardhat";
import dotenv from "dotenv";
import { EntryPoint__factory } from "../typechain-types";
import { type HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
const deployFunc = async function (): Promise<void> {
dotenv.config();
const hardhatFundedAccount = (await ethers.getSigners())[0];
const startingBalance = await ethers.provider.getBalance(
hardhatFundedAccount.address,
);
console.log(
`Deployer (${
hardhatFundedAccount.address
}) starting balance ${ethers.formatEther(startingBalance)} ETH`,
);
console.log("Starting deployment...");
const aliceAddress = process.env.VITE_ALICE_ADDRESS ?? "";
const bobAddress = process.env.VITE_BOB_ADDRESS ?? "";
const ireneAddress = process.env.VITE_IRENE_ADDRESS ?? "";
const entryPointDeployer = await ethers.getContractFactory("EntryPoint");
const entrypoint = await entryPointDeployer.deploy();
const walletDeployer = await ethers.getContractFactory("SCBridgeWallet");
console.log("EntryPoint deploying to:", await entrypoint.getAddress());
const aliceWallet = await walletDeployer.deploy(
aliceAddress,
ireneAddress,
await entrypoint.getAddress(),
);
console.log(
`Alice (${aliceAddress?.slice(
0,
12,
)}) SCBridgeWallet deploying to: ${await aliceWallet.getAddress()}`,
);
const bobWallet = await walletDeployer.deploy(
bobAddress,
ireneAddress,
await entrypoint.getAddress(),
);
console.log(
`Bob (${bobAddress?.slice(
0,
12,
)}) SCBridgeWallet deploying to: ${await bobWallet.getAddress()}`,
);
await Promise.all([
bobWallet.waitForDeployment(),
aliceWallet.waitForDeployment(),
entrypoint.waitForDeployment(),
]);
console.log("All contracts deployed");
const initialFunding = BigInt(process.env.VITE_SCW_DEPOSIT ?? "");
await fund(
[
await entrypoint.getAddress(),
await aliceWallet.getAddress(),
await bobWallet.getAddress(),
ireneAddress,
],
BigInt(initialFunding),
hardhatFundedAccount,
);
// Fund the Entrypoint to pay for gas for the SCWs
await fundEntryPoint(
[await aliceWallet.getAddress(), await bobWallet.getAddress()],
initialFunding,
await entrypoint.getAddress(),
hardhatFundedAccount,
);
console.log("Deployment complete!");
};
async function fundEntryPoint(
addresses: string[],
amount: bigint,
entryPointAddress: string,
fundedAccount: HardhatEthersSigner,
): Promise<void> {
for (const address of addresses) {
console.log(
`Funding EntryPoint for ${address} with ${ethers.formatEther(
amount,
)} ETH`,
);
await (
await EntryPoint__factory.connect(
entryPointAddress,
fundedAccount,
).depositTo(address, { value: amount })
).wait();
}
}
async function fund(
addresses: string[],
amount: bigint,
fundedAccount: HardhatEthersSigner,
): Promise<void> {
for (const address of addresses) {
const balance = await ethers.provider.getBalance(address);
if (balance >= amount) {
console.log(
`Skipping funding ${address} it already has ${ethers.formatEther(
amount,
)} ETH`,
);
continue;
}
console.log(`Funding ${address} with ${ethers.formatEther(amount)} ETH`);
await (
await fundedAccount.sendTransaction({
to: address,
value: amount,
})
).wait();
}
}
void deployFunc();