Skip to content

Commit 059fc0a

Browse files
authored
Merge pull request #6612 from BitGo/WIN-6425
feat: add taoToken skeleton
2 parents f2a8d3c + c3d65a2 commit 059fc0a

File tree

6 files changed

+81
-2
lines changed

6 files changed

+81
-2
lines changed

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
Nep141TokenConfig,
3535
CosmosTokenConfig,
3636
VetTokenConfig,
37+
TaoTokenConfig,
3738
} from '@bitgo/statics';
3839
import {
3940
Ada,
@@ -121,6 +122,7 @@ import {
121122
SuiToken,
122123
Susd,
123124
Tao,
125+
TaoToken,
124126
Ton,
125127
Tada,
126128
Talgo,
@@ -490,6 +492,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
490492
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
491493
);
492494

495+
TaoToken.createTokenConstructors([...tokens.bitcoin.tao.tokens, ...tokens.testnet.tao.tokens]).forEach(
496+
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
497+
);
498+
493499
XrpToken.createTokenConstructors([...tokens.bitcoin.xrp.tokens, ...tokens.testnet.xrp.tokens]).forEach(
494500
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
495501
);
@@ -910,6 +916,9 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
910916
case 'sui':
911917
case 'tsui':
912918
return SuiToken.createTokenConstructor(tokenConfig as SuiTokenConfig);
919+
case 'tao':
920+
case 'ttao':
921+
return TaoToken.createTokenConstructor(tokenConfig as TaoTokenConfig);
913922
case 'xrp':
914923
case 'txrp':
915924
return XrpToken.createTokenConstructor(tokenConfig as XrpTokenConfig);

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { Sgb, Tsgb } from '@bitgo/sdk-coin-sgb';
5959
import { Sol, Tsol } from '@bitgo/sdk-coin-sol';
6060
import { Stx, Tstx, Sip10Token } from '@bitgo/sdk-coin-stx';
6161
import { Sui, Tsui, SuiToken } from '@bitgo/sdk-coin-sui';
62-
import { Tao, Ttao } from '@bitgo/sdk-coin-tao';
62+
import { Tao, Ttao, TaoToken } from '@bitgo/sdk-coin-tao';
6363
import { Tia, Ttia } from '@bitgo/sdk-coin-tia';
6464
import { Ton, Tton } from '@bitgo/sdk-coin-ton';
6565
import { Trx, Ttrx } from '@bitgo/sdk-coin-trx';
@@ -131,7 +131,7 @@ export { Soneium, Tsoneium, SoneiumToken };
131131
export { Stt, Tstt };
132132
export { Stx, Tstx, Sip10Token };
133133
export { Sui, Tsui, SuiToken };
134-
export { Tao, Ttao };
134+
export { Tao, Ttao, TaoToken };
135135
export { Tia, Ttia };
136136
export { Ton, Tton };
137137
export { Bld, Tbld };

modules/bitgo/test/browser/browser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('Coins', () => {
2929
OpethToken: 1,
3030
ZkethToken: 1,
3131
SuiToken: 1,
32+
TaoToken: 1,
3233
BeraToken: 1,
3334
XrpToken: 1,
3435
Rune: 1,

modules/sdk-coin-tao/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './lib';
22
export * from './register';
33
export * from './tao';
44
export * from './ttao';
5+
export * from './taoToken';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { BitGoBase } from '@bitgo/sdk-core';
22
import { Tao } from './tao';
33
import { Ttao } from './ttao';
4+
import { TaoToken } from './taoToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('tao', Tao.createInstance);
78
sdk.register('ttao', Ttao.createInstance);
9+
TaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { coins, TaoTokenConfig, tokens } from '@bitgo/statics';
2+
import { Tao } from './tao';
3+
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
4+
5+
export class TaoToken extends Tao {
6+
public readonly tokenConfig: TaoTokenConfig;
7+
8+
constructor(bitgo: BitGoBase, tokenConfig: TaoTokenConfig) {
9+
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('tao') : coins.get('ttao');
10+
super(bitgo, staticsCoin);
11+
this.tokenConfig = tokenConfig;
12+
}
13+
14+
static createTokenConstructor(config: TaoTokenConfig): CoinConstructor {
15+
return (bitgo: BitGoBase) => new TaoToken(bitgo, config);
16+
}
17+
18+
static createTokenConstructors(
19+
tokenConfigs: TaoTokenConfig[] = [...tokens.bitcoin.tao.tokens, ...tokens.testnet.tao.tokens]
20+
): NamedCoinConstructor[] {
21+
const tokensCtors: NamedCoinConstructor[] = [];
22+
for (const token of tokenConfigs) {
23+
const tokenConstructor = TaoToken.createTokenConstructor(token);
24+
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor });
25+
}
26+
return tokensCtors;
27+
}
28+
29+
get name(): string {
30+
return this.tokenConfig.name;
31+
}
32+
33+
get coin(): string {
34+
return this.tokenConfig.coin;
35+
}
36+
37+
get network(): string {
38+
return this.tokenConfig.network;
39+
}
40+
41+
get subnetId(): string {
42+
return this.tokenConfig.subnetId;
43+
}
44+
45+
get decimalPlaces(): number {
46+
return this.tokenConfig.decimalPlaces;
47+
}
48+
49+
getChain(): string {
50+
return this.tokenConfig.type;
51+
}
52+
53+
getBaseChain(): string {
54+
return this.coin;
55+
}
56+
57+
getFullName(): string {
58+
return this._staticsCoin.fullName;
59+
}
60+
61+
getBaseFactor(): number {
62+
return Math.pow(10, this.tokenConfig.decimalPlaces);
63+
}
64+
}

0 commit comments

Comments
 (0)