@subwallet/extension-base 1.2.3-1 → 1.2.5-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 (75) hide show
  1. package/background/KoniTypes.d.ts +0 -153
  2. package/background/KoniTypes.js +0 -21
  3. package/cjs/background/KoniTypes.js +1 -22
  4. package/cjs/core/logic-validation/earning.js +2 -2
  5. package/cjs/core/logic-validation/transfer.js +0 -7
  6. package/cjs/core/substrate/nominationpools-pallet.js +11 -1
  7. package/cjs/core/substrate/system-pallet.js +2 -3
  8. package/cjs/core/substrate/xcm-parser.js +190 -0
  9. package/cjs/koni/api/dotsama/transfer.js +10 -119
  10. package/cjs/koni/api/staking/bonding/utils.js +38 -6
  11. package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
  12. package/cjs/koni/api/xcm/utils.js +8 -126
  13. package/cjs/koni/api/xcm/xTokens.js +10 -8
  14. package/cjs/koni/api/xcm/xcmPallet.js +6 -6
  15. package/cjs/koni/background/handlers/Extension.js +90 -113
  16. package/cjs/koni/background/handlers/Tabs.js +3 -2
  17. package/cjs/packageInfo.js +1 -1
  18. package/cjs/page/index.js +4 -2
  19. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +6 -3
  20. package/cjs/services/chain-service/constants.js +2 -2
  21. package/cjs/services/chain-service/utils/index.js +7 -2
  22. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +104 -113
  23. package/cjs/services/earning-service/handlers/special.js +3 -3
  24. package/cjs/services/earning-service/service.js +1 -1
  25. package/cjs/services/earning-service/utils/index.js +6 -1
  26. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
  27. package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
  28. package/cjs/services/migration-service/scripts/index.js +2 -2
  29. package/cjs/services/request-service/constants.js +5 -3
  30. package/cjs/services/request-service/handler/AuthRequestHandler.js +32 -12
  31. package/cjs/services/swap-service/handler/base-handler.js +5 -3
  32. package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
  33. package/core/logic-validation/earning.d.ts +1 -1
  34. package/core/logic-validation/earning.js +2 -2
  35. package/core/logic-validation/transfer.js +0 -7
  36. package/core/substrate/nominationpools-pallet.d.ts +4 -1
  37. package/core/substrate/nominationpools-pallet.js +8 -1
  38. package/core/substrate/system-pallet.js +2 -3
  39. package/core/substrate/xcm-parser.d.ts +49 -0
  40. package/core/substrate/xcm-parser.js +181 -0
  41. package/koni/api/dotsama/transfer.d.ts +0 -3
  42. package/koni/api/dotsama/transfer.js +12 -119
  43. package/koni/api/staking/bonding/utils.d.ts +6 -2
  44. package/koni/api/staking/bonding/utils.js +33 -4
  45. package/koni/api/xcm/polkadotXcm.js +14 -22
  46. package/koni/api/xcm/utils.d.ts +3 -48
  47. package/koni/api/xcm/utils.js +5 -114
  48. package/koni/api/xcm/xTokens.js +12 -10
  49. package/koni/api/xcm/xcmPallet.js +7 -7
  50. package/koni/background/handlers/Extension.d.ts +1 -3
  51. package/koni/background/handlers/Extension.js +8 -28
  52. package/koni/background/handlers/Tabs.js +3 -2
  53. package/package.json +11 -6
  54. package/packageInfo.js +1 -1
  55. package/page/index.d.ts +2 -2
  56. package/page/index.js +4 -2
  57. package/services/balance-service/helpers/subscribe/substrate/index.js +8 -5
  58. package/services/chain-service/constants.js +2 -2
  59. package/services/chain-service/utils/index.d.ts +3 -2
  60. package/services/chain-service/utils/index.js +5 -2
  61. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +5 -2
  62. package/services/earning-service/handlers/native-staking/relay-chain.js +106 -115
  63. package/services/earning-service/handlers/special.js +3 -3
  64. package/services/earning-service/service.js +1 -1
  65. package/services/earning-service/utils/index.d.ts +2 -0
  66. package/services/earning-service/utils/index.js +6 -2
  67. package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
  68. package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
  69. package/services/migration-service/scripts/index.js +2 -2
  70. package/services/request-service/constants.d.ts +1 -0
  71. package/services/request-service/constants.js +4 -2
  72. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  73. package/services/request-service/handler/AuthRequestHandler.js +22 -3
  74. package/services/swap-service/handler/base-handler.js +5 -3
  75. package/services/swap-service/handler/hydradx-handler.js +1 -1
