-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuidler.config.js
208 lines (189 loc) · 6.08 KB
/
buidler.config.js
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
// Libraries
const assert = require("assert");
const { utils } = require("ethers");
const GelatoCoreLib = require("@gelatonetwork/core");
// Contracts
const GnosisSafe = require("./artifacts/IGnosisSafe.json");
// Process Env Variables
require("dotenv").config();
const INFURA_ID = process.env.INFURA_ID;
const USER_PK = process.env.USER_PK;
assert.ok(INFURA_ID, "no Infura ID in process.env");
assert.ok(USER_PK, "no User private key (USER_PK) found in .env");
// ================================= CONFIG =========================================
module.exports = {
defaultNetwork: "buidlerevm",
etherscan: {
// The url for the Etherscan API you want to use.
// For example, here we're using the one for the Rinkeby test network
url: "https://api-rinkeby.etherscan.io/api",
// Your API key for Etherscan (Obtain one at https://etherscan.io/)
apiKey: process.env.ETHERSCAN_KEY,
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
},
},
networks: {
rinkeby: {
// Standard
accounts: USER_PK ? [USER_PK] : [],
chainId: 4,
url: `https://rinkeby.infura.io/v3/${INFURA_ID}`,
// Custom
// Rinkeby: addressBook
addressBook: {
// Rinkeby: Gelato
gelatoExecutor: {
default: "0xa5A98a6AD379C7B578bD85E35A3eC28AD72A336b", // PermissionedExecutors
},
},
// Rinkeby: Deployments
deployments: {
// ===== Gelato Core ====
GelatoCore: "0x733aDEf4f8346FD96107d8d6605eA9ab5645d632",
// === GelatoUserProxies ===
GelatoUserProxyFactory: "0x0309EC714C7E7c4C5B94bed97439940aED4F0624",
// ===== Provider Modules ====
ProviderModuleGelatoUserProxy:
"0x66a35534126B4B0845A2aa03825b95dFaaE88B0C",
ProviderModuleGnosisSafeProxy:
"0x2661B579243c49988D9eDAf114Bfac5c5E249287",
},
},
mainnet: {
// Standard
accounts: USER_PK ? [USER_PK] : [],
chainId: 1,
url: `https://mainnet.infura.io/v3/${INFURA_ID}`,
// Custom
// Mainnet: addressBook
addressBook: {
// Mainnet: Gelato
gelatoExecutor: {
default: "0xd70d5fb9582cc3b5b79bbfaecbb7310fd0e3b582", // PermissionedExecutors
},
},
// Mainnet: Deployments
deployments: {
// ===== Gelato Core ====
GelatoCore: "0x1d681d76ce96E4d70a88A00EBbcfc1E47808d0b8",
// === GelatoUserProxies ===
GelatoUserProxyFactory: "0xb0aa48f1eF1bF096140E1dA1c76D25151501608b",
// ===== Provider Modules ====
ProviderModuleGelatoUserProxy:
"0x4372692C2D28A8e5E15BC2B91aFb62f5f8812b93",
ProviderModuleGnosisSafeProxy:
"0x3a994Cd3a464032B8d0eAa16F91C446A46c4fEbC",
},
},
},
solc: {
version: "0.6.12",
optimizer: { enabled: true },
},
};
// ================================= BRE extension ==================================
extendEnvironment((bre) => {
// Contracts
bre.GnosisSafe = GnosisSafe;
// Libraries
bre.GelatoCoreLib = GelatoCoreLib;
});
// ================================= PLUGINS =========================================
usePlugin("@nomiclabs/buidler-ethers");
usePlugin("@nomiclabs/buidler-waffle");
usePlugin("buidler-deploy");
usePlugin("@nomiclabs/buidler-etherscan");
// ================================= TASKS =========================================
task("abi-encode-withselector")
.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-withselector: no abi passed");
const interFace = new utils.Interface(taskArgs.abi);
// if (
// !GelatoCoreLib.checkNestedObj(
// interFace,
// "functions",
// taskArgs.functionname
// )
// )
// throw new Error("\nfunctionname is not on contract's interface");
let payloadWithSelector;
if (taskArgs.inputs) {
let iterableInputs;
try {
iterableInputs = [...taskArgs.inputs];
} catch (error) {
iterableInputs = [taskArgs.inputs];
}
payloadWithSelector = interFace.functions[taskArgs.functionname].encode(
iterableInputs
);
} else {
payloadWithSelector = interFace.functions[taskArgs.functionname].encode(
[]
);
}
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 {
const gelatoCore = await ethers.getContractAt(
GelatoCoreLib.GelatoCore.abi,
taskArgs.gelatocoreaddress
? taskArgs.gelatocoreaddress
: network.config.deployments.GelatoCore
);
const oracleAbi = ["function latestAnswer() view returns (int256)"];
const gelatoGasPriceOracleAddress = await gelatoCore.gelatoGasPriceOracle();
// Get gelatoGasPriceOracleAddress
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);
}
});