@typesol/cli 0.36.0 → 0.38.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 +53 -0
- package/README.md +8 -1
- package/dist/compiler/analyze.d.ts +6 -0
- package/dist/compiler/analyze.js +47 -8
- package/dist/compiler/emit/calls.js +40 -6
- package/dist/compiler/emit/cpi-core.js +24 -2
- package/dist/compiler/emit/expressions.d.ts +2 -0
- package/dist/compiler/emit/expressions.js +90 -1
- package/dist/compiler/emit/function.js +31 -7
- package/dist/compiler/emit/program.js +1 -1
- package/dist/compiler/emit/shared.d.ts +6 -0
- package/dist/compiler/emit/shared.js +4 -0
- package/dist/compiler/emit/statements.js +27 -1
- package/dist/compiler/emit/token.js +8 -5
- package/dist/compiler/idl.d.ts +1 -1
- package/dist/compiler/idl.js +7 -3
- package/dist/compiler/model.d.ts +1 -1
- package/dist/compiler/model.js +3 -1
- package/docs/case-study-jito-mev.md +167 -0
- package/docs/case-study-raydium-clmm.md +215 -0
- package/docs/errors.md +3 -0
- package/docs/language.md +10 -6
- package/docs/migrate-from-anchor.md +1 -1
- package/lib/typesol.d.ts +25 -7
- package/package.json +1 -1
- package/runtime/typesol_rt.h +225 -0
package/lib/typesol.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export type u16 = bigint;
|
|
|
19
19
|
export type u32 = bigint;
|
|
20
20
|
export type u64 = bigint;
|
|
21
21
|
export type u128 = bigint;
|
|
22
|
+
/**
|
|
23
|
+
* 256-bit unsigned integers for computation (sqrt-price and liquidity math): locals, helper parameters and results,
|
|
24
|
+
* `u256(x)` and back with `u128(x)` / `u64(x)` (checked). Not in account data, arguments, events or return data
|
|
25
|
+
* (the IDL has no 256-bit integer).
|
|
26
|
+
*/
|
|
27
|
+
export type u256 = bigint;
|
|
22
28
|
export type i8 = bigint;
|
|
23
29
|
export type i16 = bigint;
|
|
24
30
|
export type i32 = bigint;
|
|
@@ -168,17 +174,21 @@ export interface RemainingSlice extends Iterable<CpiAccount> {
|
|
|
168
174
|
export declare function remainingAccounts(): RemainingAccounts;
|
|
169
175
|
|
|
170
176
|
/**
|
|
171
|
-
* Read a struct of this program from a remaining account
|
|
177
|
+
* Read a struct of this program from a remaining account or an `AccountInfo` parameter (Anchor's
|
|
178
|
+
* `AccountLoader::try_from` on an `UncheckedAccount`): owner, discriminator and size are checked.
|
|
172
179
|
* `loadAccountMut` also requires it to be writable, not aliased by another writable account, and not already loaded
|
|
173
|
-
* with `loadAccountMut` in this instruction (2040).
|
|
180
|
+
* with `loadAccountMut` in this instruction (2040). The result is also the account (`.key`, `.lamports`), and passes
|
|
181
|
+
* to a helper that takes `Account<T>` / `Mut<T>`.
|
|
174
182
|
*/
|
|
175
|
-
export declare function loadAccount<T>(account: RemainingAccount):
|
|
176
|
-
export declare function loadAccountMut<T>(account: RemainingAccount): T
|
|
183
|
+
export declare function loadAccount<T>(account: RemainingAccount | AccountInfo): Account<T>;
|
|
184
|
+
export declare function loadAccountMut<T>(account: RemainingAccount | AccountInfo): Mut<T>;
|
|
177
185
|
|
|
178
186
|
/** 32 bytes of hash output (sha256 / keccak256, Merkle roots). Compare with `===`. */
|
|
179
187
|
export interface Hash {
|
|
180
188
|
readonly __hash: unique symbol;
|
|
181
189
|
equals(other: Hash): boolean;
|
|
190
|
+
/** The order of the 32 bytes (lexicographic): -1, 0 or 1, as Rust compares `[u8; 32]`. */
|
|
191
|
+
compare(other: Hash): i64;
|
|
182
192
|
}
|
|
183
193
|
|
|
184
194
|
/** sha256 over the parts concatenated: strings (UTF-8), Pubkeys/Hashes (32 bytes), integers (LE), booleans (1 byte). */
|
|
@@ -535,6 +545,11 @@ export interface TokenMetadataProgram extends AccountMeta {
|
|
|
535
545
|
/** The Metaplex master edition address of a mint (PDA ["metadata", program, mint, "edition"]). */
|
|
536
546
|
export declare function masterEditionAddress(mint: Pubkey): Pubkey;
|
|
537
547
|
/** The canonical program address of `seeds` under `program` (Rust `Pubkey::find_program_address(seeds, program).0`). */
|
|
548
|
+
/**
|
|
549
|
+
* An integer seed with its bytes most significant first (Rust's `x.to_be_bytes()`), inside a seeds list:
|
|
550
|
+
* `["tick_array", pool.key, bigEndian(startIndex)]`. In `Seeds<…>` write `"@startIndex:be"`.
|
|
551
|
+
*/
|
|
552
|
+
export declare function bigEndian(value: bigint): Seed;
|
|
538
553
|
export declare function findProgramAddress(seeds: Seed[], program: Pubkey): Pubkey;
|
|
539
554
|
/** The bump of that canonical program address (`Pubkey::find_program_address(seeds, program).1`), to sign with it. */
|
|
540
555
|
export declare function findProgramAddressBump(seeds: Seed[], program: Pubkey): u8;
|
|
@@ -1631,7 +1646,8 @@ interface TokenOps {
|
|
|
1631
1646
|
transfer(from: TokenAccount, to: TokenAccount, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1632
1647
|
transferChecked(from: TokenAccount, mint: Mint, to: TokenAccount, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1633
1648
|
/** `mint`: a Mut<Mint>, or a mint this instruction created and initialized (Mut<Signer> / Mut<AccountInfo>). */
|
|
1634
|
-
|
|
1649
|
+
/** `to`: a Mut<TokenAccount>, or a Mut<AccountInfo> token account this instruction created (e.g. with `ata.create`). */
|
|
1650
|
+
mintTo(mint: Mint | AccountMeta, to: TokenAccount | AccountInfo, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1635
1651
|
burn(from: TokenAccount, mint: Mint, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1636
1652
|
/** Close a token account (empty), or under Token-2022 a mint with no supply left (its MintCloseAuthority signs). */
|
|
1637
1653
|
closeAccount(account: TokenAccount | Mint, destination: AccountMeta, authority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
@@ -1644,7 +1660,8 @@ interface TokenOps {
|
|
|
1644
1660
|
burnChecked(from: TokenAccount, mint: Mint, authority: AccountMeta, amount: u64, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1645
1661
|
/** Change or remove (null) an authority of a mint or token account: `AuthorityType.MintTokens`, …. */
|
|
1646
1662
|
setAuthority(target: AccountMeta, currentAuthority: AccountMeta, authorityType: u8, newAuthority: Pubkey | null, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1647
|
-
|
|
1663
|
+
/** `account`: a Mut<TokenAccount>, or (freezeAccount) a Mut<AccountInfo> token account this instruction created. */
|
|
1664
|
+
freezeAccount(account: TokenAccount | AccountInfo, mint: AccountMeta, freezeAuthority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1648
1665
|
thawAccount(account: TokenAccount, mint: AccountMeta, freezeAuthority: AccountMeta, signerSeeds?: Seed[] | SignerSeeds): void;
|
|
1649
1666
|
/** Update a wrapped-SOL account's amount after lamports were sent to it. */
|
|
1650
1667
|
syncNative(account: TokenAccount): void;
|
|
@@ -2009,12 +2026,13 @@ export declare function u32(value: bigint): u32;
|
|
|
2009
2026
|
export declare function u64(value: bigint): u64;
|
|
2010
2027
|
export declare function i64(value: bigint): i64;
|
|
2011
2028
|
export declare function u128(value: bigint): u128;
|
|
2029
|
+
export declare function u256(value: bigint): u256;
|
|
2012
2030
|
export declare function i8(value: bigint): i8;
|
|
2013
2031
|
export declare function i16(value: bigint): i16;
|
|
2014
2032
|
export declare function i32(value: bigint): i32;
|
|
2015
2033
|
export declare function i128(value: bigint): i128;
|
|
2016
2034
|
|
|
2017
|
-
/** floor(a * b / c) with a double-width intermediate (all u64, or all
|
|
2035
|
+
/** floor(a * b / c) with a double-width intermediate (all u64, all u128, or all u256); aborts if c is 0 or the result does not fit. */
|
|
2018
2036
|
export declare function mulDiv(a: u64, b: u64, c: u64): u64;
|
|
2019
2037
|
/** ceil(a * b / c), like mulDiv. */
|
|
2020
2038
|
export declare function mulDivCeil(a: u64, b: u64, c: u64): u64;
|
package/package.json
CHANGED
package/runtime/typesol_rt.h
CHANGED
|
@@ -186,6 +186,219 @@ static inline __attribute__((always_inline)) unsigned __int128 ts_rem_u128(unsig
|
|
|
186
186
|
return a % b;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/*
|
|
190
|
+
* u256: a computation type (locals, helper parameters and results; never stored), for math such as concentrated
|
|
191
|
+
* liquidity's sqrt-price formulas. Four little-endian 64-bit limbs. Additions, subtractions and comparisons work on
|
|
192
|
+
* the 64-bit limbs; multiplication and division on 32-bit limbs with 64-bit products (SBF has no 128-bit instructions,
|
|
193
|
+
* and the __int128 library routines cost hundreds of CU each). Division is Knuth's algorithm D, as Hacker's Delight
|
|
194
|
+
* writes it (divmnu), also used for mulDiv's 512-bit intermediate.
|
|
195
|
+
*/
|
|
196
|
+
typedef struct {
|
|
197
|
+
uint64_t w[4];
|
|
198
|
+
} TsU256;
|
|
199
|
+
|
|
200
|
+
static inline TsU256 ts_u256_lit(uint64_t a, uint64_t b, uint64_t c, uint64_t d) {
|
|
201
|
+
TsU256 r = {{a, b, c, d}};
|
|
202
|
+
return r;
|
|
203
|
+
}
|
|
204
|
+
static inline TsU256 ts_u256_from_u128(unsigned __int128 v) { return ts_u256_lit((uint64_t)v, (uint64_t)(v >> 64), 0, 0); }
|
|
205
|
+
static inline bool ts_u256_is_zero(TsU256 a) { return (a.w[0] | a.w[1] | a.w[2] | a.w[3]) == 0; }
|
|
206
|
+
static inline int ts_u256_cmp(TsU256 a, TsU256 b) {
|
|
207
|
+
for (int i = 3; i >= 0; i--)
|
|
208
|
+
if (a.w[i] != b.w[i]) return a.w[i] < b.w[i] ? -1 : 1;
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
/* Whether the value fits in `bits` (64 or 128) bits. */
|
|
212
|
+
static inline bool ts_u256_fits(TsU256 a, int bits) { return bits >= 128 ? (a.w[2] | a.w[3]) == 0 : (a.w[1] | a.w[2] | a.w[3]) == 0; }
|
|
213
|
+
static inline unsigned __int128 ts_u256_lo128(TsU256 a) { return ((unsigned __int128)a.w[1] << 64) | a.w[0]; }
|
|
214
|
+
|
|
215
|
+
static inline bool ts_u256_add(TsU256 a, TsU256 b, TsU256 *out) {
|
|
216
|
+
uint64_t carry = 0;
|
|
217
|
+
for (int i = 0; i < 4; i++) {
|
|
218
|
+
uint64_t s = a.w[i] + b.w[i];
|
|
219
|
+
uint64_t c1 = s < a.w[i];
|
|
220
|
+
uint64_t s2 = s + carry;
|
|
221
|
+
carry = c1 | (s2 < s);
|
|
222
|
+
out->w[i] = s2;
|
|
223
|
+
}
|
|
224
|
+
return carry != 0;
|
|
225
|
+
}
|
|
226
|
+
static inline bool ts_u256_sub(TsU256 a, TsU256 b, TsU256 *out) {
|
|
227
|
+
uint64_t borrow = 0;
|
|
228
|
+
for (int i = 0; i < 4; i++) {
|
|
229
|
+
uint64_t d = a.w[i] - b.w[i];
|
|
230
|
+
uint64_t b1 = a.w[i] < b.w[i];
|
|
231
|
+
uint64_t d2 = d - borrow;
|
|
232
|
+
borrow = b1 | (d < borrow);
|
|
233
|
+
out->w[i] = d2;
|
|
234
|
+
}
|
|
235
|
+
return borrow != 0;
|
|
236
|
+
}
|
|
237
|
+
static inline TsU256 ts_u256_bit(TsU256 a, TsU256 b, int op) {
|
|
238
|
+
TsU256 r;
|
|
239
|
+
for (int i = 0; i < 4; i++) r.w[i] = op == 0 ? a.w[i] & b.w[i] : op == 1 ? a.w[i] | b.w[i] : a.w[i] ^ b.w[i];
|
|
240
|
+
return r;
|
|
241
|
+
}
|
|
242
|
+
static inline TsU256 ts_u256_shl(TsU256 a, uint64_t s) {
|
|
243
|
+
TsU256 r = {{0, 0, 0, 0}};
|
|
244
|
+
int limbs = (int)(s / 64), bits = (int)(s % 64);
|
|
245
|
+
for (int i = 3; i >= limbs; i--) {
|
|
246
|
+
r.w[i] = a.w[i - limbs] << bits;
|
|
247
|
+
if (bits && i - limbs - 1 >= 0) r.w[i] |= a.w[i - limbs - 1] >> (64 - bits);
|
|
248
|
+
}
|
|
249
|
+
return r;
|
|
250
|
+
}
|
|
251
|
+
static inline TsU256 ts_u256_shr(TsU256 a, uint64_t s) {
|
|
252
|
+
TsU256 r = {{0, 0, 0, 0}};
|
|
253
|
+
int limbs = (int)(s / 64), bits = (int)(s % 64);
|
|
254
|
+
for (int i = 0; i + limbs < 4; i++) {
|
|
255
|
+
r.w[i] = a.w[i + limbs] >> bits;
|
|
256
|
+
if (bits && i + limbs + 1 < 4) r.w[i] |= a.w[i + limbs + 1] << (64 - bits);
|
|
257
|
+
}
|
|
258
|
+
return r;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
static inline void ts_u256_to32(TsU256 a, uint32_t *x) {
|
|
262
|
+
for (int i = 0; i < 4; i++) {
|
|
263
|
+
x[2 * i] = (uint32_t)a.w[i];
|
|
264
|
+
x[2 * i + 1] = (uint32_t)(a.w[i] >> 32);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
static inline TsU256 ts_u256_from32(const uint32_t *x) {
|
|
268
|
+
TsU256 r;
|
|
269
|
+
for (int i = 0; i < 4; i++) r.w[i] = (uint64_t)x[2 * i] | ((uint64_t)x[2 * i + 1] << 32);
|
|
270
|
+
return r;
|
|
271
|
+
}
|
|
272
|
+
/* r[0 .. n+m) = a[0 .. n) * b[0 .. m), 32-bit limbs. */
|
|
273
|
+
static __attribute__((noinline)) void ts_mul32(const uint32_t *a, int n, const uint32_t *b, int m, uint32_t *r) {
|
|
274
|
+
for (int i = 0; i < n + m; i++) r[i] = 0;
|
|
275
|
+
for (int j = 0; j < m; j++) {
|
|
276
|
+
uint64_t k = 0;
|
|
277
|
+
for (int i = 0; i < n; i++) {
|
|
278
|
+
uint64_t t = (uint64_t)a[i] * b[j] + r[i + j] + k;
|
|
279
|
+
r[i + j] = (uint32_t)t;
|
|
280
|
+
k = t >> 32;
|
|
281
|
+
}
|
|
282
|
+
r[j + n] = (uint32_t)k;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/*
|
|
286
|
+
* Knuth's algorithm D (Hacker's Delight, divmnu): q[0 .. m-n] = u / v and r[0 .. n) = u % v for an m-limb u and an
|
|
287
|
+
* n-limb v whose top limb is not zero, m >= n, 32-bit limbs, m <= 16.
|
|
288
|
+
*/
|
|
289
|
+
static __attribute__((noinline)) void ts_divmnu(uint32_t *q, uint32_t *r, const uint32_t *u, const uint32_t *v, int m, int n) {
|
|
290
|
+
const uint64_t b = 4294967296ULL;
|
|
291
|
+
if (n == 1) {
|
|
292
|
+
uint64_t k = 0;
|
|
293
|
+
for (int j = m - 1; j >= 0; j--) {
|
|
294
|
+
uint64_t cur = (k << 32) | u[j];
|
|
295
|
+
q[j] = (uint32_t)(cur / v[0]);
|
|
296
|
+
k = cur - (uint64_t)q[j] * v[0];
|
|
297
|
+
}
|
|
298
|
+
r[0] = (uint32_t)k;
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
uint32_t vn[8], un[17];
|
|
302
|
+
int s = __builtin_clz(v[n - 1]);
|
|
303
|
+
for (int i = n - 1; i > 0; i--) vn[i] = (v[i] << s) | (s ? v[i - 1] >> (32 - s) : 0);
|
|
304
|
+
vn[0] = v[0] << s;
|
|
305
|
+
un[m] = s ? u[m - 1] >> (32 - s) : 0;
|
|
306
|
+
for (int i = m - 1; i > 0; i--) un[i] = (u[i] << s) | (s ? u[i - 1] >> (32 - s) : 0);
|
|
307
|
+
un[0] = u[0] << s;
|
|
308
|
+
for (int j = m - n; j >= 0; j--) {
|
|
309
|
+
uint64_t num = ((uint64_t)un[j + n] << 32) | un[j + n - 1];
|
|
310
|
+
uint64_t qhat = num / vn[n - 1];
|
|
311
|
+
uint64_t rhat = num - qhat * vn[n - 1];
|
|
312
|
+
while (qhat >= b || qhat * vn[n - 2] > ((rhat << 32) | un[j + n - 2])) {
|
|
313
|
+
qhat--;
|
|
314
|
+
rhat += vn[n - 1];
|
|
315
|
+
if (rhat >= b) break;
|
|
316
|
+
}
|
|
317
|
+
int64_t t;
|
|
318
|
+
int64_t k = 0;
|
|
319
|
+
for (int i = 0; i < n; i++) {
|
|
320
|
+
uint64_t p = qhat * vn[i];
|
|
321
|
+
t = (int64_t)un[i + j] - k - (int64_t)(p & 0xFFFFFFFFULL);
|
|
322
|
+
un[i + j] = (uint32_t)t;
|
|
323
|
+
k = (int64_t)(p >> 32) - (t >> 32);
|
|
324
|
+
}
|
|
325
|
+
t = (int64_t)un[j + n] - k;
|
|
326
|
+
un[j + n] = (uint32_t)t;
|
|
327
|
+
q[j] = (uint32_t)qhat;
|
|
328
|
+
if (t < 0) {
|
|
329
|
+
q[j]--;
|
|
330
|
+
uint64_t c = 0;
|
|
331
|
+
for (int i = 0; i < n; i++) {
|
|
332
|
+
uint64_t sum = (uint64_t)un[i + j] + vn[i] + c;
|
|
333
|
+
un[i + j] = (uint32_t)sum;
|
|
334
|
+
c = sum >> 32;
|
|
335
|
+
}
|
|
336
|
+
un[j + n] += (uint32_t)c;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
for (int i = 0; i < n; i++) r[i] = (un[i] >> s) | (s ? un[i + 1] << (32 - s) : 0);
|
|
340
|
+
}
|
|
341
|
+
static inline int ts_len32(const uint32_t *x, int n) {
|
|
342
|
+
while (n > 0 && x[n - 1] == 0) n--;
|
|
343
|
+
return n;
|
|
344
|
+
}
|
|
345
|
+
/* u / v (div) or u % v (!div), for an m-limb u (up to 16 limbs) and a 256-bit v, not zero. */
|
|
346
|
+
static __attribute__((noinline)) void ts_divmod32(const uint32_t *u, int mmax, TsU256 v, uint32_t *q, TsU256 *rem) {
|
|
347
|
+
uint32_t vv[8], r[8] = {0};
|
|
348
|
+
ts_u256_to32(v, vv);
|
|
349
|
+
int n = ts_len32(vv, 8), m = ts_len32(u, mmax);
|
|
350
|
+
for (int i = 0; i < mmax; i++) q[i] = 0;
|
|
351
|
+
if (m < n) {
|
|
352
|
+
for (int i = 0; i < 8 && i < mmax; i++) r[i] = u[i];
|
|
353
|
+
} else {
|
|
354
|
+
ts_divmnu(q, r, u, vv, m, n);
|
|
355
|
+
}
|
|
356
|
+
if (rem) *rem = ts_u256_from32(r);
|
|
357
|
+
}
|
|
358
|
+
static inline bool ts_u256_mul(TsU256 a, TsU256 b, TsU256 *out) {
|
|
359
|
+
if (ts_u256_fits(a, 128) && ts_u256_fits(b, 128) && ((a.w[1] | b.w[1]) == 0)) {
|
|
360
|
+
*out = ts_u256_from_u128((unsigned __int128)a.w[0] * b.w[0]);
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
uint32_t x[8], y[8], r[16];
|
|
364
|
+
ts_u256_to32(a, x);
|
|
365
|
+
ts_u256_to32(b, y);
|
|
366
|
+
ts_mul32(x, 8, y, 8, r);
|
|
367
|
+
*out = ts_u256_from32(r);
|
|
368
|
+
for (int i = 8; i < 16; i++)
|
|
369
|
+
if (r[i]) return true;
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
static inline TsU256 ts_u256_divmod(TsU256 a, TsU256 b, bool div) {
|
|
373
|
+
if (ts_u256_fits(a, 128) && ts_u256_fits(b, 128)) {
|
|
374
|
+
unsigned __int128 x = ts_u256_lo128(a), y = ts_u256_lo128(b);
|
|
375
|
+
return ts_u256_from_u128(div ? ts_div_u128(x, y) : ts_rem_u128(x, y));
|
|
376
|
+
}
|
|
377
|
+
uint32_t u[8], q[8];
|
|
378
|
+
TsU256 rem;
|
|
379
|
+
ts_u256_to32(a, u);
|
|
380
|
+
ts_divmod32(u, 8, b, q, &rem);
|
|
381
|
+
return div ? ts_u256_from32(q) : rem;
|
|
382
|
+
}
|
|
383
|
+
/* floor or ceil(a * b / c) with a 512-bit product; false when c is zero or the result needs more than 256 bits. */
|
|
384
|
+
static __attribute__((noinline)) bool ts_u256_muldiv(TsU256 a, TsU256 b, TsU256 c, bool ceil, TsU256 *out) {
|
|
385
|
+
if (ts_u256_is_zero(c)) return false;
|
|
386
|
+
uint32_t x[8], y[8], p[16], q[16];
|
|
387
|
+
ts_u256_to32(a, x);
|
|
388
|
+
ts_u256_to32(b, y);
|
|
389
|
+
ts_mul32(x, 8, y, 8, p);
|
|
390
|
+
TsU256 rem;
|
|
391
|
+
ts_divmod32(p, 16, c, q, &rem);
|
|
392
|
+
for (int i = 8; i < 16; i++)
|
|
393
|
+
if (q[i]) return false;
|
|
394
|
+
*out = ts_u256_from32(q);
|
|
395
|
+
if (ceil && !ts_u256_is_zero(rem)) {
|
|
396
|
+
TsU256 one = {{1, 0, 0, 0}};
|
|
397
|
+
if (ts_u256_add(*out, one, out)) return false;
|
|
398
|
+
}
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
|
|
189
402
|
/* ---- Well-known program ids --------------------------------------------- */
|
|
190
403
|
static const SolPubkey TS_SYSTEM_PROGRAM_ID = {{0}};
|
|
191
404
|
/* TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA */
|
|
@@ -531,6 +744,18 @@ static inline uint64_t ts_claim_mut(TsParams *params, const TsAccount *a) {
|
|
|
531
744
|
return SUCCESS;
|
|
532
745
|
}
|
|
533
746
|
|
|
747
|
+
/* loadAccountMut of the account parameter at index `at`: its aliasing was checked on entry, a second load is refused. */
|
|
748
|
+
static inline uint64_t ts_claim_mut_at(TsParams *params, uint64_t at) {
|
|
749
|
+
#if TS_MAX_ACCOUNTS > 64
|
|
750
|
+
if (params->loaded_mut[at >> 6] >> (at & 63) & 1) TS_FAIL(TS_ERR_DUPLICATE_MUT, "TypeSOL: account already loaded with loadAccountMut");
|
|
751
|
+
params->loaded_mut[at >> 6] |= (uint64_t)1 << (at & 63);
|
|
752
|
+
#else
|
|
753
|
+
if (params->loaded_mut >> at & 1) TS_FAIL(TS_ERR_DUPLICATE_MUT, "TypeSOL: account already loaded with loadAccountMut");
|
|
754
|
+
params->loaded_mut |= (uint64_t)1 << at;
|
|
755
|
+
#endif
|
|
756
|
+
return SUCCESS;
|
|
757
|
+
}
|
|
758
|
+
|
|
534
759
|
static inline uint64_t ts_check_address(const TsAccount *a, const SolPubkey *expected) {
|
|
535
760
|
if (!ts_key_eq(&a->key, expected)) TS_FAIL(TS_ERR_WRONG_PROGRAM, "TypeSOL: unexpected program address");
|
|
536
761
|
return SUCCESS;
|