@typesol/cli 0.34.0 → 0.35.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 +9 -0
- package/dist/compiler/emit/calls.js +15 -0
- package/dist/compiler/emit/metaplex.d.ts +6 -0
- package/dist/compiler/emit/metaplex.js +41 -1
- package/docs/language.md +2 -2
- package/docs/migrate-from-anchor.md +2 -0
- package/lib/typesol.d.ts +25 -0
- package/package.json +1 -1
- package/runtime/typesol_rt.h +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ codes, and says so here.
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
## 0.35.0 — 2026-10-30
|
|
10
|
+
|
|
11
|
+
Token Metadata's Burn and the EpochSchedule and LastRestartSlot sysvars. Existing programs compile to the same binaries
|
|
12
|
+
as in 0.34.0.
|
|
13
|
+
|
|
14
|
+
- New: Token Metadata `burnV1` (Burn), for an NFT (with its master edition) or fungible asset held by a wallet or this
|
|
15
|
+
program's PDA.
|
|
16
|
+
- New: the EpochSchedule and LastRestartSlot sysvars: `slotsPerEpoch()`, `epochWarmup()`, `firstNormalEpoch()`,
|
|
17
|
+
`firstNormalSlot()`, `lastRestartSlot()`.
|
|
9
18
|
## 0.34.0 — 2026-10-30
|
|
10
19
|
|
|
11
20
|
More of anchor-spl and Anchor's tooling: Memo and Stake CPIs, Token Metadata updates, Token-2022 token groups, the
|
|
@@ -107,6 +107,21 @@ export class CallEmitter extends ExpressionEmitter {
|
|
|
107
107
|
this.line(`TS_TRY(ts_minimum_balance(a_${a.name}->data_len, &${t}));`);
|
|
108
108
|
return { c: t, type: U64 };
|
|
109
109
|
}
|
|
110
|
+
case "slotsPerEpoch":
|
|
111
|
+
case "firstNormalEpoch":
|
|
112
|
+
case "firstNormalSlot":
|
|
113
|
+
case "epochWarmup":
|
|
114
|
+
case "lastRestartSlot": {
|
|
115
|
+
if (args.length !== 0)
|
|
116
|
+
this.fail(node, `${builtin}() takes no arguments`);
|
|
117
|
+
const t = this.tmp();
|
|
118
|
+
this.line(`uint64_t ${t};`);
|
|
119
|
+
if (builtin === "lastRestartSlot")
|
|
120
|
+
this.line(`TS_TRY(ts_last_restart_slot(&${t}));`);
|
|
121
|
+
else
|
|
122
|
+
this.line(`TS_TRY(ts_epoch_schedule(${{ slotsPerEpoch: 0, epochWarmup: 2, firstNormalEpoch: 3, firstNormalSlot: 4 }[builtin]}, &${t}));`);
|
|
123
|
+
return builtin === "epochWarmup" ? { c: `(${t} != 0)`, type: BOOL } : { c: t, type: U64 };
|
|
124
|
+
}
|
|
110
125
|
case "currentSlot":
|
|
111
126
|
case "currentEpoch":
|
|
112
127
|
case "now": {
|
|
@@ -25,6 +25,12 @@ export declare abstract class MetaplexEmitter extends TokenEmitter {
|
|
|
25
25
|
* (`{ name, symbol, uri, sellerFeeBasisPoints, creators?, collection? }`); each null leaves that part as it is.
|
|
26
26
|
*/
|
|
27
27
|
protected metadataUpdate(node: ts.CallExpression, program: AccountParam): undefined;
|
|
28
|
+
/**
|
|
29
|
+
* burnV1(authority, metadata, edition | null, mint, token, collectionMetadata | null, systemProgram,
|
|
30
|
+
* instructionsSysvar, tokenProgram, amount, signerSeeds?): Token Metadata's Burn (41, BurnArgs::V1) of a
|
|
31
|
+
* non-fungible (its master edition) or fungible asset held in `token`. The holder signs and gets the rent back.
|
|
32
|
+
*/
|
|
33
|
+
protected metadataBurn(node: ts.CallExpression, program: AccountParam): undefined;
|
|
28
34
|
/** CreateMasterEditionV3 (17) and Verify (52) with VerificationArgs::CollectionV1. */
|
|
29
35
|
protected metadataCollectionOp(node: ts.CallExpression, program: AccountParam, method: string): undefined;
|
|
30
36
|
/**
|
|
@@ -189,8 +189,10 @@ export class MetaplexEmitter extends TokenEmitter {
|
|
|
189
189
|
return this.metadataCollectionOp(node, program, method);
|
|
190
190
|
if (method === "updateMetadataAccountsV2")
|
|
191
191
|
return this.metadataUpdate(node, program);
|
|
192
|
+
if (method === "burnV1")
|
|
193
|
+
return this.metadataBurn(node, program);
|
|
192
194
|
if (method !== "createV3")
|
|
193
|
-
this.fail(node.expression, `the Token Metadata program supports createV3, createMasterEditionV3, verifyCollection and
|
|
195
|
+
this.fail(node.expression, `the Token Metadata program supports createV3, createMasterEditionV3, verifyCollection, updateMetadataAccountsV2 and burnV1, not ${method}`);
|
|
194
196
|
const a = node.arguments;
|
|
195
197
|
const usage = "createV3(metadata, mint, mintAuthority, payer, updateAuthority, systemProgram, name, symbol, uri, sellerFeeBasisPoints, isMutable, { creators?, collection?, isCollection? }?, signerSeeds?)";
|
|
196
198
|
// An object literal after isMutable carries the optional creators / collection; signerSeeds stays last.
|
|
@@ -358,6 +360,44 @@ export class MetaplexEmitter extends TokenEmitter {
|
|
|
358
360
|
this.line(`TS_TRY(ts_mpl_update_v2(params, a_${program.name}, a_${metadata.name}, a_${ua.name}, ${hasData}, ${name}, ${symbol}, ${uri}, ${fee}, ${creators}, ${ncreators}, ${collection}, ${next}, ${primary}, ${mutable}, ${seeds.name}, ${seeds.count}));`);
|
|
359
361
|
return undefined;
|
|
360
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* burnV1(authority, metadata, edition | null, mint, token, collectionMetadata | null, systemProgram,
|
|
365
|
+
* instructionsSysvar, tokenProgram, amount, signerSeeds?): Token Metadata's Burn (41, BurnArgs::V1) of a
|
|
366
|
+
* non-fungible (its master edition) or fungible asset held in `token`. The holder signs and gets the rent back.
|
|
367
|
+
*/
|
|
368
|
+
metadataBurn(node, program) {
|
|
369
|
+
const a = node.arguments;
|
|
370
|
+
if (a.length !== 10 && a.length !== 11)
|
|
371
|
+
this.fail(node, "burnV1(authority, metadata, edition | null, mint, token, collectionMetadata | null, systemProgram, instructionsSysvar, tokenProgram, amount, signerSeeds?)");
|
|
372
|
+
const p = `a_${program.name}`;
|
|
373
|
+
const none = [p, false, false];
|
|
374
|
+
const authority = this.accountParam(a[0], "the authority (the holder)");
|
|
375
|
+
if (!isWritable(authority.kind))
|
|
376
|
+
this.fail(a[0], "the authority must be writable (Mut<...>): it gets the rent back");
|
|
377
|
+
// Burn: authority, collection metadata, metadata, edition, mint, token, master edition, master edition mint,
|
|
378
|
+
// master edition token, edition marker, token record (optional ones: the program id), system program,
|
|
379
|
+
// instructions sysvar, token program.
|
|
380
|
+
const metas = [
|
|
381
|
+
[`a_${authority.name}`, true, true],
|
|
382
|
+
this.mplMeta(a[5], program, "the collection metadata", true, false),
|
|
383
|
+
this.mplMeta(a[1], program, "the metadata", true, false),
|
|
384
|
+
this.mplMeta(a[2], program, "the edition", true, false),
|
|
385
|
+
this.mplMeta(a[3], program, "the mint", true, false),
|
|
386
|
+
this.mplMeta(a[4], program, "the token account", true, false),
|
|
387
|
+
none,
|
|
388
|
+
none,
|
|
389
|
+
none,
|
|
390
|
+
none,
|
|
391
|
+
none,
|
|
392
|
+
this.mplMeta(a[6], program, "the system program", false, false),
|
|
393
|
+
this.mplMeta(a[7], program, "the instructions sysvar", false, false),
|
|
394
|
+
this.mplMeta(a[8], program, "the token program", false, false),
|
|
395
|
+
];
|
|
396
|
+
const data = this.mplData(node, 10, [{ bytes: [41, 0] }, { value: a[9], type: U64 }]);
|
|
397
|
+
const seeds = this.signerSeeds(a[10], authority, a[0]);
|
|
398
|
+
this.cpi(p, metas, data.buf, data.len, seeds);
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
361
401
|
/** CreateMasterEditionV3 (17) and Verify (52) with VerificationArgs::CollectionV1. */
|
|
362
402
|
metadataCollectionOp(node, program, method) {
|
|
363
403
|
const a = node.arguments;
|
package/docs/language.md
CHANGED
|
@@ -50,7 +50,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
50
50
|
| Generic helpers | `function max<T extends bigint>(a: T, b: T): T` — compiled once per set of types it is called with (`max(a, b)` with u64 arguments, or `max<u128>(x, 1n)` when only literals tell); a type parameter stands for an integer, boolean, Pubkey, enum or fixed-size struct (`pick<Point>(…)`, or from struct arguments; a struct `T` is copied like any struct value). Each instance is checked like any helper; one that is never called is not compiled (TypeScript still type-checks it). Arithmetic on `T` is a `bigint` to TypeScript: `return (a + b) as T` (`as` names a type the value already has; it never converts) |
|
|
51
51
|
| Evaluation order | operands and arguments are read left to right, as in JS, even when a later one changes account data (`v.length + v.pop()`) |
|
|
52
52
|
| `++` `--` `+=` `-=` `*=` `/=` `%=` `&=` `\|=` `^=` `<<=` `>>=` | all checked |
|
|
53
|
-
| Sysvars | `now()`, `currentSlot()`, `currentEpoch()` (clock), `minimumBalance(account)`, `rentExempt(space)` (rent); `slotHashes: SlotHashesSysvar` (an account, too large for the sysvar syscalls): `count`, `latestSlot`, `latestHash` (public: not a source of secret randomness) |
|
|
53
|
+
| Sysvars | `now()`, `currentSlot()`, `currentEpoch()` (clock), `minimumBalance(account)`, `rentExempt(space)` (rent); `slotHashes: SlotHashesSysvar` (an account, too large for the sysvar syscalls): `count`, `latestSlot`, `latestHash` (public: not a source of secret randomness); `slotsPerEpoch()`, `epochWarmup()`, `firstNormalEpoch()`, `firstNormalSlot()` (EpochSchedule); `lastRestartSlot()` |
|
|
54
54
|
| Account size | `realloc(account, newSize, payer)` on a `Mut<Struct>` — growing charges the payer the extra rent (at most 10 KiB per instruction, 3016); shrinking keeps the lamports in the account; never below the struct. Refused on a struct with a growable `Vec` (its push / pop / clear size the account) |
|
|
55
55
|
| Token-2022 extensions | `transferFee(mint, amount)` (current-epoch TransferFeeConfig, ceil + cap like spl-token-2022), `transferFeeInverse(mint, amountReceived)` (the fee when the recipient is to get that much: spl-token-2022's `calculate_inverse_epoch_fee`), `transferFeeBasisPoints(mint)` / `transferFeeMaximum(mint)` (this epoch's; 0 without the extension), `extensionsWithin(account, [1n, 18n, …])` (every extension is one of those types), `transferHookProgram(mint)`, `transferHookAuthority(mint)`, `permanentDelegate(mint)`, `mintCloseAuthority(mint)` (Option<Pubkey>), `hasExtension(account, type)`, `isTransferring(tokenAccount)` (inside a transfer hook: whether Token-2022 is transferring from it) |
|
|
56
56
|
| Events through CPI | `emitCpi<Paid>({ … }, eventAuthority, self)` with `eventAuthority: EventAuthority, self: SelfProgram` parameters — Anchor `emit_cpi!`: the event rides in a self-CPI (inner instruction), not in logs; the program accepts Anchor's event instruction (2002 / 2006 otherwise) |
|
|
@@ -92,7 +92,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
92
92
|
| `TokenInterface` | either token program |
|
|
93
93
|
| `AssociatedTokenProgram` | `create` / `createIdempotent` CPIs; `associatedTokenAddress(owner, mint, tokenProgram)` |
|
|
94
94
|
| `MemoProgram` | SPL Memo v2: `memoProgram.memo(text, [signers], signerSeeds?)`; each listed account signs (a PDA of this program with its seeds) |
|
|
95
|
-
| `TokenMetadataProgram` | Metaplex `createV3(...)` (CreateMetadataAccountV3), optionally with `{ creators: [{ address, verified, share }], collection: mint }` after `isMutable` (1–5 creators, shares adding up to 100; only the update authority, signing, can be `verified: true`; the collection is written unverified; `isCollection: true` makes the NFT a sized collection); `createMasterEditionV3(edition, mint, updateAuthority, mintAuthority, payer, metadata, tokenProgram, systemProgram, maxSupply \| null)`; `verifyCollection(authority, metadata, collectionMint, collectionMetadata, collectionMasterEdition, systemProgram, instructionsSysvar)` (Verify with CollectionV1); `updateMetadataAccountsV2(metadata, updateAuthority, data \| null, newUpdateAuthority \| null, primarySaleHappened \| null, isMutable \| null)` (`data` replaces the whole DataV2: `{ name, symbol, uri, sellerFeeBasisPoints, creators?, collection? }`; each null leaves that part); `metadataAddress(mint)`, `masterEditionAddress(mint)` |
|
|
95
|
+
| `TokenMetadataProgram` | Metaplex `createV3(...)` (CreateMetadataAccountV3), optionally with `{ creators: [{ address, verified, share }], collection: mint }` after `isMutable` (1–5 creators, shares adding up to 100; only the update authority, signing, can be `verified: true`; the collection is written unverified; `isCollection: true` makes the NFT a sized collection); `createMasterEditionV3(edition, mint, updateAuthority, mintAuthority, payer, metadata, tokenProgram, systemProgram, maxSupply \| null)`; `verifyCollection(authority, metadata, collectionMint, collectionMetadata, collectionMasterEdition, systemProgram, instructionsSysvar)` (Verify with CollectionV1); `updateMetadataAccountsV2(metadata, updateAuthority, data \| null, newUpdateAuthority \| null, primarySaleHappened \| null, isMutable \| null)` (`data` replaces the whole DataV2: `{ name, symbol, uri, sellerFeeBasisPoints, creators?, collection? }`; each null leaves that part); `burnV1(authority, metadata, edition \| null, mint, token, collectionMetadata \| null, systemProgram, instructionsSysvar, tokenProgram, amount)` (Burn: the holder signs and gets the rent back; the token account and edition close, the metadata is cleared to one byte); `metadataAddress(mint)`, `masterEditionAddress(mint)` |
|
|
96
96
|
| `StakeProgram` | `initialize(stake, rentSysvar, staker, withdrawer)` (no lockup), `authorize(stake, clockSysvar, authority, newAuthority, "staker" \| "withdrawer")`, `delegate(stake, vote, clockSysvar, stakeHistorySysvar, stakeConfig, staker)`, `deactivate(stake, clockSysvar, staker)`, `withdraw(stake, to, clockSysvar, stakeHistorySysvar, withdrawer, lamports)`; the sysvar and config accounts are parameters, as in anchor-spl's stake module; authorities sign (PDAs with signerSeeds) |
|
|
97
97
|
| `InstructionsSysvar`, `PythPriceUpdate`, `SwitchboardFeed` | exact address / owner program + discriminator |
|
|
98
98
|
| `InstructionsSysvar` (introspection) | `ixs.length`, `ixs.currentIndex()` (the top-level instruction being executed), `ixs.get(i)` → a `TransactionInstruction`: `programId`, `accountsLength`, `dataLength`, `accountKey(j)` / `accountIsSigner(j)` / `accountIsWritable(j)`, `readU8/U16/U32/U64/readPubkey(offset)` (little-endian), `is(program, "name")` (that program's instruction by its default Anchor discriminator, sha256("global:<name>"); an instruction with its own `@discriminator` is matched with `programId` and `readU64(0)` instead). Every read is bounds-checked (5104). It is the transaction author's data: require things of the transaction with it (a repay instruction after a flash loan), never treat it as proof |
|
|
@@ -118,6 +118,8 @@ Anchor instruction that takes or returns a struct with `String` / `Vec` / `Optio
|
|
|
118
118
|
| `let (_, data) = get_return_data().unwrap(); Quote::try_from_slice(&data)?` | `const quote = returnData<Quote>(program)` (a `@layout borsh` struct when it holds Options, strings or Vecs) |
|
|
119
119
|
| `[test.validator.clone]` in Anchor.toml | `"clone": [...]` in typesol.json and `typesol clone` (loaded by `testProgram`) |
|
|
120
120
|
| `anchor_spl::metadata::update_metadata_accounts_v2` | `metadataProgram.updateMetadataAccountsV2(…)` |
|
|
121
|
+
| `anchor_spl::metadata::burn_nft` / mpl `BurnV1` | `metadataProgram.burnV1(…)` |
|
|
122
|
+
| `EpochSchedule::get()?`, `LastRestartSlot::get()?` | `slotsPerEpoch()`, `epochWarmup()`, `firstNormalEpoch()`, `firstNormalSlot()`; `lastRestartSlot()` |
|
|
121
123
|
| `anchor_spl::stake::{authorize, deactivate_stake, withdraw}`, `delegate_stake` | `stakeProgram.authorize / deactivate / withdraw / delegate(…)` |
|
|
122
124
|
| `pub fn fallback(program_id, accounts, data)` | `/** @fallback */ export function fallback(): void` with `instructionData()` and `remainingAccounts()` |
|
|
123
125
|
| `#[access_control(check(&ctx))]` | call the check first in the body (`check(vault, owner)`), or `constraint(acct, …)` for one that belongs with an account's checks |
|
package/lib/typesol.d.ts
CHANGED
|
@@ -458,6 +458,24 @@ export interface TokenMetadataProgram extends AccountMeta {
|
|
|
458
458
|
* collection left out become none; a verified collection or creator cannot be changed this way, Metaplex refuses);
|
|
459
459
|
* each `null` leaves that part as it is. The update authority signs (a PDA of this program with `signerSeeds`).
|
|
460
460
|
*/
|
|
461
|
+
/**
|
|
462
|
+
* Burn (BurnV1) a non-fungible asset (pass its master edition as `edition`) or a fungible one (`edition` null) held in
|
|
463
|
+
* `token`: the token account and edition close (the metadata is cleared to one byte, as Token Metadata does), the
|
|
464
|
+
* holder signs and gets the rent back. `collectionMetadata` is the collection's when the asset is a verified member, else null.
|
|
465
|
+
*/
|
|
466
|
+
burnV1(
|
|
467
|
+
authority: AccountMeta,
|
|
468
|
+
metadata: AccountMeta,
|
|
469
|
+
edition: AccountMeta | null,
|
|
470
|
+
mint: AccountMeta,
|
|
471
|
+
token: AccountMeta,
|
|
472
|
+
collectionMetadata: AccountMeta | null,
|
|
473
|
+
systemProgram: SystemProgram,
|
|
474
|
+
instructionsSysvar: AccountMeta,
|
|
475
|
+
tokenProgram: TokenProgram | Token2022Program | TokenInterface,
|
|
476
|
+
amount: u64,
|
|
477
|
+
signerSeeds?: Seed[] | SignerSeeds,
|
|
478
|
+
): void;
|
|
461
479
|
updateMetadataAccountsV2(
|
|
462
480
|
metadata: AccountMeta,
|
|
463
481
|
updateAuthority: AccountMeta,
|
|
@@ -1444,6 +1462,13 @@ export interface CompressedLeaf {
|
|
|
1444
1462
|
/** The current slot and epoch (Clock sysvar). */
|
|
1445
1463
|
export declare function currentSlot(): u64;
|
|
1446
1464
|
export declare function currentEpoch(): u64;
|
|
1465
|
+
/** The EpochSchedule sysvar: slots per epoch (after warmup), whether epochs warm up, and where normal epochs start. */
|
|
1466
|
+
export declare function slotsPerEpoch(): u64;
|
|
1467
|
+
export declare function epochWarmup(): boolean;
|
|
1468
|
+
export declare function firstNormalEpoch(): u64;
|
|
1469
|
+
export declare function firstNormalSlot(): u64;
|
|
1470
|
+
/** The LastRestartSlot sysvar: the last slot the cluster restarted at (0 if never). */
|
|
1471
|
+
export declare function lastRestartSlot(): u64;
|
|
1447
1472
|
export type CloseTo<A, Destination extends string> = A & { readonly __closeTo?: Destination };
|
|
1448
1473
|
|
|
1449
1474
|
/** A program-owned account that this instruction creates as a PDA. */
|
package/package.json
CHANGED
package/runtime/typesol_rt.h
CHANGED
|
@@ -597,6 +597,21 @@ static inline void ts_write_le(uint8_t *p, uint64_t v, int n) { ts_memcpy(p, &v,
|
|
|
597
597
|
/* ---- Sysvars --------------------------------------------------------------- */
|
|
598
598
|
uint64_t sol_get_rent_sysvar(void *ret);
|
|
599
599
|
uint64_t sol_get_clock_sysvar(void *ret);
|
|
600
|
+
uint64_t sol_get_epoch_schedule_sysvar(void *ret);
|
|
601
|
+
uint64_t sol_get_last_restart_slot(void *ret);
|
|
602
|
+
|
|
603
|
+
/* EpochSchedule { slots_per_epoch, leader_schedule_slot_offset, warmup (bool, padded), first_normal_epoch,
|
|
604
|
+
first_normal_slot }: one u64 of it by index (2 is warmup's word, whose first byte is the bool). */
|
|
605
|
+
static inline uint64_t ts_epoch_schedule(int field, uint64_t *out) {
|
|
606
|
+
uint64_t es[5];
|
|
607
|
+
if (sol_get_epoch_schedule_sysvar(es) != SUCCESS) TS_FAIL(TS_ERR_SYSVAR, "TypeSOL: epoch schedule sysvar unavailable");
|
|
608
|
+
*out = field == 2 ? (es[2] & 0xff) : es[field];
|
|
609
|
+
return SUCCESS;
|
|
610
|
+
}
|
|
611
|
+
static inline uint64_t ts_last_restart_slot(uint64_t *out) {
|
|
612
|
+
if (sol_get_last_restart_slot(out) != SUCCESS) TS_FAIL(TS_ERR_SYSVAR, "TypeSOL: last restart slot sysvar unavailable");
|
|
613
|
+
return SUCCESS;
|
|
614
|
+
}
|
|
600
615
|
|
|
601
616
|
/* The general case, in integers: exactly (uint64_t)((double)per_year * threshold) as soft-float computes it (the
|
|
602
617
|
conversion and the product rounded to nearest, ties to even; NaN, negative and < 1 give 0), or UINT64_MAX when that
|