@glowlabs-org/utils 0.2.128 → 0.2.130

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-CXLLMwfG.js';
17
- export { C as ControlRouter, F as FarmsRouter, c 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, u as useForwarder, a as useOffchainFractions } from './farms-router-CXLLMwfG.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-DqPqj03h.js';
17
+ export { C as ControlRouter, F as FarmsRouter, c 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, u as useForwarder, a as useOffchainFractions } from './farms-router-DqPqj03h.js';
18
18
 
19
19
  const GENESIS_TIMESTAMP = 1700352000;
20
20
 
@@ -23,12 +23,17 @@
23
23
  * ### POST `/farms/estimate-reward-scores-batch`
24
24
  * Calculates reward scores for multiple potential marketplace farms.
25
25
  * Each farm is calculated independently as if joining the protocol by itself.
26
+ *
27
+ * ### POST `/farms/mining-scores-batch`
28
+ * Calculates mining scores for existing farms that are already live on the protocol.
29
+ * The mining score represents the return on investment for a miner based on the farm's total GLW rewards.
26
30
  */
27
- import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit } from "../types";
31
+ import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse } from "../types";
28
32
  export declare function FarmsRouter(baseUrl: string): {
29
33
  readonly fetchFarmRewardSplits: (farmId: string) => Promise<FarmRewardSplit[]>;
30
34
  readonly fetchSponsoredFarms: (sponsorWallet?: string) => Promise<SponsoredFarm[]>;
31
35
  readonly fetchWalletFarmsWithRewards: (walletAddress: string) => Promise<FarmWithRewards[]>;
32
36
  readonly estimateRewardScore: (params: EstimateRewardScoreParams) => Promise<RewardScoreResponse>;
33
37
  readonly estimateRewardScoresBatch: (params: EstimateRewardScoresBatchParams) => Promise<EstimateRewardScoresBatchResponse>;
38
+ readonly calculateMiningScoresBatch: (params: MiningScoresBatchParams) => Promise<MiningScoresBatchResponse>;
34
39
  };
@@ -470,6 +470,49 @@ export type BatchRewardScoreResult = BatchRewardScoreSuccessResult | BatchReward
470
470
  export interface EstimateRewardScoresBatchResponse {
471
471
  results: BatchRewardScoreResult[];
472
472
  }
