@subwallet/extension-base 1.1.40-1 → 1.1.42-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/background/KoniTypes.d.ts +3 -1
  2. package/cjs/constants/index.js +1 -1
  3. package/cjs/koni/api/dotsama/transfer.js +1 -1
  4. package/cjs/koni/api/nft/bit.country/index.js +2 -0
  5. package/cjs/koni/api/nft/config.js +3 -1
  6. package/cjs/koni/api/tokens/evm/transfer.js +4 -4
  7. package/cjs/koni/background/handlers/Extension.js +32 -17
  8. package/cjs/koni/background/handlers/State.js +42 -10
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/page/SubWalleEvmProvider.js +5 -9
  11. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +58 -0
  12. package/cjs/services/chain-service/constants.js +11 -7
  13. package/cjs/services/chain-service/handler/chain-spec/goldberg.js +75 -8
  14. package/cjs/services/chain-service/index.js +88 -79
  15. package/cjs/services/chain-service/utils.js +11 -6
  16. package/cjs/services/earning-service/constants/chains.js +10 -5
  17. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +9 -3
  18. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
  19. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
  20. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
  21. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +4 -0
  22. package/cjs/services/earning-service/handlers/native-staking/astar.js +6 -2
  23. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +144 -45
  24. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +14 -16
  25. package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -11
  26. package/cjs/services/earning-service/handlers/special.js +2 -0
  27. package/cjs/services/earning-service/service.js +51 -18
  28. package/cjs/services/fee-service/service.js +70 -0
  29. package/cjs/services/fee-service/utils/index.js +209 -0
  30. package/cjs/services/migration-service/scripts/DeleteChainStaking.js +23 -0
  31. package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +50 -0
  32. package/cjs/services/migration-service/scripts/index.js +6 -1
  33. package/cjs/services/transaction-service/index.js +37 -37
  34. package/cjs/types/fee/index.js +1 -0
  35. package/cjs/types/index.js +11 -0
  36. package/cjs/utils/eth.js +2 -105
  37. package/cjs/utils/index.js +12 -0
  38. package/cjs/utils/reportError.js +31 -0
  39. package/constants/index.d.ts +1 -1
  40. package/constants/index.js +1 -1
  41. package/koni/api/dotsama/transfer.js +1 -1
  42. package/koni/api/nft/bit.country/index.js +3 -1
  43. package/koni/api/nft/config.d.ts +1 -0
  44. package/koni/api/nft/config.js +1 -0
  45. package/koni/api/tokens/evm/transfer.js +1 -1
  46. package/koni/background/handlers/Extension.d.ts +1 -0
  47. package/koni/background/handlers/Extension.js +18 -3
  48. package/koni/background/handlers/State.d.ts +4 -1
  49. package/koni/background/handlers/State.js +33 -2
  50. package/package.json +36 -6
  51. package/packageInfo.js +1 -1
  52. package/page/SubWalleEvmProvider.d.ts +0 -1
  53. package/page/SubWalleEvmProvider.js +5 -9
  54. package/services/balance-service/helpers/subscribe/substrate/index.js +59 -1
  55. package/services/chain-service/constants.d.ts +2 -0
  56. package/services/chain-service/constants.js +11 -7
  57. package/services/chain-service/handler/chain-spec/goldberg.d.ts +70 -1
  58. package/services/chain-service/handler/chain-spec/goldberg.js +75 -8
  59. package/services/chain-service/index.d.ts +8 -4
  60. package/services/chain-service/index.js +74 -67
  61. package/services/chain-service/types.d.ts +4 -0
  62. package/services/chain-service/utils.d.ts +1 -0
  63. package/services/chain-service/utils.js +10 -6
  64. package/services/earning-service/constants/chains.d.ts +3 -0
  65. package/services/earning-service/constants/chains.js +7 -4
  66. package/services/earning-service/handlers/liquid-staking/acala.js +9 -3
  67. package/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
  68. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +1 -1
  69. package/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
  70. package/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
  71. package/services/earning-service/handlers/native-staking/amplitude.js +4 -0
  72. package/services/earning-service/handlers/native-staking/astar.js +6 -2
  73. package/services/earning-service/handlers/native-staking/para-chain.js +144 -45
  74. package/services/earning-service/handlers/native-staking/relay-chain.js +15 -17
  75. package/services/earning-service/handlers/nomination-pool/index.js +10 -12
  76. package/services/earning-service/handlers/special.d.ts +1 -0
  77. package/services/earning-service/handlers/special.js +2 -0
  78. package/services/earning-service/service.d.ts +4 -1
  79. package/services/earning-service/service.js +52 -19
  80. package/services/fee-service/service.d.ts +12 -0
  81. package/services/fee-service/service.js +63 -0
  82. package/services/fee-service/utils/index.d.ts +8 -0
  83. package/services/fee-service/utils/index.js +193 -0
  84. package/services/migration-service/scripts/DeleteChainStaking.d.ts +4 -0
  85. package/services/migration-service/scripts/DeleteChainStaking.js +15 -0
  86. package/services/migration-service/scripts/databases/MigrateAssetSetting.d.ts +4 -0
  87. package/services/migration-service/scripts/databases/MigrateAssetSetting.js +42 -0
  88. package/services/migration-service/scripts/index.js +5 -1
  89. package/services/transaction-service/index.js +2 -2
  90. package/types/fee/index.d.ts +49 -0
  91. package/types/fee/index.js +1 -0
  92. package/types/index.d.ts +1 -0
  93. package/types/index.js +1 -0
  94. package/types/yield/info/account/unstake.d.ts +2 -0
  95. package/types/yield/info/pallet.d.ts +4 -0
  96. package/utils/eth.d.ts +0 -15
  97. package/utils/eth.js +0 -101
  98. package/utils/index.d.ts +1 -0
  99. package/utils/index.js +1 -0
  100. package/utils/reportError.d.ts +1 -0
  101. package/utils/reportError.js +23 -0
