@glowlabs-org/utils 0.2.129 → 0.2.131
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/cjs/browser.js +1 -1
- package/dist/cjs/{farms-router-BJHzbi9K.js → farms-router-DXTR8f4V.js} +17 -1
- package/dist/cjs/farms-router-DXTR8f4V.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/control-api/farms-router.d.ts +6 -1
- package/dist/cjs/lib/types/index.d.ts +45 -1
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{farms-router-CXLLMwfG.js → farms-router-DqPqj03h.js} +17 -1
- package/dist/esm/farms-router-DqPqj03h.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/control-api/farms-router.d.ts +6 -1
- package/dist/esm/lib/types/index.d.ts +45 -1
- package/package.json +1 -1
- package/src/lib/control-api/farms-router.ts +28 -0
- package/src/lib/types/index.ts +55 -1
- package/dist/cjs/farms-router-BJHzbi9K.js.map +0 -1
- package/dist/esm/farms-router-CXLLMwfG.js.map +0 -1
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-
|
|
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-
|
|
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
|
};
|
|
@@ -422,7 +422,6 @@ export interface EstimateRewardScoreParams {
|
|
|
422
422
|
paymentCurrency: PaymentCurrency;
|
|
423
423
|
adjustedWeeklyCarbonCredits: number;
|
|
424
424
|
regionId: number;
|
|
425
|
-
sponsorDepositSplit?: number;
|
|
426
425
|
}
|
|
427
426
|
export interface RewardScoreResponse {
|
|
428
427
|
rewardScore: number;
|
|
@@ -471,6 +470,51 @@ export type BatchRewardScoreResult = BatchRewardScoreSuccessResult | BatchReward
|
|
|
471
470
|
export interface EstimateRewardScoresBatchResponse {
|
|
472
471
|
results: BatchRewardScoreResult[];
|
|
473
472
|
}
|
|
473
|
+
export interface MiningScoreParams {
|
|
474
|
+
farmId: string;
|
|
475
|
+
userId: string;
|
|
476
|
+
dollarCostOfMiner: string;
|
|
477
|
+
numberOfMiners: number;
|
|
478
|
+
}
|
|
479
|
+
export interface MiningScoresBatchParams {
|
|
480
|
+
farms: MiningScoreParams[];
|
|
481
|
+
}
|
|
482
|
+
export interface MiningScoreResponse {
|
|
483
|
+
miningScore: number;
|
|
484
|
+
userWeeklyGlwRewards: string;
|
|
485
|
+
glwPriceUsd6: string;
|
|
486
|
+
dollarCostOfMiner: string;
|
|
487
|
+
numberOfMiners: number;
|
|
488
|
+
weeksOfMinerLifeRemaining: number;
|
|
489
|
+
regionInfo: {
|
|
490
|
+
regionId: number;
|
|
491
|
+
existingFarmCount: number;
|
|
492
|
+
existingTotalDepositsUsd: string;
|
|
493
|
+
currencyBreakdown: {
|
|
494
|
+
currency: string;
|
|
495
|
+
protocolDepositSum: string;
|
|
496
|
+
carbonCreditProductionSum: string;
|
|
497
|
+
}[];
|
|
498
|
+
regionGctlStaked: string;
|
|
499
|
+
totalGctlStakedAllRegions: string;
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
export interface BatchMiningScoreSuccessResult {
|
|
503
|
+
success: true;
|
|
504
|
+
data: MiningScoreResponse;
|
|
505
|
+
}
|
|
506
|
+
export interface BatchMiningScoreFailureResult {
|
|
507
|
+
success: false;
|
|
508
|
+
error: string;
|
|
509
|
+
farmData: {
|
|
510
|
+
farmId: string;
|
|
511
|
+
userId: string;
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
export type BatchMiningScoreResult = BatchMiningScoreSuccessResult | BatchMiningScoreFailureResult;
|
|
515
|
+
export interface MiningScoresBatchResponse {
|
|
516
|
+
results: BatchMiningScoreResult[];
|
|
517
|
+
}
|
|
474
518
|
export interface UserWeeklyRewards {
|
|
475
519
|
protocolDepositAsset: PaymentCurrency;
|
|
476
520
|
protocolDepositRewards: string;
|
package/package.json
CHANGED
|
@@ -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
|
}
|
package/src/lib/types/index.ts
CHANGED
|
@@ -514,7 +514,6 @@ export interface EstimateRewardScoreParams {
|
|
|
514
514
|
paymentCurrency: PaymentCurrency;
|
|
515
515
|
adjustedWeeklyCarbonCredits: number;
|
|
516
516
|
regionId: number;
|
|
517
|
-
sponsorDepositSplit?: number; // Optional: Sponsor deposit split percentage (0-1000000, where 1000000 = 100%). Defaults to 1000000 (100%)
|
|
518
517
|
}
|
|
519
518
|
|
|
520
519
|
export interface RewardScoreResponse {
|
|
@@ -574,6 +573,61 @@ export interface EstimateRewardScoresBatchResponse {
|
|
|
574
573
|
results: BatchRewardScoreResult[];
|
|
575
574
|
}
|
|
576
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
|
+
numberOfMiners: number; // Number of miners in the farm
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export interface MiningScoresBatchParams {
|
|
585
|
+
farms: MiningScoreParams[];
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export interface MiningScoreResponse {
|
|
589
|
+
miningScore: number; // Mining score (calculated using farm's total GLW rewards)
|
|
590
|
+
userWeeklyGlwRewards: string; // User's portion of weekly GLW rewards after split (18 decimals)
|
|
591
|
+
glwPriceUsd6: string; // GLW price used in calculation (6 decimals)
|
|
592
|
+
dollarCostOfMiner: string; // Dollar cost of miner (6 decimals)
|
|
593
|
+
numberOfMiners: number; // Number of miners in the farm
|
|
594
|
+
weeksOfMinerLifeRemaining: number; // Weeks of miner life remaining (calculated from farm's end reward period)
|
|
595
|
+
regionInfo: {
|
|
596
|
+
regionId: number;
|
|
597
|
+
existingFarmCount: number;
|
|
598
|
+
existingTotalDepositsUsd: string;
|
|
599
|
+
currencyBreakdown: {
|
|
600
|
+
currency: string;
|
|
601
|
+
protocolDepositSum: string;
|
|
602
|
+
carbonCreditProductionSum: string;
|
|
603
|
+
}[];
|
|
604
|
+
regionGctlStaked: string;
|
|
605
|
+
totalGctlStakedAllRegions: string;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export interface BatchMiningScoreSuccessResult {
|
|
610
|
+
success: true;
|
|
611
|
+
data: MiningScoreResponse;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
export interface BatchMiningScoreFailureResult {
|
|
615
|
+
success: false;
|
|
616
|
+
error: string;
|
|
617
|
+
farmData: {
|
|
618
|
+
farmId: string;
|
|
619
|
+
userId: string;
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
export type BatchMiningScoreResult =
|
|
624
|
+
| BatchMiningScoreSuccessResult
|
|
625
|
+
| BatchMiningScoreFailureResult;
|
|
626
|
+
|
|
627
|
+
export interface MiningScoresBatchResponse {
|
|
628
|
+
results: BatchMiningScoreResult[];
|
|
629
|
+
}
|
|
630
|
+
|
|
577
631
|
// ----------------------------- Wallet Farm Rewards ---------------------------
|
|
578
632
|
export interface UserWeeklyRewards {
|
|
579
633
|
protocolDepositAsset: PaymentCurrency;
|