@subwallet/extension-base 1.3.74-1 → 1.3.76-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.
Files changed (39) hide show
  1. package/background/KoniTypes.d.ts +9 -1
  2. package/background/KoniTypes.js +1 -0
  3. package/cjs/background/KoniTypes.js +1 -0
  4. package/cjs/constants/environment.js +4 -2
  5. package/cjs/koni/background/handlers/Extension.js +70 -37
  6. package/cjs/koni/background/handlers/State.js +82 -0
  7. package/cjs/packageInfo.js +1 -1
  8. package/cjs/services/balance-service/index.js +6 -1
  9. package/cjs/services/chain-service/index.js +1 -1
  10. package/cjs/services/earning-service/handlers/native-staking/dtao.js +85 -113
  11. package/cjs/services/earning-service/handlers/native-staking/tanssi.js +2 -1
  12. package/cjs/services/earning-service/handlers/native-staking/tao.js +85 -100
  13. package/cjs/services/earning-service/service.js +17 -2
  14. package/cjs/services/subscan-service/index.js +34 -6
  15. package/cjs/services/substrate-proxy-service/constant.js +1 -1
  16. package/cjs/utils/account/transform.js +3 -3
  17. package/constants/environment.d.ts +1 -0
  18. package/constants/environment.js +2 -1
  19. package/koni/background/handlers/Extension.d.ts +3 -0
  20. package/koni/background/handlers/Extension.js +33 -1
  21. package/koni/background/handlers/State.d.ts +5 -0
  22. package/koni/background/handlers/State.js +82 -0
  23. package/package.json +6 -6
  24. package/packageInfo.js +1 -1
  25. package/services/balance-service/index.js +6 -1
  26. package/services/chain-service/index.js +1 -1
  27. package/services/earning-service/handlers/native-staking/dtao.d.ts +2 -10
  28. package/services/earning-service/handlers/native-staking/dtao.js +86 -116
  29. package/services/earning-service/handlers/native-staking/tanssi.js +2 -1
  30. package/services/earning-service/handlers/native-staking/tao.d.ts +4 -3
  31. package/services/earning-service/handlers/native-staking/tao.js +84 -101
  32. package/services/earning-service/service.d.ts +2 -1
  33. package/services/earning-service/service.js +17 -2
  34. package/services/subscan-service/index.d.ts +2 -0
  35. package/services/subscan-service/index.js +33 -5
  36. package/services/substrate-proxy-service/constant.js +1 -1
  37. package/types/yield/actions/join/submit.d.ts +8 -1
  38. package/types/yield/info/account/info.d.ts +11 -5
  39. package/utils/account/transform.js +3 -3
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
8
9
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
10
  var _constants = require("@subwallet/extension-base/constants");
10
11
  var _types = require("@subwallet/extension-base/types");
@@ -16,49 +17,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
16
17
  // Copyright 2019-2022 @subwallet/extension-base
17
18
  // SPDX-License-Identifier: Apache-2.0
18
19
 
