-
Notifications
You must be signed in to change notification settings - Fork 0
Make manage:registrar:setStrarParam
more intuitive
#395
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed the expected type in cliTypes.stratConfig.validate |
||
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,36 +32,26 @@ 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( | ||
"manage:registrar:setStratParams:on-network", | ||
"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 && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,9 +75,9 @@ const booleanArray: CLIArgumentType<Array<boolean>> = { | |
}, | ||
}; | ||
|
||
const stratConfig: CLIArgumentType<StratConfig> = { | ||
const stratConfig: CLIArgumentType<string> = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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<StratConfig> = { | |
* @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}` | ||
); | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,7 +12,7 @@ export type StratConfig = { | |||||
params: LocalRegistrarLib.StrategyParamsStruct; | ||||||
}; | ||||||
|
||||||
export type AllStratConfigs = Record<string, StratConfig>; | ||||||
export type AllStratConfigs = Record<"dummy" | "flux", StratConfig>; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better type-safety There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a huge fan of this change. It means that each new strategy has to modify a Type which doesn't seem like it's a meaningful Type def. I would prefer the only edits necessary to be in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think type-safety and restrictiveness come in a package 😕 I understood this type to be to strategy-addresses.json what evm-smart-contracts/tasks/deploy/integrations/helpers/fullStrategy.ts Lines 18 to 19 in 48bcff3
If you think we better leave this change for some other time, I'll remove it for now |
||||||
|
||||||
export type StrategyObject = { | ||||||
locked: string; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better type-safety