From 9414820b63b4512d8857580e171bd44b52a1c880 Mon Sep 17 00:00:00 2001 From: Alexandre ABRIOUX Date: Tue, 17 Oct 2023 11:00:52 +0200 Subject: [PATCH] refactor(toolbox): addAggregator immutable args (#1195) Co-authored-by: MantisClone --- .../src/commands/chainlink/addAggregator.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/toolbox/src/commands/chainlink/addAggregator.ts b/packages/toolbox/src/commands/chainlink/addAggregator.ts index cdca3a748e..7492f8da13 100644 --- a/packages/toolbox/src/commands/chainlink/addAggregator.ts +++ b/packages/toolbox/src/commands/chainlink/addAggregator.ts @@ -57,32 +57,35 @@ export const builder = (): yargs.Argv => }); export const handler = async (args: Options): Promise => { - let { input, output, aggregator } = args; + const { input, output, aggregator: aggregatorArg } = args; const { network, list } = args; - const currencyManager = await getCurrencyManager(list); - EvmChains.assertChainSupported(network); + const currencyManager = await getCurrencyManager(list); const inputCcy = currencyManager.from(input, network) || currencyManager.from(input); const outputCcy = currencyManager.from(output, network) || currencyManager.from(output); - if (!input.startsWith('0x')) { + let inputAddress = input; + if (!inputAddress.startsWith('0x')) { assert(inputCcy, `input ${input} not found`); - input = inputCcy.hash; + inputAddress = inputCcy.hash; } - if (!output.startsWith('0x')) { + + let outputAddress = output; + if (!outputAddress.startsWith('0x')) { assert(outputCcy, `output ${output} not found`); - output = outputCcy.hash; + outputAddress = outputCcy.hash; } - if (!aggregator) { - aggregator = `${inputCcy?.symbol} / ${outputCcy?.symbol}`; - } - if (!aggregator.startsWith('0x')) { + + const aggregator = aggregatorArg || `${inputCcy?.symbol} / ${outputCcy?.symbol}`; + let aggregatorAddress = aggregator; + if (!aggregatorAddress.startsWith('0x')) { const aggregators = await getAllAggregators(network); const newAggregator = aggregators.find((x) => x.name === aggregator); assert(newAggregator, `aggregator ${aggregator} not found`); - aggregator = newAggregator?.proxyAddress; + aggregatorAddress = newAggregator?.proxyAddress; } - assert(aggregator); - await runUpdate('updateAggregator', [input, output, aggregator], args); + assert(aggregatorAddress); + + await runUpdate('updateAggregator', [inputAddress, outputAddress, aggregatorAddress], args); };