From d9c528411c94a67f52e8c1cdfaf863f3c7032db3 Mon Sep 17 00:00:00 2001 From: Dima Lekhovitsky Date: Fri, 16 Jan 2026 17:01:17 +0200 Subject: [PATCH] feat: repo cleanup Removes legacy contracts, adds constant price feed --- contracts/helpers/ConstantPriceFeed.sol | 59 ++++ contracts/helpers/DefaultLossPolicy.sol | 40 --- contracts/libraries/ContractLiterals.sol | 2 +- .../legacy/MarketConfiguratorLegacy.sol | 320 ------------------ .../configuration/ConfigurationTestHelper.sol | 5 +- .../LossPolicyConfiguration.unit.t.sol | 9 +- contracts/test/helpers/GlobalSetup.sol | 82 ++--- contracts/test/suite/NewChainDeploySuite.sol | 32 +- 8 files changed, 102 insertions(+), 447 deletions(-) create mode 100644 contracts/helpers/ConstantPriceFeed.sol delete mode 100644 contracts/helpers/DefaultLossPolicy.sol delete mode 100644 contracts/market/legacy/MarketConfiguratorLegacy.sol diff --git a/contracts/helpers/ConstantPriceFeed.sol b/contracts/helpers/ConstantPriceFeed.sol new file mode 100644 index 0000000..3257481 --- /dev/null +++ b/contracts/helpers/ConstantPriceFeed.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Gearbox Protocol. Generalized leverage for DeFi protocols +// (c) Gearbox Foundation, 2025. +pragma solidity ^0.8.23; + +import {LibString} from "@solady/utils/LibString.sol"; +import {IPriceFeed} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeed.sol"; +import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol"; +import {IncorrectPriceException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol"; +import {AP_CONSTANT_PRICE_FEED} from "../libraries/ContractLiterals.sol"; + +/// @title Constant price feed +/// @notice A simple price feed that returns a constant value set in the constructor +contract ConstantPriceFeed is IPriceFeed, SanityCheckTrait { + using LibString for string; + using LibString for bytes32; + + /// @notice Contract version + uint256 public constant override version = 3_10; + + /// @notice Contract type + bytes32 public constant override contractType = AP_CONSTANT_PRICE_FEED; + + /// @notice Answer precision (always 8 decimals for USD price feeds) + uint8 public constant override decimals = 8; + + /// @notice Indicates that price oracle can skip checks for this price feed's answers + bool public constant override skipPriceCheck = true; + + /// @notice The constant price value to return + int256 public immutable price; + + bytes32 internal descriptionTicker; + + /// @notice Constructor + /// @param _price The constant price value to return (with 8 decimals) + /// @param _descriptionTicker Short form description + constructor(int256 _price, string memory _descriptionTicker) { + if (_price <= 0) revert IncorrectPriceException(); + + price = _price; + descriptionTicker = _descriptionTicker.toSmallString(); + } + + /// @notice Price feed description + function description() external view override returns (string memory) { + return string.concat(descriptionTicker.fromSmallString(), " constant price feed"); + } + + /// @notice Serialized price feed parameters + function serialize() external view override returns (bytes memory) { + return abi.encode(price); + } + + /// @notice Returns the constant USD price of the token with 8 decimals + function latestRoundData() external view override returns (uint80, int256 answer, uint256, uint256, uint80) { + return (0, price, 0, block.timestamp, 0); + } +} diff --git a/contracts/helpers/DefaultLossPolicy.sol b/contracts/helpers/DefaultLossPolicy.sol deleted file mode 100644 index f371956..0000000 --- a/contracts/helpers/DefaultLossPolicy.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// Gearbox Protocol. Generalized leverage for DeFi protocols -// (c) Gearbox Foundation, 2025. -pragma solidity ^0.8.23; - -import {ILossPolicy} from "@gearbox-protocol/core-v3/contracts/interfaces/base/ILossPolicy.sol"; -import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol"; -import {AP_LOSS_POLICY_DEFAULT} from "../libraries/ContractLiterals.sol"; - -contract DefaultLossPolicy is ILossPolicy, ACLTrait { - uint256 public constant override version = 3_10; - bytes32 public constant override contractType = AP_LOSS_POLICY_DEFAULT; - AccessMode public override accessMode = AccessMode.Permissioned; - bool public override checksEnabled = false; - - constructor(address acl_) ACLTrait(acl_) {} - - function serialize() external view override returns (bytes memory) { - return abi.encode(accessMode, checksEnabled); - } - - function isLiquidatableWithLoss(address, address caller, Params calldata) external view override returns (bool) { - AccessMode accessMode_ = accessMode; - if (accessMode_ == AccessMode.Forbidden) return false; - if (accessMode_ == AccessMode.Permissioned && !_hasRole("LOSS_LIQUIDATOR", caller)) return false; - return !checksEnabled; - } - - function setAccessMode(AccessMode mode) external override configuratorOnly { - if (accessMode == mode) return; - accessMode = mode; - emit SetAccessMode(mode); - } - - function setChecksEnabled(bool enabled) external override configuratorOnly { - if (checksEnabled == enabled) return; - checksEnabled = enabled; - emit SetChecksEnabled(enabled); - } -} diff --git a/contracts/libraries/ContractLiterals.sol b/contracts/libraries/ContractLiterals.sol index 95c1500..2c025ea 100644 --- a/contracts/libraries/ContractLiterals.sol +++ b/contracts/libraries/ContractLiterals.sol @@ -11,6 +11,7 @@ bytes32 constant AP_ACL = "ACL"; bytes32 constant AP_ADDRESS_PROVIDER = "ADDRESS_PROVIDER"; bytes32 constant AP_BOT_LIST = "BOT_LIST"; bytes32 constant AP_BYTECODE_REPOSITORY = "BYTECODE_REPOSITORY"; +bytes32 constant AP_CONSTANT_PRICE_FEED = "PRICE_FEED::CONSTANT"; bytes32 constant AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER"; bytes32 constant AP_CREDIT_CONFIGURATOR = "CREDIT_CONFIGURATOR"; bytes32 constant AP_CREDIT_FACADE = "CREDIT_FACADE"; @@ -28,7 +29,6 @@ bytes32 constant AP_INTEREST_RATE_MODEL_DEFAULT = "IRM::DEFAULT"; bytes32 constant AP_INTEREST_RATE_MODEL_FACTORY = "INTEREST_RATE_MODEL_FACTORY"; bytes32 constant AP_INTEREST_RATE_MODEL_LINEAR = "IRM::LINEAR"; bytes32 constant AP_LOSS_POLICY_ALIASED = "LOSS_POLICY::ALIASED"; -bytes32 constant AP_LOSS_POLICY_DEFAULT = "LOSS_POLICY::DEFAULT"; bytes32 constant AP_LOSS_POLICY_FACTORY = "LOSS_POLICY_FACTORY"; bytes32 constant AP_MARKET_CONFIGURATOR = "MARKET_CONFIGURATOR"; bytes32 constant AP_MARKET_CONFIGURATOR_FACTORY = "MARKET_CONFIGURATOR_FACTORY"; diff --git a/contracts/market/legacy/MarketConfiguratorLegacy.sol b/contracts/market/legacy/MarketConfiguratorLegacy.sol deleted file mode 100644 index 6cc9ceb..0000000 --- a/contracts/market/legacy/MarketConfiguratorLegacy.sol +++ /dev/null @@ -1,320 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// Gearbox Protocol. Generalized leverage for DeFi protocols -// (c) Gearbox Foundation, 2025. -pragma solidity ^0.8.23; - -import {Address} from "@openzeppelin/contracts/utils/Address.sol"; -import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; - -import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol"; -import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol"; -import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol"; -import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol"; - -import {DefaultLossPolicy} from "../../helpers/DefaultLossPolicy.sol"; - -import {IACL} from "../../interfaces/IACL.sol"; -import {IContractsRegister} from "../../interfaces/IContractsRegister.sol"; -import {Call, MarketFactories} from "../../interfaces/Types.sol"; - -import { - AP_MARKET_CONFIGURATOR_LEGACY, - AP_CROSS_CHAIN_GOVERNANCE_PROXY, - DOMAIN_ZAPPER, - NO_VERSION_CONTROL, - ROLE_EMERGENCY_LIQUIDATOR, - ROLE_PAUSABLE_ADMIN, - ROLE_UNPAUSABLE_ADMIN -} from "../../libraries/ContractLiterals.sol"; - -import {MarketConfigurator} from "../MarketConfigurator.sol"; - -interface IACLLegacy { - function owner() external view returns (address); - function pendingOwner() external view returns (address); - function transferOwnership(address newOwner) external; - function claimOwnership() external; - - function isPausableAdmin(address account) external view returns (bool); - function addPausableAdmin(address account) external; - function removePausableAdmin(address account) external; - - function isUnpausableAdmin(address account) external view returns (bool); - function addUnpausableAdmin(address account) external; - function removeUnpausableAdmin(address account) external; -} - -interface IContractsRegisterLegacy { - function getPools() external view returns (address[] memory); - function addPool(address pool) external; - function getCreditManagers() external view returns (address[] memory); - function addCreditManager(address creditManager) external; -} - -interface IZapperRegisterLegacy { - function zappers(address pool) external view returns (address[] memory); -} - -struct PeripheryContract { - bytes32 domain; - address addr; -} - -struct LegacyParams { - address acl; - address contractsRegister; - address gearStaking; - address priceOracle; - address zapperRegister; - address[] pausableAdmins; - address[] unpausableAdmins; - address[] emergencyLiquidators; - PeripheryContract[] peripheryContracts; -} - -contract MarketConfiguratorLegacy is MarketConfigurator { - using Address for address; - using EnumerableSet for EnumerableSet.AddressSet; - - uint256 public constant override version = 3_10; - bytes32 public constant override contractType = AP_MARKET_CONFIGURATOR_LEGACY; - - address public immutable crossChainGovernanceProxy; - - address public immutable aclLegacy; - address public immutable contractsRegisterLegacy; - address public immutable gearStakingLegacy; - - error ACLOwnershipNotTransferredException(); - error AddressIsNotPausableAdminException(address admin); - error AddressIsNotUnpausableAdminException(address admin); - error CallerIsNotCrossChainGovernanceProxyException(address caller); - error CallsToLegacyContractsAreForbiddenException(); - error CollateralTokenIsNotQuotedException(address creditManager, address token); - error CreditSuiteAlreadyInitializedException(address creditManager); - error CreditSuiteIsNotInitializedException(address creditManager); - error InconsistentPriceOracleException(address creditManager); - error MarketAlreadyInitializedException(address pool); - error MarketIsNotInitializedException(address pool); - - modifier onlyCrossChainGovernanceProxy() { - _ensureCallerIsCrossChainGovernanceProxy(); - _; - } - - constructor( - address addressProvider_, - address admin_, - address emergencyAdmin_, - address feeSplitterAdmin_, - string memory curatorName_, - bool deployGovernor_, - LegacyParams memory legacyParams_ - ) MarketConfigurator(addressProvider_, admin_, emergencyAdmin_, feeSplitterAdmin_, curatorName_, deployGovernor_) { - crossChainGovernanceProxy = _getAddressOrRevert(AP_CROSS_CHAIN_GOVERNANCE_PROXY, NO_VERSION_CONTROL); - - aclLegacy = legacyParams_.acl; - contractsRegisterLegacy = legacyParams_.contractsRegister; - gearStakingLegacy = legacyParams_.gearStaking; - - // NOTE: there's no way to validate that `legacyParams_.pausableAdmins` and `legacyParams_.unpausableAdmins` - // are exhaustive because the legacy ACL contract doesn't provide needed getters, so don't screw up :) - uint256 num = legacyParams_.pausableAdmins.length; - for (uint256 i; i < num; ++i) { - address pausableAdmin = legacyParams_.pausableAdmins[i]; - if (!IACLLegacy(aclLegacy).isPausableAdmin(pausableAdmin)) { - revert AddressIsNotPausableAdminException(pausableAdmin); - } - IACL(acl).grantRole(ROLE_PAUSABLE_ADMIN, pausableAdmin); - emit GrantRole(ROLE_PAUSABLE_ADMIN, pausableAdmin); - } - num = legacyParams_.unpausableAdmins.length; - for (uint256 i; i < num; ++i) { - address unpausableAdmin = legacyParams_.unpausableAdmins[i]; - if (!IACLLegacy(aclLegacy).isUnpausableAdmin(unpausableAdmin)) { - revert AddressIsNotUnpausableAdminException(unpausableAdmin); - } - IACL(acl).grantRole(ROLE_UNPAUSABLE_ADMIN, unpausableAdmin); - emit GrantRole(ROLE_UNPAUSABLE_ADMIN, unpausableAdmin); - } - num = legacyParams_.emergencyLiquidators.length; - for (uint256 i; i < num; ++i) { - address liquidator = legacyParams_.emergencyLiquidators[i]; - IACL(acl).grantRole(ROLE_EMERGENCY_LIQUIDATOR, liquidator); - emit GrantRole(ROLE_EMERGENCY_LIQUIDATOR, liquidator); - } - - address[] memory pools = IContractsRegisterLegacy(contractsRegisterLegacy).getPools(); - uint256 numPools = pools.length; - for (uint256 i; i < numPools; ++i) { - address pool = pools[i]; - if (!_isV3Contract(pool)) continue; - - address[] memory creditManagers = IPoolV3(pool).creditManagers(); - uint256 numCreditManagers = creditManagers.length; - if (numCreditManagers == 0) continue; - - address quotaKeeper = _quotaKeeper(pool); - address lossPolicy = address(new DefaultLossPolicy(acl)); - IContractsRegister(contractsRegister).registerMarket(pool, legacyParams_.priceOracle, lossPolicy); - - for (uint256 j; j < numCreditManagers; ++j) { - address creditManager = creditManagers[j]; - if (!_isV3Contract(creditManager)) continue; - - if (ICreditManagerV3(creditManager).priceOracle() != legacyParams_.priceOracle) { - revert InconsistentPriceOracleException(creditManager); - } - - uint256 numTokens = ICreditManagerV3(creditManager).collateralTokensCount(); - uint256 quotedTokensMask = ICreditManagerV3(creditManager).quotedTokensMask(); - for (uint256 k = 1; k < numTokens; ++k) { - uint256 tokenMask = 1 << k; - address token = ICreditManagerV3(creditManager).getTokenByMask(tokenMask); - if (!IPoolQuotaKeeperV3(quotaKeeper).isQuotedToken(token) || quotedTokensMask & tokenMask == 0) { - revert CollateralTokenIsNotQuotedException(creditManager, token); - } - } - - IContractsRegister(contractsRegister).registerCreditSuite(creditManager); - } - - address[] memory zappers = IZapperRegisterLegacy(legacyParams_.zapperRegister).zappers(pool); - uint256 numZappers = zappers.length; - for (uint256 j; j < numZappers; ++j) { - _peripheryContracts[DOMAIN_ZAPPER].add(zappers[j]); - emit AddPeripheryContract(DOMAIN_ZAPPER, zappers[j]); - } - } - - uint256 numPeripheryContracts = legacyParams_.peripheryContracts.length; - for (uint256 i; i < numPeripheryContracts; ++i) { - PeripheryContract memory pc = legacyParams_.peripheryContracts[i]; - _peripheryContracts[pc.domain].add(pc.addr); - emit AddPeripheryContract(pc.domain, pc.addr); - } - } - - function initializeMarket(address pool) external { - _ensureRegisteredMarket(pool); - if (_marketFactories[pool].poolFactory != address(0)) revert MarketAlreadyInitializedException(pool); - - MarketFactories memory factories = _getLatestMarketFactories(3_10); - _marketFactories[pool] = factories; - address quotaKeeper = _quotaKeeper(pool); - address priceOracle = IContractsRegister(contractsRegister).getPriceOracle(pool); - address interestRateModel = _interestRateModel(pool); - address rateKeeper = _rateKeeper(quotaKeeper); - address lossPolicy = IContractsRegister(contractsRegister).getLossPolicy(pool); - - // NOTE: authorize factories for contracts that might still be used after the migration; legacy price oracle - // is left unauthorized since it's not gonna be used, IRM is unauthorized since it's not configurable - _authorizeFactory(factories.poolFactory, pool, pool); - _authorizeFactory(factories.poolFactory, pool, quotaKeeper); - _authorizeFactory(factories.rateKeeperFactory, pool, rateKeeper); - _authorizeFactory(factories.lossPolicyFactory, pool, lossPolicy); - - emit CreateMarket(pool, priceOracle, interestRateModel, rateKeeper, lossPolicy, factories); - } - - function initializeCreditSuite(address creditManager) external { - _ensureRegisteredCreditSuite(creditManager); - if (_creditFactories[creditManager] != address(0)) revert CreditSuiteAlreadyInitializedException(creditManager); - - address factory = _getLatestCreditFactory(3_10); - _creditFactories[creditManager] = factory; - - // NOTE: authorizing credit factory for legacy configurator is required since it's used to update to the new one; - // legacy facade and adapters are left unauthorized since they're not gonna be used after the migration - _authorizeFactory(factory, creditManager, ICreditManagerV3(creditManager).creditConfigurator()); - - emit CreateCreditSuite(creditManager, factory); - } - - // ------------- // - // CONFIGURATION // - // ------------- // - - function finalizeMigration() external onlyCrossChainGovernanceProxy { - address[] memory pools = IContractsRegister(contractsRegister).getPools(); - uint256 numPools = pools.length; - for (uint256 i; i < numPools; ++i) { - if (_marketFactories[pools[i]].poolFactory == address(0)) { - revert MarketIsNotInitializedException(pools[i]); - } - } - address[] memory creditManagers = IContractsRegister(contractsRegister).getCreditManagers(); - uint256 numCreditManagers = creditManagers.length; - for (uint256 i; i < numCreditManagers; ++i) { - if (_creditFactories[creditManagers[i]] == address(0)) { - revert CreditSuiteIsNotInitializedException(creditManagers[i]); - } - } - - // NOTE: on some chains, legacy ACL implements a 2-step ownership transfer - try IACLLegacy(aclLegacy).pendingOwner() returns (address pendingOwner) { - if (pendingOwner != address(this)) revert ACLOwnershipNotTransferredException(); - IACLLegacy(aclLegacy).claimOwnership(); - } catch { - if (IACLLegacy(aclLegacy).owner() != address(this)) revert ACLOwnershipNotTransferredException(); - } - - IACLLegacy(aclLegacy).addPausableAdmin(address(this)); - IACLLegacy(aclLegacy).addUnpausableAdmin(address(this)); - } - - function configureGearStaking(bytes calldata data) external onlyCrossChainGovernanceProxy { - gearStakingLegacy.functionCall(data); - } - - function removeLegacyPeripheryContract(bytes32 domain, address peripheryContract) external onlyAdmin { - if (_peripheryContracts[domain].remove(peripheryContract)) { - emit RemovePeripheryContract(domain, peripheryContract); - } - } - - // --------- // - // INTERNALS // - // --------- // - - function _ensureCallerIsCrossChainGovernanceProxy() internal view { - if (msg.sender != crossChainGovernanceProxy) revert CallerIsNotCrossChainGovernanceProxyException(msg.sender); - } - - function _grantRole(bytes32 role, address account) internal override { - super._grantRole(role, account); - if (role == ROLE_PAUSABLE_ADMIN) IACLLegacy(aclLegacy).addPausableAdmin(account); - else if (role == ROLE_UNPAUSABLE_ADMIN) IACLLegacy(aclLegacy).addUnpausableAdmin(account); - } - - function _revokeRole(bytes32 role, address account) internal override { - super._revokeRole(role, account); - if (role == ROLE_PAUSABLE_ADMIN) IACLLegacy(aclLegacy).removePausableAdmin(account); - else if (role == ROLE_UNPAUSABLE_ADMIN) IACLLegacy(aclLegacy).removeUnpausableAdmin(account); - } - - function _registerMarket(address pool, address priceOracle, address lossPolicy) internal override { - super._registerMarket(pool, priceOracle, lossPolicy); - IContractsRegisterLegacy(contractsRegisterLegacy).addPool(pool); - } - - function _registerCreditSuite(address creditManager) internal override { - super._registerCreditSuite(creditManager); - IContractsRegisterLegacy(contractsRegisterLegacy).addCreditManager(creditManager); - } - - function _validateCallTarget(address target, address factory) internal override { - super._validateCallTarget(target, factory); - if (target == aclLegacy || target == contractsRegisterLegacy || target == gearStakingLegacy) { - revert CallsToLegacyContractsAreForbiddenException(); - } - } - - function _isV3Contract(address contract_) internal view returns (bool) { - try IVersion(contract_).version() returns (uint256 version_) { - return version_ >= 300 && version_ < 400; - } catch { - return false; - } - } -} diff --git a/contracts/test/configuration/ConfigurationTestHelper.sol b/contracts/test/configuration/ConfigurationTestHelper.sol index f432965..22e3033 100644 --- a/contracts/test/configuration/ConfigurationTestHelper.sol +++ b/contracts/test/configuration/ConfigurationTestHelper.sol @@ -45,7 +45,6 @@ import { AP_INTEREST_RATE_MODEL_LINEAR, AP_RATE_KEEPER_TUMBLER, AP_RATE_KEEPER_GAUGE, - AP_LOSS_POLICY_DEFAULT, AP_CREDIT_MANAGER, AP_CREDIT_FACADE, AP_CREDIT_CONFIGURATOR, @@ -180,9 +179,7 @@ contract ConfigurationTestHelper is Test, GlobalSetup { address _pool = marketConfigurator.previewCreateMarket(3_10, WETH, name, symbol); DeployParams memory interestRateModelParams = DeployParams({ - postfix: "LINEAR", - salt: 0, - constructorParams: abi.encode(100, 200, 100, 100, 200, 300, false) + postfix: "LINEAR", salt: 0, constructorParams: abi.encode(100, 200, 100, 100, 200, 300, false) }); DeployParams memory rateKeeperParams = DeployParams({postfix: "TUMBLER", salt: 0, constructorParams: abi.encode(_pool, 7 days)}); diff --git a/contracts/test/configuration/LossPolicyConfiguration.unit.t.sol b/contracts/test/configuration/LossPolicyConfiguration.unit.t.sol index c38616a..5f58c9d 100644 --- a/contracts/test/configuration/LossPolicyConfiguration.unit.t.sol +++ b/contracts/test/configuration/LossPolicyConfiguration.unit.t.sol @@ -5,7 +5,6 @@ pragma solidity ^0.8.23; import {ConfigurationTestHelper} from "./ConfigurationTestHelper.sol"; import {ILossPolicy} from "@gearbox-protocol/core-v3/contracts/interfaces/base/ILossPolicy.sol"; -import {DefaultLossPolicy} from "../../helpers/DefaultLossPolicy.sol"; import {IContractsRegister} from "../../interfaces/IContractsRegister.sol"; contract LossPolicyConfigurationUnitTest is ConfigurationTestHelper { @@ -27,7 +26,7 @@ contract LossPolicyConfigurationUnitTest is ConfigurationTestHelper { ); assertEq( - uint8(DefaultLossPolicy(_lossPolicy).accessMode()), + uint8(ILossPolicy(_lossPolicy).accessMode()), uint8(ILossPolicy.AccessMode.Permissioned), "Access mode must be PERMISSIONED" ); @@ -37,7 +36,7 @@ contract LossPolicyConfigurationUnitTest is ConfigurationTestHelper { vm.prank(admin); marketConfigurator.configureLossPolicy(address(pool), abi.encodeCall(ILossPolicy.setChecksEnabled, (true))); - assertTrue(DefaultLossPolicy(_lossPolicy).checksEnabled(), "Checks must be enabled"); + assertTrue(ILossPolicy(_lossPolicy).checksEnabled(), "Checks must be enabled"); } /// EMERGENCY CONFIGURATION TESTS /// @@ -51,7 +50,7 @@ contract LossPolicyConfigurationUnitTest is ConfigurationTestHelper { ); assertEq( - uint8(DefaultLossPolicy(_lossPolicy).accessMode()), + uint8(ILossPolicy(_lossPolicy).accessMode()), uint8(ILossPolicy.AccessMode.Forbidden), "Access mode must be FORBIDDEN" ); @@ -63,6 +62,6 @@ contract LossPolicyConfigurationUnitTest is ConfigurationTestHelper { address(pool), abi.encodeCall(ILossPolicy.setChecksEnabled, (false)) ); - assertFalse(DefaultLossPolicy(_lossPolicy).checksEnabled(), "Checks must be disabled"); + assertFalse(ILossPolicy(_lossPolicy).checksEnabled(), "Checks must be disabled"); } } diff --git a/contracts/test/helpers/GlobalSetup.sol b/contracts/test/helpers/GlobalSetup.sol index bed9e4e..ca8bd36 100644 --- a/contracts/test/helpers/GlobalSetup.sol +++ b/contracts/test/helpers/GlobalSetup.sol @@ -38,7 +38,6 @@ import { AP_RATE_KEEPER_TUMBLER, AP_RATE_KEEPER_GAUGE, AP_LOSS_POLICY_ALIASED, - AP_LOSS_POLICY_DEFAULT, AP_CREDIT_MANAGER, AP_CREDIT_FACADE, AP_CREDIT_CONFIGURATOR, @@ -151,9 +150,8 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload[i].version ); - bool isPublicContract = IBytecodeRepository(bytecodeRepository).isPublicDomain( - Domain.extractDomain(contractsToUpload[i].contractType) - ); + bool isPublicContract = IBytecodeRepository(bytecodeRepository) + .isPublicDomain(Domain.extractDomain(contractsToUpload[i].contractType)); // NOTE: allowing public contracts doesn't require CCG permissions but it's convenient to execute in batch calls[i] = isPublicContract ? _generateAllowPublicContractCall(bytecodeHash) @@ -218,9 +216,7 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(CreditFactory).creationCode, - contractType: AP_CREDIT_FACTORY, - version: 3_10 + initCode: type(CreditFactory).creationCode, contractType: AP_CREDIT_FACTORY, version: 3_10 }) ); @@ -234,25 +230,19 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(PriceFeedStore).creationCode, - contractType: AP_PRICE_FEED_STORE, - version: 3_10 + initCode: type(PriceFeedStore).creationCode, contractType: AP_PRICE_FEED_STORE, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(PriceOracleFactory).creationCode, - contractType: AP_PRICE_ORACLE_FACTORY, - version: 3_10 + initCode: type(PriceOracleFactory).creationCode, contractType: AP_PRICE_ORACLE_FACTORY, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(RateKeeperFactory).creationCode, - contractType: AP_RATE_KEEPER_FACTORY, - version: 3_11 + initCode: type(RateKeeperFactory).creationCode, contractType: AP_RATE_KEEPER_FACTORY, version: 3_11 }) ); @@ -270,9 +260,7 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(TreasurySplitter).creationCode, - contractType: AP_TREASURY_SPLITTER, - version: 3_10 + initCode: type(TreasurySplitter).creationCode, contractType: AP_TREASURY_SPLITTER, version: 3_10 }) ); @@ -282,9 +270,7 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(PoolQuotaKeeperV3).creationCode, - contractType: AP_POOL_QUOTA_KEEPER, - version: 3_10 + initCode: type(PoolQuotaKeeperV3).creationCode, contractType: AP_POOL_QUOTA_KEEPER, version: 3_10 }) ); @@ -294,9 +280,7 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(GearStakingV3).creationCode, - contractType: AP_GEAR_STAKING, - version: 3_10 + initCode: type(GearStakingV3).creationCode, contractType: AP_GEAR_STAKING, version: 3_10 }) ); @@ -310,17 +294,13 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(PriceOracleV3).creationCode, - contractType: AP_PRICE_ORACLE, - version: 3_10 + initCode: type(PriceOracleV3).creationCode, contractType: AP_PRICE_ORACLE, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(MarketConfigurator).creationCode, - contractType: AP_MARKET_CONFIGURATOR, - version: 3_10 + initCode: type(MarketConfigurator).creationCode, contractType: AP_MARKET_CONFIGURATOR, version: 3_10 }) ); @@ -330,49 +310,37 @@ contract GlobalSetup is Test, InstanceManagerHelper { contractsToUpload.push( UploadableContract({ - initCode: type(ContractsRegister).creationCode, - contractType: AP_CONTRACTS_REGISTER, - version: 3_10 + initCode: type(ContractsRegister).creationCode, contractType: AP_CONTRACTS_REGISTER, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(LossPolicyFactory).creationCode, - contractType: AP_LOSS_POLICY_FACTORY, - version: 3_10 + initCode: type(LossPolicyFactory).creationCode, contractType: AP_LOSS_POLICY_FACTORY, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(CreditManagerV3).creationCode, - contractType: AP_CREDIT_MANAGER, - version: 3_10 + initCode: type(CreditManagerV3).creationCode, contractType: AP_CREDIT_MANAGER, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(CreditFacadeV3).creationCode, - contractType: AP_CREDIT_FACADE, - version: 3_10 + initCode: type(CreditFacadeV3).creationCode, contractType: AP_CREDIT_FACADE, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(CreditConfiguratorV3).creationCode, - contractType: AP_CREDIT_CONFIGURATOR, - version: 3_10 + initCode: type(CreditConfiguratorV3).creationCode, contractType: AP_CREDIT_CONFIGURATOR, version: 3_10 }) ); contractsToUpload.push( UploadableContract({ - initCode: type(ZeroPriceFeed).creationCode, - contractType: AP_ZERO_PRICE_FEED, - version: 3_10 + initCode: type(ZeroPriceFeed).creationCode, contractType: AP_ZERO_PRICE_FEED, version: 3_10 }) ); } @@ -380,9 +348,7 @@ contract GlobalSetup is Test, InstanceManagerHelper { function _setInterestRateModels() internal { contractsToUpload.push( UploadableContract({ - initCode: type(LinearInterestRateModelV3).creationCode, - contractType: "IRM::LINEAR", - version: 3_10 + initCode: type(LinearInterestRateModelV3).creationCode, contractType: "IRM::LINEAR", version: 3_10 }) ); } @@ -390,23 +356,21 @@ contract GlobalSetup is Test, InstanceManagerHelper { function _setLossPolicies() internal { contractsToUpload.push( UploadableContract({ - initCode: type(AliasedLossPolicyV3).creationCode, - contractType: "LOSS_POLICY::ALIASED", - version: 3_10 + initCode: type(AliasedLossPolicyV3).creationCode, contractType: "LOSS_POLICY::ALIASED", version: 3_10 }) ); } function _setRateKeepers() internal { contractsToUpload.push( - UploadableContract({initCode: type(GaugeV3).creationCode, contractType: "RATE_KEEPER::GAUGE", version: 3_10}) + UploadableContract({ + initCode: type(GaugeV3).creationCode, contractType: "RATE_KEEPER::GAUGE", version: 3_10 + }) ); contractsToUpload.push( UploadableContract({ - initCode: type(TumblerV3).creationCode, - contractType: "RATE_KEEPER::TUMBLER", - version: 3_10 + initCode: type(TumblerV3).creationCode, contractType: "RATE_KEEPER::TUMBLER", version: 3_10 }) ); } diff --git a/contracts/test/suite/NewChainDeploySuite.sol b/contracts/test/suite/NewChainDeploySuite.sol index ea7176f..fd3335e 100644 --- a/contracts/test/suite/NewChainDeploySuite.sol +++ b/contracts/test/suite/NewChainDeploySuite.sol @@ -34,7 +34,6 @@ import { AP_INTEREST_RATE_MODEL_LINEAR, AP_RATE_KEEPER_TUMBLER, AP_RATE_KEEPER_GAUGE, - AP_LOSS_POLICY_DEFAULT, AP_CREDIT_MANAGER, AP_CREDIT_FACADE, AP_CREDIT_CONFIGURATOR, @@ -61,7 +60,6 @@ import {PriceOracleV3} from "@gearbox-protocol/core-v3/contracts/core/PriceOracl import {LinearInterestRateModelV3} from "@gearbox-protocol/core-v3/contracts/pool/LinearInterestRateModelV3.sol"; import {TumblerV3} from "@gearbox-protocol/core-v3/contracts/pool/TumblerV3.sol"; import {GaugeV3} from "@gearbox-protocol/core-v3/contracts/pool/GaugeV3.sol"; -import {DefaultLossPolicy} from "../../helpers/DefaultLossPolicy.sol"; import {CreditManagerV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditManagerV3.sol"; import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol"; import {CreditConfiguratorV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditConfiguratorV3.sol"; @@ -151,9 +149,8 @@ contract NewChainDeploySuite is Test, GlobalSetup { uint256 gasBefore = gasleft(); vm.startPrank(riskCurator); - address mc = MarketConfiguratorFactory(mcf).createMarketConfigurator( - riskCurator, riskCurator, "Test Risk Curator", false - ); + address mc = MarketConfiguratorFactory(mcf) + .createMarketConfigurator(riskCurator, riskCurator, "Test Risk Curator", false); uint256 gasAfter = gasleft(); uint256 used = gasBefore - gasAfter; @@ -163,9 +160,7 @@ contract NewChainDeploySuite is Test, GlobalSetup { address pool = MarketConfigurator(mc).previewCreateMarket(3_10, WETH, name, symbol); DeployParams memory interestRateModelParams = DeployParams({ - postfix: "LINEAR", - salt: 0, - constructorParams: abi.encode(100, 200, 100, 100, 200, 300, false) + postfix: "LINEAR", salt: 0, constructorParams: abi.encode(100, 200, 100, 100, 200, 300, false) }); DeployParams memory rateKeeperParams = DeployParams({postfix: "TUMBLER", salt: 0, constructorParams: abi.encode(pool, 7 days)}); @@ -174,16 +169,17 @@ contract NewChainDeploySuite is Test, GlobalSetup { gasBefore = gasleft(); - address poolFromMarket = MarketConfigurator(mc).createMarket({ - minorVersion: 3_10, - underlying: WETH, - name: name, - symbol: symbol, - interestRateModelParams: interestRateModelParams, - rateKeeperParams: rateKeeperParams, - lossPolicyParams: lossPolicyParams, - underlyingPriceFeed: CHAINLINK_ETH_USD - }); + address poolFromMarket = MarketConfigurator(mc) + .createMarket({ + minorVersion: 3_10, + underlying: WETH, + name: name, + symbol: symbol, + interestRateModelParams: interestRateModelParams, + rateKeeperParams: rateKeeperParams, + lossPolicyParams: lossPolicyParams, + underlyingPriceFeed: CHAINLINK_ETH_USD + }); gasAfter = gasleft(); used = gasBefore - gasAfter;