Skip to content

Commit

Permalink
custodian coverage moving on up
Browse files Browse the repository at this point in the history
  • Loading branch information
androolloyd committed Oct 10, 2023
1 parent c10ea11 commit 9d0f3b2
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 39 deletions.
15 changes: 9 additions & 6 deletions src/Custodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract Custodian is ContractOffererInterface, TokenReceiverInterface, ConduitH
error NotSeaport();
error InvalidRepayer();
error InvalidFulfiller();
error InvalidHandler();
error InvalidHandlerExecution();
error InvalidLoan();
error InvalidAsset();

Expand Down Expand Up @@ -127,7 +127,7 @@ contract Custodian is ContractOffererInterface, TokenReceiverInterface, ConduitH
uint256 loanId = loan.getId();
if (LM.active(loanId)) {
if (SettlementHandler(loan.terms.handler).execute(loan) != SettlementHandler.execute.selector) {
revert InvalidHandler();
revert InvalidHandlerExecution();
}
_settleLoan(loan);
}
Expand Down Expand Up @@ -281,12 +281,11 @@ contract Custodian is ContractOffererInterface, TokenReceiverInterface, ConduitH
}
}

if (offer.length > 0) {
_beforeApprovalsSetHook(fulfiller, maximumSpent, context);
_setOfferApprovalsWithSeaport(offer);
}
_beforeApprovalsSetHook(fulfiller, maximumSpent, context);
_setOfferApprovalsWithSeaport(offer);
}

//custodian cant get any other assets deposited aside from what the LM supports
function _enableAssetWithSeaport(SpentItem memory offer) internal {
//approve consideration based on item type
if (offer.itemType == ItemType.NATIVE) {
Expand Down Expand Up @@ -335,4 +334,8 @@ contract Custodian is ContractOffererInterface, TokenReceiverInterface, ConduitH
try LoanSettledCallback(loan.issuer).onLoanSettled(loan) {} catch (bytes memory error) {}
}
}

fallback() external payable {}

receive() external payable {}
}
6 changes: 3 additions & 3 deletions src/LoanManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract LoanManager is ERC721, ContractOffererInterface, ConduitHelper, Ownable
ConsiderationInterface public immutable seaport;
// ConsiderationInterface public constant seaport =
// ConsiderationInterface(0x00000000000000ADc04C56Bf30aC9d3c0aAF14dC); // mainnet
address public immutable defaultCustodian;
address payable public immutable defaultCustodian;
bytes32 public immutable DEFAULT_CUSTODIAN_CODE_HASH;
bytes32 internal immutable _DOMAIN_SEPARATOR;

Expand Down Expand Up @@ -141,7 +141,7 @@ contract LoanManager is ERC721, ContractOffererInterface, ConduitHelper, Ownable
assembly {
defaultCustodianCodeHash := extcodehash(custodian)
}
defaultCustodian = custodian;
defaultCustodian = payable(custodian);
DEFAULT_CUSTODIAN_CODE_HASH = defaultCustodianCodeHash;
_DOMAIN_SEPARATOR = keccak256(abi.encode(EIP_DOMAIN, VERSION, block.chainid, address(this)));
_initializeOwner(msg.sender);
Expand Down Expand Up @@ -250,7 +250,7 @@ contract LoanManager is ERC721, ContractOffererInterface, ConduitHelper, Ownable
}
if (codeHash != DEFAULT_CUSTODIAN_CODE_HASH) {
if (
Custodian(custodian).custody(consideration, orderHashes, contractNonce, context)
Custodian(payable(custodian)).custody(consideration, orderHashes, contractNonce, context)
!= Custodian.custody.selector
) {
revert InvalidAction();
Expand Down
62 changes: 54 additions & 8 deletions test/StarPortTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {LoanManager} from "starport-core/LoanManager.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 {AAVEPoolCustodian} from "starport-core/custodians/AAVEPoolCustodian.sol";
Expand Down Expand Up @@ -157,15 +158,18 @@ contract StarPortTest is BaseOrderTest {
hook = new FixedTermHook();
vm.label(address(erc721s[0]), "Collateral NFT");
vm.label(address(erc721s[1]), "Collateral2 NFT");
vm.label(address(erc20s[0]), "Debt Token");
vm.label(address(erc20s[1]), "Collateral Token");
vm.label(address(erc20s[0]), "Debt ERC20");
vm.label(address(erc20s[1]), "Collateral ERC20");
vm.label(address(erc1155s[0]), "Collateral 1155");
vm.label(address(erc1155s[1]), "Debt 1155 ");
{
vm.startPrank(borrower.addr);
erc721s[1].mint(seller.addr, 1);
erc721s[0].mint(borrower.addr, 1);
erc721s[0].mint(borrower.addr, 2);
erc721s[0].mint(borrower.addr, 3);
erc20s[1].mint(borrower.addr, 10000);
erc1155s[0].mint(borrower.addr, 1, 1);
vm.stopPrank();
}
conduitKeyOne = bytes32(uint256(uint160(address(lender.addr))) << 96);
Expand Down Expand Up @@ -561,12 +565,21 @@ contract StarPortTest is BaseOrderTest {
}
vm.recordLogs();
vm.startPrank(borrower.addr);
consideration.fulfillAdvancedOrder({
advancedOrder: x,
criteriaResolvers: new CriteriaResolver[](0),
fulfillerConduitKey: bytes32(0),
recipient: address(borrower.addr)
});
if (collateral[0].itemType == ItemType.NATIVE) {
consideration.fulfillAdvancedOrder{value: collateral[0].endAmount}({
advancedOrder: x,
criteriaResolvers: new CriteriaResolver[](0),
fulfillerConduitKey: bytes32(0),
recipient: address(borrower.addr)
});
} else {
consideration.fulfillAdvancedOrder({
advancedOrder: x,
criteriaResolvers: new CriteriaResolver[](0),
fulfillerConduitKey: bytes32(0),
recipient: address(borrower.addr)
});
}
Vm.Log[] memory logs = vm.getRecordedLogs();
uint256 loanId;

Expand Down Expand Up @@ -761,4 +774,37 @@ contract StarPortTest is BaseOrderTest {
recipient: payable(address(custodian))
});
}

function _getERC1155Consideration(TestERC1155 token) internal view returns (ConsiderationItem memory) {
return ConsiderationItem({
token: address(token),
startAmount: 1,
endAmount: 1,
identifierOrCriteria: 1,
itemType: ItemType.ERC1155,
recipient: payable(address(custodian))
});
}

function _getERC20Consideration(TestERC20 token) internal view returns (ConsiderationItem memory) {
return ConsiderationItem({
token: address(token),
startAmount: 1,
endAmount: 1,
identifierOrCriteria: 0,
itemType: ItemType.ERC20,
recipient: payable(address(custodian))
});
}

function _getNativeConsideration() internal view returns (ConsiderationItem memory) {
return ConsiderationItem({
token: address(0),
startAmount: 100 wei,
endAmount: 100 wei,
identifierOrCriteria: 0,
itemType: ItemType.NATIVE,
recipient: payable(address(custodian))
});
}
}
Loading

0 comments on commit 9d0f3b2

Please sign in to comment.