@subwallet/extension-base 1.3.75-2 → 1.3.77-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 (63) hide show
  1. package/background/KoniTypes.d.ts +6 -2
  2. package/background/KoniTypes.js +1 -0
  3. package/cjs/background/KoniTypes.js +1 -0
  4. package/cjs/core/substrate/xcm-parser.js +8 -11
  5. package/cjs/koni/background/handlers/Extension.js +279 -64
  6. package/cjs/koni/background/handlers/Tabs.js +2 -3
  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/chain-service/utils/patch.js +1 -1
  11. package/cjs/services/earning-service/constants/chains.js +4 -1
  12. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +8 -5
  13. package/cjs/services/earning-service/handlers/native-staking/dtao.js +85 -113
  14. package/cjs/services/earning-service/handlers/native-staking/tanssi.js +2 -1
  15. package/cjs/services/earning-service/handlers/native-staking/tao.js +85 -100
  16. package/cjs/services/earning-service/service.js +35 -4
  17. package/cjs/services/multisig-service/index.js +1 -1
  18. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +12 -0
  19. package/cjs/services/request-service/index.js +3 -0
  20. package/cjs/services/setting-service/constants.js +2 -1
  21. package/cjs/services/storage-service/db-stores/InappNotification.js +1 -1
  22. package/cjs/services/substrate-proxy-service/constant.js +1 -1
  23. package/cjs/services/transaction-service/index.js +9 -0
  24. package/cjs/utils/account/transform.js +3 -3
  25. package/core/substrate/xcm-parser.d.ts +1 -0
  26. package/core/substrate/xcm-parser.js +7 -11
  27. package/koni/background/handlers/Extension.d.ts +20 -0
  28. package/koni/background/handlers/Extension.js +218 -6
  29. package/koni/background/handlers/Tabs.js +2 -3
  30. package/package.json +6 -6
  31. package/packageInfo.js +1 -1
  32. package/services/balance-service/index.js +6 -1
  33. package/services/chain-service/index.js +1 -1
  34. package/services/chain-service/utils/patch.d.ts +1 -1
  35. package/services/chain-service/utils/patch.js +1 -1
  36. package/services/earning-service/constants/chains.d.ts +1 -0
  37. package/services/earning-service/constants/chains.js +2 -0
  38. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +1 -0
  39. package/services/earning-service/handlers/liquid-staking/stella-swap.js +6 -4
  40. package/services/earning-service/handlers/native-staking/dtao.d.ts +2 -10
  41. package/services/earning-service/handlers/native-staking/dtao.js +86 -116
  42. package/services/earning-service/handlers/native-staking/tanssi.js +2 -1
  43. package/services/earning-service/handlers/native-staking/tao.d.ts +4 -3
  44. package/services/earning-service/handlers/native-staking/tao.js +84 -101
  45. package/services/earning-service/service.d.ts +2 -1
  46. package/services/earning-service/service.js +37 -6
  47. package/services/inapp-notification-service/interfaces.d.ts +1 -0
  48. package/services/multisig-service/index.js +1 -1
  49. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
  50. package/services/request-service/handler/SubstrateRequestHandler.js +12 -0
  51. package/services/request-service/index.d.ts +1 -0
  52. package/services/request-service/index.js +3 -0
  53. package/services/request-service/types.d.ts +1 -0
  54. package/services/setting-service/constants.js +2 -1
  55. package/services/storage-service/db-stores/InappNotification.js +1 -1
  56. package/services/substrate-proxy-service/constant.js +1 -1
  57. package/services/transaction-service/index.d.ts +1 -1
  58. package/services/transaction-service/index.js +9 -0
  59. package/types/balance/transfer.d.ts +2 -0
  60. package/types/multisig/index.d.ts +12 -0
  61. package/types/yield/actions/join/submit.d.ts +8 -1
  62. package/types/yield/info/account/info.d.ts +11 -5
  63. package/utils/account/transform.js +3 -3
