@typesol/cli 0.48.0 → 0.50.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +556 -1
  2. package/NOTICE +17 -1
  3. package/README.md +122 -43
  4. package/SECURITY.md +6 -0
  5. package/dist/compiler/analyze.d.ts +2 -0
  6. package/dist/compiler/analyze.js +7 -1
  7. package/dist/compiler/emit/base.d.ts +7 -4
  8. package/dist/compiler/emit/base.js +17 -5
  9. package/dist/compiler/emit/borsh.js +8 -8
  10. package/dist/compiler/emit/calls.d.ts +6 -0
  11. package/dist/compiler/emit/calls.js +110 -11
  12. package/dist/compiler/emit/cpi-core.js +3 -3
  13. package/dist/compiler/emit/cpi.js +2 -2
  14. package/dist/compiler/emit/expressions.d.ts +1 -0
  15. package/dist/compiler/emit/expressions.js +15 -1
  16. package/dist/compiler/emit/function.js +12 -8
  17. package/dist/compiler/emit/program.js +10 -4
  18. package/dist/compiler/emit/rbtree.js +1 -1
  19. package/dist/compiler/emit/shared.d.ts +12 -2
  20. package/dist/compiler/emit/shared.js +26 -6
  21. package/dist/compiler/emit/statements.d.ts +8 -1
  22. package/dist/compiler/emit/statements.js +53 -5
  23. package/dist/compiler/emit/storage.js +20 -13
  24. package/dist/compiler/emit/views.js +1 -1
  25. package/dist/compiler/hints.js +3 -0
  26. package/dist/compiler/index.d.ts +15 -1
  27. package/dist/compiler/index.js +50 -9
  28. package/dist/keys.d.ts +12 -1
  29. package/dist/keys.js +57 -7
  30. package/dist/workspace.d.ts +8 -0
  31. package/dist/workspace.js +90 -15
  32. package/docker/deps/0.49.0.lock.json +1206 -0
  33. package/docker/deps/0.50.0.lock.json +1206 -0
  34. package/docs/architecture.md +3 -3
  35. package/docs/audit.md +33 -16
  36. package/docs/case-study-escrow.md +7 -5
  37. package/docs/case-study-jito-mev.md +14 -14
  38. package/docs/case-study-marginfi.md +142 -129
  39. package/docs/case-study-multisig.md +18 -5
  40. package/docs/case-study-raydium-amm.md +2 -1
  41. package/docs/case-study-raydium-clmm.md +44 -28
  42. package/docs/case-study-raydium-cp-swap.md +18 -18
  43. package/docs/case-study-spl-stake-pool.md +4 -3
  44. package/docs/cli.md +4 -3
  45. package/docs/language-accounts.md +21 -16
  46. package/docs/language-basics.md +4 -1
  47. package/docs/language-builtins.md +6 -2
  48. package/docs/language-cpi.md +34 -0
  49. package/docs/language-errors-events.md +1 -1
  50. package/docs/language-native.md +73 -7
  51. package/docs/language-statements.md +5 -3
  52. package/docs/language-types.md +13 -3
  53. package/docs/language.md +2 -2
  54. package/docs/mainnet.md +1 -1
  55. package/docs/runtime.md +25 -1
  56. package/docs/security-model.md +12 -4
  57. package/docs/stability.md +10 -4
  58. package/docs/testing.md +22 -6
  59. package/docs/troubleshooting.md +1 -1
  60. package/lib/typesol.d.ts +43 -3
  61. package/llms-full.txt +190 -51
  62. package/llms.txt +2 -1
  63. package/package.json +3 -3
  64. package/releases/0.48.0.json +847 -0
  65. package/releases/0.49.0.json +857 -0
  66. package/runtime/typesol_builtins.c +47 -2
  67. package/runtime/typesol_rt.h +131 -4
@@ -32,9 +32,9 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
32
32
  | `ts-plugin/` | The editor plugin (`typesol/ts-plugin`) |
33
33
  | `examples/` | Example programs; the `typesol init` templates are copies of three of them |
34
34
  | `test/` | The compiler's test suite (`pnpm test:core`), by subject: `language/`, `security/`, `examples/`, `integrations/` (token, Metaplex, oracle and other CPIs), `client/`, `cli/`, `verification/` (differential and fuzz tests). Shared: `harness.ts` and the `*-helpers.ts`, `fixtures/` (programs the tests compile), `golden/` (pinned generated C and clients, and what 14 programs build to in the build container: SBPF v0, and v1 and v2 for four of them), `programs/` (third-party program binaries, see its SOURCES.md), `anchor-twins/` (below) |
35
- | `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, CP-Swap and CLMM, Jito's MEV programs, Marginfi, coral-xyz/multisig, each checked against the binary on mainnet), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
35
+ | `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, CP-Swap and CLMM, Jito's MEV programs, Marginfi, Percolator v12.20, coral-xyz/multisig, each checked against the binary on mainnet, and Meteora DBC 0.2.2, under Meteora's Non-commercial Licence and compared without its log text and compute units), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
36
36
  | `test/anchor-twins/` | Anchor twins of the counter, vault and escrow examples, for the differential tests (`pnpm build:twins`) and the zero-copy client test; the benchmarks themselves are in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) |
37
- | `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`), `language-builtins.ts` (`docs/language-builtins.md`, generated from `lib/typesol.d.ts`; `--check` in CI) |
37
+ | `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`), `language-builtins.ts` (`docs/language-builtins.md`, generated from `lib/typesol.d.ts`; `--check` in CI), `percolator-author-suite.sh` (the Percolator author's own test suite against the mainnet binary and the port) |
38
38
  | `docker/` | The Dockerfile of the `--docker` build container |
39
39
  | `releases/` | Each release's npm tarball record (`scripts/release-check.ts`); shipped, so `--docker` can check the tarball it installs |
40
40
  | `docs/` | User and contributor documentation (also published on typesol.com) |
@@ -109,7 +109,7 @@ representation in between. We reviewed this on 2026-10-30 and kept it that way f
109
109
  named in the source, see `alias.ts`), a second backend (SBF without clang), and optimizations clang cannot see
110
110
  because they depend on account semantics (dropping a repeated check, packing a `@layout borsh` account only where
111
111
  it changed).
112
- - **What it would cost now:** rewriting most of the compiler's 20,000 lines, and losing the property every release
112
+ - **What it would cost now:** rewriting most of the compiler's 21,000 lines, and losing the property every release
113
113
  relies on: programs that do not use a change compile to the same binaries. Audit scope and differential results
114
114
  would start over.
115
115
  - **What we have instead:** the layers above, each owning one concern; `Ref` / `Value` as the typed place and value
package/docs/audit.md CHANGED
@@ -1,28 +1,29 @@
1
1
  # Audit package
2
2
 
