@typesol/cli 0.33.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/CHANGELOG.md +23 -0
- package/README.md +2 -1
- package/dist/cli.js +30 -0
- package/dist/compiler/analyze.js +77 -36
- package/dist/compiler/emit/base.d.ts +6 -0
- package/dist/compiler/emit/base.js +28 -6
- package/dist/compiler/emit/calls.js +6 -0
- package/dist/compiler/emit/expressions.js +12 -0
- package/dist/compiler/emit/function.js +7 -0
- package/dist/compiler/emit/metaplex.d.ts +11 -0
- package/dist/compiler/emit/metaplex.js +108 -37
- package/dist/compiler/emit/program.js +8 -4
- package/dist/compiler/emit/statements.js +8 -0
- package/dist/compiler/emit/token.d.ts +8 -0
- package/dist/compiler/emit/token.js +189 -0
- package/dist/compiler/idl.js +30 -15
- package/dist/compiler/model.d.ts +19 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.js +5 -0
- package/dist/tools/clone.d.ts +40 -0
- package/dist/tools/clone.js +103 -0
- package/dist/workspace.d.ts +4 -0
- package/dist/workspace.js +13 -1
- package/docs/cli.md +3 -1
- package/docs/language.md +7 -4
- package/docs/migrate-from-anchor.md +8 -0
- package/docs/test-your-program.md +7 -0
- package/lib/typesol.d.ts +113 -0
- package/package.json +1 -1
- package/runtime/typesol_rt.h +63 -0
|
@@ -116,6 +116,14 @@ Anchor instruction that takes or returns a struct with `String` / `Vec` / `Optio
|
|
|
116
116
|
| `system_program::transfer(CpiContext::new_with_signer(…, &[vault_seeds]), lamports)` | `systemProgram.transfer(vault, to, lamports, ["vault", owner.key, bump])` |
|
|
117
117
|
| `invoke_signed(&ix, infos, &[seeds_a, seeds_b])` | `invoke(program, accounts, data, [seedsA, seedsB])` |
|
|
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
|
+
| `[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(…)` |
|
|
119
127
|
| `invoke_signed(&ix, &accounts, &[seeds])` | `invoke(program, [writable(a), readonly(b)], [data…], seeds)` |
|
|
120
128
|
| `invoke_signed(&Instruction { program_id, accounts, data }, ctx.remaining_accounts, …)` built at run time | `invokeInstruction(programId, metas, data, remainingAccounts(), seeds)` |
|
|
121
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;
|
|
@@ -1538,6 +1621,29 @@ interface Token2022Ops {
|
|
|
1538
1621
|
initializeGroupPointer(mint: AccountMeta, authority: Pubkey | null, groupAddress: Pubkey | null): void;
|
|
1539
1622
|
/** GroupMemberPointer: where the mint's group-member data lives. */
|
|
1540
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;
|
|
1541
1647
|
/** TransferHook: `programId` is invoked on every transfer of this mint. */
|
|
1542
1648
|
initializeTransferHook(mint: AccountMeta, authority: Pubkey | null, programId: Pubkey | null): void;
|
|
1543
1649
|
/** InterestBearingConfig: `rate` in basis points per year (UI amounts only; balances do not change). */
|
|
@@ -1792,6 +1898,13 @@ export declare function require(condition: boolean, error: string | AnchorError)
|
|
|
1792
1898
|
*/
|
|
1793
1899
|
export declare function constraint(account: AccountMeta | RemainingAccount | null, condition: boolean, error?: string | AnchorError): void;
|
|
1794
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
|
+
|
|
1795
1908
|
/** Write a string, integer or pubkey to the program log. */
|
|
1796
1909
|
export declare function log(value: string | bigint | Pubkey | Hash): void;
|
|
1797
1910
|
|
package/package.json
CHANGED
package/runtime/typesol_rt.h
CHANGED
|
@@ -1837,6 +1837,9 @@ static inline uint64_t ts_switchboard_value(const TsAccount *a, uint64_t max_sta
|
|
|
1837
1837
|
}
|
|
1838
1838
|
|
|
1839
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}};
|
|
1840
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}};
|
|
1841
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}};
|
|
1842
1845
|
|
|
@@ -1971,6 +1974,66 @@ static inline uint64_t ts_mpl_create_v3(TsParams *params, const TsAccount *progr
|
|
|
1971
1974
|
return ts_invoke(params, &ix, &signer, n > 0 ? 1 : 0);
|
|
1972
1975
|
}
|
|
1973
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
|
+
|
|
1974
2037
|
/*
|
|
1975
2038
|
* Transfer hook validation account (ExtraAccountMetaList with no extra accounts) at PDA
|
|
1976
2039
|
* ["extra-account-metas", mint]: TLV = execute discriminator | u32 length 4 | u32 count 0.
|