-
Notifications
You must be signed in to change notification settings - Fork 5
/
MIMATICAaveV3FantomListingByGuardian.t.sol
221 lines (185 loc) · 6.92 KB
/
MIMATICAaveV3FantomListingByGuardian.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import 'forge-std/Test.sol';
import {IPoolConfigurator, ConfiguratorInputTypes, IACLManager} from 'aave-address-book/AaveV3.sol';
import {AaveV3Fantom} from 'aave-address-book/AaveAddressBook.sol';
import {AaveV3FantomMIMATICListingSteward} from '../contracts/mimatic/AaveV3FantomMIMATICListingSteward.sol';
import {AaveV3Helpers, ReserveConfig, ReserveTokens, IERC20} from './helpers/AaveV3Helpers.sol';
contract MIMATICAaveV3FantomListingByGuardian is Test {
using stdStorage for StdStorage;
address public constant GUARDIAN =
0x39CB97b105173b56b5a2b4b33AD25d6a50E6c949;
address public constant CURRENT_ACL_SUPERADMIN =
0x39CB97b105173b56b5a2b4b33AD25d6a50E6c949;
address public constant MIMATIC =
0xfB98B335551a418cD0737375a2ea0ded62Ea213b;
address public constant MIMATIC_WHALE = address(0); // There is a lot of burnt tokens
address public constant DAI = 0x8D11eC38a3EB5E956B052f67Da8Bdc9bef8Abf3E;
address public constant DAI_WHALE =
0xd652776dE7Ad802be5EC7beBfafdA37600222B48;
address public constant RATE_STRATEGY =
0xf4a0039F2d4a2EaD5216AbB6Ae4C4C3AA2dB9b82;
function setUp() public {}
function testListing() public {
ReserveConfig[] memory allConfigsBefore = AaveV3Helpers
._getReservesConfigs(false);
vm.startPrank(GUARDIAN);
AaveV3FantomMIMATICListingSteward listingSteward = new AaveV3FantomMIMATICListingSteward();
IACLManager aclManager = AaveV3Fantom.ACL_MANAGER;
aclManager.addAssetListingAdmin(address(listingSteward));
aclManager.addRiskAdmin(address(listingSteward));
listingSteward.listAssetAddingOracle();
vm.stopPrank();
ReserveConfig[] memory allConfigsAfter = AaveV3Helpers
._getReservesConfigs(false);
ReserveConfig memory expectedAssetConfig = ReserveConfig({
symbol: 'miMATIC',
underlying: MIMATIC,
aToken: address(0), // Mock, as they don't get validated, because of the "dynamic" deployment on proposal execution
variableDebtToken: address(0), // Mock, as they don't get validated, because of the "dynamic" deployment on proposal execution
stableDebtToken: address(0), // Mock, as they don't get validated, because of the "dynamic" deployment on proposal execution
decimals: 18,
ltv: 0,
liquidationThreshold: 0,
liquidationBonus: 0,
liquidationProtocolFee: 1000,
reserveFactor: 1000,
usageAsCollateralEnabled: false,
borrowingEnabled: true,
interestRateStrategy: AaveV3Helpers
._findReserveConfig(allConfigsAfter, 'fUSDT', false)
.interestRateStrategy,
stableBorrowRateEnabled: false,
isActive: true,
isFrozen: false,
isSiloed: false,
isBorrowableInIsolation: false,
supplyCap: 50_000_000,
borrowCap: 0,
debtCeiling: 0,
eModeCategory: 1
});
AaveV3Helpers._validateReserveConfig(
expectedAssetConfig,
allConfigsAfter
);
AaveV3Helpers._noReservesConfigsChangesApartNewListings(
allConfigsBefore,
allConfigsAfter
);
AaveV3Helpers._validateReserveTokensImpls(
vm,
AaveV3Helpers._findReserveConfig(allConfigsAfter, 'miMATIC', false),
ReserveTokens({
aToken: listingSteward.ATOKEN_IMPL(),
stableDebtToken: listingSteward.SDTOKEN_IMPL(),
variableDebtToken: listingSteward.VDTOKEN_IMPL()
})
);
AaveV3Helpers._validateAssetSourceOnOracle(
MIMATIC,
listingSteward.PRICE_FEED()
);
// impl should be same as USDC
AaveV3Helpers._validateReserveTokensImpls(
vm,
AaveV3Helpers._findReserveConfig(allConfigsAfter, 'USDC', false),
ReserveTokens({
aToken: listingSteward.ATOKEN_IMPL(),
stableDebtToken: listingSteward.SDTOKEN_IMPL(),
variableDebtToken: listingSteward.VDTOKEN_IMPL()
})
);
_validatePoolActionsPostListing(allConfigsAfter);
require(
listingSteward.owner() == address(0),
'INVALID_OWNER_POST_LISTING'
);
}
function _validatePoolActionsPostListing(
ReserveConfig[] memory allReservesConfigs
) internal {
address aMIMATIC = AaveV3Helpers
._findReserveConfig(allReservesConfigs, 'miMATIC', false)
.aToken;
address vMIMATIC = AaveV3Helpers
._findReserveConfig(allReservesConfigs, 'miMATIC', false)
.variableDebtToken;
address sMIMATIC = AaveV3Helpers
._findReserveConfig(allReservesConfigs, 'miMATIC', false)
.stableDebtToken;
address aDAI = AaveV3Helpers
._findReserveConfig(allReservesConfigs, 'DAI', false)
.aToken;
AaveV3Helpers._deposit(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
MIMATIC,
666 ether,
true,
aMIMATIC
);
// We check revert when trying to borrow (not enabled as collateral, so any mode works)
try
AaveV3Helpers._borrow(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
MIMATIC,
10 ether,
1,
sMIMATIC
)
{
revert('_testProposal() : BORROW_NOT_REVERTING');
} catch Error(string memory revertReason) {
require(
keccak256(bytes(revertReason)) == keccak256(bytes('34')),
'_testProposal() : INVALID_VARIABLE_REVERT_MSG'
);
vm.stopPrank();
}
vm.startPrank(DAI_WHALE);
IERC20(DAI).transfer(MIMATIC_WHALE, 666 ether);
vm.stopPrank();
AaveV3Helpers._deposit(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
DAI,
666 ether,
true,
aDAI
);
AaveV3Helpers._borrow(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
MIMATIC,
222 ether,
2,
vMIMATIC
);
// Not possible to borrow and repay when vdebt index doesn't changing, so moving 1s
skip(1);
AaveV3Helpers._repay(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
MIMATIC,
IERC20(MIMATIC).balanceOf(MIMATIC_WHALE),
2,
vMIMATIC,
true
);
AaveV3Helpers._withdraw(
vm,
MIMATIC_WHALE,
MIMATIC_WHALE,
MIMATIC,
type(uint256).max,
aMIMATIC
);
}
}