3
3
  For a security firm reviewing TypeSOL. TypeSOL compiles a subset of TypeScript to C and then to Solana SBF; every
4
- program it builds includes one C runtime header. The question for an audit is whether a program compiled by TypeSOL
4
+ program it builds includes one C runtime header and, from 0.45.0 on, links one C file of compiler builtins. The question for an audit is whether a program compiled by TypeSOL
5
5
  can be made to do something its source and [the security model](security-model.md) say it cannot. Programs written
6
6
  with TypeSOL are out of scope; their authors audit them.
7
7
 
8
8
  ## Scope
9
9
 
10
- In order of priority. Line counts at 0.48.0 (November 2026).
10
+ In order of priority. Line counts at 0.50.0 (November 2026).
11
11
 
12
12
  | Priority | Component | Files | Lines | Why |
13
13
  | --- | --- | --- | ---: | --- |
14
- | 1 | C runtime | `runtime/typesol_rt.h` | 3,272 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
15
- | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 886 | Which checks each account parameter gets, and their order |
16
- | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 4,017 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
17
- | 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,746 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
14
+ | 1 | C runtime | `runtime/typesol_rt.h` | 3,399 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
15
+ | 1 | Compiler builtins | `runtime/typesol_builtins.c` | 529 | Compiled and linked with every program (0.45.0): the functions clang calls for 128-bit multiplication, division and shifts and signed 64-bit division (`__multi3`, `__udivti3`, `__divti3`, `__divdi3`, …), in place of platform-tools' compiler-builtins |
16
+ | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 890 | Which checks each account parameter gets, and their order |
17
+ | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 4,093 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
18
+ | 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,839 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
18
19
  | 1 | Raw views and the red-black tree | `src/compiler/emit/views.ts`, `rbtree.ts` | 655 | Accounts read without a discriminator at run-time offsets (`loadRaw`, `loadRawAt`, `rawArrayAt`, `BigVec`), their bounds, and the red-black tree's node indexes (`rbTreeAt`) |
19
20
  | 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,465 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
20
- | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,168 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
21
- | 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,545 | What the language accepts; constraints and account types as parsed from the source |
21
+ | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,205 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
22
+ | 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,553 | What the language accepts; constraints and account types as parsed from the source |
22
23
  | 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,460 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
23
24
  | 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
24
25
 
25
- The language surface is `lib/typesol.d.ts` (2,653 lines): every type and built-in a program can use, with its
26
+ The language surface is `lib/typesol.d.ts` (2,693 lines): every type and built-in a program can use, with its
26
27
  documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
27
28
  the code, [docs/runtime.md](runtime.md) the runtime's conventions.
28
29
 
@@ -33,7 +34,8 @@ one warn, and the review of 0.43.0 traced one defect to how that backend passes
33
34
  host package mattered too, up to 0.44.1: its compiler-builtins library, which each of the macOS, Linux arm64 and
34
35
  Linux x86_64 packages lays out differently, made a program with 128-bit or signed division link to different bytes on
35
36
  each. From 0.45.0 on the builtins are TypeSOL's own C, compiled with the program, and the programs measured build to
36
- the same bytes on the three hosts (the 76 of the sources for SBPF v0, 14 for v1 and v2;
37
+ the same bytes on the three hosts (measured with 0.45.0: the 76 programs then in the sources for SBPF v0, 14 for v1
38
+ and v2;
37
39
  [stability.md](stability.md#what-builds-the-same-bytes-where)). The reference environment for binaries is the
38
40
  `--docker` build container (`docker/Dockerfile`, linux/amd64; base images by digest, release files by sha256, the
39
41
  TypeSOL tarball by its release record and its npm dependencies by a lock whose every integrity `npm ci` checks), which
@@ -62,6 +64,16 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
62
64
  Internal reviews, by the maintainers: none of them is an independent audit. Their findings and fixes are in the
63
65
  CHANGELOG.
64
66
 
67
+ ### Not reviewed: 0.45.0 and later
68
+
69
+ 0.45.0 to 0.50.0 have had no security review. They add, among others,
70
+ `runtime/typesol_builtins.c` (the compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`,
71
+ `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), `zeroData`, `log64`,
72
+ `PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
73
+ `NATIVE_ACCOUNT_WRITES` (0.49.0), and `copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"` and whole values
74
+ copied and zeroed by the memory syscalls (0.50.0). An external review should include them
75
+ with the areas the reviews below left out.
76
+
65
77
  ### 0.44.0 (2026-11-11)
66
78
 
67
79
  A second internal review, of 0.44.0 as published, over the areas the review of 0.43.0 left out: the token,
@@ -168,11 +180,16 @@ since it skips the account checks Anchor-style parameters get, and the areas the
168
180
  Marginfi's I80F48 against vectors the `fixed` crate wrote; honest and hostile action sequences against state models
169
181
  with value conservation; account layout with two growable Vecs and aliasing through remaining accounts. Each run
170
182
  prints its seed (`FUZZ_SEED`), `pnpm fuzz` runs them wide.
171
- - **Random transactions against mainnet binaries**: Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`),
172
- Marginfi's administration and interest (`showcase/test/fuzz-marginfi.test.ts`) and Raydium CLMM (the `fuzz:`
173
- case of its differential test) take random sequences of honest and hostile
174
- transactions, in the original and the port alike, with the same outcome, account bytes and events required after
175
- every step. A new seed on every run, CI's included.
183
+ - **Random transactions against mainnet binaries**: random sequences of honest and hostile transactions go to the
184
+ original and the port alike, with the same outcome, account bytes and events required after every step (and the log
185
+ lines, for the native ports), in Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`), Marginfi's
186
+ administration and interest (`showcase/test/fuzz-marginfi.test.ts`), Raydium CLMM and CP-Swap (the `fuzz:` case of
187
+ each differential test), SPL Stake Pool (`spl-stake-pool-fuzz.test.ts`) and Meteora DBC
188
+ (`meteora-dbc-fuzz.test.ts`, `meteora-dbc-migration-fuzz.test.ts`): each takes a new seed from the clock on every
189
+ run, CI's included, and prints it. Phoenix (`phoenix-fuzz.test.ts`: seeds 1, 2 and 3), Percolator
190
+ (`percolator-fuzz.test.ts`: seeds 1 to 6 and two per oracle shape) and Raydium AMM v4 (the last case of its
191
+ differential test: seed 7) walk fixed seeds, the same in CI, unless `FUZZ_SEED` names another
192
+ ([testing.md](testing.md)).
176
193
  - **Ported programs**: all 46 programs of solana-developers/program-examples, run through their original tests' flows
177
194
  and failure paths ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)).
178
195
  - **Four-way comparison**: [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) runs 17 of those programs in
