@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
|
@@ -13,6 +13,7 @@ var _smartContract = require("@subwallet/extension-base/services/balance-service
|
|
|
13
13
|
var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
|
|
14
14
|
var _tonTransfer = require("@subwallet/extension-base/services/balance-service/transfer/ton-transfer");
|
|
15
15
|
var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm");
|
|
16
|
+
var _acrossBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge");
|
|
16
17
|
var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
|
|
17
18
|
var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
|
|
18
19
|
var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
|
|
@@ -36,7 +37,8 @@ const detectTransferTxType = (srcToken, srcChain, destChain) => {
|
|
|
36
37
|
const isSnowBridgeEvmTransfer = (0, _utils._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
37
38
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
38
39
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
39
|
-
|
|
40
|
+
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
41
|
+
return isAvailBridgeFromEvm || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer ? 'evm' : 'substrate';
|
|
40
42
|
} else {
|
|
41
43
|
if ((0, _utils._isChainEvmCompatible)(srcChain) && (0, _utils._isTokenTransferredByEvm)(srcToken)) {
|
|
42
44
|
return 'evm';
|
|
@@ -86,7 +88,8 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
86
88
|
srcChain,
|
|
87
89
|
srcToken,
|
|
88
90
|
substrateApi,
|
|
89
|
-
tonApi
|
|
91
|
+
tonApi,
|
|
92
|
+
value
|
|
90
93
|
} = request;
|
|
91
94
|
const feeChainType = fee.type;
|
|
92
95
|
let estimatedFee;
|
|
@@ -114,7 +117,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
114
117
|
from: address,
|
|
115
118
|
to: recipient,
|
|
116
119
|
transferAll: false,
|
|
117
|
-
value
|
|
120
|
+
value,
|
|
118
121
|
fallbackFee: true
|
|
119
122
|
});
|
|
120
123
|
} else {
|
|
@@ -127,7 +130,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
127
130
|
from: address,
|
|
128
131
|
to: recipient,
|
|
129
132
|
transferAll: false,
|
|
130
|
-
value
|
|
133
|
+
value,
|
|
131
134
|
fallbackFee: true
|
|
132
135
|
});
|
|
133
136
|
}
|
|
@@ -137,19 +140,18 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
137
140
|
from: address,
|
|
138
141
|
to: address,
|
|
139
142
|
networkKey: srcChain.slug,
|
|
140
|
-
value
|
|
143
|
+
value,
|
|
141
144
|
transferAll: false,
|
|
142
145
|
// currently not used
|
|
143
146
|
tonApi
|
|
144
147
|
});
|
|
145
148
|
} else if ((0, _keyring.isCardanoAddress)(address) && (0, _utils._isTokenTransferredByCardano)(srcToken)) {
|
|
146
|
-
const isTransferNativeToken = (0, _utils._isNativeToken)(srcToken);
|
|
147
149
|
[transaction] = await (0, _cardanoTransfer.createCardanoTransaction)({
|
|
148
150
|
tokenInfo: srcToken,
|
|
149
151
|
from: address,
|
|
150
152
|
to: address,
|
|
151
153
|
networkKey: srcChain.slug,
|
|
152
|
-
value
|
|
154
|
+
value,
|
|
153
155
|
cardanoTtlOffset: _consts.DEFAULT_CARDANO_TTL_OFFSET,
|
|
154
156
|
transferAll: false,
|
|
155
157
|
cardanoApi,
|
|
@@ -158,7 +160,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
158
160
|
} else {
|
|
159
161
|
[transaction] = await (0, _token.createSubstrateExtrinsic)({
|
|
160
162
|
transferAll: false,
|
|
161
|
-
value
|
|
163
|
+
value,
|
|
162
164
|
from: address,
|
|
163
165
|
networkKey: srcChain.slug,
|
|
164
166
|
tokenInfo: srcToken,
|
|
@@ -295,10 +297,11 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
295
297
|
nativeToken,
|
|
296
298
|
srcChain,
|
|
297
299
|
srcToken,
|
|
298
|
-
substrateApi
|
|
300
|
+
substrateApi,
|
|
301
|
+
value
|
|
299
302
|
} = request;
|
|
300
303
|
const feeChainType = fee.type;
|
|
301
|
-
let estimatedFee;
|
|
304
|
+
let estimatedFee = '0';
|
|
302
305
|
let feeOptions;
|
|
303
306
|
let maxTransferable;
|
|
304
307
|
let error;
|
|
@@ -307,20 +310,22 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
307
310
|
const isSnowBridgeEvmTransfer = (0, _utils._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
308
311
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
309
312
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
313
|
+
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
314
|
+
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer);
|
|
310
315
|
const fakeAddress = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
311
316
|
const substrateAddress = fakeAddress; // todo: move this
|
|
312
317
|
const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
|
|
313
|
-
|
|
318
|
+
const bnFreeBalance = new _bignumber.default(freeBalance.value);
|
|
314
319
|
const recipient = (0, _utils._isChainEvmCompatible)(destChain) ? evmAddress : substrateAddress;
|
|
320
|
+
if (!destToken) {
|
|
321
|
+
throw Error('Destination token is not available');
|
|
322
|
+
}
|
|
315
323
|
try {
|
|
316
|
-
if (!destToken) {
|
|
317
|
-
throw Error('Destination token is not available');
|
|
318
|
-
}
|
|
319
324
|
const params = {
|
|
320
325
|
destinationTokenInfo: destToken,
|
|
321
326
|
originTokenInfo: srcToken,
|
|
322
327
|
// If value is 0, substrate will throw error when estimating fee
|
|
323
|
-
sendingValue:
|
|
328
|
+
sendingValue: value,
|
|
324
329
|
sender: address,
|
|
325
330
|
recipient,
|
|
326
331
|
destinationChain: destChain,
|
|
@@ -334,6 +339,13 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
334
339
|
let funcCreateExtrinsic;
|
|
335
340
|
if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
|
|
336
341
|
funcCreateExtrinsic = _xcm.createPolygonBridgeExtrinsic;
|
|
342
|
+
} else if (isAcrossBridgeTransfer) {
|
|
343
|
+
funcCreateExtrinsic = _xcm.createAcrossBridgeExtrinsic;
|
|
344
|
+
if ((0, _acrossBridge._isAcrossTestnetBridge)(srcChain.slug)) {
|
|
345
|
+
params.sendingValue = (0, _bignumber.default)(0.0037).shiftedBy((0, _utils._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
346
|
+
} else {
|
|
347
|
+
params.sendingValue = (0, _bignumber.default)(1).shiftedBy((0, _utils._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
348
|
+
}
|
|
337
349
|
} else if (isSnowBridgeEvmTransfer) {
|
|
338
350
|
funcCreateExtrinsic = _xcm.createSnowBridgeExtrinsic;
|
|
339
351
|
} else if (isAvailBridgeFromEvm) {
|
|
@@ -341,9 +353,12 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
341
353
|
} else if (isAvailBridgeFromAvail) {
|
|
342
354
|
funcCreateExtrinsic = _xcm.createAvailBridgeExtrinsicFromAvail;
|
|
343
355
|
} else {
|
|
344
|
-
funcCreateExtrinsic = _xcm.
|
|
356
|
+
funcCreateExtrinsic = _xcm.createXcmExtrinsicV2;
|
|
357
|
+
params.sendingValue = '1';
|
|
345
358
|
}
|
|
346
359
|
const extrinsic = await funcCreateExtrinsic(params);
|
|
360
|
+
|
|
361
|
+
// todo: refactor condition
|
|
347
362
|
if (feeChainType === 'evm') {
|
|
348
363
|
var _tx$gas2;
|
|
349
364
|
// Calculate fee for evm transaction
|
|
@@ -363,12 +378,17 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
363
378
|
};
|
|
364
379
|
} else if (feeChainType === 'substrate') {
|
|
365
380
|
// Calculate fee for substrate transaction
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
381
|
+
if (isSubstrateXcm) {
|
|
382
|
+
const estimatedFeeByDryRun = await (0, _xcm.dryRunXcmExtrinsicV2)(params);
|
|
383
|
+
estimatedFee = estimatedFeeByDryRun.fee || '0';
|
|
384
|
+
} else {
|
|
385
|
+
try {
|
|
386
|
+
var _paymentInfo$partialF2;
|
|
387
|
+
const paymentInfo = await extrinsic.paymentInfo(address);
|
|
388
|
+
estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
|
|
389
|
+
} catch (e) {
|
|
390
|
+
estimatedFee = '0';
|
|
391
|
+
}
|
|
372
392
|
}
|
|
373
393
|
const _feeCustom = feeCustom;
|
|
374
394
|
const tip = (0, _combine.combineSubstrateFee)(fee, feeOption, _feeCustom).tip;
|
|
@@ -408,12 +428,12 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
408
428
|
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
409
429
|
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
410
430
|
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
411
|
-
maxTransferable =
|
|
431
|
+
maxTransferable = bnFreeBalance.minus(estimatedFeeLocal);
|
|
412
432
|
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
413
433
|
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
414
434
|
if (rate) {
|
|
415
435
|
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
416
|
-
maxTransferable =
|
|
436
|
+
maxTransferable = bnFreeBalance.minus(estimatedFeeLocal);
|
|
417
437
|
} else {
|
|
418
438
|
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
419
439
|
}
|
|
@@ -421,16 +441,20 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
421
441
|
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
422
442
|
}
|
|
423
443
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
424
|
-
maxTransferable =
|
|
444
|
+
maxTransferable = bnFreeBalance;
|
|
425
445
|
} else {
|
|
426
446
|
if (!(0, _utils._isNativeToken)(srcToken)) {
|
|
427
|
-
maxTransferable =
|
|
447
|
+
maxTransferable = bnFreeBalance;
|
|
428
448
|
} else {
|
|
429
|
-
maxTransferable = (0, _bignumber.default)(
|
|
449
|
+
maxTransferable = bnFreeBalance.minus((0, _bignumber.default)(estimatedFee).multipliedBy(_constants.XCM_FEE_RATIO));
|
|
430
450
|
}
|
|
431
451
|
}
|
|
452
|
+
if (isAvailBridgeFromAvail) {
|
|
453
|
+
const addedAmount = (0, _bignumber.default)(1).shiftedBy((0, _utils._getAssetDecimals)(srcToken));
|
|
454
|
+
maxTransferable = maxTransferable.minus(addedAmount);
|
|
455
|
+
}
|
|
432
456
|
return {
|
|
433
|
-
maxTransferable: maxTransferable.gt(_utils3.BN_ZERO) ? maxTransferable.toFixed(0)
|
|
457
|
+
maxTransferable: maxTransferable.gt(_utils3.BN_ZERO) ? maxTransferable.toFixed(0) : '0',
|
|
434
458
|
feeOptions: feeOptions,
|
|
435
459
|
feeType: feeChainType,
|
|
436
460
|
id: id,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
6
|
+
exports.termAndCondition = exports.staticData = exports.remindNotificationTime = exports.paraSpellChainMap = exports.oldChainPrefix = exports.marketingCampaigns = exports.currencySymbol = exports.crowdloanFunds = exports.buyTokenConfigs = exports.buyServiceInfos = exports.blockedActionsFeatures = exports.blockedActions = exports.StaticKey = void 0;
|
|
7
7
|
var _chainList = require("@subwallet/chain-list");
|
|
8
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
9
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -39,7 +39,10 @@ const blockedActions = require('./blockedActions.json');
|
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
40
40
|
exports.blockedActions = blockedActions;
|
|
41
41
|
const oldChainPrefix = require('./oldChainPrefix.json');
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
42
43
|
exports.oldChainPrefix = oldChainPrefix;
|
|
44
|
+
const paraSpellChainMap = require('./paraSpellChainMap.json');
|
|
45
|
+
exports.paraSpellChainMap = paraSpellChainMap;
|
|
43
46
|
let StaticKey;
|
|
44
47
|
exports.StaticKey = StaticKey;
|
|
45
48
|
(function (StaticKey) {
|
|
@@ -54,6 +57,7 @@ exports.StaticKey = StaticKey;
|
|
|
54
57
|
StaticKey["REMIND_NOTIFICATION_TIME"] = "remind-notification-time";
|
|
55
58
|
StaticKey["BLOCKED_ACTIONS"] = "blocked-actions";
|
|
56
59
|
StaticKey["OLD_CHAIN_PREFIX"] = "old-chain-prefix";
|
|
60
|
+
StaticKey["PARASPELL_CHAIN_MAP"] = "paraspell-chain-map";
|
|
57
61
|
})(StaticKey || (exports.StaticKey = StaticKey = {}));
|
|
58
62
|
const staticData = {
|
|
59
63
|
[StaticKey.CHAINS]: Object.values(_chainList.ChainInfoMap),
|
|
@@ -66,6 +70,7 @@ const staticData = {
|
|
|
66
70
|
[StaticKey.BLOCKED_ACTIONS_FEATURES]: blockedActionsFeatures,
|
|
67
71
|
[StaticKey.REMIND_NOTIFICATION_TIME]: remindNotificationTime,
|
|
68
72
|
[StaticKey.BLOCKED_ACTIONS]: blockedActions,
|
|
69
|
-
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix
|
|
73
|
+
[StaticKey.OLD_CHAIN_PREFIX]: oldChainPrefix,
|
|
74
|
+
[StaticKey.PARASPELL_CHAIN_MAP]: paraSpellChainMap
|
|
70
75
|
};
|
|
71
76
|
exports.staticData = staticData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchParaSpellChainMap(): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { fetchStaticData } from '@subwallet/extension-base/utils';
|
|
5
|
+
export async function fetchParaSpellChainMap() {
|
|
6
|
+
return await fetchStaticData('paraspell-chain-map');
|
|
7
|
+
}
|
|
@@ -17,3 +17,4 @@ export declare function estimateFeeForTransaction(validationResponse: SWTransact
|
|
|
17
17
|
export declare function checkSigningAccountForTransaction(validationResponse: SWTransactionResponse, chainInfoMap: Record<string, _ChainInfo>): void;
|
|
18
18
|
export declare function checkBalanceWithTransactionFee(validationResponse: SWTransactionResponse, transactionInput: SWTransactionInput, nativeTokenInfo: _ChainAsset, nativeTokenAvailable: AmountData): void;
|
|
19
19
|
export declare function checkTonAddressBounceableAndAccountNotActive(tonApi: _TonApi, validationResponse: SWTransactionResponse): Promise<void>;
|
|
20
|
+
export declare function validateXcmMinAmountToMythos(destChain: string, destToken: string, amount: string): TransactionError | undefined;
|
|
@@ -315,7 +315,8 @@ export async function estimateFeeForTransaction(validationResponse, transaction,
|
|
|
315
315
|
if (transaction) {
|
|
316
316
|
try {
|
|
317
317
|
if (isSubstrateTransaction(transaction)) {
|
|
318
|
-
|
|
318
|
+
var _validationResponse$x;
|
|
319
|
+
estimateFee.value = (_validationResponse$x = validationResponse.xcmFeeDryRun) !== null && _validationResponse$x !== void 0 ? _validationResponse$x : (await transaction.paymentInfo(validationResponse.address)).partialFee.toString();
|
|
319
320
|
} else if (isTonTransaction(transaction)) {
|
|
320
321
|
estimateFee.value = transaction.estimateFee; // todo: might need to update logic estimate fee inside for future actions excluding normal transfer Ton and Jetton
|
|
321
322
|
} else if (isCardanoTransaction(transaction)) {
|
|
@@ -443,4 +444,14 @@ function isTonAddressBounceable(address) {
|
|
|
443
444
|
async function isAccountActive(tonApi, address) {
|
|
444
445
|
const state = await tonApi.getAccountState(address);
|
|
445
446
|
return state === 'active';
|
|
447
|
+
}
|
|
448
|
+
export function validateXcmMinAmountToMythos(destChain, destToken, amount) {
|
|
449
|
+
const MYTHOS_DESTINATION_FEE = '2500000000000000000';
|
|
450
|
+
const errorMsg = 'Enter an amount higher than 2.5 MYTH to pay cross-chain fee and avoid your MYTH being lost after the transaction';
|
|
451
|
+
if (destChain === 'mythos' && destToken === 'mythos-NATIVE-MYTH') {
|
|
452
|
+
if (BigN(amount).lte(MYTHOS_DESTINATION_FEE)) {
|
|
453
|
+
return new TransactionError(TransferTxErrorType.NOT_ENOUGH_VALUE, t(errorMsg));
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return undefined;
|
|
446
457
|
}
|
|
@@ -55,4 +55,5 @@ export declare function _isAvailBridgeXcm(originChainInfo: _ChainInfo, destChain
|
|
|
55
55
|
export declare function _isMythosFromHydrationToMythos(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
56
56
|
export declare function _isPolygonBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
57
57
|
export declare function _isPosBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
58
|
+
export declare function _isAcrossBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
58
59
|
export declare function _adaptX1Interior(_assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
|
+
import { _isAcrossChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
5
6
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
7
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
7
8
|
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
@@ -127,7 +128,9 @@ export function _isPolygonBridgeXcm(originChainInfo, destChainInfo) {
|
|
|
127
128
|
export function _isPosBridgeXcm(originChainInfo, destChainInfo) {
|
|
128
129
|
return _isPosChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
+
export function _isAcrossBridgeXcm(originChainInfo, destChainInfo) {
|
|
132
|
+
return _isAcrossChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
133
|
+
}
|
|
131
134
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
132
135
|
|
|
133
136
|
function _getMultiLocationParent(originChainInfo, isWithinSameConsensus) {
|
package/core/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _ChainAsset } from '@subwallet/chain-list/types';
|
|
2
|
-
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { ExtrinsicType, SufficientChainsDetails } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { LedgerMustCheckType, ValidateRecipientParams } from '@subwallet/extension-base/core/types';
|
|
4
4
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
import { AccountJson } from '@subwallet/extension-base/types';
|
|
@@ -15,4 +15,4 @@ export declare function _isValidTonAddressFormat(validateRecipientParams: Valida
|
|
|
15
15
|
export declare function _isValidCardanoAddressFormat(validateRecipientParams: ValidateRecipientParams): string;
|
|
16
16
|
export declare function _isNotDuplicateAddress(validateRecipientParams: ValidateRecipientParams): string;
|
|
17
17
|
export declare function _isSupportLedgerAccount(validateRecipientParams: ValidateRecipientParams): string;
|
|
18
|
-
export declare const _isSufficientToken: (tokenInfo: _ChainAsset, substrateApi: _SubstrateApi) => Promise<boolean>;
|
|
18
|
+
export declare const _isSufficientToken: (tokenInfo: _ChainAsset, substrateApi: _SubstrateApi, sufficientChain: SufficientChainsDetails) => Promise<boolean>;
|
package/core/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ import { _AssetType } from '@subwallet/chain-list/types';
|
|
|
5
5
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { BalanceAccountType } from '@subwallet/extension-base/core/substrate/types';
|
|
7
7
|
import { tonAddressInfo } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
8
|
-
import { SUFFICIENT_CHAIN } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
8
|
import { _getTokenOnChainAssetId, _getXcmAssetMultilocation, _isBridgedToken, _isChainCardanoCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible, _isChainTonCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
9
|
import { isAddressAndChainCompatible, isSameAddress, reformatAddress } from '@subwallet/extension-base/utils';
|
|
11
10
|
import { isAddress, isCardanoTestnetAddress, isTonAddress } from '@subwallet/keyring';
|
|
@@ -132,27 +131,49 @@ export function _isSupportLedgerAccount(validateRecipientParams) {
|
|
|
132
131
|
}
|
|
133
132
|
return '';
|
|
134
133
|
}
|
|
135
|
-
export const _isSufficientToken = async (tokenInfo, substrateApi) => {
|
|
136
|
-
|
|
137
|
-
if (
|
|
134
|
+
export const _isSufficientToken = async (tokenInfo, substrateApi, sufficientChain) => {
|
|
135
|
+
var _tokenInfo$metadata;
|
|
136
|
+
if (tokenInfo.assetType !== _AssetType.NATIVE) {
|
|
138
137
|
const assetId = _isBridgedToken(tokenInfo) ? _getXcmAssetMultilocation(tokenInfo) : _getTokenOnChainAssetId(tokenInfo);
|
|
138
|
+
const chainSlug = tokenInfo.originChain;
|
|
139
139
|
const queryParams = {
|
|
140
140
|
section: 'query',
|
|
141
|
-
module: 'foreignAssets',
|
|
142
|
-
method: 'asset',
|
|
143
141
|
args: [assetId]
|
|
144
142
|
};
|
|
145
|
-
if (
|
|
143
|
+
if (sufficientChain.assetHubPallet.includes(chainSlug)) {
|
|
144
|
+
if (!_isBridgedToken(tokenInfo)) {
|
|
145
|
+
queryParams.module = 'assets';
|
|
146
|
+
} else {
|
|
147
|
+
queryParams.module = 'foreignAssets';
|
|
148
|
+
}
|
|
149
|
+
queryParams.method = 'asset';
|
|
150
|
+
}
|
|
151
|
+
if (sufficientChain.assetRegistryPallet.includes(chainSlug)) {
|
|
152
|
+
queryParams.module = 'assetRegistry';
|
|
153
|
+
queryParams.method = 'assets';
|
|
154
|
+
}
|
|
155
|
+
if (sufficientChain.assetsPallet.includes(chainSlug)) {
|
|
146
156
|
queryParams.module = 'assets';
|
|
157
|
+
queryParams.method = 'asset';
|
|
158
|
+
}
|
|
159
|
+
if (sufficientChain.foreignAssetsPallet.includes(chainSlug)) {
|
|
160
|
+
queryParams.module = 'foreignAsset';
|
|
161
|
+
queryParams.method = 'asset';
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
if (queryParams.method && queryParams.module) {
|
|
165
|
+
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
166
|
+
if ((metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient) !== undefined) {
|
|
167
|
+
return metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
console.error(e);
|
|
147
172
|
}
|
|
148
|
-
const metadata = await substrateApi.makeRpcQuery(queryParams);
|
|
149
|
-
return (metadata === null || metadata === void 0 ? void 0 : metadata.isSufficient) || false;
|
|
150
173
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// }
|
|
156
|
-
|
|
174
|
+
if ((_tokenInfo$metadata = tokenInfo.metadata) !== null && _tokenInfo$metadata !== void 0 && _tokenInfo$metadata.isSufficient) {
|
|
175
|
+
var _tokenInfo$metadata2;
|
|
176
|
+
return (_tokenInfo$metadata2 = tokenInfo.metadata) === null || _tokenInfo$metadata2 === void 0 ? void 0 : _tokenInfo$metadata2.isSufficient;
|
|
177
|
+
}
|
|
157
178
|
return false;
|
|
158
179
|
};
|
|
@@ -9,12 +9,12 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
|
|
|
9
9
|
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
10
10
|
import { CampaignDataType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, MantaPayEnableMessage, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
11
11
|
import { _SUPPORT_TOKEN_PAY_FEE_GROUP, ALL_ACCOUNT_KEY, LATEST_SESSION } from '@subwallet/extension-base/constants';
|
|
12
|
-
import { additionalValidateTransferForRecipient, validateTransferRequest, validateXcmTransferRequest } from '@subwallet/extension-base/core/logic-validation/transfer';
|
|
12
|
+
import { additionalValidateTransferForRecipient, validateTransferRequest, validateXcmMinAmountToMythos, validateXcmTransferRequest } from '@subwallet/extension-base/core/logic-validation/transfer';
|
|
13
13
|
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
14
14
|
import { _isSufficientToken } from '@subwallet/extension-base/core/utils';
|
|
15
15
|
import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
|
|
16
16
|
import { getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
17
|
-
import { _ERC721_ABI
|
|
17
|
+
import { _ERC721_ABI } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
18
18
|
import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
|
|
19
19
|
import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
|
|
20
20
|
import { UNSUPPORTED_TRANSFER_EVM_CHAIN_NAME } from '@subwallet/extension-base/koni/api/nft/config';
|
|
@@ -29,7 +29,8 @@ import { createCardanoTransaction } from '@subwallet/extension-base/services/bal
|
|
|
29
29
|
import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject, getPSP34TransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/smart-contract';
|
|
30
30
|
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
31
31
|
import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
32
|
-
import { createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic,
|
|
32
|
+
import { createAcrossBridgeExtrinsic, createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsicV2, dryRunXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
33
|
+
import { _isAcrossChainBridge, getAcrossQuote } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
33
34
|
import { getClaimTxOnAvail, getClaimTxOnEthereum, isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
34
35
|
import { _isPolygonChainBridge, getClaimPolygonBridge, isClaimedPolygonBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
35
36
|
import { _isPosChainBridge, getClaimPosBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
@@ -1104,9 +1105,10 @@ export default class KoniExtension {
|
|
|
1104
1105
|
owner,
|
|
1105
1106
|
spenderAddress
|
|
1106
1107
|
} = params;
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1108
|
+
|
|
1109
|
+
// if (!isSnowBridgeGatewayContract(spenderAddress) && !isAvailBridgeGatewayContract(spenderAddress)) {
|
|
1110
|
+
// throw new Error('Only SnowBridge and AvailBridge is supported'); // todo: support all ERC20 spending approval
|
|
1111
|
+
// }
|
|
1110
1112
|
|
|
1111
1113
|
const evmApi = this.#koniState.getEvmApi(chain);
|
|
1112
1114
|
const transactionConfig = await getERC20SpendingApprovalTx(spenderAddress, owner, contractAddress, evmApi, amount);
|
|
@@ -1298,7 +1300,8 @@ export default class KoniExtension {
|
|
|
1298
1300
|
const receiverSendingTokenKeepAliveBalance = BigInt(_receiverSendingTokenKeepAliveBalance);
|
|
1299
1301
|
const amount = BigInt(transferAmount.value);
|
|
1300
1302
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
1301
|
-
const
|
|
1303
|
+
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1304
|
+
const isSendingTokenSufficient = await _isSufficientToken(transferTokenInfo, substrateApi, sufficientChain);
|
|
1302
1305
|
const [warnings, errors] = additionalValidateTransferForRecipient(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverSendingTokenKeepAliveBalance, amount, senderSendingTokenTransferable, receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1303
1306
|
warnings.length && inputTransaction.warnings.push(...warnings);
|
|
1304
1307
|
errors.length && inputTransaction.errors.push(...errors);
|
|
@@ -1350,7 +1353,7 @@ export default class KoniExtension {
|
|
|
1350
1353
|
const destinationNativeTokenInfo = this.#koniState.getNativeTokenInfo(destinationNetworkKey);
|
|
1351
1354
|
const destinationNativeTokenSlug = destinationNativeTokenInfo.slug;
|
|
1352
1355
|
const [errors, fromKeyPair] = validateXcmTransferRequest(destinationTokenInfo, from, value);
|
|
1353
|
-
let extrinsic
|
|
1356
|
+
let extrinsic;
|
|
1354
1357
|
if (errors.length > 0) {
|
|
1355
1358
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1356
1359
|
}
|
|
@@ -1360,9 +1363,12 @@ export default class KoniExtension {
|
|
|
1360
1363
|
const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
|
|
1361
1364
|
const isPolygonBridgeTransfer = _isPolygonChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1362
1365
|
const isPosBridgeTransfer = _isPosChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1366
|
+
const isAcrossBridgeTransfer = _isAcrossChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1363
1367
|
const extrinsicType = ExtrinsicType.TRANSFER_XCM;
|
|
1368
|
+
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer);
|
|
1364
1369
|
const isTransferNative = this.#koniState.getNativeTokenInfo(originNetworkKey).slug === tokenSlug;
|
|
1365
1370
|
const isTransferLocalTokenAndPayThatTokenAsFee = !isTransferNative && tokenSlug === tokenPayFeeSlug;
|
|
1371
|
+
let xcmFeeDryRun;
|
|
1366
1372
|
let additionalValidator;
|
|
1367
1373
|
let eventsHandler;
|
|
1368
1374
|
if (fromKeyPair && destinationTokenInfo) {
|
|
@@ -1373,6 +1379,9 @@ export default class KoniExtension {
|
|
|
1373
1379
|
if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
|
|
1374
1380
|
funcCreateExtrinsic = createPolygonBridgeExtrinsic;
|
|
1375
1381
|
type = 'evm';
|
|
1382
|
+
} else if (isAcrossBridgeTransfer) {
|
|
1383
|
+
funcCreateExtrinsic = createAcrossBridgeExtrinsic;
|
|
1384
|
+
type = 'evm';
|
|
1376
1385
|
} else if (isSnowBridgeEvmTransfer) {
|
|
1377
1386
|
funcCreateExtrinsic = createSnowBridgeExtrinsic;
|
|
1378
1387
|
type = 'evm';
|
|
@@ -1383,7 +1392,7 @@ export default class KoniExtension {
|
|
|
1383
1392
|
funcCreateExtrinsic = createAvailBridgeExtrinsicFromAvail;
|
|
1384
1393
|
type = 'substrate';
|
|
1385
1394
|
} else {
|
|
1386
|
-
funcCreateExtrinsic =
|
|
1395
|
+
funcCreateExtrinsic = createXcmExtrinsicV2;
|
|
1387
1396
|
type = 'substrate';
|
|
1388
1397
|
}
|
|
1389
1398
|
const feeInfo = await this.#koniState.feeService.subscribeChainFee(getId(), originNetworkKey, type);
|
|
@@ -1402,6 +1411,19 @@ export default class KoniExtension {
|
|
|
1402
1411
|
feeInfo
|
|
1403
1412
|
};
|
|
1404
1413
|
extrinsic = await funcCreateExtrinsic(params);
|
|
1414
|
+
let dryRunInfo;
|
|
1415
|
+
if (isSubstrateXcm) {
|
|
1416
|
+
dryRunInfo = await dryRunXcmExtrinsicV2(params);
|
|
1417
|
+
xcmFeeDryRun = dryRunInfo.fee;
|
|
1418
|
+
}
|
|
1419
|
+
if (isAcrossBridgeTransfer) {
|
|
1420
|
+
const metadata = await getAcrossQuote(params);
|
|
1421
|
+
inputData.metadata = {
|
|
1422
|
+
amountOut: metadata.outputAmount,
|
|
1423
|
+
rate: metadata.rate,
|
|
1424
|
+
destChainSlug: destinationTokenInfo.slug
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1405
1427
|
if (_SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(originNetworkKey)) {
|
|
1406
1428
|
var _this$koniState$chain2, _substrateApi$api$que2;
|
|
1407
1429
|
const hydrationFeeAssetId = tokenPayFeeSlug && ((_this$koniState$chain2 = this.#koniState.chainService.getAssetBySlug(tokenPayFeeSlug).metadata) === null || _this$koniState$chain2 === void 0 ? void 0 : _this$koniState$chain2.assetId);
|
|
@@ -1411,11 +1433,20 @@ export default class KoniExtension {
|
|
|
1411
1433
|
extrinsic = batchExtrinsicSetFeeHydration(substrateApi, _extrinsic, feeSetting, hydrationFeeAssetId);
|
|
1412
1434
|
}
|
|
1413
1435
|
additionalValidator = async inputTransaction => {
|
|
1436
|
+
// hotfix xcm mythos to mythos chain
|
|
1437
|
+
const mythosError = validateXcmMinAmountToMythos(destinationNetworkKey, destinationTokenInfo.slug, value);
|
|
1438
|
+
if (mythosError) {
|
|
1439
|
+
inputTransaction.errors.push(mythosError);
|
|
1440
|
+
}
|
|
1414
1441
|
let isSendingTokenSufficient = false;
|
|
1415
1442
|
let receiverSystemAccountInfo;
|
|
1416
1443
|
if (!_isChainSubstrateCompatible(chainInfoMap[destinationNetworkKey])) {
|
|
1417
1444
|
return undefined;
|
|
1418
1445
|
}
|
|
1446
|
+
const setting = {
|
|
1447
|
+
visible: true
|
|
1448
|
+
};
|
|
1449
|
+
await this.#koniState.chainService.updateAssetSetting(destinationTokenInfo.slug, setting, true);
|
|
1419
1450
|
const {
|
|
1420
1451
|
value: _senderTransferable
|
|
1421
1452
|
} = await this.getAddressTransferableBalance({
|
|
@@ -1443,15 +1474,17 @@ export default class KoniExtension {
|
|
|
1443
1474
|
});
|
|
1444
1475
|
receiverSystemAccountInfo = _receiverNativeTotal.metadata;
|
|
1445
1476
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
}
|
|
1477
|
+
const substrateApi = this.#koniState.getSubstrateApi(destinationNetworkKey);
|
|
1478
|
+
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1479
|
+
isSendingTokenSufficient = await _isSufficientToken(destinationTokenInfo, substrateApi, sufficientChain);
|
|
1450
1480
|
const [warning, error] = additionalValidateTransferForRecipient(destinationTokenInfo, destinationNativeTokenInfo, extrinsicType, receiverDestinationTokenKeepAliveBalance, sendingAmount, senderTransferable,
|
|
1451
1481
|
// different from sendingTokenInfo being passed in
|
|
1452
1482
|
receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1453
1483
|
warning.length && inputTransaction.warnings.push(...warning);
|
|
1454
1484
|
error.length && inputTransaction.errors.push(...error);
|
|
1485
|
+
if (isSubstrateXcm && !dryRunInfo.success) {
|
|
1486
|
+
inputTransaction.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Unable to perform transaction. Select another token or destination chain and try again'));
|
|
1487
|
+
}
|
|
1455
1488
|
};
|
|
1456
1489
|
eventsHandler = eventEmitter => {
|
|
1457
1490
|
eventEmitter.on('send', () => {
|
|
@@ -1484,13 +1517,14 @@ export default class KoniExtension {
|
|
|
1484
1517
|
transaction: extrinsic,
|
|
1485
1518
|
data: inputData,
|
|
1486
1519
|
extrinsicType,
|
|
1487
|
-
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1520
|
+
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer && !isAcrossBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1488
1521
|
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
|
|
1489
1522
|
ignoreWarnings,
|
|
1490
1523
|
tokenPayFeeSlug,
|
|
1491
1524
|
isTransferAll: transferAll,
|
|
1492
1525
|
isTransferLocalTokenAndPayThatTokenAsFee,
|
|
1493
1526
|
isPassConfirmation,
|
|
1527
|
+
xcmFeeDryRun,
|
|
1494
1528
|
errors,
|
|
1495
1529
|
additionalValidator: additionalValidator,
|
|
1496
1530
|
eventsHandler: eventsHandler
|
|
@@ -1621,6 +1655,12 @@ export default class KoniExtension {
|
|
|
1621
1655
|
}) {
|
|
1622
1656
|
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1623
1657
|
}
|
|
1658
|
+
async enableChainWithPriorityAssets({
|
|
1659
|
+
chainSlug,
|
|
1660
|
+
enableTokens
|
|
1661
|
+
}) {
|
|
1662
|
+
return await this.#koniState.enableChainWithPriorityAssets(chainSlug, enableTokens);
|
|
1663
|
+
}
|
|
1624
1664
|
async reconnectChain(chainSlug) {
|
|
1625
1665
|
return this.#koniState.chainService.reconnectChain(chainSlug);
|
|
1626
1666
|
}
|
|
@@ -1729,7 +1769,8 @@ export default class KoniExtension {
|
|
|
1729
1769
|
feeCustom,
|
|
1730
1770
|
feeOption,
|
|
1731
1771
|
token,
|
|
1732
|
-
tokenPayFeeSlug
|
|
1772
|
+
tokenPayFeeSlug,
|
|
1773
|
+
value
|
|
1733
1774
|
} = request;
|
|
1734
1775
|
const cb = createSubscription(id, port);
|
|
1735
1776
|
const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(token);
|
|
@@ -1749,6 +1790,8 @@ export default class KoniExtension {
|
|
|
1749
1790
|
}
|
|
1750
1791
|
const _request = {
|
|
1751
1792
|
address: address,
|
|
1793
|
+
value,
|
|
1794
|
+
// todo: lazy subscribe to improve performance
|
|
1752
1795
|
cardanoApi: this.#koniState.chainService.getCardanoApi(chain),
|
|
1753
1796
|
destChain,
|
|
1754
1797
|
destToken,
|
|
@@ -4389,6 +4432,8 @@ export default class KoniExtension {
|
|
|
4389
4432
|
return this.getSupportedSmartContractTypes();
|
|
4390
4433
|
case 'pri(chainService.enableChain)':
|
|
4391
4434
|
return await this.enableChain(request);
|
|
4435
|
+
case 'pri(chainService.enableChainWithPriorityAssets)':
|
|
4436
|
+
return await this.enableChainWithPriorityAssets(request);
|
|
4392
4437
|
case 'pri(chainService.reconnectChain)':
|
|
4393
4438
|
return await this.reconnectChain(request);
|
|
4394
4439
|
case 'pri(chainService.disableChain)':
|
|
@@ -185,6 +185,7 @@ export default class KoniState {
|
|
|
185
185
|
private getDefaultNetworkKeys;
|
|
186
186
|
disableChain(chainSlug: string): Promise<boolean>;
|
|
187
187
|
enableChain(chainSlug: string, enableTokens?: boolean): Promise<boolean>;
|
|
188
|
+
enableChainWithPriorityAssets(chainSlug: string, enableTokens?: boolean): Promise<boolean>;
|
|
188
189
|
resetDefaultChains(): boolean;
|
|
189
190
|
getSubstrateApiMap(): Record<string, import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi>;
|
|
190
191
|
getSubstrateApi(networkKey: string): import("@subwallet/extension-base/services/chain-service/types")._SubstrateApi;
|