STBL_PT1_Oracle

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/Assets/PT1/STBL_PT1_Oracle.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/AccessControl.sol";

import "./interfaces/ISTBL_PT1_AssetOracle.sol";
import "./interfaces/external/IRWAOracle.sol";

import "./lib/STBL_PT1_Asset_Errors.sol";

/** @title USDY Asset Price Oracle
 * @notice Provides price retrieval functionality for USDY assets
 * @dev Mock oracle implementation for testing purposes with manual price updates
 */
contract STBL_PT1_Oracle is iSTBL_PT1_AssetOracle, AccessControl {
    IRWAOracle public oracle;

    uint256 public PRICE_DECIMALS;

    uint256 public PRICE_THRESHOLD;

    bool public Enabled;

    /** @notice Initializes the USDY price oracle with an oracle address
     * @param _oracleAddr The address of the oracle to be used
     * @dev Constructor sets the oracle address for the contract
     * @custom:oz-upgrades-unsafe-allow constructor
     */
    constructor(address _oracleAddr) AccessControl() {
        _grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
        oracle = IRWAOracle(_oracleAddr);
        Enabled = true;
    }

    /** @notice Enables the oracle
     * @dev Only admin can call this function
     */
    function enableOracle() external onlyRole(DEFAULT_ADMIN_ROLE) {
        Enabled = true;
        emit oracleEnabled();
    }

    /** @notice Disables the oracle
     * @dev Only admin can call this function
     */
    function disableOracle() external onlyRole(DEFAULT_ADMIN_ROLE) {
        Enabled = false;
        emit oracleDisabled();
    }

    /** @notice Sets the number of decimals for price representation
     * @param _decimals The number of decimals to be used for price representation
     * @dev Only admin can call this function
     */
    function setPriceDecimals(
        uint256 _decimals
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        PRICE_DECIMALS = _decimals;
        emit oracleSetDecimals(_decimals);
    }

    /** @notice Sets the price threshold
     * @param _threshold The price threshold to be set
     * @dev Only admin can call this function
     */
    function setPriceThreshold(
        uint256 _threshold
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        PRICE_THRESHOLD = _threshold;
        emit oracleSetPriceThreshold(_threshold);
    }

    /** @notice Gets the number of decimals for the price
     * @return The number of decimals used for price representation (8 decimals)
     */
    function getPriceDecimals() external view returns (uint256) {
        return PRICE_DECIMALS;
    }

    /** @notice Retrieves the current price of the USDY asset
     * @return price The current price of the USDY asset with 8 decimal precision
     * @dev Returns the stored price value for the USDY asset
     */
    function fetchPrice() external view returns (uint256) {
        if (!Enabled) revert STBL_Asset_OracleDisabled();
        (uint256 price, uint256 time) = oracle.getPriceData();
        if (time + PRICE_THRESHOLD <= block.timestamp)
            revert STBL_Asset_OracleStalePrice(price, time);
        return price;
    }
}
"
    },
    "node_modules/@openzeppelin/contracts/access/AccessControl.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {IERC165, ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
"
    },
    "contracts/Assets/PT1/interfaces/ISTBL_PT1_AssetOracle.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title STBL Asset Price Oracle Interface
 * @notice Interface for retrieving asset price information in the STBL protocol
 * @dev This interface defines the standard methods for price oracles used by the STBL system
 */
interface iSTBL_PT1_AssetOracle {
    /** @notice Emitted when the oracle is enabled
     */
    event oracleEnabled();

    /** @notice Emitted when the oracle is disabled
     */
    event oracleDisabled();

    /** @notice Emitted when the oracle decimals are set
     * @param _decimals The number of decimals set for price representation
     */
    event oracleSetDecimals(uint256 _decimals);

    /** @notice Emitted when the oracle price threshold is set
     * @param _threshold The price threshold that was set
     */
    event oracleSetPriceThreshold(uint256 _threshold);

    /** @notice Enables the oracle
     * @dev Only admin can call this function
     */
    function enableOracle() external;

    /** @notice Disables the oracle
     * @dev Only admin can call this function
     */
    function disableOracle() external;

    /** @notice Sets the number of decimals for price representation
     * @param _decimals The number of decimals to be used for price representation
     * @dev Only admin can call this function
     */
    function setPriceDecimals(uint256 _decimals) external;

    /** @notice Sets the price threshold
     * @param _threshold The price threshold to be set
     * @dev Only admin can call this function
     */
    function setPriceThreshold(uint256 _threshold) external;

    /** @notice Gets the number of decimals for the price
     * @return The number of decimals used for price representation (8 decimals)
     */
    function getPriceDecimals() external view returns (uint256);

