@bgd-labs/aave-address-book 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/.gitmodules +4 -0
  2. package/CHANGELOG.md +56 -0
  3. package/LICENSE +7 -0
  4. package/README.md +94 -0
  5. package/addressbook_logo.png +0 -0
  6. package/dist/AaveAddressBook.d.ts +17 -0
  7. package/dist/AaveAddressBook.js +20 -0
  8. package/dist/AaveV2Avalanche.d.ts +9 -0
  9. package/dist/AaveV2Avalanche.js +12 -0
  10. package/dist/AaveV2Ethereum.d.ts +9 -0
  11. package/dist/AaveV2Ethereum.js +12 -0
  12. package/dist/AaveV2EthereumAMM.d.ts +9 -0
  13. package/dist/AaveV2EthereumAMM.js +12 -0
  14. package/dist/AaveV2EthereumArc.d.ts +9 -0
  15. package/dist/AaveV2EthereumArc.js +12 -0
  16. package/dist/AaveV2Fuji.d.ts +9 -0
  17. package/dist/AaveV2Fuji.js +12 -0
  18. package/dist/AaveV2Mumbai.d.ts +9 -0
  19. package/dist/AaveV2Mumbai.js +12 -0
  20. package/dist/AaveV2Polygon.d.ts +9 -0
  21. package/dist/AaveV2Polygon.js +12 -0
  22. package/dist/AaveV3Arbitrum.d.ts +9 -0
  23. package/dist/AaveV3Arbitrum.js +12 -0
  24. package/dist/AaveV3Avalanche.d.ts +9 -0
  25. package/dist/AaveV3Avalanche.js +12 -0
  26. package/dist/AaveV3Fantom.d.ts +9 -0
  27. package/dist/AaveV3Fantom.js +12 -0
  28. package/dist/AaveV3FantomTestnet.d.ts +9 -0
  29. package/dist/AaveV3FantomTestnet.js +12 -0
  30. package/dist/AaveV3Fuji.d.ts +9 -0
  31. package/dist/AaveV3Fuji.js +12 -0
  32. package/dist/AaveV3Harmony.d.ts +9 -0
  33. package/dist/AaveV3Harmony.js +12 -0
  34. package/dist/AaveV3Mumbai.d.ts +9 -0
  35. package/dist/AaveV3Mumbai.js +12 -0
  36. package/dist/AaveV3Optimism.d.ts +9 -0
  37. package/dist/AaveV3Optimism.js +12 -0
  38. package/dist/AaveV3OptimismKovan.d.ts +9 -0
  39. package/dist/AaveV3OptimismKovan.js +12 -0
  40. package/dist/AaveV3Polygon.d.ts +9 -0
  41. package/dist/AaveV3Polygon.js +12 -0
  42. package/foundry.toml +8 -0
  43. package/lib/forge-std/.github/workflows/tests.yml +27 -0
  44. package/lib/forge-std/.gitmodules +3 -0
  45. package/lib/forge-std/LICENSE-APACHE +203 -0
  46. package/lib/forge-std/LICENSE-MIT +25 -0
  47. package/lib/forge-std/README.md +246 -0
  48. package/lib/forge-std/lib/ds-test/LICENSE +674 -0
  49. package/lib/forge-std/lib/ds-test/Makefile +14 -0
  50. package/lib/forge-std/lib/ds-test/default.nix +4 -0
  51. package/lib/forge-std/lib/ds-test/demo/demo.sol +222 -0
  52. package/lib/forge-std/lib/ds-test/src/test.sol +469 -0
  53. package/lib/forge-std/src/Script.sol +39 -0
  54. package/lib/forge-std/src/StdJson.sol +118 -0
  55. package/lib/forge-std/src/Test.sol +1134 -0
  56. package/lib/forge-std/src/Vm.sol +231 -0
  57. package/lib/forge-std/src/console.sol +1533 -0
  58. package/lib/forge-std/src/console2.sol +1538 -0
  59. package/lib/forge-std/src/test/Script.t.sol +12 -0
  60. package/lib/forge-std/src/test/StdAssertions.t.sol +591 -0
  61. package/lib/forge-std/src/test/StdCheats.t.sol +282 -0
  62. package/lib/forge-std/src/test/StdError.t.sol +124 -0
  63. package/lib/forge-std/src/test/StdMath.t.sol +200 -0
  64. package/lib/forge-std/src/test/StdStorage.t.sol +321 -0
  65. package/lib/forge-std/src/test/fixtures/broadcast.log.json +187 -0
  66. package/package.json +39 -0
  67. package/src/AaveAddressBook.sol +28 -0
  68. package/src/AaveAddressBookV2.sol +143 -0
  69. package/src/AaveAddressBookV2Testnet.sol +74 -0
  70. package/src/AaveAddressBookV3.sol +166 -0
  71. package/src/AaveAddressBookV3Testnet.sol +120 -0
  72. package/src/AaveGovernanceV2.sol +549 -0
  73. package/src/AaveV2.sol +931 -0
  74. package/src/AaveV2Avalanche.sol +35 -0
  75. package/src/AaveV2Ethereum.sol +36 -0
  76. package/src/AaveV2EthereumAMM.sol +36 -0
  77. package/src/AaveV2EthereumArc.sol +36 -0
  78. package/src/AaveV2Fuji.sol +35 -0
  79. package/src/AaveV2Mumbai.sol +35 -0
  80. package/src/AaveV2Polygon.sol +35 -0
  81. package/src/AaveV3.sol +2406 -0
  82. package/src/AaveV3Arbitrum.sol +34 -0
  83. package/src/AaveV3Avalanche.sol +34 -0
  84. package/src/AaveV3Fantom.sol +34 -0
  85. package/src/AaveV3FantomTestnet.sol +34 -0
  86. package/src/AaveV3Fuji.sol +34 -0
  87. package/src/AaveV3Harmony.sol +34 -0
  88. package/src/AaveV3HarmonyTestnet.sol +34 -0
  89. package/src/AaveV3Mumbai.sol +34 -0
  90. package/src/AaveV3Optimism.sol +34 -0
  91. package/src/AaveV3OptimismKovan.sol +34 -0
  92. package/src/AaveV3Polygon.sol +34 -0
  93. package/src/Common.sol +9 -0
  94. package/src/test/AaveV2Ethereum.t.sol +72 -0
  95. package/src/test/AaveV2Misfits.t.sol +33 -0
  96. package/src/test/AaveV3Avalanche.t.sol +65 -0
  97. package/src/ts/AaveAddressBook.ts +17 -0
  98. package/src/ts/AaveV2Avalanche.ts +11 -0
  99. package/src/ts/AaveV2Ethereum.ts +12 -0
  100. package/src/ts/AaveV2EthereumAMM.ts +12 -0
  101. package/src/ts/AaveV2EthereumArc.ts +12 -0
  102. package/src/ts/AaveV2Fuji.ts +11 -0
  103. package/src/ts/AaveV2Mumbai.ts +11 -0
  104. package/src/ts/AaveV2Polygon.ts +11 -0
  105. package/src/ts/AaveV3Arbitrum.ts +12 -0
  106. package/src/ts/AaveV3Avalanche.ts +12 -0
  107. package/src/ts/AaveV3Fantom.ts +12 -0
  108. package/src/ts/AaveV3FantomTestnet.ts +12 -0
  109. package/src/ts/AaveV3Fuji.ts +12 -0
  110. package/src/ts/AaveV3Harmony.ts +12 -0
  111. package/src/ts/AaveV3Mumbai.ts +12 -0
  112. package/src/ts/AaveV3Optimism.ts +12 -0
  113. package/src/ts/AaveV3OptimismKovan.ts +12 -0
  114. package/src/ts/AaveV3Polygon.ts +12 -0
  115. package/tsconfig.json +101 -0
