@subwallet/extension-base 1.3.11-0 → 1.3.12-1

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 (47) hide show
  1. package/background/KoniTypes.d.ts +3 -0
  2. package/cjs/core/substrate/xcm-parser.js +16 -2
  3. package/cjs/koni/api/contract-handler/utils/index.js +29 -1
  4. package/cjs/koni/background/handlers/Extension.js +16 -4
  5. package/cjs/packageInfo.js +1 -1
  6. package/cjs/services/balance-service/transfer/smart-contract.js +2 -0
  7. package/cjs/services/balance-service/transfer/xcm/index.js +6 -6
  8. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +2 -2
  9. package/cjs/services/balance-service/transfer/xcm/posBridge.js +144 -0
  10. package/cjs/services/chain-service/utils/patch.js +1 -1
  11. package/cjs/services/earning-service/constants/chains.js +4 -2
  12. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -1
  13. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -2
  14. package/cjs/services/inapp-notification-service/index.js +2 -0
  15. package/cjs/services/inapp-notification-service/utils/polygon.js +1 -1
  16. package/cjs/services/keyring-service/context/handlers/Ledger.js +3 -1
  17. package/cjs/services/transaction-service/utils.js +3 -0
  18. package/cjs/utils/number.js +7 -2
  19. package/constants/staking.d.ts +4 -0
  20. package/core/substrate/xcm-parser.d.ts +1 -0
  21. package/core/substrate/xcm-parser.js +15 -2
  22. package/koni/api/contract-handler/utils/index.d.ts +4 -0
  23. package/koni/api/contract-handler/utils/index.js +24 -0
  24. package/koni/api/contract-handler/utils/pos_bridge_abi.json +783 -0
  25. package/koni/api/contract-handler/utils/pos_bridge_l2_abi.json +793 -0
  26. package/koni/background/handlers/Extension.js +18 -6
  27. package/package.json +13 -6
  28. package/packageInfo.js +1 -1
  29. package/services/balance-service/transfer/smart-contract.js +2 -0
  30. package/services/balance-service/transfer/xcm/index.js +7 -7
  31. package/services/balance-service/transfer/xcm/polygonBridge.js +2 -2
  32. package/services/balance-service/transfer/xcm/posBridge.d.ts +14 -0
  33. package/services/balance-service/transfer/xcm/posBridge.js +131 -0
  34. package/services/chain-service/utils/patch.js +1 -1
  35. package/services/earning-service/constants/chains.d.ts +1 -0
  36. package/services/earning-service/constants/chains.js +2 -1
  37. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -1
  38. package/services/earning-service/handlers/liquid-staking/bifrost.js +3 -3
  39. package/services/inapp-notification-service/index.js +2 -0
  40. package/services/inapp-notification-service/interfaces.d.ts +7 -6
  41. package/services/inapp-notification-service/utils/polygon.d.ts +6 -6
  42. package/services/inapp-notification-service/utils/polygon.js +1 -1
  43. package/services/keyring-service/context/handlers/Ledger.js +3 -1
  44. package/services/transaction-service/utils.js +3 -0
  45. package/types/account/info/keyring.d.ts +2 -0
  46. package/utils/number.d.ts +1 -0
  47. package/utils/number.js +4 -0
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { Common } from '@ethereumjs/common';
5
5
  import { LegacyTransaction } from '@ethereumjs/tx';
6
+ import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
6
7
  import { _AssetType } from '@subwallet/chain-list/types';
