-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathdeploy-test-framework.js
More file actions
316 lines (293 loc) · 13.4 KB
/
deploy-test-framework.js
File metadata and controls
316 lines (293 loc) · 13.4 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
const {ethers} = require("hardhat");
const {JsonRpcProvider} = require("@ethersproject/providers");
const SuperfluidPoolDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/agreements/gdav1/SuperfluidPoolDeployerLibrary.sol/SuperfluidPoolDeployerLibrary.json");
const SuperfluidGovDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidGovDeployerLibrary.json");
const SuperfluidHostDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidHostDeployerLibrary.json");
const SuperfluidCFAv1DeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidCFAv1DeployerLibrary.json");
const SuperfluidIDAv1DeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidIDAv1DeployerLibrary.json");
const SuperfluidGDAv1DeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidGDAv1DeployerLibrary.json");
const SuperTokenDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperTokenDeployerLibrary.json");
const SuperfluidPeripheryDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidPeripheryDeployerLibrary.json");
const SuperfluidPoolLogicDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidPoolLogicDeployerLibrary.json");
const SuperfluidPoolNFTLogicDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperfluidPoolNFTLogicDeployerLibrary.json");
const ProxyDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/ProxyDeployerLibrary.json");
const CFAv1ForwarderDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/CFAv1ForwarderDeployerLibrary.json");
const GDAv1ForwarderDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/GDAv1ForwarderDeployerLibrary.json");
const SuperTokenFactoryDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/SuperTokenFactoryDeployerLibrary.json");
const SuperfluidFrameworkDeployerArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeployer.t.sol/SuperfluidFrameworkDeployer.json");
const SlotsBitmapLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/libs/SlotsBitmapLibrary.sol/SlotsBitmapLibrary.json");
const TokenDeployerLibraryArtifact = require("@superfluid-finance/ethereum-contracts/build/hardhat/contracts/utils/SuperfluidFrameworkDeploymentSteps.t.sol/TokenDeployerLibrary.json");
const ERC1820Registry = require("../dev-scripts/artifacts/ERC1820Registry.json");
const ERC1820_ADDRESS = "0x1820a4b7618bde71dce8cdc73aab6c95905fad24";
const ERC1820_BIN = ERC1820Registry.bin;
const ERC1820_DEPLOYER = "0xa990077c3205cbDf861e17Fa532eeB069cE9fF96";
const ERC1820_PAYLOAD =
"0xf90a388085174876e800830c35008080b909e5" +
ERC1820_BIN +
"1ba01820182018201820182018201820182018201820182018201820182018201820a01820182018201820182018201820182018201820182018201820182018201820";
async function deployERC1820(provider) {
if (process.env.DEBUG_CONSOLE === true) {
console.log("Deploying ERC1820...");
}
const code = await provider.send("eth_getCode", [
ERC1820_ADDRESS,
"latest",
]);
if (code === "0x") {
const [from] = await provider.send("eth_accounts", []);
await provider.send("eth_sendTransaction", [
{
from,
to: ERC1820_DEPLOYER,
value: "0x11c37937e080000",
},
]);
await provider.send("eth_sendRawTransaction", [ERC1820_PAYLOAD]);
if (process.env.DEBUG_CONSOLE === true) {
console.log("ERC1820 registry successfully deployed");
}
}
}
/**
* Gets the address of the deployed contract.
* This is for handling the different contract objects in ethers v5 (contract.address)
* vs ethers v6 (contract.target), that is, v6 does not have contract.address and vice versa.
* @param {ethers.Contract} contract
* @returns
*/
const getContractAddress = (contract) => {
return contract.address || contract.target;
};
const _getFactoryAndReturnDeployedContract = async (
contractName,
artifact,
signerOrOptions,
...args
) => {
if (process.env.DEBUG_CONSOLE === true) {
console.log(`Deploying ${contractName}...`);
}
const ContractFactory = await ethers.getContractFactoryFromArtifact(
artifact,
signerOrOptions
);
const contract = await ContractFactory.deploy(...args);
// ethers v5
if (contract.deployed) {
await contract.deployed();
} else if (!contract.deployed) {
// ethers v6
await contract.waitForDeployment();
}
if (process.env.DEBUG_CONSOLE === true) {
console.log(
`${contractName} Deployed At:`,
getContractAddress(contract)
);
}
return contract;
};
const deployTestFrameworkWithEthersV6 = async (privateKey, provider) => {
if (!privateKey) throw new Error("You must pass a private key.");
if (!provider) throw new Error("You must pass a provider.");
const signer = new ethers.Wallet(privateKey, provider);
return await _deployTestFramework(provider, signer);
};
const deployTestFrameworkWithEthersV5 = async (ethersV5Signer) => {
if (!ethersV5Signer.provider)
throw new Error("Your signer must have a provider.");
return await _deployTestFramework(ethersV5Signer.provider, ethersV5Signer);
};
const _deployTestFramework = async (provider, signer) => {
await deployERC1820(provider);
const SlotsBitmapLibrary = await _getFactoryAndReturnDeployedContract(
"SlotsBitmapLibrary",
SlotsBitmapLibraryArtifact,
signer
);
const SuperfluidGovDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidGovDeployerLibrary",
SuperfluidGovDeployerLibraryArtifact,
signer
);
const SuperfluidHostDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidHostDeployerLibrary",
SuperfluidHostDeployerLibraryArtifact,
signer
);
const SuperfluidCFAv1DeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidCFAv1DeployerLibrary",
SuperfluidCFAv1DeployerLibraryArtifact,
signer
);
const SuperfluidIDAv1DeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidIDAv1DeployerLibrary",
SuperfluidIDAv1DeployerLibraryArtifact,
{
signer,
libraries: {
SlotsBitmapLibrary: getContractAddress(SlotsBitmapLibrary),
},
}
);
const SuperfluidPoolDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidPoolDeployerLibrary",
SuperfluidPoolDeployerLibraryArtifact,
signer
);
const SuperfluidGDAv1DeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidGDAv1DeployerLibrary",
SuperfluidGDAv1DeployerLibraryArtifact,
{
signer,
libraries: {
SuperfluidPoolDeployerLibrary:
SuperfluidPoolDeployerLibrary.address,
SlotsBitmapLibrary: SlotsBitmapLibrary.address,
},
}
);
const SuperTokenDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperTokenDeployerLibrary",
SuperTokenDeployerLibraryArtifact,
{
signer,
}
);
const SuperfluidPeripheryDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidPeripheryDeployerLibrary",
SuperfluidPeripheryDeployerLibraryArtifact,
signer
);
const SuperfluidPoolLogicDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidPoolLogicDeployerLibrary",
SuperfluidPoolLogicDeployerLibraryArtifact,
signer
);
const SuperfluidPoolNFTLogicDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperfluidPoolNFTLogicDeployerLibrary",
SuperfluidPoolNFTLogicDeployerLibraryArtifact,
signer
);
const ProxyDeployerLibrary = await _getFactoryAndReturnDeployedContract(
"ProxyDeployerLibrary",
ProxyDeployerLibraryArtifact,
signer
);
const CFAv1ForwarderDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"CFAv1ForwarderDeployerLibrary",
CFAv1ForwarderDeployerLibraryArtifact,
signer
);
const GDAv1ForwarderDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"GDAv1ForwarderDeployerLibrary",
GDAv1ForwarderDeployerLibraryArtifact,
signer
);
const SuperTokenFactoryDeployerLibrary =
await _getFactoryAndReturnDeployedContract(
"SuperTokenFactoryDeployerLibrary",
SuperTokenFactoryDeployerLibraryArtifact,
signer
);
const TokenDeployerLibrary = await _getFactoryAndReturnDeployedContract(
"TokenDeployerLibrary",
TokenDeployerLibraryArtifact,
signer
);
const sfDeployer = await _getFactoryAndReturnDeployedContract(
"SuperfluidFrameworkDeployer",
SuperfluidFrameworkDeployerArtifact,
{
signer,
libraries: {
SuperfluidGovDeployerLibrary: getContractAddress(
SuperfluidGovDeployerLibrary
),
SuperfluidHostDeployerLibrary: getContractAddress(
SuperfluidHostDeployerLibrary
),
SuperfluidCFAv1DeployerLibrary: getContractAddress(
SuperfluidCFAv1DeployerLibrary
),
SuperfluidIDAv1DeployerLibrary: getContractAddress(
SuperfluidIDAv1DeployerLibrary
),
SuperfluidGDAv1DeployerLibrary: getContractAddress(
SuperfluidGDAv1DeployerLibrary
),
SuperfluidPeripheryDeployerLibrary: getContractAddress(
SuperfluidPeripheryDeployerLibrary
),
SuperTokenDeployerLibrary: getContractAddress(
SuperTokenDeployerLibrary
),
SuperfluidPoolLogicDeployerLibrary: getContractAddress(
SuperfluidPoolLogicDeployerLibrary
),
SuperfluidPoolNFTLogicDeployerLibrary: getContractAddress(
SuperfluidPoolNFTLogicDeployerLibrary
),
ProxyDeployerLibrary: getContractAddress(ProxyDeployerLibrary),
CFAv1ForwarderDeployerLibrary: getContractAddress(
CFAv1ForwarderDeployerLibrary
),
GDAv1ForwarderDeployerLibrary: getContractAddress(
GDAv1ForwarderDeployerLibrary
),
SuperTokenFactoryDeployerLibrary: getContractAddress(
SuperTokenFactoryDeployerLibrary
),
TokenDeployerLibrary: getContractAddress(TokenDeployerLibrary),
},
}
);
const numSteps = await sfDeployer.getNumSteps();
for (let i = 0; i < numSteps; i++) {
await sfDeployer.executeStep(i);
}
return {frameworkDeployer: sfDeployer};
};
const printProtocolFrameworkAddresses = (framework) => {
const output = {
Host: framework.host,
CFAv1: framework.cfa,
IDAv1: framework.ida,
SuperTokenFactory: framework.superTokenFactory,
SuperTokenLogic: framework.superTokenLogic,
Resolver: framework.resolver,
SuperfluidLoader: framework.superfluidLoader,
CFAv1Forwarder: framework.cfaV1Forwarder,
};
console.log(JSON.stringify(output, null, 2));
return output;
};
/**
* {DEPRECATED}
* Deploys Superfluid Framework in local testing environments.
*
* NOTE: This only works with Hardhat + ethers v5.
* @returns SuperfluidFrameworkDeployer Contract object
*/
const deployTestFramework = async () => {
const signer = (await ethers.getSigners())[0];
return await deployTestFrameworkWithEthersV5(signer);
};
module.exports = {
deployTestFramework,
deployTestFrameworkWithEthersV5,
deployTestFrameworkWithEthersV6,
printProtocolFrameworkAddresses,
};