@glowlabs-org/utils 0.2.154 → 0.2.155

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.
package/dist/esm/index.js CHANGED
@@ -13,8 +13,8 @@ import { parseUnits, formatUnits } from 'viem';
13
13
  import { MerkleTree } from 'merkletreejs';
14
14
  import { solidityPackedKeccak256, keccak256 } from 'ethers';
15
15
  import Decimal from 'decimal.js';
16
- import { H as HUB_URL, U as USDG_WEIGHT_DECIMAL_PRECISION, G as GLOW_WEIGHT_DECIMAL_PRECISION, M as MAX_WEIGHT } from './farms-router-C0g4hf2Z.js';
17
- export { C as ControlRouter, F as FarmsRouter, d as KICKSTARTER_STATUS, K as KickstarterRouter, O as OFF_CHAIN_PAYMENT_CURRENCIES, P as PAYMENT_CURRENCIES, b as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, T as TRANSFER_TYPES, W as WalletsRouter, c as configureSentry, u as useForwarder, a as useOffchainFractions } from './farms-router-C0g4hf2Z.js';
16
+ import { H as HUB_URL, U as USDG_WEIGHT_DECIMAL_PRECISION, G as GLOW_WEIGHT_DECIMAL_PRECISION, M as MAX_WEIGHT } from './farms-router-BYpMNa_b.js';
17
+ export { C as ControlRouter, F as FarmsRouter, d as KICKSTARTER_STATUS, K as KickstarterRouter, O as OFF_CHAIN_PAYMENT_CURRENCIES, P as PAYMENT_CURRENCIES, b as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, T as TRANSFER_TYPES, W as WalletsRouter, c as configureSentry, u as useForwarder, a as useOffchainFractions } from './farms-router-BYpMNa_b.js';
18
18
 
19
19
  const GENESIS_TIMESTAMP = 1700352000;
20
20
 
@@ -28,11 +28,12 @@
28
28
  * Calculates mining scores for existing farms that are already live on the protocol.
29
29
  * The mining score represents the return on investment for a miner based on the farm's total GLW rewards.
30
30
  */
