@typesol/cli 0.41.0 → 0.43.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 +319 -0
- package/README.md +11 -7
- package/dist/compiler/analyze.js +484 -13
- package/dist/compiler/diagnostics.d.ts +1 -0
- package/dist/compiler/diagnostics.js +13 -0
- package/dist/compiler/emit/alias.d.ts +44 -0
- package/dist/compiler/emit/alias.js +135 -4
- package/dist/compiler/emit/base.d.ts +65 -7
- package/dist/compiler/emit/base.js +91 -7
- package/dist/compiler/emit/borsh.d.ts +7 -0
- package/dist/compiler/emit/borsh.js +86 -1
- package/dist/compiler/emit/calls.d.ts +169 -2
- package/dist/compiler/emit/calls.js +1170 -81
- package/dist/compiler/emit/cpi-core.d.ts +28 -5
- package/dist/compiler/emit/cpi-core.js +238 -12
- package/dist/compiler/emit/cpi.js +16 -16
- package/dist/compiler/emit/create.d.ts +3 -3
- package/dist/compiler/emit/create.js +33 -25
- package/dist/compiler/emit/expressions.js +89 -9
- package/dist/compiler/emit/function.js +2 -2
- package/dist/compiler/emit/outline.d.ts +24 -0
- package/dist/compiler/emit/outline.js +100 -0
- package/dist/compiler/emit/program.js +37 -3
- package/dist/compiler/emit/rbtree.d.ts +7 -0
- package/dist/compiler/emit/rbtree.js +142 -0
- package/dist/compiler/emit/shared.d.ts +43 -1
- package/dist/compiler/emit/shared.js +18 -2
- package/dist/compiler/emit/statements.d.ts +58 -1
- package/dist/compiler/emit/statements.js +549 -22
- package/dist/compiler/emit/storage.d.ts +48 -1
- package/dist/compiler/emit/storage.js +220 -63
- package/dist/compiler/emit/token.d.ts +11 -8
- package/dist/compiler/emit/token.js +233 -104
- package/dist/compiler/emit/views.d.ts +60 -0
- package/dist/compiler/emit/views.js +523 -0
- package/dist/compiler/hints.js +6 -0
- package/dist/compiler/idl.js +2 -1
- package/dist/compiler/model.d.ts +84 -4
- package/dist/compiler/model.js +19 -0
- package/dist/compiler/toolchain.d.ts +15 -0
- package/dist/compiler/toolchain.js +146 -11
- package/dist/testing-stake.d.ts +216 -0
- package/dist/testing-stake.js +526 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +1 -0
- package/docs/architecture.md +9 -2
- package/docs/case-study-phoenix.md +226 -0
- package/docs/case-study-spl-stake-pool.md +122 -0
- package/docs/errors.md +1 -1
- package/docs/language.md +244 -20
- package/docs/migrate-from-anchor.md +1 -0
- package/docs/runtime.md +1 -1
- package/docs/security-model.md +4 -0
- package/docs/stability.md +33 -1
- package/docs/test-your-program.md +47 -0
- package/docs/testing.md +19 -0
- package/docs/troubleshooting.md +5 -2
- package/lib/typesol.d.ts +462 -44
- package/llms-full.txt +338 -26
- package/llms.txt +1 -1
- package/package.json +2 -2
- package/runtime/typesol_rt.h +476 -0
package/lib/typesol.d.ts
CHANGED
|
@@ -119,6 +119,17 @@ export interface Vec<T> extends ListMethods<T> {
|
|
|
119
119
|
* back: 3004, as under Anchor).
|
|
120
120
|
*/
|
|
121
121
|
push(value: T, payer?: Mut<Signer>): void;
|
|
122
|
+
/**
|
|
123
|
+
* A FixedVec's bulk append (declared here so a Vec still passes where a FixedVec is expected): a Vec in account data
|
|
124
|
+
* grows one `push` at a time, so calling it on a Vec is a compile error.
|
|
125
|
+
*/
|
|
126
|
+
pushAll(items: IndexedList<T>): void;
|
|
127
|
+
/** A `FixedVec<u8, N>`'s byte builders (declared here for the same reason; a compile error on a Vec). */
|
|
128
|
+
pushLE<I extends bigint = bigint>(this: Vec<u8>, value: I): void;
|
|
129
|
+
pushKey(this: Vec<u8>, key: Pubkey): void;
|
|
130
|
+
pushBorsh<V = unknown>(this: Vec<u8>, value: V): void;
|
|
131
|
+
setLE<I extends bigint = bigint>(this: Vec<u8>, offset: u64, value: I): void;
|
|
132
|
+
truncate(this: Vec<u8>, length: u64): void;
|
|
122
133
|
/** Remove and return the last element, shrinking the account. */
|
|
123
134
|
pop(): T;
|
|
124
135
|
/** Remove every element, shrinking the account. */
|
|
@@ -137,11 +148,75 @@ export interface FixedVec<T, N extends number> extends ListMethods<T> {
|
|
|
137
148
|
get(index: bigint): T;
|
|
138
149
|
set(index: bigint, value: T): void;
|
|
139
150
|
push(value: T): void;
|
|
151
|
+
/**
|
|
152
|
+
* Append every element of `items` in one copy (a memcpy, not a loop of pushes): another FixedVec, a Vec or FixedArray
|
|
153
|
+
* of the same elements, a Vec argument, or the instruction data or a slice of it (`out.pushAll(data.slice(a, b))`).
|
|
154
|
+
* More than the room left fails (5104) and appends nothing.
|
|
155
|
+
*/
|
|
156
|
+
pushAll(items: IndexedList<T>): void;
|
|
140
157
|
pop(): T;
|
|
141
158
|
clear(): void;
|
|
159
|
+
/**
|
|
160
|
+
* A `FixedVec<u8, N>` as a byte buffer: append an integer's little-endian bytes at its width (`buf.pushLE(count)`
|
|
161
|
+
* with `count: u16`; a literal needs one: `buf.pushLE<u16>(1n)` or `buf.pushLE(u16(1n))`). Every byte builder
|
|
162
|
+
* fails (5104) and appends nothing when the bytes do not fit in the room left.
|
|
163
|
+
*/
|
|
164
|
+
pushLE<I extends bigint = bigint>(this: FixedVec<u8, N>, value: I): void;
|
|
165
|
+
/** Append a Pubkey's 32 bytes. */
|
|
166
|
+
pushKey(this: FixedVec<u8, N>, key: Pubkey): void;
|
|
167
|
+
/**
|
|
168
|
+
* Append a value's Borsh encoding, as invoke data, events and storeBorsh encode it: a struct (an object literal
|
|
169
|
+
* takes its type: `buf.pushBorsh<Header>({ … })`), a data enum (a tag byte, then the variant's fields), a
|
|
170
|
+
* FixedArray, a list (u32 count, then the elements), an integer at its width, a boolean, a Pubkey, a string or an
|
|
171
|
+
* Option.
|
|
172
|
+
*/
|
|
173
|
+
pushBorsh<V = unknown>(this: FixedVec<u8, N>, value: V): void;
|
|
174
|
+
/**
|
|
175
|
+
* Overwrite the integer at byte `offset` with `value`'s little-endian bytes (`buf.setLE<u16>(91n, count)`): within the
|
|
176
|
+
* length, 5104 past it, as Rust's `data[a..b].copy_from_slice(…)` panics there.
|
|
177
|
+
*/
|
|
178
|
+
setLE<I extends bigint = bigint>(this: FixedVec<u8, N>, offset: u64, value: I): void;
|
|
179
|
+
/** Keep the first `length` bytes (5104 when `length` is past the current length). */
|
|
180
|
+
truncate(this: FixedVec<u8, N>, length: u64): void;
|
|
142
181
|
[Symbol.iterator](): Iterator<T>;
|
|
143
182
|
readonly __capacity?: N;
|
|
144
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* A native program's zero-copy list over the rest of an account (SPL's `big_vec::BigVec`, the stake pool's validator
|
|
186
|
+
* list): a u32 length, then the elements back to back, in an account allocated up front. Only the last field of a
|
|
187
|
+
* struct read with `loadRaw` / `loadRawMut`; its room is the account's (`capacity`), and it is never resized. Loading
|
|
188
|
+
* checks that the stored length fits in the account (ProgramError::AccountDataTooSmall). Elements are read and
|
|
189
|
+
* written in place (structs by reference).
|
|
190
|
+
*/
|
|
191
|
+
export interface BigVec<T> extends ListMethods<T> {
|
|
192
|
+
readonly length: u64;
|
|
193
|
+
/** How many elements fit: (the account's size - the struct's fixed fields - 4) / size(T). */
|
|
194
|
+
readonly capacity: u64;
|
|
195
|
+
get(index: bigint): T;
|
|
196
|
+
set(index: bigint, value: T): void;
|
|
197
|
+
/** Append after the last element (BigVec::push); no room left fails with ProgramError::AccountDataTooSmall. */
|
|
198
|
+
push(value: T): void;
|
|
199
|
+
/**
|
|
200
|
+
* Keep the elements `fn` holds for, in order, moved down in place in one pass (BigVec::retain); the bytes past the new
|
|
201
|
+
* end keep what they held.
|
|
202
|
+
*/
|
|
203
|
+
retain(fn: (x: T) => boolean): void;
|
|
204
|
+
/**
|
|
205
|
+
* Elements `start` to `end - 1` in place (BigVec::deserialize_mut_slice(start, end - start)), for `for … of`, the
|
|
206
|
+
* list methods, `get`, `set` and `.length` right where it is written. Unlike JS's slice it does not clamp: `end`
|
|
207
|
+
* past the length or before `start` fails with ProgramError::AccountDataTooSmall. `end` defaults to the length.
|
|
208
|
+
*/
|
|
209
|
+
slice(start: bigint, end?: bigint): BigVecSlice<T>;
|
|
210
|
+
[Symbol.iterator](): Iterator<T>;
|
|
211
|
+
}
|
|
212
|
+
/** Some elements of a BigVec, in place: `bigVec.slice(start, end)`. */
|
|
213
|
+
export interface BigVecSlice<T> extends ListMethods<T> {
|
|
214
|
+
readonly length: u64;
|
|
215
|
+
get(index: bigint): T;
|
|
216
|
+
set(index: bigint, value: T): void;
|
|
217
|
+
[Symbol.iterator](): Iterator<T>;
|
|
218
|
+
}
|
|
219
|
+
|
|
145
220
|
/** A FixedVec value holding these elements (`acct.owners = fixedVec([a, b])`, `{ owners: fixedVec([]) }`). */
|
|
146
221
|
export declare function fixedVec<T>(items: T[]): FixedVec<T, never>;
|
|
147
222
|
|
|
@@ -173,6 +248,23 @@ export interface RemainingSlice extends Iterable<CpiAccount> {
|
|
|
173
248
|
}
|
|
174
249
|
export declare function remainingAccounts(): RemainingAccounts;
|
|
175
250
|
|
|
251
|
+
/**
|
|
252
|
+
* A remaining account (or an AccountInfo parameter) as a typed program: `const stake = programAt<StakeProgram>(rest.get(12n))`,
|
|
253
|
+
* then `stake.split(…)`, `token.mintTo(…)`, `system.transfer(…)` as on a declared program parameter, and passed to
|
|
254
|
+
* helpers that take that program type. Its key is checked once, here (ProgramError.IncorrectProgramId otherwise;
|
|
255
|
+
* TokenInterface: either token program). The typed methods take remaining accounts as well as declared ones: the
|
|
256
|
+
* compiler checks declared parameters (writable, signer), the called program and the runtime check remaining accounts.
|
|
257
|
+
*/
|
|
258
|
+
export declare function programAt<
|
|
259
|
+
P extends StakeProgram | SystemProgram | TokenProgram | Token2022Program | TokenInterface | AssociatedTokenProgram | MemoProgram,
|
|
260
|
+
>(account: RemainingAccount | AccountInfo): P;
|
|
261
|
+
/**
|
|
262
|
+
* A remaining account (or an AccountInfo parameter) as a sysvar read in place: `sysvarAt<StakeHistorySysvar>(acct)`,
|
|
263
|
+
* bound to a const, then `.count`, `.latestEpoch`, `.effective(epoch)` …. Its key is checked once, here (ProgramError.InvalidArgument
|
|
264
|
+
* otherwise, as solana_program's `Sysvar::from_account_info`).
|
|
265
|
+
*/
|
|
266
|
+
export declare function sysvarAt<S extends StakeHistorySysvar>(account: RemainingAccount | AccountInfo): S;
|
|
267
|
+
|
|
176
268
|
/**
|
|
177
269
|
* Read a struct of this program from a remaining account or an `AccountInfo` parameter (Anchor's
|
|
178
270
|
* `AccountLoader::try_from` on an `UncheckedAccount`): owner, discriminator and size are checked.
|
|
@@ -192,6 +284,139 @@ export declare function loadAccountMut<T>(account: RemainingAccount | AccountInf
|
|
|
192
284
|
*/
|
|
193
285
|
export declare function loadRaw<T>(account: RemainingAccount | AccountInfo): Account<T>;
|
|
194
286
|
export declare function loadRawMut<T>(account: RemainingAccount | AccountInfo): Mut<T>;
|
|
287
|
+
/**
|
|
288
|
+
* `loadRaw` / `loadRawMut` at a byte offset known only at run time (a native account whose parts start where its header
|
|
289
|
+
* says: Phoenix's market at byte 576). Owned by this program (3007); `offset + size(T)` within the data, checked once
|
|
290
|
+
* here (ProgramError::AccountDataTooSmall); `loadRawMutAt` writable and claimed as `loadRawMut` is (2040; neither with
|
|
291
|
+
* `NATIVE_ACCOUNT_WRITES`). Bind it with const: `const market = loadRawMutAt<FifoMarket>(acct, 576n)`. A view (this one,
|
|
292
|
+
* `rawArrayAt`, `rbTreeAt` and what is read through them) is not used after `closeRaw` or `resizeAccount` of an account
|
|
293
|
+
* it may view, since its bounds were checked against the old length: take it again after (a compile error says so).
|
|
294
|
+
*/
|
|
295
|
+
export declare function loadRawAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Account<T>;
|
|
296
|
+
export declare function loadRawMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64): Mut<T>;
|
|
297
|
+
/**
|
|
298
|
+
* `capacity` elements of a fixed-size type packed in place from a run-time byte offset, the count known only at run
|
|
299
|
+
* time (a slab sized by its header). Bounds checked once when it is made (`offset + capacity × size(T)` within the
|
|
300
|
+
* data, overflow included: ProgramError::AccountDataTooSmall), then `get` / `set` check the index against the count
|
|
301
|
+
* (5104). Elements are references into the account (structs) or values. `.length` is the capacity.
|
|
302
|
+
*/
|
|
303
|
+
export interface RawArray<T> extends ListMethods<T> {
|
|
304
|
+
readonly length: u64;
|
|
305
|
+
get(index: bigint): T;
|
|
306
|
+
set(index: bigint, value: T): void;
|
|
307
|
+
[Symbol.iterator](): Iterator<T>;
|
|
308
|
+
}
|
|
309
|
+
/** A RawArray of a read-only view (`rawArrayAt`): elements are read, not written. */
|
|
310
|
+
export interface ReadonlyRawArray<T> extends ListMethods<T> {
|
|
311
|
+
readonly length: u64;
|
|
312
|
+
get(index: bigint): Readonly<T>;
|
|
313
|
+
[Symbol.iterator](): Iterator<Readonly<T>>;
|
|
314
|
+
}
|
|
315
|
+
/** `const slab = rawArrayMutAt<Order>(acct, offset, capacity)`: see RawArray. */
|
|
316
|
+
export declare function rawArrayAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): ReadonlyRawArray<T>;
|
|
317
|
+
export declare function rawArrayMutAt<T>(account: RemainingAccount | AccountInfo, offset: u64, capacity: u64): RawArray<T>;
|
|
318
|
+
|
|
319
|
+
/** A node of a RedBlackTree: its key (read-only), its value (in place) and its index in the tree's node array (1-based). */
|
|
320
|
+
export interface RbEntry<K, V> {
|
|
321
|
+
readonly key: Readonly<K>;
|
|
322
|
+
value: V;
|
|
323
|
+
readonly index: u32;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* lib-sokoban 0.3's `RedBlackTree<K, V, N>` in account data, byte for byte (Phoenix's order books and trader seats):
|
|
327
|
+
* at the offset, root u32, padding, the allocator (size u64, bump index u32, free list head u32), then `capacity` nodes
|
|
328
|
+
* of 16 register bytes + K + V, 1-based. Every operation makes the writes sokoban makes, so a port's account bytes
|
|
329
|
+
* match the original's after every instruction (freed nodes keep their key and value bytes; the free list is LIFO).
|
|
330
|
+
* Keys are ordered by the comparator given to `rbTreeMutAt`, called as `compare(searchedKey, nodeKey)`, or by default
|
|
331
|
+
* as Rust derives Ord (fields in order, integers by value, Pubkeys by their bytes).
|
|
332
|
+
*/
|
|
333
|
+
export interface RedBlackTree<K, V> {
|
|
334
|
+
/** The number of keys (sokoban's `len()`). */
|
|
335
|
+
readonly length: u64;
|
|
336
|
+
/** The number of nodes it was made with (sokoban's `capacity()`, its `N`). */
|
|
337
|
+
readonly capacity: u64;
|
|
338
|
+
/** NodeAllocator::initialize on zeroed bytes; anything else panics "Cannot reinitialize NodeAllocator", as sokoban. */
|
|
339
|
+
initialize(): void;
|
|
340
|
+
/** The value stored for `key`, in place (a reference: writes go to the tree), or null. */
|
|
341
|
+
get(key: K): V | null;
|
|
342
|
+
/**
|
|
343
|
+
* Insert, or replace the value of an equal key (keeping its node). The node index, or null when a new key finds the
|
|
344
|
+
* tree full (nothing written); a tree that is empty takes the key without that check, as sokoban's does.
|
|
345
|
+
* References into the tree's nodes (`get`, `min`, entries, however bound: `c ? t.min() : t.max()`, `t.get(k)!`)
|
|
346
|
+
* cannot be used after an insert (a freed node may be reused).
|
|
347
|
+
*/
|
|
348
|
+
insert(key: K, value: V): u32 | null;
|
|
349
|
+
/** Remove `key`: its value (a struct in place in the freed node, which keeps its bytes until reused), or null. */
|
|
350
|
+
remove(key: K): V | null;
|
|
351
|
+
/**
|
|
352
|
+
* Remove the node at `index` (from `addrOf`, a node of `min` / `max` / `get`'s entry or a walk): the same writes as
|
|
353
|
+
* `remove(node.key)`, without searching the tree again. Its value, or null for index 0 or a node that holds no key
|
|
354
|
+
* (a freed one); past the capacity panics as `nodeAt` does.
|
|
355
|
+
*/
|
|
356
|
+
removeAt(index: u32): V | null;
|
|
357
|
+
/** The node with the smallest key (sokoban's get_min_index), or null when empty. */
|
|
358
|
+
min(): RbEntry<K, V> | null;
|
|
359
|
+
/** The node with the largest key, or null. */
|
|
360
|
+
max(): RbEntry<K, V> | null;
|
|
361
|
+
/** The index of the node holding `key` (sokoban's get_addr), 0 when absent. */
|
|
362
|
+
addrOf(key: K): u32;
|
|
363
|
+
/** Node `index` as stored (sokoban's get_node), whether or not it holds a key; 0 or past the capacity panics as Rust's indexing. */
|
|
364
|
+
nodeAt(index: u32): RbEntry<K, V>;
|
|
365
|
+
/** `for (const e of tree.reversed())`: from the largest key down. */
|
|
366
|
+
reversed(): Iterable<RbEntry<K, V>>;
|
|
367
|
+
/**
|
|
368
|
+
* `for (const e of tree)`: from the smallest key up, `break` and `continue` as in any loop. The body may change values
|
|
369
|
+
* but not insert, remove or initialize on this tree or on any tree view of an account that may be this one (another
|
|
370
|
+
* view of the same tree), nor call a helper that takes accounts and makes an `rbTreeMutAt` view.
|
|
371
|
+
*/
|
|
372
|
+
[Symbol.iterator](): Iterator<RbEntry<K, V>>;
|
|
373
|
+
}
|
|
374
|
+
/** A RedBlackTree of a read-only view (`rbTreeAt`): read, never changed. */
|
|
375
|
+
export interface ReadonlyRedBlackTree<K, V> {
|
|
376
|
+
readonly length: u64;
|
|
377
|
+
readonly capacity: u64;
|
|
378
|
+
get(key: K): Readonly<V> | null;
|
|
379
|
+
min(): Readonly<RbEntry<K, Readonly<V>>> | null;
|
|
380
|
+
max(): Readonly<RbEntry<K, Readonly<V>>> | null;
|
|
381
|
+
addrOf(key: K): u32;
|
|
382
|
+
nodeAt(index: u32): Readonly<RbEntry<K, Readonly<V>>>;
|
|
383
|
+
reversed(): Iterable<Readonly<RbEntry<K, Readonly<V>>>>;
|
|
384
|
+
[Symbol.iterator](): Iterator<Readonly<RbEntry<K, Readonly<V>>>>;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* lib-sokoban 0.3's RedBlackTree<K, V, capacity> at a run-time byte offset (see RedBlackTree): owned by this program
|
|
388
|
+
* (3007), its 32 + capacity × (16 + size(K) + size(V)) bytes within the data (ProgramError::AccountDataTooSmall),
|
|
389
|
+
* `rbTreeMutAt` writable and claimed as `loadRawMut` is. `compare`, a function of the program `(a: K, b: K) => i8`
|
|
390
|
+
* (negative: a first; any signed integer type, an unsigned result is refused as it could never say "less"), orders the keys; it is called as compare(searchedKey, nodeKey), so an order that depends on the
|
|
391
|
+
* left key (Phoenix's FIFOOrderId: bids descending, asks ascending, by the sequence number's top bit) works as in
|
|
392
|
+
* Rust. Without it, keys are ordered as Rust's derived Ord orders them.
|
|
393
|
+
*/
|
|
394
|
+
export declare function rbTreeAt<K, V>(
|
|
395
|
+
account: RemainingAccount | AccountInfo,
|
|
396
|
+
offset: u64,
|
|
397
|
+
capacity: u64,
|
|
398
|
+
compare?: (a: K, b: K) => bigint,
|
|
399
|
+
): ReadonlyRedBlackTree<K, V>;
|
|
400
|
+
export declare function rbTreeMutAt<K, V>(
|
|
401
|
+
account: RemainingAccount | AccountInfo,
|
|
402
|
+
offset: u64,
|
|
403
|
+
capacity: u64,
|
|
404
|
+
compare?: (a: K, b: K) => bigint,
|
|
405
|
+
): RedBlackTree<K, V>;
|
|
406
|
+
/**
|
|
407
|
+
* A native program's Borsh account, as Rust's `try_from_slice_unchecked::<T>(&data)` reads it: the data from byte 0
|
|
408
|
+
* decoded into a local `T` (a copy; write it back with `storeBorsh`). No owner check and no discriminator; bytes after
|
|
409
|
+
* the value are ignored. Data too short for it, an Option tag or a boolean other than 0/1, or an enum tag out of range
|
|
410
|
+
* fail with `ProgramError.BorshIoError`. Bind it with const: `const pool = loadBorsh<StakePool>(stakePool)`.
|
|
411
|
+
*/
|
|
412
|
+
export declare function loadBorsh<T>(account: RemainingAccount | AccountInfo): T;
|
|
413
|
+
/**
|
|
414
|
+
* Write `value` into the account's data from byte 0 as Borsh, as Rust's `value.serialize(&mut *data)` does: only the
|
|
415
|
+
* encoded bytes are written (an Option that became None leaves the old bytes after it as they were); an account too
|
|
416
|
+
* small for the encoding fails with `ProgramError.BorshIoError`. The account must be writable (`Mut<AccountInfo>`, or a
|
|
417
|
+
* remaining account checked at run time).
|
|
418
|
+
*/
|
|
419
|
+
export declare function storeBorsh<T>(account: RemainingAccount | Mut<AccountInfo>, value: T): void;
|
|
195
420
|
|
|
196
421
|
/** 32 bytes of hash output (sha256 / keccak256, Merkle roots). Compare with `===`. */
|
|
197
422
|
export interface Hash {
|
|
@@ -344,48 +569,113 @@ export interface MemoProgram extends AccountMeta {
|
|
|
344
569
|
memo(text: string, signers?: AccountMeta[], signerSeeds?: Seed[] | SignerSeeds): void;
|
|
345
570
|
}
|
|
346
571
|
|
|
572
|
+
/** An account whose slot in a Stake CPI names another address: what `named(account, address)` gives. */
|
|
573
|
+
export interface NamedAccount {
|
|
574
|
+
readonly __named_account: void;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* A Stake CPI's sysvar or stake config argument as solana_program's stake instruction builders write it: the
|
|
578
|
+
* instruction's account list names `address` (`SysvarC1ock…`), and `account` (the slot's account, whatever its key) is
|
|
579
|
+
* the account handed to the runtime, as Rust's `invoke_signed(&ix, &[stake, clock_info, …])` hands it. The runtime finds
|
|
580
|
+
* each named address among the CPI's accounts only: a slot holding another account fails the call with MissingAccount
|
|
581
|
+
* (Instruction references an unknown account), as the original does, even when the sysvar is elsewhere in the
|
|
582
|
+
* transaction. Only valid as such an argument.
|
|
583
|
+
*/
|
|
584
|
+
export declare function named(account: AccountMeta, address: Pubkey): NamedAccount;
|
|
585
|
+
|
|
347
586
|
/**
|
|
348
587
|
* The native Stake program (`Stake1111…`). Its address is checked. The sysvar and config accounts it reads are
|
|
349
588
|
* passed in, as anchor-spl's stake module does (`SysvarRent…`, `SysvarC1ock…`, `SysvarStakeHistory…`,
|
|
350
|
-
* `StakeConfig…`)
|
|
589
|
+
* `StakeConfig…`), or as `named(account, address)` (a native port: the address in the instruction, the slot's account
|
|
590
|
+
* passed). Each authority signs: a wallet, or a PDA of this program with `signerSeeds`. The instructions and
|
|
591
|
+
* their accounts are solana-stake-interface's (`StakeInstruction`, bincode with a u32 tag). Every account may also be
|
|
592
|
+
* a remaining account (then the Stake program and the runtime check that it is writable and signed where it must).
|
|
351
593
|
*/
|
|
352
594
|
export interface StakeProgram extends AccountMeta {
|
|
353
595
|
readonly __stake_program: void;
|
|
354
|
-
/**
|
|
355
|
-
|
|
596
|
+
/**
|
|
597
|
+
* Initialize a stake account (created with 200 bytes, owned by the Stake program), with no lockup or with `lockup`:
|
|
598
|
+
* no withdrawal before `unixTimestamp` and `epoch` unless `custodian` signs.
|
|
599
|
+
*/
|
|
600
|
+
initialize(
|
|
601
|
+
stake: AccountMeta,
|
|
602
|
+
rentSysvar: AccountMeta | NamedAccount,
|
|
603
|
+
staker: Pubkey,
|
|
604
|
+
withdrawer: Pubkey,
|
|
605
|
+
lockup?: { unixTimestamp: i64; epoch: u64; custodian: Pubkey },
|
|
606
|
+
): void;
|
|
356
607
|
/** Hand the staker or the withdrawer authority to `newAuthority`. */
|
|
357
608
|
authorize(
|
|
358
609
|
stake: AccountMeta,
|
|
359
|
-
clockSysvar: AccountMeta,
|
|
610
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
611
|
+
authority: AccountMeta,
|
|
612
|
+
newAuthority: Pubkey,
|
|
613
|
+
which: "staker" | "withdrawer",
|
|
614
|
+
signerSeeds?: Seed[] | SignerSeeds,
|
|
615
|
+
): void;
|
|
616
|
+
/** The same, with the lockup custodian signing (to change the withdrawer while a lockup is in force). */
|
|
617
|
+
authorize(
|
|
618
|
+
stake: AccountMeta,
|
|
619
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
360
620
|
authority: AccountMeta,
|
|
361
621
|
newAuthority: Pubkey,
|
|
362
622
|
which: "staker" | "withdrawer",
|
|
623
|
+
custodian: AccountMeta,
|
|
363
624
|
signerSeeds?: Seed[] | SignerSeeds,
|
|
364
625
|
): void;
|
|
365
626
|
delegate(
|
|
366
627
|
stake: AccountMeta,
|
|
367
628
|
vote: AccountMeta,
|
|
368
|
-
clockSysvar: AccountMeta,
|
|
369
|
-
stakeHistorySysvar: AccountMeta,
|
|
370
|
-
stakeConfig: AccountMeta,
|
|
629
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
630
|
+
stakeHistorySysvar: AccountMeta | NamedAccount,
|
|
631
|
+
stakeConfig: AccountMeta | NamedAccount,
|
|
371
632
|
staker: AccountMeta,
|
|
372
633
|
signerSeeds?: Seed[] | SignerSeeds,
|
|
373
634
|
): void;
|
|
374
|
-
|
|
635
|
+
/** Move `lamports` (and their share of the stake) into `splitStake`: 200 bytes, owned by the Stake program, uninitialized. */
|
|
636
|
+
split(stake: AccountMeta, splitStake: AccountMeta, staker: AccountMeta, lamports: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
637
|
+
deactivate(stake: AccountMeta, clockSysvar: AccountMeta | NamedAccount, staker: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
375
638
|
withdraw(
|
|
376
639
|
stake: AccountMeta,
|
|
377
640
|
to: AccountMeta,
|
|
378
|
-
clockSysvar: AccountMeta,
|
|
379
|
-
stakeHistorySysvar: AccountMeta,
|
|
641
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
642
|
+
stakeHistorySysvar: AccountMeta | NamedAccount,
|
|
380
643
|
withdrawer: AccountMeta,
|
|
381
644
|
lamports: u64,
|
|
382
645
|
signerSeeds?: Seed[] | SignerSeeds,
|
|
383
646
|
): void;
|
|
647
|
+
/** The same, with the lockup custodian signing (to withdraw while a lockup is in force). */
|
|
648
|
+
withdraw(
|
|
649
|
+
stake: AccountMeta,
|
|
650
|
+
to: AccountMeta,
|
|
651
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
652
|
+
stakeHistorySysvar: AccountMeta | NamedAccount,
|
|
653
|
+
withdrawer: AccountMeta,
|
|
654
|
+
lamports: u64,
|
|
655
|
+
custodian: AccountMeta,
|
|
656
|
+
signerSeeds?: Seed[] | SignerSeeds,
|
|
657
|
+
): void;
|
|
658
|
+
/** Merge `source` into `destination` (same authorities and lockup, compatible states); `source` is drained. */
|
|
659
|
+
merge(
|
|
660
|
+
destination: AccountMeta,
|
|
661
|
+
source: AccountMeta,
|
|
662
|
+
clockSysvar: AccountMeta | NamedAccount,
|
|
663
|
+
stakeHistorySysvar: AccountMeta | NamedAccount,
|
|
664
|
+
staker: AccountMeta,
|
|
665
|
+
signerSeeds?: Seed[] | SignerSeeds,
|
|
666
|
+
): void;
|
|
667
|
+
/**
|
|
668
|
+
* The cluster's minimum delegation in lamports: a GetMinimumDelegation CPI and the u64 the Stake program returns
|
|
669
|
+
* (solana_program's `stake::tools::get_minimum_delegation`, failing as it does: InvalidInstructionData without
|
|
670
|
+
* return data or with another size, IncorrectProgramId when another program returned it).
|
|
671
|
+
*/
|
|
672
|
+
getMinimumDelegation(): u64;
|
|
384
673
|
}
|
|
385
674
|
|
|
386
675
|
/**
|
|
387
676
|
* The StakeHistory sysvar (`SysvarStakeHistory…`), read as an account: the cluster's stake per recent epoch (up to
|
|
388
|
-
* 512, newest first), as the Stake program uses it for warmup and cooldown. The address is checked.
|
|
677
|
+
* 512, newest first), as the Stake program uses it for warmup and cooldown. The address is checked. A remaining
|
|
678
|
+
* account becomes one with `sysvarAt<StakeHistorySysvar>(acct)`.
|
|
389
679
|
*/
|
|
390
680
|
export interface StakeHistorySysvar extends AccountMeta {
|
|
391
681
|
readonly __stake_history: void;
|
|
@@ -418,21 +708,21 @@ export interface SlotHashesSysvar extends AccountMeta {
|
|
|
418
708
|
export interface AssociatedTokenProgram extends AccountMeta {
|
|
419
709
|
readonly __ata_program: void;
|
|
420
710
|
create(
|
|
421
|
-
payer: Mut<Signer
|
|
711
|
+
payer: Mut<Signer> | RemainingAccount,
|
|
422
712
|
ata: AccountMeta,
|
|
423
713
|
owner: AccountMeta,
|
|
424
714
|
mint: AccountMeta,
|
|
425
|
-
systemProgram: SystemProgram,
|
|
426
|
-
tokenProgram: TokenProgram | Token2022Program | TokenInterface,
|
|
715
|
+
systemProgram: SystemProgram | RemainingAccount,
|
|
716
|
+
tokenProgram: TokenProgram | Token2022Program | TokenInterface | RemainingAccount,
|
|
427
717
|
): void;
|
|
428
718
|
/** Like create, but succeeds if the account already exists. */
|
|
429
719
|
createIdempotent(
|
|
430
|
-
payer: Mut<Signer
|
|
720
|
+
payer: Mut<Signer> | RemainingAccount,
|
|
431
721
|
ata: AccountMeta,
|
|
432
722
|
owner: AccountMeta,
|
|
433
723
|
mint: AccountMeta,
|
|
434
|
-
systemProgram: SystemProgram,
|
|
435
|
-
tokenProgram: TokenProgram | Token2022Program | TokenInterface,
|
|
724
|
+
systemProgram: SystemProgram | RemainingAccount,
|
|
725
|
+
tokenProgram: TokenProgram | Token2022Program | TokenInterface | RemainingAccount,
|
|
436
726
|
): void;
|
|
437
727
|
}
|
|
438
728
|
/** The associated token account address of `owner` for `mint` under `tokenProgram`. */
|
|
@@ -574,6 +864,12 @@ export declare function createProgramAddress(seeds: Seed[], program: Pubkey): Pu
|
|
|
574
864
|
export declare function logBase64(prefix: string, value: object): void;
|
|
575
865
|
/** The bump of that canonical program address (`Pubkey::find_program_address(seeds, program).1`), to sign with it. */
|
|
576
866
|
export declare function findProgramAddressBump(seeds: Seed[], program: Pubkey): u8;
|
|
867
|
+
/**
|
|
868
|
+
* The canonical program address and its bump from one search (Rust's `let (address, bump) =
|
|
869
|
+
* Pubkey::find_program_address(seeds, program)`), where `findProgramAddress` and `findProgramAddressBump` would search
|
|
870
|
+
* twice: bind both, `const [address, bump] = findProgramAddressWithBump(["seat", market, trader], PHOENIX_ID)`.
|
|
871
|
+
*/
|
|
872
|
+
export declare function findProgramAddressWithBump(seeds: Seed[], program: Pubkey): [address: Pubkey, bump: u8];
|
|
577
873
|
/** This program's address (`crate::ID`). */
|
|
578
874
|
export declare function programId(): Pubkey;
|
|
579
875
|
/**
|
|
@@ -677,11 +973,30 @@ export declare const AuthorityType: {
|
|
|
677
973
|
*/
|
|
678
974
|
export declare function realloc(account: AccountMeta, newSize: u64, payer: Mut<Signer>): void;
|
|
679
975
|
/**
|
|
680
|
-
* Resize a `Mut<AccountInfo>` of this program to `newSize` bytes (Rust's `AccountInfo::resize`
|
|
681
|
-
* the new bytes zeroed. No rent moves: fund the account first
|
|
682
|
-
* left short. At most 10 KiB past its size when the
|
|
976
|
+
* Resize a `Mut<AccountInfo>` or a remaining account of this program to `newSize` bytes (Rust's `AccountInfo::resize` /
|
|
977
|
+
* `realloc(newSize, true)`): the data length only, the new bytes zeroed. No rent moves: fund the account first
|
|
978
|
+
* (`rentExempt(newSize)`), the runtime refuses an account left short. At most 10 KiB past its size when the
|
|
979
|
+
* instruction started (3016). A remaining account must be writable (3006) unless the program declares
|
|
980
|
+
* `NATIVE_ACCOUNT_WRITES`, which also lets an `AccountInfo` parameter be resized without `Mut<…>`. A view of the
|
|
981
|
+
* account made before (`loadRawMutAt`, `rbTreeMutAt` …) is not used after it: take the view again.
|
|
683
982
|
*/
|
|
684
|
-
export declare function resizeAccount(account: Mut<AccountInfo>, newSize: u64): void;
|
|
983
|
+
export declare function resizeAccount(account: RemainingAccount | Mut<AccountInfo>, newSize: u64): void;
|
|
984
|
+
/**
|
|
985
|
+
* Close an account of this program as a native program does it by hand (Phoenix's Tombstone), in this order:
|
|
986
|
+
* `receiver.lamports += account.lamports`, `account.lamports = 0`, the owner set to the System Program, the data length
|
|
987
|
+
* set to 0 (`realloc(0, false)`: the bytes are not zeroed, the runtime drops them with the length). Unlike `close` it
|
|
988
|
+
* takes remaining accounts and `AccountInfo` parameters and leaves the data unwiped. Both accounts are checked writable
|
|
989
|
+
* (3006; `Mut<AccountInfo>` parameters) and passed once (2040), the account owned by this program (3007) and not the
|
|
990
|
+
* receiver itself; with `NATIVE_ACCOUNT_WRITES` nothing is checked and the runtime judges the result, as for the
|
|
991
|
+
* original. A view of the account made before is not used after it.
|
|
992
|
+
*/
|
|
993
|
+
export declare function closeRaw(account: RemainingAccount | Mut<AccountInfo>, receiver: RemainingAccount | Mut<AccountInfo>): void;
|
|
994
|
+
/**
|
|
995
|
+
* Set an account's owner in place (Rust's `AccountInfo::assign`). The runtime accepts the change, at the end of the
|
|
996
|
+
* instruction or at the next CPI, only for a writable account of this program whose data is empty or zeroed. Checked
|
|
997
|
+
* as `closeRaw` checks its account (writable, passed once, this program's), or not at all under `NATIVE_ACCOUNT_WRITES`.
|
|
998
|
+
*/
|
|
999
|
+
export declare function assignOwner(account: RemainingAccount | Mut<AccountInfo>, owner: Pubkey): void;
|
|
685
1000
|
|
|
686
1001
|
/**
|
|
687
1002
|
* Token-2022 extensions of a mint (any account works; legacy SPL Token mints have none).
|
|
@@ -752,6 +1067,20 @@ export type Account<T> = Readonly<T> & AccountMeta;
|
|
|
752
1067
|
*/
|
|
753
1068
|
export type Mut<T, E = never> = T & AccountMeta;
|
|
754
1069
|
|
|
1070
|
+
/**
|
|
1071
|
+
* A helper parameter the helper may change in place (Rust's `&mut T`): `function addEvent(rec: Inout<Recorder>, e:
|
|
1072
|
+
* Event): void`. The helper gets the caller's place itself, not a copy, and the caller sees its writes after the call,
|
|
1073
|
+
* as JS shares an object passed to a function. `T` is a fixed-size struct, a `FixedArray<T, N>` or a `FixedVec<T, N>`
|
|
1074
|
+
* (whose `push`, `pop` and `clear` the caller sees too). The caller passes a writable place: a local struct or list,
|
|
1075
|
+
* a `loadBorsh` local, a field of a `Mut<T>` account or of a `loadRawMut` view, a list element (`book.levels.get(i)`)
|
|
1076
|
+
* or another `Inout` parameter. Two arguments of one call may not overlap: places that may be the same bytes only at
|
|
1077
|
+
* run time (two `Dup` accounts, a writable and a read-only account, two native views under `NATIVE_ACCOUNT_WRITES`) are
|
|
1078
|
+
* compared before the call, an Inout one with every other argument passed in place (2040 when they overlap). Other
|
|
1079
|
+
* struct parameters stay read-only.
|
|
1080
|
+
* Integers are values in JS too: return the new value, or wrap it in a struct.
|
|
1081
|
+
*/
|
|
1082
|
+
export type Inout<T> = T;
|
|
1083
|
+
|
|
755
1084
|
/** A PDA seed: a string, a Pubkey, a Hash (its 32 bytes), an integer (at its width) or a unit enum value (one byte). */
|
|
756
1085
|
export type Seed = string | Pubkey | Hash | bigint | number;
|
|
757
1086
|
|
|
@@ -1552,6 +1881,28 @@ export declare function firstNormalEpoch(): u64;
|
|
|
1552
1881
|
export declare function firstNormalSlot(): u64;
|
|
1553
1882
|
/** The LastRestartSlot sysvar: the last slot the cluster restarted at (0 if never). */
|
|
1554
1883
|
export declare function lastRestartSlot(): u64;
|
|
1884
|
+
/** The EpochRewards sysvar, as `epochRewards()` reads it: read-only; keep it in a local (`const er = epochRewards()`). */
|
|
1885
|
+
export interface EpochRewards {
|
|
1886
|
+
/** The block height the rewards distribution started at in the current epoch. */
|
|
1887
|
+
readonly distributionStartingBlockHeight: u64;
|
|
1888
|
+
/** How many partitions the distribution has (seeds the partition hasher). */
|
|
1889
|
+
readonly numPartitions: u64;
|
|
1890
|
+
/** The parent blockhash of the epoch's first block (seeds the partition hasher). */
|
|
1891
|
+
readonly parentBlockhash: Hash;
|
|
1892
|
+
/** Sum of delegated stake × credits observed over all delegations. */
|
|
1893
|
+
readonly totalPoints: u128;
|
|
1894
|
+
/** The rewards calculated for the epoch, in lamports. */
|
|
1895
|
+
readonly totalRewards: u64;
|
|
1896
|
+
/** The rewards distributed so far, in lamports. */
|
|
1897
|
+
readonly distributedRewards: u64;
|
|
1898
|
+
/** Whether the rewards period (calculation and distribution) is active: stake accounts are being credited. */
|
|
1899
|
+
readonly active: boolean;
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* The EpochRewards sysvar through the `sol_get_epoch_rewards_sysvar` syscall, Rust's `EpochRewards::get()` (no account
|
|
1903
|
+
* needed). Native programs refuse stake operations while `epochRewards().active`.
|
|
1904
|
+
*/
|
|
1905
|
+
export declare function epochRewards(): EpochRewards;
|
|
1555
1906
|
export type CloseTo<A, Destination extends string> = A & { readonly __closeTo?: Destination };
|
|
1556
1907
|
|
|
1557
1908
|
/** A program-owned account that this instruction creates as a PDA. */
|
|
@@ -1660,47 +2011,61 @@ export interface SystemProgram extends AccountMeta {
|
|
|
1660
2011
|
* Create `account` with `space` bytes owned by `owner`, funded by `payer`. The new account signs: a
|
|
1661
2012
|
* `Mut<Signer>` keypair, or a PDA of this program when you pass its `signerSeeds` (with the bump).
|
|
1662
2013
|
*/
|
|
1663
|
-
createAccount(
|
|
2014
|
+
createAccount(
|
|
2015
|
+
payer: Mut<Signer> | RemainingAccount,
|
|
2016
|
+
account: AccountMeta,
|
|
2017
|
+
lamports: u64,
|
|
2018
|
+
space: u64,
|
|
2019
|
+
owner: Pubkey,
|
|
2020
|
+
signerSeeds?: Seed[] | SignerSeeds,
|
|
2021
|
+
): void;
|
|
1664
2022
|
/**
|
|
1665
2023
|
* Anchor's `init` with `seeds`, `space` and `owner = …` on an `UncheckedAccount`: `account` must be the PDA of this
|
|
1666
2024
|
* program for `seeds` (no bump; 2006 otherwise); it is created with `space` bytes owned by `owner`, or, when someone
|
|
1667
2025
|
* already funded the address, topped up to rent, allocated and assigned. Returns the bump. Among the creates a body
|
|
1668
2026
|
* starts with, it runs before the other accounts' constraints, as Anchor's `init` does.
|
|
1669
2027
|
*/
|
|
1670
|
-
createPda(payer: Mut<Signer
|
|
2028
|
+
createPda(payer: Mut<Signer> | RemainingAccount, account: Mut<AccountInfo> | RemainingAccount, space: u64, owner: Pubkey, seeds: Seed[]): u8;
|
|
1671
2029
|
/** System Allocate: give `account` `space` bytes of data. It signs: a keypair, or a PDA of this program with `signerSeeds`. */
|
|
1672
2030
|
allocate(account: AccountMeta, space: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1673
2031
|
/** System Assign: make `owner` the account's owner. It signs: a keypair, or a PDA of this program with `signerSeeds`. */
|
|
1674
2032
|
assign(account: AccountMeta, owner: Pubkey, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1675
2033
|
}
|
|
1676
2034
|
|
|
2035
|
+
/**
|
|
2036
|
+
* A token account or mint argument of a token CPI: a `TokenAccount` / `Mint` parameter (checked on entry), an
|
|
2037
|
+
* `AccountInfo` parameter, or a remaining account (the token program checks those).
|
|
2038
|
+
*/
|
|
2039
|
+
type TokenAccountArg = TokenAccount | AccountInfo | RemainingAccount;
|
|
2040
|
+
type MintArg = Mint | AccountInfo | RemainingAccount;
|
|
2041
|
+
|
|
1677
2042
|
/**
|
|
1678
2043
|
* Token program operations. Pass `signerSeeds` (including the bump) when `authority` is a PDA of this program.
|
|
1679
2044
|
* Prefer transferChecked: Token-2022 mints with extensions (transfer fees, hooks) require it.
|
|
1680
2045
|
*/
|
|
1681
2046
|
interface TokenOps {
|
|
1682
|
-
transfer(from:
|
|
1683
|
-
transferChecked(from:
|
|
2047
|
+
transfer(from: TokenAccountArg, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2048
|
+
transferChecked(from: TokenAccountArg, mint: MintArg, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1684
2049
|
/** `mint`: a Mut<Mint>, or a mint this instruction created and initialized (Mut<Signer> / Mut<AccountInfo>). */
|
|
1685
2050
|
/** `to`: a Mut<TokenAccount>, or a Mut<AccountInfo> token account this instruction created (e.g. with `ata.create`). */
|
|
1686
|
-
mintTo(mint:
|
|
1687
|
-
burn(from:
|
|
2051
|
+
mintTo(mint: MintArg | AccountMeta, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2052
|
+
burn(from: TokenAccountArg, mint: MintArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1688
2053
|
/** Close a token account (empty), or under Token-2022 a mint with no supply left (its MintCloseAuthority signs). */
|
|
1689
|
-
closeAccount(account:
|
|
2054
|
+
closeAccount(account: TokenAccountArg | MintArg, destination: AccountMeta, authority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1690
2055
|
/** Let `delegate` move up to `amount` from `source`. */
|
|
1691
|
-
approve(source:
|
|
1692
|
-
revoke(source:
|
|
2056
|
+
approve(source: TokenAccountArg, delegate: AccountMeta, owner: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2057
|
+
revoke(source: TokenAccountArg, owner: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1693
2058
|
/** The checked forms read the decimals from `mint`; Token-2022 mints with some extensions require them. */
|
|
1694
|
-
approveChecked(source:
|
|
1695
|
-
mintToChecked(mint:
|
|
1696
|
-
burnChecked(from:
|
|
2059
|
+
approveChecked(source: TokenAccountArg, mint: MintArg, delegate: AccountMeta, owner: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2060
|
+
mintToChecked(mint: MintArg, to: TokenAccountArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2061
|
+
burnChecked(from: TokenAccountArg, mint: MintArg, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1697
2062
|
/** Change or remove (null) an authority of a mint or token account: `AuthorityType.MintTokens`, …. */
|
|
1698
2063
|
setAuthority(target: AccountMeta, currentAuthority: AccountMeta, authorityType: u8, newAuthority: Pubkey | null, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1699
2064
|
/** `account`: a Mut<TokenAccount>, or (freezeAccount) a Mut<AccountInfo> token account this instruction created. */
|
|
1700
|
-
freezeAccount(account:
|
|
1701
|
-
thawAccount(account:
|
|
2065
|
+
freezeAccount(account: TokenAccountArg, mint: AccountMeta, freezeAuthority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
2066
|
+
thawAccount(account: TokenAccountArg, mint: AccountMeta, freezeAuthority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1702
2067
|
/** Update a wrapped-SOL account's amount after lamports were sent to it. */
|
|
1703
|
-
syncNative(account:
|
|
2068
|
+
syncNative(account: TokenAccountArg): void;
|
|
1704
2069
|
/** Initialize a mint created with systemProgram.createAccount (InitializeMint2: no rent sysvar needed). */
|
|
1705
2070
|
initializeMint2(mint: AccountMeta, decimals: u8, mintAuthority: Pubkey, freezeAuthority: Pubkey | null): void;
|
|
1706
2071
|
/** Initialize a token account created with systemProgram.createAccount (InitializeAccount3). */
|
|
@@ -1781,9 +2146,9 @@ interface Token2022Ops {
|
|
|
1781
2146
|
updateInterestRate(mint: AccountMeta, rateAuthority: AccountMeta, rate: i16, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1782
2147
|
/** TransferFee TransferCheckedWithFee: `fee` must be the fee Token-2022 computes for `amount`; decimals are the mint's. */
|
|
1783
2148
|
transferCheckedWithFee(
|
|
1784
|
-
from:
|
|
1785
|
-
mint:
|
|
1786
|
-
to:
|
|
2149
|
+
from: TokenAccountArg,
|
|
2150
|
+
mint: MintArg,
|
|
2151
|
+
to: TokenAccountArg,
|
|
1787
2152
|
authority: AccountMeta,
|
|
1788
2153
|
amount: u64,
|
|
1789
2154
|
fee: u64,
|
|
@@ -1792,7 +2157,7 @@ interface Token2022Ops {
|
|
|
1792
2157
|
/** TransferFee HarvestWithheldTokensToMint: move withheld fees from the given token accounts (passed on writable as they were passed) to the mint. */
|
|
1793
2158
|
harvestWithheldTokensToMint(mint: AccountMeta, sources: RemainingAccounts | RemainingSlice): void;
|
|
1794
2159
|
/** TransferFee WithdrawWithheldTokensFromMint: the fees held by the mint to `destination`. */
|
|
1795
|
-
withdrawWithheldTokensFromMint(mint: AccountMeta, destination:
|
|
2160
|
+
withdrawWithheldTokensFromMint(mint: AccountMeta, destination: TokenAccountArg, withdrawAuthority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1796
2161
|
/** TransferFee SetTransferFee: takes effect two epochs later. */
|
|
1797
2162
|
setTransferFee(mint: AccountMeta, configAuthority: AccountMeta, basisPoints: u16, maximumFee: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1798
2163
|
|
|
@@ -2051,9 +2416,31 @@ export declare enum ProgramError {
|
|
|
2051
2416
|
* Stop the program as a Rust `panic!` / `unwrap()` on `None` / `unreachable!()` does: the message is logged and the
|
|
2052
2417
|
* instruction fails with ProgramFailedToComplete (no error code). For porting native programs whose failures panic:
|
|
2053
2418
|
* `location` ("program/src/instruction.rs:482:17") is the place the runtime reports, as the original's panic gives it;
|
|
2054
|
-
* by default this source line.
|
|
2419
|
+
* by default this source line. A `null` message logs nothing, for a program whose panic handler writes no line of its
|
|
2420
|
+
* own: `panic(null, "src/lib.rs:105:19")` leaves only the runtime's "SBF program Panicked in src/lib.rs at 105:19".
|
|
2421
|
+
* Under `export const PANIC_STYLE = "solana-1.14"` (a program built with solana-program 1.14 to 1.17) it logs
|
|
2422
|
+
* `panicked at '<message>', <location>` and aborts, so the runtime reports "SBF program panicked", as that panic
|
|
2423
|
+
* handler does; a message is then required.
|
|
2055
2424
|
*/
|
|
2056
|
-
export declare function panic(message?: string, location?: string): never;
|
|
2425
|
+
export declare function panic(message?: string | null, location?: string): never;
|
|
2426
|
+
/**
|
|
2427
|
+
* `value`, with its checked arithmetic panicking as Rust's overflow checks do at `location` ("file:line:column", where
|
|
2428
|
+
* the original's expression is): `panicsAt("src/quantities.rs:233:1", a + b)` logs "attempt to add with overflow"
|
|
2429
|
+
* there (also "attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the
|
|
2430
|
+
* remainder with a divisor of zero", "attempt to negate with overflow", "attempt to divide with overflow", "attempt to
|
|
2431
|
+
* shift left / right with overflow" for a shift amount past the width), as `panic` logs (see `PANIC_STYLE`), instead
|
|
2432
|
+
* of failing with 5100 / 5101. Only the operators written inside it, not the helpers it calls; u256 arithmetic, `**`,
|
|
2433
|
+
* `mulDiv`, casts and the bits `<<` loses keep TypeSOL's failures (Rust checks them otherwise, or with other messages); an inner `panicsAt`
|
|
2434
|
+
* gives its own operators their own location. As a statement it takes an assignment: `panicsAt(loc, total += fee);`.
|
|
2435
|
+
*/
|
|
2436
|
+
export declare function panicsAt<T>(location: string, value: T): T;
|
|
2437
|
+
/**
|
|
2438
|
+
* Stop the program as Rust's `abort` does on SBF (the allocator's out-of-memory error, `std::process::abort`): the
|
|
2439
|
+
* runtime's `abort` syscall, which fails the instruction with ProgramFailedToComplete and logs "SBF program panicked"
|
|
2440
|
+
* (no location, nothing else). Log the original's own line first where it writes one:
|
|
2441
|
+
* `log("Error: memory allocation failed, out of memory"); abort();`.
|
|
2442
|
+
*/
|
|
2443
|
+
export declare function abort(): never;
|
|
2057
2444
|
/**
|
|
2058
2445
|
* Anchor's `constraint = condition @ error` on `account`. Written at the start of an instruction's body (before any
|
|
2059
2446
|
* other statement), it runs with that account's checks, after its has_one and before its owner check, so a transaction
|
|
@@ -2069,8 +2456,22 @@ export declare function constraint(account: AccountMeta | RemainingAccount | nul
|
|
|
2069
2456
|
*/
|
|
2070
2457
|
export declare function instructionData(): InstructionBytes;
|
|
2071
2458
|
|
|
2072
|
-
/**
|
|
2073
|
-
|
|
2459
|
+
/**
|
|
2460
|
+
* The instruction data, read in place: its bytes, and little-endian values at a byte offset. A list of u8 like any other
|
|
2461
|
+
* (`for (const b of data)`, `map` / `filter` / `reduce` / `some` …), read-only; a helper takes it (or a slice) as an
|
|
2462
|
+
* `InstructionBytes` parameter.
|
|
2463
|
+
*/
|
|
2464
|
+
export interface InstructionBytes extends IndexedList<u8>, ListMethods<u8> {
|
|
2465
|
+
readonly length: u64;
|
|
2466
|
+
/** The byte at `index` (5104 past the end). */
|
|
2467
|
+
get(index: bigint): u8;
|
|
2468
|
+
/**
|
|
2469
|
+
* Bytes `start` to `end - 1` in place, a view with the same methods (nothing is copied). Unlike JS's slice it does
|
|
2470
|
+
* not clamp: `end` past the length or before `start` fails the instruction (5104). `end` defaults to the length.
|
|
2471
|
+
* Copy one into a local list with `out.pushAll(data.slice(a, b))`.
|
|
2472
|
+
*/
|
|
2473
|
+
slice(start: bigint, end?: bigint): InstructionBytes;
|
|
2474
|
+
[Symbol.iterator](): Iterator<u8>;
|
|
2074
2475
|
/** The little-endian value at `offset`; reading past the end fails the instruction (5104). */
|
|
2075
2476
|
readU8(offset: u64): u8;
|
|
2076
2477
|
readU16(offset: u64): u16;
|
|
@@ -2098,6 +2499,23 @@ export declare function emit<T>(event: T): void;
|
|
|
2098
2499
|
*/
|
|
2099
2500
|
export declare function returnData<T extends bigint | boolean | Pubkey | Hash | object>(program: AccountMeta): T;
|
|
2100
2501
|
|
|
2502
|
+
/**
|
|
2503
|
+
* Set this instruction's return data to `bytes` as they are (Rust's `set_return_data(&bytes)`): a list of u8 such as a
|
|
2504
|
+
* local `FixedVec<u8, N>`, a Vec or FixedVec in account data, or the instruction data or a slice of it. For a native
|
|
2505
|
+
* port's `@fallback` entry and helpers (`set_return_data(order_ids.try_to_vec()?.as_ref())`), and void instructions.
|
|
2506
|
+
* The last call wins, and a CPI made afterwards replaces it with the callee's (call it after the last CPI, as Rust
|
|
2507
|
+
* must). More than 1024 bytes fails as Rust's call does: the runtime refuses it ("Return data too large").
|
|
2508
|
+
* An instruction that returns a value cannot call it (its return value is its return data); a helper it calls may, and
|
|
2509
|
+
* the instruction's return value, set last, replaces what the helper set.
|
|
2510
|
+
*/
|
|
2511
|
+
export declare function setReturnData(bytes: IndexedList<u8>): void;
|
|
2512
|
+
|
|
2513
|
+
/**
|
|
2514
|
+
* Log the compute units left (Rust's `sol_log_compute_units()`): the runtime writes "Program consumption: <N> units
|
|
2515
|
+
* remaining", as the original's line, at the same place.
|
|
2516
|
+
*/
|
|
2517
|
+
export declare function logComputeUnits(): void;
|
|
2518
|
+
|
|
2101
2519
|
/**
|
|
2102
2520
|
* Verify `account.key` is the PDA for `seeds` + `bump` under this program. Any bump that gives a PDA passes (Anchor's
|
|
2103
2521
|
* `bump = expr`): use a stored bump, not one from the arguments, or the caller picks among up to 256 addresses.
|