@subwallet/extension-base 1.2.3-0 → 1.2.4-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +4 -153
- package/background/KoniTypes.js +0 -21
- package/cjs/background/KoniTypes.js +1 -22
- package/cjs/core/logic-validation/earning.js +47 -0
- package/cjs/core/logic-validation/swap.js +99 -0
- package/cjs/core/logic-validation/transfer.js +212 -0
- package/cjs/core/substrate/nominationpools-pallet.js +22 -0
- package/cjs/core/substrate/system-pallet.js +77 -0
- package/cjs/core/substrate/xcm-parser.js +190 -0
- package/cjs/koni/api/dotsama/transfer.js +58 -122
- package/cjs/koni/api/staking/bonding/utils.js +1 -1
- package/cjs/koni/api/xcm/index.js +30 -2
- package/cjs/koni/api/xcm/polkadotXcm.js +12 -20
- package/cjs/koni/api/xcm/utils.js +8 -126
- package/cjs/koni/api/xcm/xTokens.js +10 -8
- package/cjs/koni/api/xcm/xcmPallet.js +6 -6
- package/cjs/koni/background/handlers/Extension.js +223 -356
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/group.js +4 -27
- package/cjs/services/balance-service/helpers/subscribe/index.js +2 -30
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +46 -82
- package/cjs/services/balance-service/index.js +11 -9
- package/cjs/services/chain-service/constants.js +2 -2
- package/cjs/services/chain-service/index.js +0 -1
- package/cjs/services/chain-service/utils/index.js +13 -2
- package/cjs/services/earning-service/handlers/base.js +1 -1
- package/cjs/services/earning-service/handlers/special.js +11 -12
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/swap-service/handler/base-handler.js +30 -44
- package/cjs/services/swap-service/handler/chainflip-handler.js +23 -21
- package/cjs/services/swap-service/handler/hydradx-handler.js +41 -39
- package/cjs/services/swap-service/index.js +6 -0
- package/cjs/services/swap-service/utils.js +8 -49
- package/cjs/services/transaction-service/index.js +66 -155
- package/core/logic-validation/earning.d.ts +10 -0
- package/core/logic-validation/earning.js +37 -0
- package/core/logic-validation/swap.d.ts +8 -0
- package/core/logic-validation/swap.js +89 -0
- package/core/logic-validation/transfer.d.ts +16 -0
- package/core/logic-validation/transfer.js +199 -0
- package/core/substrate/nominationpools-pallet.d.ts +10 -0
- package/core/substrate/nominationpools-pallet.js +13 -0
- package/core/substrate/system-pallet.d.ts +27 -0
- package/core/substrate/system-pallet.js +70 -0
- package/core/substrate/xcm-parser.d.ts +49 -0
- package/core/substrate/xcm-parser.js +181 -0
- package/koni/api/dotsama/transfer.d.ts +3 -4
- package/koni/api/dotsama/transfer.js +54 -118
- package/koni/api/staking/bonding/relayChain.d.ts +2 -1
- package/koni/api/staking/bonding/utils.js +1 -1
- package/koni/api/xcm/index.d.ts +2 -0
- package/koni/api/xcm/index.js +27 -1
- package/koni/api/xcm/polkadotXcm.js +14 -22
- package/koni/api/xcm/utils.d.ts +3 -48
- package/koni/api/xcm/utils.js +5 -114
- package/koni/api/xcm/xTokens.js +12 -10
- package/koni/api/xcm/xcmPallet.js +7 -7
- package/koni/background/handlers/Extension.d.ts +6 -8
- package/koni/background/handlers/Extension.js +117 -247
- package/package.json +39 -9
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/group.js +4 -27
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/index.js +2 -30
- package/services/balance-service/helpers/subscribe/substrate/index.d.ts +2 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +31 -66
- package/services/balance-service/index.d.ts +7 -6
- package/services/balance-service/index.js +12 -10
- package/services/chain-service/constants.js +2 -2
- package/services/chain-service/index.js +0 -1
- package/services/chain-service/utils/index.d.ts +4 -2
- package/services/chain-service/utils/index.js +9 -2
- package/services/earning-service/handlers/base.js +1 -1
- package/services/earning-service/handlers/nomination-pool/index.d.ts +2 -1
- package/services/earning-service/handlers/special.js +11 -12
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -1
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -1
- package/services/migration-service/scripts/index.js +2 -2
- package/services/swap-service/handler/base-handler.d.ts +3 -2
- package/services/swap-service/handler/base-handler.js +28 -42
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
- package/services/swap-service/handler/chainflip-handler.js +4 -2
- package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
- package/services/swap-service/handler/hydradx-handler.js +8 -6
- package/services/swap-service/index.js +7 -1
- package/services/swap-service/utils.d.ts +2 -4
- package/services/swap-service/utils.js +7 -47
- package/services/transaction-service/index.d.ts +1 -1
- package/services/transaction-service/index.js +30 -119
- package/services/transaction-service/types.d.ts +1 -0
- package/types/balance/index.d.ts +6 -10
- package/types/yield/info/pallet.d.ts +0 -6
|
@@ -1,121 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.checkSupportTransfer = checkSupportTransfer;
|
|
8
|
-
exports.createTransferExtrinsic = void 0;
|
|
7
|
+
exports.getTransferMockTxFee = exports.createTransferExtrinsic = void 0;
|
|
9
8
|
var _api = require("@gear-js/api");
|
|
10
9
|
var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
|
|
11
10
|
var _utils = require("@subwallet/extension-base/koni/api/tokens/wasm/utils");
|
|
12
11
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
13
12
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
14
|
-
var _utils3 = require("@subwallet/extension-base/utils");
|
|
13
|
+
var _utils3 = require("@subwallet/extension-base/services/fee-service/utils");
|
|
14
|
+
var _utils4 = require("@subwallet/extension-base/utils");
|
|
15
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
15
16
|
var _util = require("@polkadot/util");
|
|
16
17
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
17
18
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
18
19
|
// SPDX-License-Identifier: Apache-2.0
|
|
19
20
|
|
|
20
|
-
function isRefCount(accountInfo) {
|
|
21
|
-
return !!accountInfo.refcount;
|
|
22
|
-
}
|
|
23
|
-
async function checkReferenceCount(networkKey, address, substrateApiMap, chainInfo) {
|
|
24
|
-
const apiProps = await substrateApiMap[networkKey].isReady;
|
|
25
|
-
const api = apiProps.api;
|
|
26
|
-
if ((0, _utils2._isChainEvmCompatible)(chainInfo)) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
const accountInfo = await api.query.system.account(address);
|
|
32
|
-
return accountInfo ? isRefCount(accountInfo) ? !accountInfo.refcount.isZero() : !accountInfo.consumers.isZero() : false;
|
|
33
|
-
}
|
|
34
|
-
async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chainInfo) {
|
|
35
|
-
const substrateApi = await substrateApiMap[networkKey].isReady;
|
|
36
|
-
if (!tokenInfo) {
|
|
37
|
-
return {
|
|
38
|
-
supportTransfer: false,
|
|
39
|
-
supportTransferAll: false
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if ((0, _utils2._isChainEvmCompatible)(chainInfo)) {
|
|
43
|
-
return {
|
|
44
|
-
supportTransfer: true,
|
|
45
|
-
supportTransferAll: true
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (tokenInfo.symbol.startsWith(_constants._ZK_ASSET_PREFIX) && _constants._MANTA_ZK_CHAIN_GROUP.includes(tokenInfo.originChain)) {
|
|
49
|
-
return {
|
|
50
|
-
supportTransfer: false,
|
|
51
|
-
supportTransferAll: false
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if (_constants._TRANSFER_NOT_SUPPORTED_CHAINS.includes(networkKey)) {
|
|
55
|
-
return {
|
|
56
|
-
supportTransfer: false,
|
|
57
|
-
supportTransferAll: false
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const api = substrateApi.api;
|
|
61
|
-
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
62
|
-
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
63
|
-
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
64
|
-
const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
65
|
-
const result = {
|
|
66
|
-
supportTransfer: false,
|
|
67
|
-
supportTransferAll: false
|
|
68
|
-
};
|
|
69
|
-
if (!(isTxCurrenciesSupported || isTxBalancesSupported || isTxTokensSupported || isTxEqBalancesSupported)) {
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
if ((0, _utils2._isTokenWasmSmartContract)(tokenInfo) && api.query.contracts) {
|
|
73
|
-
// for PSP tokens
|
|
74
|
-
return {
|
|
75
|
-
supportTransfer: true,
|
|
76
|
-
supportTransferAll: true
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// TODO: need review
|
|
81
|
-
if (_constants._TRANSFER_CHAIN_GROUP.acala.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxCurrenciesSupported) {
|
|
82
|
-
result.supportTransfer = true;
|
|
83
|
-
result.supportTransferAll = true;
|
|
84
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxTokensSupported) {
|
|
85
|
-
result.supportTransfer = true;
|
|
86
|
-
result.supportTransferAll = true;
|
|
87
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
88
|
-
// && !_isNativeToken(tokenInfo) && isTxEqBalancesSupported
|
|
89
|
-
) {
|
|
90
|
-
result.supportTransfer = false;
|
|
91
|
-
result.supportTransferAll = false;
|
|
92
|
-
// } else if (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) && _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
93
|
-
// result.supportTransfer = true;
|
|
94
|
-
// result.supportTransferAll = true;
|
|
95
|
-
} else if (isTxBalancesSupported && (0, _utils2._isNativeToken)(tokenInfo)) {
|
|
96
|
-
result.supportTransfer = true;
|
|
97
|
-
result.supportTransferAll = true;
|
|
98
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && _constants._BALANCE_TOKEN_GROUP.bitcountry.includes(tokenInfo.symbol)) {
|
|
99
|
-
result.supportTransfer = true;
|
|
100
|
-
result.supportTransferAll = true;
|
|
101
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
102
|
-
result.supportTransfer = true;
|
|
103
|
-
result.supportTransferAll = true;
|
|
104
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey)) {
|
|
105
|
-
result.supportTransfer = true;
|
|
106
|
-
result.supportTransferAll = true;
|
|
107
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey) && _isNativeToken(tokenInfo)) {
|
|
108
|
-
// result.supportTransfer = true;
|
|
109
|
-
// result.supportTransferAll = true;
|
|
110
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
111
|
-
result.supportTransfer = true;
|
|
112
|
-
result.supportTransferAll = true;
|
|
113
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.centrifuge.includes(networkKey)) {
|
|
114
|
-
result.supportTransfer = true;
|
|
115
|
-
result.supportTransferAll = true;
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
21
|
const createTransferExtrinsic = async _ref => {
|
|
120
22
|
var _tokenInfo$metadata;
|
|
121
23
|
let {
|
|
@@ -138,11 +40,17 @@ const createTransferExtrinsic = async _ref => {
|
|
|
138
40
|
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
139
41
|
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
140
42
|
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
141
|
-
// const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
142
43
|
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
143
44
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
144
45
|
|
|
145
|
-
if ((0, _utils2.
|
|
46
|
+
if ((0, _utils2._isBridgedToken)(tokenInfo) && api.tx.foreignAssets) {
|
|
47
|
+
const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
48
|
+
if (transferAll) {
|
|
49
|
+
transfer = api.tx.foreignAssets.transfer(onChainInfo, to, value);
|
|
50
|
+
} else {
|
|
51
|
+
transfer = api.tx.foreignAssets.transferKeepAlive(onChainInfo, to, value);
|
|
52
|
+
}
|
|
53
|
+
} else if ((0, _utils2._isTokenWasmSmartContract)(tokenInfo) && api.query.contracts) {
|
|
146
54
|
const contractPromise = (0, _wasm.getPSP22ContractPromise)(api, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
147
55
|
// @ts-ignore
|
|
148
56
|
const gasLimit = await (0, _utils.getWasmContractGasLimit)(api, from, 'psp22::transfer', contractPromise, {}, [from, value, {}]);
|
|
@@ -153,7 +61,7 @@ const createTransferExtrinsic = async _ref => {
|
|
|
153
61
|
}, to, value, {});
|
|
154
62
|
transferAmount = value;
|
|
155
63
|
} else if ((0, _utils2._isTokenGearSmartContract)(tokenInfo) && api instanceof _api.GearApi) {
|
|
156
|
-
const contractPromise = (0,
|
|
64
|
+
const contractPromise = (0, _utils4.getGRC20ContractPromise)(api, (0, _utils2._getContractAddressOfToken)(tokenInfo));
|
|
157
65
|
const transaction = await contractPromise.transfer((0, _util.u8aToHex)((0, _utilCrypto.decodeAddress)(to)), BigInt(value)) // Create transfer transaction
|
|
158
66
|
.withAccount(from) // Set sender account
|
|
159
67
|
.calculateGas(); // Add account arg to extrinsic
|
|
@@ -184,25 +92,10 @@ const createTransferExtrinsic = async _ref => {
|
|
|
184
92
|
} else if (value) {
|
|
185
93
|
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
186
94
|
}
|
|
187
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
188
|
-
// && isTxEqBalancesSupported
|
|
189
|
-
) {
|
|
190
|
-
// transfer = api.tx.eqBalances.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
191
|
-
/* empty */
|
|
192
|
-
// } else if (!_isNativeToken(tokenInfo) && (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) || _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol))) {
|
|
193
|
-
// if (transferAll) {
|
|
194
|
-
// transfer = api.tx.kton.transferAll(to, false);
|
|
195
|
-
// } else if (value) {
|
|
196
|
-
// transfer = api.tx.kton.transfer(to, new BN(value));
|
|
197
|
-
// }
|
|
198
95
|
} else if (_constants._TRANSFER_CHAIN_GROUP.bitcountry.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
199
96
|
transfer = api.tx.currencies.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), value);
|
|
200
97
|
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
201
98
|
transfer = api.tx.assets.transfer((0, _utils2._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
202
|
-
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey)) {
|
|
203
|
-
// if (_isNativeToken(tokenInfo)) {
|
|
204
|
-
// transfer = api.tx.currencies.transferNativeCurrency(to, value);
|
|
205
|
-
// }
|
|
206
99
|
} else if (_constants._TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
207
100
|
transfer = api.tx.assets.transfer((0, _utils2._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
208
101
|
} else if (isTxBalancesSupported && (0, _utils2._isNativeToken)(tokenInfo)) {
|
|
@@ -221,4 +114,47 @@ const createTransferExtrinsic = async _ref => {
|
|
|
221
114
|
}
|
|
222
115
|
return [transfer, transferAmount || value];
|
|
223
116
|
};
|
|
224
|
-
exports.createTransferExtrinsic = createTransferExtrinsic;
|
|
117
|
+
exports.createTransferExtrinsic = createTransferExtrinsic;
|
|
118
|
+
const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) => {
|
|
119
|
+
try {
|
|
120
|
+
let estimatedFee;
|
|
121
|
+
if ((0, _utils2._isChainEvmCompatible)(chainInfo) && (0, _utils2._isTokenTransferredByEvm)(tokenInfo)) {
|
|
122
|
+
const web3 = api;
|
|
123
|
+
const transaction = {
|
|
124
|
+
value: 0,
|
|
125
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
126
|
+
// null address
|
|
127
|
+
from: address
|
|
128
|
+
};
|
|
129
|
+
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
130
|
+
const priority = await (0, _utils3.calculateGasFeeParams)(web3, chainInfo.slug);
|
|
131
|
+
if (priority.baseGasFee) {
|
|
132
|
+
const maxFee = priority.maxFeePerGas;
|
|
133
|
+
estimatedFee = maxFee.multipliedBy(gasLimit);
|
|
134
|
+
} else {
|
|
135
|
+
estimatedFee = new _bignumber.default(priority.gasPrice).multipliedBy(gasLimit);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
var _paymentInfo$partialF;
|
|
139
|
+
const substrateApi = api;
|
|
140
|
+
const chainApi = await substrateApi.isReady;
|
|
141
|
+
const [mockTx] = await createTransferExtrinsic({
|
|
142
|
+
from: address,
|
|
143
|
+
networkKey: chainInfo.slug,
|
|
144
|
+
substrateApi: chainApi,
|
|
145
|
+
to: address,
|
|
146
|
+
tokenInfo,
|
|
147
|
+
transferAll: true,
|
|
148
|
+
value: '1000000000000000000'
|
|
149
|
+
});
|
|
150
|
+
const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
|
|
151
|
+
estimatedFee = new _bignumber.default((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0'); // todo: should handle error case instead of setting fee to 0
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return estimatedFee;
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.error('error mocking tx fee', e);
|
|
157
|
+
return new _bignumber.default(0);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
exports.getTransferMockTxFee = getTransferMockTxFee;
|
|
@@ -423,7 +423,7 @@ function getTopValidatorByPoints(validatorPointsList) {
|
|
|
423
423
|
const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
|
|
424
424
|
const tokenInfo = (0, _utils._getChainNativeTokenBasicInfo)(chainInfo);
|
|
425
425
|
const number = (0, _number.formatNumber)(bnMinStake.toString(), tokenInfo.decimals || 0, _number.balanceFormatter);
|
|
426
|
-
return (0, _i18next.t)('Insufficient stake.
|
|
426
|
+
return (0, _i18next.t)('Insufficient stake. You need to stake at least {{number}} {{tokenSymbol}} to earn rewards', {
|
|
427
427
|
replace: {
|
|
428
428
|
tokenSymbol: tokenInfo.symbol,
|
|
429
429
|
number
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.createXcmExtrinsic = void 0;
|
|
7
|
+
exports.getXcmMockTxFee = exports.createXcmExtrinsic = void 0;
|
|
7
8
|
var _polkadotXcm = require("@subwallet/extension-base/koni/api/xcm/polkadotXcm");
|
|
8
9
|
var _xcmPallet = require("@subwallet/extension-base/koni/api/xcm/xcmPallet");
|
|
9
10
|
var _xTokens = require("@subwallet/extension-base/koni/api/xcm/xTokens");
|
|
10
11
|
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
11
12
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
13
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
12
16
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
13
17
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
18
|
|
|
@@ -39,4 +43,28 @@ const createXcmExtrinsic = async _ref => {
|
|
|
39
43
|
}
|
|
40
44
|
return extrinsic;
|
|
41
45
|
};
|
|
42
|
-
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
46
|
+
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
47
|
+
const getXcmMockTxFee = async (substrateApi, chainInfoMap, address, originTokenInfo, destinationTokenInfo) => {
|
|
48
|
+
try {
|
|
49
|
+
var _paymentInfo$partialF;
|
|
50
|
+
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
51
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
52
|
+
|
|
53
|
+
// mock receiving account from sender
|
|
54
|
+
const recipient = !(0, _utilCrypto.isEthereumAddress)(address) && (0, _utils._isChainEvmCompatible)(destChainInfo) && !(0, _utils._isChainEvmCompatible)(originChainInfo) ? (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(address)) : address;
|
|
55
|
+
const mockTx = await createXcmExtrinsic({
|
|
56
|
+
chainInfoMap,
|
|
57
|
+
destinationTokenInfo,
|
|
58
|
+
originTokenInfo,
|
|
59
|
+
recipient: recipient,
|
|
60
|
+
sendingValue: '1000000000000000000',
|
|
61
|
+
substrateApi
|
|
62
|
+
});
|
|
63
|
+
const paymentInfo = await mockTx.paymentInfo(address);
|
|
64
|
+
return new _bignumber.default((paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0');
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error('error mocking xcm tx fee', e);
|
|
67
|
+
return new _bignumber.default(0);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.getXcmMockTxFee = getXcmMockTxFee;
|
|
@@ -4,35 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getExtrinsicByPolkadotXcmPallet = getExtrinsicByPolkadotXcmPallet;
|
|
7
|
+
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
7
8
|
var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
|
|
8
9
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
9
10
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
12
|
|
|
12
13
|
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
13
|
-
|
|
14
|
-
const version = ['statemint', 'statemine', 'shiden', 'astar'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
15
|
-
const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress, version);
|
|
16
|
-
const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo, version);
|
|
17
|
-
let assetLocation = (0, _utils.getTokenLocation)(tokenInfo, value, version);
|
|
14
|
+
let version = _utils.STABLE_XCM_VERSION;
|
|
18
15
|
let method = 'limitedReserveTransferAssets';
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
parents: 1,
|
|
25
|
-
interior: 'Here'
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
fun: {
|
|
29
|
-
Fungible: value
|
|
30
|
-
}
|
|
31
|
-
}]
|
|
32
|
-
};
|
|
16
|
+
if ((0, _utils2._isBridgedToken)(tokenInfo)) {
|
|
17
|
+
version = 4;
|
|
18
|
+
method = 'transferAssets';
|
|
19
|
+
}
|
|
20
|
+
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo)) {
|
|
33
21
|
method = 'limitedTeleportAssets';
|
|
34
22
|
}
|
|
35
|
-
|
|
23
|
+
const weightParam = (0, _xcmParser._getXcmDestWeight)(originChainInfo);
|
|
24
|
+
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, version);
|
|
25
|
+
const beneficiary = (0, _xcmParser._getXcmBeneficiary)(destinationChainInfo, recipientAddress, version);
|
|
26
|
+
const tokenLocation = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, version);
|
|
27
|
+
return api.tx.polkadotXcm[method](destination, beneficiary, tokenLocation, 0,
|
|
36
28
|
// FeeAssetItem
|
|
37
29
|
weightParam);
|
|
38
30
|
}
|
|
@@ -3,133 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.getDestMultilocation = getDestMultilocation;
|
|
9
|
-
exports.getDestWeight = getDestWeight;
|
|
10
|
-
exports.getDestinationChainLocation = getDestinationChainLocation;
|
|
11
|
-
exports.getReceiverLocation = getReceiverLocation;
|
|
12
|
-
exports.getTokenLocation = getTokenLocation;
|
|
13
|
-
var _chainList = require("@subwallet/chain-list");
|
|
14
|
-
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
15
|
-
var _utilCrypto = require("@polkadot/util-crypto");
|
|
6
|
+
exports.STABLE_XCM_VERSION = void 0;
|
|
7
|
+
exports.isUseTeleportProtocol = isUseTeleportProtocol;
|
|
16
8
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
17
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
18
10
|
|
|
19
|
-
const
|
|
20
|
-
exports.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// get multilocation for destination chain from a parachain
|
|
26
|
-
exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = FOUR_INSTRUCTIONS_LIMITED_WEIGHT;
|
|
27
|
-
function getReceiverLocation(destinationChainInfo, toAddress, version) {
|
|
28
|
-
const network = version && version === 'V3' ? undefined : 'Any';
|
|
29
|
-
if (destinationChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
30
|
-
const ss58Address = (0, _utilCrypto.evmToAddress)(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
AccountId32: {
|
|
34
|
-
network,
|
|
35
|
-
id: (0, _utilCrypto.decodeAddress)(ss58Address)
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if ((0, _utils._isChainEvmCompatible)(destinationChainInfo)) {
|
|
40
|
-
return {
|
|
41
|
-
AccountKey20: {
|
|
42
|
-
network,
|
|
43
|
-
key: toAddress
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
AccountId32: {
|
|
49
|
-
network,
|
|
50
|
-
id: (0, _utilCrypto.decodeAddress)(toAddress)
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function getBeneficiary(destinationChainInfo, recipientAddress) {
|
|
55
|
-
let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
|
|
56
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
|
|
57
|
-
return {
|
|
58
|
-
[version]: {
|
|
59
|
-
parents: 0,
|
|
60
|
-
interior: {
|
|
61
|
-
X1: receiverLocation
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function getDestWeight() {
|
|
67
|
-
return 'Unlimited';
|
|
68
|
-
}
|
|
69
|
-
function getTokenLocation(tokenInfo, sendingValue) {
|
|
70
|
-
let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
|
|
71
|
-
if (!(0, _utils._isNativeToken)(tokenInfo)) {
|
|
72
|
-
const multilocation = (0, _utils._getXcmAssetMultilocation)(tokenInfo);
|
|
73
|
-
return {
|
|
74
|
-
[version]: [{
|
|
75
|
-
id: multilocation,
|
|
76
|
-
fun: {
|
|
77
|
-
Fungible: sendingValue
|
|
78
|
-
}
|
|
79
|
-
}]
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
[version]: [{
|
|
84
|
-
id: {
|
|
85
|
-
Concrete: {
|
|
86
|
-
parents: 0,
|
|
87
|
-
interior: 'Here'
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
fun: {
|
|
91
|
-
Fungible: sendingValue
|
|
92
|
-
}
|
|
93
|
-
}]
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function getDestMultilocation(destinationChainInfo, recipient) {
|
|
97
|
-
let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
|
|
98
|
-
const receiverLocation = getReceiverLocation(destinationChainInfo, recipient, version);
|
|
99
|
-
if ((0, _utils._isSubstrateParaChain)(destinationChainInfo)) {
|
|
100
|
-
const interior = {
|
|
101
|
-
X2: [{
|
|
102
|
-
Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
|
|
103
|
-
}, receiverLocation]
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
[version]: {
|
|
107
|
-
parents: 1,
|
|
108
|
-
interior
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
[version]: {
|
|
114
|
-
parents: 1,
|
|
115
|
-
interior: {
|
|
116
|
-
X1: receiverLocation
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function getDestinationChainLocation(originChainInfo, destinationChainInfo) {
|
|
122
|
-
let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
|
|
123
|
-
const parents = (0, _utils._isSubstrateRelayChain)(originChainInfo) ? 0 : 1;
|
|
124
|
-
const interior = (0, _utils._isSubstrateParaChain)(destinationChainInfo) ? {
|
|
125
|
-
X1: {
|
|
126
|
-
Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
|
|
127
|
-
}
|
|
128
|
-
} : 'Here';
|
|
129
|
-
return {
|
|
130
|
-
[version]: {
|
|
131
|
-
parents,
|
|
132
|
-
interior
|
|
133
|
-
}
|
|
134
|
-
};
|
|
11
|
+
const STABLE_XCM_VERSION = 3;
|
|
12
|
+
exports.STABLE_XCM_VERSION = STABLE_XCM_VERSION;
|
|
13
|
+
function isUseTeleportProtocol(originChainInfo, destChainInfo) {
|
|
14
|
+
const relayChainToSystemChain = ['polkadot'].includes(originChainInfo.slug) && ['statemint'].includes(destChainInfo.slug) || ['kusama'].includes(originChainInfo.slug) && ['statemine'].includes(destChainInfo.slug);
|
|
15
|
+
const systemChainToRelayChain = ['polkadot'].includes(destChainInfo.slug) && ['statemint'].includes(originChainInfo.slug) || ['kusama'].includes(destChainInfo.slug) && ['statemine'].includes(originChainInfo.slug);
|
|
16
|
+
return relayChainToSystemChain || systemChainToRelayChain;
|
|
135
17
|
}
|
|
@@ -4,27 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getExtrinsicByXtokensPallet = getExtrinsicByXtokensPallet;
|
|
7
|
+
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
7
8
|
var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
|
|
8
9
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
9
10
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
12
|
|
|
12
13
|
function getCurrencyId(tokenInfo) {
|
|
13
|
-
if (['
|
|
14
|
-
return (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
|
|
15
|
-
} else if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
14
|
+
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
16
15
|
const tokenType = (0, _utils2._getXcmAssetType)(tokenInfo);
|
|
17
16
|
const assetId = (0, _utils2._getXcmAssetId)(tokenInfo);
|
|
18
17
|
return {
|
|
19
18
|
[tokenType]: assetId
|
|
20
19
|
};
|
|
21
|
-
} else if (['pioneer'].includes(tokenInfo.originChain)) {
|
|
22
|
-
return (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
|
|
23
20
|
}
|
|
24
21
|
return (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
25
22
|
}
|
|
26
23
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
24
|
+
const version = _utils.STABLE_XCM_VERSION;
|
|
25
|
+
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, version, recipientAddress);
|
|
26
|
+
if (!(0, _utils2._getXcmAssetMultilocation)(tokenInfo)) {
|
|
27
|
+
const tokenCurrencyId = getCurrencyId(tokenInfo);
|
|
28
|
+
return api.tx.xTokens.transfer(tokenCurrencyId, value, destination, (0, _xcmParser._getXcmDestWeight)(originChainInfo));
|
|
29
|
+
}
|
|
30
|
+
const tokenMultiAsset = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, version);
|
|
31
|
+
return api.tx.xTokens.transferMultiassets(tokenMultiAsset, 0, destination, (0, _xcmParser._getXcmDestWeight)(originChainInfo));
|
|
30
32
|
}
|
|
@@ -4,19 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getExtrinsicByXcmPalletPallet = getExtrinsicByXcmPalletPallet;
|
|
7
|
+
var _xcmParser = require("@subwallet/extension-base/core/substrate/xcm-parser");
|
|
7
8
|
var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
|
|
8
9
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
9
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
11
|
|
|
11
12
|
// this pallet is only used by Relaychains
|
|
12
13
|
function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
13
|
-
const weightParam = (0,
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const tokenLocation = (0, _utils.getTokenLocation)(tokenInfo, value, xcmVer);
|
|
14
|
+
const weightParam = (0, _xcmParser._getXcmDestWeight)(originChainInfo);
|
|
15
|
+
const destination = (0, _xcmParser._getXcmMultiLocation)(originChainInfo, destinationChainInfo, _utils.STABLE_XCM_VERSION);
|
|
16
|
+
const beneficiary = (0, _xcmParser._getXcmBeneficiary)(destinationChainInfo, recipientAddress, _utils.STABLE_XCM_VERSION);
|
|
17
|
+
const tokenLocation = (0, _xcmParser._getXcmMultiAssets)(tokenInfo, value, _utils.STABLE_XCM_VERSION);
|
|
18
18
|
let method = 'limitedReserveTransferAssets';
|
|
19
|
-
if (
|
|
19
|
+
if ((0, _utils.isUseTeleportProtocol)(originChainInfo, destinationChainInfo)) {
|
|
20
20
|
method = 'limitedTeleportAssets';
|
|
21
21
|
}
|
|
22
22
|
return api.tx.xcmPallet[method](destination, beneficiary, tokenLocation, 0, weightParam);
|