feat(contracts): IStrategy interface (#20)#143
Merged
Conversation
packages/contracts/src/interfaces/IStrategy.sol — pluggable rebalance shape API. Strategies decide tick-range positions and rebalance timing; vault remains the trust boundary. Surface matches PRD §Day 3: TargetPosition struct + computePositions + shouldRebalance. NatSpec captures the ADR-005 purity contract: deterministic, stateless, vault-agnostic; block.timestamp permitted only inside shouldRebalance for the 24h liveness fallback; runtime SSTORE forbidden (CI bytecode scan). The vault re-checks Σ weight == 10_000 (#2) and length <= MAX_POSITIONS (#3) after every call, so the interface itself doesn't need to police malformed strategies — the vault reverts via Errors.WeightsDoNotSum or Errors.MaxPositionsExceeded. Tests: 2 selectors snapshotted, mock returns a full-range single position to exercise the round-trip, fuzz over inputs verifies the weight-sum invariant on the mock. 4/4 pass. forge build clean, forge fmt --check clean. Closes #20. Blocks #32, #33, #39.
Closed
10 tasks
* feat(contracts): centralised custom error library (#17) Adds packages/contracts/src/utils/Errors.sol — every PRISM contract reverts through a 4-byte selector (~200 gas) instead of a string (2,000+ gas). Errors are grouped by domain (access control, vault, strategy, hook, oracle, callback, generic) with NatSpec describing the call site of each. Coverage matches PRD §Day 1 plus the three errors introduced by ADR-004 (UnknownOp, DeltaUnsettled, Reentrancy) and the bound/value helpers (MathOverflow, ValueOutOfBounds) used by FeeLib (#23) and PositionLib (#22). Tests in test/utils/Errors.t.sol snapshot every selector against its canonical signature — 21 selectors plus 4 round-trip reverts. Selector stability is a downstream-consumer contract; bumping a signature is a breaking change and the test will catch it. forge build clean, forge test 27/27 pass, forge fmt --check clean. Closes #17. Blocks #26, #27, #28, #29, #32, #34, #35, #36, #37. * feat(contracts): BellStrategy.computePositions — bell-curve weights (#32) Default PRISM strategy. Returns 7 positions arranged as a symmetric bell around the current tick, with hardcoded weights [500, 1200, 2100, 2400, 2100, 1200, 500] bps (Σ = 10_000). Per ADR-005 the strategy is pure / stateless / vault-agnostic: - No SSTORE in runtime bytecode (constants only — W0..W6 are inline compile-time literals; CI bytecode scan in #61 verifies this) - Deterministic across repeat calls with identical inputs - amounts0/amounts1 are opaque to the strategy (vault-agnosticism) Tick alignment: currentTick is floored to the nearest tickSpacing boundary (negative-tick aware). The 7 positions tile contiguously across [anchor - 3*ts, anchor + 4*ts] with each position spanning exactly one tickSpacing. shouldRebalance returns false on this PR — #33 implements the actual gate (drift + time + 24h fallback). 16 tests: - 7 unit tests for shape, symmetry, sum, alignment, contiguity, width, anchor centering - 2 revert tests for zero / negative spacing - 3 fuzz tests for determinism, weight invariant, vault-agnosticism - 4 supporting tests for constants and ctor Stacked on contracts/20-istrategy with cherry-picked Errors (#17). Closes #32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/contracts/src/interfaces/IStrategy.sol— pluggable rebalance-shape API. Resolves #20.TargetPositionstruct +computePositions+shouldRebalance).block.timestampallowed only insideshouldRebalance; runtime SSTORE forbidden.MAX_POSITIONSafter every call.Quality gates
forge buildcleanforge test4/4 pass on this file (selector snapshots + mock round-trip + weight-sum fuzz)forge fmt --checkcleanTest plan
block.timestampcarve-out wording inshouldRebalanceis unambiguousCloses #20. Blocks #32, #33, #39.