Skip to content

Commit b14c597

Browse files
authored
Merge pull request #6629 from BitGo/WIN-6572
feat(statics): add polyx token support
2 parents 3d875ec + ce4bfa3 commit b14c597

File tree

8 files changed

+194
-124
lines changed

8 files changed

+194
-124
lines changed

modules/statics/src/account.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ export interface TaoCoinConstructorOptions extends AccountConstructorOptions {
139139
subnetId: string;
140140
}
141141

142+
export interface PolyxCoinConstructorOptions extends AccountConstructorOptions {
143+
ticker: string;
144+
assetId: string;
145+
}
146+
142147
type FiatCoinName = `fiat${string}` | `tfiat${string}`;
143148
export interface FiatCoinConstructorOptions extends AccountConstructorOptions {
144149
name: FiatCoinName;
@@ -672,6 +677,23 @@ export class TaoCoin extends AccountCoinToken {
672677
}
673678
}
674679

680+
/**
681+
* The Bittensor network supports tokens
682+
* The token name is determined by the subnetId on chain.
683+
*/
684+
export class PolyxCoin extends AccountCoinToken {
685+
public ticker: string;
686+
public assetId: string;
687+
688+
constructor(options: PolyxCoinConstructorOptions) {
689+
super({
690+
...options,
691+
});
692+
this.ticker = options.ticker;
693+
this.assetId = options.assetId;
694+
}
695+
}
696+
675697
/**
676698
* Factory function for account coin instances.
677699
*
@@ -3408,3 +3430,98 @@ export function ttaoToken(
34083430
primaryKeyCurve
34093431
);
34103432
}
3433+
3434+
/**
3435+
* Factory function for tao token instances.
3436+
*
3437+
* @param id uuid v4
3438+
* @param name unique identifier of the token
3439+
* @param fullName Complete human-readable name of the token
3440+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
3441+
* @param subnetId The uid of the subnet this token belongs to, numerical string
3442+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
3443+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
3444+
* @param prefix? Optional token prefix. Defaults to empty string
3445+
* @param suffix? Optional token suffix. Defaults to token name.
3446+
* @param network? Optional token network. Defaults to TAO main network.
3447+
* @param primaryKeyCurve The elliptic curve for this chain/token
3448+
*/
3449+
export function polyxToken(
3450+
id: string,
3451+
name: string,
3452+
fullName: string,
3453+
decimalPlaces: number,
3454+
ticker: string,
3455+
assetId: string,
3456+
asset: UnderlyingAsset,
3457+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
3458+
prefix = '',
3459+
suffix: string = name.toUpperCase(),
3460+
network: AccountNetwork = Networks.main.tao,
3461+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
3462+
): Readonly<PolyxCoin> {
3463+
return Object.freeze(
3464+
new PolyxCoin({
3465+
id,
3466+
name,
3467+
fullName,
3468+
network,
3469+
ticker,
3470+
assetId,
3471+
prefix,
3472+
suffix,
3473+
features,
3474+
decimalPlaces,
3475+
asset,
3476+
isToken: true,
3477+
primaryKeyCurve,
3478+
baseUnit: BaseUnit.TAO,
3479+
})
3480+
);
3481+
}
3482+
3483+
/**
3484+
* Factory function for testnet tao token instances.
3485+
*
3486+
* @param id uuid v4
3487+
* @param name unique identifier of the token
3488+
* @param fullName Complete human-readable name of the token
3489+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
3490+
* @param subnetId The uid of the subnet this token belongs to, numerical string
3491+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
3492+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
3493+
* @param prefix? Optional token prefix. Defaults to empty string
3494+
* @param suffix? Optional token suffix. Defaults to token name.
3495+
* @param network? Optional token network. Defaults to TAO test network.
3496+
* @param primaryKeyCurve The elliptic curve for this chain/token
3497+
*/
3498+
3499+
export function tpolyxToken(
3500+
id: string,
3501+
name: string,
3502+
fullName: string,
3503+
decimalPlaces: number,
3504+
ticker: string,
3505+
assetId: string,
3506+
asset: UnderlyingAsset,
3507+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
3508+
prefix = '',
3509+
suffix: string = name.toUpperCase(),
3510+
network: AccountNetwork = Networks.test.tao,
3511+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
3512+
): Readonly<PolyxCoin> {
3513+
return polyxToken(
3514+
id,
3515+
name,
3516+
fullName,
3517+
decimalPlaces,
3518+
ticker,
3519+
assetId,
3520+
asset,
3521+
features,
3522+
prefix,
3523+
suffix,
3524+
network,
3525+
primaryKeyCurve
3526+
);
3527+
}

