Skip to content

Commit 6c55b23

Browse files
committed
feat: add Apt NFT collection skeleton
TICKET: COIN-4036
1 parent e952d49 commit 6c55b23

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-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 { AptNFTCollectionConfig, coins, tokens } from '@bitgo/statics';
4+
5+
export class AptNFTCollection extends Apt {
6+
public readonly nftCollectionConfig: AptNFTCollectionConfig;
7+
8+
constructor(bitgo: BitGoBase, nftCollectionConfig: AptNFTCollectionConfig) {
9+
const staticsCoin = nftCollectionConfig.network === 'Mainnet' ? coins.get('apt') : coins.get('tapt');
10+
super(bitgo, staticsCoin);
11+
this.nftCollectionConfig = nftCollectionConfig;
12+
}
13+
14+
static createNFTCollectionConstructor(config: AptNFTCollectionConfig): CoinConstructor {
15+
return (bitgo: BitGoBase) => new AptNFTCollection(bitgo, config);
16+
}
17+
static createNFTCollectionConstructors(
18+
nftCollectionConfigs: AptNFTCollectionConfig[] = [
19+
...tokens.bitcoin.apt.nftCollections,
20+
...tokens.testnet.apt.nftCollections,
21+
]
22+
): NamedCoinConstructor[] {
23+
const nftCollectionCtors: NamedCoinConstructor[] = [];
24+
for (const config of nftCollectionConfigs) {
25+
const nftCollectionConstructor = AptNFTCollection.createNFTCollectionConstructor(config);
26+
nftCollectionCtors.push({ name: config.type, coinConstructor: nftCollectionConstructor });
27+
}
28+
return nftCollectionCtors;
29+
}
30+
31+
get name(): string {
32+
return this.nftCollectionConfig.name;
33+
}
34+
35+
get coin(): string {
36+
return this.nftCollectionConfig.coin;
37+
}
38+
39+
get network(): string {
40+
return this.nftCollectionConfig.network;
41+
}
42+
43+
get nftCollectionId(): string {
44+
return this.nftCollectionConfig.nftCollectionId;
45+
}
46+
47+
getChain(): string {
48+
return this.nftCollectionConfig.type;
49+
}
50+
51+
getBaseChain(): string {
52+
return this.coin;
53+
}
54+
55+
getFullName(): string {
56+
return 'Apt NFT Collection';
57+
}
58+
59+
getBaseFactor(): number {
60+
return Math.pow(10, this.nftCollectionConfig.decimalPlaces);
61+
}
62+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './register';
33
export * from './apt';
44
export * from './tapt';
55
export * from './aptToken';
6+
export * from './aptNFTCollection';

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { BitGoBase } from '@bitgo/sdk-core';
22
import { Apt } from './apt';
33
import { Tapt } from './tapt';
44
import { AptToken } from './aptToken';
5+
import { AptNFTCollection } from './aptNFTCollection';
56

67
export const register = (sdk: BitGoBase): void => {
78
sdk.register('apt', Apt.createInstance);
89
sdk.register('tapt', Tapt.createInstance);
910
AptToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
1011
sdk.register(name, coinConstructor);
1112
});
13+
AptNFTCollection.createNFTCollectionConstructors().forEach(({ name, coinConstructor }) => {
14+
sdk.register(name, coinConstructor);
15+
});
1216
};

modules/statics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
SuiCoin,
2424
XrpCoin,
2525
AptCoin,
26+
AptNFTCollection,
2627
Sip10Token,
2728
} from './account';
2829
export { CoinMap } from './map';

modules/statics/src/tokenConfig.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AdaCoin,
33
AlgoCoin,
44
AptCoin,
5+
AptNFTCollection,
56
ArbethERC20Token,
67
AvaxERC20Token,
78
BeraERC20Token,
@@ -96,6 +97,10 @@ export type AptTokenConfig = BaseNetworkConfig & {
9697
assetId: string;
9798
};
9899

100+
export type AptNFTCollectionConfig = BaseNetworkConfig & {
101+
nftCollectionId: string;
102+
};
103+
99104
export type Sip10TokenConfig = BaseNetworkConfig & {
100105
assetId: string;
101106
};
@@ -161,6 +166,7 @@ export interface Tokens {
161166
};
162167
apt: {
163168
tokens: AptTokenConfig[];
169+
nftCollections: AptNFTCollectionConfig[];
164170
};
165171
stx: {
166172
tokens: Sip10TokenConfig[];
@@ -226,6 +232,7 @@ export interface Tokens {
226232
};
227233
apt: {
228234
tokens: AptTokenConfig[];
235+
nftCollections: AptNFTCollectionConfig[];
229236
};
230237
stx: {
231238
tokens: Sip10TokenConfig[];
@@ -618,6 +625,21 @@ const getFormattedAptTokens = (customCoinMap = coins) =>
618625
return acc;
619626
}, []);
620627

628+
const getFormattedAptNFTCollections = (customCoinMap = coins) =>
629+
customCoinMap.reduce((acc: AptNFTCollectionConfig[], coin) => {
630+
if (coin instanceof AptNFTCollection) {
631+
acc.push({
632+
type: coin.name,
633+
coin: coin.network.type === NetworkType.MAINNET ? 'apt' : 'tapt',
634+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
635+
name: coin.fullName,
636+
nftCollectionId: coin.nftCollectionId,
637+
decimalPlaces: coin.decimalPlaces,
638+
});
639+
}
640+
return acc;
641+
}, []);
642+
621643
const getFormattedSip10Tokens = (customCoinMap = coins) =>
622644
customCoinMap.reduce((acc: Sip10TokenConfig[], coin) => {
623645
if (coin instanceof Sip10Token) {
@@ -634,6 +656,7 @@ const getFormattedSip10Tokens = (customCoinMap = coins) =>
634656
}, []);
635657

636658
export const getFormattedTokens = (coinMap = coins): Tokens => {
659+
const formattedAptNFTCollections = getFormattedAptNFTCollections(coinMap);
637660
return {
638661
bitcoin: {
639662
eth: {
@@ -697,6 +720,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
697720
},
698721
apt: {
699722
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Mainnet'),
723+
nftCollections: formattedAptNFTCollections.filter(
724+
(nftCollection: AptNFTCollectionConfig) => nftCollection.network === 'Mainnet'
725+
),
700726
},
701727
stx: {
702728
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Mainnet'),
@@ -764,6 +790,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
764790
},
765791
apt: {
766792
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Testnet'),
793+
nftCollections: formattedAptNFTCollections.filter(
794+
(nftCollection: AptNFTCollectionConfig) => nftCollection.network === 'Testnet'
795+
),
767796
},
768797
stx: {
769798
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Testnet'),

0 commit comments

Comments
 (0)