Skip to content

Conversation

@md0x
Copy link
Contributor

@md0x md0x commented Feb 2, 2026

Adds a utility script to merge two gas rebate JSON files into a single combined rebate. The script validates block ranges are contiguous and voting contracts match before merging shareholder payouts.

Motivation

January 2026 gas rebates needed to be run in two separate block ranges due to memory/performance constraints, then merged into a single rebate file.

Summary

  • Added mergeRebates.js utility to combine two rebate JSON files
  • Generated merged Rebate_64.json covering blocks 24136053-24358292 (622 voters, 3.97 ETH)

Details

Ran January gas rebates in two steps:

CUSTOM_NODE_URL=https://mainnet.infura.io/v3/xxx \
NODE_OPTIONS="--max-old-space-size=32096" \
OVERRIDE_FROM_BLOCK=24136053 \
OVERRIDE_TO_BLOCK=24236386 \
MIN_STAKED_TOKENS=1000 \
TRANSACTION_CONCURRENCY=10 \
MAX_BLOCK_LOOK_BACK=250 \
yarn hardhat run ./gas-rebate/VoterGasRebateV2.ts --network mainnet
CUSTOM_NODE_URL=https://mainnet.infura.io/v3/xxx \
NODE_OPTIONS="--max-old-space-size=32096" \
OVERRIDE_FROM_BLOCK=24236387 \
OVERRIDE_TO_BLOCK=24358292 \
MIN_STAKED_TOKENS=1000 \
TRANSACTION_CONCURRENCY=10 \
MAX_BLOCK_LOOK_BACK=250 \
MAX_PRIORITY_FEE_GWEI=0.001 \
yarn hardhat run ./gas-rebate/VoterGasRebateV2.ts --network mainnet

Then merged them with node packages/affiliates/gas-rebate/mergeRebates.js <file1> <file2>

Testing

  • Ran end-to-end test, running the code as in production

md0x added 3 commits February 2, 2026 11:05
Adds a utility script to merge two gas rebate JSON files into a single
combined rebate. The script validates block ranges are contiguous and
voting contracts match before merging shareholder payouts.
Periods 24136053-24358292 covering 622 voters with 3.97 ETH total.
@md0x md0x marked this pull request as ready for review February 2, 2026 16:15

for (const [address, amount] of Object.entries(second)) {
if (merged[address]) {
merged[address] = merged[address] + amount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebate script uses parsed BigNumber, so we could end up loosing precision when merging multiple rebate sets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty, fixed!

return JSON.parse(content);
}

function validateBlockRanges(first, second) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also restrict that first.toBlock is the last block of a reveal cycle? Could this otherwise end up with different results than running the rebate script over single block range (e.g. due to constraints that only one commit per round is rebated)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment and a log. We should not use this script more than once, as we have different rebate configs.

…merging

- Add ethToWeiBigInt and weiBigIntToEth functions to avoid floating point
  precision loss when summing rebate amounts
- Add warning about splitting rebates at voting round boundaries to avoid
  inconsistent results vs single-run rebates
@md0x md0x requested a review from Reinis-FRP February 2, 2026 19:27
*/
function ethToWeiBigInt(ethValue) {
// Convert to string and handle scientific notation
const ethStr = ethValue.toFixed(18);
Copy link
Contributor

@Reinis-FRP Reinis-FRP Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this still introduces some JS rounding errors, e.g. ethValue = 0.1; ethValue.toFixed(18); ends up resulting in '0.100000000000000006'
but probably fine to leave for a one-off script as result objects store rebates as number, not string, so this is inevitable. might be better to use some library for parsing and conversion, e.g. ethers, but again, not worth for a one-off script

@md0x md0x merged commit 8cecdcc into master Feb 3, 2026
7 checks passed
@md0x md0x deleted the feat/gas-rebates-january-2026 branch February 3, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants