Skip to content

Commit e585e04

Browse files
authored
Merge pull request #6129 from BitGo/coin-4036-onboard-h00ts-nft-collection
feat: add Apt NFT collection skeleton
2 parents 4b5349c + 6c55b23 commit e585e04

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
};
@@ -164,6 +169,7 @@ export interface Tokens {
164169
};
165170
apt: {
166171
tokens: AptTokenConfig[];
172+
nftCollections: AptNFTCollectionConfig[];
167173
};
168174
stx: {
169175
tokens: Sip10TokenConfig[];
@@ -232,6 +238,7 @@ export interface Tokens {
232238
};
233239
apt: {
234240
tokens: AptTokenConfig[];
241+
nftCollections: AptNFTCollectionConfig[];
235242
};
236243
stx: {
237244
tokens: Sip10TokenConfig[];
@@ -639,6 +646,21 @@ const getFormattedAptTokens = (customCoinMap = coins) =>
639646
return acc;
640647
}, []);
641648

649+
const getFormattedAptNFTCollections = (customCoinMap = coins) =>
650+
customCoinMap.reduce((acc: AptNFTCollectionConfig[], coin) => {
651+
if (coin instanceof AptNFTCollection) {
652+
acc.push({
653+
type: coin.name,
654+
coin: coin.network.type === NetworkType.MAINNET ? 'apt' : 'tapt',
655+
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
656+
name: coin.fullName,
657+
nftCollectionId: coin.nftCollectionId,
658+
decimalPlaces: coin.decimalPlaces,
659+
});
660+
}
661+
return acc;
662+
}, []);
663+
642664
const getFormattedSip10Tokens = (customCoinMap = coins) =>
643665
customCoinMap.reduce((acc: Sip10TokenConfig[], coin) => {
644666
if (coin instanceof Sip10Token) {
@@ -655,6 +677,7 @@ const getFormattedSip10Tokens = (customCoinMap = coins) =>
655677
}, []);
656678

657679
export const getFormattedTokens = (coinMap = coins): Tokens => {
680+
const formattedAptNFTCollections = getFormattedAptNFTCollections(coinMap);
658681
return {
659682
bitcoin: {
660683
eth: {
@@ -721,6 +744,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
721744
},
722745
apt: {
723746
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Mainnet'),
747+
nftCollections: formattedAptNFTCollections.filter(
748+
(nftCollection: AptNFTCollectionConfig) => nftCollection.network === 'Mainnet'
749+
),
724750
},
725751
stx: {
726752
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Mainnet'),
@@ -791,6 +817,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
791817
},
792818
apt: {
793819
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Testnet'),
820+
nftCollections: formattedAptNFTCollections.filter(
821+
(nftCollection: AptNFTCollectionConfig) => nftCollection.network === 'Testnet'
822+
),
794823
},
795824
stx: {
796825
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Testnet'),

0 commit comments

Comments
 (0)