Skip to content

Commit

Permalink
overwrite the collateral with the consideration its matched to.
Browse files Browse the repository at this point in the history
  • Loading branch information
androolloyd committed Jun 12, 2023
1 parent f8720d5 commit 59e3fa2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 49 deletions.
49 changes: 19 additions & 30 deletions gas-bench/loan-open.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
import { expect } from "chai";
import { describe, it } from "mocha";
import { ethers } from "hardhat";
import { UniqueValidator__factory } from "../typechain-types/factories/src/validators";
import { UniqueOriginator__factory } from "../typechain-types/factories/src/originators";
import { LoanManager__factory } from "../typechain-types/factories/src";
import { MockERC20__factory } from "../typechain-types/factories/lib/solmate/src/tokens";
//import { UniqueValidator__factory } from "../typechain-types/factories/src/";

describe("Loan Open Benchmarks", function() {
it("", async function() {
import { ERC20__factory } from "../typechain-types/factories/lib/solady/src/tokens";

describe("Loan Open Benchmarks", function () {
it("", async function () {
// one year in the future
// const lm = await ethers.getContractFactoryFromArtifact("LoanManager.sol");


});
});

async function setUp() {
const [astaria, strategist, lender, borrower] = await ethers.getSigners();

const conduitController = await (await ethers.getContractFactory("ConduitController")).deploy();
const consideration = await (await ethers.getContractFactory("Consideration")).deploy();
const debtToken = await (await ethers.getContractFactory("TestToken")).deploy();

const loanManager = await new LoanManager__factory(astaria).deploy(consideration.address);
const uniqueValidator = await new UniqueValidator__factory(lender).deploy(
const conduitController = await (
await ethers.getContractFactory("ConduitController")
).deploy();
const consideration = await (
await ethers.getContractFactory("Consideration")
).deploy();
const debtToken = await (
await ethers.getContractFactory("TestToken")
).deploy();

const loanManager = await new LoanManager__factory(astaria).deploy(
consideration.address
);
const uniqueOriginator = await new UniqueOriginator__factory(lender).deploy(
loanManager.address,
conduitController.address,
strategist.address,
0
);


// conduitKeyOne = bytes32(uint256(uint160(address(strategist))) << 96);

// vm.startPrank(lender);
// debtToken.approve(address(UV.conduit()), 100000);
// debtToken.mint(address(lender), 1000);

// vm.stopPrank();
}//






}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "starlite",
"dependencies": {
"@chainlink/contracts": "^0.6.1",
"chai": "^4.3.7",
"mocha": "^10.2.0"
"mocha": "^10.2.0",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3"
},
"scripts": {
"build:bench": "npx hardhat compile && npx hardhat typechain",
Expand Down
17 changes: 7 additions & 10 deletions src/LoanManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ contract LoanManager is ERC721, ContractOffererInterface, TokenReceiverInterface
Loan memory loan = nlrs[i].loan;
loan.start = block.timestamp;
loan.nonce = ++count;
_validateCollateral(loan, consideration[i]);
_setCollateral(loan, consideration[i]);
Originator.Response memory response =
Originator(loan.originator).validate(loan, nlrs[i].details, nlrs[i].signature);
if (CI.ownerOf(response.conduit) != loan.originator) {
Expand All @@ -420,18 +420,15 @@ contract LoanManager is ERC721, ContractOffererInterface, TokenReceiverInterface
}


function _validateCollateral(
function _setCollateral(
Loan memory loan,
ReceivedItem memory collateral
) internal view {
if (
collateral.amount != loan.collateral.amount ||
collateral.identifier != loan.collateral.identifier ||
collateral.itemType != loan.collateral.itemType ||
collateral.token != loan.collateral.token
) {
revert InvalidContext(ContextErrors.INVALID_COLLATERAL);
}
loan.collateral.itemType == collateral.itemType;
loan.collateral.token == collateral.token;
loan.collateral.identifier == collateral.identifier;
loan.collateral.amount == collateral.amount;

}
function _executeUnlock(ReceivedItem[] calldata consideration, bytes calldata context) internal {
//make this cheaper, by just encoding the
Expand Down
12 changes: 4 additions & 8 deletions test/TestStarLite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,12 @@ contract TestStarLite is BaseOrderTest {
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(strategist.key, hash);

SpentItem memory emptySpent;
activeLoan = _executeNLR(
LoanManager.NewLoanRequest({
details: abi.encode(loanDetails),
loan: LoanManager.Loan({
collateral: SpentItem({
token: address(erc721s[0]),
amount: 1,
identifier: 1,
itemType: ItemType.ERC721
}),
collateral: emptySpent, // gets set during the lock
debt: ReceivedItem({
recipient: payable(borrower.addr),
token: address(debtToken),
Expand Down Expand Up @@ -248,8 +244,8 @@ contract TestStarLite is BaseOrderTest {
loanDuration: 10 days
})
),
start: uint256(0),
nonce: uint256(0)
start: uint256(0), // gets set during the lock
nonce: uint256(0) // gets set during the lock
}),
signature: Originator.Signature({v: v, r: r, s: s})
})
Expand Down

0 comments on commit 59e3fa2

Please sign in to comment.