@glowlabs-org/utils 0.2.178 → 0.2.180

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 './calculate-farm-efficiency-BjXQqtxI.js';
17
- export { C as ControlRouter, F as FarmsRouter, e as KICKSTARTER_STATUS, K as KickstarterRouter, O as OFF_CHAIN_PAYMENT_CURRENCIES, P as PAYMENT_CURRENCIES, d as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, T as TRANSFER_TYPES, W as WalletsRouter, f as calculateFarmEfficiency, c as configureSentry, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel } from './calculate-farm-efficiency-BjXQqtxI.js';
16
+ import { H as HUB_URL, U as USDG_WEIGHT_DECIMAL_PRECISION, G as GLOW_WEIGHT_DECIMAL_PRECISION, M as MAX_WEIGHT } from './calculate-farm-efficiency-CZbLTXjU.js';
17
+ export { C as ControlRouter, F as FarmsRouter, e as KICKSTARTER_STATUS, K as KickstarterRouter, O as OFF_CHAIN_PAYMENT_CURRENCIES, P as PAYMENT_CURRENCIES, d as REGIONS, R as RegionRouter, S as STAKING_DIRECTIONS, T as TRANSFER_TYPES, W as WalletsRouter, f as calculateFarmEfficiency, c as configureSentry, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel } from './calculate-farm-efficiency-CZbLTXjU.js';
18
18
 
19
19
  const GENESIS_TIMESTAMP = 1700352000;
20
20
 
