@subwallet/extension-base 1.3.38-0 → 1.3.40-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/koni/background/handlers/Extension.js +79 -69
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/index.js +19 -28
- package/cjs/services/balance-service/transfer/xcm/utils.js +47 -49
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/index.js +4 -0
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/special.js +28 -36
- package/cjs/services/request-service/handler/AuthRequestHandler.js +2 -0
- package/cjs/services/swap-service/handler/base-handler.js +58 -53
- package/cjs/services/swap-service/handler/kyber-handler.js +44 -28
- package/cjs/services/swap-service/handler/simpleswap-handler.js +79 -40
- package/cjs/services/swap-service/utils.js +2 -0
- package/cjs/utils/fee/transfer.js +41 -33
- package/koni/background/handlers/Extension.js +15 -5
- package/package.json +7 -7
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/index.d.ts +1 -2
- package/services/balance-service/transfer/xcm/index.js +16 -25
- package/services/balance-service/transfer/xcm/utils.d.ts +36 -6
- package/services/balance-service/transfer/xcm/utils.js +46 -48
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/index.js +4 -0
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/special.js +12 -20
- package/services/request-service/handler/AuthRequestHandler.js +2 -0
- package/services/swap-service/handler/base-handler.js +11 -6
- package/services/swap-service/handler/kyber-handler.js +44 -28
- package/services/swap-service/handler/simpleswap-handler.js +80 -41
- package/services/swap-service/utils.js +2 -0
- package/utils/fee/transfer.js +11 -3
|
@@ -22,44 +22,59 @@ var _baseHandler = require("./base-handler");
|
|
|
22
22
|
const KYBER_CLIENT_ID = process.env.KYBER_CLIENT_ID || '';
|
|
23
23
|
exports.KYBER_CLIENT_ID = KYBER_CLIENT_ID;
|
|
24
24
|
const kyberUrl = 'https://aggregator-api.kyberswap.com';
|
|
25
|
-
async function
|
|
25
|
+
async function buildTxForKyberSwap(params, chain) {
|
|
26
26
|
const {
|
|
27
27
|
recipient,
|
|
28
28
|
sender,
|
|
29
29
|
slippageTolerance
|
|
30
30
|
} = params;
|
|
31
31
|
let routeSummary = params.routeSummary;
|
|
32
|
+
console.log('routeSummary1', routeSummary);
|
|
32
33
|
if (!routeSummary || !routeSummary.tokenIn || !routeSummary.tokenOut || !routeSummary.amountIn) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
return {
|
|
35
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, 'Invalid Route Summary')
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const {
|
|
39
|
+
amountIn,
|
|
40
|
+
tokenIn,
|
|
41
|
+
tokenOut
|
|
42
|
+
} = routeSummary;
|
|
43
|
+
const queryParams = new URLSearchParams({
|
|
44
|
+
tokenIn,
|
|
45
|
+
tokenOut,
|
|
46
|
+
amountIn,
|
|
47
|
+
gasInclude: 'true'
|
|
48
|
+
});
|
|
49
|
+
const url = `${kyberUrl}/${chain}/api/v1/routes?${queryParams.toString()}`;
|
|
50
|
+
try {
|
|
51
|
+
var _routeData$data;
|
|
52
|
+
const res = await fetch(url, {
|
|
53
|
+
method: 'GET',
|
|
54
|
+
headers: {
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
'x-client-id': KYBER_CLIENT_ID,
|
|
57
|
+
accept: 'application/json'
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
});
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const errorText = await res.text();
|
|
62
|
+
return {
|
|
63
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, `Fetch Kyber routes failed: ${errorText}`)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const routeData = await res.json();
|
|
67
|
+
if (!((_routeData$data = routeData.data) !== null && _routeData$data !== void 0 && _routeData$data.routeSummary)) {
|
|
59
68
|
return {
|
|
60
|
-
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)
|
|
69
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, routeData.message)
|
|
61
70
|
};
|
|
62
71
|
}
|
|
72
|
+
routeSummary = routeData.data.routeSummary;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error:', error);
|
|
75
|
+
return {
|
|
76
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, 'Unable to build Kyber swap transaction')
|
|
77
|
+
};
|
|
63
78
|
}
|
|
64
79
|
const body = {
|
|
65
80
|
routeSummary,
|
|
@@ -69,6 +84,7 @@ async function buildTxForSwap(params, chain) {
|
|
|
69
84
|
ignoreCappedSlippage: true,
|
|
70
85
|
enableGasEstimation: true
|
|
71
86
|
};
|
|
87
|
+
console.log('routeSummary2', routeSummary);
|
|
72
88
|
try {
|
|
73
89
|
const res = await fetch(`${kyberUrl}/${chain}/api/v1/route/build`, {
|
|
74
90
|
method: 'POST',
|
|
@@ -280,7 +296,7 @@ class KyberHandler {
|
|
|
280
296
|
const recipient = (0, _utils._reformatAddressWithChain)((_params$recipient = params.recipient) !== null && _params$recipient !== void 0 ? _params$recipient : sender, toChainInfo);
|
|
281
297
|
const metadata = params.quote.metadata;
|
|
282
298
|
const slippageTolerance = params.slippage * 10000;
|
|
283
|
-
const rawTx = await
|
|
299
|
+
const rawTx = await buildTxForKyberSwap({
|
|
284
300
|
routeSummary: metadata.routeSummary,
|
|
285
301
|
sender: params.address,
|
|
286
302
|
recipient,
|
|
@@ -14,49 +14,82 @@ var _getId = require("@subwallet/extension-base/utils/getId");
|
|
|
14
14
|
var _bignumber = _interopRequireWildcard(require("bignumber.js"));
|
|
15
15
|
var _smartContract = require("../../balance-service/transfer/smart-contract");
|
|
16
16
|
var _token = require("../../balance-service/transfer/token");
|
|
17
|
-
var _utils3 = require("../utils");
|
|
18
17
|
var _baseHandler = require("./base-handler");
|
|
19
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
20
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
22
21
|
// SPDX-License-Identifier: Apache-2.0
|
|
23
22
|
|
|
24
|
-
const apiUrl = 'https://api.simpleswap.io';
|
|
23
|
+
const apiUrl = 'https://api.simpleswap.io/v3';
|
|
25
24
|
const simpleSwapApiKey = process.env.SIMPLE_SWAP_API_KEY || '';
|
|
26
25
|
exports.simpleSwapApiKey = simpleSwapApiKey;
|
|
27
26
|
const toBNString = (input, decimal) => {
|
|
28
27
|
const raw = new _bignumber.BigNumber(input);
|
|
29
28
|
return raw.shiftedBy(decimal).integerValue(_bignumber.BigNumber.ROUND_CEIL).toFixed();
|
|
30
29
|
};
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
const buildTxForSimpleSwap = async params => {
|
|
31
|
+
try {
|
|
32
|
+
const {
|
|
33
|
+
fromAmount,
|
|
34
|
+
fromAsset,
|
|
35
|
+
fromSymbol,
|
|
36
|
+
metadata,
|
|
37
|
+
receiver,
|
|
38
|
+
sender,
|
|
39
|
+
toAsset,
|
|
40
|
+
toSymbol
|
|
41
|
+
} = params;
|
|
42
|
+
const fromDecimals = (0, _utils._getAssetDecimals)(fromAsset);
|
|
43
|
+
const toDecimals = (0, _utils._getAssetDecimals)(toAsset);
|
|
44
|
+
const formattedAmount = (0, _utils2.formatNumber)(fromAmount, fromDecimals, s => s);
|
|
45
|
+
const requestBody = {
|
|
46
|
+
fixed: false,
|
|
47
|
+
tickerFrom: fromSymbol,
|
|
48
|
+
tickerTo: toSymbol,
|
|
49
|
+
amount: formattedAmount,
|
|
50
|
+
networkFrom: metadata.fromChainSymbol,
|
|
51
|
+
networkTo: metadata.toChainSymbol,
|
|
52
|
+
addressTo: receiver,
|
|
53
|
+
extraIdTo: '',
|
|
54
|
+
userRefundAddress: sender,
|
|
55
|
+
userRefundExtraId: ''
|
|
56
|
+
};
|
|
57
|
+
const response = await fetch(`${apiUrl}/exchanges`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: {
|
|
60
|
+
accept: 'application/json',
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
'x-api-key': simpleSwapApiKey
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(requestBody)
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorText = await response.text();
|
|
68
|
+
return {
|
|
69
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR, `Unable to create simpleswap transaction: ${errorText}`)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const depositAddressResponse = await response.json();
|
|
73
|
+
const result = depositAddressResponse.result;
|
|
74
|
+
console.log('simpleswapID', result.id);
|
|
75
|
+
if (!(result !== null && result !== void 0 && result.id) || !result.addressFrom || !result.amountTo) {
|
|
76
|
+
return {
|
|
77
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
data: {
|
|
82
|
+
id: result.id,
|
|
83
|
+
addressFrom: result.addressFrom,
|
|
84
|
+
amountTo: toBNString(result.amountTo, toDecimals)
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error('Error:', err);
|
|
89
|
+
return {
|
|
90
|
+
error: new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
60
93
|
};
|
|
61
94
|
class SimpleSwapHandler {
|
|
62
95
|
constructor(chainService, balanceService, feeService) {
|
|
@@ -140,25 +173,31 @@ class SimpleSwapHandler {
|
|
|
140
173
|
const chainType = (0, _utils._isChainSubstrateCompatible)(chainInfo) ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM;
|
|
141
174
|
const sender = (0, _utils2._reformatAddressWithChain)(address, chainInfo);
|
|
142
175
|
const receiver = (0, _utils2._reformatAddressWithChain)(recipient !== null && recipient !== void 0 ? recipient : sender, toChainInfo);
|
|
143
|
-
const fromSymbol =
|
|
144
|
-
const toSymbol =
|
|
176
|
+
const fromSymbol = (0, _utils._getAssetSymbol)(fromAsset).toLowerCase();
|
|
177
|
+
const toSymbol = (0, _utils._getAssetSymbol)(toAsset).toLowerCase();
|
|
178
|
+
const metadata = quote.metadata;
|
|
145
179
|
const {
|
|
146
180
|
fromAmount
|
|
147
181
|
} = quote;
|
|
148
|
-
const {
|
|
149
|
-
addressFrom,
|
|
150
|
-
amountTo,
|
|
151
|
-
id
|
|
152
|
-
} = await createSwapRequest({
|
|
182
|
+
const result = await buildTxForSimpleSwap({
|
|
153
183
|
fromSymbol,
|
|
154
184
|
toSymbol,
|
|
155
185
|
fromAmount,
|
|
156
186
|
fromAsset,
|
|
157
187
|
receiver,
|
|
158
188
|
sender,
|
|
159
|
-
toAsset
|
|
189
|
+
toAsset,
|
|
190
|
+
metadata
|
|
160
191
|
});
|
|
161
|
-
|
|
192
|
+
if (result.error) {
|
|
193
|
+
console.error('Simple swap error:', result.error);
|
|
194
|
+
throw result.error;
|
|
195
|
+
}
|
|
196
|
+
const {
|
|
197
|
+
addressFrom,
|
|
198
|
+
amountTo,
|
|
199
|
+
id
|
|
200
|
+
} = result.data;
|
|
162
201
|
if (!id || id.length === 0 || !addressFrom || addressFrom.length === 0) {
|
|
163
202
|
throw new _SwapError.SwapError(_types.SwapErrorType.UNKNOWN);
|
|
164
203
|
}
|
|
@@ -41,6 +41,8 @@ exports.CHAIN_FLIP_TESTNET_EXPLORER = CHAIN_FLIP_TESTNET_EXPLORER;
|
|
|
41
41
|
const CHAIN_FLIP_MAINNET_EXPLORER = 'https://scan.chainflip.io';
|
|
42
42
|
exports.CHAIN_FLIP_MAINNET_EXPLORER = CHAIN_FLIP_MAINNET_EXPLORER;
|
|
43
43
|
const SIMPLE_SWAP_EXPLORER = 'https://simpleswap.io';
|
|
44
|
+
|
|
45
|
+
// Deprecated
|
|
44
46
|
exports.SIMPLE_SWAP_EXPLORER = SIMPLE_SWAP_EXPLORER;
|
|
45
47
|
const SIMPLE_SWAP_SUPPORTED_TESTNET_ASSET_MAPPING = {
|
|
46
48
|
'bittensor-NATIVE-TAO': 'tao',
|
|
@@ -17,11 +17,12 @@ var _acrossBridge = require("@subwallet/extension-base/services/balance-service/
|
|
|
17
17
|
var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
|
|
18
18
|
var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
|
|
19
19
|
var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
|
|
20
|
-
var _utils = require("@subwallet/extension-base/services/
|
|
21
|
-
var _utils2 = require("@subwallet/extension-base/services/
|
|
20
|
+
var _utils = require("@subwallet/extension-base/services/balance-service/transfer/xcm/utils");
|
|
21
|
+
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
22
|
+
var _utils3 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
22
23
|
var _tokenPayFee = require("@subwallet/extension-base/services/fee-service/utils/tokenPayFee");
|
|
23
24
|
var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
|
|
24
|
-
var
|
|
25
|
+
var _utils4 = require("@subwallet/extension-base/utils");
|
|
25
26
|
var _keyring = require("@subwallet/keyring");
|
|
26
27
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
27
28
|
var _util = require("@polkadot/util");
|
|
@@ -33,18 +34,18 @@ var _combine = require("./combine");
|
|
|
33
34
|
const detectTransferTxType = (srcToken, srcChain, destChain) => {
|
|
34
35
|
const isXcmTransfer = srcChain.slug !== destChain.slug;
|
|
35
36
|
if (isXcmTransfer) {
|
|
36
|
-
const isAvailBridgeFromEvm = (0,
|
|
37
|
-
const isSnowBridgeEvmTransfer = (0,
|
|
37
|
+
const isAvailBridgeFromEvm = (0, _utils2._isPureEvmChain)(srcChain) && (0, _availBridge.isAvailChainBridge)(destChain.slug);
|
|
38
|
+
const isSnowBridgeEvmTransfer = (0, _utils2._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
38
39
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
39
40
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
40
41
|
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
41
42
|
return isAvailBridgeFromEvm || isSnowBridgeEvmTransfer || isPolygonBridgeTransfer || isPosBridgeTransfer || isAcrossBridgeTransfer ? 'evm' : 'substrate';
|
|
42
43
|
} else {
|
|
43
|
-
if ((0,
|
|
44
|
+
if ((0, _utils2._isChainEvmCompatible)(srcChain) && (0, _utils2._isTokenTransferredByEvm)(srcToken)) {
|
|
44
45
|
return 'evm';
|
|
45
|
-
} else if ((0,
|
|
46
|
+
} else if ((0, _utils2._isChainTonCompatible)(srcChain) && (0, _utils2._isTokenTransferredByTon)(srcToken)) {
|
|
46
47
|
return 'ton';
|
|
47
|
-
} else if ((0,
|
|
48
|
+
} else if ((0, _utils2._isChainCardanoCompatible)(srcChain) && (0, _utils2._isTokenTransferredByCardano)(srcToken)) {
|
|
48
49
|
return 'cardano';
|
|
49
50
|
} else {
|
|
50
51
|
return 'substrate';
|
|
@@ -70,7 +71,7 @@ const calculateMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
70
71
|
} else {
|
|
71
72
|
maxTransferableAmount = await calculateTransferMaxTransferable(id, request, freeBalance, fee);
|
|
72
73
|
}
|
|
73
|
-
maxTransferableAmount.feePercentageSpecialCase =
|
|
74
|
+
maxTransferableAmount.feePercentageSpecialCase = _utils3.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE;
|
|
74
75
|
return maxTransferableAmount;
|
|
75
76
|
};
|
|
76
77
|
exports.calculateMaxTransferable = calculateMaxTransferable;
|
|
@@ -100,15 +101,15 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
100
101
|
const substrateAddress = fakeAddress; // todo: move this
|
|
101
102
|
const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
|
|
102
103
|
|
|
103
|
-
const recipient = (0,
|
|
104
|
+
const recipient = (0, _utils2._isChainEvmCompatible)(destChain) ? evmAddress : substrateAddress;
|
|
104
105
|
try {
|
|
105
106
|
let transaction;
|
|
106
|
-
if ((0, _utilCrypto.isEthereumAddress)(address) && (0, _utilCrypto.isEthereumAddress)(recipient) && (0,
|
|
107
|
+
if ((0, _utilCrypto.isEthereumAddress)(address) && (0, _utilCrypto.isEthereumAddress)(recipient) && (0, _utils2._isTokenTransferredByEvm)(srcToken)) {
|
|
107
108
|
// todo: refactor: merge getERC20TransactionObject & getEVMTransactionObject
|
|
108
109
|
// Estimate with EVM API
|
|
109
|
-
if ((0,
|
|
110
|
+
if ((0, _utils2._isTokenEvmSmartContract)(srcToken) || (0, _utils2._isLocalToken)(srcToken)) {
|
|
110
111
|
[transaction,, error] = await (0, _smartContract.getERC20TransactionObject)({
|
|
111
|
-
assetAddress: (0,
|
|
112
|
+
assetAddress: (0, _utils2._getContractAddressOfToken)(srcToken),
|
|
112
113
|
chain: srcChain.slug,
|
|
113
114
|
evmApi,
|
|
114
115
|
feeCustom,
|
|
@@ -134,7 +135,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
134
135
|
fallbackFee: true
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
|
-
} else if ((0, _keyring.isTonAddress)(address) && (0,
|
|
138
|
+
} else if ((0, _keyring.isTonAddress)(address) && (0, _utils2._isTokenTransferredByTon)(srcToken)) {
|
|
138
139
|
[transaction] = await (0, _tonTransfer.createTonTransaction)({
|
|
139
140
|
tokenInfo: srcToken,
|
|
140
141
|
from: address,
|
|
@@ -145,7 +146,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
145
146
|
// currently not used
|
|
146
147
|
tonApi
|
|
147
148
|
});
|
|
148
|
-
} else if ((0, _keyring.isCardanoAddress)(address) && (0,
|
|
149
|
+
} else if ((0, _keyring.isCardanoAddress)(address) && (0, _utils2._isTokenTransferredByCardano)(srcToken)) {
|
|
149
150
|
[transaction] = await (0, _cardanoTransfer.createCardanoTransaction)({
|
|
150
151
|
tokenInfo: srcToken,
|
|
151
152
|
from: address,
|
|
@@ -252,8 +253,8 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
252
253
|
}
|
|
253
254
|
if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
254
255
|
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
255
|
-
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(
|
|
256
|
-
const estimatedFeeLocal = await (0,
|
|
256
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils3.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
257
|
+
const estimatedFeeLocal = await (0, _utils3.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
257
258
|
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
258
259
|
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
259
260
|
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
@@ -269,14 +270,14 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
269
270
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
270
271
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
271
272
|
} else {
|
|
272
|
-
if (!(0,
|
|
273
|
+
if (!(0, _utils2._isNativeToken)(srcToken)) {
|
|
273
274
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
274
275
|
} else {
|
|
275
276
|
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(new _bignumber.default(estimatedFee));
|
|
276
277
|
}
|
|
277
278
|
}
|
|
278
279
|
return {
|
|
279
|
-
maxTransferable: maxTransferable.gt(
|
|
280
|
+
maxTransferable: maxTransferable.gt(_utils4.BN_ZERO) ? maxTransferable.toFixed(0) || '0' : '0',
|
|
280
281
|
feeOptions: feeOptions,
|
|
281
282
|
feeType: feeChainType,
|
|
282
283
|
id: id,
|
|
@@ -305,9 +306,9 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
305
306
|
let feeOptions;
|
|
306
307
|
let maxTransferable;
|
|
307
308
|
let error;
|
|
308
|
-
const isAvailBridgeFromEvm = (0,
|
|
309
|
-
const isAvailBridgeFromAvail = (0, _availBridge.isAvailChainBridge)(srcChain.slug) && (0,
|
|
310
|
-
const isSnowBridgeEvmTransfer = (0,
|
|
309
|
+
const isAvailBridgeFromEvm = (0, _utils2._isPureEvmChain)(srcChain) && (0, _availBridge.isAvailChainBridge)(destChain.slug);
|
|
310
|
+
const isAvailBridgeFromAvail = (0, _availBridge.isAvailChainBridge)(srcChain.slug) && (0, _utils2._isPureEvmChain)(destChain);
|
|
311
|
+
const isSnowBridgeEvmTransfer = (0, _utils2._isPureEvmChain)(srcChain) && (0, _xcmParser._isSnowBridgeXcm)(srcChain, destChain) && !isAvailBridgeFromEvm;
|
|
311
312
|
const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(srcChain.slug, destChain.slug);
|
|
312
313
|
const isPosBridgeTransfer = (0, _posBridge._isPosChainBridge)(srcChain.slug, destChain.slug);
|
|
313
314
|
const isAcrossBridgeTransfer = (0, _acrossBridge._isAcrossChainBridge)(srcChain.slug, destChain.slug);
|
|
@@ -316,7 +317,7 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
316
317
|
const substrateAddress = fakeAddress; // todo: move this
|
|
317
318
|
const evmAddress = (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(fakeAddress)); // todo: move this
|
|
318
319
|
const bnFreeBalance = new _bignumber.default(freeBalance.value);
|
|
319
|
-
const recipient = (0,
|
|
320
|
+
const recipient = (0, _utils2._isChainEvmCompatible)(destChain) ? evmAddress : substrateAddress;
|
|
320
321
|
if (!destToken) {
|
|
321
322
|
throw Error('Destination token is not available');
|
|
322
323
|
}
|
|
@@ -342,9 +343,9 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
342
343
|
} else if (isAcrossBridgeTransfer) {
|
|
343
344
|
funcCreateExtrinsic = _xcm.createAcrossBridgeExtrinsic;
|
|
344
345
|
if ((0, _acrossBridge._isAcrossTestnetBridge)(srcChain.slug)) {
|
|
345
|
-
params.sendingValue = (0, _bignumber.default)(0.0037).shiftedBy((0,
|
|
346
|
+
params.sendingValue = (0, _bignumber.default)(0.0037).shiftedBy((0, _utils2._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
346
347
|
} else {
|
|
347
|
-
params.sendingValue = (0, _bignumber.default)(1).shiftedBy((0,
|
|
348
|
+
params.sendingValue = (0, _bignumber.default)(1).shiftedBy((0, _utils2._getAssetDecimals)(srcToken)).toFixed(0, 1);
|
|
348
349
|
}
|
|
349
350
|
} else if (isSnowBridgeEvmTransfer) {
|
|
350
351
|
funcCreateExtrinsic = _xcm.createSnowBridgeExtrinsic;
|
|
@@ -379,8 +380,15 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
379
380
|
} else if (feeChainType === 'substrate') {
|
|
380
381
|
// Calculate fee for substrate transaction
|
|
381
382
|
if (isSubstrateXcm) {
|
|
382
|
-
const
|
|
383
|
-
|
|
383
|
+
const xcmFeeInfo = await (0, _utils.estimateXcmFee)({
|
|
384
|
+
fromChainInfo: params.originChain,
|
|
385
|
+
fromTokenInfo: params.originTokenInfo,
|
|
386
|
+
toChainInfo: params.destinationChain,
|
|
387
|
+
recipient: params.recipient,
|
|
388
|
+
sender: params.sender,
|
|
389
|
+
value: params.sendingValue
|
|
390
|
+
});
|
|
391
|
+
estimatedFee = (xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee) || '0';
|
|
384
392
|
} else {
|
|
385
393
|
try {
|
|
386
394
|
var _paymentInfo$partialF2;
|
|
@@ -423,11 +431,11 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
423
431
|
console.warn('Unable to estimate fee', e);
|
|
424
432
|
}
|
|
425
433
|
if (!destToken) {
|
|
426
|
-
maxTransferable =
|
|
434
|
+
maxTransferable = _utils4.BN_ZERO;
|
|
427
435
|
} else if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
428
436
|
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
429
|
-
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(
|
|
430
|
-
const estimatedFeeLocal = await (0,
|
|
437
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils3.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
438
|
+
const estimatedFeeLocal = await (0, _utils3.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
431
439
|
maxTransferable = bnFreeBalance.minus(estimatedFeeLocal);
|
|
432
440
|
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
433
441
|
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
@@ -443,18 +451,18 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
443
451
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
444
452
|
maxTransferable = bnFreeBalance;
|
|
445
453
|
} else {
|
|
446
|
-
if (!(0,
|
|
454
|
+
if (!(0, _utils2._isNativeToken)(srcToken)) {
|
|
447
455
|
maxTransferable = bnFreeBalance;
|
|
448
456
|
} else {
|
|
449
457
|
maxTransferable = bnFreeBalance.minus((0, _bignumber.default)(estimatedFee).multipliedBy(_constants.XCM_FEE_RATIO));
|
|
450
458
|
}
|
|
451
459
|
}
|
|
452
460
|
if (isAvailBridgeFromAvail) {
|
|
453
|
-
const addedAmount = (0, _bignumber.default)(1).shiftedBy((0,
|
|
461
|
+
const addedAmount = (0, _bignumber.default)(1).shiftedBy((0, _utils2._getAssetDecimals)(srcToken));
|
|
454
462
|
maxTransferable = maxTransferable.minus(addedAmount);
|
|
455
463
|
}
|
|
456
464
|
return {
|
|
457
|
-
maxTransferable: maxTransferable.gt(
|
|
465
|
+
maxTransferable: maxTransferable.gt(_utils4.BN_ZERO) ? maxTransferable.toFixed(0) : '0',
|
|
458
466
|
feeOptions: feeOptions,
|
|
459
467
|
feeType: feeChainType,
|
|
460
468
|
id: id,
|
|
@@ -34,6 +34,7 @@ import { _isAcrossChainBridge, getAcrossQuote } from '@subwallet/extension-base/
|
|
|
34
34
|
import { getClaimTxOnAvail, getClaimTxOnEthereum, isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
35
35
|
import { _isPolygonChainBridge, getClaimPolygonBridge, isClaimedPolygonBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
36
36
|
import { _isPosChainBridge, getClaimPosBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
37
|
+
import { estimateXcmFee } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
37
38
|
import { _DEFAULT_MANTA_ZK_CHAIN, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
38
39
|
import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
|
|
39
40
|
import { _getAssetDecimals, _getAssetSymbol, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _isAssetSmartContractNft, _isChainEnabled, _isChainEvmCompatible, _isChainSubstrateCompatible, _isCustomAsset, _isLocalToken, _isMantaZkAsset, _isNativeToken, _isNativeTokenBySlug, _isPureEvmChain, _isTokenEvmSmartContract, _isTokenTransferredByCardano, _isTokenTransferredByEvm, _isTokenTransferredByTon } from '@subwallet/extension-base/services/chain-service/utils';
|
|
@@ -1497,10 +1498,16 @@ export default class KoniExtension {
|
|
|
1497
1498
|
feeInfo
|
|
1498
1499
|
};
|
|
1499
1500
|
extrinsic = await funcCreateExtrinsic(params);
|
|
1500
|
-
let dryRunInfo;
|
|
1501
1501
|
if (isSubstrateXcm) {
|
|
1502
|
-
|
|
1503
|
-
|
|
1502
|
+
const xcmFeeInfo = await estimateXcmFee({
|
|
1503
|
+
fromChainInfo: params.originChain,
|
|
1504
|
+
fromTokenInfo: params.originTokenInfo,
|
|
1505
|
+
toChainInfo: params.destinationChain,
|
|
1506
|
+
recipient: params.recipient,
|
|
1507
|
+
sender: params.sender,
|
|
1508
|
+
value: params.sendingValue
|
|
1509
|
+
});
|
|
1510
|
+
xcmFeeDryRun = (xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee) || '0';
|
|
1504
1511
|
}
|
|
1505
1512
|
if (isAcrossBridgeTransfer) {
|
|
1506
1513
|
const data = await getAcrossQuote(params);
|
|
@@ -1569,8 +1576,11 @@ export default class KoniExtension {
|
|
|
1569
1576
|
receiverSystemAccountInfo, isSendingTokenSufficient);
|
|
1570
1577
|
warning.length && inputTransaction.warnings.push(...warning);
|
|
1571
1578
|
error.length && inputTransaction.errors.push(...error);
|
|
1572
|
-
if (isSubstrateXcm
|
|
1573
|
-
|
|
1579
|
+
if (isSubstrateXcm) {
|
|
1580
|
+
const isDryRunSuccess = await dryRunXcmExtrinsicV2(params);
|
|
1581
|
+
if (!isDryRunSuccess) {
|
|
1582
|
+
inputTransaction.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Unable to perform transaction. Select another token or destination chain and try again'));
|
|
1583
|
+
}
|
|
1574
1584
|
}
|
|
1575
1585
|
};
|
|
1576
1586
|
eventsHandler = eventEmitter => {
|
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.40-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2709,13 +2709,13 @@
|
|
|
2709
2709
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2710
2710
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2711
2711
|
"@substrate/connect": "^0.8.9",
|
|
2712
|
-
"@subwallet/chain-list": "0.2.
|
|
2713
|
-
"@subwallet/extension-base": "^1.3.
|
|
2714
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2715
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2716
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2712
|
+
"@subwallet/chain-list": "0.2.105",
|
|
2713
|
+
"@subwallet/extension-base": "^1.3.40-0",
|
|
2714
|
+
"@subwallet/extension-chains": "^1.3.40-0",
|
|
2715
|
+
"@subwallet/extension-dapp": "^1.3.40-0",
|
|
2716
|
+
"@subwallet/extension-inject": "^1.3.40-0",
|
|
2717
2717
|
"@subwallet/keyring": "^0.1.12",
|
|
2718
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2718
|
+
"@subwallet/subwallet-api-sdk": "^1.3.40-0",
|
|
2719
2719
|
"@subwallet/ui-keyring": "^0.1.12",
|
|
2720
2720
|
"@ton/core": "^0.56.3",
|
|
2721
2721
|
"@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.40-0'
|
|
11
11
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { DryRunInfo } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
3
2
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
3
|
import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
|
|
5
4
|
import { TransactionConfig } from 'web3-core';
|
|
@@ -23,5 +22,5 @@ export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo,
|
|
|
23
22
|
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
24
23
|
export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
25
24
|
export declare const createXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | undefined>;
|
|
26
|
-
export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<
|
|
25
|
+
export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<boolean>;
|
|
27
26
|
export declare const createAcrossBridgeExtrinsic: ({ destinationChain, destinationTokenInfo, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|