@subwallet/extension-base 1.3.40-0 → 1.3.41-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/cjs/constants/environment.js +4 -2
- package/cjs/koni/background/handlers/Extension.js +37 -38
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/cjs/services/balance-service/transfer/xcm/index.js +15 -9
- package/cjs/services/balance-service/transfer/xcm/utils.js +12 -14
- package/cjs/services/chain-service/constants.js +4 -3
- package/cjs/services/chain-service/handler/CardanoApi.js +25 -35
- package/cjs/services/earning-service/handlers/native-staking/tao.js +4 -38
- package/cjs/services/swap-service/handler/chainflip-handler.js +29 -18
- package/cjs/services/swap-service/handler/kyber-handler.js +5 -9
- package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -7
- package/cjs/services/swap-service/handler/uniswap-handler.js +5 -12
- package/cjs/services/swap-service/utils.js +46 -37
- package/cjs/types/environment.js +19 -0
- package/cjs/utils/environment.js +30 -2
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/koni/background/handlers/Extension.js +37 -38
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/services/balance-service/transfer/xcm/index.js +15 -9
- package/services/balance-service/transfer/xcm/utils.d.ts +2 -0
- package/services/balance-service/transfer/xcm/utils.js +12 -14
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +4 -3
- package/services/chain-service/handler/CardanoApi.d.ts +1 -5
- package/services/chain-service/handler/CardanoApi.js +26 -34
- package/services/earning-service/handlers/native-staking/tao.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/tao.js +4 -24
- package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
- package/services/swap-service/handler/chainflip-handler.js +25 -13
- package/services/swap-service/handler/kyber-handler.d.ts +0 -1
- package/services/swap-service/handler/kyber-handler.js +5 -8
- package/services/swap-service/handler/simpleswap-handler.d.ts +0 -1
- package/services/swap-service/handler/simpleswap-handler.js +4 -6
- package/services/swap-service/handler/uniswap-handler.js +6 -13
- package/services/swap-service/utils.d.ts +0 -13
- package/services/swap-service/utils.js +46 -34
- package/types/environment.d.ts +9 -0
- package/types/environment.js +13 -0
- package/utils/environment.d.ts +2 -0
- package/utils/environment.js +27 -1
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.SimpleSwapHandler = void 0;
|
|
7
7
|
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
8
8
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
9
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
10
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
11
|
var _types = require("@subwallet/extension-base/types");
|
|
12
|
+
var _environment = require("@subwallet/extension-base/types/environment");
|
|
12
13
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
13
14
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
14
15
|
var _bignumber = _interopRequireWildcard(require("bignumber.js"));
|
|
@@ -20,9 +21,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
20
21
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
21
22
|
// SPDX-License-Identifier: Apache-2.0
|
|
22
23
|
|
|
23
|
-
const apiUrl = 'https://api.simpleswap.io/v3';
|
|
24
|
-
const simpleSwapApiKey = process.env.SIMPLE_SWAP_API_KEY || '';
|
|
25
|
-
exports.simpleSwapApiKey = simpleSwapApiKey;
|
|
26
24
|
const toBNString = (input, decimal) => {
|
|
27
25
|
const raw = new _bignumber.BigNumber(input);
|
|
28
26
|
return raw.shiftedBy(decimal).integerValue(_bignumber.BigNumber.ROUND_CEIL).toFixed();
|
|
@@ -54,12 +52,11 @@ const buildTxForSimpleSwap = async params => {
|
|
|
54
52
|
userRefundAddress: sender,
|
|
55
53
|
userRefundExtraId: ''
|
|
56
54
|
};
|
|
57
|
-
const response = await
|
|
55
|
+
const response = await (0, _utils2.fetchFromProxyService)(_environment.ProxyServiceRoute.SIMPLESWAP, '/exchanges', {
|
|
58
56
|
method: 'POST',
|
|
59
57
|
headers: {
|
|
60
|
-
accept: 'application/json',
|
|
61
58
|
'Content-Type': 'application/json',
|
|
62
|
-
'
|
|
59
|
+
accept: 'application/json'
|
|
63
60
|
},
|
|
64
61
|
body: JSON.stringify(requestBody)
|
|
65
62
|
});
|
|
@@ -13,6 +13,7 @@ var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/
|
|
|
13
13
|
var _acrossBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge");
|
|
14
14
|
var _utils = require("@subwallet/extension-base/services/swap-service/utils");
|
|
15
15
|
var _types = require("@subwallet/extension-base/types");
|
|
16
|
+
var _environment = require("@subwallet/extension-base/types/environment");
|
|
16
17
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
17
18
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
18
19
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
@@ -22,10 +23,6 @@ var _baseHandler = require("./base-handler");
|
|
|
22
23
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
23
24
|
// SPDX-License-Identifier: Apache-2.0
|
|
24
25
|
|
|
25
|
-
const API_URL = 'https://trade-api.gateway.uniswap.org/v1';
|
|
26
|
-
const headers = {
|
|
27
|
-
'x-api-key': process.env.UNISWAP_API_KEY || ''
|
|
28
|
-
};
|
|
29
26
|
async function fetchCheckApproval(request) {
|
|
30
27
|
const {
|
|
31
28
|
address,
|
|
@@ -56,10 +53,9 @@ async function fetchCheckApproval(request) {
|
|
|
56
53
|
} else {
|
|
57
54
|
return undefined;
|
|
58
55
|
}
|
|
59
|
-
const response = await
|
|
56
|
+
const response = await (0, _utils2.fetchFromProxyService)(_environment.ProxyServiceRoute.UNISWAP, '/check_approval', {
|
|
60
57
|
method: 'POST',
|
|
61
58
|
headers: {
|
|
62
|
-
...headers,
|
|
63
59
|
'Content-Type': 'application/json'
|
|
64
60
|
},
|
|
65
61
|
body: JSON.stringify({
|
|
@@ -624,10 +620,9 @@ class UniswapHandler {
|
|
|
624
620
|
if (permitData) {
|
|
625
621
|
body.permitData = permitData;
|
|
626
622
|
}
|
|
627
|
-
postTransactionResponse = await
|
|
623
|
+
postTransactionResponse = await (0, _utils2.fetchFromProxyService)(_environment.ProxyServiceRoute.UNISWAP, '/swap', {
|
|
628
624
|
method: 'POST',
|
|
629
625
|
headers: {
|
|
630
|
-
...headers,
|
|
631
626
|
'Content-Type': 'application/json'
|
|
632
627
|
},
|
|
633
628
|
body: JSON.stringify(body)
|
|
@@ -638,10 +633,9 @@ class UniswapHandler {
|
|
|
638
633
|
const dutchQuote = quote;
|
|
639
634
|
const submitSwapOrder = async () => {
|
|
640
635
|
try {
|
|
641
|
-
const res = await
|
|
636
|
+
const res = await (0, _utils2.fetchFromProxyService)(_environment.ProxyServiceRoute.UNISWAP, '/order', {
|
|
642
637
|
method: 'POST',
|
|
643
638
|
headers: {
|
|
644
|
-
...headers,
|
|
645
639
|
'Content-Type': 'application/json'
|
|
646
640
|
},
|
|
647
641
|
body: JSON.stringify({
|
|
@@ -682,10 +676,9 @@ class UniswapHandler {
|
|
|
682
676
|
const swapper = dutchQuote.orderInfo.swapper;
|
|
683
677
|
return retryGetUniswapTx(async () => {
|
|
684
678
|
try {
|
|
685
|
-
const response = await
|
|
679
|
+
const response = await (0, _utils2.fetchFromProxyService)(_environment.ProxyServiceRoute.UNISWAP, `/orders?orderId=${orderId}&swapper=${swapper}`, {
|
|
686
680
|
method: 'GET',
|
|
687
681
|
headers: {
|
|
688
|
-
...headers,
|
|
689
682
|
'Content-Type': 'application/json'
|
|
690
683
|
}
|
|
691
684
|
});
|
|
@@ -13,9 +13,6 @@ exports.findSwapTransitDestination = findSwapTransitDestination;
|
|
|
13
13
|
exports.getAmountAfterSlippage = getAmountAfterSlippage;
|
|
14
14
|
exports.getBridgeStep = getBridgeStep;
|
|
15
15
|
exports.getChainRouteFromSteps = getChainRouteFromSteps;
|
|
16
|
-
exports.getChainflipBroker = getChainflipBroker;
|
|
17
|
-
exports.getChainflipOptions = getChainflipOptions;
|
|
18
|
-
exports.getChainflipSwap = getChainflipSwap;
|
|
19
16
|
exports.getFirstAmountFromSteps = getFirstAmountFromSteps;
|
|
20
17
|
exports.getLastAmountFromSteps = getLastAmountFromSteps;
|
|
21
18
|
exports.getSupportedSwapChains = getSupportedSwapChains;
|
|
@@ -29,7 +26,6 @@ exports.processStepsToPathActions = processStepsToPathActions;
|
|
|
29
26
|
var _chainList = require("@subwallet/chain-list");
|
|
30
27
|
var _types = require("@subwallet/chain-list/types");
|
|
31
28
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
32
|
-
var _chainflipHandler = require("@subwallet/extension-base/services/swap-service/handler/chainflip-handler");
|
|
33
29
|
var _types2 = require("@subwallet/extension-base/types");
|
|
34
30
|
var _swap = require("@subwallet/extension-base/types/swap");
|
|
35
31
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
@@ -105,39 +101,52 @@ function convertSwapRate(rate, fromAsset, toAsset) {
|
|
|
105
101
|
const bnRate = (0, _bignumber.default)(rate);
|
|
106
102
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
107
103
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
104
|
+
|
|
105
|
+
// export function getChainflipOptions (isTestnet: boolean) {
|
|
106
|
+
// if (isTestnet) {
|
|
107
|
+
// return {
|
|
108
|
+
// network: getChainflipNetwork(isTestnet)
|
|
109
|
+
// };
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
// return {
|
|
113
|
+
// network: getChainflipNetwork(isTestnet),
|
|
114
|
+
// broker: getChainflipBroker(isTestnet)
|
|
115
|
+
// };
|
|
116
|
+
// }
|
|
117
|
+
|
|
118
|
+
// function getChainflipNetwork (isTestnet: boolean) {
|
|
119
|
+
// return isTestnet ? 'perseverance' : 'mainnet';
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// export function getChainflipBroker (isTestnet: boolean) { // noted: currently not use testnet broker
|
|
123
|
+
// if (isTestnet) {
|
|
124
|
+
// return {
|
|
125
|
+
// url: `https://perseverance.chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
126
|
+
// };
|
|
127
|
+
// } else {
|
|
128
|
+
// return {
|
|
129
|
+
// url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
130
|
+
// };
|
|
131
|
+
// }
|
|
132
|
+
// }
|
|
133
|
+
|
|
134
|
+
// export function getChainflipSwap (isTestnet: boolean) {
|
|
135
|
+
// if (isTestnet) {
|
|
136
|
+
// return `https://perseverance.chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
|
|
137
|
+
// } else {
|
|
138
|
+
// return `https://chainflip-broker.io/swap?apikey=${CHAINFLIP_BROKER_API}`;
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// export function getAssetsUrl (isTestnet: boolean) {
|
|
143
|
+
// if (isTestnet) {
|
|
144
|
+
// return 'https://perseverance.chainflip-broker.io/assets';
|
|
145
|
+
// } else {
|
|
146
|
+
// return 'https://chainflip-broker.io/assets';
|
|
147
|
+
// }
|
|
148
|
+
// }
|
|
149
|
+
|
|
141
150
|
function getBridgeStep(from, to) {
|
|
142
151
|
return {
|
|
143
152
|
action: _types2.DynamicSwapType.BRIDGE,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ProxyServiceRoute = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
let ProxyServiceRoute;
|
|
10
|
+
exports.ProxyServiceRoute = ProxyServiceRoute;
|
|
11
|
+
(function (ProxyServiceRoute) {
|
|
12
|
+
ProxyServiceRoute["BITTENSOR"] = "/bittensor";
|
|
13
|
+
ProxyServiceRoute["CHAINFLIP"] = "/chainflip";
|
|
14
|
+
ProxyServiceRoute["KYBER"] = "/kyber";
|
|
15
|
+
ProxyServiceRoute["SIMPLESWAP"] = "/simpleswap";
|
|
16
|
+
ProxyServiceRoute["UNISWAP"] = "/uniswap";
|
|
17
|
+
ProxyServiceRoute["CARDANO"] = "/cardano";
|
|
18
|
+
ProxyServiceRoute["PARASPELL"] = "/paraspell";
|
|
19
|
+
})(ProxyServiceRoute || (exports.ProxyServiceRoute = ProxyServiceRoute = {}));
|
package/cjs/utils/environment.js
CHANGED
|
@@ -4,10 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.browserVersion = exports.browserName = exports.TARGET_ENV = exports.RuntimeInfo = exports.MODULE_SUPPORT = exports.BowserParser = void 0;
|
|
8
|
+
exports.fetchFromProxyService = fetchFromProxyService;
|
|
9
|
+
exports.targetIsWeb = exports.targetIsMobile = exports.targetIsExtension = exports.platformType = exports.platformModel = exports.osVersion = exports.osName = exports.isMobile = exports.isFirefox = exports.isBrave = void 0;
|
|
8
10
|
var _mv = require("@subwallet/extension-base/utils/mv3");
|
|
9
11
|
var _bowser = _interopRequireDefault(require("bowser"));
|
|
10
12
|
var _KoniTypes = require("../background/KoniTypes");
|
|
13
|
+
var _constants = require("../constants");
|
|
11
14
|
var _navigator3;
|
|
12
15
|
function detectRuntimeEnvironment() {
|
|
13
16
|
if (_mv.isSupportWindow && typeof document !== 'undefined') {
|
|
@@ -104,4 +107,29 @@ exports.targetIsMobile = targetIsMobile;
|
|
|
104
107
|
const MODULE_SUPPORT = {
|
|
105
108
|
MANTA_ZK: false
|
|
106
109
|
};
|
|
107
|
-
exports.MODULE_SUPPORT = MODULE_SUPPORT;
|
|
110
|
+
exports.MODULE_SUPPORT = MODULE_SUPPORT;
|
|
111
|
+
var HEADERS;
|
|
112
|
+
(function (HEADERS) {
|
|
113
|
+
HEADERS["PLATFORM"] = "Platform";
|
|
114
|
+
})(HEADERS || (HEADERS = {}));
|
|
115
|
+
function formatExternalServiceApi(url, isTestnet) {
|
|
116
|
+
if (isTestnet === true) {
|
|
117
|
+
return `${url}/testnet`;
|
|
118
|
+
}
|
|
119
|
+
if (isTestnet === false) {
|
|
120
|
+
return `${url}/mainnet`;
|
|
121
|
+
}
|
|
122
|
+
return url;
|
|
123
|
+
}
|
|
124
|
+
async function fetchFromProxyService(service, path, options, isTestnet) {
|
|
125
|
+
const baseUrl = formatExternalServiceApi(`${_constants.SW_EXTERNAL_SERVICES_API}${service}`, isTestnet);
|
|
126
|
+
const url = `${baseUrl}${path}`;
|
|
127
|
+
const headers = {
|
|
128
|
+
[HEADERS.PLATFORM]: TARGET_ENV,
|
|
129
|
+
...(options.headers || {})
|
|
130
|
+
};
|
|
131
|
+
return fetch(url, {
|
|
132
|
+
...options,
|
|
133
|
+
headers
|
|
134
|
+
});
|
|
135
|
+
}
|
package/constants/environment.js
CHANGED
|
@@ -5,4 +5,5 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
|
5
5
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
6
6
|
export const isProductionMode = PRODUCTION_BRANCHES.indexOf(branchName) > -1;
|
|
7
7
|
export const BACKEND_API_URL = process.env.SUBWALLET_API || (isProductionMode ? 'https://sw-services.subwallet.app/api' : 'https://be-dev.subwallet.app/api');
|
|
8
|
-
export const BACKEND_PRICE_HISTORY_URL = process.env.SUBWALLET_PRICE_HISTORY_API || (isProductionMode ? 'https://price-history.subwallet.app/api' : 'https://price-history-dev.subwallet.app/api');
|
|
8
|
+
export const BACKEND_PRICE_HISTORY_URL = process.env.SUBWALLET_PRICE_HISTORY_API || (isProductionMode ? 'https://price-history.subwallet.app/api' : 'https://price-history-dev.subwallet.app/api');
|
|
9
|
+
export const SW_EXTERNAL_SERVICES_API = process.env.SW_EXTERNAL_SERVICES_API || (isProductionMode ? 'https://external-services.subwallet.app' : 'https://external-services-dev.subwallet.app');
|
|
@@ -1452,7 +1452,7 @@ export default class KoniExtension {
|
|
|
1452
1452
|
const isPosBridgeTransfer = _isPosChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1453
1453
|
const isAcrossBridgeTransfer = _isAcrossChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1454
1454
|
const extrinsicType = ExtrinsicType.TRANSFER_XCM;
|
|
1455
|
-
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer);
|
|
1455
|
+
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer);
|
|
1456
1456
|
const isTransferNative = this.#koniState.getNativeTokenInfo(originNetworkKey).slug === tokenSlug;
|
|
1457
1457
|
const isTransferLocalTokenAndPayThatTokenAsFee = !isTransferNative && tokenSlug === tokenPayFeeSlug;
|
|
1458
1458
|
let xcmFeeDryRun;
|
|
@@ -1534,48 +1534,47 @@ export default class KoniExtension {
|
|
|
1534
1534
|
}
|
|
1535
1535
|
let isSendingTokenSufficient = false;
|
|
1536
1536
|
let receiverSystemAccountInfo;
|
|
1537
|
-
if (
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
value: _receiverDestinationTokenKeepAliveBalance
|
|
1555
|
-
} = await this.getAddressTotalBalance({
|
|
1556
|
-
address: to,
|
|
1557
|
-
networkKey: destinationNetworkKey,
|
|
1558
|
-
token: destinationTokenInfo.slug,
|
|
1559
|
-
extrinsicType
|
|
1560
|
-
});
|
|
1561
|
-
const receiverDestinationTokenKeepAliveBalance = BigInt(_receiverDestinationTokenKeepAliveBalance);
|
|
1562
|
-
if (!_isNativeToken(destinationTokenInfo)) {
|
|
1563
|
-
const _receiverNativeTotal = await this.getAddressTotalBalance({
|
|
1537
|
+
if (_isChainSubstrateCompatible(chainInfoMap[destinationNetworkKey])) {
|
|
1538
|
+
const setting = {
|
|
1539
|
+
visible: true
|
|
1540
|
+
};
|
|
1541
|
+
await this.#koniState.chainService.updateAssetSetting(destinationTokenInfo.slug, setting, true);
|
|
1542
|
+
const {
|
|
1543
|
+
value: _senderTransferable
|
|
1544
|
+
} = await this.getAddressTransferableBalance({
|
|
1545
|
+
address: from,
|
|
1546
|
+
networkKey: originNetworkKey,
|
|
1547
|
+
token: originTokenInfo.slug
|
|
1548
|
+
});
|
|
1549
|
+
const senderTransferable = BigInt(_senderTransferable);
|
|
1550
|
+
const sendingAmount = BigInt(value);
|
|
1551
|
+
const {
|
|
1552
|
+
value: _receiverDestinationTokenKeepAliveBalance
|
|
1553
|
+
} = await this.getAddressTotalBalance({
|
|
1564
1554
|
address: to,
|
|
1565
1555
|
networkKey: destinationNetworkKey,
|
|
1566
|
-
token:
|
|
1556
|
+
token: destinationTokenInfo.slug,
|
|
1567
1557
|
extrinsicType
|
|
1568
1558
|
});
|
|
1569
|
-
|
|
1559
|
+
const receiverDestinationTokenKeepAliveBalance = BigInt(_receiverDestinationTokenKeepAliveBalance);
|
|
1560
|
+
if (!_isNativeToken(destinationTokenInfo)) {
|
|
1561
|
+
const _receiverNativeTotal = await this.getAddressTotalBalance({
|
|
1562
|
+
address: to,
|
|
1563
|
+
networkKey: destinationNetworkKey,
|
|
1564
|
+
token: destinationNativeTokenSlug,
|
|
1565
|
+
extrinsicType
|
|
1566
|
+
});
|
|
1567
|
+
receiverSystemAccountInfo = _receiverNativeTotal.metadata;
|
|
1568
|
+
}
|
|
1569
|
+
const substrateApi = this.#koniState.getSubstrateApi(destinationNetworkKey);
|
|
1570
|
+
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1571
|
+
isSendingTokenSufficient = await _isSufficientToken(destinationTokenInfo, substrateApi, sufficientChain);
|
|
1572
|
+
const [warning, error] = additionalValidateTransferForRecipient(destinationTokenInfo, destinationNativeTokenInfo, extrinsicType, receiverDestinationTokenKeepAliveBalance, sendingAmount, senderTransferable,
|
|
1573
|
+
// different from sendingTokenInfo being passed in
|
|
1574
|
+
receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1575
|
+
warning.length && inputTransaction.warnings.push(...warning);
|
|
1576
|
+
error.length && inputTransaction.errors.push(...error);
|
|
1570
1577
|
}
|
|
1571
|
-
const substrateApi = this.#koniState.getSubstrateApi(destinationNetworkKey);
|
|
1572
|
-
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1573
|
-
isSendingTokenSufficient = await _isSufficientToken(destinationTokenInfo, substrateApi, sufficientChain);
|
|
1574
|
-
const [warning, error] = additionalValidateTransferForRecipient(destinationTokenInfo, destinationNativeTokenInfo, extrinsicType, receiverDestinationTokenKeepAliveBalance, sendingAmount, senderTransferable,
|
|
1575
|
-
// different from sendingTokenInfo being passed in
|
|
1576
|
-
receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1577
|
-
warning.length && inputTransaction.warnings.push(...warning);
|
|
1578
|
-
error.length && inputTransaction.errors.push(...error);
|
|
1579
1578
|
if (isSubstrateXcm) {
|
|
1580
1579
|
const isDryRunSuccess = await dryRunXcmExtrinsicV2(params);
|
|
1581
1580
|
if (!isDryRunSuccess) {
|
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.41-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2241,6 +2241,11 @@
|
|
|
2241
2241
|
"require": "./cjs/types/common/storage.js",
|
|
2242
2242
|
"default": "./types/common/storage.js"
|
|
2243
2243
|
},
|
|
2244
|
+
"./types/environment": {
|
|
2245
|
+
"types": "./types/environment.d.ts",
|
|
2246
|
+
"require": "./cjs/types/environment.js",
|
|
2247
|
+
"default": "./types/environment.js"
|
|
2248
|
+
},
|
|
2244
2249
|
"./types/error": {
|
|
2245
2250
|
"types": "./types/error.d.ts",
|
|
2246
2251
|
"require": "./cjs/types/error.js",
|
|
@@ -2710,12 +2715,12 @@
|
|
|
2710
2715
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2711
2716
|
"@substrate/connect": "^0.8.9",
|
|
2712
2717
|
"@subwallet/chain-list": "0.2.105",
|
|
2713
|
-
"@subwallet/extension-base": "^1.3.
|
|
2714
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2715
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2716
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2718
|
+
"@subwallet/extension-base": "^1.3.41-0",
|
|
2719
|
+
"@subwallet/extension-chains": "^1.3.41-0",
|
|
2720
|
+
"@subwallet/extension-dapp": "^1.3.41-0",
|
|
2721
|
+
"@subwallet/extension-inject": "^1.3.41-0",
|
|
2717
2722
|
"@subwallet/keyring": "^0.1.12",
|
|
2718
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2723
|
+
"@subwallet/subwallet-api-sdk": "^1.3.41-0",
|
|
2719
2724
|
"@subwallet/ui-keyring": "^0.1.12",
|
|
2720
2725
|
"@ton/core": "^0.56.3",
|
|
2721
2726
|
"@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.41-0'
|
|
11
11
|
};
|
|
@@ -5,6 +5,7 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
5
5
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
7
|
import { getERC20Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
8
|
+
import { _BALANCE_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
9
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
10
|
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
10
11
|
import { BN } from '@polkadot/util';
|
|
@@ -16,7 +17,11 @@ export function subscribeERC20Interval({
|
|
|
16
17
|
evmApi
|
|
17
18
|
}) {
|
|
18
19
|
const chain = chainInfo.slug;
|
|
19
|
-
|
|
20
|
+
let tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.ERC20]);
|
|
21
|
+
if (_BALANCE_CHAIN_GROUP.moonbeam.includes(chain)) {
|
|
22
|
+
const moonbeamLocal = filterAssetsByChainAndType(assetMap, chain, [_AssetType.LOCAL]);
|
|
23
|
+
tokenList = Object.assign({}, tokenList, moonbeamLocal);
|
|
24
|
+
}
|
|
20
25
|
const erc20ContractMap = {};
|
|
21
26
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
22
27
|
erc20ContractMap[slug] = getERC20Contract(_getContractAddressOfToken(tokenInfo), evmApi);
|
|
@@ -128,19 +128,25 @@ export const createXcmExtrinsicV2 = async request => {
|
|
|
128
128
|
export const dryRunXcmExtrinsicV2 = async request => {
|
|
129
129
|
try {
|
|
130
130
|
const dryRunResult = await dryRunXcm(request);
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
const originDryRunRs = dryRunResult.origin;
|
|
132
|
+
if (originDryRunRs.success) {
|
|
133
|
+
const {
|
|
134
|
+
assetHub,
|
|
135
|
+
bridgeHub,
|
|
136
|
+
destination
|
|
137
|
+
} = dryRunResult;
|
|
138
|
+
if ((assetHub === null || assetHub === void 0 ? void 0 : assetHub.success) === false || (bridgeHub === null || bridgeHub === void 0 ? void 0 : bridgeHub.success) === false || (destination === null || destination === void 0 ? void 0 : destination.success) === false) {
|
|
139
|
+
if ((destination === null || destination === void 0 ? void 0 : destination.success) === false) {
|
|
140
|
+
// pass dry-run in these cases
|
|
141
|
+
return isChainNotSupportDryRun(destination.failureReason) || isChainNotSupportPolkadotApi(destination.failureReason);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
// pass dry-run in these cases
|
|
139
|
-
return isChainNotSupportDryRun(destinationDryRunResult.failureReason) || isChainNotSupportPolkadotApi(destinationDryRunResult.failureReason);
|
|
145
|
+
return true;
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
// pass dry-run in these cases
|
|
143
|
-
return isChainNotSupportDryRun(
|
|
149
|
+
return isChainNotSupportDryRun(originDryRunRs.failureReason) || isChainNotSupportPolkadotApi(originDryRunRs.failureReason);
|
|
144
150
|
} catch (e) {
|
|
145
151
|
return false;
|
|
146
152
|
}
|
|
@@ -14,6 +14,8 @@ export declare type DryRunNodeResult = DryRunNodeSuccess | DryRunNodeFailure;
|
|
|
14
14
|
export declare type DryRunResult = {
|
|
15
15
|
origin: DryRunNodeResult;
|
|
16
16
|
destination?: DryRunNodeResult;
|
|
17
|
+
assetHub?: DryRunNodeResult;
|
|
18
|
+
bridgeHub?: DryRunNodeResult;
|
|
17
19
|
};
|
|
18
20
|
interface GetXcmFeeRequest {
|
|
19
21
|
sender: string;
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { fetchParaSpellChainMap } from '@subwallet/extension-base/constants/paraspell-chain-map';
|
|
5
|
+
import { ProxyServiceRoute } from '@subwallet/extension-base/types/environment';
|
|
6
|
+
import { fetchFromProxyService } from '@subwallet/extension-base/utils';
|
|
5
7
|
import { assert, compactToU8a, isHex, u8aConcat, u8aEq } from '@polkadot/util';
|
|
6
|
-
const
|
|
8
|
+
const version = '/v3';
|
|
7
9
|
const paraSpellApi = {
|
|
8
|
-
buildXcm: `${
|
|
9
|
-
dryRunXcm: `${
|
|
10
|
-
feeXcm: `${
|
|
10
|
+
buildXcm: `${version}/x-transfer`,
|
|
11
|
+
dryRunXcm: `${version}/dry-run`,
|
|
12
|
+
feeXcm: `${version}/xcm-fee`
|
|
11
13
|
};
|
|
12
|
-
const paraSpellKey = process.env.PARASPELL_API_KEY || '';
|
|
13
14
|
function txHexToSubmittableExtrinsic(api, hex) {
|
|
14
15
|
try {
|
|
15
16
|
assert(isHex(hex), 'Expected a hex-encoded call');
|
|
@@ -86,13 +87,12 @@ export async function buildXcm(request) {
|
|
|
86
87
|
to: paraSpellChainMap[destinationChain.slug],
|
|
87
88
|
currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
|
|
88
89
|
};
|
|
89
|
-
const response = await
|
|
90
|
+
const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.buildXcm, {
|
|
90
91
|
method: 'POST',
|
|
91
92
|
body: JSON.stringify(bodyData),
|
|
92
93
|
headers: {
|
|
93
94
|
'Content-Type': 'application/json',
|
|
94
|
-
Accept: 'application/json'
|
|
95
|
-
'X-API-KEY': paraSpellKey
|
|
95
|
+
Accept: 'application/json'
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
98
|
if (!response.ok) {
|
|
@@ -126,13 +126,12 @@ export async function dryRunXcm(request) {
|
|
|
126
126
|
to: paraSpellChainMap[destinationChain.slug],
|
|
127
127
|
currency: createParaSpellCurrency(psAssetType, psAssetValue, sendingValue)
|
|
128
128
|
};
|
|
129
|
-
const response = await
|
|
129
|
+
const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.dryRunXcm, {
|
|
130
130
|
method: 'POST',
|
|
131
131
|
body: JSON.stringify(bodyData),
|
|
132
132
|
headers: {
|
|
133
133
|
'Content-Type': 'application/json',
|
|
134
|
-
Accept: 'application/json'
|
|
135
|
-
'X-API-KEY': paraSpellKey
|
|
134
|
+
Accept: 'application/json'
|
|
136
135
|
}
|
|
137
136
|
});
|
|
138
137
|
if (!response.ok) {
|
|
@@ -170,13 +169,12 @@ export async function estimateXcmFee(request) {
|
|
|
170
169
|
to: paraSpellChainMap[toChainInfo.slug],
|
|
171
170
|
currency: createParaSpellCurrency(psAssetType, psAssetValue, value)
|
|
172
171
|
};
|
|
173
|
-
const response = await
|
|
172
|
+
const response = await fetchFromProxyService(ProxyServiceRoute.PARASPELL, paraSpellApi.feeXcm, {
|
|
174
173
|
method: 'POST',
|
|
175
174
|
body: JSON.stringify(bodyData),
|
|
176
175
|
headers: {
|
|
177
176
|
'Content-Type': 'application/json',
|
|
178
|
-
Accept: 'application/json'
|
|
179
|
-
'X-API-KEY': paraSpellKey
|
|
177
|
+
Accept: 'application/json'
|
|
180
178
|
}
|
|
181
179
|
});
|
|
182
180
|
if (!response.ok) {
|
|
@@ -30,12 +30,13 @@ export const _BALANCE_CHAIN_GROUP = {
|
|
|
30
30
|
genshiro: ['genshiro_testnet', 'genshiro'],
|
|
31
31
|
equilibrium_parachain: ['equilibrium_parachain'],
|
|
32
32
|
bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'hydradx_rococo', 'pendulum', 'amplitude', 'continuum_network', 'truth_network', 'jamton'],
|
|
33
|
-
statemine: ['statemine', 'astar', 'shiden', 'statemint', '
|
|
33
|
+
statemine: ['statemine', 'astar', 'shiden', 'statemint', 'crabParachain', 'darwinia2', 'parallel', 'calamari', 'manta_network', 'rococo_assethub', 'liberlandTest', 'liberland', 'dentnet', 'pangolin', 'crust', 'phala', 'shibuya', 'dbcchain', 'westend_assethub', 'chainflip_assethub'],
|
|
34
34
|
kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
|
|
35
35
|
// perhaps there are some runtime updates
|
|
36
36
|
centrifuge: ['centrifuge'],
|
|
37
37
|
supportBridged: ['rococo_assethub', 'statemint', 'statemine', 'polimec'],
|
|
38
|
-
bittensor: ['bittensor', 'bittensor_testnet']
|
|
38
|
+
bittensor: ['bittensor', 'bittensor_testnet'],
|
|
39
|
+
moonbeam: ['moonbeam', 'moonriver', 'moonbase']
|
|
39
40
|
};
|
|
40
41
|
export const _BALANCE_TOKEN_GROUP = {
|
|
41
42
|
crab: ['CKTON', 'PKTON'],
|
|
@@ -254,7 +255,7 @@ export const _TRANSFER_CHAIN_GROUP = {
|
|
|
254
255
|
genshiro: ['genshiro_testnet', 'genshiro', 'equilibrium_parachain'],
|
|
255
256
|
// crab: ['crab', 'pangolin'],
|
|
256
257
|
bitcountry: ['pioneer', 'bitcountry'],
|
|
257
|
-
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain', 'westend_assethub'],
|
|
258
|
+
statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel', 'liberland', 'liberlandTest', 'dentnet', 'dbcchain', 'westend_assethub', 'chainflip_assethub'],
|
|
258
259
|
riochain: ['riochain'],
|
|
259
260
|
sora_substrate: ['sora_substrate'],
|
|
260
261
|
avail: ['kate', 'goldberg_testnet'],
|
|
@@ -3,10 +3,6 @@ import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/ha
|
|
|
3
3
|
import { _CardanoApi, _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
4
|
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
5
5
|
import { BehaviorSubject } from 'rxjs';
|
|
6
|
-
export declare const API_KEY: {
|
|
7
|
-
mainnet: string;
|
|
8
|
-
testnet: string;
|
|
9
|
-
};
|
|
10
6
|
export declare class CardanoApi implements _CardanoApi {
|
|
11
7
|
chainSlug: string;
|
|
12
8
|
apiUrl: string;
|
|
@@ -18,11 +14,11 @@ export declare class CardanoApi implements _CardanoApi {
|
|
|
18
14
|
isApiReadyOnce: boolean;
|
|
19
15
|
isReadyHandler: PromiseHandler<_CardanoApi>;
|
|
20
16
|
isTestnet: boolean;
|
|
21
|
-
private projectId;
|
|
22
17
|
providerName: string;
|
|
23
18
|
constructor(chainSlug: string, apiUrl: string, { isTestnet, providerName }: _ApiOptions);
|
|
24
19
|
get isApiConnected(): boolean;
|
|
25
20
|
get connectionStatus(): _ChainConnectionStatus;
|
|
21
|
+
private fetchCardano;
|
|
26
22
|
private updateConnectionStatus;
|
|
27
23
|
get isReady(): Promise<_CardanoApi>;
|
|
28
24
|
updateApiUrl(apiUrl: string): Promise<void>;
|