Verified contractExactBUSL-1.1
ConfiguratorIntermediate
Address0x7b95c9c686c498c9dfce88bece21daef3522a90b
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.15
- Same code
Only this contract
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,298
- Creation transaction
- 0x662e753447…3ce98520b3
contracts/migration/ConfiguratorIntermediate.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;
import "./ConfiguratorIntermediateStorage.sol";
/**
* @title Compound's Configurator Contract, Intermediate version
* @dev Temporary implementation for the Configurator upgrade path (ConfiguratorV1 -> ConfiguratorIntermediate -> Configurator).
* It only moves the asset configs to their new storage, so it has nothing else of the Configurator.
* Delete this folder once the upgrade is deployed.
*/
contract ConfiguratorIntermediate is ConfiguratorIntermediateStorage {
/** Custom events **/
event AssetConfigsMigrated(address indexed cometProxy, uint256 numAssets);
/** Custom errors **/
error AlreadyInitialized();
error AlreadyMigrated();
error InvalidAddress();
error Unauthorized();
/**
* @notice Constructs a new Configurator instance
**/
constructor() {
// Set a high version to prevent the implementation contract from being initialized
version = type(uint256).max;
}
/**
* @notice Initializes the storage for Configurator
* @param governor_ The address of the governor
**/
function initialize(address governor_) public {
if (version != 0) revert AlreadyInitialized();
if (governor_ == address(0)) revert InvalidAddress();
governor = governor_;
version = 1;
}
/**
* @notice Moves the asset configs of each market from Configuration.assetConfigs to the assetConfigs mapping
* @dev Note: Only callable by governor. Every field but decimals is copied, factors and supply caps included;
* decimals are dropped because the asset list now reads them from the token.
* Clearing Configuration.assetConfigs also zeroes the slot the final Configuration reads as assetList
* @param comets The Comet proxies to migrate
*/
function migrateAssetConfig(address[] calldata comets) external {
if (msg.sender != governor) revert Unauthorized();
for (uint256 i; i < comets.length; ++i) {
address cometProxy = comets[i];
// A second run would copy the already cleared, empty array over the migrated configs
if (assetConfigs[cometProxy].length != 0) revert AlreadyMigrated();
AssetConfig[] storage oldConfigs = configuratorParams[cometProxy].assetConfigs;
uint256 numAssets = oldConfigs.length;
// The old struct has decimals between the price feed and the factors, so the two layouts differ
// and each config is rebuilt field by field instead of copying the array as a whole
for (uint256 j; j < numAssets; ++j) {
AssetConfig storage oldConfig = oldConfigs[j];
assetConfigs[cometProxy].push(CometConfiguration.AssetConfig({
asset: oldConfig.asset,
priceFeed: oldConfig.priceFeed,
borrowCollateralFactor: oldConfig.borrowCollateralFactor,
liquidateCollateralFactor: oldConfig.liquidateCollateralFactor,
liquidationFactor: oldConfig.liquidationFactor,
supplyCap: oldConfig.supplyCap
}));
}
delete configuratorParams[cometProxy].assetConfigs;
emit AssetConfigsMigrated(cometProxy, numAssets);
}
}
}
contracts/CometConfiguration.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;
/**
* @title Compound's Comet Configuration Interface
* @author Compound
*/
contract CometConfiguration {
struct ExtConfiguration {
bytes32 name32;
bytes32 symbol32;
}
struct Configuration {
address governor;
address pauseGuardian;
address baseToken;
address baseTokenPriceFeed;
address extensionDelegate;
uint64 supplyKink;
uint64 supplyPerYearInterestRateSlopeLow;
uint64 supplyPerYearInterestRateSlopeHigh;
uint64 supplyPerYearInterestRateBase;
uint64 borrowKink;
uint64 borrowPerYearInterestRateSlopeLow;
uint64 borrowPerYearInterestRateSlopeHigh;
uint64 borrowPerYearInterestRateBase;
uint64 storeFrontPriceFactor;
uint64 trackingIndexScale;
uint64 baseTrackingSupplySpeed;
uint64 baseTrackingBorrowSpeed;
uint104 baseMinForRewards;
uint104 baseBorrowMin;
uint104 targetReserves;
address assetList;
}
struct AssetConfig {
address asset;
address priceFeed;
uint64 borrowCollateralFactor;
uint64 liquidateCollateralFactor;
uint64 liquidationFactor;
uint128 supplyCap;
}
}
contracts/migration/CometConfigurationIntermediate.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;
/**
* @title Compound's Comet Configuration Interface, Intermediate version
* @dev The configuration before asset configs moved to the asset list, still with Configuration.assetConfigs.
* Used by ConfiguratorIntermediate, which migrates the asset configs out of it, and by the legacy Comet it deploys.
* Same structs as V1, so V1 and Intermediate share one storage layout. AssetConfig here still has decimals;
* the migrated configs use CometConfiguration.AssetConfig, which has none
* @author Compound
*/
contract CometConfigurationIntermediate {
struct ExtConfiguration {
bytes32 name32;
bytes32 symbol32;
}
struct Configuration {
address governor;
address pauseGuardian;
address baseToken;
address baseTokenPriceFeed;
address extensionDelegate;
uint64 supplyKink;
uint64 supplyPerYearInterestRateSlopeLow;
uint64 supplyPerYearInterestRateSlopeHigh;
uint64 supplyPerYearInterestRateBase;
uint64 borrowKink;
uint64 borrowPerYearInterestRateSlopeLow;
uint64 borrowPerYearInterestRateSlopeHigh;
uint64 borrowPerYearInterestRateBase;
uint64 storeFrontPriceFactor;
uint64 trackingIndexScale;
uint64 baseTrackingSupplySpeed;
uint64 baseTrackingBorrowSpeed;
uint104 baseMinForRewards;
uint104 baseBorrowMin;
uint104 targetReserves;
AssetConfig[] assetConfigs;
}
struct AssetConfig {
address asset;
address priceFeed;
uint8 decimals;
uint64 borrowCollateralFactor;
uint64 liquidateCollateralFactor;
uint64 liquidationFactor;
uint128 supplyCap;
}
}
contracts/migration/ConfiguratorIntermediateStorage.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;
import "./CometConfigurationIntermediate.sol";
import "../CometConfiguration.sol";
/**
* @title Compound's Comet Configuration Storage Interface
* @dev Versions can enforce append-only storage slots via inheritance.
* Temporary copy for testing the Configurator upgrade path (ConfiguratorV1 -> ConfiguratorIntermediate -> Configurator).
* Delete this folder once the upgrade is deployed.
* @author Compound
*/
contract ConfiguratorIntermediateStorage is CometConfigurationIntermediate {
/// @notice The current version of Configurator. This version should be
/// checked in the initializer function.
uint public version;
/// @notice Mapping of Comet proxy addresses to their Configuration settings
/// @dev This needs to be internal to avoid a `CompilerError: Stack too deep
/// when compiling inline assembly` error that is caused by the default
/// getters created for public variables.
mapping(address => Configuration) internal configuratorParams;
/// @notice The governor of the protocol
address public governor;
/// @notice Mapping of Comet proxy addresses to their Comet factory contracts
mapping(address => address) public factory;
/// @notice Mapping of Comet proxy addresses to their asset configs, in the final format without decimals
/// @dev Appended at the end, at the same slot and with the same struct as in the final ConfiguratorStorage,
/// and filled by migrateAssetConfig
mapping(address => CometConfiguration.AssetConfig[]) public assetConfigs;
}
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.