Skip to content

Add refreshBasket(bool skipTradingDelay) - #1320

Merged
tbrent merged 9 commits into
4.3.0-audit-forward-revenue-delayfrom
4.3.0-audit-refresh-skip-delay
Dec 1, 2026
Merged

tbrent merged 9 commits into
4.3.0-audit-forward-revenue-delayfrom
4.3.0-audit-refresh-skip-delay

Conversation

@tbrent

@tbrent tbrent commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds BasketHandler.refreshBasket(bool skipTradingDelay). Governance now has to opt in to skipping the trading delay. refreshBasket() calls refreshBasket(false).

Stacked on #1319.

Why

Trust audit finding "Unrelated queued governance proposal bypasses the trading delay" (Low).

At the audited commit, any refreshBasket() by governance skipped the trading delay. A queued proposal that refreshes the basket for an unrelated reason, for example after swapping a collateral plugin, could execute right after a default and start rebalancing immediately. Anyone can execute a queued proposal once its timelock has elapsed.

With this change the skip is explicit:

Call Caller Trading delay
refreshBasket() governance kept
refreshBasket() anyone, when the basket is disabled and trading is not paused or frozen kept
refreshBasket(false) same as refreshBasket() kept
refreshBasket(true) governance skipped
refreshBasket(true) anyone else reverts with basket unrefreshable

refreshBasket() keeps its selector and behaves as it did before 4.3.0: it never skips the delay. "Kept" means the full delay runs again from the new basket's timestamp, as every successful refresh resets it.

What changes for governance

Governance is expected to call refreshBasket(true) for basket changes, not refreshBasket(). A proposal built with refreshBasket() still works, but rebalancing waits for tradingDelay. Tooling that builds basket-change proposals needs to switch to refreshBasket(true) when RTokens upgrade to 4.3.0.

The NatSpec on refreshBasket(), docs/deployment-variables.md, and CHANGELOG.md say this, and the sample governance proposal in tasks/validation/test-proposal.ts calls refreshBasket(true). docs/reweightable-rtokens.md now says a basket normalizer proposal must end with refreshBasket(true); the recipe previously left the refresh out.

Changes

  • contracts/p1/BasketHandler.sol, contracts/p0/BasketHandler.sol, contracts/interfaces/IBasketHandler.sol: the new overload. tradingDelayBypassed is set to skipTradingDelay on a successful switch. No storage layout change.
  • Comments on tradingDelay and tradingDelayBypassed, the spell's doc comment, docs/deployment-variables.md, and CHANGELOG.md describe the new rule.
  • test/Recollateralization.test.ts: tests for skipping, for keeping the delay through both refreshBasket() and refreshBasket(false), and for a non-governance caller: passing true, and refreshing a disabled basket while trading is paused or frozen.
  • 185 existing call sites in test/ and tasks/ change from .refreshBasket(). All but three become ['refreshBasket()'](), which is mechanical: ethers v5 only exposes an overloaded function by its full signature. Three become ['refreshBasket(bool)'](true): two in the tests for skipping the delay, and the sample governance proposal.
  • CHANGELOG.md tells ethers clients that load the new ABI to do the same. Existing calldata is unaffected.

BasketHandlerP1 grows from 24,062 to 24,110 bytes (limit 24,576).

