@subwallet/extension-base 1.1.31-beta.0 → 1.1.32-beta.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 (84) hide show
  1. package/background/KoniTypes.d.ts +1 -0
  2. package/cjs/koni/api/staking/bonding/index.js +2 -0
  3. package/cjs/koni/api/staking/bonding/paraChain.js +6 -3
  4. package/cjs/koni/background/cron.js +0 -28
  5. package/cjs/koni/background/handlers/Extension.js +17 -11
  6. package/cjs/koni/background/handlers/State.js +4 -46
  7. package/cjs/koni/background/subscription.js +0 -155
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/campaign-service/index.js +19 -0
  10. package/cjs/services/chain-service/constants.js +3 -2
  11. package/cjs/services/earning-service/constants/chains.js +1 -1
  12. package/cjs/services/earning-service/handlers/base.js +9 -6
  13. package/cjs/services/earning-service/handlers/lending/base.js +61 -0
  14. package/cjs/services/earning-service/handlers/lending/interlay.js +3 -2
  15. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +3 -2
  16. package/cjs/services/earning-service/handlers/liquid-staking/base.js +54 -0
  17. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +3 -2
  18. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +3 -2
  19. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -7
  20. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +7 -2
  21. package/cjs/services/earning-service/handlers/native-staking/astar.js +7 -2
  22. package/cjs/services/earning-service/handlers/native-staking/base.js +4 -2
  23. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +7 -2
  24. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +12 -3
  25. package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -3
  26. package/cjs/services/earning-service/handlers/special.js +57 -67
  27. package/cjs/services/earning-service/service.js +370 -37
  28. package/cjs/services/event-service/index.js +1 -0
  29. package/cjs/services/migration-service/scripts/index.js +1 -2
  30. package/cjs/services/storage-service/DatabaseService.js +15 -0
  31. package/cjs/services/storage-service/db-stores/Campaign.js +9 -3
  32. package/cjs/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  33. package/cjs/services/transaction-service/index.js +15 -1
  34. package/cjs/utils/number.js +3 -1
  35. package/koni/api/staking/bonding/index.d.ts +1 -0
  36. package/koni/api/staking/bonding/index.js +2 -0
  37. package/koni/api/staking/bonding/paraChain.js +6 -3
  38. package/koni/background/cron.d.ts +0 -5
  39. package/koni/background/cron.js +1 -29
  40. package/koni/background/handlers/Extension.js +17 -11
  41. package/koni/background/handlers/State.d.ts +1 -12
  42. package/koni/background/handlers/State.js +4 -46
  43. package/koni/background/subscription.d.ts +1 -11
  44. package/koni/background/subscription.js +2 -157
  45. package/package.json +6 -6
  46. package/packageInfo.js +1 -1
  47. package/services/campaign-service/index.js +19 -0
  48. package/services/chain-service/constants.js +3 -2
  49. package/services/earning-service/constants/chains.js +1 -1
  50. package/services/earning-service/handlers/base.d.ts +1 -0
  51. package/services/earning-service/handlers/base.js +9 -6
  52. package/services/earning-service/handlers/lending/base.d.ts +2 -0
  53. package/services/earning-service/handlers/lending/base.js +61 -0
  54. package/services/earning-service/handlers/lending/interlay.js +4 -3
  55. package/services/earning-service/handlers/liquid-staking/acala.js +4 -3
  56. package/services/earning-service/handlers/liquid-staking/base.d.ts +2 -0
  57. package/services/earning-service/handlers/liquid-staking/base.js +55 -1
  58. package/services/earning-service/handlers/liquid-staking/bifrost.js +4 -3
  59. package/services/earning-service/handlers/liquid-staking/parallel.js +4 -3
  60. package/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -7
  61. package/services/earning-service/handlers/native-staking/amplitude.js +7 -2
  62. package/services/earning-service/handlers/native-staking/astar.js +7 -2
  63. package/services/earning-service/handlers/native-staking/base.js +5 -3
  64. package/services/earning-service/handlers/native-staking/para-chain.js +7 -2
  65. package/services/earning-service/handlers/native-staking/relay-chain.js +12 -3
  66. package/services/earning-service/handlers/nomination-pool/index.js +10 -4
  67. package/services/earning-service/handlers/special.d.ts +0 -1
  68. package/services/earning-service/handlers/special.js +58 -68
  69. package/services/earning-service/service.d.ts +49 -1
  70. package/services/earning-service/service.js +358 -28
  71. package/services/event-service/index.d.ts +1 -0
  72. package/services/event-service/index.js +1 -0
  73. package/services/event-service/types.d.ts +1 -0
  74. package/services/migration-service/scripts/index.js +1 -2
  75. package/services/storage-service/DatabaseService.d.ts +5 -0
  76. package/services/storage-service/DatabaseService.js +15 -0
  77. package/services/storage-service/db-stores/Campaign.js +9 -3
  78. package/services/storage-service/db-stores/YieldPositionStore.d.ts +2 -0
  79. package/services/storage-service/db-stores/YieldPositionStore.js +6 -0
  80. package/services/transaction-service/index.js +15 -1
  81. package/types/yield/actions/join/submit.d.ts +2 -1
  82. package/types/yield/info/account/reward.d.ts +2 -0
  83. package/utils/number.d.ts +1 -0
  84. package/utils/number.js +1 -0
