Skip to content

Commit

Permalink
Alias support
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa committed Jul 19, 2024
1 parent 01e77f8 commit e574351
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
6 changes: 2 additions & 4 deletions conf/mainnets/crab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ tokens:
decimals: 18
type: native
- symbol: RING
address: '0x273131F7CB50ac002BDd08cA721988731F7e1092'
decimals: 18
type: erc20
- symbol: xWRING
alias:
- xWRING
name: xWRING
address: '0x273131F7CB50ac002BDd08cA721988731F7e1092'
decimals: 18
Expand Down
10 changes: 5 additions & 5 deletions conf/mainnets/darwinia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ tokens:
decimals: 18
type: native
- symbol: CRAB
address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305'
decimals: 18
type: erc20
- symbol: xWCRAB
alias:
- xWCRAB
name: xWCRAB
address: '0x656567Eb75b765FC320783cc6EDd86bD854b2305'
decimals: 18
Expand All @@ -22,7 +20,9 @@ tokens:
address: '0x0000000000000000000000000000000000000404'
decimals: 10
type: erc20
- symbol: ahUSDT
- symbol: USDT
alias:
- ahUSDT
name: ahUSDT
address: '0x0000000000000000000000000000000000000403'
decimals: 6
Expand Down
4 changes: 3 additions & 1 deletion conf/mainnets/moonbeam.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ tokens:
address: '0xfa9343c3897324496a05fc75abed6bac29f8a40f'
decimals: 18
type: erc20
- symbol: xcUSDT
- symbol: USDT
alias:
- xcUSDT
name: xcUSDT
address: '0xFFFFFFfFea09FB06d082fd1275CD48b191cbCD1d'
decimals: 6
Expand Down
13 changes: 13 additions & 0 deletions scripts/generate/stdconf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export function standardization(global, ccf) {
function _stdGeneric(global, ccf) {
if (!ccf.messagers) ccf.messagers = [];
if (!ccf.couples) ccf.couples = [];
if (!ccf.tokens) ccf.tokens = [];
if (!ccf.rpcs) ccf.rpcs = [];
if (!ccf.protocol) ccf.protocol = {};
}

function _stdCouples(global, ccf) {
Expand All @@ -28,6 +31,16 @@ function _stdTokens(global, ccf) {
if (!token.name) {
token.name = token.symbol;
}
const alias = token.alias || [];
const stdAlias = [];
for (let i = alias.length; i-- > 0;) {
if (!alias[i]) continue;
stdAlias.push(alias[i].toUpperCase());
}
if (stdAlias.indexOf(token.symbol) == -1) {
stdAlias.push(token.symbol);
}
token.alias = stdAlias;
}
}

Expand Down
2 changes: 1 addition & 1 deletion template/ts/files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helixbridge/helixconf",
"version": "0.0.8",
"version": "0.0.9",
"description": "Helix conf",
"main": "dist/src/index.js",
"publishConfig": {
Expand Down
12 changes: 11 additions & 1 deletion template/ts/files/src/helixconf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export interface ChainToken {
symbol: string
address: string
decimals: number
type: TokenType,
type: TokenType
name: string
alias: string[]
}

export interface ChainCouple {
Expand Down Expand Up @@ -119,6 +120,15 @@ export class HelixChainConf {
return Object.keys(this._data) as Array<keyof HelixChainConfType>;
}

token(symbol: string): ChainToken | undefined {
const uppercaseSymbol = symbol.toUpperCase();
for (const token of this.tokens) {
if (token.alias.indexOf(uppercaseSymbol) != -1) {
return token;
}
}
}

categories(): string[] {
const categories = this.couples.map(item => item.category);
return categories.reduce((acc: string[], item: string) => {
Expand Down

0 comments on commit e574351

Please sign in to comment.