Verification

  • test/*.test.ts: 685 passing on P1, 587 passing on P0, before the last two commits. Those add one revenue test (from Do not apply tradingDelay to forwardRevenue() #1319) and the refreshBasket(true) guidance; the trading-delay tests in test/Revenues.test.ts and test/Recollateralization.test.ts were rerun on P0 and P1 after them.
  • Plugin, library, scenario and registry suites: 3155 passing.
  • FORK_NETWORK=mainnet yarn hardhat 4.3.0 at block 26508593 and FORK_NETWORK=base yarn hardhat 4.3.0 at Base block 63086205: eUSD, ETH+, USD3 and bsdETH upgrade and pass the post-upgrade checks.
  • Solhint and ESLint report no errors.
  • Not covered locally: the fork-based integration and plugin suites, which also call refreshBasket(). CI runs them, except the gas-report suites (for example test/integration/CTokenVaultGas.test.ts), which only run with REPORT_GAS set.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Governance can explicitly bypass the trading delay when switching to an enabled basket. Regular refreshes continue to observe the delay, and non-governance callers cannot request a bypass.
  • Documentation
    • Clarified when the delay applies and how governance proposals can request a bypass. Added guidance for clients on selecting between basket-refresh calls with the same name but different parameters.

Governance must now opt in to skipping the trading delay with
refreshBasket(true). refreshBasket() calls refreshBasket(false), so an
unrelated queued proposal that refreshes the basket no longer bypasses
the delay after a default. Only governance can skip the delay.

Tests and tasks call refreshBasket by full signature, which ethers
requires for overloaded functions.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 73a8cb9d-d889-43e3-8373-acdac308948a
Commits

Reviewing files that changed from the base of the PR and between 0e339b6 and 9f1b597.

Files selected for processing: 50

  • CHANGELOG.md
  • contracts/interfaces/IBasketHandler.sol
  • contracts/interfaces/IDeployer.sol
  • contracts/p0/BackingManager.sol
  • contracts/p0/BasketHandler.sol
  • contracts/p1/BackingManager.sol
  • contracts/p1/BasketHandler.sol
  • contracts/spells/4_3_0.sol
  • docs/deployment-variables.md
  • docs/reweightable-rtokens.md
  • tasks/deprecated/deploy.ts
  • tasks/deprecated/p0/deploy_all.ts
  • tasks/validation/test-proposal.ts
  • test/Broker.test.ts
  • test/Facade.test.ts
  • test/FacadeWrite.test.ts
  • test/Main.test.ts
  • test/RToken.test.ts
  • test/RTokenExtremes.test.ts
  • test/Recollateralization.test.ts
  • test/Revenues.test.ts
  • test/ZTradingExtremes.test.ts
  • test/ZZStRSR.test.ts
  • test/fixtures.ts
  • test/integration/AssetPlugins.test.ts
  • test/integration/CTokenVaultGas.test.ts
  • test/integration/EasyAuction.test.ts
  • test/integration/fixtures.ts
  • test/integration/mainnet-test/IssuancePremium.test.ts
  • test/monitor/FacadeMonitor.test.ts
  • test/plugins/Asset.test.ts
  • test/plugins/individual-collateral/collateralTests.ts
  • test/plugins/individual-collateral/curve/collateralTests.ts
  • test/plugins/individual-collateral/curve/cvx/CvxAppreciatingRTokenSelfReferential.test.ts
  • test/plugins/individual-collateral/curve/cvx/CvxStableRTokenMetapoolTestSuite.test.ts
  • test/scenario/BadCollateralPlugin.test.ts
  • test/scenario/BadERC20.test.ts
  • test/scenario/BasketNormalization.test.ts
  • test/scenario/ComplexBasket.test.ts
  • test/scenario/EURT.test.ts
  • test/scenario/LargeDecimals.test.ts
  • test/scenario/MaxBasketSize.test.ts
  • test/scenario/NestedRTokens.test.ts
  • test/scenario/NontrivialPeg.test.ts
  • test/scenario/RevenueHiding.test.ts
  • test/scenario/SetProtocol.test.ts
  • test/scenario/WBTC.test.ts
  • test/scenario/WETH.test.ts
  • test/scenario/cETH.test.ts
  • test/scenario/cWBTC.test.ts

No actionable comments were generated in the recent review.

Walkthrough

refreshBasket() now keeps the trading delay. Governance can call refreshBasket(true) to skip it. The implementations update the bypass state after an enabled basket switch, and callers and tests select overloaded functions by full signature.

Changes: Basket refresh delay bypass

Layer / File(s) Summary
Add refresh overload and bypass state
contracts/interfaces/IBasketHandler.sol, contracts/p0/BasketHandler.sol, contracts/p1/BasketHandler.sol, contracts/p0/BackingManager.sol, contracts/p1/BackingManager.sol, contracts/interfaces/IDeployer.sol
Both BasketHandler implementations add refreshBasket(bool skipTradingDelay). The no-argument overload passes false. Governance can request the bypass. Non-governance callers can refresh only without a bypass and when status and trading conditions permit it. The bypass state updates after an enabled basket switch.
Update proposal, deployment, and delay guidance
tasks/validation/test-proposal.ts, tasks/deprecated/deploy.ts, tasks/deprecated/p0/deploy_all.ts, CHANGELOG.md, contracts/spells/4_3_0.sol, docs/deployment-variables.md, docs/reweightable-rtokens.md
Proposal tooling uses refreshBasket(true) for a 4.3.0 target. Deployment tasks select the no-argument overload by signature. Changelog and documentation describe delay behavior and overload usage.
Update overload callers and verify refresh behavior
test/*.test.ts, test/integration/*, test/monitor/*, test/plugins/*, test/scenario/*
Tests select overloaded refresh functions by full signature. Recollateralization tests cover bypass authorization, delay timing, bypass-state changes, and successful or failed basket switches. Other updated tests retain their existing assertions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Governance
  participant BasketHandler
  participant BackingManager
  Governance->>BasketHandler: Call refreshBasket(true)
  BasketHandler->>BasketHandler: Switch basket and update bypass state
  BackingManager->>BasketHandler: Check bypass state for current basket
Loading

Possibly related PRs

Suggested reviewers: akshatmittal, julianmrodri

Merge Risk: Minimal · previous review 0e339

This change adds a governance-only option to skip the trading delay while keeping the existing refresh behavior. The supplied evidence shows no concrete merge-blocking risk. The author reports that most test suites passed, and the fork-based suites run in CI.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Add refreshBasket(bool skipTradingDelay)" names the main change: a new overload on BasketHandler that lets governance skip the trading delay. The changeset adds this overload in the P0 and …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "Add refreshBasket(bool skipTradingDelay)" names the main change: a new overload on BasketHandler that lets governance skip the trading delay. The changeset adds this overload in the P0 and P1 handlers and the IBasketHandler interface, and updates the tests and docs that use it. The title is specific and short, and it uses the exact identifier from the code. It does not describe the governance access rule or the full set of supporting edits, which is acceptable for a title.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87671d34-a765-4351-956a-45a3dd268e8f
Commits

Reviewing files that changed from the base of the PR and between 9be0801 and 0e339b6.

Files selected for processing: 3

  • contracts/p0/BasketHandler.sol
  • contracts/p1/BasketHandler.sol
  • test/Recollateralization.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

tbrent and others added 6 commits November 30, 2026 18:42
…resh-skip-delay

# Conflicts:
#	docs/deployment-variables.md
…nd frozen

Review feedback:
- the changelog tells ethers clients to call refreshBasket by signature
- the non-governance refresh test now covers a disabled basket while
  trading is paused or frozen
- the docs say a refresh without skipTradingDelay waits the full delay

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
NatSpec, docs, and changelog now say governance basket changes should
call refreshBasket(true). The sample governance proposal does so too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The spell only sets the prime basket; the proposal has to refresh the
basket afterwards. Also reword the sample proposal comment.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@tbrent
tbrent added this pull request to stack #1318 November 30, 2026 19:53
tbrent added a commit that referenced this pull request Nov 30, 2026
…prorata-rounding

Stack on #1320.

- CHANGELOG: keep both sides.
- hardhat.config: drop the BackingManagerP1 compiler override. With the stack it
  is 24,333 bytes at the default 200 optimizer runs. RTokenP1 is unaffected and
  stays at 145 runs (24,572 bytes).
- Tests: call the overloaded refreshBasket() by full signature.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…resh-skip-delay

The only incoming change moves the tradingDelayBypassed switch guard and its
test out of the earlier PRs. This branch keeps both, so its tree is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…resh-skip-delay

The incoming change restores the tradingDelayBypassed switch guard on the
earlier branches. This branch already has it, so its tree is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@tbrent
tbrent merged commit bd01378 into master Dec 1, 2026
17 of 33 checks passed
@tbrent
tbrent deleted the 4.3.0-audit-refresh-skip-delay branch December 1, 2026 17:31
tbrent added a commit that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tbrent added a commit that referenced this pull request Dec 1, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

2 participants