Skip to content
Verified contractPartialUNLICENSED

CollateralRegistry

Address0xcb4e5e0b5cd559d36264b3a7af7f37b2d1c4d694
Balance

0 ETH

 

Transactions

4

 

Compiler

solc 0.8.27

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.27+commit.40a35a09
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
UNLICENSED
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,283,695
Creation transaction
0x039e1f924d…7aa976e168
Libraries
src/libraries/TreasurySales.sol:TreasurySales0x78dc…eebf64

src/registries/CollateralRegistry.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ICollateralRegistry} from "../interfaces/ICollateralRegistry.sol";
import {IGreaterMarketReference} from "../interfaces/IGreaterMarketReference.sol";
import {CollateralConfig} from "../types/ProtocolTypes.sol";
import {Roles} from "../libraries/Roles.sol";

/// @notice Approved collateral assets. Does not define borrow products or duplicate canonical G feed configuration.
/// @dev Config is immutable after registration except the `enabled` flag (a fast safety lever).
///      Admission is economically mint-grade — gated by RISK_ADMIN_ROLE (multisig/timelock).
contract CollateralRegistry is ICollateralRegistry, AccessControl {
    error CollateralExists(uint256 collateralId);
    error CollateralTokenExists(address token, uint256 collateralId);
    error CollateralNotFound(uint256 collateralId);
    error InvalidCollateral();
    error CollateralMustStartDisabled();
    error GreaterMarketNotConfigured();
    error GreaterMarketAlreadyConfigured();
    error InvalidGreaterMarketReference();
    error InvalidGreaterMarketPrice(uint256 collateralId);

    event GreaterMarketReferenceSet(address indexed greaterMarketReference);

    mapping(uint256 => CollateralConfig) private _collaterals;
    mapping(uint256 => bool) private _exists;
    mapping(address => uint256) private _collateralIdByToken;
    IGreaterMarketReference public greaterMarket;

    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
        _grantRole(Roles.RISK_ADMIN_ROLE, admin);
    }

    function setGreaterMarketReference(address marketReference)
        external
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        if (address(greaterMarket) != address(0)) revert GreaterMarketAlreadyConfigured();
        if (marketReference == address(0) || marketReference.code.length == 0) {
            revert InvalidGreaterMarketReference();
        }
        greaterMarket = IGreaterMarketReference(marketReference);
        emit GreaterMarketReferenceSet(marketReference);
    }

    function addCollateral(CollateralConfig calldata config)
        external
        onlyRole(Roles.RISK_ADMIN_ROLE)
    {
        if (config.collateralId == 0 || config.token == address(0) || config.decimals == 0) {
            revert InvalidCollateral();
        }
        if (config.enabled) revert CollateralMustStartDisabled();
        if (_exists[config.collateralId]) revert CollateralExists(config.collateralId);
        uint256 existingCollateralId = _collateralIdByToken[config.token];
        if (existingCollateralId != 0) {
            revert CollateralTokenExists(config.token, existingCollateralId);
        }
        _collaterals[config.collateralId] = config;
        _exists[config.collateralId] = true;
        _collateralIdByToken[config.token] = config.collateralId;
        emit CollateralRegistered(config.collateralId, config.token, config.decimals);
    }

    function setCollateralEnabled(uint256 collateralId, bool enabled)
        external
        onlyRole(Roles.RISK_ADMIN_ROLE)
    {
        if (!_exists[collateralId]) revert CollateralNotFound(collateralId);
        if (enabled) {
            IGreaterMarketReference marketReference = greaterMarket;
            if (address(marketReference) == address(0)) revert GreaterMarketNotConfigured();
            (uint256 price, bool valid) = marketReference.greaterMarketPrice(collateralId);
            if (!valid || price == 0) revert InvalidGreaterMarketPrice(collateralId);
        }
        _collaterals[collateralId].enabled = enabled;
        emit CollateralEnabledSet(collateralId, enabled);
    }

    function getCollateral(uint256 collateralId) external view returns (CollateralConfig memory) {
        if (!_exists[collateralId]) revert CollateralNotFound(collateralId);
        return _collaterals[collateralId];
    }

    function collateralIdForToken(address token) external view returns (uint256) {
        return _collateralIdByToken[token];
    }

    function isEnabled(uint256 collateralId) external view returns (bool) {
        return _exists[collateralId] && _collaterals[collateralId].enabled;
    }
}

lib/openzeppelin-contracts/contracts/access/AccessControl.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {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);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    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` to `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;
        }
    }
}

lib/openzeppelin-contracts/contracts/access/IAccessControl.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @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 signaling 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;
}

lib/openzeppelin-contracts/contracts/utils/Context.sol

// 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;
    }
}

lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @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);
}

src/interfaces/ICollateralRegistry.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;

import {CollateralConfig} from "../types/ProtocolTypes.sol";

/// @notice Approved collateral assets and their oracle envelope. Does NOT define borrow products.
interface ICollateralRegistry {
    event CollateralRegistered(uint256 indexed collateralId, address indexed token, uint8 decimals);
    event CollateralEnabledSet(uint256 indexed collateralId, bool enabled);

    function getCollateral(uint256 collateralId) external view returns (CollateralConfig memory);
    function collateralIdForToken(address token) external view returns (uint256);
    function isEnabled(uint256 collateralId) external view returns (bool);
}

src/interfaces/IGreaterMarketReference.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;

/// @title IGreaterMarketReference — the canonical collateral/USD market reference `G` (task 0080/0081).
/// @notice One manipulation-resistant `G(collateralId)` that seizure sizing (`X = debt×(1+bonus)/G`), the SP
///         marginal execution boundary (`F = G×(1−SLIPPAGE_TOL)`), and the Treasury exact-residual purchase price
///         all read — so every consumer prices off the SAME value/provenance at a block, never a divergent sample.
///
///         Contract: `priceUsd18` is an 18-decimal collateral/USD price. `valid == false` means the reference is
///         unavailable (unset / stale / below-quorum / manipulated) and the CONSUMER MUST FAIL CLOSED — never
///         substitute a caller-supplied price, a raw local spot, or a last-known-good value. Collateral-decimal
///         normalization is the consumer's responsibility, not this seam's.
///
///         The manipulation-resistant construction (median of an AMM + oracle feeds, quorum, depeg + deviation
///         bounds) is task 0081; it is implemented BEHIND this interface and swapped in without touching consumers.
interface IGreaterMarketReference {
    function greaterMarketPrice(uint256 collateralId)
        external
        view
        returns (uint256 priceUsd18, bool valid);
}

src/libraries/Roles.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;

