@glowlabs-org/utils 0.2.87 → 0.2.89

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.
@@ -0,0 +1,4 @@
1
+ import type { SponsoredFarm } from "../types";
2
+ export declare function FarmsRouter(baseUrl: string): {
3
+ readonly fetchSponsoredFarms: (sponsorWallet?: string) => Promise<SponsoredFarm[]>;
4
+ };
@@ -212,14 +212,21 @@ export interface ActivationEvent {
212
212
  activated: boolean;
213
213
  ts: string;
214
214
  }
215
+ export interface FarmRewardSplit {
216
+ walletAddress: string;
217
+ glowSplitPercent6Decimals: string;
218
+ depositSplitPercent6Decimals: string;
219
+ }
215
220
  export interface SponsoredFarm {
216
221
  farmId: string;
222
+ regionId: number;
217
223
  name: string;
218
224
  location: string;
219
225
  certifiedInstallerId: string | null;
220
226
  kwhCapacity: string;
221
227
  solarPanelsQuantity: number;
222
228
  adjustedWeeklyCarbonCredits: string;
229
+ protocolDepositUSDC6Decimals: string;
223
230
  protocolDepositPaidAmount: string;
224
231
  protocolDepositPaidCurrency: string;
225
232
  protocolDepositPayerWallet: string | null;
@@ -233,6 +240,7 @@ export interface SponsoredFarm {
233
240
  url: string;
234
241
  isShowingSolarPanels: boolean;
235
242
  }[];
243
+ rewardSplits: FarmRewardSplit[];
236
244
  }
237
245
  export interface SolarFarmApplication {
238
246
  applicationId: string;
@@ -265,6 +273,9 @@ export interface ActivationEventsResponse {
265
273
  export interface RegionSolarFarmsResponse {
266
274
  sponsoredFarms: SponsoredFarm[];
267
275
  }
276
+ export interface SponsoredFarmsResponse {
277
+ farms: SponsoredFarm[];
278
+ }
268
279
  export interface FetchRegionsParams {
269
280
  isActive?: boolean;
270
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.87",
3
+ "version": "0.2.89",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
package/src/index.ts CHANGED
@@ -11,3 +11,4 @@ export { ControlRouter } from "./lib/control-api/control-router";
11
11
  export { RegionRouter } from "./lib/control-api/region-router";
12
12
  export { KickstarterRouter } from "./lib/control-api/kickstarter-router";
13
13
  export { WalletsRouter } from "./lib/control-api/wallets-router";
14
+ export { FarmsRouter } from "./lib/control-api/farms-router";
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ import type { SponsoredFarm } from "../types";
4
+ import type { SponsoredFarmsResponse } from "../types";
5
+
6
+ function parseApiError(error: unknown): string {
7
+ if (!error) return "Unknown error";
8
+ if (error instanceof Error) return error.message;
9
+ const possible: any = error;
10
+ return possible?.error?.message ?? possible?.message ?? "Unknown error";
11
+ }
12
+
13
+ export function FarmsRouter(baseUrl: string) {
14
+ if (!baseUrl) throw new Error("CONTROL API base URL is not set");
15
+
16
+ const request = async <T>(path: string, init?: RequestInit): Promise<T> => {
17
+ const res = await fetch(`${baseUrl}${path}`, init);
18
+ if (!res.ok) {
19
+ const errData = await res.json().catch(() => ({}));
20
+ throw new Error(errData?.error || `Request to ${path} failed`);
21
+ }
22
+ return (await res.json()) as T;
23
+ };
24
+
25
+ const fetchSponsoredFarms = async (
26
+ sponsorWallet?: string
27
+ ): Promise<SponsoredFarm[]> => {
28
+ try {
29
+ const query = sponsorWallet
30
+ ? `?sponsorWallet=${encodeURIComponent(sponsorWallet)}`
31
+ : "";
32
+ const data = await request<SponsoredFarmsResponse>(
33
+ `/farms/sponsored${query}`
34
+ );
35
+ return data.farms ?? [];
36
+ } catch (error) {
37
+ throw new Error(parseApiError(error));
38
+ }
39
+ };
40
+
41
+ return {
42
+ fetchSponsoredFarms,
43
+ } as const;
44
+ }
@@ -278,14 +278,22 @@ export interface ActivationEvent {
278
278
  }
279
279
 
280
280
  // ----------------------------- Region VCR View ------------------------------
281
+ export interface FarmRewardSplit {
282
+ walletAddress: string;
283
+ glowSplitPercent6Decimals: string;
284
+ depositSplitPercent6Decimals: string;
285
+ }
286
+
281
287
  export interface SponsoredFarm {
282
288
  farmId: string;
289
+ regionId: number;
283
290
  name: string;
284
291
  location: string;
285
292
  certifiedInstallerId: string | null;
286
293
  kwhCapacity: string;
287
294
  solarPanelsQuantity: number;
288
295
  adjustedWeeklyCarbonCredits: string;
296
+ protocolDepositUSDC6Decimals: string;
289
297
  protocolDepositPaidAmount: string;
290
298
  protocolDepositPaidCurrency: string;
291
299
  protocolDepositPayerWallet: string | null;
@@ -299,6 +307,7 @@ export interface SponsoredFarm {
299
307
  url: string;
300
308
  isShowingSolarPanels: boolean;
301
309
  }[];
310
+ rewardSplits: FarmRewardSplit[];
302
311
  }
303
312
 
304
313
  export interface SolarFarmApplication {
@@ -339,6 +348,10 @@ export interface RegionSolarFarmsResponse {
339
348
  sponsoredFarms: SponsoredFarm[];
340
349
  }
341
350
 
351
+ export interface SponsoredFarmsResponse {
352
+ farms: SponsoredFarm[];
353
+ }
354
+
342
355
  export interface FetchRegionsParams {
343
356
  isActive?: boolean;
344
357
  }