modules/statics/src/base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,6 +2887,9 @@ export enum UnderlyingAsset {
28872887
// TAO testnet tokens
28882888
'ttao:apex' = 'ttao:apex',
28892889

2890+
// Polymesh testnet tokens
2891+
'tpolyx:rbitgot' = 'tpolyx:rbitgot',
2892+
28902893
// Hbar tokens
28912894
'hbar:karate' = 'hbar:karate',
28922895
'hbar:sauce' = 'hbar:sauce',

modules/statics/src/coinFeatures.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,11 @@ export const POLYX_FEATURES = [
552552
CoinFeature.TSS,
553553
CoinFeature.TSS_COLD,
554554
CoinFeature.STAKING,
555+
CoinFeature.SUPPORTS_TOKENS,
555556
];
556557

558+
export const POLYX_TOKEN_FEATURES = [...ACCOUNT_COIN_DEFAULT_FEATURES, CoinFeature.TSS];
559+
557560
export const ETH_FEATURES_WITH_FRANKFURT = [...ETH_FEATURES, CoinFeature.CUSTODY_BITGO_FRANKFURT];
558561
export const ETH_FEATURES_WITH_GERMANY = [...ETH_FEATURES, CoinFeature.CUSTODY_BITGO_GERMANY];
559562
export const ETH_FEATURES_WITH_FRANKFURT_GERMANY = [...ETH_FEATURES_WITH_FRANKFURT, CoinFeature.CUSTODY_BITGO_GERMANY];

modules/statics/src/coins.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
nonstandardToken,
2525
opethErc20,
2626
polygonErc20,
27+
polyxToken,
2728
sip10Token,
2829
solToken,
2930
stellarToken,
@@ -42,6 +43,7 @@ import {
4243
terc1155,
4344
terc721,
4445
topethErc20,
46+
tpolyxToken,
4547
tronToken,
4648
tstellarToken,
4749
tsuiToken,
@@ -105,6 +107,7 @@ import {
105107
POLYGON_FEATURES,
106108
POLYGON_TOKEN_FEATURES,
107109
POLYX_FEATURES,
110+
POLYX_TOKEN_FEATURES,
108111
RBTC_FEATURES,
109112
SEI_FEATURES,
110113
SOL_FEATURES,
@@ -4099,6 +4102,16 @@ export const coins = CoinMap.fromCoins([
40994102
UnderlyingAsset['ttao:apex'],
41004103
TAO_TOKEN_FEATURES
41014104
),
4105+
tpolyxToken(
4106+
'a63b4f8d-84d6-45d3-bc67-625239e40811',
4107+
'tpolyx:rbitgot',
4108+
'R BitGo Test',
4109+
6,
4110+
'RBITGOT',
4111+
'2ffe769d-862a-8994-8e1c-cf1423bfc7f8',
4112+
UnderlyingAsset['tpolyx:rbitgot'],
4113+
POLYX_TOKEN_FEATURES
4114+
),
41024115
aptToken(
41034116
'e8bfdab3-4ef6-4b39-9450-d9cb59593f7a',
41044117
'apt:usdt',
@@ -4272,6 +4285,7 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
42724285
stx: sip10Token,
42734286
sui: suiToken,
42744287
tao: taoToken,
4288+
polyx: polyxToken,
42754289
trx: tronToken,
42764290
vet: vetToken,
42774291
xlm: stellarToken,
@@ -4393,6 +4407,13 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
43934407
token.subnetId, // subnetId
43944408
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
43954409
);
4410+
case 'polyx':
4411+
return initializer(
4412+
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
4413+
token.ticker, // ticker
4414+
token.assetId, // assetId
4415+
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
4416+
);
43964417

43974418
case 'xlm':
43984419
return initializer(

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
TronErc20Coin,
2323
SuiCoin,
2424
TaoCoin,
25+
PolyxCoin,
2526
XrpCoin,
2627
AptCoin,
2728
AptNFTCollection,

modules/statics/src/networkFeatureMapForTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
APT_FEATURES,
55
BSC_TOKEN_FEATURES,
66
POLYGON_TOKEN_FEATURES,
7+
POLYX_TOKEN_FEATURES,
78
SOL_TOKEN_FEATURES,
89
STX_TOKEN_FEATURES,
910
SUI_TOKEN_FEATURES,
@@ -28,6 +29,7 @@ export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[
2829
stx: STX_TOKEN_FEATURES,
2930
sui: SUI_TOKEN_FEATURES,
3031
tao: TAO_TOKEN_FEATURES,
32+
polyx: POLYX_TOKEN_FEATURES,
3133
trx: AccountCoin.DEFAULT_FEATURES,
3234
xlm: AccountCoin.DEFAULT_FEATURES,
3335
xrp: AccountCoin.DEFAULT_FEATURES,

modules/statics/src/tokenConfig.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
StellarCoin,
2424
SuiCoin,
2525
TaoCoin,
26+
PolyxCoin,
2627
TronErc20Coin,
2728
VetToken,
2829
WorldERC20Token,
@@ -115,6 +116,11 @@ export type TaoTokenConfig = BaseNetworkConfig & {
115116
subnetId: string;
116117
};
117118

119+
export type PolyxTokenConfig = BaseNetworkConfig & {
120+
ticker: string;
121+
assetId: string;
122+
};
123+
118124
export type Nep141TokenConfig = BaseNetworkConfig & {
119125
contractAddress: string;
120126
storageDepositAmount: string;
@@ -149,7 +155,8 @@ export type TokenConfig =
149155
| Nep141TokenConfig
150156
| CosmosTokenConfig
151157
| VetTokenConfig
152-
| TaoTokenConfig;
158+
| TaoTokenConfig
159+
| PolyxTokenConfig;
153160

154161
export interface Tokens {
155162
bitcoin: {
@@ -219,6 +226,9 @@ export interface Tokens {
219226
tao: {
220227
tokens: TaoTokenConfig[];
221228
};
229+
polyx: {
230+
tokens: PolyxTokenConfig[];
231+
};
222232
bera: {
223233
tokens: EthLikeTokenConfig[];
224234
};
@@ -300,6 +310,9 @@ export interface Tokens {
300310
tao: {
301311
tokens: TaoTokenConfig[];
302312
};
313+
polyx: {
314+
tokens: PolyxTokenConfig[];
315+
};
303316
bera: {
304317
tokens: EthLikeTokenConfig[];
305318
};
@@ -358,6 +371,7 @@ export interface AmsTokenConfig {
358371
baseUnit?: string;
359372
kind?: string;
360373
subnetId?: string;
374+
ticker?: string;
361375
}
362376

363377
export interface TrimmedAmsNetworkConfig {
@@ -831,6 +845,25 @@ const getFormattedTaoTokens = (customCoinMap = coins) =>
831845
return acc;
832846
}, []);
833847

848+
function getPolyxTokenConfig(coin: PolyxCoin): PolyxTokenConfig {
849+
return {
850+
type: coin.name,
851+
coin: coin.network.type === NetworkType.MAINNET ? 'polyx' : 'tpolyx',
852+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
853+
name: coin.fullName,
854+
decimalPlaces: coin.decimalPlaces,
855+
ticker: coin.ticker,
856+
assetId: coin.assetId,
857+
};
858+
}
859+
const getFormattedPolyxTokens = (customCoinMap = coins) =>
860+
customCoinMap.reduce((acc: PolyxTokenConfig[], coin) => {
861+
if (coin instanceof PolyxCoin) {
862+
acc.push(getPolyxTokenConfig(coin));
863+
}
864+
return acc;
865+
}, []);
866+
834867
function getAptTokenConfig(coin: AptCoin): AptTokenConfig {
835868
return {
836869
type: coin.name,
@@ -1008,6 +1041,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
10081041
tao: {
10091042
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Mainnet'),
10101043
},
1044+
polyx: {
1045+
tokens: getFormattedPolyxTokens(coinMap).filter((token) => token.network === 'Mainnet'),
1046+
},
10111047
bera: {
10121048
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Mainnet'),
10131049
},
@@ -1099,6 +1135,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
10991135
tao: {
11001136
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Testnet'),
11011137
},
1138+
polyx: {
1139+
tokens: getFormattedPolyxTokens(coinMap).filter((token) => token.network === 'Testnet'),
1140+
},
11021141
bera: {
11031142
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Testnet'),
11041143
},
@@ -1215,6 +1254,8 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
12151254
return getSuiTokenConfig(coin);
12161255
} else if (coin instanceof TaoCoin) {
12171256
return getTaoTokenConfig(coin);
1257+
} else if (coin instanceof PolyxCoin) {
1258+
return getPolyxTokenConfig(coin);
12181259
} else if (coin instanceof AptCoin) {
12191260
return getAptTokenConfig(coin);
12201261
} else if (coin instanceof AptNFTCollection) {

0 commit comments

Comments
 (0)