Parsing the PortfolioAccount buffer
QuantDesk V2 uses a zero-copy architecture for thePortfolioAccount. This maps the raw account data directly into local memory structures, so you get high-performance reads.
Why zero-copy?
Standard Anchor accounts deserialize on every fetch, which is slow and CPU-intensive for large accounts with many positions. Zero-copy lets you:- Avoid deserialization: read fields directly from the buffer.
- Sub-ms latency: critical for high-frequency trading bots.
- Atomic state: fetch balances, positions, and orders in a single RPC call.
TypeScript integration
Use the@coral-xyz/anchor library along with bytemuck-style offsets to decode the buffer.
Python integration
For Python developers, useanchorpy to interact with the V2 program.
Offset mapping
If you are building a custom high-performance parser without a full IDL client, account for the 8-byte Anchor discriminator and the zero-copy memory layout defined in thequantdesk-v2 crate.
| Field | Type | Offset |
|---|---|---|
| Discriminator | [u8; 8] | 0 |
| Owner | Pubkey | 8 |
| Balances | [Balance; 16] | 40 |
| Positions | [Position; 32] | … |
[!TIP] Always use the latest exported IDL from our GitHub repository to ensure offset alignment.