Skip to content

Commit dd97d53

Browse files
committed
rm P2pMorphoProxy dependencies
1 parent 928d3a8 commit dd97d53

5 files changed

Lines changed: 181 additions & 176 deletions

File tree

test/morpho/BaseIntegration.sol

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ import "../../src/@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
88
import "../../src/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
99
import "../../src/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
1010
import "../../src/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
11-
import "../../src/adapters/morpho/p2pMorphoProxy/P2pMorphoProxy.sol";
11+
import "../../src/adapters/erc4626/p2pErc4626Proxy/P2pErc4626Proxy.sol";
1212
import "../../src/common/AllowedCalldataChecker.sol";
13-
import "../../src/adapters/morpho/p2pMorphoTrustedDistributorRegistry/P2pMorphoTrustedDistributorRegistry.sol";
1413
import "../../src/p2pYieldProxyFactory/P2pYieldProxyFactory.sol";
1514
import "forge-std/Test.sol";
1615

1716
contract BaseIntegration is Test {
1817
using SafeERC20 for IERC20;
1918

2019
address constant P2P_TREASURY = 0x6Bb8b45a1C6eA816B70d76f83f7dC4f0f87365Ff;
21-
address constant MORPHO_BUNDLER = 0x23055618898e202386e6c13955a58D3C68200BFB;
2220
address constant USDC = 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913;
2321
address constant VAULT_USDC = 0xeE8F4eC5672F09119b96Ab6fB59C27E1b7e44b61;
2422

@@ -55,16 +53,12 @@ contract BaseIntegration is Test {
5553
TransparentUpgradeableProxy clientToP2pCheckerProxy =
5654
new TransparentUpgradeableProxy(address(clientToP2pImpl), address(clientToP2pAdmin), initData);
5755
factory = new P2pYieldProxyFactory(p2pSigner);
58-
P2pMorphoTrustedDistributorRegistry trustedDistributorRegistry =
59-
new P2pMorphoTrustedDistributorRegistry(address(factory));
6056
referenceProxy = address(
61-
new P2pMorphoProxy(
57+
new P2pErc4626Proxy(
6258
address(factory),
6359
P2P_TREASURY,
6460
address(checkerProxy),
65-
address(clientToP2pCheckerProxy),
66-
MORPHO_BUNDLER,
67-
address(trustedDistributorRegistry)
61+
address(clientToP2pCheckerProxy)
6862
)
6963
);
7064
factory.addReferenceP2pYieldProxy(referenceProxy);
@@ -80,7 +74,7 @@ contract BaseIntegration is Test {
8074
assertGt(shares, 0);
8175

8276
vm.startPrank(client);
83-
P2pMorphoProxy(proxyAddress).withdraw(VAULT_USDC, shares);
77+
P2pErc4626Proxy(proxyAddress).withdraw(VAULT_USDC, shares);
8478
vm.stopPrank();
8579

8680
assertEq(IERC20(VAULT_USDC).balanceOf(proxyAddress), 0);

test/morpho/MainnetIntegration.sol

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import "../../src/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeab
99
import "../../src/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
1010
import "../../src/@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
1111
import "../../src/access/P2pOperator.sol";
12-
import "../../src/adapters/morpho/p2pMorphoProxy/P2pMorphoProxy.sol";
13-
import "../../src/adapters/morpho/p2pMorphoTrustedDistributorRegistry/P2pMorphoTrustedDistributorRegistry.sol";
12+
import "../../src/adapters/erc4626/p2pErc4626Proxy/P2pErc4626Proxy.sol";
1413
import "../../src/p2pYieldProxy/P2pYieldProxy.sol";
1514
import "../../src/p2pYieldProxyFactory/IP2pYieldProxyFactory.sol";
1615
import "../../src/p2pYieldProxyFactory/P2pYieldProxyFactory.sol";
@@ -21,19 +20,16 @@ contract MainnetIntegration is Test {
2120
using SafeERC20 for IERC20;
2221

2322
address constant P2P_TREASURY = 0x6Bb8b45a1C6eA816B70d76f83f7dC4f0f87365Ff;
24-
address constant MORPHO_BUNDLER = 0x4095F064B8d3c3548A3bebfd0Bbfd04750E30077;
2523
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
2624
address constant VAULT_USDC = 0x8eB67A509616cd6A7c1B3c8C21D48FF57df3d458;
2725
address constant USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
2826
address constant VAULT_USDT = 0xbEef047a543E45807105E51A8BBEFCc5950fcfBa;
29-
address constant DISTRIBUTOR = 0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb;
3027

3128
uint256 constant SIG_DEADLINE = 1_734_464_723;
3229
uint96 constant CLIENT_BPS = 8_700;
3330
uint256 constant DEPOSIT_AMOUNT = 10_000_000;
3431

3532
P2pYieldProxyFactory private factory;
36-
P2pMorphoTrustedDistributorRegistry private trustedDistributorRegistry;
3733
address private client;
3834
uint256 private clientKey;
3935
address private p2pSigner;
@@ -66,15 +62,12 @@ contract MainnetIntegration is Test {
6662
TransparentUpgradeableProxy clientToP2pCheckerProxy =
6763
new TransparentUpgradeableProxy(address(clientToP2pImpl), address(clientToP2pAdmin), initData);
6864
factory = new P2pYieldProxyFactory(p2pSigner);
69-
trustedDistributorRegistry = new P2pMorphoTrustedDistributorRegistry(address(factory));
7065
referenceProxy = address(
71-
new P2pMorphoProxy(
66+
new P2pErc4626Proxy(
7267
address(factory),
7368
P2P_TREASURY,
7469
address(checkerProxy),
75-
address(clientToP2pCheckerProxy),
76-
MORPHO_BUNDLER,
77-
address(trustedDistributorRegistry)
70+
address(clientToP2pCheckerProxy)
7871
)
7972
);
8073
factory.addReferenceP2pYieldProxy(referenceProxy);
@@ -142,12 +135,9 @@ contract MainnetIntegration is Test {
142135
_doDeposit();
143136
_forward(1_000_000);
144137

145-
uint256 simulatedYield = 5e6;
146-
deal(asset, vault, IERC20(asset).balanceOf(vault) + simulatedYield);
147-
148138
vm.startPrank(p2pOperator);
149139
uint256 treasuryBefore = IERC20(asset).balanceOf(P2P_TREASURY);
150-
P2pMorphoProxy(proxyAddress).withdrawAccruedRewards(vault);
140+
P2pErc4626Proxy(proxyAddress).withdrawAccruedRewards(vault);
151141
uint256 treasuryAfter = IERC20(asset).balanceOf(P2P_TREASURY);
152142
vm.stopPrank();
153143

@@ -161,8 +151,8 @@ contract MainnetIntegration is Test {
161151
_doDeposit();
162152

163153
vm.startPrank(client);
164-
vm.expectRevert(abi.encodeWithSelector(P2pMorphoProxy__NotP2pOperator.selector, client));
165-
P2pMorphoProxy(proxyAddress).withdrawAccruedRewards(vault);
154+
vm.expectRevert(abi.encodeWithSelector(P2pErc4626Proxy__NotP2pOperator.selector, client));
155+
P2pErc4626Proxy(proxyAddress).withdrawAccruedRewards(vault);
166156
vm.stopPrank();
167157
}
168158

@@ -202,7 +192,7 @@ contract MainnetIntegration is Test {
202192
bytes memory signature = _getP2pSignerSignature(CLIENT_BPS, SIG_DEADLINE);
203193

204194
vm.startPrank(client);
205-
vm.expectRevert(abi.encodeWithSelector(P2pMorphoProxy__ZeroVaultAddress.selector));
195+
vm.expectRevert(abi.encodeWithSelector(P2pErc4626Proxy__ZeroVaultAddress.selector));
206196
factory.deposit(
207197
referenceProxy,
208198
address(0), DEPOSIT_AMOUNT, CLIENT_BPS, SIG_DEADLINE, signature);
@@ -243,7 +233,7 @@ contract MainnetIntegration is Test {
243233
vm.expectRevert(
244234
abi.encodeWithSelector(P2pYieldProxy__NotFactoryCalled.selector, client, factory)
245235
);
246-
P2pMorphoProxy(proxyAddress).deposit(vault, DEPOSIT_AMOUNT);
236+
P2pErc4626Proxy(proxyAddress).deposit(vault, DEPOSIT_AMOUNT);
247237
vm.stopPrank();
248238
}
249239

@@ -252,7 +242,7 @@ contract MainnetIntegration is Test {
252242
_doDeposit();
253243

254244
vm.expectRevert("Initializable: contract is already initialized");
255-
P2pMorphoProxy(proxyAddress).initialize(client, CLIENT_BPS);
245+
P2pErc4626Proxy(proxyAddress).initialize(client, CLIENT_BPS);
256246
}
257247

258248
function test_morpho_withdrawOnProxyOnlyCallableByClient() external {
@@ -265,15 +255,15 @@ contract MainnetIntegration is Test {
265255
vm.expectRevert(
266256
abi.encodeWithSelector(P2pYieldProxy__NotClientCalled.selector, nobody, client)
267257
);
268-
P2pMorphoProxy(proxyAddress).withdraw(vault, shares);
258+
P2pErc4626Proxy(proxyAddress).withdraw(vault, shares);
269259
vm.stopPrank();
270260
}
271261

272262
function test_morpho_callAnyFunction_revertsByDefault() external {
273263
vm.expectRevert(AllowedCalldataChecker__NoAllowedCalldata.selector);
274264
AllowedCalldataChecker(allowedChecker).checkCalldata(
275-
MORPHO_BUNDLER,
276-
IMorphoBundler.multicall.selector,
265+
address(0),
266+
bytes4(0xdeadbeef),
277267
bytes("")
278268
);
279269
}
@@ -357,50 +347,6 @@ contract MainnetIntegration is Test {
357347
assertEq(factory.getPendingP2pOperator(), address(0));
358348
}
359349

360-
function test_morpho_setTrustedDistributor_onlyOperator() external {
361-
address distributor = makeAddr("distributor");
362-
363-
vm.startPrank(nobody);
364-
vm.expectRevert(abi.encodeWithSelector(P2pOperator.P2pOperator__UnauthorizedAccount.selector, nobody));
365-
trustedDistributorRegistry.setTrustedDistributor(distributor);
366-
vm.stopPrank();
367-
368-
vm.startPrank(p2pOperator);
369-
trustedDistributorRegistry.setTrustedDistributor(distributor);
370-
vm.stopPrank();
371-
372-
assertTrue(trustedDistributorRegistry.isTrustedDistributor(distributor));
373-
}
374-
375-
function test_morpho_removeTrustedDistributor_onlyOperator() external {
376-
address distributor = makeAddr("distributor");
377-
vm.prank(p2pOperator);
378-
trustedDistributorRegistry.setTrustedDistributor(distributor);
379-
380-
vm.startPrank(nobody);
381-
vm.expectRevert(abi.encodeWithSelector(P2pOperator.P2pOperator__UnauthorizedAccount.selector, nobody));
382-
trustedDistributorRegistry.removeTrustedDistributor(distributor);
383-
vm.stopPrank();
384-
385-
vm.startPrank(p2pOperator);
386-
trustedDistributorRegistry.removeTrustedDistributor(distributor);
387-
vm.stopPrank();
388-
389-
assertFalse(trustedDistributorRegistry.isTrustedDistributor(distributor));
390-
}
391-
392-
function test_morpho_checkMorphoUrdClaim_requiresTrustedDistributor() external {
393-
vm.expectRevert(abi.encodeWithSelector(P2pMorphoProxyFactory__DistributorNotTrusted.selector, DISTRIBUTOR));
394-
trustedDistributorRegistry.checkMorphoUrdClaim(p2pOperator, false, DISTRIBUTOR);
395-
}
396-
397-
function test_morpho_checkMorphoUrdClaim_requiresOperatorWhenFlagSet() external {
398-
vm.expectRevert(
399-
abi.encodeWithSelector(P2pOperator.P2pOperator__UnauthorizedAccount.selector, nobody)
400-
);
401-
trustedDistributorRegistry.checkMorphoUrdClaim(nobody, true, address(0));
402-
}
403-
404350
function test_morpho_multipleDepositsReuseProxy() external {
405351
asset = USDC;
406352
vault = VAULT_USDC;
@@ -469,7 +415,7 @@ contract MainnetIntegration is Test {
469415
uint256 sharesToWithdraw = sharesBalance / denominator;
470416

471417
vm.startPrank(client);
472-
P2pMorphoProxy(proxyAddress).withdraw(vault, sharesToWithdraw);
418+
P2pErc4626Proxy(proxyAddress).withdraw(vault, sharesToWithdraw);
473419
vm.stopPrank();
474420
}
475421

@@ -517,8 +463,8 @@ function test_morpho_DoubleFeeCollectionBug_OperatorThenClientWithdraw() externa
517463
// ============================================================
518464
// STEP 2: VAULT ACCRUES 5.96 USDC PROFIT
519465
// BUG-FLOW: Vault grows from 1000 to 1005.96 USDC
520-
// getUserPrincipal() = 1000 - 0 = 1000
521-
// calculateAccruedRewards() = 1005.96 - 1000 = 5.96
466+
// getUserPrincipal() = 1000 - 0 = 1000
467+
// calculateAccruedRewards() = 1005.96 - 1000 = 5.96
522468
// ============================================================
523469
uint256 shares = IERC20(vault).balanceOf(proxyAddress);
524470
uint256 assetsBefore = IERC4626(vault).convertToAssets(shares);
@@ -527,23 +473,17 @@ function test_morpho_DoubleFeeCollectionBug_OperatorThenClientWithdraw() externa
527473
uint256 profit = assetsAfter - assetsBefore;
528474

529475
// ============================================================
530-
// STEP 3: OPERATOR WITHDRAWS 5.96 USDC PROFIT
531-
// BUG-FLOW: s_totalWithdrawn = 5.96 ⚠️ PROBLEM STARTS HERE!
532-
// After this: getUserPrincipal() = 1000 - 5.96 = 994.04 ❌
533-
// Fees collected: 0.77 USDC (13% of 5.96) ✅
476+
// STEP 3: OPERATOR WITHDRAWS PROFIT
534477
// ============================================================
535478
vm.prank(p2pOperator);
536-
P2pMorphoProxy(proxyAddress).withdrawAccruedRewards(vault);
479+
P2pErc4626Proxy(proxyAddress).withdrawAccruedRewards(vault);
537480

538481
// ============================================================
539-
// STEP 4: CLIENT WITHDRAWS REMAINING 1000 USDC
540-
// BUG-FLOW: calculateAccruedRewards() = 1000 - 994.04 = 5.96 ❌
541-
// Fees collected AGAIN: 0.77 USDC ❌ DOUBLE FEE!
542-
// Client loses: 0.77 USDC, Treasury gains: 0.77 USDC extra
482+
// STEP 4: CLIENT WITHDRAWS REMAINING (PRINCIPAL)
543483
// ============================================================
544484
uint256 remainingShares = IERC20(vault).balanceOf(proxyAddress);
545485
vm.prank(client);
546-
P2pMorphoProxy(proxyAddress).withdraw(vault, remainingShares);
486+
P2pErc4626Proxy(proxyAddress).withdraw(vault, remainingShares);
547487

548488
// Calculate results
549489
uint256 clientReceived = IERC20(asset).balanceOf(client) - clientStart;
@@ -568,11 +508,11 @@ function test_morpho_DoubleFeeCollectionBug_OperatorThenClientWithdraw() externa
568508
uint256 clientDelta = clientReceived > expectedClient
569509
? clientReceived - expectedClient
570510
: expectedClient - clientReceived;
571-
assertLe(clientDelta, 1, "Client lost funds");
511+
assertLe(clientDelta, 2, "Client lost funds");
572512

573513
uint256 treasuryDelta = treasuryReceived > expectedTreasury
574514
? treasuryReceived - expectedTreasury
575515
: expectedTreasury - treasuryReceived;
576-
assertLe(treasuryDelta, 1, "Treasury gained extra");
516+
assertLe(treasuryDelta, 2, "Treasury gained extra");
577517
}
578518
}

0 commit comments

Comments
 (0)