-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFed.t.sol
181 lines (140 loc) · 5.87 KB
/
Fed.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "./FiRMBaseTest.sol";
contract FedTest is FiRMBaseTest {
bytes onlyGovUpper = "ONLY GOV";
bytes unsupportedMarket = "UNSUPPORTED MARKET";
bytes tooBig = "AMOUNT TOO BIG";
bytes pausedMarkets = "CANNOT EXPAND PAUSED MARKETS";
IMarket marketParameter;
uint testAmount = 1_000_000e18;
function setUp() public {
initialize(replenishmentPriceBps, collateralFactorBps, replenishmentIncentiveBps, liquidationBonusBps, callOnDepositCallback);
marketParameter = IMarket(address(market));
vm.startPrank(chair);
fed.contraction(marketParameter, fed.supplies(marketParameter));
vm.stopPrank();
}
function testExpansion(uint256 amount) public {
amount = bound(amount, 0, 1e50);
uint startingDolaBal = DOLA.balanceOf(address(marketParameter));
vm.startPrank(chair);
fed.expansion(marketParameter, amount);
assertEq(startingDolaBal + amount, DOLA.balanceOf(address(marketParameter)), "Expansion failed - dola balance");
assertEq(fed.supplies(marketParameter), amount, "Expansion failed - fed accounting");
}
function testExpansion_Fails_If_UnsupportedMarket() public {
vm.startPrank(chair);
vm.expectRevert(unsupportedMarket);
fed.expansion(IMarket(address(0)), testAmount);
}
function testExpansion_Fails_While_MarketPaused() public {
vm.startPrank(gov);
market.pauseBorrows(true);
vm.stopPrank();
vm.startPrank(chair);
vm.expectRevert(pausedMarkets);
fed.expansion(marketParameter, testAmount);
}
function testContraction(uint256 amount) public {
amount = bound(amount, 0, 1e50);
vm.startPrank(chair);
fed.expansion(marketParameter, amount);
assertEq(fed.supplies(marketParameter), amount, "expansion failed - fed accounting");
assertEq(DOLA.balanceOf(address(marketParameter)), amount, "expansion failed - dola balance");
fed.contraction(marketParameter, amount);
assertEq(fed.supplies(marketParameter), 0, "contraction failed - fed accounting");
assertEq(DOLA.balanceOf(address(marketParameter)), 0, "contraction failed - dola balance");
}
function testContraction_Fails_If_UnsupportedMarket() public {
vm.startPrank(chair);
vm.expectRevert(unsupportedMarket);
fed.contraction(IMarket(address(0)), testAmount);
}
function testContraction_Fails_If_Amount_GT_SuppliedDOLA() public {
vm.startPrank(chair);
fed.expansion(marketParameter, testAmount);
vm.expectRevert(tooBig);
fed.contraction(marketParameter, testAmount + 1);
}
function testGetProfit_Returns0_If_SuppliedDola_GT_MarketDolaValue() public {
gibWeth(user, wethTestAmount);
gibDBR(user, wethTestAmount);
vm.startPrank(chair);
fed.expansion(marketParameter, testAmount);
vm.stopPrank();
vm.startPrank(user, user);
deposit(wethTestAmount);
market.borrow(getMaxBorrowAmount(wethTestAmount));
assertLt(DOLA.balanceOf(address(market)), testAmount, "Market DOLA value > Supplied Dola");
assertEq(fed.getProfit(marketParameter), 0, "getProfit should return 0 since market DOLA value > fed's supplied DOLA");
}
function test_takeProfit() public {
vm.startPrank(chair);
fed.expansion(marketParameter, testAmount);
gibDOLA(address(marketParameter), testAmount * 2);
vm.stopPrank();
uint startingDolaBal = DOLA.balanceOf(gov);
fed.takeProfit(marketParameter);
assertEq(startingDolaBal + testAmount, DOLA.balanceOf(gov), "takeProfit failed");
}
function test_takeProfit_doesNothing_WhenProfitIs0() public {
vm.startPrank(chair);
fed.expansion(marketParameter, testAmount);
uint startingDolaBal = DOLA.balanceOf(gov);
fed.takeProfit(marketParameter);
assertEq(startingDolaBal, DOLA.balanceOf(gov), "DOLA balance should be unchanged, there is no profit");
}
//Access Control
function test_accessControl_changeGov() public {
vm.startPrank(gov);
fed.changeGov(address(0));
vm.stopPrank();
vm.expectRevert(onlyGovUpper);
fed.changeGov(address(0));
}
function test_accessControl_changeChair() public {
vm.startPrank(gov);
fed.changeChair(address(0));
vm.stopPrank();
vm.expectRevert(onlyGovUpper);
fed.changeChair(address(0));
}
function test_accessControl_resign() public {
vm.startPrank(chair);
fed.resign();
vm.stopPrank();
vm.expectRevert(onlyChair);
fed.resign();
}
function test_accessControl_expansion() public {
vm.startPrank(chair);
fed.expansion(IMarket(address(market)), 100e18);
vm.stopPrank();
vm.expectRevert(onlyChair);
fed.expansion(IMarket(address(market)), 100e18);
}
function test_accessControl_contraction() public {
vm.startPrank(chair);
fed.expansion(IMarket(address(market)), 100e18);
fed.contraction(IMarket(address(market)), 100e18);
fed.expansion(IMarket(address(market)), 100e18);
vm.stopPrank();
vm.expectRevert(onlyChair);
fed.contraction(IMarket(address(market)), 100e18);
}
function test_changeSupplyCeiling() public {
vm.expectRevert("ONLY GOV");
fed.changeSupplyCeiling(1);
vm.prank(gov);
fed.changeSupplyCeiling(1);
assertEq(fed.supplyCeiling(), 1);
}
function test_changeMarketCeiling() public {
vm.expectRevert("ONLY GOV");
fed.changeMarketCeiling(IMarket(address(0)), 1);
vm.prank(gov);
fed.changeMarketCeiling(IMarket(address(0)), 1);
assertEq(fed.ceilings(IMarket(address(0))), 1);
}
}