@thru/programs 0.3.4 → 0.3.5

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.
Files changed (118) hide show
  1. package/README.md +123 -37
  2. package/dist/abi-manager/index.cjs +9568 -0
  3. package/dist/abi-manager/index.cjs.map +1 -0
  4. package/dist/abi-manager/index.d.cts +2169 -0
  5. package/dist/abi-manager/index.d.ts +2169 -0
  6. package/dist/abi-manager/index.js +4 -0
  7. package/dist/abi-manager/index.js.map +1 -0
  8. package/dist/amm/index.cjs +1 -3
  9. package/dist/amm/index.cjs.map +1 -1
  10. package/dist/amm/index.d.cts +1 -1
  11. package/dist/amm/index.d.ts +1 -1
  12. package/dist/amm/index.js +2 -2
  13. package/dist/amm/index.js.map +1 -1
  14. package/dist/chunk-6IC6CO5S.js +9443 -0
  15. package/dist/chunk-6IC6CO5S.js.map +1 -0
  16. package/dist/chunk-7FBCBZIY.js +41 -0
  17. package/dist/chunk-7FBCBZIY.js.map +1 -0
  18. package/dist/chunk-BNYDH4ZP.js +4351 -0
  19. package/dist/chunk-BNYDH4ZP.js.map +1 -0
  20. package/dist/chunk-OODN6LJA.js +6567 -0
  21. package/dist/chunk-OODN6LJA.js.map +1 -0
  22. package/dist/chunk-YX7BLFQZ.js +81 -0
  23. package/dist/chunk-YX7BLFQZ.js.map +1 -0
  24. package/dist/clob/index.cjs +6674 -3209
  25. package/dist/clob/index.cjs.map +1 -1
  26. package/dist/clob/index.d.cts +1114 -52
  27. package/dist/clob/index.d.ts +1114 -52
  28. package/dist/clob/index.js +6812 -3393
  29. package/dist/clob/index.js.map +1 -1
  30. package/dist/deploy/index.cjs +24734 -0
  31. package/dist/deploy/index.cjs.map +1 -0
  32. package/dist/deploy/index.d.cts +180 -0
  33. package/dist/deploy/index.d.ts +180 -0
  34. package/dist/deploy/index.js +1846 -0
  35. package/dist/deploy/index.js.map +1 -0
  36. package/dist/helpers-DD7q61nr.d.cts +7 -0
  37. package/dist/helpers-DD7q61nr.d.ts +7 -0
  38. package/dist/manager/index.cjs +6680 -0
  39. package/dist/manager/index.cjs.map +1 -0
  40. package/dist/manager/index.d.cts +1279 -0
  41. package/dist/manager/index.d.ts +1279 -0
  42. package/dist/manager/index.js +4 -0
  43. package/dist/manager/index.js.map +1 -0
  44. package/dist/passkey-manager/index.cjs +4 -5
  45. package/dist/passkey-manager/index.cjs.map +1 -1
  46. package/dist/passkey-manager/index.js +2 -2
  47. package/dist/uploader/index.cjs +4442 -0
  48. package/dist/uploader/index.cjs.map +1 -0
  49. package/dist/uploader/index.d.cts +761 -0
  50. package/dist/uploader/index.d.ts +761 -0
  51. package/dist/uploader/index.js +4 -0
  52. package/dist/uploader/index.js.map +1 -0
  53. package/package.json +22 -2
  54. package/src/abi-manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  55. package/src/abi-manager/abi/thru/common/primitives/types.ts +2428 -0
  56. package/src/abi-manager/abi/thru/program/abi_manager/types.ts +7037 -0
  57. package/src/abi-manager/accounts.ts +91 -0
  58. package/src/abi-manager/constants.ts +19 -0
  59. package/src/abi-manager/derivation.ts +86 -0
  60. package/src/abi-manager/errors.ts +48 -0
  61. package/src/abi-manager/index.test.ts +136 -0
  62. package/src/abi-manager/index.ts +56 -0
  63. package/src/abi-manager/instructions.ts +573 -0
  64. package/src/abi-manager/types.ts +150 -0
  65. package/src/amm/index.test.ts +8 -2
  66. package/src/amm/index.ts +1 -1
  67. package/src/clob/abi/thru/program/clob/types.ts +6981 -3070
  68. package/src/clob/exchange-client.test.ts +115 -2
  69. package/src/clob/exchange-client.ts +52 -13
  70. package/src/clob/exchange.test.ts +18 -16
  71. package/src/clob/exchange.ts +4 -0
  72. package/src/clob/index.test.ts +134 -7
  73. package/src/clob/index.ts +302 -10
  74. package/src/clob/price.test.ts +32 -0
  75. package/src/clob/price.ts +77 -0
  76. package/src/deploy/accounts.ts +208 -0
  77. package/src/deploy/chain.ts +163 -0
  78. package/src/deploy/constants.ts +25 -0
  79. package/src/deploy/deploy.test.ts +349 -0
  80. package/src/deploy/errors.ts +72 -0
  81. package/src/deploy/index.ts +44 -0
  82. package/src/deploy/inspection.ts +146 -0
  83. package/src/deploy/seeds.ts +29 -0
  84. package/src/deploy/types.ts +178 -0
  85. package/src/deploy/uploader.test.ts +326 -0
  86. package/src/deploy/uploader.ts +558 -0
  87. package/src/deploy/validation-imports.test.ts +55 -0
  88. package/src/deploy/validation.ts +183 -0
  89. package/src/deploy/workflows.test.ts +422 -0
  90. package/src/deploy/workflows.ts +1088 -0
  91. package/src/helpers/bytes.test.ts +58 -0
  92. package/src/helpers/bytes.ts +28 -3
  93. package/src/manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  94. package/src/manager/abi/thru/common/primitives/types.ts +2428 -0
  95. package/src/manager/abi/thru/program/manager/types.ts +3814 -0
  96. package/src/manager/accounts.ts +44 -0
  97. package/src/manager/constants.ts +16 -0
  98. package/src/manager/derivation.ts +32 -0
  99. package/src/manager/errors.ts +47 -0
  100. package/src/manager/index.test.ts +108 -0
  101. package/src/manager/index.ts +68 -0
  102. package/src/manager/instructions.ts +281 -0
  103. package/src/manager/types.ts +95 -0
  104. package/src/manager/validation.ts +35 -0
  105. package/src/uploader/abi/thru/common/primitives/types.ts +2428 -0
  106. package/src/uploader/abi/thru/program/uploader/types.ts +3022 -0
  107. package/src/uploader/accounts.ts +38 -0
  108. package/src/uploader/constants.ts +14 -0
  109. package/src/uploader/derivation.ts +34 -0
  110. package/src/uploader/errors.ts +25 -0
  111. package/src/uploader/index.test.ts +107 -0
  112. package/src/uploader/index.ts +34 -0
  113. package/src/uploader/instructions.ts +163 -0
  114. package/src/uploader/types.ts +67 -0
  115. package/src/utils/helpers.ts +121 -0
  116. package/tsup.config.ts +4 -0
  117. package/dist/chunk-P5OABVJI.js +0 -28
  118. package/dist/chunk-P5OABVJI.js.map +0 -1
@@ -0,0 +1,3814 @@
1
+ /* Auto-generated TypeScript code */
2
+ /* WARNING: Do not modify this file directly. It is generated from ABI definitions. */
3
+
4
+ import { StateProof } from "../../blockchain/state_proof/types";
5
+ import { Pubkey } from "../../common/primitives/types";
6
+
7
+ type __TnIrNode =
8
+ | { readonly op: "zero" }
9
+ | { readonly op: "const"; readonly value: bigint }
10
+ | { readonly op: "field"; readonly param: string }
11
+ | {
12
+ readonly op: "add";
13
+ readonly left: __TnIrNode;
14
+ readonly right: __TnIrNode;
15
+ }
16
+ | {
17
+ readonly op: "sub";
18
+ readonly left: __TnIrNode;
19
+ readonly right: __TnIrNode;
20
+ }
21
+ | {
22
+ readonly op: "mul";
23
+ readonly left: __TnIrNode;
24
+ readonly right: __TnIrNode;
25
+ }
26
+ | {
27
+ readonly op:
28
+ | "div"
29
+ | "mod"
30
+ | "bitAnd"
31
+ | "bitOr"
32
+ | "bitXor"
33
+ | "leftShift"
34
+ | "rightShift";
35
+ readonly left: __TnIrNode;
36
+ readonly right: __TnIrNode;
37
+ }
38
+ | {
39
+ readonly op: "align";
40
+ readonly alignment: number;
41
+ readonly node: __TnIrNode;
42
+ }
43
+ | {
44
+ readonly op: "switch";
45
+ readonly tag: string;
46
+ readonly cases: readonly { readonly value: number; readonly node: __TnIrNode }[];
47
+ readonly default?: __TnIrNode;
48
+ }
49
+ | {
50
+ readonly op: "call";
51
+ readonly typeName: string;
52
+ readonly args: readonly { readonly name: string; readonly source: string }[];
53
+ }
54
+ | {
55
+ readonly op: "sumOverArray";
56
+ readonly count: __TnIrNode;
57
+ readonly elementTypeName: string;
58
+ readonly fieldName: string;
59
+ };
60
+
61
+ type __TnIrContext = {
62
+ params: Record<string, bigint>;
63
+ buffer?: Uint8Array;
64
+ typeName?: string;
65
+ };
66
+
67
+ type __TnValidateResult = {
68
+ ok: boolean;
69
+ code?: string;
70
+ consumed?: bigint;
71
+ params?: Record<string, bigint>;
72
+ };
73
+ type __TnEvalResult =
74
+ | { ok: true; value: bigint }
75
+ | { ok: false; code: string };
76
+ type __TnBuilderLike = { build(): Uint8Array };
77
+ type __TnStructFieldInput =
78
+ | Uint8Array
79
+ | __TnBuilderLike
80
+ | { buffer?: Uint8Array }
81
+ | { asUint8Array?: () => Uint8Array }
82
+ | { bytes?: () => Uint8Array };
83
+ type __TnVariantDescriptor = {
84
+ readonly name: string;
85
+ readonly tag: number;
86
+ readonly payloadSize: number | null;
87
+ readonly payloadType?: string;
88
+ readonly createPayloadBuilder?: () => unknown | null;
89
+ };
90
+ type __TnVariantSelectorResult<Parent> = {
91
+ select(
92
+ name: string
93
+ ): { writePayload(payload: Uint8Array | __TnBuilderLike): { finish(): Parent } };
94
+ finish(): Parent;
95
+ };
96
+ type __TnFamWriterResult<Parent> = {
97
+ write(payload: Uint8Array | __TnBuilderLike): { finish(): Parent };
98
+ finish(): Parent;
99
+ };
100
+ type __TnConsole = { warn?: (...args: unknown[]) => void };
101
+
102
+ const __tnWarnings = new Set<string>();
103
+ const __tnHasNativeBigInt = typeof BigInt === "function";
104
+ const __tnHasBigIntDataView =
105
+ typeof DataView !== "undefined" &&
106
+ typeof DataView.prototype.getBigInt64 === "function" &&
107
+ typeof DataView.prototype.getBigUint64 === "function" &&
108
+ typeof DataView.prototype.setBigInt64 === "function" &&
109
+ typeof DataView.prototype.setBigUint64 === "function";
110
+ const __tnConsole: __TnConsole | undefined =
111
+ typeof globalThis !== "undefined"
112
+ ? (globalThis as { console?: __TnConsole }).console
113
+ : undefined;
114
+
115
+ function __tnLogWarn(message: string): void {
116
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
117
+ __tnConsole.warn(message);
118
+ }
119
+ }
120
+
121
+ function __tnWarnOnce(message: string): void {
122
+ if (!__tnWarnings.has(message)) {
123
+ __tnWarnings.add(message);
124
+ __tnLogWarn(message);
125
+ }
126
+ }
127
+
128
+ function __tnResolveBuilderInput(
129
+ input: Uint8Array | __TnBuilderLike,
130
+ context: string
131
+ ): Uint8Array {
132
+ if (input instanceof Uint8Array) {
133
+ return new Uint8Array(input);
134
+ }
135
+ if (input && typeof (input as __TnBuilderLike).build === "function") {
136
+ const built = (input as __TnBuilderLike).build();
137
+ if (!(built instanceof Uint8Array)) {
138
+ throw new Error(`${context}: builder did not return Uint8Array`);
139
+ }
140
+ return new Uint8Array(built);
141
+ }
142
+ throw new Error(`${context}: expected Uint8Array or builder`);
143
+ }
144
+
145
+ function __tnResolveStructFieldInput(
146
+ input: __TnStructFieldInput,
147
+ context: string
148
+ ): Uint8Array {
149
+ if (
150
+ input instanceof Uint8Array ||
151
+ (input && typeof (input as __TnBuilderLike).build === "function")
152
+ ) {
153
+ return __tnResolveBuilderInput(input as Uint8Array | __TnBuilderLike, context);
154
+ }
155
+ if (input && typeof (input as { asUint8Array?: () => Uint8Array }).asUint8Array === "function") {
156
+ const bytes = (input as { asUint8Array: () => Uint8Array }).asUint8Array();
157
+ return new Uint8Array(bytes);
158
+ }
159
+ if (input && typeof (input as { bytes?: () => Uint8Array }).bytes === "function") {
160
+ const bytes = (input as { bytes: () => Uint8Array }).bytes();
161
+ return new Uint8Array(bytes);
162
+ }
163
+ if (input && (input as { buffer?: unknown }).buffer instanceof Uint8Array) {
164
+ return new Uint8Array((input as { buffer: Uint8Array }).buffer);
165
+ }
166
+ throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
167
+ }
168
+
169
+ function __tnMaybeCallBuilder(ctor: unknown): unknown | null {
170
+ if (!ctor) {
171
+ return null;
172
+ }
173
+ const builderFn = (ctor as { builder?: () => unknown }).builder;
174
+ return typeof builderFn === "function" ? builderFn() : null;
175
+ }
176
+
177
+ function __tnCreateVariantSelector<Parent, Descriptor extends __TnVariantDescriptor>(
178
+ parent: Parent,
179
+ descriptors: readonly Descriptor[],
180
+ assign: (descriptor: Descriptor, payload: Uint8Array) => void
181
+ ): __TnVariantSelectorResult<Parent> {
182
+ return {
183
+ select(name: string) {
184
+ const descriptor = descriptors.find((variant) => variant.name === name);
185
+ if (!descriptor) {
186
+ throw new Error(`Unknown variant '${name}'`);
187
+ }
188
+ return {
189
+ writePayload(payload: Uint8Array | __TnBuilderLike) {
190
+ const bytes = __tnResolveBuilderInput(
191
+ payload,
192
+ `variant ${descriptor.name}`
193
+ );
194
+ if (
195
+ descriptor.payloadSize !== null &&
196
+ bytes.length !== descriptor.payloadSize
197
+ ) {
198
+ throw new Error(
199
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
200
+ );
201
+ }
202
+ assign(descriptor, bytes);
203
+ return {
204
+ finish(): Parent {
205
+ return parent;
206
+ },
207
+ };
208
+ },
209
+ };
210
+ },
211
+ finish(): Parent {
212
+ return parent;
213
+ },
214
+ };
215
+ }
216
+
217
+ function __tnCreateFamWriter<Parent>(
218
+ parent: Parent,
219
+ fieldName: string,
220
+ assign: (bytes: Uint8Array) => void
221
+ ): __TnFamWriterResult<Parent> {
222
+ let hasWritten = false;
223
+ return {
224
+ write(payload: Uint8Array | __TnBuilderLike) {
225
+ const bytes = __tnResolveBuilderInput(
226
+ payload,
227
+ `flexible array '${fieldName}'`
228
+ );
229
+ const copy = new Uint8Array(bytes);
230
+ assign(copy);
231
+ hasWritten = true;
232
+ return {
233
+ finish(): Parent {
234
+ return parent;
235
+ },
236
+ };
237
+ },
238
+ finish(): Parent {
239
+ if (!hasWritten) {
240
+ throw new Error(
241
+ `flexible array '${fieldName}' requires write() before finish()`
242
+ );
243
+ }
244
+ return parent;
245
+ },
246
+ };
247
+ }
248
+
249
+ const __tnMask32 = __tnHasNativeBigInt
250
+ ? (BigInt(1) << BigInt(32)) - BigInt(1)
251
+ : 0xffffffff;
252
+ const __tnSignBit32 = __tnHasNativeBigInt
253
+ ? BigInt(1) << BigInt(31)
254
+ : 0x80000000;
255
+
256
+ function __tnToBigInt(value: number | bigint): bigint {
257
+ if (__tnHasNativeBigInt) {
258
+ return typeof value === "bigint" ? value : BigInt(value);
259
+ }
260
+ if (typeof value === "bigint") return value;
261
+ if (!Number.isFinite(value)) {
262
+ throw new Error("IR runtime received non-finite numeric input");
263
+ }
264
+ if (!Number.isSafeInteger(value)) {
265
+ __tnWarnOnce(
266
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
267
+ );
268
+ }
269
+ return (value as unknown) as bigint;
270
+ }
271
+
272
+ function __tnBigIntToNumber(value: bigint, context: string): number {
273
+ if (__tnHasNativeBigInt) {
274
+ const converted = Number(value);
275
+ if (!Number.isFinite(converted)) {
276
+ throw new Error(`${context} overflowed Number range`);
277
+ }
278
+ return converted;
279
+ }
280
+ return value as unknown as number;
281
+ }
282
+
283
+ function __tnBigIntEquals(lhs: bigint, rhs: bigint): boolean {
284
+ if (__tnHasNativeBigInt) return lhs === rhs;
285
+ return (lhs as unknown as number) === (rhs as unknown as number);
286
+ }
287
+
288
+ function __tnBigIntGreaterThan(lhs: bigint, rhs: bigint): boolean {
289
+ if (__tnHasNativeBigInt) return lhs > rhs;
290
+ return (lhs as unknown as number) > (rhs as unknown as number);
291
+ }
292
+
293
+ function __tnPopcount(value: number | bigint): number {
294
+ let v =
295
+ typeof value === "bigint"
296
+ ? Number(value & BigInt(0xffffffff))
297
+ : Number(value) >>> 0;
298
+ v = v - ((v >>> 1) & 0x55555555);
299
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
300
+ return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
301
+ }
302
+
303
+ function __tnRaiseIrError(code: string, message: string): never {
304
+ const err = new Error(message);
305
+ (err as { code?: string }).code = code;
306
+ throw err;
307
+ }
308
+
309
+ function __tnCheckedAdd(lhs: bigint, rhs: bigint): bigint {
310
+ if (__tnHasNativeBigInt) {
311
+ const result = (lhs as bigint) + (rhs as bigint);
312
+ if (result < BigInt(0)) {
313
+ __tnRaiseIrError(
314
+ "tn.ir.overflow",
315
+ "IR runtime detected negative size via addition"
316
+ );
317
+ }
318
+ return result;
319
+ }
320
+ const left = lhs as unknown as number;
321
+ const right = rhs as unknown as number;
322
+ const sum = left + right;
323
+ if (sum < 0 || !Number.isFinite(sum)) {
324
+ __tnRaiseIrError(
325
+ "tn.ir.overflow",
326
+ "IR runtime detected invalid addition result"
327
+ );
328
+ }
329
+ if (!Number.isSafeInteger(sum)) {
330
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
331
+ }
332
+ return (sum as unknown) as bigint;
333
+ }
334
+
335
+ function __tnCheckedSub(lhs: bigint, rhs: bigint): bigint {
336
+ if (__tnHasNativeBigInt) {
337
+ const result = (lhs as bigint) - (rhs as bigint);
338
+ if (result < BigInt(0)) {
339
+ __tnRaiseIrError(
340
+ "tn.ir.overflow",
341
+ "IR runtime detected negative size via subtraction"
342
+ );
343
+ }
344
+ return result;
345
+ }
346
+ const left = lhs as unknown as number;
347
+ const right = rhs as unknown as number;
348
+ const diff = left - right;
349
+ if (diff < 0 || !Number.isFinite(diff)) {
350
+ __tnRaiseIrError(
351
+ "tn.ir.overflow",
352
+ "IR runtime detected invalid subtraction result"
353
+ );
354
+ }
355
+ if (!Number.isSafeInteger(diff)) {
356
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt subtraction");
357
+ }
358
+ return (diff as unknown) as bigint;
359
+ }
360
+
361
+ function __tnCheckedMul(lhs: bigint, rhs: bigint): bigint {
362
+ if (__tnHasNativeBigInt) {
363
+ const result = (lhs as bigint) * (rhs as bigint);
364
+ if (result < BigInt(0)) {
365
+ __tnRaiseIrError(
366
+ "tn.ir.overflow",
367
+ "IR runtime detected negative size via multiplication"
368
+ );
369
+ }
370
+ return result;
371
+ }
372
+ const left = lhs as unknown as number;
373
+ const right = rhs as unknown as number;
374
+ const product = left * right;
375
+ if (product < 0 || !Number.isFinite(product)) {
376
+ __tnRaiseIrError(
377
+ "tn.ir.overflow",
378
+ "IR runtime detected invalid multiplication result"
379
+ );
380
+ }
381
+ if (!Number.isSafeInteger(product)) {
382
+ __tnWarnOnce(
383
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
384
+ );
385
+ }
386
+ return (product as unknown) as bigint;
387
+ }
388
+
389
+ function __tnCheckedDiv(lhs: bigint, rhs: bigint): bigint {
390
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
391
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime division by zero");
392
+ }
393
+ if (__tnHasNativeBigInt) return (lhs as bigint) / (rhs as bigint);
394
+ const quotient = Math.floor((lhs as unknown as number) / (rhs as unknown as number));
395
+ return (quotient as unknown) as bigint;
396
+ }
397
+
398
+ function __tnCheckedMod(lhs: bigint, rhs: bigint): bigint {
399
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
400
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime modulo by zero");
401
+ }
402
+ if (__tnHasNativeBigInt) return (lhs as bigint) % (rhs as bigint);
403
+ return (((lhs as unknown as number) % (rhs as unknown as number)) as unknown) as bigint;
404
+ }
405
+
406
+ function __tnBitwise(
407
+ lhs: bigint,
408
+ rhs: bigint,
409
+ op: "and" | "or" | "xor"
410
+ ): bigint {
411
+ if (__tnHasNativeBigInt) {
412
+ if (op === "and") return (lhs as bigint) & (rhs as bigint);
413
+ if (op === "or") return (lhs as bigint) | (rhs as bigint);
414
+ return (lhs as bigint) ^ (rhs as bigint);
415
+ }
416
+ const left = lhs as unknown as number;
417
+ const right = rhs as unknown as number;
418
+ const maxU32 = 0xffffffff;
419
+ if (
420
+ !Number.isInteger(left) ||
421
+ !Number.isInteger(right) ||
422
+ left < 0 ||
423
+ right < 0 ||
424
+ left > maxU32 ||
425
+ right > maxU32
426
+ ) {
427
+ __tnRaiseIrError(
428
+ "tn.ir.overflow",
429
+ "IR runtime bitwise operation requires BigInt for values outside u32 range"
430
+ );
431
+ }
432
+ const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
433
+ return ((result >>> 0) as unknown) as bigint;
434
+ }
435
+
436
+ function __tnCheckedShift(
437
+ lhs: bigint,
438
+ rhs: bigint,
439
+ direction: "left" | "right"
440
+ ): bigint {
441
+ const amount = __tnBigIntToNumber(rhs, "IR shift amount");
442
+ if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
443
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime invalid shift amount");
444
+ }
445
+ if (__tnHasNativeBigInt) {
446
+ const shift = BigInt(amount);
447
+ return direction === "left" ? (lhs as bigint) << shift : (lhs as bigint) >> shift;
448
+ }
449
+ const value = lhs as unknown as number;
450
+ const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
451
+ if (!Number.isSafeInteger(result)) {
452
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt shift");
453
+ }
454
+ return (result as unknown) as bigint;
455
+ }
456
+
457
+ function __tnAlign(value: bigint, alignment: number): bigint {
458
+ if (alignment <= 1) return value;
459
+ const alignBig = __tnToBigInt(alignment);
460
+ if (__tnHasNativeBigInt) {
461
+ const remainder = value % alignBig;
462
+ if (__tnBigIntEquals(remainder, __tnToBigInt(0))) {
463
+ return value;
464
+ }
465
+ const delta = alignBig - remainder;
466
+ return __tnCheckedAdd(value, delta);
467
+ }
468
+ const current = __tnBigIntToNumber(value, "IR align");
469
+ const alignNum = alignment >>> 0;
470
+ const remainder = current % alignNum;
471
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
472
+ return __tnToBigInt(next);
473
+ }
474
+
475
+ function __tnSplitUint64(value: bigint): { high: number; low: number } {
476
+ if (__tnHasNativeBigInt) {
477
+ const low = Number(value & (__tnMask32 as bigint));
478
+ const high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
479
+ return { high, low };
480
+ }
481
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
482
+ const low = num >>> 0;
483
+ const high = Math.floor(num / 4294967296) >>> 0;
484
+ return { high, low };
485
+ }
486
+
487
+ function __tnSplitInt64(value: bigint): { high: number; low: number } {
488
+ if (__tnHasNativeBigInt) {
489
+ const low = Number(value & (__tnMask32 as bigint));
490
+ let high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
491
+ if ((BigInt(high) & (__tnSignBit32 as bigint)) !== BigInt(0)) {
492
+ high -= 0x100000000;
493
+ }
494
+ return { high, low };
495
+ }
496
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
497
+ const low = num >>> 0;
498
+ const high = Math.floor(num / 4294967296);
499
+ return { high, low };
500
+ }
501
+
502
+ function __tnPolyfillReadUint64(
503
+ view: DataView,
504
+ offset: number,
505
+ littleEndian: boolean
506
+ ): bigint {
507
+ const low = littleEndian
508
+ ? view.getUint32(offset, true)
509
+ : view.getUint32(offset + 4, false);
510
+ const high = littleEndian
511
+ ? view.getUint32(offset + 4, true)
512
+ : view.getUint32(offset, false);
513
+ if (__tnHasNativeBigInt) {
514
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
515
+ }
516
+ const value = high * 4294967296 + low;
517
+ if (!Number.isSafeInteger(value)) {
518
+ __tnWarnOnce(
519
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
520
+ );
521
+ }
522
+ return (value as unknown) as bigint;
523
+ }
524
+
525
+ function __tnPolyfillReadInt64(
526
+ view: DataView,
527
+ offset: number,
528
+ littleEndian: boolean
529
+ ): bigint {
530
+ const low = littleEndian
531
+ ? view.getUint32(offset, true)
532
+ : view.getUint32(offset + 4, false);
533
+ const high = littleEndian
534
+ ? view.getInt32(offset + 4, true)
535
+ : view.getInt32(offset, false);
536
+ if (__tnHasNativeBigInt) {
537
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
538
+ }
539
+ const value = high * 4294967296 + low;
540
+ if (!Number.isSafeInteger(value)) {
541
+ __tnWarnOnce(
542
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
543
+ );
544
+ }
545
+ return (value as unknown) as bigint;
546
+ }
547
+
548
+ function __tnPolyfillWriteUint64(
549
+ view: DataView,
550
+ offset: number,
551
+ value: bigint,
552
+ littleEndian: boolean
553
+ ): void {
554
+ const parts = __tnSplitUint64(value);
555
+ if (littleEndian) {
556
+ view.setUint32(offset, parts.low, true);
557
+ view.setUint32(offset + 4, parts.high, true);
558
+ } else {
559
+ view.setUint32(offset, parts.high, false);
560
+ view.setUint32(offset + 4, parts.low, false);
561
+ }
562
+ }
563
+
564
+ function __tnPolyfillWriteInt64(
565
+ view: DataView,
566
+ offset: number,
567
+ value: bigint,
568
+ littleEndian: boolean
569
+ ): void {
570
+ const parts = __tnSplitInt64(value);
571
+ if (littleEndian) {
572
+ view.setUint32(offset, parts.low >>> 0, true);
573
+ view.setInt32(offset + 4, parts.high | 0, true);
574
+ } else {
575
+ view.setInt32(offset, parts.high | 0, false);
576
+ view.setUint32(offset + 4, parts.low >>> 0, false);
577
+ }
578
+ }
579
+
580
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
581
+ const proto = DataView.prototype as unknown as Record<string, unknown>;
582
+ if (typeof proto.getBigUint64 !== "function") {
583
+ (proto as any).getBigUint64 = function (
584
+ offset: number,
585
+ littleEndian?: boolean
586
+ ): bigint {
587
+ __tnWarnOnce(
588
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
589
+ );
590
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
591
+ };
592
+ }
593
+ if (typeof proto.getBigInt64 !== "function") {
594
+ (proto as any).getBigInt64 = function (
595
+ offset: number,
596
+ littleEndian?: boolean
597
+ ): bigint {
598
+ __tnWarnOnce(
599
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
600
+ );
601
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
602
+ };
603
+ }
604
+ if (typeof proto.setBigUint64 !== "function") {
605
+ (proto as any).setBigUint64 = function (
606
+ offset: number,
607
+ value: bigint,
608
+ littleEndian?: boolean
609
+ ): void {
610
+ __tnWarnOnce(
611
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
612
+ );
613
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
614
+ };
615
+ }
616
+ if (typeof proto.setBigInt64 !== "function") {
617
+ (proto as any).setBigInt64 = function (
618
+ offset: number,
619
+ value: bigint,
620
+ littleEndian?: boolean
621
+ ): void {
622
+ __tnWarnOnce(
623
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
624
+ );
625
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
626
+ };
627
+ }
628
+ if (!__tnHasNativeBigInt) {
629
+ __tnWarnOnce(
630
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
631
+ );
632
+ }
633
+ }
634
+
635
+ const __tnFootprintRegistry: Record<
636
+ string,
637
+ (params: Record<string, bigint>) => bigint
638
+ > = {};
639
+ const __tnValidateRegistry: Record<
640
+ string,
641
+ (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
642
+ > = {};
643
+ const __tnDynamicValidateRegistry: Record<
644
+ string,
645
+ (buffer: Uint8Array) => __TnValidateResult
646
+ > = {};
647
+
648
+ function __tnRegisterFootprint(
649
+ typeName: string,
650
+ fn: (params: Record<string, bigint>) => bigint
651
+ ): void {
652
+ __tnFootprintRegistry[typeName] = fn;
653
+ }
654
+
655
+ function __tnRegisterValidate(
656
+ typeName: string,
657
+ fn: (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
658
+ ): void {
659
+ __tnValidateRegistry[typeName] = fn;
660
+ }
661
+
662
+ function __tnRegisterDynamicValidate(
663
+ typeName: string,
664
+ fn: (buffer: Uint8Array) => __TnValidateResult
665
+ ): void {
666
+ __tnDynamicValidateRegistry[typeName] = fn;
667
+ }
668
+
669
+ function __tnInvokeFootprint(
670
+ typeName: string,
671
+ params: Record<string, bigint>
672
+ ): bigint {
673
+ const fn = __tnFootprintRegistry[typeName];
674
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
675
+ return fn(params);
676
+ }
677
+
678
+ function __tnInvokeValidate(
679
+ typeName: string,
680
+ buffer: Uint8Array,
681
+ params: Record<string, bigint>
682
+ ): __TnValidateResult {
683
+ const fn = __tnValidateRegistry[typeName];
684
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
685
+ return fn(buffer, params);
686
+ }
687
+
688
+ function __tnInvokeDynamicValidate(
689
+ typeName: string,
690
+ buffer: Uint8Array
691
+ ): __TnValidateResult {
692
+ const fn = __tnDynamicValidateRegistry[typeName];
693
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
694
+ return fn(buffer);
695
+ }
696
+
697
+ function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
698
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
699
+ }
700
+
701
+ function __tnTryEvalFootprint(
702
+ node: __TnIrNode,
703
+ ctx: __TnIrContext
704
+ ): __TnEvalResult {
705
+ return __tnTryEvalIr(node, ctx);
706
+ }
707
+
708
+ function __tnTryEvalIr(
709
+ node: __TnIrNode,
710
+ ctx: __TnIrContext
711
+ ): __TnEvalResult {
712
+ try {
713
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
714
+ } catch (err) {
715
+ return { ok: false, code: __tnNormalizeIrError(err) };
716
+ }
717
+ }
718
+
719
+ function __tnIsEvalError(result: __TnEvalResult): result is { ok: false; code: string } {
720
+ return result.ok === false;
721
+ }
722
+
723
+ function __tnValidateIrTree(
724
+ ir: { readonly typeName: string; readonly root: __TnIrNode },
725
+ buffer: Uint8Array,
726
+ params: Record<string, bigint>
727
+ ): __TnValidateResult {
728
+ const evalResult = __tnTryEvalIr(ir.root, {
729
+ params,
730
+ buffer,
731
+ typeName: ir.typeName,
732
+ });
733
+ if (__tnIsEvalError(evalResult)) {
734
+ return { ok: false, code: evalResult.code };
735
+ }
736
+ const required = evalResult.value;
737
+ const available = __tnToBigInt(buffer.length);
738
+ if (__tnBigIntGreaterThan(required, available)) {
739
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
740
+ }
741
+ return { ok: true, consumed: required };
742
+ }
743
+
744
+ function __tnEvalIrNode(
745
+ node: __TnIrNode,
746
+ ctx: __TnIrContext,
747
+ baseOffset: bigint
748
+ ): bigint {
749
+ switch (node.op) {
750
+ case "zero":
751
+ return __tnToBigInt(0);
752
+ case "const":
753
+ return node.value;
754
+ case "field": {
755
+ if (node.param === "__buffer_size" && ctx.buffer) {
756
+ return __tnToBigInt(ctx.buffer.length);
757
+ }
758
+ const val = ctx.params[node.param];
759
+ if (val === undefined) {
760
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
761
+ __tnRaiseIrError(
762
+ "tn.ir.missing_param",
763
+ `${prefix}Missing IR parameter '${node.param}'`
764
+ );
765
+ }
766
+ return val;
767
+ }
768
+ case "add":
769
+ {
770
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
771
+ const right = __tnEvalIrNode(
772
+ node.right,
773
+ ctx,
774
+ __tnCheckedAdd(baseOffset, left)
775
+ );
776
+ return __tnCheckedAdd(left, right);
777
+ }
778
+ case "sub":
779
+ return __tnCheckedSub(
780
+ __tnEvalIrNode(node.left, ctx, baseOffset),
781
+ __tnEvalIrNode(node.right, ctx, baseOffset)
782
+ );
783
+ case "mul":
784
+ return __tnCheckedMul(
785
+ __tnEvalIrNode(node.left, ctx, baseOffset),
786
+ __tnEvalIrNode(node.right, ctx, baseOffset)
787
+ );
788
+ case "div":
789
+ return __tnCheckedDiv(
790
+ __tnEvalIrNode(node.left, ctx, baseOffset),
791
+ __tnEvalIrNode(node.right, ctx, baseOffset)
792
+ );
793
+ case "mod":
794
+ return __tnCheckedMod(
795
+ __tnEvalIrNode(node.left, ctx, baseOffset),
796
+ __tnEvalIrNode(node.right, ctx, baseOffset)
797
+ );
798
+ case "bitAnd":
799
+ return __tnBitwise(
800
+ __tnEvalIrNode(node.left, ctx, baseOffset),
801
+ __tnEvalIrNode(node.right, ctx, baseOffset),
802
+ "and"
803
+ );
804
+ case "bitOr":
805
+ return __tnBitwise(
806
+ __tnEvalIrNode(node.left, ctx, baseOffset),
807
+ __tnEvalIrNode(node.right, ctx, baseOffset),
808
+ "or"
809
+ );
810
+ case "bitXor":
811
+ return __tnBitwise(
812
+ __tnEvalIrNode(node.left, ctx, baseOffset),
813
+ __tnEvalIrNode(node.right, ctx, baseOffset),
814
+ "xor"
815
+ );
816
+ case "leftShift":
817
+ return __tnCheckedShift(
818
+ __tnEvalIrNode(node.left, ctx, baseOffset),
819
+ __tnEvalIrNode(node.right, ctx, baseOffset),
820
+ "left"
821
+ );
822
+ case "rightShift":
823
+ return __tnCheckedShift(
824
+ __tnEvalIrNode(node.left, ctx, baseOffset),
825
+ __tnEvalIrNode(node.right, ctx, baseOffset),
826
+ "right"
827
+ );
828
+ case "align":
829
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
830
+ case "switch": {
831
+ const tagVal = ctx.params[node.tag];
832
+ if (tagVal === undefined) {
833
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
834
+ __tnRaiseIrError(
835
+ "tn.ir.missing_param",
836
+ `${prefix}Missing IR switch tag '${node.tag}'`
837
+ );
838
+ }
839
+ const tagNumber = Number(tagVal);
840
+ for (const caseNode of node.cases) {
841
+ if (caseNode.value === tagNumber) {
842
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
843
+ }
844
+ }
845
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
846
+ __tnRaiseIrError(
847
+ "tn.ir.invalid_tag",
848
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
849
+ );
850
+ }
851
+ case "call": {
852
+ const nestedParams: Record<string, bigint> = Object.create(null);
853
+ for (const arg of node.args) {
854
+ const val = ctx.params[arg.source];
855
+ if (val === undefined) {
856
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
857
+ __tnRaiseIrError(
858
+ "tn.ir.missing_param",
859
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
860
+ );
861
+ }
862
+ nestedParams[arg.name] = val;
863
+ }
864
+ if (ctx.buffer) {
865
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
866
+ const nestedResult = __tnInvokeValidate(
867
+ node.typeName,
868
+ ctx.buffer.subarray(nestedOffset),
869
+ nestedParams
870
+ );
871
+ if (!nestedResult.ok) {
872
+ const nestedCode =
873
+ nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
874
+ const prefixed = nestedCode.startsWith("tn.")
875
+ ? nestedCode
876
+ : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
877
+ __tnRaiseIrError(
878
+ prefixed,
879
+ `Nested validator ${node.typeName} failed`
880
+ );
881
+ }
882
+ if (nestedResult.consumed !== undefined) {
883
+ return nestedResult.consumed;
884
+ }
885
+ }
886
+ return __tnInvokeFootprint(node.typeName, nestedParams);
887
+ }
888
+ case "sumOverArray": {
889
+ if (!ctx.buffer) {
890
+ __tnRaiseIrError(
891
+ "tn.ir.missing_buffer",
892
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
893
+ );
894
+ }
895
+ const count = __tnBigIntToNumber(
896
+ __tnEvalIrNode(node.count, ctx, baseOffset),
897
+ `Jagged array '${node.fieldName}' count`
898
+ );
899
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
900
+ let total = __tnToBigInt(0);
901
+ for (let i = 0; i < count; i++) {
902
+ const result = __tnInvokeDynamicValidate(
903
+ node.elementTypeName,
904
+ ctx.buffer.subarray(cursor)
905
+ );
906
+ if (!result.ok || result.consumed === undefined) {
907
+ const code = result.code ?? "tn.ir.runtime_error";
908
+ __tnRaiseIrError(
909
+ code,
910
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
911
+ );
912
+ }
913
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
914
+ total = __tnCheckedAdd(total, result.consumed);
915
+ }
916
+ return total;
917
+ }
918
+ default:
919
+ __tnRaiseIrError(
920
+ "tn.ir.runtime_error",
921
+ `Unsupported IR node ${(node as { op: string }).op}`
922
+ );
923
+ }
924
+ }
925
+
926
+ function __tnNormalizeIrError(err: unknown): string {
927
+ if (err && typeof err === "object" && "code" in err) {
928
+ const maybeCode = (err as { code?: string }).code;
929
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
930
+ return maybeCode;
931
+ }
932
+ }
933
+ const message =
934
+ err && typeof err === "object" && "message" in err
935
+ ? String((err as { message?: unknown }).message ?? "")
936
+ : typeof err === "string"
937
+ ? err
938
+ : "";
939
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
940
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
941
+ if (
942
+ message.includes("invalid") ||
943
+ message.includes("overflow") ||
944
+ message.includes("negative size")
945
+ ) {
946
+ return "tn.ir.overflow";
947
+ }
948
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
949
+ return "tn.ir.runtime_error";
950
+ }
951
+
952
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
953
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
954
+ __tnRegisterDynamicValidate("Pubkey", (buffer) => { const result = Pubkey.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
955
+
956
+ __tnRegisterFootprint("StateProof", (params) => StateProof.__tnInvokeFootprint(params));
957
+ __tnRegisterValidate("StateProof", (buffer, params) => StateProof.__tnInvokeValidate(buffer, params));
958
+ __tnRegisterDynamicValidate("StateProof", (buffer) => { const result = StateProof.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
959
+
960
+ /* ----- TYPE DEFINITION FOR CreateEphemeralArgs ----- */
961
+
962
+ const __tn_ir_CreateEphemeralArgs = {
963
+ typeName: "CreateEphemeralArgs",
964
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "seed.seed_len" }, right: { op: "const", value: 1n } } } } }
965
+ } as const;
966
+
967
+ export class CreateEphemeralArgs {
968
+ private view: DataView;
969
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
970
+ private __tnParams: CreateEphemeralArgs.Params;
971
+
972
+ private constructor(private buffer: Uint8Array, params?: CreateEphemeralArgs.Params, fieldContext?: Record<string, number | bigint>) {
973
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
974
+ this.__tnFieldContext = fieldContext ?? null;
975
+ if (params) {
976
+ this.__tnParams = params;
977
+ } else {
978
+ const derived = CreateEphemeralArgs.__tnExtractParams(this.view, buffer);
979
+ if (!derived) {
980
+ throw new Error("CreateEphemeralArgs: failed to derive dynamic parameters");
981
+ }
982
+ this.__tnParams = derived.params;
983
+ }
984
+ }
985
+
986
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: CreateEphemeralArgs.Params, fieldContext?: Record<string, number | bigint> }): CreateEphemeralArgs {
987
+ if (!buffer || buffer.length === undefined) throw new Error("CreateEphemeralArgs.__tnCreateView requires a Uint8Array");
988
+ let params = opts?.params ?? null;
989
+ if (!params) {
990
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
991
+ const derived = CreateEphemeralArgs.__tnExtractParams(view, buffer);
992
+ if (!derived) throw new Error("CreateEphemeralArgs.__tnCreateView: failed to derive params");
993
+ params = derived.params;
994
+ }
995
+ const instance = new CreateEphemeralArgs(new Uint8Array(buffer), params, opts?.fieldContext);
996
+ return instance;
997
+ }
998
+
999
+ dynamicParams(): CreateEphemeralArgs.Params {
1000
+ return this.__tnParams;
1001
+ }
1002
+
1003
+ withFieldContext(context: Record<string, number | bigint>): this {
1004
+ this.__tnFieldContext = context;
1005
+ return this;
1006
+ }
1007
+
1008
+ private __tnResolveFieldRef(path: string): number {
1009
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1010
+ const getter = (this as any)[getterName];
1011
+ if (typeof getter === "function") {
1012
+ const value = getter.call(this);
1013
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "CreateEphemeralArgs::__tnResolveFieldRef") : value;
1014
+ }
1015
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1016
+ const contextValue = this.__tnFieldContext[path];
1017
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "CreateEphemeralArgs::__tnResolveFieldRef") : contextValue;
1018
+ }
1019
+ throw new Error("CreateEphemeralArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1020
+ }
1021
+
1022
+ static builder(): CreateEphemeralArgsBuilder {
1023
+ return new CreateEphemeralArgsBuilder();
1024
+ }
1025
+
1026
+ static fromBuilder(builder: CreateEphemeralArgsBuilder): CreateEphemeralArgs | null {
1027
+ const buffer = builder.build();
1028
+ const params = builder.dynamicParams();
1029
+ return CreateEphemeralArgs.from_array(buffer, { params });
1030
+ }
1031
+
1032
+ static readonly flexibleArrayWriters = Object.freeze([
1033
+ { field: "seed", method: "seed", sizeField: "seed_len", paramKey: "seed_len", elementSize: 1 },
1034
+ ] as const);
1035
+
1036
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: CreateEphemeralArgs.Params; derived: Record<string, bigint> | null } | null {
1037
+ if (buffer.length < 20) {
1038
+ return null;
1039
+ }
1040
+ const __tnParam_seed_seed_len = __tnToBigInt(view.getUint32(16, true));
1041
+ const __tnExtractedParams = CreateEphemeralArgs.Params.fromValues({
1042
+ seed_seed_len: __tnParam_seed_seed_len,
1043
+ });
1044
+ return { params: __tnExtractedParams, derived: null };
1045
+ }
1046
+
1047
+ get_meta_account_idx(): number {
1048
+ const offset = 0;
1049
+ return this.view.getUint16(offset, true); /* little-endian */
1050
+ }
1051
+
1052
+ set_meta_account_idx(value: number): void {
1053
+ const offset = 0;
1054
+ this.view.setUint16(offset, value, true); /* little-endian */
1055
+ }
1056
+
1057
+ get meta_account_idx(): number {
1058
+ return this.get_meta_account_idx();
1059
+ }
1060
+
1061
+ set meta_account_idx(value: number) {
1062
+ this.set_meta_account_idx(value);
1063
+ }
1064
+
1065
+ get_program_account_idx(): number {
1066
+ const offset = 2;
1067
+ return this.view.getUint16(offset, true); /* little-endian */
1068
+ }
1069
+
1070
+ set_program_account_idx(value: number): void {
1071
+ const offset = 2;
1072
+ this.view.setUint16(offset, value, true); /* little-endian */
1073
+ }
1074
+
1075
+ get program_account_idx(): number {
1076
+ return this.get_program_account_idx();
1077
+ }
1078
+
1079
+ set program_account_idx(value: number) {
1080
+ this.set_program_account_idx(value);
1081
+ }
1082
+
1083
+ get_srcbuf_account_idx(): number {
1084
+ const offset = 4;
1085
+ return this.view.getUint16(offset, true); /* little-endian */
1086
+ }
1087
+
1088
+ set_srcbuf_account_idx(value: number): void {
1089
+ const offset = 4;
1090
+ this.view.setUint16(offset, value, true); /* little-endian */
1091
+ }
1092
+
1093
+ get srcbuf_account_idx(): number {
1094
+ return this.get_srcbuf_account_idx();
1095
+ }
1096
+
1097
+ set srcbuf_account_idx(value: number) {
1098
+ this.set_srcbuf_account_idx(value);
1099
+ }
1100
+
1101
+ get_srcbuf_offset(): number {
1102
+ const offset = 6;
1103
+ return this.view.getUint32(offset, true); /* little-endian */
1104
+ }
1105
+
1106
+ set_srcbuf_offset(value: number): void {
1107
+ const offset = 6;
1108
+ this.view.setUint32(offset, value, true); /* little-endian */
1109
+ }
1110
+
1111
+ get srcbuf_offset(): number {
1112
+ return this.get_srcbuf_offset();
1113
+ }
1114
+
1115
+ set srcbuf_offset(value: number) {
1116
+ this.set_srcbuf_offset(value);
1117
+ }
1118
+
1119
+ get_srcbuf_size(): number {
1120
+ const offset = 10;
1121
+ return this.view.getUint32(offset, true); /* little-endian */
1122
+ }
1123
+
1124
+ set_srcbuf_size(value: number): void {
1125
+ const offset = 10;
1126
+ this.view.setUint32(offset, value, true); /* little-endian */
1127
+ }
1128
+
1129
+ get srcbuf_size(): number {
1130
+ return this.get_srcbuf_size();
1131
+ }
1132
+
1133
+ set srcbuf_size(value: number) {
1134
+ this.set_srcbuf_size(value);
1135
+ }
1136
+
1137
+ get_authority_account_idx(): number {
1138
+ const offset = 14;
1139
+ return this.view.getUint16(offset, true); /* little-endian */
1140
+ }
1141
+
1142
+ set_authority_account_idx(value: number): void {
1143
+ const offset = 14;
1144
+ this.view.setUint16(offset, value, true); /* little-endian */
1145
+ }
1146
+
1147
+ get authority_account_idx(): number {
1148
+ return this.get_authority_account_idx();
1149
+ }
1150
+
1151
+ set authority_account_idx(value: number) {
1152
+ this.set_authority_account_idx(value);
1153
+ }
1154
+
1155
+ get_seed_len(): number {
1156
+ const offset = 16;
1157
+ return this.view.getUint32(offset, true); /* little-endian */
1158
+ }
1159
+
1160
+ set_seed_len(value: number): void {
1161
+ const offset = 16;
1162
+ this.view.setUint32(offset, value, true); /* little-endian */
1163
+ }
1164
+
1165
+ get seed_len(): number {
1166
+ return this.get_seed_len();
1167
+ }
1168
+
1169
+ set seed_len(value: number) {
1170
+ this.set_seed_len(value);
1171
+ }
1172
+
1173
+ get_seed_length(): number {
1174
+ return this.__tnResolveFieldRef("seed_len");
1175
+ }
1176
+
1177
+ get_seed_at(index: number): number {
1178
+ const offset = 20;
1179
+ return this.view.getUint8(offset + index * 1);
1180
+ }
1181
+
1182
+ get_seed(): number[] {
1183
+ const len = this.get_seed_length();
1184
+ const result: number[] = [];
1185
+ for (let i = 0; i < len; i++) {
1186
+ result.push(this.get_seed_at(i));
1187
+ }
1188
+ return result;
1189
+ }
1190
+
1191
+ set_seed_at(index: number, value: number): void {
1192
+ const offset = 20;
1193
+ this.view.setUint8((offset + index * 1), value);
1194
+ }
1195
+
1196
+ set_seed(value: number[]): void {
1197
+ const len = Math.min(this.get_seed_length(), value.length);
1198
+ for (let i = 0; i < len; i++) {
1199
+ this.set_seed_at(i, value[i]);
1200
+ }
1201
+ }
1202
+
1203
+ get seed(): number[] {
1204
+ return this.get_seed();
1205
+ }
1206
+
1207
+ set seed(value: number[]) {
1208
+ this.set_seed(value);
1209
+ }
1210
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1211
+ return __tnEvalFootprint(__tn_ir_CreateEphemeralArgs.root, { params: __tnParams });
1212
+ }
1213
+
1214
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1215
+ return __tnValidateIrTree(__tn_ir_CreateEphemeralArgs, buffer, __tnParams);
1216
+ }
1217
+
1218
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1219
+ return this.__tnFootprintInternal(__tnParams);
1220
+ }
1221
+
1222
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1223
+ return this.__tnValidateInternal(buffer, __tnParams);
1224
+ }
1225
+
1226
+ static footprintIr(seed_seed_len: number | bigint): bigint {
1227
+ const params = CreateEphemeralArgs.Params.fromValues({
1228
+ seed_seed_len: seed_seed_len,
1229
+ });
1230
+ return this.footprintIrFromParams(params);
1231
+ }
1232
+
1233
+ private static __tnPackParams(params: CreateEphemeralArgs.Params): Record<string, bigint> {
1234
+ const record: Record<string, bigint> = Object.create(null);
1235
+ record["seed.seed_len"] = params.seed_seed_len;
1236
+ return record;
1237
+ }
1238
+
1239
+ static footprintIrFromParams(params: CreateEphemeralArgs.Params): bigint {
1240
+ const __tnParams = this.__tnPackParams(params);
1241
+ return this.__tnFootprintInternal(__tnParams);
1242
+ }
1243
+
1244
+ static footprintFromParams(params: CreateEphemeralArgs.Params): number {
1245
+ const irResult = this.footprintIrFromParams(params);
1246
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1247
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for CreateEphemeralArgs');
1248
+ return __tnBigIntToNumber(irResult, 'CreateEphemeralArgs::footprintFromParams');
1249
+ }
1250
+
1251
+ static footprintFromValues(input: { seed_seed_len: number | bigint }): number {
1252
+ const params = CreateEphemeralArgs.params(input);
1253
+ return this.footprintFromParams(params);
1254
+ }
1255
+
1256
+ static footprint(params: CreateEphemeralArgs.Params): number {
1257
+ return this.footprintFromParams(params);
1258
+ }
1259
+
1260
+ static validate(buffer: Uint8Array, opts?: { params?: CreateEphemeralArgs.Params }): { ok: boolean; code?: string; consumed?: number; params?: CreateEphemeralArgs.Params } {
1261
+ if (!buffer || buffer.length === undefined) {
1262
+ return { ok: false, code: "tn.invalid_buffer" };
1263
+ }
1264
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1265
+ let params = opts?.params ?? null;
1266
+ if (!params) {
1267
+ const extracted = this.__tnExtractParams(view, buffer);
1268
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1269
+ params = extracted.params;
1270
+ }
1271
+ const __tnParamsRec = this.__tnPackParams(params);
1272
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1273
+ if (!irResult.ok) {
1274
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreateEphemeralArgs::validate') : undefined, params };
1275
+ }
1276
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreateEphemeralArgs::validate') : undefined;
1277
+ return { ok: true, consumed, params };
1278
+ }
1279
+
1280
+ static from_array(buffer: Uint8Array, opts?: { params?: CreateEphemeralArgs.Params }): CreateEphemeralArgs | null {
1281
+ if (!buffer || buffer.length === undefined) {
1282
+ return null;
1283
+ }
1284
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1285
+ let params = opts?.params ?? null;
1286
+ if (!params) {
1287
+ const derived = this.__tnExtractParams(view, buffer);
1288
+ if (!derived) return null;
1289
+ params = derived.params;
1290
+ }
1291
+ const validation = this.validate(buffer, { params });
1292
+ if (!validation.ok) {
1293
+ return null;
1294
+ }
1295
+ const cached = validation.params ?? params;
1296
+ const state = new CreateEphemeralArgs(buffer, cached);
1297
+ return state;
1298
+ }
1299
+
1300
+
1301
+ }
1302
+
1303
+ export namespace CreateEphemeralArgs {
1304
+ export type Params = {
1305
+ /** ABI path: seed.seed_len */
1306
+ readonly seed_seed_len: bigint;
1307
+ };
1308
+
1309
+ export const ParamKeys = Object.freeze({
1310
+ seed_seed_len: "seed.seed_len",
1311
+ } as const);
1312
+
1313
+ export const Params = {
1314
+ fromValues(input: { seed_seed_len: number | bigint }): Params {
1315
+ return {
1316
+ seed_seed_len: __tnToBigInt(input.seed_seed_len),
1317
+ };
1318
+ },
1319
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1320
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1321
+ return (source as { dynamicParams(): Params }).dynamicParams();
1322
+ }
1323
+ if ((source as { params?: Params }).params) {
1324
+ return (source as { params: Params }).params;
1325
+ }
1326
+ return source as Params;
1327
+ }
1328
+ };
1329
+
1330
+ export function params(input: { seed_seed_len: number | bigint }): Params {
1331
+ return Params.fromValues(input);
1332
+ }
1333
+ }
1334
+
1335
+ export class CreateEphemeralArgsBuilder {
1336
+ private buffer: Uint8Array;
1337
+ private view: DataView;
1338
+ private __tnCachedParams: CreateEphemeralArgs.Params | null = null;
1339
+ private __tnLastBuffer: Uint8Array | null = null;
1340
+ private __tnLastParams: CreateEphemeralArgs.Params | null = null;
1341
+ private __tnFam_seed: Uint8Array | null = null;
1342
+ private __tnFam_seedCount: number | null = null;
1343
+ private __tnFamWriter_seed?: __TnFamWriterResult<CreateEphemeralArgsBuilder>;
1344
+
1345
+ constructor() {
1346
+ this.buffer = new Uint8Array(20);
1347
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1348
+ }
1349
+
1350
+ private __tnInvalidate(): void {
1351
+ this.__tnCachedParams = null;
1352
+ this.__tnLastBuffer = null;
1353
+ this.__tnLastParams = null;
1354
+ }
1355
+
1356
+ set_meta_account_idx(value: number): this {
1357
+ this.view.setUint16(0, value, true);
1358
+ this.__tnInvalidate();
1359
+ return this;
1360
+ }
1361
+
1362
+ set_program_account_idx(value: number): this {
1363
+ this.view.setUint16(2, value, true);
1364
+ this.__tnInvalidate();
1365
+ return this;
1366
+ }
1367
+
1368
+ set_srcbuf_account_idx(value: number): this {
1369
+ this.view.setUint16(4, value, true);
1370
+ this.__tnInvalidate();
1371
+ return this;
1372
+ }
1373
+
1374
+ set_srcbuf_offset(value: number): this {
1375
+ this.view.setUint32(6, value, true);
1376
+ this.__tnInvalidate();
1377
+ return this;
1378
+ }
1379
+
1380
+ set_srcbuf_size(value: number): this {
1381
+ this.view.setUint32(10, value, true);
1382
+ this.__tnInvalidate();
1383
+ return this;
1384
+ }
1385
+
1386
+ set_authority_account_idx(value: number): this {
1387
+ this.view.setUint16(14, value, true);
1388
+ this.__tnInvalidate();
1389
+ return this;
1390
+ }
1391
+
1392
+ set_seed_len(value: number): this {
1393
+ this.view.setUint32(16, value, true);
1394
+ this.__tnInvalidate();
1395
+ return this;
1396
+ }
1397
+
1398
+ seed(): __TnFamWriterResult<CreateEphemeralArgsBuilder> {
1399
+ if (!this.__tnFamWriter_seed) {
1400
+ this.__tnFamWriter_seed = __tnCreateFamWriter(this, "seed", (payload) => {
1401
+ const bytes = new Uint8Array(payload);
1402
+ const elementCount = bytes.length;
1403
+ this.__tnFam_seed = bytes;
1404
+ this.__tnFam_seedCount = elementCount;
1405
+ this.set_seed_len(elementCount);
1406
+ this.__tnInvalidate();
1407
+ });
1408
+ }
1409
+ return this.__tnFamWriter_seed!;
1410
+ }
1411
+
1412
+ build(): Uint8Array {
1413
+ const params = this.__tnComputeParams();
1414
+ const size = CreateEphemeralArgs.footprintFromParams(params);
1415
+ const buffer = new Uint8Array(size);
1416
+ this.__tnWriteInto(buffer);
1417
+ this.__tnValidateOrThrow(buffer, params);
1418
+ return buffer;
1419
+ }
1420
+
1421
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1422
+ const params = this.__tnComputeParams();
1423
+ const size = CreateEphemeralArgs.footprintFromParams(params);
1424
+ if (target.length - offset < size) throw new Error("CreateEphemeralArgsBuilder: target buffer too small");
1425
+ const slice = target.subarray(offset, offset + size);
1426
+ this.__tnWriteInto(slice);
1427
+ this.__tnValidateOrThrow(slice, params);
1428
+ return target;
1429
+ }
1430
+
1431
+ finish(): CreateEphemeralArgs {
1432
+ const buffer = this.build();
1433
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1434
+ const view = CreateEphemeralArgs.from_array(buffer, { params });
1435
+ if (!view) throw new Error("CreateEphemeralArgsBuilder: failed to finalize view");
1436
+ return view;
1437
+ }
1438
+
1439
+ finishView(): CreateEphemeralArgs {
1440
+ return this.finish();
1441
+ }
1442
+
1443
+ dynamicParams(): CreateEphemeralArgs.Params {
1444
+ return this.__tnComputeParams();
1445
+ }
1446
+
1447
+ private __tnComputeParams(): CreateEphemeralArgs.Params {
1448
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1449
+ const params = CreateEphemeralArgs.Params.fromValues({
1450
+ seed_seed_len: (() => { if (this.__tnFam_seedCount === null) throw new Error("CreateEphemeralArgsBuilder: field 'seed' must be written before computing params"); return __tnToBigInt(this.__tnFam_seedCount); })(),
1451
+ });
1452
+ this.__tnCachedParams = params;
1453
+ return params;
1454
+ }
1455
+
1456
+ private __tnWriteInto(target: Uint8Array): void {
1457
+ target.set(this.buffer, 0);
1458
+ let cursor = this.buffer.length;
1459
+ const __tnLocal_seed_bytes = this.__tnFam_seed;
1460
+ if (!__tnLocal_seed_bytes) throw new Error("CreateEphemeralArgsBuilder: field 'seed' must be written before build");
1461
+ target.set(__tnLocal_seed_bytes, cursor);
1462
+ cursor += __tnLocal_seed_bytes.length;
1463
+ }
1464
+
1465
+ private __tnValidateOrThrow(buffer: Uint8Array, params: CreateEphemeralArgs.Params): void {
1466
+ const result = CreateEphemeralArgs.validate(buffer, { params });
1467
+ if (!result.ok) {
1468
+ throw new Error(`${ CreateEphemeralArgs }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1469
+ }
1470
+ this.__tnLastParams = result.params ?? params;
1471
+ this.__tnLastBuffer = buffer;
1472
+ }
1473
+ }
1474
+
1475
+ __tnRegisterFootprint("CreateEphemeralArgs", (params) => CreateEphemeralArgs.__tnInvokeFootprint(params));
1476
+ __tnRegisterValidate("CreateEphemeralArgs", (buffer, params) => CreateEphemeralArgs.__tnInvokeValidate(buffer, params));
1477
+ __tnRegisterDynamicValidate("CreateEphemeralArgs", (buffer) => { const result = CreateEphemeralArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1478
+
1479
+ /* ----- TYPE DEFINITION FOR HeaderOnlyArgs ----- */
1480
+
1481
+ const __tn_ir_HeaderOnlyArgs = {
1482
+ typeName: "HeaderOnlyArgs",
1483
+ root: { op: "const", value: 4n }
1484
+ } as const;
1485
+
1486
+ export class HeaderOnlyArgs {
1487
+ private view: DataView;
1488
+
1489
+ private constructor(private buffer: Uint8Array) {
1490
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1491
+ }
1492
+
1493
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): HeaderOnlyArgs {
1494
+ if (!buffer || buffer.length === undefined) throw new Error("HeaderOnlyArgs.__tnCreateView requires a Uint8Array");
1495
+ return new HeaderOnlyArgs(new Uint8Array(buffer));
1496
+ }
1497
+
1498
+ static builder(): HeaderOnlyArgsBuilder {
1499
+ return new HeaderOnlyArgsBuilder();
1500
+ }
1501
+
1502
+ static fromBuilder(builder: HeaderOnlyArgsBuilder): HeaderOnlyArgs | null {
1503
+ const buffer = builder.build();
1504
+ return HeaderOnlyArgs.from_array(buffer);
1505
+ }
1506
+
1507
+ get_meta_account_idx(): number {
1508
+ const offset = 0;
1509
+ return this.view.getUint16(offset, true); /* little-endian */
1510
+ }
1511
+
1512
+ set_meta_account_idx(value: number): void {
1513
+ const offset = 0;
1514
+ this.view.setUint16(offset, value, true); /* little-endian */
1515
+ }
1516
+
1517
+ get meta_account_idx(): number {
1518
+ return this.get_meta_account_idx();
1519
+ }
1520
+
1521
+ set meta_account_idx(value: number) {
1522
+ this.set_meta_account_idx(value);
1523
+ }
1524
+
1525
+ get_program_account_idx(): number {
1526
+ const offset = 2;
1527
+ return this.view.getUint16(offset, true); /* little-endian */
1528
+ }
1529
+
1530
+ set_program_account_idx(value: number): void {
1531
+ const offset = 2;
1532
+ this.view.setUint16(offset, value, true); /* little-endian */
1533
+ }
1534
+
1535
+ get program_account_idx(): number {
1536
+ return this.get_program_account_idx();
1537
+ }
1538
+
1539
+ set program_account_idx(value: number) {
1540
+ this.set_program_account_idx(value);
1541
+ }
1542
+
1543
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1544
+ return __tnEvalFootprint(__tn_ir_HeaderOnlyArgs.root, { params: __tnParams });
1545
+ }
1546
+
1547
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1548
+ return __tnValidateIrTree(__tn_ir_HeaderOnlyArgs, buffer, __tnParams);
1549
+ }
1550
+
1551
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1552
+ return this.__tnFootprintInternal(__tnParams);
1553
+ }
1554
+
1555
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1556
+ return this.__tnValidateInternal(buffer, __tnParams);
1557
+ }
1558
+
1559
+ static footprintIr(): bigint {
1560
+ return this.__tnFootprintInternal(Object.create(null));
1561
+ }
1562
+
1563
+ static footprint(): number {
1564
+ const irResult = this.footprintIr();
1565
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1566
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1567
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for HeaderOnlyArgs');
1568
+ }
1569
+ return __tnBigIntToNumber(irResult, 'HeaderOnlyArgs::footprint');
1570
+ }
1571
+
1572
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1573
+ if (buffer.length < 4) return { ok: false, code: "tn.buffer_too_small", consumed: 4 };
1574
+ return { ok: true, consumed: 4 };
1575
+ }
1576
+
1577
+ static new(meta_account_idx: number, program_account_idx: number): HeaderOnlyArgs {
1578
+ const buffer = new Uint8Array(4);
1579
+ const view = new DataView(buffer.buffer);
1580
+
1581
+ let offset = 0;
1582
+ view.setUint16(0, meta_account_idx, true); /* meta_account_idx (little-endian) */
1583
+ view.setUint16(2, program_account_idx, true); /* program_account_idx (little-endian) */
1584
+
1585
+ return new HeaderOnlyArgs(buffer);
1586
+ }
1587
+
1588
+ static from_array(buffer: Uint8Array): HeaderOnlyArgs | null {
1589
+ if (!buffer || buffer.length === undefined) {
1590
+ return null;
1591
+ }
1592
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1593
+ const validation = this.validate(buffer);
1594
+ if (!validation.ok) {
1595
+ return null;
1596
+ }
1597
+ return new HeaderOnlyArgs(buffer);
1598
+ }
1599
+
1600
+ }
1601
+
1602
+ export class HeaderOnlyArgsBuilder {
1603
+ private buffer: Uint8Array;
1604
+ private view: DataView;
1605
+
1606
+ constructor() {
1607
+ this.buffer = new Uint8Array(4);
1608
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1609
+ }
1610
+
1611
+ set_meta_account_idx(value: number): this {
1612
+ this.view.setUint16(0, value, true);
1613
+ return this;
1614
+ }
1615
+
1616
+ set_program_account_idx(value: number): this {
1617
+ this.view.setUint16(2, value, true);
1618
+ return this;
1619
+ }
1620
+
1621
+ build(): Uint8Array {
1622
+ return this.buffer.slice();
1623
+ }
1624
+
1625
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1626
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1627
+ target.set(this.buffer, offset);
1628
+ return target;
1629
+ }
1630
+
1631
+ finish(): HeaderOnlyArgs {
1632
+ const view = HeaderOnlyArgs.from_array(this.buffer.slice());
1633
+ if (!view) throw new Error("failed to build HeaderOnlyArgs");
1634
+ return view;
1635
+ }
1636
+ }
1637
+
1638
+ __tnRegisterFootprint("HeaderOnlyArgs", (params) => HeaderOnlyArgs.__tnInvokeFootprint(params));
1639
+ __tnRegisterValidate("HeaderOnlyArgs", (buffer, params) => HeaderOnlyArgs.__tnInvokeValidate(buffer, params));
1640
+ __tnRegisterDynamicValidate("HeaderOnlyArgs", (buffer) => { const result = HeaderOnlyArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1641
+
1642
+ /* ----- TYPE DEFINITION FOR ManagerError ----- */
1643
+
1644
+ const __tn_ir_ManagerError = {
1645
+ typeName: "ManagerError",
1646
+ root: { op: "const", value: 2n }
1647
+ } as const;
1648
+
1649
+ export class ManagerError {
1650
+ private view: DataView;
1651
+
1652
+ private constructor(private buffer: Uint8Array) {
1653
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1654
+ }
1655
+
1656
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): ManagerError {
1657
+ if (!buffer || buffer.length === undefined) throw new Error("ManagerError.__tnCreateView requires a Uint8Array");
1658
+ return new ManagerError(new Uint8Array(buffer));
1659
+ }
1660
+
1661
+ static builder(): ManagerErrorBuilder {
1662
+ return new ManagerErrorBuilder();
1663
+ }
1664
+
1665
+ static fromBuilder(builder: ManagerErrorBuilder): ManagerError | null {
1666
+ const buffer = builder.build();
1667
+ return ManagerError.from_array(buffer);
1668
+ }
1669
+
1670
+ get_code(): number {
1671
+ const offset = 0;
1672
+ return this.view.getUint16(offset, true); /* little-endian */
1673
+ }
1674
+
1675
+ set_code(value: number): void {
1676
+ const offset = 0;
1677
+ this.view.setUint16(offset, value, true); /* little-endian */
1678
+ }
1679
+
1680
+ get code(): number {
1681
+ return this.get_code();
1682
+ }
1683
+
1684
+ set code(value: number) {
1685
+ this.set_code(value);
1686
+ }
1687
+
1688
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1689
+ return __tnEvalFootprint(__tn_ir_ManagerError.root, { params: __tnParams });
1690
+ }
1691
+
1692
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1693
+ return __tnValidateIrTree(__tn_ir_ManagerError, buffer, __tnParams);
1694
+ }
1695
+
1696
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1697
+ return this.__tnFootprintInternal(__tnParams);
1698
+ }
1699
+
1700
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1701
+ return this.__tnValidateInternal(buffer, __tnParams);
1702
+ }
1703
+
1704
+ static footprintIr(): bigint {
1705
+ return this.__tnFootprintInternal(Object.create(null));
1706
+ }
1707
+
1708
+ static footprint(): number {
1709
+ const irResult = this.footprintIr();
1710
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1711
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1712
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for ManagerError');
1713
+ }
1714
+ return __tnBigIntToNumber(irResult, 'ManagerError::footprint');
1715
+ }
1716
+
1717
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1718
+ if (buffer.length < 2) return { ok: false, code: "tn.buffer_too_small", consumed: 2 };
1719
+ return { ok: true, consumed: 2 };
1720
+ }
1721
+
1722
+ static new(code: number): ManagerError {
1723
+ const buffer = new Uint8Array(2);
1724
+ const view = new DataView(buffer.buffer);
1725
+
1726
+ let offset = 0;
1727
+ view.setUint16(0, code, true); /* code (little-endian) */
1728
+
1729
+ return new ManagerError(buffer);
1730
+ }
1731
+
1732
+ static from_array(buffer: Uint8Array): ManagerError | null {
1733
+ if (!buffer || buffer.length === undefined) {
1734
+ return null;
1735
+ }
1736
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1737
+ const validation = this.validate(buffer);
1738
+ if (!validation.ok) {
1739
+ return null;
1740
+ }
1741
+ return new ManagerError(buffer);
1742
+ }
1743
+
1744
+ }
1745
+
1746
+ export class ManagerErrorBuilder {
1747
+ private buffer: Uint8Array;
1748
+ private view: DataView;
1749
+
1750
+ constructor() {
1751
+ this.buffer = new Uint8Array(2);
1752
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1753
+ }
1754
+
1755
+ set_code(value: number): this {
1756
+ this.view.setUint16(0, value, true);
1757
+ return this;
1758
+ }
1759
+
1760
+ build(): Uint8Array {
1761
+ return this.buffer.slice();
1762
+ }
1763
+
1764
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1765
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1766
+ target.set(this.buffer, offset);
1767
+ return target;
1768
+ }
1769
+
1770
+ finish(): ManagerError {
1771
+ const view = ManagerError.from_array(this.buffer.slice());
1772
+ if (!view) throw new Error("failed to build ManagerError");
1773
+ return view;
1774
+ }
1775
+ }
1776
+
1777
+ __tnRegisterFootprint("ManagerError", (params) => ManagerError.__tnInvokeFootprint(params));
1778
+ __tnRegisterValidate("ManagerError", (buffer, params) => ManagerError.__tnInvokeValidate(buffer, params));
1779
+ __tnRegisterDynamicValidate("ManagerError", (buffer) => { const result = ManagerError.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1780
+
1781
+ /* ----- TYPE DEFINITION FOR SetAuthorityArgs ----- */
1782
+
1783
+ const __tn_ir_SetAuthorityArgs = {
1784
+ typeName: "SetAuthorityArgs",
1785
+ root: { op: "const", value: 36n }
1786
+ } as const;
1787
+
1788
+ export class SetAuthorityArgs {
1789
+ private view: DataView;
1790
+
1791
+ private constructor(private buffer: Uint8Array) {
1792
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1793
+ }
1794
+
1795
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): SetAuthorityArgs {
1796
+ if (!buffer || buffer.length === undefined) throw new Error("SetAuthorityArgs.__tnCreateView requires a Uint8Array");
1797
+ return new SetAuthorityArgs(new Uint8Array(buffer));
1798
+ }
1799
+
1800
+ static builder(): SetAuthorityArgsBuilder {
1801
+ return new SetAuthorityArgsBuilder();
1802
+ }
1803
+
1804
+ static fromBuilder(builder: SetAuthorityArgsBuilder): SetAuthorityArgs | null {
1805
+ const buffer = builder.build();
1806
+ return SetAuthorityArgs.from_array(buffer);
1807
+ }
1808
+
1809
+ get_meta_account_idx(): number {
1810
+ const offset = 0;
1811
+ return this.view.getUint16(offset, true); /* little-endian */
1812
+ }
1813
+
1814
+ set_meta_account_idx(value: number): void {
1815
+ const offset = 0;
1816
+ this.view.setUint16(offset, value, true); /* little-endian */
1817
+ }
1818
+
1819
+ get meta_account_idx(): number {
1820
+ return this.get_meta_account_idx();
1821
+ }
1822
+
1823
+ set meta_account_idx(value: number) {
1824
+ this.set_meta_account_idx(value);
1825
+ }
1826
+
1827
+ get_program_account_idx(): number {
1828
+ const offset = 2;
1829
+ return this.view.getUint16(offset, true); /* little-endian */
1830
+ }
1831
+
1832
+ set_program_account_idx(value: number): void {
1833
+ const offset = 2;
1834
+ this.view.setUint16(offset, value, true); /* little-endian */
1835
+ }
1836
+
1837
+ get program_account_idx(): number {
1838
+ return this.get_program_account_idx();
1839
+ }
1840
+
1841
+ set program_account_idx(value: number) {
1842
+ this.set_program_account_idx(value);
1843
+ }
1844
+
1845
+ get_authority_candidate(): Pubkey {
1846
+ const offset = 4;
1847
+ const slice = this.buffer.subarray(offset, offset + 32);
1848
+ return Pubkey.from_array(slice)!;
1849
+ }
1850
+
1851
+ set_authority_candidate(value: Pubkey): void {
1852
+ /* Copy bytes from source struct to this field */
1853
+ const sourceBytes = (value as any).buffer as Uint8Array;
1854
+ const offset = 4;
1855
+ this.buffer.set(sourceBytes, offset);
1856
+ }
1857
+
1858
+ get authority_candidate(): Pubkey {
1859
+ return this.get_authority_candidate();
1860
+ }
1861
+
1862
+ set authority_candidate(value: Pubkey) {
1863
+ this.set_authority_candidate(value);
1864
+ }
1865
+
1866
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1867
+ return __tnEvalFootprint(__tn_ir_SetAuthorityArgs.root, { params: __tnParams });
1868
+ }
1869
+
1870
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1871
+ return __tnValidateIrTree(__tn_ir_SetAuthorityArgs, buffer, __tnParams);
1872
+ }
1873
+
1874
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1875
+ return this.__tnFootprintInternal(__tnParams);
1876
+ }
1877
+
1878
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1879
+ return this.__tnValidateInternal(buffer, __tnParams);
1880
+ }
1881
+
1882
+ static footprintIr(): bigint {
1883
+ return this.__tnFootprintInternal(Object.create(null));
1884
+ }
1885
+
1886
+ static footprint(): number {
1887
+ const irResult = this.footprintIr();
1888
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1889
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1890
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for SetAuthorityArgs');
1891
+ }
1892
+ return __tnBigIntToNumber(irResult, 'SetAuthorityArgs::footprint');
1893
+ }
1894
+
1895
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1896
+ if (buffer.length < 36) return { ok: false, code: "tn.buffer_too_small", consumed: 36 };
1897
+ return { ok: true, consumed: 36 };
1898
+ }
1899
+
1900
+ static from_array(buffer: Uint8Array): SetAuthorityArgs | null {
1901
+ if (!buffer || buffer.length === undefined) {
1902
+ return null;
1903
+ }
1904
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1905
+ const validation = this.validate(buffer);
1906
+ if (!validation.ok) {
1907
+ return null;
1908
+ }
1909
+ return new SetAuthorityArgs(buffer);
1910
+ }
1911
+
1912
+ }
1913
+
1914
+ export class SetAuthorityArgsBuilder {
1915
+ private buffer: Uint8Array;
1916
+ private view: DataView;
1917
+
1918
+ constructor() {
1919
+ this.buffer = new Uint8Array(36);
1920
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1921
+ }
1922
+
1923
+ set_meta_account_idx(value: number): this {
1924
+ this.view.setUint16(0, value, true);
1925
+ return this;
1926
+ }
1927
+
1928
+ set_program_account_idx(value: number): this {
1929
+ this.view.setUint16(2, value, true);
1930
+ return this;
1931
+ }
1932
+
1933
+ set_authority_candidate(value: Uint8Array): this {
1934
+ if (value.length !== 32) throw new Error("authority_candidate expects 32 bytes");
1935
+ this.buffer.set(value, 4);
1936
+ return this;
1937
+ }
1938
+
1939
+ build(): Uint8Array {
1940
+ return this.buffer.slice();
1941
+ }
1942
+
1943
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1944
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1945
+ target.set(this.buffer, offset);
1946
+ return target;
1947
+ }
1948
+
1949
+ finish(): SetAuthorityArgs {
1950
+ const view = SetAuthorityArgs.from_array(this.buffer.slice());
1951
+ if (!view) throw new Error("failed to build SetAuthorityArgs");
1952
+ return view;
1953
+ }
1954
+ }
1955
+
1956
+ __tnRegisterFootprint("SetAuthorityArgs", (params) => SetAuthorityArgs.__tnInvokeFootprint(params));
1957
+ __tnRegisterValidate("SetAuthorityArgs", (buffer, params) => SetAuthorityArgs.__tnInvokeValidate(buffer, params));
1958
+ __tnRegisterDynamicValidate("SetAuthorityArgs", (buffer) => { const result = SetAuthorityArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
1959
+
1960
+ /* ----- TYPE DEFINITION FOR SetPauseArgs ----- */
1961
+
1962
+ const __tn_ir_SetPauseArgs = {
1963
+ typeName: "SetPauseArgs",
1964
+ root: { op: "const", value: 5n }
1965
+ } as const;
1966
+
1967
+ export class SetPauseArgs {
1968
+ private view: DataView;
1969
+
1970
+ private constructor(private buffer: Uint8Array) {
1971
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1972
+ }
1973
+
1974
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): SetPauseArgs {
1975
+ if (!buffer || buffer.length === undefined) throw new Error("SetPauseArgs.__tnCreateView requires a Uint8Array");
1976
+ return new SetPauseArgs(new Uint8Array(buffer));
1977
+ }
1978
+
1979
+ static builder(): SetPauseArgsBuilder {
1980
+ return new SetPauseArgsBuilder();
1981
+ }
1982
+
1983
+ static fromBuilder(builder: SetPauseArgsBuilder): SetPauseArgs | null {
1984
+ const buffer = builder.build();
1985
+ return SetPauseArgs.from_array(buffer);
1986
+ }
1987
+
1988
+ get_meta_account_idx(): number {
1989
+ const offset = 0;
1990
+ return this.view.getUint16(offset, true); /* little-endian */
1991
+ }
1992
+
1993
+ set_meta_account_idx(value: number): void {
1994
+ const offset = 0;
1995
+ this.view.setUint16(offset, value, true); /* little-endian */
1996
+ }
1997
+
1998
+ get meta_account_idx(): number {
1999
+ return this.get_meta_account_idx();
2000
+ }
2001
+
2002
+ set meta_account_idx(value: number) {
2003
+ this.set_meta_account_idx(value);
2004
+ }
2005
+
2006
+ get_program_account_idx(): number {
2007
+ const offset = 2;
2008
+ return this.view.getUint16(offset, true); /* little-endian */
2009
+ }
2010
+
2011
+ set_program_account_idx(value: number): void {
2012
+ const offset = 2;
2013
+ this.view.setUint16(offset, value, true); /* little-endian */
2014
+ }
2015
+
2016
+ get program_account_idx(): number {
2017
+ return this.get_program_account_idx();
2018
+ }
2019
+
2020
+ set program_account_idx(value: number) {
2021
+ this.set_program_account_idx(value);
2022
+ }
2023
+
2024
+ get_is_paused(): number {
2025
+ const offset = 4;
2026
+ return this.view.getUint8(offset);
2027
+ }
2028
+
2029
+ set_is_paused(value: number): void {
2030
+ const offset = 4;
2031
+ this.view.setUint8(offset, value);
2032
+ }
2033
+
2034
+ get is_paused(): number {
2035
+ return this.get_is_paused();
2036
+ }
2037
+
2038
+ set is_paused(value: number) {
2039
+ this.set_is_paused(value);
2040
+ }
2041
+
2042
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2043
+ return __tnEvalFootprint(__tn_ir_SetPauseArgs.root, { params: __tnParams });
2044
+ }
2045
+
2046
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2047
+ return __tnValidateIrTree(__tn_ir_SetPauseArgs, buffer, __tnParams);
2048
+ }
2049
+
2050
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2051
+ return this.__tnFootprintInternal(__tnParams);
2052
+ }
2053
+
2054
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2055
+ return this.__tnValidateInternal(buffer, __tnParams);
2056
+ }
2057
+
2058
+ static footprintIr(): bigint {
2059
+ return this.__tnFootprintInternal(Object.create(null));
2060
+ }
2061
+
2062
+ static footprint(): number {
2063
+ const irResult = this.footprintIr();
2064
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2065
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2066
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for SetPauseArgs');
2067
+ }
2068
+ return __tnBigIntToNumber(irResult, 'SetPauseArgs::footprint');
2069
+ }
2070
+
2071
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2072
+ if (buffer.length < 5) return { ok: false, code: "tn.buffer_too_small", consumed: 5 };
2073
+ return { ok: true, consumed: 5 };
2074
+ }
2075
+
2076
+ static new(meta_account_idx: number, program_account_idx: number, is_paused: number): SetPauseArgs {
2077
+ const buffer = new Uint8Array(5);
2078
+ const view = new DataView(buffer.buffer);
2079
+
2080
+ let offset = 0;
2081
+ view.setUint16(0, meta_account_idx, true); /* meta_account_idx (little-endian) */
2082
+ view.setUint16(2, program_account_idx, true); /* program_account_idx (little-endian) */
2083
+ view.setUint8(4, is_paused); /* is_paused */
2084
+
2085
+ return new SetPauseArgs(buffer);
2086
+ }
2087
+
2088
+ static from_array(buffer: Uint8Array): SetPauseArgs | null {
2089
+ if (!buffer || buffer.length === undefined) {
2090
+ return null;
2091
+ }
2092
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2093
+ const validation = this.validate(buffer);
2094
+ if (!validation.ok) {
2095
+ return null;
2096
+ }
2097
+ return new SetPauseArgs(buffer);
2098
+ }
2099
+
2100
+ }
2101
+
2102
+ export class SetPauseArgsBuilder {
2103
+ private buffer: Uint8Array;
2104
+ private view: DataView;
2105
+
2106
+ constructor() {
2107
+ this.buffer = new Uint8Array(5);
2108
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2109
+ }
2110
+
2111
+ set_meta_account_idx(value: number): this {
2112
+ this.view.setUint16(0, value, true);
2113
+ return this;
2114
+ }
2115
+
2116
+ set_program_account_idx(value: number): this {
2117
+ this.view.setUint16(2, value, true);
2118
+ return this;
2119
+ }
2120
+
2121
+ set_is_paused(value: number): this {
2122
+ this.view.setUint8(4, value);
2123
+ return this;
2124
+ }
2125
+
2126
+ build(): Uint8Array {
2127
+ return this.buffer.slice();
2128
+ }
2129
+
2130
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2131
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2132
+ target.set(this.buffer, offset);
2133
+ return target;
2134
+ }
2135
+
2136
+ finish(): SetPauseArgs {
2137
+ const view = SetPauseArgs.from_array(this.buffer.slice());
2138
+ if (!view) throw new Error("failed to build SetPauseArgs");
2139
+ return view;
2140
+ }
2141
+ }
2142
+
2143
+ __tnRegisterFootprint("SetPauseArgs", (params) => SetPauseArgs.__tnInvokeFootprint(params));
2144
+ __tnRegisterValidate("SetPauseArgs", (buffer, params) => SetPauseArgs.__tnInvokeValidate(buffer, params));
2145
+ __tnRegisterDynamicValidate("SetPauseArgs", (buffer) => { const result = SetPauseArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
2146
+
2147
+ /* ----- TYPE DEFINITION FOR UpgradeArgs ----- */
2148
+
2149
+ const __tn_ir_UpgradeArgs = {
2150
+ typeName: "UpgradeArgs",
2151
+ root: { op: "const", value: 14n }
2152
+ } as const;
2153
+
2154
+ export class UpgradeArgs {
2155
+ private view: DataView;
2156
+
2157
+ private constructor(private buffer: Uint8Array) {
2158
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2159
+ }
2160
+
2161
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): UpgradeArgs {
2162
+ if (!buffer || buffer.length === undefined) throw new Error("UpgradeArgs.__tnCreateView requires a Uint8Array");
2163
+ return new UpgradeArgs(new Uint8Array(buffer));
2164
+ }
2165
+
2166
+ static builder(): UpgradeArgsBuilder {
2167
+ return new UpgradeArgsBuilder();
2168
+ }
2169
+
2170
+ static fromBuilder(builder: UpgradeArgsBuilder): UpgradeArgs | null {
2171
+ const buffer = builder.build();
2172
+ return UpgradeArgs.from_array(buffer);
2173
+ }
2174
+
2175
+ get_meta_account_idx(): number {
2176
+ const offset = 0;
2177
+ return this.view.getUint16(offset, true); /* little-endian */
2178
+ }
2179
+
2180
+ set_meta_account_idx(value: number): void {
2181
+ const offset = 0;
2182
+ this.view.setUint16(offset, value, true); /* little-endian */
2183
+ }
2184
+
2185
+ get meta_account_idx(): number {
2186
+ return this.get_meta_account_idx();
2187
+ }
2188
+
2189
+ set meta_account_idx(value: number) {
2190
+ this.set_meta_account_idx(value);
2191
+ }
2192
+
2193
+ get_program_account_idx(): number {
2194
+ const offset = 2;
2195
+ return this.view.getUint16(offset, true); /* little-endian */
2196
+ }
2197
+
2198
+ set_program_account_idx(value: number): void {
2199
+ const offset = 2;
2200
+ this.view.setUint16(offset, value, true); /* little-endian */
2201
+ }
2202
+
2203
+ get program_account_idx(): number {
2204
+ return this.get_program_account_idx();
2205
+ }
2206
+
2207
+ set program_account_idx(value: number) {
2208
+ this.set_program_account_idx(value);
2209
+ }
2210
+
2211
+ get_srcbuf_account_idx(): number {
2212
+ const offset = 4;
2213
+ return this.view.getUint16(offset, true); /* little-endian */
2214
+ }
2215
+
2216
+ set_srcbuf_account_idx(value: number): void {
2217
+ const offset = 4;
2218
+ this.view.setUint16(offset, value, true); /* little-endian */
2219
+ }
2220
+
2221
+ get srcbuf_account_idx(): number {
2222
+ return this.get_srcbuf_account_idx();
2223
+ }
2224
+
2225
+ set srcbuf_account_idx(value: number) {
2226
+ this.set_srcbuf_account_idx(value);
2227
+ }
2228
+
2229
+ get_srcbuf_offset(): number {
2230
+ const offset = 6;
2231
+ return this.view.getUint32(offset, true); /* little-endian */
2232
+ }
2233
+
2234
+ set_srcbuf_offset(value: number): void {
2235
+ const offset = 6;
2236
+ this.view.setUint32(offset, value, true); /* little-endian */
2237
+ }
2238
+
2239
+ get srcbuf_offset(): number {
2240
+ return this.get_srcbuf_offset();
2241
+ }
2242
+
2243
+ set srcbuf_offset(value: number) {
2244
+ this.set_srcbuf_offset(value);
2245
+ }
2246
+
2247
+ get_srcbuf_size(): number {
2248
+ const offset = 10;
2249
+ return this.view.getUint32(offset, true); /* little-endian */
2250
+ }
2251
+
2252
+ set_srcbuf_size(value: number): void {
2253
+ const offset = 10;
2254
+ this.view.setUint32(offset, value, true); /* little-endian */
2255
+ }
2256
+
2257
+ get srcbuf_size(): number {
2258
+ return this.get_srcbuf_size();
2259
+ }
2260
+
2261
+ set srcbuf_size(value: number) {
2262
+ this.set_srcbuf_size(value);
2263
+ }
2264
+
2265
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2266
+ return __tnEvalFootprint(__tn_ir_UpgradeArgs.root, { params: __tnParams });
2267
+ }
2268
+
2269
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2270
+ return __tnValidateIrTree(__tn_ir_UpgradeArgs, buffer, __tnParams);
2271
+ }
2272
+
2273
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2274
+ return this.__tnFootprintInternal(__tnParams);
2275
+ }
2276
+
2277
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2278
+ return this.__tnValidateInternal(buffer, __tnParams);
2279
+ }
2280
+
2281
+ static footprintIr(): bigint {
2282
+ return this.__tnFootprintInternal(Object.create(null));
2283
+ }
2284
+
2285
+ static footprint(): number {
2286
+ const irResult = this.footprintIr();
2287
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2288
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2289
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for UpgradeArgs');
2290
+ }
2291
+ return __tnBigIntToNumber(irResult, 'UpgradeArgs::footprint');
2292
+ }
2293
+
2294
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2295
+ if (buffer.length < 14) return { ok: false, code: "tn.buffer_too_small", consumed: 14 };
2296
+ return { ok: true, consumed: 14 };
2297
+ }
2298
+
2299
+ static new(meta_account_idx: number, program_account_idx: number, srcbuf_account_idx: number, srcbuf_offset: number, srcbuf_size: number): UpgradeArgs {
2300
+ const buffer = new Uint8Array(14);
2301
+ const view = new DataView(buffer.buffer);
2302
+
2303
+ let offset = 0;
2304
+ view.setUint16(0, meta_account_idx, true); /* meta_account_idx (little-endian) */
2305
+ view.setUint16(2, program_account_idx, true); /* program_account_idx (little-endian) */
2306
+ view.setUint16(4, srcbuf_account_idx, true); /* srcbuf_account_idx (little-endian) */
2307
+ view.setUint32(6, srcbuf_offset, true); /* srcbuf_offset (little-endian) */
2308
+ view.setUint32(10, srcbuf_size, true); /* srcbuf_size (little-endian) */
2309
+
2310
+ return new UpgradeArgs(buffer);
2311
+ }
2312
+
2313
+ static from_array(buffer: Uint8Array): UpgradeArgs | null {
2314
+ if (!buffer || buffer.length === undefined) {
2315
+ return null;
2316
+ }
2317
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2318
+ const validation = this.validate(buffer);
2319
+ if (!validation.ok) {
2320
+ return null;
2321
+ }
2322
+ return new UpgradeArgs(buffer);
2323
+ }
2324
+
2325
+ }
2326
+
2327
+ export class UpgradeArgsBuilder {
2328
+ private buffer: Uint8Array;
2329
+ private view: DataView;
2330
+
2331
+ constructor() {
2332
+ this.buffer = new Uint8Array(14);
2333
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2334
+ }
2335
+
2336
+ set_meta_account_idx(value: number): this {
2337
+ this.view.setUint16(0, value, true);
2338
+ return this;
2339
+ }
2340
+
2341
+ set_program_account_idx(value: number): this {
2342
+ this.view.setUint16(2, value, true);
2343
+ return this;
2344
+ }
2345
+
2346
+ set_srcbuf_account_idx(value: number): this {
2347
+ this.view.setUint16(4, value, true);
2348
+ return this;
2349
+ }
2350
+
2351
+ set_srcbuf_offset(value: number): this {
2352
+ this.view.setUint32(6, value, true);
2353
+ return this;
2354
+ }
2355
+
2356
+ set_srcbuf_size(value: number): this {
2357
+ this.view.setUint32(10, value, true);
2358
+ return this;
2359
+ }
2360
+
2361
+ build(): Uint8Array {
2362
+ return this.buffer.slice();
2363
+ }
2364
+
2365
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2366
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2367
+ target.set(this.buffer, offset);
2368
+ return target;
2369
+ }
2370
+
2371
+ finish(): UpgradeArgs {
2372
+ const view = UpgradeArgs.from_array(this.buffer.slice());
2373
+ if (!view) throw new Error("failed to build UpgradeArgs");
2374
+ return view;
2375
+ }
2376
+ }
2377
+
2378
+ __tnRegisterFootprint("UpgradeArgs", (params) => UpgradeArgs.__tnInvokeFootprint(params));
2379
+ __tnRegisterValidate("UpgradeArgs", (buffer, params) => UpgradeArgs.__tnInvokeValidate(buffer, params));
2380
+ __tnRegisterDynamicValidate("UpgradeArgs", (buffer) => { const result = UpgradeArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
2381
+
2382
+ /* ----- TYPE DEFINITION FOR ManagerProgramMeta ----- */
2383
+
2384
+ const __tn_ir_ManagerProgramMeta = {
2385
+ typeName: "ManagerProgramMeta",
2386
+ root: { op: "const", value: 73n }
2387
+ } as const;
2388
+
2389
+ export class ManagerProgramMeta {
2390
+ private view: DataView;
2391
+
2392
+ private constructor(private buffer: Uint8Array) {
2393
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2394
+ }
2395
+
2396
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): ManagerProgramMeta {
2397
+ if (!buffer || buffer.length === undefined) throw new Error("ManagerProgramMeta.__tnCreateView requires a Uint8Array");
2398
+ return new ManagerProgramMeta(new Uint8Array(buffer));
2399
+ }
2400
+
2401
+ static builder(): ManagerProgramMetaBuilder {
2402
+ return new ManagerProgramMetaBuilder();
2403
+ }
2404
+
2405
+ static fromBuilder(builder: ManagerProgramMetaBuilder): ManagerProgramMeta | null {
2406
+ const buffer = builder.build();
2407
+ return ManagerProgramMeta.from_array(buffer);
2408
+ }
2409
+
2410
+ get_authority(): Pubkey {
2411
+ const offset = 0;
2412
+ const slice = this.buffer.subarray(offset, offset + 32);
2413
+ return Pubkey.from_array(slice)!;
2414
+ }
2415
+
2416
+ set_authority(value: Pubkey): void {
2417
+ /* Copy bytes from source struct to this field */
2418
+ const sourceBytes = (value as any).buffer as Uint8Array;
2419
+ const offset = 0;
2420
+ this.buffer.set(sourceBytes, offset);
2421
+ }
2422
+
2423
+ get authority(): Pubkey {
2424
+ return this.get_authority();
2425
+ }
2426
+
2427
+ set authority(value: Pubkey) {
2428
+ this.set_authority(value);
2429
+ }
2430
+
2431
+ get_authority_candidate(): Pubkey {
2432
+ const offset = 32;
2433
+ const slice = this.buffer.subarray(offset, offset + 32);
2434
+ return Pubkey.from_array(slice)!;
2435
+ }
2436
+
2437
+ set_authority_candidate(value: Pubkey): void {
2438
+ /* Copy bytes from source struct to this field */
2439
+ const sourceBytes = (value as any).buffer as Uint8Array;
2440
+ const offset = 32;
2441
+ this.buffer.set(sourceBytes, offset);
2442
+ }
2443
+
2444
+ get authority_candidate(): Pubkey {
2445
+ return this.get_authority_candidate();
2446
+ }
2447
+
2448
+ set authority_candidate(value: Pubkey) {
2449
+ this.set_authority_candidate(value);
2450
+ }
2451
+
2452
+ get_version(): bigint {
2453
+ const offset = 64;
2454
+ return this.view.getBigUint64(offset, true); /* little-endian */
2455
+ }
2456
+
2457
+ set_version(value: bigint): void {
2458
+ const offset = 64;
2459
+ this.view.setBigUint64(offset, value, true); /* little-endian */
2460
+ }
2461
+
2462
+ get version(): bigint {
2463
+ return this.get_version();
2464
+ }
2465
+
2466
+ set version(value: bigint) {
2467
+ this.set_version(value);
2468
+ }
2469
+
2470
+ get_state(): number {
2471
+ const offset = 72;
2472
+ return this.view.getUint8(offset);
2473
+ }
2474
+
2475
+ set_state(value: number): void {
2476
+ const offset = 72;
2477
+ this.view.setUint8(offset, value);
2478
+ }
2479
+
2480
+ get state(): number {
2481
+ return this.get_state();
2482
+ }
2483
+
2484
+ set state(value: number) {
2485
+ this.set_state(value);
2486
+ }
2487
+
2488
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2489
+ return __tnEvalFootprint(__tn_ir_ManagerProgramMeta.root, { params: __tnParams });
2490
+ }
2491
+
2492
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2493
+ return __tnValidateIrTree(__tn_ir_ManagerProgramMeta, buffer, __tnParams);
2494
+ }
2495
+
2496
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2497
+ return this.__tnFootprintInternal(__tnParams);
2498
+ }
2499
+
2500
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2501
+ return this.__tnValidateInternal(buffer, __tnParams);
2502
+ }
2503
+
2504
+ static footprintIr(): bigint {
2505
+ return this.__tnFootprintInternal(Object.create(null));
2506
+ }
2507
+
2508
+ static footprint(): number {
2509
+ const irResult = this.footprintIr();
2510
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2511
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2512
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for ManagerProgramMeta');
2513
+ }
2514
+ return __tnBigIntToNumber(irResult, 'ManagerProgramMeta::footprint');
2515
+ }
2516
+
2517
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2518
+ if (buffer.length < 73) return { ok: false, code: "tn.buffer_too_small", consumed: 73 };
2519
+ return { ok: true, consumed: 73 };
2520
+ }
2521
+
2522
+ static from_array(buffer: Uint8Array): ManagerProgramMeta | null {
2523
+ if (!buffer || buffer.length === undefined) {
2524
+ return null;
2525
+ }
2526
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2527
+ const validation = this.validate(buffer);
2528
+ if (!validation.ok) {
2529
+ return null;
2530
+ }
2531
+ return new ManagerProgramMeta(buffer);
2532
+ }
2533
+
2534
+ }
2535
+
2536
+ export class ManagerProgramMetaBuilder {
2537
+ private buffer: Uint8Array;
2538
+ private view: DataView;
2539
+
2540
+ constructor() {
2541
+ this.buffer = new Uint8Array(73);
2542
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2543
+ }
2544
+
2545
+ set_authority(value: Uint8Array): this {
2546
+ if (value.length !== 32) throw new Error("authority expects 32 bytes");
2547
+ this.buffer.set(value, 0);
2548
+ return this;
2549
+ }
2550
+
2551
+ set_authority_candidate(value: Uint8Array): this {
2552
+ if (value.length !== 32) throw new Error("authority_candidate expects 32 bytes");
2553
+ this.buffer.set(value, 32);
2554
+ return this;
2555
+ }
2556
+
2557
+ set_version(value: bigint): this {
2558
+ const cast = __tnToBigInt(value);
2559
+ this.view.setBigUint64(64, cast, true);
2560
+ return this;
2561
+ }
2562
+
2563
+ set_state(value: number): this {
2564
+ this.view.setUint8(72, value);
2565
+ return this;
2566
+ }
2567
+
2568
+ build(): Uint8Array {
2569
+ return this.buffer.slice();
2570
+ }
2571
+
2572
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2573
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2574
+ target.set(this.buffer, offset);
2575
+ return target;
2576
+ }
2577
+
2578
+ finish(): ManagerProgramMeta {
2579
+ const view = ManagerProgramMeta.from_array(this.buffer.slice());
2580
+ if (!view) throw new Error("failed to build ManagerProgramMeta");
2581
+ return view;
2582
+ }
2583
+ }
2584
+
2585
+ __tnRegisterFootprint("ManagerProgramMeta", (params) => ManagerProgramMeta.__tnInvokeFootprint(params));
2586
+ __tnRegisterValidate("ManagerProgramMeta", (buffer, params) => ManagerProgramMeta.__tnInvokeValidate(buffer, params));
2587
+ __tnRegisterDynamicValidate("ManagerProgramMeta", (buffer) => { const result = ManagerProgramMeta.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
2588
+
2589
+ /* ----- TYPE DEFINITION FOR CreatePermanentArgs ----- */
2590
+
2591
+ const __tn_ir_CreatePermanentArgs = {
2592
+ typeName: "CreatePermanentArgs",
2593
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "seed.seed_len" }, right: { op: "const", value: 1n } } } }, right: { op: "align", alignment: 1, node: { op: "call", typeName: "StateProof", args: [{ name: "proof_body.hdr.type_slot", source: "proof_body.hdr.type_slot" }, { name: "proof_body.payload_size", source: "proof_body.payload_size" }] } } }, right: { op: "align", alignment: 1, node: { op: "call", typeName: "StateProof", args: [{ name: "proof_body.hdr.type_slot", source: "proof_body.hdr.type_slot" }, { name: "proof_body.payload_size", source: "proof_body.payload_size" }] } } } }
2594
+ } as const;
2595
+
2596
+ export class CreatePermanentArgs {
2597
+ private view: DataView;
2598
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
2599
+ private __tnParams: CreatePermanentArgs.Params;
2600
+
2601
+ private constructor(private buffer: Uint8Array, params?: CreatePermanentArgs.Params, fieldContext?: Record<string, number | bigint>) {
2602
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2603
+ this.__tnFieldContext = fieldContext ?? null;
2604
+ if (params) {
2605
+ this.__tnParams = params;
2606
+ } else {
2607
+ const derived = CreatePermanentArgs.__tnExtractParams(this.view, buffer);
2608
+ if (!derived) {
2609
+ throw new Error("CreatePermanentArgs: failed to derive dynamic parameters");
2610
+ }
2611
+ this.__tnParams = derived.params;
2612
+ }
2613
+ }
2614
+
2615
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: CreatePermanentArgs.Params, fieldContext?: Record<string, number | bigint> }): CreatePermanentArgs {
2616
+ if (!buffer || buffer.length === undefined) throw new Error("CreatePermanentArgs.__tnCreateView requires a Uint8Array");
2617
+ let params = opts?.params ?? null;
2618
+ if (!params) {
2619
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2620
+ const derived = CreatePermanentArgs.__tnExtractParams(view, buffer);
2621
+ if (!derived) throw new Error("CreatePermanentArgs.__tnCreateView: failed to derive params");
2622
+ params = derived.params;
2623
+ }
2624
+ const instance = new CreatePermanentArgs(new Uint8Array(buffer), params, opts?.fieldContext);
2625
+ return instance;
2626
+ }
2627
+
2628
+ dynamicParams(): CreatePermanentArgs.Params {
2629
+ return this.__tnParams;
2630
+ }
2631
+
2632
+ withFieldContext(context: Record<string, number | bigint>): this {
2633
+ this.__tnFieldContext = context;
2634
+ return this;
2635
+ }
2636
+
2637
+ private __tnResolveFieldRef(path: string): number {
2638
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
2639
+ const getter = (this as any)[getterName];
2640
+ if (typeof getter === "function") {
2641
+ const value = getter.call(this);
2642
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "CreatePermanentArgs::__tnResolveFieldRef") : value;
2643
+ }
2644
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
2645
+ const contextValue = this.__tnFieldContext[path];
2646
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "CreatePermanentArgs::__tnResolveFieldRef") : contextValue;
2647
+ }
2648
+ throw new Error("CreatePermanentArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
2649
+ }
2650
+
2651
+ static builder(): CreatePermanentArgsBuilder {
2652
+ return new CreatePermanentArgsBuilder();
2653
+ }
2654
+
2655
+ static fromBuilder(builder: CreatePermanentArgsBuilder): CreatePermanentArgs | null {
2656
+ const buffer = builder.build();
2657
+ const params = builder.dynamicParams();
2658
+ return CreatePermanentArgs.from_array(buffer, { params });
2659
+ }
2660
+
2661
+ static readonly flexibleArrayWriters = Object.freeze([
2662
+ { field: "seed", method: "seed", sizeField: "seed_len", paramKey: "seed_len", elementSize: 1 },
2663
+ ] as const);
2664
+
2665
+ static __tnComputeSequentialLayout(view: DataView, buffer: Uint8Array): { params: Record<string, bigint> | null; offsets: Record<string, number> | null; derived: Record<string, bigint> | null } | null {
2666
+ const offsets: Record<string, number> = Object.create(null);
2667
+ const __tnLength = buffer.length;
2668
+ let __tnParamSeq_proof_body_hdr_type_slot: bigint | null = null;
2669
+ let __tnParamSeq_proof_body_payload_size: bigint | null = null;
2670
+ let __tnFieldValue_meta_account_idx: number | null = null;
2671
+ let __tnFieldValue_program_account_idx: number | null = null;
2672
+ let __tnFieldValue_srcbuf_account_idx: number | null = null;
2673
+ let __tnFieldValue_srcbuf_offset: number | null = null;
2674
+ let __tnFieldValue_srcbuf_size: number | null = null;
2675
+ let __tnFieldValue_authority_account_idx: number | null = null;
2676
+ let __tnFieldValue_seed_len: number | null = null;
2677
+ let __tnCursorMutable = 0;
2678
+ if (__tnCursorMutable + 2 > __tnLength) return null;
2679
+ const __tnRead_meta_account_idx = view.getUint16(__tnCursorMutable, true);
2680
+ __tnFieldValue_meta_account_idx = __tnRead_meta_account_idx;
2681
+ __tnCursorMutable += 2;
2682
+ if (__tnCursorMutable + 2 > __tnLength) return null;
2683
+ const __tnRead_program_account_idx = view.getUint16(__tnCursorMutable, true);
2684
+ __tnFieldValue_program_account_idx = __tnRead_program_account_idx;
2685
+ __tnCursorMutable += 2;
2686
+ if (__tnCursorMutable + 2 > __tnLength) return null;
2687
+ const __tnRead_srcbuf_account_idx = view.getUint16(__tnCursorMutable, true);
2688
+ __tnFieldValue_srcbuf_account_idx = __tnRead_srcbuf_account_idx;
2689
+ __tnCursorMutable += 2;
2690
+ if (__tnCursorMutable + 4 > __tnLength) return null;
2691
+ const __tnRead_srcbuf_offset = view.getUint32(__tnCursorMutable, true);
2692
+ __tnFieldValue_srcbuf_offset = __tnRead_srcbuf_offset;
2693
+ __tnCursorMutable += 4;
2694
+ if (__tnCursorMutable + 4 > __tnLength) return null;
2695
+ const __tnRead_srcbuf_size = view.getUint32(__tnCursorMutable, true);
2696
+ __tnFieldValue_srcbuf_size = __tnRead_srcbuf_size;
2697
+ __tnCursorMutable += 4;
2698
+ if (__tnCursorMutable + 2 > __tnLength) return null;
2699
+ const __tnRead_authority_account_idx = view.getUint16(__tnCursorMutable, true);
2700
+ __tnFieldValue_authority_account_idx = __tnRead_authority_account_idx;
2701
+ __tnCursorMutable += 2;
2702
+ if (__tnCursorMutable + 4 > __tnLength) return null;
2703
+ const __tnRead_seed_len = view.getUint32(__tnCursorMutable, true);
2704
+ __tnFieldValue_seed_len = __tnRead_seed_len;
2705
+ __tnCursorMutable += 4;
2706
+ if (__tnFieldValue_seed_len === null) return null;
2707
+ const __tnArrayCount_seed = Math.trunc(Number(__tnFieldValue_seed_len));
2708
+ if (!Number.isFinite(__tnArrayCount_seed) || __tnArrayCount_seed < 0) return null;
2709
+ const __tnArrayBytes_seed = __tnArrayCount_seed * 1;
2710
+ if (__tnCursorMutable + __tnArrayBytes_seed > __tnLength) return null;
2711
+ __tnCursorMutable += __tnArrayBytes_seed;
2712
+ offsets["meta_state_proof"] = __tnCursorMutable;
2713
+ const __tnTyperefResult_meta_state_proof = __tnInvokeDynamicValidate("StateProof", buffer.subarray(__tnCursorMutable));
2714
+ if (!__tnTyperefResult_meta_state_proof.ok || __tnTyperefResult_meta_state_proof.consumed === undefined) return null;
2715
+ const __tnTyperefParams_meta_state_proof = __tnTyperefResult_meta_state_proof.params ?? null;
2716
+ if (!__tnTyperefParams_meta_state_proof || __tnTyperefParams_meta_state_proof["proof_body_hdr_type_slot"] === undefined) return null;
2717
+ __tnParamSeq_proof_body_hdr_type_slot = __tnTyperefParams_meta_state_proof["proof_body_hdr_type_slot"];
2718
+ if (!__tnTyperefParams_meta_state_proof || __tnTyperefParams_meta_state_proof["proof_body_payload_size"] === undefined) return null;
2719
+ __tnParamSeq_proof_body_payload_size = __tnTyperefParams_meta_state_proof["proof_body_payload_size"];
2720
+ __tnCursorMutable += __tnBigIntToNumber(__tnTyperefResult_meta_state_proof.consumed, "CreatePermanentArgs::meta_state_proof");
2721
+ offsets["program_state_proof"] = __tnCursorMutable;
2722
+ const __tnTyperefResult_program_state_proof = __tnInvokeDynamicValidate("StateProof", buffer.subarray(__tnCursorMutable));
2723
+ if (!__tnTyperefResult_program_state_proof.ok || __tnTyperefResult_program_state_proof.consumed === undefined) return null;
2724
+ __tnCursorMutable += __tnBigIntToNumber(__tnTyperefResult_program_state_proof.consumed, "CreatePermanentArgs::program_state_proof");
2725
+ const params: Record<string, bigint> = Object.create(null);
2726
+ if (__tnParamSeq_proof_body_hdr_type_slot === null) return null;
2727
+ params["proof_body_hdr_type_slot"] = __tnParamSeq_proof_body_hdr_type_slot as bigint;
2728
+ if (__tnParamSeq_proof_body_payload_size === null) return null;
2729
+ params["proof_body_payload_size"] = __tnParamSeq_proof_body_payload_size as bigint;
2730
+ return { params, offsets: offsets, derived: null };
2731
+ }
2732
+
2733
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: CreatePermanentArgs.Params; derived: Record<string, bigint> | null } | null {
2734
+ if (buffer.length < 20) {
2735
+ return null;
2736
+ }
2737
+ const __tnParam_seed_seed_len = __tnToBigInt(view.getUint32(16, true));
2738
+ const __tnLayout = CreatePermanentArgs.__tnComputeSequentialLayout(view, buffer);
2739
+ if (!__tnLayout || !__tnLayout.params) return null;
2740
+ const __tnSeqParams = __tnLayout.params;
2741
+ const __tnParamSeq_proof_body_hdr_type_slot = __tnSeqParams["proof_body_hdr_type_slot"];
2742
+ if (__tnParamSeq_proof_body_hdr_type_slot === undefined) return null;
2743
+ const __tnParamSeq_proof_body_payload_size = __tnSeqParams["proof_body_payload_size"];
2744
+ if (__tnParamSeq_proof_body_payload_size === undefined) return null;
2745
+ const __tnExtractedParams = CreatePermanentArgs.Params.fromValues({
2746
+ seed_seed_len: __tnParam_seed_seed_len,
2747
+ proof_body_hdr_type_slot: __tnParamSeq_proof_body_hdr_type_slot as bigint,
2748
+ proof_body_payload_size: __tnParamSeq_proof_body_payload_size as bigint,
2749
+ });
2750
+ return { params: __tnExtractedParams, derived: null };
2751
+ }
2752
+
2753
+ /* Dynamic offsets are derived once per view; mutating length fields later does not invalidate this cache. */
2754
+ private __tnDynamicOffsetCache: Record<string, number> | null = null;
2755
+ private __tnGetDynamicOffset(field: string): number {
2756
+ if (!this.__tnDynamicOffsetCache) {
2757
+ this.__tnDynamicOffsetCache = this.__tnComputeDynamicOffsets();
2758
+ }
2759
+ const offset = this.__tnDynamicOffsetCache[field];
2760
+ if (offset === undefined) {
2761
+ throw new Error("CreatePermanentArgs: field '" + field + "' does not have a dynamic offset");
2762
+ }
2763
+ return offset;
2764
+ }
2765
+
2766
+ private __tnComputeDynamicOffsets(): Record<string, number> {
2767
+ const layout = CreatePermanentArgs.__tnComputeSequentialLayout(this.view, this.buffer);
2768
+ if (!layout || !layout.offsets) {
2769
+ throw new Error("CreatePermanentArgs: failed to compute dynamic offsets");
2770
+ }
2771
+ return layout.offsets;
2772
+ }
2773
+
2774
+ get_meta_account_idx(): number {
2775
+ const offset = 0;
2776
+ return this.view.getUint16(offset, true); /* little-endian */
2777
+ }
2778
+
2779
+ set_meta_account_idx(value: number): void {
2780
+ const offset = 0;
2781
+ this.view.setUint16(offset, value, true); /* little-endian */
2782
+ }
2783
+
2784
+ get meta_account_idx(): number {
2785
+ return this.get_meta_account_idx();
2786
+ }
2787
+
2788
+ set meta_account_idx(value: number) {
2789
+ this.set_meta_account_idx(value);
2790
+ }
2791
+
2792
+ get_program_account_idx(): number {
2793
+ const offset = 2;
2794
+ return this.view.getUint16(offset, true); /* little-endian */
2795
+ }
2796
+
2797
+ set_program_account_idx(value: number): void {
2798
+ const offset = 2;
2799
+ this.view.setUint16(offset, value, true); /* little-endian */
2800
+ }
2801
+
2802
+ get program_account_idx(): number {
2803
+ return this.get_program_account_idx();
2804
+ }
2805
+
2806
+ set program_account_idx(value: number) {
2807
+ this.set_program_account_idx(value);
2808
+ }
2809
+
2810
+ get_srcbuf_account_idx(): number {
2811
+ const offset = 4;
2812
+ return this.view.getUint16(offset, true); /* little-endian */
2813
+ }
2814
+
2815
+ set_srcbuf_account_idx(value: number): void {
2816
+ const offset = 4;
2817
+ this.view.setUint16(offset, value, true); /* little-endian */
2818
+ }
2819
+
2820
+ get srcbuf_account_idx(): number {
2821
+ return this.get_srcbuf_account_idx();
2822
+ }
2823
+
2824
+ set srcbuf_account_idx(value: number) {
2825
+ this.set_srcbuf_account_idx(value);
2826
+ }
2827
+
2828
+ get_srcbuf_offset(): number {
2829
+ const offset = 6;
2830
+ return this.view.getUint32(offset, true); /* little-endian */
2831
+ }
2832
+
2833
+ set_srcbuf_offset(value: number): void {
2834
+ const offset = 6;
2835
+ this.view.setUint32(offset, value, true); /* little-endian */
2836
+ }
2837
+
2838
+ get srcbuf_offset(): number {
2839
+ return this.get_srcbuf_offset();
2840
+ }
2841
+
2842
+ set srcbuf_offset(value: number) {
2843
+ this.set_srcbuf_offset(value);
2844
+ }
2845
+
2846
+ get_srcbuf_size(): number {
2847
+ const offset = 10;
2848
+ return this.view.getUint32(offset, true); /* little-endian */
2849
+ }
2850
+
2851
+ set_srcbuf_size(value: number): void {
2852
+ const offset = 10;
2853
+ this.view.setUint32(offset, value, true); /* little-endian */
2854
+ }
2855
+
2856
+ get srcbuf_size(): number {
2857
+ return this.get_srcbuf_size();
2858
+ }
2859
+
2860
+ set srcbuf_size(value: number) {
2861
+ this.set_srcbuf_size(value);
2862
+ }
2863
+
2864
+ get_authority_account_idx(): number {
2865
+ const offset = 14;
2866
+ return this.view.getUint16(offset, true); /* little-endian */
2867
+ }
2868
+
2869
+ set_authority_account_idx(value: number): void {
2870
+ const offset = 14;
2871
+ this.view.setUint16(offset, value, true); /* little-endian */
2872
+ }
2873
+
2874
+ get authority_account_idx(): number {
2875
+ return this.get_authority_account_idx();
2876
+ }
2877
+
2878
+ set authority_account_idx(value: number) {
2879
+ this.set_authority_account_idx(value);
2880
+ }
2881
+
2882
+ get_seed_len(): number {
2883
+ const offset = 16;
2884
+ return this.view.getUint32(offset, true); /* little-endian */
2885
+ }
2886
+
2887
+ set_seed_len(value: number): void {
2888
+ const offset = 16;
2889
+ this.view.setUint32(offset, value, true); /* little-endian */
2890
+ }
2891
+
2892
+ get seed_len(): number {
2893
+ return this.get_seed_len();
2894
+ }
2895
+
2896
+ set seed_len(value: number) {
2897
+ this.set_seed_len(value);
2898
+ }
2899
+
2900
+ get_seed_length(): number {
2901
+ return this.__tnResolveFieldRef("seed_len");
2902
+ }
2903
+
2904
+ get_seed_at(index: number): number {
2905
+ const offset = 20;
2906
+ return this.view.getUint8(offset + index * 1);
2907
+ }
2908
+
2909
+ get_seed(): number[] {
2910
+ const len = this.get_seed_length();
2911
+ const result: number[] = [];
2912
+ for (let i = 0; i < len; i++) {
2913
+ result.push(this.get_seed_at(i));
2914
+ }
2915
+ return result;
2916
+ }
2917
+
2918
+ set_seed_at(index: number, value: number): void {
2919
+ const offset = 20;
2920
+ this.view.setUint8((offset + index * 1), value);
2921
+ }
2922
+
2923
+ set_seed(value: number[]): void {
2924
+ const len = Math.min(this.get_seed_length(), value.length);
2925
+ for (let i = 0; i < len; i++) {
2926
+ this.set_seed_at(i, value[i]);
2927
+ }
2928
+ }
2929
+
2930
+ get seed(): number[] {
2931
+ return this.get_seed();
2932
+ }
2933
+
2934
+ set seed(value: number[]) {
2935
+ this.set_seed(value);
2936
+ }
2937
+
2938
+ get_meta_state_proof(): StateProof {
2939
+ const offset = this.__tnGetDynamicOffset("meta_state_proof");
2940
+ const tail = this.buffer.subarray(offset);
2941
+ const validation = StateProof.validate(tail);
2942
+ if (!validation.ok || validation.consumed === undefined) {
2943
+ throw new Error("CreatePermanentArgs: failed to read field 'meta_state_proof' (invalid nested payload)");
2944
+ }
2945
+ const length = validation.consumed;
2946
+ const slice = tail.subarray(0, length);
2947
+ const opts = validation.params ? { params: validation.params } : undefined;
2948
+ return StateProof.from_array(slice, opts)!;
2949
+ }
2950
+
2951
+ set_meta_state_proof(value: StateProof): void {
2952
+ /* Copy bytes from source struct to this field */
2953
+ const sourceBytes = (value as any).buffer as Uint8Array;
2954
+ const offset = this.__tnGetDynamicOffset("meta_state_proof");
2955
+ this.buffer.set(sourceBytes, offset);
2956
+ }
2957
+
2958
+ get meta_state_proof(): StateProof {
2959
+ return this.get_meta_state_proof();
2960
+ }
2961
+
2962
+ set meta_state_proof(value: StateProof) {
2963
+ this.set_meta_state_proof(value);
2964
+ }
2965
+
2966
+ get_program_state_proof(): StateProof {
2967
+ const offset = this.__tnGetDynamicOffset("program_state_proof");
2968
+ const tail = this.buffer.subarray(offset);
2969
+ const validation = StateProof.validate(tail);
2970
+ if (!validation.ok || validation.consumed === undefined) {
2971
+ throw new Error("CreatePermanentArgs: failed to read field 'program_state_proof' (invalid nested payload)");
2972
+ }
2973
+ const length = validation.consumed;
2974
+ const slice = tail.subarray(0, length);
2975
+ const opts = validation.params ? { params: validation.params } : undefined;
2976
+ return StateProof.from_array(slice, opts)!;
2977
+ }
2978
+
2979
+ set_program_state_proof(value: StateProof): void {
2980
+ /* Copy bytes from source struct to this field */
2981
+ const sourceBytes = (value as any).buffer as Uint8Array;
2982
+ const offset = this.__tnGetDynamicOffset("program_state_proof");
2983
+ this.buffer.set(sourceBytes, offset);
2984
+ }
2985
+
2986
+ get program_state_proof(): StateProof {
2987
+ return this.get_program_state_proof();
2988
+ }
2989
+
2990
+ set program_state_proof(value: StateProof) {
2991
+ this.set_program_state_proof(value);
2992
+ }
2993
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2994
+ return __tnEvalFootprint(__tn_ir_CreatePermanentArgs.root, { params: __tnParams });
2995
+ }
2996
+
2997
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2998
+ return __tnValidateIrTree(__tn_ir_CreatePermanentArgs, buffer, __tnParams);
2999
+ }
3000
+
3001
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
3002
+ return this.__tnFootprintInternal(__tnParams);
3003
+ }
3004
+
3005
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
3006
+ return this.__tnValidateInternal(buffer, __tnParams);
3007
+ }
3008
+
3009
+ static footprintIr(seed_seed_len: number | bigint, proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint): bigint {
3010
+ const params = CreatePermanentArgs.Params.fromValues({
3011
+ seed_seed_len: seed_seed_len,
3012
+ proof_body_hdr_type_slot: proof_body_hdr_type_slot,
3013
+ proof_body_payload_size: proof_body_payload_size,
3014
+ });
3015
+ return this.footprintIrFromParams(params);
3016
+ }
3017
+
3018
+ private static __tnPackParams(params: CreatePermanentArgs.Params): Record<string, bigint> {
3019
+ const record: Record<string, bigint> = Object.create(null);
3020
+ record["seed.seed_len"] = params.seed_seed_len;
3021
+ record["proof_body.hdr.type_slot"] = params.proof_body_hdr_type_slot;
3022
+ record["proof_body.payload_size"] = params.proof_body_payload_size;
3023
+ return record;
3024
+ }
3025
+
3026
+ static footprintIrFromParams(params: CreatePermanentArgs.Params): bigint {
3027
+ const __tnParams = this.__tnPackParams(params);
3028
+ return this.__tnFootprintInternal(__tnParams);
3029
+ }
3030
+
3031
+ static footprintFromParams(params: CreatePermanentArgs.Params): number {
3032
+ const irResult = this.footprintIrFromParams(params);
3033
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3034
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for CreatePermanentArgs');
3035
+ return __tnBigIntToNumber(irResult, 'CreatePermanentArgs::footprintFromParams');
3036
+ }
3037
+
3038
+ static footprintFromValues(input: { seed_seed_len: number | bigint, proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): number {
3039
+ const params = CreatePermanentArgs.params(input);
3040
+ return this.footprintFromParams(params);
3041
+ }
3042
+
3043
+ static footprint(params: CreatePermanentArgs.Params): number {
3044
+ return this.footprintFromParams(params);
3045
+ }
3046
+
3047
+ static validate(buffer: Uint8Array, opts?: { params?: CreatePermanentArgs.Params }): { ok: boolean; code?: string; consumed?: number; params?: CreatePermanentArgs.Params } {
3048
+ if (!buffer || buffer.length === undefined) {
3049
+ return { ok: false, code: "tn.invalid_buffer" };
3050
+ }
3051
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3052
+ let params = opts?.params ?? null;
3053
+ if (!params) {
3054
+ const extracted = this.__tnExtractParams(view, buffer);
3055
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
3056
+ params = extracted.params;
3057
+ }
3058
+ const __tnParamsRec = this.__tnPackParams(params);
3059
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
3060
+ if (!irResult.ok) {
3061
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreatePermanentArgs::validate') : undefined, params };
3062
+ }
3063
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreatePermanentArgs::validate') : undefined;
3064
+ return { ok: true, consumed, params };
3065
+ }
3066
+
3067
+ static from_array(buffer: Uint8Array, opts?: { params?: CreatePermanentArgs.Params }): CreatePermanentArgs | null {
3068
+ if (!buffer || buffer.length === undefined) {
3069
+ return null;
3070
+ }
3071
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3072
+ let params = opts?.params ?? null;
3073
+ if (!params) {
3074
+ const derived = this.__tnExtractParams(view, buffer);
3075
+ if (!derived) return null;
3076
+ params = derived.params;
3077
+ }
3078
+ const validation = this.validate(buffer, { params });
3079
+ if (!validation.ok) {
3080
+ return null;
3081
+ }
3082
+ const cached = validation.params ?? params;
3083
+ const state = new CreatePermanentArgs(buffer, cached);
3084
+ return state;
3085
+ }
3086
+
3087
+
3088
+ }
3089
+
3090
+ export namespace CreatePermanentArgs {
3091
+ export type Params = {
3092
+ /** ABI path: seed.seed_len */
3093
+ readonly seed_seed_len: bigint;
3094
+ /** ABI path: proof_body.hdr.type_slot */
3095
+ readonly proof_body_hdr_type_slot: bigint;
3096
+ /** ABI path: proof_body.payload_size */
3097
+ readonly proof_body_payload_size: bigint;
3098
+ };
3099
+
3100
+ export const ParamKeys = Object.freeze({
3101
+ seed_seed_len: "seed.seed_len",
3102
+ proof_body_hdr_type_slot: "proof_body.hdr.type_slot",
3103
+ proof_body_payload_size: "proof_body.payload_size",
3104
+ } as const);
3105
+
3106
+ export const Params = {
3107
+ fromValues(input: { seed_seed_len: number | bigint, proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): Params {
3108
+ return {
3109
+ seed_seed_len: __tnToBigInt(input.seed_seed_len),
3110
+ proof_body_hdr_type_slot: __tnToBigInt(input.proof_body_hdr_type_slot),
3111
+ proof_body_payload_size: __tnToBigInt(input.proof_body_payload_size),
3112
+ };
3113
+ },
3114
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
3115
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
3116
+ return (source as { dynamicParams(): Params }).dynamicParams();
3117
+ }
3118
+ if ((source as { params?: Params }).params) {
3119
+ return (source as { params: Params }).params;
3120
+ }
3121
+ return source as Params;
3122
+ }
3123
+ };
3124
+
3125
+ export function params(input: { seed_seed_len: number | bigint, proof_body_hdr_type_slot: number | bigint, proof_body_payload_size: number | bigint }): Params {
3126
+ return Params.fromValues(input);
3127
+ }
3128
+ }
3129
+
3130
+ export class CreatePermanentArgsBuilder {
3131
+ private buffer: Uint8Array;
3132
+ private view: DataView;
3133
+ private __tnCachedParams: CreatePermanentArgs.Params | null = null;
3134
+ private __tnLastBuffer: Uint8Array | null = null;
3135
+ private __tnLastParams: CreatePermanentArgs.Params | null = null;
3136
+ private __tnFam_seed: Uint8Array | null = null;
3137
+ private __tnFam_seedCount: number | null = null;
3138
+ private __tnFamWriter_seed?: __TnFamWriterResult<CreatePermanentArgsBuilder>;
3139
+ private __tnTail_meta_state_proof: Uint8Array | null = null;
3140
+ private __tnTailParams_meta_state_proof: Record<string, bigint> | null = null;
3141
+ private __tnTail_program_state_proof: Uint8Array | null = null;
3142
+ private __tnTailParams_program_state_proof: Record<string, bigint> | null = null;
3143
+
3144
+ constructor() {
3145
+ this.buffer = new Uint8Array(20);
3146
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3147
+ }
3148
+
3149
+ private __tnInvalidate(): void {
3150
+ this.__tnCachedParams = null;
3151
+ this.__tnLastBuffer = null;
3152
+ this.__tnLastParams = null;
3153
+ }
3154
+
3155
+ set_meta_account_idx(value: number): this {
3156
+ this.view.setUint16(0, value, true);
3157
+ this.__tnInvalidate();
3158
+ return this;
3159
+ }
3160
+
3161
+ set_program_account_idx(value: number): this {
3162
+ this.view.setUint16(2, value, true);
3163
+ this.__tnInvalidate();
3164
+ return this;
3165
+ }
3166
+
3167
+ set_srcbuf_account_idx(value: number): this {
3168
+ this.view.setUint16(4, value, true);
3169
+ this.__tnInvalidate();
3170
+ return this;
3171
+ }
3172
+
3173
+ set_srcbuf_offset(value: number): this {
3174
+ this.view.setUint32(6, value, true);
3175
+ this.__tnInvalidate();
3176
+ return this;
3177
+ }
3178
+
3179
+ set_srcbuf_size(value: number): this {
3180
+ this.view.setUint32(10, value, true);
3181
+ this.__tnInvalidate();
3182
+ return this;
3183
+ }
3184
+
3185
+ set_authority_account_idx(value: number): this {
3186
+ this.view.setUint16(14, value, true);
3187
+ this.__tnInvalidate();
3188
+ return this;
3189
+ }
3190
+
3191
+ set_seed_len(value: number): this {
3192
+ this.view.setUint32(16, value, true);
3193
+ this.__tnInvalidate();
3194
+ return this;
3195
+ }
3196
+
3197
+ seed(): __TnFamWriterResult<CreatePermanentArgsBuilder> {
3198
+ if (!this.__tnFamWriter_seed) {
3199
+ this.__tnFamWriter_seed = __tnCreateFamWriter(this, "seed", (payload) => {
3200
+ const bytes = new Uint8Array(payload);
3201
+ const elementCount = bytes.length;
3202
+ this.__tnFam_seed = bytes;
3203
+ this.__tnFam_seedCount = elementCount;
3204
+ this.set_seed_len(elementCount);
3205
+ this.__tnInvalidate();
3206
+ });
3207
+ }
3208
+ return this.__tnFamWriter_seed!;
3209
+ }
3210
+
3211
+ set_meta_state_proof(value: StateProof | __TnStructFieldInput): this {
3212
+ const bytes = __tnResolveStructFieldInput(value as __TnStructFieldInput, "CreatePermanentArgsBuilder::meta_state_proof");
3213
+ const validation = __tnInvokeDynamicValidate("StateProof", bytes);
3214
+ if (!validation.ok || validation.consumed === undefined) throw new Error("CreatePermanentArgsBuilder: field 'meta_state_proof' failed validation");
3215
+ if (__tnBigIntToNumber(validation.consumed, "CreatePermanentArgsBuilder::meta_state_proof") !== bytes.length) throw new Error("CreatePermanentArgsBuilder: field 'meta_state_proof' validation did not consume the full buffer");
3216
+ this.__tnTail_meta_state_proof = bytes;
3217
+ this.__tnTailParams_meta_state_proof = validation.params ?? null;
3218
+ this.__tnInvalidate();
3219
+ return this;
3220
+ }
3221
+
3222
+ set_program_state_proof(value: StateProof | __TnStructFieldInput): this {
3223
+ const bytes = __tnResolveStructFieldInput(value as __TnStructFieldInput, "CreatePermanentArgsBuilder::program_state_proof");
3224
+ const validation = __tnInvokeDynamicValidate("StateProof", bytes);
3225
+ if (!validation.ok || validation.consumed === undefined) throw new Error("CreatePermanentArgsBuilder: field 'program_state_proof' failed validation");
3226
+ if (__tnBigIntToNumber(validation.consumed, "CreatePermanentArgsBuilder::program_state_proof") !== bytes.length) throw new Error("CreatePermanentArgsBuilder: field 'program_state_proof' validation did not consume the full buffer");
3227
+ this.__tnTail_program_state_proof = bytes;
3228
+ this.__tnTailParams_program_state_proof = validation.params ?? null;
3229
+ this.__tnInvalidate();
3230
+ return this;
3231
+ }
3232
+
3233
+ build(): Uint8Array {
3234
+ const params = this.__tnComputeParams();
3235
+ const size = CreatePermanentArgs.footprintFromParams(params);
3236
+ const buffer = new Uint8Array(size);
3237
+ this.__tnWriteInto(buffer);
3238
+ this.__tnValidateOrThrow(buffer, params);
3239
+ return buffer;
3240
+ }
3241
+
3242
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
3243
+ const params = this.__tnComputeParams();
3244
+ const size = CreatePermanentArgs.footprintFromParams(params);
3245
+ if (target.length - offset < size) throw new Error("CreatePermanentArgsBuilder: target buffer too small");
3246
+ const slice = target.subarray(offset, offset + size);
3247
+ this.__tnWriteInto(slice);
3248
+ this.__tnValidateOrThrow(slice, params);
3249
+ return target;
3250
+ }
3251
+
3252
+ finish(): CreatePermanentArgs {
3253
+ const buffer = this.build();
3254
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
3255
+ const view = CreatePermanentArgs.from_array(buffer, { params });
3256
+ if (!view) throw new Error("CreatePermanentArgsBuilder: failed to finalize view");
3257
+ return view;
3258
+ }
3259
+
3260
+ finishView(): CreatePermanentArgs {
3261
+ return this.finish();
3262
+ }
3263
+
3264
+ dynamicParams(): CreatePermanentArgs.Params {
3265
+ return this.__tnComputeParams();
3266
+ }
3267
+
3268
+ private __tnComputeParams(): CreatePermanentArgs.Params {
3269
+ if (this.__tnCachedParams) return this.__tnCachedParams;
3270
+ const params = CreatePermanentArgs.Params.fromValues({
3271
+ seed_seed_len: (() => { if (this.__tnFam_seedCount === null) throw new Error("CreatePermanentArgsBuilder: field 'seed' must be written before computing params"); return __tnToBigInt(this.__tnFam_seedCount); })(),
3272
+ proof_body_hdr_type_slot: (() => { const params = this.__tnTailParams_meta_state_proof; if (!params || params["proof_body_hdr_type_slot"] === undefined) throw new Error("CreatePermanentArgsBuilder: field 'meta_state_proof' must be written before computing params"); return params["proof_body_hdr_type_slot"]; })(),
3273
+ proof_body_payload_size: (() => { const params = this.__tnTailParams_meta_state_proof; if (!params || params["proof_body_payload_size"] === undefined) throw new Error("CreatePermanentArgsBuilder: field 'meta_state_proof' must be written before computing params"); return params["proof_body_payload_size"]; })(),
3274
+ });
3275
+ this.__tnCachedParams = params;
3276
+ return params;
3277
+ }
3278
+
3279
+ private __tnWriteInto(target: Uint8Array): void {
3280
+ target.set(this.buffer, 0);
3281
+ let cursor = this.buffer.length;
3282
+ const __tnLocal_seed_bytes = this.__tnFam_seed;
3283
+ if (!__tnLocal_seed_bytes) throw new Error("CreatePermanentArgsBuilder: field 'seed' must be written before build");
3284
+ target.set(__tnLocal_seed_bytes, cursor);
3285
+ cursor += __tnLocal_seed_bytes.length;
3286
+ const __tnLocal_meta_state_proof_bytes = this.__tnTail_meta_state_proof;
3287
+ if (!__tnLocal_meta_state_proof_bytes) throw new Error("CreatePermanentArgsBuilder: field 'meta_state_proof' must be written before build");
3288
+ target.set(__tnLocal_meta_state_proof_bytes, cursor);
3289
+ cursor += __tnLocal_meta_state_proof_bytes.length;
3290
+ const __tnLocal_program_state_proof_bytes = this.__tnTail_program_state_proof;
3291
+ if (!__tnLocal_program_state_proof_bytes) throw new Error("CreatePermanentArgsBuilder: field 'program_state_proof' must be written before build");
3292
+ target.set(__tnLocal_program_state_proof_bytes, cursor);
3293
+ cursor += __tnLocal_program_state_proof_bytes.length;
3294
+ }
3295
+
3296
+ private __tnValidateOrThrow(buffer: Uint8Array, params: CreatePermanentArgs.Params): void {
3297
+ const result = CreatePermanentArgs.validate(buffer, { params });
3298
+ if (!result.ok) {
3299
+ throw new Error(`${ CreatePermanentArgs }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3300
+ }
3301
+ this.__tnLastParams = result.params ?? params;
3302
+ this.__tnLastBuffer = buffer;
3303
+ }
3304
+ }
3305
+
3306
+ __tnRegisterFootprint("CreatePermanentArgs", (params) => CreatePermanentArgs.__tnInvokeFootprint(params));
3307
+ __tnRegisterValidate("CreatePermanentArgs", (buffer, params) => CreatePermanentArgs.__tnInvokeValidate(buffer, params));
3308
+ __tnRegisterDynamicValidate("CreatePermanentArgs", (buffer) => { const result = CreatePermanentArgs.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });
3309
+
3310
+ /* ----- TYPE DEFINITION FOR ManagerInstruction ----- */
3311
+
3312
+ const __tn_ir_ManagerInstruction = {
3313
+ typeName: "ManagerInstruction",
3314
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 1, node: { op: "const", value: 1n } }, right: { op: "align", alignment: 1, node: { op: "field", param: "payload.payload_size" } } } }
3315
+ } as const;
3316
+
3317
+ export class ManagerInstruction_payload_Inner {
3318
+ private view: DataView;
3319
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
3320
+ private constructor(private buffer: Uint8Array, private descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>) {
3321
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3322
+ this.__tnFieldContext = fieldContext ?? null;
3323
+ }
3324
+
3325
+ static __tnCreate(payload: Uint8Array, descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>): ManagerInstruction_payload_Inner {
3326
+ return new ManagerInstruction_payload_Inner(new Uint8Array(payload), descriptor, fieldContext);
3327
+ }
3328
+
3329
+ bytes(): Uint8Array {
3330
+ return new Uint8Array(this.buffer);
3331
+ }
3332
+
3333
+ variant(): __TnVariantDescriptor | null {
3334
+ return this.descriptor;
3335
+ }
3336
+
3337
+ asCreatePermanent(): CreatePermanentArgs | null {
3338
+ if (!this.descriptor || this.descriptor.tag !== 0) return null;
3339
+ return CreatePermanentArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3340
+ }
3341
+
3342
+ asCreateEphemeral(): CreateEphemeralArgs | null {
3343
+ if (!this.descriptor || this.descriptor.tag !== 1) return null;
3344
+ return CreateEphemeralArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3345
+ }
3346
+
3347
+ asUpgrade(): UpgradeArgs | null {
3348
+ if (!this.descriptor || this.descriptor.tag !== 2) return null;
3349
+ return UpgradeArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3350
+ }
3351
+
3352
+ asSetPause(): SetPauseArgs | null {
3353
+ if (!this.descriptor || this.descriptor.tag !== 3) return null;
3354
+ return SetPauseArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3355
+ }
3356
+
3357
+ asDestroy(): HeaderOnlyArgs | null {
3358
+ if (!this.descriptor || this.descriptor.tag !== 4) return null;
3359
+ return HeaderOnlyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3360
+ }
3361
+
3362
+ asFinalize(): HeaderOnlyArgs | null {
3363
+ if (!this.descriptor || this.descriptor.tag !== 5) return null;
3364
+ return HeaderOnlyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3365
+ }
3366
+
3367
+ asSetAuthority(): SetAuthorityArgs | null {
3368
+ if (!this.descriptor || this.descriptor.tag !== 6) return null;
3369
+ return SetAuthorityArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3370
+ }
3371
+
3372
+ asClaimAuthority(): HeaderOnlyArgs | null {
3373
+ if (!this.descriptor || this.descriptor.tag !== 7) return null;
3374
+ return HeaderOnlyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
3375
+ }
3376
+
3377
+ }
3378
+
3379
+ export class ManagerInstruction {
3380
+ private view: DataView;
3381
+ private static readonly __tnFieldOffset_payload = 1;
3382
+ private __tnParams: ManagerInstruction.Params;
3383
+
3384
+ private constructor(private buffer: Uint8Array, params?: ManagerInstruction.Params) {
3385
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3386
+ if (params) {
3387
+ this.__tnParams = params;
3388
+ } else {
3389
+ const derived = ManagerInstruction.__tnExtractParams(this.view, buffer);
3390
+ if (!derived) {
3391
+ throw new Error("ManagerInstruction: failed to derive dynamic parameters");
3392
+ }
3393
+ this.__tnParams = derived.params;
3394
+ }
3395
+ }
3396
+
3397
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: ManagerInstruction.Params, fieldContext?: Record<string, number | bigint> }): ManagerInstruction {
3398
+ if (!buffer || buffer.length === undefined) throw new Error("ManagerInstruction.__tnCreateView requires a Uint8Array");
3399
+ let params = opts?.params ?? null;
3400
+ if (!params) {
3401
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3402
+ const derived = ManagerInstruction.__tnExtractParams(view, buffer);
3403
+ if (!derived) throw new Error("ManagerInstruction.__tnCreateView: failed to derive params");
3404
+ params = derived.params;
3405
+ }
3406
+ const instance = new ManagerInstruction(new Uint8Array(buffer), params);
3407
+ return instance;
3408
+ }
3409
+
3410
+ dynamicParams(): ManagerInstruction.Params {
3411
+ return this.__tnParams;
3412
+ }
3413
+
3414
+ static builder(): ManagerInstructionBuilder {
3415
+ return new ManagerInstructionBuilder();
3416
+ }
3417
+
3418
+ static fromBuilder(builder: ManagerInstructionBuilder): ManagerInstruction | null {
3419
+ const buffer = builder.build();
3420
+ const params = builder.dynamicParams();
3421
+ return ManagerInstruction.from_array(buffer, { params });
3422
+ }
3423
+
3424
+ static readonly payloadVariantDescriptors = Object.freeze([
3425
+ {
3426
+ name: "create_permanent",
3427
+ tag: 0,
3428
+ payloadSize: null,
3429
+ payloadType: "ManagerInstruction::payload::create_permanent",
3430
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreatePermanentArgs),
3431
+ },
3432
+ {
3433
+ name: "create_ephemeral",
3434
+ tag: 1,
3435
+ payloadSize: null,
3436
+ payloadType: "ManagerInstruction::payload::create_ephemeral",
3437
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreateEphemeralArgs),
3438
+ },
3439
+ {
3440
+ name: "upgrade",
3441
+ tag: 2,
3442
+ payloadSize: 14,
3443
+ payloadType: "ManagerInstruction::payload::upgrade",
3444
+ createPayloadBuilder: () => __tnMaybeCallBuilder(UpgradeArgs),
3445
+ },
3446
+ {
3447
+ name: "set_pause",
3448
+ tag: 3,
3449
+ payloadSize: 5,
3450
+ payloadType: "ManagerInstruction::payload::set_pause",
3451
+ createPayloadBuilder: () => __tnMaybeCallBuilder(SetPauseArgs),
3452
+ },
3453
+ {
3454
+ name: "destroy",
3455
+ tag: 4,
3456
+ payloadSize: 4,
3457
+ payloadType: "ManagerInstruction::payload::destroy",
3458
+ createPayloadBuilder: () => __tnMaybeCallBuilder(HeaderOnlyArgs),
3459
+ },
3460
+ {
3461
+ name: "finalize",
3462
+ tag: 5,
3463
+ payloadSize: 4,
3464
+ payloadType: "ManagerInstruction::payload::finalize",
3465
+ createPayloadBuilder: () => __tnMaybeCallBuilder(HeaderOnlyArgs),
3466
+ },
3467
+ {
3468
+ name: "set_authority",
3469
+ tag: 6,
3470
+ payloadSize: 36,
3471
+ payloadType: "ManagerInstruction::payload::set_authority",
3472
+ createPayloadBuilder: () => __tnMaybeCallBuilder(SetAuthorityArgs),
3473
+ },
3474
+ {
3475
+ name: "claim_authority",
3476
+ tag: 7,
3477
+ payloadSize: 4,
3478
+ payloadType: "ManagerInstruction::payload::claim_authority",
3479
+ createPayloadBuilder: () => __tnMaybeCallBuilder(HeaderOnlyArgs),
3480
+ },
3481
+ ] as const);
3482
+
3483
+ static __tnComputeSequentialLayout(view: DataView, buffer: Uint8Array): { params: Record<string, bigint> | null; offsets: Record<string, number> | null; derived: Record<string, bigint> | null } | null {
3484
+ const __tnLength = buffer.length;
3485
+ let __tnParamSeq_payload_payload_size: bigint | null = null;
3486
+ let __tnFieldValue_tag: number | null = null;
3487
+ let __tnCursorMutable = 0;
3488
+ if (__tnCursorMutable + 1 > __tnLength) return null;
3489
+ const __tnRead_tag = view.getUint8(__tnCursorMutable);
3490
+ __tnFieldValue_tag = __tnRead_tag;
3491
+ __tnCursorMutable += 1;
3492
+ const __tnEnumTagValue_payload = __tnFieldValue_tag;
3493
+ if (__tnEnumTagValue_payload === null) return null;
3494
+ let __tnEnumSize_payload = 0;
3495
+ switch (Number(__tnEnumTagValue_payload)) {
3496
+ case 0: break;
3497
+ case 1: break;
3498
+ case 2: break;
3499
+ case 3: break;
3500
+ case 4: break;
3501
+ case 5: break;
3502
+ case 6: break;
3503
+ case 7: break;
3504
+ default: return null;
3505
+ }
3506
+ if (__tnCursorMutable > __tnLength) return null;
3507
+ __tnEnumSize_payload = __tnLength - __tnCursorMutable;
3508
+ __tnCursorMutable = __tnLength;
3509
+ __tnParamSeq_payload_payload_size = __tnToBigInt(__tnEnumSize_payload);
3510
+ const params: Record<string, bigint> = Object.create(null);
3511
+ if (__tnParamSeq_payload_payload_size === null) return null;
3512
+ params["payload_payload_size"] = __tnParamSeq_payload_payload_size as bigint;
3513
+ return { params, offsets: null, derived: null };
3514
+ }
3515
+
3516
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: ManagerInstruction.Params; derived: Record<string, bigint> | null } | null {
3517
+ if (buffer.length < 1) {
3518
+ return null;
3519
+ }
3520
+ const __tnParam_payload_tag = __tnToBigInt(view.getUint8(0));
3521
+ const __tnLayout = ManagerInstruction.__tnComputeSequentialLayout(view, buffer);
3522
+ if (!__tnLayout || !__tnLayout.params) return null;
3523
+ const __tnSeqParams = __tnLayout.params;
3524
+ const __tnParamSeq_payload_payload_size = __tnSeqParams["payload_payload_size"];
3525
+ if (__tnParamSeq_payload_payload_size === undefined) return null;
3526
+ const __tnExtractedParams = ManagerInstruction.Params.fromValues({
3527
+ payload_payload_size: __tnParamSeq_payload_payload_size as bigint,
3528
+ payload_tag: __tnParam_payload_tag,
3529
+ });
3530
+ return { params: __tnExtractedParams, derived: null };
3531
+ }
3532
+
3533
+ get_tag(): number {
3534
+ const offset = 0;
3535
+ return this.view.getUint8(offset);
3536
+ }
3537
+
3538
+ set_tag(value: number): void {
3539
+ const offset = 0;
3540
+ this.view.setUint8(offset, value);
3541
+ }
3542
+
3543
+ get tag(): number {
3544
+ return this.get_tag();
3545
+ }
3546
+
3547
+ set tag(value: number) {
3548
+ this.set_tag(value);
3549
+ }
3550
+
3551
+ payloadVariant(): typeof ManagerInstruction.payloadVariantDescriptors[number] | null {
3552
+ const tag = this.view.getUint8(0);
3553
+ return ManagerInstruction.payloadVariantDescriptors.find((variant) => variant.tag === tag) ?? null;
3554
+ }
3555
+
3556
+ payload(): ManagerInstruction_payload_Inner {
3557
+ const descriptor = this.payloadVariant();
3558
+ if (!descriptor) throw new Error("ManagerInstruction: unknown payload variant");
3559
+ const offset = ManagerInstruction.__tnFieldOffset_payload;
3560
+ const remaining = this.buffer.length - offset;
3561
+ const payloadLength = descriptor.payloadSize ?? remaining;
3562
+ if (payloadLength < 0 || offset + payloadLength > this.buffer.length) throw new Error("ManagerInstruction: payload exceeds buffer bounds");
3563
+ const slice = this.buffer.subarray(offset, offset + payloadLength);
3564
+ return ManagerInstruction_payload_Inner.__tnCreate(slice, descriptor, undefined);
3565
+ }
3566
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
3567
+ return __tnEvalFootprint(__tn_ir_ManagerInstruction.root, { params: __tnParams });
3568
+ }
3569
+
3570
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
3571
+ return __tnValidateIrTree(__tn_ir_ManagerInstruction, buffer, __tnParams);
3572
+ }
3573
+
3574
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
3575
+ return this.__tnFootprintInternal(__tnParams);
3576
+ }
3577
+
3578
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
3579
+ return this.__tnValidateInternal(buffer, __tnParams);
3580
+ }
3581
+
3582
+ static footprintIr(payload_payload_size: number | bigint, payload_tag: number | bigint): bigint {
3583
+ const params = ManagerInstruction.Params.fromValues({
3584
+ payload_payload_size: payload_payload_size,
3585
+ payload_tag: payload_tag,
3586
+ });
3587
+ return this.footprintIrFromParams(params);
3588
+ }
3589
+
3590
+ private static __tnPackParams(params: ManagerInstruction.Params): Record<string, bigint> {
3591
+ const record: Record<string, bigint> = Object.create(null);
3592
+ record["payload.payload_size"] = params.payload_payload_size;
3593
+ record["payload.tag"] = params.payload_tag;
3594
+ return record;
3595
+ }
3596
+
3597
+ static footprintIrFromParams(params: ManagerInstruction.Params): bigint {
3598
+ const __tnParams = this.__tnPackParams(params);
3599
+ return this.__tnFootprintInternal(__tnParams);
3600
+ }
3601
+
3602
+ static footprintFromParams(params: ManagerInstruction.Params): number {
3603
+ const irResult = this.footprintIrFromParams(params);
3604
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3605
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for ManagerInstruction');
3606
+ return __tnBigIntToNumber(irResult, 'ManagerInstruction::footprintFromParams');
3607
+ }
3608
+
3609
+ static footprintFromValues(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): number {
3610
+ const params = ManagerInstruction.params(input);
3611
+ return this.footprintFromParams(params);
3612
+ }
3613
+
3614
+ static footprint(params: ManagerInstruction.Params): number {
3615
+ return this.footprintFromParams(params);
3616
+ }
3617
+
3618
+ static validate(buffer: Uint8Array, opts?: { params?: ManagerInstruction.Params }): { ok: boolean; code?: string; consumed?: number; params?: ManagerInstruction.Params } {
3619
+ if (!buffer || buffer.length === undefined) {
3620
+ return { ok: false, code: "tn.invalid_buffer" };
3621
+ }
3622
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3623
+ let params = opts?.params ?? null;
3624
+ if (!params) {
3625
+ const extracted = this.__tnExtractParams(view, buffer);
3626
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
3627
+ params = extracted.params;
3628
+ }
3629
+ const __tnParamsRec = this.__tnPackParams(params);
3630
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
3631
+ if (!irResult.ok) {
3632
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'ManagerInstruction::validate') : undefined, params };
3633
+ }
3634
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'ManagerInstruction::validate') : undefined;
3635
+ return { ok: true, consumed, params };
3636
+ }
3637
+
3638
+ static from_array(buffer: Uint8Array, opts?: { params?: ManagerInstruction.Params }): ManagerInstruction | null {
3639
+ if (!buffer || buffer.length === undefined) {
3640
+ return null;
3641
+ }
3642
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3643
+ let params = opts?.params ?? null;
3644
+ if (!params) {
3645
+ const derived = this.__tnExtractParams(view, buffer);
3646
+ if (!derived) return null;
3647
+ params = derived.params;
3648
+ }
3649
+ const validation = this.validate(buffer, { params });
3650
+ if (!validation.ok) {
3651
+ return null;
3652
+ }
3653
+ const cached = validation.params ?? params;
3654
+ const state = new ManagerInstruction(buffer, cached);
3655
+ return state;
3656
+ }
3657
+
3658
+
3659
+ }
3660
+
3661
+ export namespace ManagerInstruction {
3662
+ export type Params = {
3663
+ /** ABI path: payload.payload_size */
3664
+ readonly payload_payload_size: bigint;
3665
+ /** ABI path: payload.tag */
3666
+ readonly payload_tag: bigint;
3667
+ };
3668
+
3669
+ export const ParamKeys = Object.freeze({
3670
+ payload_payload_size: "payload.payload_size",
3671
+ payload_tag: "payload.tag",
3672
+ } as const);
3673
+
3674
+ export const Params = {
3675
+ fromValues(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): Params {
3676
+ return {
3677
+ payload_payload_size: __tnToBigInt(input.payload_payload_size),
3678
+ payload_tag: __tnToBigInt(input.payload_tag),
3679
+ };
3680
+ },
3681
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
3682
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
3683
+ return (source as { dynamicParams(): Params }).dynamicParams();
3684
+ }
3685
+ if ((source as { params?: Params }).params) {
3686
+ return (source as { params: Params }).params;
3687
+ }
3688
+ return source as Params;
3689
+ }
3690
+ };
3691
+
3692
+ export function params(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): Params {
3693
+ return Params.fromValues(input);
3694
+ }
3695
+ }
3696
+
3697
+ export class ManagerInstructionBuilder {
3698
+ private __tnPrefixBuffer: Uint8Array;
3699
+ private __tnPrefixView: DataView;
3700
+ private __tnField_tag: number | null = null;
3701
+ private __tnPayload_payload: { descriptor: typeof ManagerInstruction.payloadVariantDescriptors[number]; bytes: Uint8Array } | null = null;
3702
+ private __tnCachedParams: ManagerInstruction.Params | null = null;
3703
+ private __tnLastBuffer: Uint8Array | null = null;
3704
+ private __tnLastParams: ManagerInstruction.Params | null = null;
3705
+ private __tnVariantSelector_payload?: __TnVariantSelectorResult<ManagerInstructionBuilder>;
3706
+
3707
+ constructor() {
3708
+ this.__tnPrefixBuffer = new Uint8Array(1);
3709
+ this.__tnPrefixView = new DataView(this.__tnPrefixBuffer.buffer, this.__tnPrefixBuffer.byteOffset, this.__tnPrefixBuffer.byteLength);
3710
+ }
3711
+
3712
+ private __tnInvalidate(): void {
3713
+ this.__tnCachedParams = null;
3714
+ this.__tnLastBuffer = null;
3715
+ this.__tnLastParams = null;
3716
+ }
3717
+
3718
+ private __tnAssign_tag(value: number): void {
3719
+ this.__tnField_tag = value;
3720
+ this.__tnInvalidate();
3721
+ }
3722
+
3723
+ set_tag(value: number): this {
3724
+ this.__tnAssign_tag(value);
3725
+ return this;
3726
+ }
3727
+
3728
+ payload(): __TnVariantSelectorResult<ManagerInstructionBuilder> {
3729
+ if (!this.__tnVariantSelector_payload) {
3730
+ this.__tnVariantSelector_payload = __tnCreateVariantSelector(this, ManagerInstruction.payloadVariantDescriptors, (descriptor, payload) => {
3731
+ this.__tnPayload_payload = { descriptor, bytes: new Uint8Array(payload) };
3732
+ this.__tnAssign_tag(descriptor.tag);
3733
+ });
3734
+ }
3735
+ return this.__tnVariantSelector_payload!;
3736
+ }
3737
+
3738
+ build(): Uint8Array {
3739
+ const params = this.__tnComputeParams();
3740
+ if (this.__tnField_tag === null) throw new Error("ManagerInstructionBuilder: field 'tag' must be set before build");
3741
+ if (!this.__tnPayload_payload) throw new Error("ManagerInstructionBuilder: payload variant not selected");
3742
+ const payloadLength = this.__tnPayload_payload.bytes.length;
3743
+ const requiredSize = 1 + payloadLength;
3744
+ const footprintSize = ManagerInstruction.footprintFromParams(params);
3745
+ const size = Math.max(requiredSize, footprintSize);
3746
+ const buffer = new Uint8Array(size);
3747
+ this.__tnWriteInto(buffer);
3748
+ this.__tnValidateOrThrow(buffer, params);
3749
+ return buffer;
3750
+ }
3751
+
3752
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
3753
+ const params = this.__tnComputeParams();
3754
+ if (this.__tnField_tag === null) throw new Error("ManagerInstructionBuilder: field 'tag' must be set before build");
3755
+ if (!this.__tnPayload_payload) throw new Error("ManagerInstructionBuilder: payload variant not selected");
3756
+ const payloadLength = this.__tnPayload_payload.bytes.length;
3757
+ const requiredSize = 1 + payloadLength;
3758
+ const footprintSize = ManagerInstruction.footprintFromParams(params);
3759
+ const size = Math.max(requiredSize, footprintSize);
3760
+ if (target.length - offset < size) throw new Error("ManagerInstructionBuilder: target buffer too small");
3761
+ const slice = target.subarray(offset, offset + size);
3762
+ this.__tnWriteInto(slice);
3763
+ this.__tnValidateOrThrow(slice, params);
3764
+ return target;
3765
+ }
3766
+
3767
+ finish(): ManagerInstruction {
3768
+ const buffer = this.build();
3769
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
3770
+ const view = ManagerInstruction.from_array(buffer, { params });
3771
+ if (!view) throw new Error("ManagerInstructionBuilder: failed to finalize view");
3772
+ return view;
3773
+ }
3774
+
3775
+ finishView(): ManagerInstruction {
3776
+ return this.finish();
3777
+ }
3778
+
3779
+ dynamicParams(): ManagerInstruction.Params {
3780
+ return this.__tnComputeParams();
3781
+ }
3782
+
3783
+ private __tnComputeParams(): ManagerInstruction.Params {
3784
+ if (this.__tnCachedParams) return this.__tnCachedParams;
3785
+ const params = ManagerInstruction.Params.fromValues({
3786
+ payload_payload_size: (() => { if (!this.__tnPayload_payload) throw new Error("ManagerInstructionBuilder: payload 'payload' must be selected before build"); return __tnToBigInt(this.__tnPayload_payload.bytes.length); })(),
3787
+ payload_tag: (() => { if (this.__tnField_tag === null) throw new Error("ManagerInstructionBuilder: missing enum tag"); return __tnToBigInt(this.__tnField_tag); })(),
3788
+ });
3789
+ this.__tnCachedParams = params;
3790
+ return params;
3791
+ }
3792
+
3793
+ private __tnWriteInto(target: Uint8Array): void {
3794
+ if (this.__tnField_tag === null) throw new Error("ManagerInstructionBuilder: field 'tag' must be set before build");
3795
+ if (!this.__tnPayload_payload) throw new Error("ManagerInstructionBuilder: payload variant not selected");
3796
+ const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
3797
+ target.set(this.__tnPrefixBuffer, 0);
3798
+ view.setUint8(0, this.__tnField_tag);
3799
+ target.set(this.__tnPayload_payload.bytes, 1);
3800
+ }
3801
+
3802
+ private __tnValidateOrThrow(buffer: Uint8Array, params: ManagerInstruction.Params): void {
3803
+ const result = ManagerInstruction.validate(buffer, { params });
3804
+ if (!result.ok) {
3805
+ throw new Error(`${ ManagerInstruction }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3806
+ }
3807
+ this.__tnLastParams = result.params ?? params;
3808
+ this.__tnLastBuffer = buffer;
3809
+ }
3810
+ }
3811
+
3812
+ __tnRegisterFootprint("ManagerInstruction", (params) => ManagerInstruction.__tnInvokeFootprint(params));
3813
+ __tnRegisterValidate("ManagerInstruction", (buffer, params) => ManagerInstruction.__tnInvokeValidate(buffer, params));
3814
+ __tnRegisterDynamicValidate("ManagerInstruction", (buffer) => { const result = ManagerInstruction.validate(buffer); const params = (result as { params?: Record<string, bigint> }).params; return { ok: result.ok, code: result.code, consumed: result.consumed === undefined ? undefined : __tnToBigInt(result.consumed), params }; });