Skip to content

Commit 78671d6

Browse files
authored
chore: replaced references to chainlink with aggregators (#923)
1 parent 2386f1b commit 78671d6

File tree

6 files changed

+48
-24
lines changed

6 files changed

+48
-24
lines changed

packages/currency/src/chainlink-path-aggregators.ts renamed to packages/currency/src/conversion-aggregators.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,55 @@ import fantomAggregator from './aggregators/fantom.json';
99
import nearAggregator from './aggregators/near.json';
1010
import nearTestnetAggregator from './aggregators/near-testnet.json';
1111

12+
/**
13+
* currencyFrom => currencyTo => cost
14+
*/
1215
export type CurrencyPairs = Record<string, Record<string, number>>;
13-
// List of currencies supported by network (can be generated from requestNetwork/toolbox/src/chainlinkConversionPathTools.ts)
14-
// Network => currencyFrom => currencyTo => cost
15-
// Must be updated every time an aggregator is added
16-
export const chainlinkCurrencyPairs: Record<string, CurrencyPairs> = {
16+
17+
/**
18+
* Aggregators maps define pairs of currencies for which an onchain oracle exists, by network.
19+
*
20+
* Network => currencyFrom => currencyTo => cost
21+
*/
22+
export type AggregatorsMap = Record<string, CurrencyPairs>;
23+
24+
// Pairs supported by Chainlink (can be generated from requestNetwork/toolbox/src/chainlinkConversionPathTools.ts)
25+
const chainlinkCurrencyPairs: AggregatorsMap = {
1726
private: privateAggregator,
1827
rinkeby: rinkebyAggregator,
19-
goerli: {},
2028
mainnet: mainnetAggregator,
2129
matic: maticAggregator,
2230
fantom: fantomAggregator,
23-
// FIX ME: This fix enables to get these networks registered in chainlinkSupportedNetworks.
24-
// Could be improved by removing the supported network check from the protocol
31+
};
32+
33+
// Pairs supported by Flux Protocol
34+
const fluxCurrencyPairs: AggregatorsMap = {
35+
aurora: nearAggregator,
36+
'aurora-testnet': nearTestnetAggregator,
37+
};
38+
39+
// FIX ME: This fix enables to get these networks registered in conversionSupportedNetworks.
40+
// Could be improved by removing the supported network check from the protocol
41+
const noConversionNetworks: AggregatorsMap = {
42+
goerli: {},
2543
'arbitrum-rinkeby': {},
2644
'arbitrum-one': {},
2745
xdai: {},
2846
avalanche: {},
2947
bsc: {},
30-
aurora: nearAggregator,
31-
'aurora-testnet': nearTestnetAggregator,
3248
};
3349

34-
export const chainlinkSupportedNetworks = Object.keys(chainlinkCurrencyPairs);
50+
/**
51+
* Conversion paths per network used by default if no other path given to the Currency Manager.
52+
* Must be updated every time an aggregator is added to one network.
53+
*/
54+
export const defaultConversionPairs: AggregatorsMap = {
55+
...chainlinkCurrencyPairs,
56+
...fluxCurrencyPairs,
57+
...noConversionNetworks,
58+
};
59+
60+
export const conversionSupportedNetworks = Object.keys(defaultConversionPairs);
3561

3662
/**
3763
* Gets the on-chain conversion path between two currencies.
@@ -47,7 +73,7 @@ export function getPath(
4773
currencyFrom: Pick<CurrencyDefinition, 'hash'>,
4874
currencyTo: Pick<CurrencyDefinition, 'hash'>,
4975
network = 'mainnet',
50-
pairs = chainlinkCurrencyPairs,
76+
pairs = defaultConversionPairs,
5177
): string[] | null {
5278
if (!pairs[network]) {
5379
throw Error(`network ${network} not supported`);

packages/currency/src/currencyManager.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
LegacyTokenMap,
1616
NativeCurrencyType,
1717
} from './types';
18-
import { chainlinkCurrencyPairs, CurrencyPairs, getPath } from './chainlink-path-aggregators';
18+
import { defaultConversionPairs, AggregatorsMap, getPath } from './conversion-aggregators';
1919
import { isValidNearAddress } from './currency-utils';
2020

2121
const { BTC, ERC20, ERC777, ETH, ISO4217 } = RequestLogicTypes.CURRENCY;
@@ -26,17 +26,18 @@ const { BTC, ERC20, ERC777, ETH, ISO4217 } = RequestLogicTypes.CURRENCY;
2626
export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta> {
2727
private readonly knownCurrencies: CurrencyDefinition<TMeta>[];
2828
private readonly legacyTokens: LegacyTokenMap;
29-
private readonly conversionPairs: Record<string, CurrencyPairs>;
29+
private readonly conversionPairs: AggregatorsMap;
3030

3131
/**
3232
*
3333
* @param inputCurrencies The list of currencies known by the Manager.
3434
* @param legacyTokens A mapping of legacy currency name or network name, in the format { "chainName": {"TOKEN": ["NEW_TOKEN","NEW_CHAIN"]}}
35+
* @param conversionPairs A mapping of possible conversions by network (network => currencyFrom => currencyTo => cost)
3536
*/
3637
constructor(
3738
inputCurrencies: (CurrencyInput & { id?: string; meta?: TMeta })[],
3839
legacyTokens?: LegacyTokenMap,
39-
conversionPairs?: Record<string, CurrencyPairs>,
40+
conversionPairs?: AggregatorsMap,
4041
) {
4142
this.knownCurrencies = [];
4243
for (const input of inputCurrencies) {
@@ -294,8 +295,8 @@ export class CurrencyManager<TMeta = unknown> implements ICurrencyManager<TMeta>
294295
};
295296
}
296297

297-
static getDefaultConversionPairs(): Record<string, CurrencyPairs> {
298-
return chainlinkCurrencyPairs;
298+
static getDefaultConversionPairs(): AggregatorsMap {
299+
return defaultConversionPairs;
299300
}
300301

301302
/**

packages/currency/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
export { getSupportedERC20Tokens } from './erc20';
22
export { getSupportedERC777Tokens } from './erc777';
3-
export {
4-
chainlinkSupportedNetworks as conversionSupportedNetworks,
5-
CurrencyPairs,
6-
} from './chainlink-path-aggregators';
3+
export { conversionSupportedNetworks, CurrencyPairs } from './conversion-aggregators';
74
export { getHash as getCurrencyHash } from './getHash';
85
export { CurrencyManager } from './currencyManager';
96
export * from './types';

packages/currency/test/chainlink-path-aggregators.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import { CurrencyPairs, getPath } from '../src/chainlink-path-aggregators';
2+
import { CurrencyPairs, getPath } from '../src/conversion-aggregators';
33
import { CurrencyManager } from '../src';
44
const currencyManager = CurrencyManager.getDefault();
55
const USD = currencyManager.from('USD')!;

packages/toolbox/src/chainlinkConversionPathTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export const listAggregators = async (options?: IOptions): Promise<void> => {
178178
// enables this usage: yarn -s chainlinkPath mainnet | clip
179179
console.error('#####################################################################');
180180
console.error('All aggregators nodes (currency) :');
181-
console.error('../currency/src/chainlink-path-aggregators.ts');
181+
console.error('../currency/src/conversion-aggregators.ts');
182182
console.log(JSON.stringify(aggregatorsNodesForDijkstra, null, 2));
183183
};
184184

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export const handler = async (args: Options): Promise<void> => {
7575

7676
if (!conversionSupportedNetworks.includes(network)) {
7777
console.warn(
78-
`WARNING: ${network} is missing in chainlinkSupportedNetworks from the Currency package.`,
79-
`Add '${network}: {}' to chainlinkCurrencyPairs, in currency/src/chainlink-path-aggregators.ts.`,
78+
`WARNING: ${network} is missing in conversionSupportedNetworks from the Currency package.`,
79+
`Add '${network}: {}' to chainlinkCurrencyPairs, in currency/src/conversion-aggregators.ts.`,
8080
);
8181
}
8282

0 commit comments

Comments
 (0)