@subwallet/extension-base 1.3.2-0 → 1.3.3-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.
@@ -30,6 +30,21 @@ class AssetHubNftsPalletApi extends _nft.BaseNftApi {
30
30
  }
31
31
  }).then(res => res.json());
32
32
  }
33
+ processImageUrl(image, isKodadot, isTokenInfo) {
34
+ if (!image) {
35
+ return undefined;
36
+ }
37
+ if (isKodadot) {
38
+ return isTokenInfo ? image.replace('ipfs://ipfs/', 'https://image.w.kodadot.xyz/ipfs/') : image.replace('ipfs://', 'https://image.w.kodadot.xyz/ipfs/');
39
+ }
40
+ return this.parseUrl(image);
41
+ }
42
+ parseTokenInfo(tokenInfo, classId) {
43
+ if (classId === '244' && tokenInfo) {
44
+ return JSON.parse(tokenInfo);
45
+ }
46
+ return tokenInfo;
47
+ }
33
48
 
34
49
  /**
35
50
  * Retrieve id of NFTs
@@ -87,8 +102,6 @@ class AssetHubNftsPalletApi extends _nft.BaseNftApi {
87
102
  return this.getMetadata(collectionMetadata === null || collectionMetadata === void 0 ? void 0 : collectionMetadata.data);
88
103
  }
89
104
  async handleNft(address, params) {
90
- // const start = performance.now();
91
-
92
105
  const assetIds = await this.getNfts([address]);
93
106
  try {
94
107
  if (!assetIds || assetIds.length === 0) {
@@ -97,18 +110,28 @@ class AssetHubNftsPalletApi extends _nft.BaseNftApi {
97
110
  const collectionIds = [];
98
111
  const nftIds = [];
99
112
  await Promise.all(assetIds.map(async assetId => {
113
+ var _tokenInfo2, _tokenInfo3, _tokenInfo4;
100
114
  const parsedClassId = this.parseTokenId(assetId.classId);
101
115
  const parsedTokenId = this.parseTokenId(assetId.tokenId);
102
116
  if (!collectionIds.includes(parsedClassId)) {
103
117
  collectionIds.push(parsedClassId);
104
118
  }
105
119
  nftIds.push(parsedTokenId);
106
- const [tokenInfo, collectionMeta] = await Promise.all([this.getTokenDetails(assetId), this.getCollectionDetail(parseInt(parsedClassId))]);
120
+ let [tokenInfo, collectionMeta] = await Promise.all([this.getTokenDetails(assetId), this.getCollectionDetail(parseInt(parsedClassId))]);
121
+ const isKodadot = assetId.classId === '244';
122
+ tokenInfo = this.parseTokenInfo(tokenInfo, assetId.classId);
123
+ if (tokenInfo) {
124
+ var _tokenInfo;
125
+ tokenInfo.image = this.processImageUrl((_tokenInfo = tokenInfo) === null || _tokenInfo === void 0 ? void 0 : _tokenInfo.image, isKodadot, true);
126
+ }
127
+ if (collectionMeta) {
128
+ collectionMeta.image = this.processImageUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image, isKodadot, false);
129
+ }
107
130
  const parsedNft = {
108
131
  id: parsedTokenId,
109
- name: tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.name,
110
- description: tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.description,
111
- image: tokenInfo && tokenInfo.image ? this.parseUrl(tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.image) : undefined,
132
+ name: (_tokenInfo2 = tokenInfo) === null || _tokenInfo2 === void 0 ? void 0 : _tokenInfo2.name,
133
+ description: (_tokenInfo3 = tokenInfo) === null || _tokenInfo3 === void 0 ? void 0 : _tokenInfo3.description,
134
+ image: (_tokenInfo4 = tokenInfo) === null || _tokenInfo4 === void 0 ? void 0 : _tokenInfo4.image,
112
135
  collectionId: this.parseTokenId(parsedClassId),
113
136
  chain: this.chain,
114
137
  owner: address,
@@ -119,7 +142,7 @@ class AssetHubNftsPalletApi extends _nft.BaseNftApi {
119
142
  collectionId: parsedClassId,
120
143
  chain: this.chain,
121
144
  collectionName: collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.name,
122
- image: collectionMeta && collectionMeta.image ? this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image) : undefined
145
+ image: collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image
123
146
  };
124
147
  params.updateCollection(this.chain, parsedCollection);
125
148
  }));
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.3.2-0'
16
+ version: '1.3.3-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -19,9 +19,7 @@ var _wasm = require("@subwallet/extension-base/koni/api/contract-handler/wasm");
19
19
  var _utils = require("@subwallet/extension-base/koni/api/contract-handler/wasm/utils");
20
20
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
21
21
  var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
22
- var _tao = require("@subwallet/extension-base/services/earning-service/handlers/native-staking/tao");
23
- var _utils3 = require("@subwallet/extension-base/services/earning-service/utils");
24
- var _utils4 = require("@subwallet/extension-base/utils");
22
+ var _utils3 = require("@subwallet/extension-base/utils");
25
23
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
26
24
  var _evm = require("../evm");
27
25
  var _equilibrium = require("./equilibrium");
@@ -140,11 +138,11 @@ const subscribeWithSystemAccountPallet = async _ref => {
140
138
  args: addresses
141
139
  });
142
140
  }
143
- let bittensorStakingBalances = new Array(addresses.length).fill(BigInt(0));
141
+ let bittensorStakingBalances = new Array(addresses.length).fill(new _bignumber.default(0));
144
142
  if (['bittensor'].includes(chainInfo.slug)) {
145
143
  bittensorStakingBalances = await Promise.all(addresses.map(async address => {
146
- const rawDelegateState = await (0, _tao.fetchTaoDelegateState)(address);
147
- return (0, _utils3.getTaoTotalStake)(rawDelegateState);
144
+ const TaoTotalStake = await substrateApi.api.query.subtensorModule.totalColdkeyStake(address);
145
+ return new _bignumber.default(TaoTotalStake.toString());
148
146
  }));
149
147
  }
150
148
  const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
@@ -160,7 +158,8 @@ const subscribeWithSystemAccountPallet = async _ref => {
160
158
  const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) : BigInt(0);
161
159
  totalLockedFromTransfer += nominationPoolBalance;
162
160
  }
163
- totalLockedFromTransfer += bittensorStakingBalances[index];
161
+ const stakeValue = BigInt(bittensorStakingBalances[index].toString());
162
+ totalLockedFromTransfer += stakeValue;
164
163
  return {
165
164
  address: addresses[index],
166
165
  tokenSlug: (0, _utils2._getChainNativeTokenSlug)(chainInfo),
@@ -199,7 +198,7 @@ const subscribeForeignAssetBalance = async _ref2 => {
199
198
  substrateApi
200
199
  } = _ref2;
201
200
  const foreignAssetsAccountKey = 'query_foreignAssets_account';
202
- const tokenMap = (0, _utils4.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
201
+ const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
203
202
  const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
204
203
  try {
205
204
  if ((0, _utils2._isBridgedToken)(tokenInfo)) {
@@ -266,7 +265,7 @@ const subscribePSP22Balance = _ref3 => {
266
265
  } = _ref3;
267
266
  const chain = chainInfo.slug;
268
267
  const psp22ContractMap = {};
269
- const tokenList = (0, _utils4.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.PSP22]);
268
+ const tokenList = (0, _utils3.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.PSP22]);
270
269
  Object.entries(tokenList).forEach(_ref4 => {
271
270
  let [slug, tokenInfo] = _ref4;
272
271
  psp22ContractMap[slug] = (0, _wasm.getPSP22ContractPromise)(substrateApi.api, (0, _utils2._getContractAddressOfToken)(tokenInfo));
@@ -327,7 +326,7 @@ const subscribeTokensAccountsPallet = async _ref5 => {
327
326
  } = _ref5;
328
327
  const tokensAccountsKey = 'query_tokens_accounts';
329
328
  const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
330
- const tokenMap = (0, _utils4.filterAssetsByChainAndType)(assetMap, chainInfo.slug, tokenTypes);
329
+ const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, tokenTypes);
331
330
  const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
332
331
  try {
333
332
  const params = [{
@@ -373,7 +372,7 @@ const subscribeAssetsAccountPallet = async _ref6 => {
373
372
  substrateApi
374
373
  } = _ref6;
375
374
  const assetsAccountKey = 'query_assets_account';
376
- const tokenMap = (0, _utils4.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
375
+ const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
377
376
  Object.values(tokenMap).forEach(token => {
378
377
  if (_constants2._MANTA_ZK_CHAIN_GROUP.includes(token.originChain) && token.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
379
378
  delete tokenMap[token.slug];
@@ -442,7 +441,7 @@ const subscribeOrmlTokensPallet = async _ref7 => {
442
441
  substrateApi
443
442
  } = _ref7;
444
443
  const ormlTokensAccountsKey = 'query_ormlTokens_accounts';
445
- const tokenMap = (0, _utils4.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
444
+ const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, [_types._AssetType.LOCAL]);
446
445
  const unsubList = Object.values(tokenMap).map(tokenInfo => {
447
446
  try {
448
447
  const params = [{
@@ -82,7 +82,8 @@ class BasePoolHandler {
82
82
  const decimals = this.nativeToken.decimals || 0;
83
83
  const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
84
84
  const ed = new _util.BN(this.nativeToken.minAmount || '0');
85
- const maintainBalance = ed.gte(defaultMaintainBalance) ? new _util.BN(15).mul(ed).div(_util.BN_TEN) : defaultMaintainBalance;
85
+ const calculateMaintainBalance = new _util.BN(15).mul(ed).div(_util.BN_TEN);
86
+ const maintainBalance = ed.gte(defaultMaintainBalance) ? calculateMaintainBalance : defaultMaintainBalance;
86
87
  return maintainBalance.toString();
87
88
  }
88
89
  get metadataInfo() {
@@ -20,12 +20,6 @@ var _utils3 = require("../../utils");
20
20
  // Copyright 2019-2022 @subwallet/extension-base
21
21
  // SPDX-License-Identifier: Apache-2.0
22
22
 
23
- // interface ValidatorName {
24
- // count: number;
25
- // delegates: {
26
- // name: string;
27
- // }[];
28
- // }
29
23
  const BITTENSOR_API_KEY_1 = process.env.BITTENSOR_API_KEY_1 || '';
30
24
  exports.BITTENSOR_API_KEY_1 = BITTENSOR_API_KEY_1;
31
25
  const BITTENSOR_API_KEY_2 = process.env.BITTENSOR_API_KEY_2 || '';
@@ -47,7 +41,7 @@ exports.bittensorApiKey = bittensorApiKey;
47
41
  async function fetchDelegates() {
48
42
  const apiKey = bittensorApiKey();
49
43
  return new Promise(function (resolve) {
50
- fetch('https://api.taostats.io/api/v1/validator?order=amount%3Adesc&limit=100', {
44
+ fetch('https://api-prod-v2.taostats.io/api/validator/latest/v1', {
51
45
  method: 'GET',
52
46
  headers: {
53
47
  'Content-Type': 'application/json',
@@ -61,7 +55,7 @@ async function fetchDelegates() {
61
55
  async function fetchTaoDelegateState(address) {
62
56
  const apiKey = bittensorApiKey();
63
57
  return new Promise(function (resolve) {
64
- fetch(`https://api.taostats.io/api/v1/delegate/balance?nominator_address=${address}`, {
58
+ fetch(`https://api-prod-v2.taostats.io/api/delegation/balance/latest/v1?nominator=${address}`, {
65
59
  method: 'GET',
66
60
  headers: {
67
61
  'Content-Type': 'application/json',
@@ -95,21 +89,12 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
95
89
  }
96
90
  /* Unimplemented function */
97
91
 
98
- // async fetchDelegatesInfo (address: string): Promise<ValidatorName> {
99
- // const apiKey = this.bittensorApiKey;
100
-
101
- // return new Promise(function (resolve) {
102
- // fetch(`https://api.taostats.io/api/v1/delegate/info?address=${address}`, {
103
- // method: 'GET',
104
- // headers: {
105
- // 'Content-Type': 'application/json',
106
- // Authorization: `${apiKey}`
107
- // }
108
- // }).then((resp) => {
109
- // resolve(resp.json());
110
- // }).catch(console.error);
111
- // });
112
- // }
92
+ get maintainBalance() {
93
+ const ed = new _util.BN(this.nativeToken.minAmount || '0');
94
+ const calculateMaintainBalance = new _util.BN(15).mul(ed).div(_util.BN_TEN);
95
+ const maintainBalance = calculateMaintainBalance;
96
+ return maintainBalance.toString();
97
+ }
113
98
 
114
99
  /* Subscribe pool info */
115
100
 
@@ -242,11 +227,11 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
242
227
  const owner = (0, _utils2.reformatAddress)(useAddresses[i], 42);
243
228
  const delegatorState = [];
244
229
  let bnTotalBalance = _util.BN_ZERO;
245
- const delegateStateInfo = rawDelegateStateInfo.items;
230
+ const delegateStateInfo = rawDelegateStateInfo.data;
246
231
  for (const delegate of delegateStateInfo) {
247
232
  bnTotalBalance = bnTotalBalance.add(new _util.BN(delegate.balance));
248
233
  delegatorState.push({
249
- owner: delegate.delegate_address.ss58,
234
+ owner: delegate.delegate.ss58,
250
235
  amount: delegate.balance.toString()
251
236
  });
252
237
  }
