@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/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-K4OucflI.js');
18
+ var calculateFarmEfficiency = require('./calculate-farm-efficiency-B3MkgKDh.js');
19
19
 
20
20
  const GENESIS_TIMESTAMP = 1700352000;
21
21
 
@@ -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>;
@@ -1,5 +1,5 @@
1
- import { T as TRANSFER_TYPES } from './calculate-farm-efficiency-Per18qa5.js';
2
- export { C as ControlRouter, D as DECIMALS_BY_TOKEN, m as FORWARDER_ABI, F as FarmsRouter, g as ForwarderError, t as GCA_URLS, s as GCTL_OFFCHAIN_TOKEN_ADDRESS, 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, q as SGCTL_OFFCHAIN_TOKEN_ADDRESS, 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, w as parseEthersError, v as parseViemError, r as regionMetadata, k as usStates, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel, y as waitForEthersTransactionWithRetry, x as waitForViemTransactionWithRetry } from './calculate-farm-efficiency-Per18qa5.js';
1
+ import { T as TRANSFER_TYPES } from './calculate-farm-efficiency-CZbLTXjU.js';
2
+ export { C as ControlRouter, D as DECIMALS_BY_TOKEN, m as FORWARDER_ABI, F as FarmsRouter, g as ForwarderError, t as GCA_URLS, s as GCTL_OFFCHAIN_TOKEN_ADDRESS, 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, q as SGCTL_OFFCHAIN_TOKEN_ADDRESS, 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, w as parseEthersError, v as parseViemError, r as regionMetadata, k as usStates, u as useForwarder, a as useOffchainFractions, b as useRewardsKernel, y as waitForEthersTransactionWithRetry, x as waitForViemTransactionWithRetry } from './calculate-farm-efficiency-CZbLTXjU.js';
3
3
  import 'decimal.js';
4
4
  import { verifyTypedData, checksumAddress } from 'viem';
5
5
  import 'ethers';
@@ -1,5 +1,5 @@
1
1
  import { MaxUint256, Contract } from 'ethers';
2
- import { formatEther } from 'viem';
2
+ import { formatEther, encodeFunctionData } from 'viem';
3
3
  import Decimal from 'decimal.js';
4
4
 
5
5
  const HUB_URL = "https://glow.org";
@@ -3274,6 +3274,125 @@ function useRewardsKernel(walletClient, publicClient, CHAIN_ID) {
3274
3274
  setIsProcessing(false);
3275
3275
  }
3276
3276
  }
