magicsvm 0.2.1

A fast and lightweight Solana + MagicBlock VM simulator for testing solana programs
<div align="center">
    <img src="./magicsvm-logo.png" width="50%" height="50%">
</div>

# MagicSVM

MagicSVM is a fork of [LiteSVM](https://github.com/LiteSVM/litesvm) adapted for
[MagicBlock](https://www.magicblock.xyz/) [Ephemeral Rollups](https://docs.magicblock.gg/).
It keeps LiteSVM's fast, in-process Solana VM and adds a second ledger so you can
test programs that delegate accounts, execute inside an Ephemeral Rollup, and
commit state back — without a validator or an ER node.

Pair it with [`ephemeral-rollups-sdk`](https://github.com/magicblock-labs/ephemeral-rollups-sdk)
to build the same CPIs and client instructions your production programs use.

## Features

- **Dual ledger** — base (Solana L1) and ephemeral (the rollup) in one process
- **Delegation lifecycle** — sending a DLP or Magic-program instruction is
  enough; MagicSVM applies delegate, commit, and undelegate itself
- **Post-delegation and post-commit actions** — cleartext or validator-encrypted
  ephemeral actions, plus `CallHandler` / intent bundles on base
- **Ephemeral-only accounts** — create, resize, and close via the Magic program
- **Ephemeral ATAs (EATA)** — SDK-built instructions; MagicSVM projects a
  delegated EATA onto the canonical SPL ATA on ephemeral
- **Access control** — private accounts stay hidden unless the caller
  is a permission member
- **Programs loaded by default** — DLP on base, Magic program on ephemeral,
  ESPL and the permission program on both, plus vaults and a validator identity
- **LiteSVM surface** — airdrop, `set_account`, compute budget, sigverify,
  sysvars, and the rest of LiteSVM's API; typically **10× or more faster** than
  `solana-program-test` / `solana-test-validator`

## Installation

**Rust**

```toml
[dev-dependencies]
magicsvm = { git = "https://github.com/magicblock-labs/magicsvm" }
```

**Node.js**

```sh
yarn add @magicblock-labs/magicsvm
```

Full setup is in [docs/installation.md](docs/installation.md).

## Usage

Default methods hit base. Pass an explicit target for the rollup.

**Rust**

```rust
use magicsvm::{MagicSVM, TransactionTarget};

let mut svm = MagicSVM::new();

svm.send_transaction(tx)?; // base
svm.send_transaction_to(TransactionTarget::Ephemeral, tx)?;

let on_base = svm.get_account(&pubkey);
let on_ephemeral = svm.get_account_for(TransactionTarget::Ephemeral, &pubkey);
```

**Node.js**

```ts
import { MagicSVM } from "@magicblock-labs/magicsvm";

const svm = new MagicSVM();

svm.sendTransaction(tx); // base
svm.sendTransaction(tx, { target: "ephemeral" });

const onBase = svm.getAccount(pubkey);
const onEphemeral = svm.getAccountFor(pubkey, { target: "ephemeral" });
```

Runnable copies of a full delegate → increment → undelegate flow are in
[examples/](examples/README.md).

## Docs and examples

- **[docs/]docs/README.md** — dual ledger, delegation, EATA, ephemeral-only
  accounts, access control
- **[examples/]examples/README.md** — copyable Rust and Node projects

## Bugs and feature requests

Please open an issue if you find a bug or have a feature request.

## License

MagicSVM is licensed under the Apache 2.0 license.

## Credits

MagicSVM is a fork of [LiteSVM](https://github.com/LiteSVM/litesvm) by
[Aursen](https://github.com/Aursen) and contributors. LiteSVM draws
heavily on [solana-program-test](https://crates.io/crates/solana-program-test)
and is also inspired by [bankrun](https://github.com/kevinheavey/solana-bankrun),
[Anchor Bankrun](https://github.com/kevinheavey/anchor-bankrun) and the work of
[Joey Meere](https://github.com/joeymeere). Huge thanks to all of the upstream
authors.