@@ -329,11 +314,11 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
329
314
  const getNominatorMinRequiredStake = this.substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
330
315
  const nominatorMinRequiredStake = (await getNominatorMinRequiredStake).toString();
331
316
  const bnMinBond = new _util.BN(nominatorMinRequiredStake);
332
- const validatorList = topValidator.validators;
317
+ const validatorList = topValidator.data;
333
318
  const validatorAddresses = Object.keys(validatorList);
334
319
  const results = await Promise.all(validatorAddresses.map(i => {
335
- const address = validatorList[i].hot_key.ss58;
336
- const bnTotalStake = new _util.BN(validatorList[i].amount);
320
+ const address = validatorList[i].hotkey.ss58;
321
+ const bnTotalStake = new _util.BN(validatorList[i].stake);
337
322
  const bnOwnStake = new _util.BN(validatorList[i].validator_stake);
338
323
  const otherStake = bnTotalStake.sub(bnOwnStake);
339
324
  const nominatorCount = validatorList[i].nominators;
@@ -341,12 +326,7 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
341
326
  const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
342
327
  const apr = (parseFloat(validatorList[i].apr) / 10 ** 9 * 100).toFixed(2);
343
328
  const apyCalculate = (0, _utils3.calculateReward)(parseFloat(apr));
344
-
345
- // let name = '';
346
- // const delegateInfo = await this.fetchDelegatesInfo(address);
347
-
348
- // name = delegateInfo.delegates[0]?.name || address;
349
-
329
+ const name = validatorList[i].name || address;
350
330
  return {
351
331
  address: address,
352
332
  totalStake: bnTotalStake.toString(),
@@ -360,10 +340,9 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
360
340
  isVerified: false,
361
341
  chain: this.chain,
362
342
  isCrowded: false,
363
- identity: address // name
343
+ identity: name
364
344
  };
365
345
  }));
