Skip to content
Verified contractExactBUSL-1.1

AssetList

Address0x76e8a236c37436c0e04ba67de435a7ecd29cde55
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.15

 

Same code

5 more contracts

 

Details

Compiler
solc 0.8.15+commit.e14f2714
Language
solidity
Optimization
Yes, 1 runs
Via IR
yes
License
BUSL-1.1
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,448,306
Creation transaction
0x76e9de29c5…6ff3df5f98

contracts/AssetList.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import { IPriceFeed } from "./interfaces/IPriceFeed.sol";
import { IERC20NonStandard } from "./interfaces/IERC20NonStandard.sol";
import { IAssetList } from "./interfaces/assetList/IAssetList.sol";
import { ConfigHash, IConfigHash } from "./libraries/ConfigHash.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import { StorageSlot } from "./vendor/utils/StorageSlot.sol";

/**
 * @title Compound's Asset List
 * @author Compound
 */
contract AssetList is IAssetList, IConfigHash, Initializable {
    using EnumerableSet for EnumerableSet.AddressSet;

    /*//////////////////////////////////////////////////////////////
                         CONSTANTS / IMMUTABLES
    //////////////////////////////////////////////////////////////*/

    /// @dev Required by IConfigHash library. Determines the type of the config.
    /// @dev Update if new immutable config types are added.
    bytes32 public constant TYPEHASH =
        keccak256("ImmutableConfig[](address asset,address priceFeed)");

    /// @notice The max number of assets, one per pair of immutables below
    uint8 public constant MAX_ASSETS = 24;

    /// @dev The decimals required for a price feed
    uint8 internal constant PRICE_FEED_DECIMALS = 8;

    /// @dev The ERC-1967 slot where the list proxy keeps its admin
    bytes32 internal constant PROXY_ADMIN_SLOT = bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);

    /// @dev The max asset decimals whose scale (10 to the power of the decimals) fits in uint64
    uint8 internal constant MAX_ASSET_DECIMALS = 19;

    /// @dev The scale for factors, so 1e18 is a factor of 1, the max for any of them
    uint64 internal constant FACTOR_SCALE = 1e18;

    uint256 internal immutable asset00_a;
    address internal immutable priceFeedAddress00;
    uint256 internal immutable asset01_a;
    address internal immutable priceFeedAddress01;
    uint256 internal immutable asset02_a;
    address internal immutable priceFeedAddress02;
    uint256 internal immutable asset03_a;
    address internal immutable priceFeedAddress03;
    uint256 internal immutable asset04_a;
    address internal immutable priceFeedAddress04;
    uint256 internal immutable asset05_a;
    address internal immutable priceFeedAddress05;
    uint256 internal immutable asset06_a;
    address internal immutable priceFeedAddress06;
    uint256 internal immutable asset07_a;
    address internal immutable priceFeedAddress07;
    uint256 internal immutable asset08_a;
    address internal immutable priceFeedAddress08;
    uint256 internal immutable asset09_a;
    address internal immutable priceFeedAddress09;
    uint256 internal immutable asset10_a;
    address internal immutable priceFeedAddress10;
    uint256 internal immutable asset11_a;
    address internal immutable priceFeedAddress11;
    uint256 internal immutable asset12_a;
    address internal immutable priceFeedAddress12;
    uint256 internal immutable asset13_a;
    address internal immutable priceFeedAddress13;
    uint256 internal immutable asset14_a;
    address internal immutable priceFeedAddress14;
    uint256 internal immutable asset15_a;
    address internal immutable priceFeedAddress15;
    uint256 internal immutable asset16_a;
    address internal immutable priceFeedAddress16;
    uint256 internal immutable asset17_a;
    address internal immutable priceFeedAddress17;
    uint256 internal immutable asset18_a;
    address internal immutable priceFeedAddress18;
    uint256 internal immutable asset19_a;
    address internal immutable priceFeedAddress19;
    uint256 internal immutable asset20_a;
    address internal immutable priceFeedAddress20;
    uint256 internal immutable asset21_a;
    address internal immutable priceFeedAddress21;
    uint256 internal immutable asset22_a;
    address internal immutable priceFeedAddress22;
    uint256 internal immutable asset23_a;
    address internal immutable priceFeedAddress23;

    /// @notice The number of assets this contract actually supports
    uint8 public immutable numAssets;

    /// @inheritdoc IConfigHash
    bytes32 public immutable configHash;

    /// @notice The only address allowed to call the setters
    address public immutable configurator;

    /*//////////////////////////////////////////////////////////////
                                STORAGE
    //////////////////////////////////////////////////////////////*/

    /// @dev Registered assets, so a setter rejects an unlisted asset with one lookup
    EnumerableSet.AddressSet internal assets;

    /// @dev Factors and supply cap of each asset, keyed by address so they stay with the asset whatever its index
    mapping(address => StorageAssetConfig) internal assetConfigs;

    modifier onlyConfigurator() {
        if (msg.sender != configurator) revert OnlyConfigurator();
        _;
    }

    /// @dev The transparent proxy blocks plain calls from its admin, so this passes only inside the proxy admin's
    ///      upgradeAndCall, and never on the implementation itself, whose admin slot is empty
    modifier onlyProxyAdmin() {
        if (msg.sender != StorageSlot.getAddressSlot(PROXY_ADMIN_SLOT).value) revert OnlyProxyAdmin();
        _;
    }

    constructor(ImmutableAssetConfig[] memory assetConfigs_, address configurator_) {
        _disableInitializers();

        if (assetConfigs_.length == 0) revert NoAssets();
        if (assetConfigs_.length > MAX_ASSETS) revert TooManyAssets();
        if (configurator_ == address(0)) revert ZeroConfigurator();
        configurator = configurator_;

        uint8 _numAssets = uint8(assetConfigs_.length);
        numAssets = _numAssets;
        configHash = ConfigHash.hashConfig(TYPEHASH, abi.encode(assetConfigs_));

        (asset00_a, priceFeedAddress00) = _packAsset(assetConfigs_[0]);
        (asset01_a, priceFeedAddress01) = 1 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[1]);
        (asset02_a, priceFeedAddress02) = 2 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[2]);
        (asset03_a, priceFeedAddress03) = 3 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[3]);
        (asset04_a, priceFeedAddress04) = 4 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[4]);
        (asset05_a, priceFeedAddress05) = 5 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[5]);
        (asset06_a, priceFeedAddress06) = 6 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[6]);
        (asset07_a, priceFeedAddress07) = 7 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[7]);
        (asset08_a, priceFeedAddress08) = 8 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[8]);
        (asset09_a, priceFeedAddress09) = 9 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[9]);
        (asset10_a, priceFeedAddress10) = 10 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[10]);
        (asset11_a, priceFeedAddress11) = 11 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[11]);
        (asset12_a, priceFeedAddress12) = 12 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[12]);
        (asset13_a, priceFeedAddress13) = 13 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[13]);
        (asset14_a, priceFeedAddress14) = 14 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[14]);
        (asset15_a, priceFeedAddress15) = 15 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[15]);
        (asset16_a, priceFeedAddress16) = 16 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[16]);
        (asset17_a, priceFeedAddress17) = 17 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[17]);
        (asset18_a, priceFeedAddress18) = 18 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[18]);
        (asset19_a, priceFeedAddress19) = 19 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[19]);
        (asset20_a, priceFeedAddress20) = 20 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[20]);
        (asset21_a, priceFeedAddress21) = 21 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[21]);
        (asset22_a, priceFeedAddress22) = 22 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[22]);
        (asset23_a, priceFeedAddress23) = 23 >= _numAssets ? (0, address(0)) : _packAsset(assetConfigs_[23]);
    }

    /**
     * @notice Set the factors and supply caps of the listed assets
     * @dev The configs go in the same order as the assets passed to the constructor, one per asset
     * @param storageConfigs The mutable part of the asset configurations
     */
    function initialize(StorageAssetConfig[] calldata storageConfigs) external initializer {
        if (storageConfigs.length != numAssets) revert StorageConfigsLengthMismatch();

        for (uint8 i; i < numAssets; ++i) {
            (uint256 word_a, ) = _loadPackedAsset(i);
            // The same asset listed twice is registered only once, so the second time is rejected
            if (!_setAssetConfig(address(uint160(word_a)), storageConfigs[i])) revert AssetAlreadyAdded();
        }
    }

    /*//////////////////////////////////////////////////////////////
                             CONFIGURATION
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Set the storage configs of all assets in the immutables, registering the new ones
     * @dev The proxy admin calls this through upgradeAndCall on every list upgrade, so a new asset gets registered
     *      and an updated one gets its factors and cap.
     *      Every config is written, even an unchanged one.
     *      Every asset's position in the registered assets is checked against its index in the immutables,
     *      so a wrong order is caught here, at upgrade time
     * @param storageConfigs The factors and supply cap of each asset, in the order of the immutables
     */
    function setAssetConfigs(StorageAssetConfig[] calldata storageConfigs) external onlyProxyAdmin {
        if (storageConfigs.length != numAssets) revert StorageConfigsLengthMismatch();

        for (uint8 i; i < numAssets; ++i) {
            (uint256 word_a, ) = _loadPackedAsset(i);
            address asset = address(uint160(word_a));
            _setAssetConfig(asset, storageConfigs[i]);
            // getAssetInfoByAddress finds an asset by its position in the registered assets, so that position must be
            // its index in the immutables
            if (_registeredPosition(asset) != i + 1) revert AssetIndexMismatch();
        }
    }

    /**
     * @notice Set the borrow collateral factor of an asset
     * @dev The new value is checked together with the asset's current liquidate collateral factor and liquidation factor,
     *      so raising it above the current liquidate collateral factor needs that factor raised first
     * @param asset The asset, must be listed at construction
     */
    function setBorrowCollateralFactor(address asset, uint64 borrowCollateralFactor) external onlyConfigurator {
        StorageAssetConfig storage config = _listedConfig(asset);
        _validateCollateralFactors(borrowCollateralFactor, config.liquidateCollateralFactor, config.liquidationFactor);
        config.borrowCollateralFactor = borrowCollateralFactor;
    }

    /**
     * @notice Set the liquidate collateral factor of an asset
     * @dev The new value is checked together with the asset's current borrow collateral factor and liquidation factor,
     *      so lowering it to or below the current borrow collateral factor needs that factor lowered first
     * @param asset The asset, must be listed at construction
     */
    function setLiquidateCollateralFactor(address asset, uint64 liquidateCollateralFactor) external onlyConfigurator {
        StorageAssetConfig storage config = _listedConfig(asset);
        _validateCollateralFactors(config.borrowCollateralFactor, liquidateCollateralFactor, config.liquidationFactor);
        config.liquidateCollateralFactor = liquidateCollateralFactor;
    }

    /**
     * @notice Set the liquidation factor of an asset
     * @param asset The asset, must be listed at construction
     */
    function setLiquidationFactor(address asset, uint64 liquidationFactor) external onlyConfigurator {
        StorageAssetConfig storage config = _listedConfig(asset);
        _validateCollateralFactors(config.borrowCollateralFactor, config.liquidateCollateralFactor, liquidationFactor);
        config.liquidationFactor = liquidationFactor;
    }

    /**
     * @notice Set the supply cap of an asset
     * @param asset The asset, must be listed at construction
     */
    function setSupplyCap(address asset, uint128 supplyCap) external onlyConfigurator {
        StorageAssetConfig storage config = _listedConfig(asset);
        config.supplyCap = supplyCap;
    }

    /*//////////////////////////////////////////////////////////////
                                VIEWERS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Get the i-th asset info, according to the order they were passed in originally
     * @param i The index of the asset info to get
     * @return The asset info object
     */
    function getAssetInfo(uint8 i) public view returns (AssetInfo memory) {
        if (i >= numAssets) revert AssetIndexOutOfRange();
        return _composeAssetInfo(i);
    }

    /**
     * @notice Get the asset info of an asset by its address
     * @param asset The asset, must be listed at construction
     * @return The asset info object
     */
    function getAssetInfoByAddress(address asset) public view returns (AssetInfo memory) {
        uint8 position = _registeredPosition(asset);
        if (position == 0) revert AssetNotFound();
        return _composeAssetInfo(position - 1);
    }

    /*//////////////////////////////////////////////////////////////
                                 UTILS
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev Checks and gets the packed asset info and the price feed address
     * - in the packed word, the asset address is stored in the lower 160 bits (address can be interpreted as uint160),
     *      the asset decimals in the next 8 bits, and the asset scale (10 to the power of the decimals) in the next 64 bits
     * @param assetConfig The immutable part of the asset configuration
     * @return The packed asset info and the price feed address
     */
    function _packAsset(ImmutableAssetConfig memory assetConfig) internal view returns (uint256, address) {
        address asset = assetConfig.asset;
        address priceFeed = assetConfig.priceFeed;

        if (asset == address(0) || priceFeed == address(0)) revert ZeroAddress();

        // Sanity check price feed decimals
        if (IPriceFeed(priceFeed).decimals() != PRICE_FEED_DECIMALS) revert PriceFeedDecimalsNotMatched();
        // The asset decimals come from the token itself, so they can never disagree with it
        uint8 decimals = IERC20NonStandard(asset).decimals();
        // The scale is packed as uint64, so it must fit
        if (decimals > MAX_ASSET_DECIMALS) revert MaxAssetDecimalsExceeds();
        uint64 scale = uint64(10 ** decimals);

        uint256 word_a = (uint160(asset) << 0 |        // bits 0-159: asset address
                          uint256(decimals) << 160 |  // bits 160-167: asset decimals
                          uint256(scale) << 168);      // bits 168-231: asset scale (bits 232-255 unused)
        return (word_a, priceFeed);
    }

    /**
     * @dev Sanity checks for factors ordering: BCF < LCF < LF <= FACTOR_SCALE
     * Valid collateral factor configurations:
     *  1. Both BCF and LCF are 0 => collateral is fully de-listed
     *  2. borrowCF=0, liquidateCF>0 => soft de-list (no new borrows, controlled liquidation wind-down)
     *  3. Both non-zero, properly ordered => active collateral
     *  4. Liquidation penalty (LF) can be set to 0 only with BCF and LCF set to 0, meaning non-liquidatable asset
     *  Invalid: borrowCF>0, liquidateCF=0 => reverts (borrow power without liquidation coverage)
     */
    function _validateCollateralFactors(
        uint64 borrowCollateralFactor,
        uint64 liquidateCollateralFactor,
        uint64 liquidationFactor
    ) internal pure {
        if (borrowCollateralFactor >= liquidateCollateralFactor && borrowCollateralFactor != 0) revert BorrowCFTooLarge();
        if (liquidateCollateralFactor >= liquidationFactor && liquidateCollateralFactor != 0) revert LiquidateCFTooLarge();
        if (liquidationFactor > FACTOR_SCALE) revert LiqPenaltyTooHigh();
    }

    /**
     * @dev Builds the asset info of the i-th asset from its packed word and price feed, adding its storage config
     */
    function _composeAssetInfo(uint8 i) internal view returns (AssetInfo memory) {
        (uint256 word_a, address priceFeed) = _loadPackedAsset(i);
        address asset = address(uint160(word_a));

        // Factors and supply cap are kept unscaled in storage so the Configurator can change them
        StorageAssetConfig memory config = assetConfigs[asset];

        return AssetInfo({
            asset: asset,
            scale: uint64(word_a >> 168),
            offset: i,
            priceFeed: priceFeed,
            borrowCollateralFactor: config.borrowCollateralFactor,
            supplyCap: config.supplyCap,
            liquidateCollateralFactor: config.liquidateCollateralFactor,
            liquidationFactor: config.liquidationFactor
        });
    }

    /// @dev The asset's position in the registered assets, from 1, or 0 if unregistered; EnumerableSet has no getter for it
    function _registeredPosition(address asset) internal view returns (uint8) {
        return uint8(assets._inner._indexes[bytes32(uint256(uint160(asset)))]);
    }

    /**
     * @dev Validates the factors of an asset, registers it so the setters can change it later,
     *      and stores its factors and supply cap unscaled, replacing the config of an asset already registered
     * @return True if the asset was registered by this call, false if it was registered before
     */
    function _setAssetConfig(address asset, StorageAssetConfig calldata config) internal returns (bool) {
        _validateCollateralFactors(
            config.borrowCollateralFactor,
            config.liquidateCollateralFactor,
            config.liquidationFactor
        );

        assetConfigs[asset] = config;
        // Registers a new asset; an asset already registered stays as it is
        return assets.add(asset);
    }

    /**
     * @dev Returns the stored config of an asset, reverting if the asset was not listed at construction
     */
    function _listedConfig(address asset) internal view returns (StorageAssetConfig storage) {
        if (!assets.contains(asset)) revert AssetNotFound();
        return assetConfigs[asset];
    }

    /**
     * @dev Gets the packed asset info and the price feed address of the i-th asset from the immutables
     */
    function _loadPackedAsset(uint8 i) internal view returns (uint256 word_a, address priceFeed) {
        if(i == 0){
            word_a = asset00_a;
            priceFeed = priceFeedAddress00;
        }
        if(i == 1){
            word_a = asset01_a;
            priceFeed = priceFeedAddress01;
        }
        if(i == 2){
            word_a = asset02_a;
            priceFeed = priceFeedAddress02;
        }
        if(i == 3){
            word_a = asset03_a;
            priceFeed = priceFeedAddress03;
        }
        if(i == 4){
            word_a = asset04_a;
            priceFeed = priceFeedAddress04;
        }
        if(i == 5){
            word_a = asset05_a;
            priceFeed = priceFeedAddress05;
        }
        if(i == 6){
            word_a = asset06_a;
            priceFeed = priceFeedAddress06;
        }
        if(i == 7){
            word_a = asset07_a;
            priceFeed = priceFeedAddress07;
        }
        if(i == 8){
            word_a = asset08_a;
            priceFeed = priceFeedAddress08;
        }
        if(i == 9){
            word_a = asset09_a;
            priceFeed = priceFeedAddress09;
        }
        if(i == 10){
            word_a = asset10_a;
            priceFeed = priceFeedAddress10;
        }
        if(i == 11){
            word_a = asset11_a;
            priceFeed = priceFeedAddress11;
        }
        if(i == 12){
            word_a = asset12_a;
            priceFeed = priceFeedAddress12;
        }
        if(i == 13){
            word_a = asset13_a;
            priceFeed = priceFeedAddress13;
        }
        if(i == 14){
            word_a = asset14_a;
            priceFeed = priceFeedAddress14;
        }
        if(i == 15){
            word_a = asset15_a;
            priceFeed = priceFeedAddress15;
        }
        if(i == 16){
            word_a = asset16_a;
            priceFeed = priceFeedAddress16;
        }
        if(i == 17){
            word_a = asset17_a;
            priceFeed = priceFeedAddress17;
        }
        if(i == 18){
            word_a = asset18_a;
            priceFeed = priceFeedAddress18;
        }
        if(i == 19){
            word_a = asset19_a;
            priceFeed = priceFeedAddress19;
        }
        if(i == 20){
            word_a = asset20_a;
            priceFeed = priceFeedAddress20;
        }
        if(i == 21){
            word_a = asset21_a;
            priceFeed = priceFeedAddress21;
        }
        if(i == 22){
            word_a = asset22_a;
            priceFeed = priceFeedAddress22;
        }
        if(i == 23){
            word_a = asset23_a;
            priceFeed = priceFeedAddress23;
        }
    }
}

