From 741bea01a57f34646386de4040c66deb91deaf36 Mon Sep 17 00:00:00 2001 From: Andrew Redden Date: Fri, 22 Dec 2023 15:08:49 +0100 Subject: [PATCH] update defaultFeeRake mechanism to be configurable by token decimals, default to 18 decimals if there is no decimal available --- .gas-snapshot | 228 ++++++++++++------------- src/Starport.sol | 33 +++- test/fuzz-testing/TestFuzzStarport.sol | 6 +- test/unit-testing/TestStarport.sol | 26 ++- 4 files changed, 161 insertions(+), 132 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index a6b35b7f..b51adc99 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,66 +1,66 @@ -IntegrationTestCaveats:testInvalidCaveatLength() (gas: 130618) -IntegrationTestCaveats:testInvalidCaveats() (gas: 162648) -IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 333288) -IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 283868) -IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 307416) -IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 159899) -IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 168644) -IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 285500) -IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 142518) -IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 283988) -IntegrationTestCaveats:testRefinanceAsLender() (gas: 1054470) -IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 409118) -IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 348724) -IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 457710) -IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 378400) -IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 403607) -ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 439174) -ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 442063) -ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 438186) -ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 438985) -ModuleTesting:testModuleValidation() (gas: 1275373) +IntegrationTestCaveats:testInvalidCaveatLength() (gas: 136392) +IntegrationTestCaveats:testInvalidCaveats() (gas: 168369) +IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 341270) +IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 291935) +IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 315793) +IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 165568) +IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 174350) +IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 299632) +IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 148201) +IntegrationTestCaveats:testOriginateWLenderApproval() (gas: 292055) +IntegrationTestCaveats:testRefinanceAsLender() (gas: 1071391) +IntegrationTestCaveats:testRefinanceCaveatFailure() (gas: 423956) +IntegrationTestCaveats:testRefinanceLoanStartAtBlockTimestampInvalidLoan() (gas: 363371) +IntegrationTestCaveats:testRefinanceUnapprovedFulfiller() (gas: 474530) +IntegrationTestCaveats:testRefinanceWCaveatsInvalidSalt() (gas: 393396) +IntegrationTestCaveats:testRefinanceWLenderApproval() (gas: 420544) +ModuleTesting:testFixedTermDutchAuctionSettlement() (gas: 447587) +ModuleTesting:testFixedTermDutchAuctionSettlementGetSettlementAuctionExpired() (gas: 450477) +ModuleTesting:testFixedTermDutchAuctionSettlementNotValid() (gas: 446599) +ModuleTesting:testFixedTermDutchAuctionSettlementValid() (gas: 447398) +ModuleTesting:testModuleValidation() (gas: 1283844) PausableNonReentrantImpl:test() (gas: 2464) PausableNonReentrantImpl:testReentrancy() (gas: 2757) TestBorrowerEnforcer:testBERevertAdditionalTransfersFromBorrower() (gas: 76462) TestBorrowerEnforcer:testBERevertInvalidLoanTerms() (gas: 81160) TestBorrowerEnforcer:testBEValidLoanTerms() (gas: 72257) TestBorrowerEnforcer:testBEValidLoanTermsAnyIssuer() (gas: 72321) -TestCustodian:testCannotLazyMintTwice() (gas: 78672) +TestCustodian:testCannotLazyMintTwice() (gas: 78716) TestCustodian:testCannotMintInvalidLoanInvalidCustodian() (gas: 69119) -TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 74453) +TestCustodian:testCannotMintInvalidLoanValidCustodian() (gas: 74497) TestCustodian:testCustodySelector() (gas: 2881479) TestCustodian:testDefaultCustodySelectorRevert() (gas: 72312) -TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 173187) -TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163286) -TestCustodian:testGenerateOrderRepay() (gas: 177342) -TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193828) -TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 876979) -TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 806565) +TestCustodian:testGenerateOrderInvalidPostRepayment() (gas: 173121) +TestCustodian:testGenerateOrderInvalidPostSettlement() (gas: 163220) +TestCustodian:testGenerateOrderRepay() (gas: 177276) +TestCustodian:testGenerateOrderRepayAsRepayApprovedBorrower() (gas: 193762) +TestCustodian:testGenerateOrderRepayERC1155AndERC20() (gas: 894122) +TestCustodian:testGenerateOrderRepayERC1155AndERC20HandlerAuthorized() (gas: 823702) TestCustodian:testGenerateOrderRepayInvalidHookAddress() (gas: 97653) TestCustodian:testGenerateOrderRepayInvalidHookReturnType() (gas: 92014) TestCustodian:testGenerateOrderRepayNotBorrower() (gas: 106933) -TestCustodian:testGenerateOrderSettlement() (gas: 155019) -TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160416) -TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163486) +TestCustodian:testGenerateOrderSettlement() (gas: 154953) +TestCustodian:testGenerateOrderSettlementHandlerAuthorized() (gas: 160350) +TestCustodian:testGenerateOrderSettlementNoActiveLoan() (gas: 163420) TestCustodian:testGenerateOrderSettlementUnauthorized() (gas: 101861) -TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 462541) +TestCustodian:testGenerateOrdersWithLoanStartAtBlockTimestampInvalidLoan() (gas: 471018) TestCustodian:testGetBorrower() (gas: 78643) -TestCustodian:testInvalidAction() (gas: 173252) -TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130140) -TestCustodian:testInvalidActionSettleActiveLoan() (gas: 130100) +TestCustodian:testInvalidAction() (gas: 173340) +TestCustodian:testInvalidActionRepayInActiveLoan() (gas: 130184) +TestCustodian:testInvalidActionSettleActiveLoan() (gas: 130144) TestCustodian:testInvalidEncodedData() (gas: 26170) -TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 364175) +TestCustodian:testMintWithApprovalSetAsBorrower() (gas: 372602) TestCustodian:testMintWithApprovalSetAsBorrowerInvalidLoan() (gas: 60792) -TestCustodian:testMintWithApprovalSetNotAuthorized() (gas: 76657) +TestCustodian:testMintWithApprovalSetNotAuthorized() (gas: 76701) TestCustodian:testName() (gas: 7121) TestCustodian:testNonPayableFunctions() (gas: 215173) TestCustodian:testOnlySeaport() (gas: 17918) -TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105715) -TestCustodian:testPreviewOrderRepay() (gas: 230313) -TestCustodian:testPreviewOrderSettlement() (gas: 191957) -TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 108236) -TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 116987) -TestCustodian:testRatifyOrder() (gas: 184163) +TestCustodian:testPreviewOrderNoActiveLoan() (gas: 105759) +TestCustodian:testPreviewOrderRepay() (gas: 230291) +TestCustodian:testPreviewOrderSettlement() (gas: 191935) +TestCustodian:testPreviewOrderSettlementInvalidFufliller() (gas: 108280) +TestCustodian:testPreviewOrderSettlementInvalidRepayer() (gas: 117031) +TestCustodian:testRatifyOrder() (gas: 184097) TestCustodian:testSeaportMetadata() (gas: 8666) TestCustodian:testSupportsInterface() (gas: 9428) TestCustodian:testSymbol() (gas: 7127) @@ -71,82 +71,82 @@ TestLenderEnforcer:testLERevertInvalidLoanTerms() (gas: 81096) TestLenderEnforcer:testLEValidLoanTerms() (gas: 72169) TestLenderEnforcer:testLEValidLoanTermsAnyBorrower() (gas: 72323) TestLenderEnforcer:testLEValidLoanTermsWithAdditionalTransfers() (gas: 73525) -TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 593093) -TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 600284) -TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 591600) -TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 581417) -TestNewLoan:testBuyNowPayLater() (gas: 2875036) -TestNewLoan:testInvalidSenderBNPL() (gas: 1613098) -TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1615699) -TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 875005) -TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 886270) -TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 430686) -TestNewLoan:testNewLoanRefinance() (gas: 591435) -TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 325597) -TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 384928) -TestNewLoan:testSettleLoan() (gas: 642509) +TestLoanCombinations:testLoan20For721SimpleInterestDutchFixedRepay() (gas: 601541) +TestLoanCombinations:testLoan20for20SimpleInterestDutchFixedRepay() (gas: 608735) +TestLoanCombinations:testLoan721for20SimpleInterestDutchFixedRepay() (gas: 599998) +TestLoanCombinations:testLoanAstariaSettlementRepay() (gas: 589868) +TestNewLoan:testBuyNowPayLater() (gas: 3028328) +TestNewLoan:testInvalidSenderBNPL() (gas: 1759020) +TestNewLoan:testInvalidUserDataHashBNPL() (gas: 1761621) +TestNewLoan:testNewLoanAs1271ProxyAccountSender() (gas: 877948) +TestNewLoan:testNewLoanAs1271ProxyAccountThirdPartyFiller() (gas: 894378) +TestNewLoan:testNewLoanERC721CollateralDefaultTerms2() (gas: 439228) +TestNewLoan:testNewLoanRefinance() (gas: 609112) +TestNewLoan:testNewLoanViaOriginatorBorrowerApprovalAndLenderApproval() (gas: 334419) +TestNewLoan:testNewLoanViaOriginatorLenderApproval() (gas: 393605) +TestNewLoan:testSettleLoan() (gas: 651031) TestPausableNonReentrant:testNotOwner() (gas: 21254) TestPausableNonReentrant:testPauseAndUnpause() (gas: 22621) TestPausableNonReentrant:testReentrancy() (gas: 15404) TestPausableNonReentrant:testUnpauseWhenNotPaused() (gas: 12582) -TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 664808) -TestRepayLoan:testRepayLoanBase() (gas: 601076) -TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 439828) -TestRepayLoan:testRepayLoanInSettlement() (gas: 586521) -TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 605058) -TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 859963) +TestRepayLoan:testRepayLoanApprovedRepayer() (gas: 673314) +TestRepayLoan:testRepayLoanBase() (gas: 609538) +TestRepayLoan:testRepayLoanGenerateOrderNotSeaport() (gas: 448315) +TestRepayLoan:testRepayLoanInSettlement() (gas: 595181) +TestRepayLoan:testRepayLoanInvalidRepayer() (gas: 613671) +TestRepayLoan:testRepayLoanThatDoesNotExist() (gas: 868531) TestSimpleInterestPricing:test_calculateInterest() (gas: 899536) TestSimpleInterestPricing:test_getPaymentConsideration() (gas: 946746) TestSimpleInterestPricing:test_getRefinanceConsideration() (gas: 937602) -TestStarport:testAcquireTokensFail() (gas: 60408) -TestStarport:testAcquireTokensSuccess() (gas: 162955) -TestStarport:testActive() (gas: 69269) -TestStarport:testAdditionalTransfers() (gas: 301324) -TestStarport:testAdditionalTransfersOriginate() (gas: 276042) -TestStarport:testAdditionalTransfersRefinance() (gas: 218188) -TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 129424) -TestStarport:testCannotIssueSameLoanTwice() (gas: 365283) -TestStarport:testCannotOriginateWhilePaused() (gas: 73634) -TestStarport:testCannotSettleInvalidLoan() (gas: 74947) -TestStarport:testCannotSettleUnlessValidCustodian() (gas: 71029) -TestStarport:testCaveatEnforcerRevert() (gas: 100904) -TestStarport:testDefaultFeeRake() (gas: 362297) -TestStarport:testDefaultFeeRakeExoticDebt() (gas: 372382) -TestStarport:testEIP712Signing() (gas: 83333) -TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1238418) -TestStarport:testExoticDebtWithCustomPricingAndSettlement() (gas: 1693377) -TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 377444) -TestStarport:testIncrementCaveatNonce() (gas: 35142) -TestStarport:testInitializedFlagSetProperly() (gas: 67394) -TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 230995) -TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 170859) -TestStarport:testInvalidAmountCollateral() (gas: 166536) -TestStarport:testInvalidAmountCollateral721() (gas: 166536) -TestStarport:testInvalidItemType() (gas: 152484) -TestStarport:testInvalidTransferLengthCollateral() (gas: 154774) -TestStarport:testInvalidTransferLengthDebt() (gas: 176463) -TestStarport:testInvalidateCaveatSalt() (gas: 33428) -TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 264857) -TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 291004) -TestStarport:testNonPayableFunctions() (gas: 112517) -TestStarport:testOverrideFeeRake() (gas: 358680) -TestStarport:testPause() (gas: 18171) -TestStarport:testRefinancePostRepaymentFails() (gas: 127927) -TestStarport:testStargateGetOwner() (gas: 8895) -TestStarport:testTokenNoCodeCollateral() (gas: 151319) -TestStarport:testTokenNoCodeDebt() (gas: 181570) -TestStarport:testUnpause() (gas: 17209) -TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12307) -TestStrategistOriginator:testGetStrategistData() (gas: 1511582) +TestStarport:testAcquireTokensFail() (gas: 60430) +TestStarport:testAcquireTokensSuccess() (gas: 162977) +TestStarport:testActive() (gas: 69291) +TestStarport:testAdditionalTransfers() (gas: 309370) +TestStarport:testAdditionalTransfersOriginate() (gas: 284066) +TestStarport:testAdditionalTransfersRefinance() (gas: 226704) +TestStarport:testApplyRefinanceConsiderationToLoanMalformed() (gas: 129820) +TestStarport:testCannotIssueSameLoanTwice() (gas: 379383) +TestStarport:testCannotOriginateWhilePaused() (gas: 79481) +TestStarport:testCannotSettleInvalidLoan() (gas: 74881) +TestStarport:testCannotSettleUnlessValidCustodian() (gas: 70941) +TestStarport:testCaveatEnforcerRevert() (gas: 106536) +TestStarport:testDefaultFeeRake1() (gas: 397222) +TestStarport:testDefaultFeeRakeExoticDebt() (gas: 407043) +TestStarport:testEIP712Signing() (gas: 83377) +TestStarport:testExoticDebtWithCustomPricingAndRepayment() (gas: 1247118) +TestStarport:testExoticDebtWithCustomPricingAndSettlement() (gas: 1702068) +TestStarport:testExoticDebtWithNoCaveatsNotAsBorrower() (gas: 386146) +TestStarport:testIncrementCaveatNonce() (gas: 35316) +TestStarport:testInitializedFlagSetProperly() (gas: 67416) +TestStarport:testInvalidAdditionalTransfersOriginate() (gas: 236662) +TestStarport:testInvalidAdditionalTransfersRefinance() (gas: 177007) +TestStarport:testInvalidAmountCollateral() (gas: 172176) +TestStarport:testInvalidAmountCollateral721() (gas: 172176) +TestStarport:testInvalidItemType() (gas: 158123) +TestStarport:testInvalidTransferLengthCollateral() (gas: 160442) +TestStarport:testInvalidTransferLengthDebt() (gas: 182240) +TestStarport:testInvalidateCaveatSalt() (gas: 33417) +TestStarport:testNonDefaultCustodianCustodyCallFails() (gas: 270496) +TestStarport:testNonDefaultCustodianCustodyCallSuccess() (gas: 299027) +TestStarport:testNonPayableFunctions() (gas: 112909) +TestStarport:testOverrideFeeRake() (gas: 393462) +TestStarport:testPause() (gas: 18215) +TestStarport:testRefinancePostRepaymentFails() (gas: 133975) +TestStarport:testStargateGetOwner() (gas: 8808) +TestStarport:testTokenNoCodeCollateral() (gas: 156958) +TestStarport:testTokenNoCodeDebt() (gas: 187209) +TestStarport:testUnpause() (gas: 17297) +TestStrategistOriginator:testEncodeWithAccountCounter() (gas: 12305) +TestStrategistOriginator:testGetStrategistData() (gas: 1675537) TestStrategistOriginator:testIncrementCounterAsStrategist() (gas: 18676) TestStrategistOriginator:testIncrementCounterNotAuthorized() (gas: 13401) -TestStrategistOriginator:testInvalidCollateral() (gas: 210769) -TestStrategistOriginator:testInvalidDeadline() (gas: 216448) -TestStrategistOriginator:testInvalidDebt() (gas: 212429) -TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 212768) -TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 213089) -TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 213021) -TestStrategistOriginator:testInvalidDebtLength() (gas: 211696) -TestStrategistOriginator:testInvalidOffer() (gas: 427270) -TestStrategistOriginator:testInvalidSigner() (gas: 214875) -TestStrategistOriginator:testSetStrategist() (gas: 17774) \ No newline at end of file +TestStrategistOriginator:testInvalidCollateral() (gas: 211212) +TestStrategistOriginator:testInvalidDeadline() (gas: 216963) +TestStrategistOriginator:testInvalidDebt() (gas: 212908) +TestStrategistOriginator:testInvalidDebtAmountAskingMoreThanOffered() (gas: 213259) +TestStrategistOriginator:testInvalidDebtAmountOfferingZero() (gas: 213592) +TestStrategistOriginator:testInvalidDebtAmountRequestingZero() (gas: 213524) +TestStrategistOriginator:testInvalidDebtLength() (gas: 212134) +TestStrategistOriginator:testInvalidOffer() (gas: 436509) +TestStrategistOriginator:testInvalidSigner() (gas: 215301) +TestStrategistOriginator:testSetStrategist() (gas: 17768) \ No newline at end of file diff --git a/src/Starport.sol b/src/Starport.sol index 72e85557..5d42b47a 100644 --- a/src/Starport.sol +++ b/src/Starport.sol @@ -79,7 +79,7 @@ contract Starport is PausableNonReentrant { event CaveatNonceIncremented(address owner, uint256 newNonce); event CaveatSaltInvalidated(address owner, bytes32 salt); event Close(uint256 loanId); - event FeeDataUpdated(address feeTo, uint88 defaultFeeRake); + event FeeDataUpdated(address feeTo, uint256[2][] defaultFeeRakeByDecimals); event FeeOverrideUpdated(address token, uint88 overrideValue, bool enabled); event Open(uint256 loanId, Starport.Loan loan); @@ -152,8 +152,7 @@ contract Starport is PausableNonReentrant { /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ address public feeTo; - uint88 public defaultFeeRake; - + mapping(uint256 => uint256) public defaultFeeRakeByDecimals; mapping(address => Fee) public feeOverrides; mapping(address => mapping(address => ApprovalType)) public approvals; mapping(address => mapping(bytes32 => bool)) public invalidSalts; @@ -207,7 +206,7 @@ contract Starport is PausableNonReentrant { CaveatEnforcer.SignedCaveats calldata borrowerCaveat, CaveatEnforcer.SignedCaveats calldata lenderCaveat, Starport.Loan memory loan - ) external payable pausableNonReentrant { + ) external payable pausableNonReentrant returns (Starport.Loan memory) { // Cache the addresses address borrower = loan.borrower; address issuer = loan.issuer; @@ -241,6 +240,7 @@ contract Starport is PausableNonReentrant { // Sets originator and start time _issueLoan(loan); _callCustody(loan); + return loan; } /** @@ -256,7 +256,7 @@ contract Starport is PausableNonReentrant { Starport.Loan memory loan, bytes calldata pricingData, bytes calldata extraData - ) external pausableNonReentrant { + ) external pausableNonReentrant returns (Starport.Loan memory) { if (loan.start == block.timestamp) { revert InvalidLoan(); } @@ -294,6 +294,7 @@ contract Starport is PausableNonReentrant { // Sets originator and start time _issueLoan(loan); + return loan; } /** @@ -329,12 +330,17 @@ contract Starport is PausableNonReentrant { /** * @dev Sets the default fee data, only owner can call * @param feeTo_ The feeToAddress - * @param defaultFeeRake_ The default fee rake in WAD denomination(1e17 = 10%) + * @param defaultFeeRakeByDecimals_ [decimals, defaultFeeRakeByDecimals] pairs */ - function setFeeData(address feeTo_, uint88 defaultFeeRake_) external onlyOwner { + function setFeeData(address feeTo_, uint256[2][] memory defaultFeeRakeByDecimals_) external onlyOwner { feeTo = feeTo_; - defaultFeeRake = defaultFeeRake_; - emit FeeDataUpdated(feeTo_, defaultFeeRake_); + for (uint256 i = 0; i < defaultFeeRakeByDecimals_.length;) { + defaultFeeRakeByDecimals[defaultFeeRakeByDecimals_[i][0]] = defaultFeeRakeByDecimals_[i][1]; + unchecked { + ++i; + } + } + emit FeeDataUpdated(feeTo_, defaultFeeRakeByDecimals_); } /** @@ -651,6 +657,15 @@ contract Starport is PausableNonReentrant { } catch { decimals = 18; } + uint256 defaultFeeRake = defaultFeeRakeByDecimals[decimals]; + + if (defaultFeeRake == 0 && !feeOverride.enabled) { + unchecked { + ++i; + } + continue; + } + amount = debtItem.amount.mulDiv(!feeOverride.enabled ? defaultFeeRake : feeOverride.amount, 10 ** decimals); diff --git a/test/fuzz-testing/TestFuzzStarport.sol b/test/fuzz-testing/TestFuzzStarport.sol index 28a21616..0731d694 100644 --- a/test/fuzz-testing/TestFuzzStarport.sol +++ b/test/fuzz-testing/TestFuzzStarport.sol @@ -268,8 +268,10 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq { Starport.Loan memory loan = boundFuzzLoan(params, loanBoundsData); vm.assume(!willArithmeticOverflow(loan)); - uint88 feeRake = uint88(_boundMax(0, 1e17)); address feeReceiver = address(20); + uint256[2][] memory feeRake = new uint256[2][](1); + feeRake[0][0] = uint256(18); + feeRake[0][1] = _boundMax(0, 1e17); if (params.feesOn) { SP.setFeeData(feeReceiver, feeRake); } @@ -292,7 +294,7 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq { if (params.feesOn) { assert( ERC20(loan.debt[0].token).balanceOf(loan.borrower) - == (borrowerDebtBalanceBefore + (loan.debt[0].amount - loan.debt[0].amount.mulWad(feeRake))) + == (borrowerDebtBalanceBefore + (loan.debt[0].amount - loan.debt[0].amount.mulWad(feeRake[0][1]))) ); } else { assert( diff --git a/test/unit-testing/TestStarport.sol b/test/unit-testing/TestStarport.sol index ba2bd711..811737a8 100644 --- a/test/unit-testing/TestStarport.sol +++ b/test/unit-testing/TestStarport.sol @@ -634,10 +634,14 @@ contract TestStarport is StarportTest, DeepEq { vm.stopPrank(); } - function testDefaultFeeRake() public { - assertEq(SP.defaultFeeRake(), 0); + function testDefaultFeeRake1() public { + assertEq(SP.defaultFeeRakeByDecimals(18), 0); address feeReceiver = address(20); - SP.setFeeData(feeReceiver, 1e17); //10% fees + 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"); Starport.Loan memory originationDetails = _generateOriginationDetails( _getERC721SpentItem(erc721s[0], uint256(2)), _getERC20SpentItem(erc20s[0], borrowAmount), lender.addr @@ -649,10 +653,14 @@ contract TestStarport is StarportTest, DeepEq { } function testDefaultFeeRakeExoticDebt() public { - assertEq(SP.defaultFeeRake(), 0); + assertEq(SP.defaultFeeRakeByDecimals(18), 0); address feeReceiver = address(20); - SP.setFeeData(feeReceiver, 1e17); //10% fees + 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); Starport.Loan memory originationDetails = _generateOriginationDetails( _getERC721SpentItem(erc721s[0], uint256(2)), _getERC1155SpentItem(erc1155s[1]), lender.addr ); @@ -663,9 +671,13 @@ contract TestStarport is StarportTest, DeepEq { } function testOverrideFeeRake() public { - assertEq(SP.defaultFeeRake(), 0); + assertEq(SP.defaultFeeRakeByDecimals(18), 0); address feeReceiver = address(20); - SP.setFeeData(feeReceiver, 1e17); //10% fees + 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); SP.setFeeOverride(address(erc20s[0]), 0, true); //0% fees Starport.Loan memory originationDetails = _generateOriginationDetails(