TimeArena Last Buy hard reset with TWAP on chain 4326 #352

Closed
opened 2026-06-25 20:07:32 +00:00 by PlasticDigits · 5 comments
PlasticDigits commented 2026-06-25 20:07:32 +00:00 (Migrated from gitlab.com)

Parent

Transition Gap Analysis (#342) — P2 #12. Bundles H-C2.

Current codebase

  • TimeArena._sampleCharmAnchor() branches on block.chainid == 4326 → ArenaCharmPriceTwap.compute (MegaETH mainnet); Anvil tests use spot oracle path.
  • ArenaCharmPriceTwap.t.sol tests TWAP in isolation; optional fork smoke in ArenaCharmPriceTwapFork.t.sol.
  • No TimeArena.buy hard-reset test on chain 4326 asserting lastBuyEpoch, anchor, and doubOwedForBuy.

Why needed

DOUB owed at epoch boundary could diverge between test and production TWAP path — transition correctness risk at Last Buy epoch rolls.

Constraints / guardrails

  • Prefer vm.chainId(4326) with mocked TWAP or controlled fork — avoid flaky mainnet dependency in default CI.
  • Skip or gate fork test if RPC unavailable (match existing fork patterns).
  • Do not change production TWAP config without audit note.

Relevant files

  • contracts/src/arena/TimeArena.sol (_sampleCharmAnchor)
  • contracts/src/oracle/ArenaCharmPriceTwap.sol
  • contracts/test/ArenaCharmPriceTwap.t.sol
  • contracts/test/TimeArena.t.sol
  1. Add test setting vm.chainId(4326) and mock TWAP return (or use test harness implementing same interface).
  2. Trigger Last Buy hard reset via buy; assert epoch bump, epochCharmAnchorWad, and doubOwedForBuy match TWAP-derived expectations.
  3. Document in time-arena.md test coverage cross-link.

Acceptance criteria

  • New Forge test passes on Anvil default chain id setup with vm.chainId(4326).
  • Asserts transition fields after hard reset.
  • forge test clean excluding optional fork/airdrop skips.

Test plan

Path Command
Targeted cd contracts && forge test --match-test Twap (or chosen name)
Full cd contracts && forge test

Attack / abuse test plan

  • TWAP manipulation scenarios belong in ArenaCharmPriceTwap tests; this test asserts TimeArena consumes TWAP output correctly at epoch boundary.

Verification criteria

  • Test PASS locally and in CI contract job.
  • Clear comment linking chain 4326 to MegaETH production.
## Parent [Transition Gap Analysis (#342)](https://gitlab.com/PlasticDigits/yieldomega/-/issues/342) — P2 #12. Bundles **H-C2**. ## Current codebase - `TimeArena._sampleCharmAnchor()` branches on `block.chainid == 4326` → `ArenaCharmPriceTwap.compute` (MegaETH mainnet); Anvil tests use spot oracle path. - `ArenaCharmPriceTwap.t.sol` tests TWAP in isolation; optional fork smoke in `ArenaCharmPriceTwapFork.t.sol`. - No `TimeArena.buy` hard-reset test on chain 4326 asserting `lastBuyEpoch`, anchor, and `doubOwedForBuy`. ## Why needed DOUB owed at epoch boundary could diverge between test and production TWAP path — transition correctness risk at Last Buy epoch rolls. ## Constraints / guardrails - Prefer `vm.chainId(4326)` with mocked TWAP or controlled fork — avoid flaky mainnet dependency in default CI. - Skip or gate fork test if RPC unavailable (match existing fork patterns). - Do not change production TWAP config without audit note. ## Relevant files - `contracts/src/arena/TimeArena.sol` (`_sampleCharmAnchor`) - `contracts/src/oracle/ArenaCharmPriceTwap.sol` - `contracts/test/ArenaCharmPriceTwap.t.sol` - `contracts/test/TimeArena.t.sol` ## Recommended direction 1. Add test setting `vm.chainId(4326)` and mock TWAP return (or use test harness implementing same interface). 2. Trigger Last Buy hard reset via buy; assert epoch bump, `epochCharmAnchorWad`, and `doubOwedForBuy` match TWAP-derived expectations. 3. Document in `time-arena.md` test coverage cross-link. ## Acceptance criteria - [ ] New Forge test passes on Anvil default chain id setup with `vm.chainId(4326)`. - [ ] Asserts transition fields after hard reset. - [ ] `forge test` clean excluding optional fork/airdrop skips. ## Test plan | Path | Command | |------|---------| | Targeted | `cd contracts && forge test --match-test Twap` (or chosen name) | | Full | `cd contracts && forge test` | ## Attack / abuse test plan - TWAP manipulation scenarios belong in `ArenaCharmPriceTwap` tests; this test asserts TimeArena consumes TWAP output correctly at epoch boundary. ## Verification criteria - Test PASS locally and in CI contract job. - Clear comment linking chain 4326 to MegaETH production.
PlasticDigits commented 2026-06-25 20:07:50 +00:00 (Migrated from gitlab.com)

mentioned in issue #342

mentioned in issue #342
PlasticDigits commented 2026-06-25 22:38:18 +00:00 (Migrated from gitlab.com)

mentioned in merge request !523

mentioned in merge request !523
PlasticDigits commented 2026-06-26 03:37:44 +00:00 (Migrated from gitlab.com)

mentioned in commit 87b4f06ce1

mentioned in commit 87b4f06ce127da9023939ceb4fcb43b6ba48a960
PlasticDigits commented 2026-06-26 08:10:35 +00:00 (Migrated from gitlab.com)

Verification — issue #352 (PASS)

Verified TimeArena Last Buy hard reset with TWAP on chain 4326 on main (no repo changes required).

Acceptance criteria

Item Result How verified
New Forge test passes on Anvil default setup with vm.chainId(4326) PASS cd contracts && forge test --match-contract TimeArenaTwapHardReset4326 → test_chain4326_last_buy_hard_reset_twap_reanchor PASS
Asserts transition fields after hard reset (lastBuyEpoch, epochCharmAnchorWad, doubOwedForBuy, buy DOUB) PASS Test asserts epoch bump, TWAP anchor, doubOwedForBuy preview, and paid DOUB at hard-reset boundary (contracts/test/TimeArenaTwapHardReset4326.t.sol)
forge test clean excluding optional fork/airdrop skips PASS Full forge test: 227 passed; 4 failures only in DoubAirdropMegaethFork.t.sol (missing gitignored airdrop/doub.csv — expected local skip per AGENTS.md). TWAP suites all PASS: ArenaCharmPriceTwap (4), ArenaCharmPriceTwapFork (1), TimeArenaTwapHardReset4326 (1)
Clear comment linking chain 4326 → MegaETH production PASS Contract/test NatSpec: "MegaETH (4326)" / "MegaETH chain id uses ArenaCharmPriceTwap"; production branch in TimeArena._sampleCharmAnchor() at block.chainid == 4326
Docs / invariants cross-link PASS docs/product/time-arena.md, docs/testing/invariants-and-business-logic.md (INV-TIME-ARENA-EPOCH-CHARM-TWAP-4326, INV-TIME-ARENA-DOUB-OWED-PREVIEW), skills/play-time-arena-doub/SKILL.md

Implementation notes (already on main)

  • TimeArenaTwapHardReset4326.t.sol mocks Kumbaya V3 pools via vm.chainId(4326) + vm.etch — no flaky mainnet RPC in default CI.
  • TWAP manipulation scenarios remain in ArenaCharmPriceTwap.t.sol; this test covers TimeArena consumption at epoch boundary.

Closing as verified.

## Verification — issue #352 (PASS) Verified **TimeArena Last Buy hard reset with TWAP on chain 4326** on `main` (no repo changes required). ### Acceptance criteria | Item | Result | How verified | |------|--------|--------------| | New Forge test passes on Anvil default setup with `vm.chainId(4326)` | **PASS** | `cd contracts && forge test --match-contract TimeArenaTwapHardReset4326` → `test_chain4326_last_buy_hard_reset_twap_reanchor` PASS | | Asserts transition fields after hard reset (`lastBuyEpoch`, `epochCharmAnchorWad`, `doubOwedForBuy`, buy DOUB) | **PASS** | Test asserts epoch bump, TWAP anchor, `doubOwedForBuy` preview, and paid DOUB at hard-reset boundary (`contracts/test/TimeArenaTwapHardReset4326.t.sol`) | | `forge test` clean excluding optional fork/airdrop skips | **PASS** | Full `forge test`: 227 passed; 4 failures only in `DoubAirdropMegaethFork.t.sol` (missing gitignored `airdrop/doub.csv` — expected local skip per AGENTS.md). TWAP suites all PASS: `ArenaCharmPriceTwap` (4), `ArenaCharmPriceTwapFork` (1), `TimeArenaTwapHardReset4326` (1) | | Clear comment linking chain 4326 → MegaETH production | **PASS** | Contract/test NatSpec: "MegaETH (4326)" / "MegaETH chain id uses `ArenaCharmPriceTwap`"; production branch in `TimeArena._sampleCharmAnchor()` at `block.chainid == 4326` | | Docs / invariants cross-link | **PASS** | `docs/product/time-arena.md`, `docs/testing/invariants-and-business-logic.md` (`INV-TIME-ARENA-EPOCH-CHARM-TWAP-4326`, `INV-TIME-ARENA-DOUB-OWED-PREVIEW`), `skills/play-time-arena-doub/SKILL.md` | ### Implementation notes (already on main) - `TimeArenaTwapHardReset4326.t.sol` mocks Kumbaya V3 pools via `vm.chainId(4326)` + `vm.etch` — no flaky mainnet RPC in default CI. - TWAP manipulation scenarios remain in `ArenaCharmPriceTwap.t.sol`; this test covers TimeArena consumption at epoch boundary. Closing as verified.
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-06-26 08:10:36 +00:00
PlasticDigits commented 2026-07-07 12:54:37 +00:00 (Migrated from gitlab.com)

mentioned in issue #367

mentioned in issue #367
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/yieldomega#352
No description provided.