@typesol/cli 0.32.0 → 0.34.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/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) |
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) |
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) |
@@ -67,8 +67,11 @@ The full reference. For a tour, start with the [README](../README.md).
67
67
  | `Account<T>` / `Mut<T>` | owned by this program, 8-byte discriminator matches, data large enough (and writable) |
68
68
  | `Init<T>` | writable; `create(payer, seeds)` derives the PDA, verifies it, funds rent, writes the discriminator (up to 10 KiB); `create(payer, null)` creates a new keypair account that signs the transaction instead (3010 if it did not; a signer in the IDL); a third argument is Anchor's `space = …` (discriminator included, at least 8 + the struct's size) |
69
69
  | `InitIfNeeded<T>` | `const created = acct.createIfNeeded(payer, seeds)` — creates once; afterwards re-derives the PDA and checks owner, discriminator and size (Anchor `init_if_needed`); `acct.pdaBump` after create. An existing account is used as it is: check the fields you rely on |
70
+ | `/** @fallback */ export function legacy(): void` | Anchor's `fallback`: runs when no instruction's discriminator matches the data (short data too) instead of failing with 101; it takes no parameters and reads `const data = instructionData()` (the whole data: `data.length`, `data.get(i)`, or passed on to `invokeInstruction`) and `remainingAccounts()`. Not in the IDL |
71
+ | Account groups: `p: PoolAccounts`, where `export interface PoolAccounts { pool: HasOne<Mut<Pool>, "vault">; vault: Mut<TokenAccount>; … }` | Anchor's composite accounts (a `#[derive(Accounts)]` struct as a field of another): an interface whose fields are accounts is one parameter, its accounts the instruction's in field order. The body uses `p.pool.reserve`, passes `p.vault` to CPIs and helpers, and creates `p.pool.create(…)`. Constraints inside name the group's own fields first (`HasOne<…, "vault">`, `Seeds<…, ["pool", "@mint"]>`, `TokenOf<…, "mint", "pool">`), then the instruction's. The IDL nests them (`{ name: "p", accounts: [...] }`, seeds relative to the group); the client and `t.ix` flatten them (`pPool`, `pVault`). A field may be optional (`A \| null`) or another group (`p.fees.vault`; the IDL nests it too, the client flattens it to `pFeesVault`); a group may not be optional or a helper parameter. Its checks run with the instruction's, in order, after every account's type checks (Anchor runs a group's constraints before later accounts' type checks: only a transaction failing both sees a different code) |
70
72
  | `constraint(acct, condition, error?)` | Anchor's `constraint = condition @ error` on `acct`: statements at the very start of the body, run with that account's checks (after its `has_one`, before the next account), so a transaction breaking several checks gets Anchor's code; they read accounts and arguments; the default error is ConstraintRaw (2003) |
71
73
  | `HasOne<A, "owner">`, `Seeds<A, ["vault", "@owner"], "bump">`, `CloseTo<A, "owner">` | declarative constraints like Anchor's `has_one`, `seeds`/`bump` and `close`: checked before the body (2001 / 2006), close runs when the instruction succeeds; `"@name"` = account key or argument bytes, `"@acct.field"` = a Pubkey, integer or unit enum field of a struct account parameter (also the account's own: `["offer", "@maker", "@offer.id"]`), other strings are literals; recorded as `relations` / `pda` in the IDL. a bump stored in another struct account is named `"@acct.field"` (Anchor `bump = multisig.nonce`); `acct.pdaBump` is the bump (Anchor `ctx.bumps.acct`): the stored field when one is named, else the canonical bump the check found — use it to sign as the PDA |
74
+ | `HasOne<A, "owner", ErrorCode.NotOwner>`, `Address<A, "…", E.X>`, `Owner<A, "…", E.X>`, `Signed<A, E.X>`, `Mut<T, E.X>` | one of your errors instead of Anchor's code, as Anchor's `has_one = owner @ ErrorCode.NotOwner`, `address = … @ …`, `owner = … @ …`, `signer @ …` and `mut @ …` (the constraints Anchor lets you name an error for); a member of one of the program's error enums. For several `HasOne` fields with different errors, nest them: `HasOne<HasOne<Mut<V>, "owner", E.A>, "admin", E.B>` |
72
75
  | `HasOne<TokenAccount, "mint" \| "owner">`, `HasOne<Mint, "mintAuthority" \| "freezeAuthority">` | token constraints (2014 / 2015 / 2016 / 2017) against the parameter with that name; `TokenOf<TokenAccount, "mintParam", "authorityParam", "tokenProgramParam">` / `MintOf<Mint, "authorityParam", "freezeParam", "tokenProgramParam">` name the parameters, as Anchor's `token::mint = …` / `mint::authority = …` / `…::token_program = …` do (`never` leaves one out; the token program one: owned by that token program, 2021 / 2022) |
73
76
  | `Ata<TokenAccount, "owner", "mint">` | the account is the associated token account of those parameters (2009; ATA `pda` in the IDL) |
