@glowlabs-org/utils 0.2.23 → 0.2.26
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/index.js +25 -25
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/control-api/region-router.d.ts +5 -1
- package/dist/cjs/lib/hooks/use-forwarder.d.ts +13 -13
- package/dist/cjs/lib/types/index.d.ts +50 -0
- package/dist/cjs/{region-router-DZPbuGxv.js → region-router-CIjrTHtv.js} +73 -17
- package/dist/cjs/region-router-CIjrTHtv.js.map +1 -0
- package/dist/esm/browser.js +1 -1
- package/dist/esm/index.js +27 -27
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/control-api/region-router.d.ts +5 -1
- package/dist/esm/lib/hooks/use-forwarder.d.ts +13 -13
- package/dist/esm/lib/types/index.d.ts +50 -0
- package/dist/esm/{region-router-BE9kP_sl.js → region-router-CSTfHLOs.js} +74 -18
- package/dist/esm/region-router-CSTfHLOs.js.map +1 -0
- package/package.json +3 -3
- package/src/lib/control-api/region-router.ts +59 -0
- package/src/lib/create-weekly-report/index.ts +30 -40
- package/src/lib/create-weekly-report/utils/hashLeaf.ts +2 -2
- package/src/lib/hooks/use-forwarder.ts +61 -60
- package/src/lib/types/index.ts +64 -0
- package/src/utils/hash-leaf.ts +2 -2
- package/dist/cjs/region-router-DZPbuGxv.js.map +0 -1
- package/dist/esm/region-router-BE9kP_sl.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -11,10 +11,10 @@ import zlib from 'zlib';
|
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
12
12
|
import { parseUnits, formatUnits } from 'viem';
|
|
13
13
|
import { MerkleTree } from 'merkletreejs';
|
|
14
|
-
import {
|
|
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 './region-router-
|
|
17
|
-
export { C as ControlRouter, R as RegionRouter, u as useForwarder } from './region-router-
|
|
16
|
+
import { H as HUB_URL, U as USDG_WEIGHT_DECIMAL_PRECISION, G as GLOW_WEIGHT_DECIMAL_PRECISION, M as MAX_WEIGHT } from './region-router-CSTfHLOs.js';
|
|
17
|
+
export { C as ControlRouter, R as RegionRouter, u as useForwarder } from './region-router-CSTfHLOs.js';
|
|
18
18
|
|
|
19
19
|
const GENESIS_TIMESTAMP = 1700352000;
|
|
20
20
|
|
|
@@ -18693,7 +18693,7 @@ const NUMERIC_REGEX = /^(?:\d+\.?\d*|\.\d+)$/;
|
|
|
18693
18693
|
|
|
18694
18694
|
const leafTypes = ["address", "uint256", "uint256"];
|
|
18695
18695
|
function hashLeaf({ address, glowWeight, usdcWeight, }) {
|
|
18696
|
-
const hash =
|
|
18696
|
+
const hash = solidityPackedKeccak256(leafTypes, [
|
|
18697
18697
|
address,
|
|
18698
18698
|
glowWeight,
|
|
18699
18699
|
usdcWeight,
|
|
@@ -18788,14 +18788,14 @@ async function createWeeklyReportLegacy(args) {
|
|
|
18788
18788
|
glowWeight: leaf.glowWeight,
|
|
18789
18789
|
usdcWeight: leaf.usdgWeight,
|
|
18790
18790
|
}));
|
|
18791
|
-
const tree = new MerkleTree(leaves,
|
|
18791
|
+
const tree = new MerkleTree(leaves, keccak256, { sort: true });
|
|
18792
18792
|
const root = tree.getHexRoot();
|
|
18793
|
-
const totalGlowWeightFinalizedLeavesSum = finalLeaves.reduce((acc, { glowWeight }) => acc
|
|
18794
|
-
const totalGCCWeightFinalizedLeavesSum = finalLeaves.reduce((acc, { usdgWeight }) => acc
|
|
18795
|
-
if (totalGlowWeightFinalizedLeavesSum
|
|
18793
|
+
const totalGlowWeightFinalizedLeavesSum = finalLeaves.reduce((acc, { glowWeight }) => acc + BigInt(glowWeight), 0n);
|
|
18794
|
+
const totalGCCWeightFinalizedLeavesSum = finalLeaves.reduce((acc, { usdgWeight }) => acc + BigInt(usdgWeight), 0n);
|
|
18795
|
+
if (totalGlowWeightFinalizedLeavesSum > MAX_WEIGHT) {
|
|
18796
18796
|
throw new Error("Total glow weight is greater than max weight");
|
|
18797
18797
|
}
|
|
18798
|
-
if (totalGCCWeightFinalizedLeavesSum
|
|
18798
|
+
if (totalGCCWeightFinalizedLeavesSum > MAX_WEIGHT) {
|
|
18799
18799
|
throw new Error("Total gcc weight is greater than max weight");
|
|
18800
18800
|
}
|
|
18801
18801
|
const headlineStats = {
|
|
@@ -18826,21 +18826,21 @@ async function createWeeklyReportLegacy(args) {
|
|
|
18826
18826
|
proof,
|
|
18827
18827
|
};
|
|
18828
18828
|
});
|
|
18829
|
-
let forLoopedGlowWeightSum =
|
|
18829
|
+
let forLoopedGlowWeightSum = 0n;
|
|
18830
18830
|
for (const leafProof of farmsWithMerkleProofs) {
|
|
18831
|
-
forLoopedGlowWeightSum
|
|
18831
|
+
forLoopedGlowWeightSum += BigInt(leafProof.glowWeight);
|
|
18832
18832
|
}
|
|
18833
|
-
if (
|
|
18833
|
+
if (forLoopedGlowWeightSum !== totalGlowWeightFinalizedLeavesSum) {
|
|
18834
18834
|
console.error("Glow Weight Sum Mismatch:");
|
|
18835
18835
|
console.error("Sum from loop:", forLoopedGlowWeightSum.toString());
|
|
18836
18836
|
console.error("Sum from reduce:", totalGlowWeightFinalizedLeavesSum.toString());
|
|
18837
18837
|
throw new Error("Glow weight sum is not equal");
|
|
18838
18838
|
}
|
|
18839
|
-
let forLoopedGCCWeightSum =
|
|
18839
|
+
let forLoopedGCCWeightSum = 0n;
|
|
18840
18840
|
for (const leafProof of farmsWithMerkleProofs) {
|
|
18841
|
-
forLoopedGCCWeightSum
|
|
18841
|
+
forLoopedGCCWeightSum += BigInt(leafProof.usdgWeight);
|
|
18842
18842
|
}
|
|
18843
|
-
if (
|
|
18843
|
+
if (forLoopedGCCWeightSum !== totalGCCWeightFinalizedLeavesSum) {
|
|
18844
18844
|
console.error("USDG Weight Sum Mismatch:");
|
|
18845
18845
|
console.error("Sum from loop:", forLoopedGCCWeightSum.toString());
|
|
18846
18846
|
console.error("Sum from reduce:", totalGCCWeightFinalizedLeavesSum.toString());
|
|
@@ -19021,17 +19021,17 @@ async function createWeeklyReport({ week, gcaUrls, apiUrl, }) {
|
|
|
19021
19021
|
usdcWeight: leaf.usdgWeight, // Note: Parameter name inconsistency (usdc vs usdg)
|
|
19022
19022
|
}));
|
|
19023
19023
|
// Build the Merkle tree.
|
|
19024
|
-
const merkleTree = new MerkleTree(hashedLeaves,
|
|
19024
|
+
const merkleTree = new MerkleTree(hashedLeaves, keccak256, {
|
|
19025
19025
|
sort: true, // Ensure consistent tree structure.
|
|
19026
19026
|
});
|
|
19027
19027
|
const merkleRoot = merkleTree.getHexRoot(); // Get the root hash.
|
|
19028
19028
|
// Calculate the total weights across all finalized leaves.
|
|
19029
|
-
const totalGlowWeight = finalizedLeaves.reduce((acc, { glowWeight }) => acc
|
|
19030
|
-
const totalUSDGWeight = finalizedLeaves.reduce((acc, { usdgWeight }) => acc
|
|
19029
|
+
const totalGlowWeight = finalizedLeaves.reduce((acc, { glowWeight }) => acc + BigInt(glowWeight), 0n);
|
|
19030
|
+
const totalUSDGWeight = finalizedLeaves.reduce((acc, { usdgWeight }) => acc + BigInt(usdgWeight), 0n);
|
|
19031
19031
|
// Total Weight Overflow Checks: Ensure sums don't exceed maximum.
|
|
19032
|
-
if (totalGlowWeight
|
|
19032
|
+
if (totalGlowWeight > MAX_WEIGHT)
|
|
19033
19033
|
throw new Error("Total glow weight overflow");
|
|
19034
|
-
if (totalUSDGWeight
|
|
19034
|
+
if (totalUSDGWeight > MAX_WEIGHT)
|
|
19035
19035
|
throw new Error("Total USDG weight overflow");
|
|
19036
19036
|
// Generate Merkle proofs for each leaf and verify them.
|
|
19037
19037
|
const leavesWithProofs = finalizedLeaves.map((leaf) => {
|
|
@@ -19048,15 +19048,15 @@ async function createWeeklyReport({ week, gcaUrls, apiUrl, }) {
|
|
|
19048
19048
|
});
|
|
19049
19049
|
// --- Sanity Checks on Final Weights ---
|
|
19050
19050
|
// Verify that summing weights from leavesWithProofs matches the earlier reduce calculation.
|
|
19051
|
-
const glowSumProofLoop = leavesWithProofs.reduce((acc, l) => acc
|
|
19052
|
-
if (
|
|
19051
|
+
const glowSumProofLoop = leavesWithProofs.reduce((acc, l) => acc + BigInt(l.glowWeight), 0n);
|
|
19052
|
+
if (glowSumProofLoop !== totalGlowWeight) {
|
|
19053
19053
|
console.error("Glow Weight Sum Mismatch (Post-73):");
|
|
19054
19054
|
console.error("Sum from loop:", glowSumProofLoop.toString());
|
|
19055
19055
|
console.error("Sum from reduce:", totalGlowWeight.toString());
|
|
19056
19056
|
throw new Error("Glow sum mismatch");
|
|
19057
19057
|
}
|
|
19058
|
-
const usdgSumProofLoop = leavesWithProofs.reduce((acc, l) => acc
|
|
19059
|
-
if (
|
|
19058
|
+
const usdgSumProofLoop = leavesWithProofs.reduce((acc, l) => acc + BigInt(l.usdgWeight), 0n);
|
|
19059
|
+
if (usdgSumProofLoop !== totalUSDGWeight) {
|
|
19060
19060
|
console.error("USDG Weight Sum Mismatch (Post-73):");
|
|
19061
19061
|
console.error("Sum from loop:", usdgSumProofLoop.toString());
|
|
19062
19062
|
console.error("Sum from reduce:", totalUSDGWeight.toString());
|
|
@@ -19068,7 +19068,7 @@ async function createWeeklyReport({ week, gcaUrls, apiUrl, }) {
|
|
|
19068
19068
|
return acc.plus(fromBigInt(adj, USDG_WEIGHT_DECIMAL_PRECISION));
|
|
19069
19069
|
}, new Decimal(0));
|
|
19070
19070
|
// Convert total USDG weight back to human-readable decimal for deviation check.
|
|
19071
|
-
const totalUSDGWeightHuman = new Decimal(formatUnits(
|
|
19071
|
+
const totalUSDGWeightHuman = new Decimal(formatUnits(totalUSDGWeight, USDG_WEIGHT_DECIMAL_PRECISION));
|
|
19072
19072
|
// Check deviation between total adjusted credits used and the final sum of USDG weights.
|
|
19073
19073
|
if (greaterThanMaxDeviation(totalExpectedCredits.toNumber(), totalUSDGWeightHuman.toNumber(), 0.001 // 0.1% tolerance
|
|
19074
19074
|
)) {
|
|
@@ -19079,7 +19079,7 @@ async function createWeeklyReport({ week, gcaUrls, apiUrl, }) {
|
|
|
19079
19079
|
throw new Error("totalExpectedCredits vs USDG weight deviation >0.1% ");
|
|
19080
19080
|
}
|
|
19081
19081
|
// Convert total Glow weight back to human-readable decimal.
|
|
19082
|
-
const totalGlowWeightHuman = new Decimal(formatUnits(
|
|
19082
|
+
const totalGlowWeightHuman = new Decimal(formatUnits(totalGlowWeight, GLOW_WEIGHT_DECIMAL_PRECISION));
|
|
19083
19083
|
// Sum the original weekly protocol fee payments from farm data.
|
|
19084
19084
|
const totalProtocolFeePayments = farms.reduce((acc, f) => acc + f.weeklyPayment, 0);
|
|
19085
19085
|
// Check deviation between total glow weight and total protocol fees paid.
|
|
@@ -19097,7 +19097,7 @@ async function createWeeklyReport({ week, gcaUrls, apiUrl, }) {
|
|
|
19097
19097
|
weekNumber: week,
|
|
19098
19098
|
totalCreditsProduced: formatUnits(totalCreditsProduced18dp, 18), // Original reported total
|
|
19099
19099
|
totalCreditsProducedBN: totalCreditsProduced18dp.toString(),
|
|
19100
|
-
totalGlowWeightInFinalized: totalGlowWeight.toString(), // Total weight as
|
|
19100
|
+
totalGlowWeightInFinalized: totalGlowWeight.toString(), // Total weight as bigint string
|
|
19101
19101
|
totalGlowWeightHuman: totalGlowWeightHuman.toString(), // Total weight as human-readable decimal
|
|
19102
19102
|
totalUSDGWeightInFinalized: totalUSDGWeight.toString(),
|
|
19103
19103
|
totalUSDGWeightHuman: totalUSDGWeightHuman.toString(),
|