@@ -1,4 +1,4 @@
1
- import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse, FarmWeeklyRewardsResponse, FarmWeeklyRewardsQuery, FarmEfficiencyScore, FarmWeeklyRewardsBatchQuery, FarmWeeklyRewardsBatchResponse, WalletFarmRewardsHistoryQuery, WalletFarmRewardsHistoryResponse, WalletFarmRewardsHistoryBatchQuery, WalletFarmRewardsHistoryBatchResponse } from "../types";
1
+ import type { SponsoredFarm, EstimateRewardScoreParams, RewardScoreResponse, EstimateRewardScoresBatchParams, EstimateRewardScoresBatchResponse, FarmWithRewards, FarmRewardSplit, MiningScoresBatchParams, MiningScoresBatchResponse, FarmWeeklyRewardsResponse, FarmWeeklyRewardsQuery, FarmEfficiencyScore, FarmWeeklyRewardsBatchQuery, FarmWeeklyRewardsBatchResponse, WalletFarmRewardsHistoryQuery, WalletFarmRewardsHistoryResponse, WalletFarmRewardsHistoryBatchQuery, WalletFarmRewardsHistoryBatchResponse, FarmImagesBatchQuery, FarmImagesBatchResponse } from "../types";
2
2
  export declare function FarmsRouter(baseUrl: string): {
3
3
  readonly fetchFarmRewardSplits: (farmId: string) => Promise<FarmRewardSplit[]>;
4
4
  readonly fetchSponsoredFarms: (sponsorWallet?: string) => Promise<SponsoredFarm[]>;
@@ -11,4 +11,5 @@ export declare function FarmsRouter(baseUrl: string): {
11
11
  readonly fetchFarmWeeklyRewardsBatch: (params: FarmWeeklyRewardsBatchQuery) => Promise<FarmWeeklyRewardsBatchResponse>;
12
12
  readonly fetchWalletFarmRewardsHistory: (walletAddress: string, query?: WalletFarmRewardsHistoryQuery) => Promise<WalletFarmRewardsHistoryResponse>;
13
13
  readonly fetchWalletFarmRewardsHistoryBatch: (params: WalletFarmRewardsHistoryBatchQuery) => Promise<WalletFarmRewardsHistoryBatchResponse>;
14
+ readonly fetchFarmImagesBatch: (params: FarmImagesBatchQuery) => Promise<FarmImagesBatchResponse>;
14
15
  };
@@ -26,8 +26,12 @@ export interface ClaimPayoutParams {
26
26
  isGuardedToken: boolean[];
27
27
  toCounterfactual: boolean[];
28
28
  }
29
+ export interface ClaimPayoutsMulticallParams {
30
+ claims: ClaimPayoutParams[];
31
+ }
29
32
  export declare function useRewardsKernel(walletClient: WalletClient | undefined, publicClient: PublicClient | undefined, CHAIN_ID: number): {
30
33
  claimPayout: (params: ClaimPayoutParams) => Promise<string>;
34
+ claimPayoutsMulticall: (params: ClaimPayoutsMulticallParams) => Promise<string>;
31
35
  getRewardMeta: (nonce: bigint) => Promise<RewardMeta>;
32
36
  getMaxReward: (nonce: bigint, token: `0x${string}`) => Promise<bigint>;
33
37
  getAmountClaimed: (nonce: bigint, token: `0x${string}`) => Promise<bigint>;
@@ -798,4 +798,14 @@ export interface WalletFarmRewardsHistoryBatchResult {
798
798
  export interface WalletFarmRewardsHistoryBatchResponse {
799
799
  results: Record<string, WalletFarmRewardsHistoryBatchResult>;
800
800
  }
801
+ export interface FarmImagesBatchQuery {
802
+ farmIds: string[];
803
+ }
804
+ export interface FarmImageResult {
805
+ name: string;
806
+ imageUrl: string | null;
807
+ }
808
+ export interface FarmImagesBatchResponse {
809
+ results: Record<string, FarmImageResult>;
810
+ }
801
811
  export type { MintedEvent as ControlMintedEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.178",
3
+ "version": "0.2.180",
4
4
  "description": "A library containing all typechain types and addresses relating to the glow guarded launch",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -26,6 +26,8 @@ import type {
26
26
  WalletFarmRewardsHistoryResponse,
27
27
  WalletFarmRewardsHistoryBatchQuery,
28
28
  WalletFarmRewardsHistoryBatchResponse,
29
+ FarmImagesBatchQuery,
30
+ FarmImagesBatchResponse,
29
31
  } from "../types";
30
32
  import {
31
33
  sentryAddBreadcrumb,
@@ -355,6 +357,39 @@ export function FarmsRouter(baseUrl: string) {
355
357
  }
356
358
  };
357
359
 
360
+ const fetchFarmImagesBatch = async (
361
+ params: FarmImagesBatchQuery
362
+ ): Promise<FarmImagesBatchResponse> => {
363
+ try {
364
+ sentryAddBreadcrumb({
365
+ category: "control-api",
366
+ message: "POST /farms/images/batch",
367
+ level: "info",
368
+ data: { baseUrl, farmsCount: params.farmIds?.length },
369
+ });
370
+
371
+ const data = await request<FarmImagesBatchResponse>(
372
+ "/farms/images/batch",
373
+ {
374
+ method: "POST",
375
+ headers: {
376
+ "Content-Type": "application/json",
377
+ },
378
+ body: JSON.stringify(params),
379
+ }
380
+ );
381
+
382
+ return data;
383
+ } catch (error) {
384
+ sentryCaptureException(error, {
385
+ action: "fetchFarmImagesBatch",
386
+ baseUrl,
387
+ farmsCount: params.farmIds?.length,
388
+ });
389
+ throw new Error(parseApiError(error));
390
+ }
391
+ };
392
+
358
393
  return {
359
394
  fetchFarmRewardSplits,
360
395
  fetchSponsoredFarms,
@@ -367,5 +402,6 @@ export function FarmsRouter(baseUrl: string) {
367
402
  fetchFarmWeeklyRewardsBatch,
368
403
  fetchWalletFarmRewardsHistory,
369
404
  fetchWalletFarmRewardsHistoryBatch,
405
+ fetchFarmImagesBatch,
370
406
  } as const;
371
407
  }
@@ -2,6 +2,8 @@ import {
2
2
  type WalletClient,
3
3
  type PublicClient,
4
4
  type Address,
5
+ type Hex,
6
+ encodeFunctionData,
5
7
  formatEther,
6
8
  } from "viem";
7
9
  import { REWARDS_KERNEL_ABI } from "../abis/rewardKernelABI";
@@ -49,6 +51,10 @@ export interface ClaimPayoutParams {
49
51
  toCounterfactual: boolean[]; // Whether to send to counterfactual wallet
50
52
  }
51
53
 
54
+ export interface ClaimPayoutsMulticallParams {
55
+ claims: ClaimPayoutParams[];
56
+ }
57
+
52
58
  // Type-guard style helper to ensure a wallet client exists
53
59
  function assertWalletClient(
54
60
  maybeWalletClient: WalletClient | undefined
@@ -258,6 +264,162 @@ export function useRewardsKernel(
258
264
  }
259
265
  }
260
266
 
267
+ /**
268
+ * Claim payouts for multiple nonces in one transaction via multicall
269
+ */
270
+ async function claimPayoutsMulticall(
271
+ params: ClaimPayoutsMulticallParams
272
+ ): Promise<string> {
273
+ assertWalletClient(walletClient);
274
+ assertPublicClient(publicClient);
275
+
276
+ try {
277
+ setIsProcessing(true);
278
+
279
+ const { claims } = params;
280
+ if (!claims || claims.length === 0) {
281
+ throw new Error("At least one claim is required");
282
+ }
283
+
284
+ const owner = walletClient.account?.address;
285
+ if (!owner) {
286
+ throw new Error("No account found in wallet client");
287
+ }
288
+
289
+ sentryAddBreadcrumb({
290
+ category: "rewards-kernel",
291
+ message: "claimPayoutsMulticall.start",
292
+ level: "info",
293
+ data: {
294
+ chainId: walletClient?.chain?.id,
295
+ contract: ADDRESSES.REWARDS_KERNEL,
296
+ claimsCount: claims.length,
297
+ nonces: claims.map((claim) => claim.nonce.toString()),
298
+ to: claims[0]?.to,
299
+ from: claims[0]?.from,
300
+ },
301
+ });
302
+
303
+ const seenNonces = new Set<string>();
304
+ const callData: Hex[] = [];
305
+
306
+ for (const claim of claims) {
307
+ const {
308
+ nonce,
309
+ proof,
310
+ tokensAndAmounts,
311
+ from,
312
+ to,
313
+ isGuardedToken,
314
+ toCounterfactual,
315
+ } = claim;
316
+
317
+ const nonceStr = nonce.toString();
318
+ if (seenNonces.has(nonceStr)) {
319
+ throw new Error(`Duplicate nonce in multicall: ${nonceStr}`);
320
+ }
321
+ seenNonces.add(nonceStr);
322
+
323
+ if (!proof || proof.length === 0) {
324
+ throw new Error(`Merkle proof is required for nonce ${nonceStr}`);
325
+ }
326
+ if (!tokensAndAmounts || tokensAndAmounts.length === 0) {
327
+ throw new Error(
328
+ `Tokens and amounts are required for nonce ${nonceStr}`
329
+ );
330
+ }
331
+ if (isGuardedToken.length !== tokensAndAmounts.length) {
332
+ throw new Error(
333
+ `isGuardedToken length mismatch for nonce ${nonceStr}`
334
+ );
335
+ }
336
+ if (toCounterfactual.length !== tokensAndAmounts.length) {
337
+ throw new Error(
338
+ `toCounterfactual length mismatch for nonce ${nonceStr}`
339
+ );
340
+ }
341
+ if (!from || !to) {
342
+ throw new Error(
343
+ `${RewardsKernelError.INVALID_PARAMETERS} for nonce ${nonceStr}`
344
+ );
345
+ }
346
+
347
+ const alreadyClaimed = await isClaimed(owner, nonce);
348
+ if (alreadyClaimed) {
349
+ throw new Error(
350
+ `${RewardsKernelError.ALREADY_CLAIMED} (nonce ${nonceStr})`
351
+ );
352
+ }
353
+
354
+ const finalized = await isFinalized(nonce);
355
+ if (!finalized) {
356
+ throw new Error(`${RewardsKernelError.NOT_FINALIZED} (nonce ${nonceStr})`);
357
+ }
358
+
359
+ callData.push(
360
+ encodeFunctionData({
361
+ abi: REWARDS_KERNEL_ABI,
362
+ functionName: "claimPayout",
363
+ args: [
364
+ nonce,
365
+ proof as `0x${string}`[],
366
+ tokensAndAmounts as readonly {
367
+ token: `0x${string}`;
368
+ amount: bigint;
369
+ }[],
370
+ from as Address,
371
+ to as Address,
372
+ isGuardedToken,
373
+ toCounterfactual,
374
+ ],
375
+ })
376
+ );
377
+ }
378
+
379
+ try {
380
+ await publicClient.simulateContract({
381
+ address: ADDRESSES.REWARDS_KERNEL as Address,
382
+ abi: REWARDS_KERNEL_ABI,
383
+ functionName: "multicall",
384
+ args: [callData],
385
+ account: walletClient.account!,
386
+ });
387
+ } catch (simulationError) {
388
+ sentryCaptureException(simulationError, {
389
+ action: "claimPayoutsMulticall.simulate",
390
+ chainId: walletClient?.chain?.id,
391
+ contract: ADDRESSES.REWARDS_KERNEL,
392
+ claimsCount: claims.length,
393
+ nonces: claims.map((claim) => claim.nonce.toString()),
394
+ });
395
+ throw new Error(parseViemError(simulationError));
396
+ }
397
+
398
+ const hash = await walletClient.writeContract({
399
+ address: ADDRESSES.REWARDS_KERNEL as Address,
400
+ abi: REWARDS_KERNEL_ABI,
401
+ functionName: "multicall",
402
+ args: [callData],
403
+ chain: walletClient.chain,
404
+ account: walletClient.account!,
405
+ });
406
+
407
+ await waitForViemTransactionWithRetry(publicClient, hash);
408
+ return hash;
409
+ } catch (error) {
410
+ sentryCaptureException(error, {
411
+ action: "claimPayoutsMulticall",
412
+ chainId: walletClient?.chain?.id,
413
+ contract: ADDRESSES.REWARDS_KERNEL,
414
+ claimsCount: params.claims?.length ?? 0,
415
+ nonces: params.claims?.map((claim) => claim.nonce.toString()) ?? [],
416
+ });
417
+ throw new Error(parseViemError(error));
418
+ } finally {
419
+ setIsProcessing(false);
420
+ }
421
+ }
422
+
261
423
  /**
262
424
  * Get reward metadata for a specific nonce
263
425
  * @param nonce The nonce to query
@@ -547,6 +709,7 @@ export function useRewardsKernel(
547
709
  return {
548
710
  // Core contract functions
549
711
  claimPayout,
712
+ claimPayoutsMulticall,
550
713
 
551
714
  // View functions
552
715
  getRewardMeta,
@@ -965,6 +965,22 @@ export interface WalletFarmRewardsHistoryBatchResponse {
965
965
  results: Record<string, WalletFarmRewardsHistoryBatchResult>;
966
966
  }
967
967
 
968
+ // ---------------------------------------------------------------------------
969
+ // Farm Images Batch
970
+ // ---------------------------------------------------------------------------
971
+ export interface FarmImagesBatchQuery {
972
+ farmIds: string[];
973
+ }
974
+
975
+ export interface FarmImageResult {
976
+ name: string;
977
+ imageUrl: string | null;
978
+ }
979
+
980
+ export interface FarmImagesBatchResponse {
981
+ results: Record<string, FarmImageResult>;
982
+ }
983
+
968
984
  // ---------------------------------------------------------------------------
969
985
  // Barrel exports (convenience)
970
986
  // ---------------------------------------------------------------------------