Skip to content

Commit 5245c50

Browse files
feat: add cosmos token to coinFactory
TICKET: COIN-4915
1 parent 2b9b2c4 commit 5245c50

File tree

8 files changed

+73
-4
lines changed

8 files changed

+73
-4
lines changed

modules/abstract-cosmos/src/cosmosToken.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ export class CosmosToken extends CosmosCoin {
1515
return (bitgo: BitGoBase) => new CosmosToken(bitgo, config);
1616
}
1717

18-
static createTokenConstructors(): NamedCoinConstructor[] {
18+
static createTokenConstructors(
19+
tokenConfigs: CosmosTokenConfig[] = [...tokens.bitcoin.cosmos.tokens, ...tokens.testnet.cosmos.tokens]
20+
): NamedCoinConstructor[] {
1921
const tokensCtors: NamedCoinConstructor[] = [];
20-
for (const token of [...tokens.bitcoin.cosmos.tokens, ...tokens.testnet.cosmos.tokens]) {
22+
for (const token of tokenConfigs) {
2123
const tokenConstructor = CosmosToken.createTokenConstructor(token);
2224
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor });
2325
}

modules/bitgo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"dependencies": {
4747
"@bitgo/abstract-lightning": "^6.2.3",
4848
"@bitgo/abstract-utxo": "^9.21.8",
49+
"@bitgo/abstract-cosmos": "^11.9.8",
4950
"@bitgo/account-lib": "^27.7.0",
5051
"@bitgo/blockapis": "^1.10.20",
5152
"@bitgo/sdk-api": "^1.65.1",

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
Sip10TokenConfig,
3333
CoinFeature,
3434
Nep141TokenConfig,
35+
CosmosTokenConfig,
3536
} from '@bitgo/statics';
3637
import {
3738
Ada,
@@ -60,6 +61,7 @@ import {
6061
CeloToken,
6162
Coredao,
6263
CoredaoToken,
64+
CosmosToken,
6365
Coreum,
6466
Cronos,
6567
Cspr,
@@ -494,6 +496,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
494496
Nep141Token.createTokenConstructors([...tokens.bitcoin.near.tokens, ...tokens.testnet.near.tokens]).forEach(
495497
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
496498
);
499+
500+
CosmosToken.createTokenConstructors([...tokens.bitcoin.cosmos.tokens, ...tokens.testnet.cosmos.tokens]).forEach(
501+
({ name, coinConstructor }) => coinFactory.register(name, coinConstructor)
502+
);
497503
}
498504

499505
export function getCoinConstructor(coinName: string): CoinConstructor | undefined {
@@ -899,6 +905,35 @@ export function getTokenConstructor(tokenConfig: TokenConfig): CoinConstructor |
899905
case 'near':
900906
case 'tnear':
901907
return Nep141Token.createTokenConstructor(tokenConfig as Nep141TokenConfig);
908+
case 'asi':
909+
case 'tasi':
910+
case 'atom':
911+
case 'tatom':
912+
case 'baby':
913+
case 'tbaby':
914+
case 'bld':
915+
case 'tbld':
916+
case 'coreum':
917+
case 'tcoreum':
918+
case 'cronos':
919+
case 'tcronos':
920+
case 'hash':
921+
case 'thash':
922+
case 'injective':
923+
case 'tinjective':
924+
case 'initia':
925+
case 'tinitia':
926+
case 'osmo':
927+
case 'tosmo':
928+
case 'thorchain:rune':
929+
case 'tthorchain:rune':
930+
case 'sei':
931+
case 'tsei':
932+
case 'tia':
933+
case 'ttia':
934+
case 'zeta':
935+
case 'tzeta':
936+
return CosmosToken.createTokenConstructor(tokenConfig as CosmosTokenConfig);
902937
default:
903938
return undefined;
904939
}

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Btg } from '@bitgo/sdk-coin-btg';
2121
import { Celo, CeloToken, Tcelo } from '@bitgo/sdk-coin-celo';
2222
import { Coredao, Tcoredao, CoredaoToken } from '@bitgo/sdk-coin-coredao';
2323
import { Coreum, Tcoreum } from '@bitgo/sdk-coin-coreum';
24+
import { CosmosToken } from '@bitgo/abstract-cosmos';
2425
import { Cronos, Tcronos } from '@bitgo/sdk-coin-cronos';
2526
import { Cspr, Tcspr } from '@bitgo/sdk-coin-cspr';
2627
import { Dash, Tdash } from '@bitgo/sdk-coin-dash';
@@ -93,6 +94,7 @@ export { Btg };
9394
export { Celo, CeloToken, Tcelo };
9495
export { Coredao, Tcoredao, CoredaoToken };
9596
export { Coreum, Tcoreum };
97+
export { CosmosToken };
9698
export { Cronos, Tcronos };
9799
export { Cspr, Tcspr };
98100
export { Dash, Tdash };

modules/bitgo/test/browser/browser.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('Coins', () => {
4646
EvmCoin: 1,
4747
Nep141Token: 1,
4848
WorldToken: 1,
49+
CosmosToken: 1,
4950
};
5051
Object.keys(BitGoJS.Coin)
5152
.filter((coinName) => !excludedKeys[coinName])

modules/statics/src/coinFeatures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export const COSMOS_SIDECHAIN_FEATURES = [
372372
CoinFeature.BULK_TRANSACTION,
373373
CoinFeature.STUCK_TRANSACTION_MANAGEMENT_TSS,
374374
CoinFeature.ALPHANUMERIC_MEMO_ID,
375+
CoinFeature.SUPPORTS_TOKENS,
375376
];
376377
export const COSMOS_SIDECHAIN_FEATURES_WITH_STAKING = [
377378
...COSMOS_SIDECHAIN_FEATURES,

modules/statics/src/coins.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4194,6 +4194,29 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
41944194
token.isToken, // isToken
41954195
token.kind // kind
41964196
);
4197+
case 'asi':
4198+
case 'atom':
4199+
case 'baby':
4200+
case 'bld':
4201+
case 'coreum':
4202+
case 'cronos':
4203+
case 'hash':
4204+
case 'injective':
4205+
case 'initia':
4206+
case 'osmo':
4207+
case 'thor':
4208+
case 'sei':
4209+
case 'tia':
4210+
case 'zeta':
4211+
return initializer(
4212+
...commonArgs.slice(0, 3), // id, name, fullName
4213+
token.denom, // denom
4214+
token.decimalPlaces, // decimalPlaces
4215+
token.network, // network
4216+
token.baseUnit, // baseUnit
4217+
...commonArgs.slice(4, 8), // asset, features, prefix, suffix
4218+
token.primaryKeyCurve // primaryKeyCurve
4219+
);
41974220
default:
41984221
return undefined;
41994222
}

modules/statics/src/tokenConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
BscCoin,
1010
CeloCoin,
1111
CoredaoERC20Token,
12+
CosmosChainToken,
1213
EosCoin,
1314
Erc1155Coin,
1415
Erc20Coin,
@@ -26,7 +27,6 @@ import {
2627
WorldERC20Token,
2728
XrpCoin,
2829
ZkethERC20Token,
29-
CosmosChainToken,
3030
} from './account';
3131
import { CoinFamily, CoinKind, BaseCoin } from './base';
3232
import { coins } from './coins';
@@ -141,7 +141,8 @@ export type TokenConfig =
141141
| AptTokenConfig
142142
| AptNFTCollectionConfig
143143
| Sip10TokenConfig
144-
| Nep141TokenConfig;
144+
| Nep141TokenConfig
145+
| CosmosTokenConfig;
145146

146147
export interface Tokens {
147148
bitcoin: {
@@ -339,6 +340,7 @@ export interface AmsTokenConfig {
339340
currecnycode?: string;
340341
domain?: string;
341342
assetId?: string;
343+
denom?: string;
342344
isToken: boolean;
343345
baseUnit?: string;
344346
kind?: string;
@@ -1181,6 +1183,8 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
11811183
return getSip10TokenConfig(coin);
11821184
} else if (coin instanceof Nep141Token) {
11831185
return getNep141TokenConfig(coin);
1186+
} else if (coin instanceof CosmosChainToken) {
1187+
return getCosmosTokenConfig(coin);
11841188
}
11851189
return undefined;
11861190
}

0 commit comments

Comments
 (0)