@@ -1,118 +1,9 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
- import { _getSubstrateParaId, _getXcmAssetMultilocation, _isChainEvmCompatible, _isNativeToken, _isSubstrateParaChain, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
6
- import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
7
- export const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
8
- export const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
9
- Limited: 5000000000
10
- };
11
-
12
- // get multilocation for destination chain from a parachain
13
-
14
- export function getReceiverLocation(destinationChainInfo, toAddress, version) {
15
- const network = version && version === 'V3' ? undefined : 'Any';
16
- if (destinationChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM) {
17
- const ss58Address = evmToAddress(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
18
-
19
- return {
20
- AccountId32: {
21
- network,
22
- id: decodeAddress(ss58Address)
23
- }
24
- };
25
- }
26
- if (_isChainEvmCompatible(destinationChainInfo)) {
27
- return {
28
- AccountKey20: {
29
- network,
30
- key: toAddress
31
- }
32
- };
33
- }
34
- return {
35
- AccountId32: {
36
- network,
37
- id: decodeAddress(toAddress)
38
- }
39
- };
40
- }
41
- export function getBeneficiary(destinationChainInfo, recipientAddress, version = 'V1') {
42
- const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
43
- return {
44
- [version]: {
45
- parents: 0,
46
- interior: {
47
- X1: receiverLocation
48
- }
49
- }
50
- };
51
- }
52
- export function getDestWeight() {
53
- return 'Unlimited';
54
- }
55
- export function getTokenLocation(tokenInfo, sendingValue, version = 'V1') {
56
- if (!_isNativeToken(tokenInfo)) {
57
- const multilocation = _getXcmAssetMultilocation(tokenInfo);
58
- return {
59
- [version]: [{
60
- id: multilocation,
61
- fun: {
62
- Fungible: sendingValue
63
- }
64
- }]
65
- };
66
- }
67
- return {
68
- [version]: [{
69
- id: {
70
- Concrete: {
71
- parents: 0,
72
- interior: 'Here'
73
- }
74
- },
75
- fun: {
76
- Fungible: sendingValue
77
- }
78
- }]
79
- };
80
- }
81
- export function getDestMultilocation(destinationChainInfo, recipient, version = 'V1') {
82
- const receiverLocation = getReceiverLocation(destinationChainInfo, recipient, version);
83
- if (_isSubstrateParaChain(destinationChainInfo)) {
84
- const interior = {
85
- X2: [{
86
- Parachain: _getSubstrateParaId(destinationChainInfo)
87
- }, receiverLocation]
88
- };
89
- return {
90
- [version]: {
91
- parents: 1,
92
- interior
93
- }
94
- };
95
- }
96
- return {
97
- [version]: {
98
- parents: 1,
99
- interior: {
100
- X1: receiverLocation
101
- }
102
- }
103
- };
104
- }
105
- export function getDestinationChainLocation(originChainInfo, destinationChainInfo, version = 'V1') {
106
- const parents = _isSubstrateRelayChain(originChainInfo) ? 0 : 1;
107
- const interior = _isSubstrateParaChain(destinationChainInfo) ? {
108
- X1: {
109
- Parachain: _getSubstrateParaId(destinationChainInfo)
110
- }
111
- } : 'Here';
112
- return {
113
- [version]: {
114
- parents,
115
- interior
116
- }
117
- };
4
+ export const STABLE_XCM_VERSION = 3;
5
+ export function isUseTeleportProtocol(originChainInfo, destChainInfo) {
6
+ const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug);
7
+ const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug);
8
+ return relayChainToSystemChain || systemChainToRelayChain;
118
9
  }
