@subwallet/extension-base 1.3.30-0 → 1.3.31-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.
- package/background/KoniTypes.d.ts +12 -0
- package/cjs/constants/paraspell-chain-map.js +13 -0
- package/cjs/core/logic-validation/transfer.js +13 -1
- package/cjs/core/substrate/xcm-parser.js +5 -1
- package/cjs/core/utils.js +36 -15
- package/cjs/koni/background/handlers/Extension.js +136 -90
- package/cjs/koni/background/handlers/State.js +8 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/process.js +27 -0
- package/cjs/services/balance-service/index.js +9 -0
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +229 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +96 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +213 -0
- package/cjs/services/chain-service/constants.js +2 -4
- package/cjs/services/chain-service/index.js +71 -17
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/special.js +18 -9
- package/cjs/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/cjs/services/keyring-service/context/state.js +3 -0
- package/cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js +60 -0
- package/cjs/services/migration-service/scripts/EnableChain.js +1 -1
- package/cjs/services/migration-service/scripts/index.js +3 -2
- package/cjs/services/swap-service/handler/base-handler.js +24 -11
- package/cjs/services/transaction-service/utils.js +38 -14
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- package/core/logic-validation/transfer.d.ts +1 -0
- package/core/logic-validation/transfer.js +12 -1
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +4 -1
- package/core/utils.d.ts +2 -2
- package/core/utils.js +36 -15
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +60 -15
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -7
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/process.d.ts +2 -1
- package/services/balance-service/helpers/process.js +26 -0
- package/services/balance-service/index.js +11 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +15 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +216 -0
- package/services/balance-service/transfer/xcm/index.d.ts +5 -1
- package/services/balance-service/transfer/xcm/index.js +85 -1
- package/services/balance-service/transfer/xcm/utils.d.ts +11 -0
- package/services/balance-service/transfer/xcm/utils.js +208 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +1 -2
- package/services/chain-service/index.d.ts +9 -2
- package/services/chain-service/index.js +72 -18
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/special.js +19 -10
- package/services/keyring-service/context/handlers/Ledger.js +1 -1
- package/services/keyring-service/context/state.d.ts +1 -0
- package/services/keyring-service/context/state.js +3 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.d.ts +4 -0
- package/services/migration-service/scripts/DisableZeroBalanceTokens.js +51 -0
- package/services/migration-service/scripts/EnableChain.js +1 -1
- package/services/migration-service/scripts/index.js +3 -2
- package/services/swap-service/handler/base-handler.js +25 -12
- package/services/transaction-service/types.d.ts +3 -2
- package/services/transaction-service/utils.d.ts +1 -0
- package/services/transaction-service/utils.js +38 -15
- package/types/balance/transfer.d.ts +1 -0
- package/types/transaction/request.d.ts +7 -0
- package/utils/fee/transfer.d.ts +1 -0
- package/utils/fee/transfer.js +54 -30
- package/utils/staticData/index.d.ts +4 -1
- package/utils/staticData/index.js +5 -1
- package/utils/staticData/paraSpellChainMap.json +1 -0
|
@@ -428,7 +428,7 @@ export default class KoniState {
|
|
|
428
428
|
const chainState = this.chainService.getChainStateByKey(networkKey);
|
|
429
429
|
if (authUrls[shortenUrl]) {
|
|
430
430
|
if (chainInfo && !_isChainEnabled(chainState)) {
|
|
431
|
-
await this.
|
|
431
|
+
await this.enableChainWithPriorityAssets(networkKey);
|
|
432
432
|
}
|
|
433
433
|
authUrls[shortenUrl].currentEvmNetworkKey = networkKey;
|
|
434
434
|
this.setAuthorize(authUrls);
|
|
@@ -699,6 +699,12 @@ export default class KoniState {
|
|
|
699
699
|
}
|
|
700
700
|
return this.chainService.enableChain(chainSlug);
|
|
701
701
|
}
|
|
702
|
+
async enableChainWithPriorityAssets(chainSlug, enableTokens = true) {
|
|
703
|
+
if (enableTokens) {
|
|
704
|
+
await this.chainService.updatePriorityAssetsByChain(chainSlug, true);
|
|
705
|
+
}
|
|
706
|
+
return this.chainService.enableChain(chainSlug);
|
|
707
|
+
}
|
|
702
708
|
resetDefaultChains() {
|
|
703
709
|
const defaultChains = this.getDefaultNetworkKeys();
|
|
704
710
|
return this.chainService.resetChainInfoMap(defaultChains);
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.31-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -129,6 +129,11 @@
|
|
|
129
129
|
"require": "./cjs/constants/i18n.js",
|
|
130
130
|
"default": "./constants/i18n.js"
|
|
131
131
|
},
|
|
132
|
+
"./constants/paraspell-chain-map": {
|
|
133
|
+
"types": "./constants/paraspell-chain-map.d.ts",
|
|
134
|
+
"require": "./cjs/constants/paraspell-chain-map.js",
|
|
135
|
+
"default": "./constants/paraspell-chain-map.js"
|
|
136
|
+
},
|
|
132
137
|
"./constants/remind-notification-time": {
|
|
133
138
|
"types": "./constants/remind-notification-time.d.ts",
|
|
134
139
|
"require": "./cjs/constants/remind-notification-time.js",
|
|
@@ -739,6 +744,11 @@
|
|
|
739
744
|
"require": "./cjs/services/balance-service/transfer/xcm/index.js",
|
|
740
745
|
"default": "./services/balance-service/transfer/xcm/index.js"
|
|
741
746
|
},
|
|
747
|
+
"./services/balance-service/transfer/xcm/acrossBridge": {
|
|
748
|
+
"types": "./services/balance-service/transfer/xcm/acrossBridge/index.d.ts",
|
|
749
|
+
"require": "./cjs/services/balance-service/transfer/xcm/acrossBridge/index.js",
|
|
750
|
+
"default": "./services/balance-service/transfer/xcm/acrossBridge/index.js"
|
|
751
|
+
},
|
|
742
752
|
"./services/balance-service/transfer/xcm/availBridge": {
|
|
743
753
|
"types": "./services/balance-service/transfer/xcm/availBridge.d.ts",
|
|
744
754
|
"require": "./cjs/services/balance-service/transfer/xcm/availBridge.js",
|
|
@@ -1401,6 +1411,11 @@
|
|
|
1401
1411
|
"require": "./cjs/services/migration-service/scripts/DeleteEarningData.js",
|
|
1402
1412
|
"default": "./services/migration-service/scripts/DeleteEarningData.js"
|
|
1403
1413
|
},
|
|
1414
|
+
"./services/migration-service/scripts/DisableZeroBalanceTokens": {
|
|
1415
|
+
"types": "./services/migration-service/scripts/DisableZeroBalanceTokens.d.ts",
|
|
1416
|
+
"require": "./cjs/services/migration-service/scripts/DisableZeroBalanceTokens.js",
|
|
1417
|
+
"default": "./services/migration-service/scripts/DisableZeroBalanceTokens.js"
|
|
1418
|
+
},
|
|
1404
1419
|
"./services/migration-service/scripts/EnableChain": {
|
|
1405
1420
|
"types": "./services/migration-service/scripts/EnableChain.d.ts",
|
|
1406
1421
|
"require": "./cjs/services/migration-service/scripts/EnableChain.js",
|
|
@@ -2615,6 +2630,7 @@
|
|
|
2615
2630
|
"./utils/staticData/currencySymbol.json": "./utils/staticData/currencySymbol.json",
|
|
2616
2631
|
"./utils/staticData/marketingCampaigns.json": "./utils/staticData/marketingCampaigns.json",
|
|
2617
2632
|
"./utils/staticData/oldChainPrefix.json": "./utils/staticData/oldChainPrefix.json",
|
|
2633
|
+
"./utils/staticData/paraSpellChainMap.json": "./utils/staticData/paraSpellChainMap.json",
|
|
2618
2634
|
"./utils/staticData/remindNotificationTime.json": "./utils/staticData/remindNotificationTime.json",
|
|
2619
2635
|
"./utils/staticData/termAndCondition.json": "./utils/staticData/termAndCondition.json",
|
|
2620
2636
|
"./utils/swap": {
|
|
@@ -2663,13 +2679,13 @@
|
|
|
2663
2679
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2664
2680
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2665
2681
|
"@substrate/connect": "^0.8.9",
|
|
2666
|
-
"@subwallet/chain-list": "0.2.
|
|
2667
|
-
"@subwallet/extension-base": "^1.3.
|
|
2668
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2669
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2670
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2682
|
+
"@subwallet/chain-list": "0.2.103",
|
|
2683
|
+
"@subwallet/extension-base": "^1.3.31-0",
|
|
2684
|
+
"@subwallet/extension-chains": "^1.3.31-0",
|
|
2685
|
+
"@subwallet/extension-dapp": "^1.3.31-0",
|
|
2686
|
+
"@subwallet/extension-inject": "^1.3.31-0",
|
|
2671
2687
|
"@subwallet/keyring": "^0.1.9",
|
|
2672
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2688
|
+
"@subwallet/subwallet-api-sdk": "^1.3.31-0",
|
|
2673
2689
|
"@subwallet/ui-keyring": "^0.1.9",
|
|
2674
2690
|
"@ton/core": "^0.56.3",
|
|
2675
2691
|
"@ton/crypto": "^3.2.0",
|
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.
|
|
10
|
+
version: '1.3.31-0'
|
|
11
11
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
import { CommonOptimalTransferPath } from '@subwallet/extension-base/types/service-base';
|
|
@@ -11,3 +11,4 @@ export interface RequestOptimalTransferProcess {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function getDefaultTransferProcess(): CommonOptimalTransferPath;
|
|
13
13
|
export declare function getSnowbridgeTransferProcessFromEvm(address: string, evmApi: _EvmApi, tokenInfo: _ChainAsset, amount: string): Promise<CommonOptimalTransferPath>;
|
|
14
|
+
export declare function getAcrossbridgeTransferProcessFromEvm(originChainInfo: _ChainInfo): Promise<CommonOptimalTransferPath>;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
5
|
import { CommonStepType, DEFAULT_FIRST_STEP, MOCK_STEP_FEE } from '@subwallet/extension-base/types/service-base';
|
|
6
|
+
import { _getEvmChainId } from "../../chain-service/utils/index.js";
|
|
7
|
+
import { SpokePoolMapping } from "../transfer/xcm/acrossBridge/index.js";
|
|
6
8
|
export function getDefaultTransferProcess() {
|
|
7
9
|
return {
|
|
8
10
|
totalFee: [MOCK_STEP_FEE, MOCK_STEP_FEE],
|
|
@@ -34,6 +36,30 @@ export async function getSnowbridgeTransferProcessFromEvm(address, evmApi, token
|
|
|
34
36
|
// if (!allowance || BigInt(allowance) < BigInt(amount)) {
|
|
35
37
|
// }
|
|
36
38
|
|
|
39
|
+
result.steps.push({
|
|
40
|
+
id: result.steps.length,
|
|
41
|
+
type: CommonStepType.TRANSFER,
|
|
42
|
+
name: 'Transfer'
|
|
43
|
+
});
|
|
44
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
45
|
+
return Promise.resolve(result);
|
|
46
|
+
}
|
|
47
|
+
export async function getAcrossbridgeTransferProcessFromEvm(originChainInfo) {
|
|
48
|
+
const chainId = _getEvmChainId(originChainInfo);
|
|
49
|
+
const SpokePoolAddress = SpokePoolMapping[chainId].SpokePool.address;
|
|
50
|
+
const result = {
|
|
51
|
+
totalFee: [MOCK_STEP_FEE],
|
|
52
|
+
steps: [DEFAULT_FIRST_STEP]
|
|
53
|
+
};
|
|
54
|
+
result.steps.push({
|
|
55
|
+
id: result.steps.length,
|
|
56
|
+
type: CommonStepType.TOKEN_APPROVAL,
|
|
57
|
+
name: 'Approve spending',
|
|
58
|
+
metadata: {
|
|
59
|
+
SpokePoolAddress
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
result.totalFee.push(MOCK_STEP_FEE);
|
|
37
63
|
result.steps.push({
|
|
38
64
|
id: result.steps.length,
|
|
39
65
|
type: CommonStepType.TRANSFER,
|
|
@@ -5,9 +5,9 @@ import { BalanceError } from '@subwallet/extension-base/background/errors/Balanc
|
|
|
5
5
|
import { APIItemState, BalanceErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
8
|
-
import { getDefaultTransferProcess, getSnowbridgeTransferProcessFromEvm } from '@subwallet/extension-base/services/balance-service/helpers/process';
|
|
8
|
+
import { getAcrossbridgeTransferProcessFromEvm, getDefaultTransferProcess, getSnowbridgeTransferProcessFromEvm } from '@subwallet/extension-base/services/balance-service/helpers/process';
|
|
9
9
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
10
|
-
import { _getChainNativeTokenSlug, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { _getChainNativeTokenSlug, _isNativeToken, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
11
|
import DetectAccountBalanceStore from '@subwallet/extension-base/stores/DetectAccountBalance';
|
|
12
12
|
import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwallet/extension-base/utils';
|
|
13
13
|
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
@@ -18,6 +18,7 @@ import BigN from 'bignumber.js';
|
|
|
18
18
|
import { t } from 'i18next';
|
|
19
19
|
import { BehaviorSubject } from 'rxjs';
|
|
20
20
|
import { noop } from '@polkadot/util';
|
|
21
|
+
import { _isAcrossChainBridge } from "./transfer/xcm/acrossBridge/index.js";
|
|
21
22
|
import { BalanceMapImpl } from "./BalanceMapImpl.js";
|
|
22
23
|
import { subscribeBalance } from "./helpers/index.js";
|
|
23
24
|
|
|
@@ -571,6 +572,14 @@ export class BalanceService {
|
|
|
571
572
|
const tokenInfo = this.state.chainService.getAssetBySlug(params.tokenSlug);
|
|
572
573
|
return getSnowbridgeTransferProcessFromEvm(params.address, evmApi, tokenInfo, params.amount);
|
|
573
574
|
}
|
|
575
|
+
|
|
576
|
+
// Across Bridge
|
|
577
|
+
if (_isAcrossChainBridge(originChainInfo.slug, destChainInfo.slug)) {
|
|
578
|
+
const tokenInfo = this.state.chainService.getAssetBySlug(params.tokenSlug);
|
|
579
|
+
if (!_isNativeToken(tokenInfo)) {
|
|
580
|
+
return getAcrossbridgeTransferProcessFromEvm(originChainInfo);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
574
583
|
return getDefaultTransferProcess();
|
|
575
584
|
}
|
|
576
585
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CreateXcmExtrinsicProps } from '..';
|
|
2
|
+
export declare function _isAcrossChainBridge(srcChain: string, destChain: string): boolean;
|
|
3
|
+
export declare function _isAcrossTestnetBridge(srcChain: string): boolean;
|
|
4
|
+
export declare const SpokePoolMapping: Record<number, {
|
|
5
|
+
SpokePool: {
|
|
6
|
+
address: string;
|
|
7
|
+
blockNumber: number;
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
interface AcrossQuote {
|
|
11
|
+
outputAmount: string;
|
|
12
|
+
rate: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const getAcrossQuote: ({ destinationChain, destinationTokenInfo, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<AcrossQuote>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,216 @@
|
|
|
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 { _isAcrossBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
6
|
+
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
7
|
+
// Across Bridge
|
|
8
|
+
const acrossPairsMap = new Map([[COMMON_CHAIN_SLUGS.ETHEREUM, new Set(['optimism', 'base_mainnet', 'arbitrum_one'])], ['optimism', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'base_mainnet', 'arbitrum_one'])], ['base_mainnet', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'optimism', 'arbitrum_one'])], ['arbitrum_one', new Set([COMMON_CHAIN_SLUGS.ETHEREUM, 'optimism', 'base_mainnet'])], [COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA, new Set(['base_sepolia', 'arbitrum_sepolia'])],
|
|
9
|
+
// TESTNET START HERE
|
|
10
|
+
['base_sepolia', new Set([COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA])], ['arbitrum_sepolia', new Set([COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA])]]);
|
|
11
|
+
export function _isAcrossChainBridge(srcChain, destChain) {
|
|
12
|
+
var _acrossPairsMap$get$h, _acrossPairsMap$get;
|
|
13
|
+
return (_acrossPairsMap$get$h = (_acrossPairsMap$get = acrossPairsMap.get(srcChain)) === null || _acrossPairsMap$get === void 0 ? void 0 : _acrossPairsMap$get.has(destChain)) !== null && _acrossPairsMap$get$h !== void 0 ? _acrossPairsMap$get$h : false;
|
|
14
|
+
}
|
|
15
|
+
export function _isAcrossTestnetBridge(srcChain) {
|
|
16
|
+
return srcChain === 'base_sepolia' || srcChain === 'arbitrum_sepolia' || srcChain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
|
|
17
|
+
}
|
|
18
|
+
export const SpokePoolMapping = {
|
|
19
|
+
1: {
|
|
20
|
+
SpokePool: {
|
|
21
|
+
address: '0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5',
|
|
22
|
+
blockNumber: 17117454
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
10: {
|
|
26
|
+
SpokePool: {
|
|
27
|
+
address: '0x6f26Bf09B1C792e3228e5467807a900A503c0281',
|
|
28
|
+
blockNumber: 93903076
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
11155111: {
|
|
32
|
+
SpokePool: {
|
|
33
|
+
address: '0x5ef6C01E11889d86803e0B23e3cB3F9E9d97B662',
|
|
34
|
+
blockNumber: 5288470
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
11155420: {
|
|
38
|
+
SpokePool: {
|
|
39
|
+
address: '0x4e8E101924eDE233C13e2D8622DC8aED2872d505',
|
|
40
|
+
blockNumber: 7762656
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
1135: {
|
|
44
|
+
SpokePool: {
|
|
45
|
+
address: '0x9552a0a6624A23B848060AE5901659CDDa1f83f8',
|
|
46
|
+
blockNumber: 2602337
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
130: {
|
|
50
|
+
SpokePool: {
|
|
51
|
+
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
52
|
+
blockNumber: 7915488
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
137: {
|
|
56
|
+
SpokePool: {
|
|
57
|
+
address: '0x9295ee1d8C5b022Be115A2AD3c30C72E34e7F096',
|
|
58
|
+
blockNumber: 41908657
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
168587773: {
|
|
62
|
+
SpokePool: {
|
|
63
|
+
address: '0x5545092553Cf5Bf786e87a87192E902D50D8f022',
|
|
64
|
+
blockNumber: 7634204
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
1868: {
|
|
68
|
+
SpokePool: {
|
|
69
|
+
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
70
|
+
blockNumber: 1709997
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
288: {
|
|
74
|
+
SpokePool: {
|
|
75
|
+
address: '0xBbc6009fEfFc27ce705322832Cb2068F8C1e0A58',
|
|
76
|
+
blockNumber: 619993
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
324: {
|
|
80
|
+
SpokePool: {
|
|
81
|
+
address: '0xE0B015E54d54fc84a6cB9B666099c46adE9335FF',
|
|
82
|
+
blockNumber: 10352565
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
34443: {
|
|
86
|
+
SpokePool: {
|
|
87
|
+
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
88
|
+
blockNumber: 8043187
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
37111: {
|
|
92
|
+
SpokePool: {
|
|
93
|
+
address: '0x6A0a7f39530923911832Dd60667CE5da5449967B',
|
|
94
|
+
blockNumber: 156275
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
41455: {
|
|
98
|
+
SpokePool: {
|
|
99
|
+
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
100
|
+
blockNumber: 4240318
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
4202: {
|
|
104
|
+
SpokePool: {
|
|
105
|
+
address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
|
|
106
|
+
blockNumber: 7267988
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
42161: {
|
|
110
|
+
SpokePool: {
|
|
111
|
+
address: '0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A',
|
|
112
|
+
blockNumber: 83868041
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
421614: {
|
|
116
|
+
SpokePool: {
|
|
117
|
+
address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
|
|
118
|
+
blockNumber: 12411026
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
480: {
|
|
122
|
+
SpokePool: {
|
|
123
|
+
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
124
|
+
blockNumber: 4524742
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
534352: {
|
|
128
|
+
SpokePool: {
|
|
129
|
+
address: '0x3baD7AD0728f9917d1Bf08af5782dCbD516cDd96',
|
|
130
|
+
blockNumber: 7489705
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
57073: {
|
|
134
|
+
SpokePool: {
|
|
135
|
+
address: '0xeF684C38F94F48775959ECf2012D7E864ffb9dd4',
|
|
136
|
+
blockNumber: 1139240
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
59144: {
|
|
140
|
+
SpokePool: {
|
|
141
|
+
address: '0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75',
|
|
142
|
+
blockNumber: 2721169
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
690: {
|
|
146
|
+
SpokePool: {
|
|
147
|
+
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
148
|
+
blockNumber: 5512122
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
7777777: {
|
|
152
|
+
SpokePool: {
|
|
153
|
+
address: '0x13fDac9F9b4777705db45291bbFF3c972c6d1d97',
|
|
154
|
+
blockNumber: 18382867
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
80002: {
|
|
158
|
+
SpokePool: {
|
|
159
|
+
address: '0xd08baaE74D6d2eAb1F3320B2E1a53eeb391ce8e5',
|
|
160
|
+
blockNumber: 7529960
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
81457: {
|
|
164
|
+
SpokePool: {
|
|
165
|
+
address: '0x2D509190Ed0172ba588407D4c2df918F955Cc6E1',
|
|
166
|
+
blockNumber: 5574280
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
8453: {
|
|
170
|
+
SpokePool: {
|
|
171
|
+
address: '0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64',
|
|
172
|
+
blockNumber: 2164878
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
84532: {
|
|
176
|
+
SpokePool: {
|
|
177
|
+
address: '0x82B564983aE7274c86695917BBf8C99ECb6F0F8F',
|
|
178
|
+
blockNumber: 6082004
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
919: {
|
|
182
|
+
SpokePool: {
|
|
183
|
+
address: '0xbd886FC0725Cc459b55BbFEb3E4278610331f83b',
|
|
184
|
+
blockNumber: 13999465
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// Calculate fee for across bridge transfer
|
|
189
|
+
export const getAcrossQuote = async ({
|
|
190
|
+
destinationChain,
|
|
191
|
+
destinationTokenInfo,
|
|
192
|
+
originChain,
|
|
193
|
+
originTokenInfo,
|
|
194
|
+
recipient,
|
|
195
|
+
sender,
|
|
196
|
+
sendingValue
|
|
197
|
+
}) => {
|
|
198
|
+
const isAcrossBridgeXcm = _isAcrossBridgeXcm(originChain, destinationChain);
|
|
199
|
+
console.log('sendingValue', sendingValue);
|
|
200
|
+
if (!isAcrossBridgeXcm) {
|
|
201
|
+
throw new Error('This is not a valid AcrossBridge transfer');
|
|
202
|
+
}
|
|
203
|
+
if (!sender) {
|
|
204
|
+
throw new Error('Sender is required');
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
var _subwalletApiSdk$xcmA;
|
|
208
|
+
const data = await ((_subwalletApiSdk$xcmA = subwalletApiSdk.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
|
|
209
|
+
if (!data || !data.metadata) {
|
|
210
|
+
throw new Error('Failed to get AcrossBridge quote');
|
|
211
|
+
}
|
|
212
|
+
return data.metadata;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
return Promise.reject(error);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { DryRunInfo } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
2
3
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
4
|
import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
|
|
4
5
|
import { TransactionConfig } from 'web3-core';
|
|
@@ -15,9 +16,12 @@ export declare type CreateXcmExtrinsicProps = {
|
|
|
15
16
|
substrateApi?: _SubstrateApi;
|
|
16
17
|
feeInfo: FeeInfo;
|
|
17
18
|
} & TransactionFee;
|
|
18
|
-
export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig>;
|
|
19
|
+
export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig | undefined>;
|
|
19
20
|
export declare const createSnowBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
21
|
export declare const createXcmExtrinsic: ({ destinationChain, originChain, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
21
22
|
export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo, feeOption, originChain, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
22
23
|
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
23
24
|
export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
25
|
+
export declare const createXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | undefined>;
|
|
26
|
+
export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<DryRunInfo>;
|
|
27
|
+
export declare const createAcrossBridgeExtrinsic: ({ destinationChain, destinationTokenInfo, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { _isAcrossBridgeXcm, _isPolygonBridgeXcm, _isPosBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
6
|
import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
7
|
import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
|
|
7
8
|
import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
8
9
|
import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
|
|
10
|
+
import { buildXcm, dryRunXcmV2, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
9
11
|
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
|
|
10
12
|
import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
|
|
11
13
|
import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
12
14
|
import { _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
15
|
+
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
16
|
+
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
13
17
|
import { _createPosBridgeL1toL2Extrinsic, _createPosBridgeL2toL1Extrinsic } from "./posBridge.js";
|
|
14
18
|
// SnowBridge
|
|
15
19
|
export const createSnowBridgeExtrinsic = async ({
|
|
@@ -111,4 +115,84 @@ export const createPolygonBridgeExtrinsic = async ({
|
|
|
111
115
|
const sourceChain = originChain.slug;
|
|
112
116
|
const createExtrinsic = isPolygonBridgeXcm ? sourceChain === 'polygonzkEvm_cardona' || sourceChain === 'polygonZkEvm' ? _createPolygonBridgeL2toL1Extrinsic : _createPolygonBridgeL1toL2Extrinsic : sourceChain === 'polygon_amoy' || sourceChain === 'polygon' ? _createPosBridgeL2toL1Extrinsic : _createPosBridgeL1toL2Extrinsic;
|
|
113
117
|
return createExtrinsic(originTokenInfo, originChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
|
|
118
|
+
};
|
|
119
|
+
export const createXcmExtrinsicV2 = async request => {
|
|
120
|
+
try {
|
|
121
|
+
return await buildXcm(request);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.log('createXcmExtrinsicV2 error: ', e);
|
|
124
|
+
const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred';
|
|
125
|
+
if (isChainNotSupportPolkadotApi(errorMessage)) {
|
|
126
|
+
return createXcmExtrinsic(request);
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
export const dryRunXcmExtrinsicV2 = async request => {
|
|
132
|
+
try {
|
|
133
|
+
return await dryRunXcmV2(request);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred';
|
|
136
|
+
if (isChainNotSupportDryRun(errorMessage) || isChainNotSupportPolkadotApi(errorMessage)) {
|
|
137
|
+
const xcmTransfer = await createXcmExtrinsicV2(request);
|
|
138
|
+
if (!xcmTransfer) {
|
|
139
|
+
return {
|
|
140
|
+
success: false
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const _xcmFeeInfo = await xcmTransfer.paymentInfo(request.sender);
|
|
144
|
+
const xcmFeeInfo = _xcmFeeInfo.toPrimitive();
|
|
145
|
+
|
|
146
|
+
// skip dry run in this case
|
|
147
|
+
return {
|
|
148
|
+
success: true,
|
|
149
|
+
fee: Math.round(xcmFeeInfo.partialFee * XCM_MIN_AMOUNT_RATIO).toString()
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
success: false
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
export const createAcrossBridgeExtrinsic = async ({
|
|
158
|
+
destinationChain,
|
|
159
|
+
destinationTokenInfo,
|
|
160
|
+
evmApi,
|
|
161
|
+
feeCustom,
|
|
162
|
+
feeInfo,
|
|
163
|
+
feeOption,
|
|
164
|
+
originChain,
|
|
165
|
+
originTokenInfo,
|
|
166
|
+
recipient,
|
|
167
|
+
sender,
|
|
168
|
+
sendingValue
|
|
169
|
+
}) => {
|
|
170
|
+
const isAcrossBridgeXcm = _isAcrossBridgeXcm(originChain, destinationChain);
|
|
171
|
+
if (!isAcrossBridgeXcm) {
|
|
172
|
+
throw new Error('This is not a valid AcrossBridge transfer');
|
|
173
|
+
}
|
|
174
|
+
if (!evmApi) {
|
|
175
|
+
throw new Error('Evm API is not available');
|
|
176
|
+
}
|
|
177
|
+
if (!sender) {
|
|
178
|
+
throw new Error('Sender is required');
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
var _subwalletApiSdk$xcmA;
|
|
182
|
+
const data = await ((_subwalletApiSdk$xcmA = subwalletApiSdk.xcmApi) === null || _subwalletApiSdk$xcmA === void 0 ? void 0 : _subwalletApiSdk$xcmA.fetchXcmData(sender, originTokenInfo.slug, destinationTokenInfo.slug, recipient, sendingValue));
|
|
183
|
+
const _feeCustom = feeCustom;
|
|
184
|
+
const feeCombine = combineEthFee(feeInfo, feeOption, _feeCustom);
|
|
185
|
+
const transactionConfig = {
|
|
186
|
+
from: data === null || data === void 0 ? void 0 : data.sender,
|
|
187
|
+
to: data === null || data === void 0 ? void 0 : data.to,
|
|
188
|
+
value: data === null || data === void 0 ? void 0 : data.value,
|
|
189
|
+
data: data === null || data === void 0 ? void 0 : data.transferEncodedCall,
|
|
190
|
+
...feeCombine
|
|
191
|
+
};
|
|
192
|
+
const gasLimit = await evmApi.api.eth.estimateGas(transactionConfig).catch(() => 200000);
|
|
193
|
+
transactionConfig.gas = gasLimit.toString();
|
|
194
|
+
return transactionConfig;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return Promise.reject(error);
|
|
197
|
+
}
|
|
114
198
|
};
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { CreateXcmExtrinsicProps } from '@subwallet/extension-base/services/balance-service/transfer/xcm/index';
|
|
3
|
+
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
4
|
+
export interface DryRunInfo {
|
|
5
|
+
success: boolean;
|
|
6
|
+
fee?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildXcm(request: CreateXcmExtrinsicProps): Promise<SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
9
|
+
export declare function dryRunXcm(request: CreateXcmExtrinsicProps): Promise<DryRunInfo>;
|
|
10
|
+
export declare function dryRunXcmV2(request: CreateXcmExtrinsicProps): Promise<DryRunInfo>;
|
|
11
|
+
export declare function isChainNotSupportPolkadotApi(str: string): boolean;
|
|
12
|
+
export declare function isChainNotSupportDryRun(str: string): boolean;
|
|
2
13
|
export declare const STABLE_XCM_VERSION = 3;
|
|
3
14
|
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, tokenSlug?: string): boolean;
|