19
- // interface ApiResponse {
20
- // data: SubnetData[];
21
- // }
22
-
23
- // interface PoolData {
24
- // netuid: number;
25
- // name: string;
26
- // symbol: string;
27
- // }
28
-
29
- // interface PoolApiResponse {
30
- // data: PoolData[];
31
- // }
32
-
33
- // const SUBNET_API_URL = 'https://dash.taostats.io/api/subnet';
34
- // const POOL_API_URL = 'https://dash.taostats.io/api/dtao/pool';
35
-
36
- // export async function fetchSubnetData () {
37
- // try {
38
- // const [subnetResponse, poolResponse] = await Promise.all([
39
- // fetch(SUBNET_API_URL).then((res) => res.json()) as Promise<ApiResponse>,
40
- // fetch(POOL_API_URL).then((res) => res.json()) as Promise<PoolApiResponse>
41
- // ]);
42
-
43
- // const poolMap = new Map(poolResponse.data.map((pool) => [pool.netuid, pool]));
44
-
45
- // const filteredSubnets = subnetResponse.data.filter((subnet) => subnet.netuid !== 0);
46
-
47
- // const mergedData = filteredSubnets.map((subnet) => ({
48
- // ...subnet,
49
- // name: poolMap.get(subnet.netuid)?.name || 'Unknown',
50
- // symbol: poolMap.get(subnet.netuid)?.symbol || 'Unknown'
51
- // }));
52
-
53
- // return mergedData;
54
- // } catch (err) {
55
- // console.error('Error:', err);
56
-
57
- // return [];
58
- // }
59
- // }
60
-
61
- const getAlphaToTaoMapping = async substrateApi => {
20
+ const getAlphaToTaoRateMap = async substrateApi => {
62
21
  const allSubnets = (await substrateApi.api.call.subnetInfoRuntimeApi.getAllDynamicInfo()).toJSON();
63
22
  if (!allSubnets || allSubnets.length === 0) {
64
23
  return {};
@@ -252,87 +211,92 @@ class SubnetTaoStakingPoolHandler extends _tao.default {
252
211
  const chainInfo = this.chainInfo;
253
212
  const _delegateInfo = await this.bittensorCache.get();
254
213
  const getPoolPosition = async () => {
255
- const rawDelegateStateInfos = await Promise.all(useAddresses.map(async address => (await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkey(address)).toJSON()));
256
- const price = await getAlphaToTaoMapping(this.substrateApi);
257
- if (rawDelegateStateInfos && rawDelegateStateInfos.length > 0) {
258
- rawDelegateStateInfos.forEach((rawDelegateStateInfo, i) => {
259
- const owner = (0, _utils.reformatAddress)(useAddresses[i], 42);
260
- const delegateStateInfo = rawDelegateStateInfo;
261
- const subnetPositions = {};
262
- for (const delegate of delegateStateInfo) {
263
- const hotkey = delegate.hotkey;
264
- const netuid = delegate.netuid;
265
- const stake = new _bignumber.default(delegate.stake);
266
- const aplhaToTaoPrice = new _bignumber.default(price[netuid]);
267
- if (!subnetPositions[netuid]) {
268
- subnetPositions[netuid] = {
269
- delegatorState: [],
270
- totalBalance: _util.BN_ZERO,
271
- originalTotalStake: _util.BN_ZERO
272
- };
273
- }
274
- let identity = '';
275
- if (_delegateInfo) {
276
- const delegateInfo = _delegateInfo.data.find(info => info.hotkey.ss58 === hotkey);
277
- identity = delegateInfo ? delegateInfo.name : '';
278
- }
279
- subnetPositions[netuid].delegatorState.push({
280
- owner: hotkey,
281
- amount: stake.toString(),
282
- rate: aplhaToTaoPrice,
283
- identity: identity
284
- });
285
- subnetPositions[netuid].totalBalance = subnetPositions[netuid].totalBalance.add(new _util.BN(stake.toString()));
286
- subnetPositions[netuid].originalTotalStake = subnetPositions[netuid].originalTotalStake.add(new _util.BN(stake.toString()));
214
+ const rawDelegateStateInfos = await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkeys(useAddresses);
215
+ const delegateStateInfos = rawDelegateStateInfos.toPrimitive();
216
+ const alphaToTaoRateMap = await getAlphaToTaoRateMap(this.substrateApi);
217
+ if (!delegateStateInfos || delegateStateInfos.length === 0) {
218
+ return;
219
+ }
220
+ delegateStateInfos.forEach(_ref => {
221
+ let [coldkey, stakeInfos] = _ref;
222
+ const owner = (0, _utils.reformatAddress)(coldkey, 42);
223
+ const subnetPositions = {};
224
+ for (const delegate of stakeInfos) {
225
+ const hotkey = delegate.hotkey;
226
+ const netuid = delegate.netuid;
227
+ if (netuid === 0) {
228
+ continue;
229
+ }
230
+ const stake = new _bignumber.default(delegate.stake);
231
+ const alphaToTaoPrice = new _bignumber.default(alphaToTaoRateMap[netuid]);
232
+ if (!subnetPositions[netuid]) {
233
+ subnetPositions[netuid] = {
234
+ delegatorState: [],
235
+ totalBalance: (0, _bignumber.default)(0),
236
+ originalTotalStake: (0, _bignumber.default)(0)
237
+ };
287
238
  }
288
- Object.values(this.subnetData).forEach(subnet => {
289
- const netuid = subnet.netuid;
290
- const subnetSlug = `${this.slug}__subnet_${netuid.toString().padStart(2, '0')}`;
291
- const subnetName = `${subnet.name || 'Unknown'} ${netuid}`;
292
- const subnetSymbol = subnet.symbol || 'dTAO';
293
- const {
294
- delegatorState = [],
295
- originalTotalStake = _util.BN_ZERO
296
- } = subnetPositions[netuid] || {};
297
- if (delegatorState.length > 0) {
298
- this.parseNominatorMetadata(chainInfo, delegatorState, netuid).then(nominatorMetadata => {
299
- rsCallback({
300
- ...defaultInfo,
301
- ...nominatorMetadata,
302
- address: owner,
303
- type: this.type,
304
- slug: subnetSlug,
305
- subnetData: {
306
- subnetSymbol,
307
- subnetShortName: subnetName,
308
- originalTotalStake: originalTotalStake.toString()
309
- }
310
- });
311
- }).catch(console.error);
312
- } else {
239
+ let identity = '';
240
+ if (_delegateInfo) {
241
+ const delegateInfo = _delegateInfo.data.find(info => info.hotkey.ss58 === hotkey);
242
+ identity = delegateInfo ? delegateInfo.name : '';
243
+ }
244
+ subnetPositions[netuid].delegatorState.push({
245
+ owner: hotkey,
246
+ amount: stake.toString(),
247
+ rate: alphaToTaoPrice,
248
+ identity
249
+ });
250
+ subnetPositions[netuid].totalBalance = subnetPositions[netuid].totalBalance.plus(new _bignumber.default(stake.toString()));
251
+ subnetPositions[netuid].originalTotalStake = subnetPositions[netuid].originalTotalStake.plus(new _bignumber.default(stake.toString()));
252
+ }
253
+ Object.values(this.subnetData).forEach(subnet => {
254
+ const netuid = subnet.netuid;
255
+ const subnetSlug = `${this.slug}__subnet_${netuid.toString().padStart(2, '0')}`;
256
+ const subnetName = `${subnet.name || 'Unknown'} ${netuid}`;
257
+ const subnetSymbol = subnet.symbol || 'dTAO';
258
+ const {
259
+ delegatorState = [],
260
+ originalTotalStake = _util.BN_ZERO
261
+ } = subnetPositions[netuid] || {};
262
+ if (delegatorState.length > 0) {
263
+ this.parseNominatorMetadata(chainInfo, delegatorState, netuid).then(nominatorMetadata => {
313
264
  rsCallback({
314
265
  ...defaultInfo,
315
- type: this.type,
266
+ ...nominatorMetadata,
316
267
  address: owner,
317
- balanceToken: this.nativeToken.slug,
318
- totalStake: '0',
319
- activeStake: '0',
320
- unstakeBalance: '0',
321
- status: _types.EarningStatus.NOT_STAKING,
322
- isBondedBefore: false,
323
- nominations: [],
324
- unstakings: [],
268
+ type: this.type,
325
269
  slug: subnetSlug,
326
270
  subnetData: {
327
271
  subnetSymbol,
328
272
  subnetShortName: subnetName,
329
- originalTotalStake: '0'
273
+ originalTotalStake: originalTotalStake.toString()
330
274
  }
331
275
  });
332
- }
333
- });
276
+ }).catch(console.error);
277
+ } else {
278
+ rsCallback({
279
+ ...defaultInfo,
280
+ type: this.type,
281
+ address: owner,
282
+ balanceToken: this.nativeToken.slug,
283
+ totalStake: '0',
284
+ activeStake: '0',
285
+ unstakeBalance: '0',
286
+ status: _types.EarningStatus.NOT_STAKING,
287
+ isBondedBefore: false,
288
+ nominations: [],
289
+ unstakings: [],
290
+ slug: subnetSlug,
291
+ subnetData: {
292
+ subnetSymbol,
293
+ subnetShortName: subnetName,
294
+ originalTotalStake: '0'
295
+ }
296
+ });
297
+ }
334
298
  });
335
- }
299
+ });
336
300
  };
337
301
  const getStakingPositionInterval = async () => {
338
302
  if (cancel) {
@@ -351,5 +315,13 @@ class SubnetTaoStakingPoolHandler extends _tao.default {
351
315
  }
352
316
 
353
317
  /* Subscribe pool position */
318
+
319
+ /* Unimplemented function */
320
+
321
+ handleChangeRootClaimType() {
322
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
323
+ }
324
+
325
+ /* Unimplemented function */
354
326
  }
355
327
  exports.default = SubnetTaoStakingPoolHandler;
@@ -301,7 +301,8 @@ class TanssiNativeStakingPoolHandler extends _basePara.default {
301
301
  metadata: {
302
302
  pendingStake: bnJoiningStake.toString(),
303
303
  compoundingStake: bnCompoundingStake.toString(),
304
- manualStake: bnManualStake.toString()
304
+ manualStake: bnManualStake.toString(),
305
+ isShowActiveStakeDetails: bnJoiningStake.gt(0) || bnCompoundingStake.gt(0) || !bnManualStake.gt(0)
305
306
  }
306
307
  });
307
308
  };
@@ -121,35 +121,6 @@ class BittensorCache {
121
121
  }
122
122
  }
123
123
  }
124
-
125
- // export async function fetchTaoDelegateState (address: string): Promise<RawDelegateState> {
126
- // const apiKey = bittensorApiKey();
127
-
128
- // return new Promise(function (resolve) {
129
- // fetch(`https://api.taostats.io/api/stake_balance/latest/v1?coldkey=${address}`, {
130
- // method: 'GET',
131
- // headers: {
132
- // 'Content-Type': 'application/json',
133
- // Authorization: `${apiKey}`
134
- // }
135
- // }).then((resp) => {
136
- // resolve(resp.json());
137
- // }).catch(console.error);
138
- // });
139
- // }
140
-
141
- /* Fetch data */
142
-
143
- // const testnetDelegate = {
144
- // '5G6wdAdS7hpBuH1tjuZDhpzrGw9Wf71WEVakDCxHDm1cxEQ2': {
145
- // name: '0x436c6f776e4e616d65f09fa4a1',
146
- // url: 'https://example.com ',
147
- // image: 'https://example.com/image.png',
148
- // discord: '0xe28094446973636f7264',
149
- // description: 'This is an example identity.',
150
- // additional: ''
151
- // }
152
- // };
153
124
  exports.BittensorCache = BittensorCache;
154
125
  const getAlphaToTaoRate = async (substrateApi, netuid) => {
155
126
  const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(netuid)).toJSON();
@@ -205,20 +176,9 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
205
176
  super(state, chain);
206
177
  this.bittensorCache = BittensorCache.getInstance();
207
178
  }
208
-
209
- /* Unimplemented function */
210
- handleYieldWithdraw(address, unstakingInfo) {
211
- return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
212
- }
213
- handleYieldCancelUnstake(params) {
214
- return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
215
- }
216
- /* Unimplemented function */
217
-
218
179
  get maintainBalance() {
219
180
  const ed = new _bignumber.default(this.nativeToken.minAmount || '0');
220
- const calculateMaintainBalance = new _bignumber.default(15).multipliedBy(ed).dividedBy(10);
221
- const maintainBalance = calculateMaintainBalance;
181
+ const maintainBalance = new _bignumber.default(15).multipliedBy(ed).dividedBy(10);
222
182
  return maintainBalance.toString();
223
183
  }
224
184
 
@@ -344,66 +304,75 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
344
304
  const chainInfo = this.chainInfo;
345
305
  const _delegateInfo = await this.bittensorCache.get();
346
306
  const getPoolPosition = async () => {
347
- const rawDelegateStateInfos = await Promise.all(useAddresses.map(async address => (await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkey(address)).toJSON()));
348
- if (rawDelegateStateInfos && rawDelegateStateInfos.length > 0) {
349
- rawDelegateStateInfos.forEach((rawDelegateStateInfo, i) => {
350
- const owner = (0, _utils3.reformatAddress)(useAddresses[i], 42);
351
- const delegatorState = [];
352
- let bnTotalBalance = _util.BN_ZERO;
353
- const delegateStateInfo = rawDelegateStateInfo;
354
- const totalDelegate = {};
355
- for (const delegate of delegateStateInfo) {
356
- const hotkey = delegate.hotkey;
357
- const netuid = delegate.netuid;
358
- const stake = new _bignumber.default(delegate.stake);
359
- if (netuid === 0) {
360
- const taoStake = stake.toFixed(0);
361
- if (totalDelegate[hotkey]) {
362
- totalDelegate[hotkey] = new _bignumber.default(totalDelegate[hotkey]).plus(taoStake).toFixed();
363
- } else {
364
- totalDelegate[hotkey] = taoStake;
365
- }
307
+ const rawDelegateStateInfo = await substrateApi.api.call.stakeInfoRuntimeApi.getStakeInfoForColdkeys(useAddresses);
308
+ const delegateStateInfo = rawDelegateStateInfo.toPrimitive();
309
+ const rootClaimType = await substrateApi.api.query.subtensorModule.rootClaimType.multi(useAddresses);
310
+ if (!delegateStateInfo || delegateStateInfo.length === 0) {
311
+ return;
312
+ }
313
+ delegateStateInfo.forEach((_ref2, i) => {
314
+ var _rootClaimType$i;
315
+ let [coldkey, stakeInfos] = _ref2;
316
+ const owner = (0, _utils3.reformatAddress)(coldkey, 42);
317
+ const delegatorState = [];
318
+ let bnTotalBalance = _util.BN_ZERO;
319
+ const totalDelegate = {};
320
+ for (const delegate of stakeInfos) {
321
+ const hotkey = delegate.hotkey;
322
+ const netuid = delegate.netuid;
323
+ const stake = new _bignumber.default(delegate.stake);
324
+ if (netuid === 0) {
325
+ const taoStake = stake.toFixed(0);
326
+ if (totalDelegate[hotkey]) {
327
+ totalDelegate[hotkey] = new _bignumber.default(totalDelegate[hotkey]).plus(taoStake).toFixed();
328
+ } else {
329
+ totalDelegate[hotkey] = taoStake;
366
330
  }
367
331
  }
368
- for (const hotkey in totalDelegate) {
369
- bnTotalBalance = bnTotalBalance.add(new _util.BN(totalDelegate[hotkey]));
370
- let identity = '';
371
- if (_delegateInfo) {
372
- const delegateInfo = _delegateInfo.data.find(info => info.hotkey.ss58 === hotkey);
373
- identity = delegateInfo ? delegateInfo.name : '';
374
- }
375
- delegatorState.push({
376
- owner: hotkey,
377
- amount: totalDelegate[hotkey],
378
- identity: identity
379
- });
332
+ }
333
+ for (const hotkey in totalDelegate) {
334
+ bnTotalBalance = bnTotalBalance.add(new _util.BN(totalDelegate[hotkey]));
335
+ let identity = '';
336
+ if (_delegateInfo) {
337
+ const delegateInfo = _delegateInfo.data.find(info => info.hotkey.ss58 === hotkey);
338
+ identity = delegateInfo ? delegateInfo.name : '';
380
339
  }
381
- if (delegateStateInfo && delegateStateInfo.length > 0) {
382
- this.parseNominatorMetadata(chainInfo, delegatorState).then(nominatorMetadata => {
383
- rsCallback({
384
- ...defaultInfo,
385
- ...nominatorMetadata,
386
- address: owner,
387
- type: this.type
388
- });
389
- }).catch(console.error);
390
- } else {
340
+ delegatorState.push({
341
+ owner: hotkey,
342
+ amount: totalDelegate[hotkey],
343
+ identity: identity
344
+ });
345
+ }
346
+ const rawType = (_rootClaimType$i = rootClaimType[i]) === null || _rootClaimType$i === void 0 ? void 0 : _rootClaimType$i.toString();
347
+ const rootClaimForAddress = rawType === 'Swap' || rawType === 'Keep' ? rawType : 'Others';
348
+ if (delegateStateInfo && delegateStateInfo.length > 0) {
349
+ this.parseNominatorMetadata(chainInfo, delegatorState).then(nominatorMetadata => {
391
350
  rsCallback({
392
351
  ...defaultInfo,
393
- type: this.type,
352
+ ...nominatorMetadata,
394
353
  address: owner,
395
- balanceToken: this.nativeToken.slug,
396
- totalStake: '0',
397
- activeStake: '0',
398
- unstakeBalance: '0',
399
- status: _types.EarningStatus.NOT_STAKING,
400
- isBondedBefore: false,
401
- nominations: [],
402
- unstakings: []
354
+ metadata: {
355
+ bittensorRootClaimType: rootClaimForAddress
356
+ },
357
+ type: this.type
403
358
  });
404
- }
405
- });
406
- }
359
+ }).catch(console.error);
360
+ } else {
361
+ rsCallback({
362
+ ...defaultInfo,
363
+ type: this.type,
364
+ address: owner,
365
+ balanceToken: this.nativeToken.slug,
366
+ totalStake: '0',
367
+ activeStake: '0',
368
+ unstakeBalance: '0',
369
+ status: _types.EarningStatus.NOT_STAKING,
370
+ isBondedBefore: false,
371
+ nominations: [],
372
+ unstakings: []
373
+ });
374
+ }
375
+ });
407
376
  };
408
377
  const getStakingPositionInterval = async () => {
409
378
  if (cancel) {
@@ -451,8 +420,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
451
420
  }));
452
421
  }
453
422
  async getMainnetPoolTargets(netuid) {
454
- const _topValidator = await this.bittensorCache.get();
455
- const topValidator = _topValidator;
423
+ const topValidator = await this.bittensorCache.get();
456
424
  const bnMinBond = await this.getMinBond();
457
425
  const validatorList = topValidator.data;
458
426
  const aprResponse = await this.bittensorCache.fetchApr(netuid);
@@ -460,7 +428,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
460
428
  aprResponse.data.forEach(item => {
461
429
  aprMap[item.hotkey.ss58] = item.thirty_day_apy;
462
430
  });
463
- const results = await Promise.all(validatorList.map(validator => {
431
+ return await Promise.all(validatorList.map(validator => {
464
432
  const address = validator.hotkey.ss58;
465
433
  // With bittensor we use total weight, root weight and alpha staked insted of total stake, own stake and other stake
466
434
  const bnTotalWeightStake = new _bignumber.default(validator.global_weighted_stake);
@@ -488,7 +456,6 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
488
456
  identity: name
489
457
  };
490
458
  }));
491
- return results;
492
459
  }
493
460
  async getPoolTargets(netuid) {
494
461
  if (this.chain === 'bittensor') {
@@ -639,8 +606,26 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
639
606
  }
640
607
  })));
641
608
  }
642
- const extrinsic = chainApi.api.tx.subtensorModule.moveStake(originValidator, destValidator, netuid, netuid, amount);
643
- return extrinsic;
609
+ return chainApi.api.tx.subtensorModule.moveStake(originValidator, destValidator, netuid, netuid, amount);
644
610
  }
611
+
612
+ /* Others function */
613
+ async handleChangeRootClaimType(type) {
614
+ if (type !== 'Keep' && type !== 'Swap') {
615
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS));
616
+ }
617
+ const chainApi = await this.substrateApi.isReady;
618
+ return chainApi.api.tx.subtensorModule.setRootClaimType(type);
619
+ }
620
+ /* Others function */
621
+
622
+ /* Unimplemented function */
623
+ handleYieldWithdraw(address, unstakingInfo) {
624
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
625
+ }
626
+ handleYieldCancelUnstake(params) {
627
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
628
+ }
629
+ /* Unimplemented function */
645
630
  }
