|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.17; |
| 3 | + |
| 4 | +import {Script} from "forge-std/Script.sol"; |
| 5 | +import {console} from "forge-std/console.sol"; |
| 6 | + |
| 7 | +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; |
| 8 | + |
| 9 | +import {LibString} from "@solady/utils/LibString.sol"; |
| 10 | + |
| 11 | +import {AddressProvider} from "@gearbox-protocol/governance/contracts/global/AddressProvider.sol"; |
| 12 | +import {IACL} from "@gearbox-protocol/governance/contracts/interfaces/extensions/IACL.sol"; |
| 13 | +import { |
| 14 | + AP_ACCOUNT_FACTORY, |
| 15 | + AP_ACL, |
| 16 | + AP_BOT_LIST, |
| 17 | + AP_CONTRACTS_REGISTER, |
| 18 | + AP_DEGEN_DISTRIBUTOR, |
| 19 | + AP_DEGEN_NFT, |
| 20 | + AP_GEAR_STAKING, |
| 21 | + AP_GEAR_TOKEN, |
| 22 | + AP_INFLATION_ATTACK_BLOCKER, |
| 23 | + AP_MARKET_CONFIGURATOR_FACTORY, |
| 24 | + AP_MULTI_PAUSE, |
| 25 | + AP_ROUTER, |
| 26 | + AP_TREASURY, |
| 27 | + AP_WETH_TOKEN, |
| 28 | + AP_ZAPPER_REGISTER, |
| 29 | + AP_ZERO_PRICE_FEED, |
| 30 | + NO_VERSION_CONTROL |
| 31 | +} from "@gearbox-protocol/governance/contracts/libraries/ContractLiterals.sol"; |
| 32 | + |
| 33 | +import {CreditAccountCompressor} from "../contracts/compressors/CreditAccountCompressor.sol"; |
| 34 | +import {MarketCompressor} from "../contracts/compressors/MarketCompressor.sol"; |
| 35 | +import {PriceFeedCompressor} from "../contracts/compressors/PriceFeedCompressor.sol"; |
| 36 | + |
| 37 | +import {MarketConfigurator} from "../contracts/migration/MarketConfigurator.sol"; |
| 38 | + |
| 39 | +struct APMigration { |
| 40 | + bytes32 name; |
| 41 | + uint256 version; |
| 42 | +} |
| 43 | + |
| 44 | +interface IAddressProviderLegacy { |
| 45 | + function getAddressOrRevert(bytes32 key, uint256 version) external view returns (address); |
| 46 | +} |
| 47 | + |
| 48 | +contract MigrateScript is Script { |
| 49 | + using LibString for bytes32; |
| 50 | + |
| 51 | + modifier withBroadcast() { |
| 52 | + vm.startBroadcast(vm.envUint("DEPLOYER_PRIVATE_KEY")); |
| 53 | + _; |
| 54 | + vm.stopBroadcast(); |
| 55 | + } |
| 56 | + |
| 57 | + function deployAddressProvider() external withBroadcast { |
| 58 | + address addressProviderLegacy = vm.envAddress("ADDRESS_PROVIDER"); |
| 59 | + address acl = IAddressProviderLegacy(addressProviderLegacy).getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL); |
| 60 | + |
| 61 | + AddressProvider addressProvider = new AddressProvider(); |
| 62 | + console.log("new address provider:", address(addressProvider)); |
| 63 | + |
| 64 | + addressProvider.transferOwnership(Ownable(acl).owner()); |
| 65 | + |
| 66 | + // NOTE: just some fake address |
| 67 | + addressProvider.setAddress({ |
| 68 | + key: AP_MARKET_CONFIGURATOR_FACTORY.fromSmallString(), |
| 69 | + value: address(1), |
| 70 | + saveVersion: false |
| 71 | + }); |
| 72 | + |
| 73 | + APMigration[16] memory migrations = [ |
| 74 | + APMigration({name: AP_ACCOUNT_FACTORY, version: 0}), |
| 75 | + APMigration({name: AP_BOT_LIST, version: 300}), |
| 76 | + APMigration({name: AP_DEGEN_DISTRIBUTOR, version: 0}), |
| 77 | + APMigration({name: AP_DEGEN_NFT, version: 1}), |
| 78 | + APMigration({name: AP_GEAR_STAKING, version: 300}), |
| 79 | + APMigration({name: AP_GEAR_TOKEN, version: 0}), |
| 80 | + APMigration({name: AP_INFLATION_ATTACK_BLOCKER, version: 300}), |
| 81 | + APMigration({name: AP_MULTI_PAUSE, version: 0}), |
| 82 | + APMigration({name: AP_ROUTER, version: 302}), |
| 83 | + APMigration({name: AP_WETH_TOKEN, version: 0}), |
| 84 | + APMigration({name: AP_ZAPPER_REGISTER, version: 300}), |
| 85 | + APMigration({name: AP_ZERO_PRICE_FEED, version: 0}), |
| 86 | + APMigration({name: "PARTIAL_LIQUIDATION_BOT", version: 300}), |
| 87 | + APMigration({name: "DELEVERAGE_BOT_PEGGED", version: 300}), |
| 88 | + APMigration({name: "DELEVERAGE_BOT_LV", version: 300}), |
| 89 | + APMigration({name: "DELEVERAGE_BOT_HV", version: 300}) |
| 90 | + ]; |
| 91 | + |
| 92 | + uint256 len = migrations.length; |
| 93 | + for (uint256 i; i < len; ++i) { |
| 94 | + string memory key = migrations[i].name.fromSmallString(); |
| 95 | + |
| 96 | + try IAddressProviderLegacy(addressProviderLegacy).getAddressOrRevert( |
| 97 | + migrations[i].name, migrations[i].version |
| 98 | + ) returns (address oldAddress) { |
| 99 | + console.log("migrating", key, oldAddress); |
| 100 | + |
| 101 | + addressProvider.setAddress({ |
| 102 | + key: key, |
| 103 | + value: oldAddress, |
| 104 | + saveVersion: migrations[i].version != NO_VERSION_CONTROL |
| 105 | + }); |
| 106 | + } catch { |
| 107 | + console.log("Failed to migrate", key); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + address priceFeedCompressor = address(new PriceFeedCompressor()); |
| 112 | + addressProvider.setAddress(priceFeedCompressor, true); |
| 113 | + |
| 114 | + address marketCompressor = address(new MarketCompressor(address(addressProvider), priceFeedCompressor)); |
| 115 | + addressProvider.setAddress(marketCompressor, true); |
| 116 | + |
| 117 | + address creditAccountCompressor = address(new CreditAccountCompressor(address(addressProvider))); |
| 118 | + addressProvider.setAddress(creditAccountCompressor, true); |
| 119 | + |
| 120 | + string memory obj1 = "address_provider"; |
| 121 | + vm.serializeAddress(obj1, "addressProvider", address(addressProvider)); |
| 122 | + |
| 123 | + // "Mainnet", "Arbitrum", "Optimism", "Base" |
| 124 | + string memory output = vm.serializeString(obj1, "network", "Mainnet"); |
| 125 | + |
| 126 | + string memory outDir = vm.envOr("OUT_DIR", string(".")); |
| 127 | + vm.writeJson(output, string(abi.encodePacked(outDir, "/address-provider.json"))); |
| 128 | + } |
| 129 | + |
| 130 | + function deployMarketConfigurator() external withBroadcast { |
| 131 | + address addressProviderLegacy = vm.envAddress("ADDRESS_PROVIDER"); |
| 132 | + string memory name = vm.envString("CURATOR_NAME"); |
| 133 | + |
| 134 | + address acl = IAddressProviderLegacy(addressProviderLegacy).getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL); |
| 135 | + address contractsRegister = |
| 136 | + IAddressProviderLegacy(addressProviderLegacy).getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL); |
| 137 | + address treasury = |
| 138 | + IAddressProviderLegacy(addressProviderLegacy).getAddressOrRevert(AP_TREASURY, NO_VERSION_CONTROL); |
| 139 | + address marketConfigurator = address(new MarketConfigurator(name, acl, contractsRegister, treasury)); |
| 140 | + console.log("new market configurator:", marketConfigurator); |
| 141 | + |
| 142 | + string memory obj1 = "market_configurator"; |
| 143 | + vm.serializeAddress(obj1, "marketConfigurator", address(marketConfigurator)); |
| 144 | + |
| 145 | + // "Mainnet", "Arbitrum", "Optimism", "Base" |
| 146 | + string memory output = vm.serializeString(obj1, "network", "Mainnet"); |
| 147 | + |
| 148 | + string memory outDir = vm.envOr("OUT_DIR", string(".")); |
| 149 | + vm.writeJson(output, string.concat(outDir, "/market-configurator-", name, ".json")); |
| 150 | + } |
| 151 | +} |
0 commit comments