Skip to content

feat: add OpenLiquidityStrategy for direct rebalancing#711

Merged
philbow61 merged 5 commits intodevelopfrom
feat/direct-rebalancer
Mar 10, 2026
Merged

feat: add OpenLiquidityStrategy for direct rebalancing#711
philbow61 merged 5 commits intodevelopfrom
feat/direct-rebalancer

Conversation

@solofberlin
Copy link
Copy Markdown
Contributor

Summary

  • Adds OpenLiquidityStrategy, a new liquidity strategy where the caller of rebalance() acts as the liquidity source via ERC20 transfers (no reserve minting/burning)
  • Uses EIP-1153 transient storage (tstore/tload) to track the rebalancer address within a transaction
  • Includes _clampExpansion and _clampContraction overrides that check the rebalancer's token balance and adjust amounts accordingly
  • Protocol incentive goes to protocolFeeRecipient, remaining tokens go to the rebalancer

Files

  • contracts/interfaces/IOpenLiquidityStrategy.sol — interface with OLS_OUT_OF_DEBT / OLS_OUT_OF_COLLATERAL errors
  • contracts/liquidityStrategies/OpenLiquidityStrategy.sol — full implementation
  • test/utils/harnesses/OpenLiquidityStrategyHarness.sol — test harness
  • test/unit/liquidityStrategies/OpenLiquidityStrategy/ — 40 tests (admin, rebalance, hook)

Test plan

  • All 40 tests passing (10 admin + 20 rebalance + 10 hook)
  • Review token flow correctness in _handleCallback
  • Verify transient storage slot isolation between rebalancer and hook-called flags

🤖 Generated with Claude Code

Add a new liquidity strategy where the caller of rebalance() acts as
the liquidity source, providing tokens via ERC20 transfers instead of
minting/burning through a reserve. Uses EIP-1153 transient storage to
track the rebalancer address within a transaction.

Includes full test suite (40 tests): admin, rebalance, and hook tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@solofberlin solofberlin requested review from a team, nvtaveras and philbow61 March 5, 2026 08:09
solofberlin and others added 2 commits March 5, 2026 09:15
The rebalancer address comes from transient storage set by msg.sender
in rebalance(), so the transferFrom source is not actually arbitrary.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rategy

Add a virtual _beforeRebalance(pool) hook called at the start of
rebalance() and make _getHookCalled internal instead of private.
This allows OpenLiquidityStrategy to inherit rebalance() as-is and
just override _beforeRebalance to store the caller, removing ~45
lines of duplicated logic and the _isHookCalled mirror function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
philbow61
philbow61 previously approved these changes Mar 6, 2026
Copy link
Copy Markdown
Contributor

@philbow61 philbow61 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM left some nits 👍

- Fix misleading comment "basis points to bps" -> "1e18-denominated to bps"
- Fix incorrect liquiditySourceIncentiveContraction value (50 -> 0.005e18)
  in first rebalance test (was a copy-paste bug from ReserveLiquidityStrategy)
- Remove duplicate hook tests that were identical to existing ones:
  - test_hook_expansionCallback_whenToken0IsDebt (dup of whenValidExpansion)
  - test_hook_contractionCallback_whenToken0IsDebt (dup of whenValidContraction)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
philbow61
philbow61 previously approved these changes Mar 6, 2026
@philbow61 philbow61 merged commit 6340e5b into develop Mar 10, 2026
4 checks passed
@philbow61 philbow61 deleted the feat/direct-rebalancer branch March 10, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants