@subwallet/extension-base 1.3.29-1 → 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 +16 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/paraspell-chain-map.js +13 -0
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- 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 +141 -172
- 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/availBridge.js +6 -6
- 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/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/handlers/special.js +18 -9
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- 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/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +406 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/services/transaction-service/utils.js +38 -14
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/fee/transfer.js +52 -28
- package/cjs/utils/staticData/index.js +7 -2
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/paraspell-chain-map.d.ts +1 -0
- package/constants/paraspell-chain-map.js +7 -0
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- 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 -1
- package/koni/background/handlers/Extension.js +66 -98
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +7 -1
- package/package.json +23 -13
- 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/availBridge.js +6 -6
- 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/base/types.d.ts +0 -4
- 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/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/handlers/special.js +19 -10
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- 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/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +405 -230
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- 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/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/transaction/request.d.ts +7 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -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
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
|
@@ -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';
|
|
@@ -43,7 +44,7 @@ import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setti
|
|
|
43
44
|
import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectNamespace } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
44
45
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
45
46
|
import { AccountsStore } from '@subwallet/extension-base/stores';
|
|
46
|
-
import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType,
|
|
47
|
+
import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, CommonStepType, EarningProcessType, ProcessType, StakingTxErrorType, StepStatus, SwapFeeType, YieldPoolType, YieldStepType } from '@subwallet/extension-base/types';
|
|
47
48
|
import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, createTransactionFromRLP, detectTransferTxType, getAccountSignMode, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, transformAccounts, transformAddresses, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
48
49
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
49
50
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
@@ -278,7 +279,6 @@ export default class KoniExtension {
|
|
|
278
279
|
const transformedAccounts = Object.values(accountProxies);
|
|
279
280
|
responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [combineAllAccountProxy(transformedAccounts), ...transformedAccounts] : [];
|
|
280
281
|
responseData.currentAccountProxy = currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.proxyId;
|
|
281
|
-
console.debug('subscriptionAccountGroups', responseData);
|
|
282
282
|
cb(responseData);
|
|
283
283
|
});
|
|
284
284
|
this.createUnsubscriptionHandle(id, () => {
|
|
@@ -1105,9 +1105,10 @@ export default class KoniExtension {
|
|
|
1105
1105
|
owner,
|
|
1106
1106
|
spenderAddress
|
|
1107
1107
|
} = params;
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1108
|
+
|
|
1109
|
+
// if (!isSnowBridgeGatewayContract(spenderAddress) && !isAvailBridgeGatewayContract(spenderAddress)) {
|
|
1110
|
+
// throw new Error('Only SnowBridge and AvailBridge is supported'); // todo: support all ERC20 spending approval
|
|
1111
|
+
// }
|
|
1111
1112
|
|
|
1112
1113
|
const evmApi = this.#koniState.getEvmApi(chain);
|
|
1113
1114
|
const transactionConfig = await getERC20SpendingApprovalTx(spenderAddress, owner, contractAddress, evmApi, amount);
|
|
@@ -1299,7 +1300,8 @@ export default class KoniExtension {
|
|
|
1299
1300
|
const receiverSendingTokenKeepAliveBalance = BigInt(_receiverSendingTokenKeepAliveBalance);
|
|
1300
1301
|
const amount = BigInt(transferAmount.value);
|
|
1301
1302
|
const substrateApi = this.#koniState.getSubstrateApi(chain);
|
|
1302
|
-
const
|
|
1303
|
+
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1304
|
+
const isSendingTokenSufficient = await _isSufficientToken(transferTokenInfo, substrateApi, sufficientChain);
|
|
1303
1305
|
const [warnings, errors] = additionalValidateTransferForRecipient(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverSendingTokenKeepAliveBalance, amount, senderSendingTokenTransferable, receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1304
1306
|
warnings.length && inputTransaction.warnings.push(...warnings);
|
|
1305
1307
|
errors.length && inputTransaction.errors.push(...errors);
|
|
@@ -1351,7 +1353,7 @@ export default class KoniExtension {
|
|
|
1351
1353
|
const destinationNativeTokenInfo = this.#koniState.getNativeTokenInfo(destinationNetworkKey);
|
|
1352
1354
|
const destinationNativeTokenSlug = destinationNativeTokenInfo.slug;
|
|
1353
1355
|
const [errors, fromKeyPair] = validateXcmTransferRequest(destinationTokenInfo, from, value);
|
|
1354
|
-
let extrinsic
|
|
1356
|
+
let extrinsic;
|
|
1355
1357
|
if (errors.length > 0) {
|
|
1356
1358
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1357
1359
|
}
|
|
@@ -1361,9 +1363,12 @@ export default class KoniExtension {
|
|
|
1361
1363
|
const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
|
|
1362
1364
|
const isPolygonBridgeTransfer = _isPolygonChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1363
1365
|
const isPosBridgeTransfer = _isPosChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1366
|
+
const isAcrossBridgeTransfer = _isAcrossChainBridge(originNetworkKey, destinationNetworkKey);
|
|
1364
1367
|
const extrinsicType = ExtrinsicType.TRANSFER_XCM;
|
|
1368
|
+
const isSubstrateXcm = !(isAvailBridgeFromEvm || isAvailBridgeFromAvail || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer);
|
|
1365
1369
|
const isTransferNative = this.#koniState.getNativeTokenInfo(originNetworkKey).slug === tokenSlug;
|
|
1366
1370
|
const isTransferLocalTokenAndPayThatTokenAsFee = !isTransferNative && tokenSlug === tokenPayFeeSlug;
|
|
1371
|
+
let xcmFeeDryRun;
|
|
1367
1372
|
let additionalValidator;
|
|
1368
1373
|
let eventsHandler;
|
|
1369
1374
|
if (fromKeyPair && destinationTokenInfo) {
|
|
@@ -1374,6 +1379,9 @@ export default class KoniExtension {
|
|
|
1374
1379
|
if (isPosBridgeTransfer || isPolygonBridgeTransfer) {
|
|
1375
1380
|
funcCreateExtrinsic = createPolygonBridgeExtrinsic;
|
|
1376
1381
|
type = 'evm';
|
|
1382
|
+
} else if (isAcrossBridgeTransfer) {
|
|
1383
|
+
funcCreateExtrinsic = createAcrossBridgeExtrinsic;
|
|
1384
|
+
type = 'evm';
|
|
1377
1385
|
} else if (isSnowBridgeEvmTransfer) {
|
|
1378
1386
|
funcCreateExtrinsic = createSnowBridgeExtrinsic;
|
|
1379
1387
|
type = 'evm';
|
|
@@ -1384,7 +1392,7 @@ export default class KoniExtension {
|
|
|
1384
1392
|
funcCreateExtrinsic = createAvailBridgeExtrinsicFromAvail;
|
|
1385
1393
|
type = 'substrate';
|
|
1386
1394
|
} else {
|
|
1387
|
-
funcCreateExtrinsic =
|
|
1395
|
+
funcCreateExtrinsic = createXcmExtrinsicV2;
|
|
1388
1396
|
type = 'substrate';
|
|
1389
1397
|
}
|
|
1390
1398
|
const feeInfo = await this.#koniState.feeService.subscribeChainFee(getId(), originNetworkKey, type);
|
|
@@ -1403,6 +1411,19 @@ export default class KoniExtension {
|
|
|
1403
1411
|
feeInfo
|
|
1404
1412
|
};
|
|
1405
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
|
+
}
|
|
1406
1427
|
if (_SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(originNetworkKey)) {
|
|
1407
1428
|
var _this$koniState$chain2, _substrateApi$api$que2;
|
|
1408
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);
|
|
@@ -1412,11 +1433,20 @@ export default class KoniExtension {
|
|
|
1412
1433
|
extrinsic = batchExtrinsicSetFeeHydration(substrateApi, _extrinsic, feeSetting, hydrationFeeAssetId);
|
|
1413
1434
|
}
|
|
1414
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
|
+
}
|
|
1415
1441
|
let isSendingTokenSufficient = false;
|
|
1416
1442
|
let receiverSystemAccountInfo;
|
|
1417
1443
|
if (!_isChainSubstrateCompatible(chainInfoMap[destinationNetworkKey])) {
|
|
1418
1444
|
return undefined;
|
|
1419
1445
|
}
|
|
1446
|
+
const setting = {
|
|
1447
|
+
visible: true
|
|
1448
|
+
};
|
|
1449
|
+
await this.#koniState.chainService.updateAssetSetting(destinationTokenInfo.slug, setting, true);
|
|
1420
1450
|
const {
|
|
1421
1451
|
value: _senderTransferable
|
|
1422
1452
|
} = await this.getAddressTransferableBalance({
|
|
@@ -1444,15 +1474,17 @@ export default class KoniExtension {
|
|
|
1444
1474
|
});
|
|
1445
1475
|
receiverSystemAccountInfo = _receiverNativeTotal.metadata;
|
|
1446
1476
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
}
|
|
1477
|
+
const substrateApi = this.#koniState.getSubstrateApi(destinationNetworkKey);
|
|
1478
|
+
const sufficientChain = this.#koniState.chainService.value.sufficientChains;
|
|
1479
|
+
isSendingTokenSufficient = await _isSufficientToken(destinationTokenInfo, substrateApi, sufficientChain);
|
|
1451
1480
|
const [warning, error] = additionalValidateTransferForRecipient(destinationTokenInfo, destinationNativeTokenInfo, extrinsicType, receiverDestinationTokenKeepAliveBalance, sendingAmount, senderTransferable,
|
|
1452
1481
|
// different from sendingTokenInfo being passed in
|
|
1453
1482
|
receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1454
1483
|
warning.length && inputTransaction.warnings.push(...warning);
|
|
1455
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
|
+
}
|
|
1456
1488
|
};
|
|
1457
1489
|
eventsHandler = eventEmitter => {
|
|
1458
1490
|
eventEmitter.on('send', () => {
|
|
@@ -1485,13 +1517,14 @@ export default class KoniExtension {
|
|
|
1485
1517
|
transaction: extrinsic,
|
|
1486
1518
|
data: inputData,
|
|
1487
1519
|
extrinsicType,
|
|
1488
|
-
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1520
|
+
chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer && !isPosBridgeTransfer && !isAcrossBridgeTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1489
1521
|
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
|
|
1490
1522
|
ignoreWarnings,
|
|
1491
1523
|
tokenPayFeeSlug,
|
|
1492
1524
|
isTransferAll: transferAll,
|
|
1493
1525
|
isTransferLocalTokenAndPayThatTokenAsFee,
|
|
1494
1526
|
isPassConfirmation,
|
|
1527
|
+
xcmFeeDryRun,
|
|
1495
1528
|
errors,
|
|
1496
1529
|
additionalValidator: additionalValidator,
|
|
1497
1530
|
eventsHandler: eventsHandler
|
|
@@ -1622,6 +1655,12 @@ export default class KoniExtension {
|
|
|
1622
1655
|
}) {
|
|
1623
1656
|
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1624
1657
|
}
|
|
1658
|
+
async enableChainWithPriorityAssets({
|
|
1659
|
+
chainSlug,
|
|
1660
|
+
enableTokens
|
|
1661
|
+
}) {
|
|
1662
|
+
return await this.#koniState.enableChainWithPriorityAssets(chainSlug, enableTokens);
|
|
1663
|
+
}
|
|
1625
1664
|
async reconnectChain(chainSlug) {
|
|
1626
1665
|
return this.#koniState.chainService.reconnectChain(chainSlug);
|
|
1627
1666
|
}
|
|
@@ -1730,7 +1769,8 @@ export default class KoniExtension {
|
|
|
1730
1769
|
feeCustom,
|
|
1731
1770
|
feeOption,
|
|
1732
1771
|
token,
|
|
1733
|
-
tokenPayFeeSlug
|
|
1772
|
+
tokenPayFeeSlug,
|
|
1773
|
+
value
|
|
1734
1774
|
} = request;
|
|
1735
1775
|
const cb = createSubscription(id, port);
|
|
1736
1776
|
const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(token);
|
|
@@ -1750,6 +1790,8 @@ export default class KoniExtension {
|
|
|
1750
1790
|
}
|
|
1751
1791
|
const _request = {
|
|
1752
1792
|
address: address,
|
|
1793
|
+
value,
|
|
1794
|
+
// todo: lazy subscribe to improve performance
|
|
1753
1795
|
cardanoApi: this.#koniState.chainService.getCardanoApi(chain),
|
|
1754
1796
|
destChain,
|
|
1755
1797
|
destToken,
|
|
@@ -3617,11 +3659,9 @@ export default class KoniExtension {
|
|
|
3617
3659
|
ready = true;
|
|
3618
3660
|
return this.#koniState.swapService.getSwapPairs();
|
|
3619
3661
|
}
|
|
3620
|
-
async getOptimalSwapProcessOnSelectQuote(request) {
|
|
3621
|
-
return this.#koniState.swapService.generateOptimalProcessWithoutPath(request);
|
|
3622
|
-
}
|
|
3623
3662
|
async handleSwapRequest(request) {
|
|
3624
|
-
|
|
3663
|
+
// @ts-ignore
|
|
3664
|
+
return Promise.resolve(null);
|
|
3625
3665
|
}
|
|
3626
3666
|
async handleSwapRequestV2(request) {
|
|
3627
3667
|
return this.#koniState.swapService.handleSwapRequestV2(request);
|
|
@@ -3633,7 +3673,7 @@ export default class KoniExtension {
|
|
|
3633
3673
|
return swapQuoteResponse;
|
|
3634
3674
|
}
|
|
3635
3675
|
async validateSwapProcess(params) {
|
|
3636
|
-
return this.#koniState.swapService.
|
|
3676
|
+
return this.#koniState.swapService.validateSwapProcessV2(params);
|
|
3637
3677
|
}
|
|
3638
3678
|
async handleSwapStep(inputData) {
|
|
3639
3679
|
const {
|
|
@@ -3663,7 +3703,7 @@ export default class KoniExtension {
|
|
|
3663
3703
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
3664
3704
|
}
|
|
3665
3705
|
const isLastStep = inputData.currentStep + 1 === process.steps.length;
|
|
3666
|
-
const swapValidations = await this.#koniState.swapService.
|
|
3706
|
+
const swapValidations = await this.#koniState.swapService.validateSwapProcessV2({
|
|
3667
3707
|
address,
|
|
3668
3708
|
process,
|
|
3669
3709
|
selectedQuote: quote,
|
|
@@ -3687,9 +3727,9 @@ export default class KoniExtension {
|
|
|
3687
3727
|
status: StepStatus.FAILED
|
|
3688
3728
|
});
|
|
3689
3729
|
}
|
|
3730
|
+
console.log('Error handling process step', e);
|
|
3690
3731
|
throw e;
|
|
3691
3732
|
}
|
|
3692
|
-
console.log('swap data', submitData);
|
|
3693
3733
|
|
|
3694
3734
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
3695
3735
|
const {
|
|
@@ -3701,17 +3741,12 @@ export default class KoniExtension {
|
|
|
3701
3741
|
txChain,
|
|
3702
3742
|
txData
|
|
3703
3743
|
} = submitData;
|
|
3704
|
-
|
|
3705
|
-
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
3706
|
-
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
3707
|
-
|
|
3708
3744
|
const eventsHandler = eventEmitter => {
|
|
3709
3745
|
if (onSend) {
|
|
3710
3746
|
eventEmitter.on('send', onSend);
|
|
3711
3747
|
}
|
|
3712
3748
|
};
|
|
3713
3749
|
if (processId) {
|
|
3714
|
-
const _step = process.steps[inputData.currentStep];
|
|
3715
3750
|
if (!this.#koniState.transactionService.checkProcessExist(processId) && step) {
|
|
3716
3751
|
const combineInfo = {
|
|
3717
3752
|
provider: quote.provider,
|
|
@@ -3729,23 +3764,6 @@ export default class KoniExtension {
|
|
|
3729
3764
|
combineInfo,
|
|
3730
3765
|
steps: inputData.process.steps.map((step, index) => {
|
|
3731
3766
|
const fee = inputData.process.totalFee[index];
|
|
3732
|
-
if (step.type === SwapStepType.SWAP) {
|
|
3733
|
-
const metadata = {
|
|
3734
|
-
pair: quote.pair,
|
|
3735
|
-
aliveUntil: quote.aliveUntil,
|
|
3736
|
-
fromAmount: quote.fromAmount,
|
|
3737
|
-
rate: quote.rate,
|
|
3738
|
-
provider: quote.provider,
|
|
3739
|
-
route: quote.route,
|
|
3740
|
-
toAmount: quote.toAmount
|
|
3741
|
-
};
|
|
3742
|
-
return {
|
|
3743
|
-
...step,
|
|
3744
|
-
status: StepStatus.QUEUED,
|
|
3745
|
-
fee,
|
|
3746
|
-
metadata: metadata
|
|
3747
|
-
};
|
|
3748
|
-
}
|
|
3749
3767
|
return {
|
|
3750
3768
|
...step,
|
|
3751
3769
|
fee,
|
|
@@ -3755,34 +3773,6 @@ export default class KoniExtension {
|
|
|
3755
3773
|
status: StepStatus.QUEUED
|
|
3756
3774
|
});
|
|
3757
3775
|
}
|
|
3758
|
-
const isLastStep = inputData.currentStep === process.steps.length - 1;
|
|
3759
|
-
if (isLastStep) {
|
|
3760
|
-
const metadata = {
|
|
3761
|
-
pair: quote.pair,
|
|
3762
|
-
aliveUntil: quote.aliveUntil,
|
|
3763
|
-
fromAmount: quote.fromAmount,
|
|
3764
|
-
rate: quote.rate,
|
|
3765
|
-
provider: quote.provider,
|
|
3766
|
-
route: quote.route,
|
|
3767
|
-
toAmount: quote.toAmount
|
|
3768
|
-
};
|
|
3769
|
-
const step = {
|
|
3770
|
-
..._step,
|
|
3771
|
-
// In case one sign, status already set to prepare before
|
|
3772
|
-
status: process.steps.length > 2 ? StepStatus.PREPARE : StepStatus.QUEUED,
|
|
3773
|
-
fee: process.totalFee[inputData.currentStep],
|
|
3774
|
-
metadata: metadata
|
|
3775
|
-
};
|
|
3776
|
-
const combineInfo = {
|
|
3777
|
-
provider: quote.provider,
|
|
3778
|
-
slippage: inputData.slippage,
|
|
3779
|
-
address,
|
|
3780
|
-
recipient,
|
|
3781
|
-
quote,
|
|
3782
|
-
process
|
|
3783
|
-
};
|
|
3784
|
-
await this.#koniState.transactionService.updateProcessInfo(processId, combineInfo, step);
|
|
3785
|
-
}
|
|
3786
3776
|
}
|
|
3787
3777
|
if (isPermit) {
|
|
3788
3778
|
return await this.#koniState.transactionService.handlePermitTransaction({
|
|
@@ -4014,32 +4004,10 @@ export default class KoniExtension {
|
|
|
4014
4004
|
nextTxType: ExtrinsicType.SWAP
|
|
4015
4005
|
};
|
|
4016
4006
|
submitData = async (step, callback) => {
|
|
4017
|
-
const isLastStep = step === stepNums - 1;
|
|
4018
4007
|
const isPassConfirmation = !callback;
|
|
4019
4008
|
const onSend = callback
|
|
4020
4009
|
// eslint-disable-next-line node/no-callback-literal
|
|
4021
4010
|
? rs => callback(rs) : undefined;
|
|
4022
|
-
const specialCaseForUniswap = data.quote.provider.id === SwapProviderId.UNISWAP && !!data.process.steps.find(step => step.type === SwapStepType.PERMIT);
|
|
4023
|
-
if (stepNums > 2 && isLastStep && !specialCaseForUniswap) {
|
|
4024
|
-
const quote = data.quote;
|
|
4025
|
-
const latestSwapQuote = await this.getLatestSwapQuote({
|
|
4026
|
-
address: data.address,
|
|
4027
|
-
currentQuote: quote.provider,
|
|
4028
|
-
feeToken: quote.feeInfo.selectedFeeToken,
|
|
4029
|
-
recipient: data.recipient,
|
|
4030
|
-
pair: quote.pair,
|
|
4031
|
-
fromAmount: quote.fromAmount,
|
|
4032
|
-
slippage: data.slippage
|
|
4033
|
-
});
|
|
4034
|
-
return this.handleSwapStep({
|
|
4035
|
-
...data,
|
|
4036
|
-
quote: latestSwapQuote.optimalQuote || data.quote,
|
|
4037
|
-
currentStep: step,
|
|
4038
|
-
isPassConfirmation,
|
|
4039
|
-
errorOnTimeOut: true,
|
|
4040
|
-
processId
|
|
4041
|
-
});
|
|
4042
|
-
}
|
|
4043
4011
|
return this.handleSwapStep({
|
|
4044
4012
|
...data,
|
|
4045
4013
|
currentStep: step,
|
|
@@ -4464,6 +4432,8 @@ export default class KoniExtension {
|
|
|
4464
4432
|
return this.getSupportedSmartContractTypes();
|
|
4465
4433
|
case 'pri(chainService.enableChain)':
|
|
4466
4434
|
return await this.enableChain(request);
|
|
4435
|
+
case 'pri(chainService.enableChainWithPriorityAssets)':
|
|
4436
|
+
return await this.enableChainWithPriorityAssets(request);
|
|
4467
4437
|
case 'pri(chainService.reconnectChain)':
|
|
4468
4438
|
return await this.reconnectChain(request);
|
|
4469
4439
|
case 'pri(chainService.disableChain)':
|
|
@@ -4740,8 +4710,6 @@ export default class KoniExtension {
|
|
|
4740
4710
|
/* Swap service */
|
|
4741
4711
|
case 'pri(swapService.subscribePairs)':
|
|
4742
4712
|
return this.subscribeSwapPairs(id, port);
|
|
4743
|
-
case 'pri(swapService.getOptimalProcessOnSelectQuote)':
|
|
4744
|
-
return this.getOptimalSwapProcessOnSelectQuote(request);
|
|
4745
4713
|
case 'pri(swapService.handleSwapRequest)':
|
|
4746
4714
|
return this.handleSwapRequest(request);
|
|
4747
4715
|
case 'pri(swapService.handleSwapRequestV2)':
|
|
@@ -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;
|
|
@@ -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",
|
|
@@ -1886,11 +1901,6 @@
|
|
|
1886
1901
|
"require": "./cjs/services/swap-service/handler/uniswap-handler.js",
|
|
1887
1902
|
"default": "./services/swap-service/handler/uniswap-handler.js"
|
|
1888
1903
|
},
|
|
1889
|
-
"./services/swap-service/interface": {
|
|
1890
|
-
"types": "./services/swap-service/interface.d.ts",
|
|
1891
|
-
"require": "./cjs/services/swap-service/interface.js",
|
|
1892
|
-
"default": "./services/swap-service/interface.js"
|
|
1893
|
-
},
|
|
1894
1904
|
"./services/swap-service/utils": {
|
|
1895
1905
|
"types": "./services/swap-service/utils.d.ts",
|
|
1896
1906
|
"require": "./cjs/services/swap-service/utils.js",
|
|
@@ -2620,6 +2630,7 @@
|
|
|
2620
2630
|
"./utils/staticData/currencySymbol.json": "./utils/staticData/currencySymbol.json",
|
|
2621
2631
|
"./utils/staticData/marketingCampaigns.json": "./utils/staticData/marketingCampaigns.json",
|
|
2622
2632
|
"./utils/staticData/oldChainPrefix.json": "./utils/staticData/oldChainPrefix.json",
|
|
2633
|
+
"./utils/staticData/paraSpellChainMap.json": "./utils/staticData/paraSpellChainMap.json",
|
|
2623
2634
|
"./utils/staticData/remindNotificationTime.json": "./utils/staticData/remindNotificationTime.json",
|
|
2624
2635
|
"./utils/staticData/termAndCondition.json": "./utils/staticData/termAndCondition.json",
|
|
2625
2636
|
"./utils/swap": {
|
|
@@ -2642,7 +2653,6 @@
|
|
|
2642
2653
|
"@ethereumjs/common": "^4.1.0",
|
|
2643
2654
|
"@ethereumjs/tx": "^5.1.0",
|
|
2644
2655
|
"@ethersproject/abi": "^5.7.0",
|
|
2645
|
-
"@galacticcouncil/sdk": "^5.1.0",
|
|
2646
2656
|
"@gear-js/api": "^0.38.1",
|
|
2647
2657
|
"@json-rpc-tools/utils": "^1.7.6",
|
|
2648
2658
|
"@metamask/eth-sig-util": "^7.0.3",
|
|
@@ -2669,13 +2679,13 @@
|
|
|
2669
2679
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2670
2680
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2671
2681
|
"@substrate/connect": "^0.8.9",
|
|
2672
|
-
"@subwallet/chain-list": "0.2.
|
|
2673
|
-
"@subwallet/extension-base": "^1.3.
|
|
2674
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2675
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2676
|
-
"@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",
|
|
2677
2687
|
"@subwallet/keyring": "^0.1.9",
|
|
2678
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2688
|
+
"@subwallet/subwallet-api-sdk": "^1.3.31-0",
|
|
2679
2689
|
"@subwallet/ui-keyring": "^0.1.9",
|
|
2680
2690
|
"@ton/core": "^0.56.3",
|
|
2681
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 {};
|