/// @notice Canonical access-control role identifiers.
/// @dev Every privileged surface maps to a role here and to a row in
///      docs/security/wallet-register.md. All roles are assignable to a multisig/timelock — no EOA
///      assumptions, no `tx.origin`. `DEFAULT_ADMIN_ROLE` (0x00) comes from OZ AccessControl.
library Roles {
    /// @notice Registry/protocol wiring (bindings, pool registration).
    bytes32 internal constant REGISTRY_ADMIN_ROLE = keccak256("REGISTRY_ADMIN_ROLE");
    /// @notice Risk parameters + collateral/facility admission (economically mint-grade).
    bytes32 internal constant RISK_ADMIN_ROLE = keccak256("RISK_ADMIN_ROLE");
    /// @notice Publishes/deprecates typed oracle route definitions in the on-chain `FeedCatalogue` (task 0081 U3).
    ///         DATA admission for the pricing surface — it controls which feeds a price profile may be built from; it
    ///         moves no value and mints nothing, but a bad definition mis-prices `G`. Separation from `EMERGENCY_ROLE`
    ///         is ENFORCED on-chain by the catalogue's role-commingling guard; the custody posture (multisig/timelock)
    ///         is ratified with its `docs/security/wallet-register.md` row at deployment (task 0081 U10–U12).
    bytes32 internal constant FEED_PUBLISHER_ROLE = keccak256("FEED_PUBLISHER_ROLE");
    /// @notice Pause/halt of value-moving contracts. Held separately from the registry admin.
    bytes32 internal constant EMERGENCY_ROLE = keccak256("EMERGENCY_ROLE");
    /// @notice Liquidation authority. Single ACTIVE holder per pool (race avoidance); rotatable.
    bytes32 internal constant LIQUIDATOR_ROLE = keccak256("LIQUIDATOR_ROLE");
    /// @notice PRUSD mint authority (vault debt path + treasury PSM path).
    bytes32 internal constant MINTER_ROLE = keccak256("MINTER_ROLE");
    /// @notice PRUSD burn authority (repay / window burn).
    bytes32 internal constant BURNER_ROLE = keccak256("BURNER_ROLE");
    /// @notice Treasury operations (backstop / PSM / realised-sale accounting).
    bytes32 internal constant TREASURY_ROLE = keccak256("TREASURY_ROLE");
    /// @notice The vault, authorised to update facility debt accounting and drive pool absorption.
    bytes32 internal constant VAULT_ROLE = keccak256("VAULT_ROLE");
    /// @notice Local warehouse draft only: pool-side funding permission for the canonical warehouse
    ///         contract, independently granted from the Treasury's settlement-source binding. Never an EOA.
    bytes32 internal constant WAREHOUSE_FUNDING_ROLE = keccak256("WAREHOUSE_FUNDING_ROLE");
    /// @notice Revenue sources authorised to record Treasury inflows (Vault fee/interest, StabilityPool
    ///         liquidation profit). Attribution is a privileged surface — only protocol contracts hold it.
    bytes32 internal constant REVENUE_SOURCE_ROLE = keccak256("REVENUE_SOURCE_ROLE");
    /// @notice Stability-Pool share issuance — mint/burn of per-pool wPRUSD share tokens. Held by the pool,
    ///         NOT the Vault (the pool issues shares against deposits; the vault never touches share supply).
    bytes32 internal constant SHARE_ISSUER_ROLE = keccak256("SHARE_ISSUER_ROLE");
    /// @notice Collateral-realization authority (0045A): calls `StabilityPool.realize` to sell pending settlement
    ///         collateral. The 0059A keeper holds it; distinct from LIQUIDATOR_ROLE + the loss-accept EMERGENCY_ROLE.
    bytes32 internal constant SETTLEMENT_ROLE = keccak256("SETTLEMENT_ROLE");
    /// @notice Greater-market FLOOR realization authority (0080 D1): calls `StabilityPool.realizeAtFloor` — the
    ///         routine floor-limited path that MAY realize below cost + trigger a Treasury buyer-of-last-resort mint.
    ///         DELIBERATELY SEPARATE from `SETTLEMENT_ROLE` (its own dedicated keeper wallet) so this narrower, more
    ///         consequential authority never rides the plain settlement key; NEVER the loss-accept `EMERGENCY_ROLE`.
    bytes32 internal constant FLOOR_SETTLEMENT_ROLE = keccak256("FLOOR_SETTLEMENT_ROLE");
    /// @notice The dedicated PSM contract, authorised to drive `PsmAssetRegistry` accounting (0066). Held ONLY by
    ///         the constrained PSM — the sole PRUSD minter on the reserve-backed issuance path.
    bytes32 internal constant PSM_ROLE = keccak256("PSM_ROLE");
    /// @notice The backstop path, authorised to WRITE the Treasury's per-pool backstop ledger (0067).
    ///         ATTRIBUTION ONLY — does not move funds or mint. Kept strictly separate from the fund-moving
    ///         `BACKSTOP_ASSUME_ROLE` so granting a keeper ledger-write access can never grant vault seizure.
    bytes32 internal constant BACKSTOP_ROLE = keccak256("BACKSTOP_ROLE");
    /// @notice FUND-MOVING: authorises `Vault.assumeVault` — seizing a whole unfundable vault's collateral +
    ///         burning to clear its principal (0068). Held ONLY by the wired Treasury. Distinct from
    ///         `BACKSTOP_ROLE` (attribution) so the two capabilities are never conflated.
    bytes32 internal constant BACKSTOP_ASSUME_ROLE = keccak256("BACKSTOP_ASSUME_ROLE");

    // ── 0069 role split — narrow lanes carved out of the former coarse `TREASURY_ROLE` so one leaked keeper key
    //    can't do everything. Each is granted to its OWN wallet (task 0069 / scenario §5.7).
    /// @notice Routine floor-protected hotswap clip — `Treasury.backstopResolve` (hot keeper). Floor-gated on-chain.
    bytes32 internal constant HOTSWAP_ROLE = keccak256("HOTSWAP_ROLE");
    /// @notice Backstop vault-assumption TRIGGER — `Treasury.backstopAssumeVault` (guarded keeper/operator; on-chain
    ///         guarded to only liquidatable+unfundable vaults). DISTINCT from the contract-held `BACKSTOP_ASSUME_ROLE`
    ///         (the Treasury's permission ON the Vault), which no wallet ever holds.
    bytes32 internal constant BACKSTOP_OPERATOR_ROLE = keccak256("BACKSTOP_OPERATOR_ROLE");
    /// @notice Treasury PRUSD withdrawal / reserve allocation — `Treasury.withdraw` (multisig/governance, never a
    ///         keeper). The narrowed successor of the coarse `TREASURY_ROLE`.
    bytes32 internal constant TREASURY_WITHDRAW_ROLE = keccak256("TREASURY_WITHDRAW_ROLE");

    /// @notice Triggers `StabilityPool7540.recordTabRepayment` (legacy: Treasury.repayIou). May only trigger
    ///         recorded liability repayment, never choose a different recipient or author new TAB. Granted on the
    ///         receiving pool to its repayment operator, never folded into a broad Treasury role.
    bytes32 internal constant TREASURY_REPAY_ROLE = keccak256("TREASURY_REPAY_ROLE");

    /// @notice Triggers `TreasuryWaterfall.run` (task 0197). May only say "run" over a list of pools and reserves;
    ///         every amount is computed on-chain from live figures. Granted on the waterfall contract to the keeper's
    ///         waterfall wallet, never folded into a broad Treasury role.
    bytes32 internal constant WATERFALL_ROLE = keccak256("WATERFALL_ROLE");

    // IOU_CREDIT_ROLE removed (0079 slice 2): the slice-1 `StabilityPool.creditIou` seam is gone — TAB is credited
    // ONLY via the atomic balance-delta inside `_realizeCore`, so no external credit role exists.
}

