@subwallet/extension-base 1.3.66-0 → 1.3.68-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 (81) hide show
  1. package/background/KoniTypes.d.ts +12 -1
  2. package/cjs/constants/environment.js +1 -3
  3. package/cjs/constants/index.js +4 -1
  4. package/cjs/core/substrate/system-pallet.js +4 -0
  5. package/cjs/core/substrate/xcm-parser.js +0 -176
  6. package/cjs/koni/api/nft/rari/index.js +1 -1
  7. package/cjs/koni/background/cron.js +16 -0
  8. package/cjs/koni/background/handlers/Extension.js +166 -90
  9. package/cjs/koni/background/handlers/State.js +25 -0
  10. package/cjs/packageInfo.js +1 -1
  11. package/cjs/services/balance-service/helpers/group.js +31 -2
  12. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +51 -13
  13. package/cjs/services/balance-service/helpers/subscribe/substrate/utils.js +69 -0
  14. package/cjs/services/balance-service/index.js +36 -11
  15. package/cjs/services/balance-service/transfer/smart-contract.js +56 -23
  16. package/cjs/services/balance-service/transfer/xcm/index.js +30 -44
  17. package/cjs/services/balance-service/transfer/xcm/utils.js +53 -18
  18. package/cjs/services/chain-service/constants.js +8 -46
  19. package/cjs/services/chain-service/handler/EvmChainHandler.js +6 -3
  20. package/cjs/services/earning-service/handlers/base.js +7 -1
  21. package/cjs/services/nft-service/index.js +173 -0
  22. package/cjs/services/swap-service/handler/base-handler.js +18 -21
  23. package/cjs/services/transaction-service/index.js +1 -1
  24. package/cjs/types/balance/index.js +26 -1
  25. package/cjs/utils/fee/transfer.js +5 -2
  26. package/cjs/utils/index.js +25 -2
  27. package/cjs/utils/setup-api-sdk.js +0 -5
  28. package/constants/environment.d.ts +0 -1
  29. package/constants/environment.js +0 -1
  30. package/constants/index.d.ts +1 -0
  31. package/constants/index.js +1 -0
  32. package/core/substrate/system-pallet.d.ts +1 -0
  33. package/core/substrate/system-pallet.js +3 -0
  34. package/core/substrate/types.d.ts +14 -0
  35. package/core/substrate/xcm-parser.d.ts +1 -49
  36. package/core/substrate/xcm-parser.js +1 -173
  37. package/koni/api/nft/rari/index.js +1 -1
  38. package/koni/background/cron.d.ts +1 -0
  39. package/koni/background/cron.js +17 -1
  40. package/koni/background/handlers/Extension.d.ts +3 -0
  41. package/koni/background/handlers/Extension.js +88 -14
  42. package/koni/background/handlers/State.d.ts +4 -0
  43. package/koni/background/handlers/State.js +25 -0
  44. package/package.json +16 -21
  45. package/packageInfo.js +1 -1
  46. package/services/balance-service/helpers/group.js +31 -2
  47. package/services/balance-service/helpers/subscribe/substrate/index.js +51 -13
  48. package/services/balance-service/helpers/subscribe/substrate/utils.d.ts +7 -0
  49. package/services/balance-service/helpers/subscribe/substrate/utils.js +58 -0
  50. package/services/balance-service/index.d.ts +4 -2
  51. package/services/balance-service/index.js +26 -6
  52. package/services/balance-service/transfer/smart-contract.d.ts +4 -0
  53. package/services/balance-service/transfer/smart-contract.js +54 -23
  54. package/services/balance-service/transfer/xcm/index.d.ts +2 -2
  55. package/services/balance-service/transfer/xcm/index.js +18 -32
  56. package/services/balance-service/transfer/xcm/utils.d.ts +1 -2
  57. package/services/balance-service/transfer/xcm/utils.js +51 -15
  58. package/services/chain-service/constants.d.ts +5 -24
  59. package/services/chain-service/constants.js +6 -35
  60. package/services/chain-service/handler/EvmChainHandler.js +6 -3
  61. package/services/earning-service/handlers/base.js +7 -1
  62. package/services/nft-service/index.d.ts +9 -0
  63. package/services/nft-service/index.js +165 -0
  64. package/services/swap-service/handler/base-handler.d.ts +0 -1
  65. package/services/swap-service/handler/base-handler.js +19 -22
  66. package/services/transaction-service/index.js +1 -1
  67. package/services/transaction-service/types.d.ts +2 -1
  68. package/types/balance/index.d.ts +14 -0
  69. package/types/balance/index.js +21 -1
  70. package/utils/fee/transfer.js +6 -3
  71. package/utils/index.js +25 -2
  72. package/utils/setup-api-sdk.js +1 -6
  73. package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +0 -30
  74. package/cjs/services/balance-service/transfer/xcm/xTokens.js +0 -32
  75. package/cjs/services/balance-service/transfer/xcm/xcmPallet.js +0 -23
  76. package/services/balance-service/transfer/xcm/polkadotXcm.d.ts +0 -3
  77. package/services/balance-service/transfer/xcm/polkadotXcm.js +0 -24
  78. package/services/balance-service/transfer/xcm/xTokens.d.ts +0 -3
  79. package/services/balance-service/transfer/xcm/xTokens.js +0 -26
  80. package/services/balance-service/transfer/xcm/xcmPallet.d.ts +0 -3
  81. package/services/balance-service/transfer/xcm/xcmPallet.js +0 -17
