@glowlabs-org/utils 0.2.22 → 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.
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var regionRouter = require('./region-router-BPm37uYd.js');
3
+ var regionRouter = require('./region-router-C3X3im0d.js');
4
4
  require('ethers');
5
+ require('viem');
5
6
 
6
7
 
7
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"browser.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
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-BPm37uYd.js');
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.ethers.utils.solidityKeccak256(leafTypes, [
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.ethers.utils.keccak256, { sort: true });
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.add(glowWeight), ethers.ethers.BigNumber.from(0));
18795
- const totalGCCWeightFinalizedLeavesSum = finalLeaves.reduce((acc, { usdgWeight }) => acc.add(usdgWeight), ethers.ethers.BigNumber.from(0));
18796
- if (totalGlowWeightFinalizedLeavesSum.toBigInt() > regionRouter.MAX_WEIGHT) {
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.toBigInt() > regionRouter.MAX_WEIGHT) {
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 = ethers.ethers.BigNumber.from(0);
18830
+ let forLoopedGlowWeightSum = 0n;
18831
18831
  for (const leafProof of farmsWithMerkleProofs) {
18832
- forLoopedGlowWeightSum = forLoopedGlowWeightSum.add(ethers.BigNumber.from(leafProof.glowWeight));
18832
+ forLoopedGlowWeightSum += BigInt(leafProof.glowWeight);
18833
18833
  }
18834
- if (!forLoopedGlowWeightSum.eq(totalGlowWeightFinalizedLeavesSum)) {
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 = ethers.ethers.BigNumber.from(0);
18840
+ let forLoopedGCCWeightSum = 0n;
18841
18841
  for (const leafProof of farmsWithMerkleProofs) {
18842
- forLoopedGCCWeightSum = forLoopedGCCWeightSum.add(ethers.BigNumber.from(leafProof.usdgWeight));
18842
+ forLoopedGCCWeightSum += BigInt(leafProof.usdgWeight);
18843
18843
  }
18844
- if (!forLoopedGCCWeightSum.eq(totalGCCWeightFinalizedLeavesSum)) {
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.ethers.utils.keccak256, {
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.add(glowWeight), ethers.ethers.BigNumber.from(0));
19031
- const totalUSDGWeight = finalizedLeaves.reduce((acc, { usdgWeight }) => acc.add(usdgWeight), ethers.ethers.BigNumber.from(0));
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.toBigInt() > regionRouter.MAX_WEIGHT)
19033
+ if (totalGlowWeight > regionRouter.MAX_WEIGHT)
19034
19034
  throw new Error("Total glow weight overflow");
19035
- if (totalUSDGWeight.toBigInt() > regionRouter.MAX_WEIGHT)
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.add(l.glowWeight), ethers.ethers.BigNumber.from(0));
19053
- if (!glowSumProofLoop.eq(totalGlowWeight)) {
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.add(l.usdgWeight), ethers.ethers.BigNumber.from(0));
19060
- if (!usdgSumProofLoop.eq(totalUSDGWeight)) {
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(BigInt(totalUSDGWeight.toString()), regionRouter.USDG_WEIGHT_DECIMAL_PRECISION));
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(BigInt(totalGlowWeight.toString()), regionRouter.GLOW_WEIGHT_DECIMAL_PRECISION));
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 BigNumber string
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(),