-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathAaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409.t.sol
More file actions
191 lines (152 loc) · 7.05 KB
/
AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409.t.sol
File metadata and controls
191 lines (152 loc) · 7.05 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {GovV3Helpers} from 'aave-helpers/src/GovV3Helpers.sol';
import {AaveV3MegaEth, AaveV3MegaEthAssets} from 'aave-address-book/AaveV3MegaEth.sol';
import {IERC20} from 'openzeppelin-contracts/contracts/token/ERC20/IERC20.sol';
import {GovernanceV3MegaEth} from 'aave-address-book/GovernanceV3MegaEth.sol';
import {IEmissionManager} from 'aave-v3-origin/contracts/rewards/interfaces/IEmissionManager.sol';
import {Errors} from 'aave-v3-origin/contracts/protocol/libraries/helpers/Errors.sol';
import 'forge-std/Test.sol';
import {ProtocolV3TestBase, ReserveConfig} from 'aave-helpers/src/ProtocolV3TestBase.sol';
import {AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409} from './AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409.sol';
import {IPriceCapAdapterStable} from '../interfaces/IPriceCapAdapterStable.sol';
/**
* @dev Test for AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409
* command: FOUNDRY_PROFILE=test forge test --match-path=src/20260409_AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance/AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409.t.sol -vv
*/
contract AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409_Test is ProtocolV3TestBase {
AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409 internal proposal;
function setUp() public {
vm.createSelectFork(vm.rpcUrl('megaeth'), 12933915);
proposal = new AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409();
}
/**
* @dev executes the generic test suite including e2e and config snapshots
*/
function test_defaultProposalExecution() public {
defaultTest(
'AaveV3MegaEth_OnboardUSDeToTheAaveV3MegaETHInstance_20260409',
AaveV3MegaEth.POOL,
address(proposal)
);
}
function test_dustBinHasUSDeFunds() public {
GovV3Helpers.executePayload(vm, address(proposal));
address aTokenAddress = AaveV3MegaEth.POOL.getReserveAToken(proposal.USDe());
assertGe(IERC20(aTokenAddress).balanceOf(address(AaveV3MegaEth.DUST_BIN)), 10 ** 18);
}
function test_borrowWithoutEModeReverts() public {
GovV3Helpers.executePayload(vm, address(proposal));
address user = address(505);
uint256 supplyAmount = IERC20(proposal.USDe()).balanceOf(address(AaveV3MegaEth.COLLECTOR));
vm.startPrank(GovernanceV3MegaEth.EXECUTOR_LVL_1);
AaveV3MegaEth.COLLECTOR.transfer(IERC20(proposal.USDe()), user, supplyAmount);
vm.stopPrank();
vm.startPrank(user);
IERC20(proposal.USDe()).approve(address(AaveV3MegaEth.POOL), supplyAmount);
AaveV3MegaEth.POOL.supply(proposal.USDe(), supplyAmount, user, 0);
// USDe has LTV=0 outside e-mode, borrow must revert
vm.expectRevert(abi.encodeWithSelector(Errors.LtvValidationFailed.selector));
AaveV3MegaEth.POOL.borrow(AaveV3MegaEthAssets.USDT0_UNDERLYING, 1, 2, 0, user);
vm.stopPrank();
}
function test_eMode_supplyAndBorrow() public {
GovV3Helpers.executePayload(vm, address(proposal));
uint8 eModeId = _findEModeCategoryId('USDe__USDT0_USDm');
address user = address(505);
uint256 supplyAmount = IERC20(proposal.USDe()).balanceOf(address(AaveV3MegaEth.COLLECTOR));
vm.startPrank(GovernanceV3MegaEth.EXECUTOR_LVL_1);
AaveV3MegaEth.COLLECTOR.transfer(IERC20(proposal.USDe()), user, supplyAmount);
vm.stopPrank();
vm.startPrank(user);
AaveV3MegaEth.POOL.setUserEMode(eModeId);
IERC20(proposal.USDe()).approve(address(AaveV3MegaEth.POOL), supplyAmount);
AaveV3MegaEth.POOL.supply(proposal.USDe(), supplyAmount, user, 0);
address aUSDe = AaveV3MegaEth.POOL.getReserveAToken(proposal.USDe());
assertApproxEqAbs(IERC20(aUSDe).balanceOf(user), supplyAmount, 1);
// borrow USDT0 against USDe collateral in e-mode
// supplyAmount is ~0.063 USDe (18 decimals), convert to USDT0 (6 decimals) and take half
uint256 borrowAmount = supplyAmount / 1e12 / 2;
AaveV3MegaEth.POOL.borrow(AaveV3MegaEthAssets.USDT0_UNDERLYING, borrowAmount, 2, 0, user);
assertApproxEqAbs(IERC20(AaveV3MegaEthAssets.USDT0_V_TOKEN).balanceOf(user), borrowAmount, 1);
// repay and withdraw
IERC20(AaveV3MegaEthAssets.USDT0_UNDERLYING).approve(address(AaveV3MegaEth.POOL), borrowAmount);
AaveV3MegaEth.POOL.repay(AaveV3MegaEthAssets.USDT0_UNDERLYING, borrowAmount, 2, user);
AaveV3MegaEth.POOL.withdraw(proposal.USDe(), supplyAmount / 2, user);
vm.stopPrank();
}
function test_lmAdminConfiguration() public {
GovV3Helpers.executePayload(vm, address(proposal));
address aUSDe = AaveV3MegaEth.POOL.getReserveAToken(proposal.USDe());
address vUSDe = AaveV3MegaEth.POOL.getReserveVariableDebtToken(proposal.USDe());
assertEq(
IEmissionManager(AaveV3MegaEth.EMISSION_MANAGER).getEmissionAdmin(proposal.USDe()),
proposal.LM_ADMIN()
);
assertEq(
IEmissionManager(AaveV3MegaEth.EMISSION_MANAGER).getEmissionAdmin(aUSDe),
proposal.LM_ADMIN()
);
assertEq(
IEmissionManager(AaveV3MegaEth.EMISSION_MANAGER).getEmissionAdmin(vUSDe),
proposal.LM_ADMIN()
);
}
function test_oracleConfiguration() public {
GovV3Helpers.executePayload(vm, address(proposal));
assertEq(
AaveV3MegaEth.ORACLE.getSourceOfAsset(proposal.USDe()),
0x6B00ffb3852E87c13b7f56660a7dfF64191180B3
);
assertGt(AaveV3MegaEth.ORACLE.getAssetPrice(proposal.USDe()), 0);
IPriceCapAdapterStable adapter = IPriceCapAdapterStable(
AaveV3MegaEth.ORACLE.getSourceOfAsset(proposal.USDe())
);
assertFalse(adapter.isCapped());
assertEq(adapter.getPriceCap(), 1.04e8);
assertEq(
adapter.ASSET_TO_USD_AGGREGATOR(),
IPriceCapAdapterStable(
AaveV3MegaEth.ORACLE.getSourceOfAsset(AaveV3MegaEthAssets.USDT0_UNDERLYING)
).ASSET_TO_USD_AGGREGATOR()
);
}
function test_reserveParameters() public {
GovV3Helpers.executePayload(vm, address(proposal));
(
uint256 decimals,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 reserveFactor,
,
bool borrowingEnabled,
,
bool isActive,
) = AaveV3MegaEth.AAVE_PROTOCOL_DATA_PROVIDER.getReserveConfigurationData(proposal.USDe());
assertEq(decimals, 18);
assertEq(ltv, 0);
assertEq(liquidationThreshold, 0);
assertEq(liquidationBonus, 0);
assertEq(reserveFactor, 2500);
assertTrue(borrowingEnabled);
assertTrue(isActive);
(uint256 borrowCap, uint256 supplyCap) = AaveV3MegaEth
.AAVE_PROTOCOL_DATA_PROVIDER
.getReserveCaps(proposal.USDe());
assertEq(supplyCap, 50_000_000);
assertEq(borrowCap, 40_000_000);
assertTrue(AaveV3MegaEth.AAVE_PROTOCOL_DATA_PROVIDER.getFlashLoanEnabled(proposal.USDe()));
assertEq(AaveV3MegaEth.AAVE_PROTOCOL_DATA_PROVIDER.getDebtCeiling(proposal.USDe()), 0);
}
function _findEModeCategoryId(string memory label) internal view returns (uint8) {
for (uint8 i = 1; i < 255; i++) {
if (
keccak256(bytes(AaveV3MegaEth.POOL.getEModeCategoryLabel(i))) == keccak256(bytes(label))
) {
return i;
}
}
revert('eMode category not found');
}
}