forked from Gauddel/gelato-instadapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buidler.config.ts
executable file
·259 lines (228 loc) · 8.73 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
import {
BuidlerConfig,
task,
types,
usePlugin,
} from "@nomiclabs/buidler/config";
declare var ethers;
// Libraries
const assert = require("assert");
const { utils } = require("ethers");
const GelatoCoreLib = require("@gelatonetwork/core");
import { constants } from "./src/constants/constants";
import { writeFileSync } from "fs";
// Process Env Variables
require("dotenv").config();
const INFURA_ID = process.env.INFURA_ID;
const INFURA_PRIVATE_KEY = process.env.INFURA_PRIVATE_KEY;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
assert.ok(INFURA_ID, "no Infura ID in process.env");
import { BigNumber } from "ethers";
const APY_2_PERCENT_IN_SECONDS = BigNumber.from("1000000000627937192491029810");
// ================================= CONFIG =========================================
const config: BuidlerConfig = {
defaultNetwork: "ganache",
networks: {
ganache: {
// Standard config
url: "http://localhost:8545",
// @ts-ignore
fork: `https://:${INFURA_PRIVATE_KEY}@mainnet.infura.io/v3/${INFURA_ID}`,
defaultBalanceEther: 1000,
GelatoCore: "0x1d681d76ce96E4d70a88A00EBbcfc1E47808d0b8",
},
mainnet: {
// Standard config
url: `https://:${INFURA_PRIVATE_KEY}@mainnet.infura.io/v3/${INFURA_ID}`,
accounts: PRIVATE_KEY ? [PRIVATE_KEY] : []
},
},
solc: {
version: "0.6.12",
optimizer: { enabled: true },
},
typechain: {
outDir: "typechain",
target: "ethers-v4",
},
paths: {
tests: "./src/test",
},
};
export default config;
// ================================= PLUGINS =========================================
usePlugin("@nomiclabs/buidler-ethers");
usePlugin("@nomiclabs/buidler-ganache");
usePlugin("@nomiclabs/buidler-waffle");
usePlugin("buidler-typechain");
// ================================= TASKS =========================================
task("abi-encode-with-selector")
.addPositionalParam(
"abi",
"Contract ABI in array form",
undefined,
types.json
)
.addPositionalParam("functionName")
.addOptionalVariadicPositionalParam(
"inputs",
"Array of function params",
undefined,
types.json
)
.addFlag("log")
.setAction(async (taskArgs) => {
try {
if (taskArgs.log) console.log(taskArgs);
if (!taskArgs.abi)
throw new Error("abi-encode-with-selector: no abi passed");
const interFace = new utils.Interface(taskArgs.abi);
let functionFragment;
try {
functionFragment = interFace.getFunction(taskArgs.functionName);
} catch (error) {
throw new Error(
`\n ❌ abi-encode-with-selector: functionName "${taskArgs.functionName}" not found`
);
}
let payloadWithSelector;
if (taskArgs.inputs) {
let iterableInputs;
try {
iterableInputs = [...taskArgs.inputs];
} catch (error) {
iterableInputs = [taskArgs.inputs];
}
payloadWithSelector = interFace.encodeFunctionData(
functionFragment,
iterableInputs
);
} else {
payloadWithSelector = interFace.encodeFunctionData(
functionFragment,
[]
);
}
if (taskArgs.log)
console.log(
`\nEncodedPayloadWithSelector:\n${payloadWithSelector}\n`
);
return payloadWithSelector;
} catch (err) {
console.error(err);
process.exit(1);
}
});
task(
"fetchGelatoGasPrice",
`Returns the current gelato gas price used for calling canExec and exec`
)
.addOptionalParam("gelatocoreaddress")
.addFlag("log", "Logs return values to stdout")
.setAction(async (taskArgs) => {
try {
//@ts-ignore
const gelatoCore = await ethers.getContractAt(
GelatoCoreLib.GelatoCore.abi,
taskArgs.gelatocoreaddress
? taskArgs.gelatocoreaddress
: constants.GelatoCore
);
const oracleAbi = ["function latestAnswer() view returns (int256)"];
const gelatoGasPriceOracleAddress = await gelatoCore.gelatoGasPriceOracle();
// Get gelatoGasPriceOracleAddress
//@ts-ignore
const gelatoGasPriceOracle = await ethers.getContractAt(
oracleAbi,
gelatoGasPriceOracleAddress
);
// lastAnswer is used by GelatoGasPriceOracle as well as the Chainlink Oracle
const gelatoGasPrice = await gelatoGasPriceOracle.latestAnswer();
if (taskArgs.log) {
console.log(
`\ngelatoGasPrice: ${utils.formatUnits(
gelatoGasPrice.toString(),
"gwei"
)} gwei\n`
);
}
return gelatoGasPrice;
} catch (error) {
console.error(error, "\n");
process.exit(1);
}
});
task(
"deployContractsTestNet",
`Returns the current gelato gas price used for calling canExec and exec`
).setAction(async () => {
//MockCCI
const MockCCI = await ethers.getContractFactory("MockCCI");
const mockCCI = await MockCCI.deploy(APY_2_PERCENT_IN_SECONDS);
await mockCCI.deployed();
//MockCMI
const MockCMI = await ethers.getContractFactory("MockCMI");
const mockCMI = await MockCMI.deploy(APY_2_PERCENT_IN_SECONDS);
await mockCMI.deployed();
//conditionCompareUints
const ConditionCompareUintsFromTwoSources = await ethers.getContractFactory(
"ConditionCompareUintsFromTwoSources"
);
const conditionCompareUints = await ConditionCompareUintsFromTwoSources.deploy();
await conditionCompareUints.deployed();
//conditionHasMakerVault
const ConditionHasMakerVault = await ethers.getContractFactory(
"ConditionHasOpenMakerVault"
);
const conditionHasMakerVault = await ConditionHasMakerVault.deploy();
await conditionHasMakerVault.deployed();
const addresses = {
mockCCI: mockCCI.address,
mockCMI: mockCMI.address,
conditionAddress: conditionCompareUints.address,
conditionHasMakerVault: conditionHasMakerVault.address,
};
writeFileSync("addresses.txt", JSON.stringify(addresses));
});
task(
"deployContractsMainNet",
`Returns the current gelato gas price used for calling canExec and exec`
).setAction(async () => {
let userWallet;
[userWallet] = await ethers.getSigners();
let initialBalance: number = Number(await userWallet.getBalance()) / 1e18
console.log('initial balance', initialBalance)
//CustomCompoundInterface
const CustomCompoundInterface = await ethers.getContractFactory("CustomCompoundInterface");
const customCompoundInterface = await CustomCompoundInterface.deploy();
await customCompoundInterface.deployed();
console.log('customCompoundInterface deployed at :', customCompoundInterface.address)
//CustomMakerInterface
const CustomMakerInterface = await ethers.getContractFactory("CustomMakerInterface");
const customMakerInterface = await CustomMakerInterface.deploy();
await customMakerInterface.deployed();
console.log('customMakerInterface deployed at :', customMakerInterface.address)
//conditionCompareUints
const ConditionCompareUintsFromTwoSources = await ethers.getContractFactory(
"ConditionCompareUintsFromTwoSources"
);
const conditionCompareUints = await ConditionCompareUintsFromTwoSources.deploy();
await conditionCompareUints.deployed();
console.log('conditionCompareUints deployed at :', conditionCompareUints.address)
//conditionHasMakerVault
const ConditionHasMakerVault = await ethers.getContractFactory(
"ConditionHasOpenMakerVault"
);
const conditionHasMakerVault = await ConditionHasMakerVault.deploy();
await conditionHasMakerVault.deployed();
console.log('conditionHasMakerVault deployed at :', conditionHasMakerVault.address)
console.log('total cost', initialBalance - Number(await userWallet.getBalance()) / 1e18, " ETH")
const addresses = {
customCompoundInterface: customCompoundInterface.address,
customMakerInterface: customMakerInterface.address,
conditionAddress: conditionCompareUints.address,
conditionHasMakerVault: conditionHasMakerVault.address,
};
writeFileSync("addresses.txt", JSON.stringify(addresses));
return addresses
});