Skip to content

feat(contracts): TWAP-based MAX_APPEAL_RESTITUTION for SafetyReserve #687

Closed

Description

@thiras

Context

PR #684 implemented SafetyReserve.payout with MAX_APPEAL_RESTITUTION as a governance-set USDC ceiling. ADR 028 § Contract surface calls for a TWAP-from-pool oracle derivation so the cap tracks the live TOKEN/USDC price rather than requiring a governance vote each time the market moves.

Scope

  • Wire a TWAP oracle (Balancer V3 pool from ADR 018, or Chainlink if the pool oracle is unreliable on Arbitrum Sepolia) into SafetyReserve.
  • Derive MAX_APPEAL_RESTITUTION from TWAP_window × TWAP_max_TOKEN_equiv rather than a flat USDC value.
  • Add fallback: if oracle stale beyond a governance-set max age, fall back to last-good cap (do not brick payout).
  • Update tests covering ratification with oracle-driven cap, oracle-stale fallback, and governance retune of the TOKEN-equivalent input.

References

Activity

  1. added
    design:economics
    on May 28, 2026
  2. added
    kind:feature
    kind:test
    on May 28, 2026
  3. github-actions commented on May 28, 2026

    @github-actions

    🎯 Triage report

    This is a well-scoped follow-up to PR #684, requesting that SafetyReserve.MAX_APPEAL_RESTITUTION be derived from a TWAP oracle (Balancer V3 or Chainlink fallback) rather than a flat governance-set USDC value. The work is explicitly called out in ADR 028 as a deferred follow-up and is production-blocking. Scope is clearly bounded to SafetyReserve.sol + tests.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature New on-chain capability (oracle integration), not a bug fix
    Labels enhancement, prod-blocking, testing Matches ADR-required production shape; existing economics+technical labels retained; test coverage update is explicit in scope
    Coding agent Suitable Requirements are explicit (oracle source, fallback behaviour, governance params, test cases), success criteria are enumerated, scope is limited to one contract + tests

    🔗 Similar issues

    No duplicates found. Issue #591 (single USDC token decision) is related context — confirms that the oracle must price TOKEN→USDC, not introduce a new payment token.

    💡 Notes and suggestions

    Oracle source decision needed first:
    ADR 018 specifies a Balancer V3 pool. On Arbitrum Sepolia that pool may have insufficient liquidity/history to produce a reliable TWAP. Confirm whether the pool TWAP is available; if not, Chainlink TOKEN/USD + USDC/USD feeds are the safe fallback. This decision should be recorded in ADR 028 before implementation starts.

    ADR 028 status note:
    ADR 028 was unlocked from "Locked-for-implementation" back to "Draft" (per CLAUDE.md history). This change will need an ADR 028 update to re-approve once the oracle source is selected.

    Implementation checklist:

    • Confirm oracle availability on Arbitrum Sepolia (Balancer V3 pool TWAP vs Chainlink)
    • Add ITwapOracle interface + oracleMaxAge governance param to SafetyReserve
    • Replace flat MAX_APPEAL_RESTITUTION storage with derived computation: TWAP_window × TWAP_max_TOKEN_equiv
    • Store lastGoodCap for stale-oracle fallback; do not revert payout on stale oracle
    • Emit event on stale-oracle fallback for monitoring
    • Tests: oracle-driven cap, stale fallback, governance retune of TOKEN-equiv input
    • Update ADR 028 with oracle source decision and re-approve

    Solidity CI gotchas to watch:

    • nonReentrant + always-reverting paths → W5740 under FOUNDRY_PROFILE=ci --deny warnings (see CLAUDE.md)
    • Any new bytes32 casts or unchecked ERC20 calls → covered by global forge-lint exclusions in foundry.toml, no per-line suppression needed
    • Run FOUNDRY_PROFILE=ci forge build --sizes --deny warnings locally before pushing

    Generated by Agentic Triage for issue #687 · ● 2.3M · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. alpergundogdu commented on May 29, 2026

    @alpergundogdu
    Contributor

    Recommend closing as not-planned — obsoleted by the SafetyReserve removal (#708, ADR 033 retired).

    This issue asked to derive MAX_APPEAL_RESTITUTION from a TWAP oracle. Under escrow-on-slash there is no restitution cap and no TOKEN→USDC conversion to price: a granted appeal refunds the operator's own escrowed TOKEN from CapacityBond, so there is nothing to cap. ADR 028 § Contract surface is explicit — "No MAX_APPEAL_RESTITUTION cap exists ... no TWAP/USDC conversion" — and SlashAppeal never moves USDC.

    No follow-up work remains here unless a TOKEN-side cap is wanted somewhere (none is specified today).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    design:economicskind:featurekind:test

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions