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

# Depositing and Withdrawing from Vaults

> How to deposit and withdraw from UpBots trading vaults — including token approval, unstake requests, deposit history queries, and fee behaviour.

Every vault accepts deposits and withdrawals through a pair of REST endpoints backed by on-chain events. When you deposit, the backend records the transaction and tracks your position. When you withdraw, it records the outflow and adjusts your reported balance. The backend also listens for on-chain `Transfer` events and automatically reconciles any transactions it might have missed, applying deposit and withdrawal fees from the vault entity.

<Warning>
  Fees are applied at the smart contract level and are non-refundable. Always check the vault's `depositFee` and `withdrawalFee` fields before transacting.
</Warning>

## Depositing

<Steps>
  <Step title="Connect your wallet">
    Open the vault detail page and connect your Web3 wallet. The UI initialises a Web3Modal session and reads your on-chain balance for the vault's `currency1` token.
  </Step>

  <Step title="Approve the token">
    Before the first deposit into any vault, you must approve the vault's `contractAddress` to spend your tokens. This is a standard ERC-20 `approve` transaction and requires a gas fee.
  </Step>

  <Step title="Enter an amount and deposit">
    Enter the amount of `currency1` you want to deposit. Confirm the transaction in your wallet. Once the transaction is confirmed on-chain, call the deposit recording endpoint below.
  </Step>

  <Step title="Record the deposit">
    POST the transaction details to the API so your position is tracked off-chain:

    ```http theme={null}
    POST /vaults/deposit
    ```

    **Request body:**

    <ParamField body="tx" type="string" required>
      The on-chain transaction hash of the deposit.
    </ParamField>

    <ParamField body="vaultId" type="string" required>
      The ID of the vault you deposited into.
    </ParamField>

    <ParamField body="account" type="string" required>
      Your wallet address.
    </ParamField>

    <ParamField body="amount" type="number" required>
      The amount deposited, in `currency1` units.
    </ParamField>
  </Step>
</Steps>

<Note>
  The platform automatically reconciles on-chain events periodically. If you skip the POST call, your deposit will still be detected — but there may be a short delay before your balance is reflected.
</Note>

## Withdrawing

<Steps>
  <Step title="Check for an unstake requirement">
    Some vaults require a signed unstake request before a withdrawal can be processed. Check whether you have a pending request:

    ```http theme={null}
    GET /vaults/unstake-requests/all/{account}
    ```

    If the vault requires unstaking and you have no active request, submit one before proceeding.
  </Step>

  <Step title="Submit an unstake request (if required)">
    ```http theme={null}
    POST /vaults/unstake-requests/add
    ```

    <ParamField body="account" type="string" required>
      Your wallet address.
    </ParamField>

    <ParamField body="amount" type="string" required>
      The amount to unstake.
    </ParamField>

    <ParamField body="nonce" type="number" required>
      A unique nonce for the request, used in signature verification.
    </ParamField>

    <ParamField body="contractAddress" type="string" required>
      The vault's contract address.
    </ParamField>

    <ParamField body="signature" type="string" required>
      An EIP-191 signature of the Solidity-encoded hash of `(account, amount, nonce, contractAddress)`, signed by your wallet private key. The server verifies this before creating the request.
    </ParamField>

    The server recovers the signer from the signature and rejects the request if the recovered address does not match `account`.
  </Step>

  <Step title="Execute the withdrawal on-chain">
    Call the vault contract's withdrawal function from your wallet. Confirm the transaction and copy the transaction hash.
  </Step>

  <Step title="Record the withdrawal">
    ```http theme={null}
    POST /vaults/withdraw
    ```

    The request body is identical to `POST /vaults/deposit`: provide `tx`, `vaultId`, `account`, and `amount`.
  </Step>
</Steps>

## Querying your deposit history

### Your net deposit for a single vault

```http theme={null}
GET /vaults/initial-deposit/{vaultId}/{account}
```

Returns `{ amount }` — the sum of all deposits minus the sum of all withdrawals for your account in the specified vault. Account matching is case-insensitive.

### Your net deposit across all vaults

```http theme={null}
GET /vaults/initial-deposit-all/{account}
```

Returns `{ amount }` — your net position across every vault.

### Per-vault breakdown

```http theme={null}
GET /vaults/initial-deposit-all-details/{account}
```

Returns an object keyed by `vaultId`, with each value being the net deposit amount for that vault.

## Fee behaviour

Fees are deducted automatically from your deposit or withdrawal amount by the vault's smart contract:

* **Deposit fee** — deducted when you deposit; your recorded position reflects the amount after the fee.
* **Withdrawal fee** — deducted when you withdraw; the amount you receive is reduced by the fee percentage.

Check the vault's `depositFee` and `withdrawalFee` fields on the vault detail page before transacting.

<Tip>
  You can check a vault's fee structure before depositing by inspecting the `depositFee` and `withdrawalFee` fields returned by `GET /vaults/all` or `GET /vaults/perp-vaults`.
</Tip>
