-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathaccount.ts
More file actions
4073 lines (3890 loc) · 126 KB
/
account.ts
File metadata and controls
4073 lines (3890 loc) · 126 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { BaseCoin, BaseUnit, CoinFeature, CoinKind, KeyCurve, UnderlyingAsset } from './base';
import { DOMAIN_PATTERN, HEDERA_NODE_ACCCOUNT_ID } from './constants';
import { InvalidContractAddressError, InvalidDomainError } from './errors';
import { AccountNetwork, BaseNetwork, EthereumNetwork, Networks, TronNetwork } from './networks';
import {
ACCOUNT_COIN_DEFAULT_FEATURES,
ACCOUNT_COIN_DEFAULT_FEATURES_EXCLUDE_SINGAPORE,
CELO_TOKEN_FEATURES,
COSMOS_SIDECHAIN_FEATURES,
} from './coinFeatures';
/**
* This is the program id against sol token program.
*/
export enum ProgramID {
TokenProgramId = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
Token2022ProgramId = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
}
export interface AccountConstructorOptions {
id: string;
fullName: string;
name: string;
alias?: string;
network: AccountNetwork;
asset: UnderlyingAsset;
baseUnit: BaseUnit;
features: CoinFeature[];
decimalPlaces: number;
isToken: boolean;
prefix?: string;
suffix?: string;
primaryKeyCurve: KeyCurve;
}
/**
* Account based coins, such as Ethereum, Stellar, or XRP.
*
* These types of coins maintain an "account balance" for each address on the network,
* as opposed to the unspent transaction output model which maintains a record of all
* "pieces" of coin which belong to an address.
*/
export class AccountCoin extends BaseCoin {
public static readonly DEFAULT_FEATURES = ACCOUNT_COIN_DEFAULT_FEATURES;
// Need to gate some high risk coin from SINGAPORE trust
public static readonly DEFAULT_FEATURES_EXCLUDE_SINGAPORE = ACCOUNT_COIN_DEFAULT_FEATURES_EXCLUDE_SINGAPORE;
public readonly network: AccountNetwork;
constructor(options: AccountConstructorOptions) {
super({
...options,
kind: CoinKind.CRYPTO,
});
this.network = options.network;
}
protected requiredFeatures(): Set<CoinFeature> {
return new Set<CoinFeature>([CoinFeature.ACCOUNT_MODEL]);
}
protected disallowedFeatures(): Set<CoinFeature> {
return new Set<CoinFeature>([CoinFeature.UNSPENT_MODEL]);
}
public static getFeaturesExcluding(excludedFeatures: CoinFeature[]): CoinFeature[] {
return AccountCoin.DEFAULT_FEATURES.filter((feature) => !excludedFeatures.includes(feature));
}
public static getFeaturesByTypeExcluding(
excludedFeatures: CoinFeature[],
baseFeatures: CoinFeature[] = AccountCoin.DEFAULT_FEATURES
): CoinFeature[] {
return baseFeatures.filter((feature) => !excludedFeatures.includes(feature));
}
}
export interface GasTankAccountConstructorOptions extends AccountConstructorOptions {
// low gas tank balance alert threshold is calculated as (feeEstimate x gasTankLowBalanceAlertFactor)
gasTankLowBalanceAlertFactor: number;
// min gas tank balance recommendation is calculated as (feeEstimate x gasTankMinBalanceRecommendationFactor)
gasTankMinBalanceRecommendationFactor: number;
// gas tank token is the token used to pay for gas
gasTankToken?: string;
}
export interface Erc20ConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
}
export interface Erc721ConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
}
export interface NFTCollectionIdConstructorOptions extends AccountConstructorOptions {
nftCollectionId: string;
}
export interface StellarCoinConstructorOptions extends AccountConstructorOptions {
domain: string;
}
export interface HederaCoinConstructorOptions extends AccountConstructorOptions {
nodeAccountId: string;
}
export interface HederaTokenConstructorOptions extends AccountConstructorOptions {
nodeAccountId: string;
contractAddress: string;
}
export interface EosCoinConstructorOptions extends AccountConstructorOptions {
contractName: string;
contractAddress: string;
symbol?: string;
}
export interface SolCoinConstructorOptions extends AccountConstructorOptions {
tokenAddress: string;
contractAddress: string;
programId: string;
}
export interface XrpCoinConstructorOptions extends AccountConstructorOptions {
issuerAddress: string;
currencyCode: string;
domain: string;
contractAddress: string;
}
export interface SuiCoinConstructorOptions extends AccountConstructorOptions {
packageId: string;
module: string;
symbol: string;
contractAddress: string;
}
export interface AptCoinConstructorOptions extends AccountConstructorOptions {
assetId: string;
}
export interface TaoCoinConstructorOptions extends AccountConstructorOptions {
subnetId: string;
}
export interface PolyxCoinConstructorOptions extends AccountConstructorOptions {
ticker: string;
assetId: string;
}
type FiatCoinName = `fiat${string}` | `tfiat${string}`;
export interface FiatCoinConstructorOptions extends AccountConstructorOptions {
name: FiatCoinName;
}
export interface Sip10TokenConstructorOptions extends AccountConstructorOptions {
assetId: string;
}
export interface Nep141TokenConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
storageDepositAmount: string;
}
export interface VetTokenConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
gasTankToken?: string;
}
export interface CosmosTokenConstructorOptions extends AccountConstructorOptions {
denom: string;
}
export interface JettonTokenConstructorOptions extends AccountConstructorOptions {
contractAddress: string;
}
export interface AdaTokenConstructorOptions extends AccountConstructorOptions {
policyId: string;
assetName: string;
contractAddress: string;
}
export interface ContractAddress extends String {
__contractaddress_phantom__: never;
}
export class AccountCoinToken extends AccountCoin {
constructor(options: AccountConstructorOptions) {
super({
...options,
});
}
}
export class GasTankAccountCoin extends AccountCoin {
public gasTankLowBalanceAlertFactor: number;
public gasTankMinBalanceRecommendationFactor: number;
public gasTankToken?: string;
constructor(options: GasTankAccountConstructorOptions) {
super({
...options,
});
this.gasTankLowBalanceAlertFactor = options.gasTankLowBalanceAlertFactor;
this.gasTankMinBalanceRecommendationFactor = options.gasTankMinBalanceRecommendationFactor;
this.gasTankToken = options?.gasTankToken;
}
}
/**
* Some blockchains support tokens which are defined by an address at which they have a smart contract deployed.
* Examples are ERC20 tokens, and the equivalent on other chains.
*/
export class ContractAddressDefinedToken extends AccountCoinToken {
public contractAddress: ContractAddress;
constructor(options: Erc20ConstructorOptions) {
super({
...options,
});
// valid ERC 20 contract addresses are "0x" followed by 40 lowercase hex characters
// do not use a valid address format for generic tokens because they not have onchain addresses
if (!options.contractAddress.match(/^0x[a-f0-9]{40}$/) && !options.features.includes(CoinFeature.GENERIC_TOKEN)) {
throw new InvalidContractAddressError(options.name, options.contractAddress);
}
this.contractAddress = options.contractAddress as unknown as ContractAddress;
}
}
/**
* Used for blockchains that support NFT collections.
*/
export class NFTCollectionIdDefinedToken extends AccountCoinToken {
public nftCollectionId: string;
constructor(options: NFTCollectionIdConstructorOptions) {
super({
...options,
});
this.nftCollectionId = options.nftCollectionId;
}
}
/**
* ERC20 token addresses are Base58 formatted on some blockchains.
*/
export class Base58ContractAddressDefinedToken extends AccountCoinToken {
public contractAddress: ContractAddress;
constructor(options: Erc20ConstructorOptions) {
super({
...options,
});
if (!/^[1-9A-HJ-NP-Za-km-z]{34}$/.test(options.contractAddress)) {
throw new InvalidContractAddressError(options.name, options.contractAddress);
}
this.contractAddress = options.contractAddress as unknown as ContractAddress;
}
}
/**
* ERC 20 is a token standard for the Ethereum blockchain. They are similar to other account coins, but have a
* contract address property which identifies the smart contract which defines the token.
*/
export class Erc20Coin extends ContractAddressDefinedToken {}
/**
* ERC 721 is the non fungible token standard for the Ethereum blockchain.
*
* {@link https://eips.ethereum.org/EIPS/eip-721 EIP721}
*/
export class Erc721Coin extends ContractAddressDefinedToken {}
/**
* ERC 1155 is the multi token standard for the Ethereum blockchain.
*
* {@link https://eips.ethereum.org/EIPS/eip-1155 EIP1155}
*/
export class Erc1155Coin extends ContractAddressDefinedToken {}
/**
* The TRON blockchain supports tokens of the ERC20 standard similar to ETH ERC20 tokens.
*/
export class TronErc20Coin extends Base58ContractAddressDefinedToken {}
/**
* Some blockchains have native coins which also support the ERC20 interface such as CELO.
*/
export class Erc20CompatibleAccountCoin extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super({
...options,
// These coins should not be classified as tokens as they are not children of other coins
isToken: false,
});
}
}
/**
* The CELO blockchain supports tokens of the ERC20 standard similar to ETH ERC20 tokens.
*/
export class CeloCoin extends ContractAddressDefinedToken {}
/**
* The BSC blockchain supports tokens of the ERC20 standard similar to ETH ERC20 tokens.
*/
export class BscCoin extends ContractAddressDefinedToken {}
/**
* The Stellar network supports tokens (non-native assets)
* XLM is also known as the native asset.
* Stellar tokens work similar to XLM, but the token name is determined by the chain,
* the token code and the issuer account in the form: (t)xlm:<token>-<issuer>
*/
export class StellarCoin extends AccountCoinToken {
public domain: string;
constructor(options: StellarCoinConstructorOptions) {
super({
...options,
});
if (options.domain !== '' && !options.domain.match(DOMAIN_PATTERN)) {
throw new InvalidDomainError(options.name, options.domain);
}
this.domain = options.domain as string;
}
}
/**
* The Hedera coin needs a client set with the node account Id.
* It's an account based coin that needs the node account ID
* where the transaction will be sent.
*
*/
export class HederaCoin extends AccountCoinToken {
public nodeAccountId: string;
constructor(options: HederaCoinConstructorOptions) {
super({
...options,
});
this.nodeAccountId = options.nodeAccountId;
}
}
/**
* The Hedera network supports tokens.
* Hedera tokens work similar to native Hedera coin,
* but the token is determined by the tokenId on the node
*
*/
export class HederaToken extends AccountCoinToken {
public nodeAccountId: string;
public tokenId: string;
public contractAddress: string;
constructor(options: HederaTokenConstructorOptions) {
super({
...options,
});
this.nodeAccountId = options.nodeAccountId;
this.tokenId = options.contractAddress;
this.contractAddress = options.contractAddress;
}
}
/**
* The Algo network supports tokens (assets)
* Algo tokens work similar to native ALGO coin, but the token name is determined by
* unique asset id on the chain. Internally, BitGo uses token identifiers of the format: (t)algo:<assetId>
*
*/
export class AlgoCoin extends AccountCoinToken {
constructor(options: AccountConstructorOptions) {
super({
...options,
});
}
}
/**
* The Eos network supports tokens
* Eos tokens work similar to native Eos coin, but the token name is determined by
* the contractName on the chain.
*
*/
export class EosCoin extends AccountCoinToken {
public contractName: string;
public contractAddress: string;
public symbol: string;
constructor(options: EosCoinConstructorOptions) {
super({
...options,
});
this.contractName = options.contractAddress;
this.contractAddress = options.contractAddress;
this.symbol = options.symbol ?? options.name.split(':')[1];
}
}
/**
* The Sol network supports tokens
* Sol tokens work similar to native SOL coin, but the token name is determined by
* the tokenAddress on the chain.
*
*/
export class SolCoin extends AccountCoinToken {
public tokenAddress: string;
public contractAddress: string;
public programId: string;
constructor(options: SolCoinConstructorOptions) {
super({
...options,
});
this.tokenAddress = options.contractAddress;
this.contractAddress = options.contractAddress;
this.programId = options.programId;
}
}
export class EthLikeERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
export class EthLikeERC721Token extends ContractAddressDefinedToken {
constructor(options: Erc721ConstructorOptions) {
super(options);
}
}
/**
* The AVAX C Chain network support tokens
* AVAX C Chain Tokens are ERC20 coins
*/
export class AvaxERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Polygon Chain network support tokens
* Polygon Chain Tokens are ERC20 coins
*/
export class PolygonERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Arbitrum Chain network support tokens
* Arbitrum Chain Tokens are ERC20 tokens
*/
export class ArbethERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Optimism Chain network support tokens
* Optimism Chain Tokens are ERC20 tokens
*/
export class OpethERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The zkSync network support tokens
* zkSync Tokens are ERC20 tokens
*/
export class ZkethERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Bera Chain network support tokens
* Bera Chain Tokens are ERC20 tokens
*/
export class BeraERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Coredao Chain network support tokens
* Coredao Chain Tokens are ERC20 tokens
*/
export class CoredaoERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The World Chain network supports tokens
* World Chain Tokens are ERC20 tokens
*/
export class WorldERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Flr Chain network supports tokens
* Flr Chain Tokens are ERC20 tokens
*/
export class FlrERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The XDC network supports tokens
* XDC Tokens are ERC20 tokens
*/
export class XdcERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}
/**
* The Xrp network supports tokens
* Xrp tokens are identified by their issuer address
* Naming format is similar to XLM
* <network>:<token>-<issuer>
*/
export class XrpCoin extends AccountCoinToken {
public issuerAddress: string;
public currencyCode: string;
public domain: string;
public contractAddress: string;
constructor(options: XrpCoinConstructorOptions) {
super({
...options,
});
if (options.domain !== '' && !options.domain.match(DOMAIN_PATTERN)) {
throw new InvalidDomainError(options.name, options.domain);
}
this.domain = options.domain as string;
this.issuerAddress = options.contractAddress.split('::')[0];
this.currencyCode = options.contractAddress.split('::')[1];
this.contractAddress = options.contractAddress;
}
}
export class SuiCoin extends AccountCoinToken {
public packageId: string;
public module: string;
public symbol: string;
public contractAddress: string;
constructor(options: SuiCoinConstructorOptions) {
super({
...options,
});
this.packageId = options.packageId;
this.module = options.module;
this.symbol = options.symbol;
this.contractAddress = options.contractAddress;
}
}
/**
* The Apt network supports tokens
* Apt tokens work similar to native Apt coin, but the token name is determined by
* the tokenAddress on the chain.
*
*/
export class AptCoin extends AccountCoinToken {
public assetId: string;
constructor(options: AptCoinConstructorOptions) {
super({
...options,
});
this.assetId = options.assetId;
}
}
/**
* The Apt network supports non-fungible tokens (Digital Asset Standard)
* Every NFT belongs to an NFT collection.
*/
export class AptNFTCollection extends NFTCollectionIdDefinedToken {}
/**
* The Vechain network supports non-fungible tokens
* Every NFT belongs to an NFT collection(contract).
*/
export class VetNFTCollection extends NFTCollectionIdDefinedToken {
public gasTankToken?: string;
constructor(options: NFTCollectionIdConstructorOptions & { gasTankToken?: string }) {
super(options);
this.gasTankToken = options.gasTankToken;
}
}
/**
* Fiat currencies, such as USD, EUR, or YEN.
*/
export class FiatCoin extends BaseCoin {
public static readonly DEFAULT_FEATURES = [...AccountCoin.DEFAULT_FEATURES];
public readonly network: BaseNetwork;
constructor(options: FiatCoinConstructorOptions) {
super({ ...options, kind: CoinKind.FIAT });
this.network = options.network;
}
protected requiredFeatures(): Set<CoinFeature> {
return new Set<CoinFeature>([CoinFeature.ACCOUNT_MODEL]);
}
protected disallowedFeatures(): Set<CoinFeature> {
return new Set<CoinFeature>([CoinFeature.UNSPENT_MODEL]);
}
}
/**
* The Stacks network supports tokens
* Stx tokens work similar to native Stx coin, but the token name is determined by
* the contractName on the chain.
*/
export class Sip10Token extends AccountCoinToken {
public assetId: string;
constructor(options: Sip10TokenConstructorOptions) {
super({
...options,
});
this.assetId = options.assetId;
}
}
/**
* The Near network supports tokens
* Near tokens work similar to native near coin
*/
export class Nep141Token extends AccountCoinToken {
public contractAddress: string;
public storageDepositAmount: string;
constructor(options: Nep141TokenConstructorOptions) {
super({
...options,
});
this.contractAddress = options.contractAddress;
this.storageDepositAmount = options.storageDepositAmount;
}
}
export class VetToken extends AccountCoinToken {
public contractAddress: string;
public gasTankToken?: string;
constructor(options: VetTokenConstructorOptions) {
super({
...options,
});
this.contractAddress = options.contractAddress;
this.gasTankToken = options.gasTankToken;
}
}
/**
* Cosmos network supports tokens
* Cosmos tokens work similar to native coins, but the token is determined by
* the denom on chain.
*
*/
export class CosmosChainToken extends AccountCoinToken {
public denom: string;
constructor(options: CosmosTokenConstructorOptions) {
super({
...options,
});
this.denom = options.denom;
}
}
/**
* TON supports tokens and Jetton is a token standard on TON
* Jetton tokens work similar to native TON coin
*/
export class JettonToken extends AccountCoinToken {
public contractAddress: string;
constructor(options: JettonTokenConstructorOptions) {
super({
...options,
});
this.contractAddress = options.contractAddress;
}
}
/**
* The Bittensor network supports tokens
* The token name is determined by the subnetId on chain.
*/
export class TaoCoin extends AccountCoinToken {
public subnetId: string;
constructor(options: TaoCoinConstructorOptions) {
super({
...options,
});
this.subnetId = options.subnetId;
}
}
/**
* The Bittensor network supports tokens
* The token name is determined by the subnetId on chain.
*/
export class PolyxCoin extends AccountCoinToken {
public ticker: string;
public assetId: string;
constructor(options: PolyxCoinConstructorOptions) {
super({
...options,
});
this.ticker = options.ticker;
this.assetId = options.assetId;
}
}
export class AdaToken extends AccountCoinToken {
public policyId: string;
public assetName: string;
public contractAddress: string;
constructor(options: AdaTokenConstructorOptions) {
super({
...options,
});
this.policyId = options.policyId;
this.assetName = options.assetName;
this.contractAddress = options.contractAddress;
}
}
/**
* Factory function for account coin instances.
*
* @param id uuid v4
* @param name unique identifier of the coin
* @param fullName Complete human-readable name of the coin
* @param network Network object for this coin
* @param decimalPlaces Number of decimal places this coin supports (divisibility exponent)
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve? The elliptic curve for this chain/token
* @param prefix? Optional coin prefix. Defaults to empty string
* @param suffix? Optional coin suffix. Defaults to coin name.
* @param isToken? Whether or not this account coin is a token of another coin
*/
export function account(
id: string,
name: string,
fullName: string,
network: AccountNetwork,
decimalPlaces: number,
asset: UnderlyingAsset,
baseUnit: BaseUnit,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1,
prefix = '',
suffix: string = name.toUpperCase(),
isToken = false
) {
return Object.freeze(
new AccountCoin({
id,
name,
fullName,
network,
prefix,
suffix,
baseUnit,
features,
decimalPlaces,
isToken,
asset,
primaryKeyCurve,
})
);
}
/**
* Factory function for gas tank account coin instances.
*
* @param id uuid v4
* @param name unique identifier of the coin
* @param fullName Complete human-readable name of the coin
* @param network Network object for this coin
* @param decimalPlaces Number of decimal places this coin supports (divisibility exponent)
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param baseUnit
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
* @param gasTankLowBalanceAlertFactor Low gas tank balance alert threshold = (feeEstimate x gasTankLowBalanceAlertFactor)
* @param gasTankMinBalanceRecommendationFactor Min gas tank balance recommendation = (feeEstimate x gasTankMinBalanceRecommendationFactor)
* @param prefix Optional coin prefix. Defaults to empty string
* @param suffix Optional coin suffix. Defaults to coin name.
* @param isToken Whether or not this account coin is a token of another coin
*/
export function gasTankAccount(
id: string,
name: string,
fullName: string,
network: AccountNetwork,
decimalPlaces: number,
asset: UnderlyingAsset,
baseUnit: BaseUnit,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1,
gasTankLowBalanceAlertFactor = 2,
gasTankMinBalanceRecommendationFactor = 10,
prefix = '',
suffix: string = name.toUpperCase(),
isToken = false,
gasTankToken?: string
) {
return Object.freeze(
new GasTankAccountCoin({
id,
name,
fullName,
network,
prefix,
suffix,
baseUnit,
features,
decimalPlaces,
isToken,
asset,
primaryKeyCurve,
gasTankLowBalanceAlertFactor,
gasTankMinBalanceRecommendationFactor,
gasTankToken,
})
);
}
/**
* Factory function for ethLikeErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents
* @param network Optional token network
* @param coinNames The parent coin names for mainnet and testnet
* @param features Features of this coin
* @param prefix Optional token prefix
* @param suffix Optional token suffix
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function erc20Token(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
network: AccountNetwork,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
prefix = '',
suffix: string = name.toUpperCase(),
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new EthLikeERC20Token({
id,
name,
fullName,
network,
contractAddress,
decimalPlaces,
asset,
features,
prefix,
suffix,
primaryKeyCurve,
isToken: true,
baseUnit: BaseUnit.ETH,
})
);
}
/**
* Factory function for erc721 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param contractAddress Contract address of this token
* @param network network
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param prefix Optional token prefix
* @param suffix Optional token suffix
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function erc721Token(
id: string,
name: string,
fullName: string,
contractAddress: string,
network: AccountNetwork,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
prefix = '',
suffix: string = name.toUpperCase(),
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
): Readonly<EthLikeERC721Token> {
return Object.freeze(
new EthLikeERC721Token({
id,
name,
fullName,
network,
contractAddress,
decimalPlaces: 0, // ERC721 tokens are non-divisible
asset: UnderlyingAsset.ERC721,
features,
prefix,
suffix,
primaryKeyCurve,
isToken: true,
baseUnit: BaseUnit.ETH,
})
);
}
/**
* Factory function for erc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to Ethereum main network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function erc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.BULK_TRANSACTION],
prefix = '',
suffix: string = name.toUpperCase(),
network: EthereumNetwork = Networks.main.ethereum,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new Erc20Coin({
id,
name,
fullName,
network,
contractAddress,
prefix,
suffix,
features,
decimalPlaces,
asset,