@subwallet/extension-base 1.3.1 → 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.
Files changed (65) hide show
  1. package/background/KoniTypes.d.ts +5 -1
  2. package/cjs/constants/index.js +7 -1
  3. package/cjs/koni/api/nft/assethub_nft/index.js +30 -7
  4. package/cjs/koni/api/nft/config.js +11 -1
  5. package/cjs/koni/api/nft/index.js +9 -0
  6. package/cjs/koni/api/nft/ternoa_nft/index.js +174 -0
  7. package/cjs/koni/api/staking/bonding/utils.js +1 -1
  8. package/cjs/koni/background/handlers/Extension.js +67 -32
  9. package/cjs/packageInfo.js +1 -1
  10. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +9 -0
  11. package/cjs/services/chain-service/constants.js +2 -1
  12. package/cjs/services/chain-service/index.js +11 -14
  13. package/cjs/services/earning-service/constants/chains.js +2 -1
  14. package/cjs/services/earning-service/handlers/base.js +2 -1
  15. package/cjs/services/earning-service/handlers/native-staking/index.js +8 -1
  16. package/cjs/services/earning-service/handlers/native-staking/tao.js +394 -0
  17. package/cjs/services/earning-service/service.js +3 -0
  18. package/cjs/services/earning-service/utils/index.js +2 -0
  19. package/cjs/services/keyring-service/context/handlers/Modify.js +11 -3
  20. package/cjs/services/keyring-service/context/state.js +2 -3
  21. package/cjs/services/keyring-service/index.js +1 -1
  22. package/cjs/services/swap-service/handler/chainflip-handler.js +13 -5
  23. package/cjs/services/transaction-service/utils.js +6 -0
  24. package/cjs/types/swap/index.js +4 -2
  25. package/cjs/utils/account/derive/info/solo.js +2 -0
  26. package/cjs/utils/account/derive/info/unified.js +2 -0
  27. package/cjs/utils/account/transform.js +4 -4
  28. package/constants/index.d.ts +2 -0
  29. package/constants/index.js +2 -0
  30. package/koni/api/nft/assethub_nft/index.d.ts +2 -0
  31. package/koni/api/nft/assethub_nft/index.js +30 -7
  32. package/koni/api/nft/config.d.ts +4 -0
  33. package/koni/api/nft/config.js +6 -0
  34. package/koni/api/nft/index.js +9 -0
  35. package/koni/api/nft/ternoa_nft/index.d.ts +32 -0
  36. package/koni/api/nft/ternoa_nft/index.js +167 -0
  37. package/koni/api/staking/bonding/utils.js +1 -1
  38. package/koni/background/handlers/Extension.d.ts +1 -0
  39. package/koni/background/handlers/Extension.js +38 -3
  40. package/package.json +16 -6
  41. package/packageInfo.js +1 -1
  42. package/services/balance-service/helpers/subscribe/substrate/index.js +9 -0
  43. package/services/chain-service/constants.d.ts +1 -0
  44. package/services/chain-service/constants.js +2 -1
  45. package/services/chain-service/index.js +11 -14
  46. package/services/earning-service/constants/chains.d.ts +1 -0
  47. package/services/earning-service/constants/chains.js +2 -1
  48. package/services/earning-service/handlers/base.js +2 -1
  49. package/services/earning-service/handlers/native-staking/index.d.ts +1 -0
  50. package/services/earning-service/handlers/native-staking/index.js +2 -1
  51. package/services/earning-service/handlers/native-staking/tao.d.ts +49 -0
  52. package/services/earning-service/handlers/native-staking/tao.js +378 -0
  53. package/services/earning-service/service.js +4 -1
  54. package/services/earning-service/utils/index.js +2 -0
  55. package/services/keyring-service/context/handlers/Modify.js +11 -3
  56. package/services/keyring-service/context/state.js +2 -3
  57. package/services/keyring-service/index.d.ts +1 -1
  58. package/services/keyring-service/index.js +1 -1
  59. package/services/swap-service/handler/chainflip-handler.js +13 -5
  60. package/services/transaction-service/utils.js +6 -0
  61. package/types/swap/index.d.ts +1 -0
  62. package/types/swap/index.js +2 -1
  63. package/utils/account/derive/info/solo.js +2 -0
  64. package/utils/account/derive/info/unified.js +2 -0
  65. package/utils/account/transform.js +4 -4
