Skip to content

Commit b18f305

Browse files
committed
fix: update make file; clean up tests and add for emode
1 parent 71bb4e1 commit b18f305

File tree

3 files changed

+119
-48
lines changed

3 files changed

+119
-48
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ deploy-liquidation-data-provider :;
9292
--sig "run(address,address)" ${pool} ${addressesProvider} \
9393
--verify --broadcast
9494

95-
# STEP 5: Deploys payload to update phase two assets. `make deploy-phase-two-payload CHAIN=mainnet ACCOUNT=<account>`
95+
# Deploys payload to update phase two assets. `make deploy-phase-two-payload CHAIN=mainnet ACCOUNT=<account>`
9696
deploy-phase-two-payload :;
9797
FOUNDRY_PROFILE=${CHAIN} forge script scripts/misc/DeployHorizonPhaseTwoPayload.sol:DeployHorizonPhaseTwoPayload \
9898
--rpc-url ${CHAIN} --account ${ACCOUNT} --slow --gas-estimate-multiplier 150 \

tests/deployments/HorizonBase.t.sol

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ abstract contract HorizonBaseTest is Test {
112112
test_priceFeed(token, params);
113113
}
114114

115-
function test_eMode(uint8 eModeCategory, EModeCategoryParams memory params) internal {
115+
function test_eMode(
116+
uint8 eModeCategory,
117+
EModeCategoryParams memory params,
118+
bool dealCollateral
119+
) internal {
116120
test_eMode_configuration(eModeCategory, params);
117-
test_eMode_collateralization(eModeCategory, params);
121+
test_eMode_collateralization(eModeCategory, params, true);
118122
}
119123

120-
function test_getConfiguration(address token, TokenListingParams memory params) private view {
124+
function test_getConfiguration(address token, TokenListingParams memory params) internal view {
121125
DataTypes.ReserveConfigurationMap memory config = pool.getConfiguration(token);
122126
assertEq(config.getSupplyCap(), params.supplyCap, 'supplyCap');
123127
assertEq(config.getBorrowCap(), params.borrowCap, 'borrowCap');
@@ -139,7 +143,10 @@ abstract contract HorizonBaseTest is Test {
139143
assertEq(config.getPaused(), false, 'paused');
140144
}
141145

142-
function test_interestRateStrategy(address token, TokenListingParams memory params) private view {
146+
function test_interestRateStrategy(
147+
address token,
148+
TokenListingParams memory params
149+
) internal view {
143150
assertEq(
144151
pool.getReserveData(token).interestRateStrategyAddress,
145152
address(defaultInterestRateStrategy),
@@ -148,7 +155,7 @@ abstract contract HorizonBaseTest is Test {
148155
assertEq(defaultInterestRateStrategy.getInterestRateData(token), params.interestRateData);
149156
}
150157

151-
function test_aToken(address token, TokenListingParams memory params) private {
158+
function test_aToken(address token, TokenListingParams memory params) internal {
152159
address aToken = pool.getReserveAToken(token);
153160
assertEq(IERC20Detailed(aToken).name(), params.aTokenName, 'aTokenName');
154161
assertEq(IERC20Detailed(aToken).symbol(), params.aTokenSymbol, 'aTokenSymbol');
@@ -258,7 +265,8 @@ abstract contract HorizonBaseTest is Test {
258265

259266
function test_eMode_collateralization(
260267
uint8 eModeCategory,
261-
EModeCategoryParams memory params
268+
EModeCategoryParams memory params,
269+
bool dealCollateral
262270
) internal {
263271
address poolConfigurator = pool.ADDRESSES_PROVIDER().getPoolConfigurator();
264272

@@ -267,14 +275,16 @@ abstract contract HorizonBaseTest is Test {
267275

268276
IAaveOracle oracle = IAaveOracle(pool.ADDRESSES_PROVIDER().getPriceOracle());
269277
for (uint256 i = 0; i < params.collateralAssets.length; i++) {
270-
uint256 amountInBaseCurrency = 1e6 * 1e8;
278+
uint256 amountInBaseCurrency = 1e5 * 1e8;
271279

272280
uint256 supplyAmount = (amountInBaseCurrency *
273281
10 ** IERC20Detailed(params.collateralAssets[i]).decimals()) /
274282
oracle.getAssetPrice(params.collateralAssets[i]) +
275283
1;
276284
address collateralAsset = params.collateralAssets[i];
277-
deal(collateralAsset, alice, supplyAmount);
285+
if (dealCollateral) {
286+
deal(collateralAsset, alice, supplyAmount);
287+
}
278288

279289
vm.startPrank(alice);
280290
IERC20Detailed(collateralAsset).approve(address(pool), supplyAmount);
@@ -315,7 +325,8 @@ abstract contract HorizonBaseTest is Test {
315325
function test_nonEMode_collateralization(
316326
address token,
317327
TokenListingParams memory params,
318-
address[] memory borrowableAssets
328+
address[] memory borrowableAssets,
329+
bool dealCollateral
319330
) internal {
320331
address poolConfigurator = pool.ADDRESSES_PROVIDER().getPoolConfigurator();
321332

@@ -326,45 +337,43 @@ abstract contract HorizonBaseTest is Test {
326337
oracle.getAssetPrice(token) +
327338
1;
328339

329-
// deal(token, alice, supplyAmount);
330-
vm.prank(0x69133f8Ef7F9A5F80D25c2DAEaea64C804aC7Cf9);
331-
IERC20(token).transfer(alice, supplyAmount);
332-
333-
// console.log('pool', address(pool));
340+
if (dealCollateral) {
341+
deal(token, alice, supplyAmount);
342+
}
334343

335344
vm.startPrank(alice);
336345
IERC20Detailed(token).approve(address(pool), supplyAmount);
337346
pool.supply(token, supplyAmount, alice, 0);
338347
vm.stopPrank();
339348

340-
// for (uint256 j = 0; j < borrowableAssets.length; j++) {
341-
// address borrowAsset = borrowableAssets[j];
342-
// uint256 borrowAmount = (amountInBaseCurrency.percentMul(params.ltv) *
343-
// 10 ** IERC20Detailed(borrowAsset).decimals()) /
344-
// oracle.getAssetPrice(borrowAsset) -
345-
// 1;
349+
for (uint256 j = 0; j < borrowableAssets.length; j++) {
350+
address borrowAsset = borrowableAssets[j];
351+
uint256 borrowAmount = (amountInBaseCurrency.percentMul(params.ltv) *
352+
10 ** IERC20Detailed(borrowAsset).decimals()) /
353+
oracle.getAssetPrice(borrowAsset) -
354+
1;
346355

347-
// deal(borrowAsset, bob, borrowAmount);
356+
deal(borrowAsset, bob, borrowAmount);
348357

349-
// vm.startPrank(bob);
350-
// IERC20Detailed(borrowAsset).approve(address(pool), borrowAmount);
351-
// pool.supply(borrowAsset, borrowAmount, bob, 0);
352-
// vm.stopPrank();
358+
vm.startPrank(bob);
359+
IERC20Detailed(borrowAsset).approve(address(pool), borrowAmount);
360+
pool.supply(borrowAsset, borrowAmount, bob, 0);
361+
vm.stopPrank();
353362

354-
// vm.prank(alice);
355-
// pool.borrow(borrowAsset, borrowAmount, 2, 0, alice);
363+
vm.prank(alice);
364+
pool.borrow(borrowAsset, borrowAmount, 2, 0, alice);
356365

357-
// vm.startPrank(alice);
358-
// IERC20Detailed(borrowAsset).approve(address(pool), borrowAmount);
359-
// pool.repay(borrowAsset, borrowAmount, 2, alice);
360-
// vm.stopPrank();
366+
vm.startPrank(alice);
367+
IERC20Detailed(borrowAsset).approve(address(pool), borrowAmount);
368+
pool.repay(borrowAsset, borrowAmount, 2, alice);
369+
vm.stopPrank();
361370

362-
// vm.prank(bob);
363-
// pool.withdraw(borrowAsset, borrowAmount, bob);
364-
// }
371+
vm.prank(bob);
372+
pool.withdraw(borrowAsset, borrowAmount, bob);
373+
}
365374

366-
// vm.prank(alice);
367-
// pool.withdraw(token, supplyAmount, alice);
375+
vm.prank(alice);
376+
pool.withdraw(token, supplyAmount, alice);
368377
}
369378

370379
function assertEq(
@@ -394,12 +403,19 @@ abstract contract HorizonBaseTest is Test {
394403
assertEq(abi.encode(a), abi.encode(b), 'assertEq(interestRateData): all fields');
395404
}
396405

397-
function _toDynamicAddressArray(address a) private pure returns (address[] memory) {
406+
function _toDynamicAddressArray(address a) internal pure returns (address[] memory) {
398407
address[] memory array = new address[](1);
399408
array[0] = a;
400409
return array;
401410
}
402411

412+
function _toDynamicAddressArray(address a, address b) internal pure returns (address[] memory) {
413+
address[] memory array = new address[](2);
414+
array[0] = a;
415+
array[1] = b;
416+
return array;
417+
}
418+
403419
function _toDynamicAddressArray(
404420
address a,
405421
address b,

tests/deployments/HorizonPhaseTwoListing.t.sol

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,53 @@ contract HorizonPhaseTwoListingTest is HorizonBaseTest {
4141
initialDeposit: 0
4242
});
4343

44+
EModeCategoryParams internal VBILL_GHO_EMODE_PARAMS =
45+
EModeCategoryParams({
46+
ltv: 84_00,
47+
liquidationThreshold: 89_00,
48+
liquidationBonus: 100_00 + 3_00,
49+
label: 'VBILL GHO',
50+
collateralAssets: _toDynamicAddressArray(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING),
51+
borrowableAssets: _toDynamicAddressArray(AaveV3EthereumHorizonAssets.GHO_UNDERLYING)
52+
});
53+
4454
function setUp() public virtual {
4555
vm.createSelectFork('mainnet');
4656
initEnvironment();
4757
_loadDeployment();
4858

4959
_whitelistVbillRwa(alice);
5060
_whitelistVbillRwa(pool.getReserveAToken(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING));
61+
62+
_transferVBILLTo(alice, 1_000_000e6);
5163
}
5264

5365
function test_listing_VBILL() public {
5466
test_listing(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING, VBILL_TOKEN_LISTING_PARAMS);
5567
}
5668

69+
function test_eMode_VBILL_GHO() public {
70+
test_eMode({eModeCategory: 1, params: VBILL_GHO_EMODE_PARAMS, dealCollateral: false});
71+
}
72+
73+
// fund accounts by transferring existing VBILL, as `deal` causes issues on token contract accounting
74+
function _transferVBILLTo(address user, uint256 amount) internal virtual {
75+
vm.prank(0x5E6c2AD8376A9E5E857B1d91643399E9aB65ff8c); // on-chain holder, ~25M VBILL balance
76+
IERC20(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING).transfer(user, amount);
77+
}
78+
5779
function test_listing(address token, TokenListingParams memory params) internal virtual override {
5880
super.test_listing(token, params);
5981
if (params.isRwa) {
60-
test_nonEMode_collateralization(
61-
token,
62-
params,
63-
_toDynamicAddressArray(
82+
test_nonEMode_collateralization({
83+
token: token,
84+
params: params,
85+
borrowableAssets: _toDynamicAddressArray(
6486
AaveV3EthereumHorizonAssets.USDC_UNDERLYING,
65-
AaveV3EthereumHorizonAssets.RLUSD_UNDERLYING,
6687
AaveV3EthereumHorizonAssets.GHO_UNDERLYING
67-
)
68-
);
88+
),
89+
dealCollateral: false
90+
});
6991
}
7092
}
7193

@@ -123,6 +145,38 @@ contract HorizonPhaseTwoListingTest is HorizonBaseTest {
123145
}
124146
}
125147

148+
/// forge-config: default.evm_version = "cancun"
149+
contract HorizonPhaseTwoListingVTestnetTest is HorizonPhaseTwoListingTest {
150+
function setUp() public virtual override {
151+
vm.createSelectFork('vtestnet');
152+
153+
initEnvironment();
154+
155+
_whitelistVbillRwa(alice);
156+
_whitelistVbillRwa(pool.getReserveAToken(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING));
157+
158+
_transferVBILLTo(alice, 1_000_000e6);
159+
}
160+
161+
function test_actions() public {
162+
address testUser1 = 0xabCa9b6E08dC6C031880f515Ec0cf9e395D0d6B8;
163+
address testUser2 = 0x66C1d4c6195D587C99aCc4256EbaC0a8D0AB9f64;
164+
address testUser3 = 0xd22eefD49B81e078f576Dbb4A804aa250cB3A291;
165+
166+
_supplyAndBorrow(testUser1);
167+
_supplyAndBorrow(testUser2);
168+
_supplyAndBorrow(testUser3);
169+
}
170+
171+
function _supplyAndBorrow(address user) internal virtual {
172+
vm.startPrank(user);
173+
IERC20(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING).approve(address(pool), 100e6);
174+
pool.supply(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING, 100e6, user, 0);
175+
pool.borrow(AaveV3EthereumHorizonAssets.USDC_UNDERLYING, 50e6, 2, 0, user);
176+
vm.stopPrank();
177+
}
178+
}
179+
126180
/// forge-config: default.evm_version = "cancun"
127181
contract HorizonPhaseTwoListingPostDeploymentForkTest is HorizonPhaseTwoListingTest {
128182
function setUp() public virtual override {
@@ -134,6 +188,8 @@ contract HorizonPhaseTwoListingPostDeploymentForkTest is HorizonPhaseTwoListingT
134188

135189
_whitelistVbillRwa(alice);
136190
_whitelistVbillRwa(pool.getReserveAToken(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING));
191+
192+
_transferVBILLTo(alice, 1_000_000e6);
137193
}
138194

139195
function _loadDeployment() internal virtual override {
@@ -162,11 +218,10 @@ contract HorizonPhaseTwoListingPostExecutionForkTest is HorizonPhaseTwoListingTe
162218
vm.createSelectFork('mainnet');
163219

164220
initEnvironment();
165-
_loadDeployment();
166221

167222
_whitelistVbillRwa(alice);
168223
_whitelistVbillRwa(pool.getReserveAToken(AaveV3EthereumHorizonCustom.VBILL_UNDERLYING));
169-
}
170224

171-
function _loadDeployment() internal virtual override {}
225+
_transferVBILLTo(alice, 1_000_000e6);
226+
}
172227
}

0 commit comments

Comments
 (0)