> ## Documentation Index
> Fetch the complete documentation index at: https://docs.darkpool.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# PredictManager & BalanceManager

> The two account objects users hold: PredictManager for Predict, BalanceManager for V3.

DarkPool users interact with two distinct account-style shared objects:

| Object           | Owns                                                               | Used by                                          |
| ---------------- | ------------------------------------------------------------------ | ------------------------------------------------ |
| `PredictManager` | DUSDC balance + position entries `(oracle, expiry, strike, is_up)` | Predict price markets (`/markets`)               |
| `BalanceManager` | DUSDC + YES + NO coin balances + open V3 orders                    | DeepBook V3 pools (event markets, vault, agents) |

The **same user can hold both**. They're for different markets. The wallet UX on `/profile` exposes the PredictManager controls; the agent wizard on `/agents` creates BalanceManagers for delegated trading.

## PredictManager

Created via `predict::create_manager`. After Predict shares the new manager internally, the script picks the new id from `objectChanges` and writes it to `AGENT_PREDICT_MANAGER_ID`.

Fund it via `predict_manager::deposit<T>`. The wallet splits a DUSDC coin and credits the manager's internal balance. Required before any `predict::mint`.

Frontend hook: `useMyManagers` discovers all managers owned by the connected address and surfaces them on `/profile` (one active prominently, others collapsed behind a toggle).

```typescript theme={"system"}
import { buildCreatePredictManagerPTB, buildDepositToPredictManagerPTB, buildWithdrawFromPredictManagerPTB } from '@/lib/ptb';

// Create
const tx = buildCreatePredictManagerPTB();

// Deposit $50 DUSDC
const tx = buildDepositToPredictManagerPTB({ managerId, amountMicro: 50_000_000 });

// Withdraw $20 DUSDC
const tx = buildWithdrawFromPredictManagerPTB({ managerId, amountMicro: 20_000_000 });
```

<Note>
  After a deposit / withdraw, `PredictAccountControls.refetchAccount()` replaces a one-shot refetch with `awaitBalanceChange`. 6 × 500ms polls of `acct.refetch()` that exit as soon as wallet OR manager balance differs from the pre-tx snapshot. This papers over Sui RPC eventual-consistency on `getCoins`.
</Note>

## BalanceManager

The DeepBook V3 BalanceManager is a shared account object owning DUSDC + open V3 orders. Two roles can act on it:

* **Owner.** Deposits / withdraws via `balance_manager::deposit` / `withdraw_all`. Owner-only by Move check.
* **TradeCap holder.** Places / cancels orders via `pool::place_limit_order` / `pool::swap_exact_quantity`. Cannot withdraw.

Created three ways in DarkPool:

1. **Dark-pool vault.** `scripts/create-darkpool-vault.ts` mints a fresh BalanceManager in one PTB, shares it, mints a TradeCap to the keeper. The vault stores both ids.
2. **Agent.** The `/agents` Create-agent wizard does the same plus `agent::register_agent`.
3. **Seeder.** `scripts/seed-v3-liquidity.ts` mints + uses + reshares one BalanceManager in a single PTB for two-sided liquidity provisioning.

## How they relate

A dark-pool vault's BalanceManager holds the YES + NO + DUSDC across **all depositors**. An agent's BalanceManager holds **only that agent's** DUSDC. Both are TradeCap-delegated so the trading party (keeper / agent runtime) is separated from the withdrawal party (vault admin / agent owner).

For users trading on `/markets` (Predict price markets), only the PredictManager is involved. V3 BalanceManager is invisible. For users trading on `/event-markets/:id` (DeepBook V3 pools), the swap goes through their connected wallet directly, no BalanceManager required. `pool::swap_exact_quantity` accepts a free coin in.
