Verified contractPartialGPL-2.0-or-later
SetterRatifier
Address0xb72c416382c8a6399d0765cebfb032f040b00b3c
- Balance
0 ETH
- Transactions
78
- Compiler
solc 0.8.34
- Same code
Only this contract
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- Yes, 466 runs
- EVM version
- osaka
- Via IR
- yes
- License
- GPL-2.0-or-later
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,798,183
- Creation transaction
- 0x935b62f793…a376f7b2ae
7 files
- lib/midnight/src/ratifiers/SetterRatifier.solmain2.14 KB
- lib/midnight/src/interfaces/IMidnight.sol9.37 KB
- lib/midnight/src/interfaces/IRatifier.sol295 B
- lib/midnight/src/libraries/ConstantsLib.sol1.76 KB
- lib/midnight/src/libraries/UtilsLib.sol3.02 KB
- lib/midnight/src/ratifiers/interfaces/ISetterRatifier.sol756 B
- lib/midnight/src/ratifiers/libraries/HashLib.sol6.88 KB
lib/midnight/src/ratifiers/SetterRatifier.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity 0.8.34;
import {ISetterRatifier} from "./interfaces/ISetterRatifier.sol";
import {IMidnight, Offer} from "../interfaces/IMidnight.sol";
import {CALLBACK_SUCCESS} from "../libraries/ConstantsLib.sol";
import {HashLib} from "./libraries/HashLib.sol";
/// @dev This ratifier checks that the offer has been ratified by an authorized address in a Merkle tree of offers.
/// To that end, it expects the ratifier data to contain the root of the tree, the leaf index of the offer in the tree,
/// and the proof of the offer in the tree.
/// @dev The root should correspond to the root of the offer tree, which is a Merkle tree of offers.
/// @dev The leaf index determines each hash order during merkle proof verification.
/// @dev This ratifier must only be used with the Midnight instance at MIDNIGHT.
contract SetterRatifier is ISetterRatifier {
address public immutable MIDNIGHT;
mapping(address maker => mapping(bytes32 root => bool)) public isRootRatified;
constructor(address _midnight) {
MIDNIGHT = _midnight;
}
/// @dev All offers in a tree are expected to share the same maker and ratifier. Otherwise all offers in a
/// tree might not be ratified or unratified by a single call to this function.
function setIsRootRatified(address maker, bytes32 root, bool newIsRootRatified) external {
require(maker == msg.sender || IMidnight(MIDNIGHT).isAuthorized(maker, msg.sender), Unauthorized());
isRootRatified[maker][root] = newIsRootRatified;
emit SetIsRootRatified(msg.sender, maker, root, newIsRootRatified);
}
function isRatified(Offer memory offer, bytes memory ratifierData, address) external view returns (bytes32) {
(bytes32 root, uint256 leafIndex, bytes32[] memory proof) =
abi.decode(ratifierData, (bytes32, uint256, bytes32[]));
require(HashLib.isLeaf(root, HashLib.hashOffer(offer), leafIndex, proof), InvalidProof());
require(isRootRatified[offer.maker][root], NotRatified());
return CALLBACK_SUCCESS;
}
}
lib/midnight/src/interfaces/IMidnight.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity >=0.5.0;
struct Market {
uint256 chainId;
address midnight;
address loanToken;
CollateralParams[] collateralParams;
uint256 maturity;
uint256 rcfThreshold;
address enterGate;
address liquidatorGate;
}
struct CollateralParams {
address token;
uint256 lltv;
uint256 liquidationCursor;
address oracle;
}
struct Offer {
Market market;
bool buy;
address maker;
uint256 start;
uint256 expiry;
uint256 tick;
bytes32 group;
address callback;
bytes callbackData;
address receiverIfMakerIsSeller;
address ratifier;
bool reduceOnly;
uint128 maxUnits;
uint128 maxAssets; // buyerAssets if offer.buy else sellerAssets
uint256 continuousFeeCap;
}
/// @dev Settlement fee cbp values and the continuous fee are 0 until the market is created, then set to the default
/// values.
struct MarketState {
uint128 totalUnits;
uint128 lossFactor;
uint128 withdrawable;
uint128 continuousFeeCredit;
uint16 settlementFeeCbp0;
uint16 settlementFeeCbp1;
uint16 settlementFeeCbp2;
uint16 settlementFeeCbp3;
uint16 settlementFeeCbp4;
uint16 settlementFeeCbp5;
uint16 settlementFeeCbp6;
uint32 continuousFee;
uint8 tickSpacing;
}
struct Position {
uint128 credit;
uint128 pendingFee;
uint128 lastLossFactor;
uint128 lastAccrual;
uint128 debt;
uint128 collateralBitmap;
uint128[128] collateral;
}
interface IMidnight {
/// ERRORS ///
error AlreadyConsumed();
error BuyerGatedFromIncreasingCredit();
error CannotIncreaseDebtPostMaturity();
error CollateralParamsNotSorted();
error ConsumedAssets();
error ConsumedUnits();
error ContinuousFeeAboveMax();
error ContinuousFeeAboveOfferCap();
error FeeNotMultipleOfFeeCbp();
error InconsistentInput();
error InvalidChainId();
error InvalidFeeIndex();
error InvalidLiquidationCursor();
error InvalidLltv();
error InvalidMaxLif();
error InvalidMidnight();
error InvalidOfferCaps();
error InvalidTickSpacing();
error LiquidationCursorNotEnabled();
error LiquidatorGatedFromLiquidating();
error LltvNotEnabled();
error MakerCreditOrDebtIncreased();
error MarketLossFactorMaxedOut();
error MarketNotCreated();
error MaturityTooFar();
error MaxLifTooHigh();
error NoCollateralParams();
error NotBorrower();
error NotLiquidatable();
error OfferExpired();
error OfferNotStarted();
error OnlyFeeClaimer();
error OnlyFeeSetter();
error OnlyConfigurator();
error OnlyTickSpacingSetter();
error RatifierFailed();
error RatifierUnauthorized();
error RecoveryCloseFactorConditionsViolated();
error SelfTake();
error SellerGatedFromIncreasingDebt();
error SellerIsLiquidatable();
error SettlementFeeAboveMax();
error TakerUnauthorized();
error TickNotAccessible();
error TooManyActivatedCollaterals();
error TooManyCollateralParams();
error Unauthorized();
error UnhealthyBorrower();
error UnusedReceiverMustBeZero();
error WrongBuyCallbackReturnValue();
error WrongFlashLoanCallbackReturnValue();
error WrongLiquidateCallbackReturnValue();
error WrongRepayCallbackReturnValue();
error WrongSellCallbackReturnValue();
// forgefmt: disable-start
/// STORAGE GETTERS ///
function position(bytes32 id, address user) external view returns (uint128 credit, uint128 pendingFee, uint128 lastLossFactor, uint128 lastAccrual, uint128 debt, uint128 collateralBitmap);
function marketState(bytes32 id) external view returns (uint128 totalUnits, uint128 lossFactor, uint128 withdrawable, uint128 continuousFeeCredit, uint16 settlementFeeCbp0, uint16 settlementFeeCbp1, uint16 settlementFeeCbp2, uint16 settlementFeeCbp3, uint16 settlementFeeCbp4, uint16 settlementFeeCbp5, uint16 settlementFeeCbp6, uint32 continuousFee, uint8 tickSpacing);
function consumed(address user, bytes32 group) external view returns (uint128);
function isAuthorized(address authorizer, address authorized) external view returns (bool);
function defaultSettlementFeeCbp(address loanToken, uint256 index) external view returns (uint16);
function defaultContinuousFee(address loanToken) external view returns (uint32);
function claimableSettlementFee(address token) external view returns (uint256);
function isLltvEnabled(uint256 lltv) external view returns (bool);
function isLiquidationCursorEnabled(uint256 liquidationCursor) external view returns (bool);
function configurator() external view returns (address);
function feeSetter() external view returns (address);
function feeClaimer() external view returns (address);
function tickSpacingSetter() external view returns (address);
/// MULTICALL ///
function multicall(bytes[] memory calls) external;
/// ADMIN FUNCTIONS ///
function setConfigurator(address newConfigurator) external;
function setFeeSetter(address newFeeSetter) external;
function setFeeClaimer(address newFeeClaimer) external;
function setTickSpacingSetter(address newTickSpacingSetter) external;
function enableLltv(uint256 lltv) external;
function enableLiquidationCursor(uint256 liquidationCursor) external;
function setMarketTickSpacing(bytes32 id, uint256 newTickSpacing) external;
function setMarketSettlementFee(bytes32 id, uint256 index, uint256 newSettlementFee) external;
function setDefaultSettlementFee(address loanToken, uint256 index, uint256 newSettlementFee) external;
function setMarketContinuousFee(bytes32 id, uint256 newContinuousFee) external;
function setDefaultContinuousFee(address loanToken, uint256 newContinuousFee) external;
function claimSettlementFee(address token, uint256 amount, address receiver) external;
function claimContinuousFee(Market memory market, uint256 amount, address receiver) external;
/// ENTRY-POINTS ///
function take(Offer memory offer, bytes memory ratifierData, uint256 units, address taker, address receiverIfTakerIsSeller, address takerCallback, bytes memory takerCallbackData) external returns (uint256 buyerAssets, uint256 sellerAssets);
function withdraw(Market memory market, uint256 units, address onBehalf, address receiver) external;
function repay(Market memory market, uint256 units, address onBehalf, address callback, bytes memory data) external;
function supplyCollateral(Market memory market, uint256 collateralIndex, uint256 assets, address onBehalf) external;
function withdrawCollateral(Market memory market, uint256 collateralIndex, uint256 assets, address onBehalf, address receiver) external;
function liquidate(Market memory market, uint256 collateralIndex, uint256 seizedAssets, uint256 repaidUnits, address borrower, bool postMaturityMode, address receiver, address callback, bytes memory data) external returns (uint256 outputSeizedAssets, uint256 outputRepaidUnits);
function setConsumed(bytes32 group, uint128 amount, address onBehalf) external;
function setIsAuthorized(address authorized, bool newIsAuthorized, address onBehalf) external;
function flashLoan(address[] memory tokens, uint256[] memory assets, address callback, bytes memory data) external;
function touchMarket(Market memory market) external returns (bytes32);
/// SLASHING AND CONTINUOUS FEE ACCRUAL ///
function updatePositionView(Market memory market, bytes32 id, address user) external view returns (uint128 newCredit, uint128 newPendingFee, uint128 accruedFee);
function updatePosition(Market memory market, address user) external returns (uint128 newCredit, uint128 newPendingFee, uint128 accruedFee);
/// OTHER VIEW FUNCTIONS ///
function lastLossFactor(bytes32 id, address user) external view returns (uint128);
function collateralBitmap(bytes32 id, address user) external view returns (uint128);
function collateral(bytes32 id, address user, uint256 index) external view returns (uint128);
function toMarket(bytes32 id) external view returns (Market memory);
function credit(bytes32 id, address user) external view returns (uint128);
function debt(bytes32 id, address user) external view returns (uint128);
function totalUnits(bytes32 id) external view returns (uint128);
function lossFactor(bytes32 id) external view returns (uint128);
function tickSpacing(bytes32 id) external view returns (uint8);
function withdrawable(bytes32 id) external view returns (uint128);
function settlementFeeCbps(bytes32 id) external view returns (uint16[7] memory);
function continuousFee(bytes32 id) external view returns (uint32);
function continuousFeeCredit(bytes32 id) external view returns (uint128);
function pendingFee(bytes32 id, address user) external view returns (uint128);
function lastAccrual(bytes32 id, address user) external view returns (uint128);
function liquidationLocked(bytes32 id, address user) external view returns (bool);
function isHealthy(Market memory market, bytes32 id, address borrower) external view returns (bool);
function settlementFee(bytes32 id, uint256 timeToMaturity) external view returns (uint256);
// forgefmt: disable-end
}
lib/midnight/src/interfaces/IRatifier.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity >=0.5.0;
import {Offer} from "./IMidnight.sol";
interface IRatifier {
function isRatified(Offer memory offer, bytes memory ratifierData, address taker) external view returns (bytes32);
}
lib/midnight/src/libraries/ConstantsLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity ^0.8.0;
import {UtilsLib} from "./UtilsLib.sol";
// forgefmt: disable-start
uint256 constant WAD = 1e18;
uint256 constant ORACLE_PRICE_SCALE = 1e36;
uint256 constant CBP = 1e12;
uint256 constant MAX_SETTLEMENT_FEE_0_DAYS = 0.000014e18;
uint256 constant MAX_SETTLEMENT_FEE_1_DAY = 0.000014e18;
uint256 constant MAX_SETTLEMENT_FEE_7_DAYS = 0.000098e18;
uint256 constant MAX_SETTLEMENT_FEE_30_DAYS = 0.000417e18;
uint256 constant MAX_SETTLEMENT_FEE_90_DAYS = 0.00125e18;
uint256 constant MAX_SETTLEMENT_FEE_180_DAYS = 0.0025e18;
uint256 constant MAX_SETTLEMENT_FEE_360_DAYS = 0.005e18;
uint32 constant MAX_CONTINUOUS_FEE = uint32(uint256(0.01e18) / uint256(365 days));
uint256 constant TIME_TO_MAX_LIF = 60 minutes;
uint256 constant MAX_COLLATERALS = 128;
uint256 constant MAX_COLLATERALS_PER_BORROWER = 16;
uint256 constant LIQUIDATION_LOCK_SLOT = uint256(keccak256("morpho.midnight.liquidationLocked"));
bytes32 constant CALLBACK_SUCCESS = keccak256("morpho.midnight.callbackSuccess");
uint8 constant DEFAULT_TICK_SPACING = 4;
/// @dev Returns the max settlement fee for the given index.
function maxSettlementFee(uint256 index) pure returns (uint256) {
return [MAX_SETTLEMENT_FEE_0_DAYS, MAX_SETTLEMENT_FEE_1_DAY, MAX_SETTLEMENT_FEE_7_DAYS, MAX_SETTLEMENT_FEE_30_DAYS, MAX_SETTLEMENT_FEE_90_DAYS, MAX_SETTLEMENT_FEE_180_DAYS, MAX_SETTLEMENT_FEE_360_DAYS][index];
}
/// @dev Returns the max LIF for the given lltv and liquidationCursor.
function maxLif(uint256 lltv, uint256 liquidationCursor) pure returns (uint256) {
return UtilsLib.mulDivDown(WAD, WAD, WAD - UtilsLib.mulDivDown(liquidationCursor, WAD - lltv, WAD));
}
// forgefmt: disable-end
lib/midnight/src/libraries/UtilsLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity ^0.8.0;
library UtilsLib {
error CastOverflow();
/// @dev Returns min(a, b).
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Returns (x * y) / d rounded down.
function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) {
return (x * y) / d;
}
/// @dev Returns (x * y) / d rounded up.
function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) {
return (x * y + (d - 1)) / d;
}
function toUint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max, CastOverflow());
// forge-lint: disable-next-item(unsafe-typecast) as x is less than type(uint128).max
return uint128(x);
}
function countBits(uint128 x) internal pure returns (uint256) {
unchecked {
x = x - ((x >> 1) & 0x55555555555555555555555555555555);
x = (x & 0x33333333333333333333333333333333) + ((x >> 2) & 0x33333333333333333333333333333333);
x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f;
return (x * 0x01010101010101010101010101010101) >> 120;
}
}
/// @dev Assumes bitmap is not zero.
function msb(uint128 bitmap) internal pure returns (uint256 res) {
assembly {
res := sub(255, clz(bitmap))
}
}
/// @dev Assumes bit is less than 128.
function setBit(uint128 bitmap, uint256 bit) internal pure returns (uint128) {
// forge-lint: disable-next-item(unsafe-typecast) as bit < 128
return uint128(bitmap | (1 << bit));
}
/// @dev Assumes bit is less than 128.
function clearBit(uint128 bitmap, uint256 bit) internal pure returns (uint128) {
// forge-lint: disable-next-item(unsafe-typecast)
return uint128(bitmap & ~(1 << bit));
}
/// @dev Sets a boolean in transient storage keyed by a (bytes32, address) pair.
/// @dev Returns the previous value at the written slot.
function tExchange(uint256 baseSlot, bytes32 key1, address key2, bool value) internal returns (bool previous) {
uint256 slot = uint256(keccak256(abi.encode(key1, key2, baseSlot)));
assembly ("memory-safe") {
previous := tload(slot)
tstore(slot, value)
}
}
/// @dev Gets a boolean from transient storage keyed by a (bytes32, address) pair.
function tGet(uint256 baseSlot, bytes32 key1, address key2) internal view returns (bool value) {
uint256 slot = uint256(keccak256(abi.encode(key1, key2, baseSlot)));
assembly ("memory-safe") {
value := tload(slot)
}
}
}
lib/midnight/src/ratifiers/interfaces/ISetterRatifier.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity >=0.5.0;
import {IRatifier} from "../../interfaces/IRatifier.sol";
interface ISetterRatifier is IRatifier {
/// ERRORS ///
error InvalidProof();
error Unauthorized();
error NotRatified();
/// EVENTS ///
event SetIsRootRatified(
address indexed caller, address indexed maker, bytes32 indexed root, bool newIsRootRatified
);
/// FUNCTIONS ///
function setIsRootRatified(address maker, bytes32 root, bool newIsRootRatified) external;
/// STORAGE GETTERS ///
function MIDNIGHT() external view returns (address);
function isRootRatified(address maker, bytes32 root) external view returns (bool);
}
lib/midnight/src/ratifiers/libraries/HashLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2026 Morpho Association
pragma solidity ^0.8.0;
import {Offer, Market, CollateralParams} from "../../interfaces/IMidnight.sol";
/// @dev keccak256("CollateralParams(address token,uint256 lltv,uint256 liquidationCursor,address oracle)").
bytes32 constant COLLATERAL_PARAMS_TYPEHASH = 0x39ed3f928d24fd00574b1a02aba9c2483abcf5d9a3a366118c9a5aa29885b841;
/// @dev keccak256(bytes.concat(MARKET_TYPE, COLLATERAL_PARAMS_TYPE)).
bytes32 constant MARKET_TYPEHASH = 0x510b3862f3816a109c9340b76972e8a30984246be06e034ae12ed2934220391a;
/// @dev keccak256(bytes.concat(OFFER_TYPE, COLLATERAL_PARAMS_TYPE, MARKET_TYPE)).
bytes32 constant OFFER_TYPEHASH = 0x9905214264a9fb7b6cc1b0e33db7a04687c6e4185a84755d29914314aa9d8906;
library HashLib {
error LeafIndexOutOfRange();
error TreeTooHigh();
/// @dev Returns the EIP-712 typehash of OfferTree(Offer[2]...[2] offerTree) with height levels.
/// @dev Same as keccak256(bytes.concat("OfferTree(Offer[2]...[2] offerTree)", COLLATERAL_PARAMS_TYPE,
/// MARKET_TYPE, OFFER_TYPE)).
/// @dev Reverts if height is greater than 20.
function offerTreeTypeHash(uint256 height) internal pure returns (bytes32) {
if (height <= 10) {
if (height == 0) return 0x270da1ebafc0f24637af3612fb8c3a1d828fcb56d3637c24e86dd006b12ca7f9;
if (height == 1) return 0x828b9cdf8326a1cf234328e4d5229546a98fb72ef73624f5b6b31538e555b96c;
if (height == 2) return 0xfcb7a3ca4094246b8185620c4cf025c93032b6f0384805aa3f22afe04290e982;
if (height == 3) return 0xcc97cb1955496a5269b5a7afca62ba694edcab26ba838a1adbd257931249de92;
if (height == 4) return 0xda3feb08db360ad9e09540132ff04d2b6a596fdaa4747892217aaa4c7c9bcc31;
if (height == 5) return 0x15bd6e2aa1a7a61614187ac16d2cbf8610c8f2f3c3d9eaa380ae7a501ee3cf06;
if (height == 6) return 0xb726cb7fab1a24c28213cbd482fa5a301f127fb25feb01da341919983a72711a;
if (height == 7) return 0xcea9cd557c6f821868ea287304199d0e0554af630bfa8fe36c64eb3bbacca418;
if (height == 8) return 0xf7dbde8234e8e345cec8fc0a8ac5909ee336b214882751ecd51e7b37df4f6cdd;
if (height == 9) return 0x5400a5d43d39e6bfe910af8cb84ac77bf501d310413769dffd62ccecda8b00c6;
return 0x0754209b60d99d0822b3ecd5a970f9db09df9c8998a8441e24b81f06d6c76fee;
} else {
if (height == 11) return 0xf5d561d88647c3b38ed6636709d3166819fc66f8ed52a0daf4ae186387b4646c;
if (height == 12) return 0x5801c07a6c7df039ce00a7a2b8bd92aa1cf333c30b0bc3d78768590b6063d09e;
if (height == 13) return 0xc9da7190eaf4b14c7cb1c14f9898256c0adb6b1dc303afe79594dea64fe199c0;
if (height == 14) return 0xa47534c85ac57c583568465d40fd46683d2d558d8129fe1aca01e93023afca92;
if (height == 15) return 0xb1e841691fb54f4ef85e2ed9de45d610e57f49e1e6eb2510ceead16e447dd519;
if (height == 16) return 0x4fa4f16f09f0c36c7670449a4032073380d28a60071e12ee8874bb3e5a8318fc;
if (height == 17) return 0x817bbaac8bb863670f488b454cdd5d0990d9d81871a68e9df381c3c13d3f2ba2;
if (height == 18) return 0xc447f06079bddf4b011523c4bce119e9e90fdf937de4ee88f48010406560e9c1;
if (height == 19) return 0x1608d5eb56943c667c34b413f9f8a1c24a84ddfe1301a9c25487e638de1f5822;
if (height == 20) return 0x3a677100d2e855c24a62d1e9c365bff90d02287f066a07064843ca1ee70ea113;
revert TreeTooHigh();
}
}
/// @dev Verifies a Merkle proof using the leaf index to determine the left/right position of each sibling.
/// @dev Works for offer-tree heights up to 256, the bit-width of leafIndex.
function isLeaf(bytes32 root, bytes32 leafHash, uint256 leafIndex, bytes32[] memory proof)
internal
pure
returns (bool)
{
require(leafIndex >> proof.length == 0, LeafIndexOutOfRange());
bytes32 currentHash = leafHash;
for (uint256 i = 0; i < proof.length; i++) {
currentHash = (leafIndex >> i) & 1 == 0 ? hashNode(currentHash, proof[i]) : hashNode(proof[i], currentHash);
}
return currentHash == root;
}
/// @dev Returns the keccak256 hash of the concatenation of left and right.
function hashNode(bytes32 left, bytes32 right) internal pure returns (bytes32 value) {
assembly ("memory-safe") {
mstore(0x00, left)
mstore(0x20, right)
value := keccak256(0x00, 0x40)
}
}
/// @dev Computes the EIP-712 hash struct of a CollateralParams.
function hashCollateralParams(CollateralParams memory collateralParams) internal pure returns (bytes32) {
return keccak256(
abi.encode(
COLLATERAL_PARAMS_TYPEHASH,
collateralParams.token,
collateralParams.lltv,
collateralParams.liquidationCursor,
collateralParams.oracle
)
);
}
/// @dev Computes the EIP-712 hash struct of a Market.
function hashMarket(Market memory market) internal pure returns (bytes32) {
bytes32[] memory collateralParamsHashes = new bytes32[](market.collateralParams.length);
for (uint256 i = 0; i < market.collateralParams.length; i++) {
collateralParamsHashes[i] = hashCollateralParams(market.collateralParams[i]);
}
bytes32 collateralParamsHash;
// same as keccak256(abi.encodePacked(collateralParamsHashes));
assembly ("memory-safe") {
collateralParamsHash := keccak256(
add(collateralParamsHashes, 0x20),
mul(mload(collateralParamsHashes), 0x20)
)
}
return keccak256(
abi.encode(
MARKET_TYPEHASH,
market.chainId,
market.midnight,
market.loanToken,
collateralParamsHash,
market.maturity,
market.rcfThreshold,
market.enterGate,
market.liquidatorGate
)
);
}
/// @dev Computes the EIP-712 hash struct of an Offer.
function hashOffer(Offer memory offer) internal pure returns (bytes32) {
return keccak256(
abi.encode(
OFFER_TYPEHASH,
hashMarket(offer.market),
offer.buy,
offer.maker,
offer.start,
offer.expiry,
offer.tick,
offer.group,
offer.callback,
keccak256(offer.callbackData),
offer.receiverIfMakerIsSeller,
offer.ratifier,
offer.reduceOnly,
offer.maxUnits,
offer.maxAssets,
offer.continuousFeeCap
)
);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 466,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"solmate/=lib/bundler3/lib/permit2/lib/solmate/",
"@openzeppelin/contracts/=lib/metamorpho-1.1/lib/openzeppelin-contracts/contracts/",
"bundler3/=lib/bundler3/",
"bundles/=lib/bundles/",
"ds-test/=lib/metamorpho-1.1/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/metamorpho-1.1/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/bundler3/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/morpho-blue/lib/halmos-cheatcodes/src/",
"metamorpho-1.1/=lib/metamorpho-1.1/",
"metamorpho-v1.1/=lib/vault-v2/lib/metamorpho-v1.1/",
"metamorpho/=lib/vault-v2/lib/metamorpho/",
"midnight/=lib/midnight/",
"morpho-blue-irm/=lib/morpho-blue-irm/src/",
"morpho-blue-oracles/=lib/morpho-blue-oracles/src/",
"morpho-blue/=lib/morpho-blue/",
"murky/=lib/universal-rewards-distributor/lib/murky/src/",
"openzeppelin-contracts/=lib/metamorpho-1.1/lib/openzeppelin-contracts/",
"openzeppelin/=lib/universal-rewards-distributor/lib/openzeppelin-contracts/contracts/",
"permit2/=lib/bundler3/lib/permit2/",
"pre-liquidation/=lib/pre-liquidation/src/",
"public-allocator/=lib/public-allocator/src/",
"safe-smart-account/=lib/safe-smart-account/",
"universal-rewards-distributor/=lib/universal-rewards-distributor/src/",
"vault-v2-adapter-registries/=lib/vault-v2-adapter-registries/src/",
"vault-v2/=lib/vault-v2/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.