@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/cjs/browser.js +1 -1
- package/dist/cjs/{calculate-farm-efficiency-DQqLqk0-.js → calculate-farm-efficiency-B3MkgKDh.js} +148 -1
- package/dist/cjs/calculate-farm-efficiency-B3MkgKDh.js.map +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/lib/control-api/farms-router.d.ts +2 -1
- package/dist/cjs/lib/hooks/use-rewards-kernel.d.ts +4 -0
- package/dist/cjs/lib/types/index.d.ts +10 -0
- package/dist/esm/browser.js +2 -2
- package/dist/esm/{calculate-farm-efficiency-BjXQqtxI.js → calculate-farm-efficiency-CZbLTXjU.js} +149 -2
- package/dist/esm/calculate-farm-efficiency-CZbLTXjU.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/control-api/farms-router.d.ts +2 -1
- package/dist/esm/lib/hooks/use-rewards-kernel.d.ts +4 -0
- package/dist/esm/lib/types/index.d.ts +10 -0
- package/package.json +1 -1
- package/src/lib/control-api/farms-router.ts +36 -0
- package/src/lib/hooks/use-rewards-kernel.ts +163 -0
- package/src/lib/types/index.ts +16 -0
- package/dist/cjs/calculate-farm-efficiency-DQqLqk0-.js.map +0 -1
- package/dist/esm/calculate-farm-efficiency-BjXQqtxI.js.map +0 -1
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-
|
|
18
|
+
var calculateFarmEfficiency = require('./calculate-farm-efficiency-B3MkgKDh.js');
|
|
19
19
|
|
|
20
20
|
const GENESIS_TIMESTAMP = 1700352000;
|
|
21
21
|
|
|
@@ -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/dist/esm/browser.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TRANSFER_TYPES } from './calculate-farm-efficiency-
|
|
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-
|
|
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';
|
package/dist/esm/{calculate-farm-efficiency-BjXQqtxI.js → calculate-farm-efficiency-CZbLTXjU.js}
RENAMED
|
@@ -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,
|
|
@@ -5497,6 +5617,32 @@ function FarmsRouter(baseUrl) {
|
|
|
5497
5617
|
throw new Error(parseApiError(error));
|
|
5498
5618
|
}
|
|
5499
5619
|
};
|
|
5620
|
+
const fetchFarmImagesBatch = async (params) => {
|
|
5621
|
+
try {
|
|
5622
|
+
sentryAddBreadcrumb({
|
|
5623
|
+
category: "control-api",
|
|
5624
|
+
message: "POST /farms/images/batch",
|
|
5625
|
+
level: "info",
|
|
5626
|
+
data: { baseUrl, farmsCount: params.farmIds?.length },
|
|
5627
|
+
});
|
|
5628
|
+
const data = await request("/farms/images/batch", {
|
|
5629
|
+
method: "POST",
|
|
5630
|
+
headers: {
|
|
5631
|
+
"Content-Type": "application/json",
|
|
5632
|
+
},
|
|
5633
|
+
body: JSON.stringify(params),
|
|
5634
|
+
});
|
|
5635
|
+
return data;
|
|
5636
|
+
}
|
|
5637
|
+
catch (error) {
|
|
5638
|
+
sentryCaptureException(error, {
|
|
5639
|
+
action: "fetchFarmImagesBatch",
|
|
5640
|
+
baseUrl,
|
|
5641
|
+
farmsCount: params.farmIds?.length,
|
|
5642
|
+
});
|
|
5643
|
+
throw new Error(parseApiError(error));
|
|
5644
|
+
}
|
|
5645
|
+
};
|
|
5500
5646
|
return {
|
|
5501
5647
|
fetchFarmRewardSplits,
|
|
5502
5648
|
fetchSponsoredFarms,
|
|
@@ -5509,6 +5655,7 @@ function FarmsRouter(baseUrl) {
|
|
|
5509
5655
|
fetchFarmWeeklyRewardsBatch,
|
|
5510
5656
|
fetchWalletFarmRewardsHistory,
|
|
5511
5657
|
fetchWalletFarmRewardsHistoryBatch,
|
|
5658
|
+
fetchFarmImagesBatch,
|
|
5512
5659
|
};
|
|
5513
5660
|
}
|
|
5514
5661
|
|
|
@@ -5554,4 +5701,4 @@ function calculateFarmEfficiency(protocolDepositUsd6, weeklyImpactAssetsWad) {
|
|
|
5554
5701
|
}
|
|
5555
5702
|
|
|
5556
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 };
|
|
5557
|
-
//# sourceMappingURL=calculate-farm-efficiency-
|
|
5704
|
+
//# sourceMappingURL=calculate-farm-efficiency-CZbLTXjU.js.map
|