@typesol/cli 0.42.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +350 -0
- package/NOTICE +71 -0
- package/README.md +35 -18
- package/SECURITY.md +32 -5
- package/dist/ai.d.ts +1 -1
- package/dist/ai.js +5 -5
- package/dist/cli.js +196 -72
- package/dist/compiler/analyze.js +447 -12
- package/dist/compiler/diagnostics.d.ts +1 -0
- package/dist/compiler/diagnostics.js +13 -0
- package/dist/compiler/emit/alias.d.ts +45 -1
- package/dist/compiler/emit/alias.js +143 -6
- package/dist/compiler/emit/base.d.ts +28 -1
- package/dist/compiler/emit/base.js +77 -9
- package/dist/compiler/emit/borsh.js +11 -5
- package/dist/compiler/emit/calls.d.ts +80 -0
- package/dist/compiler/emit/calls.js +612 -54
- package/dist/compiler/emit/cpi-core.d.ts +23 -4
- package/dist/compiler/emit/cpi-core.js +261 -12
- package/dist/compiler/emit/cpi.js +8 -2
- package/dist/compiler/emit/create.js +3 -0
- package/dist/compiler/emit/expressions.js +44 -8
- package/dist/compiler/emit/function.js +10 -0
- package/dist/compiler/emit/program.js +30 -1
- package/dist/compiler/emit/rbtree.d.ts +7 -0
- package/dist/compiler/emit/rbtree.js +142 -0
- package/dist/compiler/emit/shared.d.ts +25 -0
- package/dist/compiler/emit/shared.js +45 -4
- package/dist/compiler/emit/statements.d.ts +27 -1
- package/dist/compiler/emit/statements.js +305 -23
- package/dist/compiler/emit/storage.d.ts +25 -2
- package/dist/compiler/emit/storage.js +116 -64
- package/dist/compiler/emit/token.js +2 -2
- package/dist/compiler/emit/views.d.ts +60 -0
- package/dist/compiler/emit/views.js +523 -0
- package/dist/compiler/idl.js +2 -1
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +40 -3
- package/dist/compiler/model.d.ts +65 -4
- package/dist/compiler/model.js +14 -0
- package/dist/compiler/toolchain.d.ts +56 -1
- package/dist/compiler/toolchain.js +246 -12
- package/dist/testing-stake.d.ts +2 -1
- package/dist/testing-stake.js +2 -1
- package/dist/testing.js +6 -4
- package/dist/tools/clientgen.d.ts +15 -0
- package/dist/tools/clientgen.js +173 -7
- package/dist/tools/cpigen.d.ts +0 -15
- package/dist/tools/cpigen.js +19 -8
- package/dist/tools/doctor.d.ts +17 -2
- package/dist/tools/doctor.js +64 -4
- package/dist/tools/portgen.js +43 -18
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.js +173 -6
- package/docs/ai.md +10 -5
- package/docs/architecture.md +10 -3
- package/docs/audit.md +63 -17
- package/docs/case-study-escrow.md +1 -1
- package/docs/case-study-phoenix.md +226 -0
- package/docs/case-study-raydium-amm.md +3 -3
- package/docs/case-study-spl-stake-pool.md +5 -5
- package/docs/cli.md +17 -8
- package/docs/client.md +11 -3
- package/docs/errors.md +1 -1
- package/docs/language.md +148 -12
- package/docs/mainnet.md +21 -10
- package/docs/migrate-from-anchor.md +3 -1
- package/docs/runtime.md +12 -2
- package/docs/security-model.md +38 -6
- package/docs/stability.md +42 -4
- package/docs/testing.md +25 -0
- package/docs/troubleshooting.md +17 -2
- package/lib/typesol.d.ts +221 -4
- package/llms-full.txt +336 -65
- package/llms.txt +2 -2
- package/package.json +4 -2
- package/runtime/typesol_rt.h +429 -13
- package/test/programs/LICENSE-Apache-2.0.txt +201 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Case study: Phoenix v1
|
|
2
|
+
|
|
3
|
+
This page ports [Phoenix v1](https://github.com/Ellipsis-Labs/phoenix-v1), Ellipsis Labs' on-chain limit order book:
|
|
4
|
+
a central limit order book that matches and settles in the same instruction, price first and first in, first out
|
|
5
|
+
within a price, with no crank. Its repository now calls it Phoenix Legacy. The port is checked against the binary
|
|
6
|
+
that runs on mainnet as `PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY` (deployed in slot 231433470, 2023-11-21), not a
|
|
7
|
+
rebuild.
|
|
8
|
+
|
|
9
|
+
**Which source.** Commit c16694d rebuilt with `solana-verify build --library-name phoenix` (Solana 1.14.9) gives the
|
|
10
|
+
deployed executable's hash (`6877a5b732b3494b828a324ec846d526d962223959534dbaf4209e0da3b2d6a9`); OtterSec's
|
|
11
|
+
verification registry lists the program as verified from that commit. The repository was under BUSL 1.1 at c16694d;
|
|
12
|
+
on 2026-05-11 Ellipsis Labs relicensed it under the MIT License (5a34f7f) with the program's sources unchanged since
|
|
13
|
+
c16694d, so the port follows c16694d under MIT ([`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)).
|
|
14
|
+
|
|
15
|
+
Phoenix is a native program built with solana-program 1.14: a u8 tag, the instruction's Borsh arguments after it,
|
|
16
|
+
accounts by position. A market is one account: a 576-byte header, then a `FIFOMarket` whose bids, asks and traders are
|
|
17
|
+
three lib-sokoban `RedBlackTree`s laid out in the account's bytes (sized by the header: twelve size sets, up to 4,096
|
|
18
|
+
orders a side and 8,321 seats), read and written in place. Phoenix does not log its market events: it sends them to
|
|
19
|
+
itself in Log instructions, self-CPIs signed by a log-authority PDA, so clients read them from the inner instructions.
|
|
20
|
+
The order instructions return the ids of the orders that rested as return data, and the program's failures are often
|
|
21
|
+
Rust panics in solana-program 1.14's format, at the original's source locations.
|
|
22
|
+
|
|
23
|
+
| File | Holds |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| [`phoenix.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/phoenix.ts) | the entrypoint (one `@fallback` over `instructionData()` and `remainingAccounts()`): the four accounts every instruction starts with, the event recorder, dispatch to the 28 tags |
|
|
26
|
+
| [`state.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/state.ts), [`errors.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/errors.ts) | MarketHeader, the FIFOMarket prefix, the tree keys and values, Seat, PhoenixMarketEvent, the instruction arguments, PhoenixError from code 0 |
|
|
27
|
+
| [`checkers.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/checkers.ts), [`util.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/util.ts) | the account checks in the original's order, the market loader with its twelve sizes; PDAs, the quantity operators with their panics, the token CPIs |
|
|
28
|
+
| [`recorder.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/recorder.ts) | the event recorder: batches of events sent in Log self-CPIs whenever the next event would not fit |
|
|
29
|
+
| [`matching.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/matching.ts), [`book.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/book.ts) | the FIFOMarket: place_order_inner, match_order, check_for_cross, eviction; reduce_order_inner and the cancels built on it |
|
|
30
|
+
| `orders.ts`, `cancel.ts`, `initialize.ts`, `governance.ts`, `seats.ts`, `funds.ts`, `fees.ts` | the instructions by subject |
|
|
31
|
+
|
|
32
|
+
## What is ported
|
|
33
|
+
|
|
34
|
+
All 28 tags: Swap and SwapWithFreeFunds (0, 1), PlaceLimitOrder and its free-funds form (2, 3), ReduceOrder (4, 5),
|
|
35
|
+
CancelAllOrders (6, 7), CancelUpTo (8, 9), CancelMultipleOrdersById (10, 11), WithdrawFunds (12), DepositFunds (13),
|
|
36
|
+
RequestSeat (14), Log (15), PlaceMultiplePostOnlyOrders (16, 17), and the authority's InitializeMarket,
|
|
37
|
+
ClaimAuthority, NameSuccessor, ChangeMarketStatus, ChangeSeatStatus, RequestSeatAuthorized, EvictSeat,
|
|
38
|
+
ForceCancelOrders, CollectFees and ChangeFeeRecipient (100 to 109). Every order type (PostOnly, Limit, ImmediateOrCancel
|
|
39
|
+
and fill-or-kill, with base or quote budgets, minimum fills, match limits, the three self-trade behaviours, time in
|
|
40
|
+
force, fail-silent orders), free funds, taker fees, eviction from a full book, the order packet decoder with its
|
|
41
|
+
zero-padding retries, the market's statuses down to Tombstone, and the events byte for byte.
|
|
42
|
+
|
|
43
|
+
## What it needed
|
|
44
|
+
|
|
45
|
+
TypeSOL gained these features for it (docs/language.md, "Porting a native program"); programs that use none of them
|
|
46
|
+
compile to the same C as before:
|
|
47
|
+
|
|
48
|
+
- **lib-sokoban's RedBlackTree** over account bytes, `rbTreeAt` / `rbTreeMutAt`: `get`, `insert`, `remove`, `min`,
|
|
49
|
+
`max`, `addrOf`, `nodeAt`, walks both ways, with a comparator of the program (Phoenix orders bids by inverted sequence
|
|
50
|
+
numbers). It runs sokoban's code statement for statement, so the bytes are the crate's: replayed against the real
|
|
51
|
+
crate with identical bytes after every operation, on the 21,650 recorded operations of the committed test (seeds
|
|
52
|
+
1–3, capacities 1 to 4096, strides 32, 64 and 144) and, with the previous trace generator, on a one-off run of
|
|
53
|
+
1,020,000 (capacities 1 to 512); sokoban's panics come out with its messages and source lines.
|
|
54
|
+
- **`removeAt(index)`**: the node `addrOf`, `min` or `max` found, removed with `remove(key)`'s writes and no second
|
|
55
|
+
search (the trace replay runs again with every `remove(key)` as `removeAt(addrOf(key))`). The port uses it where
|
|
56
|
+
Phoenix finds an order and then removes it: 62 to 103 compute units less per cancelled order (more in deeper books),
|
|
57
|
+
about 100 per order a match fills whole, 190 to 360 per eviction.
|
|
58
|
+
- **Cheaper tree walks** (one bounds check per node, the stack by pointer) and an **owner-check cache** for native
|
|
59
|
+
views (the market viewed again passes with a pointer compare): Phoenix's helpers each view the market again, often in
|
|
60
|
+
loops that write it.
|
|
61
|
+
- **Data enums by `pushBorsh`, straight-line**: `data.pushBorsh<PhoenixMarketEvent>({ kind: "Fill", … })` writes only
|
|
62
|
+
that variant, one room check and a store per field. Every event is appended to the batch this way: 47 compute units
|
|
63
|
+
less per Reduce event than the six `pushLE` calls it replaced, each of which checked the room of the batch (an
|
|
64
|
+
`Inout` parameter) on its own, and 55 to 70 less per Fill, Place, FillSummary, Evict or ExpiredOrder than serializing
|
|
65
|
+
the whole enum.
|
|
66
|
+
- **Struct arguments in place**: an owned struct (a local, a parameter passed on) goes to a helper that takes accounts by
|
|
67
|
+
pointer, so the book helpers take their MarketShape as a plain struct, not `Inout<T>`.
|
|
68
|
+
- **`Inout<T>`** helper parameters (Rust's `&mut`: the recorder and its 1,280-byte batch passed down the matching
|
|
69
|
+
engine), **`/** @noinline */`** and **`/** @heap */`** (room beyond one 4 KiB stack frame), local lists of 2 KiB
|
|
70
|
+
(asked for by a 2,052-byte list of collected order ids; the port keeps the 512 ids as u16 node indices).
|
|
71
|
+
- **Native-program foundations**: `loadRawAt` / `loadRawMutAt` (a struct at a run-time offset), `NATIVE_ACCOUNT_WRITES`
|
|
72
|
+
(views of one account written in place, judged by the runtime), byte builders (`pushLE`, `pushKey`, `pushBorsh`,
|
|
73
|
+
`setLE`, `truncate`) and `invokeInstruction` for the Log self-CPI, `setReturnData` and `logComputeUnits`, `closeRaw`
|
|
74
|
+
for Tombstone, `findProgramAddressWithBump`, errors from code 0 that log nothing (`ERROR_LOG_PREFIX = null`), and
|
|
75
|
+
panics as solana-program 1.14 writes them (`PANIC_STYLE = "solana-1.14"`, `panicsAt` for Rust's overflow messages at
|
|
76
|
+
the original's locations).
|
|
77
|
+
- **Source-level conveniences** the port reads better with: constant expressions (`EVENT_ROOM =
|
|
78
|
+
MAX_INNER_INSTRUCTION_SIZE - LOG_IX_ACCOUNT_META_SIZE`, the node sizes, `BIDS_OFFSET`), file-local structs for
|
|
79
|
+
helper-only types (left out of the IDL), comma-separated `for` updates, and read-only views read where they are made
|
|
80
|
+
(`loadRaw<MarketHeader>(m).status`).
|
|
81
|
+
|
|
82
|
+
## How it is checked
|
|
83
|
+
|
|
84
|
+
The mainnet binary and the port run in two LiteSVMs under the same program id and the same Clock
|
|
85
|
+
([`phoenix-helpers.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/phoenix-helpers.ts)). Every account is made the same way in both, and every
|
|
86
|
+
transaction must give:
|
|
87
|
+
|
|
88
|
+
- the same outcome;
|
|
89
|
+
- the same log lines, every one: the original's messages and numbers, panics with their locations, the batch lines of
|
|
90
|
+
the recorder (Phoenix's own "Program consumption" lines by count and position; only the runtime's "consumed N of M
|
|
91
|
+
compute units" lines are left out);
|
|
92
|
+
- the same inner instructions in order, each one's program, accounts and data bytes: the Log self-CPIs, so every event
|
|
93
|
+
batch is compared byte for byte, and the token transfers;
|
|
94
|
+
- the same return data;
|
|
95
|
+
- the same lamports, owner and bytes in every account the transaction names (the books and the traders tree byte for
|
|
96
|
+
byte, rotations and colours included).
|
|
97
|
+
|
|
98
|
+
There are 3,575 such transactions in five files, on markets of 512 orders and 128 seats and of 4,096 and 8,321 (each
|
|
99
|
+
file fails unless it compares exactly its own count):
|
|
100
|
+
|
|
101
|
+
- **The non-matching instructions** (`phoenix.test.ts`; 824): the entry's checks for all 28 tags, InitializeMarket with
|
|
102
|
+
each of the twelve sizes and every refusal, the authority's instructions, seats, deposits and withdrawals, fees.
|
|
103
|
+
- **Orders and matching** (`phoenix-orders.test.ts`; 1,117): every order type on both sides, crossings of many levels,
|
|
104
|
+
self trades, match limits, minimum fills, budgets, fees (100% included), free funds, multiple-order grouping and its
|
|
105
|
+
failure behaviours, a full book (eviction and rejection), time in force, the sequence number's limit, matches whose
|
|
106
|
+
events take several Log batches (300 fills), the packet decoder on cut and invalid packets.
|
|
107
|
+
- **Reductions and cancels** (`phoenix-cancel.test.ts`; 390): the orders are placed by the original and its bytes
|
|
108
|
+
copied into the port's VM, so both start from the trees Phoenix itself wrote; partial, whole and oversized reductions,
|
|
109
|
+
foreign and unknown orders, every cancel form with its limits, ForceCancelOrders and EvictSeat, 90 to 512 cancels in
|
|
110
|
+
one instruction, the out-of-memory abort at the 513th, books of up to 8,000 orders, the overflow and division panics.
|
|
111
|
+
- **The original's own tests** (`phoenix-upstream.test.ts`; 1,082): each of the 50 test functions at c16694d (the
|
|
112
|
+
integration tests, the matching engine's unit tests, the packet decoder's) is mapped to a case
|
|
113
|
+
([the mapping](https://github.com/typesol-lang/typesol/blob/main/showcase/test/phoenix-upstream.md)): 11 were covered already, 37 are added there and run whole,
|
|
114
|
+
2 are not applicable (compile-time type checks of the quantity macros). Each refusal the upstream test expects is
|
|
115
|
+
pinned to the original's error and message, and the upstream test's own assertions (balances, the book, free lots,
|
|
116
|
+
the sequence number, fees) are made on chain.
|
|
117
|
+
- **The limits** (`phoenix-limits.test.ts`; 162): markets with a tick size or a base lot of 0 (the divisions' panics),
|
|
118
|
+
a negative clock, multiple-order packets longer than a transaction carries, and both sides of each of the heap's
|
|
119
|
+
boundaries, through a forwarding caller program where a CPI is needed (see Differences).
|
|
120
|
+
|
|
121
|
+
States no instruction reaches in a test's time (fees accrued, a sequence number near its maximum, a damaged lot size)
|
|
122
|
+
are written into both VMs' bytes, and each test checks the outcome too, so that every error path is really reached.
|
|
123
|
+
Every compared transaction's compute units are kept, and each file fails unless the port uses fewer on every
|
|
124
|
+
transaction that succeeds: 2,390 of the 3,575.
|
|
125
|
+
|
|
126
|
+
**A random walk over the order book** (`phoenix-fuzz.test.ts`, not in those counts) runs a 512/128 and a 4096/8321
|
|
127
|
+
market, each book started nearly full of orders far from the action: seated makers and unseated takers deposit and
|
|
128
|
+
withdraw, place every kind of order with tokens or free funds, reduce and cancel (with others', unknown, wrong-side and
|
|
129
|
+
bit-flipped ids), the authority changes seats, forces cancels, evicts, collects fees and changes the market's status,
|
|
130
|
+
the clock moves on so orders expire, and some packets are corrupted. Every step goes through the same comparison, and
|
|
131
|
+
an oracle checks after each that the registered traders' locked and free lots plus the uncollected fees are exactly
|
|
132
|
+
what the vaults hold. A walk's choices and every keypair come from its seed, so a seed reproduces it. By default the
|
|
133
|
+
test walks seeds 1, 2 and 3 on both markets, 300 steps each (1,801 transactions), and requires minimum counts of real
|
|
134
|
+
effects decoded from the event batches (fills, partial fills, orders rested, self trades, expiries, evictions, fees)
|
|
135
|
+
and a minimum share of successes for every kind of instruction. `FUZZ_SEED` walks another seed and
|
|
136
|
+
`PHOENIX_FUZZ_STEPS` changes the length; a walk of 1,000 steps or more must also have every main kind of instruction
|
|
137
|
+
succeed and each book fill up and evict. Before the walk drew its keys from the seed, a one-off run of five seeds (1
|
|
138
|
+
and 1794299110079 at 1,000 steps, 2, 3 and 4 at 3,000; 21,593 transactions) found no difference.
|
|
139
|
+
|
|
140
|
+
## Cost
|
|
141
|
+
|
|
142
|
+
Compute units per transaction, mainnet original against the port, from those tests (the token CPIs are the same work
|
|
143
|
+
in both; the account checks that derive PDAs vary with the bumps the keys need, each further bump about 1,500 units
|
|
144
|
+
in the original and 341 in the port, and a few rows by a few dozen units from run to run: a range is what two runs of
|
|
145
|
+
the five files gave, and `InitializeMarket`'s covers its twelve sizes):
|
|
146
|
+
|
|
147
|
+
| Instruction | Original | TypeSOL | |
|
|
148
|
+
| --- | ---: | ---: | ---: |
|
|
149
|
+
| `InitializeMarket` | 79,146–97,353 | 10,940–15,035 | 14–15% |
|
|
150
|
+
| `RequestSeat` | 14,900 | 4,599 | 31% |
|
|
151
|
+
| `DepositFunds` | 20,441 | 6,176 | 30% |
|
|
152
|
+
| `WithdrawFunds` | 17,760 | 6,201 | 35% |
|
|
153
|
+
| `CollectFees` | 13,814 | 4,977 | 36% |
|
|
154
|
+
| `PlaceLimitOrder`, PostOnly | 20,577–25,077 | 6,452–7,475 | 30–31% |
|
|
155
|
+
| `PlaceLimitOrder`, Limit, resting | 21,971–23,471 | 7,066–7,407 | 32% |
|
|
156
|
+
| `Swap`, 2 fills | 22,809–22,886 | 8,178–8,196 | 36% |
|
|
157
|
+
| `Swap`, 30 fills | 61,313–61,390 | 26,344–26,362 | 43% |
|
|
158
|
+
| `PlaceLimitOrder`, Limit through 20 fills, then resting | 108,397–114,399 | 52,894–54,260 | 47–49% |
|
|
159
|
+
| `PlaceMultiplePostOnlyOrders`, 5 orders in 4 levels | 34,605–40,614 | 13,324–14,698 | 36–39% |
|
|
160
|
+
| `ReduceOrder` | 15,235 | 5,170 | 34% |
|
|
161
|
+
| `CancelMultipleOrdersById`, 1 order | 15,984 | 5,708 | 36% |
|
|
162
|
+
| `CancelMultipleOrdersByIdWithFreeFunds`, 50 orders | 67,793–67,871 | 38,527–38,547 | 57% |
|
|
163
|
+
| `CancelUpTo`, 3 orders | 18,349–18,367 | 7,312 | 40% |
|
|
164
|
+
| `CancelAllOrdersWithFreeFunds`, 90 orders | 115,366 | 69,762 | 60% |
|
|
165
|
+
| `EvictSeat` | 22,966–33,466 | 7,306–9,693 | 29–32% |
|
|
166
|
+
|
|
167
|
+
At the extremes: a match of 300 fills in three Log batches 443,217–443,295 against 217,847–217,867 (49%);
|
|
168
|
+
`CancelAllOrders` of 512 orders in a 4,096 book 760,087 against 434,446 (57%), and of 200 among 8,000 orders 1,184,623
|
|
169
|
+
against 471,050 (40%); `CancelUpTo` searching 1,500 orders 1,002,398–1,002,399 against 456,958–456,960 (46%); the
|
|
170
|
+
513th collected id runs both out of memory after 90,220 and 30,363.
|
|
171
|
+
|
|
172
|
+
The binary is 256,360 bytes against the original's 1,344,472.
|
|
173
|
+
|
|
174
|
+
## Differences
|
|
175
|
+
|
|
176
|
+
What the port does not reproduce, and how a transaction would reach it:
|
|
177
|
+
|
|
178
|
+
- **Compute.** The port spends 13–61% of the original's units (up to 86% in `phoenix-limits.test.ts`, whose
|
|
179
|
+
transactions carry hundreds of account entries or go through a forwarding program), so a transaction that runs the
|
|
180
|
+
original out of its compute budget can complete in the port; the tests give both enough.
|
|
181
|
+
- **Memory, counted.** Phoenix allocates on solana-program 1.14.9's bump heap: 32 KiB from the top down, never freed,
|
|
182
|
+
and an allocation past it aborts with "Error: memory allocation failed, out of memory". The port keeps its own lists
|
|
183
|
+
fixed and counts Phoenix's heap instead ([`heap.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/phoenix/heap.ts)), charge by charge as the
|
|
184
|
+
Rust allocates: the entrypoint's 48 bytes per account entry and 72 per distinct account, the discriminant lines, the
|
|
185
|
+
event recorder, the status checks' messages (built even when they pass), each batch line, each SPL Token transfer's
|
|
186
|
+
instruction, the cancels' boxed tree iterators with their stacks and the ids they collect, CancelMultipleOrdersById's
|
|
187
|
+
decoded list and kept ids, the multiple-order packet's decoded lists, its sorts (the merge sort's buffer and stack of
|
|
188
|
+
runs) and the "Insufficient funds" lines of the orders it skips, the placed order ids and their Borsh bytes. So a
|
|
189
|
+
transaction that fills the heap (with up to 255 account entries, which Phoenix ignores past the ones it reads, or with
|
|
190
|
+
a CPI's larger instruction data) aborts in the port at the same allocation, after the same log lines and batches.
|
|
191
|
+
[`phoenix-limits.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/phoenix-limits.test.ts) finds the original's boundary and compares both
|
|
192
|
+
sides of it (one account entry fewer succeeds, the next aborts) for CancelAllOrders and its free-funds form (257 to
|
|
193
|
+
512 orders, bids and asks, 4 to 20 accounts of their own, top-level and through a CPI), CancelUpTo with a count and
|
|
194
|
+
with a search limit, ForceCancelOrders, CancelMultipleOrdersById through a CPI (230 and 340 entries; 341 always runs
|
|
195
|
+
out), and PlaceMultiplePostOnlyOrders through a CPI (decoded lists past their first 85 orders, scrambled sides, 130
|
|
196
|
+
resting orders, token deposits, skipped orders).
|
|
197
|
+
- **More than a transaction carries.** A CPI passes up to 10,240 bytes of instruction data, so a multiple-order packet
|
|
198
|
+
is decoded whatever its length, as Phoenix decodes it: past 170 orders a side always runs out of memory at its sort,
|
|
199
|
+
and past 340 while decoding; from 64 resting orders set_return_data refuses the ids (1,028 bytes and up), after every
|
|
200
|
+
order is placed and every batch sent, in both.
|
|
201
|
+
- **Memory, not counted.** What Phoenix formats only when it fails is not charged: assert_with_msg's line with its
|
|
202
|
+
location, the formatted failure lines (an IOC's minimum fill, "Market is not active, …"), the String of a Borsh
|
|
203
|
+
decoding error, the panic handler's line. Phoenix builds each on the heap before it reports the failure, so when the
|
|
204
|
+
heap no longer has room for it Phoenix aborts with the out-of-memory line (ProgramFailedToComplete) where the port
|
|
205
|
+
logs the failure and returns its error. A transaction gets there only by failing after it has nearly filled the
|
|
206
|
+
heap. For instance a forwarded multiple-order packet of 300 bids whose asks are cut short fails with BorshIoError in
|
|
207
|
+
both with few account entries and runs out of memory in both (its decoded Vec's last growth) with many; in between,
|
|
208
|
+
at one account count, Phoenix runs out of memory building the error's message (about 100 bytes) while the port
|
|
209
|
+
returns BorshIoError. A formatted failure line after a long match would need the same kind of near-full heap.
|
|
210
|
+
Neither are InitializeMarket's, CollectFees' and the seat and governance
|
|
211
|
+
instructions' own lines and vectors charged (only their batches): with at most 128 distinct accounts, the most a
|
|
212
|
+
transaction locks, they stay far below the heap. A Limit order's crossing check (a boxed iterator) and a match's
|
|
213
|
+
batches are counted, but no test reaches the limit with them: it takes a match of about a thousand fills and more
|
|
214
|
+
distinct accounts than a transaction holds without lookup tables.
|
|
215
|
+
- **Damaged trees.** A tree walk keeps its stack of 64 nodes on the program's stack, more than any red-black tree a u32
|
|
216
|
+
index can address holds on one path; only damaged registers go deeper, and the port panics where sokoban's heap stack
|
|
217
|
+
would grow. The panics of a node index out of range (`nodeAt` on damaged registers) take their locations from
|
|
218
|
+
sokoban's source, not from the binary.
|
|
219
|
+
- **Paths v1 never takes.** An order of zero lots on a book (only bytes written by hand put one there) is removed as
|
|
220
|
+
the original removes it: a cancel meeting one is tested, the matching engine's two such paths ("Empty order found in
|
|
221
|
+
check_for_cross", a tombstone met while matching) are ported but not reached by a test. The unclean-division warning
|
|
222
|
+
of a bid's unlock, which no market InitializeMarket accepts can produce, is tested on written bytes.
|
|
223
|
+
|
|
224
|
+
The tests run on LiteSVM without account-data direct mapping; both programs write the market in place, so both would
|
|
225
|
+
fault at the same write. The runtime truncates a transaction's log at 10,000 bytes at a point that depends on the
|
|
226
|
+
compute-unit lines, which differ by design, so the harness lifts that limit to compare the whole log.
|
|
@@ -11,9 +11,9 @@ its own errors. The port keeps all of that.
|
|
|
11
11
|
|
|
12
12
|
| File | Holds |
|
|
13
13
|
| --- | --- |
|
|
14
|
-
| [`raydium_amm.ts`](
|
|
15
|
-
| [`state.ts`](
|
|
16
|
-
| [`math.ts`](
|
|
14
|
+
| [`raydium_amm.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/raydium-amm/raydium_amm.ts) | the entrypoint (one `@fallback` over `instructionData()` and `remainingAccounts()`), every instruction, the token and system CPIs, the P&L calculation |
|
|
15
|
+
| [`state.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/raydium-amm/state.ts) | AmmInfo (752 bytes), TargetOrders, AmmConfig, Fees, the ray_log records, the 61 errors (codes 0–60) |
|
|
16
|
+
| [`math.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/raydium-amm/math.ts) | decimal normalization, the constant-product amounts, the exchange rates, with the original's panics at their places |
|
|
17
17
|
|
|
18
18
|
## What is ported
|
|
19
19
|
|
|
@@ -10,7 +10,7 @@ deployed code carries a fee-cap message main only gained later. The tag `program
|
|
|
10
10
|
branch) rebuilt with `solana-verify build --library-name spl_stake_pool --base-image
|
|
11
11
|
solanafoundation/solana-verifiable-build:3.1.14` gives the deployed executable's hash
|
|
12
12
|
(`8df58bc9f9428c02bf34fa845ae2961274156e7ff07a8dc1be0018dd765baeff`). The port follows that tag
|
|
13
|
-
([`test/programs/SOURCES.md`](
|
|
13
|
+
([`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)).
|
|
14
14
|
|
|
15
15
|
Stake Pool is a native program: one entrypoint decodes a Borsh instruction (a tag byte, then the variant's fields,
|
|
16
16
|
every byte consumed), the processor takes its accounts by position, the pool account is plain Borsh with Options and
|
|
@@ -19,9 +19,9 @@ data enums, the validator list is a header and a `BigVec` of 73-byte entries ove
|
|
|
19
19
|
|
|
20
20
|
| File | Holds |
|
|
21
21
|
| --- | --- |
|
|
22
|
-
| [`stake_pool.ts`](
|
|
23
|
-
| [`state.ts`](
|
|
24
|
-
| [`util.ts`](
|
|
22
|
+
| [`stake_pool.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/spl-stake-pool/stake_pool.ts) | the entrypoint: the instruction decoded as `try_from_slice` does, dispatch to the 27 instructions |
|
|
23
|
+
| [`state.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/spl-stake-pool/state.ts), [`errors.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/spl-stake-pool/errors.ts) | StakePool (Borsh, 611 bytes at most), ValidatorList with its `BigVec<ValidatorStakeInfo>`, the stake account layout, StakePoolError from code 0 |
|
|
24
|
+
| [`util.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/spl-stake-pool/util.ts) | PDAs, fee arithmetic, the pool-token and lamport conversions, token account and mint checks (Token-2022 extensions included), the stake CPIs as solana_program's builders make them |
|
|
25
25
|
| `admin.ts`, `validators.ts`, `update.ts`, `sol.ts`, `stake_deposit.ts`, `stake_withdraw.ts`, `rebalance.ts`, `metadata.ts` | the instructions by subject |
|
|
26
26
|
|
|
27
27
|
## What is ported
|
|
@@ -66,7 +66,7 @@ bytes in every account it names. There are 2,107 such transactions in six files:
|
|
|
66
66
|
authorities, read-only and repeated accounts (the original's RefCell panics included), pools of 50 to 60 validators,
|
|
67
67
|
warmup and cooldown over several epochs.
|
|
68
68
|
- **The original's own tests** (`spl-stake-pool-upstream.test.ts`; 701): each of the 221 test functions in
|
|
69
|
-
`program/tests` at the tag is mapped to a case ([the mapping](
|
|
69
|
+
`program/tests` at the tag is mapped to a case ([the mapping](https://github.com/typesol-lang/typesol/blob/main/showcase/test/spl-stake-pool-upstream.md)): 143
|
|
70
70
|
were covered already, 78 are added there, none is left out. huge_pool.rs runs at 3,000 and 20,000 validators.
|
|
71
71
|
- **A random walk over epochs** (`spl-stake-pool-fuzz.test.ts`): validators added and removed, users depositing and
|
|
72
72
|
withdrawing SOL and stake, rebalancing, updates in random chunks, fee and authority changes, rewards, slow warmup,
|
package/docs/cli.md
CHANGED
|
@@ -6,24 +6,33 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
6
6
|
|
|
7
7
|
| Command | What it does |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow]` | Create a project: `typesol.json`, `programs/<name>.ts`, `tests/<name>.test.ts` (LiteSVM), `package.json`, `tsconfig.json`, `programs/tsconfig.json` (with the editor plugin), `.vscode/settings.json` (the workspace TypeScript, so the plugin loads) and `.
|
|
9
|
+
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow]` | Create a project: `typesol.json`, `programs/<name>.ts`, `tests/<name>.test.ts` (LiteSVM), `package.json`, `tsconfig.json`, `programs/tsconfig.json` (with the editor plugin), `.vscode/settings.json` (the workspace TypeScript, so the plugin loads), `.gitignore`, the rules for AI coding agents (`AGENTS.md`, `CLAUDE.md` importing it, `.cursor/rules/typesol.mdc`) and the MCP server configuration (`.mcp.json`, `.cursor/mcp.json`; see [ai.md](ai.md)). `<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). Refuses to overwrite files. It warns, with the install commands, when the platform-tools that building needs are missing. |
|
|
10
10
|
| `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name. |
|
|
11
|
-
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools, the Solana CLI, its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
12
|
-
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json
|
|
13
|
-
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. A project program's `.ts` builds as that program. |
|
|
14
|
-
| `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }
|
|
11
|
+
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
12
|
+
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. |
|
|
13
|
+
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
|
|
14
|
+
| `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }`, always (a missing file or unreadable `--files` input is a diagnostic too, exit 1 or 2); `--stdin` checks the text given on stdin as that file (its imports come from disk); `--files` reads `{ "files": { "<absolute path>": "<text>", … } }` from stdin and checks with those texts instead of the disk (an editor's unsaved buffers). |
|
|
15
15
|
| `typesol clone [<address>…] [--url <rpc>] [--config <cli config>] [--out <dir>]` | Copy cluster accounts and programs for the tests (Anchor's `[test.validator.clone]`): each account to `<address>.json` (lamports, owner, data), each program to `<address>.so` (its ELF, from the ProgramData account for upgradeable programs), in `tests/accounts` (`"accounts"` in `typesol.json`) or `--out`. Without addresses it clones the project's `"clone"` list. `testProgram` loads that directory into its LiteSVM; commit it so the tests run offline. |
|
|
16
16
|
| `typesol emit-c <file.ts> [--out <file.c>] [--profile]` | Print or write the generated C. |
|
|
17
|
-
| `typesol
|
|
18
|
-
| `typesol
|
|
17
|
+
| `typesol mcp` | Serve the Model Context Protocol on stdio for AI coding agents: tools to check a program (errors with hints), read its IDL, search the docs and read the rules a TypeSOL program follows. The `.mcp.json` / `.cursor/mcp.json` that `init` writes start it as `npx --no-install typesol mcp` (the project's own copy); see [ai.md](ai.md). |
|
|
18
|
+
| `typesol deploy [<program>…] [--url <rpc>] [--keypair <payer.json>] [--config <cli config>] [--dry-run] [--sbpf …] [--toolchain-strict]` | Build (`--toolchain-strict` as for `build`), then `solana program deploy --use-rpc` at the program keypair's address. Deploying again upgrades (the payer must be the upgrade authority). `--dry-run` builds and prints the commands. It needs a cluster, `--url` or `json_rpc_url` in the Solana CLI config: it never falls back to the CLI's default. Before sending anything it prints the cluster's host and the payer, checks that the RPC answers and that the payer holds enough for the rent (about twice the binary's on a first deploy, while the buffer exists), and says what to do if not (start `solana-test-validator`, `solana airdrop` on devnet or a local validator). Needs `solana` on PATH. |
|
|
19
|
+
| `typesol idl publish [<program>…] [--url <rpc>] [--keypair <authority.json>] [--config <cli config>] [--non-canonical]` | Compile (the binary is not rebuilt), then write each IDL to the Program Metadata program (seed `idl`). Canonical IDLs must be signed by the upgrade authority. Defaults come from the Solana CLI config (`~/.config/solana/cli/config.yml`); it prints the cluster's host and the payer before sending. |
|
|
19
20
|
| `typesol cpi <idl.json> [--out <file.ts>] [--prefix <name>] [--address <base58>]` | Generate TypeSOL helpers that call another program from its IDL. Unsupported instructions are listed on stderr. |
|
|
20
21
|
| `typesol port <idl.json> [--out <file.ts>]` | A TypeSOL program skeleton from an Anchor IDL (0.30+/1.x), to port an Anchor program: account structs, enums, errors, events and one function per instruction with its accounts and arguments, each body `require(false, …NotPorted)` until written. Instruction discriminators (an explicit `@discriminator` when the name derives another), account names and error codes are kept, so existing clients keep working where the layouts match; notes on stderr list where they do not (Borsh `String`/`Option` in account data, a `Vec` that is not the last field). Error codes that skip ahead are kept with `@code`, and zero-copy types keep their IDL `repr`, `serialization` and field names (`@repr`, `@serialization`, `@idlName`). |
|
|
21
22
|
| `typesol client <idl.json> [--out <file.ts>] [--address <base58>]`, `typesol client --address <program id> [--url <rpc>] [--config <cli config>] [--out <file.ts>]` | Generate a typed TypeScript client on `@solana/kit` from an Anchor IDL (0.30+/1.x or TypeSOL); the IDL is validated first, and what the client leaves out is printed as notes. Without a file, the IDL is read from the chain: the canonical Program Metadata IDL, else Anchor's IDL account. See [client.md](client.md). |
|
|
22
|
-
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. |
|
|
23
|
+
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. On a mismatch it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given `.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a program on chain records none). |
|
|
23
24
|
| `typesol profile <logs.txt\|-> [--program <id>]` | Compute units per TypeScript line from the logs of a `--profile` build's transaction (exit 1 when the logs have no markers). |
|
|
24
25
|
| `typesol help <command>` | Same as `typesol <command> --help`. |
|
|
25
26
|
| `typesol --version` | Print the version. |
|
|
26
27
|
|
|
28
|
+
`clone`, `client --address`, `verify` and `idl publish` give up on an RPC request after 30 seconds
|
|
29
|
+
(`TYPESOL_RPC_TIMEOUT=<seconds>` changes it) and, like `doctor` and `deploy`, name only the RPC's host and the cause
|
|
30
|
+
when one fails (an RPC URL can carry an API key). A `--config` file that does not exist is a usage error everywhere.
|
|
31
|
+
|
|
32
|
+
Builds (`build`, `deploy`, `verify`, `typesol/testing`) compare the active clang with the one the release is tested
|
|
33
|
+
with (`TESTED_TOOLCHAIN` in `typesol/compiler`: Agave 3.1.10, platform-tools v1.52): another one gets one warning per
|
|
34
|
+
process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `warn` is the default.
|
|
35
|
+
|
|
27
36
|
## typesol.json
|
|
28
37
|
|
|
29
38
|
```json
|
package/docs/client.md
CHANGED
|
@@ -79,6 +79,11 @@ integers and floats are `number`, `Pubkey` is kit's `Address`, `string` and `Fix
|
|
|
79
79
|
as in the program. Names are camelCase. For Anchor IDLs, data enums use `__kind`, as Codama-generated clients do. The
|
|
80
80
|
file uses no TypeScript-only syntax (no `enum`), so it also runs under Node's type stripping.
|
|
81
81
|
|
|
82
|
+
Anchor IDLs can also hold types a TypeSOL program does not: `u256`/`i256` are `bigint` (32 bytes, little-endian), and
|
|
83
|
+
`Option<Option<T>>` is `Option<T> | null` with kit's `Option` inside, so the three values stay apart: `null` is None,
|
|
84
|
+
`none()` is Some(None) and `some(x)` (or `x`) is Some(Some(x)). A type that holds itself through a Vec or an Option
|
|
85
|
+
(`enum Shape { Dot, Rec { kids: Vec<Shape> } }`) is encoded and decoded to any depth.
|
|
86
|
+
|
|
82
87
|
## Safety
|
|
83
88
|
|
|
84
89
|
An IDL can come from anywhere, so `typesol client` refuses one whose names are not identifiers, whose discriminators or
|
|
@@ -92,9 +97,12 @@ Anchor IDLs are refused with a hint to convert them (`anchor idl convert`).
|
|
|
92
97
|
`Program data:` line only while this program is the innermost one running, and `eventsOf` reads only the `emitCpi`
|
|
93
98
|
inner instructions that call this program (it needs `tx.transaction`'s account keys for that). `parseCpiEvents(data)`
|
|
94
99
|
on its own does not check the program: give it this program's inner instructions only.
|
|
95
|
-
- **Not filled in
|
|
96
|
-
PDAs whose program is another account's field, and a PDA seeded from
|
|
97
|
-
helper from the values). `typesol client` prints a note for each.
|
|
100
|
+
- **Not filled in by the builder** (pass them): PDAs seeded from a field of another account's data (`state.owner`;
|
|
101
|
+
`resolve` reads the account and derives them), PDAs whose program is another account's field, and a PDA seeded from
|
|
102
|
+
its own fields (derive it with its `pdas` helper from the values). `typesol client` prints a note for each. PDAs
|
|
103
|
+
seeded from a field of a struct argument, at any depth (`params.inner.id`), are filled in.
|
|
104
|
+
- **Left out, with a note**: instructions, accounts and types using `Option<Option<Option<T>>>` or deeper, and types
|
|
105
|
+
the client cannot express (listed by `typesol client`).
|
|
98
106
|
- **Anchor IDLs**: zero-copy (`bytemuck`) accounts decode and encode at their `#[repr(C)]` offsets as the program sees
|
|
99
107
|
them on SBF (padding included; `packed` and `align` honored; 128-bit integers align to 8). Generic types become one
|
|
100
108
|
type per use with concrete arguments (`Pair<u64, 2>` is `PairU64N2`). Left out, with a note: zero-copy types with
|
package/docs/errors.md
CHANGED
|
@@ -20,7 +20,7 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
|
|
|
20
20
|
| 2016 / 2017 / 2018 | mint authority / freeze authority / decimals mismatch (2018: an existing mint `createIfNeeded` found) |
|
|
21
21
|
| 2021 / 2022 | token account / mint not owned by the token program `TokenOf` / `MintOf` names (ConstraintTokenTokenProgram / ConstraintMintTokenProgram) |
|
|
22
22
|
| 2024–2039 | an existing mint `createIfNeeded` found lacks a Token-2022 extension it was given, or holds other keys in it: group pointer 2024–2026, group member pointer 2027–2029, metadata pointer 2030–2032, close authority 2033–2034, permanent delegate 2035–2036, transfer hook 2037–2039 (the first code of each: the extension is missing; the next: the authority / address differs) (ConstraintMint…Extension…) |
|
|
23
|
-
| 2040 | the same account passed in two writable slots (ConstraintDuplicateMutableAccount) |
|
|
23
|
+
| 2040 | the same account passed in two writable slots (ConstraintDuplicateMutableAccount); also `close(a, b)` in a helper given one account for both |
|
|
24
24
|
| 0 (from the System Program) | an `Init` / `create` on an address already in use (AccountAlreadyInUse): the System Program refuses it, as under Anchor's `init` |
|
|
25
25
|
| 3000 | `initAccount<T>` on an account whose discriminator is already set (AccountDiscriminatorAlreadySet) |
|
|
26
26
|
| 3001 | a zero-copy (`@serialization bytemuck`) account with fewer than 8 bytes of data (AccountDiscriminatorNotFound) |
|