@subwallet/extension-base 1.3.66-0 → 1.3.67-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/core/substrate/xcm-parser.js +0 -176
- package/cjs/koni/background/handlers/Extension.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/smart-contract.js +54 -23
- package/cjs/services/balance-service/transfer/xcm/index.js +30 -44
- package/cjs/services/balance-service/transfer/xcm/utils.js +53 -18
- package/cjs/services/swap-service/handler/base-handler.js +18 -21
- package/cjs/utils/fee/transfer.js +5 -2
- package/core/substrate/xcm-parser.d.ts +1 -49
- package/core/substrate/xcm-parser.js +1 -173
- package/koni/background/handlers/Extension.js +1 -1
- package/package.json +5 -20
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/smart-contract.d.ts +4 -0
- package/services/balance-service/transfer/smart-contract.js +52 -23
- package/services/balance-service/transfer/xcm/index.d.ts +2 -2
- package/services/balance-service/transfer/xcm/index.js +18 -32
- package/services/balance-service/transfer/xcm/utils.d.ts +1 -2
- package/services/balance-service/transfer/xcm/utils.js +51 -15
- package/services/swap-service/handler/base-handler.d.ts +0 -1
- package/services/swap-service/handler/base-handler.js +19 -22
- package/utils/fee/transfer.js +6 -3
- package/cjs/services/balance-service/transfer/xcm/polkadotXcm.js +0 -30
- package/cjs/services/balance-service/transfer/xcm/xTokens.js +0 -32
- package/cjs/services/balance-service/transfer/xcm/xcmPallet.js +0 -23
- package/services/balance-service/transfer/xcm/polkadotXcm.d.ts +0 -3
- package/services/balance-service/transfer/xcm/polkadotXcm.js +0 -24
- package/services/balance-service/transfer/xcm/xTokens.d.ts +0 -3
- package/services/balance-service/transfer/xcm/xTokens.js +0 -26
- package/services/balance-service/transfer/xcm/xcmPallet.d.ts +0 -3
- package/services/balance-service/transfer/xcm/xcmPallet.js +0 -17
|
@@ -306,21 +306,6 @@ class SwapBaseHandler {
|
|
|
306
306
|
txData: txData
|
|
307
307
|
};
|
|
308
308
|
}
|
|
309
|
-
async validateSetFeeTokenStep(params, stepIndex) {
|
|
310
|
-
if (!params.selectedQuote) {
|
|
311
|
-
return Promise.resolve([new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR)]);
|
|
312
|
-
}
|
|
313
|
-
const feeInfo = params.process.totalFee[stepIndex];
|
|
314
|
-
const feeAmount = feeInfo.feeComponent[0];
|
|
315
|
-
const feeTokenInfo = this.chainService.getAssetBySlug(feeInfo.defaultFeeToken);
|
|
316
|
-
const feeTokenBalance = await this.balanceService.getTransferableBalance(params.address, feeTokenInfo.originChain, feeTokenInfo.slug);
|
|
317
|
-
const bnFeeTokenBalance = new _bignumber.default(feeTokenBalance.value);
|
|
318
|
-
const bnFeeAmount = new _bignumber.default(feeAmount.amount);
|
|
319
|
-
if (bnFeeAmount.gte(bnFeeTokenBalance)) {
|
|
320
|
-
return Promise.resolve([new _TransactionError.TransactionError(_types.BasicTxErrorType.NOT_ENOUGH_BALANCE)]);
|
|
321
|
-
}
|
|
322
|
-
return [];
|
|
323
|
-
}
|
|
324
309
|
async validateBridgeStep(request) {
|
|
325
310
|
const {
|
|
326
311
|
bnBridgeAmount,
|
|
@@ -385,7 +370,7 @@ class SwapBaseHandler {
|
|
|
385
370
|
const xcmRequest = {
|
|
386
371
|
originTokenInfo: fromToken,
|
|
387
372
|
destinationTokenInfo: toToken,
|
|
388
|
-
sendingValue: bnBridgeAmount.
|
|
373
|
+
sendingValue: bnBridgeAmount.toFixed(),
|
|
389
374
|
recipient: receiver,
|
|
390
375
|
substrateApi: substrateApi,
|
|
391
376
|
sender: sender,
|
|
@@ -393,11 +378,23 @@ class SwapBaseHandler {
|
|
|
393
378
|
originChain: fromChain,
|
|
394
379
|
feeInfo
|
|
395
380
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
381
|
+
if (isFirstBridge) {
|
|
382
|
+
const isDryRunSuccess = await (0, _xcm.dryRunXcmExtrinsicV2)(xcmRequest, false);
|
|
383
|
+
if (!isDryRunSuccess) {
|
|
384
|
+
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
const isDryRunPreviewSuccess = await (0, _xcm.dryRunXcmExtrinsicV2)(xcmRequest, true);
|
|
388
|
+
const originFee = await (0, _xcm.getXcmOriginFee)(xcmRequest);
|
|
389
|
+
if (originFee) {
|
|
390
|
+
const isBridgeTokenNativeBalanceEnough = bnFeeTokenBalance.gte(originFee);
|
|
391
|
+
if (!isBridgeTokenNativeBalanceEnough) {
|
|
392
|
+
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (!isDryRunPreviewSuccess) {
|
|
396
|
+
return [new _TransactionError.TransactionError(_types.BasicTxErrorType.UNABLE_TO_SEND, 'Swap amount too small. Increase amount and try again')];
|
|
397
|
+
}
|
|
401
398
|
}
|
|
402
399
|
}
|
|
403
400
|
return [];
|
|
@@ -202,9 +202,13 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
202
202
|
var _tx$gas;
|
|
203
203
|
// Calculate fee for evm transaction
|
|
204
204
|
const tx = transaction;
|
|
205
|
-
|
|
205
|
+
let gasLimit = ((_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.toString()) || (await evmApi.api.eth.estimateGas(tx)).toString();
|
|
206
206
|
const _feeCustom = feeCustom;
|
|
207
207
|
const combineFee = (0, _combine.combineEthFee)(fee, feeOption, _feeCustom);
|
|
208
|
+
if (srcChain.slug === 'energy_web_chain') {
|
|
209
|
+
gasLimit = _smartContract.gasSettingsForEWC.gasLimit.toString();
|
|
210
|
+
combineFee.maxFeePerGas = _smartContract.gasSettingsForEWC.maxFeePerGas;
|
|
211
|
+
}
|
|
208
212
|
if (combineFee.maxFeePerGas) {
|
|
209
213
|
estimatedFee = new _bignumber.default(combineFee.maxFeePerGas).multipliedBy(gasLimit).toFixed(0);
|
|
210
214
|
} else {
|
|
@@ -396,7 +400,6 @@ const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
396
400
|
funcCreateExtrinsic = _xcm.createAvailBridgeExtrinsicFromAvail;
|
|
397
401
|
} else {
|
|
398
402
|
funcCreateExtrinsic = _xcm.createXcmExtrinsicV2;
|
|
399
|
-
params.sendingValue = '1';
|
|
400
403
|
}
|
|
401
404
|
const extrinsic = await funcCreateExtrinsic(params);
|
|
402
405
|
|
|
@@ -1,52 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
-
export declare function _getXcmDestWeight(originChainInfo: _ChainInfo): "Unlimited" | 5000000000;
|
|
4
|
-
export declare function _getXcmBeneficiary(destChainInfo: _ChainInfo, recipient: _Address, version: number): {
|
|
5
|
-
[x: string]: {
|
|
6
|
-
parents: number;
|
|
7
|
-
interior: {
|
|
8
|
-
X1: {
|
|
9
|
-
AccountId32: {
|
|
10
|
-
network: string | undefined;
|
|
11
|
-
id: Uint8Array;
|
|
12
|
-
};
|
|
13
|
-
AccountKey20?: undefined;
|
|
14
|
-
} | {
|
|
15
|
-
AccountKey20: {
|
|
16
|
-
network: string | undefined;
|
|
17
|
-
key: string;
|
|
18
|
-
};
|
|
19
|
-
AccountId32?: undefined;
|
|
20
|
-
} | ({
|
|
21
|
-
AccountId32: {
|
|
22
|
-
network: string | undefined;
|
|
23
|
-
id: Uint8Array;
|
|
24
|
-
};
|
|
25
|
-
AccountKey20?: undefined;
|
|
26
|
-
} | {
|
|
27
|
-
AccountKey20: {
|
|
28
|
-
network: string | undefined;
|
|
29
|
-
key: string;
|
|
30
|
-
};
|
|
31
|
-
AccountId32?: undefined;
|
|
32
|
-
})[];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export declare function _getXcmMultiAssets(tokenInfo: _ChainAsset, value: string, version: number): {
|
|
37
|
-
[x: string]: {
|
|
38
|
-
id: Record<string, any>;
|
|
39
|
-
fun: {
|
|
40
|
-
Fungible: string;
|
|
41
|
-
};
|
|
42
|
-
}[];
|
|
43
|
-
};
|
|
44
|
-
export declare function _getXcmMultiLocation(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, version: number, recipient?: _Address): {
|
|
45
|
-
[x: string]: {
|
|
46
|
-
parents: number;
|
|
47
|
-
interior: unknown;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
50
2
|
export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
51
3
|
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): string;
|
|
52
4
|
export declare function _isXcmWithinSameConsensus(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
@@ -6,50 +6,7 @@ import { _isAcrossChainBridge } from '@subwallet/extension-base/services/balance
|
|
|
6
6
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
7
7
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
8
8
|
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
9
|
-
import {
|
|
10
|
-
import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
|
|
11
|
-
const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
|
|
12
|
-
const UNLIMITED_WEIGHT = 'Unlimited';
|
|
13
|
-
export function _getXcmDestWeight(originChainInfo) {
|
|
14
|
-
if (['pioneer'].includes(originChainInfo.slug)) {
|
|
15
|
-
return FOUR_INSTRUCTIONS_WEIGHT;
|
|
16
|
-
}
|
|
17
|
-
return UNLIMITED_WEIGHT;
|
|
18
|
-
}
|
|
19
|
-
export function _getXcmBeneficiary(destChainInfo, recipient, version) {
|
|
20
|
-
const receiverLocation = version < 4 // from V4, X1 is also an array
|
|
21
|
-
? _getRecipientLocation(destChainInfo, recipient, version) : [_getRecipientLocation(destChainInfo, recipient, version)];
|
|
22
|
-
return {
|
|
23
|
-
[`V${version}`]: {
|
|
24
|
-
parents: 0,
|
|
25
|
-
interior: {
|
|
26
|
-
X1: receiverLocation
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export function _getXcmMultiAssets(tokenInfo, value, version) {
|
|
32
|
-
const assetId = _getAssetIdentifier(tokenInfo, version);
|
|
33
|
-
return {
|
|
34
|
-
[`V${version}`]: [{
|
|
35
|
-
id: assetId,
|
|
36
|
-
fun: {
|
|
37
|
-
Fungible: value
|
|
38
|
-
}
|
|
39
|
-
}]
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export function _getXcmMultiLocation(originChainInfo, destChainInfo, version, recipient) {
|
|
43
|
-
const isWithinSameConsensus = _isXcmWithinSameConsensus(originChainInfo, destChainInfo);
|
|
44
|
-
const parents = _getMultiLocationParent(originChainInfo, isWithinSameConsensus);
|
|
45
|
-
const interior = _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient);
|
|
46
|
-
return {
|
|
47
|
-
[`V${version}`]: {
|
|
48
|
-
parents,
|
|
49
|
-
interior
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
9
|
+
import { _getSubstrateRelayParent, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
53
10
|
export function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
|
|
54
11
|
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo) || _isPosBridgeXcm(originChainInfo, destChainInfo);
|
|
55
12
|
}
|
|
@@ -133,123 +90,6 @@ export function _isAcrossBridgeXcm(originChainInfo, destChainInfo) {
|
|
|
133
90
|
}
|
|
134
91
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
135
92
|
|
|
136
|
-
function _getMultiLocationParent(originChainInfo, isWithinSameConsensus) {
|
|
137
|
-
let parent = 0; // how many hops up the hierarchy
|
|
138
|
-
|
|
139
|
-
if (_isSubstrateParaChain(originChainInfo)) {
|
|
140
|
-
parent += 1;
|
|
141
|
-
}
|
|
142
|
-
if (!isWithinSameConsensus) {
|
|
143
|
-
parent += 1;
|
|
144
|
-
}
|
|
145
|
-
return parent;
|
|
146
|
-
}
|
|
147
|
-
function _getMultiLocationInterior(destChainInfo, isWithinSameConsensus, version, recipient) {
|
|
148
|
-
const junctions = [];
|
|
149
|
-
if (isWithinSameConsensus) {
|
|
150
|
-
if (_isSubstrateParaChain(destChainInfo)) {
|
|
151
|
-
junctions.push({
|
|
152
|
-
Parachain: _getSubstrateParaId(destChainInfo)
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
junctions.push({
|
|
157
|
-
GlobalConsensus: _getGlobalConsensusJunction(destChainInfo, version)
|
|
158
|
-
});
|
|
159
|
-
if (_isSubstrateParaChain(destChainInfo)) {
|
|
160
|
-
junctions.push({
|
|
161
|
-
Parachain: _getSubstrateParaId(destChainInfo)
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
if (recipient) {
|
|
166
|
-
junctions.push(_getRecipientLocation(destChainInfo, recipient, version));
|
|
167
|
-
}
|
|
168
|
-
if (junctions.length === 0 && !recipient) {
|
|
169
|
-
return 'Here';
|
|
170
|
-
}
|
|
171
|
-
if (version < 4 && junctions.length === 1) {
|
|
172
|
-
return {
|
|
173
|
-
X1: junctions[0]
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
[`X${junctions.length}`]: junctions
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
function _getGlobalConsensusJunction(destChainInfo, version) {
|
|
181
|
-
let chainSlug = destChainInfo.slug;
|
|
182
|
-
let evmChainId;
|
|
183
|
-
if (_isSubstrateParaChain(destChainInfo)) {
|
|
184
|
-
const relaySlug = _getSubstrateRelayParent(destChainInfo);
|
|
185
|
-
if (!relaySlug) {
|
|
186
|
-
throw Error('Parachain must have a parent chainSlug');
|
|
187
|
-
}
|
|
188
|
-
chainSlug = relaySlug;
|
|
189
|
-
} else {
|
|
190
|
-
evmChainId = _getEvmChainId(destChainInfo);
|
|
191
|
-
}
|
|
192
|
-
if (evmChainId) {
|
|
193
|
-
return {
|
|
194
|
-
Ethereum: {
|
|
195
|
-
chainId: evmChainId
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
switch (chainSlug) {
|
|
200
|
-
case COMMON_CHAIN_SLUGS.POLKADOT:
|
|
201
|
-
return version < 4 ? {
|
|
202
|
-
Polkadot: null
|
|
203
|
-
} : 'Polkadot';
|
|
204
|
-
case COMMON_CHAIN_SLUGS.KUSAMA:
|
|
205
|
-
return version < 4 ? {
|
|
206
|
-
Kusama: null
|
|
207
|
-
} : 'Kusama';
|
|
208
|
-
default:
|
|
209
|
-
return version < 4 ? {
|
|
210
|
-
Rococo: null
|
|
211
|
-
} : 'Rococo';
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function _getRecipientLocation(destChainInfo, recipient, version) {
|
|
215
|
-
const network = _getNetworkByVersion(version);
|
|
216
|
-
if (destChainInfo.slug === COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
217
|
-
const ss58Address = evmToAddress(recipient, _getChainSubstrateAddressPrefix(destChainInfo)); // TODO: shouldn't pass addressPrefix directly
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
AccountId32: {
|
|
221
|
-
network,
|
|
222
|
-
id: decodeAddress(ss58Address)
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
if (_isChainEvmCompatible(destChainInfo)) {
|
|
227
|
-
return {
|
|
228
|
-
AccountKey20: {
|
|
229
|
-
network,
|
|
230
|
-
key: recipient
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
AccountId32: {
|
|
236
|
-
network,
|
|
237
|
-
id: decodeAddress(recipient)
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function _getAssetIdentifier(tokenInfo, version) {
|
|
242
|
-
const _assetIdentifier = _getXcmAssetMultilocation(tokenInfo);
|
|
243
|
-
if (!_assetIdentifier) {
|
|
244
|
-
throw new Error('Asset must have multilocation');
|
|
245
|
-
}
|
|
246
|
-
const assetIdentifier = ['statemint-LOCAL-KSM', 'statemine-LOCAL-DOT'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
247
|
-
? _assetIdentifier : _adaptX1Interior(_assetIdentifier, version);
|
|
248
|
-
return version >= 4 // from V4, Concrete is removed
|
|
249
|
-
? assetIdentifier : {
|
|
250
|
-
Concrete: assetIdentifier
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
93
|
export function _adaptX1Interior(_assetIdentifier, version) {
|
|
254
94
|
const assetIdentifier = structuredClone(_assetIdentifier);
|
|
255
95
|
const interior = assetIdentifier.interior;
|
|
@@ -262,16 +102,4 @@ export function _adaptX1Interior(_assetIdentifier, version) {
|
|
|
262
102
|
interior.X1 = interior.X1[0];
|
|
263
103
|
}
|
|
264
104
|
return assetIdentifier;
|
|
265
|
-
}
|
|
266
|
-
function _getNetworkByVersion(version) {
|
|
267
|
-
switch (version) {
|
|
268
|
-
case 1:
|
|
269
|
-
case 2:
|
|
270
|
-
return 'Any';
|
|
271
|
-
case 3:
|
|
272
|
-
case 4:
|
|
273
|
-
return undefined;
|
|
274
|
-
default:
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
105
|
}
|
|
@@ -1644,7 +1644,7 @@ export default class KoniExtension {
|
|
|
1644
1644
|
error.length && inputTransaction.errors.push(...error);
|
|
1645
1645
|
}
|
|
1646
1646
|
if (isSubstrateXcm) {
|
|
1647
|
-
const isDryRunSuccess = await dryRunXcmExtrinsicV2(params);
|
|
1647
|
+
const isDryRunSuccess = await dryRunXcmExtrinsicV2(params, false);
|
|
1648
1648
|
if (!isDryRunSuccess) {
|
|
1649
1649
|
inputTransaction.errors.push(new TransactionError(BasicTxErrorType.UNABLE_TO_SEND, 'Unable to perform transaction. Select another token or destination chain and try again'));
|
|
1650
1650
|
}
|
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.67-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -799,11 +799,6 @@
|
|
|
799
799
|
"require": "./cjs/services/balance-service/transfer/xcm/availBridge.js",
|
|
800
800
|
"default": "./services/balance-service/transfer/xcm/availBridge.js"
|
|
801
801
|
},
|
|
802
|
-
"./services/balance-service/transfer/xcm/polkadotXcm": {
|
|
803
|
-
"types": "./services/balance-service/transfer/xcm/polkadotXcm.d.ts",
|
|
804
|
-
"require": "./cjs/services/balance-service/transfer/xcm/polkadotXcm.js",
|
|
805
|
-
"default": "./services/balance-service/transfer/xcm/polkadotXcm.js"
|
|
806
|
-
},
|
|
807
802
|
"./services/balance-service/transfer/xcm/polygonBridge": {
|
|
808
803
|
"types": "./services/balance-service/transfer/xcm/polygonBridge.d.ts",
|
|
809
804
|
"require": "./cjs/services/balance-service/transfer/xcm/polygonBridge.js",
|
|
@@ -824,16 +819,6 @@
|
|
|
824
819
|
"require": "./cjs/services/balance-service/transfer/xcm/utils.js",
|
|
825
820
|
"default": "./services/balance-service/transfer/xcm/utils.js"
|
|
826
821
|
},
|
|
827
|
-
"./services/balance-service/transfer/xcm/xcmPallet": {
|
|
828
|
-
"types": "./services/balance-service/transfer/xcm/xcmPallet.d.ts",
|
|
829
|
-
"require": "./cjs/services/balance-service/transfer/xcm/xcmPallet.js",
|
|
830
|
-
"default": "./services/balance-service/transfer/xcm/xcmPallet.js"
|
|
831
|
-
},
|
|
832
|
-
"./services/balance-service/transfer/xcm/xTokens": {
|
|
833
|
-
"types": "./services/balance-service/transfer/xcm/xTokens.d.ts",
|
|
834
|
-
"require": "./cjs/services/balance-service/transfer/xcm/xTokens.js",
|
|
835
|
-
"default": "./services/balance-service/transfer/xcm/xTokens.js"
|
|
836
|
-
},
|
|
837
822
|
"./services/base/types": {
|
|
838
823
|
"types": "./services/base/types.d.ts",
|
|
839
824
|
"require": "./cjs/services/base/types.js",
|
|
@@ -2924,10 +2909,10 @@
|
|
|
2924
2909
|
"@substrate/connect": "^0.8.9",
|
|
2925
2910
|
"@subwallet-monorepos/subwallet-services-sdk": "0.1.13",
|
|
2926
2911
|
"@subwallet/chain-list": "0.2.121",
|
|
2927
|
-
"@subwallet/extension-base": "^1.3.
|
|
2928
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2929
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2930
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2912
|
+
"@subwallet/extension-base": "^1.3.67-0",
|
|
2913
|
+
"@subwallet/extension-chains": "^1.3.67-0",
|
|
2914
|
+
"@subwallet/extension-dapp": "^1.3.67-0",
|
|
2915
|
+
"@subwallet/extension-inject": "^1.3.67-0",
|
|
2931
2916
|
"@subwallet/keyring": "^0.1.13",
|
|
2932
2917
|
"@subwallet/ui-keyring": "^0.1.13",
|
|
2933
2918
|
"@ton/core": "^0.56.3",
|
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.67-0'
|
|
11
11
|
};
|
|
@@ -12,6 +12,10 @@ interface TransferEvmProps extends TransactionFee {
|
|
|
12
12
|
fallbackFee?: boolean;
|
|
13
13
|
data?: string;
|
|
14
14
|
}
|
|
15
|
+
export declare const gasSettingsForEWC: {
|
|
16
|
+
gasLimit: number;
|
|
17
|
+
maxFeePerGas: string;
|
|
18
|
+
};
|
|
15
19
|
export declare function getEVMTransactionObject(props: TransferEvmProps): Promise<[TransactionConfig, string, string]>;
|
|
16
20
|
export declare function getERC20TransactionObject(props: TransferERC20Props): Promise<[TransactionConfig, string, string]>;
|
|
17
21
|
interface TransferERC20Props extends TransactionFee {
|
|
@@ -9,6 +9,11 @@ import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-
|
|
|
9
9
|
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
10
10
|
import BigN from 'bignumber.js';
|
|
11
11
|
import { t } from 'i18next';
|
|
12
|
+
// hot fix gas settings for Energy Web Chain
|
|
13
|
+
export const gasSettingsForEWC = {
|
|
14
|
+
gasLimit: 4900000,
|
|
15
|
+
maxFeePerGas: '10000000'
|
|
16
|
+
};
|
|
12
17
|
export async function getEVMTransactionObject(props) {
|
|
13
18
|
const {
|
|
14
19
|
chain,
|
|
@@ -23,10 +28,18 @@ export async function getEVMTransactionObject(props) {
|
|
|
23
28
|
transferAll,
|
|
24
29
|
value
|
|
25
30
|
} = props;
|
|
31
|
+
const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
|
|
32
|
+
|
|
26
33
|
const feeCustom = _feeCustom;
|
|
27
34
|
const feeInfo = _feeInfo;
|
|
28
35
|
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
29
36
|
let errorOnEstimateFee = '';
|
|
37
|
+
if (isEnergyWebChain) {
|
|
38
|
+
feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
|
|
39
|
+
if (!feeCombine.maxPriorityFeePerGas || new BigN(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
|
|
40
|
+
feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
43
|
const transactionObject = {
|
|
31
44
|
to,
|
|
32
45
|
value,
|
|
@@ -34,16 +47,21 @@ export async function getEVMTransactionObject(props) {
|
|
|
34
47
|
data,
|
|
35
48
|
...feeCombine
|
|
36
49
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
let gasLimit;
|
|
51
|
+
if (isEnergyWebChain) {
|
|
52
|
+
gasLimit = gasSettingsForEWC.gasLimit;
|
|
53
|
+
} else {
|
|
54
|
+
const gasEstimate = await evmApi.api.eth.estimateGas(transactionObject).catch(e => {
|
|
55
|
+
console.log('Cannot estimate fee with native transfer on', chain, e);
|
|
56
|
+
if (fallbackFee) {
|
|
57
|
+
errorOnEstimateFee = e.message;
|
|
58
|
+
return 21000;
|
|
59
|
+
} else {
|
|
60
|
+
throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
gasLimit = Math.floor(gasEstimate * 1.1); // 10% buffer for fluctuations
|
|
64
|
+
}
|
|
47
65
|
|
|
48
66
|
transactionObject.gas = gasLimit;
|
|
49
67
|
let estimateFee;
|
|
@@ -74,6 +92,8 @@ export async function getERC20TransactionObject(props) {
|
|
|
74
92
|
transferAll,
|
|
75
93
|
value
|
|
76
94
|
} = props;
|
|
95
|
+
const isEnergyWebChain = chain === 'energy_web_chain'; // hot fix gas settings for Energy Web Chain
|
|
96
|
+
|
|
77
97
|
const erc20Contract = getERC20Contract(assetAddress, evmApi);
|
|
78
98
|
const feeCustom = _feeCustom;
|
|
79
99
|
let freeAmount = new BigN(0);
|
|
@@ -89,21 +109,30 @@ export async function getERC20TransactionObject(props) {
|
|
|
89
109
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
90
110
|
return erc20Contract.methods.transfer(to, transferValue).encodeABI();
|
|
91
111
|
}
|
|
92
|
-
const transferData = generateTransferData(to, transferValue);
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
94
|
-
const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
95
|
-
from
|
|
96
|
-
}).catch(e => {
|
|
97
|
-
console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
|
|
98
|
-
if (fallbackFee) {
|
|
99
|
-
errorOnEstimateFee = e.message;
|
|
100
|
-
return 70000;
|
|
101
|
-
} else {
|
|
102
|
-
throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
112
|
const feeInfo = _feeInfo;
|
|
106
113
|
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
114
|
+
const transferData = generateTransferData(to, transferValue);
|
|
115
|
+
let gasLimit;
|
|
116
|
+
if (isEnergyWebChain) {
|
|
117
|
+
gasLimit = gasSettingsForEWC.gasLimit;
|
|
118
|
+
feeCombine.maxFeePerGas = gasSettingsForEWC.maxFeePerGas;
|
|
119
|
+
if (!feeCombine.maxPriorityFeePerGas || new BigN(feeCombine.maxPriorityFeePerGas).gt(feeCombine.maxFeePerGas)) {
|
|
120
|
+
feeCombine.maxPriorityFeePerGas = gasSettingsForEWC.maxFeePerGas;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
124
|
+
gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
125
|
+
from
|
|
126
|
+
}).catch(e => {
|
|
127
|
+
console.log('Cannot estimate fee with token contract', assetAddress, chain, e);
|
|
128
|
+
if (fallbackFee) {
|
|
129
|
+
errorOnEstimateFee = e.message;
|
|
130
|
+
return 70000;
|
|
131
|
+
} else {
|
|
132
|
+
throw Error('Unable to estimate fee for this transaction. Edit fee and try again.');
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
107
136
|
const transactionObject = {
|
|
108
137
|
gas: gasLimit,
|
|
109
138
|
from,
|
|
@@ -17,10 +17,10 @@ export declare type CreateXcmExtrinsicProps = {
|
|
|
17
17
|
} & TransactionFee;
|
|
18
18
|
export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig | undefined>;
|
|
19
19
|
export declare const createSnowBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
|
-
export declare const createXcmExtrinsic: ({ destinationChain, originChain, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
21
20
|
export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo, feeOption, originChain, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
22
21
|
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
23
22
|
export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
24
23
|
export declare const createXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | undefined>;
|
|
25
|
-
export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps) => Promise<boolean>;
|
|
24
|
+
export declare const dryRunXcmExtrinsicV2: (request: CreateXcmExtrinsicProps, isPreview?: boolean) => Promise<boolean>;
|
|
25
|
+
export declare const getXcmOriginFee: (request: CreateXcmExtrinsicProps) => Promise<string | undefined>;
|
|
26
26
|
export declare const createAcrossBridgeExtrinsic: ({ destinationChain, destinationTokenInfo, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
@@ -3,14 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import { _isAcrossBridgeXcm, _isPolygonBridgeXcm, _isPosBridgeXcm, _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
5
|
import { getAvailBridgeExtrinsicFromAvail, getAvailBridgeTxFromEth } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
|
-
import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
|
|
7
6
|
import { _createPolygonBridgeL1toL2Extrinsic, _createPolygonBridgeL2toL1Extrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
8
7
|
import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
|
|
9
|
-
import { buildXcm, dryRunXcm, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
10
|
-
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
|
|
11
|
-
import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
|
|
12
|
-
import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
|
-
import { _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { buildXcm, dryRunPreviewXcm, dryRunXcm, estimateXcmFee, isChainNotSupportDryRun, isChainNotSupportPolkadotApi } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
14
9
|
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
15
10
|
import subwalletApiSdk from '@subwallet-monorepos/subwallet-services-sdk';
|
|
16
11
|
import { _createPosBridgeL1toL2Extrinsic, _createPosBridgeL2toL1Extrinsic } from "./posBridge.js";
|
|
@@ -38,30 +33,6 @@ export const createSnowBridgeExtrinsic = async ({
|
|
|
38
33
|
}
|
|
39
34
|
return getSnowBridgeEvmTransfer(originTokenInfo, originChain, destinationChain, sender, recipient, sendingValue, evmApi, feeInfo, feeCustom, feeOption);
|
|
40
35
|
};
|
|
41
|
-
|
|
42
|
-
// deprecated
|
|
43
|
-
export const createXcmExtrinsic = async ({
|
|
44
|
-
destinationChain,
|
|
45
|
-
originChain,
|
|
46
|
-
originTokenInfo,
|
|
47
|
-
recipient,
|
|
48
|
-
sendingValue,
|
|
49
|
-
substrateApi
|
|
50
|
-
}) => {
|
|
51
|
-
if (!substrateApi) {
|
|
52
|
-
throw Error('Substrate API is not available');
|
|
53
|
-
}
|
|
54
|
-
const chainApi = await substrateApi.isReady;
|
|
55
|
-
const api = chainApi.api;
|
|
56
|
-
const polkadotXcmSpecialCases = _XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChain.slug) && _isNativeToken(originTokenInfo);
|
|
57
|
-
if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
|
|
58
|
-
return getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
|
|
59
|
-
}
|
|
60
|
-
if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
61
|
-
return getExtrinsicByXcmPalletPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
|
|
62
|
-
}
|
|
63
|
-
return getExtrinsicByXtokensPallet(originTokenInfo, originChain, destinationChain, recipient, sendingValue, api);
|
|
64
|
-
};
|
|
65
36
|
export const createAvailBridgeTxFromEth = ({
|
|
66
37
|
evmApi,
|
|
67
38
|
feeCustom,
|
|
@@ -125,9 +96,9 @@ export const createXcmExtrinsicV2 = async request => {
|
|
|
125
96
|
return undefined;
|
|
126
97
|
}
|
|
127
98
|
};
|
|
128
|
-
export const dryRunXcmExtrinsicV2 = async request => {
|
|
99
|
+
export const dryRunXcmExtrinsicV2 = async (request, isPreview = false) => {
|
|
129
100
|
try {
|
|
130
|
-
const dryRunResult = await dryRunXcm(request);
|
|
101
|
+
const dryRunResult = isPreview ? await dryRunPreviewXcm(request) : await dryRunXcm(request);
|
|
131
102
|
const originDryRunRs = dryRunResult.origin;
|
|
132
103
|
if (originDryRunRs.success) {
|
|
133
104
|
const {
|
|
@@ -157,6 +128,21 @@ export const dryRunXcmExtrinsicV2 = async request => {
|
|
|
157
128
|
return false;
|
|
158
129
|
}
|
|
159
130
|
};
|
|
131
|
+
export const getXcmOriginFee = async request => {
|
|
132
|
+
try {
|
|
133
|
+
const xcmFeeInfo = await estimateXcmFee({
|
|
134
|
+
fromChainInfo: request.originChain,
|
|
135
|
+
fromTokenInfo: request.originTokenInfo,
|
|
136
|
+
toChainInfo: request.destinationChain,
|
|
137
|
+
recipient: request.recipient,
|
|
138
|
+
sender: request.sender,
|
|
139
|
+
value: request.sendingValue
|
|
140
|
+
});
|
|
141
|
+
return xcmFeeInfo === null || xcmFeeInfo === void 0 ? void 0 : xcmFeeInfo.origin.fee;
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
160
146
|
export const createAcrossBridgeExtrinsic = async ({
|
|
161
147
|
destinationChain,
|
|
162
148
|
destinationTokenInfo,
|
|
@@ -44,9 +44,8 @@ export declare type GetXcmFeeResult = {
|
|
|
44
44
|
};
|
|
45
45
|
export declare function buildXcm(request: CreateXcmExtrinsicProps): Promise<SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
46
46
|
export declare function dryRunXcm(request: CreateXcmExtrinsicProps): Promise<DryRunResult>;
|
|
47
|
+
export declare function dryRunPreviewXcm(request: CreateXcmExtrinsicProps): Promise<DryRunResult>;
|
|
47
48
|
export declare function estimateXcmFee(request: GetXcmFeeRequest): Promise<GetXcmFeeResult | undefined>;
|
|
48
49
|
export declare function isChainNotSupportPolkadotApi(str: string): boolean;
|
|
49
50
|
export declare function isChainNotSupportDryRun(str: string): boolean;
|
|
50
|
-
export declare const STABLE_XCM_VERSION = 3;
|
|
51
|
-
export declare function isUseTeleportProtocol(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, tokenSlug?: string): boolean;
|
|
52
51
|
export {};
|