@@ -1,24 +1,26 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { FOUR_INSTRUCTIONS_WEIGHT, getDestMultilocation, getDestWeight } from '@subwallet/extension-base/koni/api/xcm/utils';
5
- import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
4
+ import { _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
5
+ import { STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
6
+ import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType } from '@subwallet/extension-base/services/chain-service/utils';
6
7
  function getCurrencyId(tokenInfo) {
7
- if (['acala', 'karura'].includes(tokenInfo.originChain) && _isNativeToken(tokenInfo)) {
8
- return _getXcmAssetMultilocation(tokenInfo);
9
- } else if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
8
+ if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
10
9
  const tokenType = _getXcmAssetType(tokenInfo);
11
10
  const assetId = _getXcmAssetId(tokenInfo);
12
11
  return {
13
12
  [tokenType]: assetId
14
13
  };
15
- } else if (['pioneer'].includes(tokenInfo.originChain)) {
16
- return _getXcmAssetMultilocation(tokenInfo);
17
14
  }
18
15
  return _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo);
19
16
  }
20
17
  export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
21
- const weightParam = ['pioneer'].includes(originChainInfo.slug) ? FOUR_INSTRUCTIONS_WEIGHT : getDestWeight();
22
- const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main', 'acala', 'parallel', 'astar', 'shiden', 'centrifuge', 'manta_network'].includes(originChainInfo.slug) ? 'V3' : undefined;
23
- return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getDestMultilocation(destinationChainInfo, recipientAddress, destVersion), weightParam);
18
+ const version = STABLE_XCM_VERSION;
19
+ const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, version, recipientAddress);
20
+ if (!_getXcmAssetMultilocation(tokenInfo)) {
21
+ const tokenCurrencyId = getCurrencyId(tokenInfo);
22
+ return api.tx.xTokens.transfer(tokenCurrencyId, value, destination, _getXcmDestWeight(originChainInfo));
23
+ }
24
+ const tokenMultiAsset = _getXcmMultiAssets(tokenInfo, value, version);
25
+ return api.tx.xTokens.transferMultiassets(tokenMultiAsset, 0, destination, _getXcmDestWeight(originChainInfo));
24
26
  }
@@ -1,16 +1,16 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { getBeneficiary, getDestinationChainLocation, getDestWeight, getTokenLocation } from '@subwallet/extension-base/koni/api/xcm/utils';
4
+ import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
5
+ import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
5
6
  // this pallet is only used by Relaychains
6
7
  export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
7
- const weightParam = getDestWeight();
8
- const xcmVer = 'V3';
9
- const destination = getDestinationChainLocation(originChainInfo, destinationChainInfo, xcmVer);
10
- const beneficiary = getBeneficiary(destinationChainInfo, recipientAddress, xcmVer);
11
- const tokenLocation = getTokenLocation(tokenInfo, value, xcmVer);
8
+ const weightParam = _getXcmDestWeight(originChainInfo);
9
+ const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, STABLE_XCM_VERSION);
10
+ const beneficiary = _getXcmBeneficiary(destinationChainInfo, recipientAddress, STABLE_XCM_VERSION);
11
+ const tokenLocation = _getXcmMultiAssets(tokenInfo, value, STABLE_XCM_VERSION);
12
12
  let method = 'limitedReserveTransferAssets';
13
- if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
13
+ if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
14
14
  method = 'limitedTeleportAssets';
15
15
  }
16
16
  return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
