@@ -13,7 +13,6 @@ import {MockMorphoAllocator} from "test/mock/request/MockMorphoAllocator.sol";
1313import {Offer} from "src/interfaces/request/IOfferReceiver.sol " ;
1414import {LibCommonErrors} from "src/libs/common/LibCommonErrors.sol " ;
1515import {MockERC20} from "test/mock/MockERC20.sol " ;
16- import {MockBorrowPosition} from "test/mock/borrow/MockBorrowPosition.sol " ;
1716import {Mode, State} from "src/libs/funds/Order.sol " ;
1817import {IntentProperties, Asset} from "src/libs/facility/LibIntent.sol " ;
1918import {WithdrawalStrategy} from "src/interfaces/manager/base/IPositionManagerAdmin.sol " ;
@@ -946,15 +945,14 @@ contract MorphoFlashLoanRequestTest is FacilityBaseTest {
946945 assertEq (collateralToken.balanceOf (address (facility)), 0 );
947946 }
948947
949- function test_execute_syncMidasWithdrawalCommitUnlock ( ) public {
948+ function testFuzz_execute_syncMidasWithdrawalCommitUnlock ( bool proportional ) public {
950949 uint256 morphoBalBefore = debtToken.balanceOf (address (morpho));
951950 vm.prank (facilitator);
952951 facility.depositManager (intentId, 0 , 5_000e18 , false );
953952
954- // A price drop makes the live LTV exceed the requested 50% target.
955- oracle.setPrice (0.9e36 );
956953 uint256 withdrawAmount = 1_000e18 ;
957- uint256 repayAmount = 950e18 ; // 5,000 - (10,000 - 1,000) * 0.9 * 0.5
954+ uint256 repayAmount = 500e18 ;
955+ WithdrawalStrategy strategy = proportional ? WithdrawalStrategy.PROPORTIONAL : WithdrawalStrategy.SEQUENTIAL;
958956 vm.prank (facilitator);
959957 _setFund (intentId, address (mockFund));
960958 // MockFund represents the remaining redemption at the script's facility boundary.
@@ -969,67 +967,23 @@ contract MorphoFlashLoanRequestTest is FacilityBaseTest {
969967 repayAmount,
970968 _buildSetRequestParams (intentId, block .timestamp + 1 hours),
971969 address (syncMidasWithdrawal),
972- abi.encodeCall (SyncMidasWithdrawal.run, (address (facility), intentId, withdrawAmount, 0.5e18 , false ))
970+ abi.encodeCall (
971+ SyncMidasWithdrawal.run, (address (facility), intentId, withdrawAmount, repayAmount, false , strategy)
972+ )
973973 );
974974
975975 assertEq (positionManager.collateralAmount (), 9_000e18 );
976- assertEq (positionManager.debtAmount (), 4_050e18 );
977- assertEq (positionManager.debtAmount () * 1e18 / positionManager.collateralAmountQuoted (), 0.5e18 );
976+ assertEq (positionManager.debtAmount (), 4_500e18 );
978977 assertEq (collateralToken.balanceOf (address (mockFund)), withdrawAmount);
979978 assertEq (collateralToken.balanceOf (address (facility)), 0 );
980- assertEq (debtToken.balanceOf (address (facility)), 5_050e18 );
981- assertEq (debtToken.balanceOf (address (morpho)), morphoBalBefore - 4_050e18 );
979+ assertEq (debtToken.balanceOf (address (facility)), 5_500e18 );
980+ assertEq (debtToken.balanceOf (address (morpho)), morphoBalBefore - 4_500e18 );
982981 assertEq (debtToken.balanceOf (address (flashLoanRequest)), 0 );
983982 (, address fund , address request ,) = facility.getIntent (intentId);
984983 assertEq (fund, address (0 ));
985984 assertEq (request, address (0 ));
986985 }
987986
988- function test_syncMidasWithdrawal_rejectsInvalidParameters () public {
989- vm.expectRevert (SyncMidasWithdrawal.InvalidTargetLtv.selector );
990- syncMidasWithdrawal.run (address (facility), intentId, 1 , 1e18 , false );
991- vm.expectRevert (SyncMidasWithdrawal.InvalidPositionManager.selector );
992- syncMidasWithdrawal.run (address (facility), intentId, 1 , 0.5e18 , true );
993- vm.expectRevert (SyncMidasWithdrawal.InvalidWithdrawAmount.selector );
994- syncMidasWithdrawal.run (address (facility), intentId, 0 , 0.5e18 , false );
995- uint256 tooMuch = positionManager.collateralAmount () + 1 ;
996- vm.expectRevert (SyncMidasWithdrawal.InvalidWithdrawAmount.selector );
997- syncMidasWithdrawal.run (address (facility), intentId, tooMuch, 0.5e18 , false );
998- }
999-
1000- function test_syncMidasWithdrawal_revertsWhenPartialQueueRemovesMoreQuotedCollateral () public {
1001- vm.prank (facilitator);
1002- facility.depositManager (intentId, 0 , 4_500e18 , false );
1003-
1004- // This lower-priced module contributes to the aggregate quote but is excluded from withdrawals.
1005- MockBorrowPosition excluded = new MockBorrowPosition (address (collateralToken), address (debtToken));
1006- excluded.setTotalCollateral (10_000e18 );
1007- excluded.setTotalCollateralQuoted (5_000e18 );
1008- excluded.setSafeLtv (uint128 (PM_LTV));
1009- vm.mockCall (address (excluded), abi.encodeWithSignature ("owner() " ), abi.encode (address (positionManager)));
1010- vm.prank (owner);
1011- positionManager.addBorrowModule (address (excluded));
1012-
1013- uint256 withdrawAmount = 1_000e18 ;
1014- uint256 repayAmount = 225e18 ; // Aggregate quote estimates 750 removed; the queued position removes 1,000.
1015- vm.prank (facilitator);
1016- _setFund (intentId, address (mockFund));
1017- mockFund.setNextCommitState (State.UNLOCKING);
1018- mockFund.setUnlockAmount (withdrawAmount);
1019- debtToken.setBalance (address (mockFund), withdrawAmount);
1020- vm.prank (facilitator);
1021- facility.create (intentId, withdrawAmount, withdrawAmount, Mode.REDEEM);
1022-
1023- vm.prank (executor);
1024- vm.expectRevert (SyncMidasWithdrawal.TargetLtvExceeded.selector );
1025- flashLoanRequest.execute (
1026- repayAmount,
1027- _buildSetRequestParams (intentId, block .timestamp + 1 hours),
1028- address (syncMidasWithdrawal),
1029- abi.encodeCall (SyncMidasWithdrawal.run, (address (facility), intentId, withdrawAmount, 0.3e18 , false ))
1030- );
1031- }
1032-
1033987 /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
1034988 /* I. pullFunds() TESTS */
1035989 /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
0 commit comments