@openzeppelin/contracts/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/Address.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

@openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

contracts/interfaces/IConfigHash.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
 * @title Config Hash
 * @notice Shared getter for contracts built from a config whose hash is computed with the ConfigHash library
 * @dev Every such contract exposes its hash under this one name, so any caller can read it the same way,
 *      e.g. to check with ConfigHash.areHashesEqual whether a new config differs and a redeploy is needed
 * @author Compound
 */
interface IConfigHash {
    /// @notice The hash of the config this contract was built from
    function configHash() external view returns (bytes32);

    /// @notice The type hash the config hash was computed under; ConfigHash.areHashesEqual reads it to hash a new config the same way
    function TYPEHASH() external view returns (bytes32);
}

contracts/interfaces/IERC20NonStandard.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
 * @title IERC20NonStandard
 * @dev Version of ERC20 with no return values for `approve`, `transfer`, and `transferFrom`
 *  See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
 */
interface IERC20NonStandard {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);

    /**
     * @notice Approve `spender` to transfer up to `amount` from `src`
     * @dev This will overwrite the approval amount for `spender`
     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
     * @param spender The address of the account which may transfer tokens
     * @param amount The number of tokens that are approved (-1 means infinite)
     */
    function approve(address spender, uint256 amount) external;

    /**
     * @notice Transfer `value` tokens from `msg.sender` to `to`
     * @param to The address of the destination account
     * @param value The number of tokens to transfer
     */
    function transfer(address to, uint256 value) external;

    /**
     * @notice Transfer `value` tokens from `from` to `to`
     * @param from The address of the source account
     * @param to The address of the destination account
     * @param value The number of tokens to transfer
     */
    function transferFrom(address from, address to, uint256 value) external;

    /**
     * @notice Gets the balance of the specified address
     * @param account The address from which the balance will be retrieved
     */
    function balanceOf(address account) external view returns (uint256);
}

