@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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var calculateFarmEfficiency = require('./calculate-farm-efficiency-K4OucflI.js');
3
+ var calculateFarmEfficiency = require('./calculate-farm-efficiency-B3MkgKDh.js');
4
4
  require('decimal.js');
5
5
  var viem = require('viem');
6
6
  require('ethers');
@@ -3276,6 +3276,125 @@ function useRewardsKernel(walletClient, publicClient, CHAIN_ID) {
3276
3276
  setIsProcessing(false);
3277
3277
  }
3278
3278
  }
3279
+ /**
3280
+ * Claim payouts for multiple nonces in one transaction via multicall
3281
+ */
3282
+ async function claimPayoutsMulticall(params) {
3283
+ assertWalletClient(walletClient);
3284
+ assertPublicClient(publicClient);
3285
+ try {
3286
+ setIsProcessing(true);
3287
+ const { claims } = params;
3288
+ if (!claims || claims.length === 0) {
3289
+ throw new Error("At least one claim is required");
3290
+ }
3291
+ const owner = walletClient.account?.address;
3292
+ if (!owner) {
3293
+ throw new Error("No account found in wallet client");
3294
+ }
3295
+ sentryAddBreadcrumb({
3296
+ category: "rewards-kernel",
3297
+ message: "claimPayoutsMulticall.start",
3298
+ level: "info",
3299
+ data: {
3300
+ chainId: walletClient?.chain?.id,
3301
+ contract: ADDRESSES.REWARDS_KERNEL,
3302
+ claimsCount: claims.length,
3303
+ nonces: claims.map((claim) => claim.nonce.toString()),
3304
+ to: claims[0]?.to,
3305
+ from: claims[0]?.from,
3306
+ },
3307
+ });
3308
+ const seenNonces = new Set();
3309
+ const callData = [];
3310
+ for (const claim of claims) {
3311
+ const { nonce, proof, tokensAndAmounts, from, to, isGuardedToken, toCounterfactual, } = claim;
3312
+ const nonceStr = nonce.toString();
3313
+ if (seenNonces.has(nonceStr)) {
3314
+ throw new Error(`Duplicate nonce in multicall: ${nonceStr}`);
3315
+ }
3316
+ seenNonces.add(nonceStr);
3317
+ if (!proof || proof.length === 0) {
3318
+ throw new Error(`Merkle proof is required for nonce ${nonceStr}`);
3319
+ }
3320
+ if (!tokensAndAmounts || tokensAndAmounts.length === 0) {
3321
+ throw new Error(`Tokens and amounts are required for nonce ${nonceStr}`);
3322
+ }
3323
+ if (isGuardedToken.length !== tokensAndAmounts.length) {
3324
+ throw new Error(`isGuardedToken length mismatch for nonce ${nonceStr}`);
3325
+ }
3326
+ if (toCounterfactual.length !== tokensAndAmounts.length) {
3327
+ throw new Error(`toCounterfactual length mismatch for nonce ${nonceStr}`);
3328
+ }
3329
+ if (!from || !to) {
3330
+ throw new Error(`${exports.RewardsKernelError.INVALID_PARAMETERS} for nonce ${nonceStr}`);
3331
+ }
3332
+ const alreadyClaimed = await isClaimed(owner, nonce);
3333
+ if (alreadyClaimed) {
3334
+ throw new Error(`${exports.RewardsKernelError.ALREADY_CLAIMED} (nonce ${nonceStr})`);
3335
+ }
3336
+ const finalized = await isFinalized(nonce);
3337
+ if (!finalized) {
3338
+ throw new Error(`${exports.RewardsKernelError.NOT_FINALIZED} (nonce ${nonceStr})`);
3339
+ }
3340
+ callData.push(viem.encodeFunctionData({
3341
+ abi: REWARDS_KERNEL_ABI,
3342
+ functionName: "claimPayout",
3343
+ args: [
3344
+ nonce,
3345
+ proof,
3346
+ tokensAndAmounts,
3347
+ from,
3348
+ to,
3349
+ isGuardedToken,
3350
+ toCounterfactual,
3351
+ ],
3352
+ }));
3353
+ }
3354
+ try {
3355
+ await publicClient.simulateContract({
3356
+ address: ADDRESSES.REWARDS_KERNEL,
3357
+ abi: REWARDS_KERNEL_ABI,
3358
+ functionName: "multicall",
3359
+ args: [callData],
3360
+ account: walletClient.account,
3361
+ });
3362
+ }
3363
+ catch (simulationError) {
3364
+ sentryCaptureException(simulationError, {
3365
+ action: "claimPayoutsMulticall.simulate",
3366
+ chainId: walletClient?.chain?.id,
3367
+ contract: ADDRESSES.REWARDS_KERNEL,
3368
+ claimsCount: claims.length,
3369
+ nonces: claims.map((claim) => claim.nonce.toString()),
3370
+ });
3371
+ throw new Error(parseViemError(simulationError));
3372
+ }
3373
+ const hash = await walletClient.writeContract({
3374
+ address: ADDRESSES.REWARDS_KERNEL,
3375
+ abi: REWARDS_KERNEL_ABI,
3376
+ functionName: "multicall",
3377
+ args: [callData],
3378
+ chain: walletClient.chain,
3379
+ account: walletClient.account,
3380
+ });
3381
+ await waitForViemTransactionWithRetry(publicClient, hash);
3382
+ return hash;
3383
+ }
3384
+ catch (error) {
3385
+ sentryCaptureException(error, {
3386
+ action: "claimPayoutsMulticall",
3387
+ chainId: walletClient?.chain?.id,
3388
+ contract: ADDRESSES.REWARDS_KERNEL,
3389
+ claimsCount: params.claims?.length ?? 0,
3390
+ nonces: params.claims?.map((claim) => claim.nonce.toString()) ?? [],
3391
+ });
3392
+ throw new Error(parseViemError(error));
3393
+ }
3394
+ finally {
3395
+ setIsProcessing(false);
3396
+ }
3397
+ }
3279
3398
  /**
3280
3399
  * Get reward metadata for a specific nonce
3281
3400
  * @param nonce The nonce to query
@@ -3514,6 +3633,7 @@ function useRewardsKernel(walletClient, publicClient, CHAIN_ID) {
3514
3633
  return {
3515
3634
  // Core contract functions
3516
3635
  claimPayout,
3636
+ claimPayoutsMulticall,
3517
3637
  // View functions
3518
3638
  getRewardMeta,
3519
3639
  getMaxReward,
@@ -5615,4 +5735,4 @@ exports.useOffchainFractions = useOffchainFractions;
5615
5735
  exports.useRewardsKernel = useRewardsKernel;
5616
5736
  exports.waitForEthersTransactionWithRetry = waitForEthersTransactionWithRetry;
5617
5737
  exports.waitForViemTransactionWithRetry = waitForViemTransactionWithRetry;
5618
- //# sourceMappingURL=calculate-farm-efficiency-K4OucflI.js.map
5738
+ //# sourceMappingURL=calculate-farm-efficiency-B3MkgKDh.js.map