Commit graph

245 commits

Author SHA1 Message Date
johba
0eaf91be13 Merge pull request 'Fix #22: Remove 'any' usage and replace shims with proper typed handlers' (#28) from fix-issue-22-remove-any-types into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/28
2025-09-25 18:59:48 +02:00
openhands
aa9ff72ec0 drop lock 2025-09-25 18:57:38 +02:00
openhands
316ea0380f Fix #22: Remove 'any' usage and replace shims with proper typed handlers
- Updated all ponder event handlers to use proper TypeScript types
- Removed all 'any' type annotations from event handlers
- Handlers now properly leverage TypeScript's type inference
- Improved type safety across the ponder indexer

Fixes #22
2025-09-25 18:28:20 +02:00
johba
7da7b12b6b Merge pull request 'feature-podman' (#21) from feature-podman into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/21
2025-09-24 14:14:43 +02:00
root
41700e72da chore: Add dependencies and configs for Podman setup
- Updated kraiken-lib tsconfig and yarn.lock
- Added package.json with playwright-mcp dependency
- Updated uni-v3-lib submodule

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:12:54 +00:00
root
ea27fcb722 feat: Complete Podman stack setup with working services
- Fixed service dependencies (removed bootstrap dependency for runtime services)
- Added landing service for documentation site at root path
- Moved web-app to /app path, landing to / path
- Fixed permission issues with lowercase 'z' SELinux context
- Added kraiken-lib compilation in txn-bot container
- Fixed TypeScript build for kraiken-lib with proper volumes
- Updated entrypoint scripts to handle npm installs properly
- Added locale fixes to Containerfiles
- Changed Caddy port from 80 to 8081 for external access
- Updated Docs link to point to local landing page

All services now working:
- Landing page at /
- Web app at /app/
- GraphQL at /graphql
- Transaction bot at /txn
- Anvil RPC at /rpc/anvil

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 12:12:54 +00:00
johba
18d63e14d7 podman wip 2025-09-24 12:12:54 +00:00
johba
efecc5c348 Merge pull request 'fix web-app' (#19) from fix-web-app2 into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/19
2025-09-24 14:03:51 +02:00
johba
4467d41edf fix web-app 2025-09-24 14:02:28 +02:00
johba
967e9085ac Merge pull request 'fix agent' (#18) from fix-agent into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/18
2025-09-24 10:00:08 +02:00
johba
f3fb0f142a fix agent 2025-09-24 09:57:20 +02:00
johba
cbf5ce0733 Merge pull request 'better backend comms' (#17) from fix-web-app into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/17
2025-09-24 09:42:13 +02:00
johba
02a057622c better backend comms 2025-09-24 09:41:28 +02:00
johba
d0e8623cf9 Merge pull request 'basic cheat view' (#8) from feature/cheats into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/8
2025-09-23 21:17:43 +02:00
johba
3f137a2757 basic cheat view 2025-09-23 21:16:15 +02:00
johba
2be1e9d520 Merge pull request 'move ponder' (#7) from move-ponder into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/7
2025-09-23 20:30:28 +02:00
johba
36b7b429ef move ponder 2025-09-23 20:29:51 +02:00
johba
a9207de195 Merge pull request 'replaced subgraph with ponder' (#6) from feature/ponder into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/6
2025-09-23 19:25:39 +02:00
johba
ba64e725dc replaced subgraph with ponder 2025-09-23 19:24:05 +02:00
johba
5e6e21878c Merge pull request 'more logic to lib' (#5) from feature-lib into master
Reviewed-on: https://codeberg.org/johba/harb/pulls/5
2025-09-23 17:00:18 +02:00
johba
25fc4a4c4d more logic to lib 2025-09-23 16:57:49 +02:00
johba
cf6b9fa381 remove redundant lib 2025-09-23 15:16:15 +02:00
johba
769fa105b8 added web-app and landing 2025-09-23 14:18:04 +02:00
johba
af031877a5 fix position calculation 2025-09-23 11:46:57 +02:00
giteadmin
548fd006c1 added docs 2025-09-23 08:49:28 +02:00
johba
b8dc42201a Update README.md 2025-09-22 15:38:29 +02:00
johba
809834f0f7 Merge branch 'master' of ssh://codeberg.org/johba/harb 2025-09-22 15:12:08 +02:00
johba
a480dc7f47 update readme 2025-09-22 15:11:30 +02:00
traddoo
babe126d25 Update HARBERG.md 2025-09-22 15:11:00 +02:00
traddoo
5816ecd0d7 Add HARBERG.md 2025-09-22 14:48:58 +02:00
traddoo
1c7a8dbbf3 Update README.md 2025-09-22 14:48:03 +02:00
Your Name
0de1cffea8 another fixup of fuzzer 2025-09-16 22:46:43 +02:00
Your Name
c32f1b102b small fixes 2025-08-24 18:38:48 +02:00
johba
137adfe82b another rewrite 2025-08-23 22:32:41 +02:00
johba
c72fe56ad0 bounded buy/sell 2025-08-23 16:10:05 +02:00
johba
8b537302d8 feat: Add staking functionality to fuzzing analysis with snatching
- Integrate staking and exitPosition actions into fuzzing scenarios
- Add staking metrics (percentageStaked, avgTaxRate) to CSV output
- Implement snatching mechanism when stake pool reaches capacity
- Add configurable staking parameters (enable/disable, buy bias, staking bias)
- Support configurable number of trades per run
- Simplify to single trader account with proportional ETH funding
- Configure tax rates: 0-15 for initial stakes, 28 for snatching
- Clean up debug logging and verbose output

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 18:29:20 +02:00
johba
74e09bb38b consolidated scripts 2025-08-19 17:35:43 +02:00
johba
10702f5aa3 feat: Enhance fuzzing with staking integration and configurable parameters
- Add staking/unstaking actions to fuzzing scenarios (stake every 3rd trade)
- Implement snatching logic when stake pool reaches capacity (uses max tax rate)
- Add configurable parameters:
  - buyBias: Control buy vs sell ratio (0-100%)
  - stakingBias: Control stake vs unstake ratio (0-100%)
  - tradesPerRun: Configure number of trades per scenario
  - staking: Enable/disable staking entirely
- Simplify to single trading strategy (_executeRandomLargeTrades)
- Fix memory issues by recording only every 5th trade to CSV
- Track staking metrics (stakes attempted/succeeded, snatches attempted/succeeded)
- Update CLAUDE.md with new fuzzing parameters and usage examples
- Clean up old TODO files and unused code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 14:57:49 +02:00
johba
27a8998a82 feat: Add buy bias parameter to fuzzing analysis
- Added BUY_BIAS environment variable (0-100%) to control trading direction
- Implemented biased trading logic in all strategies (Random, Whale, Volatile, etc.)
- Created run-improved-fuzzing.sh script with buy bias support
- Fixed memory issues in CSV generation by simplifying string concatenation
- Fixed console.log parameter issues in staking functions
- Updated run-recorded-fuzzing.sh to accept buybias parameter
- Testing shows up to 99% of authorized stake reached with 100% buy bias

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 14:02:11 +02:00
johba
25d6e2301a out of gas 2025-08-19 13:47:04 +02:00
johba
db23d756e9 fix: Optimize fuzzing and fix CSV buffer accumulation
- Deploy Uniswap factory once before all runs (saves ~1.16M gas per run)
- Fix CSV buffer accumulation bug by clearing buffer between runs
- Add clearCSV() function to CSVManager for proper buffer management
- Each fuzzing run now gets its own clean CSV with correct token0isWeth values
- Comment out failing console.log in Optimizer.t.sol to fix compilation

The token ordering now correctly alternates:
- Even seeds: token0isWeth = true (WETH < KRAIKEN)
- Odd seeds: token0isWeth = false (KRAIKEN < WETH)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 13:30:18 +02:00
johba
e5d47b1890 Merge branch 'anchor' 2025-08-19 11:49:50 +02:00
johba
f3047072f6 feat: Dynamic anchorWidth based on staking metrics
Replace hardcoded anchorWidth=100 with dynamic calculation that uses staking data as a decentralized oracle.

Changes:
- Add _calculateAnchorWidth() function to Optimizer.sol
- Base width 40% with adjustments based on staking percentage and average tax rate
- Staking adjustment: -20% to +20% (inverse relationship)
- Tax rate adjustment: -10% to +30% (direct relationship)
- Final range clamped to 10-80% for safety

Rationale:
- High staking % = bullish sentiment → narrower anchor (20-35%) for fee optimization
- Low staking % = bearish/uncertain → wider anchor (60-80%) for defensive positioning
- High tax rates = volatility expected → wider anchor to reduce rebalancing
- Low tax rates = stability expected → narrower anchor for fee collection

The Harberger tax mechanism acts as a prediction market where stakers' self-assessed valuations reveal market expectations.

Tests:
- Add comprehensive unit tests in test/Optimizer.t.sol
- Add mock contracts for testing (MockStake.sol, MockKraiken.sol)
- Manual verification confirms all scenarios calculate correctly

Documentation:
- Add detailed analysis of anchorWidth price ranges
- Add staking-based strategy recommendations
- Add verification of calculation logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 11:41:02 +02:00
johba
400ab325ed refactor: Complete project renaming from HARB/Harberger to KRAIKEN
- Updated all production code references from 'harb' to 'kraiken'
- Changed 'Harberger tax' references to 'self-assessed tax'
- Updated function names (_getHarbToken -> _getKraikenToken)
- Modified documentation and comments to reflect new branding
- Updated token symbol from HARB to KRAIKEN in tests
- Maintained backward compatibility with test variable names

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 11:05:08 +02:00
johba
7eef96f366 recorded fuzzing 2025-08-18 22:09:03 +02:00
johba
85cc8191be fix: Resolve out-of-gas errors in fuzzing by disabling block gas limit
The fuzzing script was failing with out-of-gas errors when large KRAIKEN sells
tried to traverse many tick ranges in Uniswap V3. Fixed by adding the
--disable-block-gas-limit flag to forge script execution.

Also fixed the CSV symlink path for the visualizer to work correctly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 21:17:42 +02:00
johba
fbd8170198 fix: Resolve fuzzing script issues with gas limits and CSV symlinks
- Increased gas limit to 100M to prevent out-of-gas errors during large swaps
- Fixed symlink path for profitable_scenario.csv to work with visualizer
- Position CSVs are now always generated when recording profitable scenarios

The out-of-gas error was occurring when large KRAIKEN sells tried to traverse
many tick ranges in Uniswap V3. The visualizer couldn't display data because
the CSV symlink was created in the wrong directory.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 21:14:48 +02:00
johba
c1627dd4c9 refactor: Migrate to improved fuzzing system with visualizer support
- Replaced old FuzzingAnalysis.s.sol with improved RecordedFuzzingAnalysis
- Old fuzzing used trades too small (0.1-100% of remaining balance) to reach discovery
- New system uses larger trades (50-200 ETH) that successfully find invariants
- run-fuzzing.sh now redirects to run-recorded-fuzzing.sh for backward compatibility
- Added position CSV generation for profitable scenarios to support visualizer
- Visualizer automatically launches when invariants are found
- Removed unnecessary debugCSV complexity

The old fuzzing couldn't find invariants because trades got progressively smaller
(often <1 ETH after a few iterations) and couldn't move price the 3,690 ticks
needed to reach the discovery position. The new system maintains large trade sizes
throughout the scenario, successfully finding profitable exploits.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 21:09:03 +02:00
johba
2c69963151 feat: Add scenario recording and replay system for invariant debugging
Implements comprehensive fuzzing improvements to find and reproduce invariant violations:

Recording System:
- ScenarioRecorder captures exact trading sequences that violate invariants
- Exports to JSON, replay scripts, and human-readable summaries
- Unique Run IDs (format: YYMMDD-XXXX) for easy communication

Enhanced Fuzzing:
- ImprovedFuzzingAnalysis with larger trades (50-500 ETH) to reach discovery position
- Multiple strategies: Discovery Push, Whale Manipulation, Volatile Swings
- Successfully finds profitable scenarios with 66% success rate

Shell Scripts:
- run-recorded-fuzzing.sh: Automated fuzzing with recording and unique IDs
- replay-scenario.sh: One-command replay of specific scenarios

New Optimizers:
- ExtremeOptimizer: Tests extreme market conditions
- MaliciousOptimizer: Attempts to exploit the protocol

Documentation:
- Updated CLAUDE.md with complete recording workflow
- Enhanced 4-step debugging process
- Quick reference for team collaboration

This system successfully identifies and reproduces the discovery position exploit,
where traders can profit by pushing trades into the unused liquidity at extreme ticks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 20:31:39 +02:00
johba
e04885ad8a docs: Update onchain/CLAUDE.md with debugging insights
Added critical implementation details discovered during floor position debugging:
- VWAPTracker stores price² (squared) in X96 format
- Token calculation gotchas for Amount0/Amount1 functions
- Outstanding supply calculation details
- ETH scarcity sqrt calculation
- Precise optimizer parameter formulas

Made documentation more concise (133→108 lines) while adding actionable debugging tips.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 18:10:34 +02:00