Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/audit fixes round 5 #88

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -94,50 +94,50 @@ 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)
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)
Expand Down
2 changes: 1 addition & 1 deletion src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/settlement/DutchAuctionSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions test/StarportTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions test/unit-testing/TestStarport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down