Skip to content

Commit 36fc192

Browse files
feat(deploy): v1 factory contracts on holesky
Ticket: COIN-795
1 parent 953f3d2 commit 36fc192

File tree

2 files changed

+186
-1
lines changed

2 files changed

+186
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"scripts": {
1212
"deploy-prod": "hardhat run scripts/deploy.ts --network",
13-
"deploy-test": "hardhat run scripts/deploy.ts --network",
13+
"deploy-test": "hardhat run scripts/deployV1FactoryContracts.ts --network",
1414
"test": "hardhat test",
1515
"coverage": "hardhat coverage",
1616
"solhint": "./node_modules/.bin/solhint --fix 'contracts/**/*.sol'",
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import { ethers } from 'hardhat';
2+
const hre = require('hardhat');
3+
const fs = require('fs');
4+
5+
async function main() {
6+
const output = {
7+
walletImplementation: '',
8+
walletFactory: '',
9+
forwarderImplementation: '',
10+
forwarderFactory: ''
11+
};
12+
13+
const feeData = await ethers.provider.getFeeData();
14+
15+
const [walletDeployer, forwarderDeployer] = await ethers.getSigners();
16+
17+
const gasParams = {
18+
gasPrice: feeData.gasPrice!.mul('2')
19+
};
20+
const walletTxCount = await walletDeployer.getTransactionCount();
21+
22+
console.log('Deploying wallet contracts....');
23+
console.log('Wallet Tx Count: ', walletTxCount);
24+
const walletSelfTransactions = 2 - walletTxCount;
25+
for (let i = 0; i < walletSelfTransactions; i++) {
26+
const tx = await walletDeployer.sendTransaction({
27+
to: walletDeployer.address,
28+
value: ethers.utils.parseEther('0'),
29+
gasPrice: gasParams.gasPrice
30+
});
31+
await tx.wait();
32+
console.log(`Self transaction with nonce: ${i} complete`);
33+
}
34+
35+
const walletImplementationContractName = 'WalletSimple';
36+
const walletFactoryContractName = 'WalletFactory';
37+
38+
const WalletImplementation = await ethers.getContractFactory(
39+
walletImplementationContractName,
40+
walletDeployer
41+
);
42+
const walletImplementation = await WalletImplementation.deploy(gasParams);
43+
await walletImplementation.deployed();
44+
output.walletImplementation = walletImplementation.address;
45+
console.log(
46+
`${walletImplementationContractName} deployed at ` +
47+
walletImplementation.address
48+
);
49+
50+
const WalletFactory = await ethers.getContractFactory(
51+
walletFactoryContractName,
52+
walletDeployer
53+
);
54+
const walletFactory = await WalletFactory.deploy(
55+
walletImplementation.address,
56+
gasParams
57+
);
58+
await walletFactory.deployed();
59+
output.walletFactory = walletFactory.address;
60+
console.log(
61+
`${walletFactoryContractName} deployed at ` + walletFactory.address
62+
);
63+
64+
const forwarderTxCount = await forwarderDeployer.getTransactionCount();
65+
66+
console.log('Deploying forwarder contracts....');
67+
console.log('Forwarder Tx Count: ', forwarderTxCount);
68+
const forwarderSelfTransactions = 234 - forwarderTxCount;
69+
70+
for (let i = 0; i < forwarderSelfTransactions; i++) {
71+
const tx = await forwarderDeployer.sendTransaction({
72+
to: forwarderDeployer.address,
73+
value: ethers.utils.parseEther('0'),
74+
gasPrice: gasParams.gasPrice
75+
});
76+
await tx.wait();
77+
console.log(`Self transaction with nonce: ${i} complete`);
78+
}
79+
80+
const forwarderImplementationContractName = 'Forwarder';
81+
const forwarderFactoryContractName = 'ForwarderFactory';
82+
83+
const ForwarderImplementation = await ethers.getContractFactory(
84+
forwarderImplementationContractName,
85+
forwarderDeployer
86+
);
87+
88+
const forwarderImplementation = await ForwarderImplementation.deploy(
89+
gasParams
90+
);
91+
await forwarderImplementation.deployed();
92+
output.forwarderImplementation = forwarderImplementation.address;
93+
94+
console.log(
95+
`${forwarderImplementationContractName} deployed at ` +
96+
forwarderImplementation.address
97+
);
98+
99+
const ForwarderFactory = await ethers.getContractFactory(
100+
forwarderFactoryContractName,
101+
forwarderDeployer
102+
);
103+
104+
const forwarderFactory = await ForwarderFactory.deploy(
105+
forwarderImplementation.address,
106+
gasParams
107+
);
108+
109+
await forwarderFactory.deployed();
110+
output.forwarderFactory = forwarderFactory.address;
111+
console.log(
112+
`${forwarderFactoryContractName} deployed at ` + forwarderFactory.address
113+
);
114+
115+
fs.writeFileSync('output.json', JSON.stringify(output));
116+
117+
// Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract.
118+
console.log('Waiting for 5 minutes before verifying....');
119+
await new Promise((r) => setTimeout(r, 1000 * 300));
120+
121+
// We have to wait for a minimum of 10 block confirmations before we can call the etherscan api to verify
122+
123+
await walletImplementation.deployTransaction.wait(10);
124+
await walletFactory.deployTransaction.wait(10);
125+
await forwarderImplementation.deployTransaction.wait(10);
126+
await forwarderFactory.deployTransaction.wait(10);
127+
128+
console.log('Done waiting, verifying');
129+
await verifyContract(
130+
walletImplementationContractName,
131+
walletImplementation.address,
132+
[]
133+
);
134+
await verifyContract('WalletFactory', walletFactory.address, [
135+
walletImplementation.address
136+
]);
137+
138+
await verifyContract(
139+
forwarderImplementationContractName,
140+
forwarderImplementation.address,
141+
[]
142+
);
143+
144+
await verifyContract('ForwarderFactory', forwarderFactory.address, [
145+
forwarderImplementation.address
146+
]);
147+
148+
console.log('Contracts verified');
149+
}
150+
151+
async function verifyContract(
152+
contractName: string,
153+
contractAddress: string,
154+
constructorArguments: string[],
155+
contract?: string
156+
) {
157+
try {
158+
const verifyContractArgs: {
159+
address: string;
160+
constructorArguments: string[];
161+
contract?: string;
162+
} = {
163+
address: contractAddress,
164+
constructorArguments: constructorArguments
165+
};
166+
167+
if (contract) {
168+
verifyContractArgs.contract = contract;
169+
}
170+
171+
await hre.run('verify:verify', verifyContractArgs);
172+
} catch (e) {
173+
// @ts-ignore
174+
// We get a failure API response if the source code has already been uploaded, don't throw in this case.
175+
if (!e.message.includes('Reason: Already Verified')) {
176+
throw e;
177+
}
178+
}
179+
console.log(`Verified ${contractName} on Etherscan!`);
180+
}
181+
182+
main().catch((error) => {
183+
console.error(error);
184+
process.exitCode = 1;
185+
});

0 commit comments

Comments
 (0)