|
6 | 6 | ACCOUNT_COIN_DEFAULT_FEATURES, |
7 | 7 | ACCOUNT_COIN_DEFAULT_FEATURES_EXCLUDE_SINGAPORE, |
8 | 8 | CELO_TOKEN_FEATURES, |
| 9 | + COSMOS_SIDECHAIN_FEATURES, |
9 | 10 | } from './coinFeatures'; |
10 | 11 |
|
11 | 12 | /** |
@@ -149,6 +150,9 @@ export interface Nep141TokenConstructorOptions extends AccountConstructorOptions |
149 | 150 | export interface VetTokenConstructorOptions extends AccountConstructorOptions { |
150 | 151 | contractAddress: string; |
151 | 152 | } |
| 153 | +export interface CosmosTokenConstructorOptions extends AccountConstructorOptions { |
| 154 | + denom: string; |
| 155 | +} |
152 | 156 |
|
153 | 157 | export interface ContractAddress extends String { |
154 | 158 | __contractaddress_phantom__: never; |
@@ -627,6 +631,22 @@ export class VetToken extends AccountCoinToken { |
627 | 631 | } |
628 | 632 | } |
629 | 633 |
|
| 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 | + |
630 | 650 | /** |
631 | 651 | * Factory function for account coin instances. |
632 | 652 | * |
@@ -3205,3 +3225,52 @@ export function tvetToken( |
3205 | 3225 | ) { |
3206 | 3226 | return vetToken(id, name, fullName, decimalPlaces, contractAddress, asset, features, prefix, suffix, network); |
3207 | 3227 | } |
| 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