|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity 0.8.7; |
| 3 | + |
| 4 | +import { console } from "../modules/contract-test-utils/contracts/test.sol"; |
| 5 | + |
| 6 | +import { IDebtLockerLike, IERC20Like, IMapleLoanLike, IPoolV1Like } from "../simulations/mainnet/Interfaces.sol"; |
| 7 | + |
| 8 | +import { SimulationBase } from "../simulations/mainnet/SimulationBase.sol"; |
| 9 | + |
| 10 | +contract PayAndRefiUpcomingLoans is SimulationBase { |
| 11 | + |
| 12 | + // Maven Permissioned loans to |
| 13 | + address constant mavenPermissionedLoan1 = 0x500055809685ecebA5eC55786f65440583954501; |
| 14 | + address constant mavenPermissionedLoan2 = 0xa83b134809183c634A692D5b5F457b78Cd6913e6; |
| 15 | + |
| 16 | + // Maven USDC loans |
| 17 | + address constant mavenUsdcLoan1 = 0x245De7E3B9B21B68c2C8D2e4759652F0dbCE65A6; |
| 18 | + address constant mavenUsdcLoan2 = 0x502EE6D0b16d834547Fc44344D4BE3E019Fc2573; |
| 19 | + address constant mavenUsdcLoan3 = 0x726893373DE92b8272298D76a7D60a5F51b90dA9; |
| 20 | + address constant mavenUsdcLoan4 = 0xF6950F28353cA676100C2a92DD360DEa16A213cE; |
| 21 | + address constant mavenUsdcLoan5 = 0xa58fD39138083783689d700758D00873538C6C2A; |
| 22 | + address constant mavenUsdcLoan6 = 0xd027CdD569b6cd1aD13dc82d42d0CD7cDeda3521; |
| 23 | + |
| 24 | + // Maven WETH loans |
| 25 | + address constant mavenWethLoan1 = 0x0104AE451AD2542aC9250Ebe4a37D0717FdfC60C; |
| 26 | + address constant mavenWethLoan2 = 0x91A4eEe4D33d9cd7840CAe21A4f408c0919F555D; |
| 27 | + address constant mavenWethLoan3 = 0xC8c17328796F472A97B7784cc5F52b802A89deC1; |
| 28 | + address constant mavenWethLoan4 = 0x4DbE67c683A731807EAAa99A1DF2D3E79ebECA00; |
| 29 | + address constant mavenWethLoan5 = 0xFcF8725d0D9A786448c5B9b9cc67226d7e4d5c3D; |
| 30 | + address constant mavenWethLoan6 = 0x64982f1aA56340C0051bDCeFb7a69911Fd9D141d; |
| 31 | + address constant mavenWethLoan7 = 0x2cB5c20309B2DbfDda758237f20c94b5F72d0331; |
| 32 | + address constant mavenWethLoan8 = 0x40d9fBe05d8F9f1215D5a6d01994ad1a6a097616; |
| 33 | + address constant mavenWethLoan9 = 0x2872C1140117a5DE85E0DD06Ed1B439D23707AD1; |
| 34 | + address constant mavenWethLoan10 = 0xdeF9146F12e22e5c69Fb7b7D181534240c04FdCE; |
| 35 | + |
| 36 | + // Orthogonal loans |
| 37 | + address constant orthogonalLoan1 = 0x249B5907564f0Cf3Fb771b013A6f9f33e1225657; |
| 38 | + |
| 39 | + address constant usdcWhale = 0x6555e1CC97d3cbA6eAddebBCD7Ca51d75771e0B8; |
| 40 | + address constant wethWhale = 0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3; |
| 41 | + |
| 42 | + function run() external { |
| 43 | + payAllHealthyLoans(); |
| 44 | + claimAllLoans(); |
| 45 | + assertNoClaimableLoans(); |
| 46 | + refinanceAllLoans(); |
| 47 | + } |
| 48 | + |
| 49 | + function payLoan(address loan) internal { |
| 50 | + address fundsAsset = IMapleLoanLike(loan).fundsAsset(); |
| 51 | + |
| 52 | + ( uint256 principal, uint256 interest, uint256 delegateFee, uint256 treasuryFee ) = IMapleLoanLike(loan).getNextPaymentBreakdown(); |
| 53 | + |
| 54 | + uint256 paymentAmount = principal + interest + delegateFee + treasuryFee; |
| 55 | + |
| 56 | + address sender = address(fundsAsset) == usdc ? usdcWhale : wethWhale; |
| 57 | + |
| 58 | + address borrower = IMapleLoanLike(loan).borrower(); |
| 59 | + |
| 60 | + vm.broadcast(sender); |
| 61 | + IERC20Like(fundsAsset).transfer(borrower, paymentAmount); |
| 62 | + |
| 63 | + vm.startBroadcast(IMapleLoanLike(loan).borrower()); |
| 64 | + |
| 65 | + IERC20Like(fundsAsset).approve(address(loan), paymentAmount); |
| 66 | + IMapleLoanLike(loan).makePayment(paymentAmount); |
| 67 | + |
| 68 | + vm.stopBroadcast(); |
| 69 | + } |
| 70 | + |
| 71 | + function payAllHealthyLoans() internal { |
| 72 | + payLoan(mavenPermissionedLoan2); |
| 73 | + } |
| 74 | + |
| 75 | + function assertNotClaimable(address loan) internal { |
| 76 | + assertEq(IMapleLoanLike(loan).claimableFunds(), 0); |
| 77 | + } |
| 78 | + |
| 79 | + function assertNoClaimableLoans() internal { |
| 80 | + assertNotClaimable(mavenPermissionedLoan1); |
| 81 | + assertNotClaimable(mavenPermissionedLoan1); |
| 82 | + |
| 83 | + assertNotClaimable(mavenUsdcLoan1); |
| 84 | + assertNotClaimable(mavenUsdcLoan2); |
| 85 | + assertNotClaimable(mavenUsdcLoan3); |
| 86 | + assertNotClaimable(mavenUsdcLoan4); |
| 87 | + assertNotClaimable(mavenUsdcLoan5); |
| 88 | + assertNotClaimable(mavenUsdcLoan6); |
| 89 | + |
| 90 | + assertNotClaimable(mavenWethLoan1); |
| 91 | + assertNotClaimable(mavenWethLoan2); |
| 92 | + assertNotClaimable(mavenWethLoan3); |
| 93 | + assertNotClaimable(mavenWethLoan4); |
| 94 | + assertNotClaimable(mavenWethLoan5); |
| 95 | + assertNotClaimable(mavenWethLoan6); |
| 96 | + assertNotClaimable(mavenWethLoan7); |
| 97 | + assertNotClaimable(mavenWethLoan8); |
| 98 | + assertNotClaimable(mavenWethLoan9); |
| 99 | + assertNotClaimable(mavenWethLoan10); |
| 100 | + |
| 101 | + assertNotClaimable(orthogonalLoan1); |
| 102 | + } |
| 103 | + |
| 104 | + function refinanceLoan(address poolV1, address loan) internal { |
| 105 | + address borrower = IMapleLoanLike(loan).borrower(); |
| 106 | + address debtLocker = IMapleLoanLike(loan).lender(); |
| 107 | + address poolDelegate = IPoolV1Like(poolV1).poolDelegate(); |
| 108 | + |
| 109 | + bytes[] memory calls = new bytes[](4); |
| 110 | + |
| 111 | + calls[0] = abi.encodeWithSignature("setGracePeriod(uint256)", 0 seconds); |
| 112 | + calls[3] = abi.encodeWithSignature("setLateInterestPremium(uint256)", 0.05e18); |
| 113 | + calls[1] = abi.encodeWithSignature("setPaymentInterval(uint256)", 10 days); |
| 114 | + calls[2] = abi.encodeWithSignature("setPaymentsRemaining(uint256)", 1); |
| 115 | + |
| 116 | + vm.broadcast(borrower); |
| 117 | + IMapleLoanLike(loan).proposeNewTerms(refinancer, type(uint256).max, calls); |
| 118 | + |
| 119 | + vm.broadcast(poolDelegate); |
| 120 | + IDebtLockerLike(debtLocker).acceptNewTerms(refinancer, type(uint256).max, calls, 0); |
| 121 | + |
| 122 | + assertEq(IMapleLoanLike(loan).gracePeriod(), 0 seconds); |
| 123 | + assertEq(IMapleLoanLike(loan).lateInterestPremium(), 0.05e18); |
| 124 | + assertEq(IMapleLoanLike(loan).paymentInterval(), 10 days); |
| 125 | + assertEq(IMapleLoanLike(loan).paymentsRemaining(), 1); |
| 126 | + assertEq(IMapleLoanLike(loan).nextPaymentDueDate(), block.timestamp + 10 days); |
| 127 | + } |
| 128 | + |
| 129 | + function refinanceAllLoans() internal { |
| 130 | + refinanceLoan(mavenPermissionedPoolV1, mavenPermissionedLoan1); |
| 131 | + |
| 132 | + refinanceLoan(mavenUsdcPoolV1, mavenUsdcLoan1); |
| 133 | + refinanceLoan(mavenUsdcPoolV1, mavenUsdcLoan3); |
| 134 | + |
| 135 | + refinanceLoan(mavenWethPoolV1, mavenWethLoan1); |
| 136 | + refinanceLoan(mavenWethPoolV1, mavenWethLoan2); |
| 137 | + refinanceLoan(mavenWethPoolV1, mavenWethLoan5); |
| 138 | + refinanceLoan(mavenWethPoolV1, mavenWethLoan6); |
| 139 | + refinanceLoan(mavenWethPoolV1, mavenWethLoan7); |
| 140 | + } |
| 141 | + |
| 142 | +} |
0 commit comments