refactor(provider): unify slisBNB rebalance with wstETH/wbETH (DEX-ag…#201
Conversation
…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>
Pull Request ReviewThis 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 Sensitive ContentBlockchain Address:
Security IssuesNo 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>
Pull Request ReviewThis 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 Sensitive ContentBlockchain Address:
Security IssuesNo serious security issues detected. Generated by Hashdit Bot. This tool can absolutely NOT replace manual audits. |
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
V3DexAdapter/V3Provider/V3ProviderOracleare chain/LST-agnostic (WRAPPED_NATIVEimmutable + virtual_lstNativeRate()); slisBNB, wstETH, wbETH are thin subclasses.swapPairWhitelist, backendamountOutMin), shared by all pairs. Works with DEX/aggregators and with StakeManager instant-redeem/deposit (native-coin settlement is wrapped/unwrapped automatically).WRAPPED_NATIVE(); handles theloanToken == wrapped-nativecase.10 ** shareDecimals).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 = trueonly for native-input venues (e.g.StakeManager.deposit{value}).