@glowlabs-org/utils 0.2.162 → 0.2.164
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/{calculate-farm-efficiency-C1AxUV_w.js → calculate-farm-efficiency-DIL_hKMo.js} +74 -1
- package/dist/cjs/calculate-farm-efficiency-DIL_hKMo.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/control-api/farms-router.d.ts +4 -544
- package/dist/cjs/lib/types/index.d.ts +64 -0
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{calculate-farm-efficiency-BLvnmRNd.js → calculate-farm-efficiency-VRzMgQmC.js} +74 -1
- package/dist/esm/calculate-farm-efficiency-VRzMgQmC.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/control-api/farms-router.d.ts +4 -544
- package/dist/esm/lib/types/index.d.ts +64 -0
- package/package.json +1 -1
- package/src/lib/control-api/farms-router.ts +101 -544
- package/src/lib/types/index.ts +80 -0
- package/dist/cjs/calculate-farm-efficiency-C1AxUV_w.js.map +0 -1
- package/dist/esm/calculate-farm-efficiency-BLvnmRNd.js.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var viem = require('viem');
|
|
|
15
15
|
var merkletreejs = require('merkletreejs');
|
|
16
16
|
var ethers = require('ethers');
|
|
17
17
|
var Decimal = require('decimal.js');
|
|
18
|
-
var calculateFarmEfficiency = require('./calculate-farm-efficiency-
|
|
18
|
+
var calculateFarmEfficiency = require('./calculate-farm-efficiency-DIL_hKMo.js');
|
|
19
19
|
|
|
20
20
|
const GENESIS_TIMESTAMP = 1700352000;
|
|
21
21
|
|
|
@@ -1,547 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* # Farms Router
|
|
3
|
-
*
|
|
4
|
-
* This router handles operations related to solar farms.
|
|
5
|
-
*
|
|
6
|
-
* ## Endpoints
|
|
7
|
-
*
|
|
8
|
-
* ### GET `/farms/:farmId/reward-splits`
|
|
9
|
-
*
|
|
10
|
-
* Returns the current reward splits for a specific farm based on its farmId. The splits show how GLW and deposit rewards are distributed among wallet addresses.
|
|
11
|
-
*
|
|
12
|
-
* **Parameters:**
|
|
13
|
-
* - `farmId` (string): Farm ID (UUID format)
|
|
14
|
-
*
|
|
15
|
-
* **Response:**
|
|
16
|
-
*
|
|
17
|
-
* Success response:
|
|
18
|
-
* ```json
|
|
19
|
-
* {
|
|
20
|
-
* "farmId": "string",
|
|
21
|
-
* "rewardSplits": [
|
|
22
|
-
* {
|
|
23
|
-
* "walletAddress": "string", // Wallet address in 0x format
|
|
24
|
-
* "glowSplitPercent6Decimals": "string", // GLW reward split percentage (6 decimals)
|
|
25
|
-
* "depositSplitPercent6Decimals": "string" // Deposit reward split percentage (6 decimals)
|
|
26
|
-
* }
|
|
27
|
-
* ],
|
|
28
|
-
* "totalSplits": "number" // Total number of reward splits
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* Error response:
|
|
33
|
-
* ```json
|
|
34
|
-
* {
|
|
35
|
-
* "error": "string"
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* **Error Codes:**
|
|
40
|
-
* - `400`: Invalid or missing farm ID
|
|
41
|
-
* - `404`: Farm not found
|
|
42
|
-
* - `500`: Server error
|
|
43
|
-
*
|
|
44
|
-
* **Notes:**
|
|
45
|
-
* - Returns the current state of reward splits based on the complete transfer history
|
|
46
|
-
* - Splits are calculated by starting with initial allocations and applying all transfers
|
|
47
|
-
* - Only returns wallets with non-zero splits (either GLW or deposit rewards)
|
|
48
|
-
* - GLW and deposit split percentages are in 6 decimal format (e.g., 750000 = 75%)
|
|
49
|
-
*
|
|
50
|
-
* **Example:**
|
|
51
|
-
*
|
|
52
|
-
* ```bash
|
|
53
|
-
* GET /farms/550e8400-e29b-41d4-a716-446655440000/reward-splits
|
|
54
|
-
* ```
|
|
55
|
-
*
|
|
56
|
-
* ### GET `/farms/:farmId/weekly-rewards`
|
|
57
|
-
*
|
|
58
|
-
* Returns aggregated weekly totals for a farm grouped by payment currency. Each row is sourced from the `weekly_farm_rewards` table created during the weekly-report generation process.
|
|
59
|
-
*
|
|
60
|
-
* **Parameters:**
|
|
61
|
-
* - `farmId` (string): Farm ID (UUID format)
|
|
62
|
-
*
|
|
63
|
-
* **Query Parameters (optional):**
|
|
64
|
-
* - `startWeek` (number): Inclusive lower bound week/epoch.
|
|
65
|
-
* - `endWeek` (number): Inclusive upper bound week/epoch.
|
|
66
|
-
* - `paymentCurrency` (enum): Filter by a single payment currency (`PAYMENT_CURRENCIES` from `@glowlabs-org/utils/browser`).
|
|
67
|
-
* - `limit` (number): Maximum rows to return (default 52, capped at 520).
|
|
68
|
-
*
|
|
69
|
-
* **Response:**
|
|
70
|
-
*
|
|
71
|
-
* Success response:
|
|
72
|
-
* ```json
|
|
73
|
-
* {
|
|
74
|
-
* "farmId": "aa2b2449-85e9-45fe-91f1-ed21c9aed72d",
|
|
75
|
-
* "summary": {
|
|
76
|
-
* "totalProtocolDepositPaid": "22110600000",
|
|
77
|
-
* "totalGlowInflation": "6827965927008037794707",
|
|
78
|
-
* "totalExpectedProduction": "96500000000000000",
|
|
79
|
-
* "weeksActive": 1
|
|
80
|
-
* },
|
|
81
|
-
* "rewards": [
|
|
82
|
-
* {
|
|
83
|
-
* "weekNumber": 98,
|
|
84
|
-
* "paymentCurrency": "GLW",
|
|
85
|
-
* "protocolDepositPaidTotal": "22110600000",
|
|
86
|
-
* "glowInflationTotal": "6827965927008037794707",
|
|
87
|
-
* "expectedProductionTotal": "96500000000000000",
|
|
88
|
-
* "protocolDepositRewardsDistributed": "221106000"
|
|
89
|
-
* }
|
|
90
|
-
* ]
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* Error response:
|
|
95
|
-
* ```json
|
|
96
|
-
* {
|
|
97
|
-
* "error": "string"
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
* **Notes:**
|
|
102
|
-
* - The query helper automatically swaps `startWeek`/`endWeek` if they are supplied in reverse order.
|
|
103
|
-
* - `protocolDepositPaidTotal` is the **total amount the farm paid** as protocol deposit in the native decimals of `paymentCurrency` (6 decimals for USDG/USDC/SGCTL, 18 decimals for GLW/GCTL). This represents the total paid by the farm, not the amount distributed to individual wallets.
|
|
104
|
-
* - `glowInflationTotal` is the **total GLW inflation rewards allocated to this farm** (18 decimals). This is distributed to farm owners based on their `glowSplitPercent6Decimals`.
|
|
105
|
-
* - `expectedProductionTotal` is the farm's weekly carbon credit production in WAD (18 decimals).
|
|
106
|
-
* - `protocolDepositRewardsDistributed` represents the portion of protocol deposits distributed out to wallet recipients (same native decimals as `paymentCurrency`).
|
|
107
|
-
* - `weeksActive` counts distinct epochs present in the response, independent of the payment currency filters.
|
|
108
|
-
* - Data is sourced from the dedicated `weekly_farm_rewards` table for optimized farm-specific queries.
|
|
109
|
-
*
|
|
110
|
-
* **Example:**
|
|
111
|
-
*
|
|
112
|
-
* ```bash
|
|
113
|
-
* GET /farms/aa2b2449-85e9-45fe-91f1-ed21c9aed72d/weekly-rewards?startWeek=97&endWeek=98
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
* ### GET `/farms/wallet/:walletAddress/farms-with-rewards`
|
|
117
|
-
*
|
|
118
|
-
* Returns all farms where the specified wallet address has reward splits, along with their calculated weekly rewards for that wallet.
|
|
119
|
-
*
|
|
120
|
-
* **Parameters:**
|
|
121
|
-
* - `walletAddress` (string): Wallet address in 0x format
|
|
122
|
-
*
|
|
123
|
-
* **Response:**
|
|
124
|
-
*
|
|
125
|
-
* Success response:
|
|
126
|
-
* ```json
|
|
127
|
-
* {
|
|
128
|
-
* "farms": [
|
|
129
|
-
* {
|
|
130
|
-
* "farmId": "string",
|
|
131
|
-
* "certifiedInstallerId": "string" | null,
|
|
132
|
-
* "name": "string",
|
|
133
|
-
* "location": "string",
|
|
134
|
-
* "kwhCapacity": "string",
|
|
135
|
-
* "solarPanelsQuantity": number,
|
|
136
|
-
* "expectedWeeklyCarbonCredits": "string",
|
|
137
|
-
* "protocolDepositPaidAmount": "string",
|
|
138
|
-
* "protocolDepositPaidCurrency": "string",
|
|
139
|
-
*
|
|
140
|
-
* "builtEpoch": number,
|
|
141
|
-
* "builtAt": "string",
|
|
142
|
-
* "afterInstallPictures": [
|
|
143
|
-
* {
|
|
144
|
-
* "id": "string",
|
|
145
|
-
* "name": "string",
|
|
146
|
-
* "url": "string",
|
|
147
|
-
* "isShowingSolarPanels": boolean
|
|
148
|
-
* }
|
|
149
|
-
* ],
|
|
150
|
-
* "protocolDepositUSDC6Decimals": "string",
|
|
151
|
-
* "regionId": number,
|
|
152
|
-
* "rewardSplits": [
|
|
153
|
-
* {
|
|
154
|
-
* "walletAddress": "string",
|
|
155
|
-
* "glowSplitPercent6Decimals": "string",
|
|
156
|
-
* "depositSplitPercent6Decimals": "string"
|
|
157
|
-
* }
|
|
158
|
-
* ],
|
|
159
|
-
* "userWeeklyRewards": {
|
|
160
|
-
* "protocolDepositAsset": "string", // Farm payment currency (enum)
|
|
161
|
-
* "protocolDepositRewards": "string", // User's weekly protocol deposit rewards in the farm's payment currency
|
|
162
|
-
* "glwInflationRewards": "string", // User's weekly GLW inflation rewards (18 decimals)
|
|
163
|
-
* "userGlowSplitPercent": "string", // User's GLW split percentage (6 decimals)
|
|
164
|
-
* "userDepositSplitPercent": "string" // User's deposit split percentage (6 decimals)
|
|
165
|
-
* }
|
|
166
|
-
* }
|
|
167
|
-
* ],
|
|
168
|
-
* "totalFarms": number // Total number of farms returned
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* Error response:
|
|
173
|
-
* ```json
|
|
174
|
-
* {
|
|
175
|
-
* "error": "string"
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*
|
|
179
|
-
* **Notes:**
|
|
180
|
-
* - Only returns farms in active regions (where `isActivated = true`)
|
|
181
|
-
* - Weekly rewards are computed via the rewards simulator API using `getFarmRewardsForWeek`
|
|
182
|
-
* - Farms built before epoch 97 are excluded from the payload (preloaded via `preloadGlowV1`)
|
|
183
|
-
* - Simulator inputs use `weeksAlive = 100`
|
|
184
|
-
* - Protocol deposit rewards are returned in the farm's payment currency; GLW rewards use 18 decimals
|
|
185
|
-
*
|
|
186
|
-
* **Example:**
|
|
187
|
-
*
|
|
188
|
-
* ```bash
|
|
189
|
-
* GET /farms/wallet/0x1234567890abcdef1234567890abcdef12345678/farms-with-rewards
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
* ### POST `/farms/estimate-reward-score`
|
|
193
|
-
*
|
|
194
|
-
* Calculates the reward score for a potential marketplace farm based on its parameters and current region data. This endpoint uses the same reward calculation logic as the actual weekly reward distribution to ensure consistency.
|
|
195
|
-
*
|
|
196
|
-
* **Request Body:**
|
|
197
|
-
*
|
|
198
|
-
* ```json
|
|
199
|
-
* {
|
|
200
|
-
* "userId": "string", // User's wallet address (sponsor)
|
|
201
|
-
* "sponsorSplitPercent": "number", // Sponsor's split percentage (0-100)
|
|
202
|
-
* "protocolDepositAmount": "string", // Protocol deposit amount in the payment currency
|
|
203
|
-
* "paymentCurrency": "USDC" | "USDG" | "GLW" | "GCTL" | "SGCTL", // Payment currency
|
|
204
|
-
* "expectedWeeklyCarbonCredits": "number", // Weekly carbon credits production (minimum 0)
|
|
205
|
-
* "regionId": "number" // Region ID
|
|
206
|
-
* }
|
|
207
|
-
* ```
|
|
208
|
-
*
|
|
209
|
-
* **Response:**
|
|
210
|
-
*
|
|
211
|
-
* Success response:
|
|
212
|
-
*
|
|
213
|
-
* ```json
|
|
214
|
-
* {
|
|
215
|
-
* "rewardScore": "number", // Reward score (integer, rounded up)
|
|
216
|
-
* "userWeeklyPdRewards": "string", // User's weekly PD rewards in the payment currency
|
|
217
|
-
* "userWeeklyPdRewardsUsd": "string", // User's weekly PD rewards value in USD (6 decimals)
|
|
218
|
-
* "userWeeklyGlwRewards": "string", // User's weekly GLW rewards (18 decimals)
|
|
219
|
-
* "userWeeklyGlwValueUsd": "string", // User's weekly GLW rewards value in USD (6 decimals)
|
|
220
|
-
* "userEstimatedWeeklyCash": "string", // User's total estimated weekly cash in USD (6 decimals)
|
|
221
|
-
* "userProtocolDeposit": "string", // User's portion of protocol deposit in USD (6 decimals)
|
|
222
|
-
* "userGlowSplitPercent": "string", // User's GLW split percentage (6 decimals)
|
|
223
|
-
* "userDepositSplitPercent": "string", // User's deposit split percentage (6 decimals)
|
|
224
|
-
* "glwPriceUsd6": "string", // GLW price used in calculation (6 decimals)
|
|
225
|
-
* "regionInfo": {
|
|
226
|
-
* "regionId": "number",
|
|
227
|
-
* "regionGctlStaked": "string",
|
|
228
|
-
* "totalGctlStakedAllRegions": "string"
|
|
229
|
-
* }
|
|
230
|
-
* }
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* Error response:
|
|
234
|
-
*
|
|
235
|
-
* ```json
|
|
236
|
-
* {
|
|
237
|
-
* "error": "string"
|
|
238
|
-
* }
|
|
239
|
-
* ```
|
|
240
|
-
*
|
|
241
|
-
* **Example:**
|
|
242
|
-
*
|
|
243
|
-
* ```bash
|
|
244
|
-
* POST /farms/estimate-reward-score
|
|
245
|
-
* Content-Type: application/json
|
|
246
|
-
*
|
|
247
|
-
* {
|
|
248
|
-
* "userId": "0x1234567890abcdef1234567890abcdef12345678",
|
|
249
|
-
* "sponsorSplitPercent": 75,
|
|
250
|
-
* "protocolDepositAmount": "10000000000",
|
|
251
|
-
* "paymentCurrency": "USDC",
|
|
252
|
-
* "expectedWeeklyCarbonCredits": 100,
|
|
253
|
-
* "regionId": 1
|
|
254
|
-
* }
|
|
255
|
-
* ```
|
|
256
|
-
*
|
|
257
|
-
* **Notes:**
|
|
258
|
-
*
|
|
259
|
-
* - Only considers active regions (where `isActivated = true`)
|
|
260
|
-
* - Rewards are computed via the rewards simulator API using `getFarmRewardsForWeek` with `preloadGlowV1` and GCTL distribution
|
|
261
|
-
* - Simulator inputs use `weeksAlive = 100` and exclude pre-epoch-97 farms (preloaded via `preloadGlowV1`)
|
|
262
|
-
*
|
|
263
|
-
* ### POST `/farms/estimate-reward-scores-batch`
|
|
264
|
-
*
|
|
265
|
-
* Calculates reward scores for multiple potential marketplace farms. Each farm is calculated independently as if joining the protocol by itself.
|
|
266
|
-
*
|
|
267
|
-
* **Request Body:**
|
|
268
|
-
*
|
|
269
|
-
* ```json
|
|
270
|
-
* {
|
|
271
|
-
* "farms": [
|
|
272
|
-
* {
|
|
273
|
-
* "userId": "string", // User's wallet address (sponsor)
|
|
274
|
-
* "sponsorSplitPercent": "number", // Sponsor's split percentage (0-100)
|
|
275
|
-
* "protocolDepositAmount": "string", // Protocol deposit amount in the payment currency
|
|
276
|
-
* "paymentCurrency": "USDC" | "USDG" | "GLW" | "GCTL" | "SGCTL", // Payment currency
|
|
277
|
-
* "expectedWeeklyCarbonCredits": "number", // Weekly carbon credits production (minimum 0)
|
|
278
|
-
* "regionId": "number" // Region ID
|
|
279
|
-
* }
|
|
280
|
-
* ]
|
|
281
|
-
* }
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
* **Response:**
|
|
285
|
-
*
|
|
286
|
-
* ```json
|
|
287
|
-
* {
|
|
288
|
-
* "results": [
|
|
289
|
-
* // For successful calculations:
|
|
290
|
-
* {
|
|
291
|
-
* "success": true,
|
|
292
|
-
* "data": {
|
|
293
|
-
* "rewardScore": "number", // Reward score (integer, rounded up)
|
|
294
|
-
* "userWeeklyPdRewards": "string", // User's weekly PD rewards in the payment currency
|
|
295
|
-
* "userWeeklyPdRewardsUsd": "string", // User's weekly PD rewards value in USD (6 decimals)
|
|
296
|
-
* "userWeeklyGlwRewards": "string", // User's weekly GLW rewards (18 decimals)
|
|
297
|
-
* "userWeeklyGlwValueUsd": "string", // User's weekly GLW rewards value in USD (6 decimals)
|
|
298
|
-
* "userEstimatedWeeklyCash": "string", // User's total estimated weekly cash in USD (6 decimals)
|
|
299
|
-
* "userProtocolDeposit": "string", // User's portion of protocol deposit in USD (6 decimals)
|
|
300
|
-
* "userGlowSplitPercent": "string", // User's GLW split percentage (6 decimals)
|
|
301
|
-
* "userDepositSplitPercent": "string", // User's deposit split percentage (6 decimals)
|
|
302
|
-
* "glwPriceUsd6": "string", // GLW price used in calculation (6 decimals)
|
|
303
|
-
* "regionInfo": {
|
|
304
|
-
* "regionId": "number",
|
|
305
|
-
* "regionGctlStaked": "string",
|
|
306
|
-
* "totalGctlStakedAllRegions": "string"
|
|
307
|
-
* }
|
|
308
|
-
* }
|
|
309
|
-
* },
|
|
310
|
-
* // For failed calculations:
|
|
311
|
-
* {
|
|
312
|
-
* "success": false,
|
|
313
|
-
* "error": "string", // Error message
|
|
314
|
-
* "farmData": {
|
|
315
|
-
* "userId": "string",
|
|
316
|
-
* "regionId": "number",
|
|
317
|
-
* "paymentCurrency": "string"
|
|
318
|
-
* }
|
|
319
|
-
* }
|
|
320
|
-
* ]
|
|
321
|
-
* }
|
|
322
|
-
* ```
|
|
323
|
-
*
|
|
324
|
-
* **Example:**
|
|
325
|
-
*
|
|
326
|
-
* ```bash
|
|
327
|
-
* POST /farms/estimate-reward-scores-batch
|
|
328
|
-
* Content-Type: application/json
|
|
329
|
-
*
|
|
330
|
-
* {
|
|
331
|
-
* "farms": [
|
|
332
|
-
* {
|
|
333
|
-
* "userId": "0x1234567890abcdef1234567890abcdef12345678",
|
|
334
|
-
* "sponsorSplitPercent": 75,
|
|
335
|
-
* "protocolDepositAmount": "10000000000",
|
|
336
|
-
* "paymentCurrency": "USDC",
|
|
337
|
-
* "expectedWeeklyCarbonCredits": 100,
|
|
338
|
-
* "regionId": 1
|
|
339
|
-
* },
|
|
340
|
-
* {
|
|
341
|
-
* "userId": "0xabcdef1234567890abcdef1234567890abcdef12",
|
|
342
|
-
* "sponsorSplitPercent": 50,
|
|
343
|
-
* "protocolDepositAmount": "5000000000",
|
|
344
|
-
* "paymentCurrency": "USDG",
|
|
345
|
-
* "expectedWeeklyCarbonCredits": 50,
|
|
346
|
-
* "regionId": 2
|
|
347
|
-
* }
|
|
348
|
-
* ]
|
|
349
|
-
* }
|
|
350
|
-
* ```
|
|
351
|
-
*
|
|
352
|
-
* **Notes:**
|
|
353
|
-
*
|
|
354
|
-
* - Each farm in the batch is calculated independently, as if it's the only new farm joining the protocol
|
|
355
|
-
* - The calculation does not accumulate region data between farms in the batch
|
|
356
|
-
* - If one farm calculation fails, it won't affect the other farms in the batch
|
|
357
|
-
* - Failed calculations include basic identifying information to help with debugging
|
|
358
|
-
* - Only considers active regions (where `isActivated = true`)
|
|
359
|
-
* - Rewards are computed via the rewards simulator API using `getFarmRewardsForWeek` with `preloadGlowV1` and GCTL distribution; simulator inputs use `weeksAlive = 100` and exclude pre-epoch-97 farms
|
|
360
|
-
*
|
|
361
|
-
* ### POST `/farms/mining-scores-batch`
|
|
362
|
-
*
|
|
363
|
-
* Calculates mining scores for existing farms that are already live on the protocol. The mining score represents the return on investment for a miner based on the farm's total GLW rewards.
|
|
364
|
-
*
|
|
365
|
-
* **Mining Score Formula:**
|
|
366
|
-
* ```
|
|
367
|
-
* mining_score = 100 * ((glw_per_miner_after_split * weeks_of_miner_life_remaining * glw_price) / dollar_cost_of_miner)
|
|
368
|
-
* ```
|
|
369
|
-
*
|
|
370
|
-
* Where:
|
|
371
|
-
* - `glw_per_miner_after_split` = (farm's total GLW rewards / number of miners) × miner_reward_split
|
|
372
|
-
* - `miner_reward_split` = percentage of GLW rewards the miner receives (6 decimals, where 1000000 = 100%)
|
|
373
|
-
* - `weeks_of_miner_life_remaining` = farm's end reward period - current epoch
|
|
374
|
-
* - `glw_price` = current GLW price in USD (6 decimals)
|
|
375
|
-
* - `dollar_cost_of_miner` = cost of the miner in USD (6 decimals)
|
|
376
|
-
*
|
|
377
|
-
* **Mathematically equivalent to:**
|
|
378
|
-
* ```
|
|
379
|
-
* mining_score = 100 * ((farm_total_glw / number_of_miners) * miner_reward_split * weeks * glw_price) / dollar_cost
|
|
380
|
-
* ```
|
|
381
|
-
*
|
|
382
|
-
* **Request Body:**
|
|
383
|
-
*
|
|
384
|
-
* ```json
|
|
385
|
-
* {
|
|
386
|
-
* "farms": [
|
|
387
|
-
* {
|
|
388
|
-
* "farmId": "string", // The farm ID of the existing farm
|
|
389
|
-
* "userId": "string", // User's wallet address to calculate mining score for
|
|
390
|
-
* "dollarCostOfMiner": "string", // Dollar cost of the miner (USD with 6 decimals)
|
|
391
|
-
* "numberOfMiners": "number", // Number of miners in the farm
|
|
392
|
-
* "minerRewardSplit": "string" // Miner's reward split percentage (6 decimals, e.g., 100000 = 10%)
|
|
393
|
-
* }
|
|
394
|
-
* ]
|
|
395
|
-
* }
|
|
396
|
-
* ```
|
|
397
|
-
*
|
|
398
|
-
* **Response:**
|
|
399
|
-
*
|
|
400
|
-
* ```json
|
|
401
|
-
* {
|
|
402
|
-
* "results": [
|
|
403
|
-
* // For successful calculations:
|
|
404
|
-
* {
|
|
405
|
-
* "success": true,
|
|
406
|
-
* "data": {
|
|
407
|
-
* "miningScore": "number", // Mining score (calculated using farm's total GLW rewards)
|
|
408
|
-
* "userWeeklyGlwRewards": "string", // User's portion of weekly GLW rewards after split (18 decimals)
|
|
409
|
-
* "glwPriceUsd6": "string", // GLW price used in calculation (6 decimals)
|
|
410
|
-
* "dollarCostOfMiner": "string", // Dollar cost of miner (6 decimals)
|
|
411
|
-
* "weeksOfMinerLifeRemaining": "number", // Weeks of miner life remaining (calculated from farm's end reward period)
|
|
412
|
-
* "regionInfo": {
|
|
413
|
-
* "regionId": "number",
|
|
414
|
-
* "regionGctlStaked": "string",
|
|
415
|
-
* "totalGctlStakedAllRegions": "string"
|
|
416
|
-
* }
|
|
417
|
-
* }
|
|
418
|
-
* },
|
|
419
|
-
* // For failed calculations:
|
|
420
|
-
* {
|
|
421
|
-
* "success": false,
|
|
422
|
-
* "error": "string", // Error message
|
|
423
|
-
* "farmData": {
|
|
424
|
-
* "farmId": "string",
|
|
425
|
-
* "userId": "string"
|
|
426
|
-
* }
|
|
427
|
-
* }
|
|
428
|
-
* ]
|
|
429
|
-
* }
|
|
430
|
-
* ```
|
|
431
|
-
*
|
|
432
|
-
* **Example:**
|
|
433
|
-
*
|
|
434
|
-
* ```bash
|
|
435
|
-
* POST /farms/mining-scores-batch
|
|
436
|
-
* Content-Type: application/json
|
|
437
|
-
*
|
|
438
|
-
* {
|
|
439
|
-
* "farms": [
|
|
440
|
-
* {
|
|
441
|
-
* "farmId": "550e8400-e29b-41d4-a716-446655440000",
|
|
442
|
-
* "userId": "0x1234567890abcdef1234567890abcdef12345678",
|
|
443
|
-
* "dollarCostOfMiner": "5000000000",
|
|
444
|
-
* "numberOfMiners": 10,
|
|
445
|
-
* "minerRewardSplit": "100000"
|
|
446
|
-
* },
|
|
447
|
-
* {
|
|
448
|
-
* "farmId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
|
|
449
|
-
* "userId": "0xabcdef1234567890abcdef1234567890abcdef12",
|
|
450
|
-
* "dollarCostOfMiner": "3000000000",
|
|
451
|
-
* "numberOfMiners": 5,
|
|
452
|
-
* "minerRewardSplit": "150000"
|
|
453
|
-
* }
|
|
454
|
-
* ]
|
|
455
|
-
* }
|
|
456
|
-
* ```
|
|
457
|
-
*
|
|
458
|
-
* **Notes:**
|
|
459
|
-
*
|
|
460
|
-
* - The mining score represents the ROI for a single miner, calculated as: (GLW value earned over lifetime) / (miner cost) × 100
|
|
461
|
-
* - Weekly GLW rewards are obtained via the rewards simulator API using `getFarmRewardsForWeek`
|
|
462
|
-
* - Farms built before epoch 97 are excluded from the simulator payload (preloaded via `preloadGlowV1`); simulator inputs use `weeksAlive = 100`
|
|
463
|
-
* - `dollarCostOfMiner` should be provided in USD with 6 decimals (e.g., 5000000000 = $5,000.00)
|
|
464
|
-
* - `numberOfMiners` indicates how many miners are in the farm (the total GLW rewards are divided by this number)
|
|
465
|
-
* - `minerRewardSplit` is the percentage of GLW rewards the miner receives in 6 decimals (e.g., 100000 = 10%, 1000000 = 100%)
|
|
466
|
-
* - Higher mining scores indicate better return on investment
|
|
467
|
-
* - The calculation uses the current GLW price from the `getGlwPrice()` function
|
|
468
|
-
* - Only works with existing farms that are found in the database
|
|
469
|
-
* - Only considers farms in active regions (where `isActivated = true`)
|
|
470
|
-
*
|
|
471
|
-
* ### GET `/farms/efficiency-scores`
|
|
472
|
-
*
|
|
473
|
-
* Returns efficiency scores for farms, indicating the carbon credits produced per $100,000 of protocol deposit per week.
|
|
474
|
-
*
|
|
475
|
-
* **Efficiency Score Formula:**
|
|
476
|
-
* ```
|
|
477
|
-
* efficiencyScore = (CC / PD) / 100,000
|
|
478
|
-
* ```
|
|
479
|
-
*
|
|
480
|
-
* Where:
|
|
481
|
-
* - `CC` = weekly carbon credits in WAD format (18 decimals)
|
|
482
|
-
* - `PD` = protocol deposit in USD (6 decimals)
|
|
483
|
-
*
|
|
484
|
-
* Due to the decimal difference (CC has 18 decimals, PD has 6 decimals), the actual calculation maintains a 10^12 factor, resulting in:
|
|
485
|
-
* ```
|
|
486
|
-
* efficiencyScore = (CC_actual / PD_actual) × 10^8
|
|
487
|
-
* ```
|
|
488
|
-
*
|
|
489
|
-
* **Query Parameters (optional):**
|
|
490
|
-
* - `farmId` (string): Optional farm ID. If provided, returns efficiency score for that specific farm only.
|
|
491
|
-
*
|
|
492
|
-
* **Response:**
|
|
493
|
-
*
|
|
494
|
-
* Single farm response (when farmId is provided):
|
|
495
|
-
* ```json
|
|
496
|
-
* {
|
|
497
|
-
* "farmId": "string",
|
|
498
|
-
* "efficiencyScore": "number", // Carbon credits per $100,000 deposit per week
|
|
499
|
-
* "protocolDepositUsd6": "string", // Protocol deposit in USD (6 decimals)
|
|
500
|
-
* "weeklyImpactAssetsWad": "string" // Weekly carbon credits in WAD format (18 decimals)
|
|
501
|
-
* }
|
|
502
|
-
* ```
|
|
503
|
-
*
|
|
504
|
-
* All farms response (when farmId is not provided):
|
|
505
|
-
* ```json
|
|
506
|
-
* [
|
|
507
|
-
* {
|
|
508
|
-
* "farmId": "string",
|
|
509
|
-
* "efficiencyScore": "number", // Carbon credits per $100,000 deposit per week
|
|
510
|
-
* "protocolDepositUsd6": "string", // Protocol deposit in USD (6 decimals)
|
|
511
|
-
* "weeklyImpactAssetsWad": "string" // Weekly carbon credits in WAD format (18 decimals)
|
|
512
|
-
* }
|
|
513
|
-
* ]
|
|
514
|
-
* ```
|
|
515
|
-
*
|
|
516
|
-
* Error response:
|
|
517
|
-
* ```json
|
|
518
|
-
* {
|
|
519
|
-
* "error": "string"
|
|
520
|
-
* }
|
|
521
|
-
* ```
|
|
522
|
-
*
|
|
523
|
-
* **Example:**
|
|
524
|
-
*
|
|
525
|
-
* Get efficiency score for a specific farm:
|
|
526
|
-
* ```bash
|
|
527
|
-
* GET /farms/efficiency-scores?farmId=550e8400-e29b-41d4-a716-446655440000
|
|
528
|
-
* ```
|
|
529
|
-
*
|
|
530
|
-
* Get efficiency scores for all farms (sorted by efficiency descending):
|
|
531
|
-
* ```bash
|
|
532
|
-
* GET /farms/efficiency-scores
|
|
533
|
-
* ```
|
|
534
|
-
*
|
|
535
|
-
* **Notes:**
|
|
536
|
-
*
|
|
537
|
-
* - The efficiency score represents carbon credits produced per $100,000 of protocol deposit per week
|
|
538
|
-
* - Higher scores indicate more efficient farms (more carbon credits per dollar invested)
|
|
539
|
-
* - Scores are sorted in descending order when fetching all farms
|
|
540
|
-
* - Includes both legacy V1 farms (from `legacyFarms.json`) and V2+ farms from the database
|
|
541
|
-
* - Legacy farms are processed first to avoid duplicates in the results
|
|
542
|
-
* - Farms with zero carbon credits will have an efficiency score of 0
|
|
543
|
-
*/
|
|
544
|
-
import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse, FarmWeeklyRewardsResponse, FarmWeeklyRewardsQuery, FarmEfficiencyScore } from "../types";
|
|
1
|
+
import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse, FarmWeeklyRewardsResponse, FarmWeeklyRewardsQuery, FarmEfficiencyScore, FarmWeeklyRewardsBatchQuery, FarmWeeklyRewardsBatchResponse, WalletFarmRewardsHistoryQuery, WalletFarmRewardsHistoryResponse, WalletFarmRewardsHistoryBatchQuery, WalletFarmRewardsHistoryBatchResponse } from "../types";
|
|
545
2
|
export declare function FarmsRouter(baseUrl: string): {
|
|
546
3
|
readonly fetchFarmRewardSplits: (farmId: string) => Promise<FarmRewardSplit[]>;
|
|
547
4
|
readonly fetchSponsoredFarms: (sponsorWallet?: string) => Promise<SponsoredFarm[]>;
|
|
@@ -551,4 +8,7 @@ export declare function FarmsRouter(baseUrl: string): {
|
|
|
551
8
|
readonly estimateRewardScoresBatch: (params: EstimateRewardScoresBatchParams) => Promise<EstimateRewardScoresBatchResponse>;
|
|
552
9
|
readonly calculateMiningScoresBatch: (params: MiningScoresBatchParams) => Promise<MiningScoresBatchResponse>;
|
|
553
10
|
readonly fetchEfficiencyScores: (farmId?: string) => Promise<FarmEfficiencyScore[] | FarmEfficiencyScore>;
|
|
11
|
+
readonly fetchFarmWeeklyRewardsBatch: (params: FarmWeeklyRewardsBatchQuery) => Promise<FarmWeeklyRewardsBatchResponse>;
|
|
12
|
+
readonly fetchWalletFarmRewardsHistory: (walletAddress: string, query?: WalletFarmRewardsHistoryQuery) => Promise<WalletFarmRewardsHistoryResponse>;
|
|
13
|
+
readonly fetchWalletFarmRewardsHistoryBatch: (params: WalletFarmRewardsHistoryBatchQuery) => Promise<WalletFarmRewardsHistoryBatchResponse>;
|
|
554
14
|
};
|
|
@@ -723,4 +723,68 @@ export interface SingleEfficiencyScoreResponse extends FarmEfficiencyScore {
|
|
|
723
723
|
export interface EfficiencyScoresErrorResponse {
|
|
724
724
|
error: string;
|
|
725
725
|
}
|
|
726
|
+
export interface FarmWeeklyRewardsBatchQuery {
|
|
727
|
+
farmIds: string[];
|
|
728
|
+
startWeek?: number;
|
|
729
|
+
endWeek?: number;
|
|
730
|
+
}
|
|
731
|
+
export interface FarmWeeklyRewardsBatchResult {
|
|
732
|
+
regionId: number;
|
|
733
|
+
summary: FarmWeeklyRewardsSummary;
|
|
734
|
+
rewards: FarmWeeklyReward[];
|
|
735
|
+
}
|
|
736
|
+
export interface FarmWeeklyRewardsBatchErrorResult {
|
|
737
|
+
error: string;
|
|
738
|
+
}
|
|
739
|
+
export interface FarmWeeklyRewardsBatchResponse {
|
|
740
|
+
results: Record<string, FarmWeeklyRewardsBatchResult | FarmWeeklyRewardsBatchErrorResult>;
|
|
741
|
+
}
|
|
742
|
+
export interface WalletFarmReward {
|
|
743
|
+
farmId: string;
|
|
744
|
+
farmName: string;
|
|
745
|
+
regionId: number;
|
|
746
|
+
expectedWeeklyCarbonCredits: string;
|
|
747
|
+
protocolDepositUSDC6Decimals: string;
|
|
748
|
+
weekNumber: number;
|
|
749
|
+
walletTotalGlowInflationReward: string;
|
|
750
|
+
walletTotalProtocolDepositReward: string;
|
|
751
|
+
asset: PaymentCurrency;
|
|
752
|
+
inflationSplitFromLaunchpad: number;
|
|
753
|
+
inflationSplitFromMiningCenter: number;
|
|
754
|
+
depositSplitFromLaunchpad: number;
|
|
755
|
+
depositSplitFromMiningCenter: number;
|
|
756
|
+
walletInflationFromLaunchpad: string;
|
|
757
|
+
walletProtocolDepositFromLaunchpad: string;
|
|
758
|
+
walletInflationFromMiningCenter: string;
|
|
759
|
+
walletProtocolDepositFromMiningCenter: string;
|
|
760
|
+
farmTotalInflation: string;
|
|
761
|
+
farmTotalProtocolDepositReward: string;
|
|
762
|
+
}
|
|
763
|
+
export interface WalletFarmRewardsHistoryQuery {
|
|
764
|
+
startWeek?: number;
|
|
765
|
+
endWeek?: number;
|
|
766
|
+
}
|
|
767
|
+
export interface WalletFarmRewardsHistoryResponse {
|
|
768
|
+
walletAddress: string;
|
|
769
|
+
weekRange: {
|
|
770
|
+
startWeek: number;
|
|
771
|
+
endWeek: number;
|
|
772
|
+
};
|
|
773
|
+
farmRewards: WalletFarmReward[];
|
|
774
|
+
}
|
|
775
|
+
export interface WalletFarmRewardsHistoryBatchQuery {
|
|
776
|
+
wallets: string[];
|
|
777
|
+
startWeek?: number;
|
|
778
|
+
endWeek?: number;
|
|
779
|
+
}
|
|
780
|
+
export interface WalletFarmRewardsHistoryBatchResult {
|
|
781
|
+
weekRange: {
|
|
782
|
+
startWeek: number;
|
|
783
|
+
endWeek: number;
|
|
784
|
+
};
|
|
785
|
+
farmRewards: WalletFarmReward[];
|
|
786
|
+
}
|
|
787
|
+
export interface WalletFarmRewardsHistoryBatchResponse {
|
|
788
|
+
results: Record<string, WalletFarmRewardsHistoryBatchResult>;
|
|
789
|
+
}
|
|
726
790
|
export type { MintedEvent as ControlMintedEvent };
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TRANSFER_TYPES } from './calculate-farm-efficiency-
|
|
2
|
-
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, m as FORWARDER_ABI, F as FarmsRouter, g as ForwarderError, q as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, e as KICKSTARTER_STATUS, K as KickstarterRouter, M as MAX_WEIGHT, n as OFFCHAIN_FRACTIONS_ABI, O as OFF_CHAIN_PAYMENT_CURRENCIES, h as OffchainFractionsError, P as PAYMENT_CURRENCIES, d as REGIONS, o as REWARDS_KERNEL_ABI, R as RegionRouter, i as RewardsKernelError, S as STAKING_DIRECTIONS, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, j as allRegions, f as calculateFarmEfficiency, c as configureSentry, l as countries, p as getAddresses, t as parseEthersError, s as parseViemError, r as regionMetadata, k as usStates, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel, v as waitForEthersTransactionWithRetry, w as waitForViemTransactionWithRetry } from './calculate-farm-efficiency-
|
|
1
|
+
import { T as TRANSFER_TYPES } from './calculate-farm-efficiency-VRzMgQmC.js';
|
|
2
|
+
export { C as ControlRouter, D as DECIMALS_BY_TOKEN, m as FORWARDER_ABI, F as FarmsRouter, g as ForwarderError, q as GCA_URLS, G as GLOW_WEIGHT_DECIMAL_PRECISION, H as HUB_URL, e as KICKSTARTER_STATUS, K as KickstarterRouter, M as MAX_WEIGHT, n as OFFCHAIN_FRACTIONS_ABI, O as OFF_CHAIN_PAYMENT_CURRENCIES, h as OffchainFractionsError, P as PAYMENT_CURRENCIES, d as REGIONS, o as REWARDS_KERNEL_ABI, R as RegionRouter, i as RewardsKernelError, S as STAKING_DIRECTIONS, U as USDG_WEIGHT_DECIMAL_PRECISION, W as WalletsRouter, j as allRegions, f as calculateFarmEfficiency, c as configureSentry, l as countries, p as getAddresses, t as parseEthersError, s as parseViemError, r as regionMetadata, k as usStates, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel, v as waitForEthersTransactionWithRetry, w as waitForViemTransactionWithRetry } from './calculate-farm-efficiency-VRzMgQmC.js';
|
|
3
3
|
import 'decimal.js';
|
|
4
4
|
import { verifyTypedData, checksumAddress } from 'viem';
|
|
5
5
|
import 'ethers';
|