@glowlabs-org/utils 0.2.155 → 0.2.156
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/README.md +175 -17
- package/dist/cjs/browser.d.ts +2 -0
- package/dist/cjs/browser.js +7 -1
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/{farms-router-BOXNLl3m.js → farms-router-DekpTBQj.js} +687 -11
- package/dist/cjs/farms-router-DekpTBQj.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/abis/rewardKernelABI.d.ts +418 -0
- package/dist/cjs/lib/hooks/use-rewards-kernel.d.ts +45 -0
- package/dist/esm/browser.d.ts +2 -0
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{farms-router-BYpMNa_b.js → farms-router-L56VPDNz.js} +686 -12
- package/dist/esm/farms-router-L56VPDNz.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/abis/rewardKernelABI.d.ts +418 -0
- package/dist/esm/lib/hooks/use-rewards-kernel.d.ts +45 -0
- package/package.json +1 -1
- package/src/browser.ts +2 -0
- package/src/index.ts +1 -0
- package/src/lib/abis/rewardKernelABI.ts +264 -0
- package/src/lib/hooks/README.md +295 -0
- package/src/lib/hooks/use-rewards-kernel.ts +547 -0
- package/dist/cjs/farms-router-BOXNLl3m.js.map +0 -1
- package/dist/esm/farms-router-BYpMNa_b.js.map +0 -1
package/README.md
CHANGED
|
@@ -72,19 +72,18 @@ See `src/lib/hooks/use-forwarder.ts` for all available helpers (`approveToken`,
|
|
|
72
72
|
|
|
73
73
|
### Control-API SDK (framework-agnostic)
|
|
74
74
|
|
|
75
|
+
The Control API provides a comprehensive set of routers for interacting with the Glow protocol. All methods are promise-based and framework-agnostic – usable in Node, Deno, or the browser.
|
|
76
|
+
|
|
77
|
+
#### Quick Start
|
|
78
|
+
|
|
75
79
|
```typescript
|
|
76
80
|
import { ControlRouter } from "@glowlabs-org/utils";
|
|
77
81
|
|
|
78
|
-
// Base URL of your deployed Control-API instance (can be relative or absolute)
|
|
79
82
|
const controlApi = ControlRouter("https://control-api.glowlabs.org");
|
|
80
83
|
|
|
81
84
|
// Read-only queries
|
|
82
85
|
const balance = await controlApi.fetchGctlBalance("0xYourWallet");
|
|
83
86
|
const price = await controlApi.fetchGctlPrice();
|
|
84
|
-
const glwPrice = await controlApi.fetchGlwPrice();
|
|
85
|
-
|
|
86
|
-
// Paginated listings
|
|
87
|
-
const mintedPage2 = await controlApi.fetchMintedEvents(2, 25);
|
|
88
87
|
|
|
89
88
|
// Mutations
|
|
90
89
|
await controlApi.stakeGctl({
|
|
@@ -97,26 +96,185 @@ await controlApi.stakeGctl({
|
|
|
97
96
|
});
|
|
98
97
|
```
|
|
99
98
|
|
|
100
|
-
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
#### ControlRouter
|
|
102
|
+
|
|
103
|
+
Main router for GCTL token operations, balances, and staking.
|
|
104
|
+
|
|
105
|
+
**Queries:**
|
|
106
|
+
|
|
107
|
+
- `fetchGctlBalance(wallet)` → `string` - Get GCTL balance for a wallet
|
|
108
|
+
- `fetchCommittedBalance(wallet)` → `string` - Get committed GCTL balance
|
|
109
|
+
- `fetchGctlPrice()` → `string` - Current GCTL price in USDC
|
|
110
|
+
- `fetchGlwPrice()` → `string` - Current GLW price in USDC
|
|
111
|
+
- `fetchCirculatingSupply()` → `string` - Circulating supply of GCTL
|
|
112
|
+
- `fetchHoldersCount()` → `number` - Total number of GCTL holders
|
|
113
|
+
- `fetchLastNonce(wallet)` → `string` - Last nonce for wallet (type: `WalletNonce`)
|
|
114
|
+
- `fetchMintedEvents(page?, limit?)` → `MintedEventsResponse` - Paginated minted events
|
|
115
|
+
- `fetchStakeEvents(page?, limit?, regionId?)` → `StakeEventsResponse` - Paginated stake events
|
|
116
|
+
- `fetchPendingTransfers(page?, limit?, type?)` → `PendingTransfersResponse` - Pending transfers with optional type filter
|
|
117
|
+
- `fetchTransferDetails(txId)` → `TransferDetails` - Details for a specific transfer
|
|
118
|
+
- `fetchFailedOperations(page?, limit?)` → `FailedOperationsResponse` - Failed operations
|
|
119
|
+
- `fetchRegionStake(regionId)` → `RegionStake` - Total stake for a region
|
|
120
|
+
- `fetchWalletRegionStake(wallet, regionId)` → `WalletRegionStake` - Wallet's stake in a region
|
|
121
|
+
- `fetchWalletRegionUnlocked(wallet, regionId)` → `WalletRegionUnlocked` - Unlocked amount for wallet in region
|
|
122
|
+
- `fetchWalletRegionCommittedBalance(wallet, regionId)` → `WalletRegionCommittedBalance` - Committed balance
|
|
123
|
+
- `fetchGlwRegionRewards()` → `GlwRegionRewardsResponse` - GLW rewards by region
|
|
124
|
+
- `fetchFarmRewardSplits(farmId)` → `FarmRewardSplit[]` - Reward splits for a farm
|
|
125
|
+
- `fetchMigrationAmount(wallet)` → `MigrationAmountResponse` - Migration amount for wallet
|
|
126
|
+
|
|
127
|
+
**Mutations:**
|
|
128
|
+
|
|
129
|
+
- `stakeGctl(request)` - Stake GCTL to a region (type: `StakeRequest`)
|
|
130
|
+
- `unstakeGctl(request)` - Unstake GCTL from a region (type: `StakeRequest`)
|
|
131
|
+
- `restakeGctl(request)` - Move stake between regions (type: `RestakeRequest`)
|
|
132
|
+
- `retryFailedOperation(operationId)` → `RetryFailedOperationResponse` - Retry a failed operation
|
|
133
|
+
- `payProtocolDepositUsingStakedControl(request)` → `PayProtocolDepositUsingStakedControlResponse` - Pay protocol deposit using staked GCTL
|
|
134
|
+
- `migrateUser(request)` → `MigrateUserResponse` - Migrate user from v1 to v2
|
|
135
|
+
|
|
136
|
+
**Processing Flags:**
|
|
137
|
+
|
|
138
|
+
- `isStaking`, `isUnstaking`, `isRestaking`, `isRetryingFailedOperation`, `isPayingProtocolDepositUsingStakedControl`, `isMigratingUser`
|
|
101
139
|
|
|
102
140
|
---
|
|
103
141
|
|
|
104
|
-
|
|
142
|
+
#### WalletsRouter
|
|
105
143
|
|
|
106
|
-
|
|
107
|
-
import { RegionRouter } from "@glowlabs-org/utils";
|
|
144
|
+
Router for wallet-specific data including balances, farms, and rewards.
|
|
108
145
|
|
|
109
|
-
|
|
146
|
+
**Queries:**
|
|
110
147
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
148
|
+
- `fetchAllWallets()` → `ControlWallet[]` - All wallets with balances
|
|
149
|
+
- `fetchWalletByAddress(wallet)` → `WalletDetails` - Wallet details including regions and farms
|
|
150
|
+
- `fetchWalletMintedEvents(wallet, page?, limit?)` → `MintedEvent[]` - Minted events for wallet
|
|
151
|
+
- `fetchWalletStakeEvents(wallet, page?, limit?, regionId?)` → `StakedEvent[]` - Stake events for wallet
|
|
152
|
+
- `fetchWalletWeeklyRewards(wallet, query?)` → `WalletWeeklyRewardsResponse` - Weekly rewards aggregated by payment currency (query: `WeeklyRewardsQuery` with `startWeek`, `endWeek`, `paymentCurrency`, `limit`)
|
|
114
153
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
154
|
+
**Key Types:**
|
|
155
|
+
|
|
156
|
+
- `WalletDetails` - Includes `controlBalance`, `stakedControl`, `committedControl`, `regions` (array of `WalletRegionStakeTotal`), and `ownedFarms` (array of `WalletFarmInfo` with reward splits)
|
|
157
|
+
- `WalletWeeklyRewardsResponse` - Contains `summary` (`WeeklyRewardsSummary`) and `rewards` (array of `WeeklyReward`)
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
#### RegionRouter
|
|
162
|
+
|
|
163
|
+
Router for geographic regions, activation, and regional data.
|
|
164
|
+
|
|
165
|
+
**Queries:**
|
|
166
|
+
|
|
167
|
+
- `fetchRegions(params?)` → `RegionWithMetadata[]` - All regions, optionally filtered by `isActive`
|
|
168
|
+
- `fetchRegionByIdOrSlug(idOrSlug)` → `RegionDetails` - Detailed region info including farms and applications
|
|
169
|
+
- `fetchActivationConfig(regionCode)` → `ActivationConfig` - Activation thresholds and requirements
|
|
170
|
+
- `fetchActivationEvents(regionId?)` → `ActivationEvent[]` - Activation event timeline
|
|
171
|
+
- `fetchRegionSolarFarms(regionId)` → `SponsoredFarm[]` - Solar farms in a region
|
|
172
|
+
- `fetchActiveSummary()` → `ActiveRegionsSummaryResponse` - Chart-ready data with 4-epoch history
|
|
173
|
+
- `fetchRecentActivity()` → `RecentRegionActivityResponse` - 24h and 7d activity statistics
|
|
174
|
+
- `fetchRegionWeeklyRewards(regionId, query?)` → `RegionWeeklyRewardsResponse` - Weekly rewards aggregated by payment currency (query: `RegionWeeklyRewardsQuery`)
|
|
175
|
+
- `getRegionByCode(code)` → `RegionWithMetadata | null` - Get region by code, merges bundled metadata
|
|
176
|
+
|
|
177
|
+
**Mutations:**
|
|
178
|
+
|
|
179
|
+
- `applyInstallerCertification(payload)` → `InstallerApplicationResponse` - Apply for installer certification (type: `InstallerApplicationPayload`)
|
|
180
|
+
|
|
181
|
+
**Cached Data:**
|
|
182
|
+
|
|
183
|
+
- `regions` - Cached regions array
|
|
184
|
+
- `isLoading` - Loading state flag
|
|
185
|
+
|
|
186
|
+
**Key Types:**
|
|
187
|
+
|
|
188
|
+
- `RegionWithMetadata` - Includes activation progress (stake, farms, installers)
|
|
189
|
+
- `RegionDetails` - Full region view with farms, applications, and carbon credits
|
|
190
|
+
- `ActiveRegionsSummaryResponse` - Historical data with metadata, totals, per-region data, and aggregate timeline
|
|
191
|
+
- `RegionWeeklyRewardsResponse` - Summary and rewards array by week and payment currency
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
#### FarmsRouter
|
|
196
|
+
|
|
197
|
+
Router for solar farm operations, rewards, and scoring.
|
|
198
|
+
|
|
199
|
+
**Queries:**
|
|
118
200
|
|
|
119
|
-
`
|
|
201
|
+
- `fetchFarmRewardSplits(farmId)` → `FarmRewardSplit[]` - Current reward splits for a farm
|
|
202
|
+
- `fetchSponsoredFarms(sponsorWallet?)` → `SponsoredFarm[]` - All sponsored farms, optionally filtered by sponsor
|
|
203
|
+
- `fetchWalletFarmsWithRewards(walletAddress)` → `FarmWithRewards[]` - Farms where wallet has reward splits, with calculated weekly rewards
|
|
204
|
+
- `fetchFarmWeeklyRewards(farmId, query?)` → `FarmWeeklyRewardsResponse` - Weekly rewards aggregated by payment currency (query: `FarmWeeklyRewardsQuery`)
|
|
205
|
+
|
|
206
|
+
**Mutations:**
|
|
207
|
+
|
|
208
|
+
- `estimateRewardScore(params)` → `RewardScoreResponse` - Calculate reward score for a potential farm (type: `EstimateRewardScoreParams`)
|
|
209
|
+
- `estimateRewardScoresBatch(params)` → `EstimateRewardScoresBatchResponse` - Calculate reward scores for multiple farms (type: `EstimateRewardScoresBatchParams`)
|
|
210
|
+
- `calculateMiningScoresBatch(params)` → `MiningScoresBatchResponse` - Calculate mining scores for existing farms (type: `MiningScoresBatchParams`)
|
|
211
|
+
|
|
212
|
+
**Key Types:**
|
|
213
|
+
|
|
214
|
+
- `SponsoredFarm` - Complete farm details including location, capacity, pictures, and reward splits
|
|
215
|
+
- `FarmWithRewards` - Extends `SponsoredFarm` with `userWeeklyRewards` (`UserWeeklyRewards`)
|
|
216
|
+
- `RewardScoreResponse` - Comprehensive reward estimates including weekly PD/GLW rewards, USD values, and region info
|
|
217
|
+
- `MiningScoreResponse` - Mining ROI calculation with GLW rewards and lifetime estimates
|
|
218
|
+
- `FarmWeeklyRewardsResponse` - Summary and rewards array by week and payment currency
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
#### KickstarterRouter
|
|
223
|
+
|
|
224
|
+
Router for region kickstarter campaigns and commitments.
|
|
225
|
+
|
|
226
|
+
**Queries:**
|
|
227
|
+
|
|
228
|
+
- `fetchKickstarters()` → `Kickstarter[]` - All kickstarters
|
|
229
|
+
- `fetchKickstarter(idOrSlug)` → `KickstarterDetails` - Detailed kickstarter info including contributors and farms
|
|
230
|
+
- `fetchKickstartersByWallet(wallet)` → `Kickstarter[]` - Kickstarters by creator wallet
|
|
231
|
+
- `fetchRegionCommitments(regionId, query?)` → `KickstarterCommitmentsResponse` - Paginated commitments (query: `KickstarterCommitmentsQuery` with `page`, `limit`, `finalized`)
|
|
232
|
+
|
|
233
|
+
**Mutations:**
|
|
234
|
+
|
|
235
|
+
- `createKickstarter(payload)` → `KickstarterCreateResponse` - Create a new kickstarter (type: `CreateKickstarterPayload`)
|
|
236
|
+
- `commitKickstarter(kickstarterId, payload)` → `CommitKickstarterResponse` - Commit GCTL to a kickstarter (type: `CommitKickstarterPayload`)
|
|
237
|
+
|
|
238
|
+
**Processing Flags:**
|
|
239
|
+
|
|
240
|
+
- `isCreatingKickstarter`
|
|
241
|
+
|
|
242
|
+
**Key Types:**
|
|
243
|
+
|
|
244
|
+
- `Kickstarter` - Basic kickstarter info with status, targets, and progress flags
|
|
245
|
+
- `KickstarterDetails` - Extends `Kickstarter` with contributors, farm count, applications, and sponsored farms
|
|
246
|
+
- `KickstarterStatus` - Status enum: `draft`, `collecting-support`, `completed`, `failed`, `cancelled`
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### Using Individual Routers
|
|
251
|
+
|
|
252
|
+
Each router can be imported and used independently:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import {
|
|
256
|
+
ControlRouter,
|
|
257
|
+
WalletsRouter,
|
|
258
|
+
RegionRouter,
|
|
259
|
+
FarmsRouter,
|
|
260
|
+
KickstarterRouter,
|
|
261
|
+
} from "@glowlabs-org/utils";
|
|
262
|
+
|
|
263
|
+
const baseUrl = "https://control-api.glowlabs.org";
|
|
264
|
+
|
|
265
|
+
const control = ControlRouter(baseUrl);
|
|
266
|
+
const wallets = WalletsRouter(baseUrl);
|
|
267
|
+
const regions = RegionRouter(baseUrl);
|
|
268
|
+
const farms = FarmsRouter(baseUrl);
|
|
269
|
+
const kickstarters = KickstarterRouter(baseUrl);
|
|
270
|
+
|
|
271
|
+
// Use any router
|
|
272
|
+
const balance = await control.fetchGctlBalance("0x...");
|
|
273
|
+
const walletDetails = await wallets.fetchWalletByAddress("0x...");
|
|
274
|
+
const regionList = await regions.fetchRegions({ isActive: true });
|
|
275
|
+
const farmSplits = await farms.fetchFarmRewardSplits("farm-id");
|
|
276
|
+
const allKickstarters = await kickstarters.fetchKickstarters();
|
|
277
|
+
```
|
|
120
278
|
|
|
121
279
|
---
|
|
122
280
|
|
package/dist/cjs/browser.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./lib/hooks/use-forwarder";
|
|
2
2
|
export * from "./lib/hooks/use-offchain-fractions";
|
|
3
|
+
export * from "./lib/hooks/use-rewards-kernel";
|
|
3
4
|
export * from "./lib/control-api/control-router";
|
|
4
5
|
export * from "./lib/control-api/region-router";
|
|
5
6
|
export * from "./lib/control-api/kickstarter-router";
|
|
@@ -9,6 +10,7 @@ export * from "./lib/types";
|
|
|
9
10
|
export * from "./lib/region-metadata";
|
|
10
11
|
export * from "./lib/abis/forwarderABI";
|
|
11
12
|
export * from "./lib/abis/offchainFractions";
|
|
13
|
+
export * from "./lib/abis/rewardKernelABI";
|
|
12
14
|
export * from "./constants/addresses";
|
|
13
15
|
export * from "./constants/weights";
|
|
14
16
|
export * from "./constants/urls";
|
package/dist/cjs/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var farmsRouter = require('./farms-router-
|
|
3
|
+
var farmsRouter = require('./farms-router-DekpTBQj.js');
|
|
4
4
|
var viem = require('viem');
|
|
5
5
|
require('ethers');
|
|
6
6
|
|
|
@@ -12438,7 +12438,12 @@ Object.defineProperty(exports, "REGIONS", {
|
|
|
12438
12438
|
enumerable: true,
|
|
12439
12439
|
get: function () { return farmsRouter.REGIONS; }
|
|
12440
12440
|
});
|
|
12441
|
+
exports.REWARDS_KERNEL_ABI = farmsRouter.REWARDS_KERNEL_ABI;
|
|
12441
12442
|
exports.RegionRouter = farmsRouter.RegionRouter;
|
|
12443
|
+
Object.defineProperty(exports, "RewardsKernelError", {
|
|
12444
|
+
enumerable: true,
|
|
12445
|
+
get: function () { return farmsRouter.RewardsKernelError; }
|
|
12446
|
+
});
|
|
12442
12447
|
Object.defineProperty(exports, "STAKING_DIRECTIONS", {
|
|
12443
12448
|
enumerable: true,
|
|
12444
12449
|
get: function () { return farmsRouter.STAKING_DIRECTIONS; }
|
|
@@ -12456,6 +12461,7 @@ exports.regionMetadata = farmsRouter.regionMetadata;
|
|
|
12456
12461
|
exports.usStates = farmsRouter.usStates;
|
|
12457
12462
|
exports.useForwarder = farmsRouter.useForwarder;
|
|
12458
12463
|
exports.useOffchainFractions = farmsRouter.useOffchainFractions;
|
|
12464
|
+
exports.useRewardsKernel = farmsRouter.useRewardsKernel;
|
|
12459
12465
|
exports.waitForEthersTransactionWithRetry = farmsRouter.waitForEthersTransactionWithRetry;
|
|
12460
12466
|
exports.waitForViemTransactionWithRetry = farmsRouter.waitForViemTransactionWithRetry;
|
|
12461
12467
|
exports.applyCertifiedInstallerEIP712Types = applyCertifiedInstallerEIP712Types;
|