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

put market in memory instead of calldata #152

Merged
merged 8 commits into from
Jul 25, 2023
24 changes: 12 additions & 12 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract Blue {
}

/// @notice It is the owner's responsibility to ensure a fee recipient is set before setting a non-zero fee.
function setFee(Market calldata market, uint256 newFee) external onlyOwner {
function setFee(Market memory market, uint256 newFee) external onlyOwner {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(newFee <= MAX_FEE, Errors.MAX_FEE_EXCEEDED);
Expand All @@ -93,7 +93,7 @@ contract Blue {

// Markets management.

function createMarket(Market calldata market) external {
function createMarket(Market memory market) external {
Id id = market.id();
require(isIrmEnabled[market.irm], Errors.IRM_NOT_ENABLED);
require(isLltvEnabled[market.lltv], Errors.LLTV_NOT_ENABLED);
Expand All @@ -104,7 +104,7 @@ contract Blue {

// Supply management.

function supply(Market calldata market, uint256 amount, address onBehalf) external {
function supply(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -120,7 +120,7 @@ contract Blue {
market.borrowableAsset.safeTransferFrom(msg.sender, address(this), amount);
}

function withdraw(Market calldata market, uint256 amount, address onBehalf) external {
function withdraw(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -141,7 +141,7 @@ contract Blue {

// Borrow management.

function borrow(Market calldata market, uint256 amount, address onBehalf) external {
function borrow(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -161,7 +161,7 @@ contract Blue {
market.borrowableAsset.safeTransfer(msg.sender, amount);
}

function repay(Market calldata market, uint256 amount, address onBehalf) external {
function repay(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -180,7 +180,7 @@ contract Blue {
// Collateral management.

/// @dev Don't accrue interests because it's not required and it saves gas.
function supplyCollateral(Market calldata market, uint256 amount, address onBehalf) external {
function supplyCollateral(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -192,7 +192,7 @@ contract Blue {
market.collateralAsset.safeTransferFrom(msg.sender, address(this), amount);
}

function withdrawCollateral(Market calldata market, uint256 amount, address onBehalf) external {
function withdrawCollateral(Market memory market, uint256 amount, address onBehalf) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(amount != 0, Errors.ZERO_AMOUNT);
Expand All @@ -209,7 +209,7 @@ contract Blue {

// Liquidation.

function liquidate(Market calldata market, address borrower, uint256 seized) external {
function liquidate(Market memory market, address borrower, uint256 seized) external {
Id id = market.id();
require(lastUpdate[id] != 0, Errors.MARKET_NOT_CREATED);
require(seized != 0, Errors.ZERO_AMOUNT);
Expand Down Expand Up @@ -257,7 +257,7 @@ contract Blue {

// Interests management.

function _accrueInterests(Market calldata market, Id id) internal {
function _accrueInterests(Market memory market, Id id) internal {
uint256 marketTotalBorrow = totalBorrow[id];

if (marketTotalBorrow != 0) {
Expand All @@ -280,7 +280,7 @@ contract Blue {

// Health check.

function _isHealthy(Market calldata market, Id id, address user) internal view returns (bool) {
function _isHealthy(Market memory market, Id id, address user) internal view returns (bool) {
if (borrowShare[id][user] == 0) return true;

uint256 collateralPrice = market.collateralOracle.price();
Expand All @@ -289,7 +289,7 @@ contract Blue {
return _isHealthy(market, id, user, collateralPrice, borrowablePrice);
}

function _isHealthy(Market calldata market, Id id, address user, uint256 collateralPrice, uint256 borrowablePrice)
function _isHealthy(Market memory market, Id id, address user, uint256 collateralPrice, uint256 borrowablePrice)
internal
view
returns (bool)
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity >=0.5.0;
import {Market} from "src/libraries/MarketLib.sol";

interface IIrm {
function borrowRate(Market calldata market) external returns (uint256);
function borrowRate(Market memory market) external returns (uint256);
}
2 changes: 1 addition & 1 deletion src/libraries/MarketLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Market {
}

library MarketLib {
function id(Market calldata market) internal pure returns (Id) {
function id(Market memory market) internal pure returns (Id) {
return Id.wrap(keccak256(abi.encode(market)));
}
}
2 changes: 1 addition & 1 deletion src/mocks/IrmMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract IrmMock is IIrm {
blue = Blue(blueInstance);
}

function borrowRate(Market calldata market) external view returns (uint256) {
function borrowRate(Market memory market) external view returns (uint256) {
Id id = market.id();
uint256 utilization = blue.totalBorrow(id).divWadDown(blue.totalSupply(id));

Expand Down