Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ export interface TaoCoinConstructorOptions extends AccountConstructorOptions {
subnetId: string;
}

export interface PolyxCoinConstructorOptions extends AccountConstructorOptions {
ticker: string;
assetId: string;
}

type FiatCoinName = `fiat${string}` | `tfiat${string}`;
export interface FiatCoinConstructorOptions extends AccountConstructorOptions {
name: FiatCoinName;
Expand Down Expand Up @@ -672,6 +677,23 @@ export class TaoCoin extends AccountCoinToken {
}
}

/**
* The Bittensor network supports tokens
* The token name is determined by the subnetId on chain.
*/
export class PolyxCoin extends AccountCoinToken {
public ticker: string;
public assetId: string;

constructor(options: PolyxCoinConstructorOptions) {
super({
...options,
});
this.ticker = options.ticker;
this.assetId = options.assetId;
}
}

/**
* Factory function for account coin instances.
*
Expand Down Expand Up @@ -3408,3 +3430,98 @@ export function ttaoToken(
primaryKeyCurve
);
}

/**
* Factory function for tao token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param subnetId The uid of the subnet this token belongs to, numerical string
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to TAO main network.
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function polyxToken(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
ticker: string,
assetId: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.tao,
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
): Readonly<PolyxCoin> {
return Object.freeze(
new PolyxCoin({
id,
name,
fullName,
network,
ticker,
assetId,
prefix,
suffix,
features,
decimalPlaces,
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.TAO,
})
);
}

/**
* Factory function for testnet tao token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param subnetId The uid of the subnet this token belongs to, numerical string
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to TAO test network.
* @param primaryKeyCurve The elliptic curve for this chain/token
*/

export function tpolyxToken(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
ticker: string,
assetId: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.test.tao,
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
): Readonly<PolyxCoin> {
return polyxToken(
id,
name,
fullName,
decimalPlaces,
ticker,
assetId,
asset,
features,
prefix,
suffix,
network,
primaryKeyCurve
);
}
3 changes: 3 additions & 0 deletions modules/statics/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,9 @@ export enum UnderlyingAsset {
// TAO testnet tokens
'ttao:apex' = 'ttao:apex',

// Polymesh testnet tokens
'tpolyx:rbitgot' = 'tpolyx:rbitgot',

// Hbar tokens
'hbar:karate' = 'hbar:karate',
'hbar:sauce' = 'hbar:sauce',
Expand Down
3 changes: 3 additions & 0 deletions modules/statics/src/coinFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,11 @@ export const POLYX_FEATURES = [
CoinFeature.TSS,
CoinFeature.TSS_COLD,
CoinFeature.STAKING,
CoinFeature.SUPPORTS_TOKENS,
];

export const POLYX_TOKEN_FEATURES = [...ACCOUNT_COIN_DEFAULT_FEATURES, CoinFeature.TSS];

export const ETH_FEATURES_WITH_FRANKFURT = [...ETH_FEATURES, CoinFeature.CUSTODY_BITGO_FRANKFURT];
export const ETH_FEATURES_WITH_GERMANY = [...ETH_FEATURES, CoinFeature.CUSTODY_BITGO_GERMANY];
export const ETH_FEATURES_WITH_FRANKFURT_GERMANY = [...ETH_FEATURES_WITH_FRANKFURT, CoinFeature.CUSTODY_BITGO_GERMANY];
Expand Down
21 changes: 21 additions & 0 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
nonstandardToken,
opethErc20,
polygonErc20,
polyxToken,
sip10Token,
solToken,
stellarToken,
Expand All @@ -42,6 +43,7 @@ import {
terc1155,
terc721,
topethErc20,
tpolyxToken,
tronToken,
tstellarToken,
tsuiToken,
Expand Down Expand Up @@ -105,6 +107,7 @@ import {
POLYGON_FEATURES,
POLYGON_TOKEN_FEATURES,
POLYX_FEATURES,
POLYX_TOKEN_FEATURES,
RBTC_FEATURES,
SEI_FEATURES,
SOL_FEATURES,
Expand Down Expand Up @@ -4099,6 +4102,16 @@ export const coins = CoinMap.fromCoins([
UnderlyingAsset['ttao:apex'],
TAO_TOKEN_FEATURES
),
tpolyxToken(
'a63b4f8d-84d6-45d3-bc67-625239e40811',
'tpolyx:rbitgot',
'R BitGo Test',
6,
'RBITGOT',
'2ffe769d-862a-8994-8e1c-cf1423bfc7f8',
UnderlyingAsset['tpolyx:rbitgot'],
POLYX_TOKEN_FEATURES
),
aptToken(
'e8bfdab3-4ef6-4b39-9450-d9cb59593f7a',
'apt:usdt',
Expand Down Expand Up @@ -4272,6 +4285,7 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
stx: sip10Token,
sui: suiToken,
tao: taoToken,
polyx: polyxToken,
trx: tronToken,
vet: vetToken,
xlm: stellarToken,
Expand Down Expand Up @@ -4393,6 +4407,13 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
token.subnetId, // subnetId
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
);
case 'polyx':
return initializer(
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
token.ticker, // ticker
token.assetId, // assetId
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
);

case 'xlm':
return initializer(
Expand Down
1 change: 1 addition & 0 deletions modules/statics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
TronErc20Coin,
SuiCoin,
TaoCoin,
PolyxCoin,
XrpCoin,
AptCoin,
AptNFTCollection,
Expand Down
2 changes: 2 additions & 0 deletions modules/statics/src/networkFeatureMapForTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
APT_FEATURES,
BSC_TOKEN_FEATURES,
POLYGON_TOKEN_FEATURES,
POLYX_TOKEN_FEATURES,
SOL_TOKEN_FEATURES,
STX_TOKEN_FEATURES,
SUI_TOKEN_FEATURES,
Expand All @@ -28,6 +29,7 @@ export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[
stx: STX_TOKEN_FEATURES,
sui: SUI_TOKEN_FEATURES,
tao: TAO_TOKEN_FEATURES,
polyx: POLYX_TOKEN_FEATURES,
trx: AccountCoin.DEFAULT_FEATURES,
xlm: AccountCoin.DEFAULT_FEATURES,
xrp: AccountCoin.DEFAULT_FEATURES,
Expand Down
43 changes: 42 additions & 1 deletion modules/statics/src/tokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
StellarCoin,
SuiCoin,
TaoCoin,
PolyxCoin,
TronErc20Coin,
VetToken,
WorldERC20Token,
Expand Down Expand Up @@ -115,6 +116,11 @@ export type TaoTokenConfig = BaseNetworkConfig & {
subnetId: string;
};

export type PolyxTokenConfig = BaseNetworkConfig & {
ticker: string;
assetId: string;
};

export type Nep141TokenConfig = BaseNetworkConfig & {
contractAddress: string;
storageDepositAmount: string;
Expand Down Expand Up @@ -149,7 +155,8 @@ export type TokenConfig =
| Nep141TokenConfig
| CosmosTokenConfig
| VetTokenConfig
| TaoTokenConfig;
| TaoTokenConfig
| PolyxTokenConfig;

export interface Tokens {
bitcoin: {
Expand Down Expand Up @@ -219,6 +226,9 @@ export interface Tokens {
tao: {
tokens: TaoTokenConfig[];
};
polyx: {
tokens: PolyxTokenConfig[];
};
bera: {
tokens: EthLikeTokenConfig[];
};
Expand Down Expand Up @@ -300,6 +310,9 @@ export interface Tokens {
tao: {
tokens: TaoTokenConfig[];
};
polyx: {
tokens: PolyxTokenConfig[];
};
bera: {
tokens: EthLikeTokenConfig[];
};
Expand Down Expand Up @@ -358,6 +371,7 @@ export interface AmsTokenConfig {
baseUnit?: string;
kind?: string;
subnetId?: string;
ticker?: string;
}

export interface TrimmedAmsNetworkConfig {
Expand Down Expand Up @@ -831,6 +845,25 @@ const getFormattedTaoTokens = (customCoinMap = coins) =>
return acc;
}, []);

function getPolyxTokenConfig(coin: PolyxCoin): PolyxTokenConfig {
return {
type: coin.name,
coin: coin.network.type === NetworkType.MAINNET ? 'polyx' : 'tpolyx',
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
name: coin.fullName,
decimalPlaces: coin.decimalPlaces,
ticker: coin.ticker,
assetId: coin.assetId,
};
}
const getFormattedPolyxTokens = (customCoinMap = coins) =>
customCoinMap.reduce((acc: PolyxTokenConfig[], coin) => {
if (coin instanceof PolyxCoin) {
acc.push(getPolyxTokenConfig(coin));
}
return acc;
}, []);

function getAptTokenConfig(coin: AptCoin): AptTokenConfig {
return {
type: coin.name,
Expand Down Expand Up @@ -1008,6 +1041,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
tao: {
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
polyx: {
tokens: getFormattedPolyxTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
bera: {
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
Expand Down Expand Up @@ -1099,6 +1135,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
tao: {
tokens: getFormattedTaoTokens(coinMap).filter((token) => token.network === 'Testnet'),
},
polyx: {
tokens: getFormattedPolyxTokens(coinMap).filter((token) => token.network === 'Testnet'),
},
bera: {
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Testnet'),
},
Expand Down Expand Up @@ -1215,6 +1254,8 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
return getSuiTokenConfig(coin);
} else if (coin instanceof TaoCoin) {
return getTaoTokenConfig(coin);
} else if (coin instanceof PolyxCoin) {
return getPolyxTokenConfig(coin);
} else if (coin instanceof AptCoin) {
return getAptTokenConfig(coin);
} else if (coin instanceof AptNFTCollection) {
Expand Down
Loading