Skip to content

Commit 519935b

Browse files
committed
feat(sdk-coin-apt): add generic NFT collection statics
TICKET: COIN-3613
1 parent e8c3e36 commit 519935b

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

modules/statics/src/account.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export interface Erc20ConstructorOptions extends AccountConstructorOptions {
7878
contractAddress: string;
7979
}
8080

81+
export interface CollectionIdConstructorOptions extends AccountConstructorOptions {
82+
collectionId: string;
83+
}
84+
8185
export interface StellarCoinConstructorOptions extends AccountConstructorOptions {
8286
domain: string;
8387
}
@@ -180,6 +184,20 @@ export class ContractAddressDefinedToken extends AccountCoinToken {
180184
}
181185
}
182186

187+
/**
188+
* Used for blockchains that support NFT collections.
189+
*/
190+
export class CollectionIdDefinedToken extends AccountCoinToken {
191+
public collectionId: string;
192+
193+
constructor(options: CollectionIdConstructorOptions) {
194+
super({
195+
...options,
196+
});
197+
this.collectionId = options.collectionId;
198+
}
199+
}
200+
183201
/**
184202
* ERC20 token addresses are Base58 formatted on some blockchains.
185203
*/
@@ -501,6 +519,12 @@ export class AptCoin extends AccountCoinToken {
501519
}
502520
}
503521

522+
/**
523+
* The Apt network supports non-fungible tokens (Digital Asset Standard)
524+
* Every NFT belongs to an NFT collection.
525+
*/
526+
export class AptNFTCollection extends CollectionIdDefinedToken {}
527+
504528
/**
505529
* Fiat currencies, such as USD, EUR, or YEN.
506530
*/
@@ -2513,6 +2537,51 @@ export function aptToken(
25132537
);
25142538
}
25152539