646
631
  exports.default = TaoNativeStakingPoolHandler;
@@ -98,8 +98,6 @@ class EarningService {
98
98
  handlers.push(new _handlers.AmplitudeNativeStakingPoolHandler(this.state, chain));
99
99
  }
100
100
  if (_constants2._STAKING_CHAIN_GROUP.bittensor.includes(chain)) {
101
- // todo: check support for testnet
102
- // Mainnet only
103
101
  handlers.push(new _handlers.TaoNativeStakingPoolHandler(this.state, chain));
104
102
  handlers.push(new _handlers.SubnetTaoStakingPoolHandler(this.state, chain));
105
103
  }
@@ -994,6 +992,23 @@ class EarningService {
994
992
  return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.INTERNAL_ERROR));
995
993
  }
996
994
  }
995
+ async handleChangeRootClaimType(params) {
996
+ await this.eventService.waitChainReady;
997
+ const {
998
+ bittensorRootClaimType,
999
+ chain,
1000
+ slug
1001
+ } = params;
1002
+ if (!_constants2._STAKING_CHAIN_GROUP.bittensor.includes(chain)) {
1003
+ return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.UNSUPPORTED));
1004
+ }
1005
+ const handler = this.getPoolHandler(slug);
1006
+ if (handler) {
1007
+ return handler.handleChangeRootClaimType(bittensorRootClaimType);
1008
+ } else {
1009
+ return Promise.reject(new _TransactionError.TransactionError(_types2.BasicTxErrorType.INTERNAL_ERROR));
1010
+ }
1011
+ }
997
1012
 
