Commit graph

22 commits

Author SHA1 Message Date
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
85350caf52 feat: OptimizerV3 with direct 2D staking-to-LP parameter mapping
Core protocol changes for launch readiness:

- OptimizerV3: binary bear/bull mapping from (staking%, avgTax) — avoids
  exploitable AW 30-90 kill zone. Bear: AS=30%, AW=100, CI=0, DD=0.3e18.
  Bull: AS=100%, AW=20, CI=0, DD=1e18. UUPS upgradeable with __gap[48].
- Directional VWAP: only records prices on ETH inflow (buys), preventing
  sell-side dilution of price memory
- Floor formula: unified max(scarcity, mirror, clamp) — VWAP mirror uses
  distance from adjusted VWAP as floor distance, no branching
- PriceOracle (M-1 fix): correct fallback TWAP divisor (60000s, not 300s)
- Access control (M-2 fix): deployer-only guard on one-time setters
- Recenter rate limit (M-3 fix): 60-second cooldown for open recenters
- Safe fallback params: recenter() optimizer-failure defaults changed from
  exploitable CI=50%/AW=50 to safe bear-mode CI=0/AW=100
- Recentered event for monitoring and indexing
- VERSION bump to 2, kraiken-lib COMPATIBLE_CONTRACT_VERSIONS updated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:21:18 +00:00
johba
4277f19b68 feature/ci (#84)
Co-authored-by: openhands <openhands@all-hands.dev>
Reviewed-on: https://codeberg.org/johba/harb/pulls/84
2026-02-02 19:24:57 +01: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
Your Name
0de1cffea8 another fixup of fuzzer 2025-09-16 22:46:43 +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
9f0b163303 wip 2025-08-09 18:03:31 +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
6a158150b1 Clean up test suite organization and eliminate duplicate code
- Remove duplicate test files with overlapping functionality:
  * Delete VWAPDoubleOverflowAnalysis.t.sol (155 lines) - functionality already covered by VWAPTracker.t.sol with proper assertions
  * Delete ModularComponentsTest.t.sol (57 lines) - meaningless tests redundant with build process

- Improve code organization:
  * Move CSVHelper.sol and CSVManager.sol from test/helpers/ to analysis/ folder to reflect actual usage
  * Update import path in SimpleAnalysis.s.sol from ../test/helpers/CSVManager.sol to ./CSVManager.sol
  * Remove deprecated uintToStr() and intToStr() wrapper functions from CSVHelper.sol

- Update documentation:
  * Mark completed cleanup tasks in testing_todos.md
  * Add code organization improvements section showing eliminated duplicate functionality

Result: Cleaner test suite with 92 meaningful tests (vs 95 with noise), better file organization reflecting actual usage patterns, and zero dead code remaining.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-19 19:58:41 +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
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
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
77af20dcee beautified 2025-07-08 10:33:10 +02:00
giteadmin
79c26e3c31 testing price boundaries 2025-07-06 10:08:59 +02:00
giteadmin
5db3ecb3d7 wip 2024-12-09 23:08:24 +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
8c0a45a0f3 more bugs out 2024-07-09 18:00:39 +02:00
JulesCrown
39065a908e added fee payouts 2024-06-09 16:06:41 +02:00
JulesCrown
5d209e5e19 added csv serializer 2024-05-29 17:26:19 +02:00