@typesol/cli 0.40.0 → 0.42.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 +120 -0
- package/README.md +9 -5
- package/dist/ai.d.ts +10 -0
- package/dist/ai.js +43 -0
- package/dist/cli.js +15 -1
- package/dist/compiler/analyze.js +44 -3
- package/dist/compiler/diagnostics.d.ts +2 -0
- package/dist/compiler/emit/base.d.ts +40 -7
- package/dist/compiler/emit/base.js +33 -0
- package/dist/compiler/emit/borsh.d.ts +7 -0
- package/dist/compiler/emit/borsh.js +86 -1
- package/dist/compiler/emit/calls.d.ts +102 -2
- package/dist/compiler/emit/calls.js +671 -50
- package/dist/compiler/emit/cpi-core.d.ts +9 -3
- package/dist/compiler/emit/cpi-core.js +12 -7
- package/dist/compiler/emit/cpi.js +8 -14
- package/dist/compiler/emit/create.d.ts +3 -3
- package/dist/compiler/emit/create.js +33 -25
- package/dist/compiler/emit/expressions.js +51 -2
- package/dist/compiler/emit/function.js +2 -2
- package/dist/compiler/emit/outline.d.ts +24 -0
- package/dist/compiler/emit/outline.js +100 -0
- package/dist/compiler/emit/program.js +7 -2
- package/dist/compiler/emit/shared.d.ts +35 -1
- package/dist/compiler/emit/shared.js +9 -1
- package/dist/compiler/emit/statements.d.ts +31 -0
- package/dist/compiler/emit/statements.js +272 -14
- package/dist/compiler/emit/storage.d.ts +27 -1
- package/dist/compiler/emit/storage.js +124 -11
- package/dist/compiler/emit/token.d.ts +11 -8
- package/dist/compiler/emit/token.js +233 -104
- package/dist/compiler/hints.js +6 -0
- package/dist/compiler/model.d.ts +20 -1
- package/dist/compiler/model.js +5 -0
- package/dist/testing-stake.d.ts +216 -0
- package/dist/testing-stake.js +526 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +1 -0
- package/dist/tools/mcp.d.ts +11 -0
- package/dist/tools/mcp.js +208 -0
- package/dist/workspace.js +8 -0
- package/docs/ai.md +52 -0
- package/docs/architecture.md +1 -1
- package/docs/audit.md +16 -14
- package/docs/case-study-raydium-cp-swap.md +77 -41
- package/docs/case-study-spl-stake-pool.md +122 -0
- package/docs/errors.md +1 -1
- package/docs/language.md +107 -14
- package/docs/security-model.md +4 -0
- package/docs/stability.md +69 -0
- package/docs/test-your-program.md +47 -0
- package/docs/testing.md +19 -0
- package/lib/typesol.d.ts +241 -40
- package/llms-full.txt +1352 -0
- package/llms.txt +30 -0
- package/package.json +4 -2
- package/runtime/typesol_rt.h +69 -0
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, SPL Stake Pool, 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.
|
|
3
|
+
"version": "0.42.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",
|
package/runtime/typesol_rt.h
CHANGED
|
@@ -938,6 +938,26 @@ static inline uint64_t ts_last_restart_slot(uint64_t *out) {
|
|
|
938
938
|
return SUCCESS;
|
|
939
939
|
}
|
|
940
940
|
|
|
941
|
+
/* EpochRewards, as the syscall writes it: Rust's #[repr(C, align(16))] struct (81 bytes of fields, 96 in memory). The
|
|
942
|
+
runtime checks the destination's 16-byte alignment, hence the attribute. */
|
|
943
|
+
typedef struct __attribute__((aligned(16))) {
|
|
944
|
+
uint64_t distribution_starting_block_height;
|
|
945
|
+
uint64_t num_partitions;
|
|
946
|
+
SolPubkey parent_blockhash;
|
|
947
|
+
unsigned __int128 total_points;
|
|
948
|
+
uint64_t total_rewards;
|
|
949
|
+
uint64_t distributed_rewards;
|
|
950
|
+
uint8_t active;
|
|
951
|
+
} TsEpochRewards;
|
|
952
|
+
_Static_assert(sizeof(TsEpochRewards) == 96 && __builtin_offsetof(TsEpochRewards, total_points) == 48 &&
|
|
953
|
+
__builtin_offsetof(TsEpochRewards, active) == 80,
|
|
954
|
+
"EpochRewards layout");
|
|
955
|
+
uint64_t sol_get_epoch_rewards_sysvar(void *ret);
|
|
956
|
+
static inline uint64_t ts_epoch_rewards(TsEpochRewards *out) {
|
|
957
|
+
if (sol_get_epoch_rewards_sysvar(out) != SUCCESS) TS_FAIL(TS_ERR_SYSVAR, "TypeSOL: epoch rewards sysvar unavailable");
|
|
958
|
+
return SUCCESS;
|
|
959
|
+
}
|
|
960
|
+
|
|
941
961
|
/* The general case, in integers: exactly (uint64_t)((double)per_year * threshold) as soft-float computes it (the
|
|
942
962
|
conversion and the product rounded to nearest, ties to even; NaN, negative and < 1 give 0), or UINT64_MAX when that
|
|
943
963
|
product is >= 2^64 (no double below 2^64 converts to UINT64_MAX: the largest is 2^64 - 2048). No soft-float routine
|
|
@@ -1414,6 +1434,21 @@ static inline uint64_t ts_cpi(TsParams *params, const TsAccount *program, uint8_
|
|
|
1414
1434
|
return ts_invoke(params, &ix, &signer, nseeds > 0 ? 1 : 0);
|
|
1415
1435
|
}
|
|
1416
1436
|
|
|
1437
|
+
/* A CPI whose account infos are `accounts` (one per meta, in order), as Rust's invoke_signed(&ix, &[a, b, …]) takes
|
|
1438
|
+
them: a meta may name an address other than its account's key (`named(account, address)`: a sysvar, as
|
|
1439
|
+
solana_program's stake instruction builders name them). The runtime looks each meta's key up among these infos only,
|
|
1440
|
+
so a slot holding another account fails the call (MissingAccount) as it fails the original's, wherever else in the
|
|
1441
|
+
instruction the named account is. */
|
|
1442
|
+
static inline uint64_t ts_cpi_named(TsParams *params, const TsAccount *program, uint8_t *data, uint64_t len, SolAccountMeta *metas,
|
|
1443
|
+
uint64_t n, const TsAccount *const *accounts, const SolSignerSeed *seeds, int nseeds) {
|
|
1444
|
+
SolInstruction ix = {(SolPubkey *)&program->key, metas, n, data, len};
|
|
1445
|
+
SolSignerSeeds signer = {seeds, (uint64_t)nseeds};
|
|
1446
|
+
TS_INFOS_RESERVE(params, n);
|
|
1447
|
+
SolAccountInfo *infos = params->infos;
|
|
1448
|
+
for (uint64_t i = 0; i < n; i++) ts_info(accounts[i], &infos[i]);
|
|
1449
|
+
return sol_invoke_signed(&ix, infos, n, &signer, nseeds > 0 ? 1 : 0);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1417
1452
|
/* ---- Token-2022 extensions (TLV after the 165-byte base and the account-type byte) ---- */
|
|
1418
1453
|
/* `a` must be a token-program mint (want 1) or account (want 2), or either (want 0): legacy SPL Token accounts
|
|
1419
1454
|
simply have no extensions; a Token-2022 multisig or a foreign account is refused. */
|
|
@@ -1734,6 +1769,40 @@ static inline bool ts_ix_is(const TsIx *ix, const SolPubkey *program, const uint
|
|
|
1734
1769
|
}
|
|
1735
1770
|
/* How deep in CPIs the program runs: 1 when the transaction calls it directly. */
|
|
1736
1771
|
extern uint64_t sol_get_stack_height(void);
|
|
1772
|
+
/* The runtime's `abort` syscall (Rust's abort on SBF, e.g. the allocator's out-of-memory error): ProgramFailedToComplete,
|
|
1773
|
+
* logged as "SBF program panicked", with no location. */
|
|
1774
|
+
extern __attribute__((noreturn)) void abort(void);
|
|
1775
|
+
|
|
1776
|
+
/*
|
|
1777
|
+
* ---- BigVec (SPL's big_vec) ------------------------------------------------
|
|
1778
|
+
* The memmove syscall, for BigVec::retain's block moves as the Rust does: it costs max(10, n / 250) CU, where the
|
|
1779
|
+
* word loop of ts_memmove costs about n / 2 (a 1.4 MB validator list moves in a few thousand CU, not hundreds of
|
|
1780
|
+
* thousands). Overlapping ranges are allowed. The "no SDK byte loops" rule is about the SDK's C loops, not this.
|
|
1781
|
+
*/
|
|
1782
|
+
extern void sol_memmove_(void *dst, const void *src, uint64_t n);
|
|
1783
|
+
/* The memcpy syscall, for bulk copies of a length known only at run time (FixedVec.pushAll): max(10, n / 250) CU plus
|
|
1784
|
+
* the call, against about 0.74 CU a byte for ts_memcpy's word loop over unaligned data (measured: 1000 bytes of
|
|
1785
|
+
* instruction data), so copies under 32 bytes keep the loop. The ranges never overlap (a FixedVec's free slots and
|
|
1786
|
+
* another list, or its own elements). */
|
|
1787
|
+
extern void sol_memcpy_(void *dst, const void *src, uint64_t n);
|
|
1788
|
+
#define TS_MEMCPY_SYSCALL_MIN 32
|
|
1789
|
+
static inline __attribute__((always_inline)) void ts_memcpy_bulk(void *dst, const void *src, uint64_t n) {
|
|
1790
|
+
if (n >= TS_MEMCPY_SYSCALL_MIN) sol_memcpy_(dst, src, n);
|
|
1791
|
+
else ts_memcpy(dst, src, n);
|
|
1792
|
+
}
|
|
1793
|
+
/* A BigVec's room: a BigVec struct is only ever a loadRaw view, which sits at a TsAccount's data, right after its
|
|
1794
|
+
* data_len (see TsAccount); the elements that fit in the account past the struct (its fixed fields and the length). */
|
|
1795
|
+
static inline __attribute__((always_inline)) uint64_t ts_bigvec_cap(const uint8_t *data, uint64_t fixed, uint64_t elem) {
|
|
1796
|
+
uint64_t len = ts_ld64(data - 8);
|
|
1797
|
+
return len < fixed ? 0 : (len - fixed) / elem;
|
|
1798
|
+
}
|
|
1799
|
+
/* The same pointer, but one the optimizer cannot relate to `p`. BigVec::retain's scan loop steps one pointer over the
|
|
1800
|
+
* elements; its removal branch computes the moves from this copy, so clang's loop strength reduction does not rebuild
|
|
1801
|
+
* the scan around offsets the moves share (measured: 5 instructions per kept element, against 6 to 9 without). */
|
|
1802
|
+
static inline __attribute__((always_inline)) uint8_t *ts_opaque_ptr(uint8_t *p) {
|
|
1803
|
+
__asm__("" : "+r"(p));
|
|
1804
|
+
return p;
|
|
1805
|
+
}
|
|
1737
1806
|
|
|
1738
1807
|
/*
|
|
1739
1808
|
* Did an Ed25519 precompile instruction in this transaction verify `message` signed by `signer`?
|