@@ -810,7 +810,12 @@ class BalanceService {
810
810
  /** Return token slugs with balance in substrate chain - only work with substrate chains that have subscanSlug **/
811
811
  async getSubstrateTokensBalanceByChain(address, chainSlug, assetsByChain) {
812
812
  const tokenBalanceSlugs = [];
813
- const balanceData = await this.state.subscanService.getMultiChainBalance(address);
813
+
814
+ // Do not block chain enabling flow when balance detection fails.
815
+ const balanceData = await this.state.subscanService.getMultiChainBalance(address).catch(e => {
816
+ console.error(e);
817
+ return [];
818
+ });
814
819
  if (!balanceData) {
815
820
  return [];
816
821
  }
@@ -1446,10 +1446,10 @@ class ChainService {
1446
1446
  paraId: params.chainSpec.paraId,
1447
1447
  symbol: params.chainEditInfo.symbol,
1448
1448
  genesisHash: params.chainSpec.genesisHash,
1449
+ supportProxy: false,
1449
1450
  relaySlug: null,
1450
1451
  hasNativeNft: false,
1451
1452
  supportStaking: params.chainSpec.paraId === null,
1452
- supportProxy: false,
1453
1453
  supportMultisig: false,
1454
1454
  supportSmartContract: null
1455
1455
  };
@@ -12,7 +12,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
12
12
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
13
13
  const fetchDomain = process.env.PATCH_CHAIN_LIST_URL || (PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev');
14
14
  const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
15
- const ChainListVersion = '0.2.123'; // update this when build chain-list
15
+ const ChainListVersion = '0.2.126'; // update this when build chain-list
16
16
 
17
17
  // todo: move this interface to chainlist
18
18
  exports.ChainListVersion = ChainListVersion;
@@ -3,7 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports._STAKING_CHAIN_GROUP = exports.TON_CHAINS = exports.ST_LIQUID_TOKEN_ABI = exports.STAKING_IDENTITY_API_SLUG = exports.RELAY_HANDLER_DIRECT_STAKING_CHAINS = exports.MaxEraRewardPointsEras = exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = exports.MANTA_MIN_DELEGATION = exports.CHANNEL_ID = void 0;
6
+ exports._STAKING_CHAIN_GROUP = exports.TON_CHAINS = exports.SUNSETTED_YIELD_POOL_SLUGS = exports.ST_LIQUID_TOKEN_ABI = exports.STAKING_IDENTITY_API_SLUG = exports.RELAY_HANDLER_DIRECT_STAKING_CHAINS = exports.MaxEraRewardPointsEras = exports.MANTA_VALIDATOR_POINTS_PER_BLOCK = exports.MANTA_MIN_DELEGATION = exports.CHANNEL_ID = void 0;
7
+ var _stellaSwap = require("../handlers/liquid-staking/stella-swap");
7
8
  // Copyright 2019-2022 @subwallet/extension-base
8
9
  // SPDX-License-Identifier: Apache-2.0
9
10
 
@@ -29,6 +30,8 @@ const _STAKING_CHAIN_GROUP = {
29
30
  tanssi: ['tanssi', 'dancelight']
30
31
  };
31
32
  exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
33
+ const SUNSETTED_YIELD_POOL_SLUGS = [_stellaSwap.STELLA_SWAP_LIQUID_STAKING_SLUG, 'MANTA___native_staking___manta_network'];
34
+ exports.SUNSETTED_YIELD_POOL_SLUGS = SUNSETTED_YIELD_POOL_SLUGS;
32
35
  const RELAY_HANDLER_DIRECT_STAKING_CHAINS = [..._STAKING_CHAIN_GROUP.relay, ..._STAKING_CHAIN_GROUP.assetHub];
33
36
  exports.RELAY_HANDLER_DIRECT_STAKING_CHAINS = RELAY_HANDLER_DIRECT_STAKING_CHAINS;
34
37
  const TON_CHAINS = ['ton', 'ton_testnet'];
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getStellaswapLiquidStakingContract = exports.default = void 0;
7
+ exports.getStellaswapLiquidStakingContract = exports.default = exports.STELLA_SWAP_LIQUID_STAKING_SLUG = void 0;
8
8
  var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
9
9
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
10
10
  var _web = require("@subwallet/extension-base/koni/api/contract-handler/evm/web3");
@@ -28,6 +28,8 @@ exports.getStellaswapLiquidStakingContract = getStellaswapLiquidStakingContract;
28
28
  const APR_STATS_URL = 'https://stdot-apr.stellaswap.com/';
29
29
  const SUBWALLET_REFERRAL = '0x7e6815f45E624768548d085231f2d453f16FD7DD';
30
30
  const TOP_HOLDER = '0x4300e09284e3bB4d9044DdAB31EfAF5f3301DABa';
31
+ const STELLA_SWAP_LIQUID_STAKING_SLUG = 'xcDOT___liquid_staking___stellaswap';
32
+ exports.STELLA_SWAP_LIQUID_STAKING_SLUG = STELLA_SWAP_LIQUID_STAKING_SLUG;
31
33
  class StellaSwapLiquidStakingPoolHandler extends _base.default {
32
34
  inputAsset = 'moonbeam-LOCAL-xcDOT';
33
35
  altInputAsset = '';
@@ -37,8 +39,8 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
37
39
  transactionChainType = _KoniTypes.ChainType.EVM;
38
40
  rateDecimals = 10; // Derivative asset decimals
39
41
  availableMethod = {
40
- join: true,
41
- defaultUnstake: true,
42
+ join: false,
43
+ defaultUnstake: false,
42
44
  fastUnstake: false,
43
45
  cancelUnstake: false,
44
46
  withdraw: true,
@@ -47,7 +49,7 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
47
49
  };
48
50
  constructor(state, chain) {
49
51
  super(state, chain);
50
- this.slug = 'xcDOT___liquid_staking___stellaswap';
52
+ this.slug = STELLA_SWAP_LIQUID_STAKING_SLUG;
51
53
  this.name = 'StellaSwap Liquid Staking';
52
54
  this._logo = 'stellaswap';
53
55
  this.shortName = 'StellaSwap';
@@ -170,7 +172,8 @@ class StellaSwapLiquidStakingPoolHandler extends _base.default {
170
172
  unstakeBalance: unlockBalance.toString(),
171
173
  isBondedBefore: totalBalance.gt(_util.BN_ZERO),
172
174
  derivativeToken: derivativeTokenSlug,
173
- status: activeBalance.gt(_util.BN_ZERO) ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_EARNING,
175
+ // StellaSwap announced all stDOT positions are auto-unstaking, so rewards are no longer earned.
176
+ status: _types.EarningStatus.NOT_EARNING,
174
177
  nominations: [],
175
178
  unstakings
176
179
  };
@@ -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;