@@ -138,6 +138,13 @@ const subscribeWithSystemAccountPallet = async _ref => {
138
138
  args: addresses
139
139
  });
140
140
  }
141
+ let bittensorStakingBalances = new Array(addresses.length).fill(new _bignumber.default(0));
142
+ if (['bittensor'].includes(chainInfo.slug)) {
143
+ bittensorStakingBalances = await Promise.all(addresses.map(async address => {
144
+ const TaoTotalStake = await substrateApi.api.query.subtensorModule.totalColdkeyStake(address);
145
+ return new _bignumber.default(TaoTotalStake.toString());
146
+ }));
147
+ }
141
148
  const subscription = substrateApi.subscribeDataWithMulti(params, rs => {
142
149
  const balances = rs[systemAccountKey];
143
150
  const poolMemberInfos = rs[poolMembersKey];
@@ -151,6 +158,8 @@ const subscribeWithSystemAccountPallet = async _ref => {
151
158
  const nominationPoolBalance = poolMemberInfo ? (0, _nominationpoolsPallet._getTotalStakeInNominationPool)(poolMemberInfo) : BigInt(0);
152
159
  totalLockedFromTransfer += nominationPoolBalance;
153
160
  }
161
+ const stakeValue = BigInt(bittensorStakingBalances[index].toString());
162
+ totalLockedFromTransfer += stakeValue;
154
163
  return {
155
164
  address: addresses[index],
156
165
  tokenSlug: (0, _utils2._getChainNativeTokenSlug)(chainInfo),
@@ -64,7 +64,8 @@ const _NFT_CHAIN_GROUP = {
64
64
  unique_evm: ['unique_evm'],
65
65
  bitcountry: ['bitcountry', 'pioneer', 'continuum_network'],
66
66
  vara: ['vara_network'],
67
- avail: ['avail_mainnet']
67
+ avail: ['avail_mainnet'],
68
+ ternoa: ['ternoa', 'ternoa_alphanet']
68
69
  };
69
70
 
70
71
  // Staking--------------------------------------------------------------------------------------------------------------
@@ -1603,21 +1603,18 @@ class ChainService {
1603
1603
  const assetSettings = await this.getAssetSettings();
1604
1604
  const activeChainSlugs = this.getActiveChainSlugs();
1605
1605
  const assetRegistry = this.getAssetRegistry();
1606
- if (Object.keys(assetSettings).length === 0) {
1607
- // only initiate the first time
1608
- Object.values(assetRegistry).forEach(assetInfo => {
1609
- const isSettingExisted = (assetInfo.slug in assetSettings);
1606
+ Object.values(assetRegistry).forEach(assetInfo => {
1607
+ const isSettingExisted = (assetInfo.slug in assetSettings);
1610
1608
 
1611
- // Set visible for every enabled chains
1612
- if (activeChainSlugs.includes(assetInfo.originChain) && !isSettingExisted) {
1613
- // Setting only exist when set either by chain settings or user
1614
- assetSettings[assetInfo.slug] = {
1615
- visible: true
1616
- };
1617
- }
1618
- });
1619
- this.setAssetSettings(assetSettings, false);
1620
- }
1609
+ // Set visible for every enabled chains
1610
+ if (activeChainSlugs.includes(assetInfo.originChain) && !isSettingExisted) {
1611
+ // Setting only exist when set either by chain settings or user
1612
+ assetSettings[assetInfo.slug] = {
1613
+ visible: true
1614
+ };
1615
+ }
1616
+ });
1617
+ this.setAssetSettings(assetSettings, false);
1621
1618
  this.eventService.emit('asset.ready', true);
1622
1619
  }
1623
1620
  setAssetSettings(assetSettings) {
@@ -22,7 +22,8 @@ const _STAKING_CHAIN_GROUP = {
22
22
  liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
23
23
  lending: ['interlay'],
24
24
  krest_network: ['krest_network'],
25
- manta: ['manta_network']
25
+ manta: ['manta_network'],
26
+ bittensor: ['bittensor', 'bittensor_devnet']
26
27
  };
27
28
  exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
28
29
  const TON_CHAINS = ['ton', 'ton_testnet'];
@@ -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() {
@@ -28,7 +28,14 @@ Object.defineProperty(exports, "RelayNativeStakingPoolHandler", {
28
28
  return _relayChain.default;
29
29
  }
30
30
  });
31
+ Object.defineProperty(exports, "TaoNativeStakingPoolHandler", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _tao.default;
35
+ }
36
+ });
31
37
  var _amplitude = _interopRequireDefault(require("./amplitude"));
32
38
  var _astar = _interopRequireDefault(require("./astar"));
33
39
  var _relayChain = _interopRequireDefault(require("./relay-chain"));
34
- var _paraChain = _interopRequireDefault(require("./para-chain"));
40
+ var _paraChain = _interopRequireDefault(require("./para-chain"));
41
+ var _tao = _interopRequireDefault(require("./tao"));
@@ -0,0 +1,394 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.bittensorApiKey = exports.BITTENSOR_API_KEY_2 = exports.BITTENSOR_API_KEY_1 = void 0;
8
+ exports.fetchDelegates = fetchDelegates;
9
+ exports.fetchTaoDelegateState = fetchTaoDelegateState;
10
+ var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
11
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
12
+ var _constants = require("@subwallet/extension-base/constants");
13
+ var _utils = require("@subwallet/extension-base/koni/api/staking/bonding/utils");
14
+ var _basePara = _interopRequireDefault(require("@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para"));
15
+ var _types = require("@subwallet/extension-base/types");
16
+ var _utils2 = require("@subwallet/extension-base/utils");
17
+ var _bignumber = _interopRequireDefault(require("bignumber.js"));
18
+ var _util = require("@polkadot/util");
19
+ var _utils3 = require("../../utils");
20
+ // Copyright 2019-2022 @subwallet/extension-base
21
+ // SPDX-License-Identifier: Apache-2.0
22
+
23
+ const BITTENSOR_API_KEY_1 = process.env.BITTENSOR_API_KEY_1 || '';
24
+ exports.BITTENSOR_API_KEY_1 = BITTENSOR_API_KEY_1;
25
+ const BITTENSOR_API_KEY_2 = process.env.BITTENSOR_API_KEY_2 || '';
26
+ exports.BITTENSOR_API_KEY_2 = BITTENSOR_API_KEY_2;
27
+ function random() {
28
+ for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
29
+ keys[_key] = arguments[_key];
30
+ }
31
+ const validKeys = keys.filter(key => key);
32
+ const randomIndex = Math.floor(Math.random() * validKeys.length);
33
+ return validKeys[randomIndex];
34
+ }
35
+ const bittensorApiKey = () => {
36
+ return random(BITTENSOR_API_KEY_1, BITTENSOR_API_KEY_2);
37
+ };
38
+
39
+ /* Fetch data */
40
+ exports.bittensorApiKey = bittensorApiKey;
41
+ async function fetchDelegates() {
42
+ const apiKey = bittensorApiKey();
43
+ return new Promise(function (resolve) {
44
+ fetch('https://api-prod-v2.taostats.io/api/validator/latest/v1', {
45
+ method: 'GET',
46
+ headers: {
47
+ 'Content-Type': 'application/json',
48
+ Authorization: `${apiKey}`
49
+ }
50
+ }).then(resp => {
51
+ resolve(resp.json());
52
+ }).catch(console.error);
53
+ });
54
+ }
55
+ async function fetchTaoDelegateState(address) {
56
+ const apiKey = bittensorApiKey();
57
+ return new Promise(function (resolve) {
58
+ fetch(`https://api-prod-v2.taostats.io/api/delegation/balance/latest/v1?nominator=${address}`, {
59
+ method: 'GET',
60
+ headers: {
61
+ 'Content-Type': 'application/json',
62
+ Authorization: `${apiKey}`
63
+ }
64
+ }).then(resp => {
65
+ resolve(resp.json());
66
+ }).catch(console.error);
67
+ });
68
+ }
69
+
70
+ /* Fetch data */
71
+
72
+ const testnetDelegate = {
73
+ '5G6wdAdS7hpBuH1tjuZDhpzrGw9Wf71WEVakDCxHDm1cxEQ2': {
74
+ name: '0x436c6f776e4e616d65f09fa4a1',
75
+ url: 'https://example.com ',
76
+ image: 'https://example.com/image.png',
77
+ discord: '0xe28094446973636f7264',
78
+ description: 'This is an example identity.',
79
+ additional: ''
80
+ }
81
+ };
82
+ class TaoNativeStakingPoolHandler extends _basePara.default {
83
+ /* Unimplemented function */
84
+ handleYieldWithdraw(address, unstakingInfo) {
85
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
86
+ }
87
+ handleYieldCancelUnstake(params) {
88
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.UNSUPPORTED));
89
+ }
90
+ /* Unimplemented function */
91
+
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
+ }
98
+
99
+ /* Subscribe pool info */
100
+
101
+ async subscribePoolInfo(callback) {
102
+ let cancel = false;
103
+ const substrateApi = this.substrateApi;
104
+ const updateStakingInfo = async () => {
105
+ try {
106
+ if (cancel) {
107
+ return;
108
+ }
109
+ const minDelegatorStake = await substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
110
+ const BNminDelegatorStake = new _bignumber.default(minDelegatorStake.toString());
111
+ const data = {
112
+ ...this.baseInfo,
113
+ type: this.type,
114
+ metadata: {
115
+ ...this.metadataInfo,
116
+ description: this.getDescription('0')
117
+ },
118
+ statistic: {
119
+ assetEarning: [{
120
+ slug: this.nativeToken.slug
121
+ }],
122
+ maxCandidatePerFarmer: 16,
123
+ maxWithdrawalRequestPerFarmer: 1,
124
+ earningThreshold: {
125
+ join: BNminDelegatorStake.toString(),
126
+ defaultUnstake: '0',
127
+ fastUnstake: '0'
128
+ },
129
+ eraTime: 1.2,
130
+ era: 0,
131
+ unstakingPeriod: 1.2
132
+ }
133
+ };
134
+ callback(data);
135
+ } catch (error) {
136
+ console.log(error);
137
+ }
138
+ };
139
+ const subscribeStakingMetadataInterval = () => {
140
+ updateStakingInfo().catch(console.error);
141
+ };
142
+ await substrateApi.isReady;
143
+ subscribeStakingMetadataInterval();
144
+ const interval = setInterval(subscribeStakingMetadataInterval, _constants.BITTENSOR_REFRESH_STAKE_APY);
145
+ return () => {
146
+ cancel = true;
147
+ clearInterval(interval);
148
+ };
149
+ }
150
+
151
+ /* Subscribe pool position */
152
+
153
+ async parseNominatorMetadata(chainInfo, address, delegatorState) {
154
+ const nominationList = [];
155
+ const getMinDelegatorStake = this.substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
156
+ const minDelegatorStake = (await getMinDelegatorStake).toString();
157
+ let allActiveStake = _util.BN_ZERO;
158
+ for (const delegate of delegatorState) {
159
+ const activeStake = delegate.amount;
160
+ const bnActiveStake = new _util.BN(activeStake);
161
+ if (bnActiveStake.gt(_util.BN_ZERO)) {
162
+ const delegationStatus = _types.EarningStatus.EARNING_REWARD;
163
+ allActiveStake = allActiveStake.add(bnActiveStake);
164
+ nominationList.push({
165
+ status: delegationStatus,
166
+ chain: chainInfo.slug,
167
+ validatorAddress: delegate.owner,
168
+ activeStake: activeStake,
169
+ validatorMinStake: minDelegatorStake
170
+ });
171
+ }
172
+ }
173
+ const stakingStatus = (0, _utils.getEarningStatusByNominations)(allActiveStake, nominationList);
174
+ return {
175
+ status: stakingStatus,
176
+ balanceToken: this.nativeToken.slug,
177
+ totalStake: allActiveStake.toString(),
178
+ activeStake: allActiveStake.toString(),
179
+ unstakeBalance: '0',
180
+ isBondedBefore: true,
181
+ nominations: nominationList,
182
+ unstakings: []
183
+ };
184
+ }
185
+ async subscribePoolPosition(useAddresses, rsCallback) {
186
+ let cancel = false;
187
+ const substrateApi = await this.substrateApi.isReady;
188
+ const defaultInfo = this.baseInfo;
189
+ const chainInfo = this.chainInfo;
190
+ const getDevnetPoolPosition = async () => {
191
+ const testnetAddress = Object.keys(testnetDelegate)[0];
192
+ const delegatorState = [];
193
+ let bnTotalBalance = _util.BN_ZERO;
194
+ const stakePromises = useAddresses.map(async address => {
195
+ const stakeAmount = (await substrateApi.api.query.subtensorModule.stake(testnetAddress, address)).toString();
196
+ const bnStakeAmount = new _util.BN(stakeAmount);
197
+ bnTotalBalance = bnTotalBalance.add(bnStakeAmount);
198
+ delegatorState.push({
199
+ owner: testnetAddress,
200
+ amount: bnStakeAmount.toString()
201
+ });
202
+ rsCallback({
203
+ ...defaultInfo,
204
+ type: this.type,
205
+ address: address,
206
+ balanceToken: this.nativeToken.slug,
207
+ totalStake: bnTotalBalance.toString(),
208
+ activeStake: bnStakeAmount.toString(),
209
+ unstakeBalance: '0',
210
+ status: _types.EarningStatus.EARNING_REWARD,
211
+ isBondedBefore: true,
212
+ nominations: delegatorState.map(delegate => ({
213
+ chain: this.chain,
214
+ validatorAddress: delegate.owner,
215
+ activeStake: delegate.amount,
216
+ status: _types.EarningStatus.EARNING_REWARD
217
+ })),
218
+ unstakings: []
219
+ });
220
+ });
221
+ await Promise.all(stakePromises);
222
+ };
223
+ const getMainnetPoolPosition = async () => {
224
+ const rawDelegateStateInfos = await Promise.all(useAddresses.map(address => fetchTaoDelegateState(address)));
225
+ if (rawDelegateStateInfos.length > 0) {
226
+ rawDelegateStateInfos.forEach((rawDelegateStateInfo, i) => {
227
+ const owner = (0, _utils2.reformatAddress)(useAddresses[i], 42);
228
+ const delegatorState = [];
229
+ let bnTotalBalance = _util.BN_ZERO;
230
+ const delegateStateInfo = rawDelegateStateInfo.data;
231
+ for (const delegate of delegateStateInfo) {
232
+ bnTotalBalance = bnTotalBalance.add(new _util.BN(delegate.balance));
233
+ delegatorState.push({
234
+ owner: delegate.delegate.ss58,
235
+ amount: delegate.balance.toString()
236
+ });
237
+ }
238
+ if (delegateStateInfo && delegateStateInfo.length > 0) {
239
+ this.parseNominatorMetadata(chainInfo, owner, delegatorState).then(nominatorMetadata => {
240
+ rsCallback({
241
+ ...defaultInfo,
242
+ ...nominatorMetadata,
243
+ address: owner,
244
+ type: this.type
245
+ });
246
+ }).catch(console.error);
247
+ } else {
248
+ rsCallback({
249
+ ...defaultInfo,
250
+ type: this.type,
251
+ address: owner,
252
+ balanceToken: this.nativeToken.slug,
253
+ totalStake: '0',
254
+ activeStake: '0',
255
+ unstakeBalance: '0',
256
+ status: _types.EarningStatus.NOT_STAKING,
257
+ isBondedBefore: false,
258
+ nominations: [],
259
+ unstakings: []
260
+ });
261
+ }
262
+ });
263
+ }
264
+ };
265
+ const getStakingPositionInterval = async () => {
266
+ if (cancel) {
267
+ return;
268
+ }
269
+ if (this.chain === 'bittensor_devnet') {
270
+ await getDevnetPoolPosition();
271
+ } else {
272
+ await getMainnetPoolPosition();
273
+ }
274
+ };
275
+ getStakingPositionInterval().catch(console.error);
276
+ const intervalId = setInterval(() => {
277
+ getStakingPositionInterval().catch(console.error);
278
+ }, _constants.BITTENSOR_REFRESH_STAKE_INFO);
279
+ return () => {
280
+ cancel = true;
281
+ clearInterval(intervalId);
282
+ };
283
+ }
284
+
285
+ /* Subscribe pool position */
286
+
287
+ /* Get pool targets */
288
+
289
+ // eslint-disable-next-line @typescript-eslint/require-await
290
+ async getDevnetPoolTargets() {
291
+ const _topValidator = testnetDelegate;
292
+ const validatorAddresses = Object.keys(_topValidator);
293
+ return validatorAddresses.map(address => {
294
+ return {
295
+ address: address,
296
+ totalStake: '0',
297
+ ownStake: '0',
298
+ otherStake: '0',
299
+ minBond: '0',
300
+ nominatorCount: 0,
301
+ commission: '0',
302
+ expectedReturn: 0,
303
+ blocked: false,
304
+ isVerified: false,
305
+ chain: this.chain,
306
+ isCrowded: false,
307
+ identity: address
308
+ };
309
+ });
310
+ }
311
+ async getMainnetPoolTargets() {
312
+ const _topValidator = await fetchDelegates();
313
+ const topValidator = _topValidator;
314
+ const getNominatorMinRequiredStake = this.substrateApi.api.query.subtensorModule.nominatorMinRequiredStake();
315
+ const nominatorMinRequiredStake = (await getNominatorMinRequiredStake).toString();
316
+ const bnMinBond = new _util.BN(nominatorMinRequiredStake);
317
+ const validatorList = topValidator.data;
318
+ const validatorAddresses = Object.keys(validatorList);
319
+ const results = await Promise.all(validatorAddresses.map(i => {
320
+ const address = validatorList[i].hotkey.ss58;
321
+ const bnTotalStake = new _util.BN(validatorList[i].stake);
322
+ const bnOwnStake = new _util.BN(validatorList[i].validator_stake);
323
+ const otherStake = bnTotalStake.sub(bnOwnStake);
324
+ const nominatorCount = validatorList[i].nominators;
325
+ const commission = validatorList[i].take;
326
+ const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
327
+ const apr = (parseFloat(validatorList[i].apr) / 10 ** 9 * 100).toFixed(2);
328
+ const apyCalculate = (0, _utils3.calculateReward)(parseFloat(apr));
329
+ const name = validatorList[i].name || address;
330
+ return {
331
+ address: address,
332
+ totalStake: bnTotalStake.toString(),
333
+ ownStake: bnOwnStake.toString(),
334
+ otherStake: otherStake.toString(),
335
+ minBond: bnMinBond.toString(),
336
+ nominatorCount: nominatorCount,
337
+ commission: roundedCommission,
338
+ expectedReturn: apyCalculate.apy,
339
+ blocked: false,
340
+ isVerified: false,
341
+ chain: this.chain,
342
+ isCrowded: false,
343
+ identity: name
344
+ };
345
+ }));
346
+ return results;
347
+ }
348
+ async getPoolTargets() {
349
+ if (this.chain === 'bittensor_devnet') {
350
+ return this.getDevnetPoolTargets();
351
+ } else {
352
+ return this.getMainnetPoolTargets();
353
+ }
354
+ }
355
+
356
+ /* Get pool targets */
357
+
358
+ /* Join pool action */
359
+
360
+ async createJoinExtrinsic(data, positionInfo) {
361
+ let bondDest = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Staked';
362
+ const {
363
+ amount,
364
+ selectedValidators: targetValidators
365
+ } = data;
366
+ const chainApi = await this.substrateApi.isReady;
367
+ const binaryAmount = new _util.BN(amount);
368
+ const selectedValidatorInfo = targetValidators[0];
369
+ const hotkey = selectedValidatorInfo.address;
370
+ const extrinsic = chainApi.api.tx.subtensorModule.addStake(hotkey, binaryAmount);
371
+ return [extrinsic, {
372
+ slug: this.nativeToken.slug,
373
+ amount: '0'
374
+ }];
375
+ }
376
+
377
+ /* Join pool action */
378
+
379
+ /* Leave pool action */
380
+
381
+ async handleYieldUnstake(amount, address, selectedTarget) {
382
+ const apiPromise = await this.substrateApi.isReady;
383
+ const binaryAmount = new _util.BN(amount);
384
+ const poolPosition = await this.getPoolPosition(address);
385
+ if (!selectedTarget || !poolPosition) {
386
+ return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS));
387
+ }
388
+ const extrinsic = apiPromise.api.tx.subtensorModule.removeStake(selectedTarget, binaryAmount);
389
+ return [_KoniTypes.ExtrinsicType.STAKING_LEAVE_POOL, extrinsic];
390
+ }
391
+
392
+ /* Leave pool action */
393
+ }
394
+ exports.default = TaoNativeStakingPoolHandler;
@@ -72,6 +72,9 @@ class EarningService {
72
72
  if (_constants2._STAKING_CHAIN_GROUP.amplitude.includes(chain)) {
73
73
  handlers.push(new _handlers.AmplitudeNativeStakingPoolHandler(this.state, chain));
74
74
  }
75
+ if (_constants2._STAKING_CHAIN_GROUP.bittensor.includes(chain)) {
76
+ handlers.push(new _handlers.TaoNativeStakingPoolHandler(this.state, chain));
77
+ }
75
78
  if (_constants2._STAKING_CHAIN_GROUP.nominationPool.includes(chain)) {
76
79
  handlers.push(new _handlers.NominationPoolHandler(this.state, chain));
77
80
  }
@@ -116,6 +116,8 @@ function isActionFromValidator(stakingType, chain) {
116
116
  return true;
117
117
  } else if (_constants._STAKING_CHAIN_GROUP.para.includes(chain)) {
118
118
  return true;
119
+ } else if (_constants._STAKING_CHAIN_GROUP.bittensor.includes(chain)) {
120
+ return true;
119
121
  }
120
122
  return false;
121
123
  }
