Skip to content

Commit

Permalink
chore: move example implementations to mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
0xgregthedev committed Feb 3, 2024
1 parent 852edf8 commit d7a0b82
Show file tree
Hide file tree
Showing 30 changed files with 458 additions and 222 deletions.
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ solady/=lib/solady/
solarray/=lib/seaport/lib/solarray/src/
solmate/=lib/solmate/src/
starport-core/=src/
starport-test/=test/
starport-test/=test/
94 changes: 0 additions & 94 deletions src/pricing/SimpleInterestPricing.sol

This file was deleted.

47 changes: 23 additions & 24 deletions test/StarportTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "forge-std/Test.sol";
import {Vm} from "forge-std/Vm.sol";
import {Starport, Stargate} from "starport-core/Starport.sol";
import {Pricing} from "starport-core/pricing/Pricing.sol";
import {StrategistOriginator} from "starport-core/originators/StrategistOriginator.sol";
import {StrategistOriginator} from "starport-test/mocks/originators/StrategistOriginator.sol";
import {
ItemType,
ReceivedItem,
Expand All @@ -29,41 +29,38 @@ import {Consideration} from "seaport-core/src/lib/Consideration.sol";
//import {
// ReferenceConsideration as Consideration
//} from "seaport/reference/ReferenceConsideration.sol";
import {StrategistOriginator} from "starport-core/originators/StrategistOriginator.sol";

import {SimpleInterestPricing} from "starport-core/pricing/SimpleInterestPricing.sol";

import {BasePricing} from "starport-core/pricing/BasePricing.sol";

import {FixedTermStatus} from "starport-core/status/FixedTermStatus.sol";
import {FixedTermDutchAuctionSettlement} from "starport-core/settlement/FixedTermDutchAuctionSettlement.sol";
import {DutchAuctionSettlement} from "starport-core/settlement/DutchAuctionSettlement.sol";

import {Custodian} from "starport-core/Custodian.sol";
import {Starport} from "starport-core/Starport.sol";

import {Actions} from "starport-core/lib/StarportLib.sol";
import {BaseOrderTest} from "seaport/test/foundry/utils/BaseOrderTest.sol";
import {TestERC721} from "seaport/contracts/test/TestERC721.sol";
import {TestERC1155} from "seaport/contracts/test/TestERC1155.sol";
import {TestERC20} from "seaport/contracts/test/TestERC20.sol";
import {ConsiderationItemLib} from "seaport/lib/seaport-sol/src/lib/ConsiderationItemLib.sol";
import {Custodian} from "starport-core/Custodian.sol";
import "seaport/lib/seaport-sol/src/lib/AdvancedOrderLib.sol";
import {Status} from "starport-core/status/Status.sol";
import {Settlement} from "starport-core/settlement/Settlement.sol";
import {TestERC721} from "seaport/contracts/test/TestERC721.sol";
import {TestERC1155} from "seaport/contracts/test/TestERC1155.sol";
import {TestERC20} from "seaport/contracts/test/TestERC20.sol";
import {TokenReceiverInterface} from "starport-core/interfaces/TokenReceiverInterface.sol";
import {Pricing} from "starport-core/pricing/Pricing.sol";

import {BorrowerEnforcerBNPL} from "starport-test/mocks/enforcers/BorrowerEnforcerBNPL.sol";
import {Cast} from "starport-test/utils/Cast.sol";
import {DutchAuctionSettlement} from "starport-test/mocks/settlement/DutchAuctionSettlement.sol";
import {FixedTermStatus} from "starport-test/mocks/status/FixedTermStatus.sol";
import {FixedTermDutchAuctionSettlement} from "starport-test/mocks/settlement/FixedTermDutchAuctionSettlement.sol";
import {SimpleInterestPricing} from "starport-test/mocks/pricing/SimpleInterestPricing.sol";

import {ERC20} from "solady/src/tokens/ERC20.sol";
import {ERC721} from "solady/src/tokens/ERC721.sol";
import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {ContractOffererInterface} from "seaport-types/src/interfaces/ContractOffererInterface.sol";
import {TokenReceiverInterface} from "starport-core/interfaces/TokenReceiverInterface.sol";
import {Actions} from "starport-core/lib/StarportLib.sol";

import {CaveatEnforcer} from "starport-core/enforcers/CaveatEnforcer.sol";
import {BorrowerEnforcer} from "starport-core/enforcers/BorrowerEnforcer.sol";
import {BorrowerEnforcerBNPL} from "starport-core/enforcers/BorrowerEnforcerBNPL.sol";

import {LenderEnforcer} from "starport-core/enforcers/LenderEnforcer.sol";
import {BorrowerEnforcer} from "starport-test/mocks/enforcers/BorrowerEnforcer.sol";
import {LenderEnforcer} from "starport-test/mocks/enforcers/LenderEnforcer.sol";
import {FixedPointMathLib} from "solady/src/utils/FixedPointMathLib.sol";

interface IWETH9 {
Expand Down Expand Up @@ -117,8 +114,9 @@ contract StarportTest is BaseOrderTest, Stargate {
uint256 defaultLoanDuration = 14 days;

// 1% interest rate per second
bytes defaultPricingData =
abi.encode(BasePricing.Details({carryRate: (uint256(1e16) * 10), rate: uint256(1e16) * 150, decimals: 18}));
bytes defaultPricingData = abi.encode(
SimpleInterestPricing.Details({carryRate: (uint256(1e16) * 10), rate: uint256(1e16) * 150, decimals: 18})
);

bytes defaultSettlementData = abi.encode(
DutchAuctionSettlement.Details({startingPrice: uint256(500 ether), endingPrice: 100 wei, window: 7 days})
Expand All @@ -137,10 +135,10 @@ contract StarportTest is BaseOrderTest, Stargate {
Custodian custodian;
StrategistOriginator SO;

BorrowerEnforcer borrowerEnforcer;
CaveatEnforcer borrowerEnforcer;
BorrowerEnforcerBNPL borrowerEnforcerBNPL;

LenderEnforcer lenderEnforcer;
CaveatEnforcer lenderEnforcer;

//mock the test harness as stargate
function getOwner(address) external view returns (address) {
Expand Down Expand Up @@ -619,7 +617,8 @@ contract StarportTest is BaseOrderTest, Stargate {
uint256 lenderBefore = erc20s[0].balanceOf(lender.addr);
uint256 originatorBefore = erc20s[0].balanceOf(loan.originator);

BasePricing.Details memory details = abi.decode(loan.terms.pricingData, (BasePricing.Details));
SimpleInterestPricing.Details memory details =
abi.decode(loan.terms.pricingData, (SimpleInterestPricing.Details));
uint256 interest = SimpleInterestPricing(loan.terms.pricing).calculateInterest(
10 days, loan.debt[0].amount, details.rate, details.decimals
);
Expand Down
15 changes: 9 additions & 6 deletions test/fuzz-testing/TestFuzzStarport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq {

function boundPricingData(bytes memory boundPricingData) internal view virtual returns (bytes memory pricingData) {
uint256 min = abi.decode(boundPricingData, (uint256));
BasePricing.Details memory details = BasePricing.Details({
SimpleInterestPricing.Details memory details = SimpleInterestPricing.Details({
rate: _boundMax(min, (uint256(1e16) * 150)),
carryRate: _boundMax(0, uint256((1e16 * 100))),
decimals: _boundMax(0, 18)
Expand Down Expand Up @@ -204,7 +204,8 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq {
}
loan.collateral = ret;
SpentItem[] memory debt = new SpentItem[](1);
BasePricing.Details memory pricingDetails = abi.decode(loan.terms.pricingData, (BasePricing.Details));
SimpleInterestPricing.Details memory pricingDetails =
abi.decode(loan.terms.pricingData, (SimpleInterestPricing.Details));
if (pricingDetails.decimals == 18) {
debt[0] = SpentItem({
itemType: ItemType.ERC20,
Expand All @@ -230,8 +231,9 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq {
}

function willArithmeticOverflow(Starport.Loan memory loan) internal view virtual returns (bool) {
BasePricing.Details memory pricingDetails = abi.decode(loan.terms.pricingData, (BasePricing.Details));
try BasePricing(loan.terms.pricing).getPaymentConsideration(loan) returns (
SimpleInterestPricing.Details memory pricingDetails =
abi.decode(loan.terms.pricingData, (SimpleInterestPricing.Details));
try SimpleInterestPricing(loan.terms.pricing).getPaymentConsideration(loan) returns (
SpentItem[] memory repayConsideration, SpentItem[] memory carryConsideration
) {
unchecked {
Expand Down Expand Up @@ -593,10 +595,11 @@ contract TestFuzzStarport is StarportTest, Bound, DeepEq {
function testFuzzRefinance(FuzzRefinanceLoan memory params) public virtual {
Starport.Loan memory goodLoan = fuzzNewLoanOrigination(params.origination, abi.encode(LoanBounds(1)));

BasePricing.Details memory oldDetails = abi.decode(goodLoan.terms.pricingData, (BasePricing.Details));
SimpleInterestPricing.Details memory oldDetails =
abi.decode(goodLoan.terms.pricingData, (SimpleInterestPricing.Details));

uint256 newRate = _boundMax(oldDetails.rate - 1, (uint256(1e16) * 1000) / (365 * 1 days));
BasePricing.Details memory newPricingDetails = BasePricing.Details({
SimpleInterestPricing.Details memory newPricingDetails = SimpleInterestPricing.Details({
rate: newRate,
carryRate: _boundMax(0, uint256((1e16 * 100))),
decimals: oldDetails.decimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

pragma solidity ^0.8.17;

import {Starport} from "../Starport.sol";
import {Starport} from "starport-core/Starport.sol";

import {ItemType, ReceivedItem, SpentItem} from "seaport-types/src/lib/ConsiderationStructs.sol";

Expand Down
2 changes: 1 addition & 1 deletion test/fuzz-testing/differential-fuzzing/TestStarPortLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import {Conduit} from "seaport-core/src/conduit/Conduit.sol";
import {ConduitController} from "seaport-core/src/conduit/ConduitController.sol";
import {StarportLib} from "starport-core/lib/StarportLib.sol";
import {RefStarportLib} from "starport-core/lib/RefStarportLib.sol";
import {RefStarportLib} from "starport-test/fuzz-testing/differential-fuzzing/RefStarportLib.sol";
import "starport-test/utils/FuzzStructs.sol" as Fuzz;
import {Bound} from "starport-test/utils/Bound.sol";
import {DeepEq} from "starport-test/utils/DeepEq.sol";
Expand Down
7 changes: 4 additions & 3 deletions test/integration-testing/TestNewLoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.8.17;

import "starport-test/StarportTest.sol";
import {StarportLib, Actions} from "starport-core/lib/StarportLib.sol";
import {BNPLHelper, IFlashLoanRecipient} from "starport-core/BNPLHelper.sol";
import {BNPLHelper, IFlashLoanRecipient} from "starport-test/mocks/BNPLHelper.sol";
import {Originator} from "starport-core/originators/Originator.sol";
import {SignatureCheckerLib} from "solady/src/utils/SignatureCheckerLib.sol";

Expand Down Expand Up @@ -105,8 +105,9 @@ contract TestNewLoan is StarportTest {
function testNewLoanRefinance() public {
Starport.Loan memory loan = testNewLoanERC721CollateralDefaultTerms2();
Starport.Loan memory refiLoan = loanCopy(loan);
bytes memory newPricingData =
abi.encode(BasePricing.Details({carryRate: (uint256(1e16) * 10), rate: uint256(1e16) * 100, decimals: 18}));
bytes memory newPricingData = abi.encode(
SimpleInterestPricing.Details({carryRate: (uint256(1e16) * 10), rate: uint256(1e16) * 100, decimals: 18})
);
refiLoan.terms.pricingData = newPricingData;
refiLoan.debt = SP.applyRefinanceConsiderationToLoan(loan.debt, new SpentItem[](0));
LenderEnforcer.Details memory details = LenderEnforcer.Details({loan: refiLoan});
Expand Down
Loading

0 comments on commit d7a0b82

Please sign in to comment.