@@ -184,7 +201,7 @@ since it skips the account checks Anchor-style parameters get, and the areas the
184
201
  ```sh
185
202
  git clone https://github.com/typesol-lang/typesol && cd typesol
186
203
  pnpm install && pnpm build
187
- pnpm fetch:programs # Metaplex binaries for the token-metadata, Core and Bubblegum tests
204
+ pnpm fetch:programs # third-party binaries not kept in the repository: Metaplex, Kamino, JupLend, Meteora, …
188
205
  pnpm build:twins # the Anchor twins (Rust + Anchor 1.0.2)
189
206
  pnpm test # everything; CI runs it on Ubuntu (Node 22, 24) per change, macOS on demand (macos.yml)
190
207
  pnpm fuzz # the randomized checks, wide
@@ -191,16 +191,18 @@ token account. A client that matches on this code needs to accept either.
191
191
  ## Cost
192
192
 
193
193
  Mean compute units per instruction in LiteSVM (21 make_offer, 10 take_offer and 10 refund_offer calls), and the
194
- program size, from typesol-lang/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
194
+ program size, from typesol-lang/benchmarks (`results.json`, `official`: measured with TypeSOL 0.48.0 and Anchor 1.0.2
195
+ on 2026-11-14). Lower is better.
195
196
 
196
197
  | | TypeSOL | Anchor | Native Rust | Pinocchio |
197
198
  | --- | ---: | ---: | ---: | ---: |
198
- | make_offer | **19,697** | 35,726 | 33,206 | 20,581 |
199
- | take_offer | **7,053** | 29,235 | 24,995 | 21,606 |
199
+ | make_offer | **19,683** | 35,726 | 33,206 | 20,581 |
200
+ | take_offer | **7,054** | 29,235 | 24,995 | 21,606 |
200
201
  | refund_offer | **4,271** | 15,326 | 12,477 | 8,137 |
201
- | Binary | 32.0 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
202
+ | Binary | 32.1 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
202
203
 
203
- Most of `make_offer` in every version is the Associated Token Account program creating the vault. The native and
204
+ Much of `make_offer` in every version is the Associated Token Account program creating the vault (13,480 to
205
+ 22,480 CU a call in the mainnet transactions the README links), most of it in TypeSOL's and Pinocchio's. The native and
204
206
  Pinocchio versions are teaching code with fewer checks (no owner or type check on the offer, `Transfer` instead of
205
207
  `TransferChecked`; Pinocchio takes the offer's bump from the client).
206
208
 
@@ -127,30 +127,30 @@ Compute units per transaction, mainnet original against the port, from one run o
127
127
 
128
128
  | Instruction | Jito (mainnet) | TypeSOL | |
129
129
  | --- | ---: | ---: | ---: |
130
- | tip payment `initialize` | 60,085 | 23,628 | −61% |
130
+ | tip payment `initialize` | 60,085 | 23,632 | −61% |
131
131
  | `change_tip_receiver`, the receiver also the builder (both shares to one account) | 29,889 | 7,723 | −74% |
132
132
  | `change_block_builder`, a 7% commission paid first | 29,911 | 7,736 | −74% |
133
- | `change_tip_receiver`, a share kept in tip account 0 | 41,355 | 9,192 | −78% |
134
- | tip distribution `initialize` | 7,284 | 1,946 | −73% |
133
+ | `change_tip_receiver`, a share kept in tip account 0 | 41,511 | 9,198 | −78% |
134
+ | tip distribution `initialize` | 7,284 | 1,958 | −73% |
135
135
  | `initialize_tip_distribution_account` | 10,007 | 2,624 | −74% |
136
136
  | `upload_merkle_root` | 3,943 | 977 | −75% |
137
- | `claim` | 13,067 | 3,940 | −70% |
138
- | `close_claim_status` | 4,302 | 1,036 | −76% |
139
- | `close_tip_distribution_account` | 5,735 | 1,561 | −73% |
140
- | `update_config` | 2,850 | 645 | −77% |
141
- | `migrate_tda_merkle_root_upload_authority` | 6,467 | 1,342 | −79% |
142
- | priority fee `claim` | 12,730 | 3,933 | −69% |
143
- | `transfer_priority_fee_tips`, live | 6,059 | 2,014 | −67% |
144
- | `transfer_priority_fee_tips`, not live (logs SOL) | 6,362 | 2,673 | −58% |
137
+ | `claim` | 14,566 | 4,262 | −71% |
138
+ | `close_claim_status` | 4,302 | 995 | −77% |
139
+ | `close_tip_distribution_account` | 5,735 | 1,486 | −74% |
140
+ | `update_config` | 2,850 | 646 | −77% |
141
+ | `migrate_tda_merkle_root_upload_authority` | 6,467 | 1,341 | −79% |
142
+ | priority fee `claim` | 17,231 | 4,921 | −71% |
143
+ | `transfer_priority_fee_tips`, live | 6,059 | 2,013 | −67% |
144
+ | `transfer_priority_fee_tips`, not live (logs SOL) | 6,362 | 2,543 | −60% |
145
145
 
146
146
  `claim` and the account openings vary from run to run with the PDA bump searches of the random keys the test uses,
147
147
  in both programs alike.
148
148
 
149
149
  | Binary | Jito (mainnet, ELF without the padding) | TypeSOL |
150
150
  | --- | ---: | ---: |
151
- | Tip payment | 297,848 bytes | 47,128 bytes |
152
- | Tip distribution | 342,432 bytes | 46,848 bytes |
153
- | Priority fee distribution | 387,440 bytes | 61,432 bytes |
151
+ | Tip payment | 297,848 bytes | 47,208 bytes |
152
+ | Tip distribution | 342,432 bytes | 46,288 bytes |
153
+ | Priority fee distribution | 387,440 bytes | 59,384 bytes |
154
154
 
155
155
  ## Where they differ
156
156
 
@@ -472,7 +472,7 @@ circuit-breaker halt, a frozen bank, the fee state's pause, an account's flags a
472
472
 
473
473
  There are 244 transactions in that file, 174 in
474
474
  [`showcase/test/marginfi-oracle.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/marginfi-oracle.test.ts)
