@@ -19,34 +19,44 @@ import {ReserveConfiguration} from "aave-v3-origin/contracts/protocol/libraries/
1919import {GhoDirectMinter} from "../src/GhoDirectMinter.sol " ;
2020import {LidoGHOListing} from "../src/proposals/LidoGHOListing.sol " ;
2121import {IGhoToken} from "../src/interfaces/IGhoToken.sol " ;
22+ import {DeploymentLibrary} from "../script/Deploy.s.sol " ;
2223
2324contract Lido_GHODirectMinter_Test is Test {
2425 using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
2526
27+ // its the council used on other GHO stewards
28+ // might make sense to have on address book
29+ address council = 0x8513e6F37dBc52De87b166980Fa3F50639694B60 ;
30+
2631 GhoDirectMinter internal minter;
2732 IERC20 internal ghoAToken;
2833 LidoGHOListing internal proposal;
2934
30- address council = makeAddr ("council " );
3135 address owner = GovernanceV3Ethereum.EXECUTOR_LVL_1;
3236
3337 function setUp () external {
34- vm.createSelectFork (vm.rpcUrl ("mainnet " ), 21265036 );
38+ vm.createSelectFork (vm.rpcUrl ("mainnet " ), 21378878 );
39+
40+ // execute pending gho listing payload
41+ GovV3Helpers.executePayload (vm, 218 );
3542
3643 // execute payload
37- proposal = new LidoGHOListing (council);
44+ address facilitator = DeploymentLibrary._deployLido ();
45+ proposal = new LidoGHOListing (facilitator);
3846 GovV3Helpers.executePayload (vm, address (proposal));
3947
4048 address [] memory facilitators = IGhoToken (AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorsList ();
4149 minter = GhoDirectMinter (facilitators[facilitators.length - 1 ]);
50+ assertEq (address (minter), facilitator);
4251 ghoAToken = IERC20 (minter.GHO_A_TOKEN ());
4352
4453 // burn all supply to start with a clean state on the tests
54+ uint256 totalATokenSupply = ghoAToken.totalSupply ();
4555 uint128 mintAmount = proposal.GHO_MINT_AMOUNT ();
4656 vm.prank (owner);
4757 minter.withdrawAndBurn (mintAmount);
4858 assertEq (ghoAToken.balanceOf (address (minter)), 0 );
49- assertEq (ghoAToken.totalSupply (), 0 );
59+ assertEq (ghoAToken.totalSupply (), totalATokenSupply - mintAmount );
5060 }
5161
5262 function test_mintAndSupply_owner (uint256 amount ) public returns (uint256 ) {
@@ -90,33 +100,68 @@ contract Lido_GHODirectMinter_Test is Test {
90100 // generate some yield
91101 vm.warp (block .timestamp + 1000 );
92102
103+ uint256 collectorBalanceBeforeTransfer = ghoAToken.balanceOf (address (minter.COLLECTOR ()));
93104 uint256 balanceBeforeTransfer = ghoAToken.balanceOf (address (minter));
94105 assertGt (balanceBeforeTransfer, amount);
95106 minter.transferExcessToTreasury ();
96107 assertApproxEqAbs (ghoAToken.balanceOf (address (minter)), amount, 1 );
97- assertApproxEqAbs (ghoAToken.balanceOf (address (minter.COLLECTOR ())), balanceBeforeTransfer - amount, 1 );
108+ assertApproxEqAbs (
109+ ghoAToken.balanceOf (address (minter.COLLECTOR ())) - collectorBalanceBeforeTransfer,
110+ balanceBeforeTransfer - amount,
111+ 1
112+ );
98113 }
99114
115+ /// @dev supplies a bounded value of [amount, 1, type(uint256).max] to the pool
100116 function _mintAndSupply (uint256 amount , address caller ) internal returns (uint256 ) {
117+ // setup
101118 amount = bound (amount, 1 , proposal.GHO_MINT_AMOUNT ());
102119 DataTypes.ReserveConfigurationMap memory configurationBefore =
103120 AaveV3EthereumLido.POOL.getConfiguration (AaveV3EthereumAssets.GHO_UNDERLYING);
121+ uint256 totalATokenSupplyBefore = ghoAToken.totalSupply ();
122+ uint256 minterATokenSupplyBefore = IERC20 (ghoAToken).balanceOf (address (minter));
123+ (, uint256 levelBefore ) =
124+ IGhoToken (AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorBucket (proposal.FACILITATOR ());
125+
126+ // mint
104127 vm.prank (caller);
105128 minter.mintAndSupply (amount);
129+
130+ // check
106131 DataTypes.ReserveConfigurationMap memory configurationAfter =
107132 AaveV3EthereumLido.POOL.getConfiguration (AaveV3EthereumAssets.GHO_UNDERLYING);
108- assertEq (IERC20 (ghoAToken).balanceOf (address (minter)), amount);
109- assertEq (ghoAToken.totalSupply (), amount);
133+ (, uint256 levelAfter ) = IGhoToken (AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorBucket (proposal.FACILITATOR ());
134+ // after supplying the minters aToken balance should increase by the supplied amount
135+ assertEq (IERC20 (ghoAToken).balanceOf (address (minter)), minterATokenSupplyBefore + amount);
136+ // the aToken total supply should be adjusted by the same amount
137+ assertEq (ghoAToken.totalSupply (), totalATokenSupplyBefore + amount);
138+ // the cap should not be touched
110139 assertEq (configurationBefore.getSupplyCap (), configurationAfter.getSupplyCap ());
140+ // level should be increased by the minted amount
141+ assertEq (levelAfter, levelBefore + amount);
111142 return amount;
112143 }
113144
145+ // burns a bounded value of [withdrawAmount, 1, boundedSupplyAmount] from the pool
114146 function _withdrawAndBurn (uint256 supplyAmount , uint256 withdrawAmount , address caller ) internal {
115- uint256 amount = test_mintAndSupply_owner (supplyAmount);
147+ // setup
148+ uint256 amount = _mintAndSupply (supplyAmount, owner);
116149 withdrawAmount = bound (withdrawAmount, 1 , amount);
150+ uint256 totalATokenSupplyBefore = ghoAToken.totalSupply ();
151+ (, uint256 levelBefore ) =
152+ IGhoToken (AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorBucket (proposal.FACILITATOR ());
153+
154+ // burn
117155 vm.prank (caller);
118- minter.withdrawAndBurn (amount);
119- assertEq (IERC20 (ghoAToken).balanceOf (address (minter)), 0 );
120- assertEq (ghoAToken.totalSupply (), 0 );
156+ minter.withdrawAndBurn (withdrawAmount);
157+
158+ // check
159+ (, uint256 levelAfter ) = IGhoToken (AaveV3EthereumAssets.GHO_UNDERLYING).getFacilitatorBucket (proposal.FACILITATOR ());
160+ // aToken total supply should be decreased by the burned amount
161+ assertEq (ghoAToken.totalSupply (), totalATokenSupplyBefore - withdrawAmount);
162+ // the minter supply should shrink by the same amount
163+ assertEq (IERC20 (ghoAToken).balanceOf (address (minter)), amount - withdrawAmount);
164+ // the minter level should shrink by the same amount
165+ assertEq (levelAfter, levelBefore - withdrawAmount);
121166 }
122167}
0 commit comments