    /** @notice Retrieves the current price of the USDY asset
     * @return price The current price of the USDY asset with 8 decimal precision
     * @dev Returns the stored price value for the USDY asset
     */
    function fetchPrice() external view returns (uint256);
}
"
    },
    "contracts/Assets/PT1/interfaces/external/IRWAOracle.sol": {
      "content": "//SPDX-License-Identifier: BUSL-1.1

pragma solidity ^0.8.20;

interface IRWAOracle {
    /// @notice Retrieve RWA price data
    function getPriceData()
        external
        view
        returns (uint256 price, uint256 timestamp);
}
"
    },
    "contracts/Assets/PT1/lib/STBL_PT1_Asset_Errors.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @notice Thrown when the asset setup is not complete or inactive
 * @param id The ID of the asset that is not properly setup
 */
error STBL_Asset_SetupNotComplete(uint256 id);

/**
 * @notice Thrown when an unauthorized issuer attempts an operation
 * @dev Used in the isValidIssuer modifier to restrict access
 * @param id The ID of the asset with the invalid issuer
 */
error STBL_Asset_InvalidIssuer(uint256 id);

/**
 * @notice Thrown when the calling address is not the valid vault contract
 * @param id The ID of the asset with the invalid vault address
 */
error STBL_Asset_InvalidVault(uint256 id);

/**
 * @notice Thrown when attempting to interact with an invalid asset
 * @param id The ID of the invalid asset
 */
error STBL_Asset_InvalidAsset(uint256 id);

/**
 * @notice Thrown when the provided owner does not match the expected owner
 * @param _tokenID The token ID for which withdrawal was attempted too early
 * @param owner The owner ID that was provided but is incorrect
 */
error STBL_Asset_IncorrectOwner(uint256 _tokenID, address owner);

/**
 * @notice Thrown when attempting to call a function before contract initialization
 * @param id The ID of the uninitialized asset
 */
error STBL_Asset_NotInitialized(uint256 id);

/**
 * @notice Thrown when attempting to initialize an already initialized asset
 * @param id The ID of the asset that is already initialized
 */
error STBL_Asset_Initialized(uint256 id);

/**
 * @notice Thrown when attempting to withdraw before the required duration has passed
 * @param id The ID of the asset where early withdrawal was attempted
 * @param _tokenID The token ID for which withdrawal was attempted too early
 */
error STBL_Asset_WithdrawDurationNotReached(uint256 id, uint256 _tokenID);

/**
 * @notice Thrown when attempting to claim yield before the required duration has passed
 * @param id The ID of the asset where early yield claim was attempted
 * @param duration The required duration that must be satisfied before claiming yield
 */
error STBL_Asset_YieldDurationNotReached(uint256 id, uint256 duration);

/**
 * @notice Thrown when the vault value is insufficient compared to the asset value
 * @param _assetValue The current asset value that is being compared
 * @param _usdValue The USD value that is insufficient for the operation
 */
error STBL_Asset_InsufficientVaultValue(uint256 _assetValue, uint256 _usdValue);

/**
 * @notice Thrown when an invalid deposit amount is provided
 * @param assetID The ID of the asset for which the invalid deposit was attempted
 * @param amount The invalid deposit amount that was provided
 */
error STBL_Asset_InvalidDepositAmount(uint256 assetID, uint256 amount);
/**
 * @notice Thrown when the oracle price is stale or outdated
 * @param price The stale price value returned by the oracle
 * @param time The timestamp when the stale price was last updated
 */
error STBL_Asset_OracleStalePrice(uint256 price, uint256 time);

/**
 * @notice Thrown when the oracle is disabled or not available
 */
error STBL_Asset_OracleDisabled();
"
    },
    "node_modules/@openzeppelin/contracts/access/IAccessControl.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/IAccessControl.sol)

pragma solidity >=0.8.4;

/**
 * @dev External interface of AccessControl declared to support ERC-165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted to signal this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
"
    },
    "node_modules/@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
"
    },
    "node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
"
    },
    "node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
"
    }
  },
  "settings": {
    "remappings": [
      "@openzeppelin/=node_modules/@openzeppelin/",
      "forge-std/=lib/forge-std/src/",
      "eth-gas-reporter/=node_modules/eth-gas-reporter/",
      "hardhat/=node_modules/hardhat/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "paris",
    "viaIR": true
  }
}}

Tags:
ERC165, Multisig, Yield, Upgradeable, Multi-Signature, Factory, Oracle|addr:0x2efa9804eb6ecf2cb4702b60c7e3fc5a988a1f85|verified:true|block:23453984|tx:0xdfca4ee066a1b514ed448bbc7d4b186fdafb7ca1326da4e394f8bfa23d2de416|first_check:1758972000

Submitted on: 2025-09-27 13:20:01

Comments

Log in to comment.

No comments yet.