@glowlabs-org/utils 0.2.154 → 0.2.156

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 (39) hide show
  1. package/README.md +175 -17
  2. package/dist/cjs/browser.d.ts +2 -0
  3. package/dist/cjs/browser.js +7 -1
  4. package/dist/cjs/browser.js.map +1 -1
  5. package/dist/cjs/{farms-router-DwbBMkUd.js → farms-router-DekpTBQj.js} +750 -11
  6. package/dist/cjs/farms-router-DekpTBQj.js.map +1 -0
  7. package/dist/cjs/index.d.ts +1 -0
  8. package/dist/cjs/index.js +2 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/lib/abis/rewardKernelABI.d.ts +418 -0
  11. package/dist/cjs/lib/control-api/farms-router.d.ts +2 -1
  12. package/dist/cjs/lib/control-api/region-router.d.ts +2 -1
  13. package/dist/cjs/lib/control-api/wallets-router.d.ts +2 -2
  14. package/dist/cjs/lib/hooks/use-rewards-kernel.d.ts +45 -0
  15. package/dist/cjs/lib/types/index.d.ts +77 -1
  16. package/dist/esm/browser.d.ts +2 -0
  17. package/dist/esm/browser.js +2 -2
  18. package/dist/esm/{farms-router-C0g4hf2Z.js → farms-router-L56VPDNz.js} +749 -12
  19. package/dist/esm/farms-router-L56VPDNz.js.map +1 -0
  20. package/dist/esm/index.d.ts +1 -0
  21. package/dist/esm/index.js +2 -2
  22. package/dist/esm/lib/abis/rewardKernelABI.d.ts +418 -0
  23. package/dist/esm/lib/control-api/farms-router.d.ts +2 -1
  24. package/dist/esm/lib/control-api/region-router.d.ts +2 -1
  25. package/dist/esm/lib/control-api/wallets-router.d.ts +2 -2
  26. package/dist/esm/lib/hooks/use-rewards-kernel.d.ts +45 -0
  27. package/dist/esm/lib/types/index.d.ts +77 -1
  28. package/package.json +1 -1
  29. package/src/browser.ts +2 -0
  30. package/src/index.ts +1 -0
  31. package/src/lib/abis/rewardKernelABI.ts +264 -0
  32. package/src/lib/control-api/farms-router.ts +33 -0
  33. package/src/lib/control-api/region-router.ts +29 -0
  34. package/src/lib/control-api/wallets-router.ts +36 -2
  35. package/src/lib/hooks/README.md +295 -0
  36. package/src/lib/hooks/use-rewards-kernel.ts +547 -0
  37. package/src/lib/types/index.ts +91 -1
  38. package/dist/cjs/farms-router-DwbBMkUd.js.map +0 -1
  39. package/dist/esm/farms-router-C0g4hf2Z.js.map +0 -1
@@ -0,0 +1,264 @@
1
+ export const REWARDS_KERNEL_ABI = [
2
+ {
3
+ inputs: [
4
+ { internalType: "address", name: "_foundationMultisig", type: "address" },
5
+ { internalType: "address", name: "_rejectionMultisig", type: "address" },
6
+ {
7
+ internalType: "contract CounterfactualHolderFactory",
8
+ name: "f",
9
+ type: "address",
10
+ },
11
+ { internalType: "uint256", name: "_finality", type: "uint256" },
12
+ ],
13
+ stateMutability: "payable",
14
+ type: "constructor",
15
+ },
16
+ {
17
+ inputs: [{ internalType: "address", name: "target", type: "address" }],
18
+ name: "AddressEmptyCode",
19
+ type: "error",
20
+ },
21
+ {
22
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
23
+ name: "AddressInsufficientBalance",
24
+ type: "error",
25
+ },
26
+ { inputs: [], name: "AlreadyClaimedNonce", type: "error" },
27
+ { inputs: [], name: "AlreadyFinalized", type: "error" },
28
+ { inputs: [], name: "AlreadyRejected", type: "error" },
29
+ { inputs: [], name: "CannotClaimFromRejectedNonce", type: "error" },
30
+ { inputs: [], name: "CannotPostZeroRoot", type: "error" },
31
+ { inputs: [], name: "DuplicateToken", type: "error" },
32
+ { inputs: [], name: "FailedInnerCall", type: "error" },
33
+ { inputs: [], name: "InvalidMerkleProof", type: "error" },
34
+ { inputs: [], name: "LengthsDontMatch", type: "error" },
35
+ { inputs: [], name: "MaxClaimedExceeded", type: "error" },
36
+ { inputs: [], name: "NonexistentDataAtNonce", type: "error" },
37
+ { inputs: [], name: "NotFoundationMultisig", type: "error" },
38
+ { inputs: [], name: "NotRejectionMultisig", type: "error" },
39
+ { inputs: [], name: "NotYetFinalized", type: "error" },
40
+ { inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
41
+ {
42
+ inputs: [{ internalType: "address", name: "token", type: "address" }],
43
+ name: "SafeERC20FailedOperation",
44
+ type: "error",
45
+ },
46
+ {
47
+ anonymous: false,
48
+ inputs: [
49
+ {
50
+ indexed: true,
51
+ internalType: "uint256",
52
+ name: "nonce",
53
+ type: "uint256",
54
+ },
55
+ ],
56
+ name: "NonceRejected",
57
+ type: "event",
58
+ },
59
+ {
60
+ anonymous: false,
61
+ inputs: [
62
+ { indexed: true, internalType: "address", name: "user", type: "address" },
63
+ { indexed: true, internalType: "address", name: "to", type: "address" },
64
+ {
65
+ indexed: true,
66
+ internalType: "uint256",
67
+ name: "nonce",
68
+ type: "uint256",
69
+ },
70
+ {
71
+ indexed: false,
72
+ internalType: "address",
73
+ name: "from",
74
+ type: "address",
75
+ },
76
+ {
77
+ components: [
78
+ { internalType: "address", name: "token", type: "address" },
79
+ { internalType: "uint256", name: "amount", type: "uint256" },
80
+ ],
81
+ indexed: false,
82
+ internalType: "struct FoundationRewardKernel.TokenAndAmount[]",
83
+ name: "taa",
84
+ type: "tuple[]",
85
+ },
86
+ {
87
+ indexed: false,
88
+ internalType: "bool[]",
89
+ name: "isGuarded",
90
+ type: "bool[]",
91
+ },
92
+ ],
93
+ name: "RewardClaimed",
94
+ type: "event",
95
+ },
96
+ {
97
+ anonymous: false,
98
+ inputs: [
99
+ {
100
+ indexed: true,
101
+ internalType: "uint256",
102
+ name: "nonce",
103
+ type: "uint256",
104
+ },
105
+ { indexed: true, internalType: "bytes32", name: "root", type: "bytes32" },
106
+ {
107
+ components: [
108
+ { internalType: "address", name: "token", type: "address" },
109
+ { internalType: "uint256", name: "amount", type: "uint256" },
110
+ ],
111
+ indexed: false,
112
+ internalType: "struct FoundationRewardKernel.TokenAndAmount[]",
113
+ name: "taa",
114
+ type: "tuple[]",
115
+ },
116
+ ],
117
+ name: "RootPosted",
118
+ type: "event",
119
+ },
120
+ {
121
+ inputs: [],
122
+ name: "$nextPostNonce",
123
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
124
+ stateMutability: "view",
125
+ type: "function",
126
+ },
127
+ {
128
+ inputs: [],
129
+ name: "CFH_FACTORY",
130
+ outputs: [
131
+ {
132
+ internalType: "contract CounterfactualHolderFactory",
133
+ name: "",
134
+ type: "address",
135
+ },
136
+ ],
137
+ stateMutability: "view",
138
+ type: "function",
139
+ },
140
+ {
141
+ inputs: [],
142
+ name: "FINALITY",
143
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
144
+ stateMutability: "view",
145
+ type: "function",
146
+ },
147
+ {
148
+ inputs: [],
149
+ name: "FOUNDATION_MULTISIG",
150
+ outputs: [{ internalType: "address", name: "", type: "address" }],
151
+ stateMutability: "view",
152
+ type: "function",
153
+ },
154
+ {
155
+ inputs: [],
156
+ name: "REJECTION_MULTISIG",
157
+ outputs: [{ internalType: "address", name: "", type: "address" }],
158
+ stateMutability: "view",
159
+ type: "function",
160
+ },
161
+ {
162
+ inputs: [
163
+ { internalType: "uint256", name: "nonce", type: "uint256" },
164
+ { internalType: "bytes32[]", name: "proof", type: "bytes32[]" },
165
+ {
166
+ components: [
167
+ { internalType: "address", name: "token", type: "address" },
168
+ { internalType: "uint256", name: "amount", type: "uint256" },
169
+ ],
170
+ internalType: "struct FoundationRewardKernel.TokenAndAmount[]",
171
+ name: "taa",
172
+ type: "tuple[]",
173
+ },
174
+ { internalType: "address", name: "from", type: "address" },
175
+ { internalType: "address", name: "to", type: "address" },
176
+ { internalType: "bool[]", name: "isGuardedToken", type: "bool[]" },
177
+ { internalType: "bool[]", name: "toCounterfactual", type: "bool[]" },
178
+ ],
179
+ name: "claimPayout",
180
+ outputs: [],
181
+ stateMutability: "nonpayable",
182
+ type: "function",
183
+ },
184
+ {
185
+ inputs: [
186
+ { internalType: "uint256", name: "nonce", type: "uint256" },
187
+ { internalType: "address", name: "token", type: "address" },
188
+ ],
189
+ name: "getAmountClaimed",
190
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
191
+ stateMutability: "view",
192
+ type: "function",
193
+ },
194
+ {
195
+ inputs: [
196
+ { internalType: "uint256", name: "nonce", type: "uint256" },
197
+ { internalType: "address", name: "token", type: "address" },
198
+ ],
199
+ name: "getMaxReward",
200
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
201
+ stateMutability: "view",
202
+ type: "function",
203
+ },
204
+ {
205
+ inputs: [{ internalType: "uint256", name: "nonce", type: "uint256" }],
206
+ name: "getRewardMeta",
207
+ outputs: [
208
+ { internalType: "bytes32", name: "merkleRoot", type: "bytes32" },
209
+ { internalType: "uint48", name: "pushTimestamp", type: "uint48" },
210
+ { internalType: "bool", name: "rejected", type: "bool" },
211
+ ],
212
+ stateMutability: "view",
213
+ type: "function",
214
+ },
215
+ {
216
+ inputs: [
217
+ { internalType: "address", name: "user", type: "address" },
218
+ { internalType: "uint256", name: "nonce", type: "uint256" },
219
+ ],
220
+ name: "isClaimed",
221
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
222
+ stateMutability: "view",
223
+ type: "function",
224
+ },
225
+ {
226
+ inputs: [{ internalType: "uint256", name: "nonce", type: "uint256" }],
227
+ name: "isFinalized",
228
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
229
+ stateMutability: "view",
230
+ type: "function",
231
+ },
232
+ {
233
+ inputs: [{ internalType: "bytes[]", name: "data", type: "bytes[]" }],
234
+ name: "multicall",
235
+ outputs: [{ internalType: "bytes[]", name: "results", type: "bytes[]" }],
236
+ stateMutability: "nonpayable",
237
+ type: "function",
238
+ },
239
+ {
240
+ inputs: [
241
+ { internalType: "bytes32", name: "root", type: "bytes32" },
242
+ {
243
+ components: [
244
+ { internalType: "address", name: "token", type: "address" },
245
+ { internalType: "uint256", name: "amount", type: "uint256" },
246
+ ],
247
+ internalType: "struct FoundationRewardKernel.TokenAndAmount[]",
248
+ name: "taa",
249
+ type: "tuple[]",
250
+ },
251
+ ],
252
+ name: "postPayoutRoot",
253
+ outputs: [],
254
+ stateMutability: "nonpayable",
255
+ type: "function",
256
+ },
257
+ {
258
+ inputs: [{ internalType: "uint256", name: "nonce", type: "uint256" }],
259
+ name: "rejectNonce",
260
+ outputs: [],
261
+ stateMutability: "nonpayable",
262
+ type: "function",
263
+ },
264
+ ] as const;
@@ -46,6 +46,8 @@ import type {
46
46
  FarmRewardSplit,
47
47
  MiningScoresBatchParams,
48
48
  MiningScoresBatchResponse,
49
+ FarmWeeklyRewardsResponse,
50
+ FarmWeeklyRewardsQuery,
49
51
  } from "../types";
50
52
  import {
51
53
  sentryAddBreadcrumb,
@@ -128,6 +130,36 @@ export function FarmsRouter(baseUrl: string) {
128
130
  }
129
131
  };
130
132
 
133
+ const fetchFarmWeeklyRewards = async (
134
+ farmId: string,
135
+ query?: FarmWeeklyRewardsQuery
136
+ ): Promise<FarmWeeklyRewardsResponse> => {
137
+ try {
138
+ if (!farmId) {
139
+ throw new Error("Farm ID is required");
140
+ }
141
+
142
+ const params = new URLSearchParams();
143
+ if (query?.startWeek !== undefined)
144
+ params.set("startWeek", query.startWeek.toString());
145
+ if (query?.endWeek !== undefined)
146
+ params.set("endWeek", query.endWeek.toString());
147
+ if (query?.paymentCurrency)
148
+ params.set("paymentCurrency", query.paymentCurrency);
149
+ if (query?.limit !== undefined)
150
+ params.set("limit", query.limit.toString());
151
+
152
+ const queryString = params.toString();
153
+ const path = `/farms/${encodeURIComponent(farmId)}/weekly-rewards${
154
+ queryString ? `?${queryString}` : ""
155
+ }`;
156
+
157
+ return await request<FarmWeeklyRewardsResponse>(path);
158
+ } catch (error) {
159
+ throw new Error(parseApiError(error));
160
+ }
161
+ };
162
+
131
163
  const estimateRewardScore = async (
132
164
  params: EstimateRewardScoreParams
133
165
  ): Promise<RewardScoreResponse> => {
@@ -236,6 +268,7 @@ export function FarmsRouter(baseUrl: string) {
236
268
  fetchFarmRewardSplits,
237
269
  fetchSponsoredFarms,
238
270
  fetchWalletFarmsWithRewards,
271
+ fetchFarmWeeklyRewards,
239
272
  estimateRewardScore,
240
273
  estimateRewardScoresBatch,
241
274
  calculateMiningScoresBatch,
@@ -12,6 +12,8 @@ import type {
12
12
  RecentRegionActivityResponse,
13
13
  InstallerApplicationPayload,
14
14
  InstallerApplicationResponse,
15
+ RegionWeeklyRewardsResponse,
16
+ RegionWeeklyRewardsQuery,
15
17
  } from "../types";
16
18
 
17
19
  // ---------------------------------------------------------------------------
@@ -145,6 +147,32 @@ export function RegionRouter(baseUrl: string) {
145
147
  }
146
148
  };
147
149
 
150
+ const fetchRegionWeeklyRewards = async (
151
+ regionId: number,
152
+ query?: RegionWeeklyRewardsQuery
153
+ ): Promise<RegionWeeklyRewardsResponse> => {
154
+ try {
155
+ const params = new URLSearchParams();
156
+ if (query?.startWeek !== undefined)
157
+ params.set("startWeek", query.startWeek.toString());
158
+ if (query?.endWeek !== undefined)
159
+ params.set("endWeek", query.endWeek.toString());
160
+ if (query?.paymentCurrency)
161
+ params.set("paymentCurrency", query.paymentCurrency);
162
+ if (query?.limit !== undefined)
163
+ params.set("limit", query.limit.toString());
164
+
165
+ const queryString = params.toString();
166
+ const path = `/regions/weekly-rewards/${regionId}${
167
+ queryString ? `?${queryString}` : ""
168
+ }`;
169
+
170
+ return await request<RegionWeeklyRewardsResponse>(path);
171
+ } catch (error) {
172
+ throw new Error(parseApiError(error));
173
+ }
174
+ };
175
+
148
176
  const applyInstallerCertification = async (
149
177
  payload: InstallerApplicationPayload
150
178
  ): Promise<InstallerApplicationResponse> => {
@@ -218,6 +246,7 @@ export function RegionRouter(baseUrl: string) {
218
246
  fetchRegionSolarFarms,
219
247
  fetchActiveSummary,
220
248
  fetchRecentActivity,
249
+ fetchRegionWeeklyRewards,
221
250
  getRegionByCode,
222
251
  applyInstallerCertification,
223
252
 
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
2
 
3
- import type { ControlWallet, WalletsResponse, WalletDetails } from "../types";
4
- import type { MintedEvent, StakedEvent } from "../types";
3
+ import type {
4
+ ControlWallet,
5
+ WalletsResponse,
6
+ WalletDetails,
7
+ MintedEvent,
8
+ StakedEvent,
9
+ WalletWeeklyRewardsResponse,
10
+ WeeklyRewardsQuery,
11
+ } from "../types";
5
12
 
6
13
  function parseApiError(error: unknown): string {
7
14
  if (!error) return "Unknown error";
@@ -85,10 +92,37 @@ export function WalletsRouter(baseUrl: string) {
85
92
  }
86
93
  };
87
94
 
95
+ const fetchWalletWeeklyRewards = async (
96
+ wallet: string,
97
+ query?: WeeklyRewardsQuery
98
+ ): Promise<WalletWeeklyRewardsResponse> => {
99
+ try {
100
+ const params = new URLSearchParams();
101
+ if (query?.startWeek !== undefined)
102
+ params.set("startWeek", query.startWeek.toString());
103
+ if (query?.endWeek !== undefined)
104
+ params.set("endWeek", query.endWeek.toString());
105
+ if (query?.paymentCurrency)
106
+ params.set("paymentCurrency", query.paymentCurrency);
107
+ if (query?.limit !== undefined)
108
+ params.set("limit", query.limit.toString());
109
+
110
+ const queryString = params.toString();
111
+ const path = `/wallets/address/${encodeURIComponent(wallet)}/weekly-rewards${
112
+ queryString ? `?${queryString}` : ""
113
+ }`;
114
+
115
+ return await request<WalletWeeklyRewardsResponse>(path);
116
+ } catch (error) {
117
+ throw new Error(parseApiError(error));
118
+ }
119
+ };
120
+
88
121
  return {
89
122
  fetchAllWallets,
90
123
  fetchWalletByAddress,
91
124
  fetchWalletMintedEvents,
92
125
  fetchWalletStakeEvents,
126
+ fetchWalletWeeklyRewards,
93
127
  } as const;
94
128
  }