> For the complete documentation index, see [llms.txt](https://velora-1.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://velora-1.gitbook.io/docs/instruction-reference/cancel.md). Agents can also search and read this documentation through its [MCP server](https://velora-1.gitbook.io/docs/~gitbook/mcp).

# cancel

Cancels an active stream. Tokens that have vested but not yet been claimed go to the recipient; the still-locked remainder is refunded to the creator. The stream moves to `Cancelled` and can no longer be withdrawn.

```rust
pub fn cancel(ctx: Context<CancelStream>) -> Result<()>
```

## Accounts

| Account                   | Signer | Mut | Notes                                                          |
| ------------------------- | ------ | :-: | -------------------------------------------------------------- |
| `authority`               | ✅      |     | Must satisfy `is_cancellable` + `cancel_authority`.            |
| `stream_config`           |        |  ✅  | PDA; `status` set to `Cancelled`.                              |
| `vault`                   |        |  ✅  | PDA; both transfers come out of here.                          |
| `recipient_token_account` |        |  ✅  | Owned by `stream_config.recipient`. Receives vested-unclaimed. |
| `creator_token_account`   |        |  ✅  | Owned by `stream_config.creator`. Receives the locked refund.  |
| `token_program`           |        |     | SPL Token program.                                             |

No parameters.

## Authorization (`cancel_authority`)

Cancellation first requires `is_cancellable == true` (else `CancellationDisabled`). Then:

| `cancel_authority` | Who may cancel           |
| ------------------ | ------------------------ |
| `CreatorOnly`      | creator only             |
| `Either`           | creator or recipient     |
| `Neither`          | nobody (always rejected) |

## Behavior

1. Check `is_cancellable` and `cancel_authority` against the signer.
2. Require `status` is not already `Cancelled` and not `Completed`.
3. `unlocked = compute_unlocked(...)`; require `unlocked < total_amount` (a fully-vested stream cannot be cancelled — use `withdraw`).
4. `unlocked_unclaimed = unlocked - amount_claimed`.
5. `locked = vault.amount - unlocked_unclaimed`.
6. Transfer `unlocked_unclaimed` to the recipient (if > 0).
7. Transfer `locked` back to the creator (if > 0).
8. Set `amount_claimed = unlocked`, `status = Cancelled`.

## Errors

| Code                           | Cause                                                                     |
| ------------------------------ | ------------------------------------------------------------------------- |
| `CancellationDisabled`         | `is_cancellable == false`                                                 |
| `Unauthorized`                 | Signer not allowed by `cancel_authority`, or token-account owner mismatch |
| `AlreadyCancelled`             | Stream already `Cancelled`                                                |
| `FullyVested`                  | Stream is `Completed`, or everything has already unlocked                 |
| `InvalidVault` / `InvalidMint` | Vault / mint mismatch                                                     |
| `MathOverflow`                 | Arithmetic overflow while splitting balances                              |

## Example (TypeScript / Anchor)

```ts
await program.methods
  .cancel()
  .accounts({
    authority: creator.publicKey, // or recipient when cancel_authority = Either
    streamConfig,
    vault,
    recipientTokenAccount,
    creatorTokenAccount,
    tokenProgram: TOKEN_PROGRAM_ID,
  })
  .signers([creator])
  .rpc();
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://velora-1.gitbook.io/docs/instruction-reference/cancel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