@@ -9,6 +9,7 @@ import { getAcrossbridgeTransferProcessFromEvm, getDefaultTransferProcess, getSn
9
9
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
10
10
  import { _getChainNativeTokenSlug, _isCustomAsset, _isNativeToken, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
11
11
  import DetectAccountBalanceStore from '@subwallet/extension-base/stores/DetectAccountBalance';
12
+ import { BalanceType } from '@subwallet/extension-base/types';
12
13
  import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwallet/extension-base/utils';
13
14
  import { getKeypairTypeByAddress } from '@subwallet/keyring';
14
15
  import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
@@ -18,6 +19,7 @@ import BigN from 'bignumber.js';
18
19
  import { t } from 'i18next';
19
20
  import { BehaviorSubject } from 'rxjs';
20
21
  import { noop } from '@polkadot/util';
22
+ import { _BALANCE_CHAIN_GROUP } from "../chain-service/constants.js";
21
23
  import { _isAcrossChainBridge, getAcrossQuote } from "./transfer/xcm/acrossBridge/index.js";
22
24
  import { BalanceMapImpl } from "./BalanceMapImpl.js";
23
25
  import { subscribeBalance } from "./helpers/index.js";
@@ -175,7 +177,7 @@ export class BalanceService {
175
177
  }
176
178
 
177
179
  /** Subscribe token free balance of an address on chain */
178
- async subscribeBalance(address, chain, tokenSlug, balanceType = 'transferable', extrinsicType, callback) {
180
+ async subscribeBalance(address, chain, tokenSlug, balanceType = BalanceType.TRANSFERABLE, extrinsicType, callback) {
179
181
  const chainInfo = this.state.chainService.getChainInfoByKey(chain);
180
182
  const chainState = this.state.chainService.getChainStateByKey(chain);
181
183
  if (!chainInfo || !chainState || !chainState.active) {
@@ -208,9 +210,20 @@ export class BalanceService {
208
210
  const rs = result[0];
209
211
  let value;
210
212
  switch (balanceType) {
211
- case 'total':
213
+ case BalanceType.TOTAL:
212
214
  value = new BigN(rs.free).plus(new BigN(rs.locked)).toFixed();
213
215
  break;
216
+ case BalanceType.TOTAL_MINUS_RESERVED:
217
+ if (_BALANCE_CHAIN_GROUP.notSupportGetBalanceByType.includes(chainInfo.slug)) {
218
+ // TODO: Currently Vara and Avail staking from nomination pools is not fully supported.
219
+ // Return `free` to avoid incorrect TOTAL_MINUS_RESERVED calculation.
220
+ // Improve later when full staking breakdown is available.
221
+ value = rs.free;
222
+ } else {
223
+ var _rs$lockedDetails, _rs$lockedDetails2;
224
+ value = new BigN(rs.free).plus(new BigN(rs.locked)).minus(BigN.max(new BigN(((_rs$lockedDetails = rs.lockedDetails) === null || _rs$lockedDetails === void 0 ? void 0 : _rs$lockedDetails.reserved) || 0), new BigN(((_rs$lockedDetails2 = rs.lockedDetails) === null || _rs$lockedDetails2 === void 0 ? void 0 : _rs$lockedDetails2.staking) || 0))).toFixed();
225
+ }
226
+ break;
214
227
  default:
215
228
  value = rs.free;
216
229
  }
@@ -242,10 +255,13 @@ export class BalanceService {
242
255
  });
243
256
  }
244
257
  async subscribeTransferableBalance(address, chain, tokenSlug, extrinsicType, callback) {
245
- return this.subscribeBalance(address, chain, tokenSlug, 'transferable', extrinsicType, callback);
258
+ return this.subscribeBalance(address, chain, tokenSlug, BalanceType.TRANSFERABLE, extrinsicType, callback);
246
259
  }
247
260
  async subscribeTotalBalance(address, chain, tokenSlug, extrinsicType, callback) {
248
- return this.subscribeBalance(address, chain, tokenSlug, 'total', extrinsicType, callback);
261
+ return this.subscribeBalance(address, chain, tokenSlug, BalanceType.TOTAL, extrinsicType, callback);
262
+ }
263
+ async subscribeBalanceByType(address, chain, tokenSlug, balanceType = BalanceType.TRANSFERABLE, extrinsicType, callback) {
264
+ return this.subscribeBalance(address, chain, tokenSlug, balanceType, extrinsicType, callback);
249
265
  }
250
266
 
251
267
  /**
@@ -267,6 +283,10 @@ export class BalanceService {
267
283
  const [, balance] = await this.subscribeTotalBalance(address, chain, tokenSlug, extrinsicType);
268
284
  return balance;
269
285
  }
286
+ async getBalanceByType(address, chain, tokenSlug, balanceType = BalanceType.TRANSFERABLE, extrinsicType) {
287
+ const [, balance] = await this.subscribeBalanceByType(address, chain, tokenSlug, balanceType, extrinsicType);
288
+ return balance;
289
+ }
270
290
 
271
291
  /** Remove balance from the subject object by addresses */
272
292
  removeBalanceByAddresses(addresses) {
@@ -452,7 +472,7 @@ export class BalanceService {
452
472
  const type = getKeypairTypeByAddress(address);
453
473
  const typeValid = [...EthereumKeypairTypes].includes(type);
454
474
  if (typeValid) {
455
- return subwalletApiSdk.balanceDetectionApi.getSubWalletTokenBalance(address).catch(e => {
475
+ return subwalletApiSdk.balanceDetectionApi.getSwEvmTokenBalance(address).catch(e => {
456
476
  console.error(e);
457
477
  return null;
458
478
  });
@@ -632,7 +652,7 @@ export class BalanceService {
632
652
  async evmDetectBalanceToken(addresses) {
633
653
  const assetMap = this.state.chainService.getAssetRegistry();
634
654
  const evmPromiseList = addresses.map(address => {
635
- return subwalletApiSdk.balanceDetectionApi.getSubWalletTokenBalance(address).catch(e => {
655
+ return subwalletApiSdk.balanceDetectionApi.getSwEvmTokenBalance(address).catch(e => {
636
656
  console.error(e);
637
657
  return null;
638
658
  });
@@ -12,6 +12,10 @@ interface TransferEvmProps extends TransactionFee {
12
12
  fallbackFee?: boolean;
13
13
  data?: string;
14
14
  }
15
+ export declare const gasSettingsForEWC: {
16
+ gasLimit: number;
17
+ maxFeePerGas: string;
18
+ };
15
19
  export declare function getEVMTransactionObject(props: TransferEvmProps): Promise<[TransactionConfig, string, string]>;
16
20
  export declare function getERC20TransactionObject(props: TransferERC20Props): Promise<[TransactionConfig, string, string]>;
17
21
  interface TransferERC20Props extends TransactionFee {
@@ -9,6 +9,11 @@ import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-
9
9
  import { combineEthFee } from '@subwallet/extension-base/utils';
10
10
  import BigN from 'bignumber.js';
11
11
  import { t } from 'i18next';
12
+ // hot fix gas settings for Energy Web Chain
13
+ export const gasSettingsForEWC = {
14
+ gasLimit: 4900000,
15
+ maxFeePerGas: '10000000'
16
+ };
12
17
  export async function getEVMTransactionObject(props) {
13
18
  const {
14
19
  chain,
@@ -23,10 +28,18 @@ export async function getEVMTransactionObject(props) {
23
28
  transferAll,
24
29
  value
25
30
  } = props;
31
+ const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
32
+
26
33
  const feeCustom = _feeCustom;
27
34
  const feeInfo = _feeInfo;
28
35
  const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
29
36
  let errorOnEstimateFee = '';
37
+ if (isEnergyWebChain) {
38
+ feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
39
+ if (!feeCombine.maxPriorityFeePerGas || new BigN(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
40
+ feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
41
+ }
42
+ }
30
43
  const transactionObject = {
31
44
  to,
32
45
  value,
@@ -34,16 +47,21 @@ export async function getEVMTransactionObject(props) {
34
47
  data,
35
48
  ...feeCombine
36
49
  };
37
- const gasEstimate = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
38
- console.log('Cannot estimate fee with native transfer on', chain, e);
39
- if (fallbackFee) {
40
- errorOnEstimateFee = e.message;
41
- return 21000;
42
- } else {
43
- throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
44
- }
45
- });
46
- const gasLimit = Math.floor(gasEstimate * 1.1); // 10% buffer for fluctuations
50
+ let gasLimit;
51
+ if (isEnergyWebChain) {
52
+ gasLimit = gasSettingsForEWC.gasLimit;
53
+ } else {
54
+ const gasEstimate = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
55
+ console.log('Cannot estimate fee with native transfer on', chain, e);
56
+ if (fallbackFee) {
57
+ errorOnEstimateFee = e.message;
58
+ return 21000;
59
+ } else {
60
+ throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
61
+ }
62
+ });
63
+ gasLimit = Math.floor(gasEstimate * 1.1); // 10% buffer for fluctuations
64
+ }
47
65
 
48
66
  transactionObject.gas = gasLimit;
49
67
  let estimateFee;
@@ -74,6 +92,8 @@ export async function getERC20TransactionObject(props) {
74
92
  transferAll,
75
93
  value
76
94
  } = props;
95
+ const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
96
+
77
97
  const erc20Contract = getERC20Contract(assetAddress, evmApi);
78
98
  const feeCustom = _feeCustom;
79
99
  let freeAmount = new BigN(0);
@@ -89,21 +109,30 @@ export async function getERC20TransactionObject(props) {
89
109
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
90
110
  return erc20Contract.methods.transfer(to, transferValue).encodeABI();
91
111
  }
92
- const transferData = generateTransferData(to, transferValue);
93
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
94
- const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
95
- from
96
- }).catch(e => {
97
- console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
98
- if (fallbackFee) {
99
- errorOnEstimateFee = e.message;
100
- return 70000;
101
- } else {
102
- throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
103
- }
104
- });
105
112
  const feeInfo = _feeInfo;
106
113
  const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
114
+ const transferData = generateTransferData(to, transferValue);
115
+ let gasLimit;
116
+ if (isEnergyWebChain) {
117
+ gasLimit = gasSettingsForEWC.gasLimit;
118
+ feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
119
+ if (!feeCombine.maxPriorityFeePerGas || new BigN(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
120
+ feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
121
+ }
122
+ } else {
123
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
124
+ gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
125
+ from
126
+ }).catch(e => {
127
+ console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
128
+ if (fallbackFee) {
129
+ errorOnEstimateFee = e.message;
130
+ return 70000;
131
+ } else {
132
+ throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
133
+ }
134
+ });
135
+ }
107
136
  const transactionObject = {
108
137
  gas: gasLimit,
109
138
  from,
@@ -132,7 +161,9 @@ export async function getERC721Transaction(web3Api, chain, contractAddress, send
132
161
  const error = e;
133
162
  if (error.message.includes('transfer to non ERC721Receiver implementer')) {
134
163
  error.message = t('bg.BALANCE.services.service.balance.transfer.smartContract.nftNotSupportedOnRecipient');
164
+ throw error;
135
165
  }
166
+ error.message = t('bg.BALANCE.services.service.balance.transfer.smartContract.temporarilyNontransferableNFT');
136
167
  throw error;
137
168
  }
138
169
  const feeInfo = _feeInfo;
@@ -17,10 +17,10 @@ export declare type CreateXcmExtrinsicProps = {
17
17
  } & TransactionFee;
18
18
  export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig | undefined>;
19
19
  export declare const createSnowBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
20
- export declare const createXcmExtrinsic: ({ destinationChain, originChain, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
21
20
  export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo, feeOption, originChain, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
22
21
  export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
23
22
  export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
24
23
  export declare const createXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | undefined>;
25
- export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<boolean>;
24
+ export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps, isPreview?: boolean) => Promise<boolean>;
25
+ export declare const getXcmOriginFee: (request: CreateXcmExtrinsicProps) => Promise<string | undefined>;
26
26
  export declare const createAcrossBridgeExtrinsic: ({ destinationChain, destinationTokenInfo, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
@@ -3,14 +3,9 @@
3
3
 
4
4
  import { _isAcrossBridgeXcm, _isPolygonBridgeXcm, _isPosBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
5
5
  import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
6
- import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
7
6
  import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
8
7
  import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
9
- import { buildXcm, dryRunXcm, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
10
- import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
11
- import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
12
- import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
13
- import { _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
8
+ import { buildXcm, dryRunPreviewXcm, dryRunXcm, estimateXcmFee, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
14
9
  import { combineEthFee } from '@subwallet/extension-base/utils';
15
10
  import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
16
11
  import { _createPosBridgeL1toL2Extrinsic, _createPosBridgeL2toL1Extrinsic } from "./posBridge.js";
@@ -38,30 +33,6 @@ export const createSnowBridgeExtrinsic = async ({
38
33
  }
39
34
  return getSnowBridgeEvmTransfer(originTokenInfo, originChain, destinationChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
40
35
  };
41
-
42
- // deprecated
43
- export const createXcmExtrinsic = async ({
44
- destinationChain,
45
- originChain,
46
- originTokenInfo,
47
- recipient,
48
- sendingValue,
49
- substrateApi
50
- }) => {
51
- if (!substrateApi) {
52
- throw Error('Substrate API is not available');
53
- }
54
- const chainApi = await substrateApi.isReady;
55
- const api = chainApi.api;
56
- const polkadotXcmSpecialCases = _XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChain.slug) && _isNativeToken(originTokenInfo);
57
- if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
58
- return getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
59
- }
60
- if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
61
- return getExtrinsicByXcmPalletPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
62
- }
63
- return getExtrinsicByXtokensPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
64
- };
65
36
  export const createAvailBridgeTxFromEth = ({
66
37
  evmApi,
67
38
  feeCustom,
@@ -125,9 +96,9 @@ export const createXcmExtrinsicV2 = async request => {
125
96
  return undefined;
126
97
  }
127
98
  };
128
- export const dryRunXcmExtrinsicV2 = async request => {
99
+ export const dryRunXcmExtrinsicV2 = async (request, isPreview = false) => {
129
100
  try {
130
- const dryRunResult = await dryRunXcm(request);
101
+ const dryRunResult = isPreview ? await dryRunPreviewXcm(request) : await dryRunXcm(request);
131
102
  const originDryRunRs = dryRunResult.origin;
132
103
  if (originDryRunRs.success) {
133
104
  const {
@@ -157,6 +128,21 @@ export const dryRunXcmExtrinsicV2 = async request => {
157
128
  return false;
158
129
  }
159
130
  };
131
+ export const getXcmOriginFee = async request => {
132
+ try {
133
+ const xcmFeeInfo = await estimateXcmFee({
134
+ fromChainInfo: request.originChain,
135
+ fromTokenInfo: request.originTokenInfo,
136
+ toChainInfo: request.destinationChain,
137
+ recipient: request.recipient,
138
+ sender: request.sender,
139
+ value: request.sendingValue
140
+ });
141
+ return xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee;
142
+ } catch (e) {
143
+ return undefined;
144
+ }
145
+ };
160
146
  export const createAcrossBridgeExtrinsic = async ({
161
147
  destinationChain,
162
148
  destinationTokenInfo,
@@ -44,9 +44,8 @@ export declare type GetXcmFeeResult = {
44
44
  };
45
45
  export declare function buildXcm(request: CreateXcmExtrinsicProps): Promise<SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
46
46
  export declare function dryRunXcm(request: CreateXcmExtrinsicProps): Promise<DryRunResult>;
47
+ export declare function dryRunPreviewXcm(request: CreateXcmExtrinsicProps): Promise<DryRunResult>;
47
48
  export declare function estimateXcmFee(request: GetXcmFeeRequest): Promise<GetXcmFeeResult | undefined>;
48
49
  export declare function isChainNotSupportPolkadotApi(str: string): boolean;
49
50
  export declare function isChainNotSupportDryRun(str: string): boolean;
50
- export declare const STABLE_XCM_VERSION = 3;
51
- export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, tokenSlug?: string): boolean;
52
51
  export {};
@@ -4,12 +4,14 @@
4
4
  import { fetchParaSpellChainMap } from '@subwallet/extension-base/constants/paraspell-chain-map';
5
5
  import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
6
6
  import { fetchFromProxyService } from '@subwallet/extension-base/utils';
7
+ import BigNumber from 'bignumber.js';
7
8
  import { assert, compactToU8a, isHex, u8aConcat, u8aEq } from '@polkadot/util';
8
9
  const version = '/v4';
9
10
  const paraSpellApi = {
10
11
  buildXcm: `${version}/x-transfer`,
12
+ feeXcm: `${version}/xcm-fee`,
11
13
  dryRunXcm: `${version}/dry-run`,
12
- feeXcm: `${version}/xcm-fee`
14
+ dryRunPreviewXcm: `${version}/dry-run-preview`
13
15
  };
14
16
  function txHexToSubmittableExtrinsic(api, hex) {
15
17
  try {
@@ -151,6 +153,51 @@ export async function dryRunXcm(request) {
151
153
  }
152
154
  return await response.json();
153
155
  }
156
+ export async function dryRunPreviewXcm(request) {
157
+ var _originTokenInfo$meta3;
158
+ const {
159
+ destinationChain,
160
+ originChain,
161
+ originTokenInfo,
162
+ recipient,
163
+ sender,
164
+ sendingValue
165
+ } = request;
166
+ const paraSpellChainMap = await fetchParaSpellChainMap();
167
+ const paraSpellIdentifyV4 = (_originTokenInfo$meta3 = originTokenInfo.metadata) === null || _originTokenInfo$meta3 === void 0 ? void 0 : _originTokenInfo$meta3.paraSpellIdentifyV4;
168
+ if (!paraSpellIdentifyV4) {
169
+ throw new Error('Token is not support XCM at this time');
170
+ }
171
+ const bodyData = {
172
+ senderAddress: sender,
173
+ address: recipient,
174
+ from: paraSpellChainMap[originChain.slug],
175
+ to: paraSpellChainMap[destinationChain.slug],
176
+ currency: createParaSpellCurrency(paraSpellIdentifyV4, sendingValue),
177
+ options: {
178
+ abstractDecimals: false,
179
+ mintFeeAssets: true
180
+ }
181
+ };
182
+ const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.dryRunPreviewXcm, {
183
+ method: 'POST',
184
+ body: JSON.stringify(bodyData),
185
+ headers: {
186
+ 'Content-Type': 'application/json',
187
+ Accept: 'application/json'
188
+ }
189
+ });
190
+ if (!response.ok) {
191
+ const error = await response.json();
192
+ return {
193
+ origin: {
194
+ success: false,
195
+ failureReason: error.message
196
+ }
197
+ };
198
+ }
199
+ return await response.json();
200
+ }
154
201
  export async function estimateXcmFee(request) {
155
202
  var _fromTokenInfo$metada;
156
203
  const {
@@ -163,6 +210,8 @@ export async function estimateXcmFee(request) {
163
210
  } = request;
164
211
  const paraSpellChainMap = await fetchParaSpellChainMap();
165
212
  const paraSpellIdentifyV4 = (_fromTokenInfo$metada = fromTokenInfo.metadata) === null || _fromTokenInfo$metada === void 0 ? void 0 : _fromTokenInfo$metada.paraSpellIdentifyV4;
213
+ const requestValue = BigNumber(value).gt(0) ? value : '1'; // avoid bug in-case estimate fee sendingValue <= 0;
214
+
166
215
  if (!paraSpellIdentifyV4) {
167
216
  console.error('Lack of paraspell metadata');
168
217
  return undefined;
@@ -172,7 +221,7 @@ export async function estimateXcmFee(request) {
172
221
  address: recipient,
173
222
  from: paraSpellChainMap[fromChainInfo.slug],
174
223
  to: paraSpellChainMap[toChainInfo.slug],
175
- currency: createParaSpellCurrency(paraSpellIdentifyV4, value),
224
+ currency: createParaSpellCurrency(paraSpellIdentifyV4, requestValue),
176
225
  options: {
177
226
  abstractDecimals: false
178
227
  }
@@ -192,8 +241,6 @@ export async function estimateXcmFee(request) {
192
241
  return await response.json();
193
242
  }
194
243
  function createParaSpellCurrency(paraSpellIdentifyV4, amount) {
195
- // todo: handle complex conditions for asset has same symbol in a chain: Id, Multi-location, ...
196
- // todo: or update all asset to use multi-location
197
244
  return {
198
245
  ...paraSpellIdentifyV4,
199
246
  amount
@@ -208,15 +255,4 @@ export function isChainNotSupportDryRun(str) {
208
255
  const regex = /(?=.*DryRunApi)(?=.*not available).*/i; // Example: DryRunApi is not available on node Acala
209
256
 
210
257
  return regex.test(str);
211
- }
212
-
213
- // todo: remove
214
- export const STABLE_XCM_VERSION = 3;
215
-
216
- // todo: remove
217
- export function isUseTeleportProtocol(originChainInfo, destChainInfo, tokenSlug) {
218
- const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug) || ['rococo'].includes(originChainInfo.slug) && ['rococo_assethub'].includes(destChainInfo.slug) || ['westend'].includes(originChainInfo.slug) && ['westend_assethub'].includes(destChainInfo.slug);
219
- const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug) || ['rococo'].includes(destChainInfo.slug) && ['rococo_assethub'].includes(originChainInfo.slug) || ['westend'].includes(destChainInfo.slug) && ['westend_assethub'].includes(originChainInfo.slug);
220
- const isXcmMythos = originChainInfo.slug === 'mythos' && destChainInfo.slug === 'statemint' && tokenSlug === 'mythos-NATIVE-MYTH' || originChainInfo.slug === 'statemint' && destChainInfo.slug === 'mythos' && tokenSlug === 'statemint-LOCAL-MYTH';
221
- return relayChainToSystemChain || systemChainToRelayChain || isXcmMythos;
222
258
  }
@@ -1,7 +1,6 @@
1
1
  import { SingleModeJson } from '@subwallet/extension-base/background/KoniTypes';
2
2
  export declare const API_AUTO_CONNECT_MS = 3000;
3
3
  export declare const API_CONNECT_TIMEOUT = 30000;
4
- export declare const API_MAX_RETRY = 2;
5
4
  export declare const _API_OPTIONS_CHAIN_GROUP: {
6
5
  acala: string[];
7
6
  turing: string[];
@@ -22,10 +21,12 @@ export declare const _BALANCE_CHAIN_GROUP: {
22
21
  supportBridged: string[];
23
22
  bittensor: string[];
24
23
  moonbeam: string[];
24
+ notSupportGetBalanceByType: string[];
25
25
  };
26
- export declare const _BALANCE_TOKEN_GROUP: {
27
- crab: string[];
28
- bitcountry: string[];
26
+ export declare const _BALANCE_LOCKED_ID_GROUP: {
27
+ staking: string[];
28
+ gov: string[];
29
+ democracy: string[];
29
30
  };
30
31
  export declare const _NFT_CHAIN_GROUP: {
31
32
  acala: string[];
@@ -59,7 +60,6 @@ export interface _SubstrateUniformEraPayoutInflationParams extends _SubstrateInf
59
60
  }
60
61
  export declare const _SUBSTRATE_DEFAULT_INFLATION_PARAMS: _SubstrateInflationParams;
61
62
  export declare const _KNOWN_CHAIN_INFLATION_PARAMS: Record<string, _SubstrateInflationParams>;
62
- export declare const _TRANSFER_NOT_SUPPORTED_CHAINS: string[];
63
63
  export declare const _TRANSFER_CHAIN_GROUP: {
64
64
  acala: string[];
65
65
  kintsugi: string[];
@@ -74,22 +74,9 @@ export declare const _TRANSFER_CHAIN_GROUP: {
74
74
  disable_transfer: string[];
75
75
  truth: string[];
76
76
  };
77
- export declare const _BALANCE_PARSING_CHAIN_GROUP: {
78
- bobabeam: string[];
79
- };
80
77
  export declare const _MANTA_ZK_CHAIN_GROUP: string[];
81
78
  export declare const _ZK_ASSET_PREFIX = "zk";
82
79
  export declare const _DEFAULT_MANTA_ZK_CHAIN = "calamari";
83
- export declare const _XCM_CHAIN_GROUP: {
84
- polkadotXcm: string[];
85
- polkadotXcmSpecialCases: string[];
86
- xcmPallet: string[];
87
- };
88
- export declare const _XCM_TYPE: {
89
- RP: string;
90
- PP: string;
91
- PR: string;
92
- };
93
80
  export declare const _DEFAULT_ACTIVE_CHAINS: string[];
94
81
  export declare const EVM_PASS_CONNECT_STATUS: Record<string, string[]>;
95
82
  export declare const EVM_REFORMAT_DECIMALS: {
@@ -100,10 +87,4 @@ export declare const _BITCOIN_CHAIN_SLUG = "bitcoin";
100
87
  export declare const _BITCOIN_TESTNET_CHAIN_SLUG = "bitcoinTestnet";
101
88
  export declare const _BITCOIN_NAME = "Bitcoin";
102
89
  export declare const _BITCOIN_TESTNET_NAME = "Bitcoin Testnet";
103
- export declare const _CHAIN_INFO_SRC: string;
104
- export declare const _CHAIN_ASSET_SRC: string;
105
- export declare const _ASSET_REF_SRC: string;
106
- export declare const _MULTI_CHAIN_ASSET_SRC: string;
107
- export declare const _CHAIN_LOGO_MAP_SRC: string;
108
- export declare const _ASSET_LOGO_MAP_SRC: string;
109
90
  export declare const _BTC_SERVICE_TOKEN: string;
@@ -2,11 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { _DEFAULT_CHAINS } from '@subwallet/chain-list';
5
- import { _SubstrateChainType } from '@subwallet/chain-list/types';
6
5
  import { ThemeNames } from '@subwallet/extension-base/background/KoniTypes';
7
6
  export const API_AUTO_CONNECT_MS = 3000;
8
7
  export const API_CONNECT_TIMEOUT = 30000;
9
- export const API_MAX_RETRY = 2;
10
8
  export const _API_OPTIONS_CHAIN_GROUP = {
11
9
  acala: ['acala', 'karura', 'origintrail', 'kintsugi'],
12
10
  turing: ['turingStaging', 'turing'],
@@ -36,11 +34,13 @@ export const _BALANCE_CHAIN_GROUP = {
36
34
  centrifuge: ['centrifuge'],
37
35
  supportBridged: ['rococo_assethub', 'statemint', 'statemine', 'polimec'],
38
36
  bittensor: ['bittensor', 'bittensor_testnet'],
39
- moonbeam: ['moonbeam', 'moonriver', 'moonbase']
37
+ moonbeam: ['moonbeam', 'moonriver', 'moonbase'],
38
+ notSupportGetBalanceByType: ['vara_network', 'vara_testnet', 'availTuringTest', 'avail_mainnet']
40
39
  };
41
- export const _BALANCE_TOKEN_GROUP = {
42
- crab: ['CKTON', 'PKTON'],
43
- bitcountry: ['BIT']
40
+ export const _BALANCE_LOCKED_ID_GROUP = {
41
+ staking: ['staking', 'delegatedStaking', 'pooledStaking', 'stkngdel', 'stk_stks', 'dappStaking', 'parachainStaking', 'appstakeappstake', 'collatorStaking'],
42
+ gov: ['pyconvot'],
43
+ democracy: ['democrac']
44
44
  };
45
45
  export const _NFT_CHAIN_GROUP = {
46
46
  acala: ['acala'],
@@ -274,12 +274,10 @@ export const _KNOWN_CHAIN_INFLATION_PARAMS = {
274
274
 
275
275
  // Send fund------------------------------------------------------------------------------------------------------------
276
276
 
277
- export const _TRANSFER_NOT_SUPPORTED_CHAINS = ['subspace_gemini_3a', 'kulupu', 'joystream', 'equilibrium_parachain', 'genshiro_testnet', 'genshiro'];
278
277
  export const _TRANSFER_CHAIN_GROUP = {
279
278
  acala: ['karura', 'acala', 'acala_testnet'],
280
279
  kintsugi: ['kintsugi', 'kintsugi_test', 'interlay', 'mangatax_para'],
281
280
  genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
282
- // crab: ['crab', 'pangolin'],
283
281
  bitcountry: ['pioneer', 'bitcountry'],
284
282
  statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain', 'westend_assethub', 'chainflip_assethub', 'origintrail', 'xode', 'paseo_assethub'],
285
283
  riochain: ['riochain'],
@@ -290,30 +288,12 @@ export const _TRANSFER_CHAIN_GROUP = {
290
288
  disable_transfer: ['crab', 'pangolin'],
291
289
  truth: ['truth_network']
292
290
  };
293
- export const _BALANCE_PARSING_CHAIN_GROUP = {
294
- bobabeam: ['bobabeam', 'bobabase']
295
- };
296
291
  export const _MANTA_ZK_CHAIN_GROUP = ['calamari'];
297
292
  export const _ZK_ASSET_PREFIX = 'zk';
298
293
  export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
299
294
 
300
295
  // XCM------------------------------------------------------------------------------------------------------------------
301
296
 
302
- export const _XCM_CHAIN_GROUP = {
303
- polkadotXcm: ['statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos', 'westend_assethub'],
304
- polkadotXcmSpecialCases: ['astar', 'shiden'],
305
- xcmPallet: ['polkadot', 'kusama', 'rococo', 'westend']
306
- // default is xTokens pallet
307
- };
308
-
309
- export const _XCM_TYPE = {
310
- RP: `${_SubstrateChainType.RELAYCHAIN}-${_SubstrateChainType.PARACHAIN}`,
311
- // DMP
312
- PP: `${_SubstrateChainType.PARACHAIN}-${_SubstrateChainType.PARACHAIN}`,
313
- // HRMP
314
- PR: `${_SubstrateChainType.PARACHAIN}-${_SubstrateChainType.RELAYCHAIN}` // UMP
315
- };
316
-
317
297
  export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS, 'vara_network', 'ton'];
318
298
  export const EVM_PASS_CONNECT_STATUS = {
319
299
  arbitrum_one: ['*'],
@@ -326,17 +306,8 @@ export const EVM_REFORMAT_DECIMALS = {
326
306
  acala: ['acala_evm', 'karura_evm']
327
307
  };
328
308
  export const LATEST_CHAIN_DATA_FETCHING_INTERVAL = 120000;
329
-
330
- // TODO: review
331
- const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
332
309
  export const _BITCOIN_CHAIN_SLUG = 'bitcoin';
333
310
  export const _BITCOIN_TESTNET_CHAIN_SLUG = 'bitcoinTestnet';
334
311
  export const _BITCOIN_NAME = 'Bitcoin';
335
312
  export const _BITCOIN_TESTNET_NAME = 'Bitcoin Testnet';
336
- export const _CHAIN_INFO_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainInfo.json`;
337
- export const _CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainAsset.json`;
338
- export const _ASSET_REF_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetRef.json`;
339
- export const _MULTI_CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/MultiChainAsset.json`;
340
- export const _CHAIN_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainLogoMap.json`;
341
- export const _ASSET_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetLogoMap.json`;
342
313
  export const _BTC_SERVICE_TOKEN = process.env.BTC_SERVICE_TOKEN || '';
@@ -118,6 +118,9 @@ export class EvmChainHandler extends AbstractChainHandler {
118
118
  tokenContract.methods.symbol().call()]);
119
119
  name = _name;
120
120
  symbol = _symbol;
121
+ if (name === '') {
122
+ contractError = true;
123
+ }
121
124
  } else {
122
125
  tokenContract = new evmApi.api.eth.Contract(_ERC20_ABI, contractAddress);
123
126
  const [_decimals, _symbol, _name] = await Promise.all([
@@ -130,9 +133,9 @@ export class EvmChainHandler extends AbstractChainHandler {
130
133
  name = _name;
131
134
  decimals = new BigN(_decimals).toNumber();
132
135
  symbol = _symbol;
133
- }
134
- if (name === '' || symbol === '') {
135
- contractError = true;
136
+ if (name === '' || symbol === '') {
137
+ contractError = true;
138
+ }
136
139
  }
137
140
  return {
138
141
  name,
@@ -5,6 +5,7 @@ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/K
5
5
  import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
6
6
  import { DEFAULT_YIELD_FIRST_STEP, STAKING_IDENTITY_API_SLUG } from '@subwallet/extension-base/services/earning-service/constants';
7
7
  import { createClaimNotification, createWithdrawNotifications } from '@subwallet/extension-base/services/inapp-notification-service/utils';
8
+ import { BalanceType, YieldPoolType } from '@subwallet/extension-base/types';
8
9
  import { formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
9
10
  import { BN, BN_TEN } from '@polkadot/util';
10
11
  /**
@@ -154,7 +155,12 @@ export default class BasePoolHandler {
154
155
  }
155
156
  const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
156
157
  // Use TRANSFER_BALANCE extrinsic in order to get transferable balanace without minus ED
157
- const nativeTokenBalance = await this.state.balanceService.getTransferableBalance(request.address, this.chain, undefined, ExtrinsicType.TRANSFER_BALANCE);
158
+ let nativeTokenBalance;
159
+ if ([YieldPoolType.NATIVE_STAKING, YieldPoolType.NOMINATION_POOL].includes(poolInfo.type)) {
160
+ nativeTokenBalance = await this.state.balanceService.getBalanceByType(request.address, this.chain, undefined, BalanceType.TOTAL_MINUS_RESERVED, ExtrinsicType.TRANSFER_BALANCE);
161
+ } else {
162
+ nativeTokenBalance = await this.state.balanceService.getTransferableBalance(request.address, this.chain, undefined, ExtrinsicType.TRANSFER_BALANCE);
163
+ }
158
164
  const bnNativeTokenBalance = new BN(nativeTokenBalance.value);
159
165
  const bnMinBalanceToJoin = new BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new BN(poolInfo.metadata.maintainBalance));
160
166
  if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {