Skip to content

feat(contracts): venue-neutral BuybackBurner + Uniswap V3 burner - #1003

Merged
alpergundogdu merged 4 commits into
mainfrom
claude/pedantic-bose-920312
Jun 29, 2026
Merged

alpergundogdu merged 4 commits into
mainfrom
claude/pedantic-bose-920312

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Makes BuybackBurner venue-neutral and adds a Uniswap V3 burner, so the protocol can run buybacks on Arbitrum Sepolia (where Uniswap V3 is live but Balancer V3 is not deployed — the singleton Vault 0xbA13… has no code there).

Closes #1000.

Architecture

Three layers, replacing the previous Balancer-only base:

  • BuybackBurner (abstract, venue-neutral) — keeper entry point, the actual-TOKEN-balance-delta verification + burn, USDC rescue, pause. Abstract hooks: _performSwap, _requireWired.
  • GuardedBuybackBurner (abstract) — the shared MEV-defense stack lifted out of the Balancer contract: TWAP minOut floor, governed slippageBps/min/max band, per-epoch USDC liquidity cap, keeper rotation. Venue is abstracted behind _spotPrice / _usdcDepthRaw / _swapFeeE18 / _swap (+ _requireWired).
  • BuybackBurnerBalancerV3 and BuybackBurnerUniswapV3 — sibling venues binding the hooks. The Balancer Permit2 swap path is unchanged.

FeeRouter needs no change — it only safeTransfers the buyback USDC to the buybackBurner address, so switching venues is one setBuybackBurner governance call.

