diff --git a/.gas-snapshot b/.gas-snapshot index 4811f8ab..ef911bb2 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -94,28 +94,28 @@ TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582) TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 667169) TestRepayLoan:testRepayLoanBase() (gas: 599955) TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 438687) -TestRepayLoan:testRepayLoanInSettlement() (gas: 585895) +TestRepayLoan:testRepayLoanInSettlement() (gas: 585892) TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 603988) TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 858823) TestSimpleInterestPricing:test_calculateInterest() (gas: 881296) TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 928510) TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 919314) TestStarport:testAcquireTokensFail() (gas: 60430) -TestStarport:testAcquireTokensSuccess() (gas: 162977) -TestStarport:testActive() (gas: 69313) +TestStarport:testAcquireTokensSuccess() (gas: 162999) +TestStarport:testActive() (gas: 69224) TestStarport:testAdditionalTransfers() (gas: 300721) TestStarport:testAdditionalTransfersOriginate() (gas: 275417) -TestStarport:testAdditionalTransfersRefinance() (gas: 218214) +TestStarport:testAdditionalTransfersRefinance() (gas: 218147) TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 129974) TestStarport:testCannotIssueSameLoanTwice() (gas: 364057) TestStarport:testCannotOriginateWhilePaused() (gas: 73567) TestStarport:testCannotSettleInvalidLoan() (gas: 74903) TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70963) TestStarport:testCaveatEnforcerRevert() (gas: 100284) -TestStarport:testDefaultFeeRake1() (gas: 387806) -TestStarport:testDefaultFeeRakeExoticDebt() (gas: 397608) -TestStarport:testEIP712Signing() (gas: 83067) -TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1237817) +TestStarport:testDefaultFeeRake1() (gas: 387818) +TestStarport:testDefaultFeeRake2() (gas: 450161) +TestStarport:testDefaultFeeRakeExoticDebt() (gas: 397641) +TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1237839) TestStarport:testExoticDebtWithCustomPricingAndSettlement() (gas: 1692860) TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 376819) TestStarport:testIncrementCaveatNonce() (gas: 35292) @@ -123,21 +123,21 @@ TestStarport:testInitializedFlagSetProperly() (gas: 67438) TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 230392) TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 170796) TestStarport:testInvalidAmountCollateral() (gas: 165912) -TestStarport:testInvalidAmountCollateral721() (gas: 165912) +TestStarport:testInvalidAmountCollateral721() (gas: 165934) TestStarport:testInvalidItemType() (gas: 151860) -TestStarport:testInvalidTransferLengthCollateral() (gas: 154151) +TestStarport:testInvalidTransferLengthCollateral() (gas: 154173) TestStarport:testInvalidTransferLengthDebt() (gas: 175950) TestStarport:testInvalidateCaveatSalt() (gas: 33450) -TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 264233) +TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 264255) TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 290380) TestStarport:testNonPayableFunctions() (gas: 112229) TestStarport:testOverrideFeeRake() (gas: 384052) -TestStarport:testPause() (gas: 18237) +TestStarport:testPause() (gas: 18259) TestStarport:testRefinancePostRepaymentFails() (gas: 127973) TestStarport:testStargateGetOwner() (gas: 8808) TestStarport:testTokenNoCodeCollateral() (gas: 150695) TestStarport:testTokenNoCodeDebt() (gas: 180946) -TestStarport:testUnpause() (gas: 17341) +TestStarport:testUnpause() (gas: 17363) TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12330) TestStrategistOriginator:testGetStrategistData() (gas: 1809233) TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 38767) diff --git a/src/Starport.sol b/src/Starport.sol index 3761d298..1a8cd9fc 100644 --- a/src/Starport.sol +++ b/src/Starport.sol @@ -655,7 +655,7 @@ contract Starport is PausableNonReentrant { SpentItem memory debtItem = debt[i]; if (debtItem.itemType == ItemType.ERC20) { Fee memory feeOverride = feeOverrides[debtItem.token]; - SpentItem memory feeItem = feeItems[i]; + SpentItem memory feeItem = feeItems[totalFeeItems]; feeItem.identifier = 0; uint8 decimals; try ERC20(debtItem.token).decimals() returns (uint8 _decimals) { diff --git a/src/settlement/DutchAuctionSettlement.sol b/src/settlement/DutchAuctionSettlement.sol index 883e5fd8..e8d4a9d6 100644 --- a/src/settlement/DutchAuctionSettlement.sol +++ b/src/settlement/DutchAuctionSettlement.sol @@ -143,7 +143,7 @@ abstract contract DutchAuctionSettlement is Settlement, AmountDeriver { if (carry > 0 && loan.debt[0].amount + interest - carry < settlementPrice) { consideration = new ReceivedItem[](2); - uint256 excess = settlementPrice - loan.debt[0].amount + interest - carry; + uint256 excess = settlementPrice - (loan.debt[0].amount + interest - carry); consideration[0] = ReceivedItem({ itemType: loan.debt[0].itemType, identifier: loan.debt[0].identifier, diff --git a/test/StarportTest.sol b/test/StarportTest.sol index df9a7538..8efc3142 100644 --- a/test/StarportTest.sol +++ b/test/StarportTest.sol @@ -749,6 +749,18 @@ contract StarportTest is BaseOrderTest, Stargate { loan.custodian = incomingCustodian; } + function _generateOriginationDetails(SpentItem[] memory collateral, SpentItem[] memory debt, address incomingIssuer) + internal + view + returns (Starport.Loan memory loan) + { + loan = generateDefaultLoanTerms(); + loan.issuer = incomingIssuer; + loan.collateral = collateral; + loan.debt = debt; + loan.custodian = address(custodian); + } + function _getERC20SpentItem(TestERC20 token, uint256 amount) internal pure returns (SpentItem memory) { return SpentItem({ itemType: ItemType.ERC20, diff --git a/test/unit-testing/TestStarport.sol b/test/unit-testing/TestStarport.sol index ee8d97bb..6d55d507 100644 --- a/test/unit-testing/TestStarport.sol +++ b/test/unit-testing/TestStarport.sol @@ -624,6 +624,36 @@ contract TestStarport is StarportTest, DeepEq { assertEq(erc20s[0].balanceOf(feeReceiver), loan.debt[0].amount * 1e17 / 1e18, "fee receiver not paid properly"); } + function testDefaultFeeRake2() public { + assertEq(SP.defaultFeeRakeByDecimals(18), 0); + address feeReceiver = address(20); + uint256[2][] memory feeRake = new uint256[2][](1); + feeRake[0][0] = uint256(18); + feeRake[0][1] = uint256(1e17); + SP.setFeeData(feeReceiver, feeRake); //10% fees + assertEq(SP.defaultFeeRakeByDecimals(18), 1e17, "fee's not set properly"); + + SpentItem[] memory debt = new SpentItem[](2); + debt[0] = _getERC721SpentItem(erc721s[0], uint256(2)); + debt[1] = _getERC20SpentItem(erc20s[0], borrowAmount); + vm.prank(borrower.addr); + erc721s[0].transferFrom(borrower.addr, lender.addr, uint256(2)); + vm.prank(lender.addr); + erc721s[0].approve(address(SP), uint256(2)); + + erc721s[0].ownerOf(uint256(3)); + vm.prank(borrower.addr); + erc721s[0].approve(address(custodian), uint256(3)); + + SpentItem[] memory collateral = new SpentItem[](1); + collateral[0] = _getERC721SpentItem(erc721s[0], uint256(3)); + Starport.Loan memory originationDetails = _generateOriginationDetails(collateral, debt, lender.addr); + + Starport.Loan memory loan = + newLoan(originationDetails, bytes32(bytes32(msg.sig)), bytes32(bytes32(msg.sig)), lender.addr); + assertEq(erc20s[0].balanceOf(feeReceiver), loan.debt[1].amount * 1e17 / 1e18, "fee receiver not paid properly"); + } + function testDefaultFeeRakeExoticDebt() public { assertEq(SP.defaultFeeRakeByDecimals(18), 0); address feeReceiver = address(20);