diff --git a/gas-bench/loan-open.ts b/gas-bench/loan-open.ts index ebb70f6f..246a5ab1 100644 --- a/gas-bench/loan-open.ts +++ b/gas-bench/loan-open.ts @@ -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(); -}// - - - - - - +} diff --git a/package.json b/package.json index e60bc994..579a2903 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/LoanManager.sol b/src/LoanManager.sol index 111a2a74..172d4005 100644 --- a/src/LoanManager.sol +++ b/src/LoanManager.sol @@ -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) { @@ -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 diff --git a/test/TestStarLite.sol b/test/TestStarLite.sol index 5e3993c9..2faef131 100644 --- a/test/TestStarLite.sol +++ b/test/TestStarLite.sol @@ -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), @@ -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}) })