31
- import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse } from "../types";
31
+ import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse, FarmWeeklyRewardsResponse, FarmWeeklyRewardsQuery } from "../types";
32
32
  export declare function FarmsRouter(baseUrl: string): {
33
33
  readonly fetchFarmRewardSplits: (farmId: string) => Promise<FarmRewardSplit[]>;
34
34
  readonly fetchSponsoredFarms: (sponsorWallet?: string) => Promise<SponsoredFarm[]>;
35
35
  readonly fetchWalletFarmsWithRewards: (walletAddress: string) => Promise<FarmWithRewards[]>;
36
+ readonly fetchFarmWeeklyRewards: (farmId: string, query?: FarmWeeklyRewardsQuery) => Promise<FarmWeeklyRewardsResponse>;
36
37
  readonly estimateRewardScore: (params: EstimateRewardScoreParams) => Promise<RewardScoreResponse>;
37
38
  readonly estimateRewardScoresBatch: (params: EstimateRewardScoresBatchParams) => Promise<EstimateRewardScoresBatchResponse>;
38
39
  readonly calculateMiningScoresBatch: (params: MiningScoresBatchParams) => Promise<MiningScoresBatchResponse>;
@@ -1,4 +1,4 @@
1
- import type { RegionWithMetadata, ActivationConfig, ActivationEvent, RegionDetails, SponsoredFarm, ActiveRegionsSummaryResponse, RecentRegionActivityResponse, InstallerApplicationPayload, InstallerApplicationResponse } from "../types";
1
+ import type { RegionWithMetadata, ActivationConfig, ActivationEvent, RegionDetails, SponsoredFarm, ActiveRegionsSummaryResponse, RecentRegionActivityResponse, InstallerApplicationPayload, InstallerApplicationResponse, RegionWeeklyRewardsResponse, RegionWeeklyRewardsQuery } from "../types";
2
2
  export declare function RegionRouter(baseUrl: string): {
3
3
  readonly fetchRegions: (params?: {
4
4
  isActive?: boolean;
@@ -9,6 +9,7 @@ export declare function RegionRouter(baseUrl: string): {
9
9
  readonly fetchRegionSolarFarms: (regionId: number) => Promise<SponsoredFarm[]>;
10
10
  readonly fetchActiveSummary: () => Promise<ActiveRegionsSummaryResponse>;
11
11
  readonly fetchRecentActivity: () => Promise<RecentRegionActivityResponse>;
12
+ readonly fetchRegionWeeklyRewards: (regionId: number, query?: RegionWeeklyRewardsQuery) => Promise<RegionWeeklyRewardsResponse>;
12
13
  readonly getRegionByCode: (code: string) => RegionWithMetadata | null;
13
14
  readonly applyInstallerCertification: (payload: InstallerApplicationPayload) => Promise<InstallerApplicationResponse>;
14
15
  readonly regions: RegionWithMetadata[];
@@ -1,8 +1,8 @@
1
- import type { ControlWallet, WalletDetails } from "../types";
2
- import type { MintedEvent, StakedEvent } from "../types";
1
+ import type { ControlWallet, WalletDetails, MintedEvent, StakedEvent, WalletWeeklyRewardsResponse, WeeklyRewardsQuery } from "../types";
3
2
  export declare function WalletsRouter(baseUrl: string): {
4
3
  readonly fetchAllWallets: () => Promise<ControlWallet[]>;
5
4
  readonly fetchWalletByAddress: (wallet: string) => Promise<WalletDetails>;
6
5
  readonly fetchWalletMintedEvents: (wallet: string, page?: number, limit?: number) => Promise<MintedEvent[]>;
7
6
  readonly fetchWalletStakeEvents: (wallet: string, page?: number, limit?: number, regionId?: number) => Promise<StakedEvent[]>;
7
+ readonly fetchWalletWeeklyRewards: (wallet: string, query?: WeeklyRewardsQuery) => Promise<WalletWeeklyRewardsResponse>;
8
8
  };
@@ -478,7 +478,9 @@ export interface WalletFarmInfo {
478
478
  protocolDepositPaidAmount: string;
479
479
  protocolDepositPaidCurrency: string;
480
480
  builtEpoch: number;
481
- builtAt: string;
481
+ builtAt?: string;
482
+ glowSplitPercent6Decimals: string;
483
+ depositSplitPercent6Decimals: string;
482
484
  }
483
485
  export interface WalletDetails {
484
486
  wallet: string;
@@ -489,6 +491,80 @@ export interface WalletDetails {
489
491
  regions: WalletRegionStakeTotal[];
490
492
  ownedFarms: WalletFarmInfo[];
491
493
  }
494
+ export interface WeeklyReward {
495
+ weekNumber: number;
496
+ paymentCurrency: PaymentCurrency;
497
+ protocolDepositRewardsReceived: string;
498
+ glowInflationTotal: string;
499
+ }
500
+ export interface WeeklyRewardsSummary {
501
+ totalProtocolDepositRewardsReceived: string;
502
+ totalGlowInflation: string;
503
+ weeksActive: number;
504
+ }
505
+ export interface WalletWeeklyRewardsResponse {
506
+ wallet: string;
507
+ summary: WeeklyRewardsSummary;
508
+ rewards: WeeklyReward[];
509
+ }
510
+ export interface WeeklyRewardsQuery {
511
+ startWeek?: number;
512
+ endWeek?: number;
513
+ paymentCurrency?: PaymentCurrency;
514
+ limit?: number;
515
+ }
516
+ export interface FarmWeeklyReward {
517
+ weekNumber: number;
518
+ paymentCurrency: PaymentCurrency;
519
+ protocolDepositPaidTotal: string;
520
+ glowInflationTotal: string;
521
+ expectedProductionTotal: string;
522
+ protocolDepositRewardsDistributed: string;
523
+ }
524
+ export interface FarmWeeklyRewardsSummary {
525
+ totalProtocolDepositPaid: string;
526
+ totalGlowInflation: string;
527
+ totalExpectedProduction: string;
528
+ weeksActive: number;
529
+ }
530
+ export interface FarmWeeklyRewardsResponse {
531
+ farmId: string;
532
+ summary: FarmWeeklyRewardsSummary;
533
+ rewards: FarmWeeklyReward[];
534
+ }
535
+ export interface FarmWeeklyRewardsQuery {
536
+ startWeek?: number;
537
+ endWeek?: number;
538
+ paymentCurrency?: PaymentCurrency;
539
+ limit?: number;
540
+ }
541
+ export interface RegionWeeklyReward {
542
+ weekNumber: number;
543
+ paymentCurrency: PaymentCurrency;
544
+ protocolDepositPaidTotal: string;
545
+ glowInflationTotal: string;
546
+ expectedProductionTotal: string;
547
+ protocolDepositRewardsDistributed: string;
548
+ createdAt?: string;
549
+ updatedAt?: string;
550
+ }
551
+ export interface RegionWeeklyRewardsSummary {
552
+ totalProtocolDepositPaid: string;
553
+ totalGlowInflation: string;
554
+ totalExpectedProduction: string;
555
+ weeksActive: number;
556
+ }
557
+ export interface RegionWeeklyRewardsResponse {
558
+ regionId: number;
559
+ summary: RegionWeeklyRewardsSummary;
560
+ rewards: RegionWeeklyReward[];
561
+ }
562
+ export interface RegionWeeklyRewardsQuery {
563
+ startWeek?: number;
564
+ endWeek?: number;
565
+ paymentCurrency?: PaymentCurrency;
566
+ limit?: number;
567
+ }
492
568
  export interface EstimateRewardScoreParams {
493
569
  userId: string;
494
570
  sponsorSplitPercent: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.154",
3
+ "version": "0.2.155",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -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
  }
@@ -573,7 +573,9 @@ export interface WalletFarmInfo {
573
573
  protocolDepositPaidCurrency: string;
574
574
 
575
575
  builtEpoch: number;
576
- builtAt: string; // ISO 8601
576
+ builtAt?: string; // ISO 8601
577
+ glowSplitPercent6Decimals: string; // Wallet's GLW reward split (6 decimals)
578
+ depositSplitPercent6Decimals: string; // Wallet's deposit reward split (6 decimals)
577
579
  }
578
580
 
579
581
  export interface WalletDetails {
@@ -586,6 +588,94 @@ export interface WalletDetails {
586
588
  ownedFarms: WalletFarmInfo[];
587
589
  }
588
590
 
591
+ export interface WeeklyReward {
592
+ weekNumber: number;
593
+ paymentCurrency: PaymentCurrency;
594
+ protocolDepositRewardsReceived: string; // Protocol deposit rewards received by wallet
595
+ glowInflationTotal: string; // GLW inflation rewards (18 decimals)
596
+ }
597
+
598
+ export interface WeeklyRewardsSummary {
599
+ totalProtocolDepositRewardsReceived: string;
600
+ totalGlowInflation: string;
601
+ weeksActive: number;
602
+ }
603
+
604
+ export interface WalletWeeklyRewardsResponse {
605
+ wallet: string;
606
+ summary: WeeklyRewardsSummary;
607
+ rewards: WeeklyReward[];
608
+ }
609
+
610
+ export interface WeeklyRewardsQuery {
611
+ startWeek?: number; // Inclusive lower bound epoch/week
612
+ endWeek?: number; // Inclusive upper bound epoch/week
613
+ paymentCurrency?: PaymentCurrency; // Filter by payment currency
614
+ limit?: number; // Max rows to return (default 52, capped at 520)
615
+ }
616
+
617
+ // ----------------------------- Farm Weekly Rewards ---------------------------
618
+ export interface FarmWeeklyReward {
619
+ weekNumber: number;
620
+ paymentCurrency: PaymentCurrency;
621
+ protocolDepositPaidTotal: string; // Total amount farm paid as protocol deposit
622
+ glowInflationTotal: string; // Total GLW inflation rewards allocated to farm (18 decimals)
623
+ expectedProductionTotal: string; // Farm's weekly carbon credit production in WAD (18 decimals)
624
+ protocolDepositRewardsDistributed: string; // Portion of protocol deposits distributed to wallets
625
+ }
626
+
627
+ export interface FarmWeeklyRewardsSummary {
628
+ totalProtocolDepositPaid: string;
629
+ totalGlowInflation: string;
630
+ totalExpectedProduction: string;
631
+ weeksActive: number;
632
+ }
633
+
634
+ export interface FarmWeeklyRewardsResponse {
635
+ farmId: string;
636
+ summary: FarmWeeklyRewardsSummary;
637
+ rewards: FarmWeeklyReward[];
638
+ }
639
+
640
+ export interface FarmWeeklyRewardsQuery {
641
+ startWeek?: number; // Inclusive lower bound epoch/week
642
+ endWeek?: number; // Inclusive upper bound epoch/week
643
+ paymentCurrency?: PaymentCurrency; // Filter by payment currency
644
+ limit?: number; // Max rows to return (default 52, capped at 520)
645
+ }
646
+
647
+ // ----------------------------- Region Weekly Rewards -------------------------
648
+ export interface RegionWeeklyReward {
649
+ weekNumber: number;
650
+ paymentCurrency: PaymentCurrency;
651
+ protocolDepositPaidTotal: string; // Total amount paid by all farms in region as protocol deposit
652
+ glowInflationTotal: string; // Total GLW inflation rewards allocated to region (18 decimals)
653
+ expectedProductionTotal: string; // Region's total weekly carbon credit production in WAD (18 decimals)
654
+ protocolDepositRewardsDistributed: string; // Always "0" for regions (tracked at farm level)
655
+ createdAt?: string; // ISO 8601
656
+ updatedAt?: string; // ISO 8601
657
+ }
658
+
659
+ export interface RegionWeeklyRewardsSummary {
660
+ totalProtocolDepositPaid: string;
661
+ totalGlowInflation: string;
662
+ totalExpectedProduction: string;
663
+ weeksActive: number;
664
+ }
665
+
666
+ export interface RegionWeeklyRewardsResponse {
667
+ regionId: number;
668
+ summary: RegionWeeklyRewardsSummary;
669
+ rewards: RegionWeeklyReward[];
670
+ }
671
+
672
+ export interface RegionWeeklyRewardsQuery {
673
+ startWeek?: number; // Inclusive lower bound epoch/week
674
+ endWeek?: number; // Inclusive upper bound epoch/week
675
+ paymentCurrency?: PaymentCurrency; // Filter by payment currency
676
+ limit?: number; // Max rows to return (default 52, capped at 520)
677
+ }
678
+
589
679
  // ----------------------------- Farms Reward Score ---------------------------
590
680
  export interface EstimateRewardScoreParams {
591
681
  userId: string;