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