Withdraw
Withdraw returns collateral (cbBTC or SOL) from a position to your wallet. Because the collateral may be backing both your loan and Sonnar’s working borrow, withdrawal is the one action that runs as a two-step flow - and the SDK sequences it for you in a single call.
What the method does
Section titled “What the method does”Under the hood a withdrawal is two program instructions in one transaction:
prepare_withdraw- unwinds the working side first: redeems the position’s yield-vault shares and uses the proceeds to repay the lender, so the collateral you’re taking out is no longer needed as backing.withdraw- releases the collateral from the lender (Kamino obligation or Jupiter Lend position) back to your wallet.
Both run atomically - if any step fails, nothing happens. There is no state where the vault has been unwound but your collateral is stuck.
Withdrawing raises your LTV (less collateral behind the same debt), so how much you can take out is bounded by your remaining loan.
How to call it
Section titled “How to call it”import { executeAction, parseCollateral, SOL_MINT } from "@hobba-io/core";
const { signature } = await executeAction({ connection, signer, collateralMint: SOL_MINT, action: "withdraw", amount: parseCollateral("0.5", SOL_MINT), // collateral base units apiBaseUrl: "https://app.hobba.io", onStep: (s) => setStatus(s),});SOL comes back unwrapped - the SDK closes the temporary wSOL account so you receive native SOL.
Bounds - always use getLimits for “withdraw max”
Section titled “Bounds - always use getLimits for “withdraw max””const limits = await getLimits({ connection, owner, collateralMint, apiBaseUrl });// limits.maxWithdraw - collateral base unitsmaxWithdraw keeps the post-withdraw LTV at or below the 50% user cap, and
bakes in two things a naive calculation misses:
- Interest drift - debt accrues between quoting and execution, so the max is shaved by a small per-lender factor; without it a “Max” withdrawal can fail at submission.
- Unwind residual - when Sonnar has capital deployed, redeeming vault
shares leaves rounding dust and vault fees behind.
maxWithdrawreserves just enough collateral to keep that residual healthy instead of stranding it against nothing.
With zero debt, maxWithdraw is simply your full collateral balance.
Closing out entirely
Section titled “Closing out entirely”To exit a position completely:
repayto zero (uselimits.maxRepayUsdc),withdrawwithlimits.maxWithdraw(now the full balance).
The on-chain user state remains, so reopening later is a plain deposit - no re-initialization, and the wallet stays allowlisted.