@subwallet/extension-base 1.3.23-0 → 1.3.25-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 +11 -3
- package/background/KoniTypes.js +1 -0
- package/background/errors/EvmProviderError.js +4 -0
- package/background/errors/ProviderError.d.ts +1 -1
- package/background/errors/ProviderError.js +2 -2
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/background/errors/EvmProviderError.js +4 -0
- package/cjs/background/errors/ProviderError.js +2 -2
- package/cjs/constants/environment.js +1 -1
- package/cjs/constants/index.js +21 -4
- package/cjs/core/logic-validation/transfer.js +23 -8
- package/cjs/koni/background/handlers/Extension.js +109 -89
- package/cjs/koni/background/handlers/State.js +2 -2
- package/cjs/koni/background/handlers/Tabs.js +4 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +3 -3
- package/cjs/services/balance-service/transfer/smart-contract.js +24 -3
- package/cjs/services/buy-service/constants/token.js +3 -0
- package/cjs/services/chain-service/index.js +11 -0
- package/cjs/services/earning-service/constants/chains.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +11 -5
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +7 -6
- package/cjs/services/earning-service/handlers/native-staking/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +444 -0
- package/cjs/services/earning-service/handlers/native-staking/index.js +8 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +138 -125
- package/cjs/services/earning-service/service.js +14 -4
- package/cjs/services/fee-service/utils/tokenPayFee.js +151 -0
- package/cjs/services/inapp-notification-service/index.js +3 -0
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/cjs/services/request-service/index.js +2 -2
- package/cjs/services/transaction-service/index.js +14 -5
- package/cjs/types/yield/info/base.js +1 -0
- package/cjs/utils/fee/transfer.js +47 -14
- package/cjs/utils/fetchEvmChainInfo.js +10 -5
- package/constants/environment.js +1 -1
- package/constants/index.d.ts +6 -1
- package/constants/index.js +14 -1
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +25 -10
- package/koni/background/handlers/Extension.js +82 -62
- package/koni/background/handlers/State.d.ts +1 -1
- package/koni/background/handlers/State.js +2 -2
- package/koni/background/handlers/Tabs.js +4 -3
- package/package.json +16 -6
- package/packageInfo.js +1 -1
- package/page/index.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +2 -2
- package/services/balance-service/transfer/smart-contract.d.ts +4 -2
- package/services/balance-service/transfer/smart-contract.js +24 -3
- package/services/buy-service/constants/token.js +3 -0
- package/services/chain-service/index.d.ts +1 -0
- package/services/chain-service/index.js +12 -1
- package/services/earning-service/constants/chains.js +1 -1
- package/services/earning-service/handlers/base.d.ts +7 -5
- package/services/earning-service/handlers/base.js +11 -7
- package/services/earning-service/handlers/native-staking/base-para.d.ts +1 -1
- package/services/earning-service/handlers/native-staking/base-para.js +7 -6
- package/services/earning-service/handlers/native-staking/base.d.ts +1 -1
- package/services/earning-service/handlers/native-staking/base.js +6 -3
- package/services/earning-service/handlers/native-staking/dtao.d.ts +64 -0
- package/services/earning-service/handlers/native-staking/dtao.js +434 -0
- package/services/earning-service/handlers/native-staking/index.d.ts +1 -0
- package/services/earning-service/handlers/native-staking/index.js +2 -1
- package/services/earning-service/handlers/native-staking/tao.d.ts +16 -4
- package/services/earning-service/handlers/native-staking/tao.js +136 -121
- package/services/earning-service/service.d.ts +1 -0
- package/services/earning-service/service.js +15 -5
- package/services/fee-service/interfaces.d.ts +25 -0
- package/services/fee-service/utils/tokenPayFee.d.ts +8 -0
- package/services/fee-service/utils/tokenPayFee.js +141 -0
- package/services/inapp-notification-service/index.js +3 -0
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -1
- package/services/request-service/handler/MetadataRequestHandler.js +5 -13
- package/services/request-service/index.d.ts +1 -1
- package/services/request-service/index.js +2 -2
- package/services/transaction-service/index.js +16 -7
- package/types/bridge/index.d.ts +1 -0
- package/types/buy.d.ts +1 -1
- package/types/fee/option.d.ts +1 -1
- package/types/yield/actions/join/step.d.ts +1 -0
- package/types/yield/actions/join/submit.d.ts +1 -0
- package/types/yield/info/account/info.d.ts +14 -1
- package/types/yield/info/base.d.ts +3 -1
- package/types/yield/info/base.js +1 -0
- package/types/yield/info/chain/info.d.ts +5 -1
- package/utils/fee/transfer.d.ts +1 -1
- package/utils/fee/transfer.js +46 -13
- package/utils/fetchEvmChainInfo.d.ts +1 -1
- package/utils/fetchEvmChainInfo.js +10 -5
|
@@ -97,8 +97,6 @@ class TransactionService {
|
|
|
97
97
|
(0, _transfer.checkSupportForAction)(validationResponse, blockedActionsMap);
|
|
98
98
|
}
|
|
99
99
|
const transaction = transactionInput.transaction;
|
|
100
|
-
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
101
|
-
const tokenPayFeeInfo = transactionInput.nonNativeTokenPayFeeSlug ? this.chainService.getAssetBySlug(transactionInput.nonNativeTokenPayFeeSlug) : undefined;
|
|
102
100
|
|
|
103
101
|
// Check duplicated transaction
|
|
104
102
|
validationResponse.errors.push(...this.checkDuplicate(transactionInput));
|
|
@@ -124,7 +122,12 @@ class TransactionService {
|
|
|
124
122
|
// Estimate fee for transaction
|
|
125
123
|
const id = (0, _getId.getId)();
|
|
126
124
|
const feeInfo = await this.state.feeService.subscribeChainFee(id, chain, 'evm');
|
|
127
|
-
|
|
125
|
+
const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(chain);
|
|
126
|
+
const tokenPayFeeSlug = transactionInput.tokenPayFeeSlug;
|
|
127
|
+
const isNonNativeTokenPayFee = tokenPayFeeSlug && !(0, _utils2._isNativeTokenBySlug)(tokenPayFeeSlug);
|
|
128
|
+
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
129
|
+
const priceMap = (await this.state.priceService.getPrice()).priceMap;
|
|
130
|
+
validationResponse.estimateFee = await (0, _transfer.estimateFeeForTransaction)(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee);
|
|
128
131
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
129
132
|
|
|
130
133
|
// Check account signing transaction
|
|
@@ -617,7 +620,13 @@ class TransactionService {
|
|
|
617
620
|
break;
|
|
618
621
|
case _KoniTypes.ExtrinsicType.STAKING_UNBOND:
|
|
619
622
|
{
|
|
623
|
+
var _data$poolInfo;
|
|
620
624
|
const data = (0, _utils3.parseTransactionData)(transaction.data);
|
|
625
|
+
if ((_data$poolInfo = data.poolInfo) !== null && _data$poolInfo !== void 0 && _data$poolInfo.metadata.subnetData) {
|
|
626
|
+
historyItem.additionalInfo = {
|
|
627
|
+
symbol: data.poolInfo.metadata.subnetData.subnetSymbol
|
|
628
|
+
};
|
|
629
|
+
}
|
|
621
630
|
if (data.isLiquidStaking && data.derivativeTokenInfo && data.exchangeRate && data.inputTokenInfo) {
|
|
622
631
|
historyItem.amount = {
|
|
623
632
|
decimals: (0, _utils2._getAssetDecimals)(data.derivativeTokenInfo),
|
|
@@ -1367,14 +1376,14 @@ class TransactionService {
|
|
|
1367
1376
|
chain,
|
|
1368
1377
|
feeCustom,
|
|
1369
1378
|
id,
|
|
1370
|
-
nonNativeTokenPayFeeSlug,
|
|
1371
1379
|
signAfterCreate,
|
|
1372
1380
|
step,
|
|
1381
|
+
tokenPayFeeSlug,
|
|
1373
1382
|
transaction,
|
|
1374
1383
|
url
|
|
1375
1384
|
} = _ref12;
|
|
1376
1385
|
const tip = (feeCustom === null || feeCustom === void 0 ? void 0 : feeCustom.tip) || '0';
|
|
1377
|
-
const feeAssetId =
|
|
1386
|
+
const feeAssetId = tokenPayFeeSlug && !(0, _utils2._isNativeTokenBySlug)(tokenPayFeeSlug) && _constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(chain) ? (_this$state$chainServ = this.state.chainService.getAssetBySlug(tokenPayFeeSlug).metadata) === null || _this$state$chainServ === void 0 ? void 0 : _this$state$chainServ.multilocation : undefined;
|
|
1378
1387
|
const emitter = new _eventemitter.default();
|
|
1379
1388
|
const eventData = {
|
|
1380
1389
|
id,
|
|
@@ -23,6 +23,7 @@ exports.YieldPoolType = YieldPoolType;
|
|
|
23
23
|
YieldPoolType["NOMINATION_POOL"] = "NOMINATION_POOL";
|
|
24
24
|
YieldPoolType["NATIVE_STAKING"] = "NATIVE_STAKING";
|
|
25
25
|
YieldPoolType["PARACHAIN_STAKING"] = "PARACHAIN_STAKING";
|
|
26
|
+
YieldPoolType["SUBNET_STAKING"] = "SUBNET_STAKING";
|
|
26
27
|
})(YieldPoolType || (exports.YieldPoolType = YieldPoolType = {}));
|
|
27
28
|
let YieldCompoundingPeriod;
|
|
28
29
|
/**
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.detectTransferTxType = exports.
|
|
7
|
+
exports.detectTransferTxType = exports.calculateXcmMaxTransferable = exports.calculateTransferMaxTransferable = exports.calculateMaxTransferable = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/constants");
|
|
9
9
|
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
10
10
|
var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts");
|
|
@@ -18,6 +18,7 @@ var _polygonBridge = require("@subwallet/extension-base/services/balance-service
|
|
|
18
18
|
var _posBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge");
|
|
19
19
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
20
20
|
var _utils2 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
21
|
+
var _tokenPayFee = require("@subwallet/extension-base/services/fee-service/utils/tokenPayFee");
|
|
21
22
|
var _helpers = require("@subwallet/extension-base/services/transaction-service/helpers");
|
|
22
23
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
23
24
|
var _keyring = require("@subwallet/keyring");
|
|
@@ -57,7 +58,13 @@ const calculateMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
57
58
|
const isXcmTransfer = srcChain.slug !== destChain.slug;
|
|
58
59
|
let maxTransferableAmount;
|
|
59
60
|
if (isXcmTransfer) {
|
|
60
|
-
|
|
61
|
+
const _request = {
|
|
62
|
+
// todo: temp not support pay local fee with xcm
|
|
63
|
+
...request,
|
|
64
|
+
isTransferLocalTokenAndPayThatTokenAsFee: false,
|
|
65
|
+
isTransferNativeTokenAndPayLocalTokenAsFee: false
|
|
66
|
+
};
|
|
67
|
+
maxTransferableAmount = await calculateXcmMaxTransferable(id, _request, freeBalance, fee);
|
|
61
68
|
} else {
|
|
62
69
|
maxTransferableAmount = await calculateTransferMaxTransferable(id, request, freeBalance, fee);
|
|
63
70
|
}
|
|
@@ -97,7 +104,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
97
104
|
// todo: refactor: merge getERC20TransactionObject & getEVMTransactionObject
|
|
98
105
|
// Estimate with EVM API
|
|
99
106
|
if ((0, _utils._isTokenEvmSmartContract)(srcToken) || (0, _utils._isLocalToken)(srcToken)) {
|
|
100
|
-
[transaction] = await (0, _smartContract.getERC20TransactionObject)({
|
|
107
|
+
[transaction,, error] = await (0, _smartContract.getERC20TransactionObject)({
|
|
101
108
|
assetAddress: (0, _utils._getContractAddressOfToken)(srcToken),
|
|
102
109
|
chain: srcChain.slug,
|
|
103
110
|
evmApi,
|
|
@@ -107,10 +114,11 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
107
114
|
from: address,
|
|
108
115
|
to: recipient,
|
|
109
116
|
transferAll: false,
|
|
110
|
-
value: '0'
|
|
117
|
+
value: '0',
|
|
118
|
+
fallbackFee: true
|
|
111
119
|
});
|
|
112
120
|
} else {
|
|
113
|
-
[transaction] = await (0, _smartContract.getEVMTransactionObject)({
|
|
121
|
+
[transaction,, error] = await (0, _smartContract.getEVMTransactionObject)({
|
|
114
122
|
chain: srcChain.slug,
|
|
115
123
|
evmApi,
|
|
116
124
|
feeCustom,
|
|
@@ -119,7 +127,8 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
119
127
|
from: address,
|
|
120
128
|
to: recipient,
|
|
121
129
|
transferAll: false,
|
|
122
|
-
value: '0'
|
|
130
|
+
value: '0',
|
|
131
|
+
fallbackFee: true
|
|
123
132
|
});
|
|
124
133
|
}
|
|
125
134
|
} else if ((0, _keyring.isTonAddress)(address) && (0, _utils._isTokenTransferredByTon)(srcToken)) {
|
|
@@ -240,9 +249,21 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
240
249
|
console.warn('Unable to estimate fee', e);
|
|
241
250
|
}
|
|
242
251
|
if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
252
|
+
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
253
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
254
|
+
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
255
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
256
|
+
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
257
|
+
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
258
|
+
if (rate) {
|
|
259
|
+
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
260
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
261
|
+
} else {
|
|
262
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
266
|
+
}
|
|
246
267
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
247
268
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
248
269
|
} else {
|
|
@@ -261,7 +282,7 @@ const calculateTransferMaxTransferable = async (id, request, freeBalance, fee) =
|
|
|
261
282
|
};
|
|
262
283
|
};
|
|
263
284
|
exports.calculateTransferMaxTransferable = calculateTransferMaxTransferable;
|
|
264
|
-
const
|
|
285
|
+
const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
265
286
|
const {
|
|
266
287
|
address,
|
|
267
288
|
destChain,
|
|
@@ -384,9 +405,21 @@ const calculateXCMMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
384
405
|
if (!destToken) {
|
|
385
406
|
maxTransferable = _utils3.BN_ZERO;
|
|
386
407
|
} else if (isTransferLocalTokenAndPayThatTokenAsFee && feeChainType === 'substrate') {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
408
|
+
if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(srcChain.slug)) {
|
|
409
|
+
const estimatedFeeNative = (BigInt(estimatedFee) * BigInt(_utils2.FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString();
|
|
410
|
+
const estimatedFeeLocal = await (0, _utils2.calculateToAmountByReservePool)(substrateApi.api, nativeToken, srcToken, estimatedFeeNative);
|
|
411
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
412
|
+
} else if (_constants._SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(srcChain.slug)) {
|
|
413
|
+
const rate = await (0, _tokenPayFee.getHydrationRate)(address, nativeToken, srcToken);
|
|
414
|
+
if (rate) {
|
|
415
|
+
const estimatedFeeLocal = new _bignumber.default(estimatedFee).multipliedBy(rate).integerValue(_bignumber.default.ROUND_UP).toString();
|
|
416
|
+
maxTransferable = (0, _bignumber.default)(freeBalance.value).minus(estimatedFeeLocal);
|
|
417
|
+
} else {
|
|
418
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
throw new Error(`Unable to estimate fee for ${srcChain.slug}.`);
|
|
422
|
+
}
|
|
390
423
|
} else if (isTransferNativeTokenAndPayLocalTokenAsFee) {
|
|
391
424
|
maxTransferable = (0, _bignumber.default)(freeBalance.value);
|
|
392
425
|
} else {
|
|
@@ -404,4 +437,4 @@ const calculateXCMMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
|
404
437
|
error
|
|
405
438
|
};
|
|
406
439
|
};
|
|
407
|
-
exports.
|
|
440
|
+
exports.calculateXcmMaxTransferable = calculateXcmMaxTransferable;
|
|
@@ -10,11 +10,16 @@ exports.getEVMChainInfo = getEVMChainInfo;
|
|
|
10
10
|
const onlineMap = {};
|
|
11
11
|
async function getEVMChainInfo(chainId) {
|
|
12
12
|
if (Object.keys(onlineMap).length === 0) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
try {
|
|
14
|
+
const rs = await fetch('https://chainid.network/chains.json');
|
|
15
|
+
const data = await rs.json();
|
|
16
|
+
data.forEach(item => {
|
|
17
|
+
onlineMap[item.chainId] = item;
|
|
18
|
+
});
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.error(e);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
return onlineMap[chainId];
|
|
20
25
|
}
|
package/constants/environment.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
5
5
|
const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
|
|
6
6
|
export const isProductionMode = PRODUCTION_BRANCHES.indexOf(branchName) > -1;
|
|
7
|
-
export const BACKEND_API_URL = process.env.SUBWALLET_API || (isProductionMode ? 'https://sw-services.subwallet.app/api' : 'https://
|
|
7
|
+
export const BACKEND_API_URL = process.env.SUBWALLET_API || (isProductionMode ? 'https://sw-services.subwallet.app/api' : 'https://be-dev.subwallet.app/api');
|
package/constants/index.d.ts
CHANGED
|
@@ -35,7 +35,12 @@ export declare const NETWORK_MULTI_GAS_FEE: string[];
|
|
|
35
35
|
export declare const ORDINAL_COLLECTION = "__Ordinal__";
|
|
36
36
|
export declare const ORDINAL_METHODS: string[];
|
|
37
37
|
export declare const PERMISSIONS_TO_REVOKE: string[];
|
|
38
|
-
export declare const
|
|
38
|
+
export declare const _SUPPORT_TOKEN_PAY_FEE_GROUP: {
|
|
39
|
+
assetHub: string[];
|
|
40
|
+
hydration: string[];
|
|
41
|
+
};
|
|
42
|
+
export declare const getSupportTokenPayFeeChain: () => string[];
|
|
43
|
+
export declare const isChainSupportTokenPayFee: (chainSlug: string) => boolean;
|
|
39
44
|
export * from './blocked-actions';
|
|
40
45
|
export * from './environment';
|
|
41
46
|
export * from './signing';
|
package/constants/index.js
CHANGED
|
@@ -37,7 +37,20 @@ export const NETWORK_MULTI_GAS_FEE = ['*'];
|
|
|
37
37
|
export const ORDINAL_COLLECTION = '__Ordinal__';
|
|
38
38
|
export const ORDINAL_METHODS = ['drc-20', 'pol-20'];
|
|
39
39
|
export const PERMISSIONS_TO_REVOKE = ['eth_accounts'];
|
|
40
|
-
export const
|
|
40
|
+
export const _SUPPORT_TOKEN_PAY_FEE_GROUP = {
|
|
41
|
+
assetHub: ['paseo_assethub', 'westend_assethub', 'rococo_assethub', 'statemine', 'statemint'],
|
|
42
|
+
hydration: ['hydradx_main', 'hydradx_rococo']
|
|
43
|
+
};
|
|
44
|
+
export const getSupportTokenPayFeeChain = () => {
|
|
45
|
+
return Object.values(_SUPPORT_TOKEN_PAY_FEE_GROUP).flat();
|
|
46
|
+
};
|
|
47
|
+
export const isChainSupportTokenPayFee = chainSlug => {
|
|
48
|
+
if (!chainSlug) {
|
|
49
|
+
console.error('You must provide chain slug!');
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return getSupportTokenPayFeeChain().includes(chainSlug);
|
|
53
|
+
};
|
|
41
54
|
export * from "./blocked-actions.js";
|
|
42
55
|
export * from "./environment.js";
|
|
43
56
|
export * from "./signing.js";
|
|
@@ -14,7 +14,7 @@ export declare function additionalValidateXcmTransfer(originTokenInfo: _ChainAss
|
|
|
14
14
|
export declare function checkSupportForFeature(validationResponse: SWTransactionResponse, blockedFeaturesList: string[], chainInfo: _ChainInfo): void;
|
|
15
15
|
export declare function checkSupportForAction(validationResponse: SWTransactionResponse, blockedActionsMap: Record<ExtrinsicType, string[]>): void;
|
|
16
16
|
export declare function checkSupportForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction): void;
|
|
17
|
-
export declare function estimateFeeForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction, chainInfo: _ChainInfo, evmApi: _EvmApi, substrateApi: _SubstrateApi, feeInfo: EvmFeeInfo, nativeTokenInfo: _ChainAsset,
|
|
17
|
+
export declare function estimateFeeForTransaction(validationResponse: SWTransactionResponse, transaction: OptionalSWTransaction, chainInfo: _ChainInfo, evmApi: _EvmApi, substrateApi: _SubstrateApi, priceMap: Record<string, number>, feeInfo: EvmFeeInfo, nativeTokenInfo: _ChainAsset, nonNativeTokenPayFeeInfo: _ChainAsset | undefined, isTransferLocalTokenAndPayThatTokenAsFee: boolean | undefined): Promise<FeeData>;
|
|
18
18
|
export declare function checkSigningAccountForTransaction(validationResponse: SWTransactionResponse, chainInfoMap: Record<string, _ChainInfo>): void;
|
|
19
19
|
export declare function checkBalanceWithTransactionFee(validationResponse: SWTransactionResponse, transactionInput: SWTransactionInput, nativeTokenInfo: _ChainAsset, nativeTokenAvailable: AmountData): void;
|
|
20
20
|
export declare function checkTonAddressBounceableAndAccountNotActive(tonApi: _TonApi, validationResponse: SWTransactionResponse): Promise<void>;
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
|
|
7
|
-
import { LEDGER_SIGNING_COMPATIBLE_MAP, SIGNING_COMPATIBLE_MAP, XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
|
|
7
|
+
import { _SUPPORT_TOKEN_PAY_FEE_GROUP, LEDGER_SIGNING_COMPATIBLE_MAP, SIGNING_COMPATIBLE_MAP, XCM_MIN_AMOUNT_RATIO } from '@subwallet/extension-base/constants';
|
|
8
8
|
import { _canAccountBeReaped, _isAccountActive } from '@subwallet/extension-base/core/substrate/system-pallet';
|
|
9
9
|
import { getCardanoAssetId } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/utils';
|
|
10
10
|
import { isBounceableAddress } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
|
|
11
11
|
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
12
|
-
import { _getAssetDecimals, _getChainExistentialDeposit, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getTokenMinAmount, _isCIP26Token, _isNativeToken, _isTokenEvmSmartContract, _isTokenTonSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
12
|
+
import { _getAssetDecimals, _getAssetPriceId, _getAssetSymbol, _getChainExistentialDeposit, _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getTokenMinAmount, _isCIP26Token, _isNativeToken, _isNativeTokenBySlug, _isTokenEvmSmartContract, _isTokenTonSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import { calculateToAmountByReservePool, FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE } from '@subwallet/extension-base/services/fee-service/utils';
|
|
14
14
|
import { isCardanoTransaction, isSubstrateTransaction, isTonTransaction } from '@subwallet/extension-base/services/transaction-service/helpers';
|
|
15
15
|
import { AccountSignMode, BasicTxErrorType, BasicTxWarningCode, TransferTxErrorType } from '@subwallet/extension-base/types';
|
|
@@ -331,7 +331,7 @@ export function checkSupportForTransaction(validationResponse, transaction) {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
export async function estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, feeInfo, nativeTokenInfo,
|
|
334
|
+
export async function estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, isTransferLocalTokenAndPayThatTokenAsFee) {
|
|
335
335
|
const estimateFee = {
|
|
336
336
|
symbol: '',
|
|
337
337
|
decimals: 0,
|
|
@@ -377,11 +377,25 @@ export async function estimateFeeForTransaction(validationResponse, transaction,
|
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
const isCustomTokenPayFeeAssetHub = !!nonNativeTokenPayFeeInfo && _SUPPORT_TOKEN_PAY_FEE_GROUP.assetHub.includes(nonNativeTokenPayFeeInfo.originChain);
|
|
381
|
+
const isCustomTokenPayFeeHydration = !!nonNativeTokenPayFeeInfo && _SUPPORT_TOKEN_PAY_FEE_GROUP.hydration.includes(nonNativeTokenPayFeeInfo.originChain);
|
|
382
|
+
if (isCustomTokenPayFeeAssetHub) {
|
|
381
383
|
const estimatedFeeAmount = isTransferLocalTokenAndPayThatTokenAsFee ? (BigInt(estimateFee.value) * BigInt(FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE) / BigInt(100)).toString() : estimateFee.value;
|
|
382
|
-
estimateFee.decimals =
|
|
383
|
-
estimateFee.symbol =
|
|
384
|
-
estimateFee.value = await calculateToAmountByReservePool(substrateApi.api, nativeTokenInfo,
|
|
384
|
+
estimateFee.decimals = _getAssetDecimals(nonNativeTokenPayFeeInfo);
|
|
385
|
+
estimateFee.symbol = _getAssetSymbol(nonNativeTokenPayFeeInfo);
|
|
386
|
+
estimateFee.value = await calculateToAmountByReservePool(substrateApi.api, nativeTokenInfo, nonNativeTokenPayFeeInfo, estimatedFeeAmount);
|
|
387
|
+
}
|
|
388
|
+
if (isCustomTokenPayFeeHydration) {
|
|
389
|
+
const nativePriceId = _getAssetPriceId(nativeTokenInfo);
|
|
390
|
+
const nativeDecimals = _getAssetDecimals(nativeTokenInfo);
|
|
391
|
+
const nativePrice = priceMap[nativePriceId];
|
|
392
|
+
const tokenPriceId = _getAssetPriceId(nonNativeTokenPayFeeInfo);
|
|
393
|
+
const tokenDecimals = _getAssetDecimals(nonNativeTokenPayFeeInfo);
|
|
394
|
+
const tokenPrice = priceMap[tokenPriceId];
|
|
395
|
+
const rate = new BigN(nativePrice).div(tokenPrice).multipliedBy(10 ** (tokenDecimals - nativeDecimals)).toFixed();
|
|
396
|
+
estimateFee.decimals = _getAssetDecimals(nonNativeTokenPayFeeInfo);
|
|
397
|
+
estimateFee.symbol = _getAssetSymbol(nonNativeTokenPayFeeInfo);
|
|
398
|
+
estimateFee.value = new BigN(estimateFee.value).multipliedBy(rate).toFixed(0);
|
|
385
399
|
}
|
|
386
400
|
return estimateFee;
|
|
387
401
|
}
|
|
@@ -421,10 +435,11 @@ export function checkBalanceWithTransactionFee(validationResponse, transactionIn
|
|
|
421
435
|
edAsWarning,
|
|
422
436
|
extrinsicType,
|
|
423
437
|
isTransferAll,
|
|
424
|
-
|
|
425
|
-
|
|
438
|
+
skipFeeValidation,
|
|
439
|
+
tokenPayFeeSlug
|
|
426
440
|
} = transactionInput;
|
|
427
|
-
if (skipFeeValidation ||
|
|
441
|
+
if (skipFeeValidation || tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug)) {
|
|
442
|
+
// todo: need improve: input should be balance of fee token and check this again
|
|
428
443
|
return;
|
|
429
444
|
}
|
|
430
445
|
const bnFee = new BigN(validationResponse.estimateFee.value);
|