@keplr-wallet/stores 0.12.238 → 0.12.239-rc.1

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 (50) hide show
  1. package/build/account/babylon.d.ts +24 -0
  2. package/build/account/babylon.js +160 -0
  3. package/build/account/babylon.js.map +1 -0
  4. package/build/account/cosmos.js +114 -42
  5. package/build/account/cosmos.js.map +1 -1
  6. package/build/account/index.d.ts +1 -0
  7. package/build/account/index.js +1 -0
  8. package/build/account/index.js.map +1 -1
  9. package/build/query/babylon/epoching/index.d.ts +1 -0
  10. package/build/query/babylon/epoching/index.js +18 -0
  11. package/build/query/babylon/epoching/index.js.map +1 -0
  12. package/build/query/babylon/epoching/last-epoch-msgs.d.ts +12 -0
  13. package/build/query/babylon/epoching/last-epoch-msgs.js +39 -0
  14. package/build/query/babylon/epoching/last-epoch-msgs.js.map +1 -0
  15. package/build/query/babylon/epoching/types.d.ts +13 -0
  16. package/build/query/babylon/epoching/types.js +3 -0
  17. package/build/query/babylon/epoching/types.js.map +1 -0
  18. package/build/query/babylon/index.d.ts +2 -0
  19. package/build/query/babylon/index.js +19 -0
  20. package/build/query/babylon/index.js.map +1 -0
  21. package/build/query/babylon/queries.d.ts +15 -0
  22. package/build/query/babylon/queries.js +20 -0
  23. package/build/query/babylon/queries.js.map +1 -0
  24. package/build/query/cosmos/queries.d.ts +2 -0
  25. package/build/query/cosmos/queries.js +2 -0
  26. package/build/query/cosmos/queries.js.map +1 -1
  27. package/build/query/cosmos/staking/initia-validators.d.ts +24 -0
  28. package/build/query/cosmos/staking/initia-validators.js +126 -0
  29. package/build/query/cosmos/staking/initia-validators.js.map +1 -0
  30. package/build/query/cosmos/staking/pool.js +10 -2
  31. package/build/query/cosmos/staking/pool.js.map +1 -1
  32. package/build/query/cosmos/staking/types.d.ts +15 -2
  33. package/build/query/cosmos/staking/types.js.map +1 -1
  34. package/build/query/index.d.ts +1 -0
  35. package/build/query/index.js +1 -0
  36. package/build/query/index.js.map +1 -1
  37. package/package.json +16 -16
  38. package/src/account/babylon.ts +235 -0
  39. package/src/account/cosmos.ts +111 -42
  40. package/src/account/index.ts +1 -0
  41. package/src/query/babylon/epoching/index.ts +1 -0
  42. package/src/query/babylon/epoching/last-epoch-msgs.ts +55 -0
  43. package/src/query/babylon/epoching/types.ts +14 -0
  44. package/src/query/babylon/index.ts +2 -0
  45. package/src/query/babylon/queries.ts +51 -0
  46. package/src/query/cosmos/queries.ts +7 -0
  47. package/src/query/cosmos/staking/initia-validators.ts +184 -0
  48. package/src/query/cosmos/staking/pool.ts +14 -8
  49. package/src/query/cosmos/staking/types.ts +12 -2
  50. package/src/query/index.ts +1 -0
