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 && diff --git a/tasks/types.ts b/tasks/types.ts index 4074f1f13..f309530f5 100644 --- a/tasks/types.ts +++ b/tasks/types.ts @@ -75,9 +75,9 @@ const booleanArray: CLIArgumentType> = { }, }; -const stratConfig: CLIArgumentType = { +const stratConfig: CLIArgumentType = { name: "StratConfig", - parse: (_, strValue) => allStrategyConfigs[strValue] || {error: strValue}, + parse: (argName, strValue) => string.parse(argName, strValue), /** * Check if argument value is of type "StratConfig" * @@ -87,10 +87,13 @@ const stratConfig: CLIArgumentType = { * @throws HH301 if value is not of type "StratConfig" */ validate: (argName: string, argValue: any): void => { - if (!argValue || typeof argValue !== "object" || "error" in argValue) { - const invalidValue = "error" in argValue ? argValue.error : argValue; + string.validate(argName, argValue); + + const possibleValues = Object.keys(allStrategyConfigs); + + if (!possibleValues.includes(argValue)) { throw new Error( - `Invalid value '${invalidValue}' for argument '${argName}' of type \`StratConfig\`` + `Invalid value '${argValue}' for argument '${argName}', possible values: ${possibleValues}` ); } }, diff --git a/utils/manageStratParams/types.ts b/utils/manageStratParams/types.ts index fa2789f23..e2924924d 100644 --- a/utils/manageStratParams/types.ts +++ b/utils/manageStratParams/types.ts @@ -12,7 +12,7 @@ export type StratConfig = { params: LocalRegistrarLib.StrategyParamsStruct; }; -export type AllStratConfigs = Record; +export type AllStratConfigs = Record<"dummy" | "flux", StratConfig>; export type StrategyObject = { locked: string;