Skip to content

Commit

Permalink
Merge pull request #5426 from BitGo/COIN-2889-apt-token-skeleton
Browse files Browse the repository at this point in the history
feat(sdk-coin-apt): add Apt Token Skeleton
  • Loading branch information
baltiyal authored Jan 24, 2025
2 parents 55363c5 + 596f5e5 commit ac9b92d
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
62 changes: 62 additions & 0 deletions modules/sdk-coin-apt/src/aptToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Apt } from './apt';
import { BitGoBase, CoinConstructor, NamedCoinConstructor } from '@bitgo/sdk-core';
import { AptTokenConfig, coins, tokens } from '@bitgo/statics';

export class AptToken extends Apt {
public readonly tokenConfig: AptTokenConfig;

constructor(bitgo: BitGoBase, tokenConfig: AptTokenConfig) {
const staticsCoin = tokenConfig.network === 'Mainnet' ? coins.get('apt') : coins.get('tapt');
super(bitgo, staticsCoin);
this.tokenConfig = tokenConfig;
}

static createTokenConstructor(config: AptTokenConfig): CoinConstructor {
return (bitgo: BitGoBase) => new AptToken(bitgo, config);
}

static createTokenConstructors(): NamedCoinConstructor[] {
const tokensCtors: NamedCoinConstructor[] = [];
for (const token of [...tokens.bitcoin.apt.tokens, ...tokens.testnet.apt.tokens]) {
const tokenConstructor = AptToken.createTokenConstructor(token);
tokensCtors.push({ name: token.type, coinConstructor: tokenConstructor });
}
return tokensCtors;
}

get name(): string {
return this.tokenConfig.name;
}

get coin(): string {
return this.tokenConfig.coin;
}

get network(): string {
return this.tokenConfig.network;
}

get fungibleAssestAddress(): string {
return this.tokenConfig.fungibleAssetAddress;
}

get decimalPlaces(): number {
return this.tokenConfig.decimalPlaces;
}

getChain(): string {
return this.tokenConfig.type;
}

getBaseChain(): string {
return this.coin;
}

getFullName(): string {
return 'Apt Token';
}

getBaseFactor(): number {
return Math.pow(10, this.tokenConfig.decimalPlaces);
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-apt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './lib';
export * from './register';
export * from './apt';
export * from './tapt';
export * from './aptToken';
4 changes: 4 additions & 0 deletions modules/sdk-coin-apt/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Apt } from './apt';
import { Tapt } from './tapt';
import { AptToken } from './aptToken';

export const register = (sdk: BitGoBase): void => {
sdk.register('apt', Apt.createInstance);
sdk.register('tapt', Tapt.createInstance);
AptToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
});
};
1 change: 1 addition & 0 deletions modules/statics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export {
TronErc20Coin,
SuiCoin,
XrpCoin,
AptCoin,
} from './account';
export { CoinMap } from './map';
31 changes: 31 additions & 0 deletions modules/statics/src/tokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ZkethERC20Token,
SuiCoin,
BeraERC20Token,
AptCoin,
} from './account';
import { CoinFamily, CoinKind } from './base';
import { coins } from './coins';
Expand Down Expand Up @@ -80,6 +81,10 @@ export type SuiTokenConfig = BaseNetworkConfig & {
symbol: string;
};

export type AptTokenConfig = BaseNetworkConfig & {
fungibleAssetAddress: string;
};

export interface Tokens {
bitcoin: {
eth: {
Expand Down Expand Up @@ -139,6 +144,9 @@ export interface Tokens {
bera: {
tokens: EthLikeTokenConfig[];
};
apt: {
tokens: AptTokenConfig[];
};
};
testnet: {
eth: {
Expand Down Expand Up @@ -198,6 +206,9 @@ export interface Tokens {
bera: {
tokens: EthLikeTokenConfig[];
};
apt: {
tokens: AptTokenConfig[];
};
};
}

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

const formattedAptTokens = coins.reduce((acc: AptTokenConfig[], coin) => {
if (coin instanceof AptCoin) {
acc.push({
type: coin.name,
coin: coin.network.type === NetworkType.MAINNET ? 'apt' : 'tapt',
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
name: coin.fullName,
fungibleAssetAddress: coin.fungibleAssetAddress,
decimalPlaces: coin.decimalPlaces,
});
}
return acc;
}, []);

export const tokens: Tokens = {
// network name for production environments
bitcoin: {
Expand Down Expand Up @@ -565,6 +590,9 @@ export const tokens: Tokens = {
bera: {
tokens: formattedBeraTokens.filter((token) => token.network === 'Mainnet'),
},
apt: {
tokens: formattedAptTokens.filter((token) => token.network === 'Testnet'),
},
},
// network name for test environments
testnet: {
Expand Down Expand Up @@ -625,6 +653,9 @@ export const tokens: Tokens = {
bera: {
tokens: formattedBeraTokens.filter((token) => token.network === 'Testnet'),
},
apt: {
tokens: formattedAptTokens.filter((token) => token.network === 'Testnet'),
},
},
};

Expand Down

0 comments on commit ac9b92d

Please sign in to comment.