Skip to content

Commit d0107e5

Browse files
authored
Merge branch 'master' into chore/refactor-pn-ids-ble
2 parents 02f0b28 + abc53c7 commit d0107e5

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

packages/toolbox/src/commands/chainlink/addAggregator.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as yargs from 'yargs';
22
import { runUpdate } from './contractUtils';
3+
import { getAllAggregators, getCurrencyManager } from './aggregatorsUtils';
4+
import assert from 'assert';
35

46
type Options = {
57
dryRun: boolean;
@@ -8,7 +10,8 @@ type Options = {
810
mnemonic?: string;
911
input: string;
1012
output: string;
11-
aggregator: string;
13+
aggregator?: string;
14+
list?: string;
1215
};
1316

1417
export const command = 'addAggregator <network>';
@@ -26,14 +29,17 @@ export const builder = (): yargs.Argv<Options> =>
2629
input: {
2730
type: 'string',
2831
demandOption: true,
32+
describe: 'The token hash, or symbol, to use as input',
2933
},
3034
output: {
3135
type: 'string',
3236
demandOption: true,
37+
describe: 'The token hash, or symbol, to use as output',
3338
},
3439
aggregator: {
3540
type: 'string',
36-
demandOption: true,
41+
describe:
42+
'The address of the aggregation contract, or its name on ChainLink docs. eg. "USDC / USD". If omitted, will default to "input / output"',
3743
},
3844
mnemonic: {
3945
type: 'string',
@@ -42,9 +48,38 @@ export const builder = (): yargs.Argv<Options> =>
4248
type: 'string',
4349
describe: 'Takes precedence over mnemonic',
4450
},
51+
list: {
52+
type: 'string',
53+
describe:
54+
'Required when passing symbols in input or output. The list NAME must be available at https://api.request.network/currency/list/NAME',
55+
},
4556
});
4657

4758
export const handler = async (args: Options): Promise<void> => {
48-
const { input, output, aggregator } = args;
59+
let { input, output, aggregator } = args;
60+
const { network, list } = args;
61+
62+
const currencyManager = await getCurrencyManager(list);
63+
const inputCcy = currencyManager.from(input, network) || currencyManager.from(input);
64+
const outputCcy = currencyManager.from(output, network) || currencyManager.from(output);
65+
66+
if (!input.startsWith('0x')) {
67+
assert(inputCcy, `input ${input} not found`);
68+
input = inputCcy.hash;
69+
}
70+
if (!output.startsWith('0x')) {
71+
assert(outputCcy, `output ${output} not found`);
72+
output = outputCcy.hash;
73+
}
74+
if (!aggregator) {
75+
aggregator = `${inputCcy?.symbol} / ${outputCcy?.symbol}`;
76+
}
77+
if (!aggregator.startsWith('0x')) {
78+
const aggregators = await getAllAggregators(network);
79+
const newAggregator = aggregators.find((x) => x.pair === aggregator);
80+
assert(newAggregator, `aggregator ${aggregator} not found`);
81+
aggregator = newAggregator.proxy;
82+
}
83+
assert(aggregator);
4984
await runUpdate('updateAggregator', [input, output, aggregator], args);
5085
};

packages/toolbox/src/commands/chainlink/aggregatorsUtils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ const feedMap: Record<string, [chainKey: string, networkName: string]> = {
3737
avalanche: ['avalanche', 'Avalanche Mainnet'],
3838
};
3939

40-
export const getAvailableAggregators = async (
41-
network: string,
42-
cm: CurrencyManager,
43-
pairs?: string[],
44-
listAll?: boolean,
45-
): Promise<Aggregator[]> => {
40+
export const getAllAggregators = async (network: string): Promise<Proxy[]> => {
4641
const [feedName, networkName] = feedMap[network] || [];
4742
if (!feedName || !networkName) {
4843
throw new Error(
@@ -57,11 +52,22 @@ export const getAvailableAggregators = async (
5752
if (!proxies) {
5853
throw new Error(`not proxies for feed ${feedName} > ${networkName}`);
5954
}
55+
return proxies;
56+
};
57+
58+
export const getAvailableAggregators = async (
59+
network: string,
60+
cm: CurrencyManager,
61+
pairs?: string[],
62+
listAll?: boolean,
63+
): Promise<Aggregator[]> => {
64+
const proxies = await getAllAggregators(network);
65+
6066
const missingAggregators: Aggregator[] = [];
6167
for (const proxy of proxies) {
6268
const [from, to] = proxy.pair.split(' / ');
63-
const fromCurrency = cm.from(from, network);
64-
const toCurrency = cm.from(to, network);
69+
const fromCurrency = cm.from(from, network) || cm.from(from);
70+
const toCurrency = cm.from(to, network) || cm.from(to);
6571
if (pairs && !pairs.includes(`${from}-${to}`.toLowerCase())) {
6672
continue;
6773
}

0 commit comments

Comments
 (0)