475
- for the oracles, and 1,022 in
475
+ for the oracles, and 1,032 in
476
476
  [`showcase/test/marginfi-risk.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/marginfi-risk.test.ts)
477
477
  for withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine. The last two write Pyth and Switchboard accounts byte for
478
478
  byte into both ledgers:
@@ -521,7 +521,7 @@ byte into both ledgers:
521
521
  window walked up and down with its anchor creeping after it ran out, a reference at the floor reseeded, a tier past
522
522
  3 in raw state (a panic).
523
523
 
524
- - **Withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine (1,022, with the deposits they start from).** Part of a deposit, more than it, from a bank without a balance, by
524
+ - **Withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine (1,032, with the deposits they start from).** Part of a deposit, more than it, from a bank without a balance, by
525
525
  another signer, to the wrong mint, from disabled and frozen accounts, paused and reduce-only banks; the health
526
526
  accounts left out, short an oracle, out of order, with extras; healthy and unhealthy after; a stale liability
527
527
  oracle (fails) and a stale collateral oracle (skipped, recorded), an undecodable collateral oracle (skipped,
@@ -589,6 +589,18 @@ byte into both ledgers:
589
589
  fraction left, only the fraction, more than the vault holds); super-admin moves (by someone else, on the mainnet
590
590
  build).
591
591
 
592
+ The integration banks have five files of their own, each with the other program's mainnet binary (or its accounts)
593
+ loaded beside both: `marginfi-lst.test.ts` (98 transactions: staked SOL banks priced at a single pool's rate),
594
+ `marginfi-venues.test.ts` (150: Solend banks over Solend's program), `marginfi-kamino.test.ts` (237: Kamino banks over
595
+ klend and kfarms), `marginfi-drift.test.ts` (185: Drift banks over Drift v2) and `marginfi-juplend.test.ts` (201:
596
+ JupLend banks over its lending, liquidity and rewards programs). The Kamino and JupLend binaries are under the Business
597
+ Source License and fetched, not kept (`pnpm fetch:programs`); without them those two files skip.
598
+
599
+ In all, a test run compares 2,321 transactions with the mainnet binary in eight files: 244 + 174 + 1,032 in the three
600
+ above and 98 + 150 + 237 + 185 + 201 in the venue files (1,883 when the Kamino and JupLend binaries are absent).
601
+ `marginfi-state.test.ts` checks the port's account types against the on-chain IDL and the mainnet accounts, and sends
602
+ no transactions to the binary.
603
+
592
604
  Besides these, [`showcase/test/fuzz-marginfi.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/fuzz-marginfi.test.ts)
593
605
  sends random sequences of the same instructions: random bank configs and curves (most valid, some broken in one
594
606
  way), fees, balances across scales, clock jumps, frozen banks, circuit-breaker settings and halts, accounts opened and
