@glowlabs-org/utils 0.2.179 → 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-Per18qa5.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-Per18qa5.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
 
@@ -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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/utils",
3
- "version": "0.2.179",
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": "",
@@ -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,