@subwallet/extension-base 1.0.9-1 → 1.0.10-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 +5 -1
- package/background/types.d.ts +2 -1
- package/cjs/koni/api/dotsama/transfer.js +16 -7
- package/cjs/koni/api/staking/bonding/paraChain.js +3 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +3 -2
- package/cjs/koni/api/staking/bonding/utils.js +1 -1
- package/cjs/koni/api/xcm/polkadotXcm.js +5 -4
- package/cjs/koni/api/xcm/xTokens.js +1 -1
- package/cjs/koni/api/xcm/xcmPallet.js +1 -1
- package/cjs/koni/background/handlers/Extension.js +57 -18
- package/cjs/koni/background/handlers/State.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/helper/api-helper/spec/dataavail.js +152 -0
- package/cjs/services/chain-service/helper/api-helper/spec/index.js +2 -0
- package/cjs/services/chain-service/index.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateLedgerAccount.js +42 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/transaction-service/index.js +15 -15
- package/cjs/signers/web3/QrSigner.js +14 -6
- package/cjs/utils/eth/mergeTransactionAndSignature.js +22 -13
- package/cjs/utils/eth/parseTransaction/base.js +6 -6
- package/cjs/utils/eth/parseTransaction/index.js +4 -5
- package/cjs/utils/eth.js +14 -18
- package/koni/api/dotsama/transfer.js +16 -7
- package/koni/api/staking/bonding/paraChain.js +3 -2
- package/koni/api/staking/bonding/relayChain.js +3 -2
- package/koni/api/staking/bonding/utils.js +1 -1
- package/koni/api/xcm/polkadotXcm.js +5 -4
- package/koni/api/xcm/xTokens.js +1 -1
- package/koni/api/xcm/xcmPallet.js +1 -1
- package/koni/background/handlers/Extension.d.ts +0 -1
- package/koni/background/handlers/Extension.js +57 -18
- package/koni/background/handlers/State.js +3 -3
- package/package.json +17 -8
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/helper/api-helper/spec/dataavail.d.ts +3 -0
- package/services/chain-service/helper/api-helper/spec/dataavail.js +145 -0
- package/services/chain-service/helper/api-helper/spec/index.js +2 -0
- package/services/chain-service/index.js +1 -1
- package/services/migration-service/scripts/MigrateLedgerAccount.d.ts +4 -0
- package/services/migration-service/scripts/MigrateLedgerAccount.js +33 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/transaction-service/index.js +17 -17
- package/signers/types.d.ts +1 -1
- package/signers/web3/QrSigner.js +14 -5
- package/utils/eth/mergeTransactionAndSignature.d.ts +1 -1
- package/utils/eth/mergeTransactionAndSignature.js +20 -10
- package/utils/eth/parseTransaction/base.js +6 -6
- package/utils/eth/parseTransaction/index.js +4 -5
- package/utils/eth.d.ts +2 -3
- package/utils/eth.js +14 -17
|
@@ -21,8 +21,9 @@ var _eth = require("@subwallet/extension-base/utils/eth");
|
|
|
21
21
|
var _mergeTransactionAndSignature = require("@subwallet/extension-base/utils/eth/mergeTransactionAndSignature");
|
|
22
22
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
23
23
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
24
|
+
var _ethereumjsUtil = require("ethereumjs-util");
|
|
25
|
+
var _ethers = require("ethers");
|
|
24
26
|
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
25
|
-
var _rlp = _interopRequireDefault(require("rlp"));
|
|
26
27
|
var _rxjs = require("rxjs");
|
|
27
28
|
var _util = require("@polkadot/util");
|
|
28
29
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
@@ -46,7 +47,7 @@ class TransactionService {
|
|
|
46
47
|
return Object.values(this.transactions);
|
|
47
48
|
}
|
|
48
49
|
get processingTransactions() {
|
|
49
|
-
return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.QUEUED || t.status === _KoniTypes.ExtrinsicStatus.
|
|
50
|
+
return this.allTransactions.filter(t => t.status === _KoniTypes.ExtrinsicStatus.QUEUED || t.status === _KoniTypes.ExtrinsicStatus.SUBMITTING);
|
|
50
51
|
}
|
|
51
52
|
getTransaction(id) {
|
|
52
53
|
return this.transactions[id];
|
|
@@ -324,7 +325,7 @@ class TransactionService {
|
|
|
324
325
|
// Will be added in next step
|
|
325
326
|
blockHash: '',
|
|
326
327
|
// Will be added in next step
|
|
327
|
-
nonce: nonce
|
|
328
|
+
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
328
329
|
startBlock: startBlock || 0
|
|
329
330
|
};
|
|
330
331
|
const chainInfo = this.chainService.getChainInfoByKey(transaction.chain);
|
|
@@ -634,22 +635,21 @@ class TransactionService {
|
|
|
634
635
|
this.eventService.emit('transaction.failed', transaction);
|
|
635
636
|
}
|
|
636
637
|
generateHashPayload(chain, transaction) {
|
|
638
|
+
var _transaction$nonce;
|
|
637
639
|
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
638
640
|
const txObject = {
|
|
639
|
-
nonce: transaction.nonce
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
gasLimit: (0, _eth.anyNumberToBN)(transaction.gas).toNumber(),
|
|
641
|
+
nonce: (_transaction$nonce = transaction.nonce) !== null && _transaction$nonce !== void 0 ? _transaction$nonce : 0,
|
|
642
|
+
gasPrice: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gasPrice).toString(16)),
|
|
643
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.gas).toString(16)),
|
|
643
644
|
to: transaction.to !== undefined ? transaction.to : '',
|
|
644
|
-
value: (0, _eth.anyNumberToBN)(transaction.value).
|
|
645
|
-
data: transaction.data
|
|
645
|
+
value: (0, _ethereumjsUtil.addHexPrefix)((0, _eth.anyNumberToBN)(transaction.value).toString(16)),
|
|
646
|
+
data: transaction.data,
|
|
646
647
|
chainId: (0, _utils._getEvmChainId)(chainInfo)
|
|
647
648
|
};
|
|
648
|
-
|
|
649
|
-
const encoded = _rlp.default.encode(data);
|
|
650
|
-
return (0, _util.u8aToHex)(encoded);
|
|
649
|
+
return _ethers.ethers.Transaction.from(txObject).unsignedSerialized;
|
|
651
650
|
}
|
|
652
651
|
async signAndSendEvmTransaction(_ref6) {
|
|
652
|
+
var _payload$nonce;
|
|
653
653
|
let {
|
|
654
654
|
address,
|
|
655
655
|
chain,
|
|
@@ -707,13 +707,13 @@ class TransactionService {
|
|
|
707
707
|
payload.hashPayload = this.generateHashPayload(chain, payload);
|
|
708
708
|
const emitter = new _eventemitter.default();
|
|
709
709
|
const txObject = {
|
|
710
|
-
nonce: payload.nonce
|
|
710
|
+
nonce: (_payload$nonce = payload.nonce) !== null && _payload$nonce !== void 0 ? _payload$nonce : 0,
|
|
711
711
|
from: payload.from,
|
|
712
712
|
gasPrice: (0, _eth.anyNumberToBN)(payload.gasPrice).toNumber(),
|
|
713
713
|
gasLimit: (0, _eth.anyNumberToBN)(payload.gas).toNumber(),
|
|
714
714
|
to: payload.to !== undefined ? payload.to : '',
|
|
715
715
|
value: (0, _eth.anyNumberToBN)(payload.value).toNumber(),
|
|
716
|
-
data: payload.data
|
|
716
|
+
data: payload.data,
|
|
717
717
|
chainId: payload.chainId
|
|
718
718
|
};
|
|
719
719
|
const eventData = {
|
|
@@ -736,7 +736,7 @@ class TransactionService {
|
|
|
736
736
|
if (!isExternal) {
|
|
737
737
|
signedTransaction = payload;
|
|
738
738
|
} else {
|
|
739
|
-
const signed = (0, _mergeTransactionAndSignature.
|
|
739
|
+
const signed = (0, _mergeTransactionAndSignature.mergeTransactionAndSignature)(txObject, payload);
|
|
740
740
|
const recover = web3Api.eth.accounts.recoverTransaction(signed);
|
|
741
741
|
if (recover.toLowerCase() !== account.address.toLowerCase()) {
|
|
742
742
|
throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.UNAUTHORIZED, 'Bad signature');
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
-
var
|
|
10
|
-
var
|
|
8
|
+
var _ethereumjsUtil = require("ethereumjs-util");
|
|
9
|
+
var _ethers = require("ethers");
|
|
11
10
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
12
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
12
|
|
|
@@ -30,8 +29,17 @@ class QrSigner {
|
|
|
30
29
|
}
|
|
31
30
|
async signTransaction(tx) {
|
|
32
31
|
return new Promise((resolve, reject) => {
|
|
33
|
-
|
|
34
|
-
const
|
|
32
|
+
var _tx$nonce;
|
|
33
|
+
const txObject = {
|
|
34
|
+
nonce: (_tx$nonce = tx.nonce) !== null && _tx$nonce !== void 0 ? _tx$nonce : 0,
|
|
35
|
+
gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
|
|
36
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
|
|
37
|
+
to: tx.to !== undefined ? tx.to : '',
|
|
38
|
+
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
39
|
+
data: tx.data,
|
|
40
|
+
chainId: tx.chainId
|
|
41
|
+
};
|
|
42
|
+
const qrPayload = _ethers.ethers.Transaction.from(txObject).unsignedSerialized;
|
|
35
43
|
const resolver = result => {
|
|
36
44
|
this.#resolver();
|
|
37
45
|
resolve(result);
|
|
@@ -46,7 +54,7 @@ class QrSigner {
|
|
|
46
54
|
qrState: {
|
|
47
55
|
isQrHashed: false,
|
|
48
56
|
qrAddress: tx.from,
|
|
49
|
-
qrPayload:
|
|
57
|
+
qrPayload: qrPayload,
|
|
50
58
|
qrId: this.#id,
|
|
51
59
|
isEthereum: true
|
|
52
60
|
}
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.
|
|
8
|
-
var
|
|
9
|
-
var
|
|
6
|
+
exports.mergeTransactionAndSignature = void 0;
|
|
7
|
+
var _ethereumjsUtil = require("ethereumjs-util");
|
|
8
|
+
var _ethers = require("ethers");
|
|
10
9
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
11
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
11
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
const mergeTransactionAndSignature = (tx, _rawSignature) => {
|
|
13
|
+
const _signature = _rawSignature.slice(2);
|
|
14
|
+
const signature = {
|
|
15
|
+
r: `0x${_signature.substring(0, 64)}`,
|
|
16
|
+
s: `0x${_signature.substring(64, 128)}`,
|
|
17
|
+
v: parseInt(`0x${_signature.substring(128)}`)
|
|
18
|
+
};
|
|
19
|
+
const transaction = {
|
|
20
|
+
nonce: tx.nonce,
|
|
21
|
+
gasPrice: (0, _ethereumjsUtil.addHexPrefix)(tx.gasPrice.toString(16)),
|
|
22
|
+
gasLimit: (0, _ethereumjsUtil.addHexPrefix)(tx.gasLimit.toString(16)),
|
|
23
|
+
to: tx.to,
|
|
24
|
+
value: (0, _ethereumjsUtil.addHexPrefix)(tx.value.toString(16)),
|
|
25
|
+
data: tx.data,
|
|
26
|
+
chainId: tx.chainId,
|
|
27
|
+
signature: signature
|
|
28
|
+
};
|
|
29
|
+
return _ethers.ethers.Transaction.from(transaction).serialized;
|
|
21
30
|
};
|
|
22
|
-
exports.
|
|
31
|
+
exports.mergeTransactionAndSignature = mergeTransactionAndSignature;
|
|
@@ -129,7 +129,7 @@ class InputDataDecoder {
|
|
|
129
129
|
if (data.indexOf('0x') !== 0) {
|
|
130
130
|
data = `0x${data}`;
|
|
131
131
|
}
|
|
132
|
-
const _inputs = _ethers.ethers.
|
|
132
|
+
const _inputs = _ethers.ethers.AbiCoder.defaultAbiCoder().decode(types, data);
|
|
133
133
|
const inputs = deepRemoveUnwantedArrayProperties(_inputs);
|
|
134
134
|
return {
|
|
135
135
|
methodName,
|
|
@@ -188,11 +188,11 @@ class InputDataDecoder {
|
|
|
188
188
|
let inputs = [];
|
|
189
189
|
try {
|
|
190
190
|
// @ts-ignore
|
|
191
|
-
inputs = _ethers.ethers.
|
|
191
|
+
inputs = _ethers.ethers.AbiCoder.defaultAbiCoder().decode(types, inputsBuf);
|
|
192
192
|
} catch (err) {
|
|
193
193
|
try {
|
|
194
|
-
const ifc = new _ethers.ethers.
|
|
195
|
-
inputs = ifc.decodeFunctionData(_ethers.ethers.
|
|
194
|
+
const ifc = new _ethers.ethers.Interface([]);
|
|
195
|
+
inputs = ifc.decodeFunctionData(_ethers.ethers.FunctionFragment.from(abi), data);
|
|
196
196
|
} catch (err) {}
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -243,8 +243,8 @@ class InputDataDecoder {
|
|
|
243
243
|
}
|
|
244
244
|
const method = obj.name || null;
|
|
245
245
|
try {
|
|
246
|
-
const ifc = new _ethers.ethers.
|
|
247
|
-
const _result = ifc.decodeFunctionData(_ethers.ethers.
|
|
246
|
+
const ifc = new _ethers.ethers.Interface([]);
|
|
247
|
+
const _result = ifc.decodeFunctionData(_ethers.ethers.FunctionFragment.from(obj), data);
|
|
248
248
|
const inputs = deepRemoveUnwantedArrayProperties(_result);
|
|
249
249
|
result.method = method;
|
|
250
250
|
result.methodName = getMethodName(obj);
|
|
@@ -134,7 +134,6 @@ const parseContractInput = async (input, contractAddress, network) => {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
if (contractAddress && network) {
|
|
137
|
-
console.log('parseOnline');
|
|
138
137
|
if ((0, _utils._getEvmAbiExplorer)(network)) {
|
|
139
138
|
try {
|
|
140
139
|
const res = await _axios.default.get((0, _utils._getEvmAbiExplorer)(network), {
|
|
@@ -197,7 +196,7 @@ const parseEvmRlp = async (data, networkMap, evmApiMap) => {
|
|
|
197
196
|
data: tx.data,
|
|
198
197
|
gasPrice: new _bignumber.default(tx.gasPrice).toNumber(),
|
|
199
198
|
gas: new _bignumber.default(tx.gas).toNumber(),
|
|
200
|
-
to: tx.
|
|
199
|
+
to: tx.to,
|
|
201
200
|
value: new _bignumber.default(tx.value).toNumber(),
|
|
202
201
|
nonce: new _bignumber.default(tx.nonce).toNumber()
|
|
203
202
|
};
|
|
@@ -209,13 +208,13 @@ const parseEvmRlp = async (data, networkMap, evmApiMap) => {
|
|
|
209
208
|
return result;
|
|
210
209
|
}
|
|
211
210
|
}
|
|
212
|
-
if (tx.
|
|
213
|
-
if (await isContractAddress(tx.
|
|
211
|
+
if (tx.to && network) {
|
|
212
|
+
if (await isContractAddress(tx.to, evmApiMap[network.slug])) {
|
|
214
213
|
if ((0, _utils._getEvmAbiExplorer)(network) !== '') {
|
|
215
214
|
try {
|
|
216
215
|
const res = await _axios.default.get((0, _utils._getEvmAbiExplorer)(network), {
|
|
217
216
|
params: {
|
|
218
|
-
address: tx.
|
|
217
|
+
address: tx.to
|
|
219
218
|
},
|
|
220
219
|
timeout: 2000
|
|
221
220
|
});
|
package/cjs/utils/eth.js
CHANGED
|
@@ -4,9 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.signatureToHex = exports.
|
|
7
|
+
exports.signatureToHex = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
|
|
8
8
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
|
-
var
|
|
9
|
+
var _ethers = require("ethers");
|
|
10
10
|
var _util = require("@polkadot/util");
|
|
11
11
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -20,11 +20,11 @@ const hexToNumberString = s => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
class Transaction {
|
|
23
|
-
constructor(nonce, gasPrice, gas,
|
|
23
|
+
constructor(nonce, gasPrice, gas, to, value, data, ethereumChainId) {
|
|
24
24
|
this.nonce = hexToNumberString(nonce);
|
|
25
25
|
this.gasPrice = hexToNumberString(gasPrice);
|
|
26
26
|
this.gas = hexToNumberString(gas);
|
|
27
|
-
this.
|
|
27
|
+
this.to = to;
|
|
28
28
|
this.value = hexToNumberString(value);
|
|
29
29
|
this.data = data || '';
|
|
30
30
|
this.ethereumChainId = parseInt(ethereumChainId, 16).toString();
|
|
@@ -42,22 +42,18 @@ const anyNumberToBN = value => {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
exports.anyNumberToBN = anyNumberToBN;
|
|
45
|
-
const rlpItem = (rlp, position) => {
|
|
46
|
-
const decodeArr = _rlp.default.decode(rlp);
|
|
47
|
-
const u8a = decodeArr[position] || [0];
|
|
48
|
-
return (0, _util.u8aToHex)(u8a);
|
|
49
|
-
};
|
|
50
|
-
exports.rlpItem = rlpItem;
|
|
51
45
|
const createTransactionFromRLP = rlp => {
|
|
52
46
|
try {
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
47
|
+
var _transaction$gasPrice;
|
|
48
|
+
const transaction = _ethers.ethers.Transaction.from(rlp);
|
|
49
|
+
const nonce = transaction.nonce.toString(16);
|
|
50
|
+
const gasPrice = ((_transaction$gasPrice = transaction.gasPrice) === null || _transaction$gasPrice === void 0 ? void 0 : _transaction$gasPrice.toString(16)) || '';
|
|
51
|
+
const gas = transaction.gasLimit.toString(16);
|
|
52
|
+
const to = transaction.to || '';
|
|
53
|
+
const value = transaction.value.toString(16);
|
|
54
|
+
const data = transaction.data;
|
|
55
|
+
const ethereumChainId = transaction.chainId.toString(16);
|
|
56
|
+
return new Transaction(nonce, gasPrice, gas, to, value, data, ethereumChainId);
|
|
61
57
|
} catch (e) {
|
|
62
58
|
console.log(e.message);
|
|
63
59
|
return null;
|
|
@@ -67,9 +67,11 @@ export async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMa
|
|
|
67
67
|
} else if (_TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !_isNativeToken(tokenInfo) && isTxTokensSupported) {
|
|
68
68
|
result.supportTransfer = true;
|
|
69
69
|
result.supportTransferAll = true;
|
|
70
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
71
|
+
// && !_isNativeToken(tokenInfo) && isTxEqBalancesSupported
|
|
72
|
+
) {
|
|
73
|
+
result.supportTransfer = false;
|
|
74
|
+
result.supportTransferAll = false;
|
|
73
75
|
} else if (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) && _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol)) {
|
|
74
76
|
result.supportTransfer = true;
|
|
75
77
|
result.supportTransferAll = true;
|
|
@@ -88,8 +90,10 @@ export async function checkSupportTransfer(networkKey, tokenInfo, substrateApiMa
|
|
|
88
90
|
// } else if (_TRANSFER_CHAIN_GROUP.riochain.includes(networkKey) && _isNativeToken(tokenInfo)) {
|
|
89
91
|
// result.supportTransfer = true;
|
|
90
92
|
// result.supportTransferAll = true;
|
|
93
|
+
} else if (_TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
94
|
+
result.supportTransfer = false;
|
|
95
|
+
result.supportTransferAll = false;
|
|
91
96
|
}
|
|
92
|
-
|
|
93
97
|
return result;
|
|
94
98
|
}
|
|
95
99
|
export const createTransferExtrinsic = async ({
|
|
@@ -108,7 +112,7 @@ export const createTransferExtrinsic = async ({
|
|
|
108
112
|
const isTxCurrenciesSupported = !!api && !!api.tx && !!api.tx.currencies;
|
|
109
113
|
const isTxBalancesSupported = !!api && !!api.tx && !!api.tx.balances;
|
|
110
114
|
const isTxTokensSupported = !!api && !!api.tx && !!api.tx.tokens;
|
|
111
|
-
const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
115
|
+
// const isTxEqBalancesSupported = !!api && !!api.tx && !!api.tx.eqBalances;
|
|
112
116
|
const isTxAssetsSupported = !!api && !!api.tx && !!api.tx.assets;
|
|
113
117
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
114
118
|
|
|
@@ -130,8 +134,11 @@ export const createTransferExtrinsic = async ({
|
|
|
130
134
|
} else if (value) {
|
|
131
135
|
transfer = api.tx.tokens.transfer(to, _getTokenOnChainInfo(tokenInfo) || _getTokenOnChainAssetId(tokenInfo), new BN(value));
|
|
132
136
|
}
|
|
133
|
-
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
134
|
-
|
|
137
|
+
} else if (_TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey)
|
|
138
|
+
// && isTxEqBalancesSupported
|
|
139
|
+
) {
|
|
140
|
+
// transfer = api.tx.eqBalances.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
141
|
+
/* empty */
|
|
135
142
|
} else if (!_isNativeToken(tokenInfo) && (_TRANSFER_CHAIN_GROUP.crab.includes(networkKey) || _BALANCE_TOKEN_GROUP.crab.includes(tokenInfo.symbol))) {
|
|
136
143
|
if (transferAll) {
|
|
137
144
|
transfer = api.tx.kton.transferAll(to, false);
|
|
@@ -148,6 +155,8 @@ export const createTransferExtrinsic = async ({
|
|
|
148
155
|
// }
|
|
149
156
|
} else if (_TRANSFER_CHAIN_GROUP.sora_substrate.includes(networkKey) && isTxAssetsSupported) {
|
|
150
157
|
transfer = api.tx.assets.transfer(_getTokenOnChainAssetId(tokenInfo), to, value);
|
|
158
|
+
} else if (_TRANSFER_CHAIN_GROUP.avail.includes(networkKey)) {
|
|
159
|
+
/* empty */
|
|
151
160
|
} else if (isTxBalancesSupported && _isNativeToken(tokenInfo)) {
|
|
152
161
|
if (transferAll) {
|
|
153
162
|
transfer = api.tx.balances.transferAll(to, false);
|
|
@@ -147,10 +147,11 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
147
147
|
const roundInfo = _roundInfo.toPrimitive();
|
|
148
148
|
const currentRound = roundInfo.current;
|
|
149
149
|
await Promise.all(delegatorState.delegations.map(async delegation => {
|
|
150
|
-
|
|
150
|
+
var _substrateApi$api$que;
|
|
151
|
+
const [_delegationScheduledRequests, _identity, _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), (_substrateApi$api$que = substrateApi.api.query.identity) === null || _substrateApi$api$que === void 0 ? void 0 : _substrateApi$api$que.identityOf(delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
|
|
151
152
|
const collatorInfo = _collatorInfo.toPrimitive();
|
|
152
153
|
const minDelegation = collatorInfo === null || collatorInfo === void 0 ? void 0 : collatorInfo.lowestTopDelegationAmount.toString();
|
|
153
|
-
const identityInfo = _identity.toHuman();
|
|
154
|
+
const identityInfo = _identity === null || _identity === void 0 ? void 0 : _identity.toHuman();
|
|
154
155
|
const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
|
|
155
156
|
const identity = parseIdentity(identityInfo);
|
|
156
157
|
let hasUnstaking = false;
|
|
@@ -171,10 +171,11 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
171
171
|
if (nominations) {
|
|
172
172
|
const validatorList = nominations.targets;
|
|
173
173
|
await Promise.all(validatorList.map(async validatorAddress => {
|
|
174
|
+
var _chainApi$api$query$i;
|
|
174
175
|
let nominationStatus = StakingStatus.NOT_EARNING;
|
|
175
|
-
const [_identityInfo, _eraStaker] = await Promise.all([chainApi.api.query.identity.identityOf(validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
176
|
+
const [_identityInfo, _eraStaker] = await Promise.all([(_chainApi$api$query$i = chainApi.api.query.identity) === null || _chainApi$api$query$i === void 0 ? void 0 : _chainApi$api$query$i.identityOf(validatorAddress), chainApi.api.query.staking.erasStakers(currentEra, validatorAddress)]);
|
|
176
177
|
const eraStaker = _eraStaker.toPrimitive();
|
|
177
|
-
const identityInfo = _identityInfo.toHuman();
|
|
178
|
+
const identityInfo = _identityInfo === null || _identityInfo === void 0 ? void 0 : _identityInfo.toHuman();
|
|
178
179
|
const identity = parseIdentity(identityInfo);
|
|
179
180
|
const topNominators = eraStaker.others.map(nominator => {
|
|
180
181
|
return nominator.who;
|
|
@@ -26,7 +26,7 @@ export function transformPoolName(input) {
|
|
|
26
26
|
}
|
|
27
27
|
export function parseIdentity(identityInfo) {
|
|
28
28
|
let identity;
|
|
29
|
-
if (identityInfo
|
|
29
|
+
if (identityInfo) {
|
|
30
30
|
var _identityInfo$info, _identityInfo$info$di, _identityInfo$info2, _identityInfo$info2$w, _identityInfo$info3, _identityInfo$info3$r, _identityInfo$info4, _identityInfo$info4$t;
|
|
31
31
|
const displayName = identityInfo === null || identityInfo === void 0 ? void 0 : (_identityInfo$info = identityInfo.info) === null || _identityInfo$info === void 0 ? void 0 : (_identityInfo$info$di = _identityInfo$info.display) === null || _identityInfo$info$di === void 0 ? void 0 : _identityInfo$info$di.Raw;
|
|
32
32
|
const web = identityInfo === null || identityInfo === void 0 ? void 0 : (_identityInfo$info2 = identityInfo.info) === null || _identityInfo$info2 === void 0 ? void 0 : (_identityInfo$info2$w = _identityInfo$info2.web) === null || _identityInfo$info2$w === void 0 ? void 0 : _identityInfo$info2$w.Raw;
|
|
@@ -5,15 +5,16 @@ import { getBeneficiary, getDestinationChainLocation, getDestWeight, getTokenLoc
|
|
|
5
5
|
import { _isNativeToken, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
7
|
const weightParam = getDestWeight();
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const version = ['statemint', 'statemine', 'shiden'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
9
|
+
const beneficiary = getBeneficiary(destinationChainInfo, recipientAddress, version);
|
|
10
|
+
const destination = getDestinationChainLocation(originChainInfo, destinationChainInfo, version);
|
|
11
|
+
let assetLocation = getTokenLocation(tokenInfo, value, version);
|
|
11
12
|
let method = 'limitedReserveTransferAssets';
|
|
12
13
|
if (['astar', 'shiden'].includes(originChainInfo.slug) && !_isNativeToken(tokenInfo)) {
|
|
13
14
|
method = 'limitedReserveWithdrawAssets';
|
|
14
15
|
} else if (['statemint', 'statemine'].includes(originChainInfo.slug) && _isSubstrateRelayChain(destinationChainInfo)) {
|
|
15
16
|
assetLocation = {
|
|
16
|
-
|
|
17
|
+
[version]: [{
|
|
17
18
|
id: {
|
|
18
19
|
Concrete: {
|
|
19
20
|
parents: 1,
|
package/koni/api/xcm/xTokens.js
CHANGED
|
@@ -19,6 +19,6 @@ function getCurrencyId(tokenInfo) {
|
|
|
19
19
|
}
|
|
20
20
|
export function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
21
21
|
const weightParam = ['pioneer', 'hydradx_main'].includes(originChainInfo.slug) ? FOUR_INSTRUCTIONS_WEIGHT : getDestWeight();
|
|
22
|
-
const destVersion = ['moonbeam', 'moonriver'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
22
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
23
23
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getDestMultilocation(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
24
24
|
}
|
|
@@ -5,7 +5,7 @@ import { getBeneficiary, getDestinationChainLocation, getDestWeight, getTokenLoc
|
|
|
5
5
|
// this pallet is only used by Relaychains
|
|
6
6
|
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
7
7
|
const weightParam = getDestWeight();
|
|
8
|
-
const xcmVer =
|
|
8
|
+
const xcmVer = 'V3';
|
|
9
9
|
const destination = getDestinationChainLocation(originChainInfo, destinationChainInfo, xcmVer);
|
|
10
10
|
const beneficiary = getBeneficiary(destinationChainInfo, recipientAddress, xcmVer);
|
|
11
11
|
const tokenLocation = getTokenLocation(tokenInfo, value, xcmVer);
|
|
@@ -1343,14 +1343,18 @@ export default class KoniExtension {
|
|
|
1343
1343
|
});
|
|
1344
1344
|
return historySubject.getValue();
|
|
1345
1345
|
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1346
|
+
|
|
1347
|
+
// Save address to contact
|
|
1348
|
+
// private addContact (to: string) {
|
|
1349
|
+
// const toAddress = reformatAddress(to);
|
|
1350
|
+
// const account = keyring.getAccount(toAddress);
|
|
1351
|
+
// const contact = keyring.getAddress(toAddress);
|
|
1352
|
+
//
|
|
1353
|
+
// if (!account && (!contact || contact.meta.isRecent)) {
|
|
1354
|
+
// keyring.saveAddress(toAddress, {});
|
|
1355
|
+
// }
|
|
1356
|
+
// }
|
|
1357
|
+
|
|
1354
1358
|
validateTransfer(tokenSlug, from, to, value, transferAll) {
|
|
1355
1359
|
const errors = [];
|
|
1356
1360
|
const keypair = keyring.getPair(from);
|
|
@@ -1433,7 +1437,9 @@ export default class KoniExtension {
|
|
|
1433
1437
|
throw error;
|
|
1434
1438
|
}
|
|
1435
1439
|
const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
|
|
1436
|
-
|
|
1440
|
+
|
|
1441
|
+
// this.addContact(to);
|
|
1442
|
+
|
|
1437
1443
|
const additionalValidator = async inputTransaction => {
|
|
1438
1444
|
const minAmount = tokenInfo.minAmount || '0';
|
|
1439
1445
|
if (!isTransferNativeToken) {
|
|
@@ -1542,7 +1548,9 @@ export default class KoniExtension {
|
|
|
1542
1548
|
});
|
|
1543
1549
|
};
|
|
1544
1550
|
}
|
|
1545
|
-
|
|
1551
|
+
|
|
1552
|
+
// this.addContact(to);
|
|
1553
|
+
|
|
1546
1554
|
return await this.#koniState.transactionService.handleTransaction({
|
|
1547
1555
|
url: EXTENSION_REQUEST_URL,
|
|
1548
1556
|
address: from,
|
|
@@ -1569,7 +1577,9 @@ export default class KoniExtension {
|
|
|
1569
1577
|
const contractAddress = params.contractAddress;
|
|
1570
1578
|
const tokenId = params.tokenId;
|
|
1571
1579
|
const transaction = await getERC721Transaction(this.#koniState.getEvmApi(networkKey), contractAddress, senderAddress, recipientAddress, tokenId);
|
|
1572
|
-
|
|
1580
|
+
|
|
1581
|
+
// this.addContact(recipientAddress);
|
|
1582
|
+
|
|
1573
1583
|
return await this.#koniState.transactionService.handleTransaction({
|
|
1574
1584
|
address: senderAddress,
|
|
1575
1585
|
chain: networkKey,
|
|
@@ -1688,7 +1698,7 @@ export default class KoniExtension {
|
|
|
1688
1698
|
}
|
|
1689
1699
|
} else {
|
|
1690
1700
|
const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
|
|
1691
|
-
if (_isChainEvmCompatible(chainInfo)) {
|
|
1701
|
+
if (_isChainEvmCompatible(chainInfo) && _isTokenTransferredByEvm(tokenInfo)) {
|
|
1692
1702
|
const web3 = this.#koniState.chainService.getEvmApi(networkKey);
|
|
1693
1703
|
const transaction = {
|
|
1694
1704
|
value: 0,
|
|
@@ -1771,7 +1781,9 @@ export default class KoniExtension {
|
|
|
1771
1781
|
const networkKey = params === null || params === void 0 ? void 0 : params.networkKey;
|
|
1772
1782
|
const apiProps = this.#koniState.getSubstrateApi(networkKey);
|
|
1773
1783
|
const extrinsic = !isPSP34 ? getNftTransferExtrinsic(networkKey, apiProps, senderAddress, recipientAddress, params || {}) : await getPSP34TransferExtrinsic(networkKey, apiProps, senderAddress, recipientAddress, params || {});
|
|
1774
|
-
|
|
1784
|
+
|
|
1785
|
+
// this.addContact(recipientAddress);
|
|
1786
|
+
|
|
1775
1787
|
const rs = await this.#koniState.transactionService.handleTransaction({
|
|
1776
1788
|
address: senderAddress,
|
|
1777
1789
|
chain: networkKey,
|
|
@@ -1921,6 +1933,7 @@ export default class KoniExtension {
|
|
|
1921
1933
|
if (!accounts.length) {
|
|
1922
1934
|
throw new Error('No accounts to import');
|
|
1923
1935
|
}
|
|
1936
|
+
const slugMap = {};
|
|
1924
1937
|
for (const account of accounts) {
|
|
1925
1938
|
const {
|
|
1926
1939
|
accountIndex,
|
|
@@ -1928,16 +1941,36 @@ export default class KoniExtension {
|
|
|
1928
1941
|
addressOffset,
|
|
1929
1942
|
genesisHash,
|
|
1930
1943
|
hardwareType,
|
|
1944
|
+
isEthereum,
|
|
1931
1945
|
name
|
|
1932
1946
|
} = account;
|
|
1933
|
-
|
|
1947
|
+
let result;
|
|
1948
|
+
const baseMeta = {
|
|
1949
|
+
name,
|
|
1950
|
+
hardwareType,
|
|
1934
1951
|
accountIndex,
|
|
1935
1952
|
addressOffset,
|
|
1936
1953
|
genesisHash,
|
|
1937
|
-
name,
|
|
1938
1954
|
originGenesisHash: genesisHash
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1955
|
+
};
|
|
1956
|
+
if (isEthereum) {
|
|
1957
|
+
result = keyring.keyring.addFromAddress(address, {
|
|
1958
|
+
...baseMeta,
|
|
1959
|
+
isExternal: true,
|
|
1960
|
+
isHardware: true
|
|
1961
|
+
}, null, 'ethereum');
|
|
1962
|
+
keyring.saveAccount(result);
|
|
1963
|
+
slugMap.ethereum = 'ethereum';
|
|
1964
|
+
} else {
|
|
1965
|
+
result = keyring.addHardware(address, hardwareType, {
|
|
1966
|
+
...baseMeta,
|
|
1967
|
+
availableGenesisHashes: [genesisHash]
|
|
1968
|
+
}).pair;
|
|
1969
|
+
const [slug] = this.#koniState.findNetworkKeyByGenesisHash(genesisHash);
|
|
1970
|
+
if (slug) {
|
|
1971
|
+
slugMap[slug] = slug;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1941
1974
|
const _address = result.address;
|
|
1942
1975
|
addresses.push(_address);
|
|
1943
1976
|
await new Promise(resolve => {
|
|
@@ -1965,6 +1998,12 @@ export default class KoniExtension {
|
|
|
1965
1998
|
resolve();
|
|
1966
1999
|
});
|
|
1967
2000
|
});
|
|
2001
|
+
if (Object.keys(slugMap).length) {
|
|
2002
|
+
this.enableChains({
|
|
2003
|
+
chainSlugs: Object.keys(slugMap),
|
|
2004
|
+
enableTokens: true
|
|
2005
|
+
}).catch(console.error);
|
|
2006
|
+
}
|
|
1968
2007
|
return true;
|
|
1969
2008
|
}
|
|
1970
2009
|
async accountsCreateWithSecret({
|
|
@@ -2186,7 +2225,7 @@ export default class KoniExtension {
|
|
|
2186
2225
|
}
|
|
2187
2226
|
const txObject = {
|
|
2188
2227
|
gasPrice: new BigN(tx.gasPrice).toNumber(),
|
|
2189
|
-
to: tx.
|
|
2228
|
+
to: tx.to,
|
|
2190
2229
|
value: new BigN(tx.value).toNumber(),
|
|
2191
2230
|
data: tx.data,
|
|
2192
2231
|
nonce: new BigN(tx.nonce).toNumber(),
|
|
@@ -1127,12 +1127,12 @@ export default class KoniState {
|
|
|
1127
1127
|
address: pair.address,
|
|
1128
1128
|
...pair.meta
|
|
1129
1129
|
};
|
|
1130
|
-
let
|
|
1130
|
+
let hashPayload = '';
|
|
1131
1131
|
let canSign = false;
|
|
1132
1132
|
switch (method) {
|
|
1133
1133
|
case 'personal_sign':
|
|
1134
1134
|
canSign = true;
|
|
1135
|
-
|
|
1135
|
+
hashPayload = payload;
|
|
1136
1136
|
break;
|
|
1137
1137
|
case 'eth_sign':
|
|
1138
1138
|
case 'eth_signTypedData':
|
|
@@ -1150,7 +1150,7 @@ export default class KoniState {
|
|
|
1150
1150
|
account: account,
|
|
1151
1151
|
type: method,
|
|
1152
1152
|
payload: payload,
|
|
1153
|
-
hashPayload:
|
|
1153
|
+
hashPayload: hashPayload,
|
|
1154
1154
|
canSign: canSign,
|
|
1155
1155
|
id
|
|
1156
1156
|
};
|