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

# cbBTC collateral

> Deposit cbBTC and include it in Rise TypeScript and Rust margin calculations.

cbBTC stays in the associated token account (ATA) of the Phoenix trader’s wallet PDA. Phoenix credits the accounted cbBTC balance and values it at the BTC index price. PnL, funding, and trading fees settle in USDC.

Use a registered trader, the trader authority’s signing wallet, and API and RPC endpoints for the same deployment. Check that the cbBTC asset is active using `client.api.collateral().getAssets()` in TypeScript or `http.collateral().get_assets()` in Rust.

## Available instructions

| Action | TypeScript | Rust | Details |
| - | - | - | - |
| Reserve capacity | `buildReallocTraderIx` | `create_realloc_trader_ix` | Reserves a trader map entry for the cbBTC balance. The payer funds any additional rent. |
| Deposit | `buildSpotDepositFlow` | `create_sync_spot_ix` after the SPL token transfer | Reserve capacity, create the custody ATA, transfer cbBTC, and sync the accounted balance. Anyone can submit the sync instruction. |
| Withdraw | `buildWithdrawSpotIx` | `create_withdraw_spot_ix` | The trader authority signs. Use a destination token account for the cbBTC mint. Accounted withdrawals are margin checked and throttled. These builders use the fee-free protocol instruction. |
| Transfer between traders | `buildTransferSpotIx` | `create_transfer_spot_ix` | Reserve capacity on the destination first. Supply the required authority and risk accounts. |
| Sweep child to parent | `buildTransferSpotFromChildToParentIx` | `create_transfer_spot_from_child_to_parent_ix` | Sweep a flat isolated subaccount. Permissionless use depends on the account’s sweep preference. |
| Swap cbBTC and USDC | `buildSwapSpotWithUsdcIx` | `create_swap_spot_with_usdc_ix` | Supply venue instructions and a minimum output in the receiving asset’s units. |
| Liquidate cbBTC | `buildLiquidateSpotIx` | `create_liquidate_spot_ix` | Requires an authorized liquidator or the risk authority, venue instructions, and a maximum seizure amount in cbBTC base units. |

## Deposit cbBTC

Send `ReallocTrader`, create the custody ATA if needed, transfer the SPL tokens into it, and call `SyncSpot` in that order in one transaction. Each asset uses a separate trader map entry. `SyncSpot` credits the balance up to the per-trader and exchange-wide caps. If some tokens remain in custody above those limits, they carry no margin value until a later sync credits them. Read the accounted balance again after confirmation.

The Solana cbBTC mint is `cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij`. It uses `8` decimals, so `0.01 cbBTC` is `1,000,000` base units.

```ts TypeScript theme={null}
import { address } from "@solana/kit";
import {
  buildSpotDepositFlow,
  type Authority,
  type MintAddress,
  type PhoenixInstructionClient,
} from "@ellipsis-labs/rise";

const cbBtcMint = address(
  "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij"
) as MintAddress;

export async function buildCbBtcDeposit(
  client: PhoenixInstructionClient,
  authority: Authority,
  amount = 1_000_000n,
) {
  return buildSpotDepositFlow(
    { authority, mint: cbBtcMint, amount, traderPdaIndex: 0, subaccountIndex: 0 },
    client,
  );
}
```

The helper returns unsigned instructions for the wallet to sign and send. For a sponsored deposit, prepare trader capacity in a separate wallet-paid transaction and pass `traderCapacityPrepared: true` to `buildSpotDepositFlow`.

In Rust, build the same sequence with `create_realloc_trader_ix`, the SPL associated token account and transfer instructions, and `create_sync_spot_ix` with the cbBTC mint. Use the custody ATA for the trader’s wallet PDA as the token transfer destination.

## Compute margin using API data

| Input | cbBTC requirement |
| - | - |
| Balance | Read the accounted balance from the subaccount’s spot collateral entries. Match the collateral asset index from the registry and keep the USDC balance separate. |
| Collateral metadata | Read the mint, decimals, linked pricing market, caps, and margin discount bounds from the collateral registry. |
| Prices | Include the BTC index price even if the trader has no BTC position. Use mark prices for perpetual-position PnL. |
| Existing state | Keep positions, orders, funding, and risk parameters current when recomputing. |

Use the [SDK margin calculation](https://docs.phoenix.trade/sdk/margin.md#local-margin). In TypeScript, pass `resource.marginInputs()` to the calculator returned by `MarginMarketParamsStore.getCalculator()`. In Rust, load exchange metadata and market prices before calling `to_trader_portfolio_with_metadata(&metadata)` and `compute_margin(&metadata)`. Both paths use discounted cbBTC value for effective collateral and the full index-price value for portfolio value.

## View trader margin with Hawkeye

Use [Hawkeye simulation](https://docs.phoenix.trade/sdk/margin.md#hawkeye-simulation) to check the on-chain margin calculation after the deposit confirms. Hawkeye includes the discounted cbBTC balance alongside any other collateral on that subaccount. For the balance itself, read the cbBTC entry in the trader state described in [Accounts](https://docs.phoenix.trade/sdk/accounts.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.