@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.
- package/CHANGELOG.md +556 -1
- package/NOTICE +17 -1
- package/README.md +122 -43
- package/SECURITY.md +6 -0
- package/dist/compiler/analyze.d.ts +2 -0
- package/dist/compiler/analyze.js +7 -1
- package/dist/compiler/emit/base.d.ts +7 -4
- package/dist/compiler/emit/base.js +17 -5
- package/dist/compiler/emit/borsh.js +8 -8
- package/dist/compiler/emit/calls.d.ts +6 -0
- package/dist/compiler/emit/calls.js +110 -11
- package/dist/compiler/emit/cpi-core.js +3 -3
- package/dist/compiler/emit/cpi.js +2 -2
- package/dist/compiler/emit/expressions.d.ts +1 -0
- package/dist/compiler/emit/expressions.js +15 -1
- package/dist/compiler/emit/function.js +12 -8
- package/dist/compiler/emit/program.js +10 -4
- package/dist/compiler/emit/rbtree.js +1 -1
- package/dist/compiler/emit/shared.d.ts +12 -2
- package/dist/compiler/emit/shared.js +26 -6
- package/dist/compiler/emit/statements.d.ts +8 -1
- package/dist/compiler/emit/statements.js +53 -5
- package/dist/compiler/emit/storage.js +20 -13
- package/dist/compiler/emit/views.js +1 -1
- package/dist/compiler/hints.js +3 -0
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +50 -9
- package/dist/keys.d.ts +12 -1
- package/dist/keys.js +57 -7
- package/dist/workspace.d.ts +8 -0
- package/dist/workspace.js +90 -15
- package/docker/deps/0.49.0.lock.json +1206 -0
- package/docker/deps/0.50.0.lock.json +1206 -0
- package/docs/architecture.md +3 -3
- package/docs/audit.md +33 -16
- package/docs/case-study-escrow.md +7 -5
- package/docs/case-study-jito-mev.md +14 -14
- package/docs/case-study-marginfi.md +142 -129
- package/docs/case-study-multisig.md +18 -5
- package/docs/case-study-raydium-amm.md +2 -1
- package/docs/case-study-raydium-clmm.md +44 -28
- package/docs/case-study-raydium-cp-swap.md +18 -18
- package/docs/case-study-spl-stake-pool.md +4 -3
- package/docs/cli.md +4 -3
- package/docs/language-accounts.md +21 -16
- package/docs/language-basics.md +4 -1
- package/docs/language-builtins.md +6 -2
- package/docs/language-cpi.md +34 -0
- package/docs/language-errors-events.md +1 -1
- package/docs/language-native.md +73 -7
- package/docs/language-statements.md +5 -3
- package/docs/language-types.md +13 -3
- package/docs/language.md +2 -2
- package/docs/mainnet.md +1 -1
- package/docs/runtime.md +25 -1
- package/docs/security-model.md +12 -4
- package/docs/stability.md +10 -4
- package/docs/testing.md +22 -6
- package/docs/troubleshooting.md +1 -1
- package/lib/typesol.d.ts +43 -3
- package/llms-full.txt +190 -51
- package/llms.txt +2 -1
- package/package.json +3 -3
- package/releases/0.48.0.json +847 -0
- package/releases/0.49.0.json +857 -0
- package/runtime/typesol_builtins.c +47 -2
- package/runtime/typesol_rt.h +131 -4
package/docs/architecture.md
CHANGED
|
@@ -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
|
|
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.
|
|
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,
|
|
15
|
-
| 1 |
|
|
16
|
-
| 1 |
|
|
17
|
-
| 1 |
|
|
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,
|
|
21
|
-
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,
|
|
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,
|
|
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
|
|
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**:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 #
|
|
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 (
|
|
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,
|
|
199
|
-
| take_offer | **7,
|
|
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.
|
|
202
|
+
| Binary | 32.1 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
|
|
202
203
|
|
|
203
|
-
|
|
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,
|
|
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,
|
|
134
|
-
| tip distribution `initialize` | 7,284 | 1,
|
|
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` |
|
|
138
|
-
| `close_claim_status` | 4,302 |
|
|
139
|
-
| `close_tip_distribution_account` | 5,735 | 1,
|
|
140
|
-
| `update_config` | 2,850 |
|
|
141
|
-
| `migrate_tda_merkle_root_upload_authority` | 6,467 | 1,
|
|
142
|
-
| priority fee `claim` |
|
|
143
|
-
| `transfer_priority_fee_tips`, live | 6,059 | 2,
|
|
144
|
-
| `transfer_priority_fee_tips`, not live (logs SOL) | 6,362 | 2,
|
|
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,
|
|
152
|
-
| Tip distribution | 342,432 bytes | 46,
|
|
153
|
-
| Priority fee distribution | 387,440 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,
|
|
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,
|
|
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,
|
|
652
|
-
| `marginfi_group_initialize` | 27,404 |
|
|
653
|
-
| `marginfi_group_configure`, five roles | 22,917 | 1,
|
|
654
|
-
| `propagate_fee_state` | 3,821 |
|
|
655
|
-
| `lending_pool_add_bank` (SPL Token) |
|
|
656
|
-
| `lending_pool_add_bank_with_seed` (Token-2022) |
|
|
657
|
-
| `lending_pool_accrue_bank_interest`, an empty bank | 4,002 | 1,
|
|
658
|
-
| `lending_pool_accrue_bank_interest`, 25% utilization over a minute | 40,135 |
|
|
659
|
-
| `lending_pool_accrue_bank_interest`, 80% utilization over a year | 41,642 |
|
|
660
|
-
| `lending_pool_accrue_bank_interest`, 98,765,432,101 / 123,456,789,012 | 42,657 |
|
|
661
|
-
| `lending_pool_configure_bank`, a new curve | 13,716 |
|
|
662
|
-
| `lending_pool_configure_bank`, circuit breaker on | 12,743 |
|
|
663
|
-
| `lending_pool_configure_bank`, circuit breaker off during a halt (accrues first) | 33,226 |
|
|
664
|
-
| `lending_pool_configure_bank`, checked against an e-mode entry | 17,282 |
|
|
665
|
-
| `lending_pool_configure_bank_interest_only`, every field | 25,668 |
|
|
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,
|
|
669
|
-
| `marginfi_account_initialize_pda` |
|
|
670
|
-
| `lending_account_deposit`, a new balance | 15,739 |
|
|
671
|
-
| `lending_account_deposit`, interest accrued first | 51,033 |
|
|
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,
|
|
674
|
-
| `lending_account_close_balance`, dust to the insurance fund | 20,
|
|
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` |
|
|
677
|
-
| `lending_account_repay`, part | 50,404 |
|
|
678
|
-
| `lending_account_repay`, all (rounded up, the balance closed) | 10,997 | 5,
|
|
679
|
-
| `lending_account_repay`, part, with a premium settled first | 52,678 |
|
|
680
|
-
| `lending_account_repay`, tokenless, by the risk admin | 25,228 |
|
|
681
|
-
| `lending_account_repay`, Token-2022 with a transfer fee | 32,985 |
|
|
682
|
-
| `lending_pool_collect_bank_fees` |
|
|
683
|
-
| `lending_pool_withdraw_fees` | 13,
|
|
684
|
-
| `lending_pool_withdraw_insurance` | 13,536 | 2,
|
|
685
|
-
| `lending_pool_withdraw_fees_permissionless` | 10,773 | 2,
|
|
686
|
-
| `lending_pool_configure_bank_oracle`, Pyth | 7,337 | 1,
|
|
687
|
-
| `lending_pool_configure_bank_oracle`, Switchboard | 7,258 | 1,
|
|
688
|
-
| `lending_pool_set_oracle_price` | 4,644 | 1,
|
|
689
|
-
| `lending_pool_pulse_bank_price_cache`, Pyth | 14,147 | 5,
|
|
690
|
-
| `lending_pool_pulse_bank_price_cache`, Switchboard | 7,755 |
|
|
691
|
-
| `lending_pool_pulse_bank_price_cache`, fixed | 3,815 |
|
|
692
|
-
| `lending_pool_pulse_bank_price_cache`, an hour of interest first | 41,299 |
|
|
693
|
-
| `lending_pool_pulse_bank_price_cache`, the breaker's reference moved | 27,267 |
|
|
694
|
-
| `lending_pool_pulse_bank_price_cache`, a tier-3 trip breaking the bank | 24,401 |
|
|
695
|
-
| `lending_account_withdraw`, part, no debt | 52,841 |
|
|
696
|
-
| `lending_account_withdraw`, healthy after, against a USDC debt | 46,485 |
|
|
697
|
-
| `lending_account_withdraw`, a stale collateral oracle skipped | 43,441 |
|
|
698
|
-
| `lending_account_withdraw`, all of it | 41,512 |
|
|
699
|
-
| `lending_account_withdraw`, e-mode lifting the collateral | 46,182 |
|
|
700
|
-
| `lending_account_withdraw`, premium rates from the collateral mix | 63,341 |
|
|
701
|
-
| `lending_account_withdraw`, Token-2022 with a transfer fee | 53,306 |
|
|
702
|
-
| `lending_account_withdraw`, in receivership, by a liquidator | 39,987 |
|
|
703
|
-
| `lending_account_withdraw`, 16 positions, the tag cleared | 538,319 |
|
|
704
|
-
| `lending_account_borrow` | 71,645 |
|
|
705
|
-
| `lending_account_borrow`, an isolated bank | 71,024 |
|
|
706
|
-
| `lending_account_borrow`, with an origination fee | 75,830 |
|
|
707
|
-
| `lending_account_borrow`, premium-active debt | 106,636 |
|
|
708
|
-
| `lending_account_borrow`, Token-2022 with a transfer fee | 77,107 |
|
|
709
|
-
| `lending_account_pulse_health`, an empty account | 7,560 |
|
|
710
|
-
| `lending_account_pulse_health`, healthy | 81,619 |
|
|
711
|
-
| `lending_account_pulse_health`, liquidatable | 74,068 |
|
|
712
|
-
| `lending_account_pulse_health`, bankrupt | 65,817 |
|
|
713
|
-
| `lending_account_pulse_health`, a stale collateral oracle | 36,258 |
|
|
714
|
-
| `marginfi_account_tag_liq_record`, liquidatable | 25,168 | 13,
|
|
715
|
-
| `marginfi_account_init_liq_record` | 10,318 | 2,
|
|
716
|
-
| `marginfi_account_close_liq_record` | 2,444 |
|
|
717
|
-
| `lending_pool_handle_bankruptcy`, insurance covering part | 91,747 |
|
|
718
|
-
| `lending_pool_handle_bankruptcy`, permissionless, covered | 69,730 |
|
|
719
|
-
| `lending_pool_handle_bankruptcy`, past the deposits | 35,143 |
|
|
720
|
-
| `lending_pool_handle_bankruptcy`, Token-2022 with a transfer fee | 97,583 |
|
|
721
|
-
| `lending_account_liquidate`, part of a collateral | 194,785 |
|
|
722
|
-
| `lending_account_liquidate`, a liquidator owing a premium | 222,725 |
|
|
723
|
-
| `lending_account_liquidate`, a fixed-price debt | 225,420 |
|
|
724
|
-
| `lending_account_liquidate`, Token-2022 | 199,
|
|
725
|
-
| a receivership: start, withdraw 1 SOL, repay 140 USDC, end | 149,945 |
|
|
726
|
-
| a receivership: start, end | 87,094 |
|
|
727
|
-
| a receivership: a close-out under $5 | 130,094 |
|
|
728
|
-
| a deleverage: start, withdraw 1 SOL, repay 150 USDC, end | 160,288 |
|
|
729
|
-
| a flash loan: start, borrow past the limit, repay it all, end | 75,214 |
|
|
730
|
-
| a flash loan: start, end | 18,114 | 10,
|
|
731
|
-
| `marginfi_account_set_freeze` | 5,368 | 1,
|
|
732
|
-
| `transfer_to_new_account`, with balances | 12,906 |
|
|
733
|
-
| `transfer_to_new_account_pda` | 15,008 |
|
|
734
|
-
| `admin_close_account` |
|
|
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,
|
|
737
|
-
| `lending_pool_configure_group_premium`, a new pair | 5,558 | 1,
|
|
738
|
-
| `lending_pool_configure_bank_emode`, three entries sorted | 79,762 |
|
|
739
|
-
| `lending_pool_close_bank` | 4,530 |
|
|
740
|
-
| `lending_pool_configure_bank_gov`, weights | 42,109 |
|
|
741
|
-
| `lending_pool_collect_bank_premium_fees` | 18,080 |
|
|
742
|
-
| `lending_pool_emissions_deposit` | 12,486 | 5,
|
|
743
|
-
| `lending_pool_init_same_asset_emode_registry` | 9,301 | 2,
|
|
744
|
-
| `lending_pool_set_bank_same_asset_emode_eligibility` | 7,346 | 1,
|
|
745
|
-
| `init_bank_metadata` |
|
|
746
|
-
| `write_bank_metadata`, ticker and description | 5,354 | 1,
|
|
747
|
-
| `write_bank_metadata_pre_init` |
|
|
748
|
-
| `marginfi_account_place_order`, stop loss |
|
|
749
|
-
| `marginfi_account_close_order` | 4,142 | 1,
|
|
750
|
-
| `marginfi_account_set_keeper_close_flags`, one bank | 3,094 | 1,
|
|
751
|
-
| `marginfi_account_keeper_close_order` | 2,709 | 1,
|
|
752
|
-
| an order executed (start, withdraw, repay, end), stop loss |
|
|
753
|
-
| `marginfi_account_place_rebalance_order` | 10,820 | 3,
|
|
754
|
-
| `marginfi_account_update_rebalance_order` | 3,980 | 1,
|
|
755
|
-
| `marginfi_account_top_up_rebalance_fee_pool` | 6,498 | 2,
|
|
756
|
-
| a rebalance (start, withdraw, deposit, end), a tip escrowed | 270,
|
|
757
|
-
| `marginfi_account_settle_rebalance_tip`, paid |
|
|
758
|
-
| `lending_pool_resize_bank_account` | 4,711 | 2,
|
|
759
|
-
| `monitor_archive_upsert_batch`, two mints | 2,741 |
|
|
760
|
-
| `init_staked_settings` |
|
|
761
|
-
| `lending_pool_add_bank_permissionless` |
|
|
762
|
-
| `lending_pool_configure_bank_oracle_scope` | 9,597 | 1,
|
|
763
|
-
| `lending_pool_add_bank_solend` |
|
|
764
|
-
| `solend_init_obligation` |
|
|
765
|
-
| `solend_deposit` | 100,
|
|
766
|
-
| `solend_withdraw` | 191,
|
|
767
|
-
| `lending_pool_add_bank_kamino` |
|
|
768
|
-
| `kamino_init_obligation` (with a farm) |
|
|
769
|
-
| `kamino_deposit` |
|
|
770
|
-
| `kamino_withdraw` | 181,565 |
|
|
771
|
-
| `propagate_kamino_market_emergency` | 2,327 |
|
|
772
|
-
| `kamino_harvest_reward` |
|
|
773
|
-
| `lending_pool_add_bank_drift` |
|
|
774
|
-
| `drift_init_user` | 106,
|
|
775
|
-
| `drift_deposit` |
|
|
776
|
-
| `drift_withdraw` (with a debt) | 157,716 |
|
|
777
|
-
| `drift_harvest_reward` |
|
|
778
|
-
| `drift_claim_bad_debt` |
|
|
779
|
-
| `lending_pool_add_bank_juplend` |
|
|
780
|
-
| `juplend_init_position` | 71,441 | 49,
|
|
781
|
-
| `juplend_deposit` |
|
|
782
|
-
| `juplend_withdraw` (with a debt) | 141,
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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`).
|
|
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
|
|