src/types/ProtocolTypes.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.27;

/// @notice Shared enums and config/state structs for the facility-first CDP protocol.
/// @dev Types only — no logic, no storage. Registries, vault, pools, and subgraph type-generation
///      all reference this one source so `Collateral != Facility != Stability Pool` stays explicit.

/// @notice Canonical facility lifecycle states. Transition rules live in `FacilityStatusLib`.
enum FacilityStatus {
    Active,
    Paused,
    RepayOnly,
    Deprecated
}

/// @notice Stability pool exposure model.
enum PoolExposure {
    SingleAsset,
    MultiAsset
}

/// @notice Collateral asset definition. Pricing resolves separately through canonical G by `collateralId`.
struct CollateralConfig {
    uint256 collateralId;
    address token;
    uint8 decimals;
    uint256 oracleStalenessThreshold; // reserved — TODO-ORACLE-001
    uint256 twapWindow; // reserved — TODO-ORACLE-001
    uint256 maxDeviationBps; // reserved — TODO-ORACLE-001
    bool enabled;
}

/// @notice Immutable borrow-product terms. `termsHash` is registry-computed, never caller input.
struct FacilityConfig {
    uint256 facilityId;
    uint256 collateralId;
    address debtAsset;
    uint256 minOpeningCR; // Facility 1: 125% (canonical; 150% is legacy)
    uint256 liquidationCR; // Facility 1: 120%
    uint256 closeFactorBps; // Facility 1: 5000 (50%)
    uint256 liquidationBonusBps; // engine-bound; Facility 1: 1000 (10%)
    uint256 minInitialMint; // opening floor (MIN_MINT); launch facility 1,000 PRUSD
    uint256 minDebtAfterPartial; // floor left after a partial repay/liquidation (Proposed 500)
    uint256 maxDebtPerVault;
    uint256 globalDebtCap;
    uint256 mintFeeBps;
    uint256 aprBps; // fixed at registration; accrual reads this immutable facility term
    uint256 tokenOffsetCapBps; // PRYA offset cap (0046); disabled at launch
    bool redrawable; // may a borrower draw again after their first draw? (register REDRAW_LAUNCH)
    uint256 liquidationPoolId; // the ONE pool this facility routes liquidations to
    address liquidationEngine;
    address feeRecipient;
    address interestRecipient;
    address treasury;
    uint256 targetCR; // immutable warehouse target T in bps; current close-factor liquidation does not consume it
    bytes32 termsHash;
}

/// @notice Mutable facility accounting.
struct FacilityState {
    FacilityStatus status;
    uint256 currentPrincipalMinted;
    uint256 currentDebtOutstanding;
    uint256 lastAccruedAt;
}

/// @notice Borrower position, keyed by (borrower, facilityId). Never an NFT.
struct VaultData {
    uint256 collateralAmount;
    uint256 principalDebt; // raw PRUSD principal owed (== minted, still outstanding); supply == Σ principalDebt
    uint256 accruedInterest; // owed interest, NEVER minted; routed to interestRecipient on repay/close
    uint256 lastAccruedAt; // timestamp interest was last accrued (0 / unused when the facility has no interest)
    uint256 openedAt;
    bool exists;
}

/// @notice Stability pool metadata + routing. A collateralId is watched by at most one active pool.
struct StabilityPoolInfo {
    uint256 poolId;
    address pool;
    PoolExposure exposure;
    bool active;
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {
    "src/libraries/TreasurySales.sol": {
      "TreasurySales": "0x78dC32DCFbe1B0D11b85f2405669401242eebf64"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "lib/openzeppelin-community-contracts/contracts/:@openzeppelin/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
    "lib/openzeppelin-community-contracts/contracts/:@openzeppelin/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "forge-std/=lib/forge-std/src/",
    "@openzeppelin/community-contracts/=lib/openzeppelin-community-contracts/contracts/",
    "@openzeppelin7540/contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/contracts/",
    "@axelar-network/axelar-gmp-sdk-solidity/=lib/openzeppelin-community-contracts/lib/axelar-gmp-sdk-solidity/",
    "@openzeppelin-contracts/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-community-contracts/lib/@openzeppelin-contracts-upgradeable/contracts/",
    "@zk-email/contracts/=lib/openzeppelin-community-contracts/lib/zk-email-verify/packages/contracts/",
    "@zk-email/email-tx-builder/=lib/openzeppelin-community-contracts/lib/email-tx-builder/packages/contracts/",
    "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-community-contracts/=lib/openzeppelin-community-contracts/contracts/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "wormhole-solidity-sdk/=lib/openzeppelin-community-contracts/lib/wormhole-solidity-sdk/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.