@subwallet/extension-base 1.2.3-1 → 1.2.4-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 +0 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +2 -2
- package/cjs/core/logic-validation/transfer.js +0 -7
- package/cjs/core/substrate/nominationpools-pallet.js +11 -1
- package/cjs/core/substrate/system-pallet.js +2 -3
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +10 -119
- package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
- package/cjs/koni/api/xcm/utils.js +8 -126
- package/cjs/koni/api/xcm/xTokens.js +10 -8
- package/cjs/koni/api/xcm/xcmPallet.js +6 -6
- package/cjs/koni/background/handlers/Extension.js +90 -113
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +6 -3
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/utils/index.js +7 -2
- package/cjs/services/earning-service/handlers/special.js +3 -3
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/swap-service/handler/base-handler.js +5 -3
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/core/logic-validation/earning.d.ts +1 -1
- package/core/logic-validation/earning.js +2 -2
- package/core/logic-validation/transfer.js +0 -7
- package/core/substrate/nominationpools-pallet.d.ts +4 -1
- package/core/substrate/nominationpools-pallet.js +8 -1
- package/core/substrate/system-pallet.js +2 -3
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +0 -3
- package/koni/api/dotsama/transfer.js +12 -119
- package/koni/api/xcm/polkadotXcm.js +14 -22
- package/koni/api/xcm/utils.d.ts +3 -48
- package/koni/api/xcm/utils.js +5 -114
- package/koni/api/xcm/xTokens.js +12 -10
- package/koni/api/xcm/xcmPallet.js +7 -7
- package/koni/background/handlers/Extension.d.ts +1 -3
- package/koni/background/handlers/Extension.js +8 -28
- package/package.json +11 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +8 -5
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/utils/index.d.ts +3 -2
- package/services/chain-service/utils/index.js +5 -2
- package/services/earning-service/handlers/special.js +3 -3
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/services/migration-service/scripts/index.js +2 -2
- package/services/swap-service/handler/base-handler.js +5 -3
- package/services/swap-service/handler/hydradx-handler.js +1 -1
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
6
|
+
import { _isBridgedToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
|
-
|
|
8
|
-
const version = ['statemint', 'statemine', 'shiden', 'astar'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
9
|
-
const beneficiary = getBeneficiary(destinationChainInfo, recipientAddress, version);
|
|
10
|
-
const destination = getDestinationChainLocation(originChainInfo, destinationChainInfo, version);
|
|
11
|
-
let assetLocation = getTokenLocation(tokenInfo, value, version);
|
|
8
|
+
let version = STABLE_XCM_VERSION;
|
|
12
9
|
let method = 'limitedReserveTransferAssets';
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
parents: 1,
|
|
19
|
-
interior: 'Here'
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
fun: {
|
|
23
|
-
Fungible: value
|
|
24
|
-
}
|
|
25
|
-
}]
|
|
26
|
-
};
|
|
10
|
+
if (_isBridgedToken(tokenInfo)) {
|
|
11
|
+
version = 4;
|
|
12
|
+
method = 'transferAssets';
|
|
13
|
+
}
|
|
14
|
+
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
27
15
|
method = 'limitedTeleportAssets';
|
|
28
16
|
}
|
|
29
|
-
|
|
17
|
+
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
18
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, version);
|
|
19
|
+
const beneficiary = _getXcmBeneficiary(destinationChainInfo, recipientAddress, version);
|
|
20
|
+
const tokenLocation = _getXcmMultiAssets(tokenInfo, value, version);
|
|
21
|
+
return api.tx.polkadotXcm[method](destination, beneficiary, tokenLocation, 0,
|
|
30
22
|
// FeeAssetItem
|
|
31
23
|
weightParam);
|
|
32
24
|
}
|
package/koni/api/xcm/utils.d.ts
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare
|
|
4
|
-
Limited: number;
|
|
5
|
-
};
|
|
6
|
-
export declare function getReceiverLocation(destinationChainInfo: _ChainInfo, toAddress: string, version?: string): Record<string, any>;
|
|
7
|
-
export declare function getBeneficiary(destinationChainInfo: _ChainInfo, recipientAddress: string, version?: string): {
|
|
8
|
-
[x: string]: {
|
|
9
|
-
parents: number;
|
|
10
|
-
interior: {
|
|
11
|
-
X1: Record<string, any>;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare function getDestWeight(): string;
|
|
16
|
-
export declare function getTokenLocation(tokenInfo: _ChainAsset, sendingValue: string, version?: string): {
|
|
17
|
-
[x: string]: {
|
|
18
|
-
id: Record<string, any>;
|
|
19
|
-
fun: {
|
|
20
|
-
Fungible: string;
|
|
21
|
-
};
|
|
22
|
-
}[];
|
|
23
|
-
};
|
|
24
|
-
export declare function getDestMultilocation(destinationChainInfo: _ChainInfo, recipient: string, version?: string): {
|
|
25
|
-
[x: string]: {
|
|
26
|
-
parents: number;
|
|
27
|
-
interior: {
|
|
28
|
-
X2: Record<string, any>[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
} | {
|
|
32
|
-
[x: string]: {
|
|
33
|
-
parents: number;
|
|
34
|
-
interior: {
|
|
35
|
-
X1: Record<string, any>;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export declare function getDestinationChainLocation(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, version?: string): {
|
|
40
|
-
[x: string]: {
|
|
41
|
-
parents: number;
|
|
42
|
-
interior: string | {
|
|
43
|
-
X1: {
|
|
44
|
-
Parachain: number;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
export declare const STABLE_XCM_VERSION = 3;
|
|
3
|
+
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
package/koni/api/xcm/utils.js
CHANGED
|
@@ -1,118 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Limited: 5000000000
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// get multilocation for destination chain from a parachain
|
|
13
|
-
|
|
14
|
-
export function getReceiverLocation(destinationChainInfo, toAddress, version) {
|
|
15
|
-
const network = version && version === 'V3' ? undefined : 'Any';
|
|
16
|
-
if (destinationChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
17
|
-
const ss58Address = evmToAddress(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
AccountId32: {
|
|
21
|
-
network,
|
|
22
|
-
id: decodeAddress(ss58Address)
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (_isChainEvmCompatible(destinationChainInfo)) {
|
|
27
|
-
return {
|
|
28
|
-
AccountKey20: {
|
|
29
|
-
network,
|
|
30
|
-
key: toAddress
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
AccountId32: {
|
|
36
|
-
network,
|
|
37
|
-
id: decodeAddress(toAddress)
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export function getBeneficiary(destinationChainInfo, recipientAddress, version = 'V1') {
|
|
42
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
|
|
43
|
-
return {
|
|
44
|
-
[version]: {
|
|
45
|
-
parents: 0,
|
|
46
|
-
interior: {
|
|
47
|
-
X1: receiverLocation
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export function getDestWeight() {
|
|
53
|
-
return 'Unlimited';
|
|
54
|
-
}
|
|
55
|
-
export function getTokenLocation(tokenInfo, sendingValue, version = 'V1') {
|
|
56
|
-
if (!_isNativeToken(tokenInfo)) {
|
|
57
|
-
const multilocation = _getXcmAssetMultilocation(tokenInfo);
|
|
58
|
-
return {
|
|
59
|
-
[version]: [{
|
|
60
|
-
id: multilocation,
|
|
61
|
-
fun: {
|
|
62
|
-
Fungible: sendingValue
|
|
63
|
-
}
|
|
64
|
-
}]
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
[version]: [{
|
|
69
|
-
id: {
|
|
70
|
-
Concrete: {
|
|
71
|
-
parents: 0,
|
|
72
|
-
interior: 'Here'
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
fun: {
|
|
76
|
-
Fungible: sendingValue
|
|
77
|
-
}
|
|
78
|
-
}]
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
export function getDestMultilocation(destinationChainInfo, recipient, version = 'V1') {
|
|
82
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipient, version);
|
|
83
|
-
if (_isSubstrateParaChain(destinationChainInfo)) {
|
|
84
|
-
const interior = {
|
|
85
|
-
X2: [{
|
|
86
|
-
Parachain: _getSubstrateParaId(destinationChainInfo)
|
|
87
|
-
}, receiverLocation]
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
[version]: {
|
|
91
|
-
parents: 1,
|
|
92
|
-
interior
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
[version]: {
|
|
98
|
-
parents: 1,
|
|
99
|
-
interior: {
|
|
100
|
-
X1: receiverLocation
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
export function getDestinationChainLocation(originChainInfo, destinationChainInfo, version = 'V1') {
|
|
106
|
-
const parents = _isSubstrateRelayChain(originChainInfo) ? 0 : 1;
|
|
107
|
-
const interior = _isSubstrateParaChain(destinationChainInfo) ? {
|
|
108
|
-
X1: {
|
|
109
|
-
Parachain: _getSubstrateParaId(destinationChainInfo)
|
|
110
|
-
}
|
|
111
|
-
} : 'Here';
|
|
112
|
-
return {
|
|
113
|
-
[version]: {
|
|
114
|
-
parents,
|
|
115
|
-
interior
|
|
116
|
-
}
|
|
117
|
-
};
|
|
4
|
+
export const STABLE_XCM_VERSION = 3;
|
|
5
|
+
export function isUseTeleportProtocol(originChainInfo, destChainInfo) {
|
|
6
|
+
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug);
|
|
7
|
+
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug);
|
|
8
|
+
return relayChainToSystemChain || systemChainToRelayChain;
|
|
118
9
|
}
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
6
|
+
import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
function getCurrencyId(tokenInfo) {
|
|
7
|
-
if (['
|
|
8
|
-
return _getXcmAssetMultilocation(tokenInfo);
|
|
9
|
-
} else if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
8
|
+
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
10
9
|
const tokenType = _getXcmAssetType(tokenInfo);
|
|
11
10
|
const assetId = _getXcmAssetId(tokenInfo);
|
|
12
11
|
return {
|
|
13
12
|
[tokenType]: assetId
|
|
14
13
|
};
|
|
15
|
-
} else if (['pioneer'].includes(tokenInfo.originChain)) {
|
|
16
|
-
return _getXcmAssetMultilocation(tokenInfo);
|
|
17
14
|
}
|
|
18
15
|
return _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo);
|
|
19
16
|
}
|
|
20
17
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
const version = STABLE_XCM_VERSION;
|
|
19
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, version, recipientAddress);
|
|
20
|
+
if (!_getXcmAssetMultilocation(tokenInfo)) {
|
|
21
|
+
const tokenCurrencyId = getCurrencyId(tokenInfo);
|
|
22
|
+
return api.tx.xTokens.transfer(tokenCurrencyId, value, destination, _getXcmDestWeight(originChainInfo));
|
|
23
|
+
}
|
|
24
|
+
const tokenMultiAsset = _getXcmMultiAssets(tokenInfo, value, version);
|
|
25
|
+
return api.tx.xTokens.transferMultiassets(tokenMultiAsset, 0, destination, _getXcmDestWeight(originChainInfo));
|
|
24
26
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/koni/api/xcm/utils';
|
|
5
6
|
// this pallet is only used by Relaychains
|
|
6
7
|
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
|
-
const weightParam =
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const tokenLocation = getTokenLocation(tokenInfo, value, xcmVer);
|
|
8
|
+
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
9
|
+
const destination = _getXcmMultiLocation(originChainInfo, destinationChainInfo, STABLE_XCM_VERSION);
|
|
10
|
+
const beneficiary = _getXcmBeneficiary(destinationChainInfo, recipientAddress, STABLE_XCM_VERSION);
|
|
11
|
+
const tokenLocation = _getXcmMultiAssets(tokenInfo, value, STABLE_XCM_VERSION);
|
|
12
12
|
let method = 'limitedReserveTransferAssets';
|
|
13
|
-
if (
|
|
13
|
+
if (isUseTeleportProtocol(originChainInfo, destinationChainInfo)) {
|
|
14
14
|
method = 'limitedTeleportAssets';
|
|
15
15
|
}
|
|
16
16
|
return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
|
|
@@ -143,9 +143,6 @@ export default class KoniExtension {
|
|
|
143
143
|
private getXcmMaxTransferable;
|
|
144
144
|
private getNativeTokenMaxTransferable;
|
|
145
145
|
private subscribeAddressTransferableBalance;
|
|
146
|
-
private transferCheckReferenceCount;
|
|
147
|
-
private transferCheckSupporting;
|
|
148
|
-
private transferGetExistentialDeposit;
|
|
149
146
|
private substrateNftSubmitTransaction;
|
|
150
147
|
private enableChains;
|
|
151
148
|
private getAccountMeta;
|
|
@@ -182,6 +179,7 @@ export default class KoniExtension {
|
|
|
182
179
|
private keyringMigrateMasterPassword;
|
|
183
180
|
private keyringUnlock;
|
|
184
181
|
private keyringLock;
|
|
182
|
+
keyringLockSubscribe(cb: (state: boolean) => void): any;
|
|
185
183
|
private keyringExportMnemonic;
|
|
186
184
|
private resetWallet;
|
|
187
185
|
private signingApprovePasswordV2;
|
|
@@ -12,7 +12,7 @@ import { additionalValidateTransfer, additionalValidateXcmTransfer, validateTran
|
|
|
12
12
|
import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
|
|
13
13
|
import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
|
|
14
14
|
import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
|
|
15
|
-
import {
|
|
15
|
+
import { createTransferExtrinsic, getTransferMockTxFee } from '@subwallet/extension-base/koni/api/dotsama/transfer';
|
|
16
16
|
import { getNftTransferExtrinsic, isRecipientSelf } from '@subwallet/extension-base/koni/api/nft/transfer';
|
|
17
17
|
import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, validateBondingCondition, validateUnbondingCondition } from '@subwallet/extension-base/koni/api/staking/bonding';
|
|
18
18
|
import { getTuringCancelCompoundingExtrinsic, getTuringCompoundExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
|
|
@@ -23,7 +23,7 @@ import { createXcmExtrinsic, getXcmMockTxFee } from '@subwallet/extension-base/k
|
|
|
23
23
|
import { YIELD_EXTRINSIC_TYPES } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
24
24
|
import { _API_OPTIONS_CHAIN_GROUP, _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
25
25
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
26
|
-
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash,
|
|
26
|
+
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isTokenEvmSmartContract, _isTokenTransferredByEvm } from '@subwallet/extension-base/services/chain-service/utils';
|
|
27
27
|
import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
28
28
|
import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
|
|
29
29
|
import { WALLET_CONNECT_EIP155_NAMESPACE } from '@subwallet/extension-base/services/wallet-connect-service/constants';
|
|
@@ -38,6 +38,7 @@ import { keyring } from '@subwallet/ui-keyring';
|
|
|
38
38
|
import { getSdkError } from '@walletconnect/utils';
|
|
39
39
|
import BigN from 'bignumber.js';
|
|
40
40
|
import { t } from 'i18next';
|
|
41
|
+
import { Subject } from 'rxjs';
|
|
41
42
|
import { TypeRegistry } from '@polkadot/types';
|
|
42
43
|
import { assert, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
|
|
43
44
|
import { base64Decode, decodeAddress, isAddress, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
|
|
@@ -74,6 +75,7 @@ export default class KoniExtension {
|
|
|
74
75
|
#skipAutoLock = false;
|
|
75
76
|
#firstTime = true;
|
|
76
77
|
#alwaysLock = false;
|
|
78
|
+
#keyringLockSubject = new Subject();
|
|
77
79
|
constructor(state) {
|
|
78
80
|
this.#koniState = state;
|
|
79
81
|
const updateTimeAutoLock = rs => {
|
|
@@ -1912,26 +1914,6 @@ export default class KoniExtension {
|
|
|
1912
1914
|
});
|
|
1913
1915
|
return convertData(currentFreeBalance);
|
|
1914
1916
|
}
|
|
1915
|
-
async transferCheckReferenceCount({
|
|
1916
|
-
address,
|
|
1917
|
-
networkKey
|
|
1918
|
-
}) {
|
|
1919
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
|
|
1920
|
-
return await checkReferenceCount(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
|
|
1921
|
-
}
|
|
1922
|
-
async transferCheckSupporting({
|
|
1923
|
-
networkKey,
|
|
1924
|
-
tokenSlug
|
|
1925
|
-
}) {
|
|
1926
|
-
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1927
|
-
return await checkSupportTransfer(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
|
|
1928
|
-
}
|
|
1929
|
-
transferGetExistentialDeposit({
|
|
1930
|
-
tokenSlug
|
|
1931
|
-
}) {
|
|
1932
|
-
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1933
|
-
return _getTokenMinAmount(tokenInfo);
|
|
1934
|
-
}
|
|
1935
1917
|
async substrateNftSubmitTransaction(inputData) {
|
|
1936
1918
|
const {
|
|
1937
1919
|
params,
|
|
@@ -2816,8 +2798,12 @@ export default class KoniExtension {
|
|
|
2816
2798
|
|
|
2817
2799
|
keyringLock() {
|
|
2818
2800
|
this.#koniState.keyringService.lock();
|
|
2801
|
+
this.#keyringLockSubject.next(true);
|
|
2819
2802
|
clearTimeout(this.#lockTimeOut);
|
|
2820
2803
|
}
|
|
2804
|
+
keyringLockSubscribe(cb) {
|
|
2805
|
+
this.#keyringLockSubject.subscribe(cb);
|
|
2806
|
+
}
|
|
2821
2807
|
|
|
2822
2808
|
// Export mnemonic
|
|
2823
2809
|
|
|
@@ -4297,12 +4283,6 @@ export default class KoniExtension {
|
|
|
4297
4283
|
return this.subscribeAssetSetting(id, port);
|
|
4298
4284
|
case 'pri(assetSetting.update)':
|
|
4299
4285
|
return await this.updateAssetSetting(request);
|
|
4300
|
-
case 'pri(transfer.checkReferenceCount)':
|
|
4301
|
-
return await this.transferCheckReferenceCount(request);
|
|
4302
|
-
case 'pri(transfer.checkSupporting)':
|
|
4303
|
-
return await this.transferCheckSupporting(request);
|
|
4304
|
-
case 'pri(transfer.getExistentialDeposit)':
|
|
4305
|
-
return this.transferGetExistentialDeposit(request);
|
|
4306
4286
|
case 'pri(transfer.getMaxTransferable)':
|
|
4307
4287
|
return this.getMaxTransferable(request);
|
|
4308
4288
|
case 'pri(transfer.subscribeMaxTransferable)':
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.
|
|
20
|
+
"version": "1.2.4-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -154,6 +154,11 @@
|
|
|
154
154
|
"require": "./cjs/core/substrate/system-pallet.js",
|
|
155
155
|
"default": "./core/substrate/system-pallet.js"
|
|
156
156
|
},
|
|
157
|
+
"./core/substrate/xcm-parser": {
|
|
158
|
+
"types": "./core/substrate/xcm-parser.d.ts",
|
|
159
|
+
"require": "./cjs/core/substrate/xcm-parser.js",
|
|
160
|
+
"default": "./core/substrate/xcm-parser.js"
|
|
161
|
+
},
|
|
157
162
|
"./defaults": {
|
|
158
163
|
"types": "./defaults.d.ts",
|
|
159
164
|
"require": "./cjs/defaults.js",
|
|
@@ -1916,11 +1921,11 @@
|
|
|
1916
1921
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1917
1922
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1918
1923
|
"@substrate/connect": "^0.8.9",
|
|
1919
|
-
"@subwallet/chain-list": "0.2.
|
|
1920
|
-
"@subwallet/extension-base": "^1.2.
|
|
1921
|
-
"@subwallet/extension-chains": "^1.2.
|
|
1922
|
-
"@subwallet/extension-dapp": "^1.2.
|
|
1923
|
-
"@subwallet/extension-inject": "^1.2.
|
|
1924
|
+
"@subwallet/chain-list": "0.2.67",
|
|
1925
|
+
"@subwallet/extension-base": "^1.2.4-0",
|
|
1926
|
+
"@subwallet/extension-chains": "^1.2.4-0",
|
|
1927
|
+
"@subwallet/extension-dapp": "^1.2.4-0",
|
|
1928
|
+
"@subwallet/extension-inject": "^1.2.4-0",
|
|
1924
1929
|
"@subwallet/keyring": "^0.1.5",
|
|
1925
1930
|
"@subwallet/ui-keyring": "^0.1.5",
|
|
1926
1931
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
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.2.
|
|
10
|
+
version: '1.2.4-0'
|
|
11
11
|
};
|
|
@@ -5,12 +5,12 @@ import { GearApi } from '@gear-js/api';
|
|
|
5
5
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
6
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
7
|
import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
8
|
-
import {
|
|
8
|
+
import { _getTotalStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
|
|
9
9
|
import { _getSystemPalletTotalBalance, _getSystemPalletTransferable } from '@subwallet/extension-base/core/substrate/system-pallet';
|
|
10
10
|
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/tokens/wasm';
|
|
11
11
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
12
12
|
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
|
-
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain,
|
|
13
|
+
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
14
|
import { filterAssetsByChainAndType, getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
15
15
|
import BigN from 'bignumber.js';
|
|
16
16
|
import { combineLatest, Observable } from 'rxjs';
|
|
@@ -131,7 +131,7 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
131
131
|
const items = balances.map((_balance, index) => {
|
|
132
132
|
const balanceInfo = _balance.toPrimitive();
|
|
133
133
|
const poolMemberInfo = poolMemberInfos[index].toPrimitive();
|
|
134
|
-
const nominationPoolBalance = poolMemberInfo ?
|
|
134
|
+
const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : new BigN(0);
|
|
135
135
|
const transferableBalance = _getSystemPalletTransferable(balanceInfo, _getChainExistentialDeposit(chainInfo), extrinsicType);
|
|
136
136
|
const totalBalance = _getSystemPalletTotalBalance(balanceInfo);
|
|
137
137
|
const totalLockedFromTransfer = new BigN(totalBalance).minus(transferableBalance).plus(nominationPoolBalance);
|
|
@@ -165,8 +165,8 @@ const subscribeBridgedBalance = async ({
|
|
|
165
165
|
try {
|
|
166
166
|
const isBridgedToken = _isBridgedToken(tokenInfo);
|
|
167
167
|
if (isBridgedToken) {
|
|
168
|
-
const
|
|
169
|
-
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [
|
|
168
|
+
const onChainInfo = _getTokenOnChainInfo(tokenInfo);
|
|
169
|
+
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [onChainInfo, address]), balances => {
|
|
170
170
|
const items = balances.map((balance, index) => {
|
|
171
171
|
const bdata = balance === null || balance === void 0 ? void 0 : balance.toHuman();
|
|
172
172
|
let frozen = BN_ZERO;
|
|
@@ -339,6 +339,9 @@ const subscribeAssetsAccountPallet = async ({
|
|
|
339
339
|
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
340
340
|
try {
|
|
341
341
|
const assetIndex = _getTokenOnChainAssetId(tokenInfo);
|
|
342
|
+
if (assetIndex === '-1') {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
342
345
|
|
|
343
346
|
// Get Token Balance
|
|
344
347
|
return await substrateApi.query.assets.account.multi(addresses.map(address => [assetIndex, address]), balances => {
|
|
@@ -34,7 +34,7 @@ export const _BALANCE_CHAIN_GROUP = {
|
|
|
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
|
-
supportBridged: ['rococo_assethub']
|
|
37
|
+
supportBridged: ['rococo_assethub', 'statemint', 'statemine']
|
|
38
38
|
};
|
|
39
39
|
export const _BALANCE_TOKEN_GROUP = {
|
|
40
40
|
crab: ['CKTON', 'PKTON'],
|
|
@@ -249,7 +249,7 @@ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
249
249
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
250
250
|
|
|
251
251
|
export const _XCM_CHAIN_GROUP = {
|
|
252
|
-
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain'],
|
|
252
|
+
polkadotXcm: ['astar', 'shiden', 'statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub'],
|
|
253
253
|
xcmPallet: ['polkadot', 'kusama']
|
|
254
254
|
// default is xTokens pallet
|
|
255
255
|
};
|
|
@@ -35,9 +35,9 @@ export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
|
|
|
35
35
|
export declare function _isNativeTokenBySlug(tokenSlug: string): boolean;
|
|
36
36
|
export declare function _isSmartContractToken(tokenInfo: _ChainAsset): boolean;
|
|
37
37
|
export declare function _isSubstrateChain(chainInfo: _ChainInfo): boolean;
|
|
38
|
-
export declare function _getEvmChainId(chainInfo: _ChainInfo): number;
|
|
38
|
+
export declare function _getEvmChainId(chainInfo: _ChainInfo): number | undefined;
|
|
39
39
|
export declare function _getSubstrateParaId(chainInfo: _ChainInfo): number;
|
|
40
|
-
export declare function _getSubstrateRelayParent(chainInfo: _ChainInfo): string;
|
|
40
|
+
export declare function _getSubstrateRelayParent(chainInfo: _ChainInfo): string | null | undefined;
|
|
41
41
|
export declare function _getSubstrateGenesisHash(chainInfo: _ChainInfo): string;
|
|
42
42
|
export declare function _isChainSupportSubstrateStaking(chainInfo: _ChainInfo): boolean;
|
|
43
43
|
export declare function _isChainEnabled(chainState: _ChainState): boolean;
|
|
@@ -64,6 +64,7 @@ export declare function _getXcmAssetType(tokenInfo: _ChainAsset): string;
|
|
|
64
64
|
export declare function _getXcmAssetId(tokenInfo: _ChainAsset): string;
|
|
65
65
|
export declare function _getXcmAssetMultilocation(tokenInfo: _ChainAsset): Record<string, any>;
|
|
66
66
|
export declare function _getXcmTransferType(originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo): string;
|
|
67
|
+
export declare function _isRelayChain(chainInfo: _ChainInfo): boolean;
|
|
67
68
|
export declare function _isSubstrateRelayChain(chainInfo: _ChainInfo): boolean;
|
|
68
69
|
export declare function _isSubstrateParaChain(chainInfo: _ChainInfo): boolean;
|
|
69
70
|
export declare function _getEvmAbiExplorer(chainInfo: _ChainInfo): string;
|
|
@@ -131,7 +131,7 @@ export function _isSubstrateChain(chainInfo) {
|
|
|
131
131
|
|
|
132
132
|
export function _getEvmChainId(chainInfo) {
|
|
133
133
|
var _chainInfo$evmInfo;
|
|
134
|
-
return (
|
|
134
|
+
return (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId; // fallback to Ethereum
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export function _getSubstrateParaId(chainInfo) {
|
|
@@ -140,7 +140,7 @@ export function _getSubstrateParaId(chainInfo) {
|
|
|
140
140
|
}
|
|
141
141
|
export function _getSubstrateRelayParent(chainInfo) {
|
|
142
142
|
var _chainInfo$substrateI2;
|
|
143
|
-
return (
|
|
143
|
+
return (_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.relaySlug;
|
|
144
144
|
}
|
|
145
145
|
export function _getSubstrateGenesisHash(chainInfo) {
|
|
146
146
|
var _chainInfo$substrateI3;
|
|
@@ -292,6 +292,9 @@ export function _getXcmTransferType(originChainInfo, destinationChainInfo) {
|
|
|
292
292
|
var _originChainInfo$subs, _destinationChainInfo;
|
|
293
293
|
return `${((_originChainInfo$subs = originChainInfo.substrateInfo) === null || _originChainInfo$subs === void 0 ? void 0 : _originChainInfo$subs.chainType) || ''}-${((_destinationChainInfo = destinationChainInfo.substrateInfo) === null || _destinationChainInfo === void 0 ? void 0 : _destinationChainInfo.chainType) || ''}`;
|
|
294
294
|
}
|
|
295
|
+
export function _isRelayChain(chainInfo) {
|
|
296
|
+
return _isSubstrateRelayChain(chainInfo) || _isPureEvmChain(chainInfo);
|
|
297
|
+
}
|
|
295
298
|
export function _isSubstrateRelayChain(chainInfo) {
|
|
296
299
|
var _chainInfo$substrateI14;
|
|
297
300
|
return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _SubstrateChainType.RELAYCHAIN;
|
|
@@ -277,11 +277,11 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
277
277
|
const xcmFee = new BN(path.totalFee[1].amount || '0');
|
|
278
278
|
const xcmAmount = missingAmount.add(xcmFee);
|
|
279
279
|
const bnAltInputTokenBalance = new BN(altInputTokenBalance.value || '0');
|
|
280
|
-
if (!bnAltInputTokenBalance.sub(xcmAmount).gt(BN_ZERO)) {
|
|
280
|
+
if (!bnAltInputTokenBalance.sub(xcmAmount).sub(xcmFee).gt(BN_ZERO)) {
|
|
281
281
|
processValidation.failedStep = path.steps[1];
|
|
282
282
|
processValidation.ok = false;
|
|
283
283
|
processValidation.status = YieldValidationStatus.NOT_ENOUGH_BALANCE;
|
|
284
|
-
const maxBn = bnInputTokenBalance.add(new BN(altInputTokenBalance.value)).sub(xcmFee);
|
|
284
|
+
const maxBn = bnInputTokenBalance.add(new BN(altInputTokenBalance.value)).sub(xcmFee).sub(xcmFee);
|
|
285
285
|
const maxValue = formatNumber(maxBn.toString(), inputTokenInfo.decimals || 0);
|
|
286
286
|
const altInputTokenInfo = this.state.getAssetBySlug(altInputTokenSlug);
|
|
287
287
|
const symbol = altInputTokenInfo.symbol;
|
|
@@ -289,7 +289,7 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
|
|
|
289
289
|
const inputNetworkName = this.chainInfo.name;
|
|
290
290
|
const altNetworkName = altNetwork.name;
|
|
291
291
|
const currentValue = formatNumber(bnInputTokenBalance.toString(), inputTokenInfo.decimals || 0);
|
|
292
|
-
const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee);
|
|
292
|
+
const bnMaxXCM = new BN(altInputTokenBalance.value).sub(xcmFee).sub(xcmFee);
|
|
293
293
|
const maxXCMValue = formatNumber(bnMaxXCM.toString(), inputTokenInfo.decimals || 0);
|
|
294
294
|
processValidation.message = t('You can only enter a maximum of {{maxValue}} {{symbol}}, which is {{currentValue}} {{symbol}} ({{inputNetworkName}}) and {{maxXCMValue}} {{symbol}} ({{altNetworkName}}). Lower your amount and try again.', {
|
|
295
295
|
replace: {
|
|
@@ -7,7 +7,8 @@ export default class MigrateTransactionHistoryBySymbol extends BaseMigrationJob
|
|
|
7
7
|
const state = this.state;
|
|
8
8
|
try {
|
|
9
9
|
const changeSlugsMap = {
|
|
10
|
-
'
|
|
10
|
+
'bobMainnet-LOCAL-wBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3': 'bobMainnet-LOCAL-WBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3',
|
|
11
|
+
'hydradx_main-LOCAL-LRNA': 'hydradx_main-LOCAL-H2O'
|
|
11
12
|
};
|
|
12
13
|
const allTxs = [];
|
|
13
14
|
await Promise.all(Object.entries(changeSlugsMap).map(async ([oldSlug, newSlug], i) => {
|
|
@@ -6,7 +6,8 @@ export default class MigrateAssetSetting extends BaseMigrationJob {
|
|
|
6
6
|
async run() {
|
|
7
7
|
try {
|
|
8
8
|
const changeSlugsMap = {
|
|
9
|
-
'
|
|
9
|
+
'bobMainnet-LOCAL-wBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3': 'bobMainnet-LOCAL-WBTC-0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3',
|
|
10
|
+
'hydradx_main-LOCAL-LRNA': 'hydradx_main-LOCAL-H2O'
|
|
10
11
|
};
|
|
11
12
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
12
13
|
const migratedAssetSetting = {};
|
|
@@ -49,8 +49,8 @@ export default {
|
|
|
49
49
|
'1.1.28-01': MigrateEarningVersion,
|
|
50
50
|
'1.1.41-01': DeleteChainStaking,
|
|
51
51
|
'1.1.46-01': AutoEnableSomeTokens,
|
|
52
|
-
'1.1.
|
|
53
|
-
'1.1.
|
|
52
|
+
'1.1.69-03': MigrateAssetSetting,
|
|
53
|
+
'1.1.69-02': MigrateTransactionHistoryBySymbol,
|
|
54
54
|
'1.2.69-01': MigrateRemoveGenesisHash
|
|
55
55
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
56
56
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
@@ -60,11 +60,13 @@ export class SwapBaseHandler {
|
|
|
60
60
|
const xcmFeeComponent = params.process.totalFee[stepIndex].feeComponent[0]; // todo: can do better than indexing
|
|
61
61
|
const xcmFee = new BigNumber(xcmFeeComponent.amount || '0');
|
|
62
62
|
let xcmAmount = bnAmount.minus(bnFromAssetBalance);
|
|
63
|
+
let editedXcmFee = new BigNumber(0);
|
|
63
64
|
if (_isNativeToken(alternativeAsset)) {
|
|
64
65
|
xcmAmount = xcmAmount.plus(xcmFee);
|
|
66
|
+
editedXcmFee = xcmFee.times(2);
|
|
65
67
|
}
|
|
66
|
-
if (!bnAlternativeAssetBalance.minus(xcmAmount).gt(0)) {
|
|
67
|
-
const maxBn = bnFromAssetBalance.plus(new BigNumber(alternativeAssetBalance.value)).minus(xcmFee);
|
|
68
|
+
if (!bnAlternativeAssetBalance.minus(_isNativeToken(alternativeAsset) ? xcmAmount.plus(xcmFee) : xcmFee).gt(0)) {
|
|
69
|
+
const maxBn = bnFromAssetBalance.plus(new BigNumber(alternativeAssetBalance.value)).minus(_isNativeToken(alternativeAsset) ? editedXcmFee : xcmFee);
|
|
68
70
|
const maxValue = formatNumber(maxBn.toString(), fromAsset.decimals || 0);
|
|
69
71
|
const altInputTokenInfo = this.chainService.getAssetBySlug(alternativeAssetSlug);
|
|
70
72
|
const symbol = altInputTokenInfo.symbol;
|
|
@@ -73,7 +75,7 @@ export class SwapBaseHandler {
|
|
|
73
75
|
const inputNetworkName = chain.name;
|
|
74
76
|
const altNetworkName = alternativeChain.name;
|
|
75
77
|
const currentValue = formatNumber(bnFromAssetBalance.toString(), fromAsset.decimals || 0);
|
|
76
|
-
const bnMaxXCM = new BigNumber(alternativeAssetBalance.value).minus(xcmFee);
|
|
78
|
+
const bnMaxXCM = new BigNumber(alternativeAssetBalance.value).minus(_isNativeToken(alternativeAsset) ? editedXcmFee : xcmFee);
|
|
77
79
|
const maxXCMValue = formatNumber(bnMaxXCM.toString(), fromAsset.decimals || 0);
|
|
78
80
|
if (maxBn.lte(0) || bnFromAssetBalance.lte(0) || bnMaxXCM.lte(0)) {
|
|
79
81
|
return [new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE, t(`Insufficient balance. Deposit ${fromAsset.symbol} and try again.`))];
|