Skip to content

Commit e60f51c

Browse files
committed
fix: add BASIS_POINT_DIVISOR for clarity instead of using 10000 everywhere. add better admin contract tests
1 parent ee2ebf4 commit e60f51c

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

packages/libs/contracts-sdk/test/fees/AaveFeeForkTest.t.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {USDC} from "../ABIs/USDC.sol";
1818
import {IPool} from "@aave-dao/aave-v3-origin/src/contracts/interfaces/IPool.sol";
1919
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
2020

21-
contract FeeForkTest is Test {
21+
contract AaveFeeForkTest is Test {
22+
uint256 constant BASIS_POINT_DIVISOR = 10000;
23+
2224
address owner;
2325
address APP_USER_ALICE = makeAddr("Alice");
2426
// real aave pool from https://aave.com/docs/resources/addresses
@@ -148,8 +150,8 @@ contract FeeForkTest is Test {
148150
uint256 feeContractBalance = underlyingERC20.balanceOf(address(aavePerfFeeFacet));
149151

150152
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
151-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
152-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
153+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
154+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
153155
console.log("expectedTotalProfit", expectedTotalProfit);
154156
console.log("expectedUserProfit", expectedUserProfit);
155157
console.log("expectedFeeContractProfit", expectedFeeContractProfit);
@@ -362,8 +364,8 @@ contract FeeForkTest is Test {
362364
uint256 feeContractBalance = underlyingERC20.balanceOf(address(aavePerfFeeFacet));
363365

364366
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
365-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
366-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
367+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
368+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
367369
console.log("expectedTotalProfit", expectedTotalProfit);
368370
console.log("expectedUserProfit", expectedUserProfit);
369371
console.log("expectedFeeContractProfit", expectedFeeContractProfit);

packages/libs/contracts-sdk/test/fees/AerodromeFeeForkTest.t.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {USDC} from "../ABIs/USDC.sol";
1818
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
1919
import {IRouter} from "@aerodrome/contracts/interfaces/IRouter.sol";
2020

21-
contract FeeForkTest is Test {
21+
contract AerodromeFeeForkTest is Test {
22+
uint256 constant BASIS_POINT_DIVISOR = 10000;
23+
2224
address owner;
2325
address APP_USER_ALICE = makeAddr("Alice");
2426
// real aerodrome router on base from https://www.aerodrome.finance/security
@@ -117,7 +119,7 @@ contract FeeForkTest is Test {
117119
// the user swapped all their USDC to WETH, so their balance should be 0
118120
assertEq(userBalance, 0);
119121

120-
uint256 expectedFee = swapAmount * swapFeePercentage / 10000;
122+
uint256 expectedFee = swapAmount * swapFeePercentage / BASIS_POINT_DIVISOR;
121123
assertEq(feeContractBalance, expectedFee);
122124

123125
// test that USDC is in the set of tokens that have collected fees
@@ -183,7 +185,7 @@ contract FeeForkTest is Test {
183185
// the user swapped all their USDC to WETH, so their balance should be 0
184186
assertEq(userBalance, 0);
185187

186-
uint256 expectedFee = swapAmount * swapFeePercentage / 10000;
188+
uint256 expectedFee = swapAmount * swapFeePercentage / BASIS_POINT_DIVISOR;
187189
assertEq(feeContractBalance, expectedFee);
188190

189191
// test that USDC is in the set of tokens that have collected fees

packages/libs/contracts-sdk/test/fees/Fee.t.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,49 @@ contract FeeTest is Test {
8989
vm.stopPrank();
9090
assertEq(feeAdminFacet.aavePool(), NEW_AAVE_POOL);
9191
}
92+
93+
function testSetAerodromeRouter() public {
94+
address NEW_AERODROME_ROUTER = makeAddr("AerodromeRouter");
95+
assertNotEq(feeAdminFacet.aerodromeRouter(), NEW_AERODROME_ROUTER);
96+
97+
// test that a non-owner cannot set the aerodrome router
98+
vm.expectRevert(FeeUtils.CallerNotOwner.selector);
99+
feeAdminFacet.setAerodromeRouter(NEW_AERODROME_ROUTER);
100+
101+
// test that the owner can set the aerodrome router
102+
vm.startPrank(owner);
103+
feeAdminFacet.setAerodromeRouter(NEW_AERODROME_ROUTER);
104+
vm.stopPrank();
105+
assertEq(feeAdminFacet.aerodromeRouter(), NEW_AERODROME_ROUTER);
106+
}
107+
108+
function testSetSwapFeePercentage() public {
109+
uint256 NEW_SWAP_FEE_PERCENTAGE = 5;
110+
assertNotEq(feeAdminFacet.swapFeePercentage(), NEW_SWAP_FEE_PERCENTAGE);
111+
112+
// test that a non-owner cannot set the aerodrome router
113+
vm.expectRevert(FeeUtils.CallerNotOwner.selector);
114+
feeAdminFacet.setSwapFeePercentage(NEW_SWAP_FEE_PERCENTAGE);
115+
116+
// test that the owner can set the swap fee percentage
117+
vm.startPrank(owner);
118+
feeAdminFacet.setSwapFeePercentage(NEW_SWAP_FEE_PERCENTAGE);
119+
vm.stopPrank();
120+
assertEq(feeAdminFacet.swapFeePercentage(), NEW_SWAP_FEE_PERCENTAGE);
121+
}
122+
123+
function testSetPerformanceFeePercentage() public {
124+
uint256 NEW_PERFORMANCE_FEE_PERCENTAGE = 5;
125+
assertNotEq(feeAdminFacet.performanceFeePercentage(), NEW_PERFORMANCE_FEE_PERCENTAGE);
126+
127+
// test that a non-owner cannot set the performance fee percentage
128+
vm.expectRevert(FeeUtils.CallerNotOwner.selector);
129+
feeAdminFacet.setPerformanceFeePercentage(NEW_PERFORMANCE_FEE_PERCENTAGE);
130+
131+
// test that the owner can set the performance fee percentage
132+
vm.startPrank(owner);
133+
feeAdminFacet.setPerformanceFeePercentage(NEW_PERFORMANCE_FEE_PERCENTAGE);
134+
vm.stopPrank();
135+
assertEq(feeAdminFacet.performanceFeePercentage(), NEW_PERFORMANCE_FEE_PERCENTAGE);
136+
}
92137
}

packages/libs/contracts-sdk/test/fees/MorphoFee.t.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import {OwnershipFacet} from "../../contracts/diamond-base/facets/OwnershipFacet
1717
import {MockERC4626} from "../mocks/MockERC4626.sol";
1818
import {MockERC20} from "../mocks/MockERC20.sol";
1919

20-
contract FeeTest is Test {
20+
contract MorphoFeeTest is Test {
21+
uint256 constant BASIS_POINT_DIVISOR = 10000;
22+
2123
address owner;
2224
address APP_USER_ALICE = makeAddr("Alice");
2325

@@ -112,8 +114,8 @@ contract FeeTest is Test {
112114
uint256 feeContractBalance = mockERC20.balanceOf(address(morphoPerfFeeFacet));
113115

114116
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
115-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
116-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
117+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
118+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
117119
console.log("expectedTotalProfit", expectedTotalProfit);
118120
console.log("expectedUserProfit", expectedUserProfit);
119121
console.log("expectedFeeContractProfit", expectedFeeContractProfit);
@@ -228,8 +230,8 @@ contract FeeTest is Test {
228230
uint256 feeContractBalance = mockERC20.balanceOf(address(morphoPerfFeeFacet));
229231

230232
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
231-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
232-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
233+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
234+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
233235
console.log("expectedTotalProfit", expectedTotalProfit);
234236
console.log("expectedUserProfit", expectedUserProfit);
235237
console.log("expectedFeeContractProfit", expectedFeeContractProfit);

packages/libs/contracts-sdk/test/fees/MorphoFeeForkTest.t.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import {USDC} from "../ABIs/USDC.sol";
1818
import {MorphoVault} from "../ABIs/MorphoVault.sol";
1919
import {Morpho} from "../ABIs/Morpho.sol";
2020

21-
contract FeeForkTest is Test {
21+
contract MorphoFeeForkTest is Test {
22+
uint256 constant BASIS_POINT_DIVISOR = 10000;
23+
2224
address owner;
2325
address APP_USER_ALICE = makeAddr("Alice");
2426
// real morpho vault on base from https://app.morpho.org/base/vault/0x7BfA7C4f149E7415b73bdeDfe609237e29CBF34A/spark-usdc-vault
@@ -152,8 +154,8 @@ contract FeeForkTest is Test {
152154
uint256 feeContractBalance = underlyingERC20.balanceOf(address(morphoPerfFeeFacet));
153155

154156
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
155-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
156-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
157+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
158+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
157159
console.log("expectedTotalProfit", expectedTotalProfit);
158160
console.log("expectedUserProfit", expectedUserProfit);
159161
console.log("expectedFeeContractProfit", expectedFeeContractProfit);
@@ -356,8 +358,8 @@ contract FeeForkTest is Test {
356358
uint256 feeContractBalance = underlyingERC20.balanceOf(address(morphoPerfFeeFacet));
357359

358360
uint256 expectedTotalProfit = expectedTotalWithdrawal - depositAmount;
359-
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / 10000);
360-
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / 10000;
361+
uint256 expectedUserProfit = expectedTotalProfit - (expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR);
362+
uint256 expectedFeeContractProfit = expectedTotalProfit * performanceFeePercentage / BASIS_POINT_DIVISOR;
361363
console.log("expectedTotalProfit", expectedTotalProfit);
362364
console.log("expectedUserProfit", expectedUserProfit);
363365
console.log("expectedFeeContractProfit", expectedFeeContractProfit);

0 commit comments

Comments
 (0)