Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pure function for to get the id of a market #32

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct Market {
uint lLTV;
}

using {toId} for Market;
function toId(Market calldata market) pure returns (Id) {
return Id.wrap(keccak256(abi.encode(market)));
}

function irm(uint utilization) pure returns (uint) {
// Divide by the number of seconds in a year.
// This is a very simple model (to refine later) where x% utilization corresponds to x% APR.
Expand Down Expand Up @@ -55,7 +60,7 @@ contract Blue {
// Markets management.

function createMarket(Market calldata market) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] == 0, "market already exists");

accrueInterests(id);
Expand All @@ -64,7 +69,7 @@ contract Blue {
// Supply management.

function supply(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -85,7 +90,7 @@ contract Blue {
}

function withdraw(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -105,7 +110,7 @@ contract Blue {
// Borrow management.

function borrow(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -129,7 +134,7 @@ contract Blue {
}

function repay(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -147,7 +152,7 @@ contract Blue {
// Collateral management.

function supplyCollateral(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -159,7 +164,7 @@ contract Blue {
}

function withdrawCollateral(Market calldata market, uint amount) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(amount > 0, "zero amount");

Expand All @@ -175,7 +180,7 @@ contract Blue {
// Liquidation.

function liquidate(Market calldata market, address borrower, uint seized) external {
Id id = Id.wrap(keccak256(abi.encode(market)));
Id id = market.toId();
require(lastUpdate[id] != 0, "unknown market");
require(seized > 0, "zero amount");

Expand Down