366
-
367
346
  return results;
368
347
  }
369
348
  async getPoolTargets() {
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyDecimal = applyDecimal;
7
7
  exports.calculateReward = calculateReward;
8
- exports.getTaoTotalStake = getTaoTotalStake;
9
8
  exports.isActionFromValidator = isActionFromValidator;
10
9
  exports.isNominationPool = exports.isNativeStakingPool = exports.isLiquidPool = exports.isLendingPool = void 0;
11
10
  exports.parseIdentity = parseIdentity;
@@ -141,14 +140,4 @@ exports.isLendingPool = isLendingPool;
141
140
  function applyDecimal(bnNumber, decimals) {
142
141
  const bnDecimals = new _util.BN((10 ** decimals).toString());
143
142
  return bnNumber.div(bnDecimals);
144
- }
145
- function getTaoTotalStake(rawDelegateState) {
146
- const nodeInfos = rawDelegateState.items;
147
- const stakes = nodeInfos.map(stake => stake.balance);
148
- let totalStake = BigInt(0);
149
- for (const _stake of stakes) {
150
- const stakeAmount = BigInt(_stake);
151
- totalStake += stakeAmount;
152
- }
153
- return totalStake;
154
143
  }
@@ -60,6 +60,9 @@ function getExplorerLink(chainInfo, value, type) {
60
60
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
61
61
  }
62
62
  if (explorerLink && value.startsWith('0x')) {
63
+ if (chainInfo.slug === 'bittensor') {
64
+ return undefined;
65
+ }
63
66
  const route = getBlockExplorerTxRoute(chainInfo);
64
67
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
65
68
  }
@@ -3,6 +3,8 @@ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/
3
3
  export default class AssetHubNftsPalletApi extends BaseNftApi {
4
4
  constructor(api: _SubstrateApi | null, addresses: string[], chain: string);
5
5
  private getMetadata;
6
+ private processImageUrl;
7
+ private parseTokenInfo;
6
8
  /**
7
9
  * Retrieve id of NFTs
8
10
  *
@@ -24,6 +24,21 @@ export default class AssetHubNftsPalletApi extends BaseNftApi {
24
24
  }
25
25
  }).then(res => res.json());
26
26
  }
27
+ processImageUrl(image, isKodadot, isTokenInfo) {
28
+ if (!image) {
29
+ return undefined;
30
+ }
31
+ if (isKodadot) {
32
+ return isTokenInfo ? image.replace('ipfs://ipfs/', 'https://image.w.kodadot.xyz/ipfs/') : image.replace('ipfs://', 'https://image.w.kodadot.xyz/ipfs/');
33
+ }
34
+ return this.parseUrl(image);
35
+ }
36
+ parseTokenInfo(tokenInfo, classId) {
37
+ if (classId === '244' && tokenInfo) {
38
+ return JSON.parse(tokenInfo);
39
+ }
40
+ return tokenInfo;
41
+ }
27
42
 
28
43
  /**
29
44
  * Retrieve id of NFTs
@@ -81,8 +96,6 @@ export default class AssetHubNftsPalletApi extends BaseNftApi {
81
96
  return this.getMetadata(collectionMetadata === null || collectionMetadata === void 0 ? void 0 : collectionMetadata.data);
82
97
  }
83
98
  async handleNft(address, params) {
84
- // const start = performance.now();
85
-
86
99
  const assetIds = await this.getNfts([address]);
87
100
  try {
88
101
  if (!assetIds || assetIds.length === 0) {
@@ -91,18 +104,28 @@ export default class AssetHubNftsPalletApi extends BaseNftApi {
91
104
  const collectionIds = [];
92
105
  const nftIds = [];
93
106
  await Promise.all(assetIds.map(async assetId => {
107
+ var _tokenInfo2, _tokenInfo3, _tokenInfo4;
94
108
  const parsedClassId = this.parseTokenId(assetId.classId);
95
109
  const parsedTokenId = this.parseTokenId(assetId.tokenId);
96
110
  if (!collectionIds.includes(parsedClassId)) {
97
111
  collectionIds.push(parsedClassId);
98
112
  }
99
113
  nftIds.push(parsedTokenId);
100
- const [tokenInfo, collectionMeta] = await Promise.all([this.getTokenDetails(assetId), this.getCollectionDetail(parseInt(parsedClassId))]);
114
+ let [tokenInfo, collectionMeta] = await Promise.all([this.getTokenDetails(assetId), this.getCollectionDetail(parseInt(parsedClassId))]);
115
+ const isKodadot = assetId.classId === '244';
116
+ tokenInfo = this.parseTokenInfo(tokenInfo, assetId.classId);
117
+ if (tokenInfo) {
118
+ var _tokenInfo;
119
+ tokenInfo.image = this.processImageUrl((_tokenInfo = tokenInfo) === null || _tokenInfo === void 0 ? void 0 : _tokenInfo.image, isKodadot, true);
120
+ }
121
+ if (collectionMeta) {
122
+ collectionMeta.image = this.processImageUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image, isKodadot, false);
123
+ }
101
124
  const parsedNft = {
102
125
  id: parsedTokenId,
103
- name: tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.name,
104
- description: tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.description,
105
- image: tokenInfo && tokenInfo.image ? this.parseUrl(tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.image) : undefined,
126
+ name: (_tokenInfo2 = tokenInfo) === null || _tokenInfo2 === void 0 ? void 0 : _tokenInfo2.name,
127
+ description: (_tokenInfo3 = tokenInfo) === null || _tokenInfo3 === void 0 ? void 0 : _tokenInfo3.description,
128
+ image: (_tokenInfo4 = tokenInfo) === null || _tokenInfo4 === void 0 ? void 0 : _tokenInfo4.image,
106
129
  collectionId: this.parseTokenId(parsedClassId),
107
130
  chain: this.chain,
108
131
  owner: address,
@@ -113,7 +136,7 @@ export default class AssetHubNftsPalletApi extends BaseNftApi {
113
136
  collectionId: parsedClassId,
114
137
  chain: this.chain,
115
138
  collectionName: collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.name,
116
- image: collectionMeta && collectionMeta.image ? this.parseUrl(collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image) : undefined
139
+ image: collectionMeta === null || collectionMeta === void 0 ? void 0 : collectionMeta.image
117
140
  };
118
141
  params.updateCollection(this.chain, parsedCollection);
119
142
  }));
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "./cjs/detectPackage.js"
18
18
  ],
19
19
  "type": "module",
20
- "version": "1.3.2-0",
20
+ "version": "1.3.3-0",
21
21
  "main": "./cjs/index.js",
22
22
  "module": "./index.js",
23
23
  "types": "./index.d.ts",
@@ -2381,11 +2381,11 @@
2381
2381
  "@reduxjs/toolkit": "^1.9.1",
2382
2382
  "@sora-substrate/type-definitions": "^1.17.7",
2383
2383
  "@substrate/connect": "^0.8.9",
2384
- "@subwallet/chain-list": "0.2.89",
2385
- "@subwallet/extension-base": "^1.3.2-0",
2386
- "@subwallet/extension-chains": "^1.3.2-0",
2387
- "@subwallet/extension-dapp": "^1.3.2-0",
2388
- "@subwallet/extension-inject": "^1.3.2-0",
2384
+ "@subwallet/chain-list": "0.2.90",
2385
+ "@subwallet/extension-base": "^1.3.3-0",
2386
+ "@subwallet/extension-chains": "^1.3.3-0",
2387
+ "@subwallet/extension-dapp": "^1.3.3-0",
2388
+ "@subwallet/extension-inject": "^1.3.3-0",
2389
2389
  "@subwallet/keyring": "^0.1.8-beta.0",
2390
2390
  "@subwallet/ui-keyring": "^0.1.8-beta.0",
2391
2391
  "@ton/core": "^0.56.3",
package/packageInfo.js CHANGED
@@ -7,5 +7,5 @@ export const packageInfo = {
7
7
  name: '@subwallet/extension-base',
8
8
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
9
9
  type: 'esm',
10
- version: '1.3.2-0'
10
+ version: '1.3.3-0'
11
11
  };
@@ -15,8 +15,6 @@ import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/cont
15
15
  import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
16
16
  import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
17
17
  import { _checkSmartContractSupportByChain, _getAssetExistentialDeposit, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
18
- import { fetchTaoDelegateState } from '@subwallet/extension-base/services/earning-service/handlers/native-staking/tao';
19
- import { getTaoTotalStake } from '@subwallet/extension-base/services/earning-service/utils';
20
18
  import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
21
19
  import BigN from 'bignumber.js';
22
20
  import { subscribeERC20Interval } from "../evm.js";
@@ -131,11 +129,11 @@ const subscribeWithSystemAccountPallet = async ({
131
129
  args: addresses
132
130
  });
133
131
  }
134
- let bittensorStakingBalances = new Array(addresses.length).fill(BigInt(0));
132
+ let bittensorStakingBalances = new Array(addresses.length).fill(new BigN(0));
135
133
  if (['bittensor'].includes(chainInfo.slug)) {
136
134
  bittensorStakingBalances = await Promise.all(addresses.map(async address => {
137
- const rawDelegateState = await fetchTaoDelegateState(address);
138
- return getTaoTotalStake(rawDelegateState);
135
+ const TaoTotalStake = await substrateApi.api.query.subtensorModule.totalColdkeyStake(address);
136
+ return new BigN(TaoTotalStake.toString());
139
137
  }));
140
138
  }
141
139
  const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
@@ -151,7 +149,8 @@ const subscribeWithSystemAccountPallet = async ({
151
149
  const nominationPoolBalance = poolMemberInfo ? _getTotalStakeInNominationPool(poolMemberInfo) : BigInt(0);
152
150
  totalLockedFromTransfer += nominationPoolBalance;
153
151
  }
154
- totalLockedFromTransfer += bittensorStakingBalances[index];
152
+ const stakeValue = BigInt(bittensorStakingBalances[index].toString());
153
+ totalLockedFromTransfer += stakeValue;
155
154
  return {
156
155
  address: addresses[index],
157
156
  tokenSlug: _getChainNativeTokenSlug(chainInfo),
@@ -77,7 +77,8 @@ export default class BasePoolHandler {
77
77
  const decimals = this.nativeToken.decimals || 0;
78
78
  const defaultMaintainBalance = new BN(1).mul(BN_TEN.pow(new BN(decimals)));
79
79
  const ed = new BN(this.nativeToken.minAmount || '0');
80
- const maintainBalance = ed.gte(defaultMaintainBalance) ? new BN(15).mul(ed).div(BN_TEN) : defaultMaintainBalance;
80
+ const calculateMaintainBalance = new BN(15).mul(ed).div(BN_TEN);
81
+ const maintainBalance = ed.gte(defaultMaintainBalance) ? calculateMaintainBalance : defaultMaintainBalance;
81
82
  return maintainBalance.toString();
82
83
  }
83
84
  get metadataInfo() {
@@ -7,27 +7,26 @@ interface TaoStakingStakeOption {
7
7
  amount: string;
8
8
  }
9
9
  export interface RawDelegateState {
10
- items: Array<{
11
- balance: string;
12
- delegate_address: {
10
+ data: Array<{
11
+ delegate: {
13
12
  ss58: string;
14
13
  };
14
+ balance: string;
15
15
  }>;
16
16
  }
17
17
  interface ValidatorResponse {
18
- count: number;
19
- validators: Validator[];
18
+ data: Validator[];
20
19
  }
21
20
  interface Validator {
22
- validator_stake: string;
23
- amount: string;
24
- nominators: number;
25
- apr: string;
26
- hot_key: {
21
+ hotkey: {
27
22
  ss58: string;
28
23
  };
24
+ name: string;
25
+ nominators: number;
26
+ stake: string;
27
+ validator_stake: string;
29
28
  take: string;
30
- system_total_stake: string;
29
+ apr: string;
31
30
  }
32
31
  export declare const BITTENSOR_API_KEY_1: string;
33
32
  export declare const BITTENSOR_API_KEY_2: string;
@@ -37,6 +36,7 @@ export declare function fetchTaoDelegateState(address: string): Promise<RawDeleg
37
36
  export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHandler {
38
37
  handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
39
38
  handleYieldCancelUnstake(params: StakeCancelWithdrawalParams): Promise<TransactionData>;
39
+ get maintainBalance(): string;
40
40
  subscribePoolInfo(callback: (data: YieldPoolInfo) => void): Promise<VoidFunction>;
41
41
  parseNominatorMetadata(chainInfo: _ChainInfo, address: string, delegatorState: TaoStakingStakeOption[]): Promise<Omit<YieldPositionInfo, keyof BaseYieldPositionInfo>>;
42
42
  subscribePoolPosition(useAddresses: string[], rsCallback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
@@ -9,14 +9,8 @@ import BaseParaStakingPoolHandler from '@subwallet/extension-base/services/earni
9
9
  import { BasicTxErrorType, EarningStatus } from '@subwallet/extension-base/types';
10
10
  import { reformatAddress } from '@subwallet/extension-base/utils';
11
11
  import BigN from 'bignumber.js';
12
- import { BN, BN_ZERO } from '@polkadot/util';
12
+ import { BN, BN_TEN, BN_ZERO } from '@polkadot/util';
13
13
  import { calculateReward } from "../../utils/index.js";
14
- // interface ValidatorName {
15
- // count: number;
16
- // delegates: {
17
- // name: string;
18
- // }[];
19
- // }
20
14
  export const BITTENSOR_API_KEY_1 = process.env.BITTENSOR_API_KEY_1 || '';
21
15
  export const BITTENSOR_API_KEY_2 = process.env.BITTENSOR_API_KEY_2 || '';
22
16
  function random(...keys) {
@@ -33,7 +27,7 @@ export const bittensorApiKey = () => {
33
27
  export async function fetchDelegates() {
34
28
  const apiKey = bittensorApiKey();
35
29
  return new Promise(function (resolve) {
36
- fetch('https://api.taostats.io/api/v1/validator?order=amount%3Adesc&limit=100', {
30
+ fetch('https://api-prod-v2.taostats.io/api/validator/latest/v1', {
37
31
  method: 'GET',
38
32
  headers: {
39
33
  'Content-Type': 'application/json',
@@ -47,7 +41,7 @@ export async function fetchDelegates() {
47
41
  export async function fetchTaoDelegateState(address) {
48
42
  const apiKey = bittensorApiKey();
49
43
  return new Promise(function (resolve) {
50
- fetch(`https://api.taostats.io/api/v1/delegate/balance?nominator_address=${address}`, {
44
+ fetch(`https://api-prod-v2.taostats.io/api/delegation/balance/latest/v1?nominator=${address}`, {
51
45
  method: 'GET',
52
46
  headers: {
53
47
  'Content-Type': 'application/json',
@@ -81,21 +75,12 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
81
75
  }
82
76
  /* Unimplemented function */
83
77
 
84
- // async fetchDelegatesInfo (address: string): Promise<ValidatorName> {
85
- // const apiKey = this.bittensorApiKey;
86
-
87
- // return new Promise(function (resolve) {
88
- // fetch(`https://api.taostats.io/api/v1/delegate/info?address=${address}`, {
89
- // method: 'GET',
90
- // headers: {
91
- // 'Content-Type': 'application/json',
92
- // Authorization: `${apiKey}`
93
- // }
94
- // }).then((resp) => {
95
- // resolve(resp.json());
96
- // }).catch(console.error);
97
- // });
98
- // }
78
+ get maintainBalance() {
79
+ const ed = new BN(this.nativeToken.minAmount || '0');
80
+ const calculateMaintainBalance = new BN(15).mul(ed).div(BN_TEN);
81
+ const maintainBalance = calculateMaintainBalance;
82
+ return maintainBalance.toString();
83
+ }
99
84
 
100
85
  /* Subscribe pool info */
101
86
 
@@ -228,11 +213,11 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
228
213
  const owner = reformatAddress(useAddresses[i], 42);
229
214
  const delegatorState = [];
230
215
  let bnTotalBalance = BN_ZERO;
231
- const delegateStateInfo = rawDelegateStateInfo.items;
216
+ const delegateStateInfo = rawDelegateStateInfo.data;
232
217
  for (const delegate of delegateStateInfo) {
233
218
  bnTotalBalance = bnTotalBalance.add(new BN(delegate.balance));
234
219
  delegatorState.push({
235
- owner: delegate.delegate_address.ss58,
220
+ owner: delegate.delegate.ss58,
236
221
  amount: delegate.balance.toString()
237
222
  });
238
223
  }
@@ -315,11 +300,11 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
315
300
  const getNominatorMinRequiredStake = this.substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
316
301
  const nominatorMinRequiredStake = (await getNominatorMinRequiredStake).toString();
317
302
  const bnMinBond = new BN(nominatorMinRequiredStake);
318
- const validatorList = topValidator.validators;
303
+ const validatorList = topValidator.data;
319
304
  const validatorAddresses = Object.keys(validatorList);
320
305
  const results = await Promise.all(validatorAddresses.map(i => {
321
- const address = validatorList[i].hot_key.ss58;
322
- const bnTotalStake = new BN(validatorList[i].amount);
306
+ const address = validatorList[i].hotkey.ss58;
307
+ const bnTotalStake = new BN(validatorList[i].stake);
323
308
  const bnOwnStake = new BN(validatorList[i].validator_stake);
324
309
  const otherStake = bnTotalStake.sub(bnOwnStake);
325
310
  const nominatorCount = validatorList[i].nominators;
@@ -327,12 +312,7 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
327
312
  const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
328
313
  const apr = (parseFloat(validatorList[i].apr) / 10 ** 9 * 100).toFixed(2);
329
314
  const apyCalculate = calculateReward(parseFloat(apr));
330
-
331
- // let name = '';
332
- // const delegateInfo = await this.fetchDelegatesInfo(address);
333
-
334
- // name = delegateInfo.delegates[0]?.name || address;
335
-
315
+ const name = validatorList[i].name || address;
336
316
  return {
337
317
  address: address,
338
318
  totalStake: bnTotalStake.toString(),
@@ -346,10 +326,9 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
346
326
  isVerified: false,
347
327
  chain: this.chain,
348
328
  isCrowded: false,
349
- identity: address // name
329
+ identity: name
350
330
  };
351
331
  }));
352
-
353
332
  return results;
354
333
  }
355
334
  async getPoolTargets() {
@@ -1,5 +1,4 @@
1
1
  import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
2
- import { RawDelegateState } from '@subwallet/extension-base/services/earning-service/handlers/native-staking/tao';
3
2
  import { LendingYieldPoolInfo, LiquidYieldPoolInfo, NativeYieldPoolInfo, NominationYieldPoolInfo, YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
4
3
  import { BN } from '@polkadot/util';
5
4
  export declare function calculateReward(apr: number, amount?: number, compoundingPeriod?: YieldCompoundingPeriod, isApy?: boolean): YieldAssetExpectedEarning;
@@ -19,4 +18,3 @@ export declare const isNativeStakingPool: (pool: YieldPoolInfo) => pool is Nativ
19
18
  export declare const isLiquidPool: (pool: YieldPoolInfo) => pool is LiquidYieldPoolInfo;
20
19
  export declare const isLendingPool: (pool: YieldPoolInfo) => pool is LendingYieldPoolInfo;
21
20
  export declare function applyDecimal(bnNumber: BN, decimals: number): BN;
22
- export declare function getTaoTotalStake(rawDelegateState: RawDelegateState): bigint;
@@ -123,14 +123,4 @@ export const isLendingPool = pool => {
123
123
  export function applyDecimal(bnNumber, decimals) {
124
124
  const bnDecimals = new BN((10 ** decimals).toString());
125
125
  return bnNumber.div(bnDecimals);
126
- }
127
- export function getTaoTotalStake(rawDelegateState) {
128
- const nodeInfos = rawDelegateState.items;
129
- const stakes = nodeInfos.map(stake => stake.balance);
130
- let totalStake = BigInt(0);
131
- for (const _stake of stakes) {
132
- const stakeAmount = BigInt(_stake);
133
- totalStake += stakeAmount;
134
- }
135
- return totalStake;
136
126
  }
@@ -52,6 +52,9 @@ export function getExplorerLink(chainInfo, value, type) {
52
52
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
53
53
  }
54
54
  if (explorerLink && value.startsWith('0x')) {
55
+ if (chainInfo.slug === 'bittensor') {
56
+ return undefined;
57
+ }
55
58
  const route = getBlockExplorerTxRoute(chainInfo);
56
59
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
57
60
  }