prepare_marginfi_withdraw
Build an unsigned MarginFi withdraw transaction. Withdraws specified amount or all from a user's supplied bank position, pre-flighting to prevent unhealthy withdrawals.
Instructions
Build an unsigned MarginFi WITHDRAW tx. Withdraws the specified amount (or ALL, via withdrawAll: true) from the user's supplied position in the named bank. Pre-flight refuses if the account has zero free collateral (the withdraw would push the health factor below the maintenance threshold — the on-chain tx would revert). DURABLE NONCE + prepare_marginfi_init prerequisites identical to prepare_marginfi_supply. BLIND-SIGN on Ledger.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| wallet | Yes | Base58 Solana mainnet address (ed25519 pubkey, 43 or 44 chars). | |
| symbol | No | Canonical token symbol (USDC, SOL, USDT, JUP, BONK, JTO, mSOL, jitoSOL). The builder resolves this to the underlying mint; MarginFi treats SOL as wSOL internally with auto-wrap/unwrap. Pass `mint` instead if your token isn't in the canonical list. | |
| mint | No | Base58 SPL mint address. Used as an override or when the token isn't in the canonical SOLANA_TOKENS table. Exactly one of `symbol` or `mint` must be passed. | |
| accountIndex | No | MarginfiAccount slot (0 = first, 1 = second, ...). Most users stay on 0. Use a different index to segregate positions across multiple MarginfiAccounts owned by the same wallet. | |
| amount | Yes | Human-readable decimal amount to withdraw. Pre-flight refuses if the withdraw would push the health factor below the maintenance threshold. | |
| withdrawAll | No | Set true to close the entire supplied position in this bank (lets the SDK pass the `withdraw_all` on-chain flag so the bank clears the balance slot). Omit for partial. |