@@ -143,9 +143,6 @@ export default class KoniExtension {
143
143
  private getXcmMaxTransferable;
144
144
  private getNativeTokenMaxTransferable;
145
145
  private subscribeAddressTransferableBalance;
146
- private transferCheckReferenceCount;
147
- private transferCheckSupporting;
148
- private transferGetExistentialDeposit;
149
146
  private substrateNftSubmitTransaction;
150
147
  private enableChains;
151
148
  private getAccountMeta;
@@ -182,6 +179,7 @@ export default class KoniExtension {
182
179
  private keyringMigrateMasterPassword;
183
180
  private keyringUnlock;
184
181
  private keyringLock;
182
+ keyringLockSubscribe(cb: (state: boolean) => void): any;
185
183
  private keyringExportMnemonic;
186
184
  private resetWallet;
187
185
  private signingApprovePasswordV2;
@@ -12,7 +12,7 @@ import { additionalValidateTransfer, additionalValidateXcmTransfer, validateTran
12
12
  import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
13
13
  import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
14
14
  import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
15
- import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic, getTransferMockTxFee } from '@subwallet/extension-base/koni/api/dotsama/transfer';
15
+ import { createTransferExtrinsic, getTransferMockTxFee } from '@subwallet/extension-base/koni/api/dotsama/transfer';
16
16
  import { getNftTransferExtrinsic, isRecipientSelf } from '@subwallet/extension-base/koni/api/nft/transfer';
17
17
  import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, validateBondingCondition, validateUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding';
18
18
  import { getTuringCancelCompoundingExtrinsic, getTuringCompoundExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
@@ -23,7 +23,7 @@ import { createXcmExtrinsic, getXcmMockTxFee } from '@subwallet/extension-base/k
23
23
  import { YIELD_EXTRINSIC_TYPES } from '@subwallet/extension-base/koni/api/yield/helper/utils';
24
24
  import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
25
25
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
26
- import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
26
+ import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
27
27
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
28
28
  import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
29
29
  import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
@@ -38,6 +38,7 @@ import { keyring } from '@subwallet/ui-keyring';
38
38
  import { getSdkError } from '@walletconnect/utils';
39
39
  import BigN from 'bignumber.js';
40
40
  import { t } from 'i18next';
41
+ import { Subject } from 'rxjs';
41
42
  import { TypeRegistry } from '@polkadot/types';
42
43
  import { assert, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
43
44
  import { base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
@@ -74,6 +75,7 @@ export default class KoniExtension {
74
75
  #skipAutoLock = false;
75
76
  #firstTime = true;
76
77
  #alwaysLock = false;
78
+ #keyringLockSubject = new Subject();
77
79
  constructor(state) {
78
80
  this.#koniState = state;
79
81
  const updateTimeAutoLock = rs => {
@@ -1912,26 +1914,6 @@ export default class KoniExtension {
1912
1914
  });
1913
1915
  return convertData(currentFreeBalance);
1914
1916
  }
1915
- async transferCheckReferenceCount({
1916
- address,
1917
- networkKey
1918
- }) {
1919
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1920
- return await checkReferenceCount(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1921
- }
1922
- async transferCheckSupporting({
1923
- networkKey,
1924
- tokenSlug
1925
- }) {
1926
- const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1927
- return await checkSupportTransfer(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1928
- }
1929
- transferGetExistentialDeposit({
1930
- tokenSlug
1931
- }) {
1932
- const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1933
- return _getTokenMinAmount(tokenInfo);
1934
- }
1935
1917
  async substrateNftSubmitTransaction(inputData) {
1936
1918
  const {
1937
1919
  params,
@@ -2816,8 +2798,12 @@ export default class KoniExtension {
2816
2798
 
2817
2799
  keyringLock() {
2818
2800
  this.#koniState.keyringService.lock();
2801
+ this.#keyringLockSubject.next(true);
2819
2802
  clearTimeout(this.#lockTimeOut);
2820
2803
  }
2804
+ keyringLockSubscribe(cb) {
2805
+ this.#keyringLockSubject.subscribe(cb);
2806
+ }
2821
2807
 
2822
2808
  // Export mnemonic
2823
2809
 
@@ -4297,12 +4283,6 @@ export default class KoniExtension {
4297
4283
  return this.subscribeAssetSetting(id, port);
4298
4284
  case 'pri(assetSetting.update)':
4299
4285
  return await this.updateAssetSetting(request);
4300
- case 'pri(transfer.checkReferenceCount)':
4301
- return await this.transferCheckReferenceCount(request);
4302
- case 'pri(transfer.checkSupporting)':
4303
- return await this.transferCheckSupporting(request);
4304
- case 'pri(transfer.getExistentialDeposit)':
4305
- return this.transferGetExistentialDeposit(request);
4306
4286
  case 'pri(transfer.getMaxTransferable)':
4307
4287
  return this.getMaxTransferable(request);
4308
4288
  case 'pri(transfer.subscribeMaxTransferable)':
@@ -237,7 +237,7 @@ export default class KoniTabs {
237
237
  anyType
238
238
  }) {
239
239
  const authInfo = await this.getAuthInfo(url);
240
- return transformAccountsV2(this.#koniState.keyringService.accounts, anyType, authInfo, accountAuthType);
240
+ return transformAccountsV2(this.#koniState.keyringService.accounts, anyType, authInfo, (authInfo === null || authInfo === void 0 ? void 0 : authInfo.accountAuthType) || accountAuthType);
241
241
  }
242
242
  accountsSubscribeV2(url, {
243
243
  accountAuthType
@@ -249,8 +249,9 @@ export default class KoniTabs {
249
249
  this.#accountSubs[id] = {
250
250
  subscription: authInfoSubject.subscribe(infos => {
251
251
  this.getAuthInfo(url, infos).then(authInfo => {
252
+ const accountAuthType_ = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.accountAuthType) || accountAuthType;
252
253
  const accounts = this.#koniState.keyringService.accounts;
253
- return cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
254
+ return cb(transformAccountsV2(accounts, false, authInfo, accountAuthType_));
254
255
  }).catch(console.error);
255
256
  }),
256
257
  url
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.2.3-1",
20
+ "version": "1.2.5-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -154,6 +154,11 @@
154
154
  "require": "./cjs/core/substrate/system-pallet.js",
155
155
  "default": "./core/substrate/system-pallet.js"
156
156
  },
157
+ "./core/substrate/xcm-parser": {
158
+ "types": "./core/substrate/xcm-parser.d.ts",
159
+ "require": "./cjs/core/substrate/xcm-parser.js",
160
+ "default": "./core/substrate/xcm-parser.js"
161
+ },
157
162
  "./defaults": {
158
163
  "types": "./defaults.d.ts",
159
164
  "require": "./cjs/defaults.js",
@@ -1916,11 +1921,11 @@
1916
1921
  "@reduxjs/toolkit": "^1.9.1",
1917
1922
  "@sora-substrate/type-definitions": "^1.17.7",
1918
1923
  "@substrate/connect": "^0.8.9",
1919
- "@subwallet/chain-list": "0.2.66",
1920
- "@subwallet/extension-base": "^1.2.3-1",
1921
- "@subwallet/extension-chains": "^1.2.3-1",
1922
- "@subwallet/extension-dapp": "^1.2.3-1",
1923
- "@subwallet/extension-inject": "^1.2.3-1",
1924
+ "@subwallet/chain-list": "0.2.67",
1925
+ "@subwallet/extension-base": "^1.2.5-0",
1926
+ "@subwallet/extension-chains": "^1.2.5-0",
1927
+ "@subwallet/extension-dapp": "^1.2.5-0",
1928
+ "@subwallet/extension-inject": "^1.2.5-0",
1924
1929
  "@subwallet/keyring": "^0.1.5",
1925
1930
  "@subwallet/ui-keyring": "^0.1.5",
1926
1931
  "@walletconnect/keyvaluestorage": "^1.1.1",
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.3-1'
10
+ version: '1.2.5-0'
11
11
  };
package/page/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MessageTypes, MessageTypesWithNoSubscriptions, MessageTypesWithNullRequest, MessageTypesWithSubscriptions, RequestTypes, ResponseTypes, SubscriptionMessageTypes, TransportResponseMessage } from '../background/types';
2
- import { EvmProvider } from '@subwallet/extension-inject/types';
2
+ import { AuthRequestOption, EvmProvider } from '@subwallet/extension-inject/types';
3
3
  import Injected from './Injected';
4
4
  export interface Handler {
5
5
  resolve: (data?: any) => void;
@@ -10,7 +10,7 @@ export declare type Handlers = Record<string, Handler>;
10
10
  export declare function sendMessage<TMessageType extends MessageTypesWithNullRequest>(message: TMessageType): Promise<ResponseTypes[TMessageType]>;
11
11
  export declare function sendMessage<TMessageType extends MessageTypesWithNoSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType]): Promise<ResponseTypes[TMessageType]>;
12
12
  export declare function sendMessage<TMessageType extends MessageTypesWithSubscriptions>(message: TMessageType, request: RequestTypes[TMessageType], subscriber: (data: SubscriptionMessageTypes[TMessageType]) => void): Promise<ResponseTypes[TMessageType]>;
13
- export declare function enable(origin: string): Promise<Injected>;
13
+ export declare function enable(origin: string, opt?: AuthRequestOption): Promise<Injected>;
14
14
  export declare function handleResponse<TMessageType extends MessageTypes>(data: TransportResponseMessage<TMessageType> & {
15
15
  subscription?: string;
16
16
  }): void;
package/page/index.js CHANGED
@@ -38,9 +38,11 @@ export function sendMessage(message, request, subscriber) {
38
38
  }
39
39
 
40
40
  // the enable function, called by the dapp to allow access
41
- export async function enable(origin) {
41
+
42
+ export async function enable(origin, opt) {
42
43
  await sendMessage('pub(authorize.tabV2)', {
43
- origin
44
+ origin,
45
+ accountAuthType: (opt === null || opt === void 0 ? void 0 : opt.accountAuthType) || 'substrate'
44
46
  });
45
47
  return new Injected(sendMessage);
46
48
  }
@@ -5,12 +5,12 @@ import { GearApi } from '@gear-js/api';
5
5
  import { _AssetType } from '@subwallet/chain-list/types';
6
6
  import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
7
7
  import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
8
- import { _getActiveStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
8
+ import { _getTotalStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
9
9
  import { _getSystemPalletTotalBalance, _getSystemPalletTransferable } from '@subwallet/extension-base/core/substrate/system-pallet';
10
10
  import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
11
11
  import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
12
12
  import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
13
- import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
13
+ import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
14
14
  import { filterAssetsByChainAndType, getGRC20ContractPromise } from '@subwallet/extension-base/utils';
15
15
  import BigN from 'bignumber.js';
16
16
  import { combineLatest, Observable } from 'rxjs';
@@ -131,7 +131,7 @@ const subscribeWithSystemAccountPallet = async ({
131
131
  const items = balances.map((_balance, index) => {
132
132
  const balanceInfo = _balance.toPrimitive();
133
133
  const poolMemberInfo = poolMemberInfos[index].toPrimitive();
134
- const nominationPoolBalance = poolMemberInfo ? _getActiveStakeInNominationPool(poolMemberInfo) : '0';
134
+ const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : new BigN(0);
135
135
  const transferableBalance = _getSystemPalletTransferable(balanceInfo, _getChainExistentialDeposit(chainInfo), extrinsicType);
136
136
  const totalBalance = _getSystemPalletTotalBalance(balanceInfo);
137
137
  const totalLockedFromTransfer = new BigN(totalBalance).minus(transferableBalance).plus(nominationPoolBalance);
@@ -165,8 +165,8 @@ const subscribeBridgedBalance = async ({
165
165
  try {
166
166
  const isBridgedToken = _isBridgedToken(tokenInfo);
167
167
  if (isBridgedToken) {
168
- const multiLocation = _getXcmAssetMultilocation(tokenInfo);
169
- return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [multiLocation, address]), balances => {
168
+ const onChainInfo = _getTokenOnChainInfo(tokenInfo);
169
+ return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [onChainInfo, address]), balances => {
170
170
  const items = balances.map((balance, index) => {
171
171
  const bdata = balance === null || balance === void 0 ? void 0 : balance.toHuman();
172
172
  let frozen = BN_ZERO;
@@ -339,6 +339,9 @@ const subscribeAssetsAccountPallet = async ({
339
339
  const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
340
340
  try {
341
341
  const assetIndex = _getTokenOnChainAssetId(tokenInfo);
342
+ if (assetIndex === '-1') {
343
+ return undefined;
344
+ }
342
345
 
343
346
  // Get Token Balance
344
347
  return await substrateApi.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
@@ -34,7 +34,7 @@ export const _BALANCE_CHAIN_GROUP = {
34
34
  kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
35
35
  // perhaps there are some runtime updates
36
36
  centrifuge: ['centrifuge'],
37
- supportBridged: ['rococo_assethub']
37
+ supportBridged: ['rococo_assethub', 'statemint', 'statemine']
38
38
  };
39
39
  export const _BALANCE_TOKEN_GROUP = {
40
40
  crab: ['CKTON', 'PKTON'],
@@ -249,7 +249,7 @@ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
249
249
  // XCM------------------------------------------------------------------------------------------------------------------
250
250
 
251
251
  export const _XCM_CHAIN_GROUP = {
252
- polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain'],
252
+ polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
253
253
  xcmPallet: ['polkadot', 'kusama']
254
254
  // default is xTokens pallet
255
255
  };
@@ -35,9 +35,9 @@ export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
35
35
  export declare function _isNativeTokenBySlug(tokenSlug: string): boolean;
36
36
  export declare function _isSmartContractToken(tokenInfo: _ChainAsset): boolean;
37
37
  export declare function _isSubstrateChain(chainInfo: _ChainInfo): boolean;
38
- export declare function _getEvmChainId(chainInfo: _ChainInfo): number;
38
+ export declare function _getEvmChainId(chainInfo: _ChainInfo): number | undefined;
39
39
  export declare function _getSubstrateParaId(chainInfo: _ChainInfo): number;
40
- export declare function _getSubstrateRelayParent(chainInfo: _ChainInfo): string;
40
+ export declare function _getSubstrateRelayParent(chainInfo: _ChainInfo): string | null | undefined;
41
41
  export declare function _getSubstrateGenesisHash(chainInfo: _ChainInfo): string;
42
42
  export declare function _isChainSupportSubstrateStaking(chainInfo: _ChainInfo): boolean;
43
43
  export declare function _isChainEnabled(chainState: _ChainState): boolean;
@@ -64,6 +64,7 @@ export declare function _getXcmAssetType(tokenInfo: _ChainAsset): string;
64
64
  export declare function _getXcmAssetId(tokenInfo: _ChainAsset): string;
65
65
  export declare function _getXcmAssetMultilocation(tokenInfo: _ChainAsset): Record<string, any>;
66
66
  export declare function _getXcmTransferType(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo): string;
67
+ export declare function _isRelayChain(chainInfo: _ChainInfo): boolean;
67
68
  export declare function _isSubstrateRelayChain(chainInfo: _ChainInfo): boolean;
68
69
  export declare function _isSubstrateParaChain(chainInfo: _ChainInfo): boolean;
69
70
  export declare function _getEvmAbiExplorer(chainInfo: _ChainInfo): string;
@@ -131,7 +131,7 @@ export function _isSubstrateChain(chainInfo) {
131
131
 
132
132
  export function _getEvmChainId(chainInfo) {
133
133
  var _chainInfo$evmInfo;
134
- return ((_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) || 1; // fallback to Ethereum
134
+ return (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId; // fallback to Ethereum
135
135
  }
136
136
 
137
137
  export function _getSubstrateParaId(chainInfo) {
@@ -140,7 +140,7 @@ export function _getSubstrateParaId(chainInfo) {
140
140
  }
141
141
  export function _getSubstrateRelayParent(chainInfo) {
142
142
  var _chainInfo$substrateI2;
143
- return ((_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.relaySlug) || '';
143
+ return (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.relaySlug;
144
144
  }
145
145
  export function _getSubstrateGenesisHash(chainInfo) {
146
146
  var _chainInfo$substrateI3;
@@ -292,6 +292,9 @@ export function _getXcmTransferType(originChainInfo, destinationChainInfo) {
292
292
  var _originChainInfo$subs, _destinationChainInfo;
293
293
  return `${((_originChainInfo$subs = originChainInfo.substrateInfo) === null || _originChainInfo$subs === void 0 ? void 0 : _originChainInfo$subs.chainType) || ''}-${((_destinationChainInfo = destinationChainInfo.substrateInfo) === null || _destinationChainInfo === void 0 ? void 0 : _destinationChainInfo.chainType) || ''}`;
294
294
  }
295
+ export function _isRelayChain(chainInfo) {
296
+ return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
297
+ }
295
298
  export function _isSubstrateRelayChain(chainInfo) {
296
299
  var _chainInfo$substrateI14;
297
300
  return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _SubstrateChainType.RELAYCHAIN;
@@ -1,16 +1,19 @@
1
1
  import { _ChainInfo } from '@subwallet/chain-list/types';
2
2
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
3
- import { ExtrinsicType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
3
+ import { ExtrinsicType, NominationInfo, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
4
4
  import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
5
- import { BaseYieldPositionInfo, OptimalYieldPath, PalletStakingStakingLedger, StakeCancelWithdrawalParams, SubmitJoinNativeStaking, SubmitYieldJoinData, TransactionData, ValidatorInfo, YieldPoolInfo, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
5
+ import { BaseYieldPositionInfo, OptimalYieldPath, PalletStakingNominations, PalletStakingStakingLedger, StakeCancelWithdrawalParams, SubmitJoinNativeStaking, SubmitYieldJoinData, TransactionData, ValidatorInfo, YieldPoolInfo, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
6
6
  import { DeriveSessionProgress } from '@polkadot/api-derive/types';
7
7
  import { BN } from '@polkadot/util';
8
8
  import BaseNativeStakingPoolHandler from './base';
9
9
  export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPoolHandler {
10
10
  subscribePoolInfo(callback: (data: YieldPoolInfo) => void): Promise<VoidFunction>;
11
11
  parseNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, ledger: PalletStakingStakingLedger, currentEra: string, minStake: BN, _deriveSessionProgress: DeriveSessionProgress): Promise<Omit<YieldPositionInfo, keyof BaseYieldPositionInfo>>;
12
+ handleNominationsList(substrateApi: _SubstrateApi, chain: string, nominations: PalletStakingNominations, currentEra: string, address: string, maxNominatorRewardedPerValidator: number | undefined): Promise<NominationInfo[]>;
12
13
  subscribePoolPosition(useAddresses: string[], resultCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
13
14
  getPoolTargets(): Promise<ValidatorInfo[]>;
15
+ private getValidatorExpectedReturn;
16
+ private parseEraStakerData;
14
17
  validateYieldJoin(data: SubmitYieldJoinData, path: OptimalYieldPath): Promise<TransactionError[]>;
15
18
  createJoinExtrinsic(data: SubmitJoinNativeStaking, positionInfo?: YieldPositionInfo, bondDest?: string): Promise<[TransactionData, YieldTokenBaseInfo]>;
16
19
  validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string): Promise<TransactionError[]>;