-
Notifications
You must be signed in to change notification settings - Fork 91
/
UbiquityPoolFacet.t.sol
881 lines (732 loc) · 28.2 KB
/
UbiquityPoolFacet.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "forge-std/console.sol";
import {DiamondTestSetup} from "../DiamondTestSetup.sol";
import {IDollarAmoMinter} from "../../../src/dollar/interfaces/IDollarAmoMinter.sol";
import {IMetaPool} from "../../../src/dollar/interfaces/IMetaPool.sol";
import {LibUbiquityPool} from "../../../src/dollar/libraries/LibUbiquityPool.sol";
import {MockChainLinkFeed} from "../../../src/dollar/mocks/MockChainLinkFeed.sol";
import {MockERC20} from "../../../src/dollar/mocks/MockERC20.sol";
import {MockMetaPool} from "../../../src/dollar/mocks/MockMetaPool.sol";
contract MockDollarAmoMinter is IDollarAmoMinter {
function collateralDollarBalance() external pure returns (uint256) {
return 0;
}
function collateralIndex() external pure returns (uint256) {
return 0;
}
}
contract UbiquityPoolFacetTest is DiamondTestSetup {
MockDollarAmoMinter dollarAmoMinter;
MockERC20 collateralToken;
MockChainLinkFeed collateralTokenPriceFeed;
MockMetaPool curveDollarMetaPool;
MockERC20 curveTriPoolLpToken;
address user = address(1);
// Events
event AmoMinterAdded(address amoMinterAddress);
event AmoMinterRemoved(address amoMinterAddress);
event CollateralPriceFeedSet(
uint256 collateralIndex,
address priceFeedAddress,
uint256 stalenessThreshold
);
event CollateralPriceSet(uint256 collateralIndex, uint256 newPrice);
event CollateralToggled(uint256 collateralIndex, bool newState);
event FeesSet(
uint256 collateralIndex,
uint256 newMintFee,
uint256 newRedeemFee
);
event MintRedeemBorrowToggled(uint256 collateralIndex, uint8 toggleIndex);
event PoolCeilingSet(uint256 collateralIndex, uint256 newCeiling);
event PriceThresholdsSet(
uint256 newMintPriceThreshold,
uint256 newRedeemPriceThreshold
);
event RedemptionDelayBlocksSet(uint256 redemptionDelayBlocks);
function setUp() public override {
super.setUp();
vm.startPrank(admin);
// init collateral token
collateralToken = new MockERC20("COLLATERAL", "CLT", 18);
// init collateral price feed
collateralTokenPriceFeed = new MockChainLinkFeed();
// init Curve 3CRV-LP token
curveTriPoolLpToken = new MockERC20("3CRV", "3CRV", 18);
// init Curve Dollar-3CRV LP metapool
curveDollarMetaPool = new MockMetaPool(
address(dollarToken),
address(curveTriPoolLpToken)
);
// add collateral token to the pool
uint256 poolCeiling = 50_000e18; // max 50_000 of collateral tokens is allowed
ubiquityPoolFacet.addCollateralToken(
address(collateralToken),
address(collateralTokenPriceFeed),
poolCeiling
);
// set collateral price feed mock params
collateralTokenPriceFeed.updateMockParams(
1, // round id
100_000_000, // answer, 100_000_000 = $1.00 (chainlink 8 decimals answer is converted to 6 decimals pool price)
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
);
// set price feed for collateral token
ubiquityPoolFacet.setCollateralChainLinkPriceFeed(
address(collateralToken), // collateral token address
address(collateralTokenPriceFeed), // price feed address
1 days // price feed staleness threshold in seconds
);
// enable collateral at index 0
ubiquityPoolFacet.toggleCollateral(0);
// set mint and redeem fees
ubiquityPoolFacet.setFees(
0, // collateral index
10000, // 1% mint fee
20000 // 2% redeem fee
);
// set redemption delay to 2 blocks
ubiquityPoolFacet.setRedemptionDelayBlocks(2);
// set mint price threshold to $1.01 and redeem price to $0.99
ubiquityPoolFacet.setPriceThresholds(1010000, 990000);
// init AMO minter
dollarAmoMinter = new MockDollarAmoMinter();
// add AMO minter
ubiquityPoolFacet.addAmoMinter(address(dollarAmoMinter));
// stop being admin
vm.stopPrank();
// set metapool for TWAP oracle
vm.prank(owner);
twapOracleDollar3PoolFacet.setPool(
address(curveDollarMetaPool),
address(curveTriPoolLpToken)
);
// mint 100 collateral tokens to the user
collateralToken.mint(address(user), 100e18);
// user approves the pool to transfer collateral
vm.prank(user);
collateralToken.approve(address(ubiquityPoolFacet), 100e18);
}
//=====================
// Modifiers
//=====================
function testCollateralEnabled_ShouldRevert_IfCollateralIsDisabled()
public
{
// admin disables collateral
vm.prank(admin);
ubiquityPoolFacet.toggleCollateral(0);
// user tries to mint Dollars
vm.prank(user);
vm.expectRevert("Collateral disabled");
ubiquityPoolFacet.mintDollar(0, 1, 1, 1);
}
function testOnlyAmoMinter_ShouldRevert_IfCalledNoByAmoMinter() public {
vm.prank(user);
vm.expectRevert("Not an AMO Minter");
ubiquityPoolFacet.amoMinterBorrow(1);
}
//=====================
// Views
//=====================
function testAllCollaterals_ShouldReturnAllCollateralTokenAddresses()
public
{
address[] memory collateralAddresses = ubiquityPoolFacet
.allCollaterals();
assertEq(collateralAddresses.length, 1);
assertEq(collateralAddresses[0], address(collateralToken));
}
function testCollateralInformation_ShouldRevert_IfCollateralIsDisabled()
public
{
// admin disables collateral
vm.prank(admin);
ubiquityPoolFacet.toggleCollateral(0);
vm.expectRevert("Invalid collateral");
ubiquityPoolFacet.collateralInformation(address(collateralToken));
}
function testCollateralInformation_ShouldReturnCollateralInformation()
public
{
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.index, 0);
assertEq(info.symbol, "CLT");
assertEq(info.collateralAddress, address(collateralToken));
assertEq(
info.collateralPriceFeedAddress,
address(collateralTokenPriceFeed)
);
assertEq(info.collateralPriceFeedStalenessThreshold, 1 days);
assertEq(info.isEnabled, true);
assertEq(info.missingDecimals, 0);
assertEq(info.price, 1_000_000);
assertEq(info.poolCeiling, 50_000e18);
assertEq(info.isMintPaused, false);
assertEq(info.isRedeemPaused, false);
assertEq(info.isBorrowPaused, false);
assertEq(info.mintingFee, 10000);
assertEq(info.redemptionFee, 20000);
}
function testCollateralUsdBalance_ShouldReturnTotalAmountOfCollateralInUsd()
public
{
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
990000 // redeem threshold
);
// user sends 100 collateral tokens and gets 99 Dollars
vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
uint256 balanceTally = ubiquityPoolFacet.collateralUsdBalance();
assertEq(balanceTally, 100e18);
}
function testFreeCollateralBalance_ShouldReturnCollateralAmountAvailableForBorrowingByAmoMinters()
public
{
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);
// user sends 100 collateral tokens and gets 99 Dollars (-1% mint fee)
vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
// user redeems 99 Dollars for 97.02 (accounts for 2% redemption fee) collateral tokens
vm.prank(user);
ubiquityPoolFacet.redeemDollar(
0, // collateral index
99e18, // Dollar amount
90e18 // min collateral out
);
uint256 freeCollateralAmount = ubiquityPoolFacet.freeCollateralBalance(
0
);
assertEq(freeCollateralAmount, 2.98e18);
}
function testGetDollarInCollateral_ShouldReturnAmountOfDollarsWhichShouldBeMintedForInputCollateral()
public
{
uint256 amount = ubiquityPoolFacet.getDollarInCollateral(0, 100e18);
assertEq(amount, 100e18);
}
function testGetDollarPriceUsd_ShouldReturnDollarPriceInUsd() public {
uint256 dollarPriceUsd = ubiquityPoolFacet.getDollarPriceUsd();
assertEq(dollarPriceUsd, 1_000_000);
}
//====================
// Public functions
//====================
function testMintDollar_ShouldRevert_IfMintingIsPaused() public {
// admin pauses minting
vm.prank(admin);
ubiquityPoolFacet.toggleMintRedeemBorrow(0, 0);
vm.prank(user);
vm.expectRevert("Minting is paused");
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
90e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
}
function testMintDollar_ShouldRevert_IfDollarPriceUsdIsTooLow() public {
vm.prank(user);
vm.expectRevert("Dollar price too low");
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
90e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
}
function testMintDollar_ShouldRevert_OnDollarAmountSlippage() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
990000 // redeem threshold
);
vm.prank(user);
vm.expectRevert("Dollar slippage");
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
100e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
}
function testMintDollar_ShouldRevert_OnCollateralAmountSlippage() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
990000 // redeem threshold
);
vm.prank(user);
vm.expectRevert("Collateral slippage");
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
90e18, // min amount of Dollars to mint
10e18 // max collateral to send
);
}
function testMintDollar_ShouldRevert_OnReachingPoolCeiling() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
990000 // redeem threshold
);
vm.prank(user);
vm.expectRevert("Pool ceiling");
ubiquityPoolFacet.mintDollar(
0, // collateral index
60_000e18, // Dollar amount
59_000e18, // min amount of Dollars to mint
60_000e18 // max collateral to send
);
}
function testMintDollar_ShouldMintDollars() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
990000 // redeem threshold
);
// balances before
assertEq(collateralToken.balanceOf(address(ubiquityPoolFacet)), 0);
assertEq(dollarToken.balanceOf(user), 0);
vm.prank(user);
(uint256 totalDollarMint, uint256 collateralNeeded) = ubiquityPoolFacet
.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
assertEq(totalDollarMint, 99e18);
assertEq(collateralNeeded, 100e18);
// balances after
assertEq(collateralToken.balanceOf(address(ubiquityPoolFacet)), 100e18);
assertEq(dollarToken.balanceOf(user), 99e18);
}
function testRedeemDollar_ShouldRevert_IfRedeemingIsPaused() public {
// admin pauses redeeming
vm.prank(admin);
ubiquityPoolFacet.toggleMintRedeemBorrow(0, 1);
vm.prank(user);
vm.expectRevert("Redeeming is paused");
ubiquityPoolFacet.redeemDollar(
0, // collateral index
100e18, // Dollar amount
90e18 // min collateral out
);
}
function testRedeemDollar_ShouldRevert_IfDollarPriceUsdIsTooHigh() public {
vm.prank(user);
vm.expectRevert("Dollar price too high");
ubiquityPoolFacet.redeemDollar(
0, // collateral index
100e18, // Dollar amount
90e18 // min collateral out
);
}
function testRedeemDollar_ShouldRevert_OnInsufficientPoolCollateral()
public
{
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);
vm.prank(user);
vm.expectRevert("Insufficient pool collateral");
ubiquityPoolFacet.redeemDollar(
0, // collateral index
100e18, // Dollar amount
90e18 // min collateral out
);
}
function testRedeemDollar_ShouldRevert_OnCollateralSlippage() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);
// user sends 100 collateral tokens and gets 99 Dollars (-1% mint fee)
vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
vm.prank(user);
vm.expectRevert("Collateral slippage");
ubiquityPoolFacet.redeemDollar(
0, // collateral index
100e18, // Dollar amount
100e18 // min collateral out
);
}
function testRedeemDollar_ShouldRedeemCollateral() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);
// user sends 100 collateral tokens and gets 99 Dollars (-1% mint fee)
vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
// balances before
assertEq(dollarToken.balanceOf(user), 99e18);
vm.prank(user);
ubiquityPoolFacet.redeemDollar(
0, // collateral index
99e18, // Dollar amount
90e18 // min collateral out
);
// balances after
assertEq(dollarToken.balanceOf(user), 0);
}
function testCollectRedemption_ShouldRevert_IfRedeemingIsPaused() public {
// admin pauses redeeming
vm.prank(admin);
ubiquityPoolFacet.toggleMintRedeemBorrow(0, 1);
vm.prank(user);
vm.expectRevert("Redeeming is paused");
ubiquityPoolFacet.collectRedemption(0);
}
function testCollectRedemption_ShouldRevert_IfNotEnoughBlocksHaveBeenMined()
public
{
vm.prank(user);
vm.expectRevert("Too soon to collect redemption");
ubiquityPoolFacet.collectRedemption(0);
}
function testCollectRedemption_ShouldCollectRedemption() public {
vm.prank(admin);
ubiquityPoolFacet.setPriceThresholds(
1000000, // mint threshold
1000000 // redeem threshold
);
// user sends 100 collateral tokens and gets 99 Dollars (-1% mint fee)
vm.prank(user);
ubiquityPoolFacet.mintDollar(
0, // collateral index
100e18, // Dollar amount
99e18, // min amount of Dollars to mint
100e18 // max collateral to send
);
// user redeems 99 Dollars for collateral
vm.prank(user);
ubiquityPoolFacet.redeemDollar(
0, // collateral index
99e18, // Dollar amount
90e18 // min collateral out
);
// wait 3 blocks for collecting redemption to become active
vm.roll(3);
// balances before
assertEq(collateralToken.balanceOf(address(ubiquityPoolFacet)), 100e18);
assertEq(collateralToken.balanceOf(user), 0);
vm.prank(user);
uint256 collateralAmount = ubiquityPoolFacet.collectRedemption(0);
assertEq(collateralAmount, 97.02e18); // $99 - 2% redemption fee
// balances after
assertEq(
collateralToken.balanceOf(address(ubiquityPoolFacet)),
2.98e18
);
assertEq(collateralToken.balanceOf(user), 97.02e18);
}
function testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsInvalid()
public
{
// set invalid answer from chainlink
collateralTokenPriceFeed.updateMockParams(
1, // round id
0, // invalid answer
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
);
vm.expectRevert("Invalid price");
ubiquityPoolFacet.updateChainLinkCollateralPrice(0);
}
function testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsStale()
public
{
// set stale answer from chainlink
collateralTokenPriceFeed.updateMockParams(
1, // round id
100_000_000, // answer, 100_000_000 = $1.00
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
);
// wait 1 day
vm.warp(block.timestamp + 1 days);
vm.expectRevert("Stale data");
ubiquityPoolFacet.updateChainLinkCollateralPrice(0);
}
function testUpdateChainLinkCollateralPrice_ShouldUpdateCollateralPrice()
public
{
// before
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.price, 1_000_000);
// set answer from chainlink
collateralTokenPriceFeed.updateMockParams(
1, // round id
99_000_000, // answer, 99_000_000 = $0.99
block.timestamp, // started at
block.timestamp, // updated at
1 // answered in round
);
// update collateral price
ubiquityPoolFacet.updateChainLinkCollateralPrice(0);
// after
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.price, 990_000);
}
//=========================
// AMO minters functions
//=========================
function testAmoMinterBorrow_ShouldRevert_IfBorrowingIsPaused() public {
// admin pauses borrowing by AMOs
vm.prank(admin);
ubiquityPoolFacet.toggleMintRedeemBorrow(0, 2);
// Dollar AMO minter tries to borrow collateral
vm.prank(address(dollarAmoMinter));
vm.expectRevert("Borrowing is paused");
ubiquityPoolFacet.amoMinterBorrow(1);
}
function testAmoMinterBorrow_ShouldRevert_IfCollateralIsDisabled() public {
// admin disables collateral
vm.prank(admin);
ubiquityPoolFacet.toggleCollateral(0);
// Dollar AMO minter tries to borrow collateral
vm.prank(address(dollarAmoMinter));
vm.expectRevert("Collateral disabled");
ubiquityPoolFacet.amoMinterBorrow(1);
}
function testAmoMinterBorrow_ShouldBorrowCollateral() public {
// mint 100 collateral tokens to the pool
collateralToken.mint(address(ubiquityPoolFacet), 100e18);
assertEq(collateralToken.balanceOf(address(ubiquityPoolFacet)), 100e18);
assertEq(collateralToken.balanceOf(address(dollarAmoMinter)), 0);
vm.prank(address(dollarAmoMinter));
ubiquityPoolFacet.amoMinterBorrow(100e18);
assertEq(collateralToken.balanceOf(address(ubiquityPoolFacet)), 0);
assertEq(collateralToken.balanceOf(address(dollarAmoMinter)), 100e18);
}
//========================
// Restricted functions
//========================
function testAddAmoMinter_ShouldRevert_IfAmoMinterIsZeroAddress() public {
vm.startPrank(admin);
vm.expectRevert("Zero address detected");
ubiquityPoolFacet.addAmoMinter(address(0));
vm.stopPrank();
}
function testAddAmoMinter_ShouldRevert_IfAmoMinterHasInvalidInterface()
public
{
vm.startPrank(admin);
vm.expectRevert();
ubiquityPoolFacet.addAmoMinter(address(1));
vm.stopPrank();
}
function testAddAmoMinter_ShouldAddAmoMinter() public {
vm.startPrank(admin);
vm.expectEmit(address(ubiquityPoolFacet));
emit AmoMinterAdded(address(dollarAmoMinter));
ubiquityPoolFacet.addAmoMinter(address(dollarAmoMinter));
vm.stopPrank();
}
function testAddCollateralToken_ShouldAddNewTokenAsCollateral() public {
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.index, 0);
assertEq(info.symbol, "CLT");
assertEq(info.collateralAddress, address(collateralToken));
assertEq(
info.collateralPriceFeedAddress,
address(collateralTokenPriceFeed)
);
assertEq(info.collateralPriceFeedStalenessThreshold, 1 days);
assertEq(info.isEnabled, true);
assertEq(info.missingDecimals, 0);
assertEq(info.price, 1_000_000);
assertEq(info.poolCeiling, 50_000e18);
assertEq(info.isMintPaused, false);
assertEq(info.isRedeemPaused, false);
assertEq(info.isBorrowPaused, false);
assertEq(info.mintingFee, 10000);
assertEq(info.redemptionFee, 20000);
}
function testRemoveAmoMinter_ShouldRemoveAmoMinter() public {
vm.startPrank(admin);
vm.expectEmit(address(ubiquityPoolFacet));
emit AmoMinterRemoved(address(dollarAmoMinter));
ubiquityPoolFacet.removeAmoMinter(address(dollarAmoMinter));
vm.stopPrank();
}
function testSetCollateralChainLinkPriceFeed_ShouldSetPriceFeed() public {
vm.startPrank(admin);
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(
info.collateralPriceFeedAddress,
address(collateralTokenPriceFeed)
);
assertEq(info.collateralPriceFeedStalenessThreshold, 1 days);
address newPriceFeedAddress = address(1);
uint256 newStalenessThreshold = 2 days;
vm.expectEmit(address(ubiquityPoolFacet));
emit CollateralPriceFeedSet(
0,
newPriceFeedAddress,
newStalenessThreshold
);
ubiquityPoolFacet.setCollateralChainLinkPriceFeed(
address(collateralToken),
newPriceFeedAddress,
newStalenessThreshold
);
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.collateralPriceFeedAddress, newPriceFeedAddress);
assertEq(
info.collateralPriceFeedStalenessThreshold,
newStalenessThreshold
);
vm.stopPrank();
}
function testSetFees_ShouldSetMintAndRedeemFees() public {
vm.startPrank(admin);
vm.expectEmit(address(ubiquityPoolFacet));
emit FeesSet(0, 1, 2);
ubiquityPoolFacet.setFees(0, 1, 2);
vm.stopPrank();
}
function testSetPoolCeiling_ShouldSetMaxAmountOfTokensAllowedForCollateral()
public
{
vm.startPrank(admin);
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.poolCeiling, 50_000e18);
vm.expectEmit(address(ubiquityPoolFacet));
emit PoolCeilingSet(0, 10_000e18);
ubiquityPoolFacet.setPoolCeiling(0, 10_000e18);
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.poolCeiling, 10_000e18);
vm.stopPrank();
}
function testSetPriceThresholds_ShouldSetPriceThresholds() public {
vm.startPrank(admin);
vm.expectEmit(address(ubiquityPoolFacet));
emit PriceThresholdsSet(1010000, 990000);
ubiquityPoolFacet.setPriceThresholds(1010000, 990000);
vm.stopPrank();
}
function testSetRedemptionDelayBlocks_ShouldSetRedemptionDelayInBlocks()
public
{
vm.startPrank(admin);
vm.expectEmit(address(ubiquityPoolFacet));
emit RedemptionDelayBlocksSet(2);
ubiquityPoolFacet.setRedemptionDelayBlocks(2);
vm.stopPrank();
}
function testToggleCollateral_ShouldToggleCollateral() public {
vm.startPrank(admin);
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.isEnabled, true);
vm.expectEmit(address(ubiquityPoolFacet));
emit CollateralToggled(0, false);
ubiquityPoolFacet.toggleCollateral(0);
vm.expectRevert("Invalid collateral");
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
vm.stopPrank();
}
function testToggleMintRedeemBorrow_ShouldToggleMinting() public {
vm.startPrank(admin);
uint256 collateralIndex = 0;
uint8 toggleIndex = 0;
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.isMintPaused, false);
vm.expectEmit(address(ubiquityPoolFacet));
emit MintRedeemBorrowToggled(collateralIndex, toggleIndex);
ubiquityPoolFacet.toggleMintRedeemBorrow(collateralIndex, toggleIndex);
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.isMintPaused, true);
vm.stopPrank();
}
function testToggleMintRedeemBorrow_ShouldToggleRedeeming() public {
vm.startPrank(admin);
uint256 collateralIndex = 0;
uint8 toggleIndex = 1;
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.isRedeemPaused, false);
vm.expectEmit(address(ubiquityPoolFacet));
emit MintRedeemBorrowToggled(collateralIndex, toggleIndex);
ubiquityPoolFacet.toggleMintRedeemBorrow(collateralIndex, toggleIndex);
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.isRedeemPaused, true);
vm.stopPrank();
}
function testToggleMintRedeemBorrow_ShouldToggleBorrowingByAmoMinter()
public
{
vm.startPrank(admin);
uint256 collateralIndex = 0;
uint8 toggleIndex = 2;
LibUbiquityPool.CollateralInformation memory info = ubiquityPoolFacet
.collateralInformation(address(collateralToken));
assertEq(info.isBorrowPaused, false);
vm.expectEmit(address(ubiquityPoolFacet));
emit MintRedeemBorrowToggled(collateralIndex, toggleIndex);
ubiquityPoolFacet.toggleMintRedeemBorrow(collateralIndex, toggleIndex);
info = ubiquityPoolFacet.collateralInformation(
address(collateralToken)
);
assertEq(info.isBorrowPaused, true);
vm.stopPrank();
}
}