@@ -121,14 +121,16 @@ class AccountModifyHandler extends _Base.AccountBaseHandler {
121
121
  } = _ref2;
122
122
  const modifyPairs = this.state.modifyPairs;
123
123
  const isUnified = this.state.isUnifiedAccount(proxyId);
124
+ const oldAccounts = Object.keys(this.state.accounts);
125
+ const afterDeleteAccounts = oldAccounts.filter(id => id !== proxyId);
124
126
  let addresses;
125
127
  if (!isUnified) {
126
128
  addresses = [proxyId];
127
129
  } else {
128
130
  addresses = Object.keys(modifyPairs).filter(address => modifyPairs[address].accountProxyId === proxyId);
129
- this.state.deleteAccountProxy(proxyId);
130
- this.parentService.eventRemoveAccount(proxyId);
131
131
  }
132
+ this.state.deleteAccountProxy(proxyId);
133
+ this.parentService.eventRemoveAccountProxy(proxyId);
132
134
  for (const address of addresses) {
133
135
  delete modifyPairs[address];
134
136
  }
@@ -137,7 +139,13 @@ class AccountModifyHandler extends _Base.AccountBaseHandler {
137
139
  _uiKeyring.keyring.forgetAccount(address);
138
140
  }
139
141
  await Promise.all(addresses.map(address => new Promise(resolve => this.state.removeAccountRef(address, resolve))));
140
- this.state.saveCurrentAccountProxyId(_constants.ALL_ACCOUNT_KEY);
142
+
143
+ // Cannot use `this.state.accounts` because it is not completely updated yet
144
+ if (afterDeleteAccounts.length > 1) {
145
+ this.state.saveCurrentAccountProxyId(_constants.ALL_ACCOUNT_KEY);
146
+ } else {
147
+ this.state.saveCurrentAccountProxyId(afterDeleteAccounts[0]);
148
+ }
141
149
  return addresses;
142
150
  }
143
151
  tonGetAllTonWalletContractVersion(request) {
@@ -450,12 +450,11 @@ class AccountState {
450
450
  if (proxyId === _constants.ALL_ACCOUNT_KEY) {
451
451
  return allowGetAllAccount ? this.getAllAddresses() : [];
452
452
  }
453
- const accountProxies = this._accountProxy.value;
454
- const modifyPairs = this._modifyPair.value;
453
+ const accountProxies = this.accounts;
455
454
  if (!accountProxies[proxyId]) {
456
455
  return [proxyId];
457
456
  } else {
458
- return Object.keys(modifyPairs).filter(address => modifyPairs[address].accountProxyId === proxyId);
457
+ return accountProxies[proxyId].accounts.map(account => account.address);
459
458
  }
460
459
  }
461
460
 
@@ -29,7 +29,7 @@ class KeyringService {
29
29
  eventInjectReady() {
30
30
  this.state.eventService.emit('inject.ready', true);
31
31
  }
32
- eventRemoveAccount(proxyId) {
32
+ eventRemoveAccountProxy(proxyId) {
33
33
  this.state.eventService.emit('accountProxy.remove', proxyId);
34
34
  }
35
35
  updateKeyringState() {
@@ -238,7 +238,6 @@ class ChainflipSwapHandler {
238
238
  switch (fee.type) {
239
239
  case ChainflipFeeType.INGRESS:
240
240
  {
241
- console.log('ingress', fee);
242
241
  feeComponent.push({
243
242
  tokenSlug: fromAsset.slug,
244
243
  amount: fee.amount,
@@ -250,7 +249,6 @@ class ChainflipSwapHandler {
250
249
  // eslint-disable-next-line no-fallthrough
251
250
  case ChainflipFeeType.EGRESS:
252
251
  {
253
- console.log('egress', fee);
254
252
  feeComponent.push({
255
253
  tokenSlug: toAsset.slug,
256
254
  amount: fee.amount,
@@ -266,7 +264,6 @@ class ChainflipSwapHandler {
266
264
  // eslint-disable-next-line no-fallthrough
267
265
  case ChainflipFeeType.BROKER:
268
266
  {
269
- console.log('broker fee', fee);
270
267
  feeComponent.push({
271
268
  tokenSlug: this.intermediaryAssetSlug,
272
269
  amount: fee.amount,
@@ -343,7 +340,8 @@ class ChainflipSwapHandler {
343
340
  const {
344
341
  address,
345
342
  quote,
346
- recipient
343
+ recipient,
344
+ slippage
347
345
  } = params;
348
346
  const pair = quote.pair;
349
347
  const fromAsset = this.chainService.getAssetBySlug(pair.from);
@@ -355,14 +353,24 @@ class ChainflipSwapHandler {
355
353
  const destChainId = this.chainMapping[toAsset.originChain];
356
354
  const fromAssetId = (0, _utils._getAssetSymbol)(fromAsset);
357
355
  const toAssetId = (0, _utils._getAssetSymbol)(toAsset);
356
+ const minReceive = new _bignumber.default(quote.rate).times(1 - slippage).toString();
358
357
  const depositAddressResponse = await this.swapSdk.requestDepositAddress({
359
358
  srcChain: srcChainId,
360
359
  destChain: destChainId,
361
360
  srcAsset: fromAssetId,
362
361
  destAsset: toAssetId,
363
362
  destAddress: receiver,
364
- amount: quote.fromAmount
363
+ amount: quote.fromAmount,
364
+ fillOrKillParams: {
365
+ minPrice: minReceive,
366
+ // minimum accepted price for swaps through the channel
367
+ refundAddress: address,
368
+ // address to which assets are refunded
369
+ retryDurationBlocks: 100 // 100 blocks * 6 seconds = 10 minutes before deposits are refunded
370
+ }
365
371
  });
372
+
373
+ console.log('depositAddressResp', depositAddressResponse);
366
374
  const txData = {
367
375
  address,
368
376
  provider: this.providerInfo,
@@ -36,6 +36,9 @@ function getBlockExplorerAccountRoute(explorerLink) {
36
36
  if (explorerLink.includes('invarch.statescan.io')) {
37
37
  return '#/accounts';
38
38
  }
39
+ if (explorerLink.includes('explorer.zkverify.io')) {
40
+ return 'account';
41
+ }
39
42
  return 'address';
40
43
  }
41
44
  function getBlockExplorerTxRoute(chainInfo) {
@@ -57,6 +60,9 @@ function getExplorerLink(chainInfo, value, type) {
57
60
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
58
61
  }
59
62
  if (explorerLink && value.startsWith('0x')) {
63
+ if (chainInfo.slug === 'bittensor') {
64
+ return undefined;
65
+ }
60
66
  const route = getBlockExplorerTxRoute(chainInfo);
61
67
  return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}${route}/${value}`;
62
68
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = void 0;
6
+ exports._SUPPORTED_SWAP_PROVIDERS = exports.SwapStepType = exports.SwapProviderId = exports.SwapFeeType = exports.SwapErrorType = exports.CHAINFLIP_SLIPPAGE = void 0;
7
7
  // Copyright 2019-2022 @subwallet/extension-base
8
8
  // SPDX-License-Identifier: Apache-2.0
9
9
  // core
@@ -47,4 +47,6 @@ exports.SwapFeeType = SwapFeeType;
47
47
  SwapFeeType["PLATFORM_FEE"] = "PLATFORM_FEE";
48
48
  SwapFeeType["NETWORK_FEE"] = "NETWORK_FEE";
49
49
  SwapFeeType["WALLET_FEE"] = "WALLET_FEE";
50
- })(SwapFeeType || (exports.SwapFeeType = SwapFeeType = {}));
50
+ })(SwapFeeType || (exports.SwapFeeType = SwapFeeType = {}));
51
+ const CHAINFLIP_SLIPPAGE = 0.02; // Example: 0.01 for 1%
52
+ exports.CHAINFLIP_SLIPPAGE = CHAINFLIP_SLIPPAGE;