Skip to content

Commit

Permalink
updates to refinance and a test to validate its cheaper
Browse files Browse the repository at this point in the history
  • Loading branch information
androolloyd committed Oct 18, 2023
1 parent d4fc050 commit ce55a0f
Show file tree
Hide file tree
Showing 9 changed files with 498 additions and 139 deletions.
33 changes: 19 additions & 14 deletions src/Custodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {SettlementHook} from "starport-core/hooks/SettlementHook.sol";
import {SettlementHandler} from "starport-core/handlers/SettlementHandler.sol";
import {Pricing} from "starport-core/pricing/Pricing.sol";
import {LoanManager} from "starport-core/LoanManager.sol";
import {StarPortLib} from "starport-core/lib/StarPortLib.sol";
import {StarPortLib, Actions} from "starport-core/lib/StarPortLib.sol";

contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenReceiverInterface {
using {StarPortLib.getId} for LoanManager.Loan;
Expand All @@ -48,13 +48,14 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
event RepayApproval(address borrower, address repayer, bool approved);
event SeaportCompatibleContractDeployed();

error NotSeaport();
error NotLoanManager();
error InvalidRepayer();
error ImplementInChild();
error InvalidAction();
error InvalidFulfiller();
error InvalidHandlerExecution();
error InvalidLoan();
error ImplementInChild();
error InvalidRepayer();
error NotSeaport();
error NotLoanManager();

constructor(LoanManager LM_, address seaport_) {
seaport = seaport_;
Expand Down Expand Up @@ -202,12 +203,13 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
SpentItem[] calldata maximumSpent,
bytes calldata context // encoded based on the schemaID
) public view returns (SpentItem[] memory offer, ReceivedItem[] memory consideration) {
LoanManager.Loan memory loan = abi.decode(context, (LoanManager.Loan));
(Actions action, LoanManager.Loan memory loan) = abi.decode(context, (Actions, LoanManager.Loan));

if (!LM.issued(loan.getId())) {
revert InvalidLoan();
}
if (SettlementHook(loan.terms.hook).isActive(loan)) {
bool loanActive = SettlementHook(loan.terms.hook).isActive(loan);
if (action == Actions.Repayment && loanActive) {
address borrower = getBorrower(loan);
if (fulfiller != borrower && !repayApproval[borrower][fulfiller]) {
revert InvalidRepayer();
Expand All @@ -219,7 +221,7 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece

consideration = _mergeConsiderations(paymentConsiderations, carryFeeConsideration, new ReceivedItem[](0));
consideration = _removeZeroAmounts(consideration);
} else {
} else if (action == Actions.Settlement && !loanActive) {
address authorized;
(consideration, authorized) = SettlementHandler(loan.terms.handler).getSettlement(loan);

Expand All @@ -228,6 +230,8 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
} else if (authorized == loan.terms.handler || authorized == loan.issuer) {} else {
revert InvalidFulfiller();
}
} else {
revert InvalidAction();
}
}

Expand Down Expand Up @@ -264,11 +268,10 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
internal
returns (SpentItem[] memory offer, ReceivedItem[] memory consideration)
{
LoanManager.Loan memory loan = abi.decode(context, (LoanManager.Loan));
if (!LM.issued(loan.getId())) {
revert InvalidLoan();
}
if (SettlementHook(loan.terms.hook).isActive(loan)) {
(Actions action, LoanManager.Loan memory loan) = abi.decode(context, (Actions, LoanManager.Loan));

bool loanActive = SettlementHook(loan.terms.hook).isActive(loan);
if (action == Actions.Repayment && loanActive) {
address borrower = getBorrower(loan);
if (fulfiller != borrower && !repayApproval[borrower][fulfiller]) {
revert InvalidRepayer();
Expand All @@ -285,7 +288,7 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
consideration = _removeZeroAmounts(consideration);

_settleLoan(loan);
} else {
} else if (action == Actions.Settlement && !loanActive) {
address authorized;
//add in originator fee
_beforeSettlementHandlerHook(loan);
Expand All @@ -310,6 +313,8 @@ contract Custodian is ERC721, ContractOffererInterface, ConduitHelper, TokenRece
}

_settleLoan(loan);
} else {
revert InvalidAction();
}
}

Expand Down
Loading

0 comments on commit ce55a0f

Please sign in to comment.