@typesol/cli 0.39.0 → 0.41.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/llms.txt ADDED
@@ -0,0 +1,30 @@
1
+ # TypeSOL
2
+
3
+ > Write Solana programs in TypeScript. TypeSOL compiles a TypeScript subset to native SBF (no interpreter, no
4
+ > generated Rust) and writes an Anchor-compatible IDL and a typed client for every program. npm: @typesol/cli.
5
+
6
+ Integers are bigint (1n, u64), everything is imported from "typesol", and there is no throw, async, class or float.
7
+ The rules and the whole reference in one file: https://typesol.com/llms-full.txt
8
+
9
+ ## Docs
10
+
11
+ - [language](https://typesol.com/docs/language/): every type, check and built-in of the language
12
+ - [errors](https://typesol.com/docs/errors/): the error codes a program fails with
13
+ - [test-your-program](https://typesol.com/docs/test-your-program/): tests with typesol/testing in LiteSVM
14
+ - [cli](https://typesol.com/docs/cli/): the typesol commands
15
+ - [client](https://typesol.com/docs/client/): the typed client every build writes
16
+ - [migrate-from-anchor](https://typesol.com/docs/migrate-from-anchor/): each Anchor construct and its TypeSOL form
17
+ - [troubleshooting](https://typesol.com/docs/troubleshooting/): common problems
18
+ - [mainnet](https://typesol.com/docs/mainnet/): deploying, verifying and publishing the IDL
19
+ - [security-model](https://typesol.com/docs/security-model/): what a compiled program checks for you and what is left to you
20
+ - [ai](https://typesol.com/docs/ai/): the agent rules, check --json hints and the MCP server
21
+ - [stability](https://typesol.com/docs/stability/): what is stable, what is experimental, the road to 1.0
22
+
23
+ ## Tools
24
+
25
+ - `npx @typesol/cli init my-app`: a project with a program, a LiteSVM test, AGENTS.md / CLAUDE.md and the MCP server configured
26
+ - `npx typesol check --json`: errors with hints; `npx typesol mcp`: check, IDL and docs as MCP tools
27
+
28
+ ## Optional
29
+
30
+ - [Case studies](https://typesol.com/docs/case-study-marginfi/): mainnet programs (Marginfi v2, Raydium AMM v4, CLMM, CP-Swap, Jito) ported and checked against their binaries
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typesol/cli",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "Compile a TypeScript-syntax language directly to Solana SBF programs.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -55,7 +55,9 @@
55
55
  "README.md",
56
56
  "CHANGELOG.md",
57
57
  "SECURITY.md",
58
- "docs"
58
+ "docs",
59
+ "llms.txt",
60
+ "llms-full.txt"
59
61
  ],
60
62
  "scripts": {
61
63
  "build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
@@ -71,6 +71,15 @@
71
71
  /* Every failure logs through this one sol_log_ call: each syscall call site costs a 16-byte relocation in the binary. */
72
72
  static __attribute__((noinline)) uint64_t ts_fail(uint64_t code, const char *msg, uint64_t len) {
73
73
  sol_log_(msg, len);
74
+ #ifdef TS_PANIC_ON_OVERFLOW
75
+ /* PANIC_ON_OVERFLOW: arithmetic fails as a Rust `checked_*().unwrap()` does, with a panic (ProgramFailedToComplete). */
76
+ if (code == TS_ERR_OVERFLOW || code == TS_ERR_DIV_ZERO) sol_panic_("", 0, 0, 0);
77
+ #endif
78
+ #ifdef TS_CUSTOM_ZERO
79
+ /* An error with code 0 (a native program's first error) is returned as solana_program returns
80
+ * ProgramError::Custom(0): the built-in CUSTOM_ZERO, since 0 itself means success. */
81
+ if (code == 0) return (uint64_t)1 << 32;
82
+ #endif
74
83
  return code;
75
84
  }
76
85
  #define TS_FAIL(code, msg) return ts_fail((code), (msg), sol_strlen(msg))
@@ -664,6 +673,28 @@ static inline uint64_t ts_create_pda_address(const SolSignerSeed *seeds, int n,
664
673
  return SUCCESS;
665
674
  }
666
675
 
676
+ /* msg!("{prefix}{base64(bytes)}") with standard padding, as Raydium's ray_log writes it (at most 300 bytes in). */
677
+ static __attribute__((noinline, unused)) void ts_log_base64(const char *prefix, uint64_t plen, const uint8_t *data, uint64_t len) {
678
+ static const char tbl[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
679
+ char out[64 + 4 * ((300 + 2) / 3)];
680
+ if (plen > 64 || len > 300) return;
681
+ uint64_t o = 0;
682
+ for (uint64_t i = 0; i < plen; i++) out[o++] = prefix[i];
683
+ uint64_t i = 0;
684
+ for (; i + 3 <= len; i += 3) {
685
+ uint32_t v = ((uint32_t)data[i] << 16) | ((uint32_t)data[i + 1] << 8) | data[i + 2];
686
+ out[o++] = tbl[(v >> 18) & 63]; out[o++] = tbl[(v >> 12) & 63]; out[o++] = tbl[(v >> 6) & 63]; out[o++] = tbl[v & 63];
687
+ }
688
+ if (len - i == 1) {
689
+ uint32_t v = (uint32_t)data[i] << 16;
690
+ out[o++] = tbl[(v >> 18) & 63]; out[o++] = tbl[(v >> 12) & 63]; out[o++] = '='; out[o++] = '=';
691
+ } else if (len - i == 2) {
692
+ uint32_t v = ((uint32_t)data[i] << 16) | ((uint32_t)data[i + 1] << 8);
693
+ out[o++] = tbl[(v >> 18) & 63]; out[o++] = tbl[(v >> 12) & 63]; out[o++] = tbl[(v >> 6) & 63]; out[o++] = '=';
694
+ }
695
+ sol_log_(out, o);
696
+ }
697
+
667
698
  /* sol_try_find_program_address: the canonical (highest) bump. */
668
699
  static inline uint64_t ts_find_pda(const SolSignerSeed *seeds, int n, const SolPubkey *program, SolPubkey *out, uint8_t *bump_out) {
669
700
  if (!ts_pda_seeds_ok(seeds, n, TS_MAX_PDA_SEEDS - 1)) return 1; /* not SUCCESS: the PDA syscalls fail the same inputs */
@@ -2025,6 +2056,22 @@ static inline unsigned __int128 ts_isqrt_u128(unsigned __int128 x) {
2025
2056
  }
2026
2057
  }
2027
2058
 
2059
+ /* floor(sqrt(x)) of a u256 (the `uint` crate's U256::integer_sqrt): Newton's method from a power of two above it. */
2060
+ static inline TsU256 ts_isqrt_u256(TsU256 x) {
2061
+ int top = 3;
2062
+ while (top > 0 && x.w[top] == 0) top--;
2063
+ if (top == 0 && x.w[0] < 2) return x;
2064
+ int bits = 64 * top + (64 - __builtin_clzll(x.w[top]));
2065
+ TsU256 r = ts_u256_shl(ts_u256_lit(1, 0, 0, 0), (uint64_t)((bits + 1) / 2));
2066
+ while (1) {
2067
+ TsU256 q = ts_u256_divmod(x, r, true), s;
2068
+ ts_u256_add(r, q, &s); /* r + x / r stays below 2^256: r <= 2^128 and x / r < 2^256 / r */
2069
+ TsU256 n = ts_u256_shr(s, 1);
2070
+ if (ts_u256_cmp(n, r) >= 0) return r;
2071
+ r = n;
2072
+ }
2073
+ }
2074
+
2028
2075
  /* Decimal text of a 128-bit integer on the heap. */
2029
2076
  static inline uint64_t ts_str_u128(unsigned __int128 v, bool negative, TS_Str *out) {
2030
2077
  char tmp[40];
@@ -99,10 +99,33 @@ function init({ typescript: ts }) {
99
99
  return found;
100
100
  }
101
101
 
102
+ /**
103
+ * TypeScript's errors in a TypeSOL project's files, each with the hint the CLI prints under it (TypeScript's own
104
+ * advice, such as installing @types/node, points the wrong way in a program). Needs the in-process compiler.
105
+ */
106
+ function withHints(fileName, diagnostics) {
107
+ if (!compiler || !compiler.typescriptHint || !entriesNear(path.dirname(path.resolve(fileName))).size) return diagnostics;
108
+ return diagnostics.map((d) => {
109
+ if (d.category !== ts.DiagnosticCategory.Error) return d;
110
+ let hint;
111
+ try {
112
+ hint = compiler.typescriptHint(d);
113
+ } catch {
114
+ return d;
115
+ }
116
+ if (!hint) return d;
117
+ const text = `hint: ${hint}`;
118
+ const messageText =
119
+ typeof d.messageText === "string"
120
+ ? `${d.messageText}\n${text}`
121
+ : { ...d.messageText, next: [...(d.messageText.next || []), { messageText: text, category: d.category, code: d.code, next: undefined }] };
122
+ return { ...d, messageText };
123
+ });
124
+ }
102
125
  const proxy = Object.create(null);
103
126
  for (const k of Object.keys(ls)) proxy[k] = (...args) => ls[k](...args);
104
127
  proxy.getSemanticDiagnostics = (fileName) => {
105
- const prior = ls.getSemanticDiagnostics(fileName);
128
+ const prior = withHints(fileName, ls.getSemanticDiagnostics(fileName));
106
129
  if (prior.some((d) => d.category === ts.DiagnosticCategory.Error)) return prior; // TypeScript's errors first
107
130
  const target = path.resolve(fileName);
108
131
  const entries = entriesNear(path.dirname(target));