Commit graph

695 commits

Author SHA1 Message Date
openhands
5d204e5649 fix: Push3 optimizer: dyadic rational input interface (8 slots) + 4-output redesign (#548)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 15:23:36 +00:00
johba
c3792b2a63 Merge pull request 'fix: Replace anchor-midpoint VWAP with pool.observe() TWAP oracle (#575)' (#576) from fix/issue-575 into master 2026-03-11 12:00:06 +01:00
johba
4be783438f Merge pull request 'fix: fix: strip cast formatted annotations from red-team.sh (#577)' (#578) from fix/issue-577 into master 2026-03-11 11:55:34 +01:00
openhands
58729b98b4 fix: fix: strip cast formatted annotations from red-team.sh (#577)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 10:19:14 +00:00
openhands
f72f99aefa fix: Address review findings from PR #575
- Fix unsafe int32 intermediate cast: int56(int32(elapsed)) → int56(uint56(elapsed))
  to prevent TWAP tick sign inversion for intervals above int32 max (~68 years)
- Remove redundant lastRecenterTimestamp state variable; capture prevTimestamp
  from existing lastRecenterTime instead (saves ~20k gas per recenter)
- Use pool.increaseObservationCardinalityNext(ORACLE_CARDINALITY) in constructor
  instead of recomputing the pool address; extract magic 100 to named constant
- Add TWAPFallback(uint32 elapsed) event emitted when pool.observe() reverts
  so monitoring can distinguish degraded operation from normal bootstrap
- Remove conditional bypass paths in test_twapReflectsAveragePriceNotJustLastSwap;
  assert vwapAfter > 0 and vwapAfter > initialPriceX96 unconditionally

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 10:02:47 +00:00
openhands
83e43386bc ci: retrigger after infra failure 2026-03-11 08:30:27 +00:00
openhands
53c14745cb fix: Replace anchor-midpoint VWAP with pool.observe() TWAP oracle (#575)
- Add lastRecenterTimestamp to track recenter interval for TWAP
- Increase pool observation cardinality to 100 in constructor
- In _scrapePositions, use pool.observe([elapsed, 0]) to get TWAP tick
  over the full interval between recenters; falls back to anchor midpoint
  when elapsed==0 or pool.observe() reverts (insufficient history)
- Add test_twapReflectsAveragePriceNotJustLastSwap: verifies TWAP-based
  VWAP reflects the average price across the recenter interval, not just
  the last-swap anchor snapshot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 08:17:49 +00:00
johba
8c0683cbba Merge pull request 'fix: Red-team: replace ethPerToken with exact total-LM-ETH metric (#539)' (#540) from fix/issue-539 into master 2026-03-11 08:33:25 +01:00
johba
f70a7e71a2 Merge pull request 'fix: Investigate: VWAP not preventing IL crystallization during buy-only recenter cycles (#543)' (#566) from fix/issue-543 into master 2026-03-11 07:50:03 +01:00
openhands
4567ca1b6e ci: retrigger after infra failure 2026-03-11 06:28:02 +00:00
openhands
0834433db1 Fix PR #540 review findings
Critical fixes:
- LmTotalEth.s.sol: Fix imports to use @aperture/uni-v3-lib/ (lines 8-9)
- red-team.sh: Update memory regex to match lm.?eth pattern (line 266)

Additional improvements:
- red-team.sh: Update adversary balance claim to ~9000 ETH (after funding LM)
- red-team.sh: Add --no-color to forge invocation + emptiness guard
- red-team.sh: Document feeDestination storage slot 7 fragility

Tested:
- Regex pattern matches all expected formats (lm_eth, lmeth, LM-ETH, etc.)
- Import paths align with remappings.txt
2026-03-11 06:28:02 +00:00
openhands
0ddc1ccd80 fix: Red-team: replace ethPerToken with exact total-LM-ETH metric (#539)
Replace the ethPerToken metric (free balance / adjusted supply) with total
LM ETH (free + WETH + position-locked) using a forge script with exact
Uni V3 integer math. Collapses 4+ RPC calls and Python float approximation
into a single forge script call using LiquidityAmounts + TickMath.

Also updates red-team prompt, report format, memory extraction, and adds
roadmap items for #536-#538 (backtesting pipeline, Push3 evolution).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 06:28:02 +00:00
openhands
6b77a493a2 fix: address review feedback — update stale comments and tighten test guard (#543)
- _scrapePositions natspec: 'ETH inflow' → 'ETH outflow / price fell or at bootstrap'
- Inline comment above VWAP block: remove inverted 'KRK sold out / ETH inflow' rationale,
  replace with a neutral forward-reference to recenter() where the direction logic lives
- VWAPFloorProtection.t.sol: remove unused Kraiken and forge-std/Test.sol imports
  (both are already provided by UniSwapHelper)
- test_floorConservativeAfterBuyOnlyAttack: add assertFalse(token0isWeth) guard so a
  future change to the setUp parameter cannot silently invert the gap-direction assertion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 04:11:02 +00:00
openhands
e35a805138 fix: Investigate: VWAP not preventing IL crystallization during buy-only recenter cycles (#543)
Investigation findings:
- VWAP WAS being fed during buy-only cycles (shouldRecordVWAP = true on ETH inflow / price rising).
  Over 80 buy-recenter cycles VWAP converged toward the inflated current price.
- When VWAP ≈ currentTick, mirrorTick = currentTick + vwapDistance ≈ currentTick, placing
  the floor near the inflated price.  Adversary sells back through the high floor, extracting
  nearly all LM ETH.
- Optimizer parameters (anchorShare, CI) were not the primary cause.

Fix (LiquidityManager.sol):
  Flip shouldRecordVWAP from buy direction to sell direction.  VWAP is now recorded only when
  price falls (ETH outflow / sell events) or at initial bootstrap (cumulativeVolume == 0).
  Buy-only attack cycles leave VWAP frozen at the historical baseline, keeping mirrorTick and
  the floor conservatively anchored far from the inflated current price.

Also updated onchain/AGENTS.md to document the corrected recording direction.

Regression test (VWAPFloorProtection.t.sol):
  - test_vwapNotInflatedByBuyOnlyAttack: asserts getVWAP() stays at bootstrap after N buy cycles.
  - test_floorConservativeAfterBuyOnlyAttack: asserts floor center is far below inflated tick.
  - test_vwapBootstrapsOnFirstFeeEvent: confirms bootstrap path unchanged.
  - test_recenterSucceedsOnSellDirectionWithoutReverts: confirms sell-direction recenters work.

All 187 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 03:31:45 +00:00
openhands
9832b454df fix: PR #551 review findings - OptimizerV3Push3.sol + Optimizer.sol
Critical bugs fixed:
- OptimizerV3Push3: Add input validation for mantissa (inputs[0].mantissa <= 1e18)
- OptimizerInput struct: Move to shared IOptimizer.sol to eliminate duplication
- Update imports in Optimizer.sol, OptimizerV3Push3.sol, and test file

Warnings addressed:
- Document unused variables (_d2-_d7) with comments in OptimizerV3Push3
- Add shift validation: require(inputs[k].shift == 0, "shift not yet supported")
- Fix recordRecenter error style: use UnauthorizedAccount custom error

Tests: All 32 Optimizer + OptimizerV3Push3 tests passing
2026-03-10 23:13:57 +00:00
johba
08b9a3df30 Merge pull request 'fix: Unified Push3 → deploy pipeline: transpile, compile, upgrade in one command (#538)' (#547) from fix/issue-538 into master 2026-03-10 21:43:24 +01:00
openhands
3244c0a975 fix: Unified Push3 → deploy pipeline: transpile, compile, upgrade in one command (#538)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 20:21:54 +00:00
johba
d0f543e846 Merge pull request 'fix: LM: accrue fees as liquidity when feeDestination is self (#533)' (#534) from fix/issue-533 into master 2026-03-10 11:37:24 +01:00
openhands
2c21462e1e fix: LM: accrue fees as liquidity when feeDestination is self (#533)
When feeDestination == address(this), _scrapePositions() now skips the
fee safeTransfer calls so collected WETH/KRK stays in the LM balance
and is redeployed as liquidity on the next _setPositions() call.

Also fixes _getOutstandingSupply(): kraiken.outstandingSupply() already
subtracts balanceOf(liquidityManager), so when feeDestination IS the LM
the old code double-subtracted LM-held KRK, causing an arithmetic
underflow once positions were scraped.  The subtraction is now skipped
for the self-referencing case.

VWAP recording is refactored to a single unconditional block so it fires
regardless of fee destination.

New test testSelfFeeDestination_FeesAccrueAsLiquidity() demonstrates
that a two-recenter cycle with self-feeDestination completes without
underflow and without leaking WETH to any external address.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 10:11:41 +00:00
johba
13d40222b6 Merge pull request 'fix: Red-team memory: persistent cross-run learning for adversarial agent (#528)' (#529) from fix/issue-528 into master 2026-03-09 11:33:52 +01:00
openhands
816b211c2b fix: address review findings in red-team memory (#528)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 10:00:56 +00:00
openhands
c1db4cb93e fix: Red-team memory: persistent cross-run learning for adversarial agent (#528)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 09:23:37 +00:00
johba
28568dbcfd Merge pull request 'fix: feat: Red-team agent runner — adversarial floor attack (#520)' (#527) from fix/issue-520 into master 2026-03-09 05:23:46 +01:00
openhands
ea53e4cfce fix: address review findings in red-team.sh (#520)
- Move snapshot to after setRecenterAccess so agent reverts restore
  recenterAccess for account 2 on every retry
- Read feeDestination() dynamically from LM (removes hardcoded constant)
  and add || die guards on impersonation calls
- Add EXIT/INT/TERM cleanup trap that reverts to the baseline snapshot
- Fix agent floor-check snippet: add FEE_DEST/FEE_BAL reads so formula
  matches compute_eth_per_token (adj=s-f-k, not adj=s-k)
- Use `timeout "$CLAUDE_TIMEOUT"` to enforce wall-clock process limit
- Correct taxRateIndex range: 0-29 (30-element TAX_RATES array)
- Fix outstandingSupply() description: excludes LM-held KRK, not all KRK

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 03:59:12 +00:00
openhands
23d460542b fix: feat: Red-team agent runner — adversarial floor attack (#520)
Adds scripts/harb-evaluator/red-team.sh which:
- Verifies the Anvil stack is running and deployments exist
- Grants recenterAccess to account 2 (impersonating feeDestination)
- Takes an Anvil snapshot as the clean baseline
- Computes ethPerToken before the agent run (mirrors floor.ts logic)
- Builds a self-contained prompt with contract addresses, account keys,
  protocol mechanics, copy-paste cast command patterns, snapshot/revert
  instructions, and structured rules for the agent
- Spawns `claude -p --dangerously-skip-permissions` with a 2-hour timeout
- Captures output to tmp/red-team-report.txt
- Computes ethPerToken after the agent run and reports pass/fail

Exit code 0 = floor held, exit code 1 = floor broken, exit code 2 = infra error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 03:28:10 +00:00
johba
e168b2cc4e Merge pull request 'fix: feat: RPC-only staking helpers for red-team agent (#518)' (#523) from fix/issue-518 into master 2026-03-09 04:12:55 +01:00
openhands
722ecaaa0e fix: address review findings in stake-rpc.ts (#518)
- Remove dead krkAddress field from UnstakeRpcConfig (bug)
- Drop swap.js import to avoid transitive Playwright dependency; fix
  header comment to accurately describe the module boundary (warning)
- Inline pollReceipt() returning TxReceipt so snatch receipt is reused
  for log parsing without a second round-trip (warning)
- Use ZeroAddress from ethers instead of manual constant (info)
- Add comment on fromBlock '0x0' genesis-scan caveat (info)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 02:48:51 +00:00
openhands
1af022624f ci: retrigger after infra failure 2026-03-09 02:17:50 +00:00
openhands
fd44fa0bcf fix: feat: RPC-only staking helpers for red-team agent (#518)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 02:06:41 +00:00
johba
3083e24eab Merge pull request 'fix: feat: Anvil snapshot/revert and ethPerToken helpers (#519)' (#521) from fix/issue-519 into master 2026-03-09 02:53:04 +01:00
openhands
e01ef23560 fix: feat: Anvil snapshot/revert and ethPerToken helpers (#519)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 01:23:36 +00:00
openhands
866474510b fix: feat: Anvil snapshot/revert and ethPerToken helpers (#519)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 00:53:17 +00:00
openhands
b2db3c7ae5 fix: feat: Anvil snapshot/revert and ethPerToken helpers (#519)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 00:12:49 +00:00
johba
83e9a52b5b Merge pull request 'fix: Issue #447 remains unresolved: no caching path exists for POST GraphQL requests (#478)' (#516) from fix/issue-478 into master 2026-03-06 21:14:17 +01:00
openhands
694a68ad27 fix: Issue #447 remains unresolved: no caching path exists for POST GraphQL requests (#478)
Address AI review findings:

- Bug: restore 30 s periodic eviction via setInterval so queries that
  are never repeated don't accumulate forever (add setInterval/
  clearInterval to ESLint globals to allow it)
- Bug: fix .finally() race – use identity check before deleting the
  in-flight key so a waiting request's replacement promise is never
  evicted by the original promise's cleanup handler
- Warning: replace `new URL(c.req.url).search` with a string-split
  approach that cannot throw on relative URLs
- Warning: add MAX_CACHE_ENTRIES (500) cap with LRU-oldest eviction to
  bound memory growth from callers with many unique variable sets
- Warning: prefix cache key with c.req.path so /graphql and / can
  never produce cross-route cache collisions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 19:49:13 +00:00
openhands
ad19d8fc00 fix: Issue #447 remains unresolved: no caching path exists for POST GraphQL requests (#478)
Replace setInterval-based eviction with lazy eviction to avoid the
no-undef ESLint error (setInterval is not in the allowed globals list).
Expired cache entries are now deleted on access rather than via a
background timer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 19:11:21 +00:00
openhands
032222fac9 fix: Issue #447 remains unresolved: no caching path exists for POST GraphQL requests (#478)
Add server-side response cache + in-flight coalescing to Ponder's Hono
API layer (services/ponder/src/api/index.ts).

Previously every polling client generated an independent DB query, giving
O(users × 1/poll_interval) load. With a 5 s in-process cache keyed on the
raw request body (POST) or query string (GET), the effective DB hit rate
is capped at O(1/5s) regardless of how many clients are polling.

In-flight coalescing ensures that N concurrent identical queries that
arrive before the first response is ready all share a single DB hit
instead of each issuing their own. Expired entries are evicted every 30 s
to keep memory use bounded.

The 5 s TTL deliberately matches the existing Caddy `Cache-Control:
public, max-age=5` header so that if a caching proxy/CDN is layered in
front later, both layers stay in sync.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 18:56:48 +00:00
johba
b97ab18514 Merge pull request 'fix: unstakePosition() has no error handling at all (#482)' (#514) from fix/issue-482 into master 2026-03-06 19:45:01 +01:00
openhands
98dd839bb5 fix: unstakePosition() has no error handling at all (#482)
Address AI reviewer warnings:
- Add separate unstakeError ref so unstake failures are not displayed
  via the load-data error UI whose Retry calls loadActivePositionData
- Add exitSucceeded flag to distinguish pre-exit failures ("Failed to
  unstake position.") from post-exit data-refresh failures ("Position
  unstaked, but failed to refresh data."), preventing factually wrong
  messages after a successful transaction
- Unstake error UI has no Retry button; the Unstake button in actions
  remains available for retrying a failed transaction

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 18:15:30 +00:00
openhands
037de2d1fd ci: retrigger after infra failure 2026-03-06 17:44:30 +00:00
openhands
a8defd10b4 fix: unstakePosition() has no error handling at all (#482)
Wrap the entire unstakePosition() body in try/catch/finally so that
errors from exitPosition(), loadActivePositions(), and loadPositions()
are caught, displayed to the user via the existing error ref, and
loading state is always reset correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 17:32:02 +00:00
johba
c45a898e90 Merge pull request 'fix: Stale values shown during retry after prior successful load (#489)' (#510) from fix/issue-489 into master 2026-03-06 18:25:55 +01:00
openhands
4eea19bf53 fix: Stale values shown during retry after prior successful load (#489) 2026-03-06 16:51:22 +00:00
johba
70f3336024 Merge pull request 'fix: networkidle still used in stake.ts login flow (#501)' (#508) from fix/issue-501 into master 2026-03-06 17:46:13 +01:00
openhands
962b126e8b fix: networkidle still used in stake.ts login flow (#501)
Replace waitForLoadState('networkidle') in the post-login redirect with
waitForURL('**/app/stake**'). Persistent WebSocket connections prevent
networkidle from ever firing, mirroring the same fix applied to navigate.ts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 16:11:24 +00:00
johba
1302feef82 Merge pull request 'fix: P&L percentage line understates tax cost when taxDue > 0 (#504)' (#505) from fix/issue-504 into master 2026-03-06 17:02:17 +01:00
openhands
e4ed1474e1 fix: P&L percentage line understates tax cost when taxDue > 0 (#504)
Include taxDue in taxCostPercent computation so the Tax% and Net%
shown in the header P&L line are consistent with the Tax Cost card
and Total row, which already use taxDue + taxPaid.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 15:32:21 +00:00
johba
b2756e8c99 Merge pull request 'fix: Misleading 'Tax Paid' label — value includes unpaid tax due (#374)' (#503) from fix/issue-374 into master 2026-03-06 13:14:51 +01:00
openhands
18a2d4138e fix: Misleading 'Tax Paid' label — value includes unpaid tax due (#374)
taxPaidGes = taxDue + taxPaid, so the displayed value includes both
outstanding tax and historically paid tax. Rename the UI label from
'Tax Paid' to 'Tax Cost' to accurately reflect the combined amount.
Update the matching E2E test selector accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 11:51:45 +00:00
johba
98dac2f67e Merge pull request 'fix: wait_healthy does not fail fast when a service exits or crashes during the health-check window (#387)' (#502) from fix/issue-387 into master 2026-03-06 12:44:33 +01:00