@subwallet/extension-base 1.1.24-0 → 1.1.24-2

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.
Files changed (99) hide show
  1. package/background/KoniTypes.d.ts +2 -25
  2. package/cjs/constants/index.js +9 -3
  3. package/cjs/koni/api/staking/bonding/amplitude.js +6 -4
  4. package/cjs/koni/api/staking/bonding/astar.js +4 -0
  5. package/cjs/koni/api/staking/bonding/index.js +5 -0
  6. package/cjs/koni/api/staking/bonding/paraChain.js +9 -20
  7. package/cjs/koni/api/staking/bonding/relayChain.js +41 -23
  8. package/cjs/koni/api/staking/bonding/utils.js +67 -16
  9. package/cjs/koni/api/tokens/evm/balance.js +5 -1
  10. package/cjs/koni/api/tokens/evm/transfer.js +8 -4
  11. package/cjs/koni/background/cron.js +2 -2
  12. package/cjs/koni/background/handlers/Extension.js +5 -5
  13. package/cjs/koni/background/handlers/Mobile.js +1 -1
  14. package/cjs/koni/background/handlers/State.js +123 -44
  15. package/cjs/koni/background/subscription.js +2 -2
  16. package/cjs/packageInfo.js +1 -1
  17. package/cjs/services/balance-service/helpers/group.js +53 -0
  18. package/cjs/services/balance-service/helpers/subscribe/balance.js +111 -0
  19. package/cjs/services/balance-service/helpers/subscribe/evm.js +95 -0
  20. package/cjs/services/balance-service/helpers/subscribe/substrate/equilibrium.js +113 -0
  21. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +324 -0
  22. package/cjs/services/balance-service/index.js +41 -16
  23. package/cjs/services/chain-service/constants.js +4 -3
  24. package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  25. package/cjs/services/history-service/index.js +12 -8
  26. package/cjs/services/migration-service/scripts/MigrateProvider.js +1 -1
  27. package/cjs/services/storage-service/DatabaseService.js +7 -2
  28. package/cjs/services/storage-service/db-stores/Balance.js +9 -9
  29. package/cjs/services/subscan-service/index.js +66 -22
  30. package/cjs/services/transaction-service/index.js +4 -3
  31. package/cjs/types/balance.js +1 -0
  32. package/cjs/types/index.js +11 -0
  33. package/cjs/utils/{address.js → account.js} +32 -2
  34. package/cjs/utils/eth.js +7 -2
  35. package/cjs/utils/index.js +12 -0
  36. package/constants/index.d.ts +2 -0
  37. package/constants/index.js +2 -0
  38. package/koni/api/staking/bonding/amplitude.d.ts +3 -0
  39. package/koni/api/staking/bonding/amplitude.js +6 -4
  40. package/koni/api/staking/bonding/astar.d.ts +3 -0
  41. package/koni/api/staking/bonding/astar.js +4 -0
  42. package/koni/api/staking/bonding/index.d.ts +3 -0
  43. package/koni/api/staking/bonding/index.js +5 -0
  44. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  45. package/koni/api/staking/bonding/paraChain.js +9 -20
  46. package/koni/api/staking/bonding/relayChain.d.ts +3 -0
  47. package/koni/api/staking/bonding/relayChain.js +41 -24
  48. package/koni/api/staking/bonding/utils.d.ts +15 -2
  49. package/koni/api/staking/bonding/utils.js +69 -18
  50. package/koni/api/tokens/evm/balance.js +5 -1
  51. package/koni/api/tokens/evm/transfer.d.ts +1 -1
  52. package/koni/api/tokens/evm/transfer.js +8 -4
  53. package/koni/background/cron.js +3 -3
  54. package/koni/background/handlers/Extension.js +5 -5
  55. package/koni/background/handlers/Mobile.js +1 -1
  56. package/koni/background/handlers/State.d.ts +6 -4
  57. package/koni/background/handlers/State.js +111 -33
  58. package/koni/background/subscription.js +2 -2
  59. package/package.json +40 -15
  60. package/packageInfo.js +1 -1
  61. package/services/balance-service/helpers/group.d.ts +9 -0
  62. package/services/balance-service/helpers/group.js +46 -0
  63. package/services/balance-service/helpers/subscribe/balance.d.ts +4 -0
  64. package/services/balance-service/helpers/subscribe/balance.js +103 -0
  65. package/services/balance-service/helpers/subscribe/evm.d.ts +5 -0
  66. package/services/balance-service/helpers/subscribe/evm.js +87 -0
  67. package/services/balance-service/helpers/subscribe/substrate/equilibrium.d.ts +4 -0
  68. package/services/balance-service/helpers/subscribe/substrate/equilibrium.js +105 -0
  69. package/services/balance-service/helpers/subscribe/substrate/index.d.ts +4 -0
  70. package/services/balance-service/helpers/subscribe/substrate/index.js +316 -0
  71. package/services/balance-service/index.d.ts +24 -5
  72. package/services/balance-service/index.js +40 -14
  73. package/services/chain-service/constants.js +4 -3
  74. package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +7 -1
  75. package/services/history-service/index.js +12 -8
  76. package/services/migration-service/scripts/MigrateProvider.js +1 -1
  77. package/services/storage-service/DatabaseService.d.ts +4 -2
  78. package/services/storage-service/DatabaseService.js +7 -2
  79. package/services/storage-service/databases/index.d.ts +2 -1
  80. package/services/storage-service/db-stores/Balance.d.ts +2 -2
  81. package/services/storage-service/db-stores/Balance.js +9 -9
  82. package/services/subscan-service/index.d.ts +11 -5
  83. package/services/subscan-service/index.js +66 -26
  84. package/services/subscan-service/types.d.ts +4 -0
  85. package/services/transaction-service/index.js +5 -4
  86. package/types/balance.d.ts +40 -0
  87. package/types/balance.js +1 -0
  88. package/types/index.d.ts +1 -0
  89. package/types/index.js +1 -0
  90. package/utils/account.d.ts +15 -0
  91. package/utils/{address.js → account.js} +28 -0
  92. package/utils/eth.d.ts +1 -0
  93. package/utils/eth.js +4 -0
  94. package/utils/index.d.ts +1 -0
  95. package/utils/index.js +1 -0
  96. package/cjs/koni/api/dotsama/balance.js +0 -464
  97. package/koni/api/dotsama/balance.d.ts +0 -6
  98. package/koni/api/dotsama/balance.js +0 -451
  99. package/utils/address.d.ts +0 -5
