@typesol/cli 0.46.0 → 0.48.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 +164 -0
- package/NOTICE +10 -0
- package/README.md +9 -3
- package/dist/compiler/emit/base.d.ts +6 -0
- package/dist/compiler/emit/base.js +8 -0
- package/dist/compiler/emit/calls.js +18 -0
- package/dist/compiler/emit/cpi.js +3 -1
- package/dist/compiler/emit/function.js +7 -2
- package/dist/compiler/emit/program.js +5 -0
- package/dist/compiler/emit/statements.d.ts +29 -2
- package/dist/compiler/emit/statements.js +149 -6
- package/dist/compiler/emit/token.js +18 -1
- package/dist/compiler/toolchain.js +1 -0
- package/dist/idl-coder.d.ts +129 -0
- package/dist/idl-coder.js +567 -0
- package/dist/testing.d.ts +56 -8
- package/dist/testing.js +115 -34
- package/dist/workspace.js +0 -1
- package/docker/deps/0.47.0.lock.json +1206 -0
- package/docker/deps/0.48.0.lock.json +1206 -0
- package/docs/audit.md +6 -6
- package/docs/language-basics.md +2 -1
- package/docs/language-builtins.md +3 -1
- package/docs/language-chain.md +13 -1
- package/docs/language-cpi.md +26 -0
- package/docs/language-errors-events.md +15 -0
- package/docs/language-statements.md +1 -0
- package/docs/test-your-program.md +45 -4
- package/lib/typesol.d.ts +27 -0
- package/llms-full.txt +107 -10
- package/package.json +1 -5
- package/releases/0.46.0.json +817 -0
- package/releases/0.47.0.json +837 -0
- package/runtime/typesol_rt.h +274 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,170 @@ codes, and says so here.
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
## 0.48.0 — 2026-11-14
|
|
10
|
+
|
|
11
|
+
A minor release: it adds three built-ins (`transferCheckedWithHook`, the processed sibling instructions,
|
|
12
|
+
`EVENT_AUTHORITY_CHECK`), refuses an unused result of a helper that returns a proof or signature check, and makes
|
|
13
|
+
`typesol/testing` refuse missing and misspelt arguments and decode events itself. Programs that compiled with 0.47.0
|
|
14
|
+
and still compile build to the same bytes.
|
|
15
|
+
|
|
16
|
+
- Added: `export const EVENT_AUTHORITY_CHECK = "address"` checks `emitCpi`'s accounts as Anchor 1.x's `#[event_cpi]`
|
|
17
|
+
does: the event authority by address among the constraints (ConstraintAddress, 2012, after the accounts load and the
|
|
18
|
+
creates run) instead of by seeds when it loads (2006), and the `SelfProgram` account not at all (the self-CPI names
|
|
19
|
+
this program's id; an instruction that emits then fails in the runtime, MissingAccount, when this program is not among
|
|
20
|
+
its accounts, as Anchor's does). Programs without the constant build to the same bytes: the 76 programs of
|
|
21
|
+
`scripts/release-manifest.ts` other than the new port build identically with and without this change
|
|
22
|
+
(test/language/event-authority-check.test.ts; docs/language-errors-events.md).
|
|
23
|
+
- Added: `tokenProgram.transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts, signerSeeds?)`, a
|
|
24
|
+
TransferChecked by CPI of a Token-2022 mint with a transfer hook: the hook's extra accounts are resolved among
|
|
25
|
+
`hookAccounts` (the remaining accounts or a slice of them) and appended with the validation account and the hook
|
|
26
|
+
program, as spl-transfer-hook-interface 2.1's `add_extra_accounts_for_execute_cpi` (with spl-tlv-account-resolution
|
|
27
|
+
0.11) does on chain: every kind of extra account meta, the de-escalation of writable flags, and the same refusals and
|
|
28
|
+
error codes. A mint without a hook gets a plain TransferChecked (test/language/transfer-hook-cpi.test.ts;
|
|
29
|
+
showcase/test/meteora-dbc-hook.test.ts compares it with Meteora's Rust program; docs/language-cpi.md). Existing
|
|
30
|
+
programs build to the same bytes (the 76 programs of `scripts/release-manifest.ts` other than the Meteora port).
|
|
31
|
+
- Added: `processedSiblingInstructionCount()` and `processedSiblingInstruction(i)`, the instructions already processed
|
|
32
|
+
at the program's stack height (the `sol_get_processed_sibling_instruction` syscall, as Rust's
|
|
33
|
+
`get_processed_sibling_instruction` reads it), each a `TransactionInstruction` (test/language/sibling-instructions.test.ts;
|
|
34
|
+
docs/language-chain.md). Existing programs build to the same bytes.
|
|
35
|
+
- Showcase: the first stage of a port of Meteora's Dynamic Bonding Curve 0.2.2 (MeteoraAg/dynamic-bonding-curve @
|
|
36
|
+
91e696e), `showcase/mainnet/meteora-dbc/`. It is subject to Meteora's Non-commercial Licence, not to this
|
|
37
|
+
repository's MIT licence (LICENSE.md and README.md there, and NOTICE), and is not in the published package. This
|
|
38
|
+
stage has 9 of the program's 35 instructions (operator accounts, the legacy claim fee operator, token badges, partner
|
|
39
|
+
metadata, `create_config`, `create_config2`, `create_config_with_transfer_hook`), all 87 errors, the account layouts,
|
|
40
|
+
the 29 events, and the curve, fee scheduler, dynamic fee, vesting and migration-handler math that config creation
|
|
41
|
+
uses. Checked against the program deployed on mainnet at `dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN` (deployed in
|
|
42
|
+
slot 457,502,600; the dump cut at the ELF's end has sha256
|
|
43
|
+
`c9f45da65b0c87ca76c1ed5ad0d1ef2ead7c3392e8e41f194d50296820a22bb9`; fetched by `scripts/fetch-programs.sh`, not
|
|
44
|
+
kept here), with its two admin keys patched to test keys in both: `showcase/test/meteora-dbc.test.ts` sends 163
|
|
45
|
+
transactions (57 succeed, the others are refused with 47 distinct errors) and `meteora-dbc-fuzz.test.ts` 200 random
|
|
46
|
+
config parameter sets per run, each to both programs, which must give the same outcome and error code, the same
|
|
47
|
+
account bytes, the same events (the self-CPIs' instruction data, all inner instructions compared) and the same return
|
|
48
|
+
data. Not checked or different: log lines (Anchor's error messages, the original's "Math error thrown at …" lines),
|
|
49
|
+
compute units, the IDL (the config events' ConfigParameters is described field by field, the metadata Strings as
|
|
50
|
+
bytes), a read-only `payer` (ConstraintMut 2000 here, PrivilegeEscalation in the original), and a `curve` argument of
|
|
51
|
+
more than 24 points (102 here; a transaction carries at most 23).
|
|
52
|
+
The second stage adds 9 more: `swap` and `swap2` (ExactIn, PartialFill, ExactOut) with the swap math, the dynamic
|
|
53
|
+
fee's volatility tracker and the rate limiter of configs made before 0.2.1, the partner's and creator's trading fee
|
|
54
|
+
claims, both pool creation fee claims, `claim_protocol_fee2` (its signer, the protocol fee program's authority PDA,
|
|
55
|
+
patched to a test key in both), `transfer_pool_creator` and `create_virtual_pool_metadata`.
|
|
56
|
+
`showcase/test/meteora-dbc-swap.test.ts` checks them against the same binary on pools written into both ledgers as
|
|
57
|
+
pool creation leaves them (pool creation is not ported yet): every mode in both directions, referrals, slippage,
|
|
58
|
+
account refusals, the rate limiter's single-swap guard, and a random swap sequence per pool (fee schedulers, dynamic
|
|
59
|
+
fee, rate limiter, Token-2022 transfer fees on either mint) to the migration threshold (1,900+ swaps over three
|
|
60
|
+
seeds, all the same). `initialize_virtual_pool_with_spl_token` follows (its Metaplex CPIs checked against Token
|
|
61
|
+
Metadata as deployed on mainnet, sha256 `31f0a627dba051a938de650464e55cc5397a4be0fd496929c1f9cf02fe5e9011`):
|
|
62
|
+
`meteora-dbc-pool.test.ts` makes pools with each token authority option, a creation fee, a fixed supply and slot
|
|
63
|
+
activation, and the first swap at the minimum fee in the pool's creation transaction; the swap tests and fuzz now
|
|
64
|
+
swap on pools made by it (pools are written only for a Token-2022 base, a TransferHookPool or a rate limiter).
|
|
65
|
+
`meteora-dbc-mainnet.test.ts` swaps on two pools read from mainnet (an SPL and a Token-2022 base) to the end of
|
|
66
|
+
their curves. `initialize_virtual_pool_with_token2022` and `initialize_virtual_pool_with_token2022_transfer_hook`
|
|
67
|
+
follow (the base mint's MetadataPointer, transfer fee and transfer hook extensions and its metadata in the mint, as
|
|
68
|
+
the original creates them): `meteora-dbc-pool2022.test.ts` makes pools with each token authority option (the mint
|
|
69
|
+
authority kept under a transfer hook config), each base transfer fee option, a Token-2022 quote, a creation fee,
|
|
70
|
+
slot activation and addresses funded before creation, and checks their refusals, with a small transfer hook program
|
|
71
|
+
(`showcase/test/fixtures/meteora-dbc/hook.ts`) loaded in both; the swap tests now swap only on pools made by the
|
|
72
|
+
three pool creation instructions (written only under a rate limiter config). Then `swap2_with_transfer_hook`,
|
|
73
|
+
`claim_trading_fee2` and `claim_creator_trading_fee2`, the base mint's transfers carrying the hook's extra accounts
|
|
74
|
+
(`transferCheckedWithHook`): `meteora-dbc-hook.test.ts` swaps, pays referrals and claims fees on TransferHookPools
|
|
75
|
+
with each kind of extra account meta, revokes the hook at completion, and checks the slices' and the resolver's
|
|
76
|
+
refusals (malformed lists and seeds included) against the binary. The `slices` argument holds at most 64 entries
|
|
77
|
+
here (102 beyond). A swap by CPI under an active rate limiter reads the processed sibling instructions, as the
|
|
78
|
+
original does (checked against the binary through a small calling program,
|
|
79
|
+
`showcase/test/fixtures/meteora-dbc/relay.ts`). The third stage adds 7 more (31 of 35): `partner_withdraw_surplus`,
|
|
80
|
+
`creator_withdraw_surplus`, `withdraw_migration_fee`, `withdraw_leftover`, `create_locker` (the locker's
|
|
81
|
+
`create_vesting_escrow_v2` by CPI), the deprecated `migration_damm_v2_create_metadata` and `migration_damm_v2` (DAMM
|
|
82
|
+
v2's pool creation on a static or dynamic config, the second position by `add_liquidity` or, with a transfer fee, by
|
|
83
|
+
`split_position2`, permanent and vested locks, the position NFTs' owners, the base mint's transfer fee authority and
|
|
84
|
+
the burn, the pool authority's rent lent and paid back). `showcase/test/meteora-dbc-migration.test.ts` and
|
|
85
|
+
`meteora-dbc-migration-fuzz.test.ts` drive pools to the threshold by swaps and graduate them on both programs, which
|
|
86
|
+
call DAMM v2 (`cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG`, sha256 `ca7a3262…5a67`) and the locker
|
|
87
|
+
(`LocpQgucEQHbqNABEYvBvwoxCPsSbG91A1QaQhQQqjn`, sha256 `0ba6f4f5…abed`) as deployed on mainnet (fetched by
|
|
88
|
+
`scripts/fetch-programs.sh`, not kept here) on DAMM v2's seven migration configs read from mainnet
|
|
89
|
+
(`showcase/test/fixtures/meteora-dbc/damm-v2/`): every progress state, each fee option, customizable pools (collect
|
|
90
|
+
fee modes, dynamic fee, fee time and market cap schedulers, compounding), partner and creator liquidity splits with
|
|
91
|
+
permanent locks and vesting, SPL and Token-2022 bases and quotes, base and quote transfer fees with each migrated fee
|
|
92
|
+
authority option, a transfer hook pool, fixed supplies (the burn and the leftover), legacy configs, each DAMM v2
|
|
93
|
+
config check and the refusals; the fuzz graduates random configs with the withdrawals in a random order. The fourth
|
|
94
|
+
stage completes the port (35 of 35): the DAMM v1 migration, deprecated for new configs but still taken by pools of
|
|
95
|
+
configs made before 0.2.1: `migration_meteora_damm_create_metadata`, `migrate_meteora_damm` (DAMM v1's
|
|
96
|
+
`initialize_permissionless_constant_product_pool_with_config2` under flash rent, the burn, the partner's and
|
|
97
|
+
creator's LP split), `migrate_meteora_damm_lock_lp_token` (DAMM v1's `lock` into the owner's lock escrow) and
|
|
98
|
+
`migrate_meteora_damm_claim_lp_token`. `showcase/test/meteora-dbc-migration-v1.test.ts` checks them on both programs,
|
|
99
|
+
which call DAMM v1 (`Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB`, upgraded in slot 468,782,174 on 2026-11-13,
|
|
100
|
+
sha256 `ea4e6581…7f58`) and the dynamic vault (`24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi`, sha256
|
|
101
|
+
`a3c23d24…fdcb`) as deployed on mainnet (fetched by `scripts/fetch-programs.sh`, not kept here; their licences are
|
|
102
|
+
not established) on DAMM v1's six migration configs and the wrapped SOL vault read from mainnet
|
|
103
|
+
(`showcase/test/fixtures/meteora-dbc/damm-v1/`), with configs made for DAMM v2 and their migration option rewritten
|
|
104
|
+
to DAMM v1 in both ledgers: every progress state, each fee option with its config and another, the customizable
|
|
105
|
+
option, each DAMM v1 config check, partner and creator LP splits locked and claimed in different orders, a
|
|
106
|
+
self-partnered creator, vested shares (which DAMM v1 leaves with the pool authority), Token-2022 on either side
|
|
107
|
+
(refused, 3007, by both), a transfer hook pool (refused), wrapped SOL in its mainnet vault, fixed supplies, a payer
|
|
108
|
+
short of the rent, `transfer_pool_creator` after a DAMM v1 migration, and the account refusals; the migration fuzz
|
|
109
|
+
now takes the DAMM v1 or the DAMM v2 path at random, locking and claiming the LP among the other steps. The binary is
|
|
110
|
+
identified as 0.2.2 by its instruction names, error messages and source paths; it was not rebuilt. The README of
|
|
111
|
+
`showcase/mainnet/meteora-dbc/` lists what is compared, what differs and what is not verified.
|
|
112
|
+
- Changed: `typesol/testing`'s `t.ix` refuses an argument left out or misspelt. An argument missing from the arguments
|
|
113
|
+
object was encoded as zeros when its size is fixed (as Anchor's coder does), so a misspelt argument name sent
|
|
114
|
+
zeros and a misspelt `Option` argument sent None; the same for a field left out of a struct argument or of a data
|
|
115
|
+
enum variant, at any depth, and for a variant that has fields named without them (`{ Box: {} }`). Each is now an
|
|
116
|
+
error naming the instruction and the argument and listing the instruction's arguments (`set: argument "amount" is
|
|
117
|
+
missing (it takes amount, cap, frame, shape; only an Option may be left out)`), or naming the field's path and the
|
|
118
|
+
struct's fields (`set(frame).origin.y is missing (Point has x, y; only an Option may be left out)`). An `Option`
|
|
119
|
+
may still be left out (None). A key that names no argument or field, in its IDL (snake_case) or camelCase
|
|
120
|
+
spelling, was ignored and is now an error too (`set has no argument "amonut" (it takes amount, cap, frame, shape)`,
|
|
121
|
+
`set(frame) has no field "scael" (Frame has origin, scale)`). `null` for an argument or field that is not an
|
|
122
|
+
`Option` was encoded as 0 for an integer of up to 32 bits and as false for a bool; it is now an error
|
|
123
|
+
(`set(amount) is null, but it is a u64, not an Option`). No test of the repository passed a missing or unknown key.
|
|
124
|
+
- Added: `t.events(res)` in `typesol/testing`: the events a successful transaction emitted, decoded from the IDL, in
|
|
125
|
+
the order the program emitted them (`[{ name, data }]`, values as `t.account` gives them): `emit`'s `Program data:`
|
|
126
|
+
log lines while this program runs, and `emitCpi`'s self-CPIs, which it finds in the transaction's inner
|
|
127
|
+
instructions. It needs no other package; decoding events in a test took `t.coder.events.decode(…)` on each log line,
|
|
128
|
+
which needs `@anchor-lang/core`, and did not see `emitCpi` events. `t.coder` does not change. TypeSOL's Borsh coder
|
|
129
|
+
decodes events as Anchor's `coder.events.decode` does (test/client/idl-coder.test.ts compares the two on random
|
|
130
|
+
values for every program with events, and on a wrong discriminator, which both decode as null).
|
|
131
|
+
|
|
132
|
+
- Changed, now refused: a call of a helper that returns the result of `merkleVerify`, `verifyEd25519` or
|
|
133
|
+
`verifySecp256k1` whose result decides nothing. 0.46.0 refused such a call of the three themselves (as a statement,
|
|
134
|
+
as the condition of an `if` with an empty body, kept in a local never read) but compiled the same through a helper,
|
|
135
|
+
which dropped the result and checked nothing. A helper (a function, a const arrow or function expression, a generic
|
|
136
|
+
one, a closure) returns a check when one of its `return`s gives the result of one of the three or of another such
|
|
137
|
+
helper, directly, in parentheses or under `as`, combined with `&&`, `||`, `!` or `?:`, or through a local of the
|
|
138
|
+
helper that nothing but its returns reads. Its call is held to the same three rules, the message naming the helper
|
|
139
|
+
and the built-in: "the result of checkProof is discarded, so nothing is checked: it returns the result of
|
|
140
|
+
merkleVerify; write require(checkProof(…), error)", "the result of signed is not acted on: the if around it has an
|
|
141
|
+
empty body, so nothing is checked: it returns the result of verifyEd25519; …", "the result of checkProof is never
|
|
142
|
+
read (ok is not used), so nothing is checked: …". A helper that requires the result itself, or reads it anywhere
|
|
143
|
+
but in a `return`, does not return a check, and neither does one returning an unrelated boolean. Still not caught: a
|
|
144
|
+
result stored in an account field, a struct or an Option, compared (`=== true`) or passed to a function that ignores
|
|
145
|
+
it; a helper that branches on the result and returns literals (`if (!ok) { return false; } return true;`); and a
|
|
146
|
+
helper that returns what a function passed to it returns. No program of the repository is refused: the 76 build to
|
|
147
|
+
the same binaries and IDLs as with 0.47.0 (test/language/diagnostics.test.ts; a row in the refused-constructs table
|
|
148
|
+
of docs/language-statements.md; docs/language-chain.md).
|
|
149
|
+
|
|
150
|
+
## 0.47.0 — 2026-11-13
|
|
151
|
+
|
|
152
|
+
A minor release: it removes an optional peer dependency (`@anchor-lang/core`) and changes what `t.coder` of
|
|
153
|
+
`typesol/testing` needs. Compiled programs do not change: every program builds to the same bytes as with 0.46.0.
|
|
154
|
+
|
|
155
|
+
- Changed: `typesol init` no longer adds `@anchor-lang/core` to a project's `devDependencies`, and `@typesol/cli` no
|
|
156
|
+
longer lists it as an optional peer dependency. `typesol/testing` used that package (and through it Solana web3.js
|
|
157
|
+
1.x) only to encode instruction arguments and decode accounts and return data; it now does both with its own Borsh
|
|
158
|
+
coder, read from the IDL as Anchor's `BorshCoder` reads it (test/client/idl-coder.test.ts compares the two on random
|
|
159
|
+
values for every example, template and shape program). A new project's `npm install` adds 96 packages instead of 156
|
|
160
|
+
and reports 0 vulnerabilities instead of 7 (4 moderate, 3 high). Existing projects can remove `@anchor-lang/core`
|
|
161
|
+
from `devDependencies` after upgrading, unless their tests import it or read `t.coder`. Compiled programs and IDLs
|
|
162
|
+
do not change.
|
|
163
|
+
- Changed: `t.coder` is still Anchor's `BorshCoder`, now loaded from `@anchor-lang/core` the first time it is read; it
|
|
164
|
+
throws an error saying to install the package when it is missing. `TestProgram.idl` and `programHarness`'s `idl`
|
|
165
|
+
parameter are typed with `TestIdl`, a structural type an Anchor `Idl` satisfies, and `t.coder` with
|
|
166
|
+
`AnchorBorshCoder`.
|
|
167
|
+
- Changed: an integer of 64 bits or more outside its type's range now fails with an error naming the argument; Anchor's
|
|
168
|
+
coder wrote it wrong (a negative `u64` as its absolute value, `2n ** 63n` as an `i64` as that type's minimum). A
|
|
169
|
+
missing argument of variable size (a string, a Vec) fails with an error naming it instead of a buffer offset error.
|
|
170
|
+
`bytes` arguments also take a `Uint8Array` or a `number[]` (Anchor's coder took only a Buffer), and instruction data
|
|
171
|
+
is no longer limited to 1,000 bytes.
|
|
172
|
+
|
|
9
173
|
## 0.46.0 — 2026-11-13
|
|
10
174
|
|
|
11
175
|
A minor release: it adds a flag (`init --no-agent-files`) and an export of `typesol/compiler` (`typescriptMessage`),
|
package/NOTICE
CHANGED
|
@@ -80,5 +80,15 @@ Third-party material in this repository only (not in the published package)
|
|
|
80
80
|
- showcase/mainnet/: TypeSOL ports of mainnet programs, which follow their originals' source: Raydium CP-Swap, CLMM
|
|
81
81
|
and AMM v4, Jito's MEV programs, marginfi v2, coral-xyz/multisig and SPL Stake Pool (Apache-2.0), and Phoenix v1
|
|
82
82
|
(MIT, Copyright Ellipsis Labs). Every file says which program it ports and under which licence in its first line.
|
|
83
|
+
- showcase/mainnet/meteora-dbc/: a TypeSOL port of Meteora's Dynamic Bonding Curve (MeteoraAg/dynamic-bonding-curve,
|
|
84
|
+
release 0.2.2, commit 91e696e), with its tests showcase/test/meteora-dbc*.ts and the mainnet accounts of two of its
|
|
85
|
+
pools, the seven DAMM v2 migration configs, the six DAMM v1 migration configs and the wrapped SOL dynamic vault those
|
|
86
|
+
tests read (showcase/test/fixtures/meteora-dbc/; DAMM v2 is under the Meteora Noncommercial Licence too, the licences
|
|
87
|
+
of DAMM v1 and the dynamic vault are not established). It is not under this repository's MIT
|
|
88
|
+
licence: it is subject to Meteora's Non-commercial Licence, whose text is showcase/mainnet/meteora-dbc/LICENSE.md.
|
|
89
|
+
Required Notice: All underlying software code is subject to the licence set out at https://github.com/MeteoraAg/dynamic-bonding-curve
|
|
90
|
+
The program's mainnet binary is not kept here either, nor are those of DAMM v2, the locker, DAMM v1 and the dynamic
|
|
91
|
+
vault its migrations call:
|
|
92
|
+
scripts/fetch-programs.sh downloads them (test/programs/SOURCES.md).
|
|
83
93
|
- showcase/program-examples/: ports of solana-developers/program-examples (MIT, Copyright Solana Foundation; the
|
|
84
94
|
licence text is in showcase/program-examples/README.md).
|
package/README.md
CHANGED
|
@@ -80,6 +80,12 @@ succeeds. A case study for each says what was compared and what was not.
|
|
|
80
80
|
| [Jito MEV](docs/case-study-jito-mev.md) | Anchor, three programs | 24 | 150 |
|
|
81
81
|
| [coral-xyz/multisig](docs/case-study-multisig.md) | Anchor | all | 52 |
|
|
82
82
|
|
|
83
|
+
A ninth port is held to a narrower comparison and is not counted above:
|
|
84
|
+
[Meteora Dynamic Bonding Curve 0.2.2](showcase/mainnet/meteora-dbc) (Anchor, launchpad, all 35 instructions, with its
|
|
85
|
+
migrations into DAMM v1 and DAMM v2). Outcomes, error codes, account bytes, events and return data are the same as the
|
|
86
|
+
mainnet binary's; log text and compute units are not compared. That directory is under Meteora's Non-commercial
|
|
87
|
+
Licence, not this repository's (see its README).
|
|
88
|
+
|
|
83
89
|
Random walks with fixed or printed seeds run on top of these counts ([docs/testing.md](docs/testing.md)). The
|
|
84
90
|
sources are in [`showcase/mainnet`](showcase/mainnet), and where each original binary comes from is recorded in
|
|
85
91
|
[test/programs/SOURCES.md](test/programs/SOURCES.md).
|
|
@@ -207,9 +213,8 @@ and runs it in LiteSVM, an in-process Solana runtime. `build` writes `target/cou
|
|
|
207
213
|
IDL), `counter.client.ts` and `counter.build.json`.
|
|
208
214
|
|
|
209
215
|
`init` also writes rules and an MCP server config for AI coding agents (AGENTS.md, CLAUDE.md, `.cursor/`, `.mcp.json`)
|
|
210
|
-
and lists them; `--no-agent-files` leaves them out. `
|
|
211
|
-
|
|
212
|
-
uses to encode instructions and decode accounts, so the tests need it; none of it is in the program you deploy.
|
|
216
|
+
and lists them; `--no-agent-files` leaves them out. `typesol/testing` encodes instructions and decodes accounts from
|
|
217
|
+
the IDL itself, so a new project installs neither Anchor's TypeScript package nor Solana web3.js 1.x.
|
|
213
218
|
|
|
214
219
|
Other versions work, but their binaries are not covered by the project's tests: `typesol build` warns once when the
|
|
215
220
|
clang is another one (`--toolchain-strict` or `TYPESOL_TOOLCHAIN=strict` makes that an error), and every build records
|
|
@@ -437,6 +442,7 @@ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Phoenix v1](docs/case
|
|
|
437
442
|
| [`phoenix/`](showcase/mainnet/phoenix) | Phoenix v1, Ellipsis Labs' on-chain limit order book and a native program, in full, all 28 instructions: price-time matching over lib-sokoban red-black trees in one market account, every order type, self-trade behaviours, time in force, eviction, cancels, seats and fees, its events as Log self-CPIs byte for byte |
|
|
438
443
|
| [`spl-stake-pool/`](showcase/mainnet/spl-stake-pool) | SPL Stake Pool in full, all 27 instructions, a native program and the one behind most liquid staking tokens: pools of stake across up to 20,000 validators, SOL and stake deposits and withdrawals, rebalancing over epochs, fees and authorities, token metadata |
|
|
439
444
|
| [`raydium-amm/`](showcase/mainnet/raydium-amm) | Raydium AMM v4, the original constant-product AMM and a native (non-Anchor) program, in full: pool creation, deposits and withdrawals, the v1 and v2 swaps, P&L and administration, down to its log records and panics |
|
|
445
|
+
| [`meteora-dbc/`](showcase/mainnet/meteora-dbc) | Meteora Dynamic Bonding Curve 0.2.2 in full, all 35 instructions: configs, pool creation on SPL Token and Token-2022 (transfer fees and hooks), the three swap modes, fee schedulers and the rate limiter, fee claims, the locker, and the migrations into DAMM v1 and DAMM v2. Under Meteora's Non-commercial Licence (its own `LICENSE.md`); log text and compute units are not compared |
|
|
440
446
|
| [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
|
|
441
447
|
|
|
442
448
|
## Status
|
|
@@ -10,6 +10,12 @@ import { type Value, type Ref, type Local, type Closure, type FunctionChoice, ty
|
|
|
10
10
|
export declare abstract class EmitterBase {
|
|
11
11
|
protected readonly reporter: Reporter;
|
|
12
12
|
protected readonly model: ProgramModel;
|
|
13
|
+
/**
|
|
14
|
+
* `const EVENT_AUTHORITY_CHECK = "address"`: Anchor 1.x's #[event_cpi] accounts. The event authority is checked by
|
|
15
|
+
* address among the constraints (ConstraintAddress, 2012) instead of by seeds when the accounts load (2006), and the
|
|
16
|
+
* program account is not checked: the event's self-CPI names this program's id, as Anchor's emit_cpi! does.
|
|
17
|
+
*/
|
|
18
|
+
protected get eventAuthorityByAddress(): boolean;
|
|
13
19
|
protected readonly imports: Map<string, string>;
|
|
14
20
|
protected readonly accounts: Map<string, AccountParam>;
|
|
15
21
|
protected readonly args: Map<string, Local>;
|
|
@@ -9,6 +9,14 @@ import { isStable, cString, valueC, fixedVecC, passedByPointer, } from "./shared
|
|
|
9
9
|
export class EmitterBase {
|
|
10
10
|
reporter;
|
|
11
11
|
model;
|
|
12
|
+
/**
|
|
13
|
+
* `const EVENT_AUTHORITY_CHECK = "address"`: Anchor 1.x's #[event_cpi] accounts. The event authority is checked by
|
|
14
|
+
* address among the constraints (ConstraintAddress, 2012) instead of by seeds when the accounts load (2006), and the
|
|
15
|
+
* program account is not checked: the event's self-CPI names this program's id, as Anchor's emit_cpi! does.
|
|
16
|
+
*/
|
|
17
|
+
get eventAuthorityByAddress() {
|
|
18
|
+
return this.model.constants.get("EVENT_AUTHORITY_CHECK")?.value === "address";
|
|
19
|
+
}
|
|
12
20
|
imports;
|
|
13
21
|
accounts = new Map();
|
|
14
22
|
args = new Map();
|
|
@@ -57,6 +57,22 @@ export class CallEmitter extends ExpressionEmitter {
|
|
|
57
57
|
this.fail(node, "stackHeight() takes no arguments");
|
|
58
58
|
return { c: "sol_get_stack_height()", type: U64 };
|
|
59
59
|
}
|
|
60
|
+
case "processedSiblingInstructionCount": {
|
|
61
|
+
if (args.length)
|
|
62
|
+
this.fail(node, "processedSiblingInstructionCount() takes no arguments");
|
|
63
|
+
const t = this.tmp("sibn");
|
|
64
|
+
this.line(`uint64_t ${t} = ts_sibling_count();`);
|
|
65
|
+
return { c: t, type: U64 };
|
|
66
|
+
}
|
|
67
|
+
case "processedSiblingInstruction": {
|
|
68
|
+
if (args.length !== 1)
|
|
69
|
+
this.fail(node, "processedSiblingInstruction(index) takes the sibling's index");
|
|
70
|
+
const i = this.expect(this.expr(args[0], U64), U64, args[0]);
|
|
71
|
+
const t = this.tmp("sib");
|
|
72
|
+
this.line(`TsIx ${t};`);
|
|
73
|
+
this.line(`TS_TRY(ts_sibling_load(${i.c}, &${t}));`);
|
|
74
|
+
return { c: t, type: { kind: "txIx" } };
|
|
75
|
+
}
|
|
60
76
|
case "constraint":
|
|
61
77
|
this.fail(node, "constraint(account, condition, error?) goes at the start of an instruction's body, before any other statement");
|
|
62
78
|
case "require": {
|
|
@@ -1598,6 +1614,8 @@ export class CallEmitter extends ExpressionEmitter {
|
|
|
1598
1614
|
return this.isTxIx(node.expression);
|
|
1599
1615
|
if (ts.isIdentifier(node))
|
|
1600
1616
|
return this.lookup(node.text)?.type.kind === "txIx";
|
|
1617
|
+
if (ts.isCallExpression(node) && this.exportName(node.expression) === "processedSiblingInstruction")
|
|
1618
|
+
return true;
|
|
1601
1619
|
return (ts.isCallExpression(node) &&
|
|
1602
1620
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
1603
1621
|
node.expression.name.text === "get" &&
|
|
@@ -466,7 +466,9 @@ export class CpiEmitter extends MetaplexEmitter {
|
|
|
466
466
|
const signer = this.tmp("signer");
|
|
467
467
|
this.line(`SolAccountMeta ${m}[1] = {{&a_${cpi.authority}->key, false, true}};`);
|
|
468
468
|
this.line(`SolSignerSeed ${sd}[2] = {{(const uint8_t *)"__event_authority", 17}, {&eb_${cpi.authority}, 1}};`);
|
|
469
|
-
|
|
469
|
+
// EVENT_AUTHORITY_CHECK = "address": the program account is unchecked, so the CPI names this program's id.
|
|
470
|
+
const target = this.eventAuthorityByAddress ? `(SolPubkey *)params->program_id` : `&a_${cpi.program}->key`;
|
|
471
|
+
this.line(`SolInstruction ${ix} = {${target}, ${m}, 1, ${buf}, ${len}};`);
|
|
470
472
|
this.line(`SolSignerSeeds ${signer} = {${sd}, 2};`);
|
|
471
473
|
this.line(`TS_TRY(ts_invoke(params, &${ix}, &${signer}, 1));`);
|
|
472
474
|
return;
|
|
@@ -84,9 +84,12 @@ export class FunctionEmitter extends StatementEmitter {
|
|
|
84
84
|
// constraint order), as Anchor's `#[account(address = sysvar::instructions::ID)]` on an UncheckedAccount.
|
|
85
85
|
if (k.kind === "instructionsSysvar" && !a.constraints.address)
|
|
86
86
|
head.push(` TS_TRY(ts_check_address(${v}, &TS_INSTRUCTIONS_SYSVAR_ID));`);
|
|
87
|
-
if (k.kind === "eventAuthority")
|
|
87
|
+
if (k.kind === "eventAuthority" && this.eventAuthorityByAddress)
|
|
88
|
+
// Anchor 1.x: the address is checked among the constraints (constraintChecks); here only the PDA and its bump.
|
|
89
|
+
head.push(` uint8_t eb_${a.name};`, ` SolPubkey ek_${a.name};`, ` { SolSignerSeed s = {(const uint8_t *)"__event_authority", 17}; if (ts_find_pda(&s, 1, params->program_id, &ek_${a.name}, &eb_${a.name}) != SUCCESS) TS_FAIL(TS_ERR_SEEDS, "TypeSOL: no event authority"); }`);
|
|
90
|
+
else if (k.kind === "eventAuthority")
|
|
88
91
|
head.push(` uint8_t eb_${a.name};`, ` TS_TRY(ts_check_event_authority(${v}, params->program_id, &eb_${a.name}));`);
|
|
89
|
-
if (k.kind === "selfProgram")
|
|
92
|
+
if (k.kind === "selfProgram" && !this.eventAuthorityByAddress)
|
|
90
93
|
head.push(` if (!ts_key_eq(&${v}->key, params->program_id)) TS_FAIL(TS_ERR_WRONG_PROGRAM, "TypeSOL: expected this program");`);
|
|
91
94
|
if (k.kind === "programData")
|
|
92
95
|
head.push(` TS_TRY(ts_check_program_data(${v}, params->program_id));`);
|
|
@@ -667,6 +670,8 @@ export class FunctionEmitter extends StatementEmitter {
|
|
|
667
670
|
}
|
|
668
671
|
if (c.executable)
|
|
669
672
|
out.push(` if (!a_${a.name}->executable) TS_FAIL(TS_ERR_CONSTRAINT_EXECUTABLE, "TypeSOL: ${a.name} must be an executable program");`);
|
|
673
|
+
if (k === "eventAuthority" && this.eventAuthorityByAddress)
|
|
674
|
+
out.push(` if (!ts_key_eq(&a_${a.name}->key, &ek_${a.name})) TS_FAIL(TS_ERR_ADDRESS, "TypeSOL: ${a.name} is not this program's event authority");`);
|
|
670
675
|
if (c.address) {
|
|
671
676
|
out.push(` static const SolPubkey ca_${a.name} = {${cBytes(c.address.bytes)}};`);
|
|
672
677
|
out.push(` if (!ts_key_eq(&a_${a.name}->key, &ca_${a.name})) ${this.checkFail(a, "address", "TS_ERR_ADDRESS", `${a.name} is not the expected address`)};`);
|
|
@@ -68,6 +68,11 @@ export function emitProgram(analysis, opts = {}) {
|
|
|
68
68
|
else if (panicFlag?.value === true)
|
|
69
69
|
out.push(`#define TS_PANIC_ABORT 1`);
|
|
70
70
|
}
|
|
71
|
+
// `const EVENT_AUTHORITY_CHECK = "address"`: the emitCpi accounts are checked as Anchor 1.x's #[event_cpi] checks
|
|
72
|
+
// them (read by the emitter; nothing to define in C).
|
|
73
|
+
const eventCheck = model.constants.get("EVENT_AUTHORITY_CHECK");
|
|
74
|
+
if (eventCheck && eventCheck.value !== "address")
|
|
75
|
+
reporter.error(analysis.sourceFile, 'EVENT_AUTHORITY_CHECK must be "address" (the event authority checked as Anchor 1.x\'s `address = EVENT_AUTHORITY` constraint, 2012 among the constraints, and the program account left unchecked); leave it out for the default');
|
|
71
76
|
// `const NATIVE_ACCOUNT_WRITES = true`: loadRawMut / storeBorsh / BigVec writes leave writability and aliasing to the
|
|
72
77
|
// runtime, as a native program does (read by the emitter; nothing to define in C).
|
|
73
78
|
const nativeWrites = model.constants.get("NATIVE_ACCOUNT_WRITES");
|
|
@@ -3,6 +3,11 @@ import { type TypeScope } from "../analyze.js";
|
|
|
3
3
|
import { type FieldType } from "../model.js";
|
|
4
4
|
import { type Value, type Local, type Closure, type FunctionChoice, type Ref } from "./shared.js";
|
|
5
5
|
import { CpiEmitter } from "./cpi.js";
|
|
6
|
+
/** A call whose result is a proof or signature check: a built-in, or a helper (`name`) returning the result of one (`wraps`). */
|
|
7
|
+
interface CheckCall {
|
|
8
|
+
name: string;
|
|
9
|
+
wraps?: string;
|
|
10
|
+
}
|
|
6
11
|
export declare abstract class StatementEmitter extends CpiEmitter {
|
|
7
12
|
protected statement(stmt: ts.Statement, topLevel?: boolean): void;
|
|
8
13
|
protected statementInner(stmt: ts.Statement, topLevel: boolean): void;
|
|
@@ -169,8 +174,29 @@ export declare abstract class StatementEmitter extends CpiEmitter {
|
|
|
169
174
|
* a field path (no calls), so reading it once per name reads the same thing JS reads once.
|
|
170
175
|
*/
|
|
171
176
|
protected destructure(list: ts.VariableDeclarationList, d: ts.VariableDeclaration, pattern: ts.ObjectBindingPattern, init: ts.Expression, topLevel: boolean): void;
|
|
172
|
-
/**
|
|
173
|
-
|
|
177
|
+
/**
|
|
178
|
+
* The check `e` (in parentheses, or under `!` if `negated`) calls: merkleVerify, verifyEd25519 or verifySecp256k1,
|
|
179
|
+
* or a helper that returns the result of one (see returnedCheck).
|
|
180
|
+
*/
|
|
181
|
+
protected verifierCall(e: ts.Expression, negated?: boolean): CheckCall | undefined;
|
|
182
|
+
/** The built-in whose result a function declared where it is called (a closure) returns, if it does. */
|
|
183
|
+
private localFunctionCheck;
|
|
184
|
+
/** Helpers whose returnedCheck is known (null: none), and the ones being looked at (recursion). */
|
|
185
|
+
private readonly checkMemo;
|
|
186
|
+
private readonly checkActive;
|
|
187
|
+
private checkMetActive;
|
|
188
|
+
/** The built-in whose result the helper or generic helper `name` returns, if it does. */
|
|
189
|
+
private helperCheck;
|
|
190
|
+
/**
|
|
191
|
+
* The built-in check (merkleVerify, verifyEd25519 or verifySecp256k1) a helper's result comes from: a `return` that
|
|
192
|
+
* yields its result, or a helper's that returns one, directly, in parentheses or under `as`, combined with `&&`,
|
|
193
|
+
* `||`, `!` or `?:`, or through a local of the helper that was given such a value and is read only in returns. A
|
|
194
|
+
* helper that acts on the result itself (requires it, branches on it) and returns something else returns no check.
|
|
195
|
+
* A helper still being looked at (recursion) counts as returning none.
|
|
196
|
+
*/
|
|
197
|
+
private returnedCheck;
|
|
198
|
+
/** The built-in check whose result the value `e`, returned by `fn`, carries (see returnedCheck). */
|
|
199
|
+
private checkIn;
|
|
174
200
|
/**
|
|
175
201
|
* `const ok = merkleVerify(…)` (or `ok = …`, the call in parentheses or under `as`) where the function that
|
|
176
202
|
* declares `ok` never reads it: nothing is checked. A read anywhere in that function counts, in a closure inside it
|
|
@@ -180,3 +206,4 @@ export declare abstract class StatementEmitter extends CpiEmitter {
|
|
|
180
206
|
protected expressionStatement(e: ts.Expression, topLevel: boolean): void;
|
|
181
207
|
protected assign(target: ts.Expression, valueNode: ts.Expression, op?: ts.BinaryOperator, topLevel?: boolean): void;
|
|
182
208
|
}
|
|
209
|
+
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { MAX_RETURN_DATA, calleeName, resolveScalarType, resolveValueType, structNameOf, typesolName } from "../analyze.js";
|
|
3
|
-
import { INT_INFO, isScalar, optionKey, sameType, scalarSize, typeName } from "../model.js";
|
|
3
|
+
import { INT_INFO, isScalar, optionKey, sameType, scalarSize, typeName, } from "../model.js";
|
|
4
4
|
import { U64, BOOL, PUBKEY, cString, fixedVecC, helperSignature, optC, scalarC, scalarStorageC, storageDecl, valueC, } from "./shared.js";
|
|
5
5
|
import { CpiEmitter } from "./cpi.js";
|
|
6
6
|
import { cTokens, declaredNames, isGlobalName, parameterDecls, usedNames } from "./outline.js";
|
|
7
7
|
/**
|
|
8
8
|
* Statements: variables, assignment, control flow and return.
|
|
9
9
|
*/
|
|
10
|
+
/** The built-ins that return whether a proof or signature holds, and fail nothing by themselves. */
|
|
11
|
+
const VERIFIERS = new Set(["merkleVerify", "verifyEd25519", "verifySecp256k1"]);
|
|
10
12
|
/** A proof or signature check whose result decides nothing: `how` says why (discarded, never read, an empty if). */
|
|
11
|
-
const VERIFIER_UNUSED = (
|
|
13
|
+
const VERIFIER_UNUSED = (call, how) => `the result of ${call.name} ${how}, so nothing is checked: ${call.wraps ? `it returns the result of ${call.wraps}` : `it returns whether the ${call.name === "merkleVerify" ? "proof" : "signature"} holds`}; write require(${call.name}(…), error)`;
|
|
12
14
|
export class StatementEmitter extends CpiEmitter {
|
|
13
15
|
statement(stmt, topLevel = false) {
|
|
14
16
|
const outer = this.where;
|
|
@@ -1902,14 +1904,155 @@ export class StatementEmitter extends CpiEmitter {
|
|
|
1902
1904
|
this.variable({ ...list, declarations: [decl] }, topLevel);
|
|
1903
1905
|
}
|
|
1904
1906
|
}
|
|
1905
|
-
/**
|
|
1907
|
+
/**
|
|
1908
|
+
* The check `e` (in parentheses, or under `!` if `negated`) calls: merkleVerify, verifyEd25519 or verifySecp256k1,
|
|
1909
|
+
* or a helper that returns the result of one (see returnedCheck).
|
|
1910
|
+
*/
|
|
1906
1911
|
verifierCall(e, negated = false) {
|
|
1907
1912
|
while (ts.isParenthesizedExpression(e) || (negated && ts.isPrefixUnaryExpression(e) && e.operator === ts.SyntaxKind.ExclamationToken))
|
|
1908
1913
|
e = ts.isParenthesizedExpression(e) ? e.expression : e.operand;
|
|
1909
|
-
if (!ts.isCallExpression(e))
|
|
1914
|
+
if (!ts.isCallExpression(e) || !ts.isIdentifier(e.expression))
|
|
1915
|
+
return undefined;
|
|
1916
|
+
const builtin = this.exportName(e.expression);
|
|
1917
|
+
if (builtin)
|
|
1918
|
+
return VERIFIERS.has(builtin) ? { name: builtin } : undefined;
|
|
1919
|
+
// The helper the call runs, found as helperOf finds it but without instantiating a generic one.
|
|
1920
|
+
const callee = e.expression;
|
|
1921
|
+
const name = this.helper?.fnArgs?.get(callee.text) ?? calleeName(callee, this.model.helperDecls, this.checker) ?? (this.lookup(callee.text) ? undefined : callee.text);
|
|
1922
|
+
const wraps = name !== undefined ? this.helperCheck(name) : this.localFunctionCheck(callee, this.imports);
|
|
1923
|
+
return wraps ? { name: callee.text, wraps } : undefined;
|
|
1924
|
+
}
|
|
1925
|
+
/** The built-in whose result a function declared where it is called (a closure) returns, if it does. */
|
|
1926
|
+
localFunctionCheck(callee, imports) {
|
|
1927
|
+
const decl = this.checker.getSymbolAtLocation(callee)?.valueDeclaration;
|
|
1928
|
+
const init = decl && ts.isVariableDeclaration(decl) ? decl.initializer : undefined;
|
|
1929
|
+
const fn = init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init)) ? init : decl && ts.isFunctionDeclaration(decl) ? decl : undefined;
|
|
1930
|
+
return fn ? this.returnedCheck(fn, imports) : undefined;
|
|
1931
|
+
}
|
|
1932
|
+
/** Helpers whose returnedCheck is known (null: none), and the ones being looked at (recursion). */
|
|
1933
|
+
checkMemo = new Map();
|
|
1934
|
+
checkActive = new Set();
|
|
1935
|
+
checkMetActive = false;
|
|
1936
|
+
/** The built-in whose result the helper or generic helper `name` returns, if it does. */
|
|
1937
|
+
helperCheck(name) {
|
|
1938
|
+
const h = this.model.helpers.get(name) ?? this.model.generics.get(name);
|
|
1939
|
+
return h ? this.returnedCheck(h.node, h.imports) : undefined;
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* The built-in check (merkleVerify, verifyEd25519 or verifySecp256k1) a helper's result comes from: a `return` that
|
|
1943
|
+
* yields its result, or a helper's that returns one, directly, in parentheses or under `as`, combined with `&&`,
|
|
1944
|
+
* `||`, `!` or `?:`, or through a local of the helper that was given such a value and is read only in returns. A
|
|
1945
|
+
* helper that acts on the result itself (requires it, branches on it) and returns something else returns no check.
|
|
1946
|
+
* A helper still being looked at (recursion) counts as returning none.
|
|
1947
|
+
*/
|
|
1948
|
+
returnedCheck(fn, imports) {
|
|
1949
|
+
const known = this.checkMemo.get(fn);
|
|
1950
|
+
if (known !== undefined)
|
|
1951
|
+
return known ?? undefined;
|
|
1952
|
+
if (this.checkActive.has(fn)) {
|
|
1953
|
+
this.checkMetActive = true;
|
|
1910
1954
|
return undefined;
|
|
1911
|
-
|
|
1912
|
-
|
|
1955
|
+
}
|
|
1956
|
+
const outer = this.checkMetActive;
|
|
1957
|
+
this.checkMetActive = false;
|
|
1958
|
+
this.checkActive.add(fn);
|
|
1959
|
+
let found;
|
|
1960
|
+
try {
|
|
1961
|
+
const returns = [];
|
|
1962
|
+
if (fn.body && !ts.isBlock(fn.body))
|
|
1963
|
+
returns.push(fn.body);
|
|
1964
|
+
else if (fn.body) {
|
|
1965
|
+
const visit = (n) => {
|
|
1966
|
+
if (ts.isFunctionLike(n))
|
|
1967
|
+
return;
|
|
1968
|
+
if (ts.isReturnStatement(n) && n.expression)
|
|
1969
|
+
returns.push(n.expression);
|
|
1970
|
+
ts.forEachChild(n, visit);
|
|
1971
|
+
};
|
|
1972
|
+
visit(fn.body);
|
|
1973
|
+
}
|
|
1974
|
+
for (const r of returns)
|
|
1975
|
+
if ((found = this.checkIn(r, fn, imports, new Set())))
|
|
1976
|
+
break;
|
|
1977
|
+
}
|
|
1978
|
+
finally {
|
|
1979
|
+
this.checkActive.delete(fn);
|
|
1980
|
+
}
|
|
1981
|
+
// "None" found while a helper further up was still open may change once it is known: not kept.
|
|
1982
|
+
if (found || !this.checkMetActive)
|
|
1983
|
+
this.checkMemo.set(fn, found ?? null);
|
|
1984
|
+
this.checkMetActive ||= outer;
|
|
1985
|
+
return found;
|
|
1986
|
+
}
|
|
1987
|
+
/** The built-in check whose result the value `e`, returned by `fn`, carries (see returnedCheck). */
|
|
1988
|
+
checkIn(e, fn, imports, seen) {
|
|
1989
|
+
while (ts.isParenthesizedExpression(e) || ts.isAsExpression(e) || ts.isNonNullExpression(e) || ts.isSatisfiesExpression(e))
|
|
1990
|
+
e = e.expression;
|
|
1991
|
+
if (ts.isCallExpression(e)) {
|
|
1992
|
+
if (!ts.isIdentifier(e.expression))
|
|
1993
|
+
return undefined;
|
|
1994
|
+
const builtin = imports.get(e.expression.text);
|
|
1995
|
+
if (builtin)
|
|
1996
|
+
return VERIFIERS.has(builtin) ? builtin : undefined;
|
|
1997
|
+
const name = calleeName(e.expression, this.model.helperDecls, this.checker);
|
|
1998
|
+
return name !== undefined ? this.helperCheck(name) : this.localFunctionCheck(e.expression, imports);
|
|
1999
|
+
}
|
|
2000
|
+
if (ts.isPrefixUnaryExpression(e))
|
|
2001
|
+
return e.operator === ts.SyntaxKind.ExclamationToken ? this.checkIn(e.operand, fn, imports, seen) : undefined;
|
|
2002
|
+
if (ts.isBinaryExpression(e)) {
|
|
2003
|
+
const op = e.operatorToken.kind;
|
|
2004
|
+
if (op !== ts.SyntaxKind.AmpersandAmpersandToken && op !== ts.SyntaxKind.BarBarToken)
|
|
2005
|
+
return undefined;
|
|
2006
|
+
return this.checkIn(e.left, fn, imports, seen) ?? this.checkIn(e.right, fn, imports, seen);
|
|
2007
|
+
}
|
|
2008
|
+
if (ts.isConditionalExpression(e))
|
|
2009
|
+
return this.checkIn(e.condition, fn, imports, seen) ?? this.checkIn(e.whenTrue, fn, imports, seen) ?? this.checkIn(e.whenFalse, fn, imports, seen);
|
|
2010
|
+
if (!ts.isIdentifier(e))
|
|
2011
|
+
return undefined;
|
|
2012
|
+
// A local of `fn` (not of a closure in it), every value it is given, when nothing but a return reads it.
|
|
2013
|
+
const symbol = this.checker.getSymbolAtLocation(e);
|
|
2014
|
+
const decl = symbol?.valueDeclaration;
|
|
2015
|
+
if (!symbol || !decl || !ts.isVariableDeclaration(decl) || seen.has(symbol))
|
|
2016
|
+
return undefined;
|
|
2017
|
+
let owner = decl.parent;
|
|
2018
|
+
while (owner && !ts.isFunctionLike(owner))
|
|
2019
|
+
owner = owner.parent;
|
|
2020
|
+
if (owner !== fn)
|
|
2021
|
+
return undefined;
|
|
2022
|
+
seen.add(symbol);
|
|
2023
|
+
const values = decl.initializer ? [decl.initializer] : [];
|
|
2024
|
+
const inReturn = (n) => {
|
|
2025
|
+
for (let p = n.parent; p && p !== fn; p = p.parent) {
|
|
2026
|
+
if (ts.isReturnStatement(p))
|
|
2027
|
+
return true;
|
|
2028
|
+
if (ts.isFunctionLike(p))
|
|
2029
|
+
return false; // read in a closure: it may act on it
|
|
2030
|
+
}
|
|
2031
|
+
return !!fn.body && !ts.isBlock(fn.body);
|
|
2032
|
+
};
|
|
2033
|
+
let actedOn = false;
|
|
2034
|
+
const visit = (n) => {
|
|
2035
|
+
if (actedOn)
|
|
2036
|
+
return;
|
|
2037
|
+
if (ts.isIdentifier(n) && n !== decl.name && this.checker.getSymbolAtLocation(n) === symbol) {
|
|
2038
|
+
const p = n.parent;
|
|
2039
|
+
if (ts.isBinaryExpression(p) && p.left === n && p.operatorToken.kind === ts.SyntaxKind.EqualsToken)
|
|
2040
|
+
values.push(p.right);
|
|
2041
|
+
else if (!inReturn(n))
|
|
2042
|
+
actedOn = true;
|
|
2043
|
+
}
|
|
2044
|
+
ts.forEachChild(n, visit);
|
|
2045
|
+
};
|
|
2046
|
+
if (fn.body)
|
|
2047
|
+
visit(fn.body);
|
|
2048
|
+
if (actedOn)
|
|
2049
|
+
return undefined;
|
|
2050
|
+
for (const v of values) {
|
|
2051
|
+
const found = this.checkIn(v, fn, imports, seen);
|
|
2052
|
+
if (found)
|
|
2053
|
+
return found;
|
|
2054
|
+
}
|
|
2055
|
+
return undefined;
|
|
1913
2056
|
}
|
|
1914
2057
|
/**
|
|
1915
2058
|
* `const ok = merkleVerify(…)` (or `ok = …`, the call in parentheses or under `as`) where the function that
|
|
@@ -54,6 +54,23 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
54
54
|
this.line(`TS_TRY(ts_token_transfer_checked(params, ${p}, ${from.c}, ${mint.c}, ${to.c}, ${auth.c}, ${amt}, ${s.name}, ${s.count}));`);
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
|
+
case "transferCheckedWithHook": {
|
|
58
|
+
// transferChecked with a transfer hook's extra accounts, resolved among `hookAccounts` (a remaining-accounts
|
|
59
|
+
// range) as spl-transfer-hook-interface's add_extra_accounts_for_execute_cpi resolves them on chain.
|
|
60
|
+
if (a.length !== 6 && a.length !== 7)
|
|
61
|
+
this.fail(node, "transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts, signerSeeds?)");
|
|
62
|
+
const from = want(a[0], "token", true, "the source");
|
|
63
|
+
const mint = want(a[1], "mint", false, "the mint");
|
|
64
|
+
const to = want(a[2], "token", true, "the destination");
|
|
65
|
+
const auth = this.cpiAccount(a[3], "the authority");
|
|
66
|
+
const amt = this.expect(this.expr(a[4], U64), U64, a[4]);
|
|
67
|
+
const held = this.tmp("amt");
|
|
68
|
+
this.line(`uint64_t ${held} = ${amt.c};`);
|
|
69
|
+
const range = this.remainingRange(a[5]) ?? this.fail(a[5], "pass the hook's accounts as remainingAccounts() or rest.slice(a, b)");
|
|
70
|
+
const s = this.signerSeeds(a[6], auth, a[3]);
|
|
71
|
+
this.line(`TS_TRY(ts_token_transfer_checked_hook(params, ${p}, ${from.c}, ${mint.c}, ${to.c}, ${auth.c}, ${held}, ${range.base} + ${range.from}, ${range.base} + ${range.to}, ${s.name}, ${s.count}));`);
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
57
74
|
case "mintTo": {
|
|
58
75
|
arity(4);
|
|
59
76
|
// A Mut<Mint>, or a mint created and initialized earlier in this instruction (Mut<Signer> / Mut<AccountInfo>).
|
|
@@ -608,7 +625,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
608
625
|
return undefined;
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
|
-
this.fail(node.expression, `token programs support transfer, transferChecked, mintTo, burn, closeAccount, approve, revoke, setAuthority, freezeAccount, thawAccount, syncNative, initializeMint2, initializeAccount3, initializeMetadata, updateMetadataField, removeMetadataKey, updateMetadataAuthority, emitMetadata, the Token-2022 extension instructions (updateDefaultAccountState, updateTransferHook, enableRequiredMemoTransfers, disableRequiredMemoTransfers, updateInterestRate, transferCheckedWithFee, harvestWithheldTokensToMint, withdrawWithheldTokensFromMint, setTransferFee) and initializers (initializeTransferFeeConfig, initializeMintCloseAuthority, initializeNonTransferableMint, initializePermanentDelegate, initializeDefaultAccountState, initializeMetadataPointer, initializeGroupPointer, initializeGroupMemberPointer, initializeTransferHook, initializeInterestBearingMint, initializeImmutableOwner), not ${method}`);
|
|
628
|
+
this.fail(node.expression, `token programs support transfer, transferChecked, transferCheckedWithHook, mintTo, burn, closeAccount, approve, revoke, setAuthority, freezeAccount, thawAccount, syncNative, initializeMint2, initializeAccount3, initializeMetadata, updateMetadataField, removeMetadataKey, updateMetadataAuthority, emitMetadata, the Token-2022 extension instructions (updateDefaultAccountState, updateTransferHook, enableRequiredMemoTransfers, disableRequiredMemoTransfers, updateInterestRate, transferCheckedWithFee, harvestWithheldTokensToMint, withdrawWithheldTokensFromMint, setTransferFee) and initializers (initializeTransferFeeConfig, initializeMintCloseAuthority, initializeNonTransferableMint, initializePermanentDelegate, initializeDefaultAccountState, initializeMetadataPointer, initializeGroupPointer, initializeGroupMemberPointer, initializeTransferHook, initializeInterestBearingMint, initializeImmutableOwner), not ${method}`);
|
|
612
629
|
}
|
|
613
630
|
ataOp(node, program, method) {
|
|
614
631
|
if (method !== "create" && method !== "createIdempotent")
|
|
@@ -199,6 +199,7 @@ export const SYSCALLS = [
|
|
|
199
199
|
"sol_get_epoch_rewards_sysvar",
|
|
200
200
|
"sol_get_epoch_schedule_sysvar",
|
|
201
201
|
"sol_get_last_restart_slot",
|
|
202
|
+
"sol_get_processed_sibling_instruction",
|
|
202
203
|
"sol_get_rent_sysvar",
|
|
203
204
|
"sol_get_return_data",
|
|
204
205
|
"sol_get_stack_height",
|