@subwallet/extension-base 1.0.7-2 → 1.0.8-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 +2 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -1
- package/cjs/koni/api/dotsama/transfer.js +2 -2
- 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 +5 -5
- package/cjs/services/chain-service/index.js +19 -15
- package/cjs/services/chain-service/utils.js +1 -5
- package/cjs/services/transaction-service/helpers/index.js +45 -2
- package/cjs/services/transaction-service/index.js +58 -24
- 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 +2 -1
- package/koni/api/dotsama/crowdloan.js +2 -2
- package/koni/api/dotsama/transfer.js +2 -2
- 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 +13 -8
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.js +5 -5
- 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/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/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;
|
|
@@ -296,10 +296,11 @@ async function subscribeTokensAccountsPallet(addresses, chain, api, callBack, in
|
|
|
296
296
|
const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
|
|
297
297
|
try {
|
|
298
298
|
const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
|
|
299
|
+
const assetId = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
299
300
|
|
|
300
301
|
// Get Token Balance
|
|
301
302
|
// @ts-ignore
|
|
302
|
-
return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo]), balances => {
|
|
303
|
+
return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo || assetId]), balances => {
|
|
303
304
|
const tokenBalance = {
|
|
304
305
|
reserved: (0, _utils3.sumBN)(balances.map(b => b.reserved || new _util.BN(0))),
|
|
305
306
|
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);
|
|
@@ -127,9 +127,9 @@ const createTransferExtrinsic = async _ref => {
|
|
|
127
127
|
transfer = api.tx.currencies.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), value);
|
|
128
128
|
} else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxTokensSupported) {
|
|
129
129
|
if (transferAll) {
|
|
130
|
-
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), false);
|
|
130
|
+
transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), false);
|
|
131
131
|
} else if (value) {
|
|
132
|
-
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), new _util.BN(value));
|
|
132
|
+
transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
|
|
133
133
|
}
|
|
134
134
|
} else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxEqBalancesSupported) {
|
|
135
135
|
transfer = api.tx.eqBalances.transfer([(0, _utils2._getTokenOnChainAssetId)(tokenInfo)], to, value);
|
|
@@ -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';
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _common = _interopRequireDefault(require("@ethereumjs/common"));
|
|
9
|
+
var _types = require("@subwallet/chain-list/types");
|
|
9
10
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
10
11
|
var _Extension = require("@subwallet/extension-base/background/handlers/Extension");
|
|
11
12
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
@@ -30,11 +31,12 @@ var _utils2 = require("@subwallet/extension-base/utils");
|
|
|
30
31
|
var _address2 = require("@subwallet/extension-base/utils/address");
|
|
31
32
|
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
32
33
|
var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
34
|
+
var _number = require("@subwallet/extension-base/utils/number");
|
|
33
35
|
var _keyring = require("@subwallet/keyring");
|
|
34
36
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
35
37
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
36
38
|
var _ethereumjsTx = require("ethereumjs-tx");
|
|
37
|
-
var
|
|
39
|
+
var _types2 = require("@polkadot/types");
|
|
38
40
|
var _util = require("@polkadot/util");
|
|
39
41
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
40
42
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
@@ -1447,41 +1449,57 @@ class KoniExtension {
|
|
|
1447
1449
|
|
|
1448
1450
|
// Get native token amount
|
|
1449
1451
|
const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1452
|
+
try {
|
|
1453
|
+
if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils._isTokenTransferredByEvm)(tokenInfo)) {
|
|
1454
|
+
// TODO: review this
|
|
1455
|
+
chainType = _KoniTypes.ChainType.EVM;
|
|
1456
|
+
const txVal = transferAll ? freeBalance.value : value || '0';
|
|
1457
|
+
|
|
1458
|
+
// Estimate with EVM API
|
|
1459
|
+
if ((0, _utils._isTokenEvmSmartContract)(tokenInfo) || (0, _utils._isLocalToken)(tokenInfo)) {
|
|
1460
|
+
[transaction, transferAmount.value] = await (0, _transfer3.getERC20TransactionObject)((0, _utils._getContractAddressOfToken)(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApiMap);
|
|
1461
|
+
} else {
|
|
1462
|
+
[transaction, transferAmount.value] = await (0, _transfer3.getEVMTransactionObject)(chainInfo, to, txVal, !!transferAll, evmApiMap);
|
|
1463
|
+
}
|
|
1458
1464
|
} else {
|
|
1459
|
-
|
|
1465
|
+
const substrateApi = this.#koniState.getSubstrateApi(networkKey);
|
|
1466
|
+
[transaction, transferAmount.value] = await (0, _transfer.createTransferExtrinsic)({
|
|
1467
|
+
transferAll: !!transferAll,
|
|
1468
|
+
value: value || '0',
|
|
1469
|
+
from: from,
|
|
1470
|
+
networkKey,
|
|
1471
|
+
tokenInfo,
|
|
1472
|
+
to: to,
|
|
1473
|
+
substrateApi
|
|
1474
|
+
});
|
|
1460
1475
|
}
|
|
1461
|
-
}
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
networkKey,
|
|
1468
|
-
tokenInfo,
|
|
1469
|
-
to: to,
|
|
1470
|
-
substrateApi
|
|
1471
|
-
});
|
|
1476
|
+
} catch (e) {
|
|
1477
|
+
const error = e;
|
|
1478
|
+
if (error.message.includes('transfer amount exceeds balance')) {
|
|
1479
|
+
error.message = 'Not enough balance';
|
|
1480
|
+
}
|
|
1481
|
+
throw error;
|
|
1472
1482
|
}
|
|
1473
1483
|
const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
|
|
1474
1484
|
this.addContact(to);
|
|
1475
1485
|
const additionalValidator = async inputTransaction => {
|
|
1486
|
+
const minAmount = tokenInfo.minAmount || '0';
|
|
1476
1487
|
if (!isTransferNativeToken) {
|
|
1477
1488
|
const {
|
|
1478
1489
|
value: balance
|
|
1479
1490
|
} = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
|
|
1480
|
-
const minAmount = tokenInfo.minAmount || '0';
|
|
1481
1491
|
if (new _bignumber.default(balance).minus(transferAmount.value).lt(minAmount)) {
|
|
1482
1492
|
inputTransaction.warnings.push(new _TransactionWarning.TransactionWarning(_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
|
|
1483
1493
|
}
|
|
1484
1494
|
}
|
|
1495
|
+
const {
|
|
1496
|
+
value: receiverBalance
|
|
1497
|
+
} = await this.#koniState.balanceService.getTokenFreeBalance(to, networkKey, tokenSlug);
|
|
1498
|
+
if (new _bignumber.default(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
|
|
1499
|
+
const atLeast = new _bignumber.default(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
|
|
1500
|
+
const atLeastStr = (0, _number.formatNumber)(atLeast, tokenInfo.decimals || 0, _number.balanceFormatter);
|
|
1501
|
+
inputTransaction.errors.push(new _TransactionError.TransactionError(_KoniTypes.TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, `You must transfer at least ${atLeastStr} ${tokenInfo.symbol} to keep the destination account alive`));
|
|
1502
|
+
}
|
|
1485
1503
|
};
|
|
1486
1504
|
return this.#koniState.transactionService.handleTransaction({
|
|
1487
1505
|
errors,
|
|
@@ -1495,7 +1513,7 @@ class KoniExtension {
|
|
|
1495
1513
|
extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
|
|
1496
1514
|
ignoreWarnings: transferAll,
|
|
1497
1515
|
isTransferAll: isTransferNativeToken ? transferAll : false,
|
|
1498
|
-
edAsWarning:
|
|
1516
|
+
edAsWarning: isTransferNativeToken,
|
|
1499
1517
|
additionalValidator: additionalValidator
|
|
1500
1518
|
});
|
|
1501
1519
|
}
|
|
@@ -1524,6 +1542,8 @@ class KoniExtension {
|
|
|
1524
1542
|
if (errors.length > 0) {
|
|
1525
1543
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1526
1544
|
}
|
|
1545
|
+
let additionalValidator;
|
|
1546
|
+
let eventsHandler;
|
|
1527
1547
|
if (fromKeyPair && destinationTokenInfo) {
|
|
1528
1548
|
const substrateApi = this.#koniState.getSubstrateApi(originNetworkKey);
|
|
1529
1549
|
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
@@ -1535,6 +1555,40 @@ class KoniExtension {
|
|
|
1535
1555
|
chainInfoMap,
|
|
1536
1556
|
substrateApi
|
|
1537
1557
|
});
|
|
1558
|
+
additionalValidator = async inputTransaction => {
|
|
1559
|
+
const destMinAmount = destinationTokenInfo.minAmount || '0';
|
|
1560
|
+
const atLeast = new _bignumber.default(destMinAmount).multipliedBy(_constants.XCM_MIN_AMOUNT_RATIO);
|
|
1561
|
+
if (new _bignumber.default(value).lt(atLeast)) {
|
|
1562
|
+
const atLeastStr = (0, _number.formatNumber)(atLeast, destinationTokenInfo.decimals || 0, _number.balanceFormatter);
|
|
1563
|
+
inputTransaction.errors.push(new _TransactionError.TransactionError(_KoniTypes.TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT, `You must transfer at least ${atLeastStr} ${originTokenInfo.symbol} to keep the destination account alive`));
|
|
1564
|
+
}
|
|
1565
|
+
const srcMinAmount = originTokenInfo.minAmount || '0';
|
|
1566
|
+
const isTransferNativeToken = originTokenInfo.assetType === _types._AssetType.NATIVE;
|
|
1567
|
+
if (!isTransferNativeToken) {
|
|
1568
|
+
const {
|
|
1569
|
+
value: balance
|
|
1570
|
+
} = await this.#koniState.balanceService.getTokenFreeBalance(from, originNetworkKey, originTokenInfo.slug);
|
|
1571
|
+
if (new _bignumber.default(balance).minus(value).lt(srcMinAmount)) {
|
|
1572
|
+
inputTransaction.warnings.push(new _TransactionWarning.TransactionWarning(_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
eventsHandler = eventEmitter => {
|
|
1577
|
+
eventEmitter.on('send', () => {
|
|
1578
|
+
try {
|
|
1579
|
+
const dest = _uiKeyring.keyring.getPair(to);
|
|
1580
|
+
if (dest) {
|
|
1581
|
+
this.updateAssetSetting({
|
|
1582
|
+
autoEnableNativeToken: false,
|
|
1583
|
+
tokenSlug: destinationTokenInfo.slug,
|
|
1584
|
+
assetSetting: {
|
|
1585
|
+
visible: true
|
|
1586
|
+
}
|
|
1587
|
+
}).catch(console.error);
|
|
1588
|
+
}
|
|
1589
|
+
} catch (e) {}
|
|
1590
|
+
});
|
|
1591
|
+
};
|
|
1538
1592
|
}
|
|
1539
1593
|
this.addContact(to);
|
|
1540
1594
|
return await this.#koniState.transactionService.handleTransaction({
|
|
@@ -1546,8 +1600,11 @@ class KoniExtension {
|
|
|
1546
1600
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
1547
1601
|
chainType: _KoniTypes.ChainType.SUBSTRATE,
|
|
1548
1602
|
transferNativeAmount: (0, _utils._isNativeToken)(originTokenInfo) ? value : '0',
|
|
1603
|
+
ignoreWarnings: inputData.transferAll,
|
|
1549
1604
|
isTransferAll: inputData.transferAll,
|
|
1550
|
-
errors
|
|
1605
|
+
errors,
|
|
1606
|
+
additionalValidator: additionalValidator,
|
|
1607
|
+
eventsHandler: eventsHandler
|
|
1551
1608
|
});
|
|
1552
1609
|
}
|
|
1553
1610
|
async evmNftSubmitTransaction(inputData) {
|
|
@@ -2670,7 +2727,7 @@ class KoniExtension {
|
|
|
2670
2727
|
const {
|
|
2671
2728
|
payload
|
|
2672
2729
|
} = request;
|
|
2673
|
-
const registry = new
|
|
2730
|
+
const registry = new _types2.TypeRegistry();
|
|
2674
2731
|
let isEvm = false;
|
|
2675
2732
|
if ((0, _Extension.isJsonPayload)(payload)) {
|
|
2676
2733
|
// Get the metadata for the genesisHash
|
|
@@ -2943,6 +3000,7 @@ class KoniExtension {
|
|
|
2943
3000
|
let [key, value] = _ref72;
|
|
2944
3001
|
const {
|
|
2945
3002
|
additionalValidator,
|
|
3003
|
+
eventsHandler,
|
|
2946
3004
|
transaction,
|
|
2947
3005
|
...transactionResult
|
|
2948
3006
|
} = value;
|
|
@@ -52,7 +52,7 @@ const generateDefaultCrowdloanMap = () => {
|
|
|
52
52
|
const crowdloanMap = {};
|
|
53
53
|
Object.entries(_chainList.ChainInfoMap).forEach(_ref => {
|
|
54
54
|
let [networkKey, chainInfo] = _ref;
|
|
55
|
-
if ((0, _utils.
|
|
55
|
+
if ((0, _utils._isSubstrateParaChain)(chainInfo)) {
|
|
56
56
|
crowdloanMap[networkKey] = {
|
|
57
57
|
state: _KoniTypes.APIItemState.PENDING,
|
|
58
58
|
contribute: '0'
|