From 48bcff32e877543d19f92d0b03836738f2269669 Mon Sep 17 00:00:00 2001 From: Nenad Date: Mon, 2 Oct 2023 11:37:07 +0200 Subject: [PATCH] Refactor manage:registrar:setStratParams to read StratConfig during runtime --- .../integrations/helpers/fullStrategy.ts | 5 +- tasks/manage/registrar/setStratParams.ts | 57 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/tasks/deploy/integrations/helpers/fullStrategy.ts b/tasks/deploy/integrations/helpers/fullStrategy.ts index 28d3b69d4..030348a0d 100644 --- a/tasks/deploy/integrations/helpers/fullStrategy.ts +++ b/tasks/deploy/integrations/helpers/fullStrategy.ts @@ -1,6 +1,7 @@ import {ContractFactory} from "ethers"; import {Deployment, StrategyApprovalState} from "types"; import { + AllStratConfigs, deploy, getAddresses, getChainId, @@ -15,7 +16,7 @@ import {deployVaultPair} from "contracts/core/vault/scripts/deployVaultPair"; import {HardhatRuntimeEnvironment} from "hardhat/types"; export async function deployStrategySet( - strategyName: string, + strategyName: keyof AllStratConfigs, factory: ContractFactory, signerPkey: string, hre: HardhatRuntimeEnvironment @@ -65,7 +66,7 @@ export async function deployStrategySet( // establish registrar config on primary chain and this chain await hre.run("manage:registrar:setStratParams", { - stratName: strategyName, + strategyName: strategyName, modifyExisting: true, apTeamSignerPkey: signerPkey, }); diff --git a/tasks/manage/registrar/setStratParams.ts b/tasks/manage/registrar/setStratParams.ts index e0c3739fd..dd19291e8 100644 --- a/tasks/manage/registrar/setStratParams.ts +++ b/tasks/manage/registrar/setStratParams.ts @@ -1,23 +1,28 @@ import {allStrategyConfigs} from "contracts/integrations/stratConfig"; -import {subtask, task, types} from "hardhat/config"; +import {subtask, task} from "hardhat/config"; import {submitMultiSigTx} from "tasks/helpers"; import {cliTypes} from "tasks/types"; import {Registrar__factory} from "typechain-types"; import {ChainID} from "types"; -import {StratConfig, getAPTeamOwner, getAddressesByNetworkId, isProdNetwork, logger} from "utils"; +import { + AllStratConfigs, + StratConfig, + getAPTeamOwner, + getAddressesByNetworkId, + getPrimaryChainId, + logger, +} from "utils"; type TaskArgs = { - stratConfig: StratConfig; + strategyName: keyof AllStratConfigs; modifyExisting: boolean; apTeamSignerPkey?: string; }; task("manage:registrar:setStratParams") .addParam( - "stratConfig", - `The name of the strategy according to StratConfig, possible values: ${Object.keys( - allStrategyConfigs - ).join(", ")}`, + "strategyName", + `The name of the strategy, possible values: ${Object.keys(allStrategyConfigs).join(", ")}`, undefined, cliTypes.stratConfig ) @@ -27,25 +32,17 @@ task("manage:registrar:setStratParams") "If running on prod, provide a pkey for a valid APTeam Multisig Owner." ) .setAction(async function (taskArguments: TaskArgs, hre) { - if (await isProdNetwork(hre)) { - await hre.run("manage:registrar:setStratParams:on-network", { - ...taskArguments, - chainId: ChainID.polygon, - }); - await hre.run("manage:registrar:setStratParams:on-network", { - ...taskArguments, - chainId: taskArguments.stratConfig.chainId, - }); - } else { - await hre.run("manage:registrar:setStratParams:on-network", { - ...taskArguments, - chainId: ChainID.mumbai, - }); - await hre.run("manage:registrar:setStratParams:on-network", { - ...taskArguments, - chainId: taskArguments.stratConfig.chainId, - }); - } + const mainChainId = await getPrimaryChainId(hre); + const stratChainId = allStrategyConfigs[taskArguments.strategyName].chainId; + + await hre.run("manage:registrar:setStratParams:on-network", { + ...taskArguments, + chainId: mainChainId, + }); + await hre.run("manage:registrar:setStratParams:on-network", { + ...taskArguments, + chainId: stratChainId, + }); }); subtask( @@ -53,10 +50,8 @@ subtask( "Updates strat params on the network specified by the 'chainId' param" ) .addParam( - "stratName", - `The name of the strategy according to StratConfig, possible values: ${Object.keys( - allStrategyConfigs - ).join(", ")}`, + "strategyName", + `The name of the strategy, possible values: ${Object.keys(allStrategyConfigs).join(", ")}`, undefined, cliTypes.stratConfig ) @@ -85,7 +80,7 @@ subtask( logger.divider(); logger.out("Checking current strategy params at specified selector"); - const config: StratConfig = taskArguments.stratConfig; + const config: StratConfig = allStrategyConfigs[taskArguments.strategyName]; let currentStratParams = await registrar.getStrategyParamsById(config.id); if ( currentStratParams.liquidVaultAddr == hre.ethers.constants.AddressZero &&