Skip to content

Commit db1111c

Browse files
committed
feat(statics): add Apt Token support
TICKET: COIN-2892
1 parent 98b16cf commit db1111c

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

modules/statics/src/account.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ export interface SuiCoinConstructorOptions extends AccountConstructorOptions {
111111
symbol: string;
112112
}
113113

114+
export interface AptCoinConstructorOptions extends AccountConstructorOptions {
115+
fungibleAssetAddress: string;
116+
}
117+
114118
type FiatCoinName = `fiat${string}` | `tfiat${string}`;
115119
export interface FiatCoinConstructorOptions extends AccountConstructorOptions {
116120
name: FiatCoinName;
@@ -455,6 +459,23 @@ export class SuiCoin extends AccountCoinToken {
455459
}
456460
}
457461

462+
/**
463+
* The Apt network supports tokens
464+
* Apt tokens work similar to native Apt coin, but the token name is determined by
465+
* the tokenAddress on the chain.
466+
*
467+
*/
468+
export class AptCoin extends AccountCoinToken {
469+
public fungibleAssetAddress: string;
470+
constructor(options: AptCoinConstructorOptions) {
471+
super({
472+
...options,
473+
});
474+
475+
this.fungibleAssetAddress = options.fungibleAssetAddress;
476+
}
477+
}
478+
458479
/**
459480
* Fiat currencies, such as USD, EUR, or YEN.
460481
*/
@@ -2309,6 +2330,96 @@ export function tsuiToken(
23092330
);
23102331
}
23112332

2333+
/**
2334+
* Factory function for apt token instances.
2335+
*
2336+
* @param id uuid v4
2337+
* @param name unique identifier of the token
2338+
* @param fullName Complete human-readable name of the token
2339+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
2340+
* @param fungibleAssetAddress Fungible asset address of this token
2341+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2342+
* @param prefix Optional token prefix. Defaults to empty string
2343+
* @param suffix Optional token suffix. Defaults to token name.
2344+
* @param network Optional token network. Defaults to APT main network.
2345+
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES and REQUIRES_RESERVE defined in `AccountCoin`
2346+
* @param primaryKeyCurve The elliptic curve for this chain/token
2347+
*/
2348+
export function aptToken(
2349+
id: string,
2350+
name: string,
2351+
fullName: string,
2352+
decimalPlaces: number,
2353+
fungibleAssetAddress: string,
2354+
asset: UnderlyingAsset,
2355+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
2356+
prefix = '',
2357+
suffix: string = name.toUpperCase(),
2358+
network: AccountNetwork = Networks.main.apt,
2359+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
2360+
) {
2361+
return Object.freeze(
2362+
new AptCoin({
2363+
id,
2364+
name,
2365+
fullName,
2366+
network,
2367+
fungibleAssetAddress,
2368+
prefix,
2369+
suffix,
2370+
features,
2371+
decimalPlaces,
2372+
asset,
2373+
isToken: true,
2374+
primaryKeyCurve,
2375+
baseUnit: BaseUnit.APT,
2376+
})
2377+
);
2378+
}
2379+
2380+
/**
2381+
* Factory function for testnet apt token instances.
2382+
*
2383+
* @param id uuid v4
2384+
* @param name unique identifier of the token
2385+
* @param fullName Complete human-readable name of the token
2386+
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
2387+
* @param fungibleAssetAddress Fungible asset of this token
2388+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
2389+
* @param prefix Optional token prefix. Defaults to empty string
2390+
* @param suffix Optional token suffix. Defaults to token name.
2391+
* @param network Optional token network. Defaults to the testnet APT network.
2392+
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES and REQUIRES_RESERVE defined in `AccountCoin`
2393+
* @param primaryKeyCurve The elliptic curve for this chain/token
2394+
*/
2395+
export function taptToken(
2396+
id: string,
2397+
name: string,
2398+
fullName: string,
2399+
decimalPlaces: number,
2400+
fungibleAssetAddress: string,
2401+
asset: UnderlyingAsset,
2402+
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
2403+
prefix = '',
2404+
suffix: string = name.toUpperCase(),
2405+
network: AccountNetwork = Networks.test.apt,
2406+
primaryKeyCurve: KeyCurve = KeyCurve.Ed25519
2407+
) {
2408+
return aptToken(
2409+
id,
2410+
name,
2411+
fullName,
2412+
decimalPlaces,
2413+
fungibleAssetAddress,
2414+
asset,
2415+
features,
2416+
prefix,
2417+
suffix,
2418+
network,
2419+
primaryKeyCurve
2420+
);
2421+
}
2422+
23122423
/**
23132424
* Factory function for fiat coin instances.
23142425
*

0 commit comments

Comments
 (0)