@@ -609,6 +621,7 @@ end index now and then wrong. The keys come from the seed too (the order of keys
609
621
  reproduces a run exactly.
610
622
  Every step must match. Inputs the original panics on (a negative fee rate trips its asserts) only have to fail in the
611
623
  port too. Each run takes a new seed, CI's included; `FUZZ_SEED=<seed>` reproduces one, `FUZZ_STEPS=<n>` lengthens it.
624
+ At the default 150 steps a run compares about 160 more transactions (161 in one run), not counted in the 2,321.
612
625
 
613
626
  ## Differences
614
627
 
@@ -648,138 +661,138 @@ Compute units per transaction, mainnet original against the port, from one run o
648
661
 
649
662
  | Instruction | Marginfi (mainnet) | TypeSOL | |
650
663
  | --- | ---: | ---: | ---: |
651
- | `init_global_fee_state` | 7,116 | 2,310 | −68% |
652
- | `marginfi_group_initialize` | 27,404 | 7,162 | −74% |
653
- | `marginfi_group_configure`, five roles | 22,917 | 1,232 | −95% |
654
- | `propagate_fee_state` | 3,821 | 776 | −80% |
655
- | `lending_pool_add_bank` (SPL Token) | 97,333 | 20,072 | −79% |
656
- | `lending_pool_add_bank_with_seed` (Token-2022) | 100,585 | 29,973 | −70% |
657
- | `lending_pool_accrue_bank_interest`, an empty bank | 4,002 | 1,689 | −58% |
658
- | `lending_pool_accrue_bank_interest`, 25% utilization over a minute | 40,135 | 18,696 | −53% |
659
- | `lending_pool_accrue_bank_interest`, 80% utilization over a year | 41,642 | 22,733 | −45% |
660
- | `lending_pool_accrue_bank_interest`, 98,765,432,101 / 123,456,789,012 | 42,657 | 22,853 | −46% |
661
- | `lending_pool_configure_bank`, a new curve | 13,716 | 3,389 | −75% |
662
- | `lending_pool_configure_bank`, circuit breaker on | 12,743 | 3,391 | −73% |
663
- | `lending_pool_configure_bank`, circuit breaker off during a halt (accrues first) | 33,226 | 15,453 | −53% |
664
- | `lending_pool_configure_bank`, checked against an e-mode entry | 17,282 | 5,463 | −68% |
665
- | `lending_pool_configure_bank_interest_only`, every field | 25,668 | 847 | −97% |
664
+ | `init_global_fee_state` | 7,116 | 2,325 | −67% |
665
+ | `marginfi_group_initialize` | 27,404 | 5,803 | −79% |
666
+ | `marginfi_group_configure`, five roles | 22,917 | 1,249 | −95% |
667
+ | `propagate_fee_state` | 3,821 | 779 | −80% |
668
+ | `lending_pool_add_bank` (SPL Token) | 86,833 | 17,585 | −80% |
669
+ | `lending_pool_add_bank_with_seed` (Token-2022) | 96,085 | 28,841 | −70% |
670
+ | `lending_pool_accrue_bank_interest`, an empty bank | 4,002 | 1,873 | −53% |
671
+ | `lending_pool_accrue_bank_interest`, 25% utilization over a minute | 40,135 | 15,970 | −60% |
672
+ | `lending_pool_accrue_bank_interest`, 80% utilization over a year | 41,642 | 19,738 | −53% |
673
+ | `lending_pool_accrue_bank_interest`, 98,765,432,101 / 123,456,789,012 | 42,657 | 20,020 | −53% |
674
+ | `lending_pool_configure_bank`, a new curve | 13,716 | 2,782 | −80% |
675
+ | `lending_pool_configure_bank`, circuit breaker on | 12,743 | 2,914 | −77% |
676
+ | `lending_pool_configure_bank`, circuit breaker off during a halt (accrues first) | 33,226 | 12,402 | −63% |
677
+ | `lending_pool_configure_bank`, checked against an e-mode entry | 17,282 | 3,637 | −79% |
678
+ | `lending_pool_configure_bank_interest_only`, every field | 25,668 | 780 | −97% |
666
679
  | `lending_pool_configure_bank_limits_only` | 9,043 | 461 | −95% |
667
680
  | `lending_pool_update_fees_destination_account` | 8,926 | 479 | −95% |
668
- | `marginfi_account_initialize` | 6,550 | 2,603 | −60% |
669
- | `marginfi_account_initialize_pda` | 8,670 | 3,176 | −63% |
670
- | `lending_account_deposit`, a new balance | 15,739 | 7,026 | −55% |
671
- | `lending_account_deposit`, interest accrued first | 51,033 | 25,544 | −50% |
681
+ | `marginfi_account_initialize` | 6,550 | 2,610 | −60% |
682
+ | `marginfi_account_initialize_pda` | 10,170 | 3,547 | −65% |
683
+ | `lending_account_deposit`, a new balance | 15,739 | 6,873 | −56% |
684
+ | `lending_account_deposit`, interest accrued first | 51,033 | 21,932 | −57% |
672
685
  | `lending_account_deposit`, Token-2022 with a transfer fee | 18,990 | 9,525 | −50% |
673
- | `lending_account_deposit`, up to the deposit limit | 15,170 | 7,523 | −50% |
674
- | `lending_account_close_balance`, dust to the insurance fund | 20,236 | 9,349 | −54% |
686
+ | `lending_account_deposit`, up to the deposit limit | 15,170 | 7,538 | −50% |
687
+ | `lending_account_close_balance`, dust to the insurance fund | 20,288 | 7,854 | −61% |
675
688
  | `lending_account_close_balance`, an empty balance | 6,677 | 3,055 | −54% |
676
- | `marginfi_account_close` | 7,734 | 3,383 | −56% |
677
- | `lending_account_repay`, part | 50,404 | 26,697 | −47% |
678
- | `lending_account_repay`, all (rounded up, the balance closed) | 10,997 | 5,142 | −53% |
679
- | `lending_account_repay`, part, with a premium settled first | 52,678 | 31,831 | −40% |
680
- | `lending_account_repay`, tokenless, by the risk admin | 25,228 | 12,684 | −50% |
681
- | `lending_account_repay`, Token-2022 with a transfer fee | 32,985 | 15,516 | −53% |
682
- | `lending_pool_collect_bank_fees` | 29,598 | 13,619 | −54% |
683
- | `lending_pool_withdraw_fees` | 13,558 | 2,493 | −82% |
684
- | `lending_pool_withdraw_insurance` | 13,536 | 2,527 | −81% |
685
- | `lending_pool_withdraw_fees_permissionless` | 10,773 | 2,412 | −78% |
686
- | `lending_pool_configure_bank_oracle`, Pyth | 7,337 | 1,215 | −83% |
687
- | `lending_pool_configure_bank_oracle`, Switchboard | 7,258 | 1,215 | −83% |
688
- | `lending_pool_set_oracle_price` | 4,644 | 1,133 | −76% |
689
- | `lending_pool_pulse_bank_price_cache`, Pyth | 14,147 | 5,152 | −64% |
690
- | `lending_pool_pulse_bank_price_cache`, Switchboard | 7,755 | 2,934 | −62% |
691
- | `lending_pool_pulse_bank_price_cache`, fixed | 3,815 | 997 | −74% |
692
- | `lending_pool_pulse_bank_price_cache`, an hour of interest first | 41,299 | 19,318 | −53% |
693
- | `lending_pool_pulse_bank_price_cache`, the breaker's reference moved | 27,267 | 10,648 | −61% |
694
- | `lending_pool_pulse_bank_price_cache`, a tier-3 trip breaking the bank | 24,401 | 9,115 | −63% |
695
- | `lending_account_withdraw`, part, no debt | 52,841 | 28,814 | −45% |
696
- | `lending_account_withdraw`, healthy after, against a USDC debt | 46,485 | 26,504 | −43% |
697
- | `lending_account_withdraw`, a stale collateral oracle skipped | 43,441 | 25,122 | −42% |
698
- | `lending_account_withdraw`, all of it | 41,512 | 24,821 | −40% |
699
- | `lending_account_withdraw`, e-mode lifting the collateral | 46,182 | 26,463 | −43% |
700
- | `lending_account_withdraw`, premium rates from the collateral mix | 63,341 | 37,898 | −40% |
701
- | `lending_account_withdraw`, Token-2022 with a transfer fee | 53,306 | 27,801 | −48% |
702
- | `lending_account_withdraw`, in receivership, by a liquidator | 39,987 | 16,590 | −59% |
703
- | `lending_account_withdraw`, 16 positions, the tag cleared | 538,319 | 296,477 | −45% |
704
- | `lending_account_borrow` | 71,645 | 37,550 | −48% |
705
- | `lending_account_borrow`, an isolated bank | 71,024 | 36,908 | −48% |
706
- | `lending_account_borrow`, with an origination fee | 75,830 | 42,111 | −44% |
707
- | `lending_account_borrow`, premium-active debt | 106,636 | 58,252 | −45% |
708
- | `lending_account_borrow`, Token-2022 with a transfer fee | 77,107 | 41,398 | −46% |
709
- | `lending_account_pulse_health`, an empty account | 7,560 | 6,302 | −17% |
710
- | `lending_account_pulse_health`, healthy | 81,619 | 46,772 | −43% |
711
- | `lending_account_pulse_health`, liquidatable | 74,068 | 46,374 | −37% |
712
- | `lending_account_pulse_health`, bankrupt | 65,817 | 39,377 | −40% |
713
- | `lending_account_pulse_health`, a stale collateral oracle | 36,258 | 23,831 | −34% |
714
- | `marginfi_account_tag_liq_record`, liquidatable | 25,168 | 13,904 | −45% |
715
- | `marginfi_account_init_liq_record` | 10,318 | 2,855 | −72% |
716
- | `marginfi_account_close_liq_record` | 2,444 | 636 | −74% |
717
- | `lending_pool_handle_bankruptcy`, insurance covering part | 91,747 | 48,664 | −47% |
718
- | `lending_pool_handle_bankruptcy`, permissionless, covered | 69,730 | 33,101 | −53% |
719
- | `lending_pool_handle_bankruptcy`, past the deposits | 35,143 | 19,708 | −44% |
720
- | `lending_pool_handle_bankruptcy`, Token-2022 with a transfer fee | 97,583 | 50,868 | −48% |
721
- | `lending_account_liquidate`, part of a collateral | 194,785 | 122,645 | −37% |
722
- | `lending_account_liquidate`, a liquidator owing a premium | 222,725 | 138,807 | −38% |
723
- | `lending_account_liquidate`, a fixed-price debt | 225,420 | 139,274 | −38% |
724
- | `lending_account_liquidate`, Token-2022 | 199,451 | 125,412 | −37% |
725
- | a receivership: start, withdraw 1 SOL, repay 140 USDC, end | 149,945 | 95,527 | −36% |
726
- | a receivership: start, end | 87,094 | 61,272 | −30% |
727
- | a receivership: a close-out under $5 | 130,094 | 78,290 | −40% |
728
- | a deleverage: start, withdraw 1 SOL, repay 150 USDC, end | 160,288 | 94,646 | −41% |
729
- | a flash loan: start, borrow past the limit, repay it all, end | 75,214 | 35,898 | −52% |
730
- | a flash loan: start, end | 18,114 | 10,818 | −40% |
731
- | `marginfi_account_set_freeze` | 5,368 | 1,237 | −77% |
732
- | `transfer_to_new_account`, with balances | 12,906 | 7,259 | −44% |
733
- | `transfer_to_new_account_pda` | 15,008 | 7,831 | −48% |
734
- | `admin_close_account` | 5,755 | 3,591 | −38% |
689
+ | `marginfi_account_close` | 10,734 | 2,886 | −73% |
690
+ | `lending_account_repay`, part | 50,404 | 24,079 | −52% |
691
+ | `lending_account_repay`, all (rounded up, the balance closed) | 10,997 | 5,386 | −51% |
692
+ | `lending_account_repay`, part, with a premium settled first | 52,678 | 27,862 | −47% |
693
+ | `lending_account_repay`, tokenless, by the risk admin | 25,228 | 11,615 | −54% |
694
+ | `lending_account_repay`, Token-2022 with a transfer fee | 32,985 | 13,991 | −58% |
695
+ | `lending_pool_collect_bank_fees` | 26,598 | 9,730 | −63% |
696
+ | `lending_pool_withdraw_fees` | 13,527 | 2,547 | −81% |
697
+ | `lending_pool_withdraw_insurance` | 13,536 | 2,549 | −81% |
698
+ | `lending_pool_withdraw_fees_permissionless` | 10,773 | 2,435 | −77% |
699
+ | `lending_pool_configure_bank_oracle`, Pyth | 7,337 | 1,263 | −83% |
700
+ | `lending_pool_configure_bank_oracle`, Switchboard | 7,258 | 1,269 | −83% |
701
+ | `lending_pool_set_oracle_price` | 4,644 | 1,192 | −74% |
702
+ | `lending_pool_pulse_bank_price_cache`, Pyth | 14,147 | 5,111 | −64% |
703
+ | `lending_pool_pulse_bank_price_cache`, Switchboard | 7,755 | 3,396 | −56% |
704
+ | `lending_pool_pulse_bank_price_cache`, fixed | 3,815 | 1,289 | −66% |
705
+ | `lending_pool_pulse_bank_price_cache`, an hour of interest first | 41,299 | 16,499 | −60% |
706
+ | `lending_pool_pulse_bank_price_cache`, the breaker's reference moved | 27,267 | 9,724 | −64% |
707
+ | `lending_pool_pulse_bank_price_cache`, a tier-3 trip breaking the bank | 24,401 | 8,651 | −65% |
708
+ | `lending_account_withdraw`, part, no debt | 52,841 | 26,210 | −50% |
709
+ | `lending_account_withdraw`, healthy after, against a USDC debt | 46,485 | 25,010 | −46% |
710
+ | `lending_account_withdraw`, a stale collateral oracle skipped | 43,441 | 23,516 | −46% |
711
+ | `lending_account_withdraw`, all of it | 41,512 | 23,654 | −43% |
712
+ | `lending_account_withdraw`, e-mode lifting the collateral | 46,182 | 25,056 | −46% |
713
+ | `lending_account_withdraw`, premium rates from the collateral mix | 63,341 | 35,902 | −43% |
714
+ | `lending_account_withdraw`, Token-2022 with a transfer fee | 53,306 | 25,418 | −52% |
715
+ | `lending_account_withdraw`, in receivership, by a liquidator | 39,987 | 15,516 | −61% |
716
+ | `lending_account_withdraw`, 16 positions, the tag cleared | 538,319 | 266,132 | −51% |
717
+ | `lending_account_borrow` | 71,645 | 34,921 | −51% |
718
+ | `lending_account_borrow`, an isolated bank | 71,024 | 34,700 | −51% |
719
+ | `lending_account_borrow`, with an origination fee | 75,830 | 39,211 | −48% |
720
+ | `lending_account_borrow`, premium-active debt | 106,636 | 52,610 | −51% |
721
+ | `lending_account_borrow`, Token-2022 with a transfer fee | 77,107 | 38,438 | −50% |
722
+ | `lending_account_pulse_health`, an empty account | 7,560 | 4,932 | −35% |
723
+ | `lending_account_pulse_health`, healthy | 81,619 | 44,189 | −46% |
724
+ | `lending_account_pulse_health`, liquidatable | 74,068 | 43,850 | −41% |
725
+ | `lending_account_pulse_health`, bankrupt | 65,817 | 35,340 | −46% |
726
+ | `lending_account_pulse_health`, a stale collateral oracle | 36,258 | 21,340 | −41% |
727
+ | `marginfi_account_tag_liq_record`, liquidatable | 25,168 | 13,359 | −47% |
728
+ | `marginfi_account_init_liq_record` | 10,318 | 2,864 | −72% |
729
+ | `marginfi_account_close_liq_record` | 2,444 | 391 | −84% |
730
+ | `lending_pool_handle_bankruptcy`, insurance covering part | 91,747 | 41,723 | −55% |
731
+ | `lending_pool_handle_bankruptcy`, permissionless, covered | 69,730 | 28,732 | −59% |
732
+ | `lending_pool_handle_bankruptcy`, past the deposits | 35,143 | 17,863 | −49% |
733
+ | `lending_pool_handle_bankruptcy`, Token-2022 with a transfer fee | 97,583 | 42,792 | −56% |
734
+ | `lending_account_liquidate`, part of a collateral | 194,785 | 106,086 | −46% |
735
+ | `lending_account_liquidate`, a liquidator owing a premium | 222,725 | 119,306 | −46% |
736
+ | `lending_account_liquidate`, a fixed-price debt | 225,420 | 118,315 | −48% |
737
+ | `lending_account_liquidate`, Token-2022 | 199,447 | 108,609 | −46% |
738
+ | a receivership: start, withdraw 1 SOL, repay 140 USDC, end | 149,945 | 88,560 | −41% |
739
+ | a receivership: start, end | 87,094 | 59,518 | −32% |
740
+ | a receivership: a close-out under $5 | 130,094 | 71,478 | −45% |
741
+ | a deleverage: start, withdraw 1 SOL, repay 150 USDC, end | 160,288 | 87,533 | −45% |
742
+ | a flash loan: start, borrow past the limit, repay it all, end | 75,214 | 33,819 | −55% |
743
+ | a flash loan: start, end | 18,114 | 10,305 | −43% |
744
+ | `marginfi_account_set_freeze` | 5,368 | 1,247 | −77% |
745
+ | `transfer_to_new_account`, with balances | 12,906 | 5,574 | −57% |
746
+ | `transfer_to_new_account_pda` | 15,008 | 6,146 | −59% |
747
+ | `admin_close_account` | 10,255 | 3,423 | −67% |
735
748
  | `panic_pause` | 7,188 | 863 | −88% |
736
- | `update_group_rate_limiter`, an outflow | 5,152 | 1,397 | −73% |
737
- | `lending_pool_configure_group_premium`, a new pair | 5,558 | 1,155 | −79% |
738
- | `lending_pool_configure_bank_emode`, three entries sorted | 79,762 | 10,384 | −87% |
739
- | `lending_pool_close_bank` | 4,530 | 2,498 | −45% |
740
- | `lending_pool_configure_bank_gov`, weights | 42,109 | 11,196 | −73% |
741
- | `lending_pool_collect_bank_premium_fees` | 18,080 | 7,158 | −60% |
742
- | `lending_pool_emissions_deposit` | 12,486 | 5,070 | −59% |
743
- | `lending_pool_init_same_asset_emode_registry` | 9,301 | 2,314 | −75% |
744
- | `lending_pool_set_bank_same_asset_emode_eligibility` | 7,346 | 1,677 | −77% |
745
- | `init_bank_metadata` | 8,789 | 2,541 | −71% |
746
- | `write_bank_metadata`, ticker and description | 5,354 | 1,988 | −63% |
747
- | `write_bank_metadata_pre_init` | 8,719 | 2,764 | −68% |
748
- | `marginfi_account_place_order`, stop loss | 16,332 | 6,273 | −62% |
749
- | `marginfi_account_close_order` | 4,142 | 1,355 | −67% |
750
- | `marginfi_account_set_keeper_close_flags`, one bank | 3,094 | 1,083 | −65% |
751
- | `marginfi_account_keeper_close_order` | 2,709 | 1,403 | −48% |
752
- | an order executed (start, withdraw, repay, end), stop loss | 158,349 | 70,948 | −55% |
753
- | `marginfi_account_place_rebalance_order` | 10,820 | 3,570 | −67% |
754
- | `marginfi_account_update_rebalance_order` | 3,980 | 1,610 | −60% |
755
- | `marginfi_account_top_up_rebalance_fee_pool` | 6,498 | 2,970 | −54% |
756
- | a rebalance (start, withdraw, deposit, end), a tip escrowed | 270,773 | 116,319 | −57% |
757
- | `marginfi_account_settle_rebalance_tip`, paid | 72,189 | 36,058 | −50% |
758
- | `lending_pool_resize_bank_account` | 4,711 | 2,807 | −40% |
759
- | `monitor_archive_upsert_batch`, two mints | 2,741 | 973 | −65% |
760
- | `init_staked_settings` | 17,865 | 2,786 | −84% |
761
- | `lending_pool_add_bank_permissionless` | 77,694 | 19,023 | −76% |
762
- | `lending_pool_configure_bank_oracle_scope` | 9,597 | 1,225 | −87% |
763
- | `lending_pool_add_bank_solend` | 82,881 | 19,012 | −77% |
764
- | `solend_init_obligation` | 88,717 | 66,142 | −25% |
765
- | `solend_deposit` | 100,480 | 73,502 | −27% |
766
- | `solend_withdraw` | 191,792 | 137,009 | −29% |
767
- | `lending_pool_add_bank_kamino` | 77,023 | 17,759 | −77% |
768
- | `kamino_init_obligation` (with a farm) | 206,172 | 169,852 | −18% |
769
- | `kamino_deposit` | 133,066 | 106,321 | −20% |
770
- | `kamino_withdraw` | 181,565 | 125,229 | −31% |
771
- | `propagate_kamino_market_emergency` | 2,327 | 366 | −84% |
772
- | `kamino_harvest_reward` | 120,337 | 101,049 | −16% |
773
- | `lending_pool_add_bank_drift` | 76,034 | 17,489 | −77% |
774
- | `drift_init_user` | 106,471 | 83,160 | −22% |
775
- | `drift_deposit` | 76,268 | 57,301 | −25% |
776
- | `drift_withdraw` (with a debt) | 157,716 | 113,786 | −28% |
777
- | `drift_harvest_reward` | 78,993 | 58,487 | −26% |
778
- | `drift_claim_bad_debt` | 89,488 | 66,105 | −26% |
779
- | `lending_pool_add_bank_juplend` | 81,844 | 20,279 | −75% |
780
- | `juplend_init_position` | 71,441 | 49,524 | −31% |
781
- | `juplend_deposit` | 90,443 | 62,075 | −31% |
782
- | `juplend_withdraw` (with a debt) | 141,752 | 91,212 | −36% |
749
+ | `update_group_rate_limiter`, an outflow | 5,152 | 1,123 | −78% |
750
+ | `lending_pool_configure_group_premium`, a new pair | 5,558 | 1,161 | −79% |
751
+ | `lending_pool_configure_bank_emode`, three entries sorted | 79,762 | 5,652 | −93% |
752
+ | `lending_pool_close_bank` | 4,530 | 556 | −88% |
753
+ | `lending_pool_configure_bank_gov`, weights | 42,109 | 5,936 | −86% |
754
+ | `lending_pool_collect_bank_premium_fees` | 18,080 | 5,767 | −68% |
755
+ | `lending_pool_emissions_deposit` | 12,486 | 5,198 | −58% |
756
+ | `lending_pool_init_same_asset_emode_registry` | 9,301 | 2,327 | −75% |
757
+ | `lending_pool_set_bank_same_asset_emode_eligibility` | 7,346 | 1,710 | −77% |
758
+ | `init_bank_metadata` | 7,289 | 2,222 | −70% |
759
+ | `write_bank_metadata`, ticker and description | 5,354 | 1,992 | −63% |
760
+ | `write_bank_metadata_pre_init` | 7,219 | 2,433 | −66% |
761
+ | `marginfi_account_place_order`, stop loss | 23,804 | 8,008 | −66% |
762
+ | `marginfi_account_close_order` | 4,142 | 1,258 | −70% |
763
+ | `marginfi_account_set_keeper_close_flags`, one bank | 3,094 | 1,096 | −65% |
764
+ | `marginfi_account_keeper_close_order` | 2,709 | 1,292 | −52% |
765
+ | an order executed (start, withdraw, repay, end), stop loss | 159,822 | 67,554 | −58% |
766
+ | `marginfi_account_place_rebalance_order` | 10,820 | 3,578 | −67% |
767
+ | `marginfi_account_update_rebalance_order` | 3,980 | 1,629 | −59% |
768
+ | `marginfi_account_top_up_rebalance_fee_pool` | 6,498 | 2,982 | −54% |
769
+ | a rebalance (start, withdraw, deposit, end), a tip escrowed | 270,544 | 114,547 | −58% |
770
+ | `marginfi_account_settle_rebalance_tip`, paid | 70,831 | 32,478 | −54% |
771
+ | `lending_pool_resize_bank_account` | 4,711 | 2,380 | −49% |
772
+ | `monitor_archive_upsert_batch`, two mints | 2,741 | 975 | −64% |
773
+ | `init_staked_settings` | 16,150 | 2,472 | −85% |
774
+ | `lending_pool_add_bank_permissionless` | 86,716 | 20,968 | −76% |
775
+ | `lending_pool_configure_bank_oracle_scope` | 9,597 | 1,235 | −87% |
776
+ | `lending_pool_add_bank_solend` | 103,973 | 23,492 | −77% |
777
+ | `solend_init_obligation` | 93,202 | 67,155 | −28% |
778
+ | `solend_deposit` | 100,511 | 72,777 | −28% |
779
+ | `solend_withdraw` | 191,823 | 129,900 | −32% |
780
+ | `lending_pool_add_bank_kamino` | 80,023 | 18,414 | −77% |
781
+ | `kamino_init_obligation` (with a farm) | 207,503 | 171,217 | −17% |
782
+ | `kamino_deposit` | 132,922 | 104,858 | −21% |
783
+ | `kamino_withdraw` | 181,565 | 118,064 | −35% |
784
+ | `propagate_kamino_market_emergency` | 2,327 | 370 | −84% |
785
+ | `kamino_harvest_reward` | 112,590 | 94,458 | −16% |
786
+ | `lending_pool_add_bank_drift` | 83,534 | 19,110 | −77% |
787
+ | `drift_init_user` | 106,472 | 81,991 | −23% |
788
+ | `drift_deposit` | 82,049 | 63,163 | −23% |
789
+ | `drift_withdraw` (with a debt) | 157,716 | 107,299 | −32% |
790
+ | `drift_harvest_reward` | 79,359 | 58,866 | −26% |
791
+ | `drift_claim_bad_debt` | 93,988 | 67,958 | −28% |
792
+ | `lending_pool_add_bank_juplend` | 96,844 | 23,566 | −76% |
793
+ | `juplend_init_position` | 71,441 | 49,533 | −31% |
794
+ | `juplend_deposit` | 91,589 | 62,538 | −32% |
795
+ | `juplend_withdraw` (with a debt) | 141,783 | 84,286 | −41% |
783
796
 
784
797
  Across the 125 transactions of the first file that succeed, the port uses 40–97% fewer compute units; across the 118
785
798
  refused ones, 56–93% fewer. Repayments with a premium and accrual, nearly all I80F48 arithmetic, save least (from
@@ -5,7 +5,8 @@ This page ports a program that holds real authority on mainnet:
5
5
  deployed at `msigUdDBsR4zSUYqYEDrc1LcgtmuSDDM7KxpRUXNC6U`. The port is
6
6
  [`showcase/mainnet/multisig/multisig.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/multisig/multisig.ts). Instead of a twin built for the occasion, it is checked against the
7
7
  binary that runs on mainnet: [`showcase/test/multisig.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/multisig.test.ts) runs both under the
8
- same program id and compares every outcome and every account byte. See
8
+ same program id and compares every outcome, every byte of every account a transaction names, the inner instructions,
9
+ the return data and the log lines (apart from Anchor's instruction-name line and its error-message text). See
9
10
  [case-study-escrow.md](case-study-escrow.md) for a token program and [Migrate from Anchor](migrate-from-anchor.md) for
10
11
  the general reference.
11
12
 
@@ -100,10 +101,22 @@ existing clients and existing accounts work with the port unchanged.
100
101
 
101
102
  `test/programs/coral_multisig.so` is the program dumped from mainnet on 2026-10-29 (sha256 in
102
103
  [`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)). The test loads it into one LiteSVM and the port into
103
- another, both at `msigUdDB…`, then sends each transaction to both. After each one it requires the same outcome (success,
104
- or the same error down to the code) and the same lamports, owner and data bytes for every account involved.
104
+ another, both at `msigUdDB…`, then sends each transaction to both. After each one it requires:
105
105
 
106
- There are 52 transactions:
106
+ - the same outcome (success, or the same error down to the code);
107
+ - the same lamports, owner and data bytes for the fee payer and every account an instruction names (the program
108
+ itself left out: the two are different binaries);
109
+ - the same inner instructions (the CPI `execute_transaction` makes: program, accounts, data and stack height);
110
+ - the same return data;
111
+ - the same log lines, apart from the runtime's compute-unit lines, Anchor's `Instruction: <Name>` line (the port does
112
+ not write it) and, on a failure, the error message the program logs itself (Anchor's text against TypeSOL's, such as
113
+ `AnchorError caused by account: multisig. Error Code: ConstraintRaw. …` against `Error 2003 ConstraintRaw: …`; the
114
+ code is compared through the outcome and the runtime's `failed: custom program error` line).
115
+
116
+ No compared transaction differs in anything else.
117
+
118
+ There are 55 transactions (8 in the upstream flow, 11 in the `create_multisig` refusals, 14 in the other refusals,
119
+ 12 in the owner-set changes, 7 in the payouts, 3 with the 40-owner account):
107
120
 
108
121
  - **The upstream test suite** (`tests/multisig.js`): create a 2-of-3 multisig, propose `set_owners`, approve, and
109
122
  execute through the PDA. Then `Assert Unique Owners` (6008).
@@ -147,7 +160,7 @@ instruction it runs.
147
160
  | `execute_transaction` → System transfer | 9,961 | 3,358 | −66% |
148
161
 
149
162
  Refusals cost less too. For example, an already-initialized account costs 3,378 against 160, and a missing signature
150
- 4,229 against 177. The binary is 526,688 bytes on mainnet and 29,984 bytes for the port, 18 times smaller. Deploying it
163
+ 4,229 against 177. The binary is 526,688 bytes on mainnet and 30,056 bytes for the port, 18 times smaller. Deploying it
151
164
  needs about 3.5 SOL less rent.
152
165
 
153
166
  The original was built with Anchor 0.25; a rebuild with a current Anchor would cost less than the mainnet figures. The
@@ -54,7 +54,8 @@ account forms; refusals (slippage, more than held, zero, the whole pool out, wro
54
54
  as the user's account, a wrong token program); deposits on either side with and without the minimum, withdrawals with
55
55
  and without minimums, amounts past u64; status, state, fees and open time changes and their refusals; the P&L taken by
56
56
  the P&L owner after the pool grew; config creation and updates; the retired tags; excess lamports; and a random mix of
57
- swaps, deposits and withdrawals (`FUZZ_SEED`, `FUZZ_STEPS`). 484 transactions in all at 400 fuzz steps.
57
+ swaps, deposits and withdrawals (`FUZZ_SEED`, `FUZZ_STEPS`). A default run compares 144 transactions: 84 fixed ones and 60 random steps (seed 7
58
+ unless `FUZZ_SEED` names another); 484 at 400 random steps.
58
59
 
59
60
  ## Differences
60
61