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.
Account size: 2,360 bytes total (8-byte Anchor discriminator + 2,352-byte PortfolioAccount body).
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 (recommended)
Use the exported IDL with@coral-xyz/anchor — this is safer than hand-parsing offsets.
Python integration
For Python developers, useanchorpy to interact with the V2 program.
Manual offset map
Use this only for custom parsers or debugging. Layout matchescontracts/programs/quantdesk-perp-dex/src/state/portfolio.rs (verify against your deployed program version).
Nested struct sizes
[!TIP] Prefer the latest exported IDL from the QuantDesk SDK repository over manual offsets. Regenerate clients after program upgrades.
Related
- Building on QuantDesk — initialize portfolio and place orders
- V2 API endpoints — gateway read path when RPC parsing is not required
- Unified portfolio architecture — why one PDA matters