Skip to content

Commit b5632e7

Browse files
authored
Merge pull request #6856 from BitGo/WIN-6446-ada-token-configs
feat(sdk-coin-ada): Add token support config
2 parents 59e7650 + 8352773 commit b5632e7

File tree

9 files changed

+76
-42
lines changed

9 files changed

+76
-42
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Coins', () => {
1414
const excludedKeys = {
1515
AbstractUtxoCoin: 1,
1616
AbstractLightningCoin: 1,
17+
AdaToken: 1,
1718
Erc20Token: 1,
1819
Erc721Token: 1,
1920
EthLikeCoin: 1,

modules/sdk-coin-ada/src/adaToken.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { Ada } from './ada';
22
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
3-
import { coins, tokens } from '@bitgo/statics';
4-
5-
export interface AdaTokenConfig {
6-
name: string;
7-
type: string;
8-
coin: string;
9-
network: string;
10-
policyId: string;
11-
assetName: string;
12-
decimalPlaces: number;
13-
}
3+
import { coins, tokens, AdaTokenConfig } from '@bitgo/statics';
144

155
export class AdaToken extends Ada {
166
public readonly tokenConfig: AdaTokenConfig;
@@ -60,6 +50,10 @@ export class AdaToken extends Ada {
6050
return this.tokenConfig.decimalPlaces;
6151
}
6252

53+
get uniqueAssetId() {
54+
return this.tokenConfig.uniqueAssetId;
55+
}
56+
6357
getChain() {
6458
return this.tokenConfig.type;
6559
}

modules/statics/src/account.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ export interface SolCoinConstructorOptions extends AccountConstructorOptions {
112112
programId: string;
113113
}
114114

115-
export interface AdaCoinConstructorOptions extends AccountConstructorOptions {
116-
policyId: string;
117-
assetName: string;
118-
}
119-
120115
export interface XrpCoinConstructorOptions extends AccountConstructorOptions {
121116
issuerAddress: string;
122117
currencyCode: string;
@@ -166,6 +161,11 @@ export interface CosmosTokenConstructorOptions extends AccountConstructorOptions
166161
denom: string;
167162
}
168163

164+
export interface AdaTokenConstructorOptions extends AccountConstructorOptions {
165+
uniqueAssetId: string;
166+
policyId: string;
167+
assetName: string;
168+
}
169169
export interface ContractAddress extends String {
170170
__contractaddress_phantom__: never;
171171
}
@@ -413,24 +413,6 @@ export class SolCoin extends AccountCoinToken {
413413
}
414414
}
415415

416-
/**
417-
* The Ada network supports tokens
418-
* Ada tokens are identified by their policy ID and asset name
419-
*
420-
*/
421-
export class AdaCoin extends AccountCoinToken {
422-
public policyId: string;
423-
public assetName: string;
424-
constructor(options: AdaCoinConstructorOptions) {
425-
super({
426-
...options,
427-
});
428-
429-
this.policyId = options.policyId;
430-
this.assetName = options.assetName;
431-
}
432-
}
433-
434416
export class EthLikeERC20Token extends ContractAddressDefinedToken {
435417
constructor(options: Erc20ConstructorOptions) {
436418
super(options);
@@ -713,6 +695,21 @@ export class PolyxCoin extends AccountCoinToken {
713695
}
714696
}
715697

698+
export class AdaToken extends AccountCoinToken {
699+
public uniqueAssetId: string;
700+
public policyId: string;
701+
public assetName: string;
702+
constructor(options: AdaTokenConstructorOptions) {
703+
super({
704+
...options,
705+
});
706+
707+
this.uniqueAssetId = options.uniqueAssetId;
708+
this.policyId = options.policyId;
709+
this.assetName = options.assetName;
710+
}
711+
}
712+
716713
/**
717714
* Factory function for account coin instances.
718715
*
@@ -1886,15 +1883,17 @@ export function adaToken(
18861883
decimalPlaces: number,
18871884
policyId: string,
18881885
assetName: string,
1886+
encodedAssetName: string,
18891887
asset: UnderlyingAsset,
18901888
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.REQUIRES_RESERVE],
18911889
prefix = '',
18921890
suffix: string = name.toUpperCase(),
18931891
network: AccountNetwork = Networks.main.ada,
18941892
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
18951893
) {
1894+
const uniqueAssetId = `${policyId}${encodedAssetName}`;
18961895
return Object.freeze(
1897-
new AdaCoin({
1896+
new AdaToken({
18981897
id,
18991898
name,
19001899
fullName,
@@ -1909,6 +1908,7 @@ export function adaToken(
19091908
isToken: true,
19101909
primaryKeyCurve,
19111910
baseUnit: BaseUnit.ADA,
1911+
uniqueAssetId,
19121912
})
19131913
);
19141914
}
@@ -1935,13 +1935,27 @@ export function tadaToken(
19351935
decimalPlaces: number,
19361936
policyId: string,
19371937
assetName: string,
1938+
encodedAssetName: string,
19381939
asset: UnderlyingAsset,
19391940
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.REQUIRES_RESERVE],
19401941
network: AccountNetwork = Networks.test.ada,
19411942
prefix = '',
19421943
suffix: string = name.toUpperCase()
19431944
) {
1944-
return adaToken(id, name, fullName, decimalPlaces, policyId, assetName, asset, features, prefix, suffix, network);
1945+
return adaToken(
1946+
id,
1947+
name,
1948+
fullName,
1949+
decimalPlaces,
1950+
policyId,
1951+
assetName,
1952+
encodedAssetName,
1953+
asset,
1954+
features,
1955+
prefix,
1956+
suffix,
1957+
network
1958+
);
19451959
}
19461960

19471961
/**

modules/statics/src/coinFeatures.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ export const HTETH_TOKEN_FEATURES = [
170170
];
171171
export const ADA_FEATURES = [...Ada.DEFAULT_FEATURES, CoinFeature.BULK_TRANSACTION, CoinFeature.SUPPORTS_TOKENS];
172172
export const ADA_FEATURES_WITH_FRANKFURT = [...ADA_FEATURES, CoinFeature.CUSTODY_BITGO_FRANKFURT];
173+
export const ADA_TOKEN_FEATURES = [
174+
...ACCOUNT_COIN_DEFAULT_FEATURES,
175+
CoinFeature.BULK_TRANSACTION,
176+
CoinFeature.TSS,
177+
CoinFeature.TSS_COLD,
178+
CoinFeature.STAKING,
179+
];
173180
export const DOT_FEATURES = [
174181
...ACCOUNT_COIN_DEFAULT_FEATURES,
175182
CoinFeature.TSS,

modules/statics/src/coins.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
255255
...commonArgs.slice(4, 8), // asset, features, prefix, suffix
256256
token.primaryKeyCurve // primaryKeyCurve
257257
);
258+
case 'ada':
259+
return initializer(
260+
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
261+
token.uniqueAssetId,
262+
token.assetName,
263+
token.policyId,
264+
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
265+
);
258266
default:
259267
return undefined;
260268
}

modules/statics/src/coins/adaTokens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { tadaToken, AccountCoin } from '../account';
1+
import { tadaToken } from '../account';
22
import { UnderlyingAsset } from '../base';
3+
import { ADA_TOKEN_FEATURES } from '../coinFeatures';
34
import { Networks } from '../networks';
45

56
export const adaTokens = [
@@ -10,8 +11,9 @@ export const adaTokens = [
1011
6,
1112
'2533cca6eb42076e144e9f2772c390dece9fce173bc38c72294b3924',
1213
'WATER',
14+
'5741544552',
1315
UnderlyingAsset['tada:water'],
14-
AccountCoin.DEFAULT_FEATURES,
16+
ADA_TOKEN_FEATURES,
1517
Networks.test.ada
1618
),
1719
];

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export {
3131
VetToken,
3232
VetNFTCollection,
3333
CosmosChainToken,
34+
AdaToken,
3435
} from './account';
3536
export { CoinMap } from './map';
3637
export { networkFeatureMapForTokens } from './networkFeatureMapForTokens';

modules/statics/src/networkFeatureMapForTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AccountCoin } from './account';
22
import { CoinFamily, CoinFeature } from './base';
33
import {
4+
ADA_TOKEN_FEATURES,
45
APT_FEATURES,
56
BSC_TOKEN_FEATURES,
67
POLYGON_TOKEN_FEATURES,
@@ -33,4 +34,5 @@ export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[
3334
xlm: AccountCoin.DEFAULT_FEATURES,
3435
xrp: AccountCoin.DEFAULT_FEATURES,
3536
ofc: [],
37+
ada: ADA_TOKEN_FEATURES,
3638
};

modules/statics/src/tokenConfig.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
AdaCoin,
32
AlgoCoin,
43
AptCoin,
54
AptNFTCollection,
@@ -30,6 +29,7 @@ import {
3029
XrpCoin,
3130
ZkethERC20Token,
3231
VetNFTCollection,
32+
AdaToken,
3333
} from './account';
3434
import { CoinFamily, CoinKind, BaseCoin } from './base';
3535
import { coins } from './coins';
@@ -70,6 +70,7 @@ export type SolTokenConfig = BaseNetworkConfig & {
7070
export type AdaTokenConfig = BaseNetworkConfig & {
7171
policyId: string;
7272
assetName: string;
73+
uniqueAssetId: string;
7374
};
7475

7576
export type AlgoTokenConfig = BaseNetworkConfig & {
@@ -384,6 +385,9 @@ export interface AmsTokenConfig {
384385
ticker?: string;
385386
programId?: string;
386387
addressCoin?: string;
388+
assetName?: string;
389+
uniqueAssetId?: string;
390+
policyId?: string;
387391
}
388392

389393
export interface TrimmedAmsNetworkConfig {
@@ -778,7 +782,7 @@ const getFormattedHbarTokens = (customCoinMap = coins) =>
778782
return acc;
779783
}, []);
780784

781-
function getAdaTokenConfig(coin: AdaCoin): AdaTokenConfig {
785+
function getAdaTokenConfig(coin: AdaToken): AdaTokenConfig {
782786
return {
783787
type: coin.name,
784788
coin: coin.network.type === NetworkType.MAINNET ? 'ada' : 'tada',
@@ -787,11 +791,12 @@ function getAdaTokenConfig(coin: AdaCoin): AdaTokenConfig {
787791
policyId: coin.policyId,
788792
assetName: coin.assetName,
789793
decimalPlaces: coin.decimalPlaces,
794+
uniqueAssetId: coin.uniqueAssetId,
790795
};
791796
}
792797
const getFormattedAdaTokens = (customCoinMap = coins) =>
793798
customCoinMap.reduce((acc: AdaTokenConfig[], coin) => {
794-
if (coin instanceof AdaCoin) {
799+
if (coin instanceof AdaToken) {
795800
acc.push(getAdaTokenConfig(coin));
796801
}
797802
return acc;
@@ -1306,7 +1311,7 @@ export function getFormattedTokenConfigForCoin(coin: Readonly<BaseCoin>): TokenC
13061311
return getSolTokenConfig(coin);
13071312
} else if (coin instanceof HederaToken) {
13081313
return getHbarTokenConfig(coin);
1309-
} else if (coin instanceof AdaCoin) {
1314+
} else if (coin instanceof AdaToken) {
13101315
return getAdaTokenConfig(coin);
13111316
} else if (coin instanceof TronErc20Coin) {
13121317
return getTrxTokenConfig(coin);

0 commit comments

Comments
 (0)