Skip to content

Commit

Permalink
fix: migrate script updated
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmikko committed Aug 30, 2024
1 parent 9dd7ab8 commit 55b81e9
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 42 deletions.
4 changes: 3 additions & 1 deletion contracts/factories/AdapterFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.8.17;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";

import {AP_ADAPTER_FACTORY} from "../libraries/ContractLiterals.sol";

interface IAdapterDeployer {
function deploy(address creditManager, address target, bytes calldata specificParams) external returns (address);
}
Expand All @@ -15,7 +17,7 @@ contract AdapterFactoryV3 is IVersion {

/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "ADAPTER_FACTORY";
bytes32 public constant override contractType = AP_ADAPTER_FACTORY;

mapping(address => uint8) public targetTypes;
mapping(uint8 => mapping(uint256 => address)) public adapterDeployers;
Expand Down
9 changes: 7 additions & 2 deletions contracts/factories/CreditFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import {CreditManagerV3} from "@gearbox-protocol/core-v3/contracts/credit/Credit
import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol";

import {AbstractFactory} from "./AbstractFactory.sol";
import {AP_CREDIT_MANAGER, AP_CREDIT_FACADE, AP_CREDIT_CONFIGURATOR} from "../libraries/ContractLiterals.sol";
import {
AP_CREDIT_MANAGER,
AP_CREDIT_FACADE,
AP_CREDIT_CONFIGURATOR,
AP_CREDIT_FACTORY
} from "../libraries/ContractLiterals.sol";
import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol";

contract CreditFactoryV3 is AbstractFactory, IVersion {
/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "CREDIT_FACTORY";
bytes32 public constant override contractType = AP_CREDIT_FACTORY;

constructor(address _addressProvider) AbstractFactory(_addressProvider) {}

Expand Down
4 changes: 3 additions & 1 deletion contracts/factories/InterestModelFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

import {AP_INTEREST_MODEL_FACTORY} from "../libraries/ContractLiterals.sol";

contract InterestModelFactory is IVersion {
using EnumerableSet for EnumerableSet.AddressSet;

Expand All @@ -16,7 +18,7 @@ contract InterestModelFactory is IVersion {
event AddNewModel(address);

uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "INTEREST_MODEL_FACTORY";
bytes32 public constant override contractType = AP_INTEREST_MODEL_FACTORY;

EnumerableSet.AddressSet internal _modelDeployers;

Expand Down
4 changes: 2 additions & 2 deletions contracts/factories/MarketConfiguratorFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {IAddressProviderV3} from "../interfaces/IAddressProviderV3.sol";
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";

import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol";
import {AP_MARKET_CONFIGURATOR} from "../libraries/ContractLiterals.sol";
import {AP_MARKET_CONFIGURATOR, AP_MARKET_CONFIGURATOR_FACTORY} from "../libraries/ContractLiterals.sol";

interface IAdapterDeployer {
function deploy(address creditManager, address target, bytes calldata specificParams) external returns (address);
Expand All @@ -23,7 +23,7 @@ contract MarketConfiguratorFactoryV3 is AbstractFactory, IVersion {

/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "MARKET_CONFIGURATOR_FACTORY";
bytes32 public constant override contractType = AP_MARKET_CONFIGURATOR_FACTORY;

uint256 public latestMCversion;

Expand Down
10 changes: 8 additions & 2 deletions contracts/factories/PoolFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ pragma solidity ^0.8.17;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
import {AbstractFactory} from "./AbstractFactory.sol";
import {AP_POOL, AP_POOL_QUOTA_KEEPER, AP_POOL_RATE_KEEPER, AP_DEGEN_NFT} from "../libraries/ContractLiterals.sol";
import {
AP_POOL,
AP_POOL_QUOTA_KEEPER,
AP_POOL_RATE_KEEPER,
AP_DEGEN_NFT,
AP_POOL_FACTORY
} from "../libraries/ContractLiterals.sol";
import {IMarketConfiguratorV3} from "../interfaces/IMarketConfiguratorV3.sol";
import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol";
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
Expand All @@ -19,7 +25,7 @@ contract PoolFactoryV3 is AbstractFactory, IVersion {
/// @notice Contract version

uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "POOL_FACTORY";
bytes32 public constant override contractType = AP_POOL_FACTORY;

constructor(address _addressProvider) AbstractFactory(_addressProvider) {}

Expand Down
5 changes: 3 additions & 2 deletions contracts/factories/PriceOracleFactoryV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol"
import {PriceFeedValidationTrait} from "@gearbox-protocol/core-v3/contracts/traits/PriceFeedValidationTrait.sol";

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

import {AbstractFactory} from "./AbstractFactory.sol";

import {AP_PRICE_ORACLE_FACTORY} from "../libraries/ContractLiterals.sol";

contract PriceOracleFactoryV3 is AbstractFactory, PriceFeedValidationTrait, IVersion {
using EnumerableSet for EnumerableSet.AddressSet;

/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "PRICE_ORACLE_FACTORY";
bytes32 public constant override contractType = AP_PRICE_ORACLE_FACTORY;

uint256 poLatestVersion;

Expand Down
5 changes: 3 additions & 2 deletions contracts/global/AddressProviderV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {IAccountFactoryV3} from "@gearbox-protocol/core-v3/contracts/interfaces/
import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";

import {
AP_ADDRESS_PROVIDER,
AP_MARKET_CONFIGURATOR_FACTORY,
AP_BOT_LIST,
AP_ACCOUNT_FACTORY,
Expand All @@ -37,7 +38,7 @@ contract AddressProviderV3_1 is Ownable2Step, IAddressProviderV3 {

/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "ADDRESS_PROVIDER";
bytes32 public constant override contractType = AP_ADDRESS_PROVIDER;

error MarketConfiguratorsOnlyException();
error CantRemoveMarketConfiguratorWithExistingPoolsException();
Expand All @@ -63,7 +64,7 @@ contract AddressProviderV3_1 is Ownable2Step, IAddressProviderV3 {

constructor() {
// The first event is emitted for the address provider itself to aid in contract discovery
emit SetAddress("ADDRESS_PROVIDER", address(this), version);
emit SetAddress(AP_ADDRESS_PROVIDER.fromSmallString(), address(this), version);
}

/// @notice Returns the address of a contract with a given key and version
Expand Down
3 changes: 2 additions & 1 deletion contracts/global/BytecodeRepository.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pragma solidity ^0.8.17;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {IBytecodeRepository} from "../interfaces/IBytecodeRepository.sol";
import {AP_BYTECODE_REPOSITORY} from "../libraries/ContractLiterals.sol";

struct BytecodeInfo {
bytes32 contractType;
Expand All @@ -18,7 +19,7 @@ contract BytecodeRepository is IBytecodeRepository {
/// @notice Contract version

uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "BYTECODE_REPOSITORY_";
bytes32 public constant override contractType = AP_BYTECODE_REPOSITORY;

error BytecodeNotFound(bytes32 _hash);
error BytecodeAllreadyExists(bytes32 contractType, uint256 version);
Expand Down
7 changes: 4 additions & 3 deletions contracts/libraries/ContractLiterals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ pragma solidity ^0.8.17;

uint256 constant NO_VERSION_CONTROL = 0;

// bytes32 constant AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER";
// bytes32 constant AP_ACL = "ACL";

bytes32 constant AP_ACL = "ACL";
bytes32 constant AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER";

bytes32 constant AP_ADDRESS_PROVIDER = "ADDRESS_PROVIDER";
bytes32 constant AP_CONTROLLER_TIMELOCK = "CONTROLLER_TIMELOCK";

bytes32 constant AP_POOL = "LP";
bytes32 constant AP_POOL_QUOTA_KEEPER = "POOL_QUOTA_KEEPER";
Expand Down
4 changes: 3 additions & 1 deletion contracts/market/ACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IACL} from "../interfaces/IACL.sol";

import {AP_ACL} from "../libraries/ContractLiterals.sol";

/// @title ACL contract that stores admin addresses
/// More info: https://dev.gearbox.fi/security/roles
contract ACL is IACL, Ownable {
Expand All @@ -18,7 +20,7 @@ contract ACL is IACL, Ownable {

// Contract version
uint256 public constant version = 3_10;
bytes32 public constant contractType = "ACL";
bytes32 public constant contractType = AP_ACL;

/// @dev Adds an address to the set of admins that can pause contracts
/// @param admin Address of a new pausable admin
Expand Down
4 changes: 3 additions & 1 deletion contracts/market/ContractsRegister.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
import {IContractsRegister} from "../interfaces/IContractsRegister.sol";

import {AP_CONTRACTS_REGISTER} from "../libraries/ContractLiterals.sol";

contract ContractsRegister is ACLTrait, IContractsRegister {
using EnumerableSet for EnumerableSet.AddressSet;

/// @notice Contract version
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = "CONTRACTS_REGISTER";
bytes32 public constant override contractType = AP_CONTRACTS_REGISTER;

EnumerableSet.AddressSet internal _pools;
EnumerableSet.AddressSet internal _creditManagers;
Expand Down
6 changes: 4 additions & 2 deletions contracts/market/ControllerTimelockV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {IGaugeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IGaugeV3.
import {IPriceOracleV3, PriceFeedParams} from "@gearbox-protocol/core-v3/contracts/interfaces/IPriceOracleV3.sol";
import {ILPPriceFeed} from "@gearbox-protocol/oracles-v3/contracts/interfaces/ILPPriceFeed.sol";

import {AP_CONTROLLER_TIMELOCK} from "../libraries/ContractLiterals.sol";

/// @title Controller timelock V3
/// @notice Controller timelock is a governance contract that allows special actors less trusted than Gearbox Governance
/// to modify system parameters within set boundaries. This is mostly related to risk parameters that should be
Expand All @@ -25,8 +27,8 @@ import {ILPPriceFeed} from "@gearbox-protocol/oracles-v3/contracts/interfaces/IL
/// for it. The policy also determines the address that can change a particular parameter.
contract ControllerTimelockV3 is PolicyManagerV3, IControllerTimelockV3 {
/// @notice Contract version
uint256 public constant override version = 3_1;
bytes32 public constant override contractType = "CONTROLLER_TIMELOCK";
uint256 public constant override version = 3_10;
bytes32 public constant override contractType = AP_CONTROLLER_TIMELOCK;

/// @dev Minimum liquidation threshold ramp duration
uint256 constant MIN_LT_RAMP_DURATION = 7 days;
Expand Down
5 changes: 3 additions & 2 deletions contracts/market/MarketConfigurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
AP_INTEREST_MODEL_FACTORY,
AP_POOL_FACTORY,
AP_CREDIT_FACTORY,
AP_PRICE_ORACLE_FACTORY
AP_PRICE_ORACLE_FACTORY,
AP_MARKET_CONFIGURATOR
} from "../libraries/ContractLiterals.sol";
import {ControllerTimelockV3} from "./ControllerTimelockV3.sol";

Expand All @@ -56,7 +57,7 @@ contract MarketConfigurator is ACLTrait, IMarketConfiguratorV3 {
/// @notice Contract version
uint256 public constant override version = 3_10;

bytes32 public constant contractType = "MC_";
bytes32 public constant contractType = AP_MARKET_CONFIGURATOR;

error InterestModelNotAllowedException(address);

Expand Down
14 changes: 9 additions & 5 deletions contracts/market/MarketConfiguratorLegacy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ import {IACL} from "../interfaces/IACL.sol";
import {ACL} from "./ACL.sol";

import {
AP_ACL,
AP_CONTRACTS_REGISTER,
AP_TREASURY,
AP_ACCOUNT_FACTORY,
AP_DEGEN_NFT,
AP_POOL,
AP_POOL_QUOTA_KEEPER,
AP_POOL_RATE_KEEPER,
Expand All @@ -61,15 +65,15 @@ contract MarketConfiguratorLegacy is MarketConfigurator {
constructor(address _oldAddressProvider, address _newAddressProvider, string memory _name, address _vetoAdmin)
MarketConfigurator(
_newAddressProvider,
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert("ACL", NO_VERSION_CONTROL),
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert("CONTRACTS_REGISTER", NO_VERSION_CONTROL),
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert("TREASURY", NO_VERSION_CONTROL),
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL),
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL),
IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert(AP_TREASURY, NO_VERSION_CONTROL),
_name,
_vetoAdmin
)
{
/// Convert existing pools into markets
address priceOracle = IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert("PRICE_ORACLE", 300);
address priceOracle = IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert(AP_PRICE_ORACLE, 300);

address[] memory _pools = pools();
uint256 len = _pools.length;
Expand All @@ -83,7 +87,7 @@ contract MarketConfiguratorLegacy is MarketConfigurator {
}

// import degenNFT
address degenNFT = IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert("DEGEN_NFT", 1);
address degenNFT = IAddressProviderV3Legacy(_oldAddressProvider).getAddressOrRevert(AP_DEGEN_NFT, 1);
_degenNFTs.add(degenNFT);
emit DeployDegenNFT(degenNFT);
}
Expand Down
30 changes: 15 additions & 15 deletions script/Migrate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {IAddressProviderV3} from "../contracts/interfaces/IAddressProviderV3.sol
import {AddressProviderV3_1} from "../contracts/global/AddressProviderV3.sol";

import {
AP_ADDRESS_PROVIDER,
AP_ACL,
AP_WETH_TOKEN,
AP_GEAR_STAKING,
AP_ACCOUNT_FACTORY,
Expand Down Expand Up @@ -60,15 +62,24 @@ interface IAddressProviderV3Legacy {
address constant emergencyLiquidator = 0x7BD9c8161836b1F402233E80F55E3CaE0Fde4d87;

contract Migrate is Script {
function run() external {
function run() external virtual {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
address oldAddressProvider = vm.envAddress("ADDRESS_PROVIDER");
address vetoAdmin = vm.envAddress("VETO_ADMIN");

address acl = IAddressProviderV3Legacy(oldAddressProvider).getAddressOrRevert("ACL", NO_VERSION_CONTROL);

vm.startBroadcast(deployerPrivateKey);

_deployGovernance3_1(oldAddressProvider, vetoAdmin, deployer);

vm.stopBroadcast();
}

function _deployGovernance3_1(address oldAddressProvider, address vetoAdmin, address deployer)
internal
returns (address)
{
address acl = IAddressProviderV3Legacy(oldAddressProvider).getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL);
AddressProviderV3_1 _addressProvider = new AddressProviderV3_1();
console.log("new address provider:", address(_addressProvider));

Expand Down Expand Up @@ -153,17 +164,6 @@ contract Migrate is Script {
factory = address(new MarketConfiguratorFactoryV3(address(_addressProvider)));
_addressProvider.setAddress(factory, false);

vm.stopBroadcast();
}

function stringToBytes32(string memory source) public pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}

assembly {
result := mload(add(source, 32))
}
return address(_addressProvider);
}
}

0 comments on commit 55b81e9

Please sign in to comment.