Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xB88902f8...865722bc2 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
DmaMorphoBlueStopLossCommandV2
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: AGPL-3.0-or-later /// DmaMorphoBlueStopLossCommandV2.sol // Copyright (C) 2024 Oazo Apps Limited // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. pragma solidity 0.8.22; import {IServiceRegistry} from "../interfaces/IServiceRegistry.sol"; import {RatioUtils} from "../libs/RatioUtils.sol"; import {IAccountImplementation} from "../interfaces/IAccountImplementation.sol"; import {IOperationExecutor, Call} from "../interfaces/IOperationExecutor.sol"; import {BaseDMACommand, ICommand, CommonTriggerData} from "./BaseDMACommand.sol"; import {IMorpho, MarketParams, Position, Id} from "./../interfaces/MorphoBlue/IMorpho.sol"; import {IOracle} from "./../interfaces/MorphoBlue/IOracle.sol"; import "./../libs/Morpho/MorphoUtils.sol"; struct StopLossTriggerData { CommonTriggerData commonTriggerData; Id poolId; // ID from MarketParams uint256 executionLtv; // Execution loan-to-value ratio bool closeToCollateral; // Close to collateral flag } /** * @title DmaMorphoBlueStopLossCommandV2 */ contract DmaMorphoBlueStopLossCommandV2 is BaseDMACommand { IMorpho public immutable morphoBlue; string private constant MORPHO_BLUE = "MORPHO_BLUE"; uint16 private constant MORPHO_BLUE_SL_TRIGGER_TYPE = 142; uint256 private constant MAX_LTV_SL_OFFSET = 100; uint8 private constant LTV_DECIMAL_PRECISION = 4; constructor(IServiceRegistry _serviceRegistry) BaseDMACommand(_serviceRegistry) { address morphoBlueAddress = _serviceRegistry.getRegisteredService(MORPHO_BLUE); if (morphoBlueAddress == address(0)) { revert EmptyAddress(MORPHO_BLUE); } morphoBlue = IMorpho(morphoBlueAddress); } /** * @inheritdoc ICommand */ function isExecutionCorrect(bytes memory triggerData) external view override returns (bool) { StopLossTriggerData memory stopLossTriggerData = abi.decode( triggerData, (StopLossTriggerData) ); Position memory position = morphoBlue.position(stopLossTriggerData.poolId, stopLossTriggerData.commonTriggerData.positionAddress); // CloseToCollateral (close but keep collateral on protocol) if (stopLossTriggerData.closeToCollateral) { // we check if the position has collateral but no debt return (position.collateral > 0 && position.borrowShares == 0); } else { // we check if the position has no debt and no collateral return (position.collateral == 0 && position.borrowShares == 0); } } function execute(bytes calldata executionData, bytes memory triggerData) external { StopLossTriggerData memory stopLossTriggerData = abi.decode( triggerData, (StopLossTriggerData) ); uint16[] memory triggerTypes = new uint16[](1); triggerTypes[0] = MORPHO_BLUE_SL_TRIGGER_TYPE; _validateTriggerType(triggerTypes, stopLossTriggerData.commonTriggerData.triggerType); _validateSelector(operationExecutor.executeOp.selector, executionData); bytes32 operationName = IAccountImplementation( stopLossTriggerData.commonTriggerData.positionAddress ).execute(address(operationExecutor), executionData); _validateOperationName(stopLossTriggerData.commonTriggerData.operationName, operationName); } /** * @inheritdoc ICommand */ function isTriggerDataValid( bool isContinuous, bytes memory triggerData ) external view override returns (bool) { StopLossTriggerData memory stopLossTriggerData = abi.decode( triggerData, (StopLossTriggerData) ); uint256 maxExecutionLtv = (MorphoUtils.getMaxLTV(morphoBlue, stopLossTriggerData.poolId, LTV_DECIMAL_PRECISION) - MAX_LTV_SL_OFFSET); bool executionLtvBelowMaxAllowed = stopLossTriggerData.executionLtv < maxExecutionLtv; // assure that the trigger type is the correct one uint16[] memory triggerTypes = new uint16[](1); triggerTypes[0] = MORPHO_BLUE_SL_TRIGGER_TYPE; bool triggerTypeCorrect = _isTriggerTypeValid( triggerTypes, stopLossTriggerData.commonTriggerData.triggerType ); return !isContinuous && triggerTypeCorrect && executionLtvBelowMaxAllowed; } /** * @inheritdoc ICommand */ function isExecutionLegal(bytes memory triggerData) external view override returns (bool) { StopLossTriggerData memory stopLossTriggerData = abi.decode( triggerData, (StopLossTriggerData) ); Position memory position = morphoBlue.position(stopLossTriggerData.poolId, stopLossTriggerData.commonTriggerData.positionAddress); /* if there is no debt or collateral we skip the checks - it will happen eg if the user closed the position but haven't removed the trigger */ if (position.collateral == 0 || position.borrowShares == 0) { return false; } uint256 ltv = MorphoUtils.calculateLTV( morphoBlue, morphoBlue.idToMarketParams(stopLossTriggerData.poolId), position, stopLossTriggerData.commonTriggerData.positionAddress ); bool isLtvAboveExecutionThreshold = ltv >= stopLossTriggerData.executionLtv; return isLtvAboveExecutionThreshold; } function getTriggerType(bytes calldata triggerData) external view override returns (uint16) { StopLossTriggerData memory stopLossTriggerData = abi.decode( triggerData, (StopLossTriggerData) ); if (!this.isTriggerDataValid(false, triggerData)) { return 0; } return stopLossTriggerData.commonTriggerData.triggerType; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: AGPL-3.0-or-later /// BaseDMACommand.sol // Copyright (C) 2023 Oazo Apps Limited // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. pragma solidity 0.8.22; import { RatioUtils } from "../libs/RatioUtils.sol"; import { ICommand } from "../interfaces/ICommand.sol"; import { IServiceRegistry } from "../interfaces/IServiceRegistry.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import { IOperationExecutorV5, Call } from "../interfaces/IOperationExecutorV5.sol"; struct CommonTriggerData { address positionAddress; // Address of the position - dpm proxy uint16 triggerType; // Type of trigger uint256 maxCoverage; // Maximum coverage amount - max amount of additional debt taken to cover execution gas fee address debtToken; // Address of the debt token address collateralToken; // Address of the collateral token bytes32 operationName; // Operation name } /** * @title BaseDMACommand * @dev Abstract contract that serves as the base for DMA based commands. * It implements common functionality and error handling for DMA commands. */ abstract contract BaseDMACommand is ReentrancyGuard, ICommand { // Error declarations error EmptyAddress(string name); error CommandAlreadyExists(address command); error InvalidTriggerType(); error CallerNotAutomationBot(address caller); error InvalidOperationName(bytes32 operationName); error InvalidSelector(bytes4 selector); error ExecutionNotLegal(); using RatioUtils for uint256; address public immutable bot; address public immutable self; address public immutable weth; IOperationExecutorV5 public immutable operationExecutor; string private constant AUTOMATION_BOT = "AUTOMATION_BOT_V2"; string private constant OPERATION_EXECUTOR = "OperationExecutor_5"; string private constant WETH = "WETH"; uint256 public constant MIN_ALLOWED_DEVIATION = 50; // corrresponds to 0.5% /** * @dev Modifier to restrict access to only the automation bot. * Reverts with an error message if the caller is not the automation bot. */ modifier onlyBot() { if (bot != msg.sender) { revert CallerNotAutomationBot(msg.sender); } _; } /** * @dev Constructor function. * @param _serviceRegistry The address of the service registry contract. */ constructor(IServiceRegistry _serviceRegistry) { // Validate service registry address if (address(_serviceRegistry) == address(0)) { revert EmptyAddress("service registry"); } // Get the address of the automation bot from the service registry bot = _serviceRegistry.getRegisteredService(AUTOMATION_BOT); // Validate automation bot address if (bot == address(0)) { revert EmptyAddress("bot"); } // Get the address of the operation executor from the service registry operationExecutor = IOperationExecutorV5( _serviceRegistry.getRegisteredService(OPERATION_EXECUTOR) ); // Validate operation executor address if (address(operationExecutor) == address(0)) { revert EmptyAddress("operation executor"); } // Get the address of the WETH token from the service registry weth = _serviceRegistry.getRegisteredService(WETH); // Validate WETH address if (weth == address(0)) { revert EmptyAddress("weth"); } self = address(this); } /** * @dev Checks if the provided deviation is valid. * @param deviation The deviation value to check. * @return A boolean indicating whether the deviation is valid or not. */ function _isDeviationValid(uint256 deviation) internal pure returns (bool) { return deviation >= MIN_ALLOWED_DEVIATION; } /** * @dev Checks if the provided base fee is valid. * @param maxAcceptableBaseFeeInGwei The maximum acceptable base fee in Gwei. * @return A boolean indicating whether the base fee is valid or not. */ function _isBaseFeeValid(uint256 maxAcceptableBaseFeeInGwei) internal view returns (bool) { return block.basefee <= maxAcceptableBaseFeeInGwei * 1 gwei; } /** * @dev Validates the trigger type against the expected trigger types. * @param expectedTriggerTypes The array of expected trigger types. * @param triggerType The trigger type to be validated. */ function _validateTriggerType( uint16[] memory expectedTriggerTypes, uint16 triggerType ) internal pure { if (!_isTriggerTypeValid(expectedTriggerTypes, triggerType)) { revert InvalidTriggerType(); } } /** * @dev Checks if the given trigger type is valid. * @param expectedTriggerTypes The trigger type to check. * @param triggerType expected trigger type. * @return A boolean indicating whether the trigger type is valid or not. */ function _isTriggerTypeValid( uint16[] memory expectedTriggerTypes, uint16 triggerType ) internal pure returns (bool) { for (uint256 i = 0; i < expectedTriggerTypes.length; i++) { if (expectedTriggerTypes[i] == triggerType) { return true; } } return false; } /** * @dev Validates the selector. Reverts in case it is not. * @param expectedSelector The expected selector. * @param executionData The execution data containing the selector. */ function _validateSelector(bytes4 expectedSelector, bytes memory executionData) internal pure { bytes4 selector = abi.decode(executionData, (bytes4)); if (!_isSelectorValid(expectedSelector, selector)) { revert InvalidSelector(selector); } } /** * @dev Checks if the given selector is valid by comparing it with the expected selector. * @param expectedSelector The expected selector. * @param selector The selector to be checked. * @return A boolean indicating whether the selector is valid or not. */ function _isSelectorValid( bytes4 expectedSelector, bytes4 selector ) internal pure returns (bool) { return selector == expectedSelector; } /** * @dev Validates the operation name. * @param expectedOpName The expected operation name byte string stored in trigger data. * @param actualOpName The actual operation name byte string computed from the calls. */ function _validateOperationName(bytes32 expectedOpName, bytes32 actualOpName) internal pure { // Compare the bytes32 form of operation name with the expected operation name (bytes32) if (expectedOpName != actualOpName) { revert InvalidOperationName(expectedOpName); } } }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.0; interface IAccountImplementation { function execute( address _target, bytes memory _data ) external payable returns (bytes32 response); function send(address _target, bytes memory _data) external payable; function guard() external view returns (address); function owner() external view returns (address); }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.0; /** * @title Command Interface */ interface ICommand { /** * @notice Checks the validity of the trigger data when the trigger is created * @param triggerData Encoded trigger data struct * @return Correctness of the trigger data */ function isTriggerDataValid( bool continuous, bytes memory triggerData ) external view returns (bool); function getTriggerType(bytes calldata triggerData) external view returns (uint16); /** * @notice Returns the correctness of the vault state post execution of the command. * @param triggerData Encoded trigger data struct * @return Correctness of the trigger execution */ function isExecutionCorrect(bytes memory triggerData) external view returns (bool); /** * @notice Checks the validity of the trigger data when the trigger is executed * @param triggerData Encoded trigger data struct * @return Correctness of the trigger data during execution */ function isExecutionLegal(bytes memory triggerData) external view returns (bool); /** * @notice Executes the trigger * @param executionData Execution data from the Automation Worker * @param triggerData Encoded trigger data struct */ function execute(bytes calldata executionData, bytes memory triggerData) external; }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity 0.8.22; struct Call { bytes32 targetHash; bytes callData; bool skipped; } interface IOperationExecutor { function executeOp(Call[] memory calls, string calldata operationName) external payable; }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity 0.8.22; struct Call { bytes32 targetHash; bytes callData; } interface IOperationExecutorV5 { function executeOp(Call[] memory calls) external payable returns (bytes32); }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity 0.8.22; interface IServiceRegistry { function getRegisteredService(string memory) external view returns (address); function getServiceAddress(bytes32 serviceNameHash) external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.2; import {MarketParams, Market} from "./IMorpho.sol"; /// @title IIrm /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Interface that IRMs used by Morpho must implement. interface IIrm { /// @notice Returns the borrow rate of the market `marketParams`. /// @param marketParams The MarketParams struct of the market. /// @param market The Market struct of the market. function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256); /// @notice Returns the borrow rate of the market `marketParams` without modifying any storage. /// @param marketParams The MarketParams struct of the market. /// @param market The Market struct of the market. function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; type Id is bytes32; struct MarketParams { address loanToken; address collateralToken; address oracle; address irm; uint256 lltv; } /// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest /// accrual. struct Position { uint256 supplyShares; uint128 borrowShares; uint128 collateral; } /// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `totalSupplyShares` does not contain the additional shares accrued by `feeRecipient` since the last /// interest accrual. struct Market { uint128 totalSupplyAssets; uint128 totalSupplyShares; uint128 totalBorrowAssets; uint128 totalBorrowShares; uint128 lastUpdate; uint128 fee; } struct Authorization { address authorizer; address authorized; bool isAuthorized; uint256 nonce; uint256 deadline; } struct Signature { uint8 v; bytes32 r; bytes32 s; } /// @dev This interface is used for factorizing IMorphoStaticTyping and IMorpho. /// @dev Consider using the IMorpho interface instead of this one. interface IMorphoBase { /// @notice The EIP-712 domain separator. /// @dev Warning: Every EIP-712 signed message based on this domain separator can be reused on another chain sharing /// the same chain id because the domain separator would be the same. function DOMAIN_SEPARATOR() external view returns (bytes32); /// @notice The owner of the contract. /// @dev It has the power to change the owner. /// @dev It has the power to set fees on markets and set the fee recipient. /// @dev It has the power to enable but not disable IRMs and LLTVs. function owner() external view returns (address); /// @notice The fee recipient of all markets. /// @dev The recipient receives the fees of a given market through a supply position on that market. function feeRecipient() external view returns (address); /// @notice Whether the `irm` is enabled. function isIrmEnabled(address irm) external view returns (bool); /// @notice Whether the `lltv` is enabled. function isLltvEnabled(uint256 lltv) external view returns (bool); /// @notice Whether `authorized` is authorized to modify `authorizer`'s position on all markets. /// @dev Anyone is authorized to modify their own positions, regardless of this variable. function isAuthorized(address authorizer, address authorized) external view returns (bool); /// @notice The `authorizer`'s current nonce. Used to prevent replay attacks with EIP-712 signatures. function nonce(address authorizer) external view returns (uint256); /// @notice Sets `newOwner` as `owner` of the contract. /// @dev Warning: No two-step transfer ownership. /// @dev Warning: The owner can be set to the zero address. function setOwner(address newOwner) external; /// @notice Enables `irm` as a possible IRM for market creation. /// @dev Warning: It is not possible to disable an IRM. function enableIrm(address irm) external; /// @notice Enables `lltv` as a possible LLTV for market creation. /// @dev Warning: It is not possible to disable a LLTV. function enableLltv(uint256 lltv) external; /// @notice Sets the `newFee` for the given market `marketParams`. /// @param newFee The new fee, scaled by WAD. /// @dev Warning: The recipient can be the zero address. function setFee(MarketParams memory marketParams, uint256 newFee) external; /// @notice Sets `newFeeRecipient` as `feeRecipient` of the fee. /// @dev Warning: If the fee recipient is set to the zero address, fees will accrue there and will be lost. /// @dev Modifying the fee recipient will allow the new recipient to claim any pending fees not yet accrued. To /// ensure that the current recipient receives all due fees, accrue interest manually prior to making any changes. function setFeeRecipient(address newFeeRecipient) external; /// @notice Creates the market `marketParams`. /// @dev Here is the list of assumptions on the market's dependencies (tokens, IRM and oracle) that guarantees /// Morpho behaves as expected: /// - The token should be ERC-20 compliant, except that it can omit return values on `transfer` and `transferFrom`. /// - The token balance of Morpho should only decrease on `transfer` and `transferFrom`. In particular, tokens with /// burn functions are not supported. /// - The token should not re-enter Morpho on `transfer` nor `transferFrom`. /// - The token balance of the sender (resp. receiver) should decrease (resp. increase) by exactly the given amount /// on `transfer` and `transferFrom`. In particular, tokens with fees on transfer are not supported. /// - The IRM should not re-enter Morpho. /// - The oracle should return a price with the correct scaling. /// @dev Here is a list of properties on the market's dependencies that could break Morpho's liveness properties /// (funds could get stuck): /// - The token can revert on `transfer` and `transferFrom` for a reason other than an approval or balance issue. /// - A very high amount of assets (~1e35) supplied or borrowed can make the computation of `toSharesUp` and /// `toSharesDown` overflow. /// - The IRM can revert on `borrowRate`. /// - A very high borrow rate returned by the IRM can make the computation of `interest` in `_accrueInterest` /// overflow. /// - The oracle can revert on `price`. Note that this can be used to prevent `borrow`, `withdrawCollateral` and /// `liquidate` from being used under certain market conditions. /// - A very high price returned by the oracle can make the computation of `maxBorrow` in `_isHealthy` overflow, or /// the computation of `assetsRepaid` in `liquidate` overflow. /// @dev The borrow share price of a market with less than 1e4 assets borrowed can be decreased by manipulations, to /// the point where `totalBorrowShares` is very large and borrowing overflows. function createMarket(MarketParams memory marketParams) external; /// @notice Supplies `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's /// `onMorphoSupply` function with the given `data`. /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the /// caller is guaranteed to have `assets` tokens pulled from their balance, but the possibility to mint a specific /// amount of shares is given for full compatibility and precision. /// @dev Supplying a large amount can revert for overflow. /// @dev Supplying an amount of shares may lead to supply more or fewer assets than expected due to slippage. /// Consider using the `assets` parameter to avoid this. /// @param marketParams The market to supply assets to. /// @param assets The amount of assets to supply. /// @param shares The amount of shares to mint. /// @param onBehalf The address that will own the increased supply position. /// @param data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed. /// @return assetsSupplied The amount of assets supplied. /// @return sharesSupplied The amount of shares minted. function supply( MarketParams memory marketParams, uint256 assets, uint256 shares, address onBehalf, bytes memory data ) external returns (uint256 assetsSupplied, uint256 sharesSupplied); /// @notice Withdraws `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`. /// @dev Either `assets` or `shares` should be zero. To withdraw max, pass the `shares`'s balance of `onBehalf`. /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions. /// @dev Withdrawing an amount corresponding to more shares than supplied will revert for underflow. /// @dev It is advised to use the `shares` input when withdrawing the full position to avoid reverts due to /// conversion roundings between shares and assets. /// @param marketParams The market to withdraw assets from. /// @param assets The amount of assets to withdraw. /// @param shares The amount of shares to burn. /// @param onBehalf The address of the owner of the supply position. /// @param receiver The address that will receive the withdrawn assets. /// @return assetsWithdrawn The amount of assets withdrawn. /// @return sharesWithdrawn The amount of shares burned. function withdraw( MarketParams memory marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver ) external returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn); /// @notice Borrows `assets` or `shares` on behalf of `onBehalf` and sends the assets to `receiver`. /// @dev Either `assets` or `shares` should be zero. Most use cases should rely on `assets` as an input so the /// caller is guaranteed to borrow `assets` of tokens, but the possibility to mint a specific amount of shares is /// given for full compatibility and precision. /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions. /// @dev Borrowing a large amount can revert for overflow. /// @dev Borrowing an amount of shares may lead to borrow fewer assets than expected due to slippage. /// Consider using the `assets` parameter to avoid this. /// @param marketParams The market to borrow assets from. /// @param assets The amount of assets to borrow. /// @param shares The amount of shares to mint. /// @param onBehalf The address that will own the increased borrow position. /// @param receiver The address that will receive the borrowed assets. /// @return assetsBorrowed The amount of assets borrowed. /// @return sharesBorrowed The amount of shares minted. function borrow( MarketParams memory marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver ) external returns (uint256 assetsBorrowed, uint256 sharesBorrowed); /// @notice Repays `assets` or `shares` on behalf of `onBehalf`, optionally calling back the caller's /// `onMorphoReplay` function with the given `data`. /// @dev Either `assets` or `shares` should be zero. To repay max, pass the `shares`'s balance of `onBehalf`. /// @dev Repaying an amount corresponding to more shares than borrowed will revert for underflow. /// @dev It is advised to use the `shares` input when repaying the full position to avoid reverts due to conversion /// roundings between shares and assets. /// @dev An attacker can front-run a repay with a small repay making the transaction revert for underflow. /// @param marketParams The market to repay assets to. /// @param assets The amount of assets to repay. /// @param shares The amount of shares to burn. /// @param onBehalf The address of the owner of the debt position. /// @param data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed. /// @return assetsRepaid The amount of assets repaid. /// @return sharesRepaid The amount of shares burned. function repay( MarketParams memory marketParams, uint256 assets, uint256 shares, address onBehalf, bytes memory data ) external returns (uint256 assetsRepaid, uint256 sharesRepaid); /// @notice Supplies `assets` of collateral on behalf of `onBehalf`, optionally calling back the caller's /// `onMorphoSupplyCollateral` function with the given `data`. /// @dev Interest are not accrued since it's not required and it saves gas. /// @dev Supplying a large amount can revert for overflow. /// @param marketParams The market to supply collateral to. /// @param assets The amount of collateral to supply. /// @param onBehalf The address that will own the increased collateral position. /// @param data Arbitrary data to pass to the `onMorphoSupplyCollateral` callback. Pass empty data if not needed. function supplyCollateral( MarketParams memory marketParams, uint256 assets, address onBehalf, bytes memory data ) external; /// @notice Withdraws `assets` of collateral on behalf of `onBehalf` and sends the assets to `receiver`. /// @dev `msg.sender` must be authorized to manage `onBehalf`'s positions. /// @dev Withdrawing an amount corresponding to more collateral than supplied will revert for underflow. /// @param marketParams The market to withdraw collateral from. /// @param assets The amount of collateral to withdraw. /// @param onBehalf The address of the owner of the collateral position. /// @param receiver The address that will receive the collateral assets. function withdrawCollateral( MarketParams memory marketParams, uint256 assets, address onBehalf, address receiver ) external; /// @notice Liquidates the given `repaidShares` of debt asset or seize the given `seizedAssets` of collateral on the /// given market `marketParams` of the given `borrower`'s position, optionally calling back the caller's /// `onMorphoLiquidate` function with the given `data`. /// @dev Either `seizedAssets` or `repaidShares` should be zero. /// @dev Seizing more than the collateral balance will underflow and revert without any error message. /// @dev Repaying more than the borrow balance will underflow and revert without any error message. /// @dev An attacker can front-run a liquidation with a small repay making the transaction revert for underflow. /// @param marketParams The market of the position. /// @param borrower The owner of the position. /// @param seizedAssets The amount of collateral to seize. /// @param repaidShares The amount of shares to repay. /// @param data Arbitrary data to pass to the `onMorphoLiquidate` callback. Pass empty data if not needed. /// @return The amount of assets seized. /// @return The amount of assets repaid. function liquidate( MarketParams memory marketParams, address borrower, uint256 seizedAssets, uint256 repaidShares, bytes memory data ) external returns (uint256, uint256); /// @notice Executes a flash loan. /// @dev Flash loans have access to the whole balance of the contract (the liquidity and deposited collateral of all /// markets combined, plus donations). /// @dev Warning: Not ERC-3156 compliant but compatibility is easily reached: /// - `flashFee` is zero. /// - `maxFlashLoan` is the token's balance of this contract. /// - The receiver of `assets` is the caller. /// @param token The token to flash loan. /// @param assets The amount of assets to flash loan. /// @param data Arbitrary data to pass to the `onMorphoFlashLoan` callback. function flashLoan(address token, uint256 assets, bytes calldata data) external; /// @notice Sets the authorization for `authorized` to manage `msg.sender`'s positions. /// @param authorized The authorized address. /// @param newIsAuthorized The new authorization status. function setAuthorization(address authorized, bool newIsAuthorized) external; /// @notice Sets the authorization for `authorization.authorized` to manage `authorization.authorizer`'s positions. /// @dev Warning: Reverts if the signature has already been submitted. /// @dev The signature is malleable, but it has no impact on the security here. /// @dev The nonce is passed as argument to be able to revert with a different error message. /// @param authorization The `Authorization` struct. /// @param signature The signature. function setAuthorizationWithSig( Authorization calldata authorization, Signature calldata signature ) external; /// @notice Accrues interest for the given market `marketParams`. function accrueInterest(MarketParams memory marketParams) external; /// @notice Returns the data stored on the different `slots`. function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory); } /// @dev This interface is inherited by Morpho so that function signatures are checked by the compiler. /// @dev Consider using the IMorpho interface instead of this one. interface IMorphoStaticTyping is IMorphoBase { /// @notice The state of the position of `user` on the market corresponding to `id`. /// @dev Warning: For `feeRecipient`, `supplyShares` does not contain the accrued shares since the last interest /// accrual. function position( Id id, address user ) external view returns (uint256 supplyShares, uint128 borrowShares, uint128 collateral); /// @notice The state of the market corresponding to `id`. /// @dev Warning: `totalSupplyAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `totalBorrowAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last interest /// accrual. function market( Id id ) external view returns ( uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee ); /// @notice The market params corresponding to `id`. /// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer /// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`. function idToMarketParams( Id id ) external view returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv); } /// @title IMorpho /// @author Morpho Labs /// @custom:contact [email protected] /// @dev Use this interface for Morpho to have access to all the functions with the appropriate function signatures. interface IMorpho is IMorphoBase { /// @notice The state of the position of `user` on the market corresponding to `id`. /// @dev Warning: For `feeRecipient`, `p.supplyShares` does not contain the accrued shares since the last interest /// accrual. function position(Id id, address user) external view returns (Position memory p); /// @notice The state of the market corresponding to `id`. /// @dev Warning: `m.totalSupplyAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `m.totalBorrowAssets` does not contain the accrued interest since the last interest accrual. /// @dev Warning: `m.totalSupplyShares` does not contain the accrued shares by `feeRecipient` since the last /// interest accrual. function market(Id id) external view returns (Market memory m); /// @notice The market params corresponding to `id`. /// @dev This mapping is not used in Morpho. It is there to enable reducing the cost associated to calldata on layer /// 2s by creating a wrapper contract with functions that take `id` as input instead of `marketParams`. function idToMarketParams(Id id) external view returns (MarketParams memory); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title IOracle /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Interface that oracles used by Morpho must implement. /// @dev It is the user's responsibility to select markets with safe oracles. interface IOracle { /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` /// decimals of precision. function price() external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title ErrorsLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library exposing error messages. library ErrorsLib { /// @notice Thrown when the caller is not the owner. string internal constant NOT_OWNER = "not owner"; /// @notice Thrown when the LLTV to enable exceeds the maximum LLTV. string internal constant MAX_LLTV_EXCEEDED = "max LLTV exceeded"; /// @notice Thrown when the fee to set exceeds the maximum fee. string internal constant MAX_FEE_EXCEEDED = "max fee exceeded"; /// @notice Thrown when the value is already set. string internal constant ALREADY_SET = "already set"; /// @notice Thrown when the IRM is not enabled at market creation. string internal constant IRM_NOT_ENABLED = "IRM not enabled"; /// @notice Thrown when the LLTV is not enabled at market creation. string internal constant LLTV_NOT_ENABLED = "LLTV not enabled"; /// @notice Thrown when the market is already created. string internal constant MARKET_ALREADY_CREATED = "market already created"; /// @notice Thrown when the market is not created. string internal constant MARKET_NOT_CREATED = "market not created"; /// @notice Thrown when not exactly one of the input amount is zero. string internal constant INCONSISTENT_INPUT = "inconsistent input"; /// @notice Thrown when zero assets is passed as input. string internal constant ZERO_ASSETS = "zero assets"; /// @notice Thrown when a zero address is passed as input. string internal constant ZERO_ADDRESS = "zero address"; /// @notice Thrown when the caller is not authorized to conduct an action. string internal constant UNAUTHORIZED = "unauthorized"; /// @notice Thrown when the collateral is insufficient to `borrow` or `withdrawCollateral`. string internal constant INSUFFICIENT_COLLATERAL = "insufficient collateral"; /// @notice Thrown when the liquidity is insufficient to `withdraw` or `borrow`. string internal constant INSUFFICIENT_LIQUIDITY = "insufficient liquidity"; /// @notice Thrown when the position to liquidate is healthy. string internal constant HEALTHY_POSITION = "position is healthy"; /// @notice Thrown when the authorization signature is invalid. string internal constant INVALID_SIGNATURE = "invalid signature"; /// @notice Thrown when the authorization signature is expired. string internal constant SIGNATURE_EXPIRED = "signature expired"; /// @notice Thrown when the nonce is invalid. string internal constant INVALID_NONCE = "invalid nonce"; /// @notice Thrown when a token transfer has failed. string internal constant TRANSFER_FAILED = "transfer failed"; /// @notice Thrown when a token transferFrom has failed. string internal constant TRANSFER_FROM_FAILED = "transferFrom failed"; /// @notice Thrown when the maximum uint128 is exceeded. string internal constant MAX_UINT128_EXCEEDED = "max uint128 exceeded"; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.13; import {Id, MarketParams} from "../../interfaces/MorphoBlue/IMorpho.sol"; /// @title MarketParamsLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library to convert a market to its id. library MarketParamsLib { /// @notice Returns the id of the market `marketParams`. function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) { assembly ("memory-safe") { marketParamsId := keccak256(marketParams, mul(5, 32)) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; uint256 constant WAD = 1e18; /// @title MathLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library to manage fixed-point arithmetic. library MathLib { /// @dev (x * y) / WAD rounded down. function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); } /// @dev (x * WAD) / y rounded down. function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); } /// @dev (x * WAD) / y rounded up. function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); } /// @dev (x * y) / denominator rounded down. function mulDivDown(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256) { return (x * y) / denominator; } /// @dev (x * y) / denominator rounded up. function mulDivUp(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256) { return (x * y + (denominator - 1)) / denominator; } /// @dev The sum of the last three terms in a four term taylor series expansion /// to approximate a continuous compound interest rate: e^(nx) - 1. function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { uint256 firstTerm = x * n; uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); return firstTerm + secondTerm + thirdTerm; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {Id, MarketParams, Market, IMorpho} from "../../interfaces/MorphoBlue/IMorpho.sol"; import {IIrm} from "../../interfaces/MorphoBlue/IIrm.sol"; import {MathLib} from "./MathLib.sol"; import {UtilsLib} from "./UtilsLib.sol"; import {MorphoLib} from "./MorphoLib.sol"; import {SharesMathLib} from "./SharesMathLib.sol"; import {MarketParamsLib} from "./MarketParamsLib.sol"; import {MorphoStorageLib} from "./MorphoStorageLib.sol"; interface IMorphoMarketStruct { function market(Id id) external view returns (Market memory); } /// @title MorphoBalancesLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Helper library exposing getters with the expected value after interest accrual. /// @dev This library is not used in Morpho itself and is intended to be used by integrators. /// @dev The getter to retrieve the expected total borrow shares is not exposed because interest accrual does not apply /// to it. The value can be queried directly on Morpho using `totalBorrowShares`. library MorphoBalancesLib { using MathLib for uint256; using MathLib for uint128; using UtilsLib for uint256; using MorphoLib for IMorpho; using SharesMathLib for uint256; using MarketParamsLib for MarketParams; function expectedMarketBalances(IMorpho morpho, MarketParams memory marketParams) internal view returns (uint256, uint256, uint256, uint256) { Id id = marketParams.id(); Market memory market = IMorphoMarketStruct(address(morpho)).market(id); uint256 elapsed = block.timestamp - market.lastUpdate; if (elapsed != 0 && market.totalBorrowAssets != 0) { uint256 borrowRate = IIrm(marketParams.irm).borrowRateView(marketParams, market); uint256 interest = market.totalBorrowAssets.wMulDown(borrowRate.wTaylorCompounded(elapsed)); market.totalBorrowAssets += interest.toUint128(); market.totalSupplyAssets += interest.toUint128(); if (market.fee != 0) { uint256 feeAmount = interest.wMulDown(market.fee); // The fee amount is subtracted from the total supply in this calculation to compensate for the fact // that total supply is already updated. uint256 feeShares = feeAmount.toSharesDown(market.totalSupplyAssets - feeAmount, market.totalSupplyShares); market.totalSupplyShares += feeShares.toUint128(); } } return (market.totalSupplyAssets, market.totalSupplyShares, market.totalBorrowAssets, market.totalBorrowShares); } function expectedTotalSupply(IMorpho morpho, MarketParams memory marketParams) internal view returns (uint256 totalSupplyAssets) { (totalSupplyAssets,,,) = expectedMarketBalances(morpho, marketParams); } function expectedTotalBorrow(IMorpho morpho, MarketParams memory marketParams) internal view returns (uint256 totalBorrowAssets) { (,, totalBorrowAssets,) = expectedMarketBalances(morpho, marketParams); } function expectedTotalSupplyShares(IMorpho morpho, MarketParams memory marketParams) internal view returns (uint256 totalSupplyShares) { (, totalSupplyShares,,) = expectedMarketBalances(morpho, marketParams); } /// @dev Warning: Wrong for `feeRecipient` because their supply shares increase is not taken into account. function expectedSupplyBalance(IMorpho morpho, MarketParams memory marketParams, address user) internal view returns (uint256) { Id id = marketParams.id(); uint256 supplyShares = morpho.supplyShares(id, user); (uint256 totalSupplyAssets, uint256 totalSupplyShares,,) = expectedMarketBalances(morpho, marketParams); return supplyShares.toAssetsDown(totalSupplyAssets, totalSupplyShares); } function expectedBorrowBalance(IMorpho morpho, MarketParams memory marketParams, address user) internal view returns (uint256) { Id id = marketParams.id(); uint256 borrowShares = morpho.borrowShares(id, user); (,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = expectedMarketBalances(morpho, marketParams); return borrowShares.toAssetsUp(totalBorrowAssets, totalBorrowShares); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {IMorpho, Id} from "../../interfaces/MorphoBlue/IMorpho.sol"; import {MorphoStorageLib} from "./MorphoStorageLib.sol"; library MorphoLib { function supplyShares(IMorpho morpho, Id id, address user) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.positionSupplySharesSlot(id, user)); return uint256(morpho.extSloads(slot)[0]); } function borrowShares(IMorpho morpho, Id id, address user) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.positionBorrowSharesAndCollateralSlot(id, user)); return uint128(uint256(morpho.extSloads(slot)[0])); } function collateral(IMorpho morpho, Id id, address user) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.positionBorrowSharesAndCollateralSlot(id, user)); return uint256(morpho.extSloads(slot)[0] >> 128); } function totalSupplyAssets(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketTotalSupplyAssetsAndSharesSlot(id)); return uint128(uint256(morpho.extSloads(slot)[0])); } function totalSupplyShares(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketTotalSupplyAssetsAndSharesSlot(id)); return uint256(morpho.extSloads(slot)[0] >> 128); } function totalBorrowAssets(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketTotalBorrowAssetsAndSharesSlot(id)); return uint128(uint256(morpho.extSloads(slot)[0])); } function totalBorrowShares(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketTotalBorrowAssetsAndSharesSlot(id)); return uint256(morpho.extSloads(slot)[0] >> 128); } function lastUpdate(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketLastUpdateAndFeeSlot(id)); return uint128(uint256(morpho.extSloads(slot)[0])); } function fee(IMorpho morpho, Id id) internal view returns (uint256) { bytes32[] memory slot = _array(MorphoStorageLib.marketLastUpdateAndFeeSlot(id)); return uint256(morpho.extSloads(slot)[0] >> 128); } function _array(bytes32 x) private pure returns (bytes32[] memory) { bytes32[] memory res = new bytes32[](1); res[0] = x; return res; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {Id} from "../../interfaces/MorphoBlue/IMorpho.sol"; /// @title MorphoStorageLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Helper library exposing getters to access Morpho storage variables' slot. /// @dev This library is not used in Morpho itself and is intended to be used by integrators. library MorphoStorageLib { /* SLOTS */ uint256 internal constant OWNER_SLOT = 0; uint256 internal constant FEE_RECIPIENT_SLOT = 1; uint256 internal constant POSITION_SLOT = 2; uint256 internal constant MARKET_SLOT = 3; uint256 internal constant IS_IRM_ENABLED_SLOT = 4; uint256 internal constant IS_LLTV_ENABLED_SLOT = 5; uint256 internal constant IS_AUTHORIZED_SLOT = 6; uint256 internal constant NONCE_SLOT = 7; uint256 internal constant ID_TO_MARKET_PARAMS_SLOT = 8; /* SLOT OFFSETS */ uint256 internal constant BORROWABLE_TOKEN_OFFSET = 0; uint256 internal constant COLLATERAL_TOKEN_OFFSET = 1; uint256 internal constant ORACLE_OFFSET = 2; uint256 internal constant IRM_OFFSET = 3; uint256 internal constant LLTV_OFFSET = 4; uint256 internal constant SUPPLY_SHARES_OFFSET = 0; uint256 internal constant BORROW_SHARES_AND_COLLATERAL_OFFSET = 1; uint256 internal constant TOTAL_SUPPLY_ASSETS_AND_SHARES_OFFSET = 0; uint256 internal constant TOTAL_BORROW_ASSETS_AND_SHARES_OFFSET = 1; uint256 internal constant LAST_UPDATE_AND_FEE_OFFSET = 2; /* GETTERS */ function ownerSlot() internal pure returns (bytes32) { return bytes32(OWNER_SLOT); } function feeRecipientSlot() internal pure returns (bytes32) { return bytes32(FEE_RECIPIENT_SLOT); } function positionSupplySharesSlot(Id id, address user) internal pure returns (bytes32) { return bytes32( uint256(keccak256(abi.encode(user, keccak256(abi.encode(id, POSITION_SLOT))))) + SUPPLY_SHARES_OFFSET ); } function positionBorrowSharesAndCollateralSlot(Id id, address user) internal pure returns (bytes32) { return bytes32( uint256(keccak256(abi.encode(user, keccak256(abi.encode(id, POSITION_SLOT))))) + BORROW_SHARES_AND_COLLATERAL_OFFSET ); } function marketTotalSupplyAssetsAndSharesSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + TOTAL_SUPPLY_ASSETS_AND_SHARES_OFFSET); } function marketTotalBorrowAssetsAndSharesSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + TOTAL_BORROW_ASSETS_AND_SHARES_OFFSET); } function marketLastUpdateAndFeeSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, MARKET_SLOT))) + LAST_UPDATE_AND_FEE_OFFSET); } function isIrmEnabledSlot(address irm) internal pure returns (bytes32) { return keccak256(abi.encode(irm, IS_IRM_ENABLED_SLOT)); } function isLltvEnabledSlot(uint256 lltv) internal pure returns (bytes32) { return keccak256(abi.encode(lltv, IS_LLTV_ENABLED_SLOT)); } function isAuthorizedSlot(address authorizer, address authorizee) internal pure returns (bytes32) { return keccak256(abi.encode(authorizee, keccak256(abi.encode(authorizer, IS_AUTHORIZED_SLOT)))); } function nonceSlot(address authorizer) internal pure returns (bytes32) { return keccak256(abi.encode(authorizer, NONCE_SLOT)); } function idToBorrowableTokenSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + BORROWABLE_TOKEN_OFFSET); } function idToCollateralTokenSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + COLLATERAL_TOKEN_OFFSET); } function idToOracleSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + ORACLE_OFFSET); } function idToIrmSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + IRM_OFFSET); } function idToLltvSlot(Id id) internal pure returns (bytes32) { return bytes32(uint256(keccak256(abi.encode(id, ID_TO_MARKET_PARAMS_SLOT))) + LLTV_OFFSET); } }
// SPDX-License-Identifier: AGPL-3.0-or-later /// MorphoLTVHelper.sol // Copyright (C) 2021-2021 Oazo Apps Limited // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. pragma solidity 0.8.22; import {IMorpho, MarketParams, Position, Id} from "./../../interfaces/MorphoBlue/IMorpho.sol"; import {IOracle} from "./../../interfaces/MorphoBlue/IOracle.sol"; import "./MorphoBalancesLib.sol"; /// @title MorphoUtils /// @notice Library to help calculate Loan to Value (LTV) for loans managed by the MorphoBlue protocol. library MorphoUtils { uint256 constant ORACLE_PRICE_SCALE = 1e36; uint8 constant LTV_DECIMAL_PRECISION = 4; /// @notice Calculates the LTV for a given loan position. /// @param morphoBlue Interface to the MorphoBlue contract. /// @param id The market ID related to the loan. /// @param positionAddress The address of the loan position. /// @return ltv The calculated LTV as a percentage scaled to 4 decimal places. /// Example: An LTV of 57% is returned as 5700. function calculateLTV( IMorpho morphoBlue, Id id, address positionAddress ) internal view returns (uint256) { MarketParams memory marketParams = morphoBlue.idToMarketParams(id); Position memory position = morphoBlue.position(id, positionAddress); return internalLTVHelper(morphoBlue, marketParams, position, positionAddress); } /// @notice Calculates the LTV for a given loan position. /// @param morphoBlue Interface to the MorphoBlue contract. /// @param marketParams The market params for the market. /// @param position The user's existing Morpho position /// @param positionAddress The address of the loan position. /// @return ltv The calculated LTV as a percentage scaled to 4 decimal places. /// Example: An LTV of 57% is returned as 5700. function calculateLTV( IMorpho morphoBlue, MarketParams memory marketParams, Position memory position, address positionAddress ) internal view returns (uint256) { return internalLTVHelper(morphoBlue, marketParams, position, positionAddress); } /// @notice Retrieves the liquidation LTV as MaxLTV with a given decimal precision /// @param morphoBlue Interface to the MorphoBlue contract. /// @param id The market ID related to the loan. /// @return MaxLTV function getMaxLTV( IMorpho morphoBlue, Id id, uint8 desiredDecimalPrecision ) internal view returns (uint256) { MarketParams memory marketParams = morphoBlue.idToMarketParams(id); uint256 lltvDecimalPrecision = 18; uint256 divisor = (10 ** (lltvDecimalPrecision - desiredDecimalPrecision)); uint256 maxLtv = marketParams.lltv / divisor; require(maxLtv >= 1); return maxLtv; } function internalLTVHelper( IMorpho morphoBlue, MarketParams memory marketParams, Position memory position, address positionAddress ) internal view returns (uint256) { IOracle oracle = IOracle(marketParams.oracle); uint256 price = oracle.price(); // Exit early if collateral, price, or borrow shares are zero to prevent division by zero. if (position.collateral == 0 || price == 0 || position.borrowShares == 0) { return 0; } // Calculate the value of the collateral in terms of the quote currency. uint256 collateralValueInQuote = ((position.collateral * price) / ORACLE_PRICE_SCALE); // Return early here to avoid a divide by zero scenario if (collateralValueInQuote == 0) { return 0; } uint256 quoteValue = MorphoBalancesLib.expectedBorrowBalance( morphoBlue, marketParams, positionAddress ); // Adjusted LTV calculation, scaled to base 10,000. return ((quoteValue * 10 ** LTV_DECIMAL_PRECISION) / (collateralValueInQuote)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {MathLib} from "./MathLib.sol"; /// @title SharesMathLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Shares management library. /// @dev This implementation mitigates share price manipulations, using OpenZeppelin's method of virtual shares: /// https://docs.openzeppelin.com/contracts/4.x/erc4626#inflation-attack. library SharesMathLib { using MathLib for uint256; /// @dev The number of virtual shares has been chosen low enough to prevent overflows, and high enough to ensure /// high precision computations. uint256 internal constant VIRTUAL_SHARES = 1e6; /// @dev A number of virtual assets of 1 enforces a conversion rate between shares and assets when a market is /// empty. uint256 internal constant VIRTUAL_ASSETS = 1; /// @dev Calculates the value of `assets` quoted in shares, rounding down. function toSharesDown(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) { return assets.mulDivDown(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS); } /// @dev Calculates the value of `shares` quoted in assets, rounding down. function toAssetsDown(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) { return shares.mulDivDown(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES); } /// @dev Calculates the value of `assets` quoted in shares, rounding up. function toSharesUp(uint256 assets, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) { return assets.mulDivUp(totalShares + VIRTUAL_SHARES, totalAssets + VIRTUAL_ASSETS); } /// @dev Calculates the value of `shares` quoted in assets, rounding up. function toAssetsUp(uint256 shares, uint256 totalAssets, uint256 totalShares) internal pure returns (uint256) { return shares.mulDivUp(totalAssets + VIRTUAL_ASSETS, totalShares + VIRTUAL_SHARES); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import {ErrorsLib} from "./ErrorsLib.sol"; /// @title UtilsLib /// @author Morpho Labs /// @custom:contact [email protected] /// @notice Library exposing helpers. /// @dev Inspired by https://github.com/morpho-org/morpho-utils. library UtilsLib { /// @dev Returns true if there is exactly one zero. function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) { assembly { z := xor(iszero(x), iszero(y)) } } /// @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 `x` safely cast to uint128. function toUint128(uint256 x) internal pure returns (uint128) { require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED); return uint128(x); } }
// SPDX-License-Identifier: AGPL-3.0-or-later /// BasicBuyCommand.sol // Copyright (C) 2021-2021 Oazo Apps Limited // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. pragma solidity ^0.8.0; import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol"; library RatioUtils { using SafeMath for uint256; uint256 public constant RATIO = 10 ** 4; uint256 public constant WAD = 10 ** 18; uint256 public constant RAY = 10 ** 27; uint256 public constant RAD = 10 ** 45; // convert base units to ratio function toRatio(uint256 units) internal pure returns (uint256) { return units.mul(RATIO); } function wad(uint256 ratio) internal pure returns (uint256) { return ratio.mul(WAD).div(RATIO); } function ray(uint256 ratio) internal pure returns (uint256) { return ratio.mul(RAY).div(RATIO); } function bounds( uint256 ratio, uint64 deviation ) internal pure returns (uint256 lower, uint256 upper) { uint256 offset = ratio.mul(deviation).div(RATIO); return (ratio.sub(offset), ratio.add(offset)); } function rayToWad(uint256 _ray) internal pure returns (uint256 _wad) { _wad = _ray.mul(WAD).div(RAY); } function wadToRay(uint256 _wad) internal pure returns (uint256 _ray) { _ray = _wad.mul(RAY).div(WAD); } function radToWad(uint256 _rad) internal pure returns (uint256 _wad) { _wad = _rad.mul(WAD).div(RAD); } function wadToRad(uint256 _wad) internal pure returns (uint256 _rad) { _rad = _wad.mul(RAD).div(WAD); } }
{ "optimizer": { "enabled": true, "runs": 1000 }, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IServiceRegistry","name":"_serviceRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"CallerNotAutomationBot","type":"error"},{"inputs":[{"internalType":"address","name":"command","type":"address"}],"name":"CommandAlreadyExists","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"EmptyAddress","type":"error"},{"inputs":[],"name":"ExecutionNotLegal","type":"error"},{"inputs":[{"internalType":"bytes32","name":"operationName","type":"bytes32"}],"name":"InvalidOperationName","type":"error"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"InvalidSelector","type":"error"},{"inputs":[],"name":"InvalidTriggerType","type":"error"},{"inputs":[],"name":"MIN_ALLOWED_DEVIATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bot","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"executionData","type":"bytes"},{"internalType":"bytes","name":"triggerData","type":"bytes"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"triggerData","type":"bytes"}],"name":"getTriggerType","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"triggerData","type":"bytes"}],"name":"isExecutionCorrect","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"triggerData","type":"bytes"}],"name":"isExecutionLegal","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"isContinuous","type":"bool"},{"internalType":"bytes","name":"triggerData","type":"bytes"}],"name":"isTriggerDataValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"morphoBlue","outputs":[{"internalType":"contract IMorpho","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operationExecutor","outputs":[{"internalType":"contract IOperationExecutorV5","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"self","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100c95760003560e01c80636cd4f21e116100815780638a041b9c1161005b5780638a041b9c146101e85780639fce93b51461020e578063e8ce1bfa1461022157600080fd5b80636cd4f21e146101875780637104ddb21461019a578063829c7510146101c157600080fd5b806311449b61116100b257806311449b61146101355780631f6a1eb91461014b5780633fc8cef31461016057600080fd5b80630b23e6f6146100ce57806310814c37146100f6575b600080fd5b6100e16100dc3660046113b8565b610248565b60405190151581526020015b60405180910390f35b61011d7f0000000000000000000000005743b5606e94fb534a31e1cefb3242c8a9422e5e81565b6040516001600160a01b0390911681526020016100ed565b61013d603281565b6040519081526020016100ed565b61015e610159366004611451565b610328565b005b61011d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6100e16101953660046114ba565b6104c7565b61011d7f000000000000000000000000b12ab11954028df47d4a7b252c623e9f0b7d2e1b81565b61011d7f000000000000000000000000fff30c67eea809123596252e132d30e1eb75bc8381565b6101fb6101f63660046114ef565b6105f0565b60405161ffff90911681526020016100ed565b6100e161021c3660046114ba565b61069e565b61011d7f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb81565b6000808280602001905181019061025f9190611561565b9050600060646102957f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb8460200151600461086d565b61029f9190611636565b6040838101518151600180825281840190935292935083119160009160208083019080368337019050509050608e816000815181106102e0576102e0611649565b61ffff90921660209283029190910182015284510151600090610304908390610941565b9050871580156103115750805b801561031a5750825b955050505050505b92915050565b60008180602001905181019061033e9190611561565b6040805160018082528183019092529192506000919060208083019080368337019050509050608e8160008151811061037957610379611649565b61ffff9092166020928302919091018201528251015161039a908290610992565b604080516020601f87018190048102820181019092528581526103fa917f5d10041b00000000000000000000000000000000000000000000000000000000919088908890819084018382808284376000920191909152506109d692505050565b8151516040517f1cff79cd0000000000000000000000000000000000000000000000000000000081526000916001600160a01b031690631cff79cd90610468907f000000000000000000000000fff30c67eea809123596252e132d30e1eb75bc83908a908a90600401611688565b6020604051808303816000875af1158015610487573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ab91906116ab565b90506104bf836000015160a0015182610a7a565b505050505050565b600080828060200190518101906104de9190611561565b60208101518151516040516349e2903160e11b81529293506000926001600160a01b037f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb16926393c5206292610548926004019182526001600160a01b0316602082015260400190565b606060405180830381865afa158015610565573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061058991906116db565b90508160600151156105c557600081604001516001600160801b03161180156105bd575060208101516001600160801b0316155b949350505050565b60408101516001600160801b03161580156105bd5750602001516001600160801b0316159392505050565b6000806105ff83850185611740565b6040517f0b23e6f60000000000000000000000000000000000000000000000000000000081529091503090630b23e6f69061064390600090889088906004016117f2565b602060405180830381865afa158015610660573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610684919061180e565b610692576000915050610322565b51602001519392505050565b600080828060200190518101906106b59190611561565b60208101518151516040516349e2903160e11b81529293506000926001600160a01b037f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb16926393c520629261071f926004019182526001600160a01b0316602082015260400190565b606060405180830381865afa15801561073c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076091906116db565b905080604001516001600160801b031660001480610789575060208101516001600160801b0316155b15610798575060009392505050565b600061085b7f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb7f000000000000000000000000bbbbbbbbbb9cc5e90e3b3af64bdaf62c37eeffcb6001600160a01b0316632c3c915786602001516040518263ffffffff1660e01b815260040161081091815260200190565b60a060405180830381865afa15801561082d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610851919061182b565b8551518590610ab6565b60409093015190921015949350505050565b6040517f2c3c91570000000000000000000000000000000000000000000000000000000081526004810183905260009081906001600160a01b03861690632c3c91579060240160a060405180830381865afa1580156108d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f4919061182b565b90506012600061090760ff861683611636565b61091290600a6119a0565b9050600081846080015161092691906119ac565b9050600181101561093657600080fd5b979650505050505050565b6000805b8351811015610988578261ffff1684828151811061096557610965611649565b602002602001015161ffff1603610980576001915050610322565b600101610945565b5060009392505050565b61099c8282610941565b6109d2576040517ff2b2d41200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050565b6000818060200190518101906109ec91906119ce565b90507fffffffff0000000000000000000000000000000000000000000000000000000080821690841614610a75576040517f12ba286f0000000000000000000000000000000000000000000000000000000081527fffffffff00000000000000000000000000000000000000000000000000000000821660048201526024015b60405180910390fd5b505050565b8082146109d2576040517f1724c6d100000000000000000000000000000000000000000000000000000000815260048101839052602401610a6c565b6000610ac485858585610acd565b95945050505050565b600080846040015190506000816001600160a01b031663a035b1fe6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b3b91906116ab565b905084604001516001600160801b031660001480610b57575080155b80610b6d575060208501516001600160801b0316155b15610b7d576000925050506105bd565b60006ec097ce7bc90715b34b9f10000000008287604001516001600160801b0316610ba89190611a10565b610bb291906119ac565b905080600003610bc857600093505050506105bd565b6000610bd5898988610c05565b905081610be46004600a611a27565b610bee9083611a10565b610bf891906119ac565b9998505050505050505050565b600080610c138460a0902090565b90506000610c2b6001600160a01b0387168386610c5a565b9050600080610c3a8888610d2c565b9094509250610c4e9150849050838361104a565b98975050505050505050565b600080610c6f610c6a858561106f565b6110eb565b6040517f7784c6850000000000000000000000000000000000000000000000000000000081529091506001600160a01b03861690637784c68590610cb7908490600401611a36565b600060405180830381865afa158015610cd4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610cfc9190810190611a7a565b600081518110610d0e57610d0e611649565b602002602001015160001c6001600160801b03169150509392505050565b6000806000806000610d3f8660a0902090565b6040517f5c60e39a000000000000000000000000000000000000000000000000000000008152600481018290529091506000906001600160a01b03891690635c60e39a9060240160c060405180830381865afa158015610da3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dc79190611b14565b9050600081608001516001600160801b031642610de49190611636565b90508015801590610e01575060408201516001600160801b031615155b156110165760608881018051604080517f8c00bf6b0000000000000000000000000000000000000000000000000000000081528c516001600160a01b0390811660048301526020808f015182166024840152838f0151821660448401529451811660648301526080808f0151608484015288516001600160801b0390811660a485015295890151861660c484015292880151851660e483015294870151841661010482015290860151831661012482015260a08601519092166101448301526000921690638c00bf6b9061016401602060405180830381865afa158015610eec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1091906116ab565b90506000610f35610f218385611136565b60408601516001600160801b0316906111a1565b9050610f40816111b6565b84604001818151610f519190611b95565b6001600160801b0316905250610f66816111b6565b84518590610f75908390611b95565b6001600160801b0390811690915260a086015116159050611013576000610fb28560a001516001600160801b0316836111a190919063ffffffff16565b90506000610fe88287600001516001600160801b0316610fd29190611636565b60208801518491906001600160801b0316611236565b9050610ff3816111b6565b866020018181516110049190611b95565b6001600160801b031690525050505b50505b508051602082015160408301516060909301516001600160801b039283169b9183169a509282169850911695509350505050565b60006105bd61105a600185611bbc565b611067620f424085611bbc565b86919061125b565b6000600182846002604051602001611091929190918252602082015260400190565b60408051601f1981840301815282825280516020918201206001600160a01b03909416908301528101919091526060016040516020818303038152906040528051906020012060001c6110e49190611bbc565b9392505050565b6040805160018082528183019092526060916000919060208083019080368337019050509050828160008151811061112557611125611649565b602090810291909101015292915050565b6000806111438385611a10565b90506000611164828061115f670de0b6b3a76400006002611a10565b611287565b90506000611180828461115f670de0b6b3a76400006003611a10565b90508061118d8385611bbc565b6111979190611bbc565b9695505050505050565b60006110e48383670de0b6b3a7640000611287565b60408051808201909152601481527f6d61782075696e7431323820657863656564656400000000000000000000000060208201526000906001600160801b0383111561122f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6c9190611bcf565b5090919050565b60006105bd611248620f424084611bbc565b611253600186611bbc565b869190611287565b600081611269600182611636565b6112738587611a10565b61127d9190611bbc565b6105bd91906119ac565b60008161127d8486611a10565b80151581146112a257600080fd5b50565b80356112b081611294565b919050565b634e487b7160e01b600052604160045260246000fd5b6040516080810167ffffffffffffffff811182821017156112ee576112ee6112b5565b60405290565b60405160c0810167ffffffffffffffff811182821017156112ee576112ee6112b5565b604051601f8201601f1916810167ffffffffffffffff81118282101715611340576113406112b5565b604052919050565b600082601f83011261135957600080fd5b813567ffffffffffffffff811115611373576113736112b5565b611386601f8201601f1916602001611317565b81815284602083860101111561139b57600080fd5b816020850160208301376000918101602001919091529392505050565b600080604083850312156113cb57600080fd5b82356113d681611294565b9150602083013567ffffffffffffffff8111156113f257600080fd5b6113fe85828601611348565b9150509250929050565b60008083601f84011261141a57600080fd5b50813567ffffffffffffffff81111561143257600080fd5b60208301915083602082850101111561144a57600080fd5b9250929050565b60008060006040848603121561146657600080fd5b833567ffffffffffffffff8082111561147e57600080fd5b61148a87838801611408565b909550935060208601359150808211156114a357600080fd5b506114b086828701611348565b9150509250925092565b6000602082840312156114cc57600080fd5b813567ffffffffffffffff8111156114e357600080fd5b6105bd84828501611348565b6000806020838503121561150257600080fd5b823567ffffffffffffffff81111561151957600080fd5b61152585828601611408565b90969095509350505050565b6001600160a01b03811681146112a257600080fd5b61ffff811681146112a257600080fd5b80516112b081611294565b600081830361012081121561157557600080fd5b61157d6112cb565b60c082121561158b57600080fd5b6115936112f4565b915083516115a081611531565b825260208401516115b081611546565b60208301526040848101519083015260608401516115cd81611531565b606083015260808401516115e081611531565b608083015260a0848101519083015281815260c0840151602082015260e084015160408201526116136101008501611556565b6060820152949350505050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561032257610322611620565b634e487b7160e01b600052603260045260246000fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b6001600160a01b0384168152604060208201526000610ac460408301848661165f565b6000602082840312156116bd57600080fd5b5051919050565b80516001600160801b03811681146112b057600080fd5b6000606082840312156116ed57600080fd5b6040516060810181811067ffffffffffffffff82111715611710576117106112b5565b60405282518152611723602084016116c4565b6020820152611734604084016116c4565b60408201529392505050565b600081830361012081121561175457600080fd5b61175c6112cb565b60c082121561176a57600080fd5b6117726112f4565b9150833561177f81611531565b8252602084013561178f81611546565b60208301526040848101359083015260608401356117ac81611531565b606083015260808401356117bf81611531565b608083015260a0848101359083015281815260c0840135602082015260e0840135604082015261161361010085016112a5565b8315158152604060208201526000610ac460408301848661165f565b60006020828403121561182057600080fd5b81516110e481611294565b600060a0828403121561183d57600080fd5b60405160a0810181811067ffffffffffffffff82111715611860576118606112b5565b604052825161186e81611531565b8152602083015161187e81611531565b6020820152604083015161189181611531565b604082015260608301516118a481611531565b60608201526080928301519281019290925250919050565b600181815b808511156118f75781600019048211156118dd576118dd611620565b808516156118ea57918102915b93841c93908002906118c1565b509250929050565b60008261190e57506001610322565b8161191b57506000610322565b8160018114611931576002811461193b57611957565b6001915050610322565b60ff84111561194c5761194c611620565b50506001821b610322565b5060208310610133831016604e8410600b841016171561197a575081810a610322565b61198483836118bc565b806000190482111561199857611998611620565b029392505050565b60006110e483836118ff565b6000826119c957634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156119e057600080fd5b81517fffffffff00000000000000000000000000000000000000000000000000000000811681146110e457600080fd5b808202811582820484141761032257610322611620565b60006110e460ff8416836118ff565b6020808252825182820181905260009190848201906040850190845b81811015611a6e57835183529284019291840191600101611a52565b50909695505050505050565b60006020808385031215611a8d57600080fd5b825167ffffffffffffffff80821115611aa557600080fd5b818501915085601f830112611ab957600080fd5b815181811115611acb57611acb6112b5565b8060051b9150611adc848301611317565b8181529183018401918481019088841115611af657600080fd5b938501935b83851015610c4e57845182529385019390850190611afb565b600060c08284031215611b2657600080fd5b611b2e6112f4565b611b37836116c4565b8152611b45602084016116c4565b6020820152611b56604084016116c4565b6040820152611b67606084016116c4565b6060820152611b78608084016116c4565b6080820152611b8960a084016116c4565b60a08201529392505050565b6001600160801b03818116838216019080821115611bb557611bb5611620565b5092915050565b8082018082111561032257610322611620565b60006020808352835180602085015260005b81811015611bfd57858101830151858201604001528201611be1565b506000604082860101526040601f19601f830116850101925050509291505056fea2646970667358221220000f2fb80fe3cad5cb902206e69ceb3739db5a6034ca75418e441bd090a142b364736f6c63430008160033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.