Skip to content

Commit

Permalink
fix: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed Jan 13, 2025
1 parent 1374ded commit 1df8617
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 36 deletions.
8 changes: 5 additions & 3 deletions contracts/factories/AbstractFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import {AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL} from "../libraries/C
import {DeployerTrait} from "../traits/DeployerTrait.sol";

abstract contract AbstractFactory is DeployerTrait, IFactory {
address public immutable override marketConfiguratorFactory;

modifier onlyMarketConfigurators() {
_ensureCallerIsMarketConfigurator();
_;
}

constructor(address addressProvider_) DeployerTrait(addressProvider_) {}
constructor(address addressProvider_) DeployerTrait(addressProvider_) {
marketConfiguratorFactory = _getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL);
}

// ------------- //
// CONFIGURATION //
Expand All @@ -37,8 +41,6 @@ abstract contract AbstractFactory is DeployerTrait, IFactory {
// --------- //

function _ensureCallerIsMarketConfigurator() internal view {
// QUESTION: can MCF be upgraded?
address marketConfiguratorFactory = _getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL);
if (!IMarketConfiguratorFactory(marketConfiguratorFactory).isMarketConfigurator(msg.sender)) {
revert CallerIsNotMarketConfiguratorException(msg.sender);
}
Expand Down
12 changes: 10 additions & 2 deletions contracts/factories/CreditFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,16 @@ contract CreditFactory is AbstractFactory, ICreditFactory {

if (decodedCreditManager != creditManager) revert InvalidConstructorParamsException();

// FIXME: unlike other contracts, this might be deployed multiple times, so using the same salt
// can be an issue. Same thing can happen to rate keepers, IRMs, etc.
// NOTE: allowing a previously forbidden adapter is considered a valid operation,
// so we just return the contract address if it's already deployed
address adapter = _computeAddressLatestPatch({
contractType: _getContractType(DOMAIN_ADAPTER, params.postfix),
minorVersion: version,
constructorParams: params.constructorParams,
salt: bytes32(bytes20(marketConfigurator)),
deployer: address(this)
});
if (adapter.code.length != 0) return adapter;

return _deployLatestPatch({
contractType: _getContractType(DOMAIN_ADAPTER, params.postfix),
Expand Down
2 changes: 1 addition & 1 deletion contracts/factories/InterestRateModelFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract InterestRateModelFactory is AbstractMarketFactory, IInterestRateModelFa
contractType: _getContractType(DOMAIN_IRM, params.postfix),
minorVersion: version,
constructorParams: params.constructorParams,
salt: bytes32(bytes20(msg.sender))
salt: bytes32(bytes20(pool))
});

return DeployResult({
Expand Down
4 changes: 1 addition & 3 deletions contracts/factories/PoolFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import {IMarketConfigurator} from "../interfaces/IMarketConfigurator.sol";
import {Call, DeployResult} from "../interfaces/Types.sol";

import {CallBuilder} from "../libraries/CallBuilder.sol";
import {
AP_POOL_FACTORY, AP_POOL_QUOTA_KEEPER, DOMAIN_POOL, NO_VERSION_CONTROL
} from "../libraries/ContractLiterals.sol";
import {AP_POOL_FACTORY, AP_POOL_QUOTA_KEEPER, DOMAIN_POOL} from "../libraries/ContractLiterals.sol";

import {AbstractFactory} from "./AbstractFactory.sol";
import {AbstractMarketFactory} from "./AbstractMarketFactory.sol";
Expand Down
3 changes: 1 addition & 2 deletions contracts/factories/PriceOracleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ contract PriceOracleFactory is AbstractMarketFactory, IPriceOracleFactory {
/// @notice Constructor
/// @param addressProvider_ Address provider contract address
constructor(address addressProvider_) AbstractFactory(addressProvider_) {
// TODO: Dima check the version problem
priceFeedStore = _getAddressOrRevert(AP_PRICE_FEED_STORE, 3_10);
priceFeedStore = _getAddressOrRevert(AP_PRICE_FEED_STORE, NO_VERSION_CONTROL);
}

// ---------- //
Expand Down
12 changes: 5 additions & 7 deletions contracts/instance/InstanceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ contract InstanceManager is Ownable, IVersion {
}
}

function deploySystemContract(bytes32 _contractName, uint256 _version) external onlyCrossChainGovernance {
function deploySystemContract(bytes32 _contractName, uint256 _version, bool _saveVersion)
external
onlyCrossChainGovernance
{
// deploy contract
// set address in address provider

address newSystemContract = _deploySystemContract(_contractName, _version);
if (_contractName == AP_MARKET_CONFIGURATOR_FACTORY) {
_setAddress(_contractName, newSystemContract, false);
_setAddress(_contractName, newSystemContract, true);
} else {
_setAddress(_contractName, newSystemContract, true);
}
_setAddress(_contractName, newSystemContract, _saveVersion);
}

function _deploySystemContract(bytes32 _contractName, uint256 _version) internal returns (address) {
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/factories/IFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ interface IFactory is IVersion, IDeployerTrait {
error ForbiddenEmergencyConfigurationCallException(bytes4 selector);
error InvalidConstructorParamsException();

// --------------- //
// STATE VARIABLES //
// --------------- //

function marketConfiguratorFactory() external view returns (address);

// ------------- //
// CONFIGURATION //
// ------------- //
Expand Down
22 changes: 12 additions & 10 deletions contracts/test/helpers/GlobalSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct UploadableContract {
struct DeploySystemContractCall {
bytes32 contractType;
uint256 version;
bool saveVersion;
}

// It deploys all the system contracts and related ones
Expand All @@ -141,14 +142,14 @@ contract GlobalSetup is Test, InstanceManagerHelper {
_submitProposalAndSign(calls);

DeploySystemContractCall[8] memory deployCalls = [
DeploySystemContractCall({contractType: AP_PRICE_FEED_STORE, version: 3_10}),
DeploySystemContractCall({contractType: AP_POOL_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_CREDIT_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_PRICE_ORACLE_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_INTEREST_RATE_MODEL_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_RATE_KEEPER_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_LOSS_POLICY_FACTORY, version: 3_10}),
DeploySystemContractCall({contractType: AP_MARKET_CONFIGURATOR_FACTORY, version: 3_10})
DeploySystemContractCall({contractType: AP_PRICE_FEED_STORE, version: 3_10, saveVersion: false}),
DeploySystemContractCall({contractType: AP_MARKET_CONFIGURATOR_FACTORY, version: 3_10, saveVersion: false}),
DeploySystemContractCall({contractType: AP_POOL_FACTORY, version: 3_10, saveVersion: true}),
DeploySystemContractCall({contractType: AP_CREDIT_FACTORY, version: 3_10, saveVersion: true}),
DeploySystemContractCall({contractType: AP_PRICE_ORACLE_FACTORY, version: 3_10, saveVersion: true}),
DeploySystemContractCall({contractType: AP_INTEREST_RATE_MODEL_FACTORY, version: 3_10, saveVersion: true}),
DeploySystemContractCall({contractType: AP_RATE_KEEPER_FACTORY, version: 3_10, saveVersion: true}),
DeploySystemContractCall({contractType: AP_LOSS_POLICY_FACTORY, version: 3_10, saveVersion: true})
];

uint256 uploadContractsLen = contractsToUpload.length;
Expand All @@ -164,8 +165,9 @@ contract GlobalSetup is Test, InstanceManagerHelper {
}

for (uint256 i = 0; i < deploySystemContractsLen; ++i) {
calls[uploadContractsLen + i] =
_generateDeploySystemContractCall(deployCalls[i].contractType, deployCalls[i].version);
calls[uploadContractsLen + i] = _generateDeploySystemContractCall(
deployCalls[i].contractType, deployCalls[i].version, deployCalls[i].saveVersion
);
}

_submitProposalAndSign(calls);
Expand Down
11 changes: 6 additions & 5 deletions contracts/test/helpers/InstanceManagerHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {BytecodeRepository} from "../../../contracts/global/BytecodeRepository.s
import {
AP_INSTANCE_MANAGER,
AP_BYTECODE_REPOSITORY,
AP_PRICE_FEED_STORE
AP_PRICE_FEED_STORE,
NO_VERSION_CONTROL
} from "../../../contracts/libraries/ContractLiterals.sol";
import {CrossChainCall} from "../../../contracts/interfaces/ICrossChainMultisig.sol";
import {IBytecodeRepository} from "../../../contracts/interfaces/IBytecodeRepository.sol";
Expand Down Expand Up @@ -47,14 +48,14 @@ contract InstanceManagerHelper is BCRHelpers, CCGHelper {
);
}

function _generateDeploySystemContractCall(bytes32 _contractName, uint256 _version)
function _generateDeploySystemContractCall(bytes32 _contractName, uint256 _version, bool _saveVersion)
internal
returns (CrossChainCall memory)
{
return CrossChainCall({
chainId: 0,
target: address(instanceManager),
callData: abi.encodeCall(InstanceManager.deploySystemContract, (_contractName, _version))
callData: abi.encodeCall(InstanceManager.deploySystemContract, (_contractName, _version, _saveVersion))
});
}

Expand Down Expand Up @@ -86,7 +87,7 @@ contract InstanceManagerHelper is BCRHelpers, CCGHelper {

function _allowPriceFeed(address token, address _priceFeed) internal {
address ap = instanceManager.addressProvider();
address priceFeedStore = IAddressProvider(ap).getAddressOrRevert(AP_PRICE_FEED_STORE, 3_10);
address priceFeedStore = IAddressProvider(ap).getAddressOrRevert(AP_PRICE_FEED_STORE, NO_VERSION_CONTROL);
vm.prank(instanceOwner);
instanceManager.configureLocal(
priceFeedStore, abi.encodeCall(IPriceFeedStore.allowPriceFeed, (token, _priceFeed))
Expand All @@ -95,7 +96,7 @@ contract InstanceManagerHelper is BCRHelpers, CCGHelper {

function _addPriceFeed(address _priceFeed, uint32 _stalenessPeriod) internal {
address ap = instanceManager.addressProvider();
address priceFeedStore = IAddressProvider(ap).getAddressOrRevert(AP_PRICE_FEED_STORE, 3_10);
address priceFeedStore = IAddressProvider(ap).getAddressOrRevert(AP_PRICE_FEED_STORE, NO_VERSION_CONTROL);
vm.prank(instanceOwner);
instanceManager.configureLocal(
priceFeedStore, abi.encodeCall(IPriceFeedStore.addPriceFeed, (_priceFeed, _stalenessPeriod))
Expand Down
8 changes: 5 additions & 3 deletions contracts/test/suite/NewChainDeploySuite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
AP_LOSS_POLICY_DEFAULT,
AP_CREDIT_MANAGER,
AP_CREDIT_FACADE,
AP_CREDIT_CONFIGURATOR
AP_CREDIT_CONFIGURATOR,
NO_VERSION_CONTROL
} from "../../libraries/ContractLiterals.sol";
import {SignedProposal, Bytecode} from "../../interfaces/Types.sol";

Expand Down Expand Up @@ -72,6 +73,7 @@ import {GlobalSetup} from "../../test/helpers/GlobalSetup.sol";
contract NewChainDeploySuite is Test, GlobalSetup {
address internal riskCurator;

address constant TREASURY = 0x3E965117A51186e41c2BB58b729A1e518A715e5F;
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant GEAR = 0xBa3335588D9403515223F109EdC4eB7269a9Ab5D;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
Expand All @@ -88,7 +90,7 @@ contract NewChainDeploySuite is Test, GlobalSetup {

// activate instance
CrossChainCall[] memory calls = new CrossChainCall[](1);
calls[0] = _generateActivateCall(1, instanceOwner, address(0), WETH, GEAR);
calls[0] = _generateActivateCall(1, instanceOwner, TREASURY, WETH, GEAR);
_submitProposalAndSign(calls);

// Configure instance
Expand All @@ -107,7 +109,7 @@ contract NewChainDeploySuite is Test, GlobalSetup {
function test_NCD_01_createMarket() public {
address ap = instanceManager.addressProvider();

address mcf = IAddressProvider(ap).getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, 3_10);
address mcf = IAddressProvider(ap).getAddressOrRevert(AP_MARKET_CONFIGURATOR_FACTORY, NO_VERSION_CONTROL);

address poolFactory = IAddressProvider(ap).getAddressOrRevert(AP_POOL_FACTORY, 3_10);

Expand Down

0 comments on commit 1df8617

Please sign in to comment.