contracts/interfaces/IPriceFeed.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
 * @dev Interface for price feeds used by Comet
 * Note This is Chainlink's AggregatorV3Interface, but without the `getRoundData` function.
 */
interface IPriceFeed {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function latestRoundData()
    external
    view
    returns (
      uint80 roundId,
      int256 answer,
      uint256 startedAt,
      uint256 updatedAt,
      uint80 answeredInRound
    );
}

contracts/interfaces/assetList/IAssetList.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import { IAssetListErrors } from "./IAssetListErrors.sol";
import { IAssetListStructs } from "./IAssetListStructs.sol";

/**
 * @title Compound's Asset List
 * @notice Interface of the asset list. The functions are documented in the AssetList contract
 * @author Compound
 */
interface IAssetList is IAssetListErrors, IAssetListStructs {
    function numAssets() external view returns (uint8);
    
    function MAX_ASSETS() external view returns (uint8);

    function configurator() external view returns (address);

    function setAssetConfigs(StorageAssetConfig[] calldata storageConfigs) external;

    function setBorrowCollateralFactor(address asset, uint64 borrowCollateralFactor) external;

    function setLiquidateCollateralFactor(address asset, uint64 liquidateCollateralFactor) external;

    function setLiquidationFactor(address asset, uint64 liquidationFactor) external;

