[VPD-1430, 1431, 1432] feat(bstock): atomic backstop liquidator + off-chain scripts #683
Open
Debugger022 wants to merge 3 commits into
Open
[VPD-1430, 1431, 1432] feat(bstock): atomic backstop liquidator + off-chain scripts #683Debugger022 wants to merge 3 commits into
Debugger022 wants to merge 3 commits into
Conversation
- bStock is RFQ-only (no AMM), so third-party liquidators may not show. Add a self-liquidation backstop that, in one tx, repays the borrow, seizes and redeems the bStock vToken, and sells it to USDT via a pre-signed Native RFQ quote with a hard minOut, so the protocol never holds the RFQ-only asset across a drift window. - Two funding modes: own USDT inventory, or a Venus flash loan repaid (+ premium) in the same tx. - Routes the repay through the pool-wide Venus Liquidator when that gate is set, else liquidates directly; the seized amount is read as a balance delta so the liquidator treasury cut is handled. - Operator-gated and router-allowlisted: it custodies funds and forwards caller-supplied swap calldata to an external router. - Extend the shared IComptroller with getAccountLiquidity and executeFlashLoan (additive); split storage-light interface into IBStockLiquidator. - Add mocks, a unit suite (both modes, gate + treasury-cut, all guards and error paths), and a bscmainnet fork test on real Core.
- Native RFQ client (orderbook / firm-quote) plus a read-only quote smoke test for eyeballing price, depth and TTL - atomic liquidation driver: precompute the seize, fetch the signed firm-quote with the contract as taker, then call liquidate or flashLiquidate; warn early if inventory cannot cover the repay - mock-based test driving the script end to end: inventory and flash paths, plus the healthy-borrower and router-allowlist guards - add scripts/ to the eslint tsconfig include (it was uncovered) and add an exchangeRateStored getter to the collateral mock that the driver reads
- Safe Transaction Builder JSON helper (encode calls, build batch) - read-only script emitting a 4-tx batch (approve, liquidateBorrow, redeem, transfer raw bStock) for a multisig to settle a liquidation when the RFQ path is unavailable; seize amount snapshotted from chain, sends nothing
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backstop liquidation for bStock (ERC-8056 tokenized stocks: TSLAB, NVDAB, SPCXB) collateral. bStock is RFQ-only (Native is the sole market maker, no AMM), so third-party liquidators may not show up. This adds Venus's own fallback liquidator plus the off-chain tooling to drive it. Liquidation stays permissionless; this is only the backstop so the protocol never carries bad debt on an RFQ-only asset.
Changes
VPD-1430:
BStockLiquidatorcontract + testsUpgradeable, owner/operator-gated atomic liquidator. In one tx it repays an underwater borrow, seizes + redeems the bStock vToken, and sells the bStock to USDT via a pre-signed Native firm-quote with a hard
minOut(a bad or late quote reverts the whole tx, so the protocol never holds the RFQ-only asset across a price-drift window).executeFlashLoan, repaid + premium in the same tx).IComptroller(InterfacesV8) withgetAccountLiquidityandexecuteFlashLoan(additive).VPD-1431: off-chain liquidation scripts
The on-chain contract only does the atomic settle; every liquidation must be paired with an off-chain Native firm-quote. These scripts are that off-chain half.
VPD-1432: Safe multisig fallback
A read-only generator for a Safe Transaction Builder batch, used to settle a liquidation manually when the Native RFQ path is unavailable.
Scripts (
scripts/bstock/)lib/native.ts— Native (nativefi) RFQ API client (library). Orderbook / indicative / firm-quote, parses the signedtxRequest+ TTL, holds the TSLAB/NVDAB/USDT constants. API key viaNATIVE_API_KEY, never hardcoded. Not run directly.native-quote.ts— live quote smoke test (read-only, no chain). Sanity-checks the Native integration and shows price / spread / TTL / book depth before anything goes on-chain (depth is thin, so quotes above book size fail).atomic-liquidate.ts— driver for the deployedBStockLiquidator(the normal path). Confirms shortfall, precomputes the seize (adjusted for the redeemtreasuryPercent), fetches the MM-signed firm-quote with the contract as taker, checks the router is allowlisted, computesminOut, then callsliquidate(inventory) orflashLiquidate(flash loan).lib/safe.ts— Safe Transaction Builder JSON helper (library). Encodes calls and builds the batch JSON the Safe{Wallet} Transaction Builder imports. Not run directly.safe-fallback.ts— manual multisig fallback (read-only, emits JSON). When the RFQ path is down (API outage, halt, weekend, thin depth), a Safe multisig settles manually. Emits a 4-tx batch (approve,liquidateBorrow,redeem, transfer raw bStock to a custody/Binance address), seize amount snapshotted from chain. Sends nothing.Testing
tests/hardhat/BStockLiquidator.ts: 23 passing — both funding modes, gate + treasury-cut path, all guards and error paths.tests/hardhat/BStockAtomicLiquidate.ts: 4 passing — drivesatomic-liquidate.tsend to end (inventory + flash, healthy-borrower and router-allowlist guards).tests/hardhat/Fork/BStockLiquidatorFork.ts: passing — realliquidateBorrow→ seize → redeem through the live Venus Liquidator, with strict profit/borrow assertions (stand-in markets + mock router, since no bStock market is listed yet).Notes
setFlashLoanEnabled) is handled by a separate VIP (VPD-1433).