@@ -0,0 +1,184 @@
1
+ import { Dec, CoinPretty } from "@keplr-wallet/unit";
2
+ import { observable, makeObservable, computed, runInAction } from "mobx";
3
+ import { computedFn } from "mobx-utils";
4
+ import { QuerySharedContext } from "../../../common";
5
+ import { BondStatus, InitiaValidators, Validator } from "./types";
6
+ import { ObservableQueryValidatorThumbnail } from "./validators";
7
+ import {
8
+ ObservableChainQuery,
9
+ ObservableChainQueryMap,
10
+ } from "../../chain-query";
11
+ import { ChainGetter } from "../../../chain";
12
+
13
+ export class ObservableQueryInitiaValidatorsInner extends ObservableChainQuery<InitiaValidators> {
14
+ @observable.shallow
15
+ protected thumbnailMap: Map<string, ObservableQueryValidatorThumbnail> =
16
+ new Map();
17
+
18
+ constructor(
19
+ sharedContext: QuerySharedContext,
20
+ chainId: string,
21
+ chainGetter: ChainGetter,
22
+ status: BondStatus
23
+ ) {
24
+ super(
25
+ sharedContext,
26
+ chainId,
27
+ chainGetter,
28
+ `/initia/mstaking/v1/validators?pagination.limit=1000&status=${(() => {
29
+ switch (status) {
30
+ case BondStatus.Bonded:
31
+ return "BOND_STATUS_BONDED";
32
+ case BondStatus.Unbonded:
33
+ return "BOND_STATUS_UNBONDED";
34
+ case BondStatus.Unbonding:
35
+ return "BOND_STATUS_UNBONDING";
36
+ default:
37
+ return "BOND_STATUS_UNSPECIFIED";
38
+ }
39
+ })()}`
40
+ );
41
+ makeObservable(this);
42
+ }
43
+
44
+ protected override canFetch(): boolean {
45
+ if (!this.chainGetter.getChain(this.chainId).stakeCurrency) {
46
+ return false;
47
+ }
48
+ return super.canFetch();
49
+ }
50
+
51
+ @computed
52
+ get validators(): Validator[] {
53
+ if (!this.response) {
54
+ return [];
55
+ }
56
+
57
+ const stakeCurrency = this.chainGetter.getChain(this.chainId).stakeCurrency;
58
+
59
+ if (!stakeCurrency) {
60
+ return [];
61
+ }
62
+
63
+ const validators = this.response.data.validators;
64
+
65
+ return validators.map((validator) => {
66
+ return {
67
+ ...validator,
68
+ tokens:
69
+ validator.tokens.find(
70
+ (token) => token.denom === stakeCurrency.coinMinimalDenom
71
+ )?.amount ?? "0",
72
+ delegator_shares: validator.voting_power,
73
+ };
74
+ });
75
+ }
76
+
77
+ readonly getValidator = computedFn(
78
+ (validatorAddress: string): Validator | undefined => {
79
+ const validators = this.validators;
80
+
81
+ return validators.find(
82
+ (val) => val.operator_address === validatorAddress
83
+ );
84
+ }
85
+ );
86
+
87
+ @computed
88
+ get validatorsSortedByVotingPower(): Validator[] {
89
+ const validators = this.validators;
90
+ return validators.sort((v1, v2) => {
91
+ return new Dec(v1.tokens).gt(new Dec(v2.tokens)) ? -1 : 1;
92
+ });
93
+ }
94
+
95
+ readonly getValidatorThumbnail = computedFn(
96
+ (operatorAddress: string): string => {
97
+ const query = this.getQueryValidatorThumbnail(operatorAddress);
98
+ if (!query) {
99
+ return "";
100
+ }
101
+
102
+ return query.thumbnail;
103
+ }
104
+ );
105
+
106
+ readonly getQueryValidatorThumbnail = computedFn(
107
+ (
108
+ operatorAddress: string
109
+ ): ObservableQueryValidatorThumbnail | undefined => {
110
+ const validators = this.validators;
111
+ const validator = validators.find(
112
+ (val) => val.operator_address === operatorAddress
113
+ );
114
+ if (!validator) {
115
+ return;
116
+ }
117
+
118
+ if (!validator.description.identity) {
119
+ return;
120
+ }
121
+
122
+ const identity = validator.description.identity;
123
+
124
+ if (!this.thumbnailMap.has(identity)) {
125
+ runInAction(() => {
126
+ this.thumbnailMap.set(
127
+ identity,
128
+ new ObservableQueryValidatorThumbnail(this.sharedContext, validator)
129
+ );
130
+ });
131
+ }
132
+
133
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
134
+ return this.thumbnailMap.get(identity)!;
135
+ }
136
+ );
137
+
138
+ /**
139
+ * Return the validator's voting power as human friendly (considering the coin decimals).
140
+ */
141
+ readonly getValidatorShare = computedFn(
142
+ (operatorAddress: string): CoinPretty | undefined => {
143
+ const validators = this.validators;
144
+ const validator = validators.find(
145
+ (val) => val.operator_address === operatorAddress
146
+ );
147
+ if (!validator) {
148
+ return;
149
+ }
150
+
151
+ const chainInfo = this.chainGetter.getChain(this.chainId);
152
+ const stakeCurrency = chainInfo.stakeCurrency;
153
+
154
+ if (!stakeCurrency) {
155
+ return;
156
+ }
157
+
158
+ return new CoinPretty(stakeCurrency, validator.tokens);
159
+ }
160
+ );
161
+ }
162
+
163
+ export class ObservableQueryInitiaValidators extends ObservableChainQueryMap<InitiaValidators> {
164
+ constructor(
165
+ sharedContext: QuerySharedContext,
166
+ chainId: string,
167
+ chainGetter: ChainGetter
168
+ ) {
169
+ super(sharedContext, chainId, chainGetter, (status: string) => {
170
+ return new ObservableQueryInitiaValidatorsInner(
171
+ this.sharedContext,
172
+ this.chainId,
173
+ this.chainGetter,
174
+ status as BondStatus
175
+ );
176
+ });
177
+ }
178
+
179
+ getQueryStatus(
180
+ status: BondStatus = BondStatus.Bonded
181
+ ): ObservableQueryInitiaValidatorsInner {
182
+ return this.get(status) as ObservableQueryInitiaValidatorsInner;
183
+ }
184
+ }
@@ -41,10 +41,13 @@ export class ObservableQueryStakingPool extends ObservableChainQuery<StakingPool
41
41
  return new CoinPretty(chainInfo.stakeCurrency, 0);
42
42
  }
43
43
 
44
- return new CoinPretty(
45
- chainInfo.stakeCurrency,
46
- this.response.data.pool.not_bonded_tokens
47
- );
44
+ const amount = !Array.isArray(this.response.data.pool.not_bonded_tokens)
45
+ ? this.response.data.pool.not_bonded_tokens
46
+ : this.response.data.pool.not_bonded_tokens.find(
47
+ (c) => c.denom === chainInfo.stakeCurrency?.coinMinimalDenom
48
+ )?.amount || "0";
49
+
50
+ return new CoinPretty(chainInfo.stakeCurrency, amount);
48
51
  }
49
52
 
50
53
  @computed
@@ -59,9 +62,12 @@ export class ObservableQueryStakingPool extends ObservableChainQuery<StakingPool
59
62
  return new CoinPretty(chainInfo.stakeCurrency, 0);
60
63
  }
61
64
 
62
- return new CoinPretty(
63
- chainInfo.stakeCurrency,
64
- this.response.data.pool.bonded_tokens
65
- );
65
+ const amount = !Array.isArray(this.response.data.pool.bonded_tokens)
66
+ ? this.response.data.pool.bonded_tokens
67
+ : this.response.data.pool.bonded_tokens.find(
68
+ (c) => c.denom === chainInfo.stakeCurrency?.coinMinimalDenom
69
+ )?.amount || "0";
70
+
71
+ return new CoinPretty(chainInfo.stakeCurrency, amount);
66
72
  }
67
73
  }
@@ -123,6 +123,16 @@ export type Validators = {
123
123
  // pagination: {}
124
124
  };
125
125
 
126
+ export type InitiaValidator = Omit<Validator, "tokens" | "delegator_shares"> & {
127
+ voting_power: string;
128
+ tokens: Coin[];
129
+ };
130
+
131
+ export type InitiaValidators = {
132
+ validators: InitiaValidator[];
133
+ // pagination: {}
134
+ };
135
+
126
136
  export enum BondStatus {
127
137
  Unbonded = "Unbonded",
128
138
  Unbonding = "Unbonding",
@@ -143,9 +153,9 @@ export type StakingParams = {
143
153
  export type StakingPool = {
144
154
  pool: {
145
155
  // Int
146
- not_bonded_tokens: string;
156
+ not_bonded_tokens: string | { denom: string; amount: string }[];
147
157
  // Int
148
- bonded_tokens: string;
158
+ bonded_tokens: string | { denom: string; amount: string }[];
149
159
  };
150
160
  };
151
161
 
@@ -9,3 +9,4 @@ export * from "./secret-wasm";
9
9
  export * from "./osmosis";
10
10
  export * from "./icns";
11
11
  export * from "./noble";
12
+ export * from "./babylon";