74
77
  | `Ata<Init<TokenAccount>, "owner", "mint">`, `Ata<InitIfNeeded<TokenAccount>, "owner", "mint">` | Anchor `init` / `init_if_needed` with `associated_token::…`: `acct.create(payer)` creates the ATA (fails if it exists); `const created = acct.createIfNeeded(payer)` creates it only when missing, otherwise checks it is that ATA (2009). Then it is a `TokenAccount` of that mint and owner (2014 / 2015). Needs `AssociatedTokenProgram`, `SystemProgram` and a token program parameter; call it at the top level before using the account |
@@ -88,7 +91,9 @@ The full reference. For a tour, start with the [README](../README.md).
88
91
  | `SystemProgram`, `TokenProgram`, `Token2022Program` | exact program address |
89
92
  | `TokenInterface` | either token program |
90
93
  | `AssociatedTokenProgram` | `create` / `createIdempotent` CPIs; `associatedTokenAddress(owner, mint, tokenProgram)` |
91
- | `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); `metadataAddress(mint)`, `masterEditionAddress(mint)` |
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)` |
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) |
92
97
  | `InstructionsSysvar`, `PythPriceUpdate`, `SwitchboardFeed` | exact address / owner program + discriminator |
93
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 |
94
99
  | `Program<"Address…">` | exact program address + executable |
@@ -117,7 +122,7 @@ with `i == j`) is refused with 2040 too, since the two views would alias.
117
122
  `burnChecked(from, mint, authority, amount)` and `approveChecked(source, mint, delegate, owner, amount)` (the decimals
118
123
  come from the mint), `setAuthority(target, current, AuthorityType.MintTokens, next | null)`,
119
124
  `freezeAccount` / `thawAccount(account, mint, freezeAuthority)`, `syncNative(account)`, `initializeMint2(mint, decimals, mintAuthority, freezeAuthority | null)`,
120
- `initializeAccount3(account, mint, owner)`, and on Token-2022 `initializeMetadata(mint, updateAuthority, mintAuthority, name, symbol, uri)` (metadata extension) and the extension initializers to call between `createAccount` and `initializeMint2` / `initializeAccount3`: `initializeTransferFeeConfig(mint, configAuthority | null, withdrawAuthority | null, basisPoints, maximumFee)`, `initializeMintCloseAuthority(mint, authority | null)`, `initializeNonTransferableMint(mint)`, `initializePermanentDelegate(mint, delegate)`, `initializeDefaultAccountState(mint, frozen)`, `initializeMetadataPointer` / `initializeGroupPointer` / `initializeGroupMemberPointer` / `initializeTransferHook(mint, authority | null, address | null)`, `initializeInterestBearingMint(mint, rateAuthority | null, rate)`, `initializeImmutableOwner(account)`; the extension instructions `updateDefaultAccountState(mint, freezeAuthority, frozen)`, `updateTransferHook(mint, authority, programId | null)`, `enableRequiredMemoTransfers` / `disableRequiredMemoTransfers(account, owner)`, `updateInterestRate(mint, rateAuthority, rate)`, `transferCheckedWithFee(from, mint, to, authority, amount, fee)`, `harvestWithheldTokensToMint(mint, remainingAccounts())`, `withdrawWithheldTokensFromMint(mint, destination, authority)`, `setTransferFee(mint, authority, basisPoints, maximumFee)`; and the Token Metadata interface `updateMetadataField(mint, updateAuthority, field, value)` ("name" / "symbol" / "uri" or any other key), `removeMetadataKey(mint, updateAuthority, key, idempotent)`, `updateMetadataAuthority(mint, updateAuthority, next | null)`, `emitMetadata(mint)`. Each takes optional signerSeeds
125
+ `initializeAccount3(account, mint, owner)`, and on Token-2022 `initializeMetadata(mint, updateAuthority, mintAuthority, name, symbol, uri)` (metadata extension) and the extension initializers to call between `createAccount` and `initializeMint2` / `initializeAccount3`: `initializeTransferFeeConfig(mint, configAuthority | null, withdrawAuthority | null, basisPoints, maximumFee)`, `initializeMintCloseAuthority(mint, authority | null)`, `initializeNonTransferableMint(mint)`, `initializePermanentDelegate(mint, delegate)`, `initializeDefaultAccountState(mint, frozen)`, `initializeMetadataPointer` / `initializeGroupPointer` / `initializeGroupMemberPointer` / `initializeTransferHook(mint, authority | null, address | null)`, `initializeInterestBearingMint(mint, rateAuthority | null, rate)`, `initializeImmutableOwner(account)`; the extension instructions `updateDefaultAccountState(mint, freezeAuthority, frozen)`, `updateTransferHook(mint, authority, programId | null)`, `enableRequiredMemoTransfers` / `disableRequiredMemoTransfers(account, owner)`, `updateInterestRate(mint, rateAuthority, rate)`, `transferCheckedWithFee(from, mint, to, authority, amount, fee)`, `harvestWithheldTokensToMint(mint, remainingAccounts())`, `withdrawWithheldTokensFromMint(mint, destination, authority)`, `setTransferFee(mint, authority, basisPoints, maximumFee)`; and the Token Metadata interface `updateMetadataField(mint, updateAuthority, field, value)` ("name" / "symbol" / "uri" or any other key), `removeMetadataKey(mint, updateAuthority, key, idempotent)`, `updateMetadataAuthority(mint, updateAuthority, next | null)`, `emitMetadata(mint)`; and the Token Group interface: `initializeTokenGroup(group, mint, mintAuthority, updateAuthority | null, maxSize)` (a collection mint with a GroupPointer to itself; fund the rent for the group, which Token-2022 adds to the account), `initializeGroupMember(member, memberMint, memberMintAuthority, group, groupUpdateAuthority)`, `updateGroupMaxSize(group, authority, maxSize)`, `updateGroupAuthority(group, authority, next | null)`. Each takes optional signerSeeds
121
126
  - `account.lamports` read/write on `Mut` accounts, `close(account, destination)` for program accounts
