File size: 95,919 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
  "language": "Solidity",
  "sources": {
    "contracts/core/h-token/HToken.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.4;\n\nimport \"@prb/contracts/access/Ownable.sol\";\nimport \"@prb/contracts/token/erc20/Erc20.sol\";\nimport \"@prb/contracts/token/erc20/Erc20Permit.sol\";\nimport \"@prb/contracts/token/erc20/Erc20Recover.sol\";\nimport \"@prb/contracts/token/erc20/SafeErc20.sol\";\n\nimport \"./IHToken.sol\";\nimport \"../balance-sheet/IBalanceSheetV2.sol\";\nimport \"../fintroller/IFintroller.sol\";\n\n/// @title HToken\n/// @author Hifi\ncontract HToken is\n    Ownable, // one dependency\n    Erc20, // one dependency\n    Erc20Permit, // four dependencies\n    IHToken, // five dependencies\n    Erc20Recover // five dependencies\n{\n    using SafeErc20 for IErc20;\n\n    /// PUBLIC STORAGE ///\n\n    /// @inheritdoc IHToken\n    IBalanceSheetV2 public override balanceSheet;\n\n    /// @inheritdoc IHToken\n    IFintroller public override fintroller;\n\n    /// @inheritdoc IHToken\n    uint256 public override maturity;\n\n    /// @inheritdoc IHToken\n    uint256 public override totalUnderlyingReserve;\n\n    /// @inheritdoc IHToken\n    IErc20 public override underlying;\n\n    /// @inheritdoc IHToken\n    uint256 public override underlyingPrecisionScalar;\n\n    /// INTERNAL STORAGE ///\n\n    /// @dev Underlying depositor balances.\n    mapping(address => uint256) internal depositorBalances;\n\n    /// CONSTRUCTOR ///\n\n    /// @notice The hToken always has 18 decimals.\n    /// @param name_ Erc20 name of this token.\n    /// @param symbol_ Erc20 symbol of this token.\n    /// @param maturity_ Unix timestamp in seconds for when this token matures.\n    /// @param balanceSheet_ The address of the BalanceSheet contract to connect to.\n    /// @param fintroller_ The address of the Fintroller contract to connect to.\n    /// @param underlying_ The contract address of the underlying asset.\n    constructor(\n        string memory name_,\n        string memory symbol_,\n        uint256 maturity_,\n        IBalanceSheetV2 balanceSheet_,\n        IFintroller fintroller_,\n        IErc20 underlying_\n    ) Erc20Permit(name_, symbol_, 18) Ownable() {\n        // Set the maturity.\n        if (maturity_ <= block.timestamp) {\n            revert HToken__MaturityPassed(block.timestamp, maturity_);\n        }\n        maturity = maturity_;\n\n        // Set the BalanceSheet contract.\n        balanceSheet = balanceSheet_;\n\n        // Set the Fintroller contract.\n        fintroller = fintroller_;\n\n        // Set the underlying contract and calculate the precision scalar.\n        uint256 underlyingDecimals = underlying_.decimals();\n        if (underlyingDecimals == 0) {\n            revert HToken__UnderlyingDecimalsZero();\n        }\n        if (underlyingDecimals > 18) {\n            revert HToken__UnderlyingDecimalsOverflow(underlyingDecimals);\n        }\n        underlyingPrecisionScalar = 10**(18 - underlyingDecimals);\n        underlying = underlying_;\n\n        // Set the list of non-recoverable tokens.\n        nonRecoverableTokens.push(underlying);\n        isRecoverInitialized = true;\n    }\n\n    /// PUBLIC CONSTANT FUNCTIONS ///\n\n    function getDepositorBalance(address depositor) external view override returns (uint256 amount) {\n        return depositorBalances[depositor];\n    }\n\n    /// @inheritdoc IHToken\n    function isMatured() public view override returns (bool) {\n        return block.timestamp >= maturity;\n    }\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IHToken\n    function burn(address holder, uint256 burnAmount) external override {\n        // Checks: the caller is the BalanceSheet.\n        if (msg.sender != address(balanceSheet)) {\n            revert HToken__BurnNotAuthorized(msg.sender);\n        }\n\n        // Effects: burns the hTokens.\n        burnInternal(holder, burnAmount);\n\n        // Emit a Burn and a Transfer event.\n        emit Burn(holder, burnAmount);\n    }\n\n    /// @inheritdoc IHToken\n    function depositUnderlying(uint256 underlyingAmount) external override {\n        // Checks: the Fintroller allows this action to be performed.\n        if (!fintroller.getDepositUnderlyingAllowed(this)) {\n            revert HToken__DepositUnderlyingNotAllowed();\n        }\n\n        // Checks: the zero edge case.\n        if (underlyingAmount == 0) {\n            revert HToken__DepositUnderlyingZero();\n        }\n\n        // Effects: update storage.\n        totalUnderlyingReserve += underlyingAmount;\n\n        // Effects: update the balance of the depositor.\n        depositorBalances[msg.sender] += underlyingAmount;\n\n        // Normalize the underlying amount to 18 decimals.\n        uint256 hTokenAmount = normalize(underlyingAmount);\n\n        // Effects: mint the hTokens.\n        mintInternal(msg.sender, hTokenAmount);\n\n        // Interactions: perform the Erc20 transfer.\n        underlying.safeTransferFrom(msg.sender, address(this), underlyingAmount);\n\n        emit DepositUnderlying(msg.sender, underlyingAmount, hTokenAmount);\n    }\n\n    /// @inheritdoc IHToken\n    function mint(address beneficiary, uint256 mintAmount) external override {\n        // Checks: the caller is the BalanceSheet.\n        if (msg.sender != address(balanceSheet)) {\n            revert HToken__MintNotAuthorized(msg.sender);\n        }\n\n        // Effects: print the new hTokens into existence.\n        mintInternal(beneficiary, mintAmount);\n\n        // Emit a Mint event.\n        emit Mint(beneficiary, mintAmount);\n    }\n\n    /// @inheritdoc IHToken\n    function redeem(uint256 underlyingAmount) external override {\n        // Checks: before maturation.\n        if (!isMatured()) {\n            revert HToken__BondNotMatured(block.timestamp, maturity);\n        }\n\n        // Checks: the zero edge case.\n        if (underlyingAmount == 0) {\n            revert HToken__RedeemZero();\n        }\n\n        // Checks: there is enough liquidity.\n        if (underlyingAmount > totalUnderlyingReserve) {\n            revert HToken__RedeemInsufficientLiquidity(underlyingAmount, totalUnderlyingReserve);\n        }\n\n        // Effects: decrease the reserves of underlying.\n        totalUnderlyingReserve -= underlyingAmount;\n\n        // Normalize the underlying amount to 18 decimals.\n        uint256 hTokenAmount = normalize(underlyingAmount);\n\n        // Effects: burn the hTokens.\n        burnInternal(msg.sender, hTokenAmount);\n\n        // Interactions: perform the Erc20 transfer.\n        underlying.safeTransfer(msg.sender, underlyingAmount);\n\n        emit Redeem(msg.sender, underlyingAmount, hTokenAmount);\n    }\n\n    /// @inheritdoc IHToken\n    function withdrawUnderlying(uint256 underlyingAmount) external override {\n        // Checks: after maturation, depositors should call the `redeem` function instead.\n        if (isMatured()) {\n            revert HToken__BondMatured(block.timestamp, maturity);\n        }\n\n        // Checks: the zero edge case.\n        if (underlyingAmount == 0) {\n            revert HToken__WithdrawUnderlyingZero();\n        }\n\n        // Checks: the depositor has enough underlying.\n        uint256 availableAmount = depositorBalances[msg.sender];\n        if (availableAmount < underlyingAmount) {\n            revert HToken__WithdrawUnderlyingUnderflow(msg.sender, availableAmount, underlyingAmount);\n        }\n\n        // Effects: update storage.\n        totalUnderlyingReserve -= underlyingAmount;\n\n        // Effects: update the balance of the depositor.\n        depositorBalances[msg.sender] -= underlyingAmount;\n\n        // Normalize the underlying amount to 18 decimals.\n        uint256 hTokenAmount = normalize(underlyingAmount);\n\n        // Effects: burn the hTokens.\n        burnInternal(msg.sender, hTokenAmount);\n\n        // Interactions: perform the Erc20 transfer.\n        underlying.safeTransfer(msg.sender, underlyingAmount);\n\n        emit WithdrawUnderlying(msg.sender, underlyingAmount, hTokenAmount);\n    }\n\n    /// @inheritdoc IHToken\n    function _setBalanceSheet(IBalanceSheetV2 newBalanceSheet) external override onlyOwner {\n        // Effects: update storage.\n        IBalanceSheetV2 oldBalanceSheet = balanceSheet;\n        balanceSheet = newBalanceSheet;\n\n        emit SetBalanceSheet(owner, oldBalanceSheet, newBalanceSheet);\n    }\n\n    /// INTERNAL CONSTANT FUNCTIONS ///\n\n    /// @notice Upscales the underlying amount to normalized form, i.e. 18 decimals of precision.\n    /// @param underlyingAmount The underlying amount with its actual decimals of precision.\n    /// @param normalizedUnderlyingAmount The underlying amount with 18 decimals of precision.\n    function normalize(uint256 underlyingAmount) internal view returns (uint256 normalizedUnderlyingAmount) {\n        normalizedUnderlyingAmount = underlyingPrecisionScalar != 1\n            ? underlyingAmount * underlyingPrecisionScalar\n            : underlyingAmount;\n    }\n}\n"
    },
    "@prb/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\nimport \"./IOwnable.sol\";\n\n/// @notice Emitted when the caller is not the owner.\nerror Ownable__NotOwner(address owner, address caller);\n\n/// @notice Emitted when setting the owner to the zero address.\nerror Ownable__OwnerZeroAddress();\n\n/// @title Ownable\n/// @author Paul Razvan Berg\ncontract Ownable is IOwnable {\n    /// PUBLIC STORAGE ///\n\n    /// @inheritdoc IOwnable\n    address public override owner;\n\n    /// MODIFIERS ///\n\n    /// @notice Throws if called by any account other than the owner.\n    modifier onlyOwner() {\n        if (owner != msg.sender) {\n            revert Ownable__NotOwner(owner, msg.sender);\n        }\n        _;\n    }\n\n    /// CONSTRUCTOR ///\n\n    /// @notice Initializes the contract setting the deployer as the initial owner.\n    constructor() {\n        address msgSender = msg.sender;\n        owner = msgSender;\n        emit TransferOwnership(address(0), msgSender);\n    }\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IOwnable\n    function _renounceOwnership() public virtual override onlyOwner {\n        emit TransferOwnership(owner, address(0));\n        owner = address(0);\n    }\n\n    /// @inheritdoc IOwnable\n    function _transferOwnership(address newOwner) public virtual override onlyOwner {\n        if (newOwner == address(0)) {\n            revert Ownable__OwnerZeroAddress();\n        }\n        emit TransferOwnership(owner, newOwner);\n        owner = newOwner;\n    }\n}\n"
    },
    "@prb/contracts/token/erc20/Erc20.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\nimport \"./IErc20.sol\";\n\n/// @notice Emitted when the owner is the zero address.\nerror Erc20__ApproveOwnerZeroAddress();\n\n/// @notice Emitted when the spender is the zero address.\nerror Erc20__ApproveSpenderZeroAddress();\n\n/// @notice Emitted when burning more tokens than are in the account.\nerror Erc20__BurnUnderflow(uint256 accountBalance, uint256 burnAmount);\n\n/// @notice Emitted when the holder is the zero address.\nerror Erc20__BurnZeroAddress();\n\n/// @notice Emitted when the owner did not give the spender sufficient allowance.\nerror Erc20__InsufficientAllowance(uint256 allowance, uint256 amount);\n\n/// @notice Emitted when tranferring more tokens than there are in the account.\nerror Erc20__InsufficientBalance(uint256 senderBalance, uint256 amount);\n\n/// @notice Emitted when the beneficiary is the zero address.\nerror Erc20__MintZeroAddress();\n\n/// @notice Emitted when the sender is the zero address.\nerror Erc20__TransferSenderZeroAddress();\n\n/// @notice Emitted when the recipient is the zero address.\nerror Erc20__TransferRecipientZeroAddress();\n\n/// @title Erc20\n/// @author Paul Razvan Berg\ncontract Erc20 is IErc20 {\n    /// PUBLIC STORAGE ///\n\n    /// @inheritdoc IErc20\n    string public override name;\n\n    /// @inheritdoc IErc20\n    string public override symbol;\n\n    /// @inheritdoc IErc20\n    uint8 public immutable override decimals;\n\n    /// @inheritdoc IErc20\n    uint256 public override totalSupply;\n\n    /// INTERNAL STORAGE ///\n\n    /// @dev Internal mapping of balances.\n    mapping(address => uint256) internal balances;\n\n    /// @dev Internal mapping of allowances.\n    mapping(address => mapping(address => uint256)) internal allowances;\n\n    /// CONSTRUCTOR ///\n\n    /// @notice All three of these arguments are immutable: they can only be set once during construction.\n    /// @param name_ Erc20 name of this token.\n    /// @param symbol_ Erc20 symbol of this token.\n    /// @param decimals_ Erc20 decimal precision of this token.\n    constructor(\n        string memory name_,\n        string memory symbol_,\n        uint8 decimals_\n    ) {\n        name = name_;\n        symbol = symbol_;\n        decimals = decimals_;\n    }\n\n    /// PUBLIC CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IErc20\n    function allowance(address owner, address spender) public view override returns (uint256) {\n        return allowances[owner][spender];\n    }\n\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return balances[account];\n    }\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IErc20\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        approveInternal(msg.sender, spender, amount);\n        return true;\n    }\n\n    /// @inheritdoc IErc20\n    function decreaseAllowance(address spender, uint256 subtractedAmount) public virtual override returns (bool) {\n        uint256 newAllowance = allowances[msg.sender][spender] - subtractedAmount;\n        approveInternal(msg.sender, spender, newAllowance);\n        return true;\n    }\n\n    /// @inheritdoc IErc20\n    function increaseAllowance(address spender, uint256 addedAmount) public virtual override returns (bool) {\n        uint256 newAllowance = allowances[msg.sender][spender] + addedAmount;\n        approveInternal(msg.sender, spender, newAllowance);\n        return true;\n    }\n\n    /// @inheritdoc IErc20\n    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {\n        transferInternal(msg.sender, recipient, amount);\n        return true;\n    }\n\n    /// @inheritdoc IErc20\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) public virtual override returns (bool) {\n        transferInternal(sender, recipient, amount);\n\n        uint256 currentAllowance = allowances[sender][msg.sender];\n        if (currentAllowance < amount) {\n            revert Erc20__InsufficientAllowance(currentAllowance, amount);\n        }\n        unchecked {\n            approveInternal(sender, msg.sender, currentAllowance - amount);\n        }\n\n        return true;\n    }\n\n    /// INTERNAL NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Sets `amount` as the allowance of `spender` over the `owner`s tokens.\n    ///\n    /// @dev Emits an {Approval} event.\n    ///\n    /// Requirements:\n    ///\n    /// - `owner` cannot be the zero address.\n    /// - `spender` cannot be the zero address.\n    function approveInternal(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        if (owner == address(0)) {\n            revert Erc20__ApproveOwnerZeroAddress();\n        }\n        if (spender == address(0)) {\n            revert Erc20__ApproveSpenderZeroAddress();\n        }\n\n        allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /// @notice Destroys `burnAmount` tokens from `holder`, reducing the token supply.\n    ///\n    /// @dev Emits a {Transfer} event.\n    ///\n    /// Requirements:\n    ///\n    /// - `holder` must have at least `amount` tokens.\n    function burnInternal(address holder, uint256 burnAmount) internal {\n        if (holder == address(0)) {\n            revert Erc20__BurnZeroAddress();\n        }\n\n        // Burn the tokens.\n        balances[holder] -= burnAmount;\n\n        // Reduce the total supply.\n        totalSupply -= burnAmount;\n\n        emit Transfer(holder, address(0), burnAmount);\n    }\n\n    /// @notice Prints new tokens into existence and assigns them to `beneficiary`, increasing the\n    /// total supply.\n    ///\n    /// @dev Emits a {Transfer} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The beneficiary's balance and the total supply cannot overflow.\n    function mintInternal(address beneficiary, uint256 mintAmount) internal {\n        if (beneficiary == address(0)) {\n            revert Erc20__MintZeroAddress();\n        }\n\n        /// Mint the new tokens.\n        balances[beneficiary] += mintAmount;\n\n        /// Increase the total supply.\n        totalSupply += mintAmount;\n\n        emit Transfer(address(0), beneficiary, mintAmount);\n    }\n\n    /// @notice Moves `amount` tokens from `sender` to `recipient`.\n    ///\n    /// @dev Emits a {Transfer} event.\n    ///\n    /// Requirements:\n    ///\n    /// - `sender` cannot be the zero address.\n    /// - `recipient` cannot be the zero address.\n    /// - `sender` must have a balance of at least `amount`.\n    function transferInternal(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) internal virtual {\n        if (sender == address(0)) {\n            revert Erc20__TransferSenderZeroAddress();\n        }\n        if (recipient == address(0)) {\n            revert Erc20__TransferRecipientZeroAddress();\n        }\n\n        uint256 senderBalance = balances[sender];\n        if (senderBalance < amount) {\n            revert Erc20__InsufficientBalance(senderBalance, amount);\n        }\n        unchecked {\n            balances[sender] = senderBalance - amount;\n        }\n\n        balances[recipient] += amount;\n\n        emit Transfer(sender, recipient, amount);\n    }\n}\n"
    },
    "@prb/contracts/token/erc20/Erc20Permit.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\n// solhint-disable var-name-mixedcase\npragma solidity >=0.8.4;\n\nimport \"./Erc20.sol\";\nimport \"./IErc20Permit.sol\";\n\n/// @notice Emitted when the recovered owner does not match the actual owner.\nerror Erc20Permit__InvalidSignature(uint8 v, bytes32 r, bytes32 s);\n\n/// @notice Emitted when the owner is the zero address.\nerror Erc20Permit__OwnerZeroAddress();\n\n/// @notice Emitted when the permit expired.\nerror Erc20Permit__PermitExpired(uint256 deadline);\n\n/// @notice Emitted when the recovered owner is the zero address.\nerror Erc20Permit__RecoveredOwnerZeroAddress();\n\n/// @notice Emitted when the spender is the zero address.\nerror Erc20Permit__SpenderZeroAddress();\n\n/// @title Erc20Permit\n/// @author Paul Razvan Berg\ncontract Erc20Permit is\n    IErc20Permit, // one dependency\n    Erc20 // one dependency\n{\n    /// PUBLIC STORAGE ///\n\n    /// @inheritdoc IErc20Permit\n    bytes32 public immutable override DOMAIN_SEPARATOR;\n\n    /// @inheritdoc IErc20Permit\n    bytes32 public constant override PERMIT_TYPEHASH =\n        keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n\n    /// @inheritdoc IErc20Permit\n    mapping(address => uint256) public override nonces;\n\n    /// @inheritdoc IErc20Permit\n    string public constant override version = \"1\";\n\n    /// CONSTRUCTOR ///\n\n    constructor(\n        string memory _name,\n        string memory _symbol,\n        uint8 _decimals\n    ) Erc20(_name, _symbol, _decimals) {\n        uint256 chainId;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            chainId := chainid()\n        }\n        DOMAIN_SEPARATOR = keccak256(\n            abi.encode(\n                keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n                keccak256(bytes(name)),\n                keccak256(bytes(version)),\n                chainId,\n                address(this)\n            )\n        );\n    }\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IErc20Permit\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) public override {\n        if (owner == address(0)) {\n            revert Erc20Permit__OwnerZeroAddress();\n        }\n        if (spender == address(0)) {\n            revert Erc20Permit__SpenderZeroAddress();\n        }\n        if (deadline < block.timestamp) {\n            revert Erc20Permit__PermitExpired(deadline);\n        }\n\n        // It's safe to use unchecked here because the nonce cannot realistically overflow, ever.\n        bytes32 hashStruct;\n        unchecked {\n            hashStruct = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline));\n        }\n        bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", DOMAIN_SEPARATOR, hashStruct));\n        address recoveredOwner = ecrecover(digest, v, r, s);\n\n        if (recoveredOwner == address(0)) {\n            revert Erc20Permit__RecoveredOwnerZeroAddress();\n        }\n        if (recoveredOwner != owner) {\n            revert Erc20Permit__InvalidSignature(v, r, s);\n        }\n\n        approveInternal(owner, spender, value);\n    }\n}\n"
    },
    "@prb/contracts/token/erc20/Erc20Recover.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\nimport \"./IErc20.sol\";\nimport \"./IErc20Recover.sol\";\nimport \"./SafeErc20.sol\";\nimport \"../../access/Ownable.sol\";\n\n/// @notice Emitted when the contract is initialized.\nerror Initialized();\n\n/// @notice Emitted when the contract is not initialized.\nerror NotInitialized();\n\n/// @notice Emitted when recovering a token marked as non-recoverable.\nerror NonRecoverableToken(address token);\n\n/// @notice Emitted when the amount to recover is zero.\nerror RecoverZero();\n\n/// @title Erc20Recover\n/// @author Paul Razvan Berg\nabstract contract Erc20Recover is\n    Ownable, // one dependency\n    IErc20Recover // two dependencies\n{\n    using SafeErc20 for IErc20;\n\n    /// PUBLIC STORAGE ///\n\n    /// @inheritdoc IErc20Recover\n    IErc20[] public override nonRecoverableTokens;\n\n    /// @dev A flag that signals whether the the non-recoverable tokens were set or not.\n    bool internal isRecoverInitialized;\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @inheritdoc IErc20Recover\n    function _setNonRecoverableTokens(IErc20[] memory tokens) public override onlyOwner {\n        // Checks\n        if (isRecoverInitialized) {\n            revert Initialized();\n        }\n\n        // Iterate over the token list, sanity check each and update the mapping.\n        uint256 length = tokens.length;\n        for (uint256 i = 0; i < length; i += 1) {\n            tokens[i].symbol();\n            nonRecoverableTokens.push(tokens[i]);\n        }\n\n        // Effects: prevent this function from ever being called again.\n        isRecoverInitialized = true;\n\n        emit SetNonRecoverableTokens(owner, tokens);\n    }\n\n    /// @inheritdoc IErc20Recover\n    function _recover(IErc20 token, uint256 recoverAmount) public override onlyOwner {\n        // Checks\n        if (!isRecoverInitialized) {\n            revert NotInitialized();\n        }\n\n        if (recoverAmount == 0) {\n            revert RecoverZero();\n        }\n\n        bytes32 tokenSymbolHash = keccak256(bytes(token.symbol()));\n        uint256 length = nonRecoverableTokens.length;\n\n        // We iterate over the non-recoverable token array and check that:\n        //\n        //   1. The addresses of the tokens are not the same.\n        //   2. The symbols of the tokens are not the same.\n        //\n        // It is true that the second check may lead to a false positive, but there is no better way\n        // to fend off against proxied tokens.\n        for (uint256 i = 0; i < length; i += 1) {\n            if (\n                address(token) == address(nonRecoverableTokens[i]) ||\n                tokenSymbolHash == keccak256(bytes(nonRecoverableTokens[i].symbol()))\n            ) {\n                revert NonRecoverableToken(address(token));\n            }\n        }\n\n        // Interactions\n        token.safeTransfer(owner, recoverAmount);\n\n        emit Recover(owner, token, recoverAmount);\n    }\n}\n"
    },
    "@prb/contracts/token/erc20/SafeErc20.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\nimport \"./IErc20.sol\";\nimport \"../../utils/Address.sol\";\n\n/// @notice Emitted when the call is made to a non-contract.\nerror SafeErc20__CallToNonContract(address target);\n\n/// @notice Emitted when there is no return data.\nerror SafeErc20__NoReturnData();\n\n/// @title SafeErc20.sol\n/// @author Paul Razvan Berg\n/// @notice Wraps around Erc20 operations that throw on failure (when the token contract\n/// returns false). Tokens that return no value (and instead revert or throw\n/// on failure) are also supported, non-reverting calls are assumed to be successful.\n///\n/// To use this library you can add a `using SafeErc20 for IErc20;` statement to your contract,\n/// which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n///\n/// @dev Forked from OpenZeppelin\n/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/utils/Address.sol\nlibrary SafeErc20 {\n    using Address for address;\n\n    /// INTERNAL FUNCTIONS ///\n\n    function safeTransfer(\n        IErc20 token,\n        address to,\n        uint256 amount\n    ) internal {\n        callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, amount));\n    }\n\n    function safeTransferFrom(\n        IErc20 token,\n        address from,\n        address to,\n        uint256 amount\n    ) internal {\n        callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, amount));\n    }\n\n    /// PRIVATE FUNCTIONS ///\n\n    /// @dev Imitates a Solidity high-level call (a regular function call to a contract), relaxing the requirement\n    /// on the return value: the return value is optional (but if data is returned, it cannot be false).\n    /// @param token The token targeted by the call.\n    /// @param data The call data (encoded using abi.encode or one of its variants).\n    function callOptionalReturn(IErc20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n        bytes memory returndata = functionCall(address(token), data, \"SafeErc20LowLevelCall\");\n        if (returndata.length > 0) {\n            // Return data is optional.\n            if (!abi.decode(returndata, (bool))) {\n                revert SafeErc20__NoReturnData();\n            }\n        }\n    }\n\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) private returns (bytes memory) {\n        if (!target.isContract()) {\n            revert SafeErc20__CallToNonContract(target);\n        }\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call(data);\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present.\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly.\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
    },
    "contracts/core/h-token/IHToken.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.4;\n\nimport \"@prb/contracts/access/IOwnable.sol\";\nimport \"@prb/contracts/token/erc20/IErc20.sol\";\nimport \"@prb/contracts/token/erc20/IErc20Permit.sol\";\nimport \"@prb/contracts/token/erc20/IErc20Recover.sol\";\n\nimport \"../balance-sheet/IBalanceSheetV2.sol\";\nimport \"../fintroller/IFintroller.sol\";\n\n/// @title IHToken\n/// @author Hifi\n/// @notice Zero-coupon bond that tracks an Erc20 underlying asset.\ninterface IHToken is\n    IOwnable, // no dependency\n    IErc20Permit, // one dependency\n    IErc20Recover // one dependency\n{\n    /// CUSTOM ERRORS ///\n\n    /// @notice Emitted when the bond matured.\n    error HToken__BondMatured(uint256 now, uint256 maturity);\n\n    /// @notice Emitted when the bond did not mature.\n    error HToken__BondNotMatured(uint256 now, uint256 maturity);\n\n    /// @notice Emitted when burning hTokens and the caller is not the BalanceSheet contract.\n    error HToken__BurnNotAuthorized(address caller);\n\n    /// @notice Emitted when underlying deposits are not allowed by the Fintroller contract.\n    error HToken__DepositUnderlyingNotAllowed();\n\n    /// @notice Emitted when depositing a zero amount of underlying.\n    error HToken__DepositUnderlyingZero();\n\n    /// @notice Emitted when the maturity is in the past.\n    error HToken__MaturityPassed(uint256 now, uint256 maturity);\n\n    /// @notice Emitted when minting hTokens and the caller is not the BalanceSheet contract.\n    error HToken__MintNotAuthorized(address caller);\n\n    /// @notice Emitted when redeeming more underlying that there is in the reserve.\n    error HToken__RedeemInsufficientLiquidity(uint256 underlyingAmount, uint256 totalUnderlyingReserve);\n\n    /// @notice Emitted when redeeming a zero amount of underlying.\n    error HToken__RedeemZero();\n\n    /// @notice Emitted when constructing the contract and the underlying has more than 18 decimals.\n    error HToken__UnderlyingDecimalsOverflow(uint256 decimals);\n\n    /// @notice Emitted when constructing the contract and the underlying has zero decimals.\n    error HToken__UnderlyingDecimalsZero();\n\n    /// @notice Emitted when withdrawing more underlying than there is available.\n    error HToken__WithdrawUnderlyingUnderflow(address depositor, uint256 availableAmount, uint256 underlyingAmount);\n\n    /// @notice Emitted when withdrawing a zero amount of underlying.\n    error HToken__WithdrawUnderlyingZero();\n\n    /// EVENTS ///\n\n    /// @notice Emitted when tokens are burnt.\n    /// @param holder The address of the holder.\n    /// @param burnAmount The amount of burnt tokens.\n    event Burn(address indexed holder, uint256 burnAmount);\n\n    /// @notice Emitted when underlying is deposited in exchange for an equivalent amount of hTokens.\n    /// @param depositor The address of the depositor.\n    /// @param depositUnderlyingAmount The amount of deposited underlying.\n    /// @param hTokenAmount The amount of minted hTokens.\n    event DepositUnderlying(address indexed depositor, uint256 depositUnderlyingAmount, uint256 hTokenAmount);\n\n    /// @notice Emitted when tokens are minted.\n    /// @param beneficiary The address of the holder.\n    /// @param mintAmount The amount of minted tokens.\n    event Mint(address indexed beneficiary, uint256 mintAmount);\n\n    /// @notice Emitted when underlying is redeemed.\n    /// @param account The account redeeming the underlying.\n    /// @param underlyingAmount The amount of redeemed underlying.\n    /// @param hTokenAmount The amount of provided hTokens.\n    event Redeem(address indexed account, uint256 underlyingAmount, uint256 hTokenAmount);\n\n    /// @notice Emitted when the BalanceSheet is set.\n    /// @param owner The address of the owner.\n    /// @param oldBalanceSheet The address of the old BalanceSheet.\n    /// @param newBalanceSheet The address of the new BalanceSheet.\n    event SetBalanceSheet(address indexed owner, IBalanceSheetV2 oldBalanceSheet, IBalanceSheetV2 newBalanceSheet);\n\n    /// @notice Emitted when a depositor withdraws previously deposited underlying.\n    /// @param depositor The address of the depositor.\n    /// @param underlyingAmount The amount of withdrawn underlying.\n    /// @param hTokenAmount The amount of minted hTokens.\n    event WithdrawUnderlying(address indexed depositor, uint256 underlyingAmount, uint256 hTokenAmount);\n\n    /// PUBLIC CONSTANT FUNCTIONS ///\n\n    /// @notice Returns the BalanceSheet contract this HToken is connected to.\n    function balanceSheet() external view returns (IBalanceSheetV2);\n\n    /// @notice Returns the balance of the given depositor.\n    function getDepositorBalance(address depositor) external view returns (uint256 amount);\n\n    /// @notice Returns the Fintroller contract this HToken is connected to.\n    function fintroller() external view returns (IFintroller);\n\n    /// @notice Checks if the bond matured.\n    /// @return bool true = bond matured, otherwise it didn't.\n    function isMatured() external view returns (bool);\n\n    /// @notice Unix timestamp in seconds for when this HToken matures.\n    function maturity() external view returns (uint256);\n\n    /// @notice The amount of underlying redeemable after maturation.\n    function totalUnderlyingReserve() external view returns (uint256);\n\n    /// @notice The Erc20 underlying asset for this HToken.\n    function underlying() external view returns (IErc20);\n\n    /// @notice The ratio between normalized precision (1e18) and the underlying precision.\n    function underlyingPrecisionScalar() external view returns (uint256);\n\n    /// PUBLIC NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Destroys `burnAmount` tokens from `holder`, reducing the token supply.\n    ///\n    /// @dev Emits a {Burn} and a {Transfer} event.\n    ///\n    /// Requirements:\n    /// - Can only be called by the BalanceSheet contract.\n    ///\n    /// @param holder The account whose hTokens to burn.\n    /// @param burnAmount The amount of hTokens to burn.\n    function burn(address holder, uint256 burnAmount) external;\n\n    /// @notice Deposits underlying in exchange for an equivalent amount of hTokens.\n    ///\n    /// @dev Emits a {DepositUnderlying} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The Fintroller must allow this action to be performed.\n    /// - The underlying amount to deposit cannot be zero.\n    /// - The caller must have allowed this contract to spend `underlyingAmount` tokens.\n    ///\n    /// @param underlyingAmount The amount of underlying to deposit.\n    function depositUnderlying(uint256 underlyingAmount) external;\n\n    /// @notice Prints new tokens into existence and assigns them to `beneficiary`, increasing the total supply.\n    ///\n    /// @dev Emits a {Mint} and a {Transfer} event.\n    ///\n    /// Requirements:\n    /// - Can only be called by the BalanceSheet contract.\n    ///\n    /// @param beneficiary The account to mint the hTokens for.\n    /// @param mintAmount The amount of hTokens to print into existence.\n    function mint(address beneficiary, uint256 mintAmount) external;\n\n    /// @notice Pays the token holder the face value after maturation.\n    ///\n    /// @dev Emits a {Redeem} event.\n    ///\n    /// Requirements:\n    ///\n    /// - Can only be called after maturation.\n    /// - The amount of underlying to redeem cannot be zero.\n    /// - There must be enough liquidity in the contract.\n    ///\n    /// @param underlyingAmount The amount of underlying to redeem.\n    function redeem(uint256 underlyingAmount) external;\n\n    /// @notice Updates the BalanceSheet contract this HToken is connected to.\n    ///\n    /// @dev Throws a {SetBalanceSheet} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param newBalanceSheet The address of the new BalanceSheet contract.\n    function _setBalanceSheet(IBalanceSheetV2 newBalanceSheet) external;\n\n    /// @notice Withdraws underlying in exchange for hTokens.\n    ///\n    /// @dev Emits a {WithdrawUnderlying} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The underlying amount to withdraw cannot be zero.\n    /// - Can only be called before maturation.\n    ///\n    /// @param underlyingAmount The amount of underlying to withdraw.\n    function withdrawUnderlying(uint256 underlyingAmount) external;\n}\n"
    },
    "contracts/core/balance-sheet/IBalanceSheetV2.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.4;\n\nimport \"@prb/contracts/token/erc20/IErc20.sol\";\n\nimport \"../fintroller/IFintroller.sol\";\nimport \"../h-token/IHToken.sol\";\nimport \"../../access/IOwnableUpgradeable.sol\";\nimport \"../../oracles/IChainlinkOperator.sol\";\n\n/// @title IBalanceSheetV2\n/// @author Hifi\n/// @notice Manages the collaterals and the debts for all users.\ninterface IBalanceSheetV2 is IOwnableUpgradeable {\n    /// CUSTOM ERRORS ///\n\n    /// @notice Emitted when the bond matured.\n    error BalanceSheet__BondMatured(IHToken bond);\n\n    /// @notice Emitted when the account exceeds the maximum numbers of bonds permitted.\n    error BalanceSheet__BorrowMaxBonds(IHToken bond, uint256 newBondListLength, uint256 maxBonds);\n\n    /// @notice Emitted when the account exceeds the maximum numbers of collateral permitted.\n    error BalanceSheet__DepositMaxCollaterals(\n        IErc20 collateral,\n        uint256 newCollateralListLength,\n        uint256 maxCollaterals\n    );\n\n    /// @notice Emitted when borrows are not allowed by the Fintroller contract.\n    error BalanceSheet__BorrowNotAllowed(IHToken bond);\n\n    /// @notice Emitted when borrowing a zero amount of hTokens.\n    error BalanceSheet__BorrowZero();\n\n    /// @notice Emitted when the new collateral amount exceeds the collateral ceiling.\n    error BalanceSheet__CollateralCeilingOverflow(uint256 newTotalSupply, uint256 debtCeiling);\n\n    /// @notice Emitted when the new total amount of debt exceeds the debt ceiling.\n    error BalanceSheet__DebtCeilingOverflow(uint256 newCollateralAmount, uint256 debtCeiling);\n\n    /// @notice Emitted when collateral deposits are not allowed by the Fintroller contract.\n    error BalanceSheet__DepositCollateralNotAllowed(IErc20 collateral);\n\n    /// @notice Emitted when depositing a zero amount of collateral.\n    error BalanceSheet__DepositCollateralZero();\n\n    /// @notice Emitted when setting the Fintroller contract to the zero address.\n    error BalanceSheet__FintrollerZeroAddress();\n\n    /// @notice Emitted when there is not enough collateral to seize.\n    error BalanceSheet__LiquidateBorrowInsufficientCollateral(\n        address account,\n        uint256 vaultCollateralAmount,\n        uint256 seizableAmount\n    );\n\n    /// @notice Emitted when borrow liquidations are not allowed by the Fintroller contract.\n    error BalanceSheet__LiquidateBorrowNotAllowed(IHToken bond);\n\n    /// @notice Emitted when the borrower is liquidating themselves.\n    error BalanceSheet__LiquidateBorrowSelf(address account);\n\n    /// @notice Emitted when there is a liquidity shortfall.\n    error BalanceSheet__LiquidityShortfall(address account, uint256 shortfallLiquidity);\n\n    /// @notice Emitted when there is no liquidity shortfall.\n    error BalanceSheet__NoLiquidityShortfall(address account);\n\n    /// @notice Emitted when setting the oracle contract to the zero address.\n    error BalanceSheet__OracleZeroAddress();\n\n    /// @notice Emitted when the repayer does not have enough hTokens to repay the debt.\n    error BalanceSheet__RepayBorrowInsufficientBalance(IHToken bond, uint256 repayAmount, uint256 hTokenBalance);\n\n    /// @notice Emitted when repaying more debt than the borrower owes.\n    error BalanceSheet__RepayBorrowInsufficientDebt(IHToken bond, uint256 repayAmount, uint256 debtAmount);\n\n    /// @notice Emitted when borrow repays are not allowed by the Fintroller contract.\n    error BalanceSheet__RepayBorrowNotAllowed(IHToken bond);\n\n    /// @notice Emitted when repaying a borrow with a zero amount of hTokens.\n    error BalanceSheet__RepayBorrowZero();\n\n    /// @notice Emitted when withdrawing more collateral than there is in the vault.\n    error BalanceSheet__WithdrawCollateralUnderflow(\n        address account,\n        uint256 vaultCollateralAmount,\n        uint256 withdrawAmount\n    );\n\n    /// @notice Emitted when withdrawing a zero amount of collateral.\n    error BalanceSheet__WithdrawCollateralZero();\n\n    /// EVENTS ///\n\n    /// @notice Emitted when a borrow is made.\n    /// @param account The address of the borrower.\n    /// @param bond The address of the bond contract.\n    /// @param borrowAmount The amount of hTokens borrowed.\n    event Borrow(address indexed account, IHToken indexed bond, uint256 borrowAmount);\n\n    /// @notice Emitted when collateral is deposited.\n    /// @param account The address of the borrower.\n    /// @param collateral The related collateral.\n    /// @param collateralAmount The amount of deposited collateral.\n    event DepositCollateral(address indexed account, IErc20 indexed collateral, uint256 collateralAmount);\n\n    /// @notice Emitted when a borrow is liquidated.\n    /// @param liquidator The address of the liquidator.\n    /// @param borrower The address of the borrower.\n    /// @param bond The address of the bond contract.\n    /// @param repayAmount The amount of repaid funds.\n    /// @param collateral The address of the collateral contract.\n    /// @param seizedCollateralAmount The amount of seized collateral.\n    event LiquidateBorrow(\n        address indexed liquidator,\n        address indexed borrower,\n        IHToken indexed bond,\n        uint256 repayAmount,\n        IErc20 collateral,\n        uint256 seizedCollateralAmount\n    );\n\n    /// @notice Emitted when a borrow is repaid.\n    /// @param payer The address of the payer.\n    /// @param borrower The address of the borrower.\n    /// @param bond The address of the bond contract.\n    /// @param repayAmount The amount of repaid funds.\n    /// @param newDebtAmount The amount of the new debt.\n    event RepayBorrow(\n        address indexed payer,\n        address indexed borrower,\n        IHToken indexed bond,\n        uint256 repayAmount,\n        uint256 newDebtAmount\n    );\n\n    /// @notice Emitted when a new Fintroller contract is set.\n    /// @param owner The address of the owner.\n    /// @param oldFintroller The address of the old Fintroller contract.\n    /// @param newFintroller The address of the new Fintroller contract.\n    event SetFintroller(address indexed owner, address oldFintroller, address newFintroller);\n\n    /// @notice Emitted when a new oracle contract is set.\n    /// @param owner The address of the owner.\n    /// @param oldOracle The address of the old oracle contract.\n    /// @param newOracle The address of the new oracle contract.\n    event SetOracle(address indexed owner, address oldOracle, address newOracle);\n\n    /// @notice Emitted when collateral is withdrawn.\n    /// @param account The address of the borrower.\n    /// @param collateral The related collateral.\n    /// @param collateralAmount The amount of withdrawn collateral.\n    event WithdrawCollateral(address indexed account, IErc20 indexed collateral, uint256 collateralAmount);\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice Returns the list of bond markets the given account entered.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param account The borrower account to make the query against.\n    function getBondList(address account) external view returns (IHToken[] memory);\n\n    /// @notice Returns the amount of collateral deposited by the given account for the given collateral type.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param account The borrower account to make the query against.\n    /// @param collateral The collateral to make the query against.\n    function getCollateralAmount(address account, IErc20 collateral) external view returns (uint256 collateralAmount);\n\n    /// @notice Returns the list of collaterals the given account deposited.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param account The borrower account to make the query against.\n    function getCollateralList(address account) external view returns (IErc20[] memory);\n\n    /// @notice Calculates the current account liquidity.\n    /// @param account The account to make the query against.\n    /// @return excessLiquidity account liquidity in excess of collateral requirements.\n    /// @return shortfallLiquidity account shortfall below collateral requirements\n    function getCurrentAccountLiquidity(address account)\n        external\n        view\n        returns (uint256 excessLiquidity, uint256 shortfallLiquidity);\n\n    /// @notice Returns the amount of debt accrued by the given account in the given bond market.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param account The borrower account to make the query against.\n    /// @param bond The bond to make the query against.\n    function getDebtAmount(address account, IHToken bond) external view returns (uint256 debtAmount);\n\n    /// @notice Calculates the account liquidity given a modified collateral, collateral amount, bond and debt amount,\n    /// using the current prices provided by the oracle.\n    ///\n    /// @dev Works by summing up each collateral amount multiplied by the USD value of each unit and divided by its\n    /// respective collateral ratio, then dividing the sum by the total amount of debt drawn by the user.\n    ///\n    /// Caveats:\n    /// - This function expects that the \"collateralList\" and the \"bondList\" are each modified in advance to include\n    /// the collateral and bond due to be modified.\n    ///\n    /// @param account The account to make the query against.\n    /// @param collateralModify The collateral to make the check against.\n    /// @param collateralAmountModify The hypothetical normalized amount of collateral.\n    /// @param bondModify The bond to make the check against.\n    /// @param debtAmountModify The hypothetical amount of debt.\n    /// @return excessLiquidity hypothetical account liquidity in excess of collateral requirements.\n    /// @return shortfallLiquidity hypothetical account shortfall below collateral requirements\n    function getHypotheticalAccountLiquidity(\n        address account,\n        IErc20 collateralModify,\n        uint256 collateralAmountModify,\n        IHToken bondModify,\n        uint256 debtAmountModify\n    ) external view returns (uint256 excessLiquidity, uint256 shortfallLiquidity);\n\n    /// @notice Calculates the amount of hTokens that should be repaid in order to seize a given amount of collateral.\n    /// Note that this is for informational purposes only, it doesn't say anything about whether the user can be\n    /// liquidated.\n    /// @dev The formula used is:\n    /// repayAmount = (seizableCollateralAmount * collateralPriceUsd) / (liquidationIncentive * underlyingPriceUsd)\n    /// @param collateral The collateral to make the query against.\n    /// @param seizableCollateralAmount The amount of collateral to seize.\n    /// @param bond The bond to make the query against.\n    /// @return repayAmount The amount of hTokens that should be repaid.\n    function getRepayAmount(\n        IErc20 collateral,\n        uint256 seizableCollateralAmount,\n        IHToken bond\n    ) external view returns (uint256 repayAmount);\n\n    /// @notice Calculates the amount of collateral that can be seized when liquidating a borrow. Note that this\n    /// is for informational purposes only, it doesn't say anything about whether the user can be liquidated.\n    /// @dev The formula used is:\n    /// seizableCollateralAmount = repayAmount * liquidationIncentive * underlyingPriceUsd / collateralPriceUsd\n    /// @param bond The bond to make the query against.\n    /// @param repayAmount The amount of hTokens to repay.\n    /// @param collateral The collateral to make the query against.\n    /// @return seizableCollateralAmount The amount of seizable collateral.\n    function getSeizableCollateralAmount(\n        IHToken bond,\n        uint256 repayAmount,\n        IErc20 collateral\n    ) external view returns (uint256 seizableCollateralAmount);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Increases the debt of the caller and mints new hTokens.\n    ///\n    /// @dev Emits a {Borrow} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The Fintroller must allow this action to be performed.\n    /// - The maturity of the bond must be in the future.\n    /// - The amount to borrow cannot be zero.\n    /// - The new length of the bond list must be below the max bonds limit.\n    /// - The new total amount of debt cannot exceed the debt ceiling.\n    /// - The caller must not end up having a shortfall of liquidity.\n    ///\n    /// @param bond The address of the bond contract.\n    /// @param borrowAmount The amount of hTokens to borrow and print into existence.\n    function borrow(IHToken bond, uint256 borrowAmount) external;\n\n    /// @notice Deposits collateral in the caller's account.\n    ///\n    /// @dev Emits a {DepositCollateral} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The Fintroller must allow this action to be performed.\n    /// - The amount to deposit cannot be zero.\n    /// - The caller must have allowed this contract to spend `collateralAmount` tokens.\n    /// - The new collateral amount cannot exceed the collateral ceiling.\n    ///\n    /// @param collateral The address of the collateral contract.\n    /// @param depositAmount The amount of collateral to deposit.\n    function depositCollateral(IErc20 collateral, uint256 depositAmount) external;\n\n    /// @notice Repays the debt of the borrower and rewards the caller with a surplus of collateral.\n    ///\n    /// @dev Emits a {LiquidateBorrow} event.\n    ///\n    /// Requirements:\n    ///\n    /// - All from \"repayBorrow\".\n    /// - The caller cannot be the same with the borrower.\n    /// - The Fintroller must allow this action to be performed.\n    /// - The borrower must have a shortfall of liquidity if the bond didn't mature.\n    /// - The amount of seized collateral cannot be more than what the borrower has in the vault.\n    ///\n    /// @param bond The address of the bond contract.\n    /// @param borrower The account to liquidate.\n    /// @param repayAmount The amount of hTokens to repay.\n    /// @param collateral The address of the collateral contract.\n    function liquidateBorrow(\n        address borrower,\n        IHToken bond,\n        uint256 repayAmount,\n        IErc20 collateral\n    ) external;\n\n    /// @notice Erases the borrower's debt and takes the hTokens out of circulation.\n    ///\n    /// @dev Emits a {RepayBorrow} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The amount to repay cannot be zero.\n    /// - The Fintroller must allow this action to be performed.\n    /// - The caller must have at least `repayAmount` hTokens.\n    /// - The caller must have at least `repayAmount` debt.\n    ///\n    /// @param bond The address of the bond contract.\n    /// @param repayAmount The amount of hTokens to repay.\n    function repayBorrow(IHToken bond, uint256 repayAmount) external;\n\n    /// @notice Erases the borrower's debt and takes the hTokens out of circulation.\n    ///\n    /// @dev Emits a {RepayBorrow} event.\n    ///\n    /// Requirements:\n    /// - Same as the `repayBorrow` function, but here `borrower` is the account that must have at least\n    /// `repayAmount` hTokens to repay the borrow.\n    ///\n    /// @param borrower The borrower account for which to repay the borrow.\n    /// @param bond The address of the bond contract\n    /// @param repayAmount The amount of hTokens to repay.\n    function repayBorrowBehalf(\n        address borrower,\n        IHToken bond,\n        uint256 repayAmount\n    ) external;\n\n    /// @notice Updates the Fintroller contract this BalanceSheet is connected to.\n    ///\n    /// @dev Emits a {SetFintroller} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The new address cannot be the zero address.\n    ///\n    /// @param newFintroller The new Fintroller contract.\n    function setFintroller(IFintroller newFintroller) external;\n\n    /// @notice Updates the oracle contract.\n    ///\n    /// @dev Emits a {SetOracle} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The new address cannot be the zero address.\n    ///\n    /// @param newOracle The new oracle contract.\n    function setOracle(IChainlinkOperator newOracle) external;\n\n    /// @notice Withdraws a portion or all of the collateral.\n    ///\n    /// @dev Emits a {WithdrawCollateral} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The amount to withdraw cannot be zero.\n    /// - There must be enough collateral in the vault.\n    /// - The caller's account cannot fall below the collateral ratio.\n    ///\n    /// @param collateral The address of the collateral contract.\n    /// @param withdrawAmount The amount of collateral to withdraw.\n    function withdrawCollateral(IErc20 collateral, uint256 withdrawAmount) external;\n}\n"
    },
    "contracts/core/fintroller/IFintroller.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.4;\n\nimport \"@prb/contracts/token/erc20/IErc20.sol\";\nimport \"@prb/contracts/access/IOwnable.sol\";\n\nimport \"../h-token/IHToken.sol\";\n\n/// @notice IFintroller\n/// @author Hifi\n/// @notice Controls the financial permissions and risk parameters for the Hifi protocol.\ninterface IFintroller is IOwnable {\n    /// CUSTOM ERRORS ///\n\n    /// @notice Emitted when interacting with a bond that is not listed.\n    error Fintroller__BondNotListed(IHToken bond);\n\n    /// @notice Emitted when allowing borrow for a bond when liquidate borrow is disallowed.\n    error Fintroller__BondBorrowAllowedWithLiquidateBorrowDisallowed();\n\n    /// @notice Emitted when allowing liquidate borrow for a bond when repay borrow is disallowed.\n    error Fintroller__BondLiquidateBorrowAllowedWithRepayBorrowDisallowed();\n\n    /// @notice Emitted when disallowing liquidate borrow for a bond when borrow is allowed.\n    error Fintroller__BondLiquidateBorrowDisallowedWithBorrowAllowed();\n\n    /// @notice Emitted when disallowing repay borrow for a bond when liquidate borrow is allowed.\n    error Fintroller__BondRepayBorrowDisallowedWithLiquidateBorrowAllowed();\n\n    /// @notice Emitted when listing a collateral that has more than 18 decimals.\n    error Fintroller__CollateralDecimalsOverflow(uint256 decimals);\n\n    /// @notice Emitted when listing a collateral that has zero decimals.\n    error Fintroller__CollateralDecimalsZero();\n\n    /// @notice Emitted when interacting with a collateral that is not listed.\n    error Fintroller__CollateralNotListed(IErc20 collateral);\n\n    /// @notice Emitted when setting a new collateral ratio that is below the liquidation incentive\n    error Fintroller__CollateralRatioBelowLiquidationIncentive(uint256 newCollateralRatio);\n\n    /// @notice Emitted when setting a new collateral ratio that is above the upper bound.\n    error Fintroller__CollateralRatioOverflow(uint256 newCollateralRatio);\n\n    /// @notice Emitted when setting a new collateral ratio that is below the lower bound.\n    error Fintroller__CollateralRatioUnderflow(uint256 newCollateralRatio);\n\n    /// @notice Emitted when setting a new debt ceiling that is below the total supply of hTokens.\n    error Fintroller__DebtCeilingUnderflow(uint256 newDebtCeiling, uint256 totalSupply);\n\n    /// @notice Emitted when setting a new liquidation incentive that is higher than the collateral ratio.\n    error Fintroller__LiquidationIncentiveAboveCollateralRatio(uint256 newLiquidationIncentive);\n\n    /// @notice Emitted when setting a new liquidation incentive that is above the upper bound.\n    error Fintroller__LiquidationIncentiveOverflow(uint256 newLiquidationIncentive);\n\n    /// @notice Emitted when setting a new liquidation incentive that is below the lower bound.\n    error Fintroller__LiquidationIncentiveUnderflow(uint256 newLiquidationIncentive);\n\n    /// EVENTS ///\n\n    /// @notice Emitted when a new bond is listed.\n    /// @param owner The address of the contract owner.\n    /// @param bond The newly listed bond.\n    event ListBond(address indexed owner, IHToken indexed bond);\n\n    /// @notice Emitted when a new collateral is listed.\n    /// @param owner The address of the contract owner.\n    /// @param collateral The newly listed collateral.\n    event ListCollateral(address indexed owner, IErc20 indexed collateral);\n\n    /// @notice Emitted when the borrow permission is updated.\n    /// @param owner The address of the contract owner.\n    /// @param bond The related HToken.\n    /// @param state True if borrowing is allowed.\n    event SetBorrowAllowed(address indexed owner, IHToken indexed bond, bool state);\n\n    /// @notice Emitted when the collateral ceiling is updated.\n    /// @param owner The address of the contract owner.\n    /// @param collateral The related collateral.\n    /// @param oldCollateralCeiling The old collateral ceiling.\n    /// @param newCollateralCeiling The new collateral ceiling.\n    event SetCollateralCeiling(\n        address indexed owner,\n        IErc20 indexed collateral,\n        uint256 oldCollateralCeiling,\n        uint256 newCollateralCeiling\n    );\n\n    /// @notice Emitted when the collateral ratio is updated.\n    /// @param owner The address of the contract owner.\n    /// @param collateral The related HToken.\n    /// @param oldCollateralRatio The old collateral ratio.\n    /// @param newCollateralRatio the new collateral ratio.\n    event SetCollateralRatio(\n        address indexed owner,\n        IErc20 indexed collateral,\n        uint256 oldCollateralRatio,\n        uint256 newCollateralRatio\n    );\n\n    /// @notice Emitted when the debt ceiling for a bond is updated.\n    /// @param owner The address of the contract owner.\n    /// @param bond The related HToken.\n    /// @param oldDebtCeiling The old debt ceiling.\n    /// @param newDebtCeiling The new debt ceiling.\n    event SetDebtCeiling(address indexed owner, IHToken indexed bond, uint256 oldDebtCeiling, uint256 newDebtCeiling);\n\n    /// @notice Emitted when the deposit collateral permission is updated.\n    /// @param owner The address of the contract owner.\n    /// @param state True if depositing collateral is allowed.\n    event SetDepositCollateralAllowed(address indexed owner, IErc20 indexed collateral, bool state);\n\n    /// @notice Emitted when the deposit underlying permission is set.\n    /// @param owner The address of the contract owner.\n    /// @param bond The related HToken.\n    /// @param state True if deposit underlying is allowed.\n    event SetDepositUnderlyingAllowed(address indexed owner, IHToken indexed bond, bool state);\n\n    /// @notice Emitted when the liquidate borrow permission is updated.\n    /// @param owner The address of the contract owner.\n    /// @param bond The related HToken.\n    /// @param state True if liquidating borrow is allowed.\n    event SetLiquidateBorrowAllowed(address indexed owner, IHToken indexed bond, bool state);\n\n    /// @notice Emitted when the collateral liquidation incentive is set.\n    /// @param owner The address of the contract owner.\n    /// @param collateral The related collateral.\n    /// @param oldLiquidationIncentive The old liquidation incentive.\n    /// @param newLiquidationIncentive The new liquidation incentive.\n    event SetLiquidationIncentive(\n        address indexed owner,\n        IErc20 collateral,\n        uint256 oldLiquidationIncentive,\n        uint256 newLiquidationIncentive\n    );\n\n    /// @notice Emitted when a new max bonds value is set.\n    /// @param owner The address indexed owner.\n    /// @param oldMaxBonds The address of the old max bonds value.\n    /// @param newMaxBonds The address of the new max bonds value.\n    event SetMaxBonds(address indexed owner, uint256 oldMaxBonds, uint256 newMaxBonds);\n\n    /// @notice Emitted when a new max collaterals value is set.\n    /// @param owner The address indexed owner.\n    /// @param oldMaxCollaterals The address of the old max collaterals value.\n    /// @param newMaxCollaterals The address of the new max collaterals value.\n    event SetMaxCollaterals(address indexed owner, uint256 oldMaxCollaterals, uint256 newMaxCollaterals);\n\n    /// @notice Emitted when the repay borrow permission is updated.\n    /// @param owner The address of the contract owner.\n    /// @param bond The related HToken.\n    /// @param state True if repaying borrow is allowed.\n    event SetRepayBorrowAllowed(address indexed owner, IHToken indexed bond, bool state);\n\n    /// STRUCTS ///\n\n    struct Bond {\n        uint256 debtCeiling;\n        bool isBorrowAllowed;\n        bool isDepositUnderlyingAllowed;\n        bool isLiquidateBorrowAllowed;\n        bool isListed;\n        bool isRepayBorrowAllowed;\n    }\n\n    struct Collateral {\n        uint256 ceiling;\n        uint256 ratio;\n        uint256 liquidationIncentive;\n        bool isDepositCollateralAllowed;\n        bool isListed;\n    }\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice Returns the Bond struct instance associated to the given address.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param bond The address of the bond contract.\n    /// @return The bond object.\n    function getBond(IHToken bond) external view returns (Bond memory);\n\n    /// @notice Checks if the account should be allowed to borrow hTokens.\n    /// @dev The bond must be listed.\n    /// @param bond The bond to make the check against.\n    /// @return bool true = allowed, false = not allowed.\n    function getBorrowAllowed(IHToken bond) external view returns (bool);\n\n    /// @notice Returns the Collateral struct instance associated to the given address.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param collateral The address of the collateral contract.\n    /// @return The collateral object.\n    function getCollateral(IErc20 collateral) external view returns (Collateral memory);\n\n    /// @notice Returns the collateral ceiling.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param collateral The address of the collateral contract.\n    /// @return The collateral ceiling as a uint256, or zero if an invalid address was provided.\n    function getCollateralCeiling(IErc20 collateral) external view returns (uint256);\n\n    /// @notice Returns the collateral ratio.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param collateral The address of the collateral contract.\n    /// @return The collateral ratio, or zero if an invalid address was provided.\n    function getCollateralRatio(IErc20 collateral) external view returns (uint256);\n\n    /// @notice Returns the debt ceiling for the given bond.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param bond The address of the bond contract.\n    /// @return The debt ceiling as a uint256, or zero if an invalid address was provided.\n    function getDebtCeiling(IHToken bond) external view returns (uint256);\n\n    /// @notice Checks if collateral deposits are allowed.\n    /// @dev The collateral must be listed.\n    /// @param collateral The collateral to make the check against.\n    /// @return bool true = allowed, false = not allowed.\n    function getDepositCollateralAllowed(IErc20 collateral) external view returns (bool);\n\n    /// @notice Checks if underlying deposits are allowed.\n    /// @dev The bond must be listed.\n    /// @param bond The bond to make the check against.\n    /// @return bool true = allowed, false = not allowed.\n    function getDepositUnderlyingAllowed(IHToken bond) external view returns (bool);\n\n    /// @notice Returns the liquidation incentive of the given collateral.\n    /// @dev It is not an error to provide an invalid address.\n    /// @param collateral The address of the collateral contract.\n    /// @return The liquidation incentive, or zero if an invalid address was provided.\n    function getLiquidationIncentive(IErc20 collateral) external view returns (uint256);\n\n    /// @notice Checks if the account should be allowed to liquidate hToken borrows.\n    /// @dev The bond must be listed.\n    /// @param bond The bond to make the check against.\n    /// @return bool true = allowed, false = not allowed.\n    function getLiquidateBorrowAllowed(IHToken bond) external view returns (bool);\n\n    /// @notice Checks if the account should be allowed to repay borrows.\n    /// @dev The bond must be listed.\n    /// @param bond The bond to make the check against.\n    /// @return bool true = allowed, false = not allowed.\n    function getRepayBorrowAllowed(IHToken bond) external view returns (bool);\n\n    /// @notice Checks if the bond is listed.\n    /// @param bond The bond to make the check against.\n    /// @return bool true = listed, otherwise not.\n    function isBondListed(IHToken bond) external view returns (bool);\n\n    /// @notice Checks if the collateral is listed.\n    /// @param collateral The collateral to make the check against.\n    /// @return bool true = listed, otherwise not.\n    function isCollateralListed(IErc20 collateral) external view returns (bool);\n\n    /// @notice Returns the maximum number of bond markets a single account can enter.\n    function maxBonds() external view returns (uint256);\n\n    /// @notice Returns the maximum number of Collaterals a single account can deposit.\n    function maxCollaterals() external view returns (uint256);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Marks the bond as listed in this registry.\n    ///\n    /// @dev It is not an error to list a bond twice. Emits a {ListBond} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param bond The hToken contract to list.\n    function listBond(IHToken bond) external;\n\n    /// @notice Marks the collateral as listed in this registry.\n    ///\n    /// @dev Emits a {ListCollateral} event. It is not an error to list a bond twice.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The collateral must have between 1 and 18 decimals.\n    ///\n    /// @param collateral The collateral contract to list.\n    function listCollateral(IErc20 collateral) external;\n\n    /// @notice Updates the state of the permission accessed by the hToken before a borrow.\n    ///\n    /// @dev Emits a {SetBorrowAllowed} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The bond must be listed.\n    ///\n    /// @param bond The bond to update the permission for.\n    /// @param state The new state to put in storage.\n    function setBorrowAllowed(IHToken bond, bool state) external;\n\n    /// @notice Updates the collateral ceiling.\n    ///\n    /// @dev Emits a {SetCollateralCeiling} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The collateral must be listed.\n    ///\n    /// @param collateral The collateral to update the ceiling for.\n    /// @param newCollateralCeiling The new collateral ceiling.\n    function setCollateralCeiling(IHToken collateral, uint256 newCollateralCeiling) external;\n\n    /// @notice Updates the collateral ratio.\n    ///\n    /// @dev Emits a {SetCollateralRatio} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The collateral must be listed.\n    /// - The new collateral ratio cannot be higher than the maximum collateral ratio.\n    /// - The new collateral ratio cannot be lower than the minimum collateral ratio.\n    ///\n    /// @param collateral The collateral to update the collateral ratio for.\n    /// @param newCollateralRatio The new collateral ratio.\n    function setCollateralRatio(IErc20 collateral, uint256 newCollateralRatio) external;\n\n    /// @notice Updates the debt ceiling for the given bond.\n    ///\n    /// @dev Emits a {SetDebtCeiling} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The bond must be listed.\n    /// - The debt ceiling cannot fall below the current total supply of hTokens.\n    ///\n    /// @param bond The bond to update the debt ceiling for.\n    /// @param newDebtCeiling The new debt ceiling.\n    function setDebtCeiling(IHToken bond, uint256 newDebtCeiling) external;\n\n    /// @notice Updates the state of the permission accessed by the BalanceSheet before a collateral deposit.\n    ///\n    /// @dev Emits a {SetDepositCollateralAllowed} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param collateral The collateral to update the permission for.\n    /// @param state The new state to put in storage.\n    function setDepositCollateralAllowed(IErc20 collateral, bool state) external;\n\n    /// @notice Updates the state of the permission accessed by the hToken before an underlying deposit.\n    ///\n    /// @dev Emits a {SetDepositUnderlyingAllowed} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param bond The bond to update the permission for.\n    /// @param state The new state to put in storage.\n    function setDepositUnderlyingAllowed(IHToken bond, bool state) external;\n\n    /// @notice Updates the collateral liquidation incentive.\n    ///\n    /// @dev Emits a {SetLiquidationIncentive} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The collateral must be listed.\n    /// - The new liquidation incentive cannot be higher than the maximum liquidation incentive.\n    /// - The new liquidation incentive cannot be lower than the minimum liquidation incentive.\n    ///\n    /// @param collateral The collateral to update the liquidation incentive for.\n    /// @param newLiquidationIncentive The new liquidation incentive.\n    function setLiquidationIncentive(IErc20 collateral, uint256 newLiquidationIncentive) external;\n\n    /// @notice Updates the state of the permission accessed by the hToken before a liquidate borrow.\n    ///\n    /// @dev Emits a {SetLiquidateBorrowAllowed} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The bond must be listed.\n    ///\n    /// @param bond The hToken contract to update the permission for.\n    /// @param state The new state to put in storage.\n    function setLiquidateBorrowAllowed(IHToken bond, bool state) external;\n\n    /// @notice Sets max bonds value, which controls how many bond markets a single account can enter.\n    ///\n    /// @dev Emits a {SetMaxBonds} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param newMaxBonds New max bonds value.\n    function setMaxBonds(uint256 newMaxBonds) external;\n\n    /// @notice Sets max collaterals value, which controls how many collaterals a single account can deposit.\n    ///\n    /// @dev Emits a {SetMaxCollaterals} event.\n    ///\n    /// Requirements:\n    /// - The caller must be the owner.\n    ///\n    /// @param newMaxCollaterals New max collaterals value.\n    function setMaxCollaterals(uint256 newMaxCollaterals) external;\n\n    /// @notice Updates the state of the permission accessed by the hToken before a repay borrow.\n    ///\n    /// @dev Emits a {SetRepayBorrowAllowed} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The bond must be listed.\n    ///\n    /// @param bond The hToken contract to update the permission for.\n    /// @param state The new state to put in storage.\n    function setRepayBorrowAllowed(IHToken bond, bool state) external;\n}\n"
    },
    "@prb/contracts/access/IOwnable.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\n/// @title IOwnable\n/// @author Paul Razvan Berg\n/// @notice Contract module that provides a basic access control mechanism, where there is an\n/// account (an owner) that can be granted exclusive access to specific functions.\n///\n/// By default, the owner account will be the one that deploys the contract. This can later be\n/// changed with {transfer}.\n///\n/// This module is used through inheritance. It will make available the modifier `onlyOwner`,\n/// which can be applied to your functions to restrict their use to the owner.\n///\n/// @dev Forked from OpenZeppelin\n/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/access/Ownable.sol\ninterface IOwnable {\n    /// EVENTS ///\n\n    /// @notice Emitted when ownership is transferred.\n    /// @param oldOwner The address of the old owner.\n    /// @param newOwner The address of the new owner.\n    event TransferOwnership(address indexed oldOwner, address indexed newOwner);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Leaves the contract without owner, so it will not be possible to call `onlyOwner`\n    /// functions anymore.\n    ///\n    /// WARNING: Doing this will leave the contract without an owner, thereby removing any\n    /// functionality that is only available to the owner.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    function _renounceOwnership() external;\n\n    /// @notice Transfers the owner of the contract to a new account (`newOwner`). Can only be\n    /// called by the current owner.\n    /// @param newOwner The account of the new owner.\n    function _transferOwnership(address newOwner) external;\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice The address of the owner account or contract.\n    /// @return The address of the owner.\n    function owner() external view returns (address);\n}\n"
    },
    "@prb/contracts/token/erc20/IErc20.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\n/// @title IErc20\n/// @author Paul Razvan Berg\n/// @notice Implementation for the Erc20 standard.\n///\n/// We have followed general OpenZeppelin guidelines: functions revert instead of returning\n/// `false` on failure. This behavior is nonetheless conventional and does not conflict with\n/// the with the expectations of Erc20 applications.\n///\n/// Additionally, an {Approval} event is emitted on calls to {transferFrom}. This allows\n/// applications to reconstruct the allowance for all accounts just by listening to said\n/// events. Other implementations of the Erc may not emit these events, as it isn't\n/// required by the specification.\n///\n/// Finally, the non-standard {decreaseAllowance} and {increaseAllowance} functions have been\n/// added to mitigate the well-known issues around setting allowances.\n///\n/// @dev Forked from OpenZeppelin\n/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.0/contracts/token/ERC20/ERC20.sol\ninterface IErc20 {\n    /// EVENTS ///\n\n    /// @notice Emitted when an approval happens.\n    /// @param owner The address of the owner of the tokens.\n    /// @param spender The address of the spender.\n    /// @param amount The maximum amount that can be spent.\n    event Approval(address indexed owner, address indexed spender, uint256 amount);\n\n    /// @notice Emitted when a transfer happens.\n    /// @param from The account sending the tokens.\n    /// @param to The account receiving the tokens.\n    /// @param amount The amount of tokens transferred.\n    event Transfer(address indexed from, address indexed to, uint256 amount);\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice Returns the remaining number of tokens that `spender` will be allowed to spend\n    /// on behalf of `owner` through {transferFrom}. This is zero by default.\n    ///\n    /// @dev This value changes when {approve} or {transferFrom} are called.\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /// @notice Returns the amount of tokens owned by `account`.\n    function balanceOf(address account) external view returns (uint256);\n\n    /// @notice Returns the number of decimals used to get its user representation.\n    function decimals() external view returns (uint8);\n\n    /// @notice Returns the name of the token.\n    function name() external view returns (string memory);\n\n    /// @notice Returns the symbol of the token, usually a shorter version of the name.\n    function symbol() external view returns (string memory);\n\n    /// @notice Returns the amount of tokens in existence.\n    function totalSupply() external view returns (uint256);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.\n    ///\n    /// @dev Emits an {Approval} event.\n    ///\n    /// IMPORTANT: Beware that changing an allowance with this method brings the risk that someone may\n    /// use both the old and the new allowance by unfortunate transaction ordering. One possible solution\n    /// to mitigate this race condition is to first reduce the spender's allowance to 0 and set the desired\n    /// value afterwards: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n    ///\n    /// Requirements:\n    ///\n    /// - `spender` cannot be the zero address.\n    ///\n    /// @return a boolean value indicating whether the operation succeeded.\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /// @notice Atomically decreases the allowance granted to `spender` by the caller.\n    ///\n    /// @dev Emits an {Approval} event indicating the updated allowance.\n    ///\n    /// This is an alternative to {approve} that can be used as a mitigation for problems described\n    /// in {Erc20Interface-approve}.\n    ///\n    /// Requirements:\n    ///\n    /// - `spender` cannot be the zero address.\n    /// - `spender` must have allowance for the caller of at least `subtractedAmount`.\n    function decreaseAllowance(address spender, uint256 subtractedAmount) external returns (bool);\n\n    /// @notice Atomically increases the allowance granted to `spender` by the caller.\n    ///\n    /// @dev Emits an {Approval} event indicating the updated allowance.\n    ///\n    /// This is an alternative to {approve} that can be used as a mitigation for the problems described above.\n    ///\n    /// Requirements:\n    ///\n    /// - `spender` cannot be the zero address.\n    function increaseAllowance(address spender, uint256 addedAmount) external returns (bool);\n\n    /// @notice Moves `amount` tokens from the caller's account to `recipient`.\n    ///\n    /// @dev Emits a {Transfer} event.\n    ///\n    /// Requirements:\n    ///\n    /// - `recipient` cannot be the zero address.\n    /// - The caller must have a balance of at least `amount`.\n    ///\n    /// @return a boolean value indicating whether the operation succeeded.\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /// @notice Moves `amount` tokens from `sender` to `recipient` using the allowance mechanism. `amount`\n    /// `is then deducted from the caller's allowance.\n    ///\n    /// @dev Emits a {Transfer} event and an {Approval} event indicating the updated allowance. This is\n    /// not required by the Erc. See the note at the beginning of {Erc20}.\n    ///\n    /// Requirements:\n    ///\n    /// - `sender` and `recipient` cannot be the zero address.\n    /// - `sender` must have a balance of at least `amount`.\n    /// - The caller must have approed `sender` to spent at least `amount` tokens.\n    ///\n    /// @return a boolean value indicating whether the operation succeeded.\n    function transferFrom(\n        address sender,\n        address recipient,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@prb/contracts/token/erc20/IErc20Permit.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\n// solhint-disable func-name-mixedcase\npragma solidity >=0.8.4;\n\nimport \"./IErc20.sol\";\n\n/// @title IErc20Permit\n/// @author Paul Razvan Berg\n/// @notice Extension of Erc20 that allows token holders to use their tokens without sending any\n/// transactions by setting the allowance with a signature using the `permit` method, and then spend\n/// them via `transferFrom`.\n/// @dev See https://eips.ethereum.org/EIPS/eip-2612.\ninterface IErc20Permit is IErc20 {\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Sets `value` as the allowance of `spender` over `owner`'s tokens, assuming the latter's\n    /// signed approval.\n    ///\n    /// @dev Emits an {Approval} event.\n    ///\n    /// IMPORTANT: The same issues Erc20 `approve` has related to transaction\n    /// ordering also apply here.\n    ///\n    /// Requirements:\n    ///\n    /// - `owner` cannot be the zero address.\n    /// - `spender` cannot be the zero address.\n    /// - `deadline` must be a timestamp in the future.\n    /// - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` over the Eip712-formatted\n    /// function arguments.\n    /// - The signature must use `owner`'s current nonce.\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice The Eip712 domain's keccak256 hash.\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n\n    /// @notice Provides replay protection.\n    function nonces(address account) external view returns (uint256);\n\n    /// @notice keccak256(\"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)\");\n    function PERMIT_TYPEHASH() external view returns (bytes32);\n\n    /// @notice Eip712 version of this implementation.\n    function version() external view returns (string memory);\n}\n"
    },
    "@prb/contracts/token/erc20/IErc20Recover.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\n// solhint-disable var-name-mixedcase\npragma solidity >=0.8.4;\n\nimport \"./IErc20.sol\";\nimport \"../../access/IOwnable.sol\";\n\n/// @title IErc20Recover\n/// @author Paul Razvan Berg\n/// @notice Contract that gives the owner the ability to recover the Erc20 tokens that were sent\n/// (accidentally, or not) to the contract.\ninterface IErc20Recover is IOwnable {\n    /// EVENTS ///\n\n    /// @notice Emitted when tokens are recovered.\n    /// @param owner The address of the owner recoverring the tokens.\n    /// @param token The address of the recovered token.\n    /// @param recoverAmount The amount of recovered tokens.\n    event Recover(address indexed owner, IErc20 token, uint256 recoverAmount);\n\n    /// @notice Emitted when tokens are set as non-recoverable.\n    /// @param owner The address of the owner calling the function.\n    /// @param nonRecoverableTokens An array of token addresses.\n    event SetNonRecoverableTokens(address indexed owner, IErc20[] nonRecoverableTokens);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Recover Erc20 tokens sent to this contract (by accident or otherwise).\n    /// @dev Emits a {RecoverToken} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The contract must be initialized.\n    /// - The amount to recover cannot be zero.\n    /// - The token to recover cannot be among the non-recoverable tokens.\n    ///\n    /// @param token The token to make the recover for.\n    /// @param recoverAmount The uint256 amount to recover, specified in the token's decimal system.\n    function _recover(IErc20 token, uint256 recoverAmount) external;\n\n    /// @notice Sets the tokens that this contract cannot recover.\n    ///\n    /// @dev Emits a {SetNonRecoverableTokens} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The contract cannot be already initialized.\n    ///\n    /// @param tokens The array of tokens to set as non-recoverable.\n    function _setNonRecoverableTokens(IErc20[] calldata tokens) external;\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice The tokens that can be recovered cannot be in this mapping.\n    function nonRecoverableTokens(uint256 index) external view returns (IErc20);\n}\n"
    },
    "@prb/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.4;\n\n/// @title Address\n/// @author Paul Razvan Berg\n/// @notice Collection of functions related to the address type.\n/// @dev Forked from OpenZeppelin\n/// https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/v3.4.0/contracts/utils/Address.sol\nlibrary Address {\n    /// @dev Returns true if `account` is a contract.\n    ///\n    /// IMPORTANT: It is unsafe to assume that an address for which this function returns false is an\n    /// externally-owned account (EOA) and not a contract.\n    ///\n    /// Among others, `isContract` will return false for the following types of addresses:\n    ///\n    /// - An externally-owned account\n    /// - A contract in construction\n    /// - An address where a contract will be created\n    /// - An address where a contract lived, but was destroyed\n    function isContract(address account) internal view returns (bool) {\n        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n        // for accounts without code, i.e. `keccak256('')`.\n        bytes32 codehash;\n        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n        // solhint-disable-next-line no-inline-assembly\n        assembly {\n            codehash := extcodehash(account)\n        }\n        return (codehash != accountHash && codehash != 0x0);\n    }\n}\n"
    },
    "contracts/access/IOwnableUpgradeable.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.4;\n\n/// @title IOwnableUpgradeable\n/// @author Hifi\ninterface IOwnableUpgradeable {\n    /// CUSTOM ERRORS ///\n\n    /// @notice Emitted when the caller is not the owner.\n    error OwnableUpgradeable__NotOwner(address owner, address caller);\n\n    /// @notice Emitted when setting the owner to the zero address.\n    error OwnableUpgradeable__OwnerZeroAddress();\n\n    /// EVENTS ///\n\n    /// @notice Emitted when ownership is transferred.\n    /// @param oldOwner The address of the old owner.\n    /// @param newOwner The address of the new owner.\n    event TransferOwnership(address indexed oldOwner, address indexed newOwner);\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice The address of the owner account or contract.\n    /// @return The address of the owner.\n    function owner() external view returns (address);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Leaves the contract without an owner, so it will not be possible to call `onlyOwner`\n    /// functions anymore.\n    ///\n    /// WARNING: Doing this will leave the contract without an owner, thereby removing any\n    /// functionality that is only available to the owner.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    function _renounceOwnership() external;\n\n    /// @notice Transfers the owner of the contract to a new account (`newOwner`). Can only be\n    /// called by the current owner.\n    /// @param newOwner The account of the new owner.\n    function _transferOwnership(address newOwner) external;\n}\n"
    },
    "contracts/oracles/IChainlinkOperator.sol": {
      "content": "// SPDX-License-Identifier: BUSL-1.1\npragma solidity >=0.8.4;\n\nimport \"@prb/contracts/token/erc20/IErc20.sol\";\nimport \"@prb/contracts/access/IOwnable.sol\";\n\nimport \"../external/chainlink/IAggregatorV3.sol\";\n\n/// @title IChainlinkOperator\n/// @author Hifi\n/// @notice Aggregates the price feeds provided by Chainlink.\ninterface IChainlinkOperator {\n    /// CUSTOM ERRORS ///\n\n    /// @notice Emitted when the decimal precision of the feed is not the same as the expected number.\n    error ChainlinkOperator__DecimalsMismatch(string symbol, uint256 decimals);\n\n    /// @notice Emitted when trying to interact with a feed not set yet.\n    error ChainlinkOperator__FeedNotSet(string symbol);\n\n    /// @notice Emitted when the price returned by the oracle is less than or equal to zero.\n    error ChainlinkOperator__PriceLessThanOrEqualToZero(string symbol);\n\n    /// @notice Emitted when the latest price update timestamp returned by the oracle is too old.\n    error ChainlinkOperator__PriceStale(string symbol);\n\n    /// EVENTS ///\n\n    /// @notice Emitted when a feed is deleted.\n    /// @param asset The related asset.\n    /// @param feed The related feed.\n    event DeleteFeed(IErc20 indexed asset, IAggregatorV3 indexed feed);\n\n    /// @notice Emitted when a feed is set.\n    /// @param asset The related asset.\n    /// @param feed The related feed.\n    event SetFeed(IErc20 indexed asset, IAggregatorV3 indexed feed);\n\n    /// @notice Emitted when the Chainlink price staleness threshold is set.\n    /// @param oldPriceStalenessThreshold The old Chainlink price staleness threshold.\n    /// @param newPriceStalenessThreshold The new Chainlink price staleness threshold.\n    event SetPriceStalenessThreshold(uint256 oldPriceStalenessThreshold, uint256 newPriceStalenessThreshold);\n\n    /// STRUCTS ///\n\n    struct Feed {\n        IErc20 asset;\n        IAggregatorV3 id;\n        bool isSet;\n    }\n\n    /// CONSTANT FUNCTIONS ///\n\n    /// @notice Gets the official feed for a symbol.\n    /// @param symbol The symbol to return the feed for.\n    /// @return (address asset, address id, bool isSet).\n    function getFeed(string memory symbol)\n        external\n        view\n        returns (\n            IErc20,\n            IAggregatorV3,\n            bool\n        );\n\n    /// @notice Gets the official price for a symbol and adjusts it have 18 decimals instead of the\n    /// format used by Chainlink, which has 8 decimals.\n    ///\n    /// @dev Requirements:\n    /// - The normalized price cannot overflow.\n    ///\n    /// @param symbol The Erc20 symbol of the token for which to query the price.\n    /// @return The normalized price.\n    function getNormalizedPrice(string memory symbol) external view returns (uint256);\n\n    /// @notice Gets the official price for a symbol in the default format used by Chainlink, which\n    /// has 8 decimals.\n    ///\n    /// @dev Requirements:\n    ///\n    /// - The feed must be set.\n    /// - The price returned by the oracle cannot be zero.\n    ///\n    /// @param symbol The symbol to fetch the price for.\n    /// @return The price denominated in USD, with 8 decimals.\n    function getPrice(string memory symbol) external view returns (uint256);\n\n    /// @notice Chainlink price precision for USD-quoted data.\n    function pricePrecision() external view returns (uint256);\n\n    /// @notice The ratio between normalized precision (1e18) and the Chainlink price precision (1e8).\n    function pricePrecisionScalar() external view returns (uint256);\n\n    /// @notice The Chainlink price staleness threshold.\n    function priceStalenessThreshold() external view returns (uint256);\n\n    /// NON-CONSTANT FUNCTIONS ///\n\n    /// @notice Deletes a previously set Chainlink price feed.\n    ///\n    /// @dev Emits a {DeleteFeed} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The feed must be set already.\n    ///\n    /// @param symbol The Erc20 symbol of the asset to delete the feed for.\n    function deleteFeed(string memory symbol) external;\n\n    /// @notice Sets a Chainlink price feed.\n    ///\n    /// @dev It is not an error to set a feed twice. Emits a {SetFeed} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    /// - The number of decimals of the feed must be 8.\n    ///\n    /// @param asset The address of the Erc20 contract for which to get the price.\n    /// @param feed The address of the Chainlink price feed contract.\n    function setFeed(IErc20 asset, IAggregatorV3 feed) external;\n\n    /// @notice Sets the Chainlink price staleness threshold.\n    ///\n    /// @dev Emits a {SetPriceStalenessThreshold} event.\n    ///\n    /// Requirements:\n    ///\n    /// - The caller must be the owner.\n    ///\n    /// @param newPriceStalenessThreshold The new Chainlink price staleness threshold.\n    function setPriceStalenessThreshold(uint256 newPriceStalenessThreshold) external;\n}\n"
    },
    "contracts/external/chainlink/IAggregatorV3.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.4;\n\n/// @title IAggregatorV3\n/// @author Hifi\n/// @dev Forked from Chainlink\n/// github.com/smartcontractkit/chainlink/blob/v1.2.0/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\ninterface IAggregatorV3 {\n    function decimals() external view returns (uint8);\n\n    function description() external view returns (string memory);\n\n    function version() external view returns (uint256);\n\n    /// getRoundData and latestRoundData should both raise \"No data present\" if they do not have\n    /// data to report, instead of returning unset values which could be misinterpreted as\n    /// actual reported values.\n    function getRoundData(uint80 _roundId)\n        external\n        view\n        returns (\n            uint80 roundId,\n            int256 answer,\n            uint256 startedAt,\n            uint256 updatedAt,\n            uint80 answeredInRound\n        );\n\n    function latestRoundData()\n        external\n        view\n        returns (\n            uint80 roundId,\n            int256 answer,\n            uint256 startedAt,\n            uint256 updatedAt,\n            uint80 answeredInRound\n        );\n}\n"
    }
  },
  "settings": {
    "metadata": {
      "bytecodeHash": "none"
    },
    "optimizer": {
      "enabled": true,
      "runs": 800
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}