Skip to content

Commit

Permalink
feat/AST 1952 v1 handler testing (#43)
Browse files Browse the repository at this point in the history
* update getAuctionStart to be a public helper, make an internal version that is more optimized(less calls/decoding), add tests

* coverage testing for AstariaV1Settlement handler complete

* coverage testing for AstariaV1Settlement handler complete

* fix test name

* Astaria V1 Hook testing complete(-withdraw), Conduit Helper Removed, ConduitTransfer => AdditionalTransfer

* remove commented code

* final comment removal
  • Loading branch information
androolloyd authored Nov 2, 2023
1 parent 2364ed7 commit b2157b3
Show file tree
Hide file tree
Showing 26 changed files with 342 additions and 327 deletions.
8 changes: 4 additions & 4 deletions src/BNPLHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ItemType,
Fulfillment
} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {ConduitTransfer, ConduitItemType} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";

import {Seaport} from "seaport/contracts/Seaport.sol";
import {LoanManager} from "./LoanManager.sol";
Expand Down Expand Up @@ -113,10 +113,10 @@ contract BNPLHelper is IFlashLoanRecipient {
execution.orders, execution.resolvers, execution.fulfillments, execution.borrower
);

ConduitTransfer[] memory transfers = new ConduitTransfer[](tokens.length);
AdditionalTransfer[] memory transfers = new AdditionalTransfer[](tokens.length);
for (uint256 i = 0; i < tokens.length;) {
transfers[i] = ConduitTransfer({
itemType: ConduitItemType.ERC20,
transfers[i] = AdditionalTransfer({
itemType: ItemType.ERC20,
identifier: 0,
token: tokens[0],
from: execution.borrower,
Expand Down
164 changes: 0 additions & 164 deletions src/ConduitHelper.sol

This file was deleted.

4 changes: 2 additions & 2 deletions src/Custodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {ERC1155} from "solady/src/tokens/ERC1155.sol";
import {ItemType, Schema, SpentItem, ReceivedItem} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {ConsiderationInterface} from "seaport-types/src/interfaces/ConsiderationInterface.sol";
import {ContractOffererInterface} from "seaport-types/src/interfaces/ContractOffererInterface.sol";
import {ConduitHelper} from "starport-core/ConduitHelper.sol";

import {FixedPointMathLib} from "solady/src/utils/FixedPointMathLib.sol";
import {SettlementHook} from "starport-core/hooks/SettlementHook.sol";
import {SettlementHandler} from "starport-core/handlers/SettlementHandler.sol";
Expand All @@ -36,7 +36,7 @@ import {LoanManager} from "starport-core/LoanManager.sol";
import {StarPortLib, Actions} from "starport-core/lib/StarPortLib.sol";
import "forge-std/console2.sol";

contract Custodian is ERC721, ContractOffererInterface, ConduitHelper {
contract Custodian is ERC721, ContractOffererInterface {
using {StarPortLib.getId} for LoanManager.Loan;

LoanManager public immutable LM;
Expand Down
49 changes: 9 additions & 40 deletions src/LoanManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {SettlementHandler} from "starport-core/handlers/SettlementHandler.sol";
import {Pricing} from "starport-core/pricing/Pricing.sol";

import {StarPortLib, Actions} from "starport-core/lib/StarPortLib.sol";
import {ConduitTransfer, ConduitItemType} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";
import {ConduitControllerInterface} from "seaport-types/src/interfaces/ConduitControllerInterface.sol";
import {ConduitInterface} from "seaport-types/src/interfaces/ConduitInterface.sol";
import {Custodian} from "starport-core/Custodian.sol";
Expand Down Expand Up @@ -130,7 +130,7 @@ contract LoanManager is Ownable, ERC721 {
error InvalidItemType();
error InvalidTransferLength();
error CannotTransferLoans();
error ConduitTransferError();
error AdditionalTransferError();
error LoanExists();
error NotLoanCustodian();
error NotSeaport();
Expand Down Expand Up @@ -199,7 +199,7 @@ contract LoanManager is Ownable, ERC721 {
}

function originate(
ConduitTransfer[] calldata additionalTransfers,
AdditionalTransfer[] calldata additionalTransfers,
CaveatEnforcer.CaveatWithApproval calldata borrowerCaveat,
CaveatEnforcer.CaveatWithApproval calldata lenderCaveat,
LoanManager.Loan memory loan
Expand Down Expand Up @@ -234,7 +234,7 @@ contract LoanManager is Ownable, ERC721 {

if (additionalTransfers.length > 0) {
_validateAdditionalTransfersCalldata(borrower, issuer, msg.sender, additionalTransfers);
_transferConduitTransfers(additionalTransfers);
StarPortLib.transferAdditionalTransfers(additionalTransfers);
}

//sets originator and start time
Expand All @@ -253,7 +253,7 @@ contract LoanManager is Ownable, ERC721 {
(
SpentItem[] memory considerationPayment,
SpentItem[] memory carryPayment,
ConduitTransfer[] memory additionalTransfers
AdditionalTransfer[] memory additionalTransfers
) = Pricing(loan.terms.pricing).isValidRefinance(loan, pricingData, msg.sender);

_settle(loan);
Expand All @@ -272,7 +272,7 @@ contract LoanManager is Ownable, ERC721 {

if (additionalTransfers.length > 0) {
_validateAdditionalTransfers(loan.borrower, loan.issuer, msg.sender, additionalTransfers);
_transferConduitTransfers(additionalTransfers);
StarPortLib.transferAdditionalTransfers(additionalTransfers);
}

//sets originator and start time
Expand Down Expand Up @@ -338,7 +338,7 @@ contract LoanManager is Ownable, ERC721 {
address borrower,
address lender,
address fulfiller,
ConduitTransfer[] memory additionalTransfers
AdditionalTransfer[] memory additionalTransfers
) internal pure {
uint256 i = 0;
for (i; i < additionalTransfers.length;) {
Expand All @@ -358,7 +358,7 @@ contract LoanManager is Ownable, ERC721 {
address borrower,
address lender,
address fulfiller,
ConduitTransfer[] calldata additionalTransfers
AdditionalTransfer[] calldata additionalTransfers
) internal pure {
uint256 i = 0;
for (i; i < additionalTransfers.length;) {
Expand All @@ -375,7 +375,7 @@ contract LoanManager is Ownable, ERC721 {
function _validateAndEnforceCaveats(
CaveatEnforcer.CaveatWithApproval calldata caveatApproval,
address validator,
ConduitTransfer[] memory additionalTransfers,
AdditionalTransfer[] memory additionalTransfers,
LoanManager.Loan memory loan
) internal {
bytes32 hash = hashCaveatWithSaltAndNonce(validator, caveatApproval.salt, caveatApproval.caveat);
Expand All @@ -399,37 +399,6 @@ contract LoanManager is Ownable, ERC721 {
}
}

function _transferConduitTransfers(ConduitTransfer[] memory transfers) internal {
uint256 i = 0;
uint256 amount = 0;
for (i; i < transfers.length;) {
amount = transfers[i].amount;
if (amount > 0) {
if (transfers[i].itemType == ConduitItemType.ERC20) {
// erc20 transfer

SafeTransferLib.safeTransferFrom(transfers[i].token, transfers[i].from, transfers[i].to, amount);
} else if (transfers[i].itemType == ConduitItemType.ERC721) {
// erc721 transfer
if (amount > 1) {
revert InvalidItemAmount();
}
ERC721(transfers[i].token).transferFrom(transfers[i].from, transfers[i].to, transfers[i].identifier);
} else if (transfers[i].itemType == ConduitItemType.ERC1155) {
// erc1155 transfer
ERC1155(transfers[i].token).safeTransferFrom(
transfers[i].from, transfers[i].to, transfers[i].identifier, amount, new bytes(0)
);
} else {
revert NativeAssetsNotSupported();
}
}
unchecked {
++i;
}
}
}

function _transferItem(
ItemType itemType,
address token,
Expand Down
4 changes: 2 additions & 2 deletions src/enforcers/BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.8.17;

import {CaveatEnforcer} from "starport-core/enforcers/CaveatEnforcer.sol";
import {ConduitTransfer} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";
import {LoanManager} from "starport-core/LoanManager.sol";
import {ConsiderationInterface} from "seaport-types/src/interfaces/ConsiderationInterface.sol";

Expand All @@ -21,7 +21,7 @@ contract BorrowerEnforcer is CaveatEnforcer {
/// @param loan The loan terms
/// @param caveatData The borrowers encoded details
function validate(
ConduitTransfer[] calldata additionalTransfers,
AdditionalTransfer[] calldata additionalTransfers,
LoanManager.Loan calldata loan,
bytes calldata caveatData
) public view virtual override {
Expand Down
6 changes: 3 additions & 3 deletions src/enforcers/BorrowerEnforcerBNPL.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.8.17;

import {CaveatEnforcer} from "starport-core/enforcers/CaveatEnforcer.sol";
import {ConduitTransfer} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";
import {LoanManager} from "starport-core/LoanManager.sol";
import {ConsiderationInterface} from "seaport-types/src/interfaces/ConsiderationInterface.sol";

Expand All @@ -16,11 +16,11 @@ contract BorrowerEnforcerBNPL is CaveatEnforcer {
LoanManager.Loan loan;
address seaport;
bytes32 offerHash;
ConduitTransfer additionalTransfer;
AdditionalTransfer additionalTransfer;
}

function validate(
ConduitTransfer[] calldata additionalTransfers,
AdditionalTransfer[] calldata additionalTransfers,
LoanManager.Loan calldata loan,
bytes calldata caveatData
) public view virtual override {
Expand Down
4 changes: 2 additions & 2 deletions src/enforcers/CaveatEnforcer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.8.17;

import {ConduitTransfer} from "seaport-types/src/conduit/lib/ConduitStructs.sol";
import {AdditionalTransfer} from "starport-core/lib/StarPortLib.sol";
import {LoanManager} from "starport-core/LoanManager.sol";

abstract contract CaveatEnforcer {
Expand All @@ -18,7 +18,7 @@ abstract contract CaveatEnforcer {
Caveat[] caveat;
}

function validate(ConduitTransfer[] calldata solution, LoanManager.Loan calldata loan, bytes calldata caveatData)
function validate(AdditionalTransfer[] calldata solution, LoanManager.Loan calldata loan, bytes calldata caveatData)
public
view
virtual;
Expand Down
Loading

0 comments on commit b2157b3

Please sign in to comment.