diff --git a/.openzeppelin/sepolia.json b/.openzeppelin/sepolia.json index 90d50f25..b8705eac 100644 --- a/.openzeppelin/sepolia.json +++ b/.openzeppelin/sepolia.json @@ -784,6 +784,11 @@ "address": "0x75726da161ef6aE712e941E00705879715b260f6", "txHash": "0xcb8a84e91a264b44fc00c807ea3736e68d2fa84562889cbd9062d8747963febb", "kind": "transparent" + }, + { + "address": "0x918539ab47a93bA64cdaa2923Ef0Fd07aeb208D5", + "txHash": "0xc243e35f1ccef6c0b694a5d8fadc1d5f835ca095709139b43f33e3de12dde595", + "kind": "transparent" } ], "impls": { @@ -47511,6 +47516,120 @@ } } } + }, + "6d838117edf6833c74149c4daf15a65a3ce1d9f7088af7b7c3517a631f80ea95": { + "address": "0xdcf061D9FD1AbC9A12deF64fe5AEe2C961aB2091", + "txHash": "0xb08e368137061b717e9e4988e6d330d048b3645a1f4380930ee449bcf0a78ffe", + "layout": { + "solcVersion": "0.8.22", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36" + }, + { + "label": "__gap", + "offset": 0, + "slot": "51", + "type": "t_array(t_uint256)50_storage", + "contract": "ERC165Upgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol:41" + }, + { + "label": "_roles", + "offset": 0, + "slot": "101", + "type": "t_mapping(t_bytes32,t_struct(RoleData)9957_storage)", + "contract": "AccessControlUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol:62" + }, + { + "label": "__gap", + "offset": 0, + "slot": "102", + "type": "t_array(t_uint256)49_storage", + "contract": "AccessControlUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol:260" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_bool)": { + "label": "mapping(address => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_struct(RoleData)9957_storage)": { + "label": "mapping(bytes32 => struct AccessControlUpgradeable.RoleData)", + "numberOfBytes": "32" + }, + "t_struct(RoleData)9957_storage": { + "label": "struct AccessControlUpgradeable.RoleData", + "members": [ + { + "label": "members", + "type": "t_mapping(t_address,t_bool)", + "offset": 0, + "slot": "0" + }, + { + "label": "adminRole", + "type": "t_bytes32", + "offset": 0, + "slot": "1" + } + ], + "numberOfBytes": "64" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + } + } } } } diff --git a/helpers/utils.ts b/helpers/utils.ts index 8ac334c1..d3335baa 100644 --- a/helpers/utils.ts +++ b/helpers/utils.ts @@ -66,40 +66,17 @@ export const getMTokenOrThrow = (hre: HardhatRuntimeEnvironment) => { return mToken; }; -export const getOriginalNetwork = (hre: HardhatRuntimeEnvironment) => { - const originalNetwork = hre.layerZero?.originalNetwork; - return originalNetwork; -}; - -export const getOriginalNetworkOrThrow = (hre: HardhatRuntimeEnvironment) => { - const originalNetwork = hre.layerZero?.originalNetwork; - if (!originalNetwork) { - throw new Error('OriginalNetwork parameter not found'); - } - return originalNetwork; -}; - -export const getPaymentTokenOrThrow = (hre: HardhatRuntimeEnvironment) => { - const paymentToken = hre.paymentToken; - if (!paymentToken) { - throw new Error('PaymentToken parameter not found'); - } - return paymentToken; -}; - -export const getActionOrThrow = (hre: HardhatRuntimeEnvironment) => { - const action = hre.action; - if (!action) { - throw new Error('Action parameter not found'); - } - return action; -}; - -export const getMTokenOrPaymentTokenOrThrow = ( - hre: HardhatRuntimeEnvironment, -) => { - const mToken = hre.mtoken; - const paymentToken = hre.paymentToken; +export type MTokenOrPaymentToken = + | { mToken: MTokenName; paymentToken?: undefined } + | { mToken?: undefined; paymentToken: PaymentTokenName }; + +/** + * Validates that exactly one of `mToken` / `paymentToken` is provided. + */ +export const requireOneOfMTokenOrPaymentToken = ( + mToken?: MTokenName, + paymentToken?: PaymentTokenName, +): MTokenOrPaymentToken => { if (mToken && paymentToken) { throw new Error('Only one of MToken or PaymentToken can be provided'); } @@ -115,6 +92,10 @@ export const getMTokenOrPaymentTokenOrThrow = ( throw new Error('MToken or PaymentToken parameter not found'); }; +export const getMTokenOrPaymentTokenOrThrow = ( + hre: HardhatRuntimeEnvironment, +) => requireOneOfMTokenOrPaymentToken(hre.mtoken, hre.paymentToken); + export const getImplAddressFromProxy = async ( hre: HardhatRuntimeEnvironment, proxyAddress: string, diff --git a/package.json b/package.json index 555342a9..b8bf7bfa 100644 --- a/package.json +++ b/package.json @@ -38,69 +38,10 @@ "codestyle:fix": "run-s \"lint:*:*\" \"format:*:*\"", "hh:run": "yarn hardhat run", "hh:run:script": "yarn hardhat runscript", - "deploy:ac": "yarn hh:run:script scripts/deploy/deploy_AccessControl.ts", - "deploy:timelock": "yarn hh:run:script scripts/deploy/deploy_TimeLock.ts", - "deploy:token": "yarn hh:run:script scripts/deploy/deploy_Token.ts", - "deploy:aggregator": "yarn hh:run:script scripts/deploy/deploy_CustomAggregator.ts", - "deploy:aggregator:adjusted": "yarn hh:run:script scripts/deploy/misc/deploy_CustomAggregatorAdjusted.ts", - "deploy:aggregator:adjusted:dv": "yarn hh:run:script scripts/deploy/misc/deploy_CustomAggregatorAdjustedDv.ts", - "deploy:aggregator:adjusted:rv": "yarn hh:run:script scripts/deploy/misc/deploy_CustomAggregatorAdjustedRv.ts", - "deploy:aggregator:ptoken": "yarn hh:run:script scripts/deploy/deploy_PaymentToken_CustomAggregator.ts", - "deploy:feed": "yarn hh:run:script scripts/deploy/deploy_DataFeed.ts", - "deploy:feed:dv": "yarn hh:run:script scripts/deploy/deploy_DataFeedDv.ts", - "deploy:feed:rv": "yarn hh:run:script scripts/deploy/deploy_DataFeedRv.ts", - "deploy:feed:ptoken": "yarn hh:run:script scripts/deploy/deploy_PaymentToken_DataFeed.ts", - "deploy:dv": "yarn hh:run:script scripts/deploy/deploy_DV.ts", - "deploy:dv:ustb": "yarn hh:run:script scripts/deploy/deploy_DVUstb.ts", - "deploy:dv:aave": "yarn hh:run:script scripts/deploy/deploy_DVAave.ts", - "deploy:dv:morpho": "yarn hh:run:script scripts/deploy/deploy_DVMorpho.ts", - "deploy:dv:mtoken": "yarn hh:run:script scripts/deploy/deploy_DVMToken.ts", - "deploy:rv": "yarn hh:run:script scripts/deploy/deploy_RV.ts", - "deploy:rv:swapper": "yarn hh:run:script scripts/deploy/deploy_RVSwapper.ts", - "deploy:rv:aave": "yarn hh:run:script scripts/deploy/deploy_RVAave.ts", - "deploy:rv:morpho": "yarn hh:run:script scripts/deploy/deploy_RVMorpho.ts", - "deploy:rv:mtoken": "yarn hh:run:script scripts/deploy/deploy_RVMToken.ts", - "deploy:generate:contracts": "yarn hh:run:script scripts/deploy/codegen/generate_contracts.ts", - "deploy:generate:config": "yarn hh:run:script scripts/deploy/codegen/generate_config.ts", - "deploy:post:add:ptokens": "yarn hh:run:script scripts/deploy/post-deploy/add_PaymentTokens.ts", - "deploy:post:grant:roles": "yarn hh:run:script scripts/deploy/post-deploy/grant_AllProductRoles.ts", - "deploy:post:grant:admin": "yarn hh:run:script scripts/deploy/post-deploy/grant_DefaultAdminRole.ts", - "deploy:post:revoke:roles": "yarn hh:run:script scripts/deploy/post-deploy/revoke_DeployerRoles.ts", - "deploy:post:transfer:proxyadmin": "yarn hh:run:script scripts/deploy/post-deploy/transfer_ProxyAdminToTimelock.ts", - "deploy:post:set:price": "yarn hh:run:script scripts/deploy/post-deploy/set_RoundData.ts", - "deploy:post:set:expected-answers": "yarn hh:run:script scripts/deploy/post-deploy/set_ExpectedAnswers.ts", - "deploy:post:set:waived": "yarn hh:run:script scripts/deploy/post-deploy/add_FeeWaived.ts", - "deploy:post:set:greenlist": "yarn hh:run:script scripts/deploy/post-deploy/set_Greenlist.ts", - "timelock:upgrade:vaults:propose": "yarn hh:run:script scripts/upgrades/proposeUpgrade_Vaults.ts", - "timelock:upgrade:vaults:execute": "yarn hh:run:script scripts/upgrades/executeUpgrade_Vaults.ts", - "timelock:upgrade:vaults:validate": "yarn hh:run:script scripts/upgrades/validateUpgrade_Vaults.ts", - "timelock:admin:transfer:propose": "yarn hh:run:script scripts/upgrades/proposeTransferOwnership_ProxyAdmin.ts", - "timelock:admin:transfer:execute": "yarn hh:run:script scripts/upgrades/executeTransferOwnership_ProxyAdmin.ts", - "deploy:post:pause:functions": "yarn hh:run:script scripts/deploy/post-deploy/pause_Functions.ts", - "deploy:post:add:addressbook": "yarn hh:run:script scripts/deploy/post-deploy/add_ToAddressBook.ts", - "deploy:lz:composer": "yarn hh:run:script scripts/deploy/misc/layerzero/deploy_Composer.ts", - "deploy:lz:oft": "yarn hh:run:script scripts/deploy/misc/layerzero/deploy_OFT.ts", - "deploy:lz:oft:adapter": "yarn hh:run:script scripts/deploy/misc/layerzero/deploy_OFTAdapter.ts", - "deploy:lz:oft:adapter:mintburn": "yarn hh:run:script scripts/deploy/misc/layerzero/deploy_MintBurnOFTAdapter.ts", - "deploy:lz:post:set:ratelimit": "yarn hh:run:script scripts/deploy/misc/layerzero/set_RateLimitConfigs.ts", - "deploy:lz:post:transfer:owner": "yarn hh:run:script scripts/deploy/misc/layerzero/transfer_Owner.ts", - "deploy:lz:post:grant:roles": "yarn hh:run:script scripts/deploy/misc/layerzero/grant_Roles.ts", - "deploy:lz:post:revoke:roles": "yarn hh:run:script scripts/deploy/misc/layerzero/revoke_Roles.ts", "deploy:lz:post:wire": "yarn hardhat lz:oapp:wire:midas", - "deploy:lz:deprecate": "yarn hh:run:script scripts/deploy/misc/layerzero/deprecate_Ofts.ts", - "deploy:axelar:executable": "yarn hh:run:script scripts/deploy/misc/axelar/deploy_Executable.ts", - "deploy:axelar:post:wire": "yarn hh:run:script scripts/deploy/misc/axelar/wire_Tokens.ts", - "deploy:axelar:post:wire:ptoken": "yarn hh:run:script scripts/deploy/misc/axelar/wire_PaymentTokens.ts", - "deploy:axelar:post:set:flowlimit": "yarn hh:run:script scripts/deploy/misc/axelar/set_FlowLimit.ts", - "deploy:axelar:post:grant:roles": "yarn hh:run:script scripts/deploy/misc/axelar/grant_Roles.ts", - "deploy:axelar:post:revoke:roles": "yarn hh:run:script scripts/deploy/misc/axelar/revoke_Roles.ts", - "deploy:post:set:sanctionsList": "yarn hh:run:script scripts/deploy/post-deploy/set_SanctionsList.ts", - "deploy:post:set:aaveconfig": "yarn hh:run:script scripts/deploy/post-deploy/set_AaveConfig.ts", - "deploy:post:set:morphoconfig": "yarn hh:run:script scripts/deploy/post-deploy/set_MorphoConfig.ts", "verify:proxy": "yarn hardhat verify-transparent-proxy", "verify:sourcify": "VERIFY_SOURCIFY=true VERIFY_ETHERSCAN=false yarn hardhat verify", "dump:roles": "yarn hh:run scripts/dump_roles.ts", - "verify:all:impl": "yarn hh:run:script scripts/verify_contracts.ts", "oz:merge-manifest": "ts-node scripts/merge-oz-manifests.ts" }, "devDependencies": { diff --git a/scripts/deploy/codegen/generate_config.ts b/scripts/deploy/codegen/generate_config.ts index 5d2534f7..b8e69440 100644 --- a/scripts/deploy/codegen/generate_config.ts +++ b/scripts/deploy/codegen/generate_config.ts @@ -2,11 +2,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { generateDeploymentConfig } from './common'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await generateDeploymentConfig(hre, mToken); }; diff --git a/scripts/deploy/common/types.ts b/scripts/deploy/common/types.ts index 41e30cb1..59d5d43b 100644 --- a/scripts/deploy/common/types.ts +++ b/scripts/deploy/common/types.ts @@ -168,4 +168,8 @@ export type NetworkDeploymentConfig = Record< } >; -export type DeployFunction = (hre: HardhatRuntimeEnvironment) => Promise; +export type DeployFunction = ( + hre: HardhatRuntimeEnvironment, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...params: any[] +) => Promise; diff --git a/scripts/deploy/deploy_CustomAggregator.ts b/scripts/deploy/deploy_CustomAggregator.ts index 1a25c2a5..be0fcc31 100644 --- a/scripts/deploy/deploy_CustomAggregator.ts +++ b/scripts/deploy/deploy_CustomAggregator.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployMTokenCustomAggregator } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenCustomAggregator(hre, mToken); }; diff --git a/scripts/deploy/deploy_DV.ts b/scripts/deploy/deploy_DV.ts index d2e99aca..97fe8a4c 100644 --- a/scripts/deploy/deploy_DV.ts +++ b/scripts/deploy/deploy_DV.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployDepositVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployDepositVault(hre, mToken, 'dv'); }; diff --git a/scripts/deploy/deploy_DVAave.ts b/scripts/deploy/deploy_DVAave.ts index 3d2b8563..d7f5a116 100644 --- a/scripts/deploy/deploy_DVAave.ts +++ b/scripts/deploy/deploy_DVAave.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployDepositVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployDepositVault(hre, mToken, 'dvAave'); }; diff --git a/scripts/deploy/deploy_DVMToken.ts b/scripts/deploy/deploy_DVMToken.ts index aa7de28a..1da546d6 100644 --- a/scripts/deploy/deploy_DVMToken.ts +++ b/scripts/deploy/deploy_DVMToken.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployDepositVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployDepositVault(hre, mToken, 'dvMToken'); }; diff --git a/scripts/deploy/deploy_DVMorpho.ts b/scripts/deploy/deploy_DVMorpho.ts index b9b147a1..f00423c5 100644 --- a/scripts/deploy/deploy_DVMorpho.ts +++ b/scripts/deploy/deploy_DVMorpho.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployDepositVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployDepositVault(hre, mToken, 'dvMorpho'); }; diff --git a/scripts/deploy/deploy_DVUstb.ts b/scripts/deploy/deploy_DVUstb.ts index 5a85369d..21daa3e9 100644 --- a/scripts/deploy/deploy_DVUstb.ts +++ b/scripts/deploy/deploy_DVUstb.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployDepositVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployDepositVault(hre, mToken, 'dvUstb'); }; diff --git a/scripts/deploy/deploy_DataFeed.ts b/scripts/deploy/deploy_DataFeed.ts index ade9506e..11387b5a 100644 --- a/scripts/deploy/deploy_DataFeed.ts +++ b/scripts/deploy/deploy_DataFeed.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployMTokenDataFeed } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenDataFeed(hre, mToken); }; diff --git a/scripts/deploy/deploy_DataFeedDv.ts b/scripts/deploy/deploy_DataFeedDv.ts index 00dc9b30..8516a910 100644 --- a/scripts/deploy/deploy_DataFeedDv.ts +++ b/scripts/deploy/deploy_DataFeedDv.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployMTokenDataFeedDv } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenDataFeedDv(hre, mToken); }; diff --git a/scripts/deploy/deploy_DataFeedRv.ts b/scripts/deploy/deploy_DataFeedRv.ts index dfc5efc6..b35e5439 100644 --- a/scripts/deploy/deploy_DataFeedRv.ts +++ b/scripts/deploy/deploy_DataFeedRv.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployMTokenDataFeedRv } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenDataFeedRv(hre, mToken); }; diff --git a/scripts/deploy/deploy_PaymentToken_CustomAggregator.ts b/scripts/deploy/deploy_PaymentToken_CustomAggregator.ts index fd0f24c9..941e0d18 100644 --- a/scripts/deploy/deploy_PaymentToken_CustomAggregator.ts +++ b/scripts/deploy/deploy_PaymentToken_CustomAggregator.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployPaymentTokenCustomAggregator } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getPaymentTokenOrThrow } from '../../helpers/utils'; +import { PaymentTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const paymentToken = getPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + paymentToken: PaymentTokenName, +) => { await deployPaymentTokenCustomAggregator(hre, paymentToken); }; diff --git a/scripts/deploy/deploy_PaymentToken_DataFeed.ts b/scripts/deploy/deploy_PaymentToken_DataFeed.ts index be211a87..dd1965f5 100644 --- a/scripts/deploy/deploy_PaymentToken_DataFeed.ts +++ b/scripts/deploy/deploy_PaymentToken_DataFeed.ts @@ -3,11 +3,14 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployPaymentTokenDataFeed } from './common/data-feed'; import { DeployFunction } from './common/types'; -import { getPaymentTokenOrThrow } from '../../helpers/utils'; +import { PaymentTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const paymentToken = getPaymentTokenOrThrow(hre); - await deployPaymentTokenDataFeed(hre, paymentToken, hre.aggregatorType); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + paymentToken: PaymentTokenName, + aggregatorType?: 'numerator' | 'denominator', +) => { + await deployPaymentTokenDataFeed(hre, paymentToken, aggregatorType); }; export default func; diff --git a/scripts/deploy/deploy_RV.ts b/scripts/deploy/deploy_RV.ts index 88ef8734..983828f5 100644 --- a/scripts/deploy/deploy_RV.ts +++ b/scripts/deploy/deploy_RV.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployRedemptionVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployRedemptionVault(hre, mToken, 'rv'); }; diff --git a/scripts/deploy/deploy_RVAave.ts b/scripts/deploy/deploy_RVAave.ts index 829c59be..84f4c627 100644 --- a/scripts/deploy/deploy_RVAave.ts +++ b/scripts/deploy/deploy_RVAave.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployRedemptionVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployRedemptionVault(hre, mToken, 'rvAave'); }; diff --git a/scripts/deploy/deploy_RVBuidl.ts b/scripts/deploy/deploy_RVBuidl.ts deleted file mode 100644 index 2fddc01d..00000000 --- a/scripts/deploy/deploy_RVBuidl.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { HardhatRuntimeEnvironment } from 'hardhat/types'; - -import { deployRedemptionVault } from './common'; -import { DeployFunction } from './common/types'; - -import { getMTokenOrThrow } from '../../helpers/utils'; - -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - await deployRedemptionVault(hre, mToken, 'rvBuidl'); -}; - -export default func; diff --git a/scripts/deploy/deploy_RVMToken.ts b/scripts/deploy/deploy_RVMToken.ts index d29eeba7..c6cb051c 100644 --- a/scripts/deploy/deploy_RVMToken.ts +++ b/scripts/deploy/deploy_RVMToken.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployRedemptionVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployRedemptionVault(hre, mToken, 'rvMToken'); }; diff --git a/scripts/deploy/deploy_RVMorpho.ts b/scripts/deploy/deploy_RVMorpho.ts index 189ad368..7260432e 100644 --- a/scripts/deploy/deploy_RVMorpho.ts +++ b/scripts/deploy/deploy_RVMorpho.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployRedemptionVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployRedemptionVault(hre, mToken, 'rvMorpho'); }; diff --git a/scripts/deploy/deploy_RVSwapper.ts b/scripts/deploy/deploy_RVSwapper.ts index 60115958..c53600d0 100644 --- a/scripts/deploy/deploy_RVSwapper.ts +++ b/scripts/deploy/deploy_RVSwapper.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployRedemptionVault } from './common'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployRedemptionVault(hre, mToken, 'rvSwapper'); }; diff --git a/scripts/deploy/deploy_TimeLock.ts b/scripts/deploy/deploy_TimeLock.ts index 00f1d534..fb2fda95 100644 --- a/scripts/deploy/deploy_TimeLock.ts +++ b/scripts/deploy/deploy_TimeLock.ts @@ -3,7 +3,10 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployTimelock } from './common/timelock'; import { DeployFunction } from './common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + _skipValidation?: boolean, +) => { await deployTimelock(hre); }; diff --git a/scripts/deploy/deploy_Token.ts b/scripts/deploy/deploy_Token.ts index b874e812..128cd958 100644 --- a/scripts/deploy/deploy_Token.ts +++ b/scripts/deploy/deploy_Token.ts @@ -3,10 +3,12 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { deployMToken } from './common/token'; import { DeployFunction } from './common/types'; -import { getMTokenOrThrow } from '../../helpers/utils'; +import { MTokenName } from '../../config'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMToken(hre, mToken); }; diff --git a/scripts/deploy/misc/acre/deploy_AcreAdapter.ts b/scripts/deploy/misc/acre/deploy_AcreAdapter.ts index ccaba3aa..9155a352 100644 --- a/scripts/deploy/misc/acre/deploy_AcreAdapter.ts +++ b/scripts/deploy/misc/acre/deploy_AcreAdapter.ts @@ -1,23 +1,21 @@ import { group, select } from '@clack/prompts'; import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName, PaymentTokenName } from '../../../../config'; import { getCurrentAddresses, VaultType, } from '../../../../config/constants/addresses'; -import { - etherscanVerify, - getMTokenOrThrow, - getPaymentTokenOrThrow, - logDeploy, -} from '../../../../helpers/utils'; +import { etherscanVerify, logDeploy } from '../../../../helpers/utils'; import { AcreAdapter__factory } from '../../../../typechain-types'; import { DeployFunction } from '../../common/types'; import { getDeployer } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - const pToken = getPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + pToken: PaymentTokenName, +) => { const deployer = await getDeployer(hre); const addresses = getCurrentAddresses(hre); diff --git a/scripts/deploy/misc/axelar/deploy_Executable.ts b/scripts/deploy/misc/axelar/deploy_Executable.ts index 610efb2d..d457c9ce 100644 --- a/scripts/deploy/misc/axelar/deploy_Executable.ts +++ b/scripts/deploy/misc/axelar/deploy_Executable.ts @@ -1,11 +1,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName, PaymentTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { axelarItsAddress } from '../../../../helpers/axelar'; -import { - getMTokenOrThrow, - getPaymentTokenOrThrow, -} from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { deployAndVerifyProxy } from '../../common/utils'; import { @@ -14,9 +11,11 @@ import { routingRedemptionVaultPriority, } from '../../common/vault-resolver'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - const pToken = getPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + pToken: PaymentTokenName, +) => { const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/axelar/grant_Roles.ts b/scripts/deploy/misc/axelar/grant_Roles.ts index aebdda8d..f7e0b895 100644 --- a/scripts/deploy/misc/axelar/grant_Roles.ts +++ b/scripts/deploy/misc/axelar/grant_Roles.ts @@ -1,14 +1,16 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { getRolesForToken } from '../../../../helpers/roles'; -import { getMTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, sendAndWaitForCustomTxSign } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/axelar/revoke_Roles.ts b/scripts/deploy/misc/axelar/revoke_Roles.ts index f3212ced..37437c5c 100644 --- a/scripts/deploy/misc/axelar/revoke_Roles.ts +++ b/scripts/deploy/misc/axelar/revoke_Roles.ts @@ -1,14 +1,16 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { getRolesForToken } from '../../../../helpers/roles'; -import { getMTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, sendAndWaitForCustomTxSign } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/axelar/set_FlowLimit.ts b/scripts/deploy/misc/axelar/set_FlowLimit.ts index 2f1d6dd0..d897fc46 100644 --- a/scripts/deploy/misc/axelar/set_FlowLimit.ts +++ b/scripts/deploy/misc/axelar/set_FlowLimit.ts @@ -1,8 +1,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { axelarTokenManagerAbi } from '../../../../helpers/axelar'; -import { getMTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, @@ -10,9 +10,11 @@ import { sendAndWaitForCustomTxSign, } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/axelar/wire_PaymentTokens.ts b/scripts/deploy/misc/axelar/wire_PaymentTokens.ts index 65bdd029..f344ef41 100644 --- a/scripts/deploy/misc/axelar/wire_PaymentTokens.ts +++ b/scripts/deploy/misc/axelar/wire_PaymentTokens.ts @@ -8,6 +8,7 @@ import { isTestnetNetwork, itsConfigPerPToken, Network, + PaymentTokenName, } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { @@ -21,7 +22,6 @@ import { getTokenId, } from '../../../../helpers/axelar/utils'; import { getHreByNetworkName } from '../../../../helpers/hardhat'; -import { getPaymentTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, @@ -30,10 +30,11 @@ import { } from '../../common/utils'; import { paymentTokenDeploymentConfigs } from '../../configs/payment-tokens'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + pToken: PaymentTokenName, +) => { const deployerHub = await getDeployer(hre); - - const pToken = getPaymentTokenOrThrow(hre); const hubNetwork = hre.network.name as Network; const config = itsConfigPerPToken[hubNetwork]?.[pToken]; diff --git a/scripts/deploy/misc/axelar/wire_Tokens.ts b/scripts/deploy/misc/axelar/wire_Tokens.ts index faa82123..4cdea399 100644 --- a/scripts/deploy/misc/axelar/wire_Tokens.ts +++ b/scripts/deploy/misc/axelar/wire_Tokens.ts @@ -10,6 +10,7 @@ import { axelarChainNames, isTestnetNetwork, itsConfigPerMToken, + MTokenName, Network, } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; @@ -25,7 +26,7 @@ import { getTokenId, } from '../../../../helpers/axelar/utils'; import { getHreByNetworkName } from '../../../../helpers/hardhat'; -import { getMTokenOrThrow, logDeploy } from '../../../../helpers/utils'; +import { logDeploy } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, @@ -36,10 +37,13 @@ import { const TOKEN_MANAGER_MINT_BURN = 4; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + action?: string, +) => { const deployerHub = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const hubNetwork = hre.network.name as Network; const config = itsConfigPerMToken[hubNetwork]?.[mToken]; @@ -82,7 +86,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const defaultGas = 300_000; - const salt = calculateSalt(mToken, hre.action); + const salt = calculateSalt(mToken, action); const linkedDeploySalt = await calculateDeploySalt( hre, diff --git a/scripts/deploy/misc/deploy_CustomAggregatorAdjusted.ts b/scripts/deploy/misc/deploy_CustomAggregatorAdjusted.ts index cfc60da4..3baaa43b 100644 --- a/scripts/deploy/misc/deploy_CustomAggregatorAdjusted.ts +++ b/scripts/deploy/misc/deploy_CustomAggregatorAdjusted.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { deployMTokenCustomAggregatorAdjusted } from '../common/data-feed'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenCustomAggregatorAdjusted(hre, mToken); }; diff --git a/scripts/deploy/misc/deploy_CustomAggregatorAdjustedDv.ts b/scripts/deploy/misc/deploy_CustomAggregatorAdjustedDv.ts index 75ce1c03..25c0e6df 100644 --- a/scripts/deploy/misc/deploy_CustomAggregatorAdjustedDv.ts +++ b/scripts/deploy/misc/deploy_CustomAggregatorAdjustedDv.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { deployMTokenCustomAggregatorAdjustedDv } from '../common/data-feed'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenCustomAggregatorAdjustedDv(hre, mToken); }; diff --git a/scripts/deploy/misc/deploy_CustomAggregatorAdjustedRv.ts b/scripts/deploy/misc/deploy_CustomAggregatorAdjustedRv.ts index 89c7d62a..8ab5b45e 100644 --- a/scripts/deploy/misc/deploy_CustomAggregatorAdjustedRv.ts +++ b/scripts/deploy/misc/deploy_CustomAggregatorAdjustedRv.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { deployMTokenCustomAggregatorAdjustedRv } from '../common/data-feed'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await deployMTokenCustomAggregatorAdjustedRv(hre, mToken); }; diff --git a/scripts/deploy/misc/layerzero/deploy_Composer.ts b/scripts/deploy/misc/layerzero/deploy_Composer.ts index 715fc135..187ecfb5 100644 --- a/scripts/deploy/misc/layerzero/deploy_Composer.ts +++ b/scripts/deploy/misc/layerzero/deploy_Composer.ts @@ -1,10 +1,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName, PaymentTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; -import { - getMTokenOrThrow, - getPaymentTokenOrThrow, -} from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { deployAndVerifyProxy } from '../../common/utils'; import { @@ -13,9 +10,11 @@ import { routingRedemptionVaultPriority, } from '../../common/vault-resolver'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - const pToken = getPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + pToken: PaymentTokenName, +) => { const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/layerzero/deploy_MintBurnOFTAdapter.ts b/scripts/deploy/misc/layerzero/deploy_MintBurnOFTAdapter.ts index 845dc331..30ac0c36 100644 --- a/scripts/deploy/misc/layerzero/deploy_MintBurnOFTAdapter.ts +++ b/scripts/deploy/misc/layerzero/deploy_MintBurnOFTAdapter.ts @@ -1,23 +1,21 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { layerZeroEids, Network } from '../../../../config'; +import { layerZeroEids, MTokenName, Network } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { lzConfigsPerMToken } from '../../../../config/misc'; -import { - etherscanVerify, - getOriginalNetwork, - getMTokenOrThrow, - logDeploy, -} from '../../../../helpers/utils'; +import { etherscanVerify, logDeploy } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, getNetworkConfig } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + originalNetwork?: Network, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); - const originalNetwork = - getOriginalNetwork(hre) ?? (hre.network.name as Network); + const resolvedOriginalNetwork = + originalNetwork ?? (hre.network.name as Network); const addresses = getCurrentAddresses(hre); @@ -44,15 +42,16 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const rateLimitConfigOverrides = config.layerZero.rateLimitConfig?.overrides; const allReceiverNetworks = - lzConfigsPerMToken?.[originalNetwork]?.[mToken]?.linkedNetworks; + lzConfigsPerMToken?.[resolvedOriginalNetwork]?.[mToken]?.linkedNetworks; if (!allReceiverNetworks || allReceiverNetworks.length === 0) { throw new Error('Receiver networks not found'); } - const networksToRateLimit = [...allReceiverNetworks, originalNetwork].filter( - (network) => network !== hre.network.name, - ); + const networksToRateLimit = [ + ...allReceiverNetworks, + resolvedOriginalNetwork, + ].filter((network) => network !== hre.network.name); const rateLimitConfigs = networksToRateLimit.map((network) => { const configBase = diff --git a/scripts/deploy/misc/layerzero/deploy_OFT.ts b/scripts/deploy/misc/layerzero/deploy_OFT.ts index a1b3271b..10304b4f 100644 --- a/scripts/deploy/misc/layerzero/deploy_OFT.ts +++ b/scripts/deploy/misc/layerzero/deploy_OFT.ts @@ -1,21 +1,18 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { rpcUrls } from '../../../../config'; +import { Network, PaymentTokenName, rpcUrls } from '../../../../config'; import { midasAddressesPerNetwork } from '../../../../config/constants/addresses'; -import { - etherscanVerify, - getOriginalNetworkOrThrow, - getPaymentTokenOrThrow, - logDeploy, -} from '../../../../helpers/utils'; +import { etherscanVerify, logDeploy } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer } from '../../common/utils'; import { paymentTokenDeploymentConfigs } from '../../configs/payment-tokens'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + paymentToken: PaymentTokenName, + originalNetwork: Network, +) => { const deployer = await getDeployer(hre); - const paymentToken = getPaymentTokenOrThrow(hre); - const originalNetwork = getOriginalNetworkOrThrow(hre); const config = paymentTokenDeploymentConfigs.networkConfigs[hre.network.config.chainId!]?.[ diff --git a/scripts/deploy/misc/layerzero/deploy_OFTAdapter.ts b/scripts/deploy/misc/layerzero/deploy_OFTAdapter.ts index 27ec6cbe..4d35a2b7 100644 --- a/scripts/deploy/misc/layerzero/deploy_OFTAdapter.ts +++ b/scripts/deploy/misc/layerzero/deploy_OFTAdapter.ts @@ -1,18 +1,17 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { PaymentTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; -import { - etherscanVerify, - getPaymentTokenOrThrow, - logDeploy, -} from '../../../../helpers/utils'; +import { etherscanVerify, logDeploy } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer } from '../../common/utils'; import { paymentTokenDeploymentConfigs } from '../../configs/payment-tokens'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + paymentToken: PaymentTokenName, +) => { const deployer = await getDeployer(hre); - const paymentToken = getPaymentTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); diff --git a/scripts/deploy/misc/layerzero/grant_Roles.ts b/scripts/deploy/misc/layerzero/grant_Roles.ts index 2bc23444..4ce4be99 100644 --- a/scripts/deploy/misc/layerzero/grant_Roles.ts +++ b/scripts/deploy/misc/layerzero/grant_Roles.ts @@ -1,14 +1,16 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { getRolesForToken } from '../../../../helpers/roles'; -import { getMTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, sendAndWaitForCustomTxSign } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/layerzero/revoke_Roles.ts b/scripts/deploy/misc/layerzero/revoke_Roles.ts index ae99dcf5..7ce8c2b0 100644 --- a/scripts/deploy/misc/layerzero/revoke_Roles.ts +++ b/scripts/deploy/misc/layerzero/revoke_Roles.ts @@ -1,14 +1,16 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { getRolesForToken } from '../../../../helpers/roles'; -import { getMTokenOrThrow } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, sendAndWaitForCustomTxSign } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); const addresses = getCurrentAddresses(hre); const mTokenAddresses = addresses?.[mToken]; diff --git a/scripts/deploy/misc/layerzero/set_RateLimitConfigs.ts b/scripts/deploy/misc/layerzero/set_RateLimitConfigs.ts index 42c0ad93..7e507cc1 100644 --- a/scripts/deploy/misc/layerzero/set_RateLimitConfigs.ts +++ b/scripts/deploy/misc/layerzero/set_RateLimitConfigs.ts @@ -1,12 +1,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { layerZeroEids, Network } from '../../../../config'; +import { layerZeroEids, MTokenName, Network } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; import { lzConfigsPerMToken } from '../../../../config/misc'; -import { - getOriginalNetwork, - getMTokenOrThrow, -} from '../../../../helpers/utils'; import { RateLimiter } from '../../../../typechain-types'; import { DeployFunction } from '../../common/types'; import { @@ -15,12 +11,15 @@ import { sendAndWaitForCustomTxSign, } from '../../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + originalNetwork?: Network, +) => { const deployer = await getDeployer(hre); - const mToken = getMTokenOrThrow(hre); - const originalNetwork = - getOriginalNetwork(hre) ?? (hre.network.name as Network); + const resolvedOriginalNetwork = + originalNetwork ?? (hre.network.name as Network); const addresses = getCurrentAddresses(hre); @@ -49,7 +48,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const rateLimitConfigDefault = config.layerZero.rateLimitConfig?.default; const rateLimitConfigOverrides = config.layerZero.rateLimitConfig?.overrides; - const lzConfig = lzConfigsPerMToken?.[originalNetwork]?.[mToken]; + const lzConfig = lzConfigsPerMToken?.[resolvedOriginalNetwork]?.[mToken]; if (!lzConfig) { throw new Error( @@ -63,16 +62,16 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { let networksToRateLimit: Network[]; if (isDirectOnly) { - if (currentNetwork === originalNetwork) { + if (currentNetwork === resolvedOriginalNetwork) { // on original network: can send to all linked networks networksToRateLimit = linkedNetworks; } else { // on linked network: can only send back to the original network - networksToRateLimit = [originalNetwork]; + networksToRateLimit = [resolvedOriginalNetwork]; } } else { // For 'all' pathways (default): can send to all linked networks + original network - networksToRateLimit = [...linkedNetworks, originalNetwork].filter( + networksToRateLimit = [...linkedNetworks, resolvedOriginalNetwork].filter( (network) => network !== currentNetwork, ); } diff --git a/scripts/deploy/misc/layerzero/transfer_Owner.ts b/scripts/deploy/misc/layerzero/transfer_Owner.ts index 4e5239ab..524969d2 100644 --- a/scripts/deploy/misc/layerzero/transfer_Owner.ts +++ b/scripts/deploy/misc/layerzero/transfer_Owner.ts @@ -1,7 +1,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName, PaymentTokenName } from '../../../../config'; import { getCurrentAddresses } from '../../../../config/constants/addresses'; -import { getMTokenOrPaymentTokenOrThrow } from '../../../../helpers/utils'; +import { requireOneOfMTokenOrPaymentToken } from '../../../../helpers/utils'; import { DeployFunction } from '../../common/types'; import { getDeployer, @@ -10,8 +11,12 @@ import { } from '../../common/utils'; import { paymentTokenDeploymentConfigs } from '../../configs/payment-tokens'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const { mToken, paymentToken } = getMTokenOrPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + paymentToken?: PaymentTokenName, +) => { + const selected = requireOneOfMTokenOrPaymentToken(mToken, paymentToken); const deployer = await getDeployer(hre); const addresses = getCurrentAddresses(hre); @@ -19,16 +24,16 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { let address: string | undefined; let newOwner: string | undefined; - if (mToken) { - address = addresses?.[mToken]?.layerZero?.oft; - const config = getNetworkConfig(hre, mToken, 'postDeploy'); + if (selected.mToken) { + address = addresses?.[selected.mToken]?.layerZero?.oft; + const config = getNetworkConfig(hre, selected.mToken, 'postDeploy'); newOwner = config?.layerZero?.owner ?? config?.layerZero?.delegate; } else { - address = addresses?.paymentTokens?.[paymentToken]?.layerZero?.oft; + address = addresses?.paymentTokens?.[selected.paymentToken]?.layerZero?.oft; const config = paymentTokenDeploymentConfigs.networkConfigs[ hre.network.config.chainId! - ]?.[paymentToken]?.postDeploy?.layerZero; + ]?.[selected.paymentToken]?.postDeploy?.layerZero; newOwner = config?.owner ?? config?.delegate; } diff --git a/scripts/deploy/post-deploy/add_FeeWaived.ts b/scripts/deploy/post-deploy/add_FeeWaived.ts index 8d54e4c4..11892122 100644 --- a/scripts/deploy/post-deploy/add_FeeWaived.ts +++ b/scripts/deploy/post-deploy/add_FeeWaived.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { addFeeWaived } from '../common/common-vault'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await addFeeWaived(hre, mToken); }; diff --git a/scripts/deploy/post-deploy/add_PaymentTokens.ts b/scripts/deploy/post-deploy/add_PaymentTokens.ts index 030ca0af..74c4cbb5 100644 --- a/scripts/deploy/post-deploy/add_PaymentTokens.ts +++ b/scripts/deploy/post-deploy/add_PaymentTokens.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { addPaymentTokens } from '../common/common-vault'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await addPaymentTokens(hre, mToken); }; diff --git a/scripts/deploy/post-deploy/add_ToAddressBook.ts b/scripts/deploy/post-deploy/add_ToAddressBook.ts index 4c69c4e0..de9a08aa 100644 --- a/scripts/deploy/post-deploy/add_ToAddressBook.ts +++ b/scripts/deploy/post-deploy/add_ToAddressBook.ts @@ -1,11 +1,11 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../config'; import { getCurrentAddresses, LayerZeroTokenAddresses, TokenAddresses, } from '../../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../../helpers/utils'; import { DeployFunction } from '../common/types'; type AddressBookEntryConfig = { @@ -49,9 +49,11 @@ const ADDRESS_BOOK_MAPPING: Partial< }, }; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + keys?: string[], +) => { const addresses = getCurrentAddresses(hre); if (!addresses) { @@ -64,7 +66,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { throw new Error('Token addresses not found'); } - const allowedKeys = hre.addressBookKeys; + const allowedKeys = keys; for (const [key, value] of Object.entries(tokenAddresses)) { if (!value) { diff --git a/scripts/deploy/post-deploy/grant_AllProductRoles.ts b/scripts/deploy/post-deploy/grant_AllProductRoles.ts index 0dbfa6d9..6343e6e2 100644 --- a/scripts/deploy/post-deploy/grant_AllProductRoles.ts +++ b/scripts/deploy/post-deploy/grant_AllProductRoles.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { grantAllProductRoles } from '../common/roles'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await grantAllProductRoles(hre, mToken); }; diff --git a/scripts/deploy/post-deploy/pause_Functions.ts b/scripts/deploy/post-deploy/pause_Functions.ts index 5bb0ef96..0ca2e422 100644 --- a/scripts/deploy/post-deploy/pause_Functions.ts +++ b/scripts/deploy/post-deploy/pause_Functions.ts @@ -1,16 +1,19 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../config'; import { getCurrentAddresses, VaultType, } from '../../../config/constants/addresses'; -import { getChainOrThrow, getMTokenOrThrow } from '../../../helpers/utils'; +import { getChainOrThrow } from '../../../helpers/utils'; import { DeployFunction, VAULT_FUNCTION_SELECTORS } from '../common/types'; import { sendAndWaitForCustomTxSign, getNetworkConfig } from '../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const { networkName } = getChainOrThrow(hre); - const mToken = getMTokenOrThrow(hre); const pauseFunctions = getNetworkConfig( hre, diff --git a/scripts/deploy/post-deploy/set_AaveConfig.ts b/scripts/deploy/post-deploy/set_AaveConfig.ts index f7421ee4..78ef4baa 100644 --- a/scripts/deploy/post-deploy/set_AaveConfig.ts +++ b/scripts/deploy/post-deploy/set_AaveConfig.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { setAaveConfig } from '../common/common-vault'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await setAaveConfig(hre, mToken); }; diff --git a/scripts/deploy/post-deploy/set_ExpectedAnswers.ts b/scripts/deploy/post-deploy/set_ExpectedAnswers.ts index 2fbbd662..438950e1 100644 --- a/scripts/deploy/post-deploy/set_ExpectedAnswers.ts +++ b/scripts/deploy/post-deploy/set_ExpectedAnswers.ts @@ -1,19 +1,24 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrPaymentTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName, PaymentTokenName } from '../../../config'; +import { requireOneOfMTokenOrPaymentToken } from '../../../helpers/utils'; import { updateExpectedAnswersMToken, updateExpectedAnswersPaymentToken, } from '../common/data-feed'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const { mToken, paymentToken } = getMTokenOrPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + paymentToken?: PaymentTokenName, +) => { + const selected = requireOneOfMTokenOrPaymentToken(mToken, paymentToken); - if (mToken) { - await updateExpectedAnswersMToken(hre, mToken); + if (selected.mToken) { + await updateExpectedAnswersMToken(hre, selected.mToken); } else { - await updateExpectedAnswersPaymentToken(hre, paymentToken); + await updateExpectedAnswersPaymentToken(hre, selected.paymentToken); } }; diff --git a/scripts/deploy/post-deploy/set_Greenlist.ts b/scripts/deploy/post-deploy/set_Greenlist.ts index 8fbbd3c1..b202a692 100644 --- a/scripts/deploy/post-deploy/set_Greenlist.ts +++ b/scripts/deploy/post-deploy/set_Greenlist.ts @@ -1,14 +1,17 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../config'; import { getCurrentAddresses } from '../../../config/constants/addresses'; -import { getChainOrThrow, getMTokenOrThrow } from '../../../helpers/utils'; +import { getChainOrThrow } from '../../../helpers/utils'; import { applyGreenlistConfig } from '../common/greenlist'; import { DeployFunction } from '../common/types'; import { getNetworkConfig } from '../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const { networkName } = getChainOrThrow(hre); - const mToken = getMTokenOrThrow(hre); const greenlistConfig = getNetworkConfig( hre, mToken, diff --git a/scripts/deploy/post-deploy/set_MorphoConfig.ts b/scripts/deploy/post-deploy/set_MorphoConfig.ts index b85f9330..02b5deaf 100644 --- a/scripts/deploy/post-deploy/set_MorphoConfig.ts +++ b/scripts/deploy/post-deploy/set_MorphoConfig.ts @@ -1,11 +1,13 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName } from '../../../config'; import { setMorphoConfig } from '../common/common-vault'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { await setMorphoConfig(hre, mToken); }; diff --git a/scripts/deploy/post-deploy/set_RoundData.ts b/scripts/deploy/post-deploy/set_RoundData.ts index e7eff683..6e59d658 100644 --- a/scripts/deploy/post-deploy/set_RoundData.ts +++ b/scripts/deploy/post-deploy/set_RoundData.ts @@ -1,19 +1,24 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; -import { getMTokenOrPaymentTokenOrThrow } from '../../../helpers/utils'; +import { MTokenName, PaymentTokenName } from '../../../config'; +import { requireOneOfMTokenOrPaymentToken } from '../../../helpers/utils'; import { setRoundDataMToken, setRoundDataPaymentToken, } from '../common/data-feed'; import { DeployFunction } from '../common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const { mToken, paymentToken } = getMTokenOrPaymentTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + paymentToken?: PaymentTokenName, +) => { + const selected = requireOneOfMTokenOrPaymentToken(mToken, paymentToken); - if (mToken) { - await setRoundDataMToken(hre, mToken); + if (selected.mToken) { + await setRoundDataMToken(hre, selected.mToken); } else { - await setRoundDataPaymentToken(hre, paymentToken); + await setRoundDataPaymentToken(hre, selected.paymentToken); } }; diff --git a/scripts/deploy/post-deploy/set_SanctionsList.ts b/scripts/deploy/post-deploy/set_SanctionsList.ts index d43a1a20..aadc9f4a 100644 --- a/scripts/deploy/post-deploy/set_SanctionsList.ts +++ b/scripts/deploy/post-deploy/set_SanctionsList.ts @@ -1,17 +1,20 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../../config'; import { getCurrentAddresses, sanctionListContracts, VaultType, } from '../../../config/constants/addresses'; -import { getChainOrThrow, getMTokenOrThrow } from '../../../helpers/utils'; +import { getChainOrThrow } from '../../../helpers/utils'; import { DeployFunction } from '../common/types'; import { sendAndWaitForCustomTxSign } from '../common/utils'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const { chainId, networkName } = getChainOrThrow(hre); - const mToken = getMTokenOrThrow(hre); const sanctionsList = sanctionListContracts[chainId]; if (!sanctionsList) { diff --git a/scripts/upgrades/common/aggregator-timelapsed-upgrade.ts b/scripts/upgrades/common/aggregator-timelapsed-upgrade.ts index bb4ac8eb..6cb10e89 100644 --- a/scripts/upgrades/common/aggregator-timelapsed-upgrade.ts +++ b/scripts/upgrades/common/aggregator-timelapsed-upgrade.ts @@ -51,16 +51,18 @@ const runAggregatorTimelapsedForMToken = async ( export const resolveAggregatorTimelapsedMTokenRunList = ( hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + action?: string, ): MTokenName[] => { - if (hre.mtoken) { - return [hre.mtoken]; + if (mToken) { + return [mToken]; } - if (!hre.action) { + if (!action) { throw new Error( 'Provide --mtoken for a single product, or --action for a batch (configure targets in scripts/upgrades/configs/aggregator-timelapsed-config.ts)', ); } - return resolveTimelapsedMTokens(hre, hre.action); + return resolveTimelapsedMTokens(hre, action); }; export const proposeAggregatorTimelapsedForMToken = ( diff --git a/scripts/upgrades/executeTransferOwnership_ProxyAdmin.ts b/scripts/upgrades/executeTransferOwnership_ProxyAdmin.ts index c57235a3..03f8f0c3 100644 --- a/scripts/upgrades/executeTransferOwnership_ProxyAdmin.ts +++ b/scripts/upgrades/executeTransferOwnership_ProxyAdmin.ts @@ -2,12 +2,14 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { executeTransferOwnershipProxyAdmin } from './common/upgrade-vaults'; -import { getActionOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const upgradeId = getActionOrThrow(hre); - await executeTransferOwnershipProxyAdmin(hre, upgradeId); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + action: string, + _skipValidation?: boolean, +) => { + await executeTransferOwnershipProxyAdmin(hre, action); }; export default func; diff --git a/scripts/upgrades/executeUpgrade_AggregatorDeviation.ts b/scripts/upgrades/executeUpgrade_AggregatorDeviation.ts index 73d9fc3f..7de81679 100644 --- a/scripts/upgrades/executeUpgrade_AggregatorDeviation.ts +++ b/scripts/upgrades/executeUpgrade_AggregatorDeviation.ts @@ -7,8 +7,8 @@ import { } from './common/aggregator-deviation'; import { executeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; /** @@ -16,9 +16,11 @@ import { DeployFunction } from '../deploy/common/types'; */ const deviation = parseUnits('0.35', 8); -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const networkAddresses = getCurrentAddresses(hre); const tokenAddresses = networkAddresses?.[mToken]; @@ -53,5 +55,3 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { }; export default func; - -// yarn hardhat runscript scripts/upgrades/executeUpgrade_AggregatorDeviation.ts --network --mtoken diff --git a/scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts b/scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts index cd6a6b26..3f7a02a9 100644 --- a/scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts +++ b/scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts @@ -8,8 +8,13 @@ import { import { MTokenName } from '../../config'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mTokens = resolveAggregatorTimelapsedMTokenRunList(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + action?: string, + _skipValidation?: boolean, +) => { + const mTokens = resolveAggregatorTimelapsedMTokenRunList(hre, mToken, action); const failures: { mToken: MTokenName; error: string }[] = []; let upgraded = 0; let skipped = 0; @@ -20,10 +25,10 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { } mToken(s): ${mTokens.join(', ')}`, ); - for (const mToken of mTokens) { - hre.mtoken = mToken; + for (const token of mTokens) { + hre.mtoken = token; try { - const outcome = await executeAggregatorTimelapsedForMToken(hre, mToken); + const outcome = await executeAggregatorTimelapsedForMToken(hre, token); if (outcome === 'skipped') { skipped++; } else { @@ -32,7 +37,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { } catch (e) { console.error(`Upgrade failed with error ${e}`); failures.push({ - mToken, + mToken: token, error: e instanceof Error ? e.message : String(e), }); } @@ -51,9 +56,3 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { }; export default func; - -// Single product: -// yarn hardhat runscript scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts --network --mtoken -// -// Batch (targets in scripts/upgrades/configs/aggregator-timelapsed-config.ts): -// yarn hardhat runscript scripts/upgrades/executeUpgrade_AggregatorTimelapsed.ts --network --action diff --git a/scripts/upgrades/executeUpgrade_Aggregators.ts b/scripts/upgrades/executeUpgrade_Aggregators.ts index c687eb42..55d65936 100644 --- a/scripts/upgrades/executeUpgrade_Aggregators.ts +++ b/scripts/upgrades/executeUpgrade_Aggregators.ts @@ -3,14 +3,17 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { executeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const upgradeId = 'mkralpha-custom-aggregator-upgrade-v2'; const networkAddresses = getCurrentAddresses(hre); - const mToken = getMTokenOrThrow(hre); const tokenAddresses = networkAddresses?.[mToken]; if (!tokenAddresses) { diff --git a/scripts/upgrades/executeUpgrade_Token.ts b/scripts/upgrades/executeUpgrade_Token.ts index d0cbaeba..4d9bf580 100644 --- a/scripts/upgrades/executeUpgrade_Token.ts +++ b/scripts/upgrades/executeUpgrade_Token.ts @@ -2,14 +2,17 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { executeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const upgradeId = 'mwin-upgrade-permissioned'; const networkAddresses = getCurrentAddresses(hre); - const mToken = getMTokenOrThrow(hre); const tokenAddresses = networkAddresses?.[mToken]; if (!tokenAddresses) { diff --git a/scripts/upgrades/executeUpgrade_Vaults.ts b/scripts/upgrades/executeUpgrade_Vaults.ts index d8e66688..18f23f7d 100644 --- a/scripts/upgrades/executeUpgrade_Vaults.ts +++ b/scripts/upgrades/executeUpgrade_Vaults.ts @@ -2,12 +2,14 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { executeUpgradeVaults } from './common/upgrade-vaults'; -import { getActionOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const upgradeId = getActionOrThrow(hre); - await executeUpgradeVaults(hre, upgradeId); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + action: string, + _skipValidation?: boolean, +) => { + await executeUpgradeVaults(hre, action); }; export default func; diff --git a/scripts/upgrades/proposeTransferOwnership_ProxyAdmin.ts b/scripts/upgrades/proposeTransferOwnership_ProxyAdmin.ts index f36aee38..77294934 100644 --- a/scripts/upgrades/proposeTransferOwnership_ProxyAdmin.ts +++ b/scripts/upgrades/proposeTransferOwnership_ProxyAdmin.ts @@ -2,12 +2,14 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { proposeTransferOwnershipProxyAdmin } from './common/upgrade-vaults'; -import { getActionOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const upgradeId = getActionOrThrow(hre); - await proposeTransferOwnershipProxyAdmin(hre, upgradeId); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + action: string, + _skipValidation?: boolean, +) => { + await proposeTransferOwnershipProxyAdmin(hre, action); }; export default func; diff --git a/scripts/upgrades/proposeUpgrade_AggregatorDeviation.ts b/scripts/upgrades/proposeUpgrade_AggregatorDeviation.ts index cf93af39..f1ba294b 100644 --- a/scripts/upgrades/proposeUpgrade_AggregatorDeviation.ts +++ b/scripts/upgrades/proposeUpgrade_AggregatorDeviation.ts @@ -7,8 +7,8 @@ import { } from './common/aggregator-deviation'; import { proposeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; /** @@ -16,9 +16,11 @@ import { DeployFunction } from '../deploy/common/types'; */ const deviation = parseUnits('0.35', 8); -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const networkAddresses = getCurrentAddresses(hre); const tokenAddresses = networkAddresses?.[mToken]; @@ -53,5 +55,3 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { }; export default func; - -// yarn hardhat runscript scripts/upgrades/proposeUpgrade_AggregatorDeviation.ts --network --mtoken diff --git a/scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts b/scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts index 50d9c49c..0d0de611 100644 --- a/scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts +++ b/scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts @@ -8,8 +8,13 @@ import { import { MTokenName } from '../../config'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mTokens = resolveAggregatorTimelapsedMTokenRunList(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken?: MTokenName, + action?: string, + _skipValidation?: boolean, +) => { + const mTokens = resolveAggregatorTimelapsedMTokenRunList(hre, mToken, action); const failures: { mToken: MTokenName; error: string }[] = []; let upgraded = 0; let skipped = 0; @@ -20,10 +25,10 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { } mToken(s): ${mTokens.join(', ')}`, ); - for (const mToken of mTokens) { - hre.mtoken = mToken; + for (const token of mTokens) { + hre.mtoken = token; try { - const outcome = await proposeAggregatorTimelapsedForMToken(hre, mToken); + const outcome = await proposeAggregatorTimelapsedForMToken(hre, token); if (outcome === 'skipped') { skipped++; } else { @@ -32,7 +37,7 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { } catch (e) { console.error(`Upgrade failed with error ${e}`); failures.push({ - mToken, + mToken: token, error: e instanceof Error ? e.message : String(e), }); } @@ -51,9 +56,3 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { }; export default func; - -// Single product: -// yarn hardhat runscript scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts --network --mtoken -// -// Batch (targets in scripts/upgrades/configs/aggregator-timelapsed-config.ts): -// yarn hardhat runscript scripts/upgrades/proposeUpgrade_AggregatorTimelapsed.ts --network --action diff --git a/scripts/upgrades/proposeUpgrade_Aggregators.ts b/scripts/upgrades/proposeUpgrade_Aggregators.ts index ef2707d9..7ce0e28c 100644 --- a/scripts/upgrades/proposeUpgrade_Aggregators.ts +++ b/scripts/upgrades/proposeUpgrade_Aggregators.ts @@ -3,15 +3,18 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { proposeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const upgradeId = 'mre7-custom-aggregator-upgrade-v3'; const networkAddresses = getCurrentAddresses(hre); - const mToken = getMTokenOrThrow(hre); const tokenAddresses = networkAddresses?.[mToken]; if (!tokenAddresses) { diff --git a/scripts/upgrades/proposeUpgrade_Token.ts b/scripts/upgrades/proposeUpgrade_Token.ts index 525e25c0..0431c5e2 100644 --- a/scripts/upgrades/proposeUpgrade_Token.ts +++ b/scripts/upgrades/proposeUpgrade_Token.ts @@ -2,14 +2,17 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { proposeUpgradeContracts } from './common/upgrade-contracts'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, + _skipValidation?: boolean, +) => { const upgradeId = 'mwin-upgrade-permissioned'; const networkAddresses = getCurrentAddresses(hre); - const mToken = getMTokenOrThrow(hre); const tokenAddresses = networkAddresses?.[mToken]; if (!tokenAddresses) { diff --git a/scripts/upgrades/proposeUpgrade_Vaults.ts b/scripts/upgrades/proposeUpgrade_Vaults.ts index 2849bfe7..089b2875 100644 --- a/scripts/upgrades/proposeUpgrade_Vaults.ts +++ b/scripts/upgrades/proposeUpgrade_Vaults.ts @@ -2,12 +2,14 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { proposeUpgradeVaults } from './common/upgrade-vaults'; -import { getActionOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const upgradeId = getActionOrThrow(hre); - await proposeUpgradeVaults(hre, upgradeId); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + action: string, + _skipValidation?: boolean, +) => { + await proposeUpgradeVaults(hre, action); }; export default func; diff --git a/scripts/upgrades/upgrade_RedemptionVaultMToken.ts b/scripts/upgrades/upgrade_RedemptionVaultMToken.ts index 1943ca53..40c1b102 100644 --- a/scripts/upgrades/upgrade_RedemptionVaultMToken.ts +++ b/scripts/upgrades/upgrade_RedemptionVaultMToken.ts @@ -1,8 +1,8 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; +import { MTokenName } from '../../config'; import { getCurrentAddresses } from '../../config/constants/addresses'; import { getTokenContractNames } from '../../helpers/contracts'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; import { getDeployer } from '../deploy/common/utils'; @@ -11,14 +11,15 @@ import { getDeployer } from '../deploy/common/utils'; * RedemptionVaultWithMToken implementation. * * Usage: - * npx hardhat runscript scripts/upgrades/upgrade_RedemptionVaultMToken.ts --mtoken mFONE --network + * yarn hardhat upgrade:rv:mtoken --mtoken mFONE --network * * The script uses `prepareUpgrade` which validates storage layout * compatibility and deploys the new implementation (if changed). */ -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); - +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const addresses = getCurrentAddresses(hre); const proxyAddress = addresses?.[mToken]?.redemptionVaultSwapper; diff --git a/scripts/upgrades/validateUpgrade_Vaults.ts b/scripts/upgrades/validateUpgrade_Vaults.ts index 7153fb66..4e38666b 100644 --- a/scripts/upgrades/validateUpgrade_Vaults.ts +++ b/scripts/upgrades/validateUpgrade_Vaults.ts @@ -5,13 +5,15 @@ import { validateUpgradeVaults, } from './common/upgrade-vaults'; -import { getActionOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const upgradeId = getActionOrThrow(hre); - await validateProposeUpgradeVaults(hre, upgradeId); - await validateUpgradeVaults(hre, upgradeId); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + action: string, + _skipValidation?: boolean, +) => { + await validateProposeUpgradeVaults(hre, action); + await validateUpgradeVaults(hre, action); }; export default func; diff --git a/scripts/upgrades/verifyUpgrade_Reinitializers.ts b/scripts/upgrades/verifyUpgrade_Reinitializers.ts index 835fa3d1..6c7ef05d 100644 --- a/scripts/upgrades/verifyUpgrade_Reinitializers.ts +++ b/scripts/upgrades/verifyUpgrade_Reinitializers.ts @@ -2,6 +2,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import { verifyReinitializersConsumed } from './common/reinitializer'; +import { MTokenName } from '../../config'; import { getCurrentAddresses, VaultType, @@ -12,13 +13,14 @@ import { TokenContractNames, vaultTypeToContractName, } from '../../helpers/contracts'; -import { getMTokenOrThrow } from '../../helpers/utils'; import { DeployFunction } from '../deploy/common/types'; // Verifies that every upgradeable contract of the given mToken on the current // network has consumed its top reinitializer (read-only; no tx sent). -const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { - const mToken = getMTokenOrThrow(hre); +const func: DeployFunction = async ( + hre: HardhatRuntimeEnvironment, + mToken: MTokenName, +) => { const addresses = getCurrentAddresses(hre); const tokenAddresses = addresses?.[mToken]; if (!tokenAddresses) throw new Error(`Addresses not found for ${mToken}`); @@ -82,5 +84,3 @@ const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { }; export default func; - -// yarn hardhat runscript scripts/upgrades/verifyUpgrade_Reinitializers.ts --network --mtoken diff --git a/tasks/common/deploy-tasks-definition.ts b/tasks/common/deploy-tasks-definition.ts new file mode 100644 index 00000000..d4a9f56e --- /dev/null +++ b/tasks/common/deploy-tasks-definition.ts @@ -0,0 +1,260 @@ +import path from 'node:path'; + +import { + actionParam, + aggregatorTypeParam, + keysParam, + mTokenParam, + originalNetworkParam, + ParseParamFn, + pTokenParam, + skipValidationParam, +} from './task-params'; + +type DeploymentTask = [string, ...ReturnType[]]; + +const deploy = (file: string) => path.join('scripts/deploy', `${file}.ts`); +const deployMisc = (file: string) => + path.join('scripts/deploy/misc', `${file}.ts`); +const deployPost = (file: string) => + path.join('scripts/deploy/post-deploy', `${file}.ts`); +const deployLz = (file: string) => + path.join('scripts/deploy/misc/layerzero', `${file}.ts`); +const deployAxelar = (file: string) => + path.join('scripts/deploy/misc/axelar', `${file}.ts`); +const deployCodegen = (file: string) => + path.join('scripts/deploy/codegen', `${file}.ts`); +const upgrade = (file: string) => path.join('scripts/upgrades', `${file}.ts`); + +const deployTasksRecord: Record = { + // Core deploy + 'deploy:ac': [deploy('deploy_AccessControl')], + 'deploy:timelock': [deploy('deploy_TimeLock'), skipValidationParam(true)], + 'deploy:token': [deploy('deploy_Token'), mTokenParam()], + 'deploy:aggregator': [deploy('deploy_CustomAggregator'), mTokenParam()], + 'deploy:aggregator:adjusted': [ + deployMisc('deploy_CustomAggregatorAdjusted'), + mTokenParam(), + ], + 'deploy:aggregator:adjusted:dv': [ + deployMisc('deploy_CustomAggregatorAdjustedDv'), + mTokenParam(), + ], + 'deploy:aggregator:adjusted:rv': [ + deployMisc('deploy_CustomAggregatorAdjustedRv'), + mTokenParam(), + ], + 'deploy:aggregator:ptoken': [ + deploy('deploy_PaymentToken_CustomAggregator'), + pTokenParam(), + ], + 'deploy:feed': [deploy('deploy_DataFeed'), mTokenParam()], + 'deploy:feed:dv': [deploy('deploy_DataFeedDv'), mTokenParam()], + 'deploy:feed:rv': [deploy('deploy_DataFeedRv'), mTokenParam()], + 'deploy:feed:ptoken': [ + deploy('deploy_PaymentToken_DataFeed'), + pTokenParam(), + aggregatorTypeParam(true), + ], + 'deploy:dv': [deploy('deploy_DV'), mTokenParam()], + 'deploy:dv:ustb': [deploy('deploy_DVUstb'), mTokenParam()], + 'deploy:dv:aave': [deploy('deploy_DVAave'), mTokenParam()], + 'deploy:dv:morpho': [deploy('deploy_DVMorpho'), mTokenParam()], + 'deploy:dv:mtoken': [deploy('deploy_DVMToken'), mTokenParam()], + 'deploy:rv': [deploy('deploy_RV'), mTokenParam()], + 'deploy:rv:swapper': [deploy('deploy_RVSwapper'), mTokenParam()], + 'deploy:rv:aave': [deploy('deploy_RVAave'), mTokenParam()], + 'deploy:rv:morpho': [deploy('deploy_RVMorpho'), mTokenParam()], + 'deploy:rv:mtoken': [deploy('deploy_RVMToken'), mTokenParam()], + + // Misc + 'deploy:acre:adapter': [ + path.join('scripts/deploy/misc/acre', 'deploy_AcreAdapter.ts'), + mTokenParam(), + pTokenParam(), + ], + + // Codegen + 'deploy:generate:contracts': [deployCodegen('generate_contracts')], + 'deploy:generate:config': [deployCodegen('generate_config'), mTokenParam()], + + // Post-deploy + 'deploy:post:add:ptokens': [deployPost('add_PaymentTokens'), mTokenParam()], + 'deploy:post:grant:roles': [ + deployPost('grant_AllProductRoles'), + mTokenParam(), + ], + 'deploy:post:grant:admin': [deployPost('grant_DefaultAdminRole')], + 'deploy:post:revoke:roles': [deployPost('revoke_DeployerRoles')], + 'deploy:post:transfer:proxyadmin': [ + deployPost('transfer_ProxyAdminToTimelock'), + ], + 'deploy:post:set:price': [ + deployPost('set_RoundData'), + mTokenParam(true), + pTokenParam(true), + ], + 'deploy:post:set:expected-answers': [ + deployPost('set_ExpectedAnswers'), + mTokenParam(true), + pTokenParam(true), + ], + 'deploy:post:set:waived': [deployPost('add_FeeWaived'), mTokenParam()], + 'deploy:post:set:greenlist': [deployPost('set_Greenlist'), mTokenParam()], + 'deploy:post:pause:functions': [deployPost('pause_Functions'), mTokenParam()], + 'deploy:post:add:addressbook': [ + deployPost('add_ToAddressBook'), + mTokenParam(), + keysParam(true), + ], + 'deploy:post:set:sanctionsList': [ + deployPost('set_SanctionsList'), + mTokenParam(), + ], + 'deploy:post:set:aaveconfig': [deployPost('set_AaveConfig'), mTokenParam()], + 'deploy:post:set:morphoconfig': [ + deployPost('set_MorphoConfig'), + mTokenParam(), + ], + + // LayerZero + 'deploy:lz:composer': [ + deployLz('deploy_Composer'), + mTokenParam(), + pTokenParam(), + ], + 'deploy:lz:oft': [ + deployLz('deploy_OFT'), + pTokenParam(), + originalNetworkParam(), + ], + 'deploy:lz:oft:adapter': [deployLz('deploy_OFTAdapter'), pTokenParam()], + 'deploy:lz:oft:adapter:mintburn': [ + deployLz('deploy_MintBurnOFTAdapter'), + mTokenParam(), + originalNetworkParam(true), + ], + 'deploy:lz:post:set:ratelimit': [ + deployLz('set_RateLimitConfigs'), + mTokenParam(), + originalNetworkParam(true), + ], + 'deploy:lz:post:transfer:owner': [ + deployLz('transfer_Owner'), + mTokenParam(true), + pTokenParam(true), + ], + 'deploy:lz:post:grant:roles': [deployLz('grant_Roles'), mTokenParam()], + 'deploy:lz:post:revoke:roles': [deployLz('revoke_Roles'), mTokenParam()], + 'deploy:lz:deprecate': [deployLz('deprecate_Ofts')], + + // Axelar + 'deploy:axelar:executable': [ + deployAxelar('deploy_Executable'), + mTokenParam(), + pTokenParam(), + ], + 'deploy:axelar:post:wire': [ + deployAxelar('wire_Tokens'), + mTokenParam(), + actionParam(true), + ], + 'deploy:axelar:post:wire:ptoken': [ + deployAxelar('wire_PaymentTokens'), + pTokenParam(), + ], + 'deploy:axelar:post:set:flowlimit': [ + deployAxelar('set_FlowLimit'), + mTokenParam(), + ], + 'deploy:axelar:post:grant:roles': [ + deployAxelar('grant_Roles'), + mTokenParam(), + ], + 'deploy:axelar:post:revoke:roles': [ + deployAxelar('revoke_Roles'), + mTokenParam(), + ], + + // Timelock upgrades + 'timelock:upgrade:vaults:propose': [ + upgrade('proposeUpgrade_Vaults'), + actionParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:vaults:execute': [ + upgrade('executeUpgrade_Vaults'), + actionParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:vaults:validate': [ + upgrade('validateUpgrade_Vaults'), + actionParam(), + skipValidationParam(true), + ], + 'timelock:admin:transfer:propose': [ + upgrade('proposeTransferOwnership_ProxyAdmin'), + actionParam(), + skipValidationParam(true), + ], + 'timelock:admin:transfer:execute': [ + upgrade('executeTransferOwnership_ProxyAdmin'), + actionParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:token:propose': [ + upgrade('proposeUpgrade_Token'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:token:execute': [ + upgrade('executeUpgrade_Token'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregators:propose': [ + upgrade('proposeUpgrade_Aggregators'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregators:execute': [ + upgrade('executeUpgrade_Aggregators'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregator-deviation:propose': [ + upgrade('proposeUpgrade_AggregatorDeviation'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregator-deviation:execute': [ + upgrade('executeUpgrade_AggregatorDeviation'), + mTokenParam(), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregator-timelapsed:propose': [ + upgrade('proposeUpgrade_AggregatorTimelapsed'), + mTokenParam(true), + actionParam(true), + skipValidationParam(true), + ], + 'timelock:upgrade:aggregator-timelapsed:execute': [ + upgrade('executeUpgrade_AggregatorTimelapsed'), + mTokenParam(true), + actionParam(true), + skipValidationParam(true), + ], + 'timelock:upgrade:reinitializers:verify': [ + upgrade('verifyUpgrade_Reinitializers'), + mTokenParam(), + ], + 'upgrade:rv:mtoken': [ + upgrade('upgrade_RedemptionVaultMToken'), + mTokenParam(), + ], + + // Verify + 'verify:all:impl': [path.join('scripts', 'verify_contracts.ts')], +}; + +export const deployTasks = Object.entries(deployTasksRecord); diff --git a/tasks/common/index.ts b/tasks/common/index.ts new file mode 100644 index 00000000..ba76c993 --- /dev/null +++ b/tasks/common/index.ts @@ -0,0 +1,3 @@ +export * from './task-params'; +export * from './run-script'; +export * from './deploy-tasks-definition'; diff --git a/tasks/common/run-script.ts b/tasks/common/run-script.ts new file mode 100644 index 00000000..5f1bdef6 --- /dev/null +++ b/tasks/common/run-script.ts @@ -0,0 +1,109 @@ +import { mine } from '@nomicfoundation/hardhat-network-helpers'; +import { + ConfigurableTaskDefinition, + HardhatRuntimeEnvironment, +} from 'hardhat/types'; + +import path from 'node:path'; + +import { ParamFnBase, forkingNetworkParam } from './task-params'; + +import { ENV, chainIds, extendWithContext, rpcUrls } from '../../config'; +import { Network } from '../../config'; +import { isMTokenName, isPaymentTokenName } from '../../helpers/utils'; + +/** Truly global runner flags attached to every script task. */ +export const globalRunScriptParams = [forkingNetworkParam(true)]; + +export const withGlobalRunScriptParams = (task: ConfigurableTaskDefinition) => { + globalRunScriptParams.forEach((paramFn) => { + const param = paramFn(); + if (param.isOptional) { + task.addOptionalParam(param.name, param.description, param.defaultValue); + } else { + task.addParam(param.name, param.description, param.defaultValue); + } + }); + return task; +}; + +/** @deprecated Use withGlobalRunScriptParams */ +export const withRunScriptParams = withGlobalRunScriptParams; + +export const runScript = async ( + taskArgs: Record, + hre: HardhatRuntimeEnvironment, + scriptParams: ParamFnBase[], +) => { + const mtoken = taskArgs.mtoken as string | undefined; + const ptoken = taskArgs.ptoken as string | undefined; + const action = taskArgs.action as string | undefined; + + const forkingNetwork: Network = + (taskArgs.forkingNetwork as Network | undefined) ?? ENV.FORKING_NETWORK; + + if (forkingNetwork) { + console.log('Forking network', forkingNetwork); + await hre.network.provider.request({ + method: 'hardhat_reset', + params: [ + { + forking: { + jsonRpcUrl: rpcUrls[forkingNetwork], + }, + }, + ], + }); + + await mine(); + + const chainId = chainIds[forkingNetwork]; + hre.network.config.chainId = chainId; + hre.network.name = forkingNetwork; + } + + const originalNetwork = taskArgs.originalNetwork as Network | undefined; + const skipValidation = taskArgs.skipValidation as string | undefined; + + // Kept on hre: used by extended-hre, layerzero tasks, and shared script helpers + hre.skipValidation = (skipValidation ?? 'false') === 'true'; + + hre.action = action; + + if (action) { + extendWithContext(hre, `${action}-${new Date().toISOString()}`); + } + + if (mtoken) { + if (!isMTokenName(mtoken)) { + throw new Error('Invalid mtoken parameter'); + } + + hre.mtoken = mtoken; + } + + if (ptoken) { + if (!isPaymentTokenName(ptoken)) { + throw new Error('Invalid ptoken parameter'); + } + hre.paymentToken = ptoken; + } + + if (originalNetwork) { + hre.layerZero = { + originalNetwork, + }; + } + + const scriptPath = taskArgs.path as string; + const scriptPathResolved = path.resolve(scriptPath); + const { default: run } = await import(scriptPathResolved); + + if (!run) { + throw new Error('Script not found or it doesnt have a default export'); + } + + const params = scriptParams.map((param) => param().parse(hre, taskArgs)); + + await run(hre, ...params); +}; diff --git a/tasks/common/task-params.ts b/tasks/common/task-params.ts new file mode 100644 index 00000000..74c8c2f6 --- /dev/null +++ b/tasks/common/task-params.ts @@ -0,0 +1,182 @@ +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +import { MTokenName, Network, PaymentTokenName } from '../../config'; +import { isMTokenName, isPaymentTokenName } from '../../helpers/utils'; + +export type ParamFnBase = () => { + isOptional: boolean; + name: string; + description: string; + /** Hardhat CLI default (always a string when set). */ + defaultValue: string | undefined; + parse: ( + hre: HardhatRuntimeEnvironment, + taskArgs: Record, + ) => TReturn; +}; + +type ValueOrUndefined = T | undefined; +export type ParseParamFn = ( + optional?: boolean, +) => ParamFnBase>; + +export const mTokenParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'mtoken', + description: 'MToken', + defaultValue: undefined, + parse: (hre, _) => { + const mToken = hre.mtoken; + if (!mToken && !isOptional) { + throw new Error('mToken parameter not found'); + } + + if (mToken && !isMTokenName(mToken)) { + throw new Error('Invalid mToken parameter'); + } + + return mToken; + }, + }; +}; + +export const pTokenParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'ptoken', + description: 'Payment Token', + defaultValue: undefined, + parse: (hre, _) => { + const paymentToken = hre.paymentToken; + if (!paymentToken && !isOptional) { + throw new Error('PaymentToken parameter not found'); + } + + if (paymentToken && !isPaymentTokenName(paymentToken)) { + throw new Error('Invalid PaymentToken parameter'); + } + + return paymentToken; + }, + }; +}; + +export const actionParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'action', + description: 'Timelock / upgrade action id', + defaultValue: undefined, + parse: (hre, _) => { + const action = hre.action; + if (!action && !isOptional) { + throw new Error('Action parameter not found'); + } + return action; + }, + }; +}; + +export type AggregatorType = 'numerator' | 'denominator'; + +export const aggregatorTypeParam: ParseParamFn = + (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'aggregatorType', + description: 'Aggregator type (numerator | denominator)', + defaultValue: undefined, + parse: (_, taskArgs) => { + const aggregatorType = taskArgs.aggregatorType as + | AggregatorType + | undefined; + if (!aggregatorType && !isOptional) { + throw new Error('aggregatorType parameter not found'); + } + if ( + aggregatorType && + !['numerator', 'denominator'].includes(aggregatorType) + ) { + throw new Error('Invalid aggregator type parameter'); + } + return aggregatorType; + }, + }; + }; + +export const originalNetworkParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'originalNetwork', + description: 'Original / hub network for LayerZero', + defaultValue: undefined, + parse: (hre, _) => { + const originalNetwork = hre.layerZero?.originalNetwork; + if (!originalNetwork && !isOptional) { + throw new Error('OriginalNetwork parameter not found'); + } + return originalNetwork; + }, + }; +}; + +export const keysParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'keys', + description: + 'Comma-separated list of address book keys to include (e.g. layerZero)', + defaultValue: undefined, + parse: (_, taskArgs) => { + const keys = taskArgs.keys as string | undefined; + if (!keys && !isOptional) { + throw new Error('keys parameter not found'); + } + if (!keys) { + return undefined; + } + return keys + .split(',') + .map((k) => k.trim()) + .filter(Boolean); + }, + }; +}; + +export const skipValidationParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? false; + return { + isOptional, + name: 'skipValidation', + description: 'Skip timelock validation', + defaultValue: 'false', + parse: (hre, _) => { + // Hydrated on hre by runScript for shared timelock helpers + const skipValidation = hre.skipValidation ?? false; + if (skipValidation === undefined && !isOptional) { + throw new Error('skipValidation parameter not found'); + } + return skipValidation; + }, + }; +}; + +export const forkingNetworkParam: ParseParamFn = (optional) => () => { + const isOptional = optional ?? true; + return { + isOptional, + name: 'forkingNetwork', + description: 'Forking Network', + defaultValue: undefined, + parse: (_, taskArgs) => { + return taskArgs.forkingNetwork as Network | undefined; + }, + }; +}; diff --git a/tasks/deploy.ts b/tasks/deploy.ts new file mode 100644 index 00000000..bec49c8a --- /dev/null +++ b/tasks/deploy.ts @@ -0,0 +1,32 @@ +import { task } from 'hardhat/config'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +import { deployTasks, runScript, withGlobalRunScriptParams } from './common'; + +deployTasks.forEach(([name, [scriptPath, ...params]]) => { + const actionFn = async ( + taskArgs: Record, + hre: HardhatRuntimeEnvironment, + ) => { + await runScript({ path: scriptPath, ...taskArgs }, hre, params); + }; + + const t = task(name); + withGlobalRunScriptParams(t); + + params.forEach((param) => { + const metadata = param(); + + if (metadata.isOptional) { + t.addOptionalParam( + metadata.name, + metadata.description, + metadata.defaultValue, + ); + } else { + t.addParam(metadata.name, metadata.description, metadata.defaultValue); + } + }); + + t.setAction(actionFn); +}); diff --git a/tasks/index.ts b/tasks/index.ts index 18dc931f..15c24c01 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,113 +1,29 @@ -import { mine } from '@nomicfoundation/hardhat-network-helpers'; import { task } from 'hardhat/config'; -import path from 'path'; - -import { chainIds, ENV, extendWithContext, Network, rpcUrls } from '../config'; -import { isMTokenName, isPaymentTokenName } from '../helpers/utils'; +import { runScript, withGlobalRunScriptParams } from './common'; import './layerzero'; import './axelar'; import './verify'; +import './deploy'; + +const runScriptTask = task('runscript', 'Runs a user-defined script'); + +withGlobalRunScriptParams(runScriptTask); -task('runscript', 'Runs a user-defined script') +// Ad-hoc runscript still accepts any param so one-off scripts keep working. +runScriptTask .addPositionalParam('path', 'Path to the script') .addOptionalParam('mtoken', 'MToken') .addOptionalParam('ptoken', 'Payment Token') .addOptionalParam('action', 'Timelock Action') - .addOptionalParam('customSignerScript', 'Custom Signer Script') .addOptionalParam('skipValidation', 'Skip Validation', 'false') .addOptionalParam('aggregatorType', 'Aggregator Type') - .addOptionalParam('logToFile', 'Log to file') - .addOptionalParam('logsFolderPath', 'Logs folder path') - .addOptionalParam('forkingNetwork', 'Forking Network') .addOptionalParam('originalNetwork', 'Original Network') .addOptionalParam( 'keys', 'Comma-separated list of address book keys to include (e.g. layerZero)', ) .setAction(async (taskArgs, hre) => { - const mtoken = taskArgs.mtoken; - const ptoken = taskArgs.ptoken; - const action = taskArgs.action; - - const forkingNetwork: Network = - taskArgs.forkingNetwork ?? ENV.FORKING_NETWORK; - - if (forkingNetwork) { - console.log('Forking network', forkingNetwork); - // Fork the specified network - await hre.network.provider.request({ - method: 'hardhat_reset', - params: [ - { - forking: { - jsonRpcUrl: rpcUrls[forkingNetwork], - }, - }, - ], - }); - - await mine(); - - const chainId = chainIds[forkingNetwork]; - hre.network.config.chainId = chainId; - hre.network.name = forkingNetwork; - } - - const originalNetwork = taskArgs.originalNetwork; - const keys = taskArgs.keys; - - const scriptPath = taskArgs.path; - const skipValidation = taskArgs.skipValidation; - - hre.skipValidation = (skipValidation ?? 'false') === 'true'; - hre.aggregatorType = taskArgs.aggregatorType; - - if ( - hre.aggregatorType && - !['numerator', 'denominator'].includes(hre.aggregatorType) - ) { - throw new Error('Invalid aggregator type parameter'); - } - - hre.action = action; - - if (action) { - extendWithContext(hre, `${action}-${new Date().toISOString()}`); - } - - if (mtoken) { - if (!isMTokenName(mtoken)) { - throw new Error('Invalid mtoken parameter'); - } - - hre.mtoken = mtoken; - } - - if (ptoken) { - if (!isPaymentTokenName(ptoken)) { - throw new Error('Invalid ptoken parameter'); - } - hre.paymentToken = ptoken; - } - - if (originalNetwork) { - hre.layerZero = { - originalNetwork, - }; - } - - if (keys) { - hre.addressBookKeys = keys.split(',').map((k: string) => k.trim()); - } - - const scriptPathResolved = path.resolve(scriptPath); - const { default: run } = await import(scriptPathResolved); - - if (!run) { - throw new Error('Script not found or it doesnt have a default export'); - } - - await run(hre); + await runScript(taskArgs, hre, []); }); diff --git a/types/hardhat.d.ts b/types/hardhat.d.ts index 39132020..f13d323f 100644 --- a/types/hardhat.d.ts +++ b/types/hardhat.d.ts @@ -19,8 +19,6 @@ declare module 'hardhat/types/runtime' { paymentToken?: PaymentTokenName; action?: string; skipValidation?: boolean; - aggregatorType?: 'numerator' | 'denominator'; - addressBookKeys?: string[]; logger: { // default: false logToFile: boolean;