Commit graph

38 commits

Author SHA1 Message Date
openhands
aa274fd8ed fix: address review findings for anchorWidth guard (#817)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-15 22:04:13 +00:00
openhands
ac4aa745f6 fix: fix: remove MAX_ANCHOR_WIDTH clamp in ThreePositionStrategy (#783)
Remove the MAX_ANCHOR_WIDTH=100 constant and the corresponding clamp on
anchorWidth in LiquidityManager.recenter(). The optimizer is now free to
choose any anchor width; evolution run 7 immediately exploited AW=153.

Update IOptimizer.sol NatSpec to reflect no clamping. Update the
testAnchorWidthAbove100IsClamped test to testAnchorWidthAbove100IsNotClamped,
asserting the tick range matches the full AW=150 width.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 23:21:30 +00:00
openhands
0d3aee15b4 fix: address AI review findings for #706 recenterAccess removal
- DeployBase.sol: remove broken inline second recenter() (would always
  revert with 'recenter cooldown' in same Forge broadcast); replace with
  operator instructions to run the new BootstrapVWAPPhase2.s.sol script
  at least 60 s after deployment
- BootstrapVWAPPhase2.s.sol: new script for the second VWAP bootstrap
  recenter on Base mainnet deployments
- StrategyExecutor.sol: update stale docstring that still described the
  removed recenterAccess bypass; reflect permissionless model with vm.warp
- TestBase.sol: remove vestigial recenterCaller parameter from all four
  setupEnvironment* functions (parameter was silently ignored after
  setRecenterAccess was removed); update all callers across six test files
- bootstrap-common.sh: fix misleading retry recenter in
  seed_application_state() — add evm_increaseTime 61 before evm_mine so
  the recenter cooldown actually clears and the retry can succeed

All 210 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 09:15:48 +00:00
openhands
1a410a30b7 fix: Remove recenterAccess — make recenter() public with TWAP enforcement (#706) 2026-03-13 22:32:53 +00:00
openhands
39c25fa330 fix: LiquidityManager silently clamps anchorWidth to 100, undocumented upper bound (#689)
- Extract magic number into named constant MAX_ANCHOR_WIDTH = 100 in LiquidityManager.sol
- Document effective ceiling in IOptimizer.sol natspec for anchorWidth return value
- Add testAnchorWidthAbove100IsClamped in LiquidityManager.t.sol asserting that
  optimizer-returned anchorWidth=150 is silently clamped to 100 (not rejected)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 18:14:37 +00:00
openhands
b8f5ed9411 fix: Dead code branch: lastRecenterTick==0 with cumulativeVolume>0 (#568)
Remove unreachable else branch in VWAP recording logic. The branch was
only reachable if lastRecenterTick==0 and cumulativeVolume>0, which
requires tick==0 on the very first recenter — virtually impossible on a
live pool. Collapse else-if into else and delete the corresponding
testVWAPElseBranch test that exercised the path via vm.store.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 19:21:11 +00:00
openhands
b902b89e3b fix: address review findings — CREATE2 guard, transition test, docs
- LiquidityManager.setFeeDestination: add CREATE2 bypass guard — also
  blocks re-assignment when the current feeDestination has since acquired
  bytecode (was a plain address when set, contract deployed to it later)
- LiquidityManager.setFeeDestination: expand NatSpec to document the
  EOA-mutability trade-off and the CREATE2 guard explicitly
- Test: add testSetFeeDestinationEOAToContract_Locks covering the
  realistic EOA→contract transition (the primary lock-activation path)
- red-team.sh: add comment that DEPLOYER_PK is Anvil account-0 and must
  only be used against a local ephemeral Anvil instance
- ARCHITECTURE.md: document feeDestination conditional-lock semantics and
  contrast with Kraiken's strictly set-once liquidityManager/stakingPool

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 17:13:50 +00:00
openhands
512640226b fix: fix: Conditional lock on feeDestination — lock when set to contract (#580) (#580)
- Add `feeDestinationLocked` bool to LiquidityManager
- Replace one-shot setter with conditional trapdoor: EOAs may be set
  repeatedly, but setting a contract address locks permanently
- Remove `AddressAlreadySet` error (superseded by the new lock mechanic)
- Replace fragile SLOT7 storage hack in red-team.sh with a proper
  `setFeeDestination()` call using the deployer key
- Update tests: replace AddressAlreadySet test with three new tests
  covering EOA multi-set, contract lock, and locked revert

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-12 16:13:44 +00: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
openhands
cfcf750084 fix: Backtesting #5: Position tracking + P&L metrics (#319)
- Add PositionTracker.sol: tracks position lifecycle (open/close per
  recenter), records tick ranges, liquidity, entry/exit blocks/timestamps,
  token amounts (via LiquidityAmounts math), fees (proportional to
  liquidity share), IL (LP exit value − HODL value at exit price), and
  net P&L per position. Aggregates total fees, cumulative IL, net P&L,
  rebalance count, Anchor time-in-range, and capital efficiency accumulators.
  Logs with [TRACKER][TYPE] prefix; emits cumulative P&L every 500 blocks.

- Modify StrategyExecutor.sol: add IUniswapV3Pool + token0isWeth to
  constructor (creates PositionTracker internally), call
  tracker.notifyBlock() on every block for time-in-range, and call
  tracker.recordRecenter() on each successful recenter. logSummary()
  now delegates to tracker.logFinalSummary().

- Modify BacktestRunner.s.sol: pass sp.pool and token0isWeth to
  StrategyExecutor constructor; log tracker address.

- forge fmt: reformat all backtesting scripts and affected src/test files
  to project style (number_underscore=thousands, multiline_func_header=all).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 11:23:18 +00:00
openhands
9cce524b8a fix: Test coverage: LiquidityManager + Optimizer + OptimizerV3 to 100% (#285)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 02:41:02 +00:00
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
af031877a5 fix position calculation 2025-09-23 11:46:57 +02:00
johba
1dad2fb12a renaming 2025-07-25 19:09:11 +02:00
johba
f710750e87 separated setup form test 2025-07-25 18:49:34 +02:00
giteadmin
62b53ccf1d Implement liquidity-aware trading functions with DRY architecture
- Add precise Uniswap V3 math-based trade size calculations
- Implement buyLimitToLiquidityBoundary() and sellLimitToLiquidityBoundary()
- Create buyRaw()/sellRaw() for unsafe trading without limits
- Establish DRY architecture where buy() calls buyRaw() internally
- Add try-catch error handling for boundary conditions
- Clean up debug console logs and convert important ones to comments
- Remove debug-only testEmptyPoolBoundaryJump() function
- All tests pass with proper boundary testing capabilities

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-19 19:24:39 +02:00
giteadmin
bab3550ebf Add position contiguity validation and VWAP recording test improvements
- Enhanced LiquidityManager test infrastructure with position contiguity checking
- Added tick range validation to Response struct and checkLiquidity() function
- Implemented proper assertions for testRecordVolumeAndPriceUnsafe() fuzzing test
- Added anchor-discovery contiguity validation for both token orderings
- Improved VWAP overflow detection testing with contract state validation
- Updated testing todos with completion status and priority analysis

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-18 22:39:22 +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
c5f0323df7 fixed tests 2025-07-17 21:35:18 +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
30fa49d469 Implement anti-arbitrage strategy validation test
- Add testAntiArbitrageStrategyValidation() to LiquidityManager.t.sol
- Validates asymmetric slippage profile protects against trade-recenter-reverse attacks
- Test results: 80% round-trip slippage loss proves protection mechanism effective
- Confirms ANCHOR (17% ratio) vs FLOOR/DISCOVERY (deep) liquidity design
- Update CLAUDE.md with comprehensive anti-arbitrage strategy documentation
- Update VWAP_TEST_GAPS.md marking anti-arbitrage validation as completed

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-08 11:25:30 +02:00
giteadmin
77af20dcee beautified 2025-07-08 10:33:10 +02:00
giteadmin
ab127336c8 better tests 2025-07-06 11:45:25 +02:00
giteadmin
ac715c544a separated scenarios from tests 2025-07-06 11:20:35 +02:00
giteadmin
3a239b6cbf cleaned up tests 2025-07-06 10:29:34 +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
giteadmin
092f88a668 took out UBI and cleaned up 2025-01-23 13:21:49 +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
JulesCrown
16e65f0f15 take harb minted for staking into account when setting floor 2024-08-15 15:17:44 +02:00
JulesCrown
3eeef258e3 set capital efficiency in tests 2024-08-13 20:41:39 +02:00
roleengineer
0329a5da4f priceRatio stored and used in vwap always ETH/HARB. fixed compatibility. 2024-08-13 18:33:41 +00:00
JulesCrown
c7582350a0 correct accumulator pricing 2024-08-12 19:07:07 +02:00
JulesCrown
b243874f02 added overflow checks 2024-07-18 07:35:39 +02:00
JulesCrown
694afbe9fe make slide and shift one function 2024-07-16 20:47:06 +02:00
JulesCrown
ae8c3a1e4f added gov params 2024-07-16 19:47:39 +02:00
JulesCrown
236469f023 added comments 2024-07-13 18:33:47 +02:00
Renamed from onchain/test/BaseLineLP2.t.sol (Browse further)