@subwallet/extension-base 1.1.28-beta.1 → 1.1.28-beta.2

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 (89) hide show
  1. package/background/KoniTypes.d.ts +9 -7
  2. package/cjs/koni/api/yield/helper/utils.js +2 -2
  3. package/cjs/koni/background/handlers/Extension.js +25 -1
  4. package/cjs/services/earning-service/constants/chains.js +2 -2
  5. package/cjs/services/earning-service/handlers/base.js +24 -6
  6. package/cjs/services/earning-service/handlers/lending/interlay.js +9 -7
  7. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +9 -7
  8. package/cjs/services/earning-service/handlers/liquid-staking/base.js +5 -1
  9. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +9 -7
  10. package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +9 -7
  11. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +9 -7
  12. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +23 -9
  13. package/cjs/services/earning-service/handlers/native-staking/astar.js +28 -8
  14. package/cjs/services/earning-service/handlers/native-staking/base-para.js +5 -5
  15. package/cjs/services/earning-service/handlers/native-staking/base.js +11 -1
  16. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +21 -7
  17. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +35 -18
  18. package/cjs/services/earning-service/handlers/nomination-pool/index.js +34 -14
  19. package/cjs/services/earning-service/handlers/special.js +32 -8
  20. package/cjs/services/earning-service/service.js +41 -17
  21. package/cjs/services/earning-service/utils/index.js +18 -1
  22. package/cjs/services/migration-service/scripts/databases/MigrateEarningHistory.js +21 -0
  23. package/cjs/services/migration-service/scripts/databases/MigrateEarningVersion.js +21 -0
  24. package/cjs/services/migration-service/scripts/index.js +3 -1
  25. package/cjs/services/storage-service/DatabaseService.js +4 -0
  26. package/cjs/services/transaction-service/index.js +3 -3
  27. package/cjs/types/yield/actions/join/step.js +10 -0
  28. package/cjs/types/yield/info/base.js +7 -0
  29. package/cjs/utils/yield/index.js +3 -0
  30. package/koni/api/yield/helper/utils.js +2 -2
  31. package/koni/background/handlers/Extension.d.ts +2 -0
  32. package/koni/background/handlers/Extension.js +25 -1
  33. package/package.json +11 -1
  34. package/services/earning-service/constants/chains.js +2 -2
  35. package/services/earning-service/handlers/base.d.ts +6 -4
  36. package/services/earning-service/handlers/base.js +24 -6
  37. package/services/earning-service/handlers/lending/interlay.d.ts +1 -1
  38. package/services/earning-service/handlers/lending/interlay.js +9 -7
  39. package/services/earning-service/handlers/liquid-staking/acala.d.ts +2 -2
  40. package/services/earning-service/handlers/liquid-staking/acala.js +9 -7
  41. package/services/earning-service/handlers/liquid-staking/base.d.ts +2 -1
  42. package/services/earning-service/handlers/liquid-staking/base.js +5 -1
  43. package/services/earning-service/handlers/liquid-staking/bifrost.d.ts +2 -2
  44. package/services/earning-service/handlers/liquid-staking/bifrost.js +9 -7
  45. package/services/earning-service/handlers/liquid-staking/parallel.d.ts +2 -2
  46. package/services/earning-service/handlers/liquid-staking/parallel.js +9 -7
  47. package/services/earning-service/handlers/liquid-staking/stella-swap.d.ts +1 -1
  48. package/services/earning-service/handlers/liquid-staking/stella-swap.js +9 -7
  49. package/services/earning-service/handlers/native-staking/amplitude.js +23 -9
  50. package/services/earning-service/handlers/native-staking/astar.d.ts +2 -1
  51. package/services/earning-service/handlers/native-staking/astar.js +28 -8
  52. package/services/earning-service/handlers/native-staking/base-para.js +5 -5
  53. package/services/earning-service/handlers/native-staking/base.d.ts +3 -2
  54. package/services/earning-service/handlers/native-staking/base.js +10 -1
  55. package/services/earning-service/handlers/native-staking/para-chain.js +21 -7
  56. package/services/earning-service/handlers/native-staking/relay-chain.js +35 -18
  57. package/services/earning-service/handlers/nomination-pool/index.d.ts +1 -1
  58. package/services/earning-service/handlers/nomination-pool/index.js +33 -14
  59. package/services/earning-service/handlers/special.d.ts +4 -2
  60. package/services/earning-service/handlers/special.js +32 -8
  61. package/services/earning-service/service.d.ts +6 -2
  62. package/services/earning-service/service.js +40 -17
  63. package/services/earning-service/utils/index.d.ts +5 -1
  64. package/services/earning-service/utils/index.js +13 -1
  65. package/services/migration-service/scripts/databases/MigrateEarningHistory.d.ts +4 -0
  66. package/services/migration-service/scripts/databases/MigrateEarningHistory.js +13 -0
  67. package/services/migration-service/scripts/databases/MigrateEarningVersion.d.ts +4 -0
  68. package/services/migration-service/scripts/databases/MigrateEarningVersion.js +13 -0
  69. package/services/migration-service/scripts/index.js +3 -1
  70. package/services/storage-service/DatabaseService.d.ts +1 -0
  71. package/services/storage-service/DatabaseService.js +4 -0
  72. package/services/transaction-service/index.js +3 -3
  73. package/types/yield/actions/join/step.d.ts +19 -0
  74. package/types/yield/actions/join/step.js +12 -0
  75. package/types/yield/actions/others.d.ts +4 -1
  76. package/types/yield/info/account/info.d.ts +3 -14
  77. package/types/yield/info/account/reward.d.ts +3 -14
  78. package/types/yield/info/base.d.ts +17 -0
  79. package/types/yield/info/base.js +8 -0
  80. package/types/yield/info/chain/info.d.ts +81 -63
  81. package/types/yield/info/chain/target.d.ts +4 -0
  82. package/cjs/koni/api/dotsama/balance.js +0 -464
  83. package/cjs/services/migration-service/scripts/MigrateEthProvider.js +0 -17
  84. package/cjs/services/migration-service/scripts/MigratePioneerProvider.js +0 -17
  85. package/cjs/services/migration-service/scripts/MigrateProvider.js +0 -29
  86. package/cjs/services/storage-service/index.js +0 -241
  87. package/cjs/types.js +0 -1
  88. package/cjs/utils/address.js +0 -34
  89. package/cjs/utils/keyring.js +0 -57
@@ -13,17 +13,24 @@ import { t } from 'i18next';
13
13
  import { BN_ZERO, noop } from '@polkadot/util';
14
14
  import BasePoolHandler from "./base.js";
15
15
  export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
16
+ /** Pool's type */
17
+
16
18
  /** Allow to create default unstake transaction */
17
19
  allowDefaultUnstake = false;
18
20
  /** Allow to create fast unstake transaction */
19
21
  allowFastUnstake = true;
20
- get baseMetadata() {
22
+ get metadataInfo() {
21
23
  return {
22
24
  altInputAssets: this.altInputAsset,
23
25
  derivativeAssets: this.derivativeAssets,
24
26
  inputAsset: this.inputAsset,
25
27
  rewardAssets: this.rewardAssets,
26
- feeAssets: this.feeAssets
28
+ feeAssets: this.feeAssets,
29
+ logo: this.logo,
30
+ shortName: this.shortName,
31
+ name: this.name,
32
+ isAvailable: true,
33
+ allowCancelUnstaking: false
27
34
  };
28
35
  }
29
36
  get isPoolSupportAlternativeFee() {
@@ -40,11 +47,25 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
40
47
  async subscribePoolInfo(callback) {
41
48
  let cancel = false;
42
49
  const getStatInterval = () => {
43
- this.getPoolStat().then(rs => {
50
+ if (!this.isActive) {
44
51
  if (!cancel) {
52
+ const rs = {
53
+ ...this.baseInfo,
54
+ type: this.type,
55
+ metadata: {
56
+ ...this.metadataInfo,
57
+ description: this.getDescription()
58
+ }
59
+ };
45
60
  callback(rs);
46
61
  }
47
- }).catch(console.error);
62
+ } else {
63
+ this.getPoolStat().then(rs => {
64
+ if (!cancel) {
65
+ callback(rs);
66
+ }
67
+ }).catch(console.error);
68
+ }
48
69
  };
49
70
  getStatInterval();
50
71
  const interval = setInterval(() => {
@@ -192,6 +213,9 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
192
213
  return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
193
214
  }
194
215
  const poolInfo = _poolInfo;
216
+ if (!poolInfo.statistic) {
217
+ return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
218
+ }
195
219
  const processValidation = {
196
220
  ok: true,
197
221
  status: YieldValidationStatus.OK
@@ -213,7 +237,7 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
213
237
  return [new TransactionError(YieldValidationStatus.NOT_ENOUGH_FEE, processValidation.message, processValidation)];
214
238
  }
215
239
  }
216
- if (!bnAmount.gte(new BN(poolInfo.metadata.minJoinPool || '0'))) {
240
+ if (!bnAmount.gte(new BN(poolInfo.statistic.minJoinPool || '0'))) {
217
241
  processValidation.failedStep = path.steps[id];
218
242
  processValidation.ok = false;
219
243
  processValidation.status = YieldValidationStatus.NOT_ENOUGH_MIN_JOIN_POOL;
@@ -331,7 +355,7 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
331
355
  async validateYieldLeave(amount, address, fastLeave, selectedTarget) {
332
356
  const poolInfo = await this.getPoolInfo();
333
357
  const poolPosition = await this.getPoolPosition(address);
334
- if (!poolInfo || !poolPosition) {
358
+ if (!poolInfo || !poolInfo.statistic || !poolPosition) {
335
359
  return [new TransactionError(BasicTxErrorType.INTERNAL_ERROR)];
336
360
  }
337
361
  if (!this.allowDefaultUnstake && !fastLeave) {
@@ -343,8 +367,8 @@ export default class BaseSpecialStakingPoolHandler extends BasePoolHandler {
343
367
  const errors = [];
344
368
  const bnActiveStake = new BN(poolPosition.activeStake);
345
369
  const bnRemainingStake = bnActiveStake.sub(new BN(amount));
346
- const minStake = new BN(poolInfo.metadata.minJoinPool || '0');
347
- const maxUnstake = poolInfo.metadata.maxWithdrawalRequestPerFarmer;
370
+ const minStake = new BN(poolInfo.statistic.minJoinPool || '0');
371
+ const maxUnstake = poolInfo.statistic.maxWithdrawalRequestPerFarmer;
348
372
  if (!(bnRemainingStake.isZero() || bnRemainingStake.gte(minStake))) {
349
373
  errors.push(new TransactionError(StakingTxErrorType.INVALID_ACTIVE_STAKE));
350
374
  }
@@ -1,17 +1,20 @@
1
1
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
2
2
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
3
3
  import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
4
- import { EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
4
+ import { EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
5
5
  import { BehaviorSubject } from 'rxjs';
6
6
  import { BasePoolHandler } from './handlers';
7
7
  export default class EarningService {
8
8
  protected readonly state: KoniState;
9
9
  protected handlers: Record<string, BasePoolHandler>;
10
10
  private earningRewardSubject;
11
+ private minAmountPercentSubject;
11
12
  constructor(state: KoniState);
12
- initHandlers(): void;
13
+ private initHandlers;
13
14
  getPoolHandler(slug: string): BasePoolHandler | undefined;
14
15
  isPoolSupportAlternativeFee(slug: string): boolean;
16
+ subscribeMinAmountPercent(): BehaviorSubject<Record<string, number>>;
17
+ getMinAmountPercent(): Record<string, number>;
15
18
  subscribePoolsInfo(callback: (rs: YieldPoolInfo) => void): Promise<VoidFunction>;
16
19
  subscribePoolPositions(addresses: string[], callback: (rs: YieldPositionInfo) => void): Promise<VoidFunction>;
17
20
  updateEarningReward(stakingRewardData: EarningRewardItem, callback?: (earningRewardData: EarningRewardJson) => void): void;
@@ -25,6 +28,7 @@ export default class EarningService {
25
28
  * @return {Promise<YieldPoolTarget[]>} List of pool's target
26
29
  * */
27
30
  getPoolTargets(slug: string): Promise<YieldPoolTarget[]>;
31
+ earlyValidateJoin(request: RequestEarlyValidateYield): Promise<ResponseEarlyValidateYield>;
28
32
  generateOptimalSteps(params: OptimalYieldPathParams): Promise<OptimalYieldPath>;
29
33
  validateYieldJoin(params: ValidateYieldProcessParams): Promise<TransactionError[]>;
30
34
  handleYieldJoin(params: HandleYieldStepParams): Promise<HandleYieldStepData>;
@@ -5,6 +5,8 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
5
5
  import { BasicTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
6
6
  import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
7
7
  import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants';
8
+ import BaseLiquidStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/liquid-staking/base';
9
+ import { YieldPoolType } from '@subwallet/extension-base/types';
8
10
  import { categoryAddresses } from '@subwallet/extension-base/utils';
9
11
  import { BehaviorSubject } from 'rxjs';
10
12
  import { AcalaLiquidStakingPoolHandler, AmplitudeNativeStakingPoolHandler, AstarNativeStakingPoolHandler, BifrostLiquidStakingPoolHandler, InterlayLendingPoolHandler, NominationPoolHandler, ParallelLiquidStakingPoolHandler, ParaNativeStakingPoolHandler, RelayNativeStakingPoolHandler, StellaSwapLiquidStakingPoolHandler } from "./handlers/index.js";
@@ -14,12 +16,15 @@ export default class EarningService {
14
16
  ready: false,
15
17
  data: {}
16
18
  });
19
+ minAmountPercentSubject = new BehaviorSubject({});
17
20
  constructor(state) {
18
21
  this.state = state;
19
- this.initHandlers();
22
+ this.initHandlers().catch(console.error);
20
23
  }
21
- initHandlers() {
22
- const chains = this.state.activeChainSlugs;
24
+ async initHandlers() {
25
+ await this.state.eventService.waitChainReady;
26
+ const chains = Object.keys(this.state.getChainInfoMap());
27
+ const minAmountPercent = {};
23
28
  for (const chain of chains) {
24
29
  const handlers = [];
25
30
  if (_STAKING_CHAIN_GROUP.relay.includes(chain)) {
@@ -60,9 +65,15 @@ export default class EarningService {
60
65
  this.handlers[handler.slug] = handler;
61
66
  }
62
67
  }
68
+ for (const handler of Object.values(this.handlers)) {
69
+ if (handler.type === YieldPoolType.LIQUID_STAKING) {
70
+ minAmountPercent[handler.slug] = handler.minAmountPercent;
71
+ }
72
+ }
73
+ minAmountPercent.default = BaseLiquidStakingPoolHandler.defaultMinAmountPercent;
74
+ this.minAmountPercentSubject.next(minAmountPercent);
63
75
  }
64
76
  getPoolHandler(slug) {
65
- this.initHandlers();
66
77
  return this.handlers[slug];
67
78
  }
68
79
  isPoolSupportAlternativeFee(slug) {
@@ -73,25 +84,27 @@ export default class EarningService {
73
84
  throw new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
74
85
  }
75
86
  }
87
+ subscribeMinAmountPercent() {
88
+ return this.minAmountPercentSubject;
89
+ }
90
+ getMinAmountPercent() {
91
+ return this.minAmountPercentSubject.getValue();
92
+ }
76
93
 
77
94
  /* Subscribe pools' info */
78
95
 
79
96
  async subscribePoolsInfo(callback) {
80
97
  let cancel = false;
81
98
  await this.state.eventService.waitChainReady;
82
- this.initHandlers();
83
- const activeChains = this.state.activeChainSlugs;
84
99
  const unsubList = [];
85
100
  for (const handler of Object.values(this.handlers)) {
86
- if (activeChains.includes(handler.chain)) {
87
- handler.subscribePoolInfo(callback).then(unsub => {
88
- if (cancel) {
89
- unsub();
90
- } else {
91
- unsubList.push(unsub);
92
- }
93
- }).catch(console.error);
94
- }
101
+ handler.subscribePoolInfo(callback).then(unsub => {
102
+ if (cancel) {
103
+ unsub();
104
+ } else {
105
+ unsubList.push(unsub);
106
+ }
107
+ }).catch(console.error);
95
108
  }
96
109
  return () => {
97
110
  cancel = true;
@@ -108,7 +121,6 @@ export default class EarningService {
108
121
  async subscribePoolPositions(addresses, callback) {
109
122
  let cancel = false;
110
123
  await this.state.eventService.waitChainReady;
111
- this.initHandlers();
112
124
  const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
113
125
  const activeChains = this.state.activeChainSlugs;
114
126
  const unsubList = [];
@@ -150,7 +162,6 @@ export default class EarningService {
150
162
  async getPoolReward(addresses, callback) {
151
163
  let cancel = false;
152
164
  await this.state.eventService.waitChainReady;
153
- this.initHandlers();
154
165
  const [substrateAddresses, evmAddresses] = categoryAddresses(addresses);
155
166
  const activeChains = this.state.activeChainSlugs;
156
167
  const unsubList = [];
@@ -207,6 +218,18 @@ export default class EarningService {
207
218
 
208
219
  /* Join */
209
220
 
221
+ async earlyValidateJoin(request) {
222
+ await this.state.eventService.waitChainReady;
223
+ const {
224
+ slug
225
+ } = request;
226
+ const handler = this.getPoolHandler(slug);
227
+ if (handler) {
228
+ return handler.earlyValidate(request);
229
+ } else {
230
+ throw new TransactionError(BasicTxErrorType.INTERNAL_ERROR);
231
+ }
232
+ }
210
233
  async generateOptimalSteps(params) {
211
234
  await this.state.eventService.waitChainReady;
212
235
  const {
@@ -1,5 +1,5 @@
1
1
  import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
2
- import { YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolType } from '@subwallet/extension-base/types';
2
+ import { LendingYieldPoolInfo, LiquidYieldPoolInfo, NativeYieldPoolInfo, NominationYieldPoolInfo, YieldAssetExpectedEarning, YieldCompoundingPeriod, YieldPoolInfo, YieldPoolType } from '@subwallet/extension-base/types';
3
3
  export declare function calculateReward(apr: number, amount?: number, compoundingPeriod?: YieldCompoundingPeriod, isApy?: boolean): YieldAssetExpectedEarning;
4
4
  /**
5
5
  * @returns
@@ -12,3 +12,7 @@ export declare function calculateReward(apr: number, amount?: number, compoundin
12
12
  * */
13
13
  export declare function parseIdentity(substrateApi: _SubstrateApi, address: string, children?: string): Promise<[string | undefined, boolean]>;
14
14
  export declare function isActionFromValidator(stakingType: YieldPoolType, chain: string): boolean;
15
+ export declare const isNominationPool: (pool: YieldPoolInfo) => pool is NominationYieldPoolInfo;
16
+ export declare const isNativeStakingPool: (pool: YieldPoolInfo) => pool is NativeYieldPoolInfo;
17
+ export declare const isLiquidPool: (pool: YieldPoolInfo) => pool is LiquidYieldPoolInfo;
18
+ export declare const isLendingPool: (pool: YieldPoolInfo) => pool is LendingYieldPoolInfo;
@@ -97,4 +97,16 @@ export function isActionFromValidator(stakingType, chain) {
97
97
  return true;
98
98
  }
99
99
  return false;
100
- }
100
+ }
101
+ export const isNominationPool = pool => {
102
+ return pool.type === YieldPoolType.NOMINATION_POOL;
103
+ };
104
+ export const isNativeStakingPool = pool => {
105
+ return pool.type === YieldPoolType.NATIVE_STAKING;
106
+ };
107
+ export const isLiquidPool = pool => {
108
+ return pool.type === YieldPoolType.LIQUID_STAKING;
109
+ };
110
+ export const isLendingPool = pool => {
111
+ return pool.type === YieldPoolType.LENDING;
112
+ };
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateEarningHistory extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ export default class MigrateEarningHistory extends BaseMigrationJob {
6
+ async run() {
7
+ try {
8
+ await this.state.dbService.removeOldEarningData();
9
+ } catch (e) {
10
+ console.error(e);
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateEarningVersion extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
5
+ export default class MigrateEarningVersion extends BaseMigrationJob {
6
+ async run() {
7
+ try {
8
+ await this.state.dbService.removeOldEarningData();
9
+ } catch (e) {
10
+ console.error(e);
11
+ }
12
+ }
13
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  import DeleteEarningData from '@subwallet/extension-base/services/migration-service/scripts/DeleteEarningData';
5
5
  import EnableEarningChains from '@subwallet/extension-base/services/migration-service/scripts/EnableEarningChains';
6
+ import MigrateEarningVersion from "./databases/MigrateEarningVersion.js";
6
7
  import MigrateEthProvider from "./providers/MigrateEthProvider.js";
7
8
  import MigratePioneerProvider from "./providers/MigratePioneerProvider.js";
8
9
  import MigrateProvidersV1M1P24 from "./providers/MigrateProvidersV1M1P24.js";
@@ -40,6 +41,7 @@ export default {
40
41
  '1.1.17-01': MigratePioneerProvider,
41
42
  '1.1.17-03': EnableVaraChain,
42
43
  '1.1.24-01': MigrateProvidersV1M1P24,
43
- '1.1.26-01': MigratePolygonUSDCProvider
44
+ '1.1.26-01': MigratePolygonUSDCProvider,
45
+ '1.1.28-01': MigrateEarningVersion
44
46
  // [`${EVERYTIME}-1`]: AutoEnableChainsTokens
45
47
  };
@@ -88,6 +88,7 @@ export default class DatabaseService {
88
88
  subscribeMantaPayConfig(chain: string, callback: (data: MantaPayConfig[]) => void): void;
89
89
  getMantaPayConfig(chain: string): Promise<any[]>;
90
90
  getMantaPayFirstConfig(chain: string): Promise<any>;
91
+ removeOldEarningData(): Promise<void>;
91
92
  updateYieldPoolStore(data: YieldPoolInfo): Promise<void>;
92
93
  deleteYieldPoolInfo(slugs: string[]): Promise<void>;
93
94
  getYieldPools(): Promise<YieldPoolInfo[]>;
@@ -279,6 +279,10 @@ export default class DatabaseService {
279
279
 
280
280
  /* Earning */
281
281
 
282
+ async removeOldEarningData() {
283
+ await this.stores.yieldPoolInfo.clear();
284
+ await this.stores.yieldPosition.clear();
285
+ }
282
286
  async updateYieldPoolStore(data) {
283
287
  await this.stores.yieldPoolInfo.upsert(data);
284
288
  }
@@ -525,7 +525,7 @@ export default class TransactionService {
525
525
  case ExtrinsicType.REDEEM_QDOT:
526
526
  {
527
527
  const data = parseTransactionData(transaction.data);
528
- const yieldPoolInfo = data.yieldPoolInfo;
528
+ const yieldPoolInfo = data.poolInfo;
529
529
  if (yieldPoolInfo.metadata.derivativeAssets) {
530
530
  const inputTokenSlug = yieldPoolInfo.metadata.inputAsset;
531
531
  const inputTokenInfo = this.state.chainService.getAssetBySlug(inputTokenSlug);
@@ -546,11 +546,11 @@ export default class TransactionService {
546
546
  case ExtrinsicType.REDEEM_VDOT:
547
547
  {
548
548
  const data = parseTransactionData(transaction.data);
549
- const yieldPoolInfo = data.yieldPoolInfo;
549
+ const yieldPoolInfo = data.poolInfo;
550
550
  if (yieldPoolInfo.metadata.derivativeAssets) {
551
551
  const derivativeTokenSlug = yieldPoolInfo.metadata.derivativeAssets[0];
552
552
  const derivativeTokenInfo = this.state.chainService.getAssetBySlug(derivativeTokenSlug);
553
- const chainInfo = this.state.chainService.getChainInfoByKey(data.yieldPoolInfo.chain);
553
+ const chainInfo = this.state.chainService.getChainInfoByKey(data.poolInfo.chain);
554
554
  historyItem.amount = {
555
555
  value: data.amount,
556
556
  symbol: _getAssetSymbol(derivativeTokenInfo),
@@ -1,4 +1,23 @@
1
1
  import { YieldPoolTarget } from '@subwallet/extension-base/types';
2
+ /**
3
+ * @interface RequestEarlyValidateYield
4
+ * @description Params to early validate join pool
5
+ * @prop {string} slug - Pool's slug
6
+ * @prop {string} address - Account's address
7
+ * */
8
+ export interface RequestEarlyValidateYield {
9
+ /** Pool's slug */
10
+ slug: string;
11
+ /** Account's address */
12
+ address: string;
13
+ }
14
+ /**
15
+ * @interface ResponseEarlyValidateYield
16
+ * @prop {boolean} passed - Passed validate
17
+ * */
18
+ export interface ResponseEarlyValidateYield {
19
+ passed: boolean;
20
+ }
2
21
  /**
3
22
  * @interface OptimalYieldPathParams
4
23
  * @description Params to generate steps
@@ -1,6 +1,18 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ /**
5
+ * @interface RequestEarlyValidateYield
6
+ * @description Params to early validate join pool
7
+ * @prop {string} slug - Pool's slug
8
+ * @prop {string} address - Account's address
9
+ * */
10
+
11
+ /**
12
+ * @interface ResponseEarlyValidateYield
13
+ * @prop {boolean} passed - Passed validate
14
+ * */
15
+
4
16
  /**
5
17
  * @interface OptimalYieldPathParams
6
18
  * @description Params to generate steps
@@ -1,5 +1,5 @@
1
1
  import { BaseRequestSign, InternalRequestSign } from '@subwallet/extension-base/background/KoniTypes';
2
- import { UnstakingInfo } from '../info';
2
+ import { UnstakingInfo, YieldPoolInfo } from '../info';
3
3
  /**
4
4
  * @interface YieldLeaveParams
5
5
  * @description Request params to leave pool
@@ -8,6 +8,7 @@ import { UnstakingInfo } from '../info';
8
8
  * @prop {string} slug - Pool's slug
9
9
  * @prop {string} [selectedTarget] - Pool target want to leave (nomination pool and native staking need)
10
10
  * @prop {boolean} fastLeave - Fast leave pool (swap token)
11
+ * @prop {YieldPoolInfo} poolInfo - Pool's info - use for create history
11
12
  * */
12
13
  export interface YieldLeaveParams extends BaseRequestSign {
13
14
  /** Request account */
@@ -20,6 +21,8 @@ export interface YieldLeaveParams extends BaseRequestSign {
20
21
  selectedTarget?: string;
21
22
  /** Fast leave pool (swap token) */
22
23
  fastLeave: boolean;
24
+ /** Pool's info - use for create history */
25
+ poolInfo: YieldPoolInfo;
23
26
  }
24
27
  export declare type RequestYieldLeave = InternalRequestSign<YieldLeaveParams>;
25
28
  /**
@@ -1,4 +1,4 @@
1
- import { YieldPoolType } from '../base';
1
+ import { BasePoolInfo, YieldPoolType } from '../base';
2
2
  import { EarningStatus, NominationInfo } from './target';
3
3
  import { UnstakingInfo } from './unstake';
4
4
  export interface YieldAssetBalance {
@@ -8,23 +8,12 @@ export interface YieldAssetBalance {
8
8
  }
9
9
  /**
10
10
  * @interface BaseYieldPositionInfo
11
+ * @extends BasePoolInfo
11
12
  * @prop {string} address - Account address
12
- * @prop {string} chain - Chain's slug
13
- * @prop {string} group - Pool's group
14
- * @prop {string} slug - Pool's slug
15
- * @prop {YieldPoolType} type - Pool's type
16
13
  * */
17
- export interface BaseYieldPositionInfo {
14
+ export interface BaseYieldPositionInfo extends BasePoolInfo {
18
15
  /** Account address */
19
16
  address: string;
20
- /** Chain's slug */
21
- chain: string;
22
- /** Pool's group */
23
- group: string;
24
- /** Pool's slug */
25
- slug: string;
26
- /** Pool's type */
27
- type: YieldPoolType;
28
17
  }
29
18
  /**
30
19
  * @interface AbstractYieldPositionInfo
@@ -1,29 +1,18 @@
1
1
  import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
2
- import { YieldPoolType } from '../base';
2
+ import { BasePoolInfo } from '../base';
3
3
  /**
4
4
  * @interface EarningRewardItem
5
+ * @extends BasePoolInfo
5
6
  * @prop {string} address - Account address
6
- * @prop {string} chain - Chain's slug
7
- * @prop {string} group - Pool's group
8
- * @prop {string} slug - Pool's slug
9
- * @prop {YieldPoolType} type - Pool's type
10
7
  * @prop {APIItemState} state - State of item
11
8
  * @prop {string} [latestReward] - Latest rewarded claimed
12
9
  * @prop {string} [totalReward] - Total rewarded claimed
13
10
  * @prop {string} [totalSlash] - Total token slashed
14
11
  * @prop {string} [unclaimedReward] - Un-claim reward
15
12
  * */
16
- export interface EarningRewardItem {
13
+ export interface EarningRewardItem extends BasePoolInfo {
17
14
  /** Account address */
18
15
  address: string;
19
- /** Chain's slug */
20
- chain: string;
21
- /** Pool's group */
22
- group: string;
23
- /** Pool's slug */
24
- slug: string;
25
- /** Pool's type */
26
- type: YieldPoolType;
27
16
  /** State of item */
28
17
  state: APIItemState;
29
18
  /** Latest rewarded claimed */
@@ -26,3 +26,20 @@ export declare enum YieldCompoundingPeriod {
26
26
  MONTHLY = 30,
27
27
  YEARLY = 365
28
28
  }
29
+ /**
30
+ * @interface BasePoolInfo
31
+ * @prop {string} slug - Pool's slug
32
+ * @prop {string} chain - Pool's chain
33
+ * @prop {string} type - Pool's type
34
+ * @prop {string} group - Pool's group (by token)
35
+ * */
36
+ export interface BasePoolInfo {
37
+ /** Pool's slug */
38
+ slug: string;
39
+ /** Pool's chain */
40
+ chain: string;
41
+ /** Pool's type */
42
+ type: YieldPoolType;
43
+ /** Pool's group (by token) */
44
+ group: string;
45
+ }
@@ -20,6 +20,14 @@ export let YieldPoolType;
20
20
  YieldPoolType["PARACHAIN_STAKING"] = "PARACHAIN_STAKING";
21
21
  })(YieldPoolType || (YieldPoolType = {}));
22
22
  export let YieldCompoundingPeriod;
23
+
24
+ /**
25
+ * @interface BasePoolInfo
26
+ * @prop {string} slug - Pool's slug
27
+ * @prop {string} chain - Pool's chain
28
+ * @prop {string} type - Pool's type
29
+ * @prop {string} group - Pool's group (by token)
30
+ * */
23
31
  (function (YieldCompoundingPeriod) {
24
32
  YieldCompoundingPeriod[YieldCompoundingPeriod["DAILY"] = 1] = "DAILY";
25
33
  YieldCompoundingPeriod[YieldCompoundingPeriod["WEEKLY"] = 7] = "WEEKLY";