@@ -1574,6 +1574,7 @@ export interface BaseCampaignData {
1574
1574
  slug: string;
1575
1575
  campaignId: number;
1576
1576
  isDone: boolean;
1577
+ isArchive: boolean;
1577
1578
  type: CampaignDataType;
1578
1579
  data: Record<string, any>;
1579
1580
  buttons: CampaignButton[];
@@ -41,6 +41,8 @@ function validateBondingCondition(chainInfo, amount, selectedValidators, address
41
41
  }
42
42
  return (0, _paraChain.validateParaChainBondingCondition)(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata);
43
43
  }
44
+
45
+ /** Deprecated */
44
46
  async function getChainStakingMetadata(chainInfo, substrateApi) {
45
47
  if (_constants._STAKING_CHAIN_GROUP.astar.includes(chainInfo.slug)) {
46
48
  return (0, _astar.getAstarStakingMetadata)(chainInfo.slug, substrateApi);
@@ -107,17 +107,18 @@ function validateParaChainBondingCondition(chainInfo, amount, selectedCollators,
107
107
  }
108
108
  function subscribeParaChainStakingMetadata(chain, substrateApi, callback) {
109
109
  return substrateApi.api.query.parachainStaking.round(_round => {
110
- var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3;
110
+ var _substrateApi$api$con, _substrateApi$api$con2, _substrateApi$api$con3, _substrateApi$api$con4, _substrateApi$api$con5, _substrateApi$api$con6;
111
111
  const roundObj = _round.toHuman();
112
112
  const round = (0, _utils4.parseRawNumber)(roundObj.current);
113
113
  const maxDelegations = (_substrateApi$api$con = substrateApi.api.consts) === null || _substrateApi$api$con === void 0 ? void 0 : (_substrateApi$api$con2 = _substrateApi$api$con.parachainStaking) === null || _substrateApi$api$con2 === void 0 ? void 0 : (_substrateApi$api$con3 = _substrateApi$api$con2.maxDelegationsPerDelegator) === null || _substrateApi$api$con3 === void 0 ? void 0 : _substrateApi$api$con3.toString();
114
114
  const unstakingDelay = substrateApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
115
115
  const unstakingPeriod = parseInt(unstakingDelay) * (_constants._STAKING_ERA_LENGTH_MAP[chain] || _constants._STAKING_ERA_LENGTH_MAP.default);
116
+ const minDelegatorStake = (_substrateApi$api$con4 = substrateApi.api.consts) === null || _substrateApi$api$con4 === void 0 ? void 0 : (_substrateApi$api$con5 = _substrateApi$api$con4.parachainStaking) === null || _substrateApi$api$con5 === void 0 ? void 0 : (_substrateApi$api$con6 = _substrateApi$api$con5.minDelegatorStk) === null || _substrateApi$api$con6 === void 0 ? void 0 : _substrateApi$api$con6.toString();
116
117
  callback(chain, {
117
118
  chain,
118
119
  type: _KoniTypes.StakingType.NOMINATED,
119
120
  era: round,
120
- minStake: '0',
121
+ minStake: minDelegatorStake || '0',
121
122
  maxValidatorPerNominator: parseInt(maxDelegations),
122
123
  maxWithdrawalRequestPerValidator: 1,
123
124
  // by default
@@ -127,11 +128,13 @@ function subscribeParaChainStakingMetadata(chain, substrateApi, callback) {
127
128
  });
128
129
  }
129
130
  async function getParaChainStakingMetadata(chain, substrateApi) {
131
+ var _chainApi$api$consts$, _chainApi$api$consts$2;
130
132
  const chainApi = await substrateApi.isReady;
131
133
  const _round = (await chainApi.api.query.parachainStaking.round()).toHuman();
132
134
  const round = (0, _utils4.parseRawNumber)(_round.current);
133
135
  const maxDelegations = chainApi.api.consts.parachainStaking.maxDelegationsPerDelegator.toString();
134
136
  const unstakingDelay = chainApi.api.consts.parachainStaking.delegationBondLessDelay.toString();
137
+ const minDelegatorStake = (_chainApi$api$consts$ = chainApi.api.consts.parachainStaking) === null || _chainApi$api$consts$ === void 0 ? void 0 : (_chainApi$api$consts$2 = _chainApi$api$consts$.minDelegatorStk) === null || _chainApi$api$consts$2 === void 0 ? void 0 : _chainApi$api$consts$2.toString();
135
138
  let _unvestedAllocation;
136
139
  if (chainApi.api.query.vesting && chainApi.api.query.vesting.totalUnvestedAllocation) {
137
140
  _unvestedAllocation = await chainApi.api.query.vesting.totalUnvestedAllocation();
@@ -156,7 +159,7 @@ async function getParaChainStakingMetadata(chain, substrateApi) {
156
159
  type: _KoniTypes.StakingType.NOMINATED,
157
160
  era: round,
158
161
  inflation,
159
- minStake: '0',
162
+ minStake: minDelegatorStake || '0',
160
163
  maxValidatorPerNominator: parseInt(maxDelegations),
161
164
  maxWithdrawalRequestPerValidator: 1,
162
165
  // by default
@@ -8,7 +8,6 @@ var _constants = require("@subwallet/extension-base/constants");
8
8
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
9
9
  var _utils2 = require("@subwallet/extension-base/utils");
10
10
  var _rxjs = require("rxjs");
11
- var _util = require("@polkadot/util");
12
11
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
13
12
  // SPDX-License-Identifier: Apache-2.0
14
13
 
@@ -18,7 +17,6 @@ class KoniCron {
18
17
  this.subscriptions = subscriptions;
19
18
  this.dbService = dbService;
20
19
  this.state = state;
21
- this.logger = (0, _util.logger)('Cron');
22
20
  // this.init();
23
21
  }
24
22
 
@@ -106,10 +104,6 @@ class KoniCron {
106
104
  // only add cron jobs if there's at least 1 active network
107
105
  (commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
108
106
  reloadMantaPay && this.addCron('syncMantaPay', this.syncMantaPay, _constants.CRON_SYNC_MANTA_PAY);
109
- (commonReload || chainUpdated) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
110
- (commonReload || chainUpdated) && this.addCron('refreshEarningRewardHistoryInterval', this.refreshEarningRewardHistoryInterval(currentAccountInfo.address), _constants.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
111
- } else {
112
- this.setStakingRewardReady();
113
107
  }
114
108
  };
115
109
  this.state.eventService.onLazy(this.eventHandler);
@@ -120,11 +114,7 @@ class KoniCron {
120
114
  this.resetNft(currentAccountInfo.address);
121
115
  this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), _constants.CRON_REFRESH_NFT_INTERVAL);
122
116
  // this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
123
- this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), _constants.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
124
- this.addCron('refreshEarningRewardHistoryInterval', this.refreshEarningRewardHistoryInterval(currentAccountInfo.address), _constants.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
125
117
  this.addCron('syncMantaPay', this.syncMantaPay, _constants.CRON_SYNC_MANTA_PAY);
126
- } else {
127
- this.setStakingRewardReady();
128
118
  }
129
119
  this.status = 'running';
130
120
  };
@@ -159,24 +149,6 @@ class KoniCron {
159
149
  resetNft = newAddress => {
160
150
  this.state.resetNft(newAddress);
161
151
  };
162
- refreshStakingReward = address => {
163
- return () => {
164
- this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
165
- };
166
- };
167
- refreshStakingRewardFastInterval = address => {
168
- return () => {
169
- this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
170
- };
171
- };
172
- refreshEarningRewardHistoryInterval = address => {
173
- return () => {
174
- this.subscriptions.subscribeEarningRewardHistoryInterval(address).catch(this.logger.error);
175
- };
176
- };
177
- setStakingRewardReady = () => {
178
- this.state.updateStakingRewardReady(true);
179
- };
180
152
  checkNetworkAvailable = serviceInfo => {
181
153
  return Object.keys(serviceInfo.chainApiMap.substrate).length > 0 || Object.keys(serviceInfo.chainApiMap.evm).length > 0;
182
154
  };
@@ -3655,18 +3655,19 @@ class KoniExtension {
3655
3655
  this.#koniState.keyringService.removeInjectAccounts(request.addresses);
3656
3656
  return true;
3657
3657
  }
3658
- subscribeYieldPoolInfo(id, port) {
3658
+ async subscribeYieldPoolInfo(id, port) {
3659
3659
  const cb = (0, _subscriptions.createSubscription)(id, port);
3660
- const yieldPoolSubscription = this.#koniState.subscribeYieldPoolInfo().subscribe({
3660
+ await this.#koniState.earningService.waitForStarted();
3661
+ const yieldPoolSubscription = this.#koniState.earningService.subscribeYieldPoolInfo().subscribe({
3661
3662
  next: rs => {
3662
- cb(rs);
3663
+ cb(Object.values(rs));
3663
3664
  }
3664
3665
  });
3665
3666
  this.createUnsubscriptionHandle(id, yieldPoolSubscription.unsubscribe);
3666
3667
  port.onDisconnect.addListener(() => {
3667
3668
  this.cancelSubscription(id);
3668
3669
  });
3669
- return this.#koniState.getYieldPoolInfo();
3670
+ return this.#koniState.earningService.getYieldPoolInfo();
3670
3671
  }
3671
3672
  async earlyValidateJoin(request) {
3672
3673
  return await this.#koniState.earningService.earlyValidateJoin(request);
@@ -3697,6 +3698,7 @@ class KoniExtension {
3697
3698
 
3698
3699
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3699
3700
  const {
3701
+ chainType,
3700
3702
  extrinsic,
3701
3703
  extrinsicType,
3702
3704
  transferNativeAmount,
@@ -3705,7 +3707,6 @@ class KoniExtension {
3705
3707
  } = await this.#koniState.earningService.handleYieldJoin(inputData);
3706
3708
  const isPoolSupportAlternativeFee = this.#koniState.earningService.isPoolSupportAlternativeFee(inputData.data.slug);
3707
3709
  const isMintingStep = _utils.YIELD_EXTRINSIC_TYPES.includes(extrinsicType);
3708
- const chainInfo = this.#koniState.getChainInfo(txChain);
3709
3710
  return await this.#koniState.transactionService.handleTransaction({
3710
3711
  address,
3711
3712
  chain: txChain,
@@ -3714,7 +3715,7 @@ class KoniExtension {
3714
3715
  data: txData,
3715
3716
  extrinsicType,
3716
3717
  // change this depends on step
3717
- chainType: (0, _utils2._isChainEvmCompatible)(chainInfo) ? _KoniTypes.ChainType.EVM : _KoniTypes.ChainType.SUBSTRATE,
3718
+ chainType,
3718
3719
  resolveOnDone: !isLastStep,
3719
3720
  transferNativeAmount,
3720
3721
  skipFeeValidation: isMintingStep && isPoolSupportAlternativeFee
@@ -3745,6 +3746,7 @@ class KoniExtension {
3745
3746
  const {
3746
3747
  slug
3747
3748
  } = request;
3749
+ await this.#koniState.earningService.waitForStarted();
3748
3750
  const targets = await this.#koniState.earningService.getPoolTargets(slug);
3749
3751
  return {
3750
3752
  slug,
@@ -3753,7 +3755,8 @@ class KoniExtension {
3753
3755
  }
3754
3756
  async subscribeYieldPosition(id, port) {
3755
3757
  const cb = (0, _subscriptions.createSubscription)(id, port);
3756
- const yieldPositionSubscription = this.#koniState.subscribeYieldPosition().subscribe({
3758
+ await this.#koniState.earningService.waitForStarted();
3759
+ const yieldPositionSubscription = this.#koniState.earningService.subscribeYieldPosition().subscribe({
3757
3760
  next: rs => {
3758
3761
  cb(rs);
3759
3762
  }
@@ -3762,10 +3765,11 @@ class KoniExtension {
3762
3765
  port.onDisconnect.addListener(() => {
3763
3766
  this.cancelSubscription(id);
3764
3767
  });
3765
- return this.#koniState.getYieldPositionInfo();
3768
+ return await this.#koniState.earningService.getYieldPositionInfo();
3766
3769
  }
3767
- subscribeYieldReward(id, port) {
3770
+ async subscribeYieldReward(id, port) {
3768
3771
  const cb = (0, _subscriptions.createSubscription)(id, port);
3772
+ await this.#koniState.earningService.waitForStarted();
3769
3773
  const stakingRewardSubscription = this.#koniState.earningService.subscribeEarningReward().subscribe({
3770
3774
  next: rs => {
3771
3775
  cb(rs);
@@ -3777,8 +3781,9 @@ class KoniExtension {
3777
3781
  });
3778
3782
  return this.#koniState.earningService.getEarningRewards();
3779
3783
  }
3780
- subscribeYieldRewardHistory(id, port) {
3784
+ async subscribeYieldRewardHistory(id, port) {
3781
3785
  const cb = (0, _subscriptions.createSubscription)(id, port);
3786
+ await this.#koniState.earningService.waitForStarted();
3782
3787
  const rewardHistorySubscription = this.#koniState.earningService.subscribeEarningRewardHistory().subscribe({
3783
3788
  next: rs => {
3784
3789
  cb(rs);
@@ -3790,8 +3795,9 @@ class KoniExtension {
3790
3795
  });
3791
3796
  return this.#koniState.earningService.getEarningRewardHistory();
3792
3797
  }
3793
- subscribeEarningMinAmountPercent(id, port) {
3798
+ async subscribeEarningMinAmountPercent(id, port) {
3794
3799
  const cb = (0, _subscriptions.createSubscription)(id, port);
3800
+ await this.#koniState.earningService.waitForStarted();
3795
3801
  const earningMinAmountPercentSubscription = this.#koniState.earningService.subscribeMinAmountPercent().subscribe({
3796
3802
  next: rs => {
3797
3803
  cb(rs);
@@ -83,10 +83,6 @@ class KoniState {
83
83
  ready: false,
84
84
  data: {}
85
85
  };
86
-
87
- // earning
88
- yieldPoolInfoSubject = new _rxjs.Subject();
89
- yieldPositionSubject = new _rxjs.Subject();
90
86
  lazyMap = {};
91
87
  // Handle the general status of the extension
92
88
  generalStatus = _types.ServiceStatus.INITIALIZING;
@@ -234,6 +230,7 @@ class KoniState {
234
230
  await this.migrationService.run();
235
231
  this.campaignService.init();
236
232
  this.eventService.emit('chain.ready', true);
233
+ await this.earningService.init();
237
234
  this.onReady();
238
235
  this.onAccountAdd();
239
236
  this.onAccountRemove();
@@ -263,14 +260,6 @@ class KoniState {
263
260
  this.dbService.subscribeMantaPayConfig(_constants2._DEFAULT_MANTA_ZK_CHAIN, data => {
264
261
  this.mantaPayConfigSubject.next(data);
265
262
  });
266
- let unsub;
267
- this.keyringService.accountSubject.subscribe(accounts => {
268
- // TODO: improve this
269
- unsub && unsub.unsubscribe();
270
- unsub = this.dbService.subscribeYieldPosition(Object.keys(accounts), data => {
271
- this.yieldPositionSubject.next(data);
272
- });
273
- });
274
263
  }
275
264
  onReady() {
276
265
  // Todo: Need optimize in the future to, only run important services onetime to save resources
@@ -363,22 +352,6 @@ class KoniState {
363
352
  async getPooledStakingRecordsByAddress(addresses) {
364
353
  return this.dbService.getPooledStakings(addresses, this.activeChainSlugs);
365
354
  }
366
- async getPooledPositionByAddress(addresses) {
367
- return this.dbService.getYieldNominationPoolPosition(addresses, this.activeChainSlugs);
368
- }
369
- subscribeYieldPoolInfo() {
370
- return this.yieldPoolInfoSubject;
371
- }
372
- subscribeYieldPosition() {
373
- return this.yieldPositionSubject;
374
- }
375
- getYieldPoolInfo() {
376
- return this.dbService.getYieldPools();
377
- }
378
- getYieldPositionInfo() {
379
- const addresses = this.getDecodedAddresses(this.keyringService.currentAccount.address);
380
- return this.dbService.getYieldPositionByAddress(addresses);
381
- }
382
355
  subscribeMantaPayConfig() {
383
356
  return this.mantaPayConfigSubject;
384
357
  }
@@ -1456,7 +1429,7 @@ class KoniState {
1456
1429
  // Stopping services
1457
1430
  await Promise.all([this.cron.stop(), this.subscription.stop()]);
1458
1431
  await this.pauseAllNetworks(undefined, 'IDLE mode');
1459
- await Promise.all([this.historyService.stop(), this.priceService.stop()]);
1432
+ await Promise.all([this.historyService.stop(), this.priceService.stop(), this.earningService.stop()]);
1460
1433
 
1461
1434
  // Complete sleeping
1462
1435
  sleeping.resolve();
@@ -1489,7 +1462,7 @@ class KoniState {
1489
1462
  }
1490
1463
 
1491
1464
  // Start services
1492
- await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start()]);
1465
+ await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.earningService.start()]);
1493
1466
 
1494
1467
  // Complete starting
1495
1468
  starting.resolve();
@@ -1591,7 +1564,7 @@ class KoniState {
1591
1564
  return await this.cron.reloadNft();
1592
1565
  }
1593
1566
  async reloadStaking() {
1594
- await this.subscription.reloadStaking();
1567
+ await this.earningService.reloadEarning(true);
1595
1568
  return true;
1596
1569
  }
1597
1570
  async reloadBalance() {
@@ -1790,21 +1763,6 @@ class KoniState {
1790
1763
  specVersion: parseInt((metadata === null || metadata === void 0 ? void 0 : metadata.specVersion) || '0')
1791
1764
  };
1792
1765
  }
1793
- updateYieldPoolInfo(data) {
1794
- this.dbService.updateYieldPoolStore(data).catch(e => this.logger.warn(e));
1795
- }
1796
- resetYieldPoolInfo(chains) {
1797
- this.dbService.subscribeYieldPoolInfo(chains, data => {
1798
- // TODO: no unsub
1799
- this.yieldPoolInfoSubject.next(data);
1800
- });
1801
- }
1802
- updateYieldPosition(data) {
1803
- this.dbService.updateYieldPosition(data).catch(e => this.logger.warn(e));
1804
- }
1805
- getYieldPoolStakingInfo(chain, poolType) {
1806
- return this.dbService.getYieldPoolStakingInfo(chain, poolType);
1807
- }
1808
1766
  getCrowdloanContributions(_ref11) {
1809
1767
  let {
1810
1768
  address,
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.KoniSubscription = void 0;
7
7
  var _crowdloan = require("@subwallet/extension-base/koni/api/dotsama/crowdloan");
8
8
  var _staking = require("@subwallet/extension-base/koni/api/staking");
9
- var _bonding = require("@subwallet/extension-base/koni/api/staking/bonding");
10
9
  var _handlers = require("@subwallet/extension-base/koni/background/handlers");
11
10
  var _balance = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/balance");
12
11
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
@@ -20,8 +19,6 @@ class KoniSubscription {
20
19
  subscriptionMap = {
21
20
  crowdloan: undefined,
22
21
  balance: undefined,
23
- stakingOnChain: undefined,
24
- essentialChainStakingMetadata: undefined,
25
22
  yieldPoolStats: undefined,
26
23
  yieldPosition: undefined
27
24
  };
@@ -50,20 +47,14 @@ class KoniSubscription {
50
47
  this.subscriptionMap.crowdloan();
51
48
  delete this.subscriptionMap.crowdloan;
52
49
  }
53
- if (this.subscriptionMap.stakingOnChain) {
54
- this.subscriptionMap.stakingOnChain();
55
- delete this.subscriptionMap.stakingOnChain;
56
- }
57
50
  }
58
51
  async start() {
59
52
  var _this$state$keyringSe;
60
53
  await Promise.all([this.state.eventService.waitCryptoReady, this.state.eventService.waitKeyringReady, this.state.eventService.waitAssetReady]);
61
54
  const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
62
- this.subscribeYieldPools(this.state.getChainInfoMap(), this.state.getAssetRegistry(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap(), currentAddress);
63
55
  if (currentAddress) {
64
56
  this.subscribeBalances(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
65
57
  this.subscribeCrowdloans(currentAddress, this.state.getSubstrateApiMap());
66
- this.subscribeStakingOnChain(currentAddress, this.state.getSubstrateApiMap());
67
58
  }
68
59
  this.eventHandler = (events, eventTypes) => {
69
60
  var _serviceInfo$currentA;
@@ -73,15 +64,11 @@ class KoniSubscription {
73
64
  return;
74
65
  }
75
66
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
76
-
77
- // @ts-ignore
78
- this.subscribeYieldPools(serviceInfo.chainInfoMap, serviceInfo.assetRegistry, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm, address);
79
67
  if (!address) {
80
68
  return;
81
69
  }
82
70
  this.subscribeBalances(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate, serviceInfo.chainApiMap.evm);
83
71
  this.subscribeCrowdloans(address, serviceInfo.chainApiMap.substrate);
84
- this.subscribeStakingOnChain(address, serviceInfo.chainApiMap.substrate);
85
72
  };
86
73
  this.state.eventService.onLazy(this.eventHandler.bind(this));
87
74
  }
@@ -111,121 +98,6 @@ class KoniSubscription {
111
98
  this.updateSubscription('crowdloan', this.initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
112
99
  }).catch(console.error);
113
100
  }
114
- subscribeYieldPools(chainInfoMap, assetInfoMap, substrateApiMap, evmApiMap, address, onlyRunOnFirstTime) {
115
- this.updateSubscription('yieldPoolStats', this.initYieldPoolStatsSubscription(substrateApiMap, evmApiMap, onlyRunOnFirstTime));
116
- if (address) {
117
- const addresses = this.state.getDecodedAddresses(address);
118
- if (!addresses.length) {
119
- return;
120
- }
121
- this.updateSubscription('yieldPosition', this.initYieldPositionSubscription(addresses, substrateApiMap, evmApiMap, chainInfoMap, assetInfoMap));
122
- }
123
- }
124
- initYieldPositionSubscription(addresses, substrateApiMap, evmApiMap, chainInfoMap, assetInfoMap, onlyRunOnFirstTime) {
125
- let cancel = false;
126
- const updateYieldPoolStats = data => {
127
- this.state.updateYieldPosition(data);
128
- };
129
- let unsub = _util.noop;
130
- this.state.earningService.subscribePoolPositions(addresses, updateYieldPoolStats).then(rs => {
131
- if (cancel) {
132
- rs();
133
- } else {
134
- if (onlyRunOnFirstTime) {
135
- rs && rs();
136
- } else {
137
- unsub = rs;
138
- }
139
- }
140
- }).catch(console.error);
141
- return () => {
142
- cancel = true;
143
- unsub && unsub();
144
- };
145
- }
146
- initYieldPoolStatsSubscription(substrateApiMap, evmApiMap, onlyRunOnFirstTime) {
147
- let cancel = false;
148
- this.state.resetYieldPoolInfo(Object.keys(this.state.getChainInfoMap()));
149
- const updateYieldPoolStats = data => {
150
- this.state.updateYieldPoolInfo(data);
151
- };
152
-
153
- // const unsub = subscribeYieldPoolStats(substrateApiMap, evmApiMap, this.state.getActiveChainInfoMap(), this.state.getAssetRegistry(), updateYieldPoolStats);
154
- let unsub = _util.noop;
155
- this.state.earningService.subscribePoolsInfo(updateYieldPoolStats).then(rs => {
156
- if (cancel) {
157
- rs();
158
- } else {
159
- if (onlyRunOnFirstTime) {
160
- rs && rs();
161
- } else {
162
- unsub = rs;
163
- }
164
- }
165
- }).catch(console.error);
166
-
167
- //
168
- // if (onlyRunOnFirstTime) {
169
- // unsub && unsub();
170
- //
171
- // return;
172
- // }
173
-
174
- return () => {
175
- cancel = true;
176
- // unsub && unsub();
177
- unsub && unsub();
178
- };
179
- }
180
- subscribeStakingOnChain(address, substrateApiMap, onlyRunOnFirstTime) {
181
- this.state.resetStaking(address);
182
- const addresses = this.state.getDecodedAddresses(address);
183
- if (!addresses.length) {
184
- return;
185
- }
186
- this.updateSubscription('stakingOnChain', this.initStakingOnChainSubscription(addresses, substrateApiMap, onlyRunOnFirstTime));
187
- this.updateSubscription('essentialChainStakingMetadata', this.initEssentialChainStakingMetadataSubscription(substrateApiMap, onlyRunOnFirstTime)); // TODO: might not need to re-subscribe on changing account
188
- }
189
-
190
- initStakingOnChainSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
191
- const stakingCallback = (networkKey, rs) => {
192
- this.state.setStakingItem(networkKey, rs);
193
- };
194
- const nominatorStateCallback = nominatorMetadata => {
195
- this.state.updateStakingNominatorMetadata(nominatorMetadata);
196
- };
197
- const unsub = (0, _staking.stakingOnChainApi)(addresses, substrateApiMap, this.state.getActiveChainInfoMap(), stakingCallback, nominatorStateCallback);
198
- if (onlyRunOnFirstTime) {
199
- unsub && unsub();
200
- return;
201
- }
202
- return () => {
203
- unsub && unsub();
204
- };
205
- }
206
- initEssentialChainStakingMetadataSubscription(substrateApiMap, onlyRunOnFirstTime) {
207
- const unsub = (0, _bonding.subscribeEssentialChainStakingMetadata)(substrateApiMap, this.state.getActiveChainInfoMap(), (networkKey, rs) => {
208
- this.state.updateChainStakingMetadata(rs, {
209
- era: rs.era,
210
- minStake: rs.minStake,
211
- maxValidatorPerNominator: rs.maxValidatorPerNominator,
212
- // temporary fix for Astar, there's no limit for now
213
- maxWithdrawalRequestPerValidator: rs.maxWithdrawalRequestPerValidator,
214
- // by default
215
- allowCancelUnstaking: rs.allowCancelUnstaking,
216
- unstakingPeriod: rs.unstakingPeriod,
217
- expectedReturn: rs.expectedReturn,
218
- inflation: rs.inflation
219
- });
220
- });
221
- if (onlyRunOnFirstTime) {
222
- unsub && unsub();
223
- return;
224
- }
225
- return () => {
226
- unsub && unsub();
227
- };
228
- }
229
101
  initBalanceSubscription(addresses, chainInfoMap, chainStateMap, substrateApiMap, evmApiMap, onlyRunOnFirstTime) {
230
102
  const filteredChainInfoMap = {};
231
103
  Object.values(chainStateMap).forEach(chainState => {
@@ -296,33 +168,6 @@ class KoniSubscription {
296
168
  this.state.updateStakingReward(rewardItem);
297
169
  });
298
170
  }
299
- async subscribeStakingRewardFastInterval(address) {
300
- const addresses = this.state.getDecodedAddresses(address);
301
- if (!addresses.length) {
302
- return;
303
- }
304
- const updateState = result => {
305
- this.state.earningService.updateEarningReward(result);
306
- };
307
- await Promise.all([this.state.earningService.getPoolReward(addresses, updateState)]);
308
- }
309
- async subscribeEarningRewardHistoryInterval(address) {
310
- const addresses = this.state.getDecodedAddresses(address);
311
- if (!addresses.length) {
312
- return;
313
- }
314
- const updateState = result => {
315
- this.state.earningService.updateEarningRewardHistory(result);
316
- };
317
- await Promise.all([this.state.earningService.fetchPoolRewardHistory(addresses, updateState)]);
318
- }
319
- async reloadStaking() {
320
- // const currentAddress = this.state.keyringService.currentAccount?.address;
321
-
322
- // this.subscribeYieldPools(this.state.getSubstrateApiMap());
323
-
324
- await (0, _utils2.waitTimeout)(1800);
325
- }
326
171
  async reloadBalance() {
327
172
  var _this$state$keyringSe2;
328
173
  const currentAddress = (_this$state$keyringSe2 = this.state.keyringService.currentAccount) === null || _this$state$keyringSe2 === void 0 ? void 0 : _this$state$keyringSe2.address;
@@ -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.1.31-1'
16
+ version: '1.1.32-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -53,6 +53,7 @@ class CampaignService {
53
53
  endTime,
54
54
  startTime,
55
55
  isDone: false,
56
+ isArchive: false,
56
57
  campaignId,
57
58
  type: _KoniTypes.CampaignDataType.BANNER,
58
59
  buttons,
@@ -73,6 +74,7 @@ class CampaignService {
73
74
  endTime,
74
75
  startTime,
75
76
  isDone: false,
77
+ isArchive: false,
76
78
  campaignId,
77
79
  type: _KoniTypes.CampaignDataType.NOTIFICATION,
78
80
  buttons,
@@ -85,6 +87,23 @@ class CampaignService {
85
87
  const exists = await this.#state.dbService.getCampaign(campaign.slug);
86
88
  if (!exists) {
87
89
  await this.#state.dbService.upsertCampaign(campaign);
90
+ } else {
91
+ const data = {
92
+ ...campaign,
93
+ isDone: exists.isDone
94
+ };
95
+ await this.#state.dbService.upsertCampaign(data);
96
+ }
97
+ }
98
+ const allCampaign = await this.#state.dbService.getAllCampaign();
99
+ for (const stored of allCampaign) {
100
+ const exists = campaigns.find(campaign => campaign.slug === stored.slug);
101
+ if (!exists) {
102
+ const data = {
103
+ ...stored,
104
+ isArchive: true
105
+ };
106
+ await this.#state.dbService.upsertCampaign(data);
88
107
  }
89
108
  }
90
109
  this.#state.eventService.emit('campaign.ready', true);
@@ -96,7 +96,8 @@ const _STAKING_ERA_LENGTH_MAP = {
96
96
  kate: 6,
97
97
  creditcoin: 24,
98
98
  vara_network: 12,
99
- goldberg_testnet: 24
99
+ goldberg_testnet: 24,
100
+ manta_network: 6
100
101
  };
101
102
  exports._STAKING_ERA_LENGTH_MAP = _STAKING_ERA_LENGTH_MAP;
102
103
  const _EXPECTED_BLOCK_TIME = {
@@ -251,7 +252,7 @@ const _XCM_TYPE = {
251
252
  PR: `${_types._SubstrateChainType.PARACHAIN}-${_types._SubstrateChainType.RELAYCHAIN}` // UMP
252
253
  };
253
254
  exports._XCM_TYPE = _XCM_TYPE;
254
- const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS, 'vara_network', 'bifrost_dot', 'parallel', 'acala', 'interlay'];
255
+ const _DEFAULT_ACTIVE_CHAINS = [..._chainList._DEFAULT_CHAINS, 'vara_network'];
255
256
  exports._DEFAULT_ACTIVE_CHAINS = _DEFAULT_ACTIVE_CHAINS;
256
257
  const EVM_PASS_CONNECT_STATUS = {
257
258
  arbitrum_one: ['*']
@@ -9,7 +9,7 @@ exports._STAKING_CHAIN_GROUP = exports.ST_LIQUID_TOKEN_ABI = void 0;
9
9
 
10
10
  const _STAKING_CHAIN_GROUP = {
11
11
  relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'ternoa_alphanet', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
12
- para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari'],
12
+ para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network'],
13
13
  astar: ['astar', 'shiden', 'shibuya'],
14
14
  amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum'],
15
15
  // amplitude and kilt only share some common logic
@@ -75,6 +75,9 @@ class BasePoolHandler {
75
75
  slug: this.slug
76
76
  };
77
77
  }
78
+ getAssetBySlug(slug) {
79
+ return this.state.getAssetBySlug(slug);
80
+ }
78
81
  get maintainBalance() {
79
82
  const decimals = this.nativeToken.decimals || 0;
80
83
  const defaultMaintainBalance = new _util.BN(1).mul(_util.BN_TEN.pow(new _util.BN(decimals)));
@@ -100,10 +103,10 @@ class BasePoolHandler {
100
103
  return false;
101
104
  }
102
105
  async getPoolInfo() {
103
- return this.state.dbService.getYieldPool(this.slug);
106
+ return await this.state.earningService.getYieldPool(this.slug);
104
107
  }
105
108
  async getPoolPosition(address) {
106
- return this.state.dbService.getYieldPositionByAddressAndSlug(address, this.slug);
109
+ return await this.state.earningService.getYieldPosition(address, this.slug);
107
110
  }
108
111
 
109
112
  /* Subscribe data */
@@ -122,7 +125,7 @@ class BasePoolHandler {
122
125
  if (!poolInfo || !((_poolInfo$statistic = poolInfo.statistic) !== null && _poolInfo$statistic !== void 0 && _poolInfo$statistic.earningThreshold.join)) {
123
126
  return {
124
127
  passed: false,
125
- errorMessage: 'There\'s a trouble fetching data, please check your internet connection and try again'
128
+ errorMessage: 'There is a problem fetching your data. Check your Internet connection or change the network endpoint and try again.'
126
129
  };
127
130
  }
128
131
  if (request.address === _constants.ALL_ACCOUNT_KEY) {
@@ -133,9 +136,9 @@ class BasePoolHandler {
133
136
  const nativeTokenInfo = this.state.chainService.getNativeTokenInfo(this.chain);
134
137
  const nativeTokenBalance = await this.state.balanceService.getTokenFreeBalance(request.address, this.chain);
135
138
  const bnNativeTokenBalance = new _util.BN(nativeTokenBalance.value);
136
- if (bnNativeTokenBalance.lte(new _util.BN((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join))) {
137
- var _poolInfo$statistic3, _poolInfo$statistic3$;
138
- const minJoin = (0, _utils.formatNumber)(((_poolInfo$statistic3 = poolInfo.statistic) === null || _poolInfo$statistic3 === void 0 ? void 0 : (_poolInfo$statistic3$ = _poolInfo$statistic3.earningThreshold) === null || _poolInfo$statistic3$ === void 0 ? void 0 : _poolInfo$statistic3$.join) || '0', this.nativeToken.decimals || 0);
139
+ const bnMinBalanceToJoin = new _util.BN(((_poolInfo$statistic2 = poolInfo.statistic) === null || _poolInfo$statistic2 === void 0 ? void 0 : (_poolInfo$statistic2$ = _poolInfo$statistic2.earningThreshold) === null || _poolInfo$statistic2$ === void 0 ? void 0 : _poolInfo$statistic2$.join) || '0').add(new _util.BN(poolInfo.metadata.maintainBalance));
140
+ if (bnNativeTokenBalance.lte(bnMinBalanceToJoin)) {
141
+ const minJoin = (0, _utils.formatNumber)(bnMinBalanceToJoin.toString(), this.nativeToken.decimals || 0);
139
142
  const originChain = this.state.getChainInfo(nativeTokenInfo.originChain);
140
143
  return {
141
144
  passed: false,