    function setSupplyCap(address asset, uint128 supplyCap) external;

    function getAssetInfo(uint8 i) external view returns (AssetInfo memory);

    function getAssetInfoByAddress(address asset) external view returns (AssetInfo memory);
}

contracts/interfaces/assetList/IAssetListErrors.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
 * @title Compound's Asset List Errors
 * @author Compound
 */
interface IAssetListErrors {
    /// @dev The asset list is built with no assets
    error NoAssets();

    /// @dev The asset list is built with more assets than it can hold
    error TooManyAssets();

    /// @dev The number of storage configs differs from the number of assets
    error StorageConfigsLengthMismatch();

    /// @dev The index is not below the number of assets
    error AssetIndexOutOfRange();

    /// @dev The asset is not registered in the list
    error AssetNotFound();

    /// @dev The asset's position in the registered assets differs from its index in the immutables
    error AssetIndexMismatch();

    /// @dev The asset or its price feed is the zero address
    error ZeroAddress();

    /// @dev The price feed does not have the expected 8 decimals
    error PriceFeedDecimalsNotMatched();

    /// @dev The asset has too many decimals for its scale to fit in uint64
    error MaxAssetDecimalsExceeds();

    /// @dev The borrow collateral factor is not below the liquidate collateral factor
    error BorrowCFTooLarge();