@@ -65,14 +65,19 @@ class DatabaseService {
65
65
  async getStoredBalance() {
66
66
  return this.stores.balance.table.toArray();
67
67
  }
68
- async updateBalanceStore(address, item) {
68
+ async updateBalanceStore(item) {
69
69
  if (item.state === _KoniTypes.APIItemState.READY) {
70
70
  return this.stores.balance.upsert({
71
- address,
72
71
  ...item
73
72
  });
74
73
  }
75
74
  }
75
+ async updateBulkBalanceStore(items) {
76
+ const filtered = items.filter(item => item.state !== _KoniTypes.APIItemState.PENDING);
77
+ if (filtered.length) {
78
+ return this.stores.balance.bulkUpsert(filtered);
79
+ }
80
+ }
76
81
  async removeFromBalanceStore(assets) {
77
82
  return this.stores.balance.removeBySlugs(assets);
78
83
  }
@@ -10,17 +10,17 @@ var _BaseStoreWithAddress = _interopRequireDefault(require("../db-stores/BaseSto
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
12
12
  class BalanceStore extends _BaseStoreWithAddress.default {
13
- async getBalanceMapByAddress(address) {
14
- const data = await this.table.where('address').equals(address).toArray();
13
+ async getBalanceMapByAddresses(addresses) {
14
+ const data = await this.table.where('address').anyOf(addresses).toArray();
15
15
  const balanceMap = {};
16
16
  data.forEach(storedBalance => {
17
- balanceMap[storedBalance.tokenSlug] = {
18
- tokenSlug: storedBalance.tokenSlug,
19
- state: storedBalance.state,
20
- free: storedBalance.free,
21
- locked: storedBalance.locked,
22
- substrateInfo: storedBalance.substrateInfo,
23
- timestamp: storedBalance.timestamp
17
+ const address = storedBalance.address;
18
+ const slug = storedBalance.tokenSlug;
19
+ if (!balanceMap[address]) {
20
+ balanceMap[address] = {};
21
+ }
22
+ balanceMap[address][slug] = {
23
+ ...storedBalance
24
24
  };
25
25
  });
26
26
  return balanceMap;
@@ -129,11 +129,19 @@ class SubscanService {
129
129
  }
130
130
  getExtrinsicsList(chain, address) {
131
131
  let page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
132
+ let blockRange = arguments.length > 3 ? arguments[3] : undefined;
133
+ const _blockRange = (() => {
134
+ if (!blockRange || !blockRange.to) {
135
+ return null;
136
+ }
137
+ return `${blockRange.from || 0}-${blockRange.to}`;
138
+ })();
132
139
  return this.addRequest(async () => {
133
140
  const rs = await this.postRequest(this.getApiUrl(chain, 'api/scan/extrinsics'), {
134
141
  page,
135
142
  row: QUERY_ROW,
136
- address
143
+ address,
144
+ block_range: _blockRange
137
145
  });
138
146
  if (rs.status !== 200) {
139
147
  throw new _SWError.SWError('SubscanService.getExtrinsicsList', await rs.text());
@@ -143,22 +151,38 @@ class SubscanService {
143
151
  });
144
152
  }
145
153
  async fetchAllPossibleExtrinsicItems(chain, address, cbAfterEachRequest) {
146
- let count = 0;
154
+ let limit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
155
+ page: 10,
156
+ record: 1000
157
+ };
158
+ let maxCount = 0;
159
+ let currentCount = 0;
160
+ const blockRange = {
161
+ from: null,
162
+ to: null
163
+ };
147
164
  const resultMap = {};
148
165
  const _getExtrinsicItems = async page => {
149
- const res = await this.getExtrinsicsList(chain, address, page);
166
+ const res = await this.getExtrinsicsList(chain, address, page, blockRange);
150
167
  if (!res || !res.count || !res.extrinsics || !res.extrinsics.length) {
151
168
  return;
152
169
  }
153
- if (res.count > count) {
154
- count = res.count;
170
+ if (res.count > maxCount) {
171
+ maxCount = res.count;
155
172
  }
156
173
  cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.extrinsics);
157
174
  res.extrinsics.forEach(item => {
158
175
  resultMap[item.extrinsic_hash] = item;
159
176
  });
160
- if (Object.values(resultMap).length < count) {
177
+ currentCount += res.extrinsics.length;
178
+ if (page > limit.page || currentCount > limit.record) {
179
+ return;
180
+ }
181
+ if (currentCount < maxCount) {
161
182
  await (0, _utils.wait)(100);
183
+ if (page === 0) {
184
+ blockRange.to = res.extrinsics[0].block_num;
185
+ }
162
186
  await _getExtrinsicItems(++page);
163
187
  }
164
188
  };
@@ -168,16 +192,16 @@ class SubscanService {
168
192
  getTransfersList(chain, address) {
169
193
  let page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
170
194
  let direction = arguments.length > 3 ? arguments[3] : undefined;
171
- const requestBody = {
172
- page,
173
- row: QUERY_ROW,
174
- address
175
- };
176
- if (direction) {
177
- requestBody.direction = direction;
178
- }
195
+ let blockRange = arguments.length > 4 ? arguments[4] : undefined;
179
196
  return this.addRequest(async () => {
180
- const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'), requestBody);
197
+ const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/transfers'), {
198
+ page,
199
+ row: QUERY_ROW,
200
+ address,
201
+ direction: direction || null,
202
+ from_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.from) || null,
203
+ to_block: (blockRange === null || blockRange === void 0 ? void 0 : blockRange.to) || null
204
+ });
181
205
  if (rs.status !== 200) {
182
206
  throw new _SWError.SWError('SubscanService.getTransfersList', await rs.text());
183
207
  }
@@ -186,27 +210,47 @@ class SubscanService {
186
210
  });
187
211
  }
188
212
  async fetchAllPossibleTransferItems(chain, address, direction, cbAfterEachRequest) {
189
- let count = 0;
213
+ let limit = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {
214
+ page: 10,
215
+ record: 1000
216
+ };
217
+ let maxCount = 0;
218
+ let currentCount = 0;
219
+ const blockRange = {
220
+ from: null,
221
+ to: null
222
+ };
190
223
  const resultMap = {};
191
224
  const _getTransferItems = async page => {
192
- const res = await this.getTransfersList(chain, address, page, direction);
225
+ const res = await this.getTransfersList(chain, address, page, direction, blockRange);
193
226
  if (!res || !res.count || !res.transfers || !res.transfers.length) {
194
227
  return;
195
228
  }
196
- if (res.count > count) {
197
- count = res.count;
229
+ if (res.count > maxCount) {
230
+ maxCount = res.count;
198
231
  }
199
232
  cbAfterEachRequest === null || cbAfterEachRequest === void 0 ? void 0 : cbAfterEachRequest(res.transfers);
200
233
  res.transfers.forEach(item => {
201
- resultMap[item.hash] = item;
234
+ if (!resultMap[item.hash]) {
235
+ resultMap[item.hash] = [item];
236
+ } else {
237
+ resultMap[item.hash].push(item);
238
+ }
202
239
  });
203
- if (Object.values(resultMap).length < count) {
240
+ currentCount += res.transfers.length;
241
+ if (page > limit.page || currentCount > limit.record) {
242
+ return;
243
+ }
244
+ if (currentCount < maxCount) {
204
245
  await (0, _utils.wait)(100);
246
+ if (page === 0) {
247
+ blockRange.to = res.transfers[0].block_num;
248
+ }
205
249
  await _getTransferItems(++page);
206
250
  }
207
251
  };
208
252
  await _getTransferItems(0);
209
- return Object.values(resultMap);
253
+ return resultMap;
210
254
  }
211
255
  }
212
256
  exports.SubscanService = SubscanService;
@@ -121,7 +121,8 @@ class TransactionService {
121
121
  if (!web3) {
122
122
  validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.CHAIN_DISCONNECTED, undefined));
123
123
  } else {
124
- const gasPrice = await web3.api.eth.getGasPrice();
124
+ const _price = await web3.api.eth.getGasPrice();
125
+ const gasPrice = (0, _eth.recalculateGasPrice)(_price, chainInfo.slug);
125
126
  const gasLimit = await web3.api.eth.estimateGas(transaction);
126
127
  estimateFee.value = (gasLimit * parseInt(gasPrice)).toString();
127
128
  }
@@ -932,8 +933,8 @@ class TransactionService {
932
933
  }).forEach(_ref11 => {
933
934
  let {
934
935
  event: {
935
- method,
936
- data: [error]
936
+ data: [error],
937
+ method
937
938
  }
938
939
  } = _ref11;
939
940
  if (method === 'ExtrinsicFailed') {
@@ -0,0 +1 @@
1
+ "use strict";
@@ -3,6 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _balance = require("./balance");
7
+ Object.keys(_balance).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _balance[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _balance[key];
14
+ }
15
+ });
16
+ });
6
17
  var _buy = require("./buy");
7
18
  Object.keys(_buy).forEach(function (key) {
8
19
  if (key === "default" || key === "__esModule") return;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.convertSubjectInfoToAddresses = void 0;
7
+ exports.getAccountJsonByAddress = exports.convertSubjectInfoToAddresses = void 0;
7
8
  exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
8
9
  exports.simpleAddress = void 0;
9
10
  var _index = require("@subwallet/extension-base/utils/index");
11
+ var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
10
12
  var _utilCrypto = require("@polkadot/util-crypto");
11
13
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
12
14
  // SPDX-License-Identifier: Apache-2.0
@@ -31,4 +33,32 @@ const convertSubjectInfoToAddresses = subjectInfo => {
31
33
  ...info.json.meta
32
34
  }));
33
35
  };
34
- exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
36
+
37
+ /**
38
+ * @function getAccountJsonByAddress
39
+ * @desc Get account info by address
40
+ * <p>
41
+ * Note: Use on the background only
42
+ * </p>
43
+ * @param {string} address - Address
44
+ * @returns {AccountJson|null} - Account info or null if not found
45
+ */
46
+ exports.convertSubjectInfoToAddresses = convertSubjectInfoToAddresses;
47
+ const getAccountJsonByAddress = address => {
48
+ try {
49
+ const pair = _uiKeyring.default.getPair(address);
50
+ if (pair) {
51
+ return {
52
+ address: pair.address,
53
+ type: pair.type,
54
+ ...pair.meta
55
+ };
56
+ } else {
57
+ return null;
58
+ }
59
+ } catch (e) {
60
+ console.warn(e);
61
+ return null;
62
+ }
63
+ };
64
+ exports.getAccountJsonByAddress = getAccountJsonByAddress;
package/cjs/utils/eth.js CHANGED
@@ -4,7 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.signatureToHex = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
7
+ exports.signatureToHex = exports.recalculateGasPrice = exports.createTransactionFromRLP = exports.anyNumberToBN = exports.Transaction = void 0;
8
+ var _constants = require("@subwallet/extension-base/constants");
8
9
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
9
10
  var _ethers = require("ethers");
10
11
  var _util = require("@polkadot/util");
@@ -69,4 +70,8 @@ const signatureToHex = sig => {
69
70
  const hexV = (0, _util.hexStripPrefix)((0, _util.numberToHex)(v));
70
71
  return hexR + hexS + hexV;
71
72
  };
72
- exports.signatureToHex = signatureToHex;
73
+ exports.signatureToHex = signatureToHex;
74
+ const recalculateGasPrice = (_price, chain) => {
75
+ return _constants.NETWORK_MULTI_GAS_FEE.includes(chain) ? new _bignumber.default(_price).multipliedBy(_constants.GAS_PRICE_RATIO).toFixed(0) : _price;
76
+ };
77
+ exports.recalculateGasPrice = recalculateGasPrice;
@@ -78,6 +78,18 @@ var _i18next = require("i18next");
78
78
  var _util = require("@polkadot/util");
79
79
  var _utilCrypto = require("@polkadot/util-crypto");
80
80
  var _canDerive = require("./canDerive");
81
+ var _account = require("./account");
82
+ Object.keys(_account).forEach(function (key) {
83
+ if (key === "default" || key === "__esModule") return;
84
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
85
+ if (key in exports && exports[key] === _account[key]) return;
86
+ Object.defineProperty(exports, key, {
87
+ enumerable: true,
88
+ get: function () {
89
+ return _account[key];
90
+ }
91
+ });
92
+ });
81
93
  var _array = require("./array");
82
94
  Object.keys(_array).forEach(function (key) {
83
95
  if (key === "default" || key === "__esModule") return;
@@ -20,5 +20,7 @@ export declare const ALL_GENESIS_HASH: null;
20
20
  export declare const IGNORE_GET_SUBSTRATE_FEATURES_LIST: string[];
21
21
  export declare const IGNORE_QR_SIGNER: string[];
22
22
  export declare const XCM_MIN_AMOUNT_RATIO = 1.2;
23
+ export declare const GAS_PRICE_RATIO = 1.05;
24
+ export declare const NETWORK_MULTI_GAS_FEE: string[];
23
25
  export * from './staking';
24
26
  export * from './storage';
@@ -23,5 +23,7 @@ export const ALL_GENESIS_HASH = null;
23
23
  export const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
24
24
  export const IGNORE_QR_SIGNER = [];
25
25
  export const XCM_MIN_AMOUNT_RATIO = 1.2;
26
+ export const GAS_PRICE_RATIO = 1.05;
27
+ export const NETWORK_MULTI_GAS_FEE = ['astarEvm'];
26
28
  export * from "./staking.js";
27
29
  export * from "./storage.js";
@@ -6,6 +6,9 @@ import { Codec } from '@polkadot/types/types';
6
6
  export declare function subscribeAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
7
7
  export declare function getAmplitudeStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
8
8
  export declare function subscribeAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: ParachainStakingStakeOption, unstakingInfo: Record<string, number>): Promise<NominatorMetadata>;
9
+ /**
10
+ * Deprecated
11
+ * */
9
12
  export declare function getAmplitudeNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
10
13
  export declare function getAmplitudeCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
11
14
  export declare function getAmplitudeBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, selectedValidatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
@@ -61,8 +61,7 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
61
61
  let activeStake = '0';
62
62
  if (delegatorState) {
63
63
  // delegatorState can be null while unstaking all
64
- const identityInfo = substrateApi.api.query.identity ? (await substrateApi.api.query.identity.identityOf(delegatorState.owner)).toPrimitive() : undefined;
65
- const identity = identityInfo ? parseIdentity(identityInfo) : undefined;
64
+ const [identity] = await parseIdentity(substrateApi, delegatorState.owner);
66
65
  activeStake = delegatorState.amount.toString();
67
66
  const bnActiveStake = new BN(activeStake);
68
67
  let delegationStatus = StakingStatus.NOT_EARNING;
@@ -111,6 +110,10 @@ export async function subscribeAmplitudeNominatorMetadata(chainInfo, address, su
111
110
  unstakings: unstakingList
112
111
  };
113
112
  }
113
+
114
+ /**
115
+ * Deprecated
116
+ * */
114
117
  export async function getAmplitudeNominatorMetadata(chainInfo, address, substrateApi) {
115
118
  if (isEthereumAddress(address)) {
116
119
  return;
@@ -137,8 +140,7 @@ export async function getAmplitudeNominatorMetadata(chainInfo, address, substrat
137
140
  let activeStake = '0';
138
141
  if (delegatorState) {
139
142
  // delegatorState can be null while unstaking all
140
- const identityInfo = chainApi.api.query.identity ? (await chainApi.api.query.identity.identityOf(delegatorState.owner)).toPrimitive() : undefined;
141
- const identity = identityInfo ? parseIdentity(identityInfo) : undefined;
143
+ const [identity] = await parseIdentity(substrateApi, delegatorState.owner);
142
144
  activeStake = delegatorState.amount.toString();
143
145
  const bnActiveStake = new BN(activeStake);
144
146
  let delegationStatus = StakingStatus.NOT_EARNING;
@@ -6,6 +6,9 @@ import { Codec } from '@polkadot/types/types';
6
6
  export declare function subscribeAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
7
7
  export declare function getAstarStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
8
8
  export declare function subscribeAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, ledger: PalletDappsStakingAccountLedger): Promise<NominatorMetadata>;
9
+ /**
10
+ * Deprecated
11
+ * */
9
12
  export declare function getAstarNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
10
13
  export declare function getAstarDappsInfo(networkKey: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
11
14
  export declare function getAstarBondingExtrinsic(substrateApi: _SubstrateApi, amount: string, dappInfo: ValidatorInfo): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
@@ -148,6 +148,10 @@ export async function subscribeAstarNominatorMetadata(chainInfo, address, substr
148
148
  status: stakingStatus
149
149
  };
150
150
  }
151
+
152
+ /**
153
+ * Deprecated
154
+ * */
151
155
  export async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
152
156
  if (isEthereumAddress(address)) {
153
157
  return;
@@ -5,6 +5,9 @@ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/
5
5
  export declare function validateUnbondingCondition(nominatorMetadata: NominatorMetadata, amount: string, chain: string, chainStakingMetadata: ChainStakingMetadata, selectedValidator?: string): TransactionError[];
6
6
  export declare function validateBondingCondition(chainInfo: _ChainInfo, amount: string, selectedValidators: ValidatorInfo[], address: string, chainStakingMetadata: ChainStakingMetadata, nominatorMetadata?: NominatorMetadata): TransactionError[];
7
7
  export declare function getChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
8
+ /**
9
+ * Deprecated
10
+ * */
8
11
  export declare function getNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
9
12
  export declare function getValidatorsInfo(networkKey: string, substrateApi: _SubstrateApi, decimals: number, chainStakingMetadata: ChainStakingMetadata): Promise<ValidatorInfo[]>;
10
13
  export declare function getNominationPoolsInfo(chain: string, substrateApi: _SubstrateApi): Promise<import("@subwallet/extension-base/background/KoniTypes").NominationPoolInfo[]>;
@@ -31,6 +31,10 @@ export async function getChainStakingMetadata(chainInfo, substrateApi) {
31
31
  }
32
32
  return getRelayChainStakingMetadata(chainInfo, substrateApi);
33
33
  }
34
+
35
+ /**
36
+ * Deprecated
37
+ * */
34
38
  export async function getNominatorMetadata(chainInfo, address, substrateApi) {
35
39
  if (_STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
36
40
  return getAstarNominatorMetadata(chainInfo, address, substrateApi);
@@ -104,6 +108,7 @@ export async function getCancelWithdrawalExtrinsic(substrateApi, chain, selected
104
108
  export function subscribeEssentialChainStakingMetadata(substrateApiMap, chainInfoMap, callback) {
105
109
  const unsubList = [];
106
110
 
111
+ // TODO: replace with for of to improve performance
107
112
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
108
113
  Object.values(chainInfoMap).forEach(async chainInfo => {
109
114
  if (!substrateApiMap[chainInfo.slug]) {
@@ -9,6 +9,9 @@ export declare function validateParaChainBondingCondition(chainInfo: _ChainInfo,
9
9
  export declare function subscribeParaChainStakingMetadata(chain: string, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
10
10
  export declare function getParaChainStakingMetadata(chain: string, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
11
11
  export declare function subscribeParaChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, delegatorState: PalletParachainStakingDelegator): Promise<NominatorMetadata>;
12
+ /**
13
+ * Deprecated
14
+ * */
12
15
  export declare function getParaChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
13
16
  export declare function getParachainCollatorsInfo(chain: string, substrateApi: _SubstrateApi): Promise<ValidatorInfo[]>;
14
17
  export declare function getParaBondingExtrinsic(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, amount: string, selectedCollatorInfo: ValidatorInfo, nominatorMetadata?: NominatorMetadata): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
@@ -27,7 +27,7 @@ export function validateParaChainUnbondingCondition(amount, nominatorMetadata, c
27
27
  const bnChainMinStake = new BN(chainStakingMetadata.minStake || '0');
28
28
  const bnCollatorMinStake = new BN(targetNomination.validatorMinStake || '0');
29
29
  const bnMinStake = BN.max(bnCollatorMinStake, bnChainMinStake);
30
- const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainStakingMetadata.chain);
30
+ const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainStakingMetadata.chain, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type);
31
31
  if (targetNomination.hasUnstaking) {
32
32
  errors.push(new TransactionError(StakingTxErrorType.EXIST_UNSTAKING_REQUEST, existUnstakeErrorMessage));
33
33
  }
@@ -45,7 +45,7 @@ export function validateParaChainBondingCondition(chainInfo, amount, selectedCol
45
45
  const bnMinStake = bnCollatorMinStake > bnChainMinStake ? bnCollatorMinStake : bnChainMinStake;
46
46
  const minStakeErrorMessage = getMinStakeErrorMessage(chainInfo, bnMinStake);
47
47
  const maxValidatorErrorMessage = getMaxValidatorErrorMessage(chainInfo, chainStakingMetadata.maxValidatorPerNominator);
48
- const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, true);
48
+ const existUnstakeErrorMessage = getExistUnstakeErrorMessage(chainInfo.slug, nominatorMetadata === null || nominatorMetadata === void 0 ? void 0 : nominatorMetadata.type, true);
49
49
  if (!nominatorMetadata || nominatorMetadata.status === StakingStatus.NOT_STAKING) {
50
50
  if (!bnTotalStake.gte(bnMinStake)) {
51
51
  errors.push(new TransactionError(StakingTxErrorType.NOT_ENOUGH_MIN_STAKE, minStakeErrorMessage));
@@ -152,13 +152,10 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
152
152
  const roundInfo = _roundInfo.toPrimitive();
153
153
  const currentRound = roundInfo.current;
154
154
  await Promise.all(delegatorState.delegations.map(async delegation => {
155
- var _substrateApi$api$que;
156
- 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)]);
155
+ const [_delegationScheduledRequests, [identity], _collatorInfo] = await Promise.all([substrateApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), parseIdentity(substrateApi, delegation.owner), substrateApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
157
156
  const collatorInfo = _collatorInfo.toPrimitive();
158
157
  const minDelegation = collatorInfo === null || collatorInfo === void 0 ? void 0 : collatorInfo.lowestTopDelegationAmount.toString();
159
- const identityInfo = _identity === null || _identity === void 0 ? void 0 : _identity.toHuman();
160
158
  const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
161
- const identity = parseIdentity(identityInfo);
162
159
  let hasUnstaking = false;
163
160
  let delegationStatus = StakingStatus.NOT_EARNING;
164
161
 
@@ -220,6 +217,10 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
220
217
  unstakings: Object.values(unstakingMap)
221
218
  };
222
219
  }
220
+
221
+ /**
222
+ * Deprecated
223
+ * */
223
224
  export async function getParaChainNominatorMetadata(chainInfo, address, substrateApi) {
224
225
  if (_isChainEvmCompatible(chainInfo) && !isEthereumAddress(address)) {
225
226
  return;
@@ -243,14 +244,12 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
243
244
  }
244
245
  let bnTotalActiveStake = BN_ZERO;
245
246
  await Promise.all(delegatorState.delegations.map(async delegation => {
246
- const [_delegationScheduledRequests, _identity, _roundInfo, _collatorInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), chainApi.api.query.identity.identityOf(delegation.owner), chainApi.api.query.parachainStaking.round(), chainApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
247
+ const [_delegationScheduledRequests, [identity], _roundInfo, _collatorInfo] = await Promise.all([chainApi.api.query.parachainStaking.delegationScheduledRequests(delegation.owner), parseIdentity(substrateApi, delegation.owner), chainApi.api.query.parachainStaking.round(), chainApi.api.query.parachainStaking.candidateInfo(delegation.owner)]);
247
248
  const rawCollatorInfo = _collatorInfo.toHuman();
248
249
  const minDelegation = (rawCollatorInfo === null || rawCollatorInfo === void 0 ? void 0 : rawCollatorInfo.lowestTopDelegationAmount).replaceAll(',', '');
249
- const identityInfo = _identity.toHuman();
250
250
  const roundInfo = _roundInfo.toPrimitive();
251
251
  const delegationScheduledRequests = _delegationScheduledRequests.toPrimitive();
252
252
  const currentRound = roundInfo.current;
253
- const identity = parseIdentity(identityInfo);
254
253
  let hasUnstaking = false;
255
254
  let delegationStatus = StakingStatus.NOT_EARNING;
256
255
 
@@ -340,19 +339,9 @@ export async function getParachainCollatorsInfo(chain, substrateApi) {
340
339
  }
341
340
  const extraInfoMap = {};
342
341
  await Promise.all(allCollators.map(async collator => {
343
- var _apiProps$api$query, _apiProps$api$query$i;
344
- const [_info, _identity] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), (_apiProps$api$query = apiProps.api.query) === null || _apiProps$api$query === void 0 ? void 0 : (_apiProps$api$query$i = _apiProps$api$query.identity) === null || _apiProps$api$query$i === void 0 ? void 0 : _apiProps$api$query$i.identityOf(collator.address) // some chains might not have identity pallet
345
- ]);
342
+ const [_info, [identity, isReasonable]] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo(collator.address), parseIdentity(apiProps, collator.address)]);
346
343
  const rawInfo = _info.toHuman();
347
- const rawIdentity = _identity ? _identity.toHuman() : null;
348
344
  const active = (rawInfo === null || rawInfo === void 0 ? void 0 : rawInfo.status) === 'Active';
349
- let isReasonable = false;
350
- let identity;
351
- if (rawIdentity !== null) {
352
- // Check if identity is eth address
353
- isReasonable = rawIdentity.judgements.length > 0;
354
- identity = parseIdentity(rawIdentity);
355
- }
356
345
  extraInfoMap[collator.address] = {
357
346
  identity,
358
347
  isVerified: isReasonable,
@@ -26,6 +26,9 @@ export declare function validateRelayBondingCondition(chainInfo: _ChainInfo, amo
26
26
  export declare function subscribeRelayChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi, callback: (chain: string, rs: ChainStakingMetadata) => void): Promise<Codec>;
27
27
  export declare function getRelayChainStakingMetadata(chainInfo: _ChainInfo, substrateApi: _SubstrateApi): Promise<ChainStakingMetadata>;
28
28
  export declare function subscribeRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, ledger: PalletStakingStakingLedger): Promise<NominatorMetadata>;
29
+ /**
30
+ * Deprecated
31
+ * */
29
32
  export declare function getRelayChainNominatorMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;
30
33
  export declare function subscribeRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi, poolMemberInfo: PalletNominationPoolsPoolMember): Promise<NominatorMetadata>;
31
34
  export declare function getRelayChainPoolMemberMetadata(chainInfo: _ChainInfo, address: string, substrateApi: _SubstrateApi): Promise<NominatorMetadata | undefined>;