@subwallet/extension-base 1.3.7-0 → 1.3.9-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 (109) hide show
  1. package/background/KoniTypes.d.ts +11 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/core/logic-validation/transfer.js +35 -24
  5. package/cjs/core/substrate/system-pallet.js +1 -1
  6. package/cjs/core/substrate/xcm-parser.js +16 -2
  7. package/cjs/core/utils.js +2 -2
  8. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  9. package/cjs/koni/background/handlers/Extension.js +158 -86
  10. package/cjs/koni/background/handlers/State.js +11 -2
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/services/balance-service/index.js +24 -2
  13. package/cjs/services/balance-service/transfer/smart-contract.js +16 -5
  14. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  15. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  16. package/cjs/services/chain-online-service/constants.js +32 -0
  17. package/cjs/services/chain-online-service/index.js +190 -0
  18. package/cjs/services/chain-service/constants.js +3 -1
  19. package/cjs/services/chain-service/index.js +87 -127
  20. package/cjs/services/chain-service/utils/index.js +0 -2
  21. package/cjs/services/chain-service/utils/patch.js +7 -3
  22. package/cjs/services/fee-service/utils/index.js +14 -0
  23. package/cjs/services/inapp-notification-service/consts.js +6 -4
  24. package/cjs/services/inapp-notification-service/index.js +110 -6
  25. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  26. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  27. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  28. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  29. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  30. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  31. package/cjs/services/migration-service/scripts/index.js +3 -1
  32. package/cjs/services/setting-service/SettingService.js +8 -0
  33. package/cjs/services/setting-service/constants.js +2 -1
  34. package/cjs/services/storage-service/DatabaseService.js +3 -0
  35. package/cjs/services/transaction-service/index.js +1 -1
  36. package/cjs/stores/ChainlistStore.js +18 -0
  37. package/cjs/types/index.js +11 -0
  38. package/cjs/types/transaction/error.js +1 -0
  39. package/cjs/utils/account/transform.js +1 -1
  40. package/core/logic-validation/transfer.d.ts +2 -1
  41. package/core/logic-validation/transfer.js +36 -25
  42. package/core/substrate/system-pallet.js +1 -1
  43. package/core/substrate/xcm-parser.d.ts +1 -0
  44. package/core/substrate/xcm-parser.js +15 -2
  45. package/core/types.d.ts +1 -0
  46. package/core/utils.js +2 -2
  47. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  48. package/koni/api/contract-handler/utils/index.js +12 -0
  49. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  50. package/koni/background/handlers/Extension.d.ts +4 -0
  51. package/koni/background/handlers/Extension.js +93 -22
  52. package/koni/background/handlers/State.d.ts +2 -0
  53. package/koni/background/handlers/State.js +11 -2
  54. package/package.json +56 -14
  55. package/packageInfo.js +1 -1
  56. package/services/balance-service/index.d.ts +3 -0
  57. package/services/balance-service/index.js +21 -2
  58. package/services/balance-service/transfer/smart-contract.js +16 -5
  59. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  60. package/services/balance-service/transfer/xcm/index.js +29 -1
  61. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  62. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  63. package/services/chain-online-service/constants.d.ts +4 -0
  64. package/services/chain-online-service/constants.js +23 -0
  65. package/services/chain-online-service/index.d.ts +22 -0
  66. package/services/chain-online-service/index.js +182 -0
  67. package/services/chain-service/constants.d.ts +1 -0
  68. package/services/chain-service/constants.js +1 -0
  69. package/services/chain-service/index.d.ts +6 -7
  70. package/services/chain-service/index.js +78 -116
  71. package/services/chain-service/utils/index.js +0 -2
  72. package/services/chain-service/utils/patch.d.ts +16 -1
  73. package/services/chain-service/utils/patch.js +7 -3
  74. package/services/fee-service/utils/index.js +14 -0
  75. package/services/inapp-notification-service/consts.d.ts +3 -1
  76. package/services/inapp-notification-service/consts.js +6 -4
  77. package/services/inapp-notification-service/index.d.ts +10 -2
  78. package/services/inapp-notification-service/index.js +111 -7
  79. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  80. package/services/inapp-notification-service/interfaces.js +7 -0
  81. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  82. package/services/inapp-notification-service/utils/avail.js +73 -0
  83. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  84. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  85. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  86. package/services/inapp-notification-service/utils/index.js +6 -0
  87. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  88. package/services/inapp-notification-service/utils/polygon.js +54 -0
  89. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  90. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  91. package/services/migration-service/scripts/index.js +3 -1
  92. package/services/setting-service/SettingService.d.ts +4 -0
  93. package/services/setting-service/SettingService.js +8 -0
  94. package/services/setting-service/constants.js +2 -1
  95. package/services/storage-service/DatabaseService.d.ts +1 -0
  96. package/services/storage-service/DatabaseService.js +3 -0
  97. package/services/transaction-service/index.js +1 -1
  98. package/stores/ChainlistStore.d.ts +7 -0
  99. package/stores/ChainlistStore.js +10 -0
  100. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  101. package/types/index.d.ts +1 -0
  102. package/types/index.js +1 -0
  103. package/types/notification/index.d.ts +5 -0
  104. package/types/transaction/error.d.ts +2 -1
  105. package/types/transaction/error.js +1 -0
  106. package/utils/account/transform.js +1 -1
  107. package/services/inapp-notification-service/utils.d.ts +0 -55
  108. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  109. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -0,0 +1,22 @@
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
3
+ import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
4
+ import { TransactionConfig } from 'web3-core';
5
+ export interface gasStation {
6
+ safeLow: number;
7
+ standard: number;
8
+ fastLow: number;
9
+ }
10
+ export declare const POLYGON_PROOF_INDEXER: {
11
+ MAINNET: string;
12
+ TESTNET: string;
13
+ };
14
+ export declare const POLYGON_GAS_INDEXER: {
15
+ MAINNET: string;
16
+ TESTNET: string;
17
+ };
18
+ export declare function _createPolygonBridgeL1toL2Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
19
+ export declare function _createPolygonBridgeL2toL1Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
20
+ export declare function getClaimPolygonBridge(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi): Promise<TransactionConfig>;
21
+ export declare function isClaimedPolygonBridge(chainSlug: string, counter: number, sourceNetwork: number, evmApi: _EvmApi): Promise<any>;
22
+ export declare function _isPolygonChainBridge(srcChain: string, destChain: string): boolean;
@@ -0,0 +1,95 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
+ import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
6
+ import { _POLYGON_BRIDGE_ABI, getPolygonBridgeContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
7
+ import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
9
+ export const POLYGON_PROOF_INDEXER = {
10
+ MAINNET: 'https://api-gateway.polygon.technology/api/v3/proof/mainnet/merkle-proof',
11
+ TESTNET: 'https://api-gateway.polygon.technology/api/v3/proof/testnet/merkle-proof'
12
+ };
13
+ export const POLYGON_GAS_INDEXER = {
14
+ MAINNET: 'https://gasstation.polygon.technology/zkevm',
15
+ TESTNET: 'https://gasstation.polygon.technology/zkevm/cardona'
16
+ };
17
+ async function createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, destinationNetwork, evmApi) {
18
+ var _priority$maxFeePerGa, _priority$maxPriority;
19
+ const polygonBridgeContractAddress = getPolygonBridgeContract(originChainInfo.slug);
20
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
21
+ const tokenContract = _getContractAddressOfToken(tokenInfo) || '0x0000000000000000000000000000000000000000'; // FOR Ethereum: use null address
22
+
23
+ if (tokenContract !== '0x0000000000000000000000000000000000000000') {
24
+ throw new Error('Only native token transfer is supported');
25
+ }
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
28
+ const transferCall = polygonBridgeContract.methods.bridgeAsset(destinationNetwork, recipientAddress, value, tokenContract, true, '0x');
29
+ const transferEncodedCall = transferCall.encodeABI();
30
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
31
+ const transactionConfig = {
32
+ from: sender,
33
+ to: polygonBridgeContractAddress,
34
+ value: value,
35
+ data: transferEncodedCall,
36
+ gasPrice: priority.gasPrice,
37
+ maxFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
38
+ maxPriorityFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
39
+ };
40
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
41
+ transactionConfig.gas = gasLimit.toString();
42
+ return transactionConfig;
43
+ }
44
+ export async function _createPolygonBridgeL1toL2Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
45
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 1, evmApi);
46
+ }
47
+ export async function _createPolygonBridgeL2toL1Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
48
+ return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 0, evmApi);
49
+ }
50
+ export async function getClaimPolygonBridge(chainSlug, notification, evmApi) {
51
+ var _priority$maxFeePerGa2, _priority$maxPriority2;
52
+ const polygonBridgeContractAddress = getPolygonBridgeContract(chainSlug);
53
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
54
+ const metadata = notification.metadata;
55
+ const isTestnet = chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
56
+ const proofDomain = isTestnet ? POLYGON_PROOF_INDEXER.TESTNET : POLYGON_PROOF_INDEXER.MAINNET;
57
+ const proofResponse = await fetch(`${proofDomain}?networkId=${metadata.sourceNetwork}&depositCount=${metadata.counter}`).then(res => res.json());
58
+ const proof = proofResponse.proof;
59
+
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
61
+ const transferCall = polygonBridgeContract.methods.claimAsset(proof.merkle_proof, proof.rollup_merkle_proof, metadata.counter, proof.main_exit_root, proof.rollup_exit_root, metadata.originTokenNetwork, metadata.originTokenAddress, metadata.destinationNetwork, metadata.receiver, metadata.amounts[0], '0x');
62
+ const transferEncodedCall = transferCall.encodeABI();
63
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
64
+ const transactionConfig = {
65
+ from: metadata.userAddress,
66
+ to: polygonBridgeContractAddress,
67
+ value: '0',
68
+ data: transferEncodedCall,
69
+ gasPrice: priority.gasPrice,
70
+ maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
71
+ maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
72
+ };
73
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
74
+ transactionConfig.gas = gasLimit.toString();
75
+ return transactionConfig;
76
+ }
77
+ export async function isClaimedPolygonBridge(chainSlug, counter, sourceNetwork, evmApi) {
78
+ const polygonBridgeContractAddress = getPolygonBridgeContract(chainSlug);
79
+ const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
80
+
81
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-member-access
82
+ return await polygonBridgeContract.methods.isClaimed(counter, sourceNetwork).call();
83
+ }
84
+ export function _isPolygonChainBridge(srcChain, destChain) {
85
+ if (srcChain === 'polygonzkEvm_cardona' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
86
+ return true;
87
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA && destChain === 'polygonzkEvm_cardona') {
88
+ return true;
89
+ } else if (srcChain === 'polygonZkEvm' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM) {
90
+ return true;
91
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM && destChain === 'polygonZkEvm') {
92
+ return true;
93
+ }
94
+ return false;
95
+ }
@@ -0,0 +1,4 @@
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ export declare const LATEST_CHAIN_PATCH_FETCHING_INTERVAL = 180000;
3
+ export declare function md5HashChainInfo(data: _ChainInfo): string;
4
+ export declare function md5HashChainAsset(data: _ChainAsset): string;
@@ -0,0 +1,23 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Md5 } from 'ts-md5';
5
+ export const LATEST_CHAIN_PATCH_FETCHING_INTERVAL = 180000;
6
+ export function md5HashChainInfo(data) {
7
+ // todo: use from chain list package later
8
+ const {
9
+ chainStatus,
10
+ icon,
11
+ providers,
12
+ ...chainBaseInfo
13
+ } = data;
14
+ return Md5.hashStr(JSON.stringify(chainBaseInfo));
15
+ }
16
+ export function md5HashChainAsset(data) {
17
+ // todo: use from chain list package later
18
+ const {
19
+ icon,
20
+ ...assetBaseInfo
21
+ } = data;
22
+ return Md5.hashStr(JSON.stringify(assetBaseInfo));
23
+ }
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
3
+ import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
+ import { PatchInfo } from '@subwallet/extension-base/services/chain-service/utils';
5
+ import { EventService } from '@subwallet/extension-base/services/event-service';
6
+ import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
7
+ import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
8
+ export declare class ChainOnlineService {
9
+ private chainService;
10
+ private settingService;
11
+ private eventService;
12
+ private dbService;
13
+ private firstApplied;
14
+ refreshLatestChainDataTimeOut: NodeJS.Timer | undefined;
15
+ constructor(chainService: ChainService, settingService: SettingService, eventService: EventService, dbService: DatabaseService);
16
+ validatePatchWithHash(latestPatch: PatchInfo): boolean;
17
+ validatePatchBeforeStore(candidateChainInfoMap: Record<string, _ChainInfo>, candidateAssetRegistry: Record<string, _ChainAsset>, latestPatch: PatchInfo): boolean;
18
+ handleLatestPatch(latestPatch: PatchInfo): Promise<void>;
19
+ private fetchLatestPatchData;
20
+ handleLatestPatchData(): void;
21
+ checkLatestData(): void;
22
+ }
@@ -0,0 +1,182 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AssetLogoMap, ChainLogoMap } from '@subwallet/chain-list';
5
+ import { LATEST_CHAIN_PATCH_FETCHING_INTERVAL, md5HashChainAsset, md5HashChainInfo } from '@subwallet/extension-base/services/chain-online-service/constants';
6
+ import { filterAssetInfoMap } from '@subwallet/extension-base/services/chain-service';
7
+ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
8
+ import { fetchPatchData, randomizeProvider } from '@subwallet/extension-base/services/chain-service/utils';
9
+ export class ChainOnlineService {
10
+ constructor(chainService, settingService, eventService, dbService) {
11
+ this.chainService = chainService;
12
+ this.settingService = settingService;
13
+ this.eventService = eventService;
14
+ this.dbService = dbService;
15
+ this.firstApplied = false;
16
+ }
17
+ validatePatchWithHash(latestPatch) {
18
+ const {
19
+ ChainAsset,
20
+ ChainAssetHashMap,
21
+ ChainInfo,
22
+ ChainInfoHashMap
23
+ } = latestPatch;
24
+ for (const [chainSlug, chain] of Object.entries(ChainInfo)) {
25
+ if (md5HashChainInfo(chain) !== ChainInfoHashMap[chainSlug]) {
26
+ return false;
27
+ }
28
+ }
29
+ for (const [assetSlug, asset] of Object.entries(ChainAsset)) {
30
+ if (md5HashChainAsset(asset) !== ChainAssetHashMap[assetSlug]) {
31
+ return false;
32
+ }
33
+ }
34
+ return true;
35
+ }
36
+ validatePatchBeforeStore(candidateChainInfoMap, candidateAssetRegistry, latestPatch) {
37
+ for (const [chainSlug, chainHash] of Object.entries(latestPatch.ChainInfoHashMap)) {
38
+ if (md5HashChainInfo(candidateChainInfoMap[chainSlug]) !== chainHash) {
39
+ return false;
40
+ }
41
+ }
42
+ for (const [assetSlug, assetHash] of Object.entries(latestPatch.ChainAssetHashMap)) {
43
+ if (!candidateAssetRegistry[assetSlug]) {
44
+ if (!latestPatch.ChainInfo[assetSlug]) {
45
+ // assets are not existed in case chain is removed
46
+ continue;
47
+ }
48
+ return false;
49
+ }
50
+ if (md5HashChainAsset(candidateAssetRegistry[assetSlug]) !== assetHash) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ async handleLatestPatch(latestPatch) {
57
+ try {
58
+ var _await$this$settingSe;
59
+ // 1. validate fetch data with its hash
60
+ const isSafePatch = this.validatePatchWithHash(latestPatch);
61
+ const {
62
+ AssetLogoMap: latestAssetLogoMap,
63
+ ChainAsset: latestAssetInfo,
64
+ ChainInfo: latestChainInfo,
65
+ ChainLogoMap: latestChainLogoMap,
66
+ patchVersion: latestPatchVersion
67
+ } = latestPatch;
68
+ const currentPatchVersion = ((_await$this$settingSe = await this.settingService.getChainlistSetting()) === null || _await$this$settingSe === void 0 ? void 0 : _await$this$settingSe.patchVersion) || '';
69
+ const oldChainInfoMap = structuredClone(this.chainService.getChainInfoMap());
70
+ const oldAssetRegistry = structuredClone(this.chainService.getAssetRegistry());
71
+ let chainInfoMap = structuredClone(this.chainService.getChainInfoMap());
72
+ let assetRegistry = structuredClone(this.chainService.getAssetRegistry());
73
+ const currentChainStateMap = structuredClone(this.chainService.getChainStateMap());
74
+ const currentChainStatusMap = structuredClone(this.chainService.getChainStatusMap());
75
+ let addedChain = [];
76
+ if (isSafePatch && (!this.firstApplied || currentPatchVersion !== latestPatchVersion)) {
77
+ this.firstApplied = true;
78
+
79
+ // 2. merge data map
80
+ if (latestChainInfo && Object.keys(latestChainInfo).length > 0) {
81
+ chainInfoMap = Object.assign({}, oldChainInfoMap, latestChainInfo);
82
+ const [currentChainStateKey, newChainKey] = [Object.keys(currentChainStateMap), Object.keys(chainInfoMap)];
83
+ addedChain = newChainKey.filter(chain => !currentChainStateKey.includes(chain));
84
+ addedChain.forEach(key => {
85
+ currentChainStateMap[key] = {
86
+ active: false,
87
+ currentProvider: randomizeProvider(chainInfoMap[key].providers).providerKey,
88
+ manualTurnOff: false,
89
+ slug: key
90
+ };
91
+ currentChainStatusMap[key] = {
92
+ slug: key,
93
+ connectionStatus: _ChainConnectionStatus.DISCONNECTED,
94
+ lastUpdated: Date.now()
95
+ };
96
+ });
97
+ }
98
+ if (latestAssetInfo && Object.keys(latestAssetInfo).length > 0) {
99
+ assetRegistry = filterAssetInfoMap(oldChainInfoMap, Object.assign({}, oldAssetRegistry, latestAssetInfo), addedChain);
100
+ }
101
+
102
+ // 3. validate data before write
103
+ const isCorrectPatch = this.validatePatchBeforeStore(chainInfoMap, assetRegistry, latestPatch);
104
+
105
+ // 4. write to subject
106
+ if (isCorrectPatch) {
107
+ this.chainService.setChainInfoMap(chainInfoMap);
108
+ this.chainService.subscribeChainInfoMap().next(chainInfoMap);
109
+ this.chainService.setAssetRegistry(assetRegistry);
110
+ this.chainService.subscribeAssetRegistry().next(assetRegistry);
111
+ this.chainService.autoEnableTokens().then(() => {
112
+ this.eventService.emit('asset.updateState', '');
113
+ }).catch(console.error);
114
+ this.chainService.setChainStateMap(currentChainStateMap);
115
+ this.chainService.subscribeChainStateMap().next(currentChainStateMap);
116
+ this.chainService.subscribeChainStatusMap().next(currentChainStatusMap);
117
+ const storedChainInfoList = Object.keys(chainInfoMap).map(chainSlug => {
118
+ return {
119
+ ...chainInfoMap[chainSlug],
120
+ ...currentChainStateMap[chainSlug]
121
+ };
122
+ });
123
+ await this.dbService.bulkUpdateChainStore(storedChainInfoList);
124
+ const addedAssets = [];
125
+
126
+ // todo: the stored asset is lack of adding new assets and edited assets of old chain, update to tracking exactly updated assets from patch online.
127
+ Object.entries(assetRegistry).forEach(([slug, asset]) => {
128
+ if (addedChain.includes(asset.originChain)) {
129
+ addedAssets.push(asset);
130
+ }
131
+ });
132
+ await this.dbService.bulkUpdateAssetsStore(addedAssets);
133
+ if (latestChainLogoMap) {
134
+ const logoMap = Object.assign({}, ChainLogoMap, latestChainLogoMap);
135
+ this.chainService.subscribeChainLogoMap().next(logoMap);
136
+ }
137
+ if (latestAssetLogoMap) {
138
+ const logoMap = Object.assign({}, AssetLogoMap, latestAssetLogoMap);
139
+ this.chainService.subscribeAssetLogoMap().next(logoMap);
140
+ }
141
+ this.settingService.setChainlist({
142
+ patchVersion: latestPatchVersion
143
+ });
144
+ }
145
+ }
146
+ } catch (e) {
147
+ console.error('Error fetching latest patch data');
148
+ }
149
+ }
150
+ async fetchLatestPatchData() {
151
+ return await fetchPatchData();
152
+ }
153
+ handleLatestPatchData() {
154
+ this.fetchLatestPatchData().then(latestPatch => {
155
+ return new Promise(resolve => {
156
+ if (latestPatch && !this.chainService.getlockChainInfoMap()) {
157
+ this.eventService.waitAssetReady.then(() => {
158
+ this.chainService.setLockChainInfoMap(true);
159
+ this.handleLatestPatch(latestPatch).then(() => this.chainService.setLockChainInfoMap(false)).catch(e => {
160
+ this.chainService.setLockChainInfoMap(false);
161
+ console.error('Error update latest patch', e);
162
+ }).finally(resolve);
163
+ }).catch(e => {
164
+ console.error('Asset fail to ready', e);
165
+ resolve();
166
+ });
167
+ } else {
168
+ resolve();
169
+ }
170
+ });
171
+ }).catch(e => {
172
+ console.error('Error get latest patch or data map is locking', e);
173
+ }).finally(() => {
174
+ this.eventService.emit('asset.online.ready', true);
175
+ });
176
+ }
177
+ checkLatestData() {
178
+ clearInterval(this.refreshLatestChainDataTimeOut);
179
+ this.handleLatestPatchData();
180
+ this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestPatchData.bind(this), LATEST_CHAIN_PATCH_FETCHING_INTERVAL);
181
+ }
182
+ }
@@ -82,6 +82,7 @@ export declare const _XCM_CHAIN_GROUP: {
82
82
  polkadotXcmSpecialCases: string[];
83
83
  xcmPallet: string[];
84
84
  };
85
+ export declare const SUFFICIENT_CHAIN: string[];
85
86
  export declare const _XCM_TYPE: {
86
87
  RP: string;
87
88
  PP: string;
@@ -270,6 +270,7 @@ export const _XCM_CHAIN_GROUP = {
270
270
  // default is xTokens pallet
271
271
  };
272
272
 
273
+ export const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'];
273
274
  export const _XCM_TYPE = {
274
275
  RP: `${_SubstrateChainType.RELAYCHAIN}-${_SubstrateChainType.PARACHAIN}`,
275
276
  // DMP
@@ -8,6 +8,7 @@ import { IMetadataItem } from '@subwallet/extension-base/services/storage-servic
8
8
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
9
9
  import { BehaviorSubject, Subject } from 'rxjs';
10
10
  import { ExtraInfo } from '@polkadot-api/merkleize-metadata';
11
+ export declare const filterAssetInfoMap: (chainInfo: Record<string, _ChainInfo>, assets: Record<string, _ChainAsset>, addedChains?: string[]) => Record<string, _ChainAsset>;
11
12
  export declare class ChainService {
12
13
  private dataMap;
13
14
  private dbService;
@@ -29,8 +30,6 @@ export declare class ChainService {
29
30
  private assetLogoMapSubject;
30
31
  private chainLogoMapSubject;
31
32
  private ledgerGenericAllowChainsSubject;
32
- private assetMapPatch;
33
- private assetLogoPatch;
34
33
  private store;
35
34
  private assetSettingSubject;
36
35
  private logger;
@@ -44,6 +43,8 @@ export declare class ChainService {
44
43
  subscribeSwapRefMap(): Subject<Record<string, _AssetRef>>;
45
44
  get xcmRefMap(): Record<string, _AssetRef>;
46
45
  get swapRefMap(): Record<string, _AssetRef>;
46
+ getlockChainInfoMap(): boolean;
47
+ setLockChainInfoMap(isLock: boolean): void;
47
48
  getEvmApi(slug: string): import("./handler/EvmApi").EvmApi;
48
49
  getEvmApiMap(): Record<string, import("./handler/EvmApi").EvmApi>;
49
50
  getSubstrateApi(slug: string): _SubstrateApi;
@@ -61,16 +62,19 @@ export declare class ChainService {
61
62
  subscribeChainStateMap(): Subject<Record<string, _ChainState>>;
62
63
  subscribeChainStatusMap(): BehaviorSubject<Record<string, _ChainApiStatus>>;
63
64
  getAssetRegistry(): Record<string, _ChainAsset>;
65
+ setAssetRegistry(assetRegistry: Record<string, _ChainAsset>): void;
64
66
  getMultiChainAssetMap(): Record<string, _MultiChainAsset>;
65
67
  getSmartContractTokens(): Record<string, _ChainAsset>;
66
68
  getAssetHubToken(): Record<string, _ChainAsset>;
67
69
  getChainInfoMap(): Record<string, _ChainInfo>;
70
+ setChainInfoMap(chainInfoMap: Record<string, _ChainInfo>): void;
68
71
  getEvmChainInfoMap(): Record<string, _ChainInfo>;
69
72
  getSubstrateChainInfoMap(): Record<string, _ChainInfo>;
70
73
  getAllPriceIds(): string[];
71
74
  getNativeTokenInfo(chainSlug: string): _ChainAsset;
72
75
  getAssetRefMap(): Record<string, _AssetRef>;
73
76
  getChainStateMap(): Record<string, _ChainState>;
77
+ setChainStateMap(chainStateMap: Record<string, _ChainState>): void;
74
78
  getChainStateByKey(key: string): _ChainState;
75
79
  getChainStatusMap(): Record<string, _ChainApiStatus>;
76
80
  getChainStatusByKey(key: string): _ChainApiStatus;
@@ -99,9 +103,6 @@ export declare class ChainService {
99
103
  checkLatestData(): void;
100
104
  stopCheckLatestChainData(): void;
101
105
  handleLatestChainData(latestChainInfo: _ChainInfo[]): void;
102
- handleLatestAssetRef(latestBlockedAssetRefList: string[], latestAssetRefMap: Record<string, _AssetRef> | null): void;
103
- handleLatestPriceId(latestPriceIds: Record<string, string | null>): void;
104
- handleLatestAssetData(latestAssetInfo: Record<string, _ChainAsset> | null, latestAssetLogoMap: Record<string, string> | null): void;
105
106
  autoEnableTokens(): Promise<void>;
106
107
  handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains: string[]): void;
107
108
  handleLatestData(): void;
@@ -115,9 +116,7 @@ export declare class ChainService {
115
116
  disableChain(chainSlug: string): boolean;
116
117
  private checkExistedPredefinedChain;
117
118
  private fetchLatestChainData;
118
- private fetchLatestAssetData;
119
119
  private fetchLatestPriceIdsData;
120
- private fetchLatestAssetRef;
121
120
  private fetchLatestLedgerGenericAllowChains;
122
121
  private initChains;
123
122
  private initAssetRegistry;