Skip to content

Commit ac9b92d

Browse files
authored
Merge pull request #5426 from BitGo/COIN-2889-apt-token-skeleton
feat(sdk-coin-apt): add Apt Token Skeleton
2 parents 55363c5 + 596f5e5 commit ac9b92d

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Apt } from './apt';
2+
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
3+
import { AptTokenConfig, coins, tokens } from '@bitgo/statics';
4+
5+
export class AptToken extends Apt {
6+
public readonly tokenConfig: AptTokenConfig;
7+
8+
constructor(bitgo: BitGoBase, tokenConfig: AptTokenConfig) {
9+
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('apt') : coins.get('tapt');
10+
super(bitgo, staticsCoin);
11+
this.tokenConfig = tokenConfig;
12+
}
13+
14+
static createTokenConstructor(config: AptTokenConfig): CoinConstructor {
15+
return (bitgo: BitGoBase) => new AptToken(bitgo, config);
16+
}
17+
18+
static createTokenConstructors(): NamedCoinConstructor[] {
19+
const tokensCtors: NamedCoinConstructor[] = [];
20+
for (const token of [...tokens.bitcoin.apt.tokens, ...tokens.testnet.apt.tokens]) {
21+
const tokenConstructor = AptToken.createTokenConstructor(token);
22+
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor });
23+
}
24+
return tokensCtors;
25+
}
26+
27+
get name(): string {
28+
return this.tokenConfig.name;
29+
}
30+
31+
get coin(): string {
32+
return this.tokenConfig.coin;
33+
}
34+
35+
get network(): string {
36+
return this.tokenConfig.network;
37+
}
38+
39+
get fungibleAssestAddress(): string {
40+
return this.tokenConfig.fungibleAssetAddress;
41+
}
42+
43+
get decimalPlaces(): number {
44+
return this.tokenConfig.decimalPlaces;
45+
}
46+
47+
getChain(): string {
48+
return this.tokenConfig.type;
49+
}
50+
51+
getBaseChain(): string {
52+
return this.coin;
53+
}
54+
55+
getFullName(): string {
56+
return 'Apt Token';
57+
}
58+
59+
getBaseFactor(): number {
60+
return Math.pow(10, this.tokenConfig.decimalPlaces);
61+
}
62+
}

modules/sdk-coin-apt/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './lib';
22
export * from './register';
33
export * from './apt';
44
export * from './tapt';
5+
export * from './aptToken';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { BitGoBase } from '@bitgo/sdk-core';
22
import { Apt } from './apt';
33
import { Tapt } from './tapt';
4+
import { AptToken } from './aptToken';
45

56
export const register = (sdk: BitGoBase): void => {
67
sdk.register('apt', Apt.createInstance);
78
sdk.register('tapt', Tapt.createInstance);
9+
AptToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
10+
sdk.register(name, coinConstructor);
11+
});
812
};

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export {
2020
TronErc20Coin,
2121
SuiCoin,
2222
XrpCoin,
23+
AptCoin,
2324
} from './account';
2425
export { CoinMap } from './map';

modules/statics/src/tokenConfig.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ZkethERC20Token,
2020
SuiCoin,
2121
BeraERC20Token,
22+
AptCoin,
2223
} from './account';
2324
import { CoinFamily, CoinKind } from './base';
2425
import { coins } from './coins';
@@ -80,6 +81,10 @@ export type SuiTokenConfig = BaseNetworkConfig & {
8081
symbol: string;
8182
};
8283

84+
export type AptTokenConfig = BaseNetworkConfig & {
85+
fungibleAssetAddress: string;
86+
};
87+
8388
export interface Tokens {
8489
bitcoin: {
8590
eth: {
@@ -139,6 +144,9 @@ export interface Tokens {
139144
bera: {
140145
tokens: EthLikeTokenConfig[];
141146
};
147+
apt: {
148+
tokens: AptTokenConfig[];
149+
};
142150
};
143151
testnet: {
144152
eth: {
@@ -198,6 +206,9 @@ export interface Tokens {
198206
bera: {
199207
tokens: EthLikeTokenConfig[];
200208
};
209+
apt: {
210+
tokens: AptTokenConfig[];
211+
};
201212
};
202213
}
203214

@@ -505,6 +516,20 @@ const formattedSuiTokens = coins.reduce((acc: SuiTokenConfig[], coin) => {
505516
return acc;
506517
}, []);
507518

519+
const formattedAptTokens = coins.reduce((acc: AptTokenConfig[], coin) => {
520+
if (coin instanceof AptCoin) {
521+
acc.push({
522+
type: coin.name,
523+
coin: coin.network.type === NetworkType.MAINNET ? 'apt' : 'tapt',
524+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
525+
name: coin.fullName,
526+
fungibleAssetAddress: coin.fungibleAssetAddress,
527+
decimalPlaces: coin.decimalPlaces,
528+
});
529+
}
530+
return acc;
531+
}, []);
532+
508533
export const tokens: Tokens = {
509534
// network name for production environments
510535
bitcoin: {
@@ -565,6 +590,9 @@ export const tokens: Tokens = {
565590
bera: {
566591
tokens: formattedBeraTokens.filter((token) => token.network === 'Mainnet'),
567592
},
593+
apt: {
594+
tokens: formattedAptTokens.filter((token) => token.network === 'Testnet'),
595+
},
568596
},
569597
// network name for test environments
570598
testnet: {
@@ -625,6 +653,9 @@ export const tokens: Tokens = {
625653
bera: {
626654
tokens: formattedBeraTokens.filter((token) => token.network === 'Testnet'),
627655
},
656+
apt: {
657+
tokens: formattedAptTokens.filter((token) => token.network === 'Testnet'),
658+
},
628659
},
629660
};
630661

0 commit comments

Comments
 (0)