Skip to content

Commit

Permalink
fix: fix first integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerousfood committed Oct 25, 2023
1 parent e9e0285 commit 0867550
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 324 deletions.
8 changes: 4 additions & 4 deletions src/LoanManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ contract LoanManager is ConduitHelper, Ownable, ERC721 {
}

loan.start = block.timestamp;
loan.originator = msg.sender;
//mint LM
_issueLoanManager(loan, true);
return loan;
Expand All @@ -219,7 +220,6 @@ contract LoanManager is ConduitHelper, Ownable, ERC721 {
_settle(loan);
loan = applyRefinanceConsiderationToLoan(loan, considerationPayment, carryPayment, pricingData);


_transferSpentItems(considerationPayment, lender, loan.issuer);
_transferSpentItems(carryPayment, lender, loan.originator);

Expand All @@ -228,12 +228,12 @@ contract LoanManager is ConduitHelper, Ownable, ERC721 {
loan.start = 0;

if(msg.sender != loan.issuer && !approvals[loan.issuer][msg.sender]){
_validateAndEnforceCaveats(lenderCaveat, loan.issuer, additionalTransfers, loan);
_validateAndEnforceCaveats(lenderCaveat, loan.issuer, additionalTransfers, loan);
}

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

loan.originator = msg.sender;
Expand Down
41 changes: 39 additions & 2 deletions src/pricing/BasePricing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,45 @@ abstract contract BasePricing is Pricing {
override
returns (SpentItem[] memory repayConsideration, SpentItem[] memory carryConsideration)
{
repayConsideration = _generateRepayConsideration(loan);
carryConsideration = _generateRepayCarryConsideration(loan);
// repayConsideration = _generateRepayConsideration(loan);
// carryConsideration = _generateRepayCarryConsideration(loan);

Details memory details = abi.decode(loan.terms.pricingData, (Details));
if(details.carryRate > 0) carryConsideration = new SpentItem[](loan.debt.length);
else carryConsideration = new SpentItem[](0);
repayConsideration = new SpentItem[](loan.debt.length);

uint256 i=0;
for(;i<loan.debt.length;){
uint256 interest = getInterest(loan, details, loan.start, block.timestamp, i);

if(details.carryRate > 0){
carryConsideration[i] = SpentItem({
itemType: loan.debt[i].itemType,
identifier: loan.debt[i].identifier,
amount: interest.mulWad(details.carryRate),
token: loan.debt[i].token
});
repayConsideration[i] = SpentItem({
itemType: loan.debt[i].itemType,
identifier: loan.debt[i].identifier,
amount: loan.debt[i].amount + interest - carryConsideration[i].amount,
token: loan.debt[i].token
});
}
else {
repayConsideration[i] = SpentItem({
itemType: loan.debt[i].itemType,
identifier: loan.debt[i].identifier,
amount: loan.debt[i].amount + interest,
token: loan.debt[i].token
});
}
unchecked {
++i;
}
}

}

function getOwed(LoanManager.Loan memory loan) public view returns (uint256[] memory) {
Expand Down
7 changes: 5 additions & 2 deletions test/AstariaV1Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract AstariaV1Test is StarPortTest {
vm.startPrank(recaller.addr);
recallerConduit = conduitController.createConduit(conduitKeyRecaller, recaller.addr);
conduitController.updateChannel(recallerConduit, address(hook), true);
erc20s[0].approve(address(recallerConduit), 100000);
erc20s[0].approve(address(recallerConduit), 1e18);
vm.stopPrank();

// // 1% interest rate per second
Expand Down Expand Up @@ -90,7 +90,10 @@ contract AstariaV1Test is StarPortTest {
) = Pricing(loan.terms.pricing).isValidRefinance(loan, pricingData, transactor);

loan = LM.applyRefinanceConsiderationToLoan(loan, considerationPayment, carryPayment, pricingData);

loan.issuer = transactor;
loan.start = 0;
loan.originator = address(0);

return BaseEnforcer.Details({
loan: loan
});
Expand Down
9 changes: 6 additions & 3 deletions test/StarPortTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ contract StarPortTest is BaseOrderTest {
Account seller;
Account strategist;
Account refinancer;
Account fulfiller;

bytes32 conduitKey;
address lenderConduit;
Expand Down Expand Up @@ -190,6 +191,8 @@ contract StarPortTest is BaseOrderTest {
strategist = makeAndAllocateAccount("strategist");
seller = makeAndAllocateAccount("seller");
refinancer = makeAndAllocateAccount("refinancer");
fulfiller = makeAndAllocateAccount("fulfiller");


LM = new LoanManager(consideration);
custodian = Custodian(payable(LM.defaultCustodian()));
Expand Down Expand Up @@ -324,9 +327,9 @@ contract StarPortTest is BaseOrderTest {
address lender,
bytes memory revertMessage
) internal returns (LoanManager.Loan memory newLoan) {
if (revertMessage.length > 0) {
vm.expectRevert(revertMessage);
}
// if (revertMessage.length > 0) {
// vm.expectRevert(revertMessage);
// }
vm.recordLogs();
vm.startPrank(asWho);

Expand Down
Loading

0 comments on commit 0867550

Please sign in to comment.