forked from pie-dao/PieVaults
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buidler.config.ts
291 lines (239 loc) · 10.3 KB
/
buidler.config.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
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
require("dotenv").config();
import { usePlugin, task, types } from "@nomiclabs/buidler/config";
import {Signer, Wallet, utils, constants, Contract, BytesLike} from "ethers";
import {deployContract} from "ethereum-waffle";
import DiamondFactoryArtifact from './artifacts/DiamondFactoryContract.json';
import {DiamondFactoryContract} from "./typechain/DiamondFactoryContract";
import { BasketFacet, CallFacet, DiamondCutFacet, DiamondFactory, DiamondFactoryContractFactory, DiamondLoupeFacet, Erc20Facet, OwnershipFacet, PieFactoryContract, PieFactoryContractFactory } from "./typechain";
import BasketFacetArtifact from "./artifacts/BasketFacet.json";
import Erc20FacetArtifact from "./artifacts/ERC20Facet.json";
import CallFacetArtifact from "./artifacts/CallFacet.json";
import DiamondCutFacetArtifact from "./artifacts/DiamondCutFacet.json";
import DiamondLoupeFacetArtifact from "./artifacts/DiamondLoupeFacet.json";
import OwnershipFacetArtifact from "./artifacts/OwnershipFacet.json";
import PieFactoryContractArtifact from "./artifacts/PieFactoryContract.json";
import { IExperiPieFactory } from "./typechain/IExperiPieFactory";
import { Ierc20Factory } from "./typechain/Ierc20Factory";
import { LendingLogicCompoundFactory } from "./typechain/LendingLogicCompoundFactory";
import { LendingRegistry } from "./typechain/LendingRegistry";
import { LendingRegistryFactory } from "./typechain/LendingRegistryFactory";
import { LendingLogicAaveFactory } from "./typechain/LendingLogicAaveFactory";
import { LendingManagerFactory } from "./typechain/LendingManagerFactory";
usePlugin("@nomiclabs/buidler-ethers");
usePlugin('solidity-coverage');
usePlugin("@nomiclabs/buidler-etherscan");
usePlugin('solidity-coverage');
function getSelectors(contract: Contract) {
const signatures: BytesLike[] = [];
for(const key of Object.keys(contract.functions)) {
signatures.push(utils.keccak256(utils.toUtf8Bytes(key)).substr(0, 10));
}
return signatures;
}
const config = {
defaultNetwork: 'buidlerevm',
networks: {
buidlerevm: {
gasPrice: 0,
blockGasLimit: 10000000,
},
localhost: {
url: 'http://localhost:8545'
},
mainnet: {
url: `https://mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`,
accounts: [process.env.PRIVATE_KEY],
gasPrice: 70000000000
},
kovan: {
url: `https://kovan.infura.io/v3/${process.env.INFURA_PROJECT_ID}`,
accounts: [process.env.PRIVATE_KEY]
},
coverage: {
url: 'http://127.0.0.1:8555', // Coverage launches its own ganache-cli client
gasPrice: 0,
blockGasLimit: 100000000,
},
frame: {
url: "http://localhost:1248"
}
},
solc: {
version: '0.7.1',
optimizer: {
// Factory goes above contract size limit
enabled: true,
runs: 200
}
},
etherscan: { apiKey: process.env.ETHERSCAN_KEY }
}
task("deploy-diamond-factory")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const diamondFactory = (await deployContract(signers[0] as Wallet, DiamondFactoryArtifact, [], {gasLimit: 5000000})) as DiamondFactoryContract;
console.log("Factory address:", diamondFactory.address);
return diamondFactory;
});
task("deploy-diamond-from-factory")
.addParam("factory", "address of the factory")
.addParam("diamondCut", "facets to add", undefined, types.json)
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
const diamondCut = taskArgs.diamondCut;
console.log(diamondCut);
const diamondFactory = DiamondFactoryContractFactory.connect(taskArgs.factory, signers[0]);
diamondFactory.deployNewDiamond(account, diamondCut);
});
task("execute-calls")
.addParam("pie", "address of the pie")
.addParam("input", "calls.json", "./call.json")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
const pie = IExperiPieFactory.connect(taskArgs.pie, signers[0]);
const calls = require(taskArgs.input);
const targets: string[] = calls.map((item) => item.target);
const data: string[] = calls.map((item) => item.data);
const values: string[] = calls.map((item) => item.value);
const tx = await pie.call(
targets,
data,
values
);
console.log("Calls send tx id:", tx.hash);
});
task("get-default-cut")
.addParam("factory")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const factory = PieFactoryContractFactory.connect(taskArgs.factory, signers[0]);
const cut = await factory.getDefaultCut();
console.log(cut);
});
task("deploy-pie-from-factory")
.addParam("allocation", "path to json")
.addParam("factory", "pieFactory address", "0xf1e9eC6f1a4D00a24a9F8035C2C5e1D093f9b9aD")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
const factory = PieFactoryContractFactory.connect(taskArgs.factory, signers[0]);
const allocation = require(taskArgs.allocation);
const tokens = allocation.tokens;
for (const token of tokens) {
const tokenContract = Ierc20Factory.connect(token.address, signers[0]);
const allowance = await tokenContract.allowance(account, factory.address);
if(allowance.lt(token.amount)) {
console.log(`Approving ${token.name} ${token.address}`);
await (await tokenContract.approve(factory.address, constants.MaxUint256)).wait(1);
}
}
const receipt = await factory.bakePie(
tokens.map(token => (token.address)),
tokens.map(token => (token.amount)),
allocation.initialSupply,
allocation.symbol,
allocation.name
);
console.log(`Pie deployed: ${receipt.hash}`);
});
task("deploy-pie-factory")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const account = await signers[0].getAddress();
console.log("deploying from:", account);
const contracts: any[] = [];
const gasPrice = 40000000000
const overrides = {
gasPrice
};
const basketFacet = (await deployContract(signers[0], BasketFacetArtifact, [], overrides)) as BasketFacet;
contracts.push({name: "basketFacet", address: basketFacet.address});
const erc20Facet = (await deployContract(signers[0], Erc20FacetArtifact, [], overrides)) as Erc20Facet;
contracts.push({name: "erc20Facet", address: erc20Facet.address});
const callFacet = (await deployContract(signers[0], CallFacetArtifact, [], overrides)) as CallFacet;
contracts.push({name: "callFacet", address: callFacet.address});
const diamondCutFacet = (await deployContract(signers[0], DiamondCutFacetArtifact, [], overrides)) as DiamondCutFacet;
contracts.push({name: "diamondCutFacet", address: diamondCutFacet.address});
const diamondLoupeFacet = (await deployContract(signers[0], DiamondLoupeFacetArtifact, [], overrides)) as DiamondLoupeFacet;
contracts.push({name: "diamondLoupeFacet", address: diamondLoupeFacet.address});
const ownershipFacet = (await deployContract(signers[0], OwnershipFacetArtifact, [], overrides)) as OwnershipFacet;
contracts.push({name: "ownershipFacet", address: ownershipFacet.address});
console.table(contracts);
const FacetCutAction = {
Add: 0,
Replace: 1,
Remove: 2,
};
const diamondCut = [
{
action: FacetCutAction.Add,
facetAddress: basketFacet.address,
functionSelectors: getSelectors(basketFacet)
},
{
action: FacetCutAction.Add,
facetAddress: erc20Facet.address,
functionSelectors: getSelectors(erc20Facet)
},
{
action: FacetCutAction.Add,
facetAddress: callFacet.address,
functionSelectors: getSelectors(callFacet)
},
{
action: FacetCutAction.Add,
facetAddress: diamondCutFacet.address,
functionSelectors: getSelectors(diamondCutFacet)
},
{
action: FacetCutAction.Add,
facetAddress: diamondLoupeFacet.address,
functionSelectors: getSelectors(diamondLoupeFacet)
},
{
action: FacetCutAction.Add,
facetAddress: ownershipFacet.address,
functionSelectors: getSelectors(ownershipFacet)
},
];
console.log(JSON.stringify(diamondCut));
console.log("deploying factory");
const pieFactory = (await deployContract(signers[0], PieFactoryContractArtifact, [] , overrides)) as PieFactoryContract;
console.log(`Factory deployed at: ${pieFactory.address}`);
// Add default facets
for(const facet of diamondCut) {
console.log("adding default facet");
await (await pieFactory.addFacet(facet, overrides)).wait(1);
}
});
task("deploy-lending-manager")
.addParam("lendingRegistry", "address of the lending registry")
.addParam("pie", "address of the pie to manage")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const lendingManager = await (new LendingManagerFactory(signers[0])).deploy(taskArgs.lendingRegistry, taskArgs.pie);
console.log(`lendingManager deployed at: ${lendingManager.address}`);
});
task("deploy-lending-registry")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const lendingRegistry = await (new LendingRegistryFactory(signers[0])).deploy();
console.log(`Deployed lendingRegistry at: ${lendingRegistry.address}`);
});
task("deploy-lending-logic-compound")
.addParam("lendingRegistry", "address of the lending registry")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const lendingLogicCompound = await (new LendingLogicCompoundFactory(signers[0])).deploy(taskArgs.lendingRegistry);
console.log(`Deployed lendingLogicCompound at: ${lendingLogicCompound.address}`);
});
task("deploy-lending-logic-aave")
.addParam("lendingPool")
.setAction(async(taskArgs, {ethers}) => {
const signers = await ethers.getSigners();
const lendingLogicAave = await (new LendingLogicAaveFactory(signers[0])).deploy(taskArgs.lendingPool, 21);
console.log(`Deployed lendingLogicAave at: ${lendingLogicAave.address}`);
});
export default config;