@@ -0,0 +1,469 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+ // This program is free software: you can redistribute it and/or modify
4
+ // it under the terms of the GNU General Public License as published by
5
+ // the Free Software Foundation, either version 3 of the License, or
6
+ // (at your option) any later version.
7
+
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU General Public License for more details.
12
+
13
+ // You should have received a copy of the GNU General Public License
14
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ pragma solidity >=0.5.0;
17
+
18
+ contract DSTest {
19
+ event log (string);
20
+ event logs (bytes);
21
+
22
+ event log_address (address);
23
+ event log_bytes32 (bytes32);
24
+ event log_int (int);
25
+ event log_uint (uint);
26
+ event log_bytes (bytes);
27
+ event log_string (string);
28
+
29
+ event log_named_address (string key, address val);
30
+ event log_named_bytes32 (string key, bytes32 val);
31
+ event log_named_decimal_int (string key, int val, uint decimals);
32
+ event log_named_decimal_uint (string key, uint val, uint decimals);
33
+ event log_named_int (string key, int val);
34
+ event log_named_uint (string key, uint val);
35
+ event log_named_bytes (string key, bytes val);
36
+ event log_named_string (string key, string val);
37
+
38
+ bool public IS_TEST = true;
39
+ bool private _failed;
40
+
41
+ address constant HEVM_ADDRESS =
42
+ address(bytes20(uint160(uint256(keccak256('hevm cheat code')))));
43
+
44
+ modifier mayRevert() { _; }
45
+ modifier testopts(string memory) { _; }
46
+
47
+ function failed() public returns (bool) {
48
+ if (_failed) {
49
+ return _failed;
50
+ } else {
51
+ bool globalFailed = false;
52
+ if (hasHEVMContext()) {
53
+ (, bytes memory retdata) = HEVM_ADDRESS.call(
54
+ abi.encodePacked(
55
+ bytes4(keccak256("load(address,bytes32)")),
56
+ abi.encode(HEVM_ADDRESS, bytes32("failed"))
57
+ )
58
+ );
59
+ globalFailed = abi.decode(retdata, (bool));
60
+ }
61
+ return globalFailed;
62
+ }
63
+ }
64
+
65
+ function fail() internal {
66
+ if (hasHEVMContext()) {
67
+ (bool status, ) = HEVM_ADDRESS.call(
68
+ abi.encodePacked(
69
+ bytes4(keccak256("store(address,bytes32,bytes32)")),
70
+ abi.encode(HEVM_ADDRESS, bytes32("failed"), bytes32(uint256(0x01)))
71
+ )
72
+ );
73
+ status; // Silence compiler warnings
74
+ }
75
+ _failed = true;
76
+ }
77
+
78
+ function hasHEVMContext() internal view returns (bool) {
79
+ uint256 hevmCodeSize = 0;
80
+ assembly {
81
+ hevmCodeSize := extcodesize(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D)
82
+ }
83
+ return hevmCodeSize > 0;
84
+ }
85
+
86
+ modifier logs_gas() {
87
+ uint startGas = gasleft();
88
+ _;
89
+ uint endGas = gasleft();
90
+ emit log_named_uint("gas", startGas - endGas);
91
+ }
92
+
93
+ function assertTrue(bool condition) internal {
94
+ if (!condition) {
95
+ emit log("Error: Assertion Failed");
96
+ fail();
97
+ }
98
+ }
99
+
100
+ function assertTrue(bool condition, string memory err) internal {
101
+ if (!condition) {
102
+ emit log_named_string("Error", err);
103
+ assertTrue(condition);
104
+ }
105
+ }
106
+
107
+ function assertEq(address a, address b) internal {
108
+ if (a != b) {
109
+ emit log("Error: a == b not satisfied [address]");
110
+ emit log_named_address(" Expected", b);
111
+ emit log_named_address(" Actual", a);
112
+ fail();
113
+ }
114
+ }
115
+ function assertEq(address a, address b, string memory err) internal {
116
+ if (a != b) {
117
+ emit log_named_string ("Error", err);
118
+ assertEq(a, b);
119
+ }
120
+ }
121
+
122
+ function assertEq(bytes32 a, bytes32 b) internal {
123
+ if (a != b) {
124
+ emit log("Error: a == b not satisfied [bytes32]");
125
+ emit log_named_bytes32(" Expected", b);
126
+ emit log_named_bytes32(" Actual", a);
127
+ fail();
128
+ }
129
+ }
130
+ function assertEq(bytes32 a, bytes32 b, string memory err) internal {
131
+ if (a != b) {
132
+ emit log_named_string ("Error", err);
133
+ assertEq(a, b);
134
+ }
135
+ }
136
+ function assertEq32(bytes32 a, bytes32 b) internal {
137
+ assertEq(a, b);
138
+ }
139
+ function assertEq32(bytes32 a, bytes32 b, string memory err) internal {
140
+ assertEq(a, b, err);
141
+ }
142
+
143
+ function assertEq(int a, int b) internal {
144
+ if (a != b) {
145
+ emit log("Error: a == b not satisfied [int]");
146
+ emit log_named_int(" Expected", b);
147
+ emit log_named_int(" Actual", a);
148
+ fail();
149
+ }
150
+ }
151
+ function assertEq(int a, int b, string memory err) internal {
152
+ if (a != b) {
153
+ emit log_named_string("Error", err);
154
+ assertEq(a, b);
155
+ }
156
+ }
157
+ function assertEq(uint a, uint b) internal {
158
+ if (a != b) {
159
+ emit log("Error: a == b not satisfied [uint]");
160
+ emit log_named_uint(" Expected", b);
161
+ emit log_named_uint(" Actual", a);
162
+ fail();
163
+ }
164
+ }
165
+ function assertEq(uint a, uint b, string memory err) internal {
166
+ if (a != b) {
167
+ emit log_named_string("Error", err);
168
+ assertEq(a, b);
169
+ }
170
+ }
171
+ function assertEqDecimal(int a, int b, uint decimals) internal {
172
+ if (a != b) {
173
+ emit log("Error: a == b not satisfied [decimal int]");
174
+ emit log_named_decimal_int(" Expected", b, decimals);
175
+ emit log_named_decimal_int(" Actual", a, decimals);
176
+ fail();
177
+ }
178
+ }
179
+ function assertEqDecimal(int a, int b, uint decimals, string memory err) internal {
180
+ if (a != b) {
181
+ emit log_named_string("Error", err);
182
+ assertEqDecimal(a, b, decimals);
183
+ }
184
+ }
185
+ function assertEqDecimal(uint a, uint b, uint decimals) internal {
186
+ if (a != b) {
187
+ emit log("Error: a == b not satisfied [decimal uint]");
188
+ emit log_named_decimal_uint(" Expected", b, decimals);
189
+ emit log_named_decimal_uint(" Actual", a, decimals);
190
+ fail();
191
+ }
192
+ }
193
+ function assertEqDecimal(uint a, uint b, uint decimals, string memory err) internal {
194
+ if (a != b) {
195
+ emit log_named_string("Error", err);
196
+ assertEqDecimal(a, b, decimals);
197
+ }
198
+ }
199
+
200
+ function assertGt(uint a, uint b) internal {
201
+ if (a <= b) {
202
+ emit log("Error: a > b not satisfied [uint]");
203
+ emit log_named_uint(" Value a", a);
204
+ emit log_named_uint(" Value b", b);
205
+ fail();
206
+ }
207
+ }
208
+ function assertGt(uint a, uint b, string memory err) internal {
209
+ if (a <= b) {
210
+ emit log_named_string("Error", err);
211
+ assertGt(a, b);
212
+ }
213
+ }
214
+ function assertGt(int a, int b) internal {
215
+ if (a <= b) {
216
+ emit log("Error: a > b not satisfied [int]");
217
+ emit log_named_int(" Value a", a);
218
+ emit log_named_int(" Value b", b);
219
+ fail();
220
+ }
221
+ }
222
+ function assertGt(int a, int b, string memory err) internal {
223
+ if (a <= b) {
224
+ emit log_named_string("Error", err);
225
+ assertGt(a, b);
226
+ }
227
+ }
228
+ function assertGtDecimal(int a, int b, uint decimals) internal {
229
+ if (a <= b) {
230
+ emit log("Error: a > b not satisfied [decimal int]");
231
+ emit log_named_decimal_int(" Value a", a, decimals);
232
+ emit log_named_decimal_int(" Value b", b, decimals);
233
+ fail();
234
+ }
235
+ }
236
+ function assertGtDecimal(int a, int b, uint decimals, string memory err) internal {
237
+ if (a <= b) {
238
+ emit log_named_string("Error", err);
239
+ assertGtDecimal(a, b, decimals);
240
+ }
241
+ }
242
+ function assertGtDecimal(uint a, uint b, uint decimals) internal {
243
+ if (a <= b) {
244
+ emit log("Error: a > b not satisfied [decimal uint]");
245
+ emit log_named_decimal_uint(" Value a", a, decimals);
246
+ emit log_named_decimal_uint(" Value b", b, decimals);
247
+ fail();
248
+ }
249
+ }
250
+ function assertGtDecimal(uint a, uint b, uint decimals, string memory err) internal {
251
+ if (a <= b) {
252
+ emit log_named_string("Error", err);
253
+ assertGtDecimal(a, b, decimals);
254
+ }
255
+ }
256
+
257
+ function assertGe(uint a, uint b) internal {
258
+ if (a < b) {
259
+ emit log("Error: a >= b not satisfied [uint]");
260
+ emit log_named_uint(" Value a", a);
261
+ emit log_named_uint(" Value b", b);
262
+ fail();
263
+ }
264
+ }
265
+ function assertGe(uint a, uint b, string memory err) internal {
266
+ if (a < b) {
267
+ emit log_named_string("Error", err);
268
+ assertGe(a, b);
269
+ }
270
+ }
271
+ function assertGe(int a, int b) internal {
272
+ if (a < b) {
273
+ emit log("Error: a >= b not satisfied [int]");
274
+ emit log_named_int(" Value a", a);
275
+ emit log_named_int(" Value b", b);
276
+ fail();
277
+ }
278
+ }
279
+ function assertGe(int a, int b, string memory err) internal {
280
+ if (a < b) {
281
+ emit log_named_string("Error", err);
282
+ assertGe(a, b);
283
+ }
284
+ }
285
+ function assertGeDecimal(int a, int b, uint decimals) internal {
286
+ if (a < b) {
287
+ emit log("Error: a >= b not satisfied [decimal int]");
288
+ emit log_named_decimal_int(" Value a", a, decimals);
289
+ emit log_named_decimal_int(" Value b", b, decimals);
290
+ fail();
291
+ }
292
+ }
293
+ function assertGeDecimal(int a, int b, uint decimals, string memory err) internal {
294
+ if (a < b) {
295
+ emit log_named_string("Error", err);
296
+ assertGeDecimal(a, b, decimals);
297
+ }
298
+ }
299
+ function assertGeDecimal(uint a, uint b, uint decimals) internal {
300
+ if (a < b) {
301
+ emit log("Error: a >= b not satisfied [decimal uint]");
302
+ emit log_named_decimal_uint(" Value a", a, decimals);
303
+ emit log_named_decimal_uint(" Value b", b, decimals);
304
+ fail();
305
+ }
306
+ }
307
+ function assertGeDecimal(uint a, uint b, uint decimals, string memory err) internal {
308
+ if (a < b) {
309
+ emit log_named_string("Error", err);
310
+ assertGeDecimal(a, b, decimals);
311
+ }
312
+ }
313
+
314
+ function assertLt(uint a, uint b) internal {
315
+ if (a >= b) {
316
+ emit log("Error: a < b not satisfied [uint]");
317
+ emit log_named_uint(" Value a", a);
318
+ emit log_named_uint(" Value b", b);
319
+ fail();
320
+ }
321
+ }
322
+ function assertLt(uint a, uint b, string memory err) internal {
323
+ if (a >= b) {
324
+ emit log_named_string("Error", err);
325
+ assertLt(a, b);
326
+ }
327
+ }
328
+ function assertLt(int a, int b) internal {
329
+ if (a >= b) {
330
+ emit log("Error: a < b not satisfied [int]");
331
+ emit log_named_int(" Value a", a);
332
+ emit log_named_int(" Value b", b);
333
+ fail();
334
+ }
335
+ }
336
+ function assertLt(int a, int b, string memory err) internal {
337
+ if (a >= b) {
338
+ emit log_named_string("Error", err);
339
+ assertLt(a, b);
340
+ }
341
+ }
342
+ function assertLtDecimal(int a, int b, uint decimals) internal {
343
+ if (a >= b) {
344
+ emit log("Error: a < b not satisfied [decimal int]");
345
+ emit log_named_decimal_int(" Value a", a, decimals);
346
+ emit log_named_decimal_int(" Value b", b, decimals);
347
+ fail();
348
+ }
349
+ }
350
+ function assertLtDecimal(int a, int b, uint decimals, string memory err) internal {
351
+ if (a >= b) {
352
+ emit log_named_string("Error", err);
353
+ assertLtDecimal(a, b, decimals);
354
+ }
355
+ }
356
+ function assertLtDecimal(uint a, uint b, uint decimals) internal {
357
+ if (a >= b) {
358
+ emit log("Error: a < b not satisfied [decimal uint]");
359
+ emit log_named_decimal_uint(" Value a", a, decimals);
360
+ emit log_named_decimal_uint(" Value b", b, decimals);
361
+ fail();
362
+ }
363
+ }
364
+ function assertLtDecimal(uint a, uint b, uint decimals, string memory err) internal {
365
+ if (a >= b) {
366
+ emit log_named_string("Error", err);
367
+ assertLtDecimal(a, b, decimals);
368
+ }
369
+ }
370
+
371
+ function assertLe(uint a, uint b) internal {
372
+ if (a > b) {
373
+ emit log("Error: a <= b not satisfied [uint]");
374
+ emit log_named_uint(" Value a", a);
375
+ emit log_named_uint(" Value b", b);
376
+ fail();
377
+ }
378
+ }
379
+ function assertLe(uint a, uint b, string memory err) internal {
380
+ if (a > b) {
381
+ emit log_named_string("Error", err);
382
+ assertLe(a, b);
383
+ }
384
+ }
385
+ function assertLe(int a, int b) internal {
386
+ if (a > b) {
387
+ emit log("Error: a <= b not satisfied [int]");
388
+ emit log_named_int(" Value a", a);
389
+ emit log_named_int(" Value b", b);
390
+ fail();
391
+ }
392
+ }
393
+ function assertLe(int a, int b, string memory err) internal {
394
+ if (a > b) {
395
+ emit log_named_string("Error", err);
396
+ assertLe(a, b);
397
+ }
398
+ }
399
+ function assertLeDecimal(int a, int b, uint decimals) internal {
400
+ if (a > b) {
401
+ emit log("Error: a <= b not satisfied [decimal int]");
402
+ emit log_named_decimal_int(" Value a", a, decimals);
403
+ emit log_named_decimal_int(" Value b", b, decimals);
404
+ fail();
405
+ }
406
+ }
407
+ function assertLeDecimal(int a, int b, uint decimals, string memory err) internal {
408
+ if (a > b) {
409
+ emit log_named_string("Error", err);
410
+ assertLeDecimal(a, b, decimals);
411
+ }
412
+ }
413
+ function assertLeDecimal(uint a, uint b, uint decimals) internal {
414
+ if (a > b) {
415
+ emit log("Error: a <= b not satisfied [decimal uint]");
416
+ emit log_named_decimal_uint(" Value a", a, decimals);
417
+ emit log_named_decimal_uint(" Value b", b, decimals);
418
+ fail();
419
+ }
420
+ }
421
+ function assertLeDecimal(uint a, uint b, uint decimals, string memory err) internal {
422
+ if (a > b) {
423
+ emit log_named_string("Error", err);
424
+ assertGeDecimal(a, b, decimals);
425
+ }
426
+ }
427
+
428
+ function assertEq(string memory a, string memory b) internal {
429
+ if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
430
+ emit log("Error: a == b not satisfied [string]");
431
+ emit log_named_string(" Expected", b);
432
+ emit log_named_string(" Actual", a);
433
+ fail();
434
+ }
435
+ }
436
+ function assertEq(string memory a, string memory b, string memory err) internal {
437
+ if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
438
+ emit log_named_string("Error", err);
439
+ assertEq(a, b);
440
+ }
441
+ }
442
+
443
+ function checkEq0(bytes memory a, bytes memory b) internal pure returns (bool ok) {
444
+ ok = true;
445
+ if (a.length == b.length) {
446
+ for (uint i = 0; i < a.length; i++) {
447
+ if (a[i] != b[i]) {
448
+ ok = false;
449
+ }
450
+ }
451
+ } else {
452
+ ok = false;
453
+ }
454
+ }
455
+ function assertEq0(bytes memory a, bytes memory b) internal {
456
+ if (!checkEq0(a, b)) {
457
+ emit log("Error: a == b not satisfied [bytes]");
458
+ emit log_named_bytes(" Expected", b);
459
+ emit log_named_bytes(" Actual", a);
460
+ fail();
461
+ }
462
+ }
463
+ function assertEq0(bytes memory a, bytes memory b, string memory err) internal {
464
+ if (!checkEq0(a, b)) {
465
+ emit log_named_string("Error", err);
466
+ assertEq0(a, b);
467
+ }
468
+ }
469
+ }
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.6.0 <0.9.0;
3
+
4
+ import "./console.sol";
5
+ import "./console2.sol";
6
+ import "./StdJson.sol";
7
+
8
+ abstract contract Script {
9
+ bool public IS_SCRIPT = true;
10
+ address constant private VM_ADDRESS =
11
+ address(bytes20(uint160(uint256(keccak256('hevm cheat code')))));
12
+
13
+ Vm public constant vm = Vm(VM_ADDRESS);
14
+
15
+ /// @dev Compute the address a contract will be deployed at for a given deployer address and nonce
16
+ /// @notice adapated from Solmate implementation (https://github.com/transmissions11/solmate/blob/main/src/utils/LibRLP.sol)
17
+ function computeCreateAddress(address deployer, uint256 nonce) internal pure returns (address) {
18
+ // The integer zero is treated as an empty byte string, and as a result it only has a length prefix, 0x80, computed via 0x80 + 0.
19
+ // A one byte integer uses its own value as its length prefix, there is no additional "0x80 + length" prefix that comes before it.
20
+ if (nonce == 0x00) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80))));
21
+ if (nonce <= 0x7f) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))));
22
+
23
+ // Nonces greater than 1 byte all follow a consistent encoding scheme, where each value is preceded by a prefix of 0x80 + length.
24
+ if (nonce <= 2**8 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd7), bytes1(0x94), deployer, bytes1(0x81), uint8(nonce))));
25
+ if (nonce <= 2**16 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))));
26
+ if (nonce <= 2**24 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))));
27
+
28
+ // More details about RLP encoding can be found here: https://eth.wiki/fundamentals/rlp
29
+ // 0xda = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x84 ++ nonce)
30
+ // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
31
+ // 0x84 = 0x80 + 0x04 (0x04 = the bytes length of the nonce, 4 bytes, in hex)
32
+ // We assume nobody can have a nonce large enough to require more than 32 bytes.
33
+ return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce))));
34
+ }
35
+
36
+ function addressFromLast20Bytes(bytes32 bytesValue) internal pure returns (address) {
37
+ return address(uint160(uint256(bytesValue)));
38
+ }
39
+ }
@@ -0,0 +1,118 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.6.0 <0.9.0;
3
+ pragma experimental ABIEncoderV2;
4
+
5
+ import "./Vm.sol";
6
+
7
+ // Helpers for parsing keys into types.
8
+ library stdJson {
9
+
10
+ Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
11
+
12
+ function parseRaw(string memory json, string memory key)
13
+ internal
14
+ returns (bytes memory)
15
+ {
16
+ return vm.parseJson(json, key);
17
+ }
18
+
19
+ function readUint(string memory json, string memory key)
20
+ internal
21
+ returns (uint256)
22
+ {
23
+ return abi.decode(vm.parseJson(json, key), (uint256));
24
+ }
25
+
26
+ function readUintArray(string memory json, string memory key)
27
+ internal
28
+ returns (uint256[] memory)
29
+ {
30
+ return abi.decode(vm.parseJson(json, key), (uint256[]));
31
+ }
32
+
33
+ function readInt(string memory json, string memory key)
34
+ internal
35
+ returns (int256)
36
+ {
37
+ return abi.decode(vm.parseJson(json, key), (int256));
38
+ }
39
+
40
+ function readIntArray(string memory json, string memory key)
41
+ internal
42
+ returns (int256[] memory)
43
+ {
44
+ return abi.decode(vm.parseJson(json, key), (int256[]));
45
+ }
46
+
47
+ function readBytes32(string memory json, string memory key)
48
+ internal
49
+ returns (bytes32)
50
+ {
51
+ return abi.decode(vm.parseJson(json, key), (bytes32));
52
+ }
53
+
54
+ function readBytes32Array(string memory json, string memory key)
55
+ internal
56
+ returns (bytes32[] memory)
57
+ {
58
+ return abi.decode(vm.parseJson(json, key), (bytes32[]));
59
+ }
60
+
61
+ function readString(string memory json, string memory key)
62
+ internal
63
+ returns (string memory)
64
+ {
65
+ return abi.decode(vm.parseJson(json, key), (string));
66
+ }
67
+
68
+ function readStringArray(string memory json, string memory key)
69
+ internal
70
+ returns (string[] memory)
71
+ {
72
+ return abi.decode(vm.parseJson(json, key), (string[]));
73
+ }
74
+
75
+ function readAddress(string memory json, string memory key)
76
+ internal
77
+ returns (address)
78
+ {
79
+ return abi.decode(vm.parseJson(json, key), (address));
80
+ }
81
+
82
+ function readAddressArray(string memory json, string memory key)
83
+ internal
84
+ returns (address[] memory)
85
+ {
86
+ return abi.decode(vm.parseJson(json, key), (address[]));
87
+ }
88
+
89
+ function readBool(string memory json, string memory key)
90
+ internal
91
+ returns (bool)
92
+ {
93
+ return abi.decode(vm.parseJson(json, key), (bool));
94
+ }
95
+
96
+ function readBoolArray(string memory json, string memory key)
97
+ internal
98
+ returns (bool[] memory)
99
+ {
100
+ return abi.decode(vm.parseJson(json, key), (bool[]));
101
+ }
102
+
103
+ function readBytes(string memory json, string memory key)
104
+ internal
105
+ returns (bytes memory)
106
+ {
107
+ return abi.decode(vm.parseJson(json, key), (bytes));
108
+ }
109
+
110
+ function readBytesArray(string memory json, string memory key)
111
+ internal
112
+ returns (bytes[] memory)
113
+ {
114
+ return abi.decode(vm.parseJson(json, key), (bytes[]));
115
+ }
116
+
117
+
118
+ }