Verified contractPartialGPL-2.0-or-later
Blm
Address0xb0ffb27d9d7f160d588c669329f807e58add4eef
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 800 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
- 26,348,677
- Creation transaction
- 0xe92ed82ffa…82fc38a585
5 files
- src/blm/Blm.solmain1.41 KB
- src/interfaces/IBlm.sol852 B
- src/interfaces/IIris.sol5.05 KB
- src/libraries/ConstantsLib.sol1.31 KB
- src/libraries/MathLib.sol1.43 KB
src/blm/Blm.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.35;
import {IBlm} from "../interfaces/IBlm.sol";
import {IIris, Quote} from "../interfaces/IIris.sol";
import {WAD} from "../libraries/ConstantsLib.sol";
import {MathLib} from "../libraries/MathLib.sol";
contract Blm is IBlm {
using MathLib for uint256;
/* IMMUTABLES */
IIris public immutable IRIS;
/* STORAGE */
mapping(address token => uint256) public slope;
mapping(address token => uint256) public intercept;
/* CONSTRUCTOR */
constructor(address iris) {
require(iris != address(0), ZeroAddress());
IRIS = IIris(iris);
}
/* SETTER */
function setParams(address token, uint256 newSlope, uint256 newIntercept) external {
require(msg.sender == IRIS.owner(), Unauthorized());
require(token != address(0), ZeroAddress());
require(newSlope != 0, ZeroAmount());
require(newSlope < WAD && newIntercept < WAD, ParamsTooHigh());
slope[token] = newSlope;
intercept[token] = newIntercept;
emit SetParams(token, newSlope, newIntercept);
}
/* BOND REQUIREMENT */
function bondRequirement(Quote calldata quote) external view returns (uint256) {
uint256 ratio = slope[quote.debtToken].mulDivDown(quote.duration, 1 days) + intercept[quote.debtToken];
return quote.debt.mulDivDown(ratio, WAD);
}
}
src/interfaces/IBlm.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
import {IIris, Quote} from "./IIris.sol";
interface IBlm {
// Events
event SetParams(address token, uint256 newSlope, uint256 newIntercept);
// Errors
error ParamsTooHigh();
error Unauthorized();
error ZeroAddress();
error ZeroAmount();
// Immutables
function IRIS() external view returns (IIris);
// Functions
function slope(address token) external view returns (uint256);
function intercept(address token) external view returns (uint256);
/// @dev A linear function scaled by debt: A(mx + b) = debt * (duration * slope + intercept).
function bondRequirement(Quote calldata quote) external view returns (uint256 bondRequirement);
function setParams(address token, uint256 newSlope, uint256 newIntercept) external;
}
src/interfaces/IIris.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
struct Loan {
address borrower;
address solver;
address collateralToken;
address debtToken;
uint128 venueBitmap;
uint32 maturity;
uint32 overduePeriod;
uint16 fixedRate;
uint16 overdueRate; // added to fixedRate after maturity
uint16 bondLltv;
uint16 fee;
}
struct Position {
uint128 collateral;
uint128 debt;
uint128 bond;
uint128 bondRequirement;
uint128 collateralIndex;
uint128 debtIndex;
uint128 fixedLeg;
uint128 floatingLeg;
uint128 surplus;
uint32 lastUpdate;
uint8 venueId;
bytes data;
}
struct Authorization {
address authorizer;
address authorized;
bool isAuthorized;
uint256 nonce;
uint256 deadline;
}
struct Quote {
address borrower;
address solver;
address receiver;
address blm;
address collateralToken;
address debtToken;
uint256 collateral;
uint256 debt;
uint256 fixedRate;
uint256 duration;
uint256 overdueRate;
uint256 overduePeriod;
uint256 bond;
uint256 bondLltv;
uint256 venueBitmap;
uint256 venueId;
uint256 deadline;
uint256 nonce;
bytes data;
}
interface IIris {
// Errors
error AdapterNotSet();
error AlreadySet();
error BlmNotEnabled();
error BondLltvNotEnabled();
error BondLltvTooHigh();
error FeeTooHigh();
error FixedRateTooHigh();
error HealthyBond();
error HealthyLoan();
error InsufficientBond();
error InsufficientCollateral();
error InvalidData();
error InvalidDuration();
error InvalidNonce();
error InvalidSignature();
error LiquidatableLoan();
error LoanNotCreated();
error LoanNotResolved();
error NotAllowedVenue();
error NotMultipleOfBp();
error OverduePeriodTooHigh();
error OverdueRateTooHigh();
error QuoteExpired();
error SignatureExpired();
error Unauthorized();
error VenueIdTooHigh();
error ZeroAddress();
error ZeroAmount();
// Getters
function DOMAIN_SEPARATOR() external view returns (bytes32);
function getLoan(address pod) external view returns (Loan memory);
function getPosition(address pod) external view returns (Position memory);
// State variables
function POD_IMPL() external view returns (address);
function owner() external view returns (address);
function fee() external view returns (uint16);
function feeRecipient() external view returns (address);
function claimable(address token, address account) external view returns (uint256);
function isBlmEnabled(address blm) external view returns (bool);
function isBondLltvEnabled(uint256 lltv) external view returns (bool);
function isDataEnabled(bytes32 data) external view returns (bool);
function isAuthorized(address authorizer, address authorized) external view returns (bool);
function isQuoteNonceUsed(address solver, uint256 nonce) external view returns (bool);
function nonce(address authorizer) external view returns (uint256);
function venueAdapter(uint256 venueId) external view returns (address);
// Owner functions
function setOwner(address newOwner) external;
function setFee(uint256 newFee) external;
function setFeeRecipient(address newFeeRecipient) external;
function setVenueAdapter(uint256 venueId, address adapter) external;
function enableBlm(address blm) external;
function enableBondLltv(uint256 lltv) external;
function enableData(bytes32 data) external;
function setAuthorization(address authorized, bool newIsAuthorized) external;
function setAuthorizationWithSig(Authorization calldata authorization, bytes calldata signature) external;
// Loan functions
function take(Quote calldata quote, bytes calldata signature) external returns (address pod);
function repay(address pod) external returns (uint256 repaid);
function liquidate(address pod, address receiver) external returns (uint256 repaid, uint256 seized);
// Collateral functions
function supplyCollateral(address pod, uint256 amount) external;
function withdrawCollateral(address pod, uint256 amount, address receiver) external;
// Bond functions
function supplyBond(address pod, uint256 amount) external;
function withdrawBond(address pod, uint256 amount, address receiver) external;
function liquidateBond(address pod, address receiver) external returns (uint256 seized);
// Venue management
function refinance(address pod, address receiver, uint256 venueId, bytes calldata data) external;
function escape(address pod, address receiver) external;
function rebase(address pod) external;
// Interest
// forgefmt: disable-next-line
function accrueLegsView(address pod) external view returns (uint256 collateralIndex, uint256 debtIndex, uint256 fixedLeg, uint256 floatingLeg, uint256 surplus);
function claim(address token, uint256 amount, address onBehalf, address receiver) external;
}
src/libraries/ConstantsLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
uint256 constant WAD = 1e18;
uint256 constant BP = 1e14;
uint256 constant ORACLE_PRICE_SCALE = 1e36;
uint256 constant SECONDS_PER_YEAR = 365 days;
uint256 constant MIN_DURATION = 1 days;
uint256 constant MAX_DURATION = 730 days; // 2 years
uint256 constant MAX_FIXED_RATE = 1e18; // 100%
uint256 constant MAX_OVERDUE_RATE = 1e18;
uint256 constant MAX_OVERDUE_PERIOD = 30 days;
uint256 constant MAX_LIF = 0.15e18;
uint256 constant TIME_TO_MAX_LIF = 15 minutes;
uint256 constant MAX_BOND_LIF = 0.05e18;
uint256 constant LIQUIDATION_CURSOR = 0.5e18;
uint256 constant MAX_FEE = 0.4e18; // 40%
bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)");
bytes32 constant AUTHORIZATION_TYPEHASH =
keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)");
bytes32 constant QUOTE_TYPEHASH = keccak256(
"Quote(address borrower,address solver,address receiver,address blm,address collateralToken,address debtToken,uint256 collateral,uint256 debt,uint256 fixedRate,uint256 duration,uint256 overdueRate,uint256 overduePeriod,uint256 bond,uint256 bondLltv,uint256 venueBitmap,uint256 venueId,uint256 deadline,uint256 nonce,bytes data)"
);
src/libraries/MathLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
library MathLib {
error CastOverflow();
/// @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;
}
/// @dev Returns the min of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns the max of `x` and `y`.
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := xor(x, mul(xor(x, y), gt(y, x)))
}
}
/// @dev Returns max(0, x - y).
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Casts from uint256 to uint128, reverting if input number is too large.
function toUint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max, CastOverflow());
// forge-lint: disable-next-item(unsafe-typecast) safe because x <= type(uint128).max.
return uint128(x);
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 800,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@solady/=lib/solady/src/",
"@morpho-blue/=lib/morpho-blue/src/",
"@aave/=lib/aave-v3-origin/src/",
"@morpho-blue-irm/=lib/morpho-blue-irm/src/",
"@morpho-blue-irm-mb/=lib/morpho-blue-irm/lib/morpho-blue/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/aave-v3-origin/lib/solidity-utils/lib/openzeppelin-contracts-upgradeable/contracts/",
"aave-v3-origin/=lib/aave-v3-origin/",
"ds-test/=lib/aave-v3-origin/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"morpho-blue-irm/=lib/morpho-blue-irm/",
"morpho-blue/=lib/morpho-blue/",
"openzeppelin-contracts-upgradeable/=lib/aave-v3-origin/lib/solidity-utils/lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solady/=lib/solady/src/",
"solidity-utils/=lib/aave-v3-origin/lib/solidity-utils/",
"solmate/=lib/morpho-blue-irm/lib/solmate/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.