Skip to content

Commit ea00ff3

Browse files
authored
Merge pull request #6639 from BitGo/WIN-6573
feat: add polyxToken skeleton
2 parents 6903c47 + c7be0ef commit ea00ff3

File tree

6 files changed

+85
-2
lines changed

6 files changed

+85
-2
lines changed

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
CosmosTokenConfig,
3636
VetTokenConfig,
3737
TaoTokenConfig,
38+
PolyxTokenConfig,
3839
} from '@bitgo/statics';
3940
import {
4041
Ada,
@@ -107,6 +108,7 @@ import {
107108
Polygon,
108109
PolygonToken,
109110
Polyx,
111+
PolyxToken,
110112
Rune,
111113
Rbtc,
112114
Sei,
@@ -496,6 +498,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
496498
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
497499
);
498500

501+
PolyxToken.createTokenConstructors([...tokens.bitcoin.polyx.tokens, ...tokens.testnet.polyx.tokens]).forEach(
502+
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
503+
);
504+
499505
XrpToken.createTokenConstructors([...tokens.bitcoin.xrp.tokens, ...tokens.testnet.xrp.tokens]).forEach(
500506
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
501507
);
@@ -919,6 +925,9 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
919925
case 'tao':
920926
case 'ttao':
921927
return TaoToken.createTokenConstructor(tokenConfig as TaoTokenConfig);
928+
case 'polyx':
929+
case 'tpolyx':
930+
return PolyxToken.createTokenConstructor(tokenConfig as PolyxTokenConfig);
922931
case 'xrp':
923932
case 'txrp':
924933
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
@@ -49,7 +49,7 @@ import { Oas, Toas } from '@bitgo/sdk-coin-oas';
4949
import { Opeth, Topeth, OpethToken } from '@bitgo/sdk-coin-opeth';
5050
import { Osmo, Tosmo } from '@bitgo/sdk-coin-osmo';
5151
import { Polygon, PolygonToken, Tpolygon } from '@bitgo/sdk-coin-polygon';
52-
import { Polyx, Tpolyx } from '@bitgo/sdk-coin-polyx';
52+
import { Polyx, Tpolyx, PolyxToken } from '@bitgo/sdk-coin-polyx';
5353
import { Rbtc, Trbtc } from '@bitgo/sdk-coin-rbtc';
5454
import { Rune, Trune } from '@bitgo/sdk-coin-rune';
5555
import { Sei, Tsei } from '@bitgo/sdk-coin-sei';
@@ -122,7 +122,7 @@ export { Oas, Toas };
122122
export { Opeth, Topeth, OpethToken };
123123
export { Osmo, Tosmo };
124124
export { Polygon, PolygonToken, Tpolygon };
125-
export { Polyx, Tpolyx };
125+
export { Polyx, Tpolyx, PolyxToken };
126126
export { Rbtc, Trbtc };
127127
export { Rune, Trune };
128128
export { Sgb, Tsgb };

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('Coins', () => {
3030
ZkethToken: 1,
3131
SuiToken: 1,
3232
TaoToken: 1,
33+
PolyxToken: 1,
3334
BeraToken: 1,
3435
XrpToken: 1,
3536
Rune: 1,

modules/sdk-coin-polyx/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 './polyx';
44
export * from './tpolyx';
5+
export * from './polyxToken';
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { coins, PolyxTokenConfig, tokens } from '@bitgo/statics';
2+
import { Polyx } from './polyx';
3+
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
4+
5+
export class PolyxToken extends Polyx {
6+
public readonly tokenConfig: PolyxTokenConfig;
7+
8+
constructor(bitgo: BitGoBase, tokenConfig: PolyxTokenConfig) {
9+
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('polyx') : coins.get('tpolyx');
10+
super(bitgo, staticsCoin);
11+
this.tokenConfig = tokenConfig;
12+
}
13+
14+
static createTokenConstructor(config: PolyxTokenConfig): CoinConstructor {
15+
return (bitgo: BitGoBase) => new PolyxToken(bitgo, config);
16+
}
17+
18+
static createTokenConstructors(
19+
tokenConfigs: PolyxTokenConfig[] = [...tokens.bitcoin.polyx.tokens, ...tokens.testnet.polyx.tokens]
20+
): NamedCoinConstructor[] {
21+
const tokensCtors: NamedCoinConstructor[] = [];
22+
for (const token of tokenConfigs) {
23+
const tokenConstructor = PolyxToken.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 ticker(): string {
42+
return this.tokenConfig.ticker;
43+
}
44+
45+
get assetId(): string {
46+
return this.tokenConfig.assetId;
47+
}
48+
49+
get decimalPlaces(): number {
50+
return this.tokenConfig.decimalPlaces;
51+
}
52+
53+
getChain(): string {
54+
return this.tokenConfig.type;
55+
}
56+
57+
getBaseChain(): string {
58+
return this.coin;
59+
}
60+
61+
getFullName(): string {
62+
return this._staticsCoin.fullName;
63+
}
64+
65+
getBaseFactor(): number {
66+
return Math.pow(10, this.tokenConfig.decimalPlaces);
67+
}
68+
}
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 { Polyx } from './polyx';
33
import { Tpolyx } from './tpolyx';
4+
import { PolyxToken } from './polyxToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('polyx', Polyx.createInstance);
78
sdk.register('tpolyx', Tpolyx.createInstance);
9+
PolyxToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};

0 commit comments

Comments
 (0)