11import * as yargs from 'yargs' ;
22import { runUpdate } from './contractUtils' ;
3+ import { getAllAggregators , getCurrencyManager } from './aggregatorsUtils' ;
4+ import assert from 'assert' ;
35
46type 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
1417export 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
4758export 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} ;
0 commit comments