Velocity ProtocolDevelopers
Getting Started

Withdraw and close an account

What has to be true for a withdrawal to go through, and the stricter conditions on deleting a subaccount.

Collateral can be withdrawn at any time, including while positions or borrows are open. The only thing the protocol asks is that the account is still above its initial margin requirement once the withdrawal has been taken out (meets_withdraw_margin_requirement). Partial withdrawals are fine, and the amount available is the account's free collateral, which any portfolio screen shows alongside the rest of the account health breakdown.

A large withdrawal can additionally be throttled by the spot market's own rolling withdrawal limits, which are about the market's solvency rather than the account's and apply even to an account with no positions at all. See Withdrawal and borrow limits for the two bounds, the small-depositor exception, and the withdraw guard threshold that both formulas are built on.

One more condition applies to an account holding a borrow in a spot market other than the one being withdrawn from: that market's interest has to have been brought up to date recently. The window is an hour on most markets and shorter on a market with a very high borrow rate. Bringing it up to date is permissionless, the interface does it in the same transaction as the withdrawal, and keepers do it continuously during normal activity, so an active market rarely runs into it. If a withdrawal is rejected with SpotMarketInterestStaleForMargin, that is this check, and retrying is enough. The exact window and why it exists are in Troubleshooting.

Deleting a subaccount

Deleting is considerably stricter than withdrawing. validate_user_deletion requires the subaccount to be completely empty and completely quiet: no open perpetual positions, no open spot positions, no open orders, no unsettled P&L, no remaining balances, not bankrupt, and not currently being liquidated. A perp position counts as open while it holds unsettled P&L even if its base amount is zero, which is the usual reason a delete button stays greyed out on an account the owner believes is flat.

A wallet that has referred other users cannot delete its main account (subaccount 0) at all, because that account anchors the referral relationships. Every other subaccount under the same authority can still be deleted normally.

The reverse case does not work the way people expect. For a wallet that was referred, deleting its accounts does not make it referable again: the referrer is recorded once during the first initialize_user and is never rewritten. See Referral links.

Idle account deletion

A keeper holding the UserFlag hot-admin role can force-delete accounts that have gone dormant, which keeps unused onchain storage from accumulating across the program and the keeper networks that index it. Two conditions both have to hold: the account must have been inactive for at least 12 weeks, and its total equity must be at most $0.05 (handle_force_delete_user). The oracle prices used for that equity check must all be valid, so a stale price cannot make a funded account look like dust.

The rent goes back to the account's authority, as it does on a normal deletion. Whatever deposits remain, worth under $0.05 by construction, go to the keeper's token account as the incentive for doing the cleanup. Trading history stays available through the UI, and a new subaccount can be created at any time afterwards.

Reclaiming rent

Rent comes back when the account is deleted, in the same transaction and to the same wallet that paid it. Go to the accounts page, click the trash icon next to the account, and sign. There is no waiting period and no second step.