998
1013
  /* Other */
999
1014
 
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.SubscanService = void 0;
7
7
  var _SWError = require("@subwallet/extension-base/background/errors/SWError");
8
- var _constants = require("@subwallet/extension-base/koni/api/nft/ordinal_nft/constants");
8
+ var _constants = require("@subwallet/extension-base/constants");
9
+ var _constants2 = require("@subwallet/extension-base/koni/api/nft/ordinal_nft/constants");
9
10
  var _subscanChainMap = require("@subwallet/extension-base/services/subscan-service/subscan-chain-map");
10
11
  var _base = require("@subwallet/extension-base/strategy/api-request-strategy/context/base");
11
12
  var _apiRequestStrategyV = require("@subwallet/extension-base/strategy/api-request-strategy-v2");
@@ -15,11 +16,15 @@ var _utils = require("@subwallet/extension-base/utils");
15
16
 
16
17
  const QUERY_ROW = 100;
17
18
  class SubscanService extends _apiRequestStrategyV.BaseApiRequestStrategyV2 {
19
+ apiKey = null;
18
20
  constructor(subscanChainMap, options) {
19
21
  const context = new _base.BaseApiRequestContext(options);
20
22
  super(context);
21
23
  this.subscanChainMap = subscanChainMap;
22
24
  }
25
+ setApiKey(key) {
26
+ this.apiKey = key;
27
+ }
23
28
  getApiUrl(chain, path) {
24
29
  const subscanChain = this.subscanChainMap[chain];
25
30
  if (!subscanChain) {
@@ -28,11 +33,26 @@ class SubscanService extends _apiRequestStrategyV.BaseApiRequestStrategyV2 {
28
33
  return `https://${subscanChain}.api.subscan.io/${path}`;
29
34
  }
30
35
  postRequest(url, body) {
36
+ const parsed = new URL(url);
37
+ const headers = {
38
+ 'Content-Type': 'application/json'
39
+ };
40
+ if (this.apiKey) {
41
+ headers['X-API-Key'] = this.apiKey;
42
+ }
43
+ if (_utils.targetIsWeb) {
44
+ const suffix = '.api.subscan.io';
45
+ const subscanChain = parsed.hostname.endsWith(suffix) ? parsed.hostname.slice(0, -suffix.length) : parsed.hostname;
46
+ headers['x-network'] = subscanChain;
47
+ return fetch(`${_constants.SUBSCAN_GATEWAY_URL}${parsed.pathname}${parsed.search}`, {
48
+ method: 'POST',
49
+ headers,
50
+ body: JSON.stringify(body)
51
+ });
52
+ }
31
53
  return fetch(url, {
32
54
  method: 'POST',
33
- headers: {
34
- 'Content-Type': 'application/json'
35
- },
55
+ headers,
36
56
  body: JSON.stringify(body)
37
57
  });
38
58
  }
@@ -244,7 +264,7 @@ class SubscanService extends _apiRequestStrategyV.BaseApiRequestStrategyV2 {
244
264
  getAccountRemarkEvents(groupId, chain, address) {
245
265
  return this.addRequest(async () => {
246
266
  const rs = await this.postRequest(this.getApiUrl(chain, 'api/v2/scan/events'), {
247
- ..._constants.BASE_FETCH_ORDINAL_EVENT_DATA,
267
+ ..._constants2.BASE_FETCH_ORDINAL_EVENT_DATA,
248
268
  address
249
269
  });
250
270
  if (rs.status !== 200) {
@@ -272,7 +292,15 @@ class SubscanService extends _apiRequestStrategyV.BaseApiRequestStrategyV2 {
272
292
 
273
293
  static getInstance() {
274
294
  if (!SubscanService._instance) {
275
- SubscanService._instance = new SubscanService(_subscanChainMap.SUBSCAN_API_CHAIN_MAP);
295
+ // Subscan API allows only ~2 requests per second.
296
+ // However, each request from the webapp also triggers an OPTIONS request (CORS preflight),
297
+ // which Subscan counts towards the quota as well → effectively 1 call = 2 requests.
298
+ // To avoid hitting the rate limit, we configure the queue
299
+ // to allow only 1 request per second.
300
+ SubscanService._instance = new SubscanService(_subscanChainMap.SUBSCAN_API_CHAIN_MAP, {
301
+ limitRate: 1,
302
+ intervalCheck: 1000
303
+ });
276
304
  }
277
305
  return SubscanService._instance;
278
306
  }
@@ -9,7 +9,7 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
9
  // SPDX-License-Identifier: Apache-2.0
10
10
 
11
11
  const SUBSTRATE_PROXY_ACCOUNT_EXTRINSIC_GROUPS = {
12
- STAKING: [_KoniTypes.ExtrinsicType.STAKING_BOND, _KoniTypes.ExtrinsicType.STAKING_UNBOND, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW, _KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.STAKING_LEAVE_POOL, _KoniTypes.ExtrinsicType.CHANGE_EARNING_VALIDATOR, _KoniTypes.ExtrinsicType.STAKING_CANCEL_UNSTAKE, _KoniTypes.ExtrinsicType.STAKING_CLAIM_REWARD],
12
+ STAKING: [_KoniTypes.ExtrinsicType.STAKING_BOND, _KoniTypes.ExtrinsicType.STAKING_UNBOND, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW, _KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.STAKING_LEAVE_POOL, _KoniTypes.ExtrinsicType.CHANGE_EARNING_VALIDATOR, _KoniTypes.ExtrinsicType.STAKING_CANCEL_UNSTAKE, _KoniTypes.ExtrinsicType.STAKING_CLAIM_REWARD, _KoniTypes.ExtrinsicType.CHANGE_BITTENSOR_ROOT_CLAIM_TYPE],
13
13
  GOV: [_KoniTypes.ExtrinsicType.GOV_VOTE, _KoniTypes.ExtrinsicType.GOV_UNVOTE, _KoniTypes.ExtrinsicType.GOV_UNLOCK_VOTE],
14
14
  PROXY: [
15
15
  // only type any can add proxy
@@ -177,7 +177,7 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
177
177
  if ([_types2.AccountSignMode.PASSWORD, _types2.AccountSignMode.INJECTED].includes(signMode)) {
178
178
  switch (networkType) {
179
179
  case _types2.AccountChainType.SUBSTRATE:
180
- return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
180
+ return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, _KoniTypes.ExtrinsicType.CHANGE_BITTENSOR_ROOT_CLAIM_TYPE, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
181
181
  case _types2.AccountChainType.ETHEREUM:
182
182
  return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...SUBSTRATE_PROXY_ACTION, ...EVM_ACTIONS];
183
183
  case _types2.AccountChainType.TON:
@@ -190,7 +190,7 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
190
190
  } else if (signMode === _types2.AccountSignMode.QR) {
191
191
  switch (networkType) {
192
192
  case _types2.AccountChainType.SUBSTRATE:
193
- return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
193
+ return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, _KoniTypes.ExtrinsicType.CHANGE_BITTENSOR_ROOT_CLAIM_TYPE, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
194
194
  case _types2.AccountChainType.ETHEREUM:
195
195
  return [...(_constants.isProductionMode ? [] : [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OTHER_ACTIONS, ...EVM_ACTIONS])];
196
196
  case _types2.AccountChainType.TON:
@@ -224,7 +224,7 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
224
224
  case _types2.AccountChainType.SUBSTRATE:
225
225
  return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS,
226
226
  // ...EARN_QDOT_ACTIONS,
227
- ...OPEN_GOV_ACTIONS, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
227
+ ...OPEN_GOV_ACTIONS, _KoniTypes.ExtrinsicType.CHANGE_BITTENSOR_ROOT_CLAIM_TYPE, ...MULTISIG_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
228
228
  case _types2.AccountChainType.ETHEREUM:
229
229
  return [...BASE_TRANSFER_ACTIONS, ...EARN_STDOT_ACTIONS, ...EVM_ACTIONS, ...CLAIM_AVAIL_BRIDGE, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW,
230
230
  // For liquid staking
@@ -2,3 +2,4 @@ export declare const APP_VERSION: string;
2
2
  export declare const isProductionMode: boolean;
3
3
  export declare const BACKEND_API_URL: string;
4
4
  export declare const SW_EXTERNAL_SERVICES_API: string;
5
+ export declare const SUBSCAN_GATEWAY_URL: string;