2540+
/**
2541+
* Factory function for Apt NFT collections.
2542+
*
2543+
* @param id uuid v4
2544+
* @param name unique identifier of the NFT collection
2545+
* @param fullName Complete human-readable name of the NFT collection
2546+
* @param collectionId collection ID of the non-fungible tokens (NFTs)
2547+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2548+
* @param prefix Optional token prefix. Defaults to empty string
2549+
* @param suffix Optional token suffix. Defaults to token name.
2550+
* @param network Optional token network. Defaults to APT main network.
2551+
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES and REQUIRES_RESERVE defined in `AccountCoin`
2552+
* @param primaryKeyCurve The elliptic curve for this chain/token
2553+
*/
2554+
export function aptNFTCollection(
2555+
id: string,
2556+
name: string,
2557+
fullName: string,
2558+
collectionId: string,
2559+
asset: UnderlyingAsset,
2560+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
2561+
prefix = '',
2562+
suffix: string = name.toUpperCase(),
2563+
network: AccountNetwork = Networks.main.apt,
2564+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
2565+
) {
2566+
return Object.freeze(
2567+
new AptNFTCollection({
2568+
id,
2569+
name,
2570+
fullName,
2571+
network,
2572+
collectionId,
2573+
prefix,
2574+
suffix,
2575+
features,
2576+
decimalPlaces: 0,
2577+
asset,
2578+
isToken: true,
2579+
primaryKeyCurve,
2580+
baseUnit: BaseUnit.APT,
2581+
})
2582+
);
2583+
}
2584+
25162585
/**
25172586
* Factory function for testnet apt token instances.
25182587
*
@@ -2556,6 +2625,35 @@ export function taptToken(
25562625
);
25572626
}
25582627

2628+
/**
2629+
* Factory function for testnet Apt NFT collections.
2630+
*
2631+
* @param id uuid v4
2632+
* @param name unique identifier of the NFT collection
2633+
* @param fullName Complete human-readable name of the NFT collection
2634+
* @param collectionId collection ID of the non-fungible tokens (NFTs)
2635+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2636+
* @param prefix Optional token prefix. Defaults to empty string
2637+
* @param suffix Optional token suffix. Defaults to token name.
2638+
* @param network Optional token network. Defaults to APT test network.
2639+
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES and REQUIRES_RESERVE defined in `AccountCoin`
2640+
* @param primaryKeyCurve The elliptic curve for this chain/token
2641+
*/
2642+
export function taptNFTCollection(
2643+
id: string,
2644+
name: string,
2645+
fullName: string,
2646+
collectionId: string,
2647+
asset: UnderlyingAsset,
2648+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
2649+
prefix = '',
2650+
suffix: string = name.toUpperCase(),
2651+
network: AccountNetwork = Networks.test.apt,
2652+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
2653+
) {
2654+
return aptNFTCollection(id, name, fullName, collectionId, asset, features, prefix, suffix, network, primaryKeyCurve);
2655+
}
2656+
25592657
/**
25602658
* Factory function for fiat coin instances.
25612659
*

modules/statics/src/base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,9 @@ export enum UnderlyingAsset {
25162516
// Apt testnet tokens
25172517
'tapt:usdt' = 'tapt:usdt',
25182518

2519+
// Apt testnet NFT collections
2520+
'tapt:nftcollection1' = 'tapt:nftcollection1',
2521+
25192522
// Sip10 tokens
25202523
'stx:sbtc' = 'stx:sbtc',
25212524
'stx:ststx' = 'stx:ststx',

modules/statics/src/coins.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
account,
33
AccountCoin,
44
algoToken,
5+
aptNFTCollection,
6+
aptToken,
57
arbethErc20,
68
avaxErc20,
79
beraErc20,
@@ -23,7 +25,6 @@ import {
2325
solToken,
2426
stellarToken,
2527
suiToken,
26-
aptToken,
2728
talgoToken,
2829
tarbethErc20,
2930
tberaErc20,
@@ -41,6 +42,7 @@ import {
4142
xrpToken,
4243
zkethErc20,
4344
taptToken,
45+
taptNFTCollection,
4446
} from './account';
4547
import { ada } from './ada';
4648
import { avaxp } from './avaxp';
@@ -2902,6 +2904,15 @@ export const coins = CoinMap.fromCoins([
29022904
UnderlyingAsset['tapt:usdt'],
29032905
APT_FEATURES
29042906
),
2907+
// TODO: remove after APT NFTs are live on prod
2908+
taptNFTCollection(
2909+
'8f222afb-99b5-4811-b7d0-3a0753b8be74',
2910+
'tapt:nftcollection1',
2911+
'BitGo Apt NFT Collection (Test) #1',
2912+
'0xbbc561fbfa5d105efd8dfb06ae3e7e5be46331165b99d518f094c701e40603b5',
2913+
UnderlyingAsset['tapt:nftcollection1'],
2914+
APT_FEATURES
2915+
),
29052916
fiat('3f89b1f5-4ada-49c0-a613-15e484d42426', 'fiatusd', 'US Dollar', Networks.main.fiat, 2, UnderlyingAsset.USD),
29062917
fiat(
29072918
'8691cc4f-a425-4192-b6cb-3b0b6f646cbc',
@@ -3017,6 +3028,13 @@ function createToken(
30173028
);
30183029

30193030
case 'apt':
3031+
const { initFunc, objectId } = getAptTokenInitializer(token);
3032+
return initFunc(
3033+
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
3034+
objectId,
3035+
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
3036+
);
3037+
30203038
case 'stx':
30213039
return initializer(
30223040
...commonArgs.slice(0, 4), // id, name, fullName, decimalPlaces
@@ -3091,6 +3109,21 @@ function createToken(
30913109
}
30923110
}
30933111

3112+
function getAptTokenInitializer(token: AmsTokenConfig) {
3113+
if (token.assetId) {
3114+
// used for fungible-assets / legacy coins etc.
3115+
return {
3116+
initFunc: aptToken as (...args: unknown[]) => Readonly<BaseCoin>,
3117+
objectId: token.assetId,
3118+
};
3119+
}
3120+
// used for non-fungible token (NFT) collections
3121+
return {
3122+
initFunc: aptNFTCollection as (...args: unknown[]) => Readonly<BaseCoin>,
3123+
objectId: token.collectionId,
3124+
};
3125+
}
3126+
30943127
export function createTokenMapUsingConfigDetails(tokenConfigMap: Record<string, AmsTokenConfig[]>): CoinMap {
30953128
const BaseCoins: Map<string, Readonly<BaseCoin>> = new Map();
30963129
const initializerMap: Record<string, unknown> = {

modules/statics/src/tokenConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export interface AmsTokenConfig {
247247
primaryKeyCurve?: string;
248248
contractAddress?: string;
249249
tokenAddress?: string;
250+
collectionId?: string;
250251
alias?: string;
251252
contractName?: string;
252253
tokenId?: string;

0 commit comments

Comments
 (0)