Skip to content

Commit 080e5ae

Browse files
committed
feat(statics): add tao token support
TICKET: WIN-6424
1 parent 92c999a commit 080e5ae

File tree

7 files changed

+178
-1
lines changed

7 files changed

+178
-1
lines changed

modules/statics/src/account.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ export interface AptCoinConstructorOptions extends AccountConstructorOptions {
135135
assetId: string;
136136
}
137137

138+
export interface TaoCoinConstructorOptions extends AccountConstructorOptions {
139+
subnetId: string;
140+
}
141+
138142
type FiatCoinName = `fiat${string}` | `tfiat${string}`;
139143
export interface FiatCoinConstructorOptions extends AccountConstructorOptions {
140144
name: FiatCoinName;
@@ -654,6 +658,20 @@ export class CosmosChainToken extends AccountCoinToken {
654658
}
655659
}
656660

661+
/**
662+
* The Bittensor network supports tokens
663+
* The token name is determined by the subnetId on chain.
664+
*/
665+
export class TaoCoin extends AccountCoinToken {
666+
public subnetId: string;
667+
constructor(options: TaoCoinConstructorOptions) {
668+
super({
669+
...options,
670+
});
671+
this.subnetId = options.subnetId;
672+
}
673+
}
674+
657675
/**
658676
* Factory function for account coin instances.
659677
*
@@ -3299,3 +3317,94 @@ export function cosmosToken(
32993317
})
33003318
);
33013319
}
3320+
3321+
/**
3322+
* Factory function for tao token instances.
3323+
*
3324+
* @param id uuid v4
3325+
* @param name unique identifier of the token
3326+
* @param fullName Complete human-readable name of the token
3327+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
3328+
* @param subnetId Contract address of this token formed with `packageId::module::symbol`
3329+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
3330+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
3331+
* @param prefix? Optional token prefix. Defaults to empty string
3332+
* @param suffix? Optional token suffix. Defaults to token name.
3333+
* @param network? Optional token network. Defaults to TAO main network.
3334+
* @param primaryKeyCurve The elliptic curve for this chain/token
3335+
*/
3336+
export function taoToken(
3337+
id: string,
3338+
name: string,
3339+
fullName: string,
3340+
decimalPlaces: number,
3341+
subnetId: string,
3342+
asset: UnderlyingAsset,
3343+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
3344+
prefix = '',
3345+
suffix: string = name.toUpperCase(),
3346+
network: AccountNetwork = Networks.main.tao,
3347+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
3348+
): Readonly<TaoCoin> {
3349+
return Object.freeze(
3350+
new TaoCoin({
3351+
id,
3352+
name,
3353+
fullName,
3354+
network,
3355+
subnetId,
3356+
prefix,
3357+
suffix,
3358+
features,
3359+
decimalPlaces,
3360+
asset,
3361+
isToken: true,
3362+
primaryKeyCurve,
3363+
baseUnit: BaseUnit.TAO,
3364+
})
3365+
);
3366+
}
3367+
3368+
/**
3369+
* Factory function for testnet tao token instances.
3370+
*
3371+
* @param id uuid v4
3372+
* @param name unique identifier of the token
3373+
* @param fullName Complete human-readable name of the token
3374+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
3375+
* @param subnetId Contract address of this token formed with `packageId::module::symbol`
3376+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
3377+
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
3378+
* @param prefix? Optional token prefix. Defaults to empty string
3379+
* @param suffix? Optional token suffix. Defaults to token name.
3380+
* @param network? Optional token network. Defaults to TAO test network.
3381+
* @param primaryKeyCurve The elliptic curve for this chain/token
3382+
*/
3383+
3384+
export function ttaoToken(
3385+
id: string,
3386+
name: string,
3387+
fullName: string,
3388+
decimalPlaces: number,
3389+
subnetId: string,
3390+
asset: UnderlyingAsset,
3391+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
3392+
prefix = '',
3393+
suffix: string = name.toUpperCase(),
3394+
network: AccountNetwork = Networks.test.tao,
3395+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
3396+
): Readonly<TaoCoin> {
3397+
return taoToken(
3398+
id,
3399+
name,
3400+
fullName,
3401+
decimalPlaces,
3402+
subnetId,
3403+
asset,
3404+
features,
3405+
prefix,
3406+
suffix,
3407+
network,
3408+
primaryKeyCurve
3409+
);
3410+
}

modules/statics/src/base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,6 +2873,9 @@ export enum UnderlyingAsset {
28732873
'tstx:tsip6dp' = 'tstx:tsip6dp',
28742874
'tstx:tsip8dp' = 'tstx:tsip8dp',
28752875

2876+
// TAO testnet tokens
2877+
'ttao:apex' = 'ttao:apex',
2878+
28762879
// Hbar tokens
28772880
'hbar:karate' = 'hbar:karate',
28782881
'hbar:sauce' = 'hbar:sauce',

modules/statics/src/coinFeatures.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,11 @@ export const TAO_FEATURES = [
526526
CoinFeature.TSS,
527527
CoinFeature.TSS_COLD,
528528
CoinFeature.STAKING,
529+
CoinFeature.SUPPORTS_TOKENS,
529530
];
530531

532+
export const TAO_TOKEN_FEATURES = [...ACCOUNT_COIN_DEFAULT_FEATURES, CoinFeature.TSS, CoinFeature.TSS_COLD];
533+
531534
export const SONEIUM_FEATURES = [
532535
...ETH_FEATURES,
533536
CoinFeature.TSS,

modules/statics/src/coins.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
vetToken,
3232
cosmosToken,
3333
talgoToken,
34+
taoToken,
3435
taptNFTCollection,
3536
taptToken,
3637
tarbethErc20,
@@ -44,6 +45,7 @@ import {
4445
tronToken,
4546
tstellarToken,
4647
tsuiToken,
48+
ttaoToken,
4749
ttronToken,
4850
txrpToken,
4951
tworldErc20,
@@ -112,6 +114,7 @@ import {
112114
SUI_TOKEN_FEATURES,
113115
SUI_TOKEN_FEATURES_STAKING,
114116
TAO_FEATURES,
117+
TAO_TOKEN_FEATURES,
115118
TIA_FEATURES,
116119
TOKEN_FEATURES_WITH_FRANKFURT,
117120
TON_FEATURES,
@@ -3957,6 +3960,15 @@ export const coins = CoinMap.fromCoins([
39573960
UnderlyingAsset['tsui:wal'],
39583961
SUI_TOKEN_FEATURES_STAKING
39593962
),
3963+
ttaoToken(
3964+
'b8b5fded-65f8-49eb-8f83-ad97d08d07f2',
3965+
'ttao:apex',
3966+
'Apex',
3967+
9,
3968+
'1',
3969+
UnderlyingAsset['ttao:apex'],
3970+
TAO_TOKEN_FEATURES
3971+
),
39603972
aptToken(
39613973
'e8bfdab3-4ef6-4b39-9450-d9cb59593f7a',
39623974
'apt:usdt',
@@ -4129,6 +4141,7 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
41294141
sol: solToken,
41304142
stx: sip10Token,
41314143
sui: suiToken,
4144+
tao: taoToken,
41324145
trx: tronToken,
41334146
vet: vetToken,
41344147
xlm: stellarToken,
@@ -4244,6 +4257,13 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
42444257
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
42454258
);
42464259

4260+
case 'tao':
4261+
return initializer(
4262+
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
4263+
token.subnetId, // subnetId
4264+
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
4265+
);
4266+
42474267
case 'xlm':
42484268
return initializer(
42494269
...commonArgs.slice(0, 5), // id, name, fullName, decimalPlaces, asset

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {
2121
HederaToken,
2222
TronErc20Coin,
2323
SuiCoin,
24+
TaoCoin,
2425
XrpCoin,
2526
AptCoin,
2627
AptNFTCollection,

modules/statics/src/networkFeatureMapForTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
SOL_TOKEN_FEATURES,
88
STX_TOKEN_FEATURES,
99
SUI_TOKEN_FEATURES,
10+
TAO_TOKEN_FEATURES,
1011
} from './coinFeatures';
1112
import { OfcCoin } from './ofc';
1213

@@ -26,6 +27,7 @@ export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[
2627
sol: SOL_TOKEN_FEATURES,
2728
stx: STX_TOKEN_FEATURES,
2829
sui: SUI_TOKEN_FEATURES,
30+
tao: TAO_TOKEN_FEATURES,
2931
trx: AccountCoin.DEFAULT_FEATURES,
3032
xlm: AccountCoin.DEFAULT_FEATURES,
3133
xrp: AccountCoin.DEFAULT_FEATURES,

modules/statics/src/tokenConfig.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
SolCoin,
2323
StellarCoin,
2424
SuiCoin,
25+
TaoCoin,
2526
TronErc20Coin,
2627
VetToken,
2728
WorldERC20Token,
@@ -110,6 +111,10 @@ export type Sip10TokenConfig = BaseNetworkConfig & {
110111
assetId: string;
111112
};
112113

114+
export type TaoTokenConfig = BaseNetworkConfig & {
115+
subnetId: string;
116+
};
117+
113118
export type Nep141TokenConfig = BaseNetworkConfig & {
114119
contractAddress: string;
115120
storageDepositAmount: string;
@@ -143,7 +148,8 @@ export type TokenConfig =
143148
| Sip10TokenConfig
144149
| Nep141TokenConfig
145150
| CosmosTokenConfig
146-
| VetTokenConfig;
151+
| VetTokenConfig
152+
| TaoTokenConfig;
147153

148154
export interface Tokens {
149155
bitcoin: {
@@ -210,6 +216,9 @@ export interface Tokens {
210216
sui: {
211217
tokens: SuiTokenConfig[];
212218
};
219+
tao: {
220+
tokens: TaoTokenConfig[];
221+
};
213222
bera: {
214223
tokens: EthLikeTokenConfig[];
215224
};
@@ -288,6 +297,9 @@ export interface Tokens {
288297
sui: {
289298
tokens: SuiTokenConfig[];
290299
};
300+
tao: {
301+
tokens: TaoTokenConfig[];
302+
};
291303
bera: {
292304
tokens: EthLikeTokenConfig[];
293305
};
@@ -345,6 +357,7 @@ export interface AmsTokenConfig {
345357
isToken: boolean;
346358
baseUnit?: string;
347359
kind?: string;
360+
subnetId?: string;
348361
}
349362

350363
export interface TrimmedAmsNetworkConfig {
@@ -800,6 +813,24 @@ const getFormattedSuiTokens = (customCoinMap = coins) =>
800813
return acc;
801814
}, []);
802815

816+
function getTaoTokenConfig(coin: TaoCoin): TaoTokenConfig {
817+
return {
818+
type: coin.name,
819+
coin: coin.network.type === NetworkType.MAINNET ? 'tao' : 'ttao',
820+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
821+
name: coin.fullName,
822+
decimalPlaces: coin.decimalPlaces,
823+
subnetId: coin.subnetId,
824+
};
825+
}
826+
const getFormattedTaoTokens = (customCoinMap = coins) =>
827+
customCoinMap.reduce((acc: TaoTokenConfig[], coin) => {
828+
if (coin instanceof TaoCoin) {
829+
acc.push(getTaoTokenConfig(coin));
830+
}
831+
return acc;
832+
}, []);
833+
803834
function getAptTokenConfig(coin: AptCoin): AptTokenConfig {
804835
return {
805836
type: coin.name,
@@ -974,6 +1005,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
9741005
sui: {
9751006
tokens: getFormattedSuiTokens(coinMap).filter((token) => token.network === 'Mainnet'),
9761007
},
1008+
tao: {
1009+
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Mainnet'),
1010+
},
9771011
bera: {
9781012
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Mainnet'),
9791013
},
@@ -1062,6 +1096,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
10621096
sui: {
10631097
tokens: getFormattedSuiTokens(coinMap).filter((token) => token.network === 'Testnet'),
10641098
},
1099+
tao: {
1100+
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Testnet'),
1101+
},
10651102
bera: {
10661103
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Testnet'),
10671104
},
@@ -1176,6 +1213,8 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
11761213
return getXrpTokenConfig(coin);
11771214
} else if (coin instanceof SuiCoin) {
11781215
return getSuiTokenConfig(coin);
1216+
} else if (coin instanceof TaoCoin) {
1217+
return getTaoTokenConfig(coin);
11791218
} else if (coin instanceof AptCoin) {
11801219
return getAptTokenConfig(coin);
11811220
} else if (coin instanceof AptNFTCollection) {

0 commit comments

Comments
 (0)