Skip to content

fix(dao): add updateEpochTotalAmount to ClisBNBLaunchPoolDistributor - #124

Closed
toccata-yy-lista wants to merge 1 commit into
masterfrom
fix/clisbnb-launchpool-update-epoch-amount
Closed

fix(dao): add updateEpochTotalAmount to ClisBNBLaunchPoolDistributor#124
toccata-yy-lista wants to merge 1 commit into
masterfrom
fix/clisbnb-launchpool-update-epoch-amount

Conversation

@toccata-yy-lista

Copy link
Copy Markdown
Contributor

Problem

One epoch of ClisBNBLaunchPoolDistributor was created with a totalAmount lower than the sum of its merkle tree. Since claim() does:

totalUnclaimedAmount[epoch.token] -= _amount;
epoch.unclaimedAmount -= _amount;

once cumulative claims exceed the configured totalAmount, unclaimedAmount underflows and every remaining user's claim reverts. There was no way to correct an epoch after it started — setEpochMerkleRoot only appends nextEpochId, and revokeEpoch requires the epoch to not have started yet.

Fix

Add an admin-only updateEpochTotalAmount(uint64 _epochId, uint256 _totalAmount):

  • DEFAULT_ADMIN_ROLE only (more sensitive than setEpochMerkleRoot, which is OPERATOR).
  • Works on a running epoch (only requires the epoch to exist and to not have ended), which is what the incident needs.
  • The delta is applied to epoch.unclaimedAmount and totalUnclaimedAmount[token], so already-claimed amounts and the claimed flags are untouched.
  • Decrease is supported but capped at unclaimedAmount ("Amount already claimed"), so it can never underflow.
  • Post-check: the contract's balance of the epoch token (BNB or ERC20) must cover totalUnclaimedAmount[token]the contract must be funded before calling, otherwise it reverts with "Insufficient balance".
  • Emits UpdateEpochTotalAmount(epochId, token, oldTotalAmount, newTotalAmount, unclaimedAmount).

No new storage variables, so the upgrade is storage-layout safe. scripts/foundry/dao/deploy_ClisBNBLaunchPoolDistributor_impl.sol already covers the impl-only deploy.

Tests

forge test --match-path test/dao/ClisBNBLaunchPoolDistributor.t.sol — 30 passed, 0 failed (16 for the new method).

The main one, test_updateEpochTotalAmount_fix_insufficient_total_amount, reproduces the incident (totalAmount 1000e18 vs merkle sum 1737e18 → third claimer reverts), applies the fix and shows all four users claiming down to a zero balance. Also covered: event payload, multiple epochs sharing one token (totalUnclaimedAmount aggregation + balance check), collectUnclaimed after an increase, decrease / decrease-to-claimed-boundary / decrease-below-claimed, BNB and ERC20 insufficient balance, ended epoch, revoked and unknown epochId, zero and unchanged amount, and ACL (incl. OPERATOR being rejected).

An epoch whose totalAmount was configured lower than the sum of its merkle
tree makes the remaining users unable to claim: `epoch.unclaimedAmount -=
_amount` underflows once the shortfall is reached.

Add an admin-only `updateEpochTotalAmount(epochId, totalAmount)` which
adjusts totalAmount of a not-yet-ended epoch and applies the difference to
`unclaimedAmount` / `totalUnclaimedAmount`, so already claimed rewards stay
untouched. Decreases are capped by the unclaimed part, and the new total
must be fully covered by the contract balance of the epoch token.
@hashdit-bot

hashdit-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Pull Request Review

This Solidity smart contract PR adds an admin-only function to correct an active epoch’s total reward amount while preserving already-claimed rewards and updating aggregate liabilities. It also adds an update event and comprehensive Foundry tests covering increases, decreases, balance requirements, epoch state, BNB/ERC20 rewards, and access control.

Sensitive Content

No sensitive content detected.

Security Issues

No serious security issues detected.


Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits.

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.

1 participant