@subwallet/extension-base 1.0.7-2 → 1.0.9-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 +3 -1
- package/background/KoniTypes.js +1 -0
- package/background/errors/TransactionError.js +5 -1
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/background/errors/TransactionError.js +4 -0
- package/cjs/constants/index.js +6 -3
- package/cjs/koni/api/dotsama/balance.js +5 -2
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/dotsama/transfer.js +19 -5
- package/cjs/koni/api/tokens/wasm/index.js +7 -0
- package/cjs/koni/api/xcm/polkadotXcm.js +18 -37
- package/cjs/koni/api/xcm/utils.js +78 -11
- package/cjs/koni/api/xcm/xTokens.js +4 -33
- package/cjs/koni/api/xcm/xcmPallet.js +4 -36
- package/cjs/koni/background/handlers/Extension.js +83 -25
- package/cjs/koni/background/handlers/State.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +9 -7
- package/cjs/services/chain-service/index.js +19 -15
- package/cjs/services/chain-service/utils.js +1 -5
- package/cjs/services/history-service/constants/index.js +13 -0
- package/cjs/services/history-service/subsquid-multi-chain-history.js +38 -3
- package/cjs/services/transaction-service/helpers/index.js +45 -2
- package/cjs/services/transaction-service/index.js +58 -24
- package/cjs/utils/eth/parseTransaction/index.js +69 -59
- package/cjs/utils/number.js +112 -0
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/koni/api/dotsama/balance.js +4 -2
- package/koni/api/dotsama/crowdloan.js +2 -2
- package/koni/api/dotsama/transfer.js +19 -5
- package/koni/api/tokens/wasm/index.js +7 -0
- package/koni/api/xcm/polkadotXcm.js +20 -39
- package/koni/api/xcm/utils.d.ts +36 -3
- package/koni/api/xcm/utils.js +72 -11
- package/koni/api/xcm/xTokens.js +6 -35
- package/koni/api/xcm/xcmPallet.js +5 -35
- package/koni/background/handlers/Extension.js +82 -24
- package/koni/background/handlers/State.js +2 -2
- package/package.json +18 -8
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +9 -7
- package/services/chain-service/index.js +13 -8
- package/services/chain-service/utils.d.ts +0 -1
- package/services/chain-service/utils.js +1 -4
- package/services/history-service/constants/index.d.ts +2 -0
- package/services/history-service/constants/index.js +5 -0
- package/services/history-service/subsquid-multi-chain-history.d.ts +1 -1
- package/services/history-service/subsquid-multi-chain-history.js +36 -3
- package/services/transaction-service/helpers/index.d.ts +2 -0
- package/services/transaction-service/helpers/index.js +42 -0
- package/services/transaction-service/index.js +54 -20
- package/services/transaction-service/types.d.ts +2 -2
- package/utils/eth/parseTransaction/index.js +69 -59
- package/utils/number.d.ts +9 -0
- package/utils/number.js +100 -0
|
@@ -386,6 +386,7 @@ export interface AmountData extends BasicTokenInfo {
|
|
|
386
386
|
}
|
|
387
387
|
export interface XCMTransactionAdditionalInfo {
|
|
388
388
|
destinationChain: string;
|
|
389
|
+
originalChain: string;
|
|
389
390
|
fee?: AmountData;
|
|
390
391
|
}
|
|
391
392
|
export interface NFTTransactionAdditionalInfo {
|
|
@@ -458,7 +459,8 @@ export declare enum TransferTxErrorType {
|
|
|
458
459
|
NOT_ENOUGH_VALUE = "NOT_ENOUGH_VALUE",
|
|
459
460
|
NOT_ENOUGH_FEE = "NOT_ENOUGH_FEE",
|
|
460
461
|
INVALID_TOKEN = "INVALID_TOKEN",
|
|
461
|
-
TRANSFER_ERROR = "TRANSFER_ERROR"
|
|
462
|
+
TRANSFER_ERROR = "TRANSFER_ERROR",
|
|
463
|
+
RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"
|
|
462
464
|
}
|
|
463
465
|
export declare type TransactionErrorType = BasicTxErrorType | TransferTxErrorType | StakingTxErrorType;
|
|
464
466
|
export declare enum BasicTxWarningCode {
|
package/background/KoniTypes.js
CHANGED
|
@@ -120,6 +120,7 @@ export let TransferTxErrorType;
|
|
|
120
120
|
TransferTxErrorType["NOT_ENOUGH_FEE"] = "NOT_ENOUGH_FEE";
|
|
121
121
|
TransferTxErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
|
|
122
122
|
TransferTxErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
123
|
+
TransferTxErrorType["RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
|
|
123
124
|
})(TransferTxErrorType || (TransferTxErrorType = {}));
|
|
124
125
|
export let BasicTxWarningCode;
|
|
125
126
|
(function (BasicTxWarningCode) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
5
|
-
import { BasicTxErrorType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { BasicTxErrorType, StakingTxErrorType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
|
|
7
7
|
// Todo: finish this map in the future
|
|
8
8
|
const defaultErrorMap = {
|
|
@@ -77,6 +77,10 @@ const defaultErrorMap = {
|
|
|
77
77
|
[StakingTxErrorType.INACTIVE_NOMINATION_POOL]: {
|
|
78
78
|
message: 'This nomination pool is not active',
|
|
79
79
|
code: undefined
|
|
80
|
+
},
|
|
81
|
+
[TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
|
|
82
|
+
message: 'Receiver is not enough existential deposit',
|
|
83
|
+
code: undefined
|
|
80
84
|
}
|
|
81
85
|
};
|
|
82
86
|
export class TransactionError extends SWError {
|
|
@@ -127,6 +127,7 @@ exports.TransferTxErrorType = TransferTxErrorType;
|
|
|
127
127
|
TransferTxErrorType["NOT_ENOUGH_FEE"] = "NOT_ENOUGH_FEE";
|
|
128
128
|
TransferTxErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
|
|
129
129
|
TransferTxErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
|
|
130
|
+
TransferTxErrorType["RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
|
|
130
131
|
})(TransferTxErrorType || (exports.TransferTxErrorType = TransferTxErrorType = {}));
|
|
131
132
|
let BasicTxWarningCode;
|
|
132
133
|
exports.BasicTxWarningCode = BasicTxWarningCode;
|
|
@@ -82,6 +82,10 @@ const defaultErrorMap = {
|
|
|
82
82
|
[_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL]: {
|
|
83
83
|
message: 'This nomination pool is not active',
|
|
84
84
|
code: undefined
|
|
85
|
+
},
|
|
86
|
+
[_KoniTypes.TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
|
|
87
|
+
message: 'Receiver is not enough existential deposit',
|
|
88
|
+
code: undefined
|
|
85
89
|
}
|
|
86
90
|
};
|
|
87
91
|
class TransactionError extends _SWError.SWError {
|
package/cjs/constants/index.js
CHANGED
|
@@ -22,9 +22,10 @@ var _exportNames = {
|
|
|
22
22
|
ALL_NETWORK_KEY: true,
|
|
23
23
|
ALL_GENESIS_HASH: true,
|
|
24
24
|
IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
|
|
25
|
-
IGNORE_QR_SIGNER: true
|
|
25
|
+
IGNORE_QR_SIGNER: true,
|
|
26
|
+
XCM_MIN_AMOUNT_RATIO: true
|
|
26
27
|
};
|
|
27
|
-
exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
|
|
28
|
+
exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
|
|
28
29
|
var _staking = require("./staking");
|
|
29
30
|
Object.keys(_staking).forEach(function (key) {
|
|
30
31
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -77,4 +78,6 @@ exports.ALL_GENESIS_HASH = ALL_GENESIS_HASH;
|
|
|
77
78
|
const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
|
|
78
79
|
exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
|
|
79
80
|
const IGNORE_QR_SIGNER = [];
|
|
80
|
-
exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
|
|
81
|
+
exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
|
|
82
|
+
const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
83
|
+
exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
|
|
@@ -1,5 +1,6 @@
|
|
|
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
|
});
|
|
@@ -17,6 +18,7 @@ var _handlers = require("@subwallet/extension-base/koni/background/handlers");
|
|
|
17
18
|
var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
|
|
18
19
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
19
20
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
21
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
20
22
|
var _util = require("@polkadot/util");
|
|
21
23
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
22
24
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -241,7 +243,7 @@ async function subscribeEquilibriumTokenBalance(addresses, chain, api, callBack,
|
|
|
241
243
|
|
|
242
244
|
// @ts-ignore
|
|
243
245
|
const freeTokenBalance = balanceList.find(data => data[0] === parseInt(assetId));
|
|
244
|
-
const bnFreeTokenBalance = freeTokenBalance ? new _util.BN(freeTokenBalance[1].positive.toString()) : _util.BN_ZERO;
|
|
246
|
+
const bnFreeTokenBalance = freeTokenBalance ? new _util.BN(new _bignumber.default(freeTokenBalance[1].positive).toString()) : _util.BN_ZERO;
|
|
245
247
|
tokenFreeBalance = tokenFreeBalance.add(bnFreeTokenBalance);
|
|
246
248
|
}
|
|
247
249
|
const tokenBalance = {
|
|
@@ -296,10 +298,11 @@ async function subscribeTokensAccountsPallet(addresses, chain, api, callBack, in
|
|
|
296
298
|
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
297
299
|
try {
|
|
298
300
|
const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
301
|
+
const assetId = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
299
302
|
|
|
300
303
|
// Get Token Balance
|
|
301
304
|
// @ts-ignore
|
|
302
|
-
return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo]), balances => {
|
|
305
|
+
return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo || assetId]), balances => {
|
|
303
306
|
const tokenBalance = {
|
|
304
307
|
reserved: (0, _utils3.sumBN)(balances.map(b => b.reserved || new _util.BN(0))),
|
|
305
308
|
frozen: (0, _utils3.sumBN)(balances.map(b => b.frozen || new _util.BN(0))),
|
|
@@ -112,7 +112,7 @@ async function subscribeCrowdloan(addresses, substrateApiMap, callback, chainInf
|
|
|
112
112
|
});
|
|
113
113
|
Object.entries(chainInfoMap).forEach(_ref3 => {
|
|
114
114
|
let [networkKey, chainInfo] = _ref3;
|
|
115
|
-
if ((0, _utils.
|
|
115
|
+
if ((0, _utils._isSubstrateParaChain)(chainInfo)) {
|
|
116
116
|
const parentChain = (0, _utils._getSubstrateRelayParent)(chainInfo);
|
|
117
117
|
const crowdloanCb = rs => {
|
|
118
118
|
callback(networkKey, rs);
|
|
@@ -90,7 +90,14 @@ async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMap, chai
|
|
|
90
90
|
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
91
91
|
result.supportTransfer = true;
|
|
92
92
|
result.supportTransferAll = true;
|
|
93
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey)) {
|
|
94
|
+
result.supportTransfer = true;
|
|
95
|
+
result.supportTransferAll = true;
|
|
96
|
+
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey) && _isNativeToken(tokenInfo)) {
|
|
97
|
+
// result.supportTransfer = true;
|
|
98
|
+
// result.supportTransferAll = true;
|
|
93
99
|
}
|
|
100
|
+
|
|
94
101
|
return result;
|
|
95
102
|
}
|
|
96
103
|
const createTransferExtrinsic = async _ref => {
|
|
@@ -111,6 +118,7 @@ const createTransferExtrinsic = async _ref => {
|
|
|
111
118
|
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
112
119
|
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
113
120
|
const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
121
|
+
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
114
122
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
115
123
|
|
|
116
124
|
if ((0, _utils2._isTokenWasmSmartContract)(tokenInfo) && api.query.contracts) {
|
|
@@ -125,14 +133,14 @@ const createTransferExtrinsic = async _ref => {
|
|
|
125
133
|
transferAmount = value;
|
|
126
134
|
} else if (_constants._TRANSFER_CHAIN_GROUP.acala.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxCurrenciesSupported) {
|
|
127
135
|
transfer = api.tx.currencies.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), value);
|
|
128
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) &&
|
|
136
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && isTxTokensSupported) {
|
|
129
137
|
if (transferAll) {
|
|
130
|
-
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), false);
|
|
138
|
+
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), false);
|
|
131
139
|
} else if (value) {
|
|
132
|
-
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), new _util.BN(value));
|
|
140
|
+
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
133
141
|
}
|
|
134
|
-
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey) &&
|
|
135
|
-
transfer = api.tx.eqBalances.transfer(
|
|
142
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey) && isTxEqBalancesSupported) {
|
|
143
|
+
transfer = api.tx.eqBalances.transfer((0, _utils2._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
136
144
|
} else if (!(0, _utils2._isNativeToken)(tokenInfo) && (_constants._TRANSFER_CHAIN_GROUP.crab.includes(networkKey) || _constants._BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol))) {
|
|
137
145
|
if (transferAll) {
|
|
138
146
|
transfer = api.tx.kton.transferAll(to, false);
|
|
@@ -143,6 +151,12 @@ const createTransferExtrinsic = async _ref => {
|
|
|
143
151
|
transfer = api.tx.currencies.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), value);
|
|
144
152
|
} else if (_constants._TRANSFER_CHAIN_GROUP.statemine.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
145
153
|
transfer = api.tx.assets.transfer((0, _utils2._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
154
|
+
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey)) {
|
|
155
|
+
// if (_isNativeToken(tokenInfo)) {
|
|
156
|
+
// transfer = api.tx.currencies.transferNativeCurrency(to, value);
|
|
157
|
+
// }
|
|
158
|
+
} else if (_constants._TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
159
|
+
transfer = api.tx.assets.transfer((0, _utils2._getTokenOnChainAssetId)(tokenInfo), to, value);
|
|
146
160
|
} else if (isTxBalancesSupported && (0, _utils2._isNativeToken)(tokenInfo)) {
|
|
147
161
|
if (transferAll) {
|
|
148
162
|
transfer = api.tx.balances.transferAll(to, false);
|
|
@@ -18,9 +18,15 @@ function getPSP22ContractPromise(apiPromise, contractAddress) {
|
|
|
18
18
|
function getPSP34ContractPromise(apiPromise, contractAddress) {
|
|
19
19
|
return new _apiContract.ContractPromise(apiPromise, _helper._PSP34_ABI, contractAddress);
|
|
20
20
|
}
|
|
21
|
+
const mustFormatNumberReg = /^-?[0-9][0-9,.]+$/;
|
|
21
22
|
async function getPSP34TransferExtrinsic(networkKey, substrateApi, senderAddress, recipientAddress, params) {
|
|
22
23
|
const contractAddress = params.contractAddress;
|
|
23
24
|
const onChainOption = params.onChainOption;
|
|
25
|
+
for (const [key, value] of Object.entries(onChainOption)) {
|
|
26
|
+
if (mustFormatNumberReg.test(value)) {
|
|
27
|
+
onChainOption[key] = value.replaceAll(',', '');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
try {
|
|
25
31
|
const contractPromise = getPSP34ContractPromise(substrateApi.api, contractAddress);
|
|
26
32
|
// @ts-ignore
|
|
@@ -31,6 +37,7 @@ async function getPSP34TransferExtrinsic(networkKey, substrateApi, senderAddress
|
|
|
31
37
|
gasLimit
|
|
32
38
|
}, recipientAddress, onChainOption, {});
|
|
33
39
|
} catch (e) {
|
|
40
|
+
console.debug(e);
|
|
34
41
|
return null;
|
|
35
42
|
}
|
|
36
43
|
}
|
|
@@ -9,47 +9,28 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
|
9
9
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
|
|
12
|
-
function getDestinationChainLocation(destinationChainInfo) {
|
|
13
|
-
if ((0, _utils2._isSubstrateParaChain)(destinationChainInfo)) {
|
|
14
|
-
return {
|
|
15
|
-
V1: {
|
|
16
|
-
parents: 1,
|
|
17
|
-
interior: {
|
|
18
|
-
X1: {
|
|
19
|
-
Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
// to relaychain by default
|
|
27
|
-
V1: {
|
|
28
|
-
parents: 1,
|
|
29
|
-
interior: 'Here'
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function getAssetLocation(tokenInfo, sendingValue) {
|
|
34
|
-
const multilocation = (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
|
|
35
|
-
return {
|
|
36
|
-
V1: [{
|
|
37
|
-
id: multilocation,
|
|
38
|
-
fun: {
|
|
39
|
-
Fungible: sendingValue
|
|
40
|
-
}
|
|
41
|
-
}]
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
12
|
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
45
13
|
const weightParam = (0, _utils.getDestWeight)();
|
|
46
|
-
const beneficiary = (0, _utils.getBeneficiary)(
|
|
47
|
-
const destination = getDestinationChainLocation(destinationChainInfo);
|
|
48
|
-
|
|
14
|
+
const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress);
|
|
15
|
+
const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo);
|
|
16
|
+
let assetLocation = (0, _utils.getTokenLocation)(tokenInfo, value);
|
|
49
17
|
let method = 'limitedReserveTransferAssets';
|
|
50
|
-
if (['astar', 'shiden'].includes(originChainInfo.slug)) {
|
|
18
|
+
if (['astar', 'shiden'].includes(originChainInfo.slug) && !(0, _utils2._isNativeToken)(tokenInfo)) {
|
|
51
19
|
method = 'limitedReserveWithdrawAssets';
|
|
52
|
-
} else if ((0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
|
|
20
|
+
} else if (['statemint', 'statemine'].includes(originChainInfo.slug) && (0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
|
|
21
|
+
assetLocation = {
|
|
22
|
+
V1: [{
|
|
23
|
+
id: {
|
|
24
|
+
Concrete: {
|
|
25
|
+
parents: 1,
|
|
26
|
+
interior: 'Here'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
fun: {
|
|
30
|
+
Fungible: value
|
|
31
|
+
}
|
|
32
|
+
}]
|
|
33
|
+
};
|
|
53
34
|
method = 'limitedTeleportAssets';
|
|
54
35
|
}
|
|
55
36
|
return api.tx.polkadotXcm[method](destination, beneficiary, assetLocation, 0,
|
|
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.FOUR_INSTRUCTIONS_WEIGHT = exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = void 0;
|
|
7
7
|
exports.getBeneficiary = getBeneficiary;
|
|
8
|
+
exports.getDestMultilocation = getDestMultilocation;
|
|
8
9
|
exports.getDestWeight = getDestWeight;
|
|
10
|
+
exports.getDestinationChainLocation = getDestinationChainLocation;
|
|
9
11
|
exports.getReceiverLocation = getReceiverLocation;
|
|
12
|
+
exports.getTokenLocation = getTokenLocation;
|
|
10
13
|
var _chainList = require("@subwallet/chain-list");
|
|
11
14
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
12
15
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
@@ -21,13 +24,14 @@ const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
|
|
|
21
24
|
|
|
22
25
|
// get multilocation for destination chain from a parachain
|
|
23
26
|
exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = FOUR_INSTRUCTIONS_LIMITED_WEIGHT;
|
|
24
|
-
function getReceiverLocation(
|
|
27
|
+
function getReceiverLocation(destinationChainInfo, toAddress, version) {
|
|
28
|
+
const network = version && version === 'V3' ? undefined : 'Any';
|
|
25
29
|
if (destinationChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM) {
|
|
26
30
|
const ss58Address = (0, _utilCrypto.evmToAddress)(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
|
|
27
31
|
|
|
28
32
|
return {
|
|
29
33
|
AccountId32: {
|
|
30
|
-
network
|
|
34
|
+
network,
|
|
31
35
|
id: (0, _utilCrypto.decodeAddress)(ss58Address)
|
|
32
36
|
}
|
|
33
37
|
};
|
|
@@ -35,21 +39,21 @@ function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
|
|
|
35
39
|
if ((0, _utils._isChainEvmCompatible)(destinationChainInfo)) {
|
|
36
40
|
return {
|
|
37
41
|
AccountKey20: {
|
|
38
|
-
network
|
|
42
|
+
network,
|
|
39
43
|
key: toAddress
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
return {
|
|
44
48
|
AccountId32: {
|
|
45
|
-
network
|
|
49
|
+
network,
|
|
46
50
|
id: (0, _utilCrypto.decodeAddress)(toAddress)
|
|
47
51
|
}
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
|
-
function getBeneficiary(
|
|
51
|
-
let version = arguments.length >
|
|
52
|
-
const receiverLocation = getReceiverLocation(
|
|
54
|
+
function getBeneficiary(destinationChainInfo, recipientAddress) {
|
|
55
|
+
let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
|
|
56
|
+
const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
|
|
53
57
|
return {
|
|
54
58
|
[version]: {
|
|
55
59
|
parents: 0,
|
|
@@ -61,8 +65,71 @@ function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress)
|
|
|
61
65
|
}
|
|
62
66
|
function getDestWeight() {
|
|
63
67
|
return 'Unlimited';
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
};
|
|
68
135
|
}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getExtrinsicByXtokensPallet = getExtrinsicByXtokensPallet;
|
|
7
7
|
var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
|
|
8
|
-
var _constants = require("@subwallet/extension-base/services/chain-service/constants");
|
|
9
8
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
10
9
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
11
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -22,38 +21,10 @@ function getCurrencyId(tokenInfo) {
|
|
|
22
21
|
} else if (['pioneer'].includes(tokenInfo.originChain)) {
|
|
23
22
|
return (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
|
|
24
23
|
}
|
|
25
|
-
return (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
26
|
-
}
|
|
27
|
-
function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, toAddress) {
|
|
28
|
-
const xcmType = (0, _utils2._getXcmTransferType)(originChainInfo, destinationChainInfo);
|
|
29
|
-
const paraId = (0, _utils2._getSubstrateParaId)(destinationChainInfo);
|
|
30
|
-
const receiverLocation = (0, _utils.getReceiverLocation)(originChainInfo, destinationChainInfo, toAddress);
|
|
31
|
-
if (xcmType === _constants._XCM_TYPE.PP) {
|
|
32
|
-
// parachain -> parachain
|
|
33
|
-
const interior = {
|
|
34
|
-
X2: [{
|
|
35
|
-
Parachain: paraId
|
|
36
|
-
}, receiverLocation]
|
|
37
|
-
};
|
|
38
|
-
return {
|
|
39
|
-
V1: {
|
|
40
|
-
parents: 1,
|
|
41
|
-
interior
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// parachain -> relaychain by default
|
|
47
|
-
return {
|
|
48
|
-
V1: {
|
|
49
|
-
parents: 1,
|
|
50
|
-
interior: {
|
|
51
|
-
X1: receiverLocation
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
24
|
+
return (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
55
25
|
}
|
|
56
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
57
|
-
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
58
|
-
|
|
27
|
+
const weightParam = ['pioneer', 'hydradx_main'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
|
+
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
59
30
|
}
|
|
@@ -5,48 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getExtrinsicByXcmPalletPallet = getExtrinsicByXcmPalletPallet;
|
|
7
7
|
var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
|
|
8
|
-
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
9
8
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
10
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
10
|
|
|
12
|
-
function getDestinationChainLocation(destinationChainInfo) {
|
|
13
|
-
let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V1';
|
|
14
|
-
return {
|
|
15
|
-
[version]: {
|
|
16
|
-
parents: 0,
|
|
17
|
-
interior: {
|
|
18
|
-
X1: {
|
|
19
|
-
Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function getTokenLocation(sendingValue) {
|
|
26
|
-
let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V2';
|
|
27
|
-
return {
|
|
28
|
-
// always native token of relaychain
|
|
29
|
-
[version]: [{
|
|
30
|
-
id: {
|
|
31
|
-
Concrete: {
|
|
32
|
-
parents: 0,
|
|
33
|
-
interior: 'Here'
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
fun: {
|
|
37
|
-
Fungible: sendingValue
|
|
38
|
-
}
|
|
39
|
-
}]
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
11
|
// this pallet is only used by Relaychains
|
|
44
12
|
function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
45
13
|
const weightParam = (0, _utils.getDestWeight)();
|
|
46
|
-
const xcmVer = ['kusama'].includes(originChainInfo.slug) ? '
|
|
47
|
-
const destination = getDestinationChainLocation(destinationChainInfo, xcmVer);
|
|
48
|
-
const beneficiary = (0, _utils.getBeneficiary)(
|
|
49
|
-
const tokenLocation = getTokenLocation(value, xcmVer);
|
|
14
|
+
const xcmVer = ['kusama'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
15
|
+
const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo, xcmVer);
|
|
16
|
+
const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress, xcmVer);
|
|
17
|
+
const tokenLocation = (0, _utils.getTokenLocation)(tokenInfo, value, xcmVer);
|
|
50
18
|
let method = 'limitedReserveTransferAssets';
|
|
51
19
|
if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
|
|
52
20
|
method = 'limitedTeleportAssets';
|