Skip to content

refactor(provider): unify slisBNB rebalance with wstETH/wbETH (DEX-ag…#201

Merged
qingyang-lista merged 2 commits into
feature/v3-lpfrom
feature/eth-v3-lp
Jun 26, 2026
Merged

refactor(provider): unify slisBNB rebalance with wstETH/wbETH (DEX-ag…#201
qingyang-lista merged 2 commits into
feature/v3-lpfrom
feature/eth-v3-lp

Conversation

@razww

@razww razww commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Generalize the (not-yet-deployed) slisBNB/BNB V3 LP collateral provider into a chain/LST-agnostic base and add Ethereum wstETH/WETH and wbETH/WETH LP markets. slisBNB becomes a thin subclass with byte-equivalent behavior.

Highlights

  • Generalized baseV3DexAdapter / V3Provider / V3ProviderOracle are chain/LST-agnostic (WRAPPED_NATIVE immutable + virtual _lstNativeRate()); slisBNB, wstETH, wbETH are thin subclasses.
  • DEX-agnostic rebalance — inventory conversion is a backend-built swap against a whitelisted venue (swapPairWhitelist, backend amountOutMin), shared by all pairs. Works with DEX/aggregators and with StakeManager instant-redeem/deposit (native-coin settlement is wrapped/unwrapped automatically).
  • Share oracle — exchange-rate-implied (slisBNB) or pool-TWAP-clamped-to-rate (wstETH/wbETH); legs valued rate-derived via the resilient oracle, with a conservative haircut.
  • V3Liquidator — chain-agnostic native leg via WRAPPED_NATIVE(); handles the loanToken == wrapped-native case.
  • Precision — supports non-18-decimal paired tokens (wrapped-native is 18-dec); oracle quotes per whole share (10 ** shareDecimals).
  • Safety — provider↔adapter↔oracle wiring cross-checks; swap-venue whitelist rejects the position's own token/pool/NPM.

Testing

263 tests pass — BSC slisBNB + V3Liquidator regression unchanged; Ethereum fork suites for wstETH, wbETH, V3Liquidator, and the non-18-decimal sqrt-price math. forge build + prettier clean.

Backend note

Rebalance swapData = abi.encode(swapPair, sellToken0, amountIn, amountOutMin, nativeIn, innerSwapData)nativeIn = true only for native-input venues (e.g. StakeManager.deposit{value}).

…nostic swap)

Make the slisBNB/BNB rebalance inventory conversion identical to the wstETH/WETH and
wbETH/WETH families: a backend-built swap against a whitelisted venue, swap-pair-agnostic on
chain. instantWithdraw is conceptually just a swap, so the StakeManager special-casing is no
longer needed — promoting one shared implementation also simplifies the code.

- Promote the generic conversion to the base V3DexAdapter: swapPairWhitelist +
  setSwapPairWhitelist (rejecting TOKEN0/TOKEN1/POOL/NPM) + the decode-and-swap
  _convertToOptimalRatio (via SwapInventoryLib, backend amountOutMin). All three rate-implied
  subclasses inherit it; both declared on IV3DexAdapter.
- SwapInventoryLib is native-aware: when a venue settles the wrapped-native leg as the native
  coin (e.g. a StakeManager instant-redeem → BNB), the received native is wrapped back into the
  wrapped-native ERC20 before amountOutMin is measured; receive() accepts native from a
  whitelisted venue. ⇒ instantWithdraw works as a whitelisted swap venue (slisBNB→BNB→WBNB),
  with no StakeManager special-casing on chain.
- Slim SlisBNBV3DexAdapter to _lstNativeRate() (StakeManager rate) + the pair guard; drop the
  StakeManager conversion override, the instant-withdraw slippage config, and the StakeManager
  receive() override. Delete SlisBnbInventoryLib.
- Slim WstETH/WbETHV3DexAdapter: swap logic now in the base; keep rate hook + TWAP-clamp.
- SlisBNBV3Provider.rebalance gains bytes calldata swapData, forwarded to the adapter.

Behavioral change: slisBNB rebalance converts via a whitelisted venue (a DEX/aggregator OR the
StakeManager instant-redeem) using backend swapData + amountOutMin, instead of a hardcoded path.

Tests: 257 passing — slisBNB swap-conversion (instantWithdraw-as-venue, both directions,
amountOutMin-revert) + whitelist + sensitive-pair-reject; old StakeManager-special-case/slippage
tests removed; wstETH/wbETH/liquidator/reentrancy green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@hashdit-bot

hashdit-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

Pull Request Review

This PR refactors the Solidity V3 adapter/provider architecture to unify rebalance inventory conversion across slisBNB, wstETH, and wbETH using a shared DEX-agnostic swap flow in V3DexAdapter + SwapInventoryLib. It removes slisBNB-specific StakeManager conversion logic (SlisBnbInventoryLib, custom receive/slippage settings) and introduces a common swapPairWhitelist control and backend-provided swapData path, including native-to-wrapped handling in swap settlement. It also updates interfaces and provider signatures to pass swapData, and aligns tests to validate whitelist checks, amountOutMin enforcement, and instantWithdraw-as-venue behavior.

Sensitive Content

Blockchain Address:

  • 0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B (slisBNB token) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0x1adB950d8bB3dA4bE104211D5AB038628e477fE6 (StakeManager) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c (WBNB token) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE (BNB sentinel address) in src/provider/v3/SlisBNBV3Provider.sol
  • 0xa2E3356610840701BDf5611a53974510Ae27E2e1 (wbETH token) in src/provider/v3/WbETHV3DexAdapter.sol
  • 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (WETH token) in src/provider/v3/WbETHV3DexAdapter.sol
  • 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 (wstETH token) in src/provider/v3/WstETHV3DexAdapter.sol
  • 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (WETH token) in src/provider/v3/WstETHV3DexAdapter.sol

Security Issues

No serious security issues detected.


Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits.

Build on the unified DEX-agnostic rebalance swap (9ba9766) so the V3 LP base is correct for
native-settling venues and non-18-decimal tokens.

- SwapInventoryLib native-aware both directions: the swapData blob gains bool nativeIn — now
  (swapPair, sellToken0, amountIn, amountOutMin, nativeIn, innerSwapData). nativeIn ⇒ the wrapped-native
  input leg is unwrapped and forwarded as msg.value (supports StakeManager.deposit{value} for
  WBNB→slisBNB). Any native a venue delivers (e.g. instantWithdraw → BNB) is wrapped back into the
  wrapped-native ERC20 before amountOutMin is measured — never stranded; reverts UnexpectedNative if
  neither leg is the wrapped-native.
- Non-18-decimal paired token: _sqrtPriceX96FromRate now scales the raw pool price by
  10^(DECIMALS1 - DECIMALS0) instead of assuming equal decimals (pure→view; cascaded to _tickRangeForRate).
  The wrapped-native stays 18-dec; the paired token may have any decimals.
- Oracle share-decimal correctness: V3ProviderOracle quotes peek(share) per ONE WHOLE share
  (10 ** SHARE_DECIMALS, read from the share token) instead of hardcoded 1e18, matching Moolah._getPrice
  which uses collateralToken.decimals(). No-op for the current 18-dec accounting assets.

Tests: 263 passing — new V3DexAdapterDecimals.t.sol (non-18-dec USDC(6)/WETH(18) + 18/18) proves the
sqrtPrice decimal math; slisBNB depositAsSwapVenue (nativeIn), wrongNativeOutput_reverts, instantWithdraw
no-stranded-native; swapData blobs updated to the 6-field shape. Backend encoder must add nativeIn.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@hashdit-bot

hashdit-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

Pull Request Review

This PR refactors the Solidity V3 adapter architecture to unify rebalance inventory conversion across slisBNB, wstETH, and wbETH by moving swap conversion logic into the shared V3DexAdapter + SwapInventoryLib. It removes the specialized SlisBnbInventoryLib and slisBNB-specific instant-withdraw slippage config, introduces swap-pair whitelisting in the base adapter/interface, and extends swap execution to support native-in/native-out wrapping behavior. It also fixes pricing math to account for token decimal differences in _sqrtPriceX96FromRate and updates oracle share pricing to use SHARE_DECIMALS instead of hardcoded 1e18.

Sensitive Content

Blockchain Address:

  • 0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B (contract/token address) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0x1adB950d8bB3dA4bE104211D5AB038628e477fE6 (contract address) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c (contract/token address) in src/provider/v3/SlisBNBV3DexAdapter.sol
  • 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE (sentinel native-token address) in src/provider/v3/SlisBNBV3Provider.sol
  • 0xa2E3356610840701BDf5611a53974510Ae27E2e1 (contract/token address) in src/provider/v3/WbETHV3DexAdapter.sol
  • 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 (contract/token address) in src/provider/v3/WbETHV3DexAdapter.sol
  • 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 (contract/token address) in src/provider/v3/WstETHV3DexAdapter.sol
  • 0xC36442b4a4522E871399CD717aBDD847Ab11FE88 (contract address) in test/provider/V3DexAdapterDecimals.t.sol
  • 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 (contract/token address) in test/provider/V3DexAdapterDecimals.t.sol

Security Issues

No serious security issues detected.


Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits.

@razww razww requested a review from qingyang-lista June 26, 2026 07:27

@qingyang-lista qingyang-lista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@qingyang-lista qingyang-lista merged commit 0f5c382 into feature/v3-lp Jun 26, 2026
6 checks passed
@qingyang-lista qingyang-lista deleted the feature/eth-v3-lp branch June 26, 2026 07:42
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.

2 participants