@subwallet/extension-base 1.2.27-0 → 1.2.29-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 (61) hide show
  1. package/background/KoniTypes.d.ts +7 -8
  2. package/cjs/constants/index.js +6 -3
  3. package/cjs/core/logic-validation/request.js +160 -23
  4. package/cjs/core/substrate/xcm-parser.js +16 -6
  5. package/cjs/koni/api/staking/bonding/utils.js +1 -0
  6. package/cjs/koni/background/handlers/Extension.js +3 -3
  7. package/cjs/koni/background/handlers/State.js +35 -66
  8. package/cjs/koni/background/handlers/Tabs.js +96 -23
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/services/balance-service/helpers/subscribe/index.js +19 -13
  11. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
  12. package/cjs/services/balance-service/transfer/xcm/index.js +8 -13
  13. package/cjs/services/chain-service/constants.js +2 -1
  14. package/cjs/services/chain-service/index.js +1 -1
  15. package/cjs/services/earning-service/constants/chains.js +1 -3
  16. package/cjs/services/earning-service/handlers/lending/interlay.js +0 -2
  17. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
  18. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +31 -25
  19. package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -2
  20. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
  21. package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
  22. package/cjs/services/migration-service/scripts/index.js +2 -2
  23. package/cjs/services/mkt-campaign-service/index.js +30 -6
  24. package/cjs/services/request-service/handler/EvmRequestHandler.js +0 -1
  25. package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
  26. package/cjs/services/wallet-connect-service/index.js +25 -1
  27. package/constants/index.d.ts +1 -0
  28. package/constants/index.js +1 -0
  29. package/core/logic-validation/request.d.ts +22 -1
  30. package/core/logic-validation/request.js +154 -23
  31. package/core/substrate/xcm-parser.d.ts +3 -2
  32. package/core/substrate/xcm-parser.js +15 -6
  33. package/koni/api/staking/bonding/utils.js +1 -0
  34. package/koni/background/handlers/Extension.js +3 -3
  35. package/koni/background/handlers/State.d.ts +0 -1
  36. package/koni/background/handlers/State.js +19 -49
  37. package/koni/background/handlers/Tabs.d.ts +1 -0
  38. package/koni/background/handlers/Tabs.js +77 -6
  39. package/package.json +14 -12
  40. package/packageInfo.js +1 -1
  41. package/services/balance-service/helpers/subscribe/index.js +19 -13
  42. package/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
  43. package/services/balance-service/transfer/xcm/index.js +8 -13
  44. package/services/chain-service/constants.d.ts +1 -0
  45. package/services/chain-service/constants.js +2 -1
  46. package/services/chain-service/index.js +1 -1
  47. package/services/earning-service/constants/chains.d.ts +0 -1
  48. package/services/earning-service/constants/chains.js +0 -1
  49. package/services/earning-service/handlers/lending/interlay.js +0 -2
  50. package/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
  51. package/services/earning-service/handlers/native-staking/relay-chain.js +32 -26
  52. package/services/earning-service/handlers/nomination-pool/index.js +1 -2
  53. package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
  54. package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
  55. package/services/migration-service/scripts/index.js +2 -2
  56. package/services/mkt-campaign-service/index.js +30 -6
  57. package/services/mkt-campaign-service/types.d.ts +2 -0
  58. package/services/request-service/handler/EvmRequestHandler.js +0 -1
  59. package/services/swap-service/handler/hydradx-handler.js +1 -1
  60. package/services/wallet-connect-service/index.js +24 -1
  61. package/types/yield/info/chain/target.d.ts +4 -0
@@ -6,7 +6,7 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
6
6
  import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
7
7
  import { APIItemState, BasicTxErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
8
8
  import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
9
- import { generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
9
+ import { convertErrorFormat, generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
10
10
  import { BalanceService } from '@subwallet/extension-base/services/balance-service';
11
11
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
12
12
  import BuyService from '@subwallet/extension-base/services/buy-service';
@@ -35,7 +35,7 @@ import TransactionService from '@subwallet/extension-base/services/transaction-s
35
35
  import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
36
36
  import { SWStorage } from '@subwallet/extension-base/storage';
37
37
  import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
38
- import { isAccountAll, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
38
+ import { isAccountAll, isManifestV3, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
39
39
  import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
40
40
  import { decodePair } from '@subwallet/keyring/pair/decode';
41
41
  import { keyring } from '@subwallet/ui-keyring';
@@ -548,44 +548,6 @@ export default class KoniState {
548
548
  }));
549
549
  }
550
550
  }
551
- async switchNetworkAccount(id, url, networkKey, changeAddress) {
552
- const chainInfo = this.chainService.getChainInfoByKey(networkKey);
553
- const chainState = this.chainService.getChainStateByKey(networkKey);
554
- const {
555
- address,
556
- currentGenesisHash
557
- } = this.keyringService.currentAccount;
558
- return this.requestService.addConfirmation(id, url, 'switchNetworkRequest', {
559
- networkKey,
560
- address: changeAddress
561
- }, {
562
- address: changeAddress
563
- }).then(({
564
- isApproved
565
- }) => {
566
- if (isApproved) {
567
- const useAddress = changeAddress || address;
568
- if (chainInfo && !_isChainEnabled(chainState)) {
569
- this.enableChain(networkKey).catch(console.error);
570
- }
571
- if (useAddress !== ALL_ACCOUNT_KEY) {
572
- const pair = keyring.getPair(useAddress);
573
- assert(pair, t('Unable to find account'));
574
- keyring.saveAccountMeta(pair, {
575
- ...pair.meta,
576
- genesisHash: _getSubstrateGenesisHash(chainInfo)
577
- });
578
- }
579
- if (address !== changeAddress || _getSubstrateGenesisHash(chainInfo) !== currentGenesisHash || isApproved) {
580
- this.setCurrentAccount({
581
- address: useAddress,
582
- currentGenesisHash: _getSubstrateGenesisHash(chainInfo)
583
- });
584
- }
585
- }
586
- return isApproved;
587
- });
588
- }
589
551
  async addNetworkConfirm(id, url, networkData) {
590
552
  return this.requestService.addConfirmation(id, url, 'addNetworkRequest', networkData).then(async ({
591
553
  isApproved
@@ -1098,9 +1060,10 @@ export default class KoniState {
1098
1060
  };
1099
1061
  const validationSteps = [topic ? validationAuthWCMiddleware : validationAuthMiddleware, validationEvmSignMessageMiddleware];
1100
1062
  const result = await generateValidationProcess(this, url, payloadValidation, validationSteps, topic);
1063
+ const errorsFormated = convertErrorFormat(result.errors);
1101
1064
  const payloadAfterValidated = {
1102
1065
  ...result.payloadAfterValidated,
1103
- errors: result.errors,
1066
+ errors: errorsFormated,
1104
1067
  id
1105
1068
  };
1106
1069
  return this.requestService.addConfirmation(id, url, 'evmSignatureRequest', payloadAfterValidated, {}).then(({
@@ -1161,9 +1124,13 @@ export default class KoniState {
1161
1124
  errors,
1162
1125
  networkKey: networkKey_
1163
1126
  } = result;
1164
- if (errors && errors.length > 0 && confirmationType) {
1127
+ const errorsFormated = convertErrorFormat(errors);
1128
+ if (errorsFormated && errorsFormated.length > 0 && confirmationType) {
1165
1129
  if (ERROR_CONFIRMATION_TYPE.includes(confirmationType)) {
1166
- return this.requestService.addConfirmation(id, url, confirmationType, result, {}).then(() => {
1130
+ return this.requestService.addConfirmation(id, url, confirmationType, {
1131
+ ...result,
1132
+ errors: errorsFormated
1133
+ }, {}).then(() => {
1167
1134
  throw new EvmProviderError(EvmProviderErrorType.USER_REJECTED_REQUEST);
1168
1135
  });
1169
1136
  }
@@ -1172,7 +1139,7 @@ export default class KoniState {
1172
1139
  const networkKey = networkKey_ || '';
1173
1140
  const requestPayload = {
1174
1141
  ...transactionValidated,
1175
- errors: errors
1142
+ errors: errorsFormated
1176
1143
  };
1177
1144
  const eType = transactionValidated.value ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.EVM_EXECUTE;
1178
1145
  const transactionData = {
@@ -1232,14 +1199,17 @@ export default class KoniState {
1232
1199
  async onMV3Update() {
1233
1200
  const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
1234
1201
  if (!migrationStatus || migrationStatus !== 'done') {
1235
- // Open migration tab
1236
- const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1237
- await openPopup(url);
1202
+ if (isManifestV3) {
1203
+ // Open migration tab
1204
+ const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
1205
+ await openPopup(url);
1238
1206
 
1239
- // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1207
+ // migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
1208
+ } else {
1209
+ this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
1210
+ }
1240
1211
  }
1241
1212
  }
1242
-
1243
1213
  async migrateMV3LocalStorage(data) {
1244
1214
  try {
1245
1215
  const parsedData = JSON.parse(data);
@@ -34,6 +34,7 @@ export default class KoniTabs {
34
34
  private getEvmCurrentAccount;
35
35
  private getEvmState;
36
36
  private getEvmPermission;
37
+ private revokePermissions;
37
38
  private switchEvmChain;
38
39
  private addEvmToken;
39
40
  private addEvmChain;
@@ -8,7 +8,7 @@ import { createSubscription, unsubscribe } from '@subwallet/extension-base/backg
8
8
  import { EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
9
9
  import RequestBytesSign from '@subwallet/extension-base/background/RequestBytesSign';
10
10
  import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
11
- import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS } from '@subwallet/extension-base/constants';
11
+ import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS, PERMISSIONS_TO_REVOKE } from '@subwallet/extension-base/constants';
12
12
  import { generateValidationProcess, validationAuthMiddleware } from '@subwallet/extension-base/core/logic-validation';
13
13
  import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
14
14
  import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
@@ -17,7 +17,8 @@ import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/
17
17
  import { canDerive, getEVMChainInfo, stripUrl } from '@subwallet/extension-base/utils';
18
18
  import Web3 from 'web3';
19
19
  import { checkIfDenied } from '@polkadot/phishing';
20
- import { isNumber } from '@polkadot/util';
20
+ import { isArray, isNumber } from '@polkadot/util';
21
+ import { isEthereumAddress } from '@polkadot/util-crypto';
21
22
  function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthType) {
22
23
  const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
23
24
  let authTypeFilter = ({
@@ -246,8 +247,6 @@ export default class KoniTabs {
246
247
  }, id, port) {
247
248
  const cb = createSubscription(id, port);
248
249
  const authInfoSubject = this.#koniState.requestService.subscribeAuthorizeUrlSubject;
249
-
250
- // Update unsubscribe from @polkadot/extension-base
251
250
  this.#accountSubs[id] = {
252
251
  subscription: authInfoSubject.subscribe(infos => {
253
252
  this.getAuthInfo(url, infos).then(authInfo => {
@@ -258,6 +257,8 @@ export default class KoniTabs {
258
257
  }),
259
258
  url
260
259
  };
260
+
261
+ // Update unsubscribe from @polkadot/extension-base
261
262
  port.onDisconnect.addListener(() => {
262
263
  this.accountsUnsubscribe(url, {
263
264
  id
@@ -380,6 +381,74 @@ export default class KoniTabs {
380
381
  date: new Date().getTime()
381
382
  }];
382
383
  }
384
+ async revokePermissions(url, id, {
385
+ params
386
+ }) {
387
+ if (!params || !isArray(params) || params.length === 0) {
388
+ throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, 'No list of permissions found to revoke in the parameters.');
389
+ }
390
+
391
+ // Example of a request in MetaMask wallet
392
+ // await window.ethereum.request({
393
+ // "method": "wallet_revokePermissions",
394
+ // "params": [
395
+ // {
396
+ // "eth_accounts": {}
397
+ // }
398
+ // ]
399
+ // });
400
+ // Doc: https://docs.metamask.io/wallet/reference/wallet_revokepermissions/
401
+
402
+ const permissions = new Set(Object.keys(params[0]).filter(permission => PERMISSIONS_TO_REVOKE.includes(permission)));
403
+ const permissionPromise = async permission => {
404
+ if (permission === 'eth_accounts') {
405
+ return new Promise(resolve => {
406
+ this.#koniState.getAuthorize(value => {
407
+ const urlStripped = stripUrl(url);
408
+ if (value && value[urlStripped]) {
409
+ const {
410
+ accountAuthType,
411
+ isAllowedMap
412
+ } = {
413
+ ...value[urlStripped]
414
+ };
415
+ if (!accountAuthType) {
416
+ resolve();
417
+ }
418
+ switch (accountAuthType) {
419
+ case 'substrate':
420
+ resolve();
421
+ break;
422
+ case 'evm':
423
+ delete value[urlStripped];
424
+ break;
425
+ case 'both':
426
+ {
427
+ value[urlStripped].isAllowedMap = Object.entries(isAllowedMap).reduce((allowedMap, [address, value]) => {
428
+ if (isEthereumAddress(address)) {
429
+ allowedMap[address] = false;
430
+ } else {
431
+ allowedMap[address] = value;
432
+ }
433
+ return allowedMap;
434
+ }, {});
435
+ value[urlStripped].accountAuthType = 'substrate';
436
+ break;
437
+ }
438
+ }
439
+ this.#koniState.setAuthorize(value, () => {
440
+ resolve();
441
+ });
442
+ } else {
443
+ resolve();
444
+ }
445
+ });
446
+ });
447
+ }
448
+ };
449
+ await Promise.all(Array.from(permissions).map(permissionPromise));
450
+ return null;
451
+ }
383
452
  async switchEvmChain(id, url, {
384
453
  params
385
454
  }) {
@@ -831,6 +900,8 @@ export default class KoniTabs {
831
900
  return await this.getEvmPermission(url, id);
832
901
  case 'wallet_getPermissions':
833
902
  return await this.getEvmPermission(url, id);
903
+ case 'wallet_revokePermissions':
904
+ return await this.revokePermissions(url, id, request);
834
905
  case 'wallet_addEthereumChain':
835
906
  return await this.addEvmChain(id, url, request);
836
907
  case 'wallet_switchEthereumChain':
@@ -870,7 +941,7 @@ export default class KoniTabs {
870
941
  return true;
871
942
  }
872
943
  isEvmPublicRequest(type, request) {
873
- return type === 'evm(request)' && ['eth_chainId', 'net_version'].includes(request === null || request === void 0 ? void 0 : request.method);
944
+ return type === 'evm(request)' && ['eth_chainId', 'net_version', 'wallet_requestPermissions', 'wallet_getPermissions'].includes(request === null || request === void 0 ? void 0 : request.method) || type === 'evm(events.subscribe)';
874
945
  }
875
946
  async addPspToken(id, url, {
876
947
  genesisHash,
@@ -936,7 +1007,7 @@ export default class KoniTabs {
936
1007
 
937
1008
  // Wait for account ready and chain ready
938
1009
  await Promise.all([this.#koniState.eventService.waitAccountReady, this.#koniState.eventService.waitChainReady]);
939
- if (type !== 'pub(authorize.tabV2)' && !this.isEvmPublicRequest(type, request)) {
1010
+ if (!['pub(authorize.tabV2)', 'pub(accounts.subscribeV2)'].includes(type) && !this.isEvmPublicRequest(type, request)) {
940
1011
  await this.#koniState.ensureUrlAuthorizedV2(url).catch(e => {
941
1012
  if (type.startsWith('evm')) {
942
1013
  throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, e.message);
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.2.27-0",
20
+ "version": "1.2.29-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -2043,9 +2043,10 @@
2043
2043
  "@ethereumjs/common": "^4.1.0",
2044
2044
  "@ethereumjs/tx": "^5.1.0",
2045
2045
  "@ethersproject/abi": "^5.7.0",
2046
- "@galacticcouncil/sdk": "^2.1.0",
2046
+ "@galacticcouncil/sdk": "^4.2.0",
2047
2047
  "@gear-js/api": "^0.38.1",
2048
2048
  "@json-rpc-tools/utils": "^1.7.6",
2049
+ "@metamask/eth-sig-util": "^7.0.3",
2049
2050
  "@metamask/safe-event-emitter": "^2.0.0",
2050
2051
  "@metaverse-network-sdk/type-definitions": "^0.0.1-13",
2051
2052
  "@oak-foundation/types": "^0.0.23",
@@ -2069,17 +2070,17 @@
2069
2070
  "@reduxjs/toolkit": "^1.9.1",
2070
2071
  "@sora-substrate/type-definitions": "^1.17.7",
2071
2072
  "@substrate/connect": "^0.8.9",
2072
- "@subwallet/chain-list": "0.2.83",
2073
- "@subwallet/extension-base": "^1.2.27-0",
2074
- "@subwallet/extension-chains": "^1.2.27-0",
2075
- "@subwallet/extension-dapp": "^1.2.27-0",
2076
- "@subwallet/extension-inject": "^1.2.27-0",
2077
- "@subwallet/keyring": "^0.1.5",
2078
- "@subwallet/ui-keyring": "^0.1.5",
2073
+ "@subwallet/chain-list": "0.2.86",
2074
+ "@subwallet/extension-base": "^1.2.29-0",
2075
+ "@subwallet/extension-chains": "^1.2.29-0",
2076
+ "@subwallet/extension-dapp": "^1.2.29-0",
2077
+ "@subwallet/extension-inject": "^1.2.29-0",
2078
+ "@subwallet/keyring": "^0.1.6",
2079
+ "@subwallet/ui-keyring": "^0.1.6",
2079
2080
  "@walletconnect/keyvaluestorage": "^1.1.1",
2080
- "@walletconnect/sign-client": "^2.13.1",
2081
- "@walletconnect/types": "^2.13.1",
2082
- "@walletconnect/utils": "^2.13.1",
2081
+ "@walletconnect/sign-client": "^2.14.0",
2082
+ "@walletconnect/types": "^2.14.0",
2083
+ "@walletconnect/utils": "^2.14.0",
2083
2084
  "avail-js-sdk": "^0.2.12",
2084
2085
  "axios": "^1.6.2",
2085
2086
  "bignumber.js": "^9.1.1",
@@ -2097,6 +2098,7 @@
2097
2098
  "graphql": "^16.8.1",
2098
2099
  "i18next": "^21.9.2",
2099
2100
  "is-buffer": "^2.0.5",
2101
+ "joi": "^17.13.3",
2100
2102
  "json-rpc-engine": "^6.1.0",
2101
2103
  "manta-extension-sdk": "^1.1.0",
2102
2104
  "moment": "^2.29.4",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.2.27-0'
10
+ version: '1.2.29-0'
11
11
  };
@@ -70,6 +70,21 @@ const filterAddress = (addresses, chainInfo) => {
70
70
  return [fetchList, [...unfetchList, ...evmAddresses]];
71
71
  }
72
72
  };
73
+ const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap, state, callback) => {
74
+ const tokens = filterAssetsByChainAndType(chainAssetMap, chainSlug, [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.PSP22, _AssetType.LOCAL, _AssetType.GRC20, _AssetType.VFT]);
75
+ const now = new Date().getTime();
76
+ Object.values(tokens).forEach(token => {
77
+ const items = addresses.map(address => ({
78
+ address,
79
+ tokenSlug: token.slug,
80
+ free: '0',
81
+ locked: '0',
82
+ state,
83
+ timestamp: now
84
+ }));
85
+ callback(items);
86
+ });
87
+ };
73
88
 
74
89
  // main subscription, use for multiple chains, multiple addresses and multiple tokens
75
90
  export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
@@ -82,19 +97,7 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
82
97
  const chainSlug = chainInfo.slug;
83
98
  const [useAddresses, notSupportAddresses] = filterAddress(addresses, chainInfo);
84
99
  if (notSupportAddresses.length) {
85
- const tokens = filterAssetsByChainAndType(chainAssetMap, chainSlug, [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.PSP22, _AssetType.LOCAL, _AssetType.GRC20, _AssetType.VFT]);
86
- const now = new Date().getTime();
87
- Object.values(tokens).forEach(token => {
88
- const items = notSupportAddresses.map(address => ({
89
- address,
90
- tokenSlug: token.slug,
91
- free: '0',
92
- locked: '0',
93
- state: APIItemState.NOT_SUPPORT,
94
- timestamp: now
95
- }));
96
- callback(items);
97
- });
100
+ handleUnsupportedOrPendingAddresses(notSupportAddresses, chainSlug, chainAssetMap, APIItemState.NOT_SUPPORT, callback);
98
101
  }
99
102
  const evmApi = evmApiMap[chainSlug];
100
103
  if (_isPureEvmChain(chainInfo)) {
@@ -106,6 +109,9 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
106
109
  evmApi
107
110
  });
108
111
  }
112
+ if (!substrateApiMap[chainSlug].isApiReady) {
113
+ handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, APIItemState.PENDING, callback);
114
+ }
109
115
  const substrateApi = await substrateApiMap[chainSlug].isReady;
110
116
  return subscribeSubstrateBalance(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
111
117
  });
@@ -112,10 +112,9 @@ const subscribeWithSystemAccountPallet = async ({
112
112
  extrinsicType,
113
113
  substrateApi
114
114
  }) => {
115
- var _substrateApi$api$tx, _substrateApi$api$tx$;
116
115
  const systemAccountKey = 'query_system_account';
117
116
  const poolMembersKey = 'query_nominationPools_poolMembers';
118
- const isNominationPoolMigrated = !!((_substrateApi$api$tx = substrateApi.api.tx) !== null && _substrateApi$api$tx !== void 0 && (_substrateApi$api$tx$ = _substrateApi$api$tx.nominationPools) !== null && _substrateApi$api$tx$ !== void 0 && _substrateApi$api$tx$.migrateDelegation);
117
+ const isNominationPoolMigrated = await checkNominationPoolCompleteMigrated(substrateApi);
119
118
  const params = [{
120
119
  section: 'query',
121
120
  module: systemAccountKey.split('_')[1],
@@ -158,6 +157,19 @@ const subscribeWithSystemAccountPallet = async ({
158
157
  subscription.unsubscribe();
159
158
  };
160
159
  };
160
+ const checkNominationPoolCompleteMigrated = async substrateApi => {
161
+ if (!substrateApi.api.tx.nominationPools || !substrateApi.api.query.staking) {
162
+ return false;
163
+ }
164
+ const isNominationPoolMigrated = !!substrateApi.api.tx.nominationPools.migrateDelegation && !!substrateApi.api.query.staking.counterForVirtualStakers && !!substrateApi.api.query.staking.virtualStakers;
165
+ if (!isNominationPoolMigrated) {
166
+ return false;
167
+ }
168
+ const [nominationPoolCounterRaw, nominationPoolInfoRaw] = await Promise.all([substrateApi.api.query.staking.counterForVirtualStakers(), substrateApi.api.query.staking.virtualStakers.entries()]);
169
+ const nominationPoolCounter = nominationPoolCounterRaw.toPrimitive();
170
+ const nominationPoolInfoLength = nominationPoolInfoRaw.length;
171
+ return nominationPoolCounter !== 0 && nominationPoolInfoLength !== 0;
172
+ };
161
173
  const subscribeForeignAssetBalance = async ({
162
174
  addresses,
163
175
  assetMap,
@@ -39,26 +39,21 @@ export const createXcmExtrinsic = async ({
39
39
  const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
40
40
  const chainApi = await substrateApi.isReady;
41
41
  const api = chainApi.api;
42
- let extrinsic;
43
- if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain)) {
44
- if (['astar', 'shiden'].includes(originChainInfo.slug) && !_isNativeToken(originTokenInfo)) {
45
- extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
46
- } else {
47
- extrinsic = getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
48
- }
49
- } else if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
50
- extrinsic = getExtrinsicByXcmPalletPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
51
- } else {
52
- extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
42
+ const polkadotXcmSpecialCases = _XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && _isNativeToken(originTokenInfo);
43
+ if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
44
+ return getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
53
45
  }
54
- return extrinsic;
46
+ if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
47
+ return getExtrinsicByXcmPalletPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
48
+ }
49
+ return getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
55
50
  };
56
51
  export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
57
52
  try {
58
53
  var _paymentInfo$partialF;
59
54
  const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
60
55
  const originChainInfo = chainInfoMap[originTokenInfo.originChain];
61
- const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap';
56
+ const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
62
57
 
63
58
  // mock receiving account from sender
64
59
  const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(destChainInfo) && !_isChainEvmCompatible(originChainInfo) ? u8aToHex(addressToEvm(address)) : address;
@@ -76,6 +76,7 @@ export declare const _ZK_ASSET_PREFIX = "zk";
76
76
  export declare const _DEFAULT_MANTA_ZK_CHAIN = "calamari";
77
77
  export declare const _XCM_CHAIN_GROUP: {
78
78
  polkadotXcm: string[];
79
+ polkadotXcmSpecialCases: string[];
79
80
  xcmPallet: string[];
80
81
  };
81
82
  export declare const _XCM_TYPE: {
@@ -261,7 +261,8 @@ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
261
261
  // XCM------------------------------------------------------------------------------------------------------------------
262
262
 
263
263
  export const _XCM_CHAIN_GROUP = {
264
- polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
264
+ polkadotXcm: ['statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
265
+ polkadotXcmSpecialCases: ['astar', 'shiden'],
265
266
  xcmPallet: ['polkadot', 'kusama', 'rococo']
266
267
  // default is xTokens pallet
267
268
  };
@@ -18,7 +18,7 @@ import { logger as createLogger } from '@polkadot/util/logger';
18
18
  const filterChainInfoMap = (data, ignoredChains) => {
19
19
  return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
20
20
  };
21
- const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'ton', 'ton_testnet'];
21
+ const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'ton', 'ton_testnet', 'storyPartner_testnet'];
22
22
  const filterAssetInfoMap = (chainInfo, assets) => {
23
23
  return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
24
24
  };
@@ -13,7 +13,6 @@ export declare const _STAKING_CHAIN_GROUP: {
13
13
  krest_network: string[];
14
14
  manta: string[];
15
15
  };
16
- export declare const _UPDATED_RUNTIME_STAKING_GROUP: string[];
17
16
  export declare const MaxEraRewardPointsEras = 14;
18
17
  export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
19
18
  export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
@@ -18,7 +18,6 @@ export const _STAKING_CHAIN_GROUP = {
18
18
  krest_network: ['krest_network'],
19
19
  manta: ['manta_network']
20
20
  };
21
- export const _UPDATED_RUNTIME_STAKING_GROUP = ['kusama', 'polkadot', 'westend', 'availTuringTest', 'avail_mainnet', 'dentnet'];
22
21
  export const MaxEraRewardPointsEras = 14;
23
22
 
24
23
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
@@ -54,7 +54,6 @@ export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
54
54
  statistic: {
55
55
  assetEarning: [{
56
56
  slug: this.rewardAssets[0],
57
- apr: 1.29,
58
57
  exchangeRate: exchangeRate / decimals
59
58
  }],
60
59
  maxCandidatePerFarmer: 1,
@@ -64,7 +63,6 @@ export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
64
63
  defaultUnstake: '0',
65
64
  fastUnstake: '0'
66
65
  },
67
- totalApr: 1.29,
68
66
  tvl: '291890000000000'
69
67
  }
70
68
  };
@@ -39,7 +39,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
39
39
 
40
40
  async getPoolStat() {
41
41
  const substrateApi = await this.substrateApi.isReady;
42
- const [_exchangeRate, _currentBlockHeader, _currentTimestamp, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.rpc.chain.getHeader(), substrateApi.api.query.timestamp.now(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
42
+ const [_exchangeRate, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
43
43
  let tvl = BN_ZERO;
44
44
  for (const _stakingLedger of _stakingLedgers) {
45
45
  const _ledger = _stakingLedger[1];
@@ -47,16 +47,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
47
47
  tvl = tvl.add(new BN(ledger.total.toString()));
48
48
  }
49
49
  const exchangeRate = _exchangeRate.toPrimitive();
50
- const currentBlockHeader = _currentBlockHeader.toPrimitive();
51
- const currentTimestamp = _currentTimestamp.toPrimitive();
52
- const beginBlock = currentBlockHeader.number - 24 * 60 * 60 / 6 * 14;
53
- const _beginBlockHash = await substrateApi.api.rpc.chain.getBlockHash(beginBlock);
54
- const beginBlockHash = _beginBlockHash.toString();
55
- const [_beginTimestamp, _beginExchangeRate] = await Promise.all([substrateApi.api.query.timestamp.now.at(beginBlockHash), substrateApi.api.query.liquidStaking.exchangeRate.at(beginBlockHash)]);
56
- const beginTimestamp = _beginTimestamp.toPrimitive();
57
- const beginExchangeRate = _beginExchangeRate.toPrimitive();
58
50
  const decimals = 10 ** this.rateDecimals;
59
- const apy = (exchangeRate / beginExchangeRate) ** (365 * 24 * 60 * 60000 / (currentTimestamp - beginTimestamp)) - 1;
60
51
  const minStake = substrateApi.api.consts.liquidStaking.minStake.toString();
61
52
  const minUnstake = substrateApi.api.consts.liquidStaking.minUnstake.toString();
62
53
  this.updateExchangeRate(exchangeRate);
@@ -70,7 +61,6 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
70
61
  statistic: {
71
62
  assetEarning: [{
72
63
  slug: this.rewardAssets[0],
73
- apy: apy * 100,
74
64
  exchangeRate: exchangeRate / decimals
75
65
  }],
76
66
  unstakingPeriod: 24 * 28,
@@ -81,7 +71,6 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
81
71
  defaultUnstake: minUnstake,
82
72
  fastUnstake: '0'
83
73
  },
84
- totalApy: apy * 100,
85
74
  tvl: tvl.toString()
86
75
  }
87
76
  };