Document doubOwedForBuy mutability and TWAP usage #315

Closed
opened 2026-06-13 07:34:24 +00:00 by PlasticDigits · 12 comments
PlasticDigits commented 2026-06-13 07:34:24 +00:00 (Migrated from gitlab.com)

Parent

Gap analysis follow-up from #309.

Current codebase

  • doubOwedForBuy(uint256 charmWad) external returns (uint256) — not view because _sampleCharmAnchor() may call Kumbaya/TWAP externals (TimeArena.sol L311–318).
  • TimeArenaBuyRouter.buyViaKumbaya uses this for pricing (TimeArenaBuyRouter.sol L101).
  • No dedicated Forge test; integrators may expect eth_call staticcall compatibility.

Why needed

Approved: Check when TWAP is needed and document mutability/view semantics for integrators and indexers.

Constraints / guardrails

  • Prefer view if no state mutation occurs (current code does not write state in preview path).
  • Document hard-reset boundary behavior vs effectiveCharmPriceWad().
  • Update docs/integrations/kumbaya.md and router ABI notes.

Relevant files

  • contracts/src/arena/TimeArena.sol — doubOwedForBuy, _sampleCharmAnchor, _willLastBuyHardReset
  • contracts/src/arena/TimeArenaBuyRouter.sol
  • contracts/test/TimeArenaEpochCharmPrice.t.sol
  • indexer/ decoder if ABI changes
  • frontend/ buy preview callers
  1. Audit call graph: if no state writes, change to view (or add doubOwedForBuyView pure preview).
  2. Document TWAP/spot anchor conditions in PARAMETERS.md and integration docs.
  3. Add Forge test matching doubOwedForBuy output to actual buy cost at boundary epochs.

Acceptance criteria

  • Documented when external calls occur and why.
  • Integrators have a staticcall-safe preview path (view fn or documented workaround).
  • Forge test covers hard-reset boundary pricing.

Test plan

  • cd contracts && forge test --match-contract TimeArenaEpochCharmPrice.
  • bash scripts/verify-time-arena-buy-router-anvil.sh if router ABI changes.

Attack / abuse test plan

  • Preview/manipulation: TWAP anchor cannot be sandwiched to underpay in same block (document assumptions).

Verification criteria

  • NatSpec + PARAMETERS.md explain non-view vs view decision.
  • Test doubOwedForBuy(charm) == actual DOUB pulled on immediate buy.
## Parent Gap analysis follow-up from [#309](https://gitlab.com/PlasticDigits/yieldomega/-/issues/309). ## Current codebase - `doubOwedForBuy(uint256 charmWad) external returns (uint256)` — not `view` because `_sampleCharmAnchor()` may call Kumbaya/TWAP externals (`TimeArena.sol` L311–318). - `TimeArenaBuyRouter.buyViaKumbaya` uses this for pricing (`TimeArenaBuyRouter.sol` L101). - No dedicated Forge test; integrators may expect `eth_call` staticcall compatibility. ## Why needed Approved: Check when TWAP is needed and document mutability/view semantics for integrators and indexers. ## Constraints / guardrails - Prefer `view` if no state mutation occurs (current code does not write state in preview path). - Document hard-reset boundary behavior vs `effectiveCharmPriceWad()`. - Update `docs/integrations/kumbaya.md` and router ABI notes. ## Relevant files - `contracts/src/arena/TimeArena.sol` — `doubOwedForBuy`, `_sampleCharmAnchor`, `_willLastBuyHardReset` - `contracts/src/arena/TimeArenaBuyRouter.sol` - `contracts/test/TimeArenaEpochCharmPrice.t.sol` - `indexer/` decoder if ABI changes - `frontend/` buy preview callers ## Recommended direction 1. Audit call graph: if no state writes, change to `view` (or add `doubOwedForBuyView` pure preview). 2. Document TWAP/spot anchor conditions in `PARAMETERS.md` and integration docs. 3. Add Forge test matching `doubOwedForBuy` output to actual `buy` cost at boundary epochs. ## Acceptance criteria - [ ] Documented when external calls occur and why. - [ ] Integrators have a staticcall-safe preview path (view fn or documented workaround). - [ ] Forge test covers hard-reset boundary pricing. ## Test plan - `cd contracts && forge test --match-contract TimeArenaEpochCharmPrice`. - `bash scripts/verify-time-arena-buy-router-anvil.sh` if router ABI changes. ## Attack / abuse test plan - Preview/manipulation: TWAP anchor cannot be sandwiched to underpay in same block (document assumptions). ## Verification criteria - NatSpec + `PARAMETERS.md` explain non-view vs view decision. - Test `doubOwedForBuy(charm) ==` actual DOUB pulled on immediate `buy`.
PlasticDigits commented 2026-06-13 07:34:43 +00:00 (Migrated from gitlab.com)

mentioned in issue #309

mentioned in issue #309
PlasticDigits commented 2026-06-13 08:02:56 +00:00 (Migrated from gitlab.com)

mentioned in commit 1e966591d1

mentioned in commit 1e966591d1f0036158c16009907e0984170eae8e
PlasticDigits commented 2026-06-13 08:03:10 +00:00 (Migrated from gitlab.com)

mentioned in merge request !459

mentioned in merge request !459
PlasticDigits commented 2026-06-13 09:27:46 +00:00 (Migrated from gitlab.com)

mentioned in commit 97d56f93ff

mentioned in commit 97d56f93fff397c2eb12f02837c387355afb671d
PlasticDigits commented 2026-06-13 13:29:31 +00:00 (Migrated from gitlab.com)

mentioned in merge request !474

mentioned in merge request !474
PlasticDigits commented 2026-06-13 14:12:28 +00:00 (Migrated from gitlab.com)

mentioned in commit bc74435db9

mentioned in commit bc74435db9558298f2bd32140f3ed74867a9dcc5
PlasticDigits commented 2026-06-13 14:12:32 +00:00 (Migrated from gitlab.com)

mentioned in merge request !466

mentioned in merge request !466
PlasticDigits commented 2026-06-13 14:14:42 +00:00 (Migrated from gitlab.com)

mentioned in commit 1a4c39440b

mentioned in commit 1a4c39440bea263030dec905967bbabf7b5c2e0f
PlasticDigits commented 2026-06-14 02:36:20 +00:00 (Migrated from gitlab.com)

mentioned in commit 2f53f814df

mentioned in commit 2f53f814df33dbb4070575ad56833f8e119eb6fd
PlasticDigits (Migrated from gitlab.com) closed this issue 2026-06-14 02:36:20 +00:00
PlasticDigits commented 2026-06-14 22:08:38 +00:00 (Migrated from gitlab.com)

mentioned in issue #325

mentioned in issue #325
PlasticDigits commented 2026-06-21 03:43:53 +00:00 (Migrated from gitlab.com)

mentioned in issue #341

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

mentioned in merge request !523

mentioned in merge request !523
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#315
No description provided.