BuybackBurnerUniswapV3

  • Single exactInputSingle USDC→TOKEN swap on SwapRouter02, scoped ERC20 router approval (V2-style; no Permit2 leg).
  • TWAP floor via the inherited hand-rolled accumulator sampling slot0.sqrtPriceX96 (not the pool's native observe() oracle — keeps both burners on one TWAP impl and works on a freshly-seeded pool whose observation cardinality is still 1). _spotPrice handles both token orderings and the USDC decimal gap, unit-tested with exact sqrt-price vectors.
  • Fee-tier-derived swap fee; pool USDC balance as the per-epoch cap denominator.
  • setPool fail-fast-validates the pool is a USDC/TOKEN pair with a live price.

Rollout

Wire BuybackBurnerUniswapV3 on Arbitrum Sepolia now; swap to BuybackBurnerBalancerV3 via setBuybackBurner once Balancer V3 lands there.

Verification

  • forge fmt --check ✓
  • FOUNDRY_PROFILE=ci forge build --deny warnings ✓
  • forge test (non-fork): 654 passed, 0 failed, incl. 14 new Uniswap V3 tests and the unchanged Balancer suite as the refactor regression net.
  • slither . --config-file slither.config.json: no medium+ findings (the new _spotPrice tuple-destructure unused-return is waived per the CLAUDE.md convention).

Fork tests (gated, need an RPC) were not run locally.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a guarded, TWAP-backed buyback venue model with slippage controls and per-epoch liquidity caps.
    • Introduced a new Uniswap V3–based buyback venue implementation.
    • Governance can update keeper and venue configuration, with automatic guard-state resets on venue rotation.
    • Updated the activation script to target the guarded keeper setter.
  • Bug Fixes
    • Fail-closed behavior now blocks execution when venue wiring is missing or stale after rotation.
  • Tests / Chores
    • Refreshed gas snapshots and updated fuzz test expectations to match the new guarded error/event surface.

Extract the shared MEV-defense stack (TWAP floor, min/max band, per-epoch
liquidity cap) into a new abstract `GuardedBuybackBurner`, leaving
`BuybackBurner` venue-neutral: keeper entry point, TOKEN-balance-delta
verification, burn, USDC rescue, pause, plus abstract `_performSwap` /
`_requireWired` hooks.

Rebase `BuybackBurnerBalancerV3` onto the guard (Permit2 swap path unchanged),
and add `BuybackBurnerUniswapV3` as a sibling venue: a single
`exactInputSingle` USDC->TOKEN swap on SwapRouter02 with a scoped router
approval, a slot0-sourced TWAP floor (hand-rolled accumulator, both token
orderings), the fee-tier swap fee, and pool USDC balance as the cap
denominator.

`FeeRouter` is already venue-agnostic (it only transfers the buyback USDC to
the burner address), so switching venues is one `setBuybackBurner` call.
Targets Arbitrum Sepolia, where Uniswap V3 is live but Balancer V3 is not yet
deployed; the Balancer burner can be swapped in later with no FeeRouter change.

Closes #1000.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings June 26, 2026 13:57
@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 90.12% (2245/2491 lines)
▲ +0.16pp vs base (89.96% → 90.12%)
Run: 28388072498

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the buyback burner architecture to be venue-neutral by introducing an abstract GuardedBuybackBurner contract that houses the shared MEV-defense stack (TWAP accumulator, slippage floor, min/max buyback band, and per-epoch USDC liquidity cap). The existing BuybackBurnerBalancerV3 is refactored to inherit from this new base, and a new BuybackBurnerUniswapV3 implementation is introduced to support Uniswap V3. The review feedback highlights an opportunity to improve consistency and robustness by validating the Uniswap V3 pool address in the constructor of BuybackBurnerUniswapV3 if it is supplied at deployment time, matching the fail-fast behavior of the Balancer V3 burner.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the buyback burner contracts to be venue-neutral and introduces a Uniswap V3-backed burner for Arbitrum Sepolia, while extracting the shared MEV-defense logic (TWAP floor, slippage/band checks, and per-epoch USDC cap) into a reusable GuardedBuybackBurner layer.

Changes:

  • Refactor BuybackBurner into a venue-neutral abstract base with venue wiring delegated to _requireWired() and swap execution delegated to _performSwap().
  • Introduce GuardedBuybackBurner as the shared MEV-defense stack used by both Balancer and Uniswap venue implementations.
  • Add BuybackBurnerUniswapV3 (plus interfaces and a new unit test suite) and update existing Balancer tests/scripts for the refactor.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
contracts/src/BuybackBurner.sol Refactors base burner into venue-neutral abstract contract with _requireWired() hook.
contracts/src/GuardedBuybackBurner.sol Adds shared TWAP floor + band + epoch-cap MEV-defense layer used by venue implementations.
contracts/src/BuybackBurnerBalancerV3.sol Adapts Balancer burner to extend GuardedBuybackBurner and provide Balancer-specific venue hooks and wiring setters.
contracts/src/BuybackBurnerUniswapV3.sol Adds Uniswap V3 burner implementation with slot0-based spot math and scoped router approval.
contracts/src/interfaces/IUniswapV3SwapRouter.sol Adds minimal router interface for exactInputSingle.
contracts/src/interfaces/IUniswapV3Pool.sol Adds minimal pool interface for slot0/token ordering/fee tier reads.
contracts/test/BuybackBurner.t.sol Updates base tests to reflect venue-neutral wiring (_requireWired) instead of Balancer-specific wiring.
contracts/test/BuybackBurnerBalancerV3.t.sol Updates Balancer tests to expect shared GuardedBuybackBurner errors/events after refactor.
contracts/test/BuybackBurnerBalancerV3.swapburn.fork.t.sol Updates fork test expectations for moved error selectors.
contracts/test/BuybackBurnerUniswapV3.t.sol Adds unit tests for Uniswap venue hooks (spot math, wiring validation, scoped approval, guard behavior).
contracts/script/ActivateBuyback.s.sol Updates keeper calldata encoding to the new GuardedBuybackBurner.setKeeper entry point.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread contracts/script/ActivateBuyback.s.sol Resolved
Review comments (#1003):
- BuybackBurnerUniswapV3: validate a deploy-time pool in the constructor
  (fail-fast via _spotPrice, symmetric with setPool and the Balancer ctor).
- Reset the inherited TWAP accumulator + per-epoch cap on every venue
  rotation (Uniswap setPool, Balancer setPool/setVault) via a shared
  GuardedBuybackBurner._resetGuardState(), so the floor/cap re-derive
  fail-closed against the new venue instead of carrying stale state.
- ActivateBuyback script: log GuardedBuybackBurner.setKeeper to match the
  encoded calldata.

CI gates (were red, independent of the comments):
- Regenerate .gas-snapshot (stale after the new contracts).
- Waive slither incorrect-equality on the epochStartUsdcDepth == 0 lazy-init
  sentinel — newly tripped because the Uniswap _usdcDepthRaw is balanceOf-
  backed; the sentinel is intentional (same as twapLastUpdate == 0).
- Waive aderyn unsafe-casting on the Permit2 uint160(amountIn) downcast —
  the bound check moved into the BuybackBurner parent, so aderyn can no
  longer see it across the contract split; the cast is provably safe.

Adds tests for the constructor validation and guard-state reset on rotation.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cd24e4b2-1ed7-452b-9823-148708df5b93

📥 Commits

Reviewing files that changed from the base of the PR and between 3413640 and 2bf050b.

📒 Files selected for processing (1)
  • contracts/.gas-snapshot
🚧 Files skipped from review as they are similar to previous changes (1)
  • contracts/.gas-snapshot

Walkthrough

BuybackBurner becomes venue-neutral, shared guard logic is extracted, BuybackBurnerBalancerV3 is adapted to the guard, and BuybackBurnerUniswapV3 is added. Matching script, test, and gas snapshot updates follow.

Changes

Venue-neutral BuybackBurner + UniswapV3

Layer / File(s) Summary
BuybackBurner base made venue-neutral
contracts/src/BuybackBurner.sol
Removes Balancer wiring state, events, and setters from the base burner, and replaces the direct wiring check in executeBuyback with an abstract _requireWired() hook.
Shared guard logic added
contracts/src/GuardedBuybackBurner.sol
Adds the abstract guard contract with TWAP accumulation, fee- and slippage-adjusted floor checks, per-epoch cap accounting, governance setters, state reset, and abstract venue hooks.
Balancer venue moved onto the guarded base
contracts/src/BuybackBurnerBalancerV3.sol, contracts/script/ActivateBuyback.s.sol
Changes BuybackBurnerBalancerV3 to inherit the guarded base, keeps Balancer-specific state and wiring events in the contract, rewrites swap/spot/depth hooks, updates pool/vault rotation, and retargets the activation script’s keeper calldata.
Uniswap V3 burner implementation
contracts/src/interfaces/IUniswapV3Pool.sol, contracts/src/interfaces/IUniswapV3SwapRouter.sol, contracts/src/BuybackBurnerUniswapV3.sol
Adds minimal Uniswap V3 interfaces and a new burner with router/pool wiring, fail-fast pool validation, exactInputSingle execution, pool-fee conversion, spot-price derivation from slot0, and USDC depth sourcing from the pool balance.
Base burner tests updated
contracts/test/BuybackBurner.t.sol
Reworks the base burner test subclass to use a wired flag, updates setup and revert coverage for the new wiring hook, and removes the old pool/vault setter tests.
Balancer tests updated for guarded selectors
contracts/test/BuybackBurnerBalancerV3.t.sol, contracts/test/BuybackBurnerBalancerV3.swapburn.fork.t.sol
Updates Balancer burner unit and fork tests to use guarded error and event selectors, and adds rotation coverage that expects guard-state reset and TWAP re-maturity.
Uniswap V3 burner test suite
contracts/test/BuybackBurnerUniswapV3.t.sol
Adds mocks and a full BuybackBurnerUniswapV3 test suite covering constructor validation, TWAP pricing, guarded swap behavior, cap enforcement, pool rotation, and router/pool wiring validation.
Gas snapshot refreshed
contracts/.gas-snapshot
Refreshes the gas snapshot entries for the buyback test suites and unrelated fuzz tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The Uniswap V3 burner uses a shared hand-rolled TWAP accumulator instead of the issue's required native observe()-based oracle floor. Switch the Uniswap V3 path to an observe()-derived TWAP floor and remove the shared accumulator from that burner as requested.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the venue-neutral BuybackBurner plus new Uniswap V3 burner.
Out of Scope Changes check ✅ Passed The changes stay focused on the buyback burner refactor, new Uniswap V3 implementation, tests, and rollout script update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/pedantic-bose-920312

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
contracts/src/BuybackBurner.sol (1)

142-148: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Clarify that _performSwap returns the received delta.

Line 144 says “post-swap TOKEN amount,” but Line 132 compares the hook return to balanceAfter - balanceBefore. Returning the total post-swap balance would spuriously revert when the contract already holds TOKEN.

Suggested wording
-    ///      USDC->TOKEN swap (the TOKEN landing in this contract) and returns the
-    ///      post-swap TOKEN amount. Keeping this `virtual` without a body keeps
+    ///      USDC->TOKEN swap (the TOKEN landing in this contract) and returns the
+    ///      received TOKEN balance delta, not this contract's post-swap TOKEN
+    ///      balance. Keeping this `virtual` without a body keeps
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/src/BuybackBurner.sol` around lines 142 - 148, The `_performSwap`
hook in `BuybackBurner` is documented inconsistently with its caller: it should
return the TOKEN amount received from the swap (the delta), not the contract’s
total post-swap TOKEN balance. Update the `@dev` comment on `_performSwap` to
clearly state that the return value is the received TOKEN increase used against
`balanceAfter - balanceBefore`, so the contract can already hold TOKEN without
triggering a false revert.
contracts/test/BuybackBurnerBalancerV3.t.sol (1)

786-812: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Also assert the epoch-cap state resets on rotation.

Line 786 and Line 800 only verify the TWAP side of _resetGuardState() via TwapNotReady. Accruing some epochSwappedUsdc() before the rotation and asserting it returns to zero afterward would cover the other half of the documented reset behavior and catch a partial-reset regression.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/test/BuybackBurnerBalancerV3.t.sol` around lines 786 - 812, The
rotation tests for setPool and setVault only verify the TWAP reset path, but
they should also cover the epoch-cap reset handled by _resetGuardState(). Before
calling bb.setPool and bb.setVault, accrue some epochSwappedUsdc() on bb, then
assert that value returns to zero after rotation alongside the existing
TwapNotReady check. Update test_setPool_resetsGuardStateOnRotation and
test_setVault_resetsGuardStateOnRotation so they validate both GuardStateReset
behavior and the epoch-swapped state reset.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/src/BuybackBurnerBalancerV3.sol`:
- Around line 228-229: Add the matching Aderyn waiver immediately above the same
lines that already use slither-disable-next-line missing-zero-check in
BuybackBurnerBalancerV3.setPool and the other affected spot around the later
setter, so both analyzer suppressions are paired on the target line. Keep the
existing Slither suppression and insert the corresponding
aderyn-ignore-next-line(missing-zero-check) directly before each affected
statement to satisfy the repo’s paired-waiver rule.

In `@contracts/src/GuardedBuybackBurner.sol`:
- Around line 215-218: The poke() flow in GuardedBuybackBurner is using a
transient spot via _updateTwapAccumulator(), which lets a permissionless caller
pin a manipulated price across the next TWAP interval. Update poke() and the
related TWAP accumulation logic to derive the floor from finalized cumulative
oracle state or venue observations instead of sampling the latest marginal spot,
and adjust the helper path referenced by _updateTwapAccumulator() so the next
interval cannot be biased by a one-transaction price move.

---

Nitpick comments:
In `@contracts/src/BuybackBurner.sol`:
- Around line 142-148: The `_performSwap` hook in `BuybackBurner` is documented
inconsistently with its caller: it should return the TOKEN amount received from
the swap (the delta), not the contract’s total post-swap TOKEN balance. Update
the `@dev` comment on `_performSwap` to clearly state that the return value is
the received TOKEN increase used against `balanceAfter - balanceBefore`, so the
contract can already hold TOKEN without triggering a false revert.

In `@contracts/test/BuybackBurnerBalancerV3.t.sol`:
- Around line 786-812: The rotation tests for setPool and setVault only verify
the TWAP reset path, but they should also cover the epoch-cap reset handled by
_resetGuardState(). Before calling bb.setPool and bb.setVault, accrue some
epochSwappedUsdc() on bb, then assert that value returns to zero after rotation
alongside the existing TwapNotReady check. Update
test_setPool_resetsGuardStateOnRotation and
test_setVault_resetsGuardStateOnRotation so they validate both GuardStateReset
behavior and the epoch-swapped state reset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 76197e8d-6d66-4039-a60d-2b29e03573fc

📥 Commits

Reviewing files that changed from the base of the PR and between f2a4cc9 and dc2bb17.

📒 Files selected for processing (12)
  • contracts/.gas-snapshot
  • contracts/script/ActivateBuyback.s.sol
  • contracts/src/BuybackBurner.sol
  • contracts/src/BuybackBurnerBalancerV3.sol
  • contracts/src/BuybackBurnerUniswapV3.sol
  • contracts/src/GuardedBuybackBurner.sol
  • contracts/src/interfaces/IUniswapV3Pool.sol
  • contracts/src/interfaces/IUniswapV3SwapRouter.sol
  • contracts/test/BuybackBurner.t.sol
  • contracts/test/BuybackBurnerBalancerV3.swapburn.fork.t.sol
  • contracts/test/BuybackBurnerBalancerV3.t.sol
  • contracts/test/BuybackBurnerUniswapV3.t.sol

Comment on lines +228 to +229
// slither-disable-next-line missing-zero-check
function setPool(address newPool) external onlyRole(GOVERNANCE_ROLE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add the matching Aderyn waiver next to these Slither suppressions.

Line 228 and Line 248 add slither-disable-next-line missing-zero-check, but the repo rule requires the paired aderyn-ignore-next-line(...) immediately above the same target line. Without that second waiver, this change can still fail the expected analyzer pass. As per coding guidelines, "Place // slither-disable-next-line <detector> immediately before the targeted line, and place // aderyn-ignore-next-line(<detector>) immediately before the targeted line as well."

Also applies to: 248-249

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/src/BuybackBurnerBalancerV3.sol` around lines 228 - 229, Add the
matching Aderyn waiver immediately above the same lines that already use
slither-disable-next-line missing-zero-check in BuybackBurnerBalancerV3.setPool
and the other affected spot around the later setter, so both analyzer
suppressions are paired on the target line. Keep the existing Slither
suppression and insert the corresponding
aderyn-ignore-next-line(missing-zero-check) directly before each affected
statement to satisfy the repo’s paired-waiver rule.

Source: Coding guidelines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not applying — there's no such paired-waiver rule in this repo, and there's no Aderyn finding to suppress.

  • missing-zero-check is a Slither detector. Aderyn v0.6.8 (the version CI runs) reports zero missing-zero-check/address-without-check findings on these setters, so an aderyn-ignore-next-line(missing-zero-check) would waive a finding that doesn't exist.
  • The established repo pattern is Slither-only here: FeeRouter.sol:156 uses the same lone // slither-disable-next-line missing-zero-check and is green on main. The CLAUDE.md guidance is about placement of each directive when used, not a requirement to pair them.

Verified locally: forge build + Slither (0 medium+) + Aderyn 0.6.8 (0 high) all pass without the added waiver.

Comment on lines +215 to +218
function poke() external {
_requireWired();
_updateTwapAccumulator();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

poke() can pin a transient price for the entire next TWAP interval.

_updateTwapAccumulator() records the current marginal spot and later treats it as if it remained valid until the next sample. Because poke() is permissionless, an attacker can skew the pool, call poke(), unwind immediately, and still have that manipulated spot weighted across the whole interval to the next update. That makes the TWAP floor biasable/DOSable with a one-transaction price move, which undermines the MEV guard this layer is meant to provide. This needs a cumulative oracle derived from finalized interval state (for example the venue’s native oracle/observations) instead of assuming the latest sampled spot persisted after the sampling transaction.

Also applies to: 374-405

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/src/GuardedBuybackBurner.sol` around lines 215 - 218, The poke()
flow in GuardedBuybackBurner is using a transient spot via
_updateTwapAccumulator(), which lets a permissionless caller pin a manipulated
price across the next TWAP interval. Update poke() and the related TWAP
accumulation logic to derive the floor from finalized cumulative oracle state or
venue observations instead of sampling the latest marginal spot, and adjust the
helper path referenced by _updateTwapAccumulator() so the next interval cannot
be biased by a one-transaction price move.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a real property of the accumulator, but it's the documented, accepted design — not a regression in this PR, and the suggested remedy isn't available on these venues.

  • Accepted per ADR 018. The floor is a self-maintained cumulative-price accumulator precisely because Balancer V3 ships no built-in pool oracle (V2's was removed) and TOKEN has no external feed at launch. ADR 018 states it is necessary-not-sufficient and stays layered under mandatory keeper-side private-RPC routing and the per-epoch liquidity cap.
  • Native oracle isn't an option here. Balancer V3 has no observe(); the Uniswap V3 pool is freshly-seeded with observation cardinality 1, so its native oracle returns nothing usable. That's the explicit reason both burners share the hand-rolled accumulator (see the contract header).
  • The floor is not the primary gate. The effective minimum is max(twapFloor, keeper minTokenOut) and every buyback is submitted through a private-RPC bundle, so a public single-poke skew can't be paired with a same-block front-run of the keeper's swap. A manipulated-low floor still leaves the keeper's own minOut; a manipulated-high floor is bounded griefing.
  • Pre-existing + out of scope. _updateTwapAccumulator/poke() are lifted byte-identical from the already-merged BuybackBurnerBalancerV3 on main; this PR only made them venue-neutral. Replacing the accumulator with a finalized-cumulative oracle is an ADR-018-level change for a separate PR, not this venue refactor.

Not changing it here.

From the comprehensive PR review:
- BuybackBurnerUniswapV3._spotPrice: guard the direct (USDC=token0) branch
  against a spot that floor-divides to 0, symmetric with the inverted branch,
  so an implausibly-cheap TOKEN can't collapse the TWAP floor to 0 (fail-open).
- Tests: cover the Uniswap-specific balanceOf-backed per-epoch cap
  (EpochCapExceeded), depth re-snapshot after a setPool rotation, and the new
  zero-spot revert guard.
- ActivateBuyback: fix the stale doc comment to GuardedBuybackBurner.setKeeper.

Regenerated .gas-snapshot for the new tests.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu

Copy link
Copy Markdown
Contributor Author

Review round 2 — addressed in 3413640 (+ dc2bb17)

New reviewer comments

  • CodeRabbit (Major) — poke() can pin a transient TWAP spot. Not changing it: this is the documented, accepted ADR-018 design. The hand-rolled accumulator exists precisely because Balancer V3 ships no pool oracle and the fresh Uniswap V3 pool has observation cardinality 1, so a native observe() oracle isn't available on either venue. ADR 018 declares the floor necessary-not-sufficient, layered under mandatory keeper-side private-RPC routing + the per-epoch cap, with the effective minimum max(twapFloor, keeperMinOut). The _updateTwapAccumulator/poke() code is also byte-identical to the already-merged BuybackBurnerBalancerV3 on main — this PR only made it venue-neutral, so a redesign is out of scope (separate ADR-018-level PR). Replied inline.
  • CodeRabbit (Minor) — pair an Aderyn waiver with the Slither missing-zero-check. Not applying: missing-zero-check is a Slither detector; Aderyn v0.6.8 (CI's version) reports zero such findings on these setters, so the waiver would suppress nothing. The repo pattern is Slither-only here (FeeRouter.sol:156 is the same and green on main). Replied inline.

Comprehensive review pass

I ran an adversarial review over the full diff (spot-price math both orderings, _resetGuardState + epoch interactions, constructor ordering, scoped router approval, interface match, CEI/access-control). No correctness, reentrancy, access-control, or interface bugs. Three low-severity items found and fixed:

  1. _spotPrice fail-open asymmetry — the direct (USDC=token0) branch could return a floor-divided 0 while the inverted branch reverts; a 0 spot collapses the TWAP floor. Added the symmetric PoolStateInvalid guard.
  2. Uniswap test coverage gap — added tests for the Uniswap-specific balanceOf-backed per-epoch cap (EpochCapExceeded), depth re-snapshot after a setPool rotation, and the new zero-spot guard.
  3. Stale doc comment in ActivateBuyback.s.sol → GuardedBuybackBurner.setKeeper.

Verification (local, mirrors CI): forge fmt --check ✓ · FOUNDRY_PROFILE=ci forge build --deny warnings ✓ · forge test 661 passed / 0 failed ✓ · gas snapshot regenerated/stable ✓ · Slither 0 medium+ ✓ · Aderyn v0.6.8 0 high ✓

…920312

# Conflicts:
#	contracts/.gas-snapshot
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.

Make BuybackBurner venue-neutral and add BuybackBurnerUniswapV3

2 participants