> For the complete documentation index, see [llms.txt](https://docs.flash.trade/flash-trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/concepts/funds-lifecycle.md).

# Funds lifecycle

Collateral flows through four stages:

```
deposit  →  delegate  →  trade  →  withdraw
```

```
init-deposit-ledger   ─┐
init-basket           ─┼─ one-time setup
deposit               ─┘   (bundles any missing setup + funds the ledger)
delegate-basket       ─── enable trading
   │
   ▼
trade (fast, gasless)
   │
   ▼
withdraw              ─── pull funds back out
```

## Deposit

The one-shot [`deposit`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#deposit) endpoint funds the deposit ledger and conditionally bundles whatever setup is missing (basket, deposit ledger, delegation, trade vault). Prefer it for onboarding. Use [`deposit-direct`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#deposit-direct) if you'd rather run each setup step yourself.

**Deposit ledger** — a per-owner PDA that tracks the balances available as collateral. Deposits credit it; opening positions and adding collateral draw it down.

**Trade vault** — a per-mint token account that deposits land in and withdrawals are paid from.

## Delegate

[`delegate-basket`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#delegate-basket) is a one-time step that enables trading on your basket. A trade submitted before the basket is delegated is rejected.

## Withdraw

The single-call [`withdraw`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#withdraw) endpoint builds one transaction that locks the amount and releases the funds. Two things to know:

1. **Fee payer ≠ owner.** The client supplies its own fee payer (which must differ from `owner`) and co-signs the transaction with both keys.
2. **It's asynchronous.** Funds release after the transaction lands; poll the returned escrow `receipt` until it closes.

Two response flags drive the flow:

* `custodySettlementRequired: true` → the trade vault can't cover the amount yet. Call [`custody-settlement`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#custody-settlement) first, then retry `withdraw`.
* `isNativeSol: true` → the released funds arrive as WSOL; unwrap the WSOL account back to native SOL.

If a withdrawal doesn't finalize on its own, [`withdrawal-settle`](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/account-and-funds.md#withdrawal-settle) resumes it.

Step-by-step: [Withdraw funds](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/guides/withdraw-funds.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/concepts/funds-lifecycle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