473
+ export interface MiningScoreParams {
474
+ farmId: string;
475
+ userId: string;
476
+ dollarCostOfMiner: string;
477
+ }
478
+ export interface MiningScoresBatchParams {
479
+ farms: MiningScoreParams[];
480
+ }
481
+ export interface MiningScoreResponse {
482
+ miningScore: number;
483
+ userWeeklyGlwRewards: string;
484
+ glwPriceUsd6: string;
485
+ dollarCostOfMiner: string;
486
+ weeksOfMinerLifeRemaining: number;
487
+ regionInfo: {
488
+ regionId: number;
489
+ existingFarmCount: number;
490
+ existingTotalDepositsUsd: string;
491
+ currencyBreakdown: {
492
+ currency: string;
493
+ protocolDepositSum: string;
494
+ carbonCreditProductionSum: string;
495
+ }[];
496
+ regionGctlStaked: string;
497
+ totalGctlStakedAllRegions: string;
498
+ };
499
+ }
500
+ export interface BatchMiningScoreSuccessResult {
501
+ success: true;
502
+ data: MiningScoreResponse;
503
+ }
504
+ export interface BatchMiningScoreFailureResult {
505
+ success: false;
506
+ error: string;
507
+ farmData: {
508
+ farmId: string;
509
+ userId: string;
510
+ };
511
+ }
512
+ export type BatchMiningScoreResult = BatchMiningScoreSuccessResult | BatchMiningScoreFailureResult;
513
+ export interface MiningScoresBatchResponse {
514
+ results: BatchMiningScoreResult[];
515
+ }
473
516
  export interface UserWeeklyRewards {
474
517
  protocolDepositAsset: PaymentCurrency;
475
518
  protocolDepositRewards: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.128",
3
+ "version": "0.2.130",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -25,6 +25,10 @@
25
25
  * ### POST `/farms/estimate-reward-scores-batch`
26
26
  * Calculates reward scores for multiple potential marketplace farms.
27
27
  * Each farm is calculated independently as if joining the protocol by itself.
28
+ *
29
+ * ### POST `/farms/mining-scores-batch`
30
+ * Calculates mining scores for existing farms that are already live on the protocol.
31
+ * The mining score represents the return on investment for a miner based on the farm's total GLW rewards.
28
32
  */
29
33
 
30
34
  import type {
@@ -40,6 +44,8 @@ import type {
40
44
  FarmRewardSplitsResponse,
41
45
  FarmRewardSplitsErrorResponse,
42
46
  FarmRewardSplit,
47
+ MiningScoresBatchParams,
48
+ MiningScoresBatchResponse,
43
49
  } from "../types";
44
50
 
45
51
  function parseApiError(error: unknown): string {
@@ -166,11 +172,33 @@ export function FarmsRouter(baseUrl: string) {
166
172
  }
167
173
  };
168
174
 
175
+ const calculateMiningScoresBatch = async (
176
+ params: MiningScoresBatchParams
177
+ ): Promise<MiningScoresBatchResponse> => {
178
+ try {
179
+ const data = await request<MiningScoresBatchResponse>(
180
+ "/farms/mining-scores-batch",
181
+ {
182
+ method: "POST",
183
+ headers: {
184
+ "Content-Type": "application/json",
185
+ },
186
+ body: JSON.stringify(params),
187
+ }
188
+ );
189
+
190
+ return data;
191
+ } catch (error) {
192
+ throw new Error(parseApiError(error));
193
+ }
194
+ };
195
+
169
196
  return {
170
197
  fetchFarmRewardSplits,
171
198
  fetchSponsoredFarms,
172
199
  fetchWalletFarmsWithRewards,
173
200
  estimateRewardScore,
174
201
  estimateRewardScoresBatch,
202
+ calculateMiningScoresBatch,
175
203
  } as const;
176
204
  }
@@ -573,6 +573,59 @@ export interface EstimateRewardScoresBatchResponse {
573
573
  results: BatchRewardScoreResult[];
574
574
  }
575
575
 
576
+ // ----------------------------- Farms Mining Score ----------------------------
577
+ export interface MiningScoreParams {
578
+ farmId: string; // The farm ID of the existing farm
579
+ userId: string; // User's wallet address to calculate mining score for
580
+ dollarCostOfMiner: string; // Dollar cost of the miner (USD with 6 decimals)
581
+ }
582
+
583
+ export interface MiningScoresBatchParams {
584
+ farms: MiningScoreParams[];
585
+ }
586
+
587
+ export interface MiningScoreResponse {
588
+ miningScore: number; // Mining score (calculated using farm's total GLW rewards)
589
+ userWeeklyGlwRewards: string; // User's portion of weekly GLW rewards after split (18 decimals)
590
+ glwPriceUsd6: string; // GLW price used in calculation (6 decimals)
591
+ dollarCostOfMiner: string; // Dollar cost of miner (6 decimals)
592
+ weeksOfMinerLifeRemaining: number; // Weeks of miner life remaining (calculated from farm's end reward period)
593
+ regionInfo: {
594
+ regionId: number;
595
+ existingFarmCount: number;
596
+ existingTotalDepositsUsd: string;
597
+ currencyBreakdown: {
598
+ currency: string;
599
+ protocolDepositSum: string;
600
+ carbonCreditProductionSum: string;
601
+ }[];
602
+ regionGctlStaked: string;
603
+ totalGctlStakedAllRegions: string;
604
+ };
605
+ }
606
+
607
+ export interface BatchMiningScoreSuccessResult {
608
+ success: true;
609
+ data: MiningScoreResponse;
610
+ }
611
+
612
+ export interface BatchMiningScoreFailureResult {
613
+ success: false;
614
+ error: string;
615
+ farmData: {
616
+ farmId: string;
617
+ userId: string;
618
+ };
619
+ }
620
+
621
+ export type BatchMiningScoreResult =
622
+ | BatchMiningScoreSuccessResult
623
+ | BatchMiningScoreFailureResult;
624
+
625
+ export interface MiningScoresBatchResponse {
626
+ results: BatchMiningScoreResult[];
627
+ }
628
+
576
629
  // ----------------------------- Wallet Farm Rewards ---------------------------
577
630
  export interface UserWeeklyRewards {
578
631
  protocolDepositAsset: PaymentCurrency;