122
127
  - `requirePda(account, seeds, bump)`: any bump that gives a valid PDA passes, as with Anchor's `bump = expr`. Use a bump
123
128
  stored when the account was created (or `Seeds<…>`); one taken from the instruction's arguments lets the caller pick
@@ -159,6 +164,9 @@ export function payOut(admin: Signer, treasury: Mut<SystemAccount>, recipient: M
159
164
  - A seed list used more than once can be named: `const vault = signer(["vault", owner.key, bump])`, then pass `vault`
160
165
  wherever signerSeeds go.
161
166
  - After the call, `returnData<u64>(program)` reads what the callee returned, checking the size and that it came from `program`.
167
+ A struct is bound to a local, `const quote = returnData<Quote>(amm)`: a fixed layout of integers, booleans, Pubkeys,
168
+ unit enums and arrays is read as its bytes (bools and enums checked); a struct with Options, strings or Vecs is
169
+ declared `/** @layout borsh */` and Borsh-decoded. Bytes that are not exactly the struct fail with 5106.
162
170
 
163
171
  A call decided at run time, such as one a multisig stored in account data, is `invokeInstruction` (Rust's
164
172
  `invoke_signed(&Instruction { program_id, accounts, data }, infos, seeds)`):
@@ -30,6 +30,7 @@ and error codes. Its notes (on stderr) list what an existing Anchor client would
30
30
  | Anchor | TypeSOL |
31
31
  | --- | --- |
32
32
  | `#[derive(Accounts)] struct Ctx` + `ctx.accounts.x` | the instruction's parameters, in the same order |
33
+ | a composite field, `pub pool: PoolAccounts<'info>` + `ctx.accounts.pool.vault` | an account group: `export interface PoolAccounts { vault: Mut<TokenAccount>; … }`, the parameter `pool: PoolAccounts`, and `pool.vault` |
33
34
  | `Signer<'info>` / `#[account(mut)] Signer` | `Signer` / `Mut<Signer>` |
34
35
  | `Account<'info, T>` / `#[account(mut)]` | `Account<T>` / `Mut<T>` |
35
36
  | `#[account(init, payer = p, space = …, seeds = […], bump)]` | `Init<T>`, then `const bump = acct.create(p, ["seed", other.key])` (space is computed; `acct.create(p, […], 8n + 64n)` keeps an explicit `space`) |
@@ -38,6 +39,7 @@ and error codes. Its notes (on stderr) list what an existing Anchor client would
38
39
  | `seeds = [b"vault", owner.key().as_ref()], bump = vault.bump` | `Seeds<Mut<Vault>, ["vault", "@owner"], "bump">` |
39
40
  | `seeds = [b"offer", offer.maker.as_ref(), offer.id.to_le_bytes().as_ref()]` | `Seeds<…, ["offer", "@offer.maker", "@offer.id"], "bump">` |
40
41
  | `has_one = owner` | `HasOne<Mut<T>, "owner">` |
42
+ | `has_one = owner @ ErrorCode::NotOwner` (also `address`, `owner`, `signer`, `mut` with `@ …`) | `HasOne<Mut<T>, "owner", ErrorCode.NotOwner>`; `Address<A, "…", E.X>`, `Owner<A, "…", E.X>`, `Signed<A, E.X>`, `Mut<T, E.X>` |
41
43
  | `close = destination` | `CloseTo<Mut<T>, "destination">`, or `close(acct, destination)` in the body |
42
44
  | `address = ADMIN` | `Address<AccountInfo, "Admin1111…">` |
43
45
  | `owner = program`, `executable` | `Owner<A, "…">`, `Executable<A>` |
@@ -113,6 +115,15 @@ Anchor instruction that takes or returns a struct with `String` / `Vec` / `Optio
113
115
  | `token::mint_to_checked` / `burn_checked` / `approve_checked` | `tokenProgram.mintToChecked(mint, to, authority, amount)` / `burnChecked(from, mint, authority, amount)` / `approveChecked(source, mint, delegate, owner, amount)` |
114
116
  | `system_program::transfer(CpiContext::new_with_signer(…, &[vault_seeds]), lamports)` | `systemProgram.transfer(vault, to, lamports, ["vault", owner.key, bump])` |
115
117
  | `invoke_signed(&ix, infos, &[seeds_a, seeds_b])` | `invoke(program, accounts, data, [seedsA, seedsB])` |
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
+ | `[test.validator.clone]` in Anchor.toml | `"clone": [...]` in typesol.json and `typesol clone` (loaded by `testProgram`) |
120
+ | `anchor_spl::metadata::update_metadata_accounts_v2` | `metadataProgram.updateMetadataAccountsV2(…)` |
121
+ | `anchor_spl::stake::{authorize, deactivate_stake, withdraw}`, `delegate_stake` | `stakeProgram.authorize / deactivate / withdraw / delegate(…)` |
122
+ | `pub fn fallback(program_id, accounts, data)` | `/** @fallback */ export function fallback(): void` with `instructionData()` and `remainingAccounts()` |
123
+ | `#[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 |
124
+ | `spl_memo::build_memo` + `invoke` | `memoProgram.memo(text, [signers])` |
125
+ | `UncheckedAccount` at the SlotHashes address | `SlotHashesSysvar`: `latestSlot`, `latestHash` |
126
+ | `spl_token_group_interface` CPIs (`initialize_group`, `initialize_member`, …) | `token.initializeTokenGroup(…)`, `initializeGroupMember(…)`, `updateGroupMaxSize(…)`, `updateGroupAuthority(…)` |
116
127
  | `invoke_signed(&ix, &accounts, &[seeds])` | `invoke(program, [writable(a), readonly(b)], [data…], seeds)` |
117
128
  | `invoke_signed(&Instruction { program_id, accounts, data }, ctx.remaining_accounts, …)` built at run time | `invokeInstruction(programId, metas, data, remainingAccounts(), seeds)` |
118
129
  | `multisig.owners = owners` (a `Vec` argument into account data) | the same |
@@ -60,6 +60,13 @@ instruction that takes the bump as an argument.
60
60
  | `t.tokenBalance(address)` | the amount a token account holds, or `null` when it does not exist |
61
61
  | `t.warp({ unixTimestamp?, slot?, seconds? })` | moves the Clock: to a timestamp or slot, or forward by `seconds` |
62
62
 
63
+ ## Accounts from a cluster
64
+
65
+ To test against accounts that exist on mainnet (a mint, an oracle, another program), list them in `typesol.json` as
66
+ `"clone": ["<address>", …]` and run `typesol clone --url mainnet-beta` once (or `typesol clone <address>…`). They are
67
+ written to `tests/accounts/`, which `testProgram` loads into its LiteSVM before your first test; commit the directory so
68
+ the tests run offline. `loadClonedAccounts(svm, dir)` does the same for a LiteSVM of your own.
69
+
63
70
  `t.svm`, `t.programId`, `t.idl` and `t.coder` are there for anything else. `programHarness(svm, programId, idl)` gives the same helpers for a
64
71
  program you loaded yourself, and `svmConnection(svm)` the RPC pair alone (for any LiteSVM, e.g. one with an Anchor
65
72
  program loaded). Transactions sent through it run at once; `getProgramAccounts` (`fetchAll`) sees the accounts those
package/lib/typesol.d.ts CHANGED
@@ -294,6 +294,68 @@ export declare function switchboardValue(
294
294
  ): i64;
295
295
 
296
296
  /** The Associated Token Account program (ATokenGP…). Its address is checked. */
297
+ /** The SPL Memo program (v2, `MemoSq4g…`). Its address is checked. */
298
+ export interface MemoProgram extends AccountMeta {
299
+ readonly __memo_program: void;
300
+ /**
301
+ * Record a UTF-8 memo in the transaction (Anchor's `spl_memo::build_memo`). Each account in `signers` must sign it:
302
+ * a `Signer`, or a PDA of this program with `signerSeeds`.
303
+ */
304
+ memo(text: string, signers?: AccountMeta[], signerSeeds?: Seed[] | SignerSeeds): void;
305
+ }
306
+
307
+ /**
308
+ * The native Stake program (`Stake1111…`). Its address is checked. The sysvar and config accounts it reads are
309
+ * passed in, as anchor-spl's stake module does (`SysvarRent…`, `SysvarC1ock…`, `SysvarStakeHistory…`,
310
+ * `StakeConfig…`). Each authority signs: a wallet, or a PDA of this program with `signerSeeds`.
311
+ */
312
+ export interface StakeProgram extends AccountMeta {
313
+ readonly __stake_program: void;
314
+ /** Initialize a stake account (created with 200 bytes, owned by the Stake program), with no lockup. */
315
+ initialize(stake: AccountMeta, rentSysvar: AccountMeta, staker: Pubkey, withdrawer: Pubkey): void;
316
+ /** Hand the staker or the withdrawer authority to `newAuthority`. */
317
+ authorize(
318
+ stake: AccountMeta,
319
+ clockSysvar: AccountMeta,
320
+ authority: AccountMeta,
321
+ newAuthority: Pubkey,
322
+ which: "staker" | "withdrawer",
323
+ signerSeeds?: Seed[] | SignerSeeds,
324
+ ): void;
325
+ delegate(
326
+ stake: AccountMeta,
327
+ vote: AccountMeta,
328
+ clockSysvar: AccountMeta,
329
+ stakeHistorySysvar: AccountMeta,
330
+ stakeConfig: AccountMeta,
331
+ staker: AccountMeta,
332
+ signerSeeds?: Seed[] | SignerSeeds,
333
+ ): void;
334
+ deactivate(stake: AccountMeta, clockSysvar: AccountMeta, staker: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
335
+ withdraw(
336
+ stake: AccountMeta,
337
+ to: AccountMeta,
338
+ clockSysvar: AccountMeta,
339
+ stakeHistorySysvar: AccountMeta,
340
+ withdrawer: AccountMeta,
341
+ lamports: u64,
342
+ signerSeeds?: Seed[] | SignerSeeds,
343
+ ): void;
344
+ }
345
+
346
+ /**
347
+ * The SlotHashes sysvar (`SysvarS1otHashes…`), read as an account: it is too large for the sysvar syscalls (Anchor's
348
+ * `Sysvar<SlotHashes>` cannot load it either). The address is checked, and that it holds an entry (5103).
349
+ */
350
+ export interface SlotHashesSysvar extends AccountMeta {
351
+ readonly __slot_hashes: void;
352
+ /** How many recent slots it lists (up to 512). */
353
+ readonly count: u64;
354
+ /** The most recent slot it lists, and that slot's bank hash: known to everyone, so not a secret source of randomness. */
355
+ readonly latestSlot: u64;
356
+ readonly latestHash: Hash;
357
+ }
358
+
297
359
  export interface AssociatedTokenProgram extends AccountMeta {
298
360
  readonly __ata_program: void;
299
361
  create(
@@ -391,6 +453,27 @@ export interface TokenMetadataProgram extends AccountMeta {
391
453
  instructionsSysvar: AccountMeta,
392
454
  signerSeeds?: Seed[] | SignerSeeds,
393
455
  ): void;
456
+ /**
457
+ * UpdateMetadataAccountV2 (Anchor's `update_metadata_accounts_v2`): `data` replaces the whole DataV2 (creators and
458
+ * collection left out become none; a verified collection or creator cannot be changed this way, Metaplex refuses);
459
+ * each `null` leaves that part as it is. The update authority signs (a PDA of this program with `signerSeeds`).
460
+ */
461
+ updateMetadataAccountsV2(
462
+ metadata: AccountMeta,
463
+ updateAuthority: AccountMeta,
464
+ data: {
465
+ name: string;
466
+ symbol: string;
467
+ uri: string;
468
+ sellerFeeBasisPoints: u16;
469
+ creators?: { address: Pubkey; verified: boolean; share: u8 }[];
470
+ collection?: Pubkey;
471
+ } | null,
472
+ newUpdateAuthority: Pubkey | null,
473
+ primarySaleHappened: boolean | null,
474
+ isMutable: boolean | null,
475
+ signerSeeds?: Seed[] | SignerSeeds,
476
+ ): void;
394
477
  }
395
478
  /** The Metaplex master edition address of a mint (PDA ["metadata", program, mint, "edition"]). */
396
479
  export declare function masterEditionAddress(mint: Pubkey): Pubkey;
@@ -469,8 +552,11 @@ export interface AccountMeta {
469
552
  */
470
553
  export declare function pubkey(base58: string): Pubkey;
471
554
 
472
- /** The account must be this exact address (Anchor `address = …`, error 2012): `Address<Mut<AccountInfo>, "4Nd1…">`. */
473
- export type Address<A, Base58 extends string> = A & { readonly __address?: Base58 };
555
+ /**
556
+ * The account must be this exact address (Anchor `address = …`, error 2012): `Address<Mut<AccountInfo>, "4Nd1…">`.
557
+ * A third argument fails with one of your errors instead (Anchor's `address = … @ ErrorCode.X`).
558
+ */
559
+ export type Address<A, Base58 extends string, E = never> = A & { readonly __address?: [Base58, E] };
474
560
 
475
561
  /**
476
562
  * Token constraints, checked before your code runs:
@@ -561,8 +647,11 @@ export interface AccountInfo extends AccountMeta {
561
647
  /** A program-owned account holding struct `T`. Owner and discriminator are checked. */
562
648
  export type Account<T> = Readonly<T> & AccountMeta;
563
649
 
564
- /** Like `Account<T>` but writable. Also usable as `Mut<Signer>`, `Mut<AccountInfo>`, `Mut<TokenAccount>`. */
565
- export type Mut<T> = T & AccountMeta;
650
+ /**
651
+ * Like `Account<T>` but writable. Also usable as `Mut<Signer>`, `Mut<AccountInfo>`, `Mut<TokenAccount>`. A second
652
+ * argument fails with one of your errors when the account is not writable (Anchor's `mut @ ErrorCode.X`; else 2000).
653
+ */
654
+ export type Mut<T, E = never> = T & AccountMeta;
566
655
 
567
656
  /** A PDA seed: a string, a Pubkey, an integer (at its width) or a unit enum value (one byte). */
568
657
  export type Seed = string | Pubkey | bigint | number;
@@ -647,8 +736,12 @@ export type InitIfNeeded<T> = T extends TokenAccount
647
736
  * ("@param" names a program parameter, or give a base58 address).
648
737
  * - `CloseTo<Mut<Vault>, "owner">`: close the account into `owner` when the instruction succeeds.
649
738
  * They nest: `CloseTo<HasOne<Mut<Vault>, "owner">, "owner">`.
739
+ *
740
+ * `HasOne`, `Address`, `Owner`, `Signed` and `Mut` take one of your errors as their last argument, as Anchor's
741
+ * `has_one = owner @ ErrorCode.NotOwner` does: `HasOne<Mut<Vault>, "owner", ErrorCode.NotOwner>` (for one field each
742
+ * its own error, nest them: `HasOne<HasOne<Mut<Vault>, "owner", E.A>, "admin", E.B>`).
650
743
  */
651
- export type HasOne<A, Field extends string> = A & { readonly __hasOne?: Field };
744
+ export type HasOne<A, Field extends string, E = never> = A & { readonly __hasOne?: [Field, E] };
652
745
  /**
653
746
  * Anchor's `token::mint = mintParam, token::authority = authorityParam, token::token_program = tokenProgramParam` on an
654
747
  * existing token account, naming the parameters (2014 / 2015 / 2021: owned by that token program); `never` leaves one out.
@@ -673,7 +766,7 @@ export type Dup<A> = A & { readonly __dup?: true };
673
766
  * The account must sign the transaction (Anchor's `signer` constraint on an account that is not a `Signer`; 2002), e.g.
674
767
  * `Signed<Zeroed<Multisig>>` for an account the client creates with a fresh keypair in the same transaction.
675
768
  */
676
- export type Signed<A> = A & { readonly __signed?: true };
769
+ export type Signed<A, E = never> = A & { readonly __signed?: E | true };
677
770
  /**
678
771
  * Anchor 1.0's `Migration<From, To>`: an existing `From` account (owner, discriminator and size checked) that this
679
772
  * instruction rewrites as `To` with `acct.migrate(payer, value)`, a top-level statement every path must reach. Read
@@ -694,8 +787,8 @@ export type Seeds<A, Names extends readonly string[], Bump extends string = neve
694
787
  /** The PDA's bump (Anchor `ctx.bumps.<account>`): the stored bump field when one is named, else the canonical bump found. */
695
788
  readonly pdaBump: u8;
696
789
  };
697
- /** The account's owner program must be this address (Anchor `owner = …`, 2004). */
698
- export type Owner<A, Base58 extends string> = A & { readonly __owner?: Base58 };
790
+ /** The account's owner program must be this address (Anchor `owner = …`, 2004; a third argument: one of your errors). */
791
+ export type Owner<A, Base58 extends string, E = never> = A & { readonly __owner?: [Base58, E] };
699
792
  /**
700
793
  * An optional account (Anchor `Option<Account<…>>`): the client passes this program's id in its slot to leave it out.
701
794
  * Same as `A | null`. Check `x !== null` before using it; its checks and constraints run only when it is passed.
@@ -1528,6 +1621,29 @@ interface Token2022Ops {
1528
1621
  initializeGroupPointer(mint: AccountMeta, authority: Pubkey | null, groupAddress: Pubkey | null): void;
1529
1622
  /** GroupMemberPointer: where the mint's group-member data lives. */
1530
1623
  initializeGroupMemberPointer(mint: AccountMeta, authority: Pubkey | null, memberAddress: Pubkey | null): void;
1624
+ /**
1625
+ * The Token Group interface on Token-2022 mints (a collection of mints): make `group` (usually the mint itself, with
1626
+ * a GroupPointer to it, its space allocated) a group of at most `maxSize` members. The mint authority signs.
1627
+ */
1628
+ initializeTokenGroup(
1629
+ group: AccountMeta,
1630
+ mint: AccountMeta,
1631
+ mintAuthority: AccountMeta,
1632
+ updateAuthority: Pubkey | null,
1633
+ maxSize: u64,
1634
+ signerSeeds?: Seed[] | SignerSeeds,
1635
+ ): void;
1636
+ /** Add `memberMint` to `group` (`member` holds the membership, usually the member mint itself). Both authorities sign. */
1637
+ initializeGroupMember(
1638
+ member: AccountMeta,
1639
+ memberMint: AccountMeta,
1640
+ memberMintAuthority: AccountMeta,
1641
+ group: AccountMeta,
1642
+ groupUpdateAuthority: AccountMeta,
1643
+ signerSeeds?: Seed[] | SignerSeeds,
1644
+ ): void;
1645
+ updateGroupMaxSize(group: AccountMeta, updateAuthority: AccountMeta, maxSize: u64, signerSeeds?: Seed[] | SignerSeeds): void;
1646
+ updateGroupAuthority(group: AccountMeta, updateAuthority: AccountMeta, next: Pubkey | null, signerSeeds?: Seed[] | SignerSeeds): void;
1531
1647
  /** TransferHook: `programId` is invoked on every transfer of this mint. */
1532
1648
  initializeTransferHook(mint: AccountMeta, authority: Pubkey | null, programId: Pubkey | null): void;
1533
1649
  /** InterestBearingConfig: `rate` in basis points per year (UI amounts only; balances do not change). */
@@ -1782,6 +1898,13 @@ export declare function require(condition: boolean, error: string | AnchorError)
1782
1898
  */
1783
1899
  export declare function constraint(account: AccountMeta | RemainingAccount | null, condition: boolean, error?: string | AnchorError): void;
1784
1900
 
1901
+ /**
1902
+ * The instruction data as sent, discriminator included: `const data = instructionData()`, then `data.length`,
1903
+ * `data.get(i)`, or pass it on to `invokeInstruction`. A `/** @fallback *\/` instruction (Anchor's fallback: no
1904
+ * parameters, run when no instruction matches) reads its input this way, and its accounts with remainingAccounts().
1905
+ */
1906
+ export declare function instructionData(): IndexedList<u8>;
1907
+
1785
1908
  /** Write a string, integer or pubkey to the program log. */
1786
1909
  export declare function log(value: string | bigint | Pubkey | Hash): void;
1787
1910
 
@@ -1793,9 +1916,12 @@ export declare function emit<T>(event: T): void;
1793
1916
 
1794
1917
  /**
1795
1918
  * Read the return data the last invoke() left behind, checking it came from `program`
1796
- * and has exactly the size of T: `const n = returnData<u64>(counterProgram)`.
1919
+ * and has exactly the size of T: `const n = returnData<u64>(counterProgram)`. A struct is bound to a local:
1920
+ * `const quote = returnData<Quote>(amm)`. A fixed layout of integers, booleans, Pubkeys, unit enums and arrays is its
1921
+ * own Borsh form; a struct with Options, strings or Vecs is declared `@layout borsh` and Borsh-decoded (5106 when the
1922
+ * bytes do not decode to exactly it).
1797
1923
  */
1798
- export declare function returnData<T extends bigint | boolean | Pubkey | Hash>(program: AccountMeta): T;
1924
+ export declare function returnData<T extends bigint | boolean | Pubkey | Hash | object>(program: AccountMeta): T;
1799
1925
 
1800
1926
  /**
1801
1927
  * Verify `account.key` is the PDA for `seeds` + `bump` under this program. Any bump that gives a PDA passes (Anchor's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typesol/cli",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "Compile a TypeScript-syntax language directly to Solana SBF programs.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1249,6 +1249,15 @@ static inline uint64_t ts_return_data(const TsAccount *program, uint8_t *out, ui
1249
1249
  return SUCCESS;
1250
1250
  }
1251
1251
 
1252
+ /* Return data of exactly `size` bytes (a struct), copied straight into `out`. */
1253
+ static inline uint64_t ts_return_data_exact(const TsAccount *program, void *out, uint64_t size) {
1254
+ SolPubkey from;
1255
+ uint64_t n = sol_get_return_data((uint8_t *)out, size, &from);
1256
+ if (n != size || !ts_key_eq(&from, &program->key))
1257
+ TS_FAIL(TS_ERR_RETURN_DATA, "TypeSOL: missing or mismatched return data");
1258
+ return SUCCESS;
1259
+ }
1260
+
1252
1261
  /* ---- Crypto ---------------------------------------------------------------- */
1253
1262
  static const SolPubkey TS_ED25519_PROGRAM_ID = {{3,125,70,214,124,147,251,190,18,249,66,143,131,141,64,255,5,112,116,73,39,244,138,100,252,202,112,68,128,0,0,0}};
1254
1263
  static const SolPubkey TS_INSTRUCTIONS_SYSVAR_ID = {{6,167,213,23,24,123,209,102,53,218,212,4,85,253,194,192,193,36,198,143,33,86,117,165,219,186,203,95,8,0,0,0}};
@@ -1431,6 +1440,17 @@ static inline uint64_t ts_alloc(uint64_t n, uint8_t **out) {
1431
1440
  return SUCCESS;
1432
1441
  }
1433
1442
 
1443
+ /* Return data of any size (Borsh, at most 1024 bytes) into a heap buffer: its bytes and length. */
1444
+ static inline uint64_t ts_return_data_any(const TsAccount *program, uint8_t **out, uint64_t *len) {
1445
+ TS_TRY(ts_alloc(1024, out));
1446
+ SolPubkey from;
1447
+ uint64_t n = sol_get_return_data(*out, 1024, &from);
1448
+ if (n == 0 || n > 1024 || !ts_key_eq(&from, &program->key))
1449
+ TS_FAIL(TS_ERR_RETURN_DATA, "TypeSOL: missing or mismatched return data");
1450
+ *len = n;
1451
+ return SUCCESS;
1452
+ }
1453
+
1434
1454
  /* A heap Vec (a Vec<T> in a @layout borsh struct, held on the heap while the instruction runs): room for at least
1435
1455
  `need` elements of `size` bytes, doubling as Rust's Vec does. Elements move when it grows (the compiler refuses
1436
1456
  references into it that would outlive a push). Bounded by the heap; the account bounds it when it is packed (3004). */
@@ -1817,6 +1837,9 @@ static inline uint64_t ts_switchboard_value(const TsAccount *a, uint64_t max_sta
1817
1837
  }
1818
1838
 
1819
1839
  /* ---- Associated token accounts, token metadata, transfer hooks ------------------- */
1840
+ static const SolPubkey TS_STAKE_PROGRAM_ID = {{6,161,216,23,145,55,84,42,152,52,55,189,254,42,122,178,85,127,83,92,138,120,114,43,104,164,157,192,0,0,0,0}};
1841
+ static const SolPubkey TS_MEMO_PROGRAM_ID = {{5,74,83,90,153,41,33,6,77,36,232,113,96,218,56,124,124,53,181,221,188,146,187,129,228,31,168,64,65,5,68,141}};
1842
+ static const SolPubkey TS_SLOT_HASHES_ID = {{6,167,213,23,25,47,10,175,198,242,101,227,251,119,204,122,218,130,197,41,208,190,59,19,110,45,0,85,32,0,0,0}};
1820
1843
  static const SolPubkey TS_ATA_PROGRAM_ID = {{140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89}};
1821
1844
  static const SolPubkey TS_MPL_METADATA_ID = {{11,112,101,177,227,209,124,69,56,157,82,127,107,4,195,205,88,184,108,115,26,160,253,181,73,182,209,188,3,248,41,70}};
1822
1845
 
@@ -1951,6 +1974,66 @@ static inline uint64_t ts_mpl_create_v3(TsParams *params, const TsAccount *progr
1951
1974
  return ts_invoke(params, &ix, &signer, n > 0 ? 1 : 0);
1952
1975
  }
1953
1976
 
1977
+ /*
1978
+ * UpdateMetadataAccountV2 (15): each part optional. `has_data` sets the whole DataV2 (name, symbol, uri, fee, creators
1979
+ * (ncreators < 0: None), collection (NULL: None), uses None); `new_ua` NULL leaves the update authority; `primary` and
1980
+ * `mutable` are -1 to leave them, else 0 / 1. The update authority signs.
1981
+ */
1982
+ static inline uint64_t ts_mpl_update_v2(TsParams *params, const TsAccount *program, TsAccount *metadata,
1983
+ TsAccount *update_authority, bool has_data, TS_Str name, TS_Str symbol, TS_Str uri,
1984
+ uint16_t fee_bps, const uint8_t *creators, int ncreators, const SolPubkey *collection,
1985
+ const SolPubkey *new_ua, int primary, int mutable_, const SolSignerSeed *seeds, int n) {
1986
+ uint8_t *data;
1987
+ uint64_t ncr = ncreators > 0 ? (uint64_t)ncreators : 0;
1988
+ TS_TRY(ts_alloc(1 + 1 + 12 + name.len + symbol.len + uri.len + 2 + (1 + 4 + 34 * ncr) + (1 + 33) + 1 + 33 + 2 + 2, &data));
1989
+ uint64_t at = 0;
1990
+ data[at++] = 15;
1991
+ if (!has_data) {
1992
+ data[at++] = 0;
1993
+ } else {
1994
+ data[at++] = 1;
1995
+ ts_put_str(data, &at, name);
1996
+ ts_put_str(data, &at, symbol);
1997
+ ts_put_str(data, &at, uri);
1998
+ ts_memcpy(data + at, &fee_bps, 2);
1999
+ at += 2;
2000
+ if (ncreators < 0) {
2001
+ data[at++] = 0;
2002
+ } else {
2003
+ data[at++] = 1;
2004
+ uint32_t count = (uint32_t)ncreators;
2005
+ ts_memcpy(data + at, &count, 4);
2006
+ at += 4;
2007
+ ts_memcpy(data + at, creators, 34 * ncr);
2008
+ at += 34 * ncr;
2009
+ }
2010
+ if (collection) {
2011
+ data[at++] = 1;
2012
+ data[at++] = 0; /* verified: false */
2013
+ ts_memcpy(data + at, collection, 32);
2014
+ at += 32;
2015
+ } else {
2016
+ data[at++] = 0;
2017
+ }
2018
+ data[at++] = 0; /* uses: None */
2019
+ }
2020
+ if (new_ua) {
2021
+ data[at++] = 1;
2022
+ ts_memcpy(data + at, new_ua, 32);
2023
+ at += 32;
2024
+ } else {
2025
+ data[at++] = 0;
2026
+ }
2027
+ if (primary < 0) data[at++] = 0;
2028
+ else data[at++] = 1, data[at++] = (uint8_t)primary;
2029
+ if (mutable_ < 0) data[at++] = 0;
2030
+ else data[at++] = 1, data[at++] = (uint8_t)mutable_;
2031
+ SolAccountMeta metas[2] = {{&metadata->key, true, false}, {&update_authority->key, false, true}};
2032
+ SolInstruction ix = {(SolPubkey *)&program->key, metas, 2, data, at};
2033
+ SolSignerSeeds signer = {seeds, (uint64_t)n};
2034
+ return ts_invoke(params, &ix, &signer, n > 0 ? 1 : 0);
2035
+ }
2036
+
1954
2037
  /*
1955
2038
  * Transfer hook validation account (ExtraAccountMetaList with no extra accounts) at PDA
1956
2039
  * ["extra-account-metas", mint]: TLV = execute discriminator | u32 length 4 | u32 count 0.