    /// @dev The liquidate collateral factor is above 1
    error LiquidateCFTooLarge();

    /// @dev The liquidation factor is above 1
    error LiqPenaltyTooHigh();

    /// @dev The caller is not the configurator
    error OnlyConfigurator();

    /// @dev The caller is not the admin of the list proxy
    error OnlyProxyAdmin();

    /// @dev The configurator is the zero address
    error ZeroConfigurator();

    /// @dev The asset is already registered, so its storage config can only be changed through the setters
    error AssetAlreadyAdded();
}

contracts/interfaces/assetList/IAssetListStructs.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

/**
 * @title Compound's Asset List Structs
 * @author Compound
 */
interface IAssetListStructs {
    /**
     * @notice The part of an asset config that never changes for a deployed asset list
     * @dev Passed to the asset list constructor and kept in immutables, so reading it costs no storage access.
     *      Changing any of these values means deploying a new asset list. The asset decimals are read from the token
     */
    struct ImmutableAssetConfig {
        address asset;                      // slot 0
        address priceFeed;                  // slot 1
    }

    /**
     * @notice The part of an asset config the configurator can change without redeploying the asset list
     * @dev Kept in storage so the setters can update it
     */
    struct StorageAssetConfig {
        uint64 borrowCollateralFactor;      // slot 0
        uint64 liquidateCollateralFactor;
        uint64 liquidationFactor;
        uint128 supplyCap;                  // slot 1
    }