3277
+ /**
3278
+ * Claim payouts for multiple nonces in one transaction via multicall
3279
+ */
3280
+ async function claimPayoutsMulticall(params) {
3281
+ assertWalletClient(walletClient);
3282
+ assertPublicClient(publicClient);
3283
+ try {
3284
+ setIsProcessing(true);
3285
+ const { claims } = params;
3286
+ if (!claims || claims.length === 0) {
3287
+ throw new Error("At least one claim is required");
3288
+ }
3289
+ const owner = walletClient.account?.address;
3290
+ if (!owner) {
3291
+ throw new Error("No account found in wallet client");
3292
+ }
3293
+ sentryAddBreadcrumb({
3294
+ category: "rewards-kernel",
3295
+ message: "claimPayoutsMulticall.start",
3296
+ level: "info",
3297
+ data: {
3298
+ chainId: walletClient?.chain?.id,
3299
+ contract: ADDRESSES.REWARDS_KERNEL,
3300
+ claimsCount: claims.length,
3301
+ nonces: claims.map((claim) => claim.nonce.toString()),
3302
+ to: claims[0]?.to,
3303
+ from: claims[0]?.from,
3304
+ },
3305
+ });
3306
+ const seenNonces = new Set();
3307
+ const callData = [];
3308
+ for (const claim of claims) {
3309
+ const { nonce, proof, tokensAndAmounts, from, to, isGuardedToken, toCounterfactual, } = claim;
3310
+ const nonceStr = nonce.toString();
3311
+ if (seenNonces.has(nonceStr)) {
3312
+ throw new Error(`Duplicate nonce in multicall: ${nonceStr}`);
3313
+ }
3314
+ seenNonces.add(nonceStr);
3315
+ if (!proof || proof.length === 0) {
3316
+ throw new Error(`Merkle proof is required for nonce ${nonceStr}`);
3317
+ }
3318
+ if (!tokensAndAmounts || tokensAndAmounts.length === 0) {
3319
+ throw new Error(`Tokens and amounts are required for nonce ${nonceStr}`);
3320
+ }
3321
+ if (isGuardedToken.length !== tokensAndAmounts.length) {
3322
+ throw new Error(`isGuardedToken length mismatch for nonce ${nonceStr}`);
3323
+ }
3324
+ if (toCounterfactual.length !== tokensAndAmounts.length) {
3325
+ throw new Error(`toCounterfactual length mismatch for nonce ${nonceStr}`);
3326
+ }
3327
+ if (!from || !to) {
3328
+ throw new Error(`${RewardsKernelError.INVALID_PARAMETERS} for nonce ${nonceStr}`);
3329
+ }
3330
+ const alreadyClaimed = await isClaimed(owner, nonce);
3331
+ if (alreadyClaimed) {
3332
+ throw new Error(`${RewardsKernelError.ALREADY_CLAIMED} (nonce ${nonceStr})`);
3333
+ }
3334
+ const finalized = await isFinalized(nonce);
3335
+ if (!finalized) {
3336
+ throw new Error(`${RewardsKernelError.NOT_FINALIZED} (nonce ${nonceStr})`);
3337
+ }
3338
+ callData.push(encodeFunctionData({
3339
+ abi: REWARDS_KERNEL_ABI,
3340
+ functionName: "claimPayout",
3341
+ args: [
3342
+ nonce,
3343
+ proof,
3344
+ tokensAndAmounts,
3345
+ from,
3346
+ to,
3347
+ isGuardedToken,
3348
+ toCounterfactual,
3349
+ ],
3350
+ }));
3351
+ }
3352
+ try {
3353
+ await publicClient.simulateContract({
3354
+ address: ADDRESSES.REWARDS_KERNEL,
3355
+ abi: REWARDS_KERNEL_ABI,
3356
+ functionName: "multicall",
3357
+ args: [callData],
3358
+ account: walletClient.account,
3359
+ });
3360
+ }
3361
+ catch (simulationError) {
3362
+ sentryCaptureException(simulationError, {
3363
+ action: "claimPayoutsMulticall.simulate",
3364
+ chainId: walletClient?.chain?.id,
3365
+ contract: ADDRESSES.REWARDS_KERNEL,
3366
+ claimsCount: claims.length,
3367
+ nonces: claims.map((claim) => claim.nonce.toString()),
3368
+ });
3369
+ throw new Error(parseViemError(simulationError));
3370
+ }
3371
+ const hash = await walletClient.writeContract({
3372
+ address: ADDRESSES.REWARDS_KERNEL,
3373
+ abi: REWARDS_KERNEL_ABI,
3374
+ functionName: "multicall",
3375
+ args: [callData],
3376
+ chain: walletClient.chain,
3377
+ account: walletClient.account,
3378
+ });
3379
+ await waitForViemTransactionWithRetry(publicClient, hash);
3380
+ return hash;
3381
+ }
3382
+ catch (error) {
3383
+ sentryCaptureException(error, {
3384
+ action: "claimPayoutsMulticall",
3385
+ chainId: walletClient?.chain?.id,
3386
+ contract: ADDRESSES.REWARDS_KERNEL,
3387
+ claimsCount: params.claims?.length ?? 0,
3388
+ nonces: params.claims?.map((claim) => claim.nonce.toString()) ?? [],
3389
+ });
3390
+ throw new Error(parseViemError(error));
3391
+ }
3392
+ finally {
3393
+ setIsProcessing(false);
3394
+ }
3395
+ }
3277
3396
  /**
3278
3397
  * Get reward metadata for a specific nonce
3279
3398
  * @param nonce The nonce to query
@@ -3512,6 +3631,7 @@ function useRewardsKernel(walletClient, publicClient, CHAIN_ID) {
3512
3631
  return {
3513
3632
  // Core contract functions
3514
3633
  claimPayout,
3634
+ claimPayoutsMulticall,
3515
3635
  // View functions
3516
3636
  getRewardMeta,
3517
3637
  getMaxReward,
@@ -5581,4 +5701,4 @@ function calculateFarmEfficiency(protocolDepositUsd6, weeklyImpactAssetsWad) {
5581
5701
  }
5582
5702
 
5583
5703
  export { ControlRouter as C, DECIMALS_BY_TOKEN as D, FarmsRouter as F, GLOW_WEIGHT_DECIMAL_PRECISION as G, HUB_URL as H, KickstarterRouter as K, MAX_WEIGHT as M, OFF_CHAIN_PAYMENT_CURRENCIES as O, PAYMENT_CURRENCIES as P, RegionRouter as R, STAKING_DIRECTIONS as S, TRANSFER_TYPES as T, USDG_WEIGHT_DECIMAL_PRECISION as U, WalletsRouter as W, useOffchainFractions as a, useRewardsKernel as b, configureSentry as c, REGIONS as d, KICKSTARTER_STATUS as e, calculateFarmEfficiency as f, ForwarderError as g, OffchainFractionsError as h, RewardsKernelError as i, allRegions as j, usStates as k, countries as l, FORWARDER_ABI as m, OFFCHAIN_FRACTIONS_ABI as n, REWARDS_KERNEL_ABI as o, getAddresses as p, SGCTL_OFFCHAIN_TOKEN_ADDRESS as q, regionMetadata as r, GCTL_OFFCHAIN_TOKEN_ADDRESS as s, GCA_URLS as t, useForwarder as u, parseViemError as v, parseEthersError as w, waitForViemTransactionWithRetry as x, waitForEthersTransactionWithRetry as y };
5584
- //# sourceMappingURL=calculate-farm-efficiency-Per18qa5.js.map
5704
+ //# sourceMappingURL=calculate-farm-efficiency-CZbLTXjU.js.map