This repository was archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathDssAction.t.sol
1310 lines (1089 loc) · 47.3 KB
/
DssAction.t.sol
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// DssAction.sol -- DSS Executive Spell Action Tests
//
// Copyright (C) 2020-2022 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import "ds-test/test.sol";
import "ds-token/token.sol";
import "ds-value/value.sol";
import {ChainLog} from "dss-chain-log/ChainLog.sol";
import {OsmMom} from "osm-mom/OsmMom.sol";
import {MkrAuthority} from "mkr-authority/MkrAuthority.sol";
import {IlkRegistry} from "ilk-registry/IlkRegistry.sol";
import {ClipperMom} from "clipper-mom/ClipperMom.sol";
import {Median} from "median/median.sol";
import {OSM} from 'osm/osm.sol';
import {OsmAbstract,
LerpAbstract} from "dss-interfaces/Interfaces.sol";
import {UNIV2LPOracle} from "univ2-lp-oracle/UNIV2LPOracle.sol";
import {DSProxyFactory,
DSProxy} from "ds-proxy/proxy.sol";
import {DssAutoLine} from "dss-auto-line/DssAutoLine.sol";
import {LerpFactory} from "dss-lerp/LerpFactory.sol";
import {DssDirectDepositAaveDai}
from "dss-direct-deposit/DssDirectDepositAaveDai.sol";
import {AaveMock} from "./fixtures/AaveMock.sol";
import {DirectDepositMom} from "dss-direct-deposit/DirectDepositMom.sol";
import {RwaLiquidationOracle}
from "MIP21-RWA-Example/RwaLiquidationOracle.sol";
import {AuthGemJoin} from "dss-gem-joins/join-auth.sol";
import {RwaOutputConduit} from "MIP21-RWA-Example/RwaConduit.sol";
import {RwaUrn} from "MIP21-RWA-Example/RwaUrn.sol";
import {RwaToken} from "MIP21-RWA-Example/RwaToken.sol";
import {Vat} from "dss/vat.sol";
import {Dog} from "dss/dog.sol";
import {Cat} from "dss/cat.sol";
import {Vow} from "dss/vow.sol";
import {Pot} from "dss/pot.sol";
import {Jug} from "dss/jug.sol";
import {Clipper} from "dss/clip.sol";
import {Flapper} from "dss/flap.sol";
import {Flopper} from "dss/flop.sol";
import {GemJoin,DaiJoin} from "dss/join.sol";
import {End} from "dss/end.sol";
import {Spotter} from "dss/spot.sol";
import {Dai} from "dss/dai.sol";
import {LinearDecrease,
StairstepExponentialDecrease,
ExponentialDecrease} from "dss/abaci.sol";
import "../CollateralOpts.sol";
import {DssTestAction, DssTestNoOfficeHoursAction} from './DssTestAction.sol';
interface Hevm {
function warp(uint256) external;
function store(address,bytes32,bytes32) external;
function load(address,bytes32) external view returns (bytes32);
}
interface PipLike {
function peek() external returns (bytes32, bool);
function read() external returns (bytes32);
}
contract UniPairMock {
address public token0; address public token1;
constructor(address _token0, address _token1) public {
token0 = _token0; token1 = _token1;
}
}
contract ActionTest is DSTest {
Hevm hevm;
Vat vat;
End end;
Vow vow;
Pot pot;
Jug jug;
Dog dog;
Cat cat;
Dai daiToken;
DaiJoin daiJoin;
DSToken gov;
IlkRegistry reg;
Median median;
OsmMom osmMom;
ClipperMom clipperMom;
MkrAuthority govGuard;
DssAutoLine autoLine;
LerpFactory lerpFab;
RwaLiquidationOracle rwaOracle;
ChainLog clog;
Spotter spot;
Flapper flap;
Flopper flop;
DssTestAction action;
struct Ilk {
DSValue pip;
OSM osm;
DSToken gem;
GemJoin gemA;
Clipper clip;
}
mapping (bytes32 => Ilk) ilks;
address constant public LOG = 0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F;
uint256 constant public THOUSAND = 10 ** 3;
uint256 constant public MILLION = 10 ** 6;
uint256 constant public WAD = 10 ** 18;
uint256 constant public RAY = 10 ** 27;
uint256 constant public RAD = 10 ** 45;
uint256 constant START_TIME = 604411200;
string constant doc = "QmcniBv7UQ4gGPQQW2BwbD4ZZHzN3o3tPuNLZCbBchd1zh";
function ray(uint wad) internal pure returns (uint) {
return wad * 10 ** 9;
}
function rad(uint wad) internal pure returns (uint) {
return wad * RAY;
}
function rmul(uint x, uint y) internal pure returns (uint z) {
z = x * y;
require(y == 0 || z / y == x);
z = z / RAY;
}
function rpow(uint256 x, uint256 n, uint256 b) internal pure returns (uint256 z) {
assembly {
switch n case 0 { z := b }
default {
switch x case 0 { z := 0 }
default {
switch mod(n, 2) case 0 { z := b } default { z := x }
let half := div(b, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n,2) } {
let xx := mul(x, x)
if shr(128, x) { revert(0,0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0,0) }
x := div(xxRound, b)
if mod(n,2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0,0) }
z := div(zxRound, b)
}
}
}
}
}
}
function min(uint x, uint y) internal pure returns (uint z) {
(x >= y) ? z = y : z = x;
}
function dai(address urn) internal view returns (uint) {
return vat.dai(urn) / RAY;
}
function gem(bytes32 ilk, address urn) internal view returns (uint) {
return vat.gem(ilk, urn);
}
function ink(bytes32 ilk, address urn) internal view returns (uint) {
(uint ink_, uint art_) = vat.urns(ilk, urn); art_;
return ink_;
}
function art(bytes32 ilk, address urn) internal view returns (uint) {
(uint ink_, uint art_) = vat.urns(ilk, urn); ink_;
return art_;
}
function Art(bytes32 ilk) internal view returns (uint) {
(uint Art_, uint rate_, uint spot_, uint line_, uint dust_) = vat.ilks(ilk);
rate_; spot_; line_; dust_;
return Art_;
}
function balanceOf(bytes32 ilk, address usr) internal view returns (uint) {
return ilks[ilk].gem.balanceOf(usr);
}
function stringToBytes32(string memory source) public pure returns (bytes32 result) {
assembly {
result := mload(add(source, 32))
}
}
/**
* @notice Test that two values are approximately equal within a certain tolerance range
* @param _a First value
* @param _b Second value
* @param _tolerance Maximum tolerated difference, in absolute terms
*/
function assertEqApprox(uint256 _a, uint256 _b, uint256 _tolerance) internal {
uint256 a = _a;
uint256 b = _b;
if (a < b) { // if a < b, switch values so that a is always the biggest amount
uint256 tmp = a;
a = b;
b = tmp;
}
if (a - b > _tolerance) {
emit log_bytes32("Error: Wrong `uint' value");
emit log_named_uint(" Expected", _b);
emit log_named_uint(" Actual", _a);
fail();
}
}
function init_collateral(bytes32 name, address _action) internal returns (Ilk memory) {
DSToken coin = new DSToken("Token");
coin.mint(20 ether);
DSValue pip = new DSValue();
spot.file(name, "pip", address(pip));
spot.file(name, "mat", ray(2 ether));
// initial collateral price of 6
pip.poke(bytes32(6 * WAD));
spot.poke(name);
OSM osm = new OSM(address(pip));
osm.rely(address(clipperMom));
vat.init(name);
GemJoin gemA = new GemJoin(address(vat), name, address(coin));
vat.file(name, "line", rad(1000 ether));
coin.approve(address(gemA));
coin.approve(address(vat));
vat.rely(address(gemA));
Clipper clip = new Clipper(address(vat), address(spot), address(dog), name);
vat.hope(address(clip));
clip.rely(address(end));
clip.rely(address(dog));
dog.rely(address(clip));
dog.file(name, "clip", address(clip));
dog.file(name, "chop", 1 ether);
dog.file("Hole", rad((10 ether) * MILLION));
reg.add(address(gemA));
clip.rely(_action);
gemA.rely(_action);
osm.rely(_action);
ilks[name].pip = pip;
ilks[name].osm = osm;
ilks[name].gem = coin;
ilks[name].gemA = gemA;
ilks[name].clip = clip;
return ilks[name];
}
function init_rwa(
bytes32 ilk,
uint256 line,
uint48 tau,
uint256 duty,
uint256 mat,
address operator
) internal {
uint256 val = rmul(rmul(line / RAY, mat), rpow(duty, 2 * 365 days, RAY));
rwaOracle.init(ilk, val, doc, tau);
(,address pip,,) = rwaOracle.ilks(ilk);
spot.file(ilk, "pip", pip);
vat.init(ilk);
jug.init(ilk);
string memory name = string(abi.encodePacked(ilk));
RwaToken token = new RwaToken(name, name);
AuthGemJoin join = new AuthGemJoin(address(vat), ilk, address(token));
vat.rely(address(join));
vat.rely(address(rwaOracle));
vat.file(ilk, "line", line);
vat.file("Line", vat.Line() + line);
jug.file(ilk, "duty", duty);
spot.file(ilk, "mat", mat);
spot.poke(ilk);
RwaOutputConduit out = new RwaOutputConduit(address(gov), address(daiToken));
RwaUrn urn = new RwaUrn(address(vat), address(jug), address(join), address(daiJoin), address(out));
join.rely(address(urn));
urn.hope(operator);
out.hope(operator);
}
function setUp() public {
hevm = Hevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
hevm.warp(START_TIME);
vat = new Vat();
gov = new DSToken('GOV');
flap = new Flapper(address(vat), address(gov));
flop = new Flopper(address(vat), address(gov));
gov.setOwner(address(flop));
vow = new Vow(address(vat), address(flap), address(flop));
pot = new Pot(address(vat));
vat.rely(address(pot));
pot.file("vow", address(vow));
dog = new Dog(address(vat));
dog.file("vow", address(vow));
vat.rely(address(dog));
vow.rely(address(dog));
cat = new Cat(address(vat));
cat.file("vow", address(vow));
vat.rely(address(cat));
vow.rely(address(cat));
spot = new Spotter(address(vat));
vat.file("Line", rad(1000 ether));
vat.rely(address(spot));
jug = new Jug(address(vat));
vat.rely(address(jug));
daiToken = new Dai(1);
daiJoin = new DaiJoin(address(vat), address(daiToken));
daiToken.rely(address(daiJoin));
daiToken.deny(address(this));
end = new End();
end.file("vat", address(vat));
end.file("dog", address(dog));
end.file("vow", address(vow));
end.file("pot", address(pot));
end.file("spot", address(spot));
end.file("wait", 1 hours);
vat.rely(address(end));
vow.rely(address(end));
spot.rely(address(end));
pot.rely(address(end));
dog.rely(address(end));
flap.rely(address(vow));
flop.rely(address(vow));
reg = new IlkRegistry(address(vat), address(dog), address(cat), address(spot));
osmMom = new OsmMom();
govGuard = new MkrAuthority();
clipperMom = new ClipperMom(address(dog));
autoLine = new DssAutoLine(address(vat));
vat.rely(address(autoLine));
lerpFab = new LerpFactory();
median = new Median();
rwaOracle = new RwaLiquidationOracle(address(vat), address(vow));
hevm.store(
LOG,
keccak256(abi.encode(address(this), uint256(0))), // Grant auth to test contract
bytes32(uint256(1))
);
clog = ChainLog(0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F); // Deployed chain
clog.setAddress("MCD_VAT", address(vat));
clog.setAddress("MCD_DOG", address(dog));
clog.setAddress("MCD_JUG", address(jug));
clog.setAddress("MCD_POT", address(pot));
clog.setAddress("MCD_VOW", address(vow));
clog.setAddress("MCD_SPOT", address(spot));
clog.setAddress("MCD_FLAP", address(flap));
clog.setAddress("MCD_FLOP", address(flop));
clog.setAddress("MCD_END", address(end));
clog.setAddress("MCD_DAI", address(daiToken));
clog.setAddress("MCD_JOIN_DAI", address(daiJoin));
clog.setAddress("ILK_REGISTRY", address(reg));
clog.setAddress("OSM_MOM", address(osmMom));
clog.setAddress("GOV_GUARD", address(govGuard));
clog.setAddress("CLIPPER_MOM", address(clipperMom));
clog.setAddress("MCD_IAM_AUTO_LINE", address(autoLine));
clog.setAddress("LERP_FAB", address(lerpFab));
clog.setAddress("MIP21_LIQUIDATION_ORACLE", address(rwaOracle));
action = new DssTestAction();
init_collateral("gold", address(action));
init_rwa({
ilk: "6s",
line: 20_000_000 * RAD,
tau: 365 days,
duty: 1000000000937303470807876289, // 3% APY
mat: 105 * RAY / 100,
operator: address(123)
});
vat.rely(address(action));
spot.rely(address(action));
dog.rely(address(action));
vow.rely(address(action));
end.rely(address(action));
pot.rely(address(action));
jug.rely(address(action));
flap.rely(address(action));
flop.rely(address(action));
daiJoin.rely(address(action));
median.rely(address(action));
clog.rely(address(action));
autoLine.rely(address(action));
lerpFab.rely(address(action));
rwaOracle.rely(address(action));
clipperMom.setOwner(address(action));
osmMom.setOwner(address(action));
govGuard.setRoot(address(action));
}
// /******************************/
// /*** OfficeHours Management ***/
// /******************************/
function test_canCast() public {
assertTrue(action.canCast_test(1616169600, true)); // Friday 2021/03/19, 4:00:00 PM GMT
assertTrue(action.canCast_test(1616169600, false)); // Friday 2021/03/19, 4:00:00 PM GMT
assertTrue(action.canCast_test(1616256000, false)); // Saturday 2021/03/20, 4:00:00 PM GMT
}
function testFail_canCast() public {
assertTrue(action.canCast_test(1616256000, true)); // Saturday 2021/03/20, 4:00:00 PM GMT
}
function test_nextCastTime() public {
assertEq(action.nextCastTime_test(1616169600, 1616169600, true), 1616169600);
assertEq(action.nextCastTime_test(1616169600, 1616169600, false), 1616169600);
assertEq(action.nextCastTime_test(1616256000, 1616256000, true), 1616421600);
assertEq(action.nextCastTime_test(1616256000, 1616256000, false), 1616256000);
}
function testFail_nextCastTime_eta_zero() public view {
action.nextCastTime_test(0, 1616256000, false);
}
function testFail_nextCastTime_ts_zero() public view {
action.nextCastTime_test(1616256000, 0, false);
}
// /**********************/
// /*** Authorizations ***/
// /**********************/
function test_authorize() public {
assertEq(vat.wards(address(1)), 0);
action.authorize_test(address(vat), address(1));
assertEq(vat.wards(address(1)), 1);
}
function test_deauthorize() public {
assertEq(vat.wards(address(1)), 0);
action.authorize_test(address(vat), address(1));
assertEq(vat.wards(address(1)), 1);
action.deauthorize_test(address(vat), address(1));
assertEq(vat.wards(address(1)), 0);
}
function test_setAuthority() public {
assertEq(clipperMom.authority(), address(0));
action.setAuthority_test(address(clipperMom), address(1));
assertEq(clipperMom.authority(), address(1));
}
function test_disable() public {
AaveMock aave = new AaveMock();
DssDirectDepositAaveDai d3m = new DssDirectDepositAaveDai(address(clog), "tungsten", address(aave), address(0));
d3m.rely(address(action));
action.setD3MTargetInterestRate_test(address(d3m), 500); // set to 5%
assertEq(d3m.bar(), 5 * RAY / 100);
DirectDepositMom directDepositMom = new DirectDepositMom();
directDepositMom.setAuthority(address(govGuard));
assertEq(directDepositMom.authority(), address(govGuard));
d3m.rely(address(directDepositMom));
assertEq(d3m.wards(address(directDepositMom)), 1);
action.disable_test(address(directDepositMom), address(d3m));
assertEq(d3m.bar(), 0);
}
function test_delegateVat() public {
assertEq(vat.can(address(action), address(1)), 0);
action.delegateVat_test(address(1));
assertEq(vat.can(address(action), address(1)), 1);
}
function test_undelegateVat() public {
assertEq(vat.can(address(action), address(1)), 0);
action.delegateVat_test(address(1));
assertEq(vat.can(address(action), address(1)), 1);
action.undelegateVat_test(address(1));
assertEq(vat.can(address(action), address(1)), 0);
}
/****************************/
/*** Changelog Management ***/
/****************************/
function test_setAddress() public {
bytes32 ilk = "silver";
action.setChangelogAddress_test(ilk, address(this));
assertEq(clog.getAddress(ilk), address(this));
}
function test_setVersion() public {
string memory version = "9001.0.0";
action.setChangelogVersion_test(version);
assertEq(clog.version(), version);
}
function test_setIPFS() public {
string memory ipfs = "QmefQMseb3AiTapiAKKexdKHig8wroKuZbmLtPLv4u2YwW";
action.setChangelogIPFS_test(ipfs);
assertEq(clog.ipfs(), ipfs);
}
function test_setSHA256() public {
string memory SHA256 = "e42dc9d043a57705f3f097099e6b2de4230bca9a020c797508da079f9079e35b";
action.setChangelogSHA256_test(SHA256);
assertEq(clog.sha256sum(), SHA256);
}
/**************************/
/*** Accumulating Rates ***/
/**************************/
function test_accumulateDSR() public {
uint256 beforeChi = pot.chi();
action.setDSR_test(1000000001243680656318820312); // 4%
hevm.warp(START_TIME + 1 days);
action.accumulateDSR_test();
uint256 afterChi = pot.chi();
assertTrue(afterChi - beforeChi > 0);
}
function test_accumulateCollateralStabilityFees() public {
(, uint256 beforeRate,,,) = vat.ilks("gold");
action.setDSR_test(1000000001243680656318820312); // 4%
hevm.warp(START_TIME + 1 days);
action.accumulateCollateralStabilityFees_test("gold");
(, uint256 afterRate,,,) = vat.ilks("gold");
assertTrue(afterRate - beforeRate > 0);
}
/*********************/
/*** Price Updates ***/
/*********************/
function test_updateCollateralPrice() public {
uint256 _spot;
(,, _spot,,) = vat.ilks("gold");
assertEq(_spot, ray(3 ether));
ilks["gold"].pip.poke(bytes32(10 * WAD));
action.updateCollateralPrice_test("gold");
(,, _spot,,) = vat.ilks("gold");
assertEq(_spot, ray(5 ether)); // $5 at 200%
}
/****************************/
/*** System Configuration ***/
/****************************/
function test_setContract() public {
action.setContract_test(address(jug), "vow", address(1));
assertEq(jug.vow(), address(1));
}
/******************************/
/*** System Risk Parameters ***/
/******************************/
function test_setGlobalDebtCeiling() public {
action.setGlobalDebtCeiling_test(100 * MILLION); // 100,000,000 Dai
assertEq(vat.Line(), 100 * MILLION * RAD); // Fixes precision
}
function test_increaseGlobalDebtCeiling() public {
action.setGlobalDebtCeiling_test(100 * MILLION); // setup
action.increaseGlobalDebtCeiling_test(100 * MILLION); // 100,000,000 Dai
assertEq(vat.Line(), 200 * MILLION * RAD); // Fixes precision
}
function test_decreaseGlobalDebtCeiling() public {
action.setGlobalDebtCeiling_test(300 * MILLION); // setup
action.decreaseGlobalDebtCeiling_test(100 * MILLION); // 100,000,000 Dai
assertEq(vat.Line(), 200 * MILLION * RAD); // Fixes precision
}
function testFail_decreaseGlobalDebtCeiling() public {
action.setGlobalDebtCeiling_test(100 * MILLION); // setup
action.decreaseGlobalDebtCeiling_test(101 * MILLION); // fail
}
function test_setDSR() public {
uint256 rate = 1000000001243680656318820312;
action.setDSR_test(rate);
assertEq(pot.dsr(), rate);
}
function test_setSuruplusAuctionAmount() public {
action.setSurplusAuctionAmount_test(100 * THOUSAND);
assertEq(vow.bump(), 100 * THOUSAND * RAD);
}
function test_setSurplusBuffer() public {
action.setSurplusBuffer_test(1 * MILLION);
assertEq(vow.hump(), 1 * MILLION * RAD);
}
function test_setMinSurplusAuctionBidIncrease() public {
action.setMinSurplusAuctionBidIncrease_test(525); // 5.25%
assertEq(flap.beg(), 1 ether + 5.25 ether / 100); // (1 + pct) * WAD
}
function test_setSurplusAuctionBidDuration() public {
action.setSurplusAuctionBidDuration_test(12 hours);
assertEq(uint256(flap.ttl()), 12 hours);
}
function test_setSurplusAuctionDuration() public {
action.setSurplusAuctionDuration_test(12 hours);
assertEq(uint256(flap.tau()), 12 hours);
}
function test_setDebtAuctionDelay() public {
action.setDebtAuctionDelay_test(12 hours);
assertEq(vow.wait(), 12 hours);
}
function test_setDebtAuctionDAIAmount() public {
action.setDebtAuctionDAIAmount_test(100 * THOUSAND);
assertEq(vow.sump(), 100 * THOUSAND * RAD);
}
function test_setDebtAuctionMKRAmount() public {
action.setDebtAuctionMKRAmount_test(100);
assertEq(vow.dump(), 100 * WAD);
}
function test_setMinDebtAuctionBidIncrease() public {
action.setMinDebtAuctionBidIncrease_test(525); // 5.25%
assertEq(flop.beg(), 1 ether + 5.25 ether / 100); // (1 + pct) * WAD
}
function testFail_setMinDebtAuctionBidIncreaseTooHigh() public {
action.setMinDebtAuctionBidIncrease_test(10000); // Fail on 100%
}
function test_setDebtAuctionBidDuration() public {
action.setDebtAuctionBidDuration_test(12 hours);
assertEq(uint256(flop.ttl()), 12 hours);
}
function testFail_setDebtAuctionBidDurationMax() public {
action.setDebtAuctionBidDuration_test(type(uint48).max); // Fail on max
}
function test_setDebtAuctionDuration() public {
action.setDebtAuctionDuration_test(12 hours);
assertEq(uint256(flop.tau()), 12 hours);
}
function testFail_setDebtAuctionDurationMax() public {
action.setDebtAuctionDuration_test(type(uint48).max); // Fail on max
}
function test_setDebtAuctionMKRIncreaseRate() public {
action.setDebtAuctionMKRIncreaseRate_test(525);
assertEq(flop.pad(), 105.25 ether / 100); // WAD pct
}
function testFail_setDebtAuctionMKRIncreaseRateTooHigh() public {
action.setDebtAuctionMKRIncreaseRate_test(10000); // Fail on 100%
}
function test_setMaxTotalDAILiquidationAmount() public {
action.setMaxTotalDAILiquidationAmount_test(50 * MILLION);
assertEq(dog.Hole(), 50 * MILLION * RAD); // WAD pct
}
function test_setEmergencyShutdownProcessingTime() public {
action.setEmergencyShutdownProcessingTime_test(12 hours);
assertEq(end.wait(), 12 hours);
}
function test_setGlobalStabilityFee() public {
uint256 rate = 1000000001243680656318820312;
action.setGlobalStabilityFee_test(rate);
assertEq(jug.base(), rate);
}
function test_setDAIReferenceValue() public {
action.setDAIReferenceValue_test(1005); // $1.005
assertEq(spot.par(), ray(1.005 ether));
}
/*****************************/
/*** Collateral Management ***/
/*****************************/
function test_setIlkDebtCeiling() public {
action.setIlkDebtCeiling_test("gold", 100 * MILLION);
(,,, uint256 line,) = vat.ilks("gold");
assertEq(line, 100 * MILLION * RAD);
}
function test_increaseIlkDebtCeiling() public {
action.setGlobalDebtCeiling_test(100 * MILLION);
action.setIlkDebtCeiling_test("gold", 100 * MILLION); // Setup
action.increaseIlkDebtCeiling_test("gold", 100 * MILLION);
(,,, uint256 line,) = vat.ilks("gold");
assertEq(line, 200 * MILLION * RAD);
assertEq(vat.Line(), 200 * MILLION * RAD); // also increased
}
function test_decreaseIlkDebtCeiling() public {
action.setGlobalDebtCeiling_test(300 * MILLION);
action.setIlkDebtCeiling_test("gold", 300 * MILLION); // Setup
action.decreaseIlkDebtCeiling_test("gold", 100 * MILLION);
(,,, uint256 line,) = vat.ilks("gold");
assertEq(line, 200 * MILLION * RAD);
assertEq(vat.Line(), 200 * MILLION * RAD); // also decreased
}
function testFail_decreaseIlkDebtCeiling() public {
action.setIlkDebtCeiling_test("gold", 100 * MILLION); // Setup
action.decreaseIlkDebtCeiling_test("gold", 101 * MILLION); // Fail
}
function test_setRWAIlkDebtCeiling() public {
(,address pip,,) = rwaOracle.ilks("6s");
uint256 price = uint256(PipLike(pip).read());
assertEqApprox(price, 22_278_900 * WAD, WAD); // 20MM * 1.03^2 * 1.05
action.setRWAIlkDebtCeiling_test("6s", 50 * MILLION, 55 * MILLION); // Increase
(,,, uint256 line,) = vat.ilks("6s");
assertEq(line, 50 * MILLION * RAD);
price = uint256(PipLike(pip).read());
assertEq(price, 55 * MILLION * WAD);
action.setRWAIlkDebtCeiling_test("6s", 40 * MILLION, 55 * MILLION); // Decrease
(,,, line,) = vat.ilks("6s");
assertEq(line, 40 * MILLION * RAD);
price = uint256(PipLike(pip).read());
assertEq(price, 55 * MILLION * WAD);
}
function testFail_setRWAIlkDebtCeiling() public {
action.setRWAIlkDebtCeiling_test("6s", 50 * MILLION, 20 * MILLION); // Fail
}
function test_setIlkAutoLineParameters() public {
action.setIlkAutoLineParameters_test("gold", 150 * MILLION, 5 * MILLION, 10000); // Setup
(,,, uint256 line,) = vat.ilks("gold");
assertEq(line, 1000 * RAD); // does not change line
autoLine.exec("gold");
(,,, line,) = vat.ilks("gold");
assertEq(line, 5 * MILLION * RAD); // Change to match the gap
}
function test_setIlkAutoLineDebtCeiling() public {
action.setIlkAutoLineParameters_test("gold", 1, 5 * MILLION, 10000); // gap and ttl must be configured already
action.setIlkAutoLineDebtCeiling_test("gold", 150 * MILLION); // Setup
(,,, uint256 line,) = vat.ilks("gold");
assertEq(line, 1000 * RAD); // does not change line
autoLine.exec("gold");
(,,, line,) = vat.ilks("gold");
assertEq(line, 5 * MILLION * RAD); // Change to match the gap
}
function test_setRemoveIlkFromAutoLine() public {
action.setIlkAutoLineParameters_test("gold", 100 * MILLION, 5 * MILLION, 10000); // gap and ttl must be configured already
action.removeIlkFromAutoLine_test("gold");
assertEq(autoLine.exec("gold"), 1000 * RAD);
}
function test_setIlkMinVaultAmountLt() public {
action.setIlkMaxLiquidationAmount_test("gold", 100);
action.setIlkMinVaultAmount_test("gold", 1);
(,,,, uint256 dust) = vat.ilks("gold");
assertEq(dust, 1 * RAD);
}
function test_setIlkMinVaultAmountEq() public {
action.setIlkMaxLiquidationAmount_test("gold", 100);
action.setIlkMinVaultAmount_test("gold", 100);
(,,,, uint256 dust) = vat.ilks("gold");
assertEq(dust, 100 * RAD);
action.setIlkMaxLiquidationAmount_test("gold", 0);
action.setIlkMinVaultAmount_test("gold", 0);
(,,,, dust) = vat.ilks("gold");
assertEq(dust, 0);
}
function testFail_setIlkMinVaultAmountGt() public {
action.setIlkMaxLiquidationAmount_test("gold", 100);
action.setIlkMinVaultAmount_test("gold", 101); // Fail here
}
function test_setIlkLiquidationPenalty() public {
action.setIlkLiquidationPenalty_test("gold", 1325); // 13.25%
(, uint256 chop,,) = dog.ilks("gold");
assertEq(chop, 113.25 ether / 100); // WAD pct 113.25%
}
function test_setIlkMaxLiquidationAmount() public {
action.setIlkMaxLiquidationAmount_test("gold", 50 * THOUSAND);
(,, uint256 hole,) = dog.ilks("gold");
assertEq(hole, 50 * THOUSAND * RAD);
}
function test_setIlkLiquidationRatio() public {
action.setIlkLiquidationRatio_test("gold", 15000); // 150% in bp
(, uint256 mat) = spot.ilks("gold");
assertEq(mat, ray(150 ether / 100)); // RAY pct
}
function test_setStartingPriceMultiplicativeFactor() public {
action.setStartingPriceMultiplicativeFactor_test("gold", 15000); // 150%
assertEq(ilks["gold"].clip.buf(), 150 * RAY / 100); // RAY pct
}
function test_setAuctionTimeBeforeReset() public {
action.setAuctionTimeBeforeReset_test("gold", 12 hours);
assertEq(ilks["gold"].clip.tail(), 12 hours);
}
function test_setAuctionPermittedDrop() public {
action.setAuctionPermittedDrop_test("gold", 8000);
assertEq(ilks["gold"].clip.cusp(), 80 * RAY / 100);
}
function test_setKeeperIncentivePercent() public {
action.setKeeperIncentivePercent_test("gold", 10); // 0.1 %
assertEq(ilks["gold"].clip.chip(), 10 * WAD / 10000);
}
function test_setKeeperIncentiveFlatRate() public {
action.setKeeperIncentiveFlatRate_test("gold", 1000); // 1000 Dai
assertEq(ilks["gold"].clip.tip(), 1000 * RAD);
}
function test_setLiquidationBreakerPriceTolerance() public {
action.setLiquidationBreakerPriceTolerance_test(address(ilks["gold"].clip), 6000);
assertEq(clipperMom.tolerance(address(ilks["gold"].clip)), 600000000000000000000000000);
}
function test_setIlkStabilityFee() public {
hevm.warp(START_TIME + 1 days);
action.setIlkStabilityFee_test("gold", 1000000001243680656318820312);
(uint256 duty, uint256 rho) = jug.ilks("gold");
assertEq(duty, 1000000001243680656318820312);
assertEq(rho, START_TIME + 1 days);
}
/**************************/
/*** Pricing Management ***/
/**************************/
function test_setLinearDecrease() public {
LinearDecrease calc = new LinearDecrease();
calc.rely(address(action));
action.setLinearDecrease_test(address(calc), 14 hours);
assertEq(calc.tau(), 14 hours);
}
function test_setStairstepExponentialDecrease() public {
StairstepExponentialDecrease calc = new StairstepExponentialDecrease();
calc.rely(address(action));
action.setStairstepExponentialDecrease_test(address(calc), 90, 9999); // 90 seconds per step, 99.99% multiplicative
assertEq(calc.step(), 90);
assertEq(calc.cut(), 999900000000000000000000000);
}
function test_setExponentialDecrease() public {
ExponentialDecrease calc = new ExponentialDecrease();
calc.rely(address(action));
action.setExponentialDecrease_test(address(calc), 9999); // 99.99% multiplicative
assertEq(calc.cut(), 999900000000000000000000000);
}
/*************************/
/*** Oracle Management ***/
/*************************/
function test_whitelistOracle_OSM() public {
address tokenPip = address(new OSM(address(median)));
assertEq(median.bud(tokenPip), 0);
action.whitelistOracleMedians_test(tokenPip);
assertEq(median.bud(tokenPip), 1);
}
function test_whitelistOracle_LP() public {
// Mock an LP oracle and whitelist it
address token0 = address(new DSToken("nil"));
address token1 = address(new DSToken("one"));
Median med0 = new Median();
Median med1 = new Median();
address lperc = address(new UniPairMock(token0, token1));
med0.rely(address(action));
med1.rely(address(action));
UNIV2LPOracle lorc = new UNIV2LPOracle(address(lperc), "NILONE", address(med0), address(med1));
assertEq(med0.bud(address(lorc)), 0);
assertEq(med1.bud(address(lorc)), 0);
action.whitelistOracleMedians_test(address(lorc));
assertEq(med0.bud(address(lorc)), 1);
assertEq(med1.bud(address(lorc)), 1);
}
function test_whitelistOracleWithDSValue_LP() public {
// Should not fail for LP tokens if one or more oracles are DSValue
address token0 = address(new DSToken("nil"));
address token1 = address(new DSToken("one"));
DSValue med0 = new DSValue();
DSValue med1 = new DSValue();
address lperc = address(new UniPairMock(token0, token1));
med0.poke(bytes32(uint256(100)));
med1.poke(bytes32(uint256(100)));
UNIV2LPOracle lorc = new UNIV2LPOracle(address(lperc), "NILONE", address(med0), address(med1));
action.whitelistOracleMedians_test(address(lorc));
}
function test_addReaderToWhitelistCall() public {
address reader = address(1);
assertEq(median.bud(address(1)), 0);
action.addReaderToWhitelistCall_test(address(median), reader);
assertEq(median.bud(address(1)), 1);
}
function test_removeReaderFromWhitelistCall() public {
address reader = address(1);
assertEq(median.bud(address(1)), 0);
action.addReaderToWhitelistCall_test(address(median), reader);
assertEq(median.bud(address(1)), 1);
action.removeReaderFromWhitelistCall_test(address(median), reader);
assertEq(median.bud(address(1)), 0);
}
function test_setMedianWritersQuorum() public {
action.setMedianWritersQuorum_test(address(median), 11);
assertEq(median.bar(), 11);
}
function test_addReaderToWhitelist() public {
OSM osm = ilks["gold"].osm;