    /**
     * @notice Everything about one asset, as returned by getAssetInfo and getAssetInfoByAddress
     * @dev Joins the immutable part (asset, scale, price feed) with the storage part (factors, supply cap).
     *      The offset is the asset's index in the list. The scale is 10 to the power of the asset decimals
     */
    struct AssetInfo {
        uint8 offset;                       // slot 0
        address asset;
        address priceFeed;                  // slot 1
        uint64 scale;
        uint64 borrowCollateralFactor;      // slot 2
        uint64 liquidateCollateralFactor;
        uint64 liquidationFactor;
        uint128 supplyCap;                  // slot 3
    }
}

contracts/libraries/ConfigHash.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import { IConfigHash } from "../interfaces/IConfigHash.sol";

/**
 * @title ConfigHash
 * @notice Typed hashing of configs, so a stored hash can tell whether a config changed
 * @dev Works for any config type: the caller passes its own type hash and the config ABI-encoded with `abi.encode`.
 *      The type hash keeps configs of different types apart even when their bytes are equal.
 *      Never pass `abi.encodePacked` output: packed encoding is ambiguous and two configs could share a hash.
 * @author Compound
 */
library ConfigHash {
    /**
     * @dev Hashes an encoded config under a type hash
     * @param typeHash The hash identifying the config type
     * @param encoded The config, ABI-encoded with `abi.encode`
     * @return The config hash
     */
    function hashConfig(bytes32 typeHash, bytes memory encoded) internal pure returns (bytes32) {
        // The type hash has a fixed length, so joining it with the encoded config cannot be read two ways
        return keccak256(bytes.concat(typeHash, encoded));
    }

    /**
     * @dev Checks whether a new config is the one a deployed contract was built from, meaning no redeploy is needed
     * @param target The deployed contract to compare with, which must implement IConfigHash and come from a trusted source
     * @param newConfig The new config, ABI-encoded with `abi.encode`
     * @return True if the new config hashes to the target's configHash
     */
    function areHashesEqual(address target, bytes memory newConfig) internal view returns (bool) {
        return hashConfig(IConfigHash(target).TYPEHASH(), newConfig) == IConfigHash(target).configHash();
    }
}

contracts/vendor/utils/StorageSlot.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/StorageSlot.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly {
            r.slot := slot
        }
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 1,
    "details": {
      "yulDetails": {
        "optimizerSteps": "dhfoDgvulfnTUtnIf [xa[r]scLM cCTUtTOntnfDIul Lcul Vcul [j] Tpeul xa[rul] xa[r]cL gvif CTUca[r]LsTOtfDnca[r]Iulc] jmul[jul] VcTOcul jmul"
      }
    },
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.