Commit graph

19 commits

Author SHA1 Message Date
johba
d7c2184ccf Add Solidity linting with solhint, Foundry formatter, and pre-commit hooks (#51)
## Changes

### Configuration
- Added .solhint.json with recommended rules + custom config
  - 160 char line length (warn)
  - Double quotes enforcement (error)
  - Explicit visibility required (error)
  - Console statements allowed (scripts/tests need them)
  - Gas optimization warnings enabled
  - Ignores test/helpers/, lib/, out/, cache/, broadcast/

- Added foundry.toml [fmt] section
  - 160 char line length
  - 4-space tabs
  - Double quotes
  - Thousands separators for numbers
  - Sort imports enabled

- Added .lintstagedrc.json for pre-commit auto-fix
  - Runs solhint --fix on .sol files
  - Runs forge fmt on .sol files

- Added husky pre-commit hook via lint-staged

### NPM Scripts
- lint:sol - run solhint
- lint:sol:fix - auto-fix solhint issues
- format:sol - format with forge fmt
- format:sol:check - check formatting
- lint / lint:fix - combined commands

### Code Changes
- Added explicit visibility modifiers (internal) to constants in scripts and tests
- Fixed quote style in DeployLocal.sol
- All Solidity files formatted with forge fmt

## Verification
-  forge fmt --check passes
-  No solhint errors (warnings only)
-  forge build succeeds
-  forge test passes (107/107)

resolves #44

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/51
2025-10-04 15:17:09 +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
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
1a45646017 docs: Replace debugging reflection with actionable TODOs
Converted the debugging reflection into 4 concrete improvement areas:
1. Document Uniswap V3 mechanics & token flows
2. Document optimizer parameters & effects
3. Implement calculation tracing & visualization tools
4. Improve code quality with type safety, tests & invariants

Each TODO has specific tasks and acceptance criteria for implementation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 17:47:59 +02:00
johba
516b7cc087 fix: Correct VWAP price calculation in floor position placement
The VWAP tracker stores price² (squared price) in X96 format, but the floor position
calculation was using it as regular price. This caused two issues:

1. ETH scarcity calculation overestimated required ETH by using price² instead of price
2. ETH abundance floor placement was incorrect due to passing price² to _tickAtPriceRatio

Fixed by taking sqrt(vwapX96) before using it in both ETH scarcity and abundance cases.

Also updated BullMarketOptimizer documentation to be more accurate.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-18 15:33:57 +02:00
johba
2205ae719b feat: Optimize discovery position depth calculation
- Implement dynamic discovery depth based on anchor position share
- Add configurable discovery_max_multiple (1.5-4x) for flexible adjustment
- Update BullMarketOptimizer with new depth calculation logic
- Fix scenario visualizer floor position visibility
- Add comprehensive tests for discovery depth behavior

The discovery position now dynamically adjusts its depth based on the anchor
position's share of total liquidity, allowing for more effective price discovery
while maintaining protection against manipulation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-16 16:45:24 +02:00
johba
bcec691bbb whale mode 2025-08-10 16:37:58 +02:00
johba
e021aff978 better scripts 2025-08-09 19:17:46 +02:00
johba
9f0b163303 wip 2025-08-09 18:03:31 +02:00
giteadmin
3687029dcb half-way working analysis 2025-07-25 10:52:56 +02:00
giteadmin
eac7360ff9 Consolidate duplicate helper functions and improve test maintainability
- Create shared MockVWAPTracker.sol to eliminate duplicate mock implementations
- Add TestBase.sol with shared utilities (getDefaultParams, bp, denormTR)
- Update CSVHelper.sol to use Forge's vm.toString() instead of manual conversion
- Standardize tick calculation function names across test files
- Update test files to use consolidated utilities
- Remove helper function inventory (consolidation complete)

Eliminates 200-300 lines of duplicate code while maintaining 100% test compatibility.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 20:30:50 +02:00
giteadmin
fa2cd00cfa Remove redundant VWAP tests and fix fuzzing test SPL error
- Remove two redundant VWAP tests from LiquidityManager.t.sol that provided no unique coverage beyond comprehensive testing in VWAPTracker.t.sol
- Fix testFuzzRobustness fuzzing test failure caused by "SPL" (Square root Price Limit) errors in extreme price conditions
- Improve price limit calculation in UniswapTestBase.sol with better boundary checking and safety margins
- All tests now pass consistently (97/97 tests passing across 11 test suites)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 19:37:30 +02:00
giteadmin
74143dfac7 Complete project rename from HARB/Harberg to KRAIKEN with KRK token symbol
- Renamed core contract from Harberg.sol to Kraiken.sol
- Updated token symbol from HARB to KRK
- Renamed TypeScript library from harb-lib to kraiken-lib
- Updated all contract imports and references across smart contracts
- Modified subgraph schema and source files for new naming
- Updated transaction bot dependencies and service references
- Fixed test files to use new contract and token names
- Updated documentation in CLAUDE.md and README.md
- Regenerated subgraph types and ABI files
- Added new deployment script (DeployScript2.sol)

All components compile successfully and tests pass.
Smart contracts:  Compilation and tests pass
TypeScript library:  Package renamed and configured
Subgraph:  Code generation and build successful
Transaction bot:  Dependencies updated

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 13:47:42 +02:00
giteadmin
d958374019 Implement comprehensive market condition sentiment analysis framework
## Key Features

### Dynamic Sentiment Configuration
- Enhanced MockOptimizer with configurable parameters
- Replaced hardcoded sentiment values with dynamic market condition scenarios
- Bull Market (20% capital inefficiency), Neutral (50%), Bear Market (80%)

### Market Condition Matrix Analysis
- Parameter validation testing across sentiment scenarios
- Fuzzing analysis for profitable trading opportunity detection
- Comprehensive vulnerability assessment framework

### Sentiment Fuzzing Results
- Bull Market: 11% profitable scenarios (moderate vulnerability as expected)
- Neutral Market: 0% profitable scenarios (good protection)
- Bear Market: 0% profitable scenarios (strong protection)

### Anti-Arbitrage Validation
- Confirmed low capital inefficiency exposes profitable trades
- Validated economic model: aggressive positioning = higher vulnerability
- Proved conservative positioning = stronger protection

### Testing Infrastructure
- Comprehensive sentiment scenario testing framework
- Real-time profitability analysis and vulnerability detection
- Foundation for genetic algorithm parameter optimization

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-08 13:57:42 +02:00
giteadmin
77af20dcee beautified 2025-07-08 10:33:10 +02:00
giteadmin
79c26e3c31 testing price boundaries 2025-07-06 10:08:59 +02:00
giteadmin
78b48f1639 replaced sentiment with specific params 2025-02-01 21:51:03 +01:00
Jules Clown
97b5e249ac fix tests 2024-11-13 16:37:23 +01:00
giteadmin
bb34d0725f feature/simulations (#11)
this pull request:
- creates a unit test that can take any scenario file (default: `out/scenario.json` and play it back on the deployment
- during the playback a debug trace generated in `timeSeries.csv`
- extracts the sentimenter into a separate upgradeable contract

Co-authored-by: JulesCrown <admin@noip.localhost>
Co-authored-by: giteadmin <gite@admin.com>
Reviewed-on: http://gitea.loseyourip.com:4000/dark-meme-society/harb/pulls/11
2024-11-07 15:33:40 +00:00