7
8
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
8
9
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
@@ -29,16 +30,17 @@ import { createTonTransaction } from '@subwallet/extension-base/services/balance
29
30
  import { createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsic, getXcmMockTxFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
30
31
  import { getClaimTxOnAvail, getClaimTxOnEthereum, isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
31
32
  import { _isPolygonChainBridge, getClaimPolygonBridge, isClaimedPolygonBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
33
+ import { _isPosChainBridge, getClaimPosBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
32
34
  import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX, SUFFICIENT_CHAIN } from '@subwallet/extension-base/services/chain-service/constants';
33
35
  import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
34
- import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isAssetSmartContractNft, _isBridgedToken, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
36
+ import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getTokenMinAmount, _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isAssetSmartContractNft, _isBridgedToken, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
35
37
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
36
38
  import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
37
39
  import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
38
40
  import { SWStorage } from '@subwallet/extension-base/storage';
39
41
  import { AccountsStore } from '@subwallet/extension-base/stores';
40
42
  import { BasicTxErrorType, BasicTxWarningCode, StakingTxErrorType, YieldPoolType } from '@subwallet/extension-base/types';
41
- import { _analyzeAddress, BN_ZERO, combineAllAccountProxy, createTransactionFromRLP, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
43
+ import { _analyzeAddress, BN_ZERO, combineAllAccountProxy, createTransactionFromRLP, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, toBNString, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
42
44
  import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
43
45
  import { metadataExpand } from '@subwallet/extension-chains';
44
46
  import { getKeypairTypeByAddress, isAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
@@ -1262,6 +1264,7 @@ export default class KoniExtension {
1262
1264
  const isAvailBridgeFromAvail = isAvailChainBridge(originNetworkKey) && _isPureEvmChain(chainInfoMap[destinationNetworkKey]);
1263
1265
  const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
1264
1266
  const isPolygonBridgeTransfer = _isPolygonChainBridge(originNetworkKey, destinationNetworkKey);
1267
+ const isPosBridgeTransfer = _isPosChainBridge(originNetworkKey, destinationNetworkKey);
1265
1268
  let additionalValidator;
1266
1269
  let eventsHandler;
1267
1270
  if (fromKeyPair && destinationTokenInfo) {
@@ -1278,7 +1281,7 @@ export default class KoniExtension {
1278
1281
  evmApi
1279
1282
  };
1280
1283
  let funcCreateExtrinsic;
1281
- if (isPolygonBridgeTransfer) {
1284
+ if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
1282
1285
  funcCreateExtrinsic = createPolygonBridgeExtrinsic;
1283
1286
  } else if (isSnowBridgeEvmTransfer) {
1284
1287
  funcCreateExtrinsic = createSnowBridgeExtrinsic;
@@ -1345,7 +1348,7 @@ export default class KoniExtension {
1345
1348
  transaction: extrinsic,
1346
1349
  data: inputData,
1347
1350
  extrinsicType: ExtrinsicType.TRANSFER_XCM,
1348
- chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
1351
+ chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
1349
1352
  transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
1350
1353
  ignoreWarnings,
1351
1354
  isTransferAll: transferAll,
@@ -1562,6 +1565,10 @@ export default class KoniExtension {
1562
1565
  const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
1563
1566
  const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
1564
1567
  const existentialDeposit = originTokenInfo.minAmount || '0';
1568
+
1569
+ // todo: improve this case. Currently set 1 AVAIL for covering fee as default.
1570
+ const isSpecialBridgeFromAvail = originTokenInfo.slug === 'avail_mainnet-NATIVE-AVAIL' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM;
1571
+ const specialBridgeFromAvailFee = new BigN(toBNString(1, _getAssetDecimals(originTokenInfo))).minus(new BigN(_getTokenMinAmount(originTokenInfo)));
1565
1572
  if (destinationTokenInfo) {
1566
1573
  const [bnMockExecutionFee, {
1567
1574
  value
@@ -1572,7 +1579,7 @@ export default class KoniExtension {
1572
1579
  token: originTokenInfo.slug
1573
1580
  })]);
1574
1581
  const bnMaxTransferable = new BigN(value);
1575
- const estimatedFee = bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO).plus(new BigN(existentialDeposit));
1582
+ const estimatedFee = isSpecialBridgeFromAvail ? specialBridgeFromAvailFee : bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO).plus(new BigN(existentialDeposit));
1576
1583
  return bnMaxTransferable.minus(estimatedFee);
1577
1584
  }
1578
1585
  return new BigN(0);
@@ -3447,7 +3454,12 @@ export default class KoniExtension {
3447
3454
  const extrinsicType = ExtrinsicType.CLAIM_BRIDGE;
3448
3455
  let transaction = null;
3449
3456
  const evmApi = this.#koniState.getEvmApi(chain);
3450
- transaction = await getClaimPolygonBridge(chain, notification, evmApi);
3457
+ const metadata = notification.metadata;
3458
+ if (metadata.bridgeType === 'POS') {
3459
+ transaction = await getClaimPosBridge(chain, notification, evmApi);
3460
+ } else {
3461
+ transaction = await getClaimPolygonBridge(chain, notification, evmApi);
3462
+ }
3451
3463
  const chainType = ChainType.EVM;
3452
3464
  return await this.#koniState.transactionService.handleTransaction({
3453
3465
  address,
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.3.11-0",
20
+ "version": "1.3.12-1",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -272,6 +272,8 @@
272
272
  "./koni/api/contract-handler/utils/neuroguns_psp34_abi.json": "./koni/api/contract-handler/utils/neuroguns_psp34_abi.json",
273
273
  "./koni/api/contract-handler/utils/pink_psp34_abi.json": "./koni/api/contract-handler/utils/pink_psp34_abi.json",
274
274
  "./koni/api/contract-handler/utils/polygon_bridge_abi.json": "./koni/api/contract-handler/utils/polygon_bridge_abi.json",
275
+ "./koni/api/contract-handler/utils/pos_bridge_abi.json": "./koni/api/contract-handler/utils/pos_bridge_abi.json",
276
+ "./koni/api/contract-handler/utils/pos_bridge_l2_abi.json": "./koni/api/contract-handler/utils/pos_bridge_l2_abi.json",
275
277
  "./koni/api/contract-handler/utils/psp22_abi.json": "./koni/api/contract-handler/utils/psp22_abi.json",
276
278
  "./koni/api/contract-handler/utils/psp34_abi.json": "./koni/api/contract-handler/utils/psp34_abi.json",
277
279
  "./koni/api/contract-handler/utils/snowbridge_gateway_abi.json": "./koni/api/contract-handler/utils/snowbridge_gateway_abi.json",
@@ -722,6 +724,11 @@
722
724
  "require": "./cjs/services/balance-service/transfer/xcm/polygonBridge.js",
723
725
  "default": "./services/balance-service/transfer/xcm/polygonBridge.js"
724
726
  },
727
+ "./services/balance-service/transfer/xcm/posBridge": {
728
+ "types": "./services/balance-service/transfer/xcm/posBridge.d.ts",
729
+ "require": "./cjs/services/balance-service/transfer/xcm/posBridge.js",
730
+ "default": "./services/balance-service/transfer/xcm/posBridge.js"
731
+ },
725
732
  "./services/balance-service/transfer/xcm/snowBridge": {
726
733
  "types": "./services/balance-service/transfer/xcm/snowBridge.d.ts",
727
734
  "require": "./cjs/services/balance-service/transfer/xcm/snowBridge.js",
@@ -2496,11 +2503,11 @@
2496
2503
  "@reduxjs/toolkit": "^1.9.1",
2497
2504
  "@sora-substrate/type-definitions": "^1.17.7",
2498
2505
  "@substrate/connect": "^0.8.9",
2499
- "@subwallet/chain-list": "0.2.96",
2500
- "@subwallet/extension-base": "^1.3.11-0",
2501
- "@subwallet/extension-chains": "^1.3.11-0",
2502
- "@subwallet/extension-dapp": "^1.3.11-0",
2503
- "@subwallet/extension-inject": "^1.3.11-0",
2506
+ "@subwallet/chain-list": "0.2.97",
2507
+ "@subwallet/extension-base": "^1.3.12-1",
2508
+ "@subwallet/extension-chains": "^1.3.12-1",
2509
+ "@subwallet/extension-dapp": "^1.3.12-1",
2510
+ "@subwallet/extension-inject": "^1.3.12-1",
2504
2511
  "@subwallet/keyring": "^0.1.8-beta.0",
2505
2512
  "@subwallet/ui-keyring": "^0.1.8-beta.0",
2506
2513
  "@ton/core": "^0.56.3",
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.3.11-0'
10
+ version: '1.3.12-1'
11
11
  };
@@ -58,6 +58,8 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
58
58
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
59
59
  erc20Contract.methods.transfer(to, transferValue).estimateGas({
60
60
  from
61
+ }).catch(() => {
62
+ throw Error('Unable to estimate fee for this transaction. Try again or contact support at agent@subwallet.app');
61
63
  }), calculateGasFeeParams(evmApi, networkKey)]);
62
64
  const transactionObject = {
63
65
  gas: gasLimit,
@@ -1,7 +1,7 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { _isPolygonBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
4
+ import { _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
6
  import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
7
7
  import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
@@ -13,6 +13,7 @@ import { _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base
13
13
  import BigN from 'bignumber.js';
14
14
  import { u8aToHex } from '@polkadot/util';
15
15
  import { addressToEvm } from '@polkadot/util-crypto';
16
+ import { _createPosBridgeL1toL2Extrinsic, _createPosBridgeL2toL1Extrinsic } from "./posBridge.js";
16
17
  export const createSnowBridgeExtrinsic = async ({
17
18
  chainInfoMap,
18
19
  destinationTokenInfo,
@@ -97,7 +98,9 @@ export const createPolygonBridgeExtrinsic = async ({
97
98
  }) => {
98
99
  const originChainInfo = chainInfoMap[originTokenInfo.originChain];
99
100
  const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
100
- if (!_isPolygonBridgeXcm(originChainInfo, destinationChainInfo)) {
101
+ const isPolygonBridgeXcm = _isPolygonBridgeXcm(originChainInfo, destinationChainInfo);
102
+ const isValidBridge = isPolygonBridgeXcm || _isPosBridgeXcm(originChainInfo, destinationChainInfo);
103
+ if (!isValidBridge) {
101
104
  throw new Error('This is not a valid PolygonBridge transfer');
102
105
  }
103
106
  if (!evmApi) {
@@ -107,11 +110,8 @@ export const createPolygonBridgeExtrinsic = async ({
107
110
  throw Error('Sender is required');
108
111
  }
109
112
  const sourceChain = originChainInfo.slug;
110
- if (sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm') {
111
- return _createPolygonBridgeL2toL1Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
112
- } else {
113
- return _createPolygonBridgeL1toL2Extrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
114
- }
113
+ const createExtrinsic = isPolygonBridgeXcm ? sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm' ? _createPolygonBridgeL2toL1Extrinsic : _createPolygonBridgeL1toL2Extrinsic : sourceChain === 'polygon_amoy' || sourceChain === 'polygon' ? _createPosBridgeL2toL1Extrinsic : _createPosBridgeL1toL2Extrinsic;
114
+ return createExtrinsic(originTokenInfo, originChainInfo, sender, recipient, sendingValue, evmApi);
115
115
  };
116
116
  export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
117
117
  try {
@@ -48,13 +48,13 @@ export async function _createPolygonBridgeL2toL1Extrinsic(tokenInfo, originChain
48
48
  return createPolygonBridgeTransaction(tokenInfo, originChainInfo, sender, recipientAddress, value, 0, evmApi);
49
49
  }
50
50
  export async function getClaimPolygonBridge(chainSlug, notification, evmApi) {
51
- var _priority$maxFeePerGa2, _priority$maxPriority2;
51
+ var _metadata$sourceNetwo, _metadata$counter, _priority$maxFeePerGa2, _priority$maxPriority2;
52
52
  const polygonBridgeContractAddress = getPolygonBridgeContract(chainSlug);
53
53
  const polygonBridgeContract = getWeb3Contract(polygonBridgeContractAddress, evmApi, _POLYGON_BRIDGE_ABI);
54
54
  const metadata = notification.metadata;
55
55
  const isTestnet = chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
56
56
  const proofDomain = isTestnet ? POLYGON_PROOF_INDEXER.TESTNET : POLYGON_PROOF_INDEXER.MAINNET;
57
- const proofResponse = await fetch(`${proofDomain}?networkId=${metadata.sourceNetwork}&depositCount=${metadata.counter}`).then(res => res.json());
57
+ const proofResponse = await fetch(`${proofDomain}?networkId=${(_metadata$sourceNetwo = metadata.sourceNetwork) !== null && _metadata$sourceNetwo !== void 0 ? _metadata$sourceNetwo : ''}&depositCount=${(_metadata$counter = metadata.counter) !== null && _metadata$counter !== void 0 ? _metadata$counter : ''}`).then(res => res.json());
58
58
  const proof = proofResponse.proof;
59
59
 
60
60
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
@@ -0,0 +1,14 @@
1
+ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
+ import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
3
+ import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
4
+ import { TransactionConfig } from 'web3-core';
5
+ export declare const POS_EXIT_PAYLOAD_INDEXER: {
6
+ MAINNET: string;
7
+ TESTNET: string;
8
+ };
9
+ export declare function _createPosBridgeL1toL2Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
10
+ export declare function _createPosBridgeL2toL1Extrinsic(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
11
+ export declare function getClaimPosBridge(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi): Promise<TransactionConfig>;
12
+ export declare function isClaimedPosBridge(id: string, address: string, isTestnet: boolean): Promise<boolean>;
13
+ export declare function _isPosChainBridge(srcChain: string, destChain: string): boolean;
14
+ export declare function _isPosChainL2Bridge(srcChain: string, destChain: string): boolean;
@@ -0,0 +1,131 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
5
+ import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
6
+ import { _POS_BRIDGE_ABI, _POS_BRIDGE_L2_ABI, getPosL1BridgeContract, getPosL2BridgeContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
7
+ import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
8
+ import { fetchPolygonBridgeTransactions } from '@subwallet/extension-base/services/inapp-notification-service/utils';
9
+ import { BasicTxErrorType } from '@subwallet/extension-base/types';
10
+ export const POS_EXIT_PAYLOAD_INDEXER = {
11
+ MAINNET: 'https://proof-generator.polygon.technology/api/v1/matic/exit-payload',
12
+ TESTNET: 'https://proof-generator.polygon.technology/api/v1/amoy/exit-payload'
13
+ };
14
+ export async function _createPosBridgeL1toL2Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
15
+ var _priority$maxFeePerGa, _priority$maxPriority;
16
+ const posBridgeContractAddress = getPosL1BridgeContract(originChainInfo.slug);
17
+ const posBridgeContract = getWeb3Contract(posBridgeContractAddress, evmApi, _POS_BRIDGE_ABI);
18
+
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
20
+ const transferCall = posBridgeContract.methods.depositEtherFor(recipientAddress);
21
+ const transferEncodedCall = transferCall.encodeABI();
22
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
23
+ const transactionConfig = {
24
+ from: sender,
25
+ to: posBridgeContractAddress,
26
+ value: value,
27
+ data: transferEncodedCall,
28
+ gasPrice: priority.gasPrice,
29
+ maxFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
30
+ maxPriorityFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
31
+ };
32
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
33
+ transactionConfig.gas = gasLimit.toString();
34
+ return transactionConfig;
35
+ }
36
+ export async function _createPosBridgeL2toL1Extrinsic(tokenInfo, originChainInfo, sender, recipientAddress, value, evmApi) {
37
+ var _priority$maxFeePerGa2, _priority$maxPriority2;
38
+ const posBridgeContractAddress = getPosL2BridgeContract(originChainInfo.slug);
39
+ const posBridgeContract = getWeb3Contract(posBridgeContractAddress, evmApi, _POS_BRIDGE_L2_ABI);
40
+
41
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
42
+ const transferCall = posBridgeContract.methods.withdraw(value);
43
+ const transferEncodedCall = transferCall.encodeABI();
44
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
45
+ const transactionConfig = {
46
+ from: sender,
47
+ to: posBridgeContractAddress,
48
+ value: undefined,
49
+ data: transferEncodedCall,
50
+ gasPrice: priority.gasPrice,
51
+ maxFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
52
+ maxPriorityFeePerGas: priority === null || priority === void 0 ? void 0 : (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
53
+ };
54
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
55
+ transactionConfig.gas = gasLimit.toString();
56
+ return transactionConfig;
57
+ }
58
+ export async function getClaimPosBridge(chainSlug, notification, evmApi) {
59
+ var _event$arguments, _event$arguments$, _event$arguments$$top, _priority$maxFeePerGa3, _priority$maxPriority3;
60
+ const posBridgeContractAddress = getPosL2BridgeContract(chainSlug);
61
+ const posBridgeContract = getWeb3Contract(posBridgeContractAddress, evmApi, _POS_BRIDGE_L2_ABI);
62
+ const metadata = notification.metadata;
63
+
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
65
+ const event = posBridgeContract.events.Transfer(metadata.userAddress, metadata.userAddress, metadata.amounts[0]);
66
+ const isTestnet = chainSlug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
67
+ const domain = isTestnet ? POS_EXIT_PAYLOAD_INDEXER.TESTNET : POS_EXIT_PAYLOAD_INDEXER.MAINNET;
68
+ const eventSignature = event === null || event === void 0 ? void 0 : (_event$arguments = event.arguments) === null || _event$arguments === void 0 ? void 0 : (_event$arguments$ = _event$arguments[0]) === null || _event$arguments$ === void 0 ? void 0 : (_event$arguments$$top = _event$arguments$.topics) === null || _event$arguments$$top === void 0 ? void 0 : _event$arguments$$top[0];
69
+ let inputData;
70
+ try {
71
+ const res = await fetch(`${domain}/${metadata.transactionHash}?eventSignature=${eventSignature}`);
72
+ inputData = await res.json();
73
+ if (inputData.error && inputData.message.includes('not been checkpointed yet')) {
74
+ throw new Error(`${inputData.message}. Please try again later.`);
75
+ }
76
+ } catch (err) {
77
+ console.error('Error:', err);
78
+ throw new Error(BasicTxErrorType.INTERNAL_ERROR);
79
+ }
80
+ const posClaimContractAddress = getPosL1BridgeContract(chainSlug);
81
+ const posClaimContract = getWeb3Contract(posClaimContractAddress, evmApi, _POS_BRIDGE_ABI);
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
84
+ const transferCall = posClaimContract.methods.exit(inputData.result);
85
+ const transferEncodedCall = transferCall.encodeABI();
86
+ const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
87
+ const transactionConfig = {
88
+ from: metadata.userAddress,
89
+ to: posClaimContractAddress,
90
+ value: '0',
91
+ data: transferEncodedCall,
92
+ gasPrice: priority.gasPrice,
93
+ maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
94
+ maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString()
95
+ };
96
+ const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
97
+ transactionConfig.gas = gasLimit.toString();
98
+ return transactionConfig;
99
+ }
100
+ export async function isClaimedPosBridge(id, address, isTestnet) {
101
+ try {
102
+ const isClaimableBridge = await fetchPolygonBridgeTransactions(address, isTestnet);
103
+ if (isClaimableBridge && isClaimableBridge.success) {
104
+ const isIdClaimable = isClaimableBridge.result.some(transaction => transaction._id === id);
105
+ return !isIdClaimable;
106
+ }
107
+ } catch (err) {
108
+ console.error('Error:', err);
109
+ }
110
+ return false;
111
+ }
112
+ export function _isPosChainBridge(srcChain, destChain) {
113
+ if (srcChain === 'polygon_amoy' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
114
+ return true;
115
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA && destChain === 'polygon_amoy') {
116
+ return true;
117
+ } else if (srcChain === 'polygon' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM) {
118
+ return true;
119
+ } else if (srcChain === COMMON_CHAIN_SLUGS.ETHEREUM && destChain === 'polygon') {
120
+ return true;
121
+ }
122
+ return false;
123
+ }
124
+ export function _isPosChainL2Bridge(srcChain, destChain) {
125
+ if (srcChain === 'polygon_amoy' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
126
+ return true;
127
+ } else if (srcChain === 'polygon' && destChain === COMMON_CHAIN_SLUGS.ETHEREUM) {
128
+ return true;
129
+ }
130
+ return false;
131
+ }
@@ -5,7 +5,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
5
5
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
6
6
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
7
7
  const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
8
- const ChainListVersion = '0.2.96'; // update this when build chainlist
8
+ const ChainListVersion = '0.2.97'; // update this when build chainlist
9
9
 
10
10
  // todo: move this interface to chainlist
11
11
 
@@ -19,3 +19,4 @@ export declare const MaxEraRewardPointsEras = 14;
19
19
  export declare const ST_LIQUID_TOKEN_ABI: Record<string, any>;
20
20
  export declare const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
21
21
  export declare const MANTA_MIN_DELEGATION = 500;
22
+ export declare const CHANNEL_ID = 7;
@@ -25,4 +25,5 @@ export const MaxEraRewardPointsEras = 14;
25
25
  // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
26
26
  export const ST_LIQUID_TOKEN_ABI = require("./abis/st_liquid_token_abi.json");
27
27
  export const MANTA_VALIDATOR_POINTS_PER_BLOCK = 20;
28
- export const MANTA_MIN_DELEGATION = 500;
28
+ export const MANTA_MIN_DELEGATION = 500;
29
+ export const CHANNEL_ID = 7;
@@ -3,6 +3,7 @@
3
3
 
4
4
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { _getAssetDecimals, _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
6
+ import { CHANNEL_ID } from '@subwallet/extension-base/services/earning-service/constants';
6
7
  import { YieldStepType } from '@subwallet/extension-base/types';
7
8
  import BifrostLiquidStakingPoolHandler from "./bifrost.js";
8
9
  const STATS_URL = 'https://api.bifrost.app/api/site';
@@ -98,7 +99,7 @@ export default class BifrostMantaLiquidStakingPoolHandler extends BifrostLiquidS
98
99
  const substrateApi = await this.substrateApi.isReady;
99
100
  const inputTokenSlug = this.inputAsset;
100
101
  const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
101
- const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined, undefined);
102
+ const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined, CHANNEL_ID);
102
103
  return {
103
104
  txChain: this.chain,
104
105
  extrinsicType: ExtrinsicType.MINT_VMANTA,
@@ -4,7 +4,7 @@
4
4
  import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
5
  import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
6
6
  import { _getAssetDecimals, _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
7
- import { fakeAddress } from '@subwallet/extension-base/services/earning-service/constants';
7
+ import { CHANNEL_ID, fakeAddress } from '@subwallet/extension-base/services/earning-service/constants';
8
8
  import { EarningStatus, UnstakingStatus, YieldStepType } from '@subwallet/extension-base/types';
9
9
  import { reformatAddress } from '@subwallet/extension-base/utils';
10
10
  import BigNumber from 'bignumber.js';
@@ -244,7 +244,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
244
244
  const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
245
245
  const defaultFeeTokenSlug = this.feeAssets[0];
246
246
  if (new BN(params.amount).gt(BN_ZERO)) {
247
- const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), params.amount, undefined, undefined).paymentInfo(fakeAddress);
247
+ const _mintFeeInfo = await poolOriginSubstrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), params.amount, undefined, CHANNEL_ID).paymentInfo(fakeAddress);
248
248
  const mintFeeInfo = _mintFeeInfo.toPrimitive();
249
249
  return {
250
250
  amount: mintFeeInfo.partialFee.toString(),
@@ -261,7 +261,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
261
261
  const substrateApi = await this.substrateApi.isReady;
262
262
  const inputTokenSlug = this.inputAsset;
263
263
  const inputTokenInfo = this.state.getAssetBySlug(inputTokenSlug);
264
- const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined, undefined);
264
+ const extrinsic = substrateApi.api.tx.vtokenMinting.mint(_getTokenOnChainInfo(inputTokenInfo), data.amount, undefined, CHANNEL_ID);
265
265
  return {
266
266
  txChain: this.chain,
267
267
  extrinsicType: ExtrinsicType.MINT_VDOT,
@@ -276,6 +276,7 @@ export class InappNotificationService {
276
276
  const {
277
277
  _id,
278
278
  amounts,
279
+ bridgeType,
279
280
  counter,
280
281
  destinationNetwork,
281
282
  originTokenAddress,
@@ -292,6 +293,7 @@ export class InappNotificationService {
292
293
  tokenSlug: token.slug,
293
294
  _id,
294
295
  amounts,
296
+ bridgeType,
295
297
  counter,
296
298
  destinationNetwork,
297
299
  originTokenAddress,
@@ -59,15 +59,16 @@ export interface ClaimPolygonBridgeNotificationMetadata {
59
59
  tokenSlug: string;
60
60
  _id: string;
61
61
  amounts: string[];
62
- counter: number;
62
+ bridgeType: string;
63
+ counter?: number;
63
64
  destinationNetwork: number;
64
- originTokenAddress: string;
65
- originTokenNetwork: number;
66
- receiver: string;
67
- sourceNetwork: number;
65
+ originTokenAddress?: string;
66
+ originTokenNetwork?: number;
67
+ receiver?: string;
68
+ sourceNetwork?: number;
68
69
  status: BridgeTransactionStatus;
69
70
  transactionHash: string;
70
- transactionInitiator: string;
71
+ transactionInitiator?: string;
71
72
  userAddress: string;
72
73
  }
73
74
  export declare enum NotificationTimePeriod {
@@ -6,7 +6,7 @@ export declare const POLYGON_BRIDGE_INDEXER: {
6
6
  export interface PolygonTransaction {
7
7
  _id: string;
8
8
  transactionIndex?: number;
9
- sourceNetwork: number;
9
+ sourceNetwork?: number;
10
10
  destinationNetwork: number;
11
11
  blockNumber: number;
12
12
  amounts: string[];
@@ -20,16 +20,16 @@ export interface PolygonTransaction {
20
20
  userAddress: string;
21
21
  wrappedTokenAddress?: string;
22
22
  wrappedTokenNetwork?: number;
23
- counter: number;
23
+ counter?: number;
24
24
  bridgeContractAddress?: string;
25
25
  eventInitiatorAddress?: string;
26
26
  globalExitRootManager?: string;
27
27
  leaf?: string;
28
28
  mainnetExitRoot?: string;
29
29
  metadata?: string;
30
- originTokenAddress: string;
31
- originTokenNetwork: number;
32
- receiver: string;
30
+ originTokenAddress?: string;
31
+ originTokenNetwork?: number;
32
+ receiver?: string;
33
33
  refuel: boolean;
34
34
  rollUpExitRoot?: string;
35
35
  nonce?: any;
@@ -38,7 +38,7 @@ export interface PolygonTransaction {
38
38
  claimTransactionBlockNumber?: number;
39
39
  claimTransactionHash?: string;
40
40
  claimTransactionTimestamp?: string;
41
- transactionInitiator: string;
41
+ transactionInitiator?: string;
42
42
  }
43
43
  interface PaginationData {
44
44
  hasNextPage: boolean;
@@ -18,7 +18,7 @@ export async function fetchPolygonBridgeTransactions(userAddress, isTestnet, pag
18
18
  pageSize: pageSize.toString(),
19
19
  page: page.toString()
20
20
  });
21
- const networkIds = [0, 1];
21
+ const networkIds = [0, 1, -1];
22
22
  networkIds.forEach(networkId => {
23
23
  params.append('destinationNetworkIds', networkId.toString());
24
24
  params.append('sourceNetworkIds', networkId.toString());
@@ -94,6 +94,7 @@ export class AccountLedgerHandler extends AccountBaseHandler {
94
94
  hardwareType,
95
95
  isEthereum,
96
96
  isGeneric,
97
+ isLedgerRecovery,
97
98
  name,
98
99
  originGenesisHash
99
100
  } = account;
@@ -104,7 +105,8 @@ export class AccountLedgerHandler extends AccountBaseHandler {
104
105
  addressOffset,
105
106
  genesisHash,
106
107
  originGenesisHash,
107
- isGeneric
108
+ isGeneric,
109
+ isLedgerRecovery
108
110
  };
109
111
  const type = isEthereum ? 'ethereum' : 'sr25519';
110
112
  const pair = keyring.keyring.createFromAddress(address, {
@@ -31,6 +31,9 @@ function getBlockExplorerAccountRoute(explorerLink) {
31
31
  if (explorerLink.includes('tangle.statescan.io')) {
32
32
  return '#/accounts';
33
33
  }
34
+ if (explorerLink.includes('laos.statescan.io')) {
35
+ return '#/accounts';
36
+ }
34
37
  if (explorerLink.includes('explorer.zkverify.io')) {
35
38
  return 'account';
36
39
  }
@@ -52,6 +52,8 @@ export interface AccountLedgerData {
52
52
  originGenesisHash?: string | null;
53
53
  /** Ledger's availableGenesisHashes */
54
54
  availableGenesisHashes?: string[];
55
+ /** Is Ledger recovery chain */
56
+ isLedgerRecovery?: boolean;
55
57
  }
56
58
  /**
57
59
  * @interface AccountInjectData
package/utils/number.d.ts CHANGED
@@ -9,6 +9,7 @@ export interface NumberFormatter {
9
9
  export declare const balanceFormatter: NumberFormatter;
10
10
  export declare const balanceNoPrefixFormater: NumberFormatter;
11
11
  export declare const PREDEFINED_FORMATTER: Record<string, NumberFormatter>;
12
+ export declare const toBNString: (input: string | number | BigNumber, decimal: number) => string;
12
13
  /** @function formatNumber
13
14
  * Convert number to a formatted string by dividing by 10^decimal
14
15
  * @param {string | number | BigNumber} input - Input number
package/utils/number.js CHANGED
@@ -182,6 +182,10 @@ export const balanceNoPrefixFormater = (input, metadata) => {
182
182
  export const PREDEFINED_FORMATTER = {
183
183
  balance: balanceFormatter
184
184
  };
185
+ export const toBNString = (input, decimal) => {
186
+ const raw = new BigNumber(input);
187
+ return raw.multipliedBy(BN_TEN.pow(decimal)).toFixed();
188
+ };
185
189
 
186
190
  /** @function formatNumber
187
191
  * Convert number to a formatted string by dividing by 10^decimal