Skip to content

Commit b05650c

Browse files
Merge pull request #6499 from BitGo/COIN-4914-sdk-add-token-support-to-statics
feat(statics): add Cosmos token support
2 parents bea410a + 9c2e613 commit b05650c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

modules/statics/src/account.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ACCOUNT_COIN_DEFAULT_FEATURES,
77
ACCOUNT_COIN_DEFAULT_FEATURES_EXCLUDE_SINGAPORE,
88
CELO_TOKEN_FEATURES,
9+
COSMOS_SIDECHAIN_FEATURES,
910
} from './coinFeatures';
1011

1112
/**
@@ -149,6 +150,9 @@ export interface Nep141TokenConstructorOptions extends AccountConstructorOptions
149150
export interface VetTokenConstructorOptions extends AccountConstructorOptions {
150151
contractAddress: string;
151152
}
153+
export interface CosmosTokenConstructorOptions extends AccountConstructorOptions {
154+
denom: string;
155+
}
152156

153157
export interface ContractAddress extends String {
154158
__contractaddress_phantom__: never;
@@ -627,6 +631,22 @@ export class VetToken extends AccountCoinToken {
627631
}
628632
}
629633

634+
/**
635+
* Cosmos network supports tokens
636+
* Cosmos tokens work similar to native coins, but the token is determined by
637+
* the denom on chain.
638+
*
639+
*/
640+
export class CosmosChainToken extends AccountCoinToken {
641+
public denom: string;
642+
constructor(options: CosmosTokenConstructorOptions) {
643+
super({
644+
...options,
645+
});
646+
this.denom = options.denom;
647+
}
648+
}
649+
630650
/**
631651
* Factory function for account coin instances.
632652
*
@@ -3205,3 +3225,52 @@ export function tvetToken(
32053225
) {
32063226
return vetToken(id, name, fullName, decimalPlaces, contractAddress, asset, features, prefix, suffix, network);
32073227
}
3228+
3229+
/**
3230+
* Factory function for Cosmos chain token instances.
3231+
*
3232+
* @param id uuid v4
3233+
* @param name unique identifier of the token
3234+
* @param fullName Complete human-readable name of the token
3235+
* @param denom denomination of this token which will act as a unique identifier for the token on chain
3236+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
3237+
* @param network Network (mainnet or testnet) for this token
3238+
* @param baseUnit Base unit of this token (native asset)
3239+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
3240+
* @param features Features of this coin. Defaults to the COSMOS_SIDECHAIN_FEATURES defined in `coinFeatures.ts`
3241+
* @param prefix Optional token prefix. Defaults to empty string
3242+
* @param suffix Optional token suffix. Defaults to token name.
3243+
* @param primaryKeyCurve The elliptic curve for this chain/token
3244+
*/
3245+
export function cosmosToken(
3246+
id: string,
3247+
name: string,
3248+
fullName: string,
3249+
denom: string,
3250+
decimalPlaces: number,
3251+
network: AccountNetwork,
3252+
baseUnit: BaseUnit,
3253+
asset: UnderlyingAsset,
3254+
features: CoinFeature[] = COSMOS_SIDECHAIN_FEATURES,
3255+
prefix = '',
3256+
suffix: string = name.toUpperCase(),
3257+
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
3258+
) {
3259+
return Object.freeze(
3260+
new CosmosChainToken({
3261+
id,
3262+
name,
3263+
fullName,
3264+
denom,
3265+
decimalPlaces,
3266+
network,
3267+
baseUnit,
3268+
asset,
3269+
features,
3270+
prefix,
3271+
suffix,
3272+
primaryKeyCurve,
3273+
isToken: true,
3274+
})
3275+
);
3276+
}

0 commit comments

Comments
 (0)