@@ -2,7 +2,7 @@
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
3
  import { AssetSetting, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
5
- import { _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
5
+ import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
6
6
  import { EventService } from '@subwallet/extension-base/services/event-service';
7
7
  import { IMetadataItem } from '@subwallet/extension-base/services/storage-service/databases';
8
8
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
@@ -19,6 +19,7 @@ export declare class ChainService {
19
19
  get mantaPay(): MantaPrivateHandler | undefined;
20
20
  private chainInfoMapSubject;
21
21
  private chainStateMapSubject;
22
+ private chainStatusMapSubject;
22
23
  private assetRegistrySubject;
23
24
  private multiChainAssetMapSubject;
24
25
  private xcmRefMapSubject;
@@ -26,7 +27,7 @@ export declare class ChainService {
26
27
  private assetSettingSubject;
27
28
  private logger;
28
29
  constructor(dbService: DatabaseService, eventService: EventService);
29
- getXcmRefMap(): Record<string, _AssetRef>;
30
+ get xcmRefMap(): Record<string, _AssetRef>;
30
31
  getEvmApi(slug: string): import("./handler/EvmApi").EvmApi;
31
32
  getEvmApiMap(): Record<string, import("./handler/EvmApi").EvmApi>;
32
33
  getSubstrateApiMap(): Record<string, import("./handler/SubstrateApi").SubstrateApi>;
@@ -40,6 +41,7 @@ export declare class ChainService {
40
41
  subscribeMultiChainAssetMap(): Subject<Record<string, _MultiChainAsset>>;
41
42
  subscribeXcmRefMap(): Subject<Record<string, _AssetRef>>;
42
43
  subscribeChainStateMap(): Subject<Record<string, _ChainState>>;
44
+ subscribeChainStatusMap(): BehaviorSubject<Record<string, _ChainApiStatus>>;
43
45
  getAssetRegistry(): Record<string, _ChainAsset>;
44
46
  getMultiChainAssetMap(): Record<string, _MultiChainAsset>;
45
47
  getSmartContractTokens(): Record<string, _ChainAsset>;
@@ -51,6 +53,8 @@ export declare class ChainService {
51
53
  getAssetRefMap(): Record<string, _AssetRef>;
52
54
  getChainStateMap(): Record<string, _ChainState>;
53
55
  getChainStateByKey(key: string): _ChainState;
56
+ getChainStatusMap(): Record<string, _ChainApiStatus>;
57
+ getChainStatusByKey(key: string): _ChainApiStatus;
54
58
  getActiveChains(): string[];
55
59
  getSupportedSmartContractTypes(): _AssetType[];
56
60
  getActiveChainInfoMap(): Record<string, _ChainInfo>;
@@ -66,7 +70,8 @@ export declare class ChainService {
66
70
  forceRemoveChain(slug: string): boolean;
67
71
  removeCustomChain(slug: string): boolean;
68
72
  resetChainInfoMap(excludedChains?: string[]): boolean;
69
- setChainConnectionStatus(slug: string, connectionStatus: _ChainConnectionStatus): void;
73
+ private connectionStatusQueueMap;
74
+ updateChainConnectionStatus(slug: string, connectionStatus: _ChainConnectionStatus): void;
70
75
  upsertCustomToken(token: _ChainAsset): string;
71
76
  deleteAssetsByChain(chainSlug: string): void;
72
77
  deleteCustomAssets(targetAssets: string[]): void;
@@ -109,7 +114,6 @@ export declare class ChainService {
109
114
  refreshEvmApi(slug: string): void;
110
115
  stopAllChainApis(): Promise<void>;
111
116
  resumeAllChainApis(): Promise<void>;
112
- checkAndUpdateStatusMapForChain(chainSlug: string): void;
113
117
  initAssetSettings(): Promise<void>;
114
118
  setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
115
119
  setMantaZkAssetSettings(visible: boolean): void;
@@ -31,6 +31,7 @@ export class ChainService {
31
31
  // TODO: consider BehaviorSubject
32
32
  chainInfoMapSubject = new Subject();
33
33
  chainStateMapSubject = new Subject();
34
+ chainStatusMapSubject = new BehaviorSubject({});
34
35
  assetRegistrySubject = new Subject();
35
36
  multiChainAssetMapSubject = new Subject();
36
37
  xcmRefMapSubject = new Subject();
@@ -44,7 +45,7 @@ export class ChainService {
44
45
  this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
45
46
  this.chainStateMapSubject.next(this.dataMap.chainStateMap);
46
47
  this.assetRegistrySubject.next(this.dataMap.assetRegistry);
47
- this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
48
+ this.xcmRefMapSubject.next(this.xcmRefMap);
48
49
  if (MODULE_SUPPORT.MANTA_ZK) {
49
50
  console.log('Init Manta ZK');
50
51
  this.mantaChainHandler = new MantaPrivateHandler(dbService);
@@ -55,19 +56,15 @@ export class ChainService {
55
56
  }
56
57
 
57
58
  // Getter
58
- getXcmRefMap() {
59
- return this.dataMap.assetRefMap;
60
- // const result: Record<string, _AssetRef> = {};
61
- //
62
- // Object.entries(AssetRefMap).forEach(([key, assetRef]) => {
63
- // if (assetRef.path === _AssetRefPath.XCM) {
64
- // result[key] = assetRef;
65
- // }
66
- // });
67
- //
68
- // return result;
59
+ get xcmRefMap() {
60
+ const result = {};
61
+ Object.entries(AssetRefMap).forEach(([key, assetRef]) => {
62
+ if (assetRef.path === _AssetRefPath.XCM) {
63
+ result[key] = assetRef;
64
+ }
65
+ });
66
+ return result;
69
67
  }
70
-
71
68
  getEvmApi(slug) {
72
69
  return this.evmChainHandler.getEvmApiByChain(slug);
73
70
  }
@@ -104,6 +101,9 @@ export class ChainService {
104
101
  subscribeChainStateMap() {
105
102
  return this.chainStateMapSubject;
106
103
  }
104
+ subscribeChainStatusMap() {
105
+ return this.chainStatusMapSubject;
106
+ }
107
107
  getAssetRegistry() {
108
108
  return this.dataMap.assetRegistry;
109
109
  }
@@ -181,6 +181,12 @@ export class ChainService {
181
181
  getChainStateByKey(key) {
182
182
  return this.dataMap.chainStateMap[key];
183
183
  }
184
+ getChainStatusMap() {
185
+ return this.chainStatusMapSubject.getValue();
186
+ }
187
+ getChainStatusByKey(key) {
188
+ return this.getChainStatusMap()[key];
189
+ }
184
190
  getActiveChains() {
185
191
  return Object.entries(this.dataMap.chainStateMap).filter(([, chainState]) => _isChainEnabled(chainState)).map(([key]) => key);
186
192
  }
@@ -250,7 +256,7 @@ export class ChainService {
250
256
  if (asset.originChain === destinationChainSlug) {
251
257
  // check
252
258
  const assetRefKey = _parseAssetRefKey(originTokenSlug, asset.slug);
253
- const assetRef = this.getAssetRefMap()[assetRefKey];
259
+ const assetRef = this.xcmRefMap[assetRefKey];
254
260
  if (assetRef && assetRef.path === _AssetRefPath.XCM) {
255
261
  // there's only 1 corresponding token on 1 chain
256
262
  destinationTokenInfo = asset;
@@ -339,9 +345,31 @@ export class ChainService {
339
345
  this.lockChainInfoMap = false;
340
346
  return true;
341
347
  }
342
- setChainConnectionStatus(slug, connectionStatus) {
343
- const chainStateMap = this.getChainStateMap();
344
- chainStateMap[slug].connectionStatus = connectionStatus;
348
+ connectionStatusQueueMap = {};
349
+ updateChainConnectionStatus(slug, connectionStatus) {
350
+ this.connectionStatusQueueMap[slug] = connectionStatus;
351
+ addLazy('updateChainConnectionStatus', () => {
352
+ const chainStatusMap = this.getChainStatusMap();
353
+ let update = false;
354
+ Object.entries(this.connectionStatusQueueMap).forEach(([slug, status]) => {
355
+ if (chainStatusMap[slug]) {
356
+ if (chainStatusMap[slug].connectionStatus !== status) {
357
+ chainStatusMap[slug].connectionStatus = status;
358
+ chainStatusMap[slug].lastUpdated = Date.now();
359
+ update = true;
360
+ }
361
+ } else {
362
+ chainStatusMap[slug] = {
363
+ slug,
364
+ connectionStatus: status,
365
+ lastUpdated: Date.now()
366
+ };
367
+ update = true;
368
+ }
369
+ });
370
+ this.connectionStatusQueueMap = {};
371
+ update && this.chainStatusMapSubject.next(chainStatusMap);
372
+ });
345
373
  }
346
374
  upsertCustomToken(token) {
347
375
  if (token.slug.length === 0) {
@@ -404,7 +432,7 @@ export class ChainService {
404
432
  await this.initChains();
405
433
  this.chainInfoMapSubject.next(this.getChainInfoMap());
406
434
  this.assetRegistrySubject.next(this.getAssetRegistry());
407
- this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
435
+ this.xcmRefMapSubject.next(this.xcmRefMap);
408
436
  await this.initApis();
409
437
  await this.initAssetSettings();
410
438
  await this.initAssetRefMap();
@@ -466,17 +494,21 @@ export class ChainService {
466
494
  this.dataMap.assetRefMap = updatedAssetRefMap;
467
495
 
468
496
  // this.dbService.setAssetRef(this.dataMap.assetRefMap).catch(console.error);
469
- this.xcmRefMapSubject.next(this.dataMap.assetRefMap);
497
+ this.xcmRefMapSubject.next(this.xcmRefMap);
470
498
  this.logger.log('Finished updating latest asset ref');
471
499
  }
472
500
  handleLatestPriceId(latestPriceIds) {
501
+ let isUpdated = false;
473
502
  Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
474
- if (this.dataMap.assetRegistry[slug]) {
503
+ if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
504
+ isUpdated = true;
475
505
  this.dataMap.assetRegistry[slug].priceId = priceId;
476
506
  }
477
507
  });
478
- this.assetRegistrySubject.next(this.dataMap.assetRegistry);
479
- this.eventService.emit('asset.updateState', '');
508
+ if (isUpdated) {
509
+ this.assetRegistrySubject.next(this.dataMap.assetRegistry);
510
+ this.eventService.emit('asset.updateState', '');
511
+ }
480
512
  this.logger.log('Finished updating latest price IDs');
481
513
  }
482
514
  handleLatestData() {
@@ -486,12 +518,10 @@ export class ChainService {
486
518
  this.fetchLatestBlockedAssetRef().then(latestAssetRef => {
487
519
  this.handleLatestBlockedAssetRef(latestAssetRef);
488
520
  }).catch(console.error);
489
-
490
- // this.fetchLatestPriceIdsData().then((latestPriceIds) => {
491
- // this.handleLatestPriceId(latestPriceIds);
492
- // }).catch(console.error);
521
+ this.fetchLatestPriceIdsData().then(latestPriceIds => {
522
+ this.handleLatestPriceId(latestPriceIds);
523
+ }).catch(console.error);
493
524
  }
494
-
495
525
  async initApis() {
496
526
  const chainInfoMap = this.getChainInfoMap();
497
527
  const chainStateMap = this.getChainStateMap();
@@ -513,13 +543,8 @@ export class ChainService {
513
543
  providerName
514
544
  } = this.getChainCurrentProviderByKey(chainInfo.slug);
515
545
  const onUpdateStatus = status => {
516
- const currentStatus = this.getChainStateByKey(chainInfo.slug).connectionStatus;
517
-
518
- // Avoid unnecessary update in case disable chain
519
- if (currentStatus !== status) {
520
- this.setChainConnectionStatus(chainInfo.slug, status);
521
- this.updateChainStateMapSubscription();
522
- }
546
+ const slug = chainInfo.slug;
547
+ this.updateChainConnectionStatus(slug, status);
523
548
  };
524
549
  if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
525
550
  if (_MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug) && MODULE_SUPPORT.MANTA_ZK && this.mantaChainHandler) {
@@ -618,7 +643,7 @@ export class ChainService {
618
643
  this.lockChainInfoMap = true;
619
644
  chainStateMap[chainSlug].active = false;
620
645
  // Set disconnect state for inactive chain
621
- chainStateMap[chainSlug].connectionStatus = _ChainConnectionStatus.DISCONNECTED;
646
+ this.updateChainConnectionStatus(chainSlug, _ChainConnectionStatus.DISCONNECTED);
622
647
  this.destroyApiForChain(chainInfo);
623
648
  this.dbService.updateChainStore({
624
649
  ...chainInfo,
@@ -711,9 +736,9 @@ export class ChainService {
711
736
  this.dataMap.chainStateMap[chainInfo.slug] = {
712
737
  currentProvider: providerKey,
713
738
  slug: chainInfo.slug,
714
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
715
739
  active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
716
740
  };
741
+ this.updateChainConnectionStatus(chainInfo.slug, _ChainConnectionStatus.DISCONNECTED);
717
742
 
718
743
  // create data for storage
719
744
  newStorageData.push({
@@ -764,9 +789,9 @@ export class ChainService {
764
789
  this.dataMap.chainStateMap[storedSlug] = {
765
790
  currentProvider: selectedProvider,
766
791
  slug: storedSlug,
767
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
768
792
  active: canActive && storedChainInfo.active
769
793
  };
794
+ this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
770
795
  newStorageData.push({
771
796
  ...mergedChainInfoMap[storedSlug],
772
797
  active: canActive && storedChainInfo.active,
@@ -786,9 +811,9 @@ export class ChainService {
786
811
  this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
787
812
  currentProvider: storedChainInfo.currentProvider,
788
813
  slug: duplicatedDefaultSlug,
789
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
790
814
  active: storedChainInfo.active
791
815
  };
816
+ this.updateChainConnectionStatus(duplicatedDefaultSlug, _ChainConnectionStatus.DISCONNECTED);
792
817
  newStorageData.push({
793
818
  ...mergedChainInfoMap[duplicatedDefaultSlug],
794
819
  active: storedChainInfo.active,
@@ -813,9 +838,9 @@ export class ChainService {
813
838
  currentProvider: storedChainInfo.currentProvider,
814
839
  // TODO: review
815
840
  slug: storedSlug,
816
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
817
841
  active: storedChainInfo.active
818
842
  };
843
+ this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
819
844
  newStorageData.push({
820
845
  ...mergedChainInfoMap[storedSlug],
821
846
  active: storedChainInfo.active,
@@ -833,9 +858,9 @@ export class ChainService {
833
858
  this.dataMap.chainStateMap[slug] = {
834
859
  currentProvider: Object.keys(chainInfo.providers)[0],
835
860
  slug,
836
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
837
861
  active: _DEFAULT_ACTIVE_CHAINS.includes(slug)
838
862
  };
863
+ this.updateChainConnectionStatus(slug, _ChainConnectionStatus.DISCONNECTED);
839
864
  newStorageData.push({
840
865
  ...mergedChainInfoMap[slug],
841
866
  active: _DEFAULT_ACTIVE_CHAINS.includes(slug),
@@ -910,9 +935,7 @@ export class ChainService {
910
935
  }
911
936
  }
912
937
  updateChainStateMapSubscription() {
913
- addLazy('updateChainStateMapSubscription', () => {
914
- this.chainStateMapSubject.next(this.getChainStateMap());
915
- }, 300, 900);
938
+ this.chainStateMapSubject.next(this.getChainStateMap());
916
939
  }
917
940
  updateChainInfoMapSubscription() {
918
941
  this.chainInfoMapSubject.next(this.getChainInfoMap());
@@ -1021,10 +1044,17 @@ export class ChainService {
1021
1044
  const chainStateMap = this.getChainStateMap();
1022
1045
  chainStateMap[newChainSlug] = {
1023
1046
  active: true,
1024
- connectionStatus: _ChainConnectionStatus.DISCONNECTED,
1025
1047
  currentProvider: params.chainEditInfo.currentProvider,
1026
1048
  slug: newChainSlug
1027
1049
  };
1050
+
1051
+ // const chainStatusMap = this.getChainStatusMap();
1052
+ // const chainStatusMap[newChainSlug] = {
1053
+ // slug: newChainSlug,
1054
+ // connectionStatus: _ChainConnectionStatus.DISCONNECTED,
1055
+ // lastUpdated: Date.now()
1056
+ // };
1057
+
1028
1058
  await this.initApiForChain(chainInfo);
1029
1059
 
1030
1060
  // create a record in assetRegistry for native token and update store/subscription
@@ -1309,29 +1339,6 @@ export class ChainService {
1309
1339
  await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp()]);
1310
1340
  this.checkLatestData();
1311
1341
  }
1312
- checkAndUpdateStatusMapForChain(chainSlug) {
1313
- const substrateApiMap = this.getSubstrateApiMap();
1314
- const evmApiMap = this.getEvmApiMap();
1315
- const chainState = this.getChainStateByKey(chainSlug);
1316
- let update = false;
1317
- function updateState(current, status) {
1318
- if (current.connectionStatus !== status) {
1319
- current.connectionStatus = status;
1320
- update = true;
1321
- }
1322
- }
1323
- if (chainState.active) {
1324
- const api = substrateApiMap[chainSlug] || evmApiMap[chainSlug];
1325
- if (api) {
1326
- updateState(chainState, api.isApiConnected ? _ChainConnectionStatus.CONNECTED : _ChainConnectionStatus.DISCONNECTED);
1327
- }
1328
- } else {
1329
- updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
1330
- }
1331
- if (update) {
1332
- this.dataMap.chainStateMap[chainSlug] = chainState;
1333
- }
1334
- }
1335
1342
  async initAssetSettings() {
1336
1343
  const assetSettings = await this.getAssetSettings();
1337
1344
  const activeChainSlugs = this.getActiveChainSlugs();
@@ -22,7 +22,11 @@ export interface _ChainState {
22
22
  slug: string;
23
23
  active: boolean;
24
24
  currentProvider: string;
25
+ }
26
+ export interface _ChainApiStatus {
27
+ slug: string;
25
28
  connectionStatus: _ChainConnectionStatus;
29
+ lastUpdated: number;
26
30
  }
27
31
  export interface _SubstrateDefaultFormatBalance {
28
32
  decimals?: number[] | number;
@@ -15,6 +15,7 @@ export declare function _isTokenTransferredByEvm(tokenInfo: _ChainAsset): boolea
15
15
  export declare function _checkSmartContractSupportByChain(chainInfo: _ChainInfo, contractType: _AssetType): boolean;
16
16
  export declare function _getTokenOnChainAssetId(tokenInfo: _ChainAsset): string;
17
17
  export declare function _getTokenOnChainInfo(tokenInfo: _ChainAsset): Record<string, any>;
18
+ export declare function _isBridgedToken(tokenInfo: _ChainAsset): boolean;
18
19
  export declare function _getTokenMinAmount(tokenInfo: _ChainAsset): string;
19
20
  export declare function _isChainEvmCompatible(chainInfo: _ChainInfo): boolean;
20
21
  export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
@@ -88,6 +88,10 @@ export function _getTokenOnChainInfo(tokenInfo) {
88
88
  var _tokenInfo$metadata4;
89
89
  return (_tokenInfo$metadata4 = tokenInfo.metadata) === null || _tokenInfo$metadata4 === void 0 ? void 0 : _tokenInfo$metadata4.onChainInfo;
90
90
  }
91
+ export function _isBridgedToken(tokenInfo) {
92
+ var _tokenInfo$metadata5;
93
+ return (_tokenInfo$metadata5 = tokenInfo.metadata) === null || _tokenInfo$metadata5 === void 0 ? void 0 : _tokenInfo$metadata5.isBridged;
94
+ }
91
95
  export function _getTokenMinAmount(tokenInfo) {
92
96
  return tokenInfo.minAmount || '0';
93
97
  }
@@ -240,16 +244,16 @@ export function _isXcmPathSupported(originTokenSlug, destinationTokenSlug, asset
240
244
  return assetRef.path === _AssetRefPath.XCM;
241
245
  }
242
246
  export function _getXcmAssetType(tokenInfo) {
243
- var _tokenInfo$metadata5;
244
- return ((_tokenInfo$metadata5 = tokenInfo.metadata) === null || _tokenInfo$metadata5 === void 0 ? void 0 : _tokenInfo$metadata5.assetType) || '';
247
+ var _tokenInfo$metadata6;
248
+ return ((_tokenInfo$metadata6 = tokenInfo.metadata) === null || _tokenInfo$metadata6 === void 0 ? void 0 : _tokenInfo$metadata6.assetType) || '';
245
249
  }
246
250
  export function _getXcmAssetId(tokenInfo) {
247
- var _tokenInfo$metadata6;
248
- return ((_tokenInfo$metadata6 = tokenInfo.metadata) === null || _tokenInfo$metadata6 === void 0 ? void 0 : _tokenInfo$metadata6.assetId) || '-1';
251
+ var _tokenInfo$metadata7;
252
+ return ((_tokenInfo$metadata7 = tokenInfo.metadata) === null || _tokenInfo$metadata7 === void 0 ? void 0 : _tokenInfo$metadata7.assetId) || '-1';
249
253
  }
250
254
  export function _getXcmAssetMultilocation(tokenInfo) {
251
- var _tokenInfo$metadata7;
252
- return (_tokenInfo$metadata7 = tokenInfo.metadata) === null || _tokenInfo$metadata7 === void 0 ? void 0 : _tokenInfo$metadata7.multilocation;
255
+ var _tokenInfo$metadata8;
256
+ return (_tokenInfo$metadata8 = tokenInfo.metadata) === null || _tokenInfo$metadata8 === void 0 ? void 0 : _tokenInfo$metadata8.multilocation;
253
257
  }
254
258
  export function _getXcmTransferType(originChainInfo, destinationChainInfo) {
255
259
  var _originChainInfo$subs, _destinationChainInfo;
@@ -11,5 +11,8 @@ export declare const _STAKING_CHAIN_GROUP: {
11
11
  liquidStaking: string[];
12
12
  lending: string[];
13
13
  krest_network: string[];
14
+ manta: string[];
14
15
  };
15
16
  export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
17
+ export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
18
+ export declare const MANTA_MIN_DELEGATION = 500;
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export const _STAKING_CHAIN_GROUP = {
5
- relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
5
+ relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
6
6
  para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network'],
7
7
  astar: ['astar', 'shiden', 'shibuya'],
8
8
  amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
@@ -12,11 +12,14 @@ export const _STAKING_CHAIN_GROUP = {
12
12
  bifrost: ['bifrost', 'bifrost_testnet'],
13
13
  aleph: ['aleph', 'alephTest'],
14
14
  // A0 has distinct tokenomics
15
- ternoa: ['ternoa', 'ternoa_alphanet'],
15
+ ternoa: ['ternoa'],
16
16
  liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
17
17
  lending: ['interlay'],
18
- krest_network: ['krest_network']
18
+ krest_network: ['krest_network'],
19
+ manta: ['manta_network']
19
20
  };
20
21
 
21
22
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
22
- export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
23
+ export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
24
+ export const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
25
+ export const MANTA_MIN_DELEGATION = 500;
@@ -23,7 +23,8 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
23
23
  defaultUnstake: true,
24
24
  fastUnstake: true,
25
25
  cancelUnstake: false,
26
- withdraw: true,
26
+ withdraw: false,
27
+ // TODO: Change after verify unstake info
27
28
  claimReward: false
28
29
  };
29
30
  constructor(state, chain) {
@@ -112,6 +113,7 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
112
113
  }
113
114
  const balances = _balances;
114
115
  const redeemRequests = await substrateApi.api.query.homa.redeemRequests.multi(useAddresses);
116
+ // This rate is multiple with decimals
115
117
  const exchangeRate = await this.getExchangeRate();
116
118
  const decimals = BN_TEN.pow(new BN(this.rateDecimals));
117
119
  for (let i = 0; i < balances.length; i++) {
@@ -123,14 +125,17 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
123
125
  const unstakings = [];
124
126
  const redeemRequest = redeemRequests[i].toPrimitive();
125
127
  if (redeemRequest) {
128
+ // If withdrawable = false, redeem request is claimed
126
129
  const [redeemAmount, withdrawable] = redeemRequest;
127
- const amount = new BN(redeemAmount);
130
+
131
+ // Redeem amount in derivative token
132
+ const amount = new BN(redeemAmount).mul(new BN(exchangeRate)).div(decimals);
128
133
  totalBalance = totalBalance.add(amount);
129
134
  unlockingBalance = unlockingBalance.add(amount);
130
135
  unstakings.push({
131
136
  chain: this.chain,
132
137
  status: withdrawable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
133
- claimable: redeemAmount.toString()
138
+ claimable: amount.toString()
134
139
  });
135
140
  }
136
141
  const result = {
@@ -203,6 +208,7 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
203
208
  async handleYieldRedeem(amount, address, selectedTarget) {
204
209
  const substrateApi = await this.substrateApi.isReady;
205
210
  const weightedMinAmount = await this.createParamToRedeem(amount, address);
211
+ // const extrinsic = substrateApi.api.tx.stableAsset.swap(0, 1, 0, amount, weightedMinAmount);
206
212
  const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
207
213
  // Swap path
208
214
  [{
@@ -76,6 +76,8 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
76
76
  const assetInfo = this.state.getAssetBySlug(this.inputAsset);
77
77
  const assetDecimals = 10 ** _getAssetDecimals(assetInfo);
78
78
  const rate = parseFloat(exchangeRate.data.slp_polkadot_ratio[0].ratio);
79
+
80
+ /** Special for bifrost, the rate is divined and unknown decimals to convert (asset decimal is 10 but the rate length is 18) */
79
81
  this.updateExchangeRate(rate);
80
82
  return {
81
83
  ...this.baseInfo,
@@ -128,7 +130,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
128
130
  const [_unlockLedgerList, _currentRelayEra, rate] = await Promise.all([substrateApi.api.query.vtokenMinting.userUnlockLedger.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(inputTokenInfo)])), substrateApi.api.query.vtokenMinting.ongoingTimeUnit(_getTokenOnChainInfo(inputTokenInfo)), this.getExchangeRate()]);
129
131
  const exchangeRate = new BigNumber(rate);
130
132
  const currentRelayEraObj = _currentRelayEra.toPrimitive();
131
- const currentRelayEra = currentRelayEraObj.Era;
133
+ const currentRelayEra = currentRelayEraObj.era;
132
134
  const unlockLedgerList = [];
133
135
  const activeBalanceMap = {};
134
136
  for (let i = 0; i < balances.length; i++) {
@@ -188,15 +190,20 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
188
190
  const isClaimable = unlocking.era - currentRelayEra < 0;
189
191
  const remainingEra = unlocking.era - currentRelayEra;
190
192
  const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[this.chain];
193
+ // const currentTimestampMs = Date.now();
194
+ // const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
195
+
191
196
  unlockBalance = unlockBalance.add(new BN(unlocking.balance));
192
197
  unstakingList.push({
193
198
  chain: this.chain,
194
199
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
195
200
  claimable: unlocking.balance,
196
201
  waitingTime: waitingTime
202
+ // targetTimestampMs: targetTimestampMs
197
203
  });
198
204
  });
199
205
  }
206
+
200
207
  const activeToTotalBalance = exchangeRate.multipliedBy(bnActiveBalance.toString());
201
208
  const totalBalance = activeToTotalBalance.plus(unlockBalance.toString());
202
209
  const result = {
@@ -11,7 +11,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
11
11
  protected readonly inputAsset: string;
12
12
  protected readonly rewardAssets: string[];
13
13
  protected readonly feeAssets: string[];
14
- readonly minAmountPercent = 0.97;
14
+ readonly minAmountPercent = 0.96;
15
15
  protected readonly rateDecimals = 18;
16
16
  protected readonly availableMethod: YieldPoolMethodInfo;
17
17
  constructor(state: KoniState, chain: string);
@@ -14,7 +14,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
14
14
  inputAsset = 'parallel-LOCAL-DOT';
15
15
  rewardAssets = ['parallel-LOCAL-DOT'];
16
16
  feeAssets = ['parallel-NATIVE-PARA'];
17
- minAmountPercent = 0.97;
17
+ minAmountPercent = 0.96;
18
18
  rateDecimals = 18;
19
19
  availableMethod = {
20
20
  join: true,
@@ -126,6 +126,9 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
126
126
  const remainingEra = chunk.era - currentEra;
127
127
  const eraTime = _STAKING_ERA_LENGTH_MAP[this.chain] || _STAKING_ERA_LENGTH_MAP.default;
128
128
  const waitingTime = remainingEra * eraTime;
129
+ // const currentTimestampMs = Date.now();
130
+ // const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
131
+
129
132
  totalBalance = totalBalance.add(amount);
130
133
  unlockingBalance = unlockingBalance.add(amount);
131
134
  unstakings.push({
@@ -133,9 +136,11 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
133
136
  status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
134
137
  claimable: amount.toString(),
135
138
  waitingTime: waitingTime
139
+ // targetTimestampMs: targetTimestampMs
136
140
  });
137
141
  }
138
142
  }
143
+
139
144
  const result = {
140
145
  ...this.baseInfo,
141
146
  type: this.type,