-
Notifications
You must be signed in to change notification settings - Fork 6
/
buidler.config.js
157 lines (139 loc) · 4.79 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
// Libraries
const assert = require("assert");
const { utils } = require("ethers");
const GelatoCoreLib = require("@gelatonetwork/core");
// Process Env Variables
require("dotenv").config();
const INFURA_ID = process.env.INFURA_ID;
assert.ok(INFURA_ID, "no Infura ID in process.env");
// ================================= CONFIG =========================================
module.exports = {
defaultNetwork: "ganache",
networks: {
ganache: {
timeout: 120000,
// Standard config
url: "http://localhost:8545",
fork: `https://mainnet.infura.io/v3/${INFURA_ID}`,
// Custom
GelatoCore: "0x1d681d76ce96E4d70a88A00EBbcfc1E47808d0b8",
InstaIndex: "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723",
InstaList: "0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb",
InstaConnectors: "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c",
InstaAccount: "0x939Daad09fC4A9B8f8A9352A485DAb2df4F4B3F8",
ConnectAuth: "0xd1aFf9f2aCf800C876c409100D6F39AEa93Fc3D9",
ConnectBasic: "0x6a31c5982C5Bc5533432913cf06a66b6D3333a95",
ConnectGelato: "0x37A7009d424951dd5D5F155fA588D9a03C455163",
ConnectMaker: "0xac02030d8a8F49eD04b2f52C394D3F901A10F8A9",
ConnectCompound: "0x07F81230d73a78f63F0c2A3403AD281b067d28F8",
ConnectInstaPool: "0xCeF5f3c402d4fef76A038e89a4357176963e1464",
DAI: "0x6b175474e89094c44da98b954eedeac495271d0f",
DAI_UNISWAP: "0x2a1530C4C41db0B0b2bB646CB5Eb1A67b7158667",
CDAI: "0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643",
DssCdpManager: "0x5ef30b9986345249bc32d8928B7ee64DE9435E39",
GetCdps: "0x36a724Bd100c39f0Ea4D3A20F7097eE01A8Ff573",
ProviderModuleDSA: "0x0C25452d20cdFeEd2983fa9b9b9Cf4E81D6f2fE2",
},
},
solc: {
version: "0.6.12",
optimizer: { enabled: true },
},
};
// ================================= PLUGINS =========================================
usePlugin("@nomiclabs/buidler-ethers");
usePlugin("@nomiclabs/buidler-ganache");
usePlugin("@nomiclabs/buidler-waffle");
// ================================= 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);
let functionFragment;
try {
functionFragment = interFace.getFunction(taskArgs.functionname);
} catch (error) {
throw new Error(
`\n ❌ abi-encode-withselector: 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 {
const gelatoCore = await ethers.getContractAt(
GelatoCoreLib.GelatoCore.abi,
taskArgs.gelatocoreaddress
? taskArgs.gelatocoreaddress
: network.config.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);
}
});