@thru/programs 0.3.3 → 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 (122) 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-7DRJVAYI.js +8587 -0
  17. package/dist/chunk-7DRJVAYI.js.map +1 -0
  18. package/dist/chunk-7FBCBZIY.js +41 -0
  19. package/dist/chunk-7FBCBZIY.js.map +1 -0
  20. package/dist/chunk-BNYDH4ZP.js +4351 -0
  21. package/dist/chunk-BNYDH4ZP.js.map +1 -0
  22. package/dist/chunk-OODN6LJA.js +6567 -0
  23. package/dist/chunk-OODN6LJA.js.map +1 -0
  24. package/dist/chunk-YX7BLFQZ.js +81 -0
  25. package/dist/chunk-YX7BLFQZ.js.map +1 -0
  26. package/dist/clob/index.cjs +19361 -6851
  27. package/dist/clob/index.cjs.map +1 -1
  28. package/dist/clob/index.d.cts +1243 -63
  29. package/dist/clob/index.d.ts +1243 -63
  30. package/dist/clob/index.js +6826 -2818
  31. package/dist/clob/index.js.map +1 -1
  32. package/dist/deploy/index.cjs +24734 -0
  33. package/dist/deploy/index.cjs.map +1 -0
  34. package/dist/deploy/index.d.cts +180 -0
  35. package/dist/deploy/index.d.ts +180 -0
  36. package/dist/deploy/index.js +1846 -0
  37. package/dist/deploy/index.js.map +1 -0
  38. package/dist/helpers-DD7q61nr.d.cts +7 -0
  39. package/dist/helpers-DD7q61nr.d.ts +7 -0
  40. package/dist/manager/index.cjs +6680 -0
  41. package/dist/manager/index.cjs.map +1 -0
  42. package/dist/manager/index.d.cts +1279 -0
  43. package/dist/manager/index.d.ts +1279 -0
  44. package/dist/manager/index.js +4 -0
  45. package/dist/manager/index.js.map +1 -0
  46. package/dist/passkey-manager/index.cjs +4 -5
  47. package/dist/passkey-manager/index.cjs.map +1 -1
  48. package/dist/passkey-manager/index.js +2 -2
  49. package/dist/token/index.js +1 -8585
  50. package/dist/token/index.js.map +1 -1
  51. package/dist/uploader/index.cjs +4442 -0
  52. package/dist/uploader/index.cjs.map +1 -0
  53. package/dist/uploader/index.d.cts +761 -0
  54. package/dist/uploader/index.d.ts +761 -0
  55. package/dist/uploader/index.js +4 -0
  56. package/dist/uploader/index.js.map +1 -0
  57. package/package.json +22 -2
  58. package/src/abi-manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  59. package/src/abi-manager/abi/thru/common/primitives/types.ts +2428 -0
  60. package/src/abi-manager/abi/thru/program/abi_manager/types.ts +7037 -0
  61. package/src/abi-manager/accounts.ts +91 -0
  62. package/src/abi-manager/constants.ts +19 -0
  63. package/src/abi-manager/derivation.ts +86 -0
  64. package/src/abi-manager/errors.ts +48 -0
  65. package/src/abi-manager/index.test.ts +136 -0
  66. package/src/abi-manager/index.ts +56 -0
  67. package/src/abi-manager/instructions.ts +573 -0
  68. package/src/abi-manager/types.ts +150 -0
  69. package/src/amm/index.test.ts +8 -2
  70. package/src/amm/index.ts +1 -1
  71. package/src/clob/abi/thru/program/clob/types.ts +6981 -3070
  72. package/src/clob/exchange-client.test.ts +592 -0
  73. package/src/clob/exchange-client.ts +953 -0
  74. package/src/clob/exchange.test.ts +18 -16
  75. package/src/clob/exchange.ts +4 -0
  76. package/src/clob/index.test.ts +134 -7
  77. package/src/clob/index.ts +303 -10
  78. package/src/clob/price.test.ts +32 -0
  79. package/src/clob/price.ts +77 -0
  80. package/src/deploy/accounts.ts +208 -0
  81. package/src/deploy/chain.ts +163 -0
  82. package/src/deploy/constants.ts +25 -0
  83. package/src/deploy/deploy.test.ts +349 -0
  84. package/src/deploy/errors.ts +72 -0
  85. package/src/deploy/index.ts +44 -0
  86. package/src/deploy/inspection.ts +146 -0
  87. package/src/deploy/seeds.ts +29 -0
  88. package/src/deploy/types.ts +178 -0
  89. package/src/deploy/uploader.test.ts +326 -0
  90. package/src/deploy/uploader.ts +558 -0
  91. package/src/deploy/validation-imports.test.ts +55 -0
  92. package/src/deploy/validation.ts +183 -0
  93. package/src/deploy/workflows.test.ts +422 -0
  94. package/src/deploy/workflows.ts +1088 -0
  95. package/src/helpers/bytes.test.ts +58 -0
  96. package/src/helpers/bytes.ts +28 -3
  97. package/src/manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
  98. package/src/manager/abi/thru/common/primitives/types.ts +2428 -0
  99. package/src/manager/abi/thru/program/manager/types.ts +3814 -0
  100. package/src/manager/accounts.ts +44 -0
  101. package/src/manager/constants.ts +16 -0
  102. package/src/manager/derivation.ts +32 -0
  103. package/src/manager/errors.ts +47 -0
  104. package/src/manager/index.test.ts +108 -0
  105. package/src/manager/index.ts +68 -0
  106. package/src/manager/instructions.ts +281 -0
  107. package/src/manager/types.ts +95 -0
  108. package/src/manager/validation.ts +35 -0
  109. package/src/uploader/abi/thru/common/primitives/types.ts +2428 -0
  110. package/src/uploader/abi/thru/program/uploader/types.ts +3022 -0
  111. package/src/uploader/accounts.ts +38 -0
  112. package/src/uploader/constants.ts +14 -0
  113. package/src/uploader/derivation.ts +34 -0
  114. package/src/uploader/errors.ts +25 -0
  115. package/src/uploader/index.test.ts +107 -0
  116. package/src/uploader/index.ts +34 -0
  117. package/src/uploader/instructions.ts +163 -0
  118. package/src/uploader/types.ts +67 -0
  119. package/src/utils/helpers.ts +121 -0
  120. package/tsup.config.ts +4 -0
  121. package/dist/chunk-P5OABVJI.js +0 -28
  122. package/dist/chunk-P5OABVJI.js.map +0 -1
@@ -0,0 +1,3022 @@
1
+ /* Auto-generated TypeScript code */
2
+ /* WARNING: Do not modify this file directly. It is generated from ABI definitions. */
3
+
4
+ import { Hash, Pubkey } from "../../common/primitives/types";
5
+
6
+ type __TnIrNode =
7
+ | { readonly op: "zero" }
8
+ | { readonly op: "const"; readonly value: bigint }
9
+ | { readonly op: "field"; readonly param: string }
10
+ | {
11
+ readonly op: "add";
12
+ readonly left: __TnIrNode;
13
+ readonly right: __TnIrNode;
14
+ }
15
+ | {
16
+ readonly op: "sub";
17
+ readonly left: __TnIrNode;
18
+ readonly right: __TnIrNode;
19
+ }
20
+ | {
21
+ readonly op: "mul";
22
+ readonly left: __TnIrNode;
23
+ readonly right: __TnIrNode;
24
+ }
25
+ | {
26
+ readonly op:
27
+ | "div"
28
+ | "mod"
29
+ | "bitAnd"
30
+ | "bitOr"
31
+ | "bitXor"
32
+ | "leftShift"
33
+ | "rightShift";
34
+ readonly left: __TnIrNode;
35
+ readonly right: __TnIrNode;
36
+ }
37
+ | {
38
+ readonly op: "align";
39
+ readonly alignment: number;
40
+ readonly node: __TnIrNode;
41
+ }
42
+ | {
43
+ readonly op: "switch";
44
+ readonly tag: string;
45
+ readonly cases: readonly { readonly value: number; readonly node: __TnIrNode }[];
46
+ readonly default?: __TnIrNode;
47
+ }
48
+ | {
49
+ readonly op: "call";
50
+ readonly typeName: string;
51
+ readonly args: readonly { readonly name: string; readonly source: string }[];
52
+ }
53
+ | {
54
+ readonly op: "sumOverArray";
55
+ readonly count: __TnIrNode;
56
+ readonly elementTypeName: string;
57
+ readonly fieldName: string;
58
+ };
59
+
60
+ type __TnIrContext = {
61
+ params: Record<string, bigint>;
62
+ buffer?: Uint8Array;
63
+ typeName?: string;
64
+ };
65
+
66
+ type __TnValidateResult = {
67
+ ok: boolean;
68
+ code?: string;
69
+ consumed?: bigint;
70
+ params?: Record<string, bigint>;
71
+ };
72
+ type __TnEvalResult =
73
+ | { ok: true; value: bigint }
74
+ | { ok: false; code: string };
75
+ type __TnBuilderLike = { build(): Uint8Array };
76
+ type __TnStructFieldInput =
77
+ | Uint8Array
78
+ | __TnBuilderLike
79
+ | { buffer?: Uint8Array }
80
+ | { asUint8Array?: () => Uint8Array }
81
+ | { bytes?: () => Uint8Array };
82
+ type __TnVariantDescriptor = {
83
+ readonly name: string;
84
+ readonly tag: number;
85
+ readonly payloadSize: number | null;
86
+ readonly payloadType?: string;
87
+ readonly createPayloadBuilder?: () => unknown | null;
88
+ };
89
+ type __TnVariantSelectorResult<Parent> = {
90
+ select(
91
+ name: string
92
+ ): { writePayload(payload: Uint8Array | __TnBuilderLike): { finish(): Parent } };
93
+ finish(): Parent;
94
+ };
95
+ type __TnFamWriterResult<Parent> = {
96
+ write(payload: Uint8Array | __TnBuilderLike): { finish(): Parent };
97
+ finish(): Parent;
98
+ };
99
+ type __TnConsole = { warn?: (...args: unknown[]) => void };
100
+
101
+ const __tnWarnings = new Set<string>();
102
+ const __tnHasNativeBigInt = typeof BigInt === "function";
103
+ const __tnHasBigIntDataView =
104
+ typeof DataView !== "undefined" &&
105
+ typeof DataView.prototype.getBigInt64 === "function" &&
106
+ typeof DataView.prototype.getBigUint64 === "function" &&
107
+ typeof DataView.prototype.setBigInt64 === "function" &&
108
+ typeof DataView.prototype.setBigUint64 === "function";
109
+ const __tnConsole: __TnConsole | undefined =
110
+ typeof globalThis !== "undefined"
111
+ ? (globalThis as { console?: __TnConsole }).console
112
+ : undefined;
113
+
114
+ function __tnLogWarn(message: string): void {
115
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
116
+ __tnConsole.warn(message);
117
+ }
118
+ }
119
+
120
+ function __tnWarnOnce(message: string): void {
121
+ if (!__tnWarnings.has(message)) {
122
+ __tnWarnings.add(message);
123
+ __tnLogWarn(message);
124
+ }
125
+ }
126
+
127
+ function __tnResolveBuilderInput(
128
+ input: Uint8Array | __TnBuilderLike,
129
+ context: string
130
+ ): Uint8Array {
131
+ if (input instanceof Uint8Array) {
132
+ return new Uint8Array(input);
133
+ }
134
+ if (input && typeof (input as __TnBuilderLike).build === "function") {
135
+ const built = (input as __TnBuilderLike).build();
136
+ if (!(built instanceof Uint8Array)) {
137
+ throw new Error(`${context}: builder did not return Uint8Array`);
138
+ }
139
+ return new Uint8Array(built);
140
+ }
141
+ throw new Error(`${context}: expected Uint8Array or builder`);
142
+ }
143
+
144
+ function __tnResolveStructFieldInput(
145
+ input: __TnStructFieldInput,
146
+ context: string
147
+ ): Uint8Array {
148
+ if (
149
+ input instanceof Uint8Array ||
150
+ (input && typeof (input as __TnBuilderLike).build === "function")
151
+ ) {
152
+ return __tnResolveBuilderInput(input as Uint8Array | __TnBuilderLike, context);
153
+ }
154
+ if (input && typeof (input as { asUint8Array?: () => Uint8Array }).asUint8Array === "function") {
155
+ const bytes = (input as { asUint8Array: () => Uint8Array }).asUint8Array();
156
+ return new Uint8Array(bytes);
157
+ }
158
+ if (input && typeof (input as { bytes?: () => Uint8Array }).bytes === "function") {
159
+ const bytes = (input as { bytes: () => Uint8Array }).bytes();
160
+ return new Uint8Array(bytes);
161
+ }
162
+ if (input && (input as { buffer?: unknown }).buffer instanceof Uint8Array) {
163
+ return new Uint8Array((input as { buffer: Uint8Array }).buffer);
164
+ }
165
+ throw new Error(`${context}: expected Uint8Array, builder, or view-like value`);
166
+ }
167
+
168
+ function __tnMaybeCallBuilder(ctor: unknown): unknown | null {
169
+ if (!ctor) {
170
+ return null;
171
+ }
172
+ const builderFn = (ctor as { builder?: () => unknown }).builder;
173
+ return typeof builderFn === "function" ? builderFn() : null;
174
+ }
175
+
176
+ function __tnCreateVariantSelector<Parent, Descriptor extends __TnVariantDescriptor>(
177
+ parent: Parent,
178
+ descriptors: readonly Descriptor[],
179
+ assign: (descriptor: Descriptor, payload: Uint8Array) => void
180
+ ): __TnVariantSelectorResult<Parent> {
181
+ return {
182
+ select(name: string) {
183
+ const descriptor = descriptors.find((variant) => variant.name === name);
184
+ if (!descriptor) {
185
+ throw new Error(`Unknown variant '${name}'`);
186
+ }
187
+ return {
188
+ writePayload(payload: Uint8Array | __TnBuilderLike) {
189
+ const bytes = __tnResolveBuilderInput(
190
+ payload,
191
+ `variant ${descriptor.name}`
192
+ );
193
+ if (
194
+ descriptor.payloadSize !== null &&
195
+ bytes.length !== descriptor.payloadSize
196
+ ) {
197
+ throw new Error(
198
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
199
+ );
200
+ }
201
+ assign(descriptor, bytes);
202
+ return {
203
+ finish(): Parent {
204
+ return parent;
205
+ },
206
+ };
207
+ },
208
+ };
209
+ },
210
+ finish(): Parent {
211
+ return parent;
212
+ },
213
+ };
214
+ }
215
+
216
+ function __tnCreateFamWriter<Parent>(
217
+ parent: Parent,
218
+ fieldName: string,
219
+ assign: (bytes: Uint8Array) => void
220
+ ): __TnFamWriterResult<Parent> {
221
+ let hasWritten = false;
222
+ return {
223
+ write(payload: Uint8Array | __TnBuilderLike) {
224
+ const bytes = __tnResolveBuilderInput(
225
+ payload,
226
+ `flexible array '${fieldName}'`
227
+ );
228
+ const copy = new Uint8Array(bytes);
229
+ assign(copy);
230
+ hasWritten = true;
231
+ return {
232
+ finish(): Parent {
233
+ return parent;
234
+ },
235
+ };
236
+ },
237
+ finish(): Parent {
238
+ if (!hasWritten) {
239
+ throw new Error(
240
+ `flexible array '${fieldName}' requires write() before finish()`
241
+ );
242
+ }
243
+ return parent;
244
+ },
245
+ };
246
+ }
247
+
248
+ const __tnMask32 = __tnHasNativeBigInt
249
+ ? (BigInt(1) << BigInt(32)) - BigInt(1)
250
+ : 0xffffffff;
251
+ const __tnSignBit32 = __tnHasNativeBigInt
252
+ ? BigInt(1) << BigInt(31)
253
+ : 0x80000000;
254
+
255
+ function __tnToBigInt(value: number | bigint): bigint {
256
+ if (__tnHasNativeBigInt) {
257
+ return typeof value === "bigint" ? value : BigInt(value);
258
+ }
259
+ if (typeof value === "bigint") return value;
260
+ if (!Number.isFinite(value)) {
261
+ throw new Error("IR runtime received non-finite numeric input");
262
+ }
263
+ if (!Number.isSafeInteger(value)) {
264
+ __tnWarnOnce(
265
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
266
+ );
267
+ }
268
+ return (value as unknown) as bigint;
269
+ }
270
+
271
+ function __tnBigIntToNumber(value: bigint, context: string): number {
272
+ if (__tnHasNativeBigInt) {
273
+ const converted = Number(value);
274
+ if (!Number.isFinite(converted)) {
275
+ throw new Error(`${context} overflowed Number range`);
276
+ }
277
+ return converted;
278
+ }
279
+ return value as unknown as number;
280
+ }
281
+
282
+ function __tnBigIntEquals(lhs: bigint, rhs: bigint): boolean {
283
+ if (__tnHasNativeBigInt) return lhs === rhs;
284
+ return (lhs as unknown as number) === (rhs as unknown as number);
285
+ }
286
+
287
+ function __tnBigIntGreaterThan(lhs: bigint, rhs: bigint): boolean {
288
+ if (__tnHasNativeBigInt) return lhs > rhs;
289
+ return (lhs as unknown as number) > (rhs as unknown as number);
290
+ }
291
+
292
+ function __tnPopcount(value: number | bigint): number {
293
+ let v =
294
+ typeof value === "bigint"
295
+ ? Number(value & BigInt(0xffffffff))
296
+ : Number(value) >>> 0;
297
+ v = v - ((v >>> 1) & 0x55555555);
298
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
299
+ return (((v + (v >>> 4)) & 0x0f0f0f0f) * 0x01010101) >>> 24;
300
+ }
301
+
302
+ function __tnRaiseIrError(code: string, message: string): never {
303
+ const err = new Error(message);
304
+ (err as { code?: string }).code = code;
305
+ throw err;
306
+ }
307
+
308
+ function __tnCheckedAdd(lhs: bigint, rhs: bigint): bigint {
309
+ if (__tnHasNativeBigInt) {
310
+ const result = (lhs as bigint) + (rhs as bigint);
311
+ if (result < BigInt(0)) {
312
+ __tnRaiseIrError(
313
+ "tn.ir.overflow",
314
+ "IR runtime detected negative size via addition"
315
+ );
316
+ }
317
+ return result;
318
+ }
319
+ const left = lhs as unknown as number;
320
+ const right = rhs as unknown as number;
321
+ const sum = left + right;
322
+ if (sum < 0 || !Number.isFinite(sum)) {
323
+ __tnRaiseIrError(
324
+ "tn.ir.overflow",
325
+ "IR runtime detected invalid addition result"
326
+ );
327
+ }
328
+ if (!Number.isSafeInteger(sum)) {
329
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
330
+ }
331
+ return (sum as unknown) as bigint;
332
+ }
333
+
334
+ function __tnCheckedSub(lhs: bigint, rhs: bigint): bigint {
335
+ if (__tnHasNativeBigInt) {
336
+ const result = (lhs as bigint) - (rhs as bigint);
337
+ if (result < BigInt(0)) {
338
+ __tnRaiseIrError(
339
+ "tn.ir.overflow",
340
+ "IR runtime detected negative size via subtraction"
341
+ );
342
+ }
343
+ return result;
344
+ }
345
+ const left = lhs as unknown as number;
346
+ const right = rhs as unknown as number;
347
+ const diff = left - right;
348
+ if (diff < 0 || !Number.isFinite(diff)) {
349
+ __tnRaiseIrError(
350
+ "tn.ir.overflow",
351
+ "IR runtime detected invalid subtraction result"
352
+ );
353
+ }
354
+ if (!Number.isSafeInteger(diff)) {
355
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt subtraction");
356
+ }
357
+ return (diff as unknown) as bigint;
358
+ }
359
+
360
+ function __tnCheckedMul(lhs: bigint, rhs: bigint): bigint {
361
+ if (__tnHasNativeBigInt) {
362
+ const result = (lhs as bigint) * (rhs as bigint);
363
+ if (result < BigInt(0)) {
364
+ __tnRaiseIrError(
365
+ "tn.ir.overflow",
366
+ "IR runtime detected negative size via multiplication"
367
+ );
368
+ }
369
+ return result;
370
+ }
371
+ const left = lhs as unknown as number;
372
+ const right = rhs as unknown as number;
373
+ const product = left * right;
374
+ if (product < 0 || !Number.isFinite(product)) {
375
+ __tnRaiseIrError(
376
+ "tn.ir.overflow",
377
+ "IR runtime detected invalid multiplication result"
378
+ );
379
+ }
380
+ if (!Number.isSafeInteger(product)) {
381
+ __tnWarnOnce(
382
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
383
+ );
384
+ }
385
+ return (product as unknown) as bigint;
386
+ }
387
+
388
+ function __tnCheckedDiv(lhs: bigint, rhs: bigint): bigint {
389
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
390
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime division by zero");
391
+ }
392
+ if (__tnHasNativeBigInt) return (lhs as bigint) / (rhs as bigint);
393
+ const quotient = Math.floor((lhs as unknown as number) / (rhs as unknown as number));
394
+ return (quotient as unknown) as bigint;
395
+ }
396
+
397
+ function __tnCheckedMod(lhs: bigint, rhs: bigint): bigint {
398
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
399
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime modulo by zero");
400
+ }
401
+ if (__tnHasNativeBigInt) return (lhs as bigint) % (rhs as bigint);
402
+ return (((lhs as unknown as number) % (rhs as unknown as number)) as unknown) as bigint;
403
+ }
404
+
405
+ function __tnBitwise(
406
+ lhs: bigint,
407
+ rhs: bigint,
408
+ op: "and" | "or" | "xor"
409
+ ): bigint {
410
+ if (__tnHasNativeBigInt) {
411
+ if (op === "and") return (lhs as bigint) & (rhs as bigint);
412
+ if (op === "or") return (lhs as bigint) | (rhs as bigint);
413
+ return (lhs as bigint) ^ (rhs as bigint);
414
+ }
415
+ const left = lhs as unknown as number;
416
+ const right = rhs as unknown as number;
417
+ const maxU32 = 0xffffffff;
418
+ if (
419
+ !Number.isInteger(left) ||
420
+ !Number.isInteger(right) ||
421
+ left < 0 ||
422
+ right < 0 ||
423
+ left > maxU32 ||
424
+ right > maxU32
425
+ ) {
426
+ __tnRaiseIrError(
427
+ "tn.ir.overflow",
428
+ "IR runtime bitwise operation requires BigInt for values outside u32 range"
429
+ );
430
+ }
431
+ const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
432
+ return ((result >>> 0) as unknown) as bigint;
433
+ }
434
+
435
+ function __tnCheckedShift(
436
+ lhs: bigint,
437
+ rhs: bigint,
438
+ direction: "left" | "right"
439
+ ): bigint {
440
+ const amount = __tnBigIntToNumber(rhs, "IR shift amount");
441
+ if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
442
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime invalid shift amount");
443
+ }
444
+ if (__tnHasNativeBigInt) {
445
+ const shift = BigInt(amount);
446
+ return direction === "left" ? (lhs as bigint) << shift : (lhs as bigint) >> shift;
447
+ }
448
+ const value = lhs as unknown as number;
449
+ const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
450
+ if (!Number.isSafeInteger(result)) {
451
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt shift");
452
+ }
453
+ return (result as unknown) as bigint;
454
+ }
455
+
456
+ function __tnAlign(value: bigint, alignment: number): bigint {
457
+ if (alignment <= 1) return value;
458
+ const alignBig = __tnToBigInt(alignment);
459
+ if (__tnHasNativeBigInt) {
460
+ const remainder = value % alignBig;
461
+ if (__tnBigIntEquals(remainder, __tnToBigInt(0))) {
462
+ return value;
463
+ }
464
+ const delta = alignBig - remainder;
465
+ return __tnCheckedAdd(value, delta);
466
+ }
467
+ const current = __tnBigIntToNumber(value, "IR align");
468
+ const alignNum = alignment >>> 0;
469
+ const remainder = current % alignNum;
470
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
471
+ return __tnToBigInt(next);
472
+ }
473
+
474
+ function __tnSplitUint64(value: bigint): { high: number; low: number } {
475
+ if (__tnHasNativeBigInt) {
476
+ const low = Number(value & (__tnMask32 as bigint));
477
+ const high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
478
+ return { high, low };
479
+ }
480
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
481
+ const low = num >>> 0;
482
+ const high = Math.floor(num / 4294967296) >>> 0;
483
+ return { high, low };
484
+ }
485
+
486
+ function __tnSplitInt64(value: bigint): { high: number; low: number } {
487
+ if (__tnHasNativeBigInt) {
488
+ const low = Number(value & (__tnMask32 as bigint));
489
+ let high = Number((value >> BigInt(32)) & (__tnMask32 as bigint));
490
+ if ((BigInt(high) & (__tnSignBit32 as bigint)) !== BigInt(0)) {
491
+ high -= 0x100000000;
492
+ }
493
+ return { high, low };
494
+ }
495
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
496
+ const low = num >>> 0;
497
+ const high = Math.floor(num / 4294967296);
498
+ return { high, low };
499
+ }
500
+
501
+ function __tnPolyfillReadUint64(
502
+ view: DataView,
503
+ offset: number,
504
+ littleEndian: boolean
505
+ ): bigint {
506
+ const low = littleEndian
507
+ ? view.getUint32(offset, true)
508
+ : view.getUint32(offset + 4, false);
509
+ const high = littleEndian
510
+ ? view.getUint32(offset + 4, true)
511
+ : view.getUint32(offset, false);
512
+ if (__tnHasNativeBigInt) {
513
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
514
+ }
515
+ const value = high * 4294967296 + low;
516
+ if (!Number.isSafeInteger(value)) {
517
+ __tnWarnOnce(
518
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
519
+ );
520
+ }
521
+ return (value as unknown) as bigint;
522
+ }
523
+
524
+ function __tnPolyfillReadInt64(
525
+ view: DataView,
526
+ offset: number,
527
+ littleEndian: boolean
528
+ ): bigint {
529
+ const low = littleEndian
530
+ ? view.getUint32(offset, true)
531
+ : view.getUint32(offset + 4, false);
532
+ const high = littleEndian
533
+ ? view.getInt32(offset + 4, true)
534
+ : view.getInt32(offset, false);
535
+ if (__tnHasNativeBigInt) {
536
+ return (BigInt(high) << BigInt(32)) | BigInt(low);
537
+ }
538
+ const value = high * 4294967296 + low;
539
+ if (!Number.isSafeInteger(value)) {
540
+ __tnWarnOnce(
541
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
542
+ );
543
+ }
544
+ return (value as unknown) as bigint;
545
+ }
546
+
547
+ function __tnPolyfillWriteUint64(
548
+ view: DataView,
549
+ offset: number,
550
+ value: bigint,
551
+ littleEndian: boolean
552
+ ): void {
553
+ const parts = __tnSplitUint64(value);
554
+ if (littleEndian) {
555
+ view.setUint32(offset, parts.low, true);
556
+ view.setUint32(offset + 4, parts.high, true);
557
+ } else {
558
+ view.setUint32(offset, parts.high, false);
559
+ view.setUint32(offset + 4, parts.low, false);
560
+ }
561
+ }
562
+
563
+ function __tnPolyfillWriteInt64(
564
+ view: DataView,
565
+ offset: number,
566
+ value: bigint,
567
+ littleEndian: boolean
568
+ ): void {
569
+ const parts = __tnSplitInt64(value);
570
+ if (littleEndian) {
571
+ view.setUint32(offset, parts.low >>> 0, true);
572
+ view.setInt32(offset + 4, parts.high | 0, true);
573
+ } else {
574
+ view.setInt32(offset, parts.high | 0, false);
575
+ view.setUint32(offset + 4, parts.low >>> 0, false);
576
+ }
577
+ }
578
+
579
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
580
+ const proto = DataView.prototype as unknown as Record<string, unknown>;
581
+ if (typeof proto.getBigUint64 !== "function") {
582
+ (proto as any).getBigUint64 = function (
583
+ offset: number,
584
+ littleEndian?: boolean
585
+ ): bigint {
586
+ __tnWarnOnce(
587
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
588
+ );
589
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
590
+ };
591
+ }
592
+ if (typeof proto.getBigInt64 !== "function") {
593
+ (proto as any).getBigInt64 = function (
594
+ offset: number,
595
+ littleEndian?: boolean
596
+ ): bigint {
597
+ __tnWarnOnce(
598
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
599
+ );
600
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
601
+ };
602
+ }
603
+ if (typeof proto.setBigUint64 !== "function") {
604
+ (proto as any).setBigUint64 = function (
605
+ offset: number,
606
+ value: bigint,
607
+ littleEndian?: boolean
608
+ ): void {
609
+ __tnWarnOnce(
610
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
611
+ );
612
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
613
+ };
614
+ }
615
+ if (typeof proto.setBigInt64 !== "function") {
616
+ (proto as any).setBigInt64 = function (
617
+ offset: number,
618
+ value: bigint,
619
+ littleEndian?: boolean
620
+ ): void {
621
+ __tnWarnOnce(
622
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
623
+ );
624
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
625
+ };
626
+ }
627
+ if (!__tnHasNativeBigInt) {
628
+ __tnWarnOnce(
629
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
630
+ );
631
+ }
632
+ }
633
+
634
+ const __tnFootprintRegistry: Record<
635
+ string,
636
+ (params: Record<string, bigint>) => bigint
637
+ > = {};
638
+ const __tnValidateRegistry: Record<
639
+ string,
640
+ (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
641
+ > = {};
642
+ const __tnDynamicValidateRegistry: Record<
643
+ string,
644
+ (buffer: Uint8Array) => __TnValidateResult
645
+ > = {};
646
+
647
+ function __tnRegisterFootprint(
648
+ typeName: string,
649
+ fn: (params: Record<string, bigint>) => bigint
650
+ ): void {
651
+ __tnFootprintRegistry[typeName] = fn;
652
+ }
653
+
654
+ function __tnRegisterValidate(
655
+ typeName: string,
656
+ fn: (buffer: Uint8Array, params: Record<string, bigint>) => __TnValidateResult
657
+ ): void {
658
+ __tnValidateRegistry[typeName] = fn;
659
+ }
660
+
661
+ function __tnRegisterDynamicValidate(
662
+ typeName: string,
663
+ fn: (buffer: Uint8Array) => __TnValidateResult
664
+ ): void {
665
+ __tnDynamicValidateRegistry[typeName] = fn;
666
+ }
667
+
668
+ function __tnInvokeFootprint(
669
+ typeName: string,
670
+ params: Record<string, bigint>
671
+ ): bigint {
672
+ const fn = __tnFootprintRegistry[typeName];
673
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
674
+ return fn(params);
675
+ }
676
+
677
+ function __tnInvokeValidate(
678
+ typeName: string,
679
+ buffer: Uint8Array,
680
+ params: Record<string, bigint>
681
+ ): __TnValidateResult {
682
+ const fn = __tnValidateRegistry[typeName];
683
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
684
+ return fn(buffer, params);
685
+ }
686
+
687
+ function __tnInvokeDynamicValidate(
688
+ typeName: string,
689
+ buffer: Uint8Array
690
+ ): __TnValidateResult {
691
+ const fn = __tnDynamicValidateRegistry[typeName];
692
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
693
+ return fn(buffer);
694
+ }
695
+
696
+ function __tnEvalFootprint(node: __TnIrNode, ctx: __TnIrContext): bigint {
697
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
698
+ }
699
+
700
+ function __tnTryEvalFootprint(
701
+ node: __TnIrNode,
702
+ ctx: __TnIrContext
703
+ ): __TnEvalResult {
704
+ return __tnTryEvalIr(node, ctx);
705
+ }
706
+
707
+ function __tnTryEvalIr(
708
+ node: __TnIrNode,
709
+ ctx: __TnIrContext
710
+ ): __TnEvalResult {
711
+ try {
712
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
713
+ } catch (err) {
714
+ return { ok: false, code: __tnNormalizeIrError(err) };
715
+ }
716
+ }
717
+
718
+ function __tnIsEvalError(result: __TnEvalResult): result is { ok: false; code: string } {
719
+ return result.ok === false;
720
+ }
721
+
722
+ function __tnValidateIrTree(
723
+ ir: { readonly typeName: string; readonly root: __TnIrNode },
724
+ buffer: Uint8Array,
725
+ params: Record<string, bigint>
726
+ ): __TnValidateResult {
727
+ const evalResult = __tnTryEvalIr(ir.root, {
728
+ params,
729
+ buffer,
730
+ typeName: ir.typeName,
731
+ });
732
+ if (__tnIsEvalError(evalResult)) {
733
+ return { ok: false, code: evalResult.code };
734
+ }
735
+ const required = evalResult.value;
736
+ const available = __tnToBigInt(buffer.length);
737
+ if (__tnBigIntGreaterThan(required, available)) {
738
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
739
+ }
740
+ return { ok: true, consumed: required };
741
+ }
742
+
743
+ function __tnEvalIrNode(
744
+ node: __TnIrNode,
745
+ ctx: __TnIrContext,
746
+ baseOffset: bigint
747
+ ): bigint {
748
+ switch (node.op) {
749
+ case "zero":
750
+ return __tnToBigInt(0);
751
+ case "const":
752
+ return node.value;
753
+ case "field": {
754
+ if (node.param === "__buffer_size" && ctx.buffer) {
755
+ return __tnToBigInt(ctx.buffer.length);
756
+ }
757
+ const val = ctx.params[node.param];
758
+ if (val === undefined) {
759
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
760
+ __tnRaiseIrError(
761
+ "tn.ir.missing_param",
762
+ `${prefix}Missing IR parameter '${node.param}'`
763
+ );
764
+ }
765
+ return val;
766
+ }
767
+ case "add":
768
+ {
769
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
770
+ const right = __tnEvalIrNode(
771
+ node.right,
772
+ ctx,
773
+ __tnCheckedAdd(baseOffset, left)
774
+ );
775
+ return __tnCheckedAdd(left, right);
776
+ }
777
+ case "sub":
778
+ return __tnCheckedSub(
779
+ __tnEvalIrNode(node.left, ctx, baseOffset),
780
+ __tnEvalIrNode(node.right, ctx, baseOffset)
781
+ );
782
+ case "mul":
783
+ return __tnCheckedMul(
784
+ __tnEvalIrNode(node.left, ctx, baseOffset),
785
+ __tnEvalIrNode(node.right, ctx, baseOffset)
786
+ );
787
+ case "div":
788
+ return __tnCheckedDiv(
789
+ __tnEvalIrNode(node.left, ctx, baseOffset),
790
+ __tnEvalIrNode(node.right, ctx, baseOffset)
791
+ );
792
+ case "mod":
793
+ return __tnCheckedMod(
794
+ __tnEvalIrNode(node.left, ctx, baseOffset),
795
+ __tnEvalIrNode(node.right, ctx, baseOffset)
796
+ );
797
+ case "bitAnd":
798
+ return __tnBitwise(
799
+ __tnEvalIrNode(node.left, ctx, baseOffset),
800
+ __tnEvalIrNode(node.right, ctx, baseOffset),
801
+ "and"
802
+ );
803
+ case "bitOr":
804
+ return __tnBitwise(
805
+ __tnEvalIrNode(node.left, ctx, baseOffset),
806
+ __tnEvalIrNode(node.right, ctx, baseOffset),
807
+ "or"
808
+ );
809
+ case "bitXor":
810
+ return __tnBitwise(
811
+ __tnEvalIrNode(node.left, ctx, baseOffset),
812
+ __tnEvalIrNode(node.right, ctx, baseOffset),
813
+ "xor"
814
+ );
815
+ case "leftShift":
816
+ return __tnCheckedShift(
817
+ __tnEvalIrNode(node.left, ctx, baseOffset),
818
+ __tnEvalIrNode(node.right, ctx, baseOffset),
819
+ "left"
820
+ );
821
+ case "rightShift":
822
+ return __tnCheckedShift(
823
+ __tnEvalIrNode(node.left, ctx, baseOffset),
824
+ __tnEvalIrNode(node.right, ctx, baseOffset),
825
+ "right"
826
+ );
827
+ case "align":
828
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
829
+ case "switch": {
830
+ const tagVal = ctx.params[node.tag];
831
+ if (tagVal === undefined) {
832
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
833
+ __tnRaiseIrError(
834
+ "tn.ir.missing_param",
835
+ `${prefix}Missing IR switch tag '${node.tag}'`
836
+ );
837
+ }
838
+ const tagNumber = Number(tagVal);
839
+ for (const caseNode of node.cases) {
840
+ if (caseNode.value === tagNumber) {
841
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
842
+ }
843
+ }
844
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
845
+ __tnRaiseIrError(
846
+ "tn.ir.invalid_tag",
847
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
848
+ );
849
+ }
850
+ case "call": {
851
+ const nestedParams: Record<string, bigint> = Object.create(null);
852
+ for (const arg of node.args) {
853
+ const val = ctx.params[arg.source];
854
+ if (val === undefined) {
855
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
856
+ __tnRaiseIrError(
857
+ "tn.ir.missing_param",
858
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
859
+ );
860
+ }
861
+ nestedParams[arg.name] = val;
862
+ }
863
+ if (ctx.buffer) {
864
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
865
+ const nestedResult = __tnInvokeValidate(
866
+ node.typeName,
867
+ ctx.buffer.subarray(nestedOffset),
868
+ nestedParams
869
+ );
870
+ if (!nestedResult.ok) {
871
+ const nestedCode =
872
+ nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
873
+ const prefixed = nestedCode.startsWith("tn.")
874
+ ? nestedCode
875
+ : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
876
+ __tnRaiseIrError(
877
+ prefixed,
878
+ `Nested validator ${node.typeName} failed`
879
+ );
880
+ }
881
+ if (nestedResult.consumed !== undefined) {
882
+ return nestedResult.consumed;
883
+ }
884
+ }
885
+ return __tnInvokeFootprint(node.typeName, nestedParams);
886
+ }
887
+ case "sumOverArray": {
888
+ if (!ctx.buffer) {
889
+ __tnRaiseIrError(
890
+ "tn.ir.missing_buffer",
891
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
892
+ );
893
+ }
894
+ const count = __tnBigIntToNumber(
895
+ __tnEvalIrNode(node.count, ctx, baseOffset),
896
+ `Jagged array '${node.fieldName}' count`
897
+ );
898
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
899
+ let total = __tnToBigInt(0);
900
+ for (let i = 0; i < count; i++) {
901
+ const result = __tnInvokeDynamicValidate(
902
+ node.elementTypeName,
903
+ ctx.buffer.subarray(cursor)
904
+ );
905
+ if (!result.ok || result.consumed === undefined) {
906
+ const code = result.code ?? "tn.ir.runtime_error";
907
+ __tnRaiseIrError(
908
+ code,
909
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
910
+ );
911
+ }
912
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
913
+ total = __tnCheckedAdd(total, result.consumed);
914
+ }
915
+ return total;
916
+ }
917
+ default:
918
+ __tnRaiseIrError(
919
+ "tn.ir.runtime_error",
920
+ `Unsupported IR node ${(node as { op: string }).op}`
921
+ );
922
+ }
923
+ }
924
+
925
+ function __tnNormalizeIrError(err: unknown): string {
926
+ if (err && typeof err === "object" && "code" in err) {
927
+ const maybeCode = (err as { code?: string }).code;
928
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
929
+ return maybeCode;
930
+ }
931
+ }
932
+ const message =
933
+ err && typeof err === "object" && "message" in err
934
+ ? String((err as { message?: unknown }).message ?? "")
935
+ : typeof err === "string"
936
+ ? err
937
+ : "";
938
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
939
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
940
+ if (
941
+ message.includes("invalid") ||
942
+ message.includes("overflow") ||
943
+ message.includes("negative size")
944
+ ) {
945
+ return "tn.ir.overflow";
946
+ }
947
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
948
+ return "tn.ir.runtime_error";
949
+ }
950
+
951
+ __tnRegisterFootprint("Hash", (params) => Hash.__tnInvokeFootprint(params));
952
+ __tnRegisterValidate("Hash", (buffer, params) => Hash.__tnInvokeValidate(buffer, params));
953
+ __tnRegisterDynamicValidate("Hash", (buffer) => { const result = Hash.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 }; });
954
+
955
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey.__tnInvokeFootprint(params));
956
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey.__tnInvokeValidate(buffer, params));
957
+ __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 }; });
958
+
959
+ /* ----- TYPE DEFINITION FOR DestroyArgs ----- */
960
+
961
+ const __tn_ir_DestroyArgs = {
962
+ typeName: "DestroyArgs",
963
+ root: { op: "const", value: 4n }
964
+ } as const;
965
+
966
+ export class DestroyArgs {
967
+ private view: DataView;
968
+
969
+ private constructor(private buffer: Uint8Array) {
970
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
971
+ }
972
+
973
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): DestroyArgs {
974
+ if (!buffer || buffer.length === undefined) throw new Error("DestroyArgs.__tnCreateView requires a Uint8Array");
975
+ return new DestroyArgs(new Uint8Array(buffer));
976
+ }
977
+
978
+ static builder(): DestroyArgsBuilder {
979
+ return new DestroyArgsBuilder();
980
+ }
981
+
982
+ static fromBuilder(builder: DestroyArgsBuilder): DestroyArgs | null {
983
+ const buffer = builder.build();
984
+ return DestroyArgs.from_array(buffer);
985
+ }
986
+
987
+ get_buffer_account_idx(): number {
988
+ const offset = 0;
989
+ return this.view.getUint16(offset, true); /* little-endian */
990
+ }
991
+
992
+ set_buffer_account_idx(value: number): void {
993
+ const offset = 0;
994
+ this.view.setUint16(offset, value, true); /* little-endian */
995
+ }
996
+
997
+ get buffer_account_idx(): number {
998
+ return this.get_buffer_account_idx();
999
+ }
1000
+
1001
+ set buffer_account_idx(value: number) {
1002
+ this.set_buffer_account_idx(value);
1003
+ }
1004
+
1005
+ get_meta_account_idx(): number {
1006
+ const offset = 2;
1007
+ return this.view.getUint16(offset, true); /* little-endian */
1008
+ }
1009
+
1010
+ set_meta_account_idx(value: number): void {
1011
+ const offset = 2;
1012
+ this.view.setUint16(offset, value, true); /* little-endian */
1013
+ }
1014
+
1015
+ get meta_account_idx(): number {
1016
+ return this.get_meta_account_idx();
1017
+ }
1018
+
1019
+ set meta_account_idx(value: number) {
1020
+ this.set_meta_account_idx(value);
1021
+ }
1022
+
1023
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1024
+ return __tnEvalFootprint(__tn_ir_DestroyArgs.root, { params: __tnParams });
1025
+ }
1026
+
1027
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1028
+ return __tnValidateIrTree(__tn_ir_DestroyArgs, buffer, __tnParams);
1029
+ }
1030
+
1031
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1032
+ return this.__tnFootprintInternal(__tnParams);
1033
+ }
1034
+
1035
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1036
+ return this.__tnValidateInternal(buffer, __tnParams);
1037
+ }
1038
+
1039
+ static footprintIr(): bigint {
1040
+ return this.__tnFootprintInternal(Object.create(null));
1041
+ }
1042
+
1043
+ static footprint(): number {
1044
+ const irResult = this.footprintIr();
1045
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1046
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1047
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for DestroyArgs');
1048
+ }
1049
+ return __tnBigIntToNumber(irResult, 'DestroyArgs::footprint');
1050
+ }
1051
+
1052
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1053
+ if (buffer.length < 4) return { ok: false, code: "tn.buffer_too_small", consumed: 4 };
1054
+ return { ok: true, consumed: 4 };
1055
+ }
1056
+
1057
+ static new(buffer_account_idx: number, meta_account_idx: number): DestroyArgs {
1058
+ const buffer = new Uint8Array(4);
1059
+ const view = new DataView(buffer.buffer);
1060
+
1061
+ let offset = 0;
1062
+ view.setUint16(0, buffer_account_idx, true); /* buffer_account_idx (little-endian) */
1063
+ view.setUint16(2, meta_account_idx, true); /* meta_account_idx (little-endian) */
1064
+
1065
+ return new DestroyArgs(buffer);
1066
+ }
1067
+
1068
+ static from_array(buffer: Uint8Array): DestroyArgs | null {
1069
+ if (!buffer || buffer.length === undefined) {
1070
+ return null;
1071
+ }
1072
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1073
+ const validation = this.validate(buffer);
1074
+ if (!validation.ok) {
1075
+ return null;
1076
+ }
1077
+ return new DestroyArgs(buffer);
1078
+ }
1079
+
1080
+ }
1081
+
1082
+ export class DestroyArgsBuilder {
1083
+ private buffer: Uint8Array;
1084
+ private view: DataView;
1085
+
1086
+ constructor() {
1087
+ this.buffer = new Uint8Array(4);
1088
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1089
+ }
1090
+
1091
+ set_buffer_account_idx(value: number): this {
1092
+ this.view.setUint16(0, value, true);
1093
+ return this;
1094
+ }
1095
+
1096
+ set_meta_account_idx(value: number): this {
1097
+ this.view.setUint16(2, value, true);
1098
+ return this;
1099
+ }
1100
+
1101
+ build(): Uint8Array {
1102
+ return this.buffer.slice();
1103
+ }
1104
+
1105
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1106
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1107
+ target.set(this.buffer, offset);
1108
+ return target;
1109
+ }
1110
+
1111
+ finish(): DestroyArgs {
1112
+ const view = DestroyArgs.from_array(this.buffer.slice());
1113
+ if (!view) throw new Error("failed to build DestroyArgs");
1114
+ return view;
1115
+ }
1116
+ }
1117
+
1118
+ __tnRegisterFootprint("DestroyArgs", (params) => DestroyArgs.__tnInvokeFootprint(params));
1119
+ __tnRegisterValidate("DestroyArgs", (buffer, params) => DestroyArgs.__tnInvokeValidate(buffer, params));
1120
+ __tnRegisterDynamicValidate("DestroyArgs", (buffer) => { const result = DestroyArgs.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 }; });
1121
+
1122
+ /* ----- TYPE DEFINITION FOR UploaderError ----- */
1123
+
1124
+ const __tn_ir_UploaderError = {
1125
+ typeName: "UploaderError",
1126
+ root: { op: "const", value: 8n }
1127
+ } as const;
1128
+
1129
+ export class UploaderError {
1130
+ private view: DataView;
1131
+
1132
+ private constructor(private buffer: Uint8Array) {
1133
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1134
+ }
1135
+
1136
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): UploaderError {
1137
+ if (!buffer || buffer.length === undefined) throw new Error("UploaderError.__tnCreateView requires a Uint8Array");
1138
+ return new UploaderError(new Uint8Array(buffer));
1139
+ }
1140
+
1141
+ static builder(): UploaderErrorBuilder {
1142
+ return new UploaderErrorBuilder();
1143
+ }
1144
+
1145
+ static fromBuilder(builder: UploaderErrorBuilder): UploaderError | null {
1146
+ const buffer = builder.build();
1147
+ return UploaderError.from_array(buffer);
1148
+ }
1149
+
1150
+ get_code(): bigint {
1151
+ const offset = 0;
1152
+ return this.view.getBigUint64(offset, true); /* little-endian */
1153
+ }
1154
+
1155
+ set_code(value: bigint): void {
1156
+ const offset = 0;
1157
+ this.view.setBigUint64(offset, value, true); /* little-endian */
1158
+ }
1159
+
1160
+ get code(): bigint {
1161
+ return this.get_code();
1162
+ }
1163
+
1164
+ set code(value: bigint) {
1165
+ this.set_code(value);
1166
+ }
1167
+
1168
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1169
+ return __tnEvalFootprint(__tn_ir_UploaderError.root, { params: __tnParams });
1170
+ }
1171
+
1172
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1173
+ return __tnValidateIrTree(__tn_ir_UploaderError, buffer, __tnParams);
1174
+ }
1175
+
1176
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1177
+ return this.__tnFootprintInternal(__tnParams);
1178
+ }
1179
+
1180
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1181
+ return this.__tnValidateInternal(buffer, __tnParams);
1182
+ }
1183
+
1184
+ static footprintIr(): bigint {
1185
+ return this.__tnFootprintInternal(Object.create(null));
1186
+ }
1187
+
1188
+ static footprint(): number {
1189
+ const irResult = this.footprintIr();
1190
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1191
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1192
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for UploaderError');
1193
+ }
1194
+ return __tnBigIntToNumber(irResult, 'UploaderError::footprint');
1195
+ }
1196
+
1197
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1198
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
1199
+ return { ok: true, consumed: 8 };
1200
+ }
1201
+
1202
+ static new(code: bigint): UploaderError {
1203
+ const buffer = new Uint8Array(8);
1204
+ const view = new DataView(buffer.buffer);
1205
+
1206
+ let offset = 0;
1207
+ view.setBigUint64(0, code, true); /* code (little-endian) */
1208
+
1209
+ return new UploaderError(buffer);
1210
+ }
1211
+
1212
+ static from_array(buffer: Uint8Array): UploaderError | null {
1213
+ if (!buffer || buffer.length === undefined) {
1214
+ return null;
1215
+ }
1216
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1217
+ const validation = this.validate(buffer);
1218
+ if (!validation.ok) {
1219
+ return null;
1220
+ }
1221
+ return new UploaderError(buffer);
1222
+ }
1223
+
1224
+ }
1225
+
1226
+ export class UploaderErrorBuilder {
1227
+ private buffer: Uint8Array;
1228
+ private view: DataView;
1229
+
1230
+ constructor() {
1231
+ this.buffer = new Uint8Array(8);
1232
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1233
+ }
1234
+
1235
+ set_code(value: bigint): this {
1236
+ const cast = __tnToBigInt(value);
1237
+ this.view.setBigUint64(0, cast, true);
1238
+ return this;
1239
+ }
1240
+
1241
+ build(): Uint8Array {
1242
+ return this.buffer.slice();
1243
+ }
1244
+
1245
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1246
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1247
+ target.set(this.buffer, offset);
1248
+ return target;
1249
+ }
1250
+
1251
+ finish(): UploaderError {
1252
+ const view = UploaderError.from_array(this.buffer.slice());
1253
+ if (!view) throw new Error("failed to build UploaderError");
1254
+ return view;
1255
+ }
1256
+ }
1257
+
1258
+ __tnRegisterFootprint("UploaderError", (params) => UploaderError.__tnInvokeFootprint(params));
1259
+ __tnRegisterValidate("UploaderError", (buffer, params) => UploaderError.__tnInvokeValidate(buffer, params));
1260
+ __tnRegisterDynamicValidate("UploaderError", (buffer) => { const result = UploaderError.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 }; });
1261
+
1262
+ /* ----- TYPE DEFINITION FOR UploaderProgramMeta ----- */
1263
+
1264
+ const __tn_ir_UploaderProgramMeta = {
1265
+ typeName: "UploaderProgramMeta",
1266
+ root: { op: "const", value: 65n }
1267
+ } as const;
1268
+
1269
+ export class UploaderProgramMeta {
1270
+ private view: DataView;
1271
+
1272
+ private constructor(private buffer: Uint8Array) {
1273
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1274
+ }
1275
+
1276
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): UploaderProgramMeta {
1277
+ if (!buffer || buffer.length === undefined) throw new Error("UploaderProgramMeta.__tnCreateView requires a Uint8Array");
1278
+ return new UploaderProgramMeta(new Uint8Array(buffer));
1279
+ }
1280
+
1281
+ static builder(): UploaderProgramMetaBuilder {
1282
+ return new UploaderProgramMetaBuilder();
1283
+ }
1284
+
1285
+ static fromBuilder(builder: UploaderProgramMetaBuilder): UploaderProgramMeta | null {
1286
+ const buffer = builder.build();
1287
+ return UploaderProgramMeta.from_array(buffer);
1288
+ }
1289
+
1290
+ get_authority(): Pubkey {
1291
+ const offset = 0;
1292
+ const slice = this.buffer.subarray(offset, offset + 32);
1293
+ return Pubkey.from_array(slice)!;
1294
+ }
1295
+
1296
+ set_authority(value: Pubkey): void {
1297
+ /* Copy bytes from source struct to this field */
1298
+ const sourceBytes = (value as any).buffer as Uint8Array;
1299
+ const offset = 0;
1300
+ this.buffer.set(sourceBytes, offset);
1301
+ }
1302
+
1303
+ get authority(): Pubkey {
1304
+ return this.get_authority();
1305
+ }
1306
+
1307
+ set authority(value: Pubkey) {
1308
+ this.set_authority(value);
1309
+ }
1310
+
1311
+ get_expected_account_hash(): Hash {
1312
+ const offset = 32;
1313
+ const slice = this.buffer.subarray(offset, offset + 32);
1314
+ return Hash.from_array(slice)!;
1315
+ }
1316
+
1317
+ set_expected_account_hash(value: Hash): void {
1318
+ /* Copy bytes from source struct to this field */
1319
+ const sourceBytes = (value as any).buffer as Uint8Array;
1320
+ const offset = 32;
1321
+ this.buffer.set(sourceBytes, offset);
1322
+ }
1323
+
1324
+ get expected_account_hash(): Hash {
1325
+ return this.get_expected_account_hash();
1326
+ }
1327
+
1328
+ set expected_account_hash(value: Hash) {
1329
+ this.set_expected_account_hash(value);
1330
+ }
1331
+
1332
+ get_state(): number {
1333
+ const offset = 64;
1334
+ return this.view.getUint8(offset);
1335
+ }
1336
+
1337
+ set_state(value: number): void {
1338
+ const offset = 64;
1339
+ this.view.setUint8(offset, value);
1340
+ }
1341
+
1342
+ get state(): number {
1343
+ return this.get_state();
1344
+ }
1345
+
1346
+ set state(value: number) {
1347
+ this.set_state(value);
1348
+ }
1349
+
1350
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1351
+ return __tnEvalFootprint(__tn_ir_UploaderProgramMeta.root, { params: __tnParams });
1352
+ }
1353
+
1354
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1355
+ return __tnValidateIrTree(__tn_ir_UploaderProgramMeta, buffer, __tnParams);
1356
+ }
1357
+
1358
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1359
+ return this.__tnFootprintInternal(__tnParams);
1360
+ }
1361
+
1362
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1363
+ return this.__tnValidateInternal(buffer, __tnParams);
1364
+ }
1365
+
1366
+ static footprintIr(): bigint {
1367
+ return this.__tnFootprintInternal(Object.create(null));
1368
+ }
1369
+
1370
+ static footprint(): number {
1371
+ const irResult = this.footprintIr();
1372
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1373
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1374
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for UploaderProgramMeta');
1375
+ }
1376
+ return __tnBigIntToNumber(irResult, 'UploaderProgramMeta::footprint');
1377
+ }
1378
+
1379
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
1380
+ if (buffer.length < 65) return { ok: false, code: "tn.buffer_too_small", consumed: 65 };
1381
+ return { ok: true, consumed: 65 };
1382
+ }
1383
+
1384
+ static from_array(buffer: Uint8Array): UploaderProgramMeta | null {
1385
+ if (!buffer || buffer.length === undefined) {
1386
+ return null;
1387
+ }
1388
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1389
+ const validation = this.validate(buffer);
1390
+ if (!validation.ok) {
1391
+ return null;
1392
+ }
1393
+ return new UploaderProgramMeta(buffer);
1394
+ }
1395
+
1396
+ }
1397
+
1398
+ export class UploaderProgramMetaBuilder {
1399
+ private buffer: Uint8Array;
1400
+ private view: DataView;
1401
+
1402
+ constructor() {
1403
+ this.buffer = new Uint8Array(65);
1404
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1405
+ }
1406
+
1407
+ set_authority(value: Uint8Array): this {
1408
+ if (value.length !== 32) throw new Error("authority expects 32 bytes");
1409
+ this.buffer.set(value, 0);
1410
+ return this;
1411
+ }
1412
+
1413
+ set_expected_account_hash(value: Uint8Array): this {
1414
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
1415
+ this.buffer.set(value, 32);
1416
+ return this;
1417
+ }
1418
+
1419
+ set_state(value: number): this {
1420
+ this.view.setUint8(64, value);
1421
+ return this;
1422
+ }
1423
+
1424
+ build(): Uint8Array {
1425
+ return this.buffer.slice();
1426
+ }
1427
+
1428
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1429
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1430
+ target.set(this.buffer, offset);
1431
+ return target;
1432
+ }
1433
+
1434
+ finish(): UploaderProgramMeta {
1435
+ const view = UploaderProgramMeta.from_array(this.buffer.slice());
1436
+ if (!view) throw new Error("failed to build UploaderProgramMeta");
1437
+ return view;
1438
+ }
1439
+ }
1440
+
1441
+ __tnRegisterFootprint("UploaderProgramMeta", (params) => UploaderProgramMeta.__tnInvokeFootprint(params));
1442
+ __tnRegisterValidate("UploaderProgramMeta", (buffer, params) => UploaderProgramMeta.__tnInvokeValidate(buffer, params));
1443
+ __tnRegisterDynamicValidate("UploaderProgramMeta", (buffer) => { const result = UploaderProgramMeta.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 }; });
1444
+
1445
+ /* ----- TYPE DEFINITION FOR WriteArgs ----- */
1446
+
1447
+ const __tn_ir_WriteArgs = {
1448
+ typeName: "WriteArgs",
1449
+ root: { op: "align", alignment: 1, node: { 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: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 4, node: { op: "const", value: 4n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "data.data_len" }, right: { op: "const", value: 1n } } } } }
1450
+ } as const;
1451
+
1452
+ export class WriteArgs {
1453
+ private view: DataView;
1454
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1455
+ private __tnParams: WriteArgs.Params;
1456
+
1457
+ private constructor(private buffer: Uint8Array, params?: WriteArgs.Params, fieldContext?: Record<string, number | bigint>) {
1458
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1459
+ this.__tnFieldContext = fieldContext ?? null;
1460
+ if (params) {
1461
+ this.__tnParams = params;
1462
+ } else {
1463
+ const derived = WriteArgs.__tnExtractParams(this.view, buffer);
1464
+ if (!derived) {
1465
+ throw new Error("WriteArgs: failed to derive dynamic parameters");
1466
+ }
1467
+ this.__tnParams = derived.params;
1468
+ }
1469
+ }
1470
+
1471
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: WriteArgs.Params, fieldContext?: Record<string, number | bigint> }): WriteArgs {
1472
+ if (!buffer || buffer.length === undefined) throw new Error("WriteArgs.__tnCreateView requires a Uint8Array");
1473
+ let params = opts?.params ?? null;
1474
+ if (!params) {
1475
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1476
+ const derived = WriteArgs.__tnExtractParams(view, buffer);
1477
+ if (!derived) throw new Error("WriteArgs.__tnCreateView: failed to derive params");
1478
+ params = derived.params;
1479
+ }
1480
+ const instance = new WriteArgs(new Uint8Array(buffer), params, opts?.fieldContext);
1481
+ return instance;
1482
+ }
1483
+
1484
+ dynamicParams(): WriteArgs.Params {
1485
+ return this.__tnParams;
1486
+ }
1487
+
1488
+ withFieldContext(context: Record<string, number | bigint>): this {
1489
+ this.__tnFieldContext = context;
1490
+ return this;
1491
+ }
1492
+
1493
+ private __tnResolveFieldRef(path: string): number {
1494
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1495
+ const getter = (this as any)[getterName];
1496
+ if (typeof getter === "function") {
1497
+ const value = getter.call(this);
1498
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "WriteArgs::__tnResolveFieldRef") : value;
1499
+ }
1500
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1501
+ const contextValue = this.__tnFieldContext[path];
1502
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "WriteArgs::__tnResolveFieldRef") : contextValue;
1503
+ }
1504
+ throw new Error("WriteArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1505
+ }
1506
+
1507
+ static builder(): WriteArgsBuilder {
1508
+ return new WriteArgsBuilder();
1509
+ }
1510
+
1511
+ static fromBuilder(builder: WriteArgsBuilder): WriteArgs | null {
1512
+ const buffer = builder.build();
1513
+ const params = builder.dynamicParams();
1514
+ return WriteArgs.from_array(buffer, { params });
1515
+ }
1516
+
1517
+ static readonly flexibleArrayWriters = Object.freeze([
1518
+ { field: "data", method: "data", sizeField: "data_len", paramKey: "data_len", elementSize: 1 },
1519
+ ] as const);
1520
+
1521
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: WriteArgs.Params; derived: Record<string, bigint> | null } | null {
1522
+ if (buffer.length < 8) {
1523
+ return null;
1524
+ }
1525
+ const __tnParam_data_data_len = __tnToBigInt(view.getUint32(4, true));
1526
+ const __tnExtractedParams = WriteArgs.Params.fromValues({
1527
+ data_data_len: __tnParam_data_data_len,
1528
+ });
1529
+ return { params: __tnExtractedParams, derived: null };
1530
+ }
1531
+
1532
+ get_buffer_account_idx(): number {
1533
+ const offset = 0;
1534
+ return this.view.getUint16(offset, true); /* little-endian */
1535
+ }
1536
+
1537
+ set_buffer_account_idx(value: number): void {
1538
+ const offset = 0;
1539
+ this.view.setUint16(offset, value, true); /* little-endian */
1540
+ }
1541
+
1542
+ get buffer_account_idx(): number {
1543
+ return this.get_buffer_account_idx();
1544
+ }
1545
+
1546
+ set buffer_account_idx(value: number) {
1547
+ this.set_buffer_account_idx(value);
1548
+ }
1549
+
1550
+ get_meta_account_idx(): number {
1551
+ const offset = 2;
1552
+ return this.view.getUint16(offset, true); /* little-endian */
1553
+ }
1554
+
1555
+ set_meta_account_idx(value: number): void {
1556
+ const offset = 2;
1557
+ this.view.setUint16(offset, value, true); /* little-endian */
1558
+ }
1559
+
1560
+ get meta_account_idx(): number {
1561
+ return this.get_meta_account_idx();
1562
+ }
1563
+
1564
+ set meta_account_idx(value: number) {
1565
+ this.set_meta_account_idx(value);
1566
+ }
1567
+
1568
+ get_data_len(): number {
1569
+ const offset = 4;
1570
+ return this.view.getUint32(offset, true); /* little-endian */
1571
+ }
1572
+
1573
+ set_data_len(value: number): void {
1574
+ const offset = 4;
1575
+ this.view.setUint32(offset, value, true); /* little-endian */
1576
+ }
1577
+
1578
+ get data_len(): number {
1579
+ return this.get_data_len();
1580
+ }
1581
+
1582
+ set data_len(value: number) {
1583
+ this.set_data_len(value);
1584
+ }
1585
+
1586
+ get_data_offset(): number {
1587
+ const offset = 8;
1588
+ return this.view.getUint32(offset, true); /* little-endian */
1589
+ }
1590
+
1591
+ set_data_offset(value: number): void {
1592
+ const offset = 8;
1593
+ this.view.setUint32(offset, value, true); /* little-endian */
1594
+ }
1595
+
1596
+ get data_offset(): number {
1597
+ return this.get_data_offset();
1598
+ }
1599
+
1600
+ set data_offset(value: number) {
1601
+ this.set_data_offset(value);
1602
+ }
1603
+
1604
+ get_data_length(): number {
1605
+ return this.__tnResolveFieldRef("data_len");
1606
+ }
1607
+
1608
+ get_data_at(index: number): number {
1609
+ const offset = 12;
1610
+ return this.view.getUint8(offset + index * 1);
1611
+ }
1612
+
1613
+ get_data(): number[] {
1614
+ const len = this.get_data_length();
1615
+ const result: number[] = [];
1616
+ for (let i = 0; i < len; i++) {
1617
+ result.push(this.get_data_at(i));
1618
+ }
1619
+ return result;
1620
+ }
1621
+
1622
+ set_data_at(index: number, value: number): void {
1623
+ const offset = 12;
1624
+ this.view.setUint8((offset + index * 1), value);
1625
+ }
1626
+
1627
+ set_data(value: number[]): void {
1628
+ const len = Math.min(this.get_data_length(), value.length);
1629
+ for (let i = 0; i < len; i++) {
1630
+ this.set_data_at(i, value[i]);
1631
+ }
1632
+ }
1633
+
1634
+ get data(): number[] {
1635
+ return this.get_data();
1636
+ }
1637
+
1638
+ set data(value: number[]) {
1639
+ this.set_data(value);
1640
+ }
1641
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
1642
+ return __tnEvalFootprint(__tn_ir_WriteArgs.root, { params: __tnParams });
1643
+ }
1644
+
1645
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
1646
+ return __tnValidateIrTree(__tn_ir_WriteArgs, buffer, __tnParams);
1647
+ }
1648
+
1649
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
1650
+ return this.__tnFootprintInternal(__tnParams);
1651
+ }
1652
+
1653
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
1654
+ return this.__tnValidateInternal(buffer, __tnParams);
1655
+ }
1656
+
1657
+ static footprintIr(data_data_len: number | bigint): bigint {
1658
+ const params = WriteArgs.Params.fromValues({
1659
+ data_data_len: data_data_len,
1660
+ });
1661
+ return this.footprintIrFromParams(params);
1662
+ }
1663
+
1664
+ private static __tnPackParams(params: WriteArgs.Params): Record<string, bigint> {
1665
+ const record: Record<string, bigint> = Object.create(null);
1666
+ record["data.data_len"] = params.data_data_len;
1667
+ return record;
1668
+ }
1669
+
1670
+ static footprintIrFromParams(params: WriteArgs.Params): bigint {
1671
+ const __tnParams = this.__tnPackParams(params);
1672
+ return this.__tnFootprintInternal(__tnParams);
1673
+ }
1674
+
1675
+ static footprintFromParams(params: WriteArgs.Params): number {
1676
+ const irResult = this.footprintIrFromParams(params);
1677
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1678
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for WriteArgs');
1679
+ return __tnBigIntToNumber(irResult, 'WriteArgs::footprintFromParams');
1680
+ }
1681
+
1682
+ static footprintFromValues(input: { data_data_len: number | bigint }): number {
1683
+ const params = WriteArgs.params(input);
1684
+ return this.footprintFromParams(params);
1685
+ }
1686
+
1687
+ static footprint(params: WriteArgs.Params): number {
1688
+ return this.footprintFromParams(params);
1689
+ }
1690
+
1691
+ static validate(buffer: Uint8Array, opts?: { params?: WriteArgs.Params }): { ok: boolean; code?: string; consumed?: number; params?: WriteArgs.Params } {
1692
+ if (!buffer || buffer.length === undefined) {
1693
+ return { ok: false, code: "tn.invalid_buffer" };
1694
+ }
1695
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1696
+ let params = opts?.params ?? null;
1697
+ if (!params) {
1698
+ const extracted = this.__tnExtractParams(view, buffer);
1699
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1700
+ params = extracted.params;
1701
+ }
1702
+ const __tnParamsRec = this.__tnPackParams(params);
1703
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1704
+ if (!irResult.ok) {
1705
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'WriteArgs::validate') : undefined, params };
1706
+ }
1707
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'WriteArgs::validate') : undefined;
1708
+ return { ok: true, consumed, params };
1709
+ }
1710
+
1711
+ static from_array(buffer: Uint8Array, opts?: { params?: WriteArgs.Params }): WriteArgs | null {
1712
+ if (!buffer || buffer.length === undefined) {
1713
+ return null;
1714
+ }
1715
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1716
+ let params = opts?.params ?? null;
1717
+ if (!params) {
1718
+ const derived = this.__tnExtractParams(view, buffer);
1719
+ if (!derived) return null;
1720
+ params = derived.params;
1721
+ }
1722
+ const validation = this.validate(buffer, { params });
1723
+ if (!validation.ok) {
1724
+ return null;
1725
+ }
1726
+ const cached = validation.params ?? params;
1727
+ const state = new WriteArgs(buffer, cached);
1728
+ return state;
1729
+ }
1730
+
1731
+
1732
+ }
1733
+
1734
+ export namespace WriteArgs {
1735
+ export type Params = {
1736
+ /** ABI path: data.data_len */
1737
+ readonly data_data_len: bigint;
1738
+ };
1739
+
1740
+ export const ParamKeys = Object.freeze({
1741
+ data_data_len: "data.data_len",
1742
+ } as const);
1743
+
1744
+ export const Params = {
1745
+ fromValues(input: { data_data_len: number | bigint }): Params {
1746
+ return {
1747
+ data_data_len: __tnToBigInt(input.data_data_len),
1748
+ };
1749
+ },
1750
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
1751
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
1752
+ return (source as { dynamicParams(): Params }).dynamicParams();
1753
+ }
1754
+ if ((source as { params?: Params }).params) {
1755
+ return (source as { params: Params }).params;
1756
+ }
1757
+ return source as Params;
1758
+ }
1759
+ };
1760
+
1761
+ export function params(input: { data_data_len: number | bigint }): Params {
1762
+ return Params.fromValues(input);
1763
+ }
1764
+ }
1765
+
1766
+ export class WriteArgsBuilder {
1767
+ private buffer: Uint8Array;
1768
+ private view: DataView;
1769
+ private __tnCachedParams: WriteArgs.Params | null = null;
1770
+ private __tnLastBuffer: Uint8Array | null = null;
1771
+ private __tnLastParams: WriteArgs.Params | null = null;
1772
+ private __tnFam_data: Uint8Array | null = null;
1773
+ private __tnFam_dataCount: number | null = null;
1774
+ private __tnFamWriter_data?: __TnFamWriterResult<WriteArgsBuilder>;
1775
+
1776
+ constructor() {
1777
+ this.buffer = new Uint8Array(12);
1778
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1779
+ }
1780
+
1781
+ private __tnInvalidate(): void {
1782
+ this.__tnCachedParams = null;
1783
+ this.__tnLastBuffer = null;
1784
+ this.__tnLastParams = null;
1785
+ }
1786
+
1787
+ set_buffer_account_idx(value: number): this {
1788
+ this.view.setUint16(0, value, true);
1789
+ this.__tnInvalidate();
1790
+ return this;
1791
+ }
1792
+
1793
+ set_meta_account_idx(value: number): this {
1794
+ this.view.setUint16(2, value, true);
1795
+ this.__tnInvalidate();
1796
+ return this;
1797
+ }
1798
+
1799
+ set_data_len(value: number): this {
1800
+ this.view.setUint32(4, value, true);
1801
+ this.__tnInvalidate();
1802
+ return this;
1803
+ }
1804
+
1805
+ set_data_offset(value: number): this {
1806
+ this.view.setUint32(8, value, true);
1807
+ this.__tnInvalidate();
1808
+ return this;
1809
+ }
1810
+
1811
+ data(): __TnFamWriterResult<WriteArgsBuilder> {
1812
+ if (!this.__tnFamWriter_data) {
1813
+ this.__tnFamWriter_data = __tnCreateFamWriter(this, "data", (payload) => {
1814
+ const bytes = new Uint8Array(payload);
1815
+ const elementCount = bytes.length;
1816
+ this.__tnFam_data = bytes;
1817
+ this.__tnFam_dataCount = elementCount;
1818
+ this.set_data_len(elementCount);
1819
+ this.__tnInvalidate();
1820
+ });
1821
+ }
1822
+ return this.__tnFamWriter_data!;
1823
+ }
1824
+
1825
+ build(): Uint8Array {
1826
+ const params = this.__tnComputeParams();
1827
+ const size = WriteArgs.footprintFromParams(params);
1828
+ const buffer = new Uint8Array(size);
1829
+ this.__tnWriteInto(buffer);
1830
+ this.__tnValidateOrThrow(buffer, params);
1831
+ return buffer;
1832
+ }
1833
+
1834
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
1835
+ const params = this.__tnComputeParams();
1836
+ const size = WriteArgs.footprintFromParams(params);
1837
+ if (target.length - offset < size) throw new Error("WriteArgsBuilder: target buffer too small");
1838
+ const slice = target.subarray(offset, offset + size);
1839
+ this.__tnWriteInto(slice);
1840
+ this.__tnValidateOrThrow(slice, params);
1841
+ return target;
1842
+ }
1843
+
1844
+ finish(): WriteArgs {
1845
+ const buffer = this.build();
1846
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1847
+ const view = WriteArgs.from_array(buffer, { params });
1848
+ if (!view) throw new Error("WriteArgsBuilder: failed to finalize view");
1849
+ return view;
1850
+ }
1851
+
1852
+ finishView(): WriteArgs {
1853
+ return this.finish();
1854
+ }
1855
+
1856
+ dynamicParams(): WriteArgs.Params {
1857
+ return this.__tnComputeParams();
1858
+ }
1859
+
1860
+ private __tnComputeParams(): WriteArgs.Params {
1861
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1862
+ const params = WriteArgs.Params.fromValues({
1863
+ data_data_len: (() => { if (this.__tnFam_dataCount === null) throw new Error("WriteArgsBuilder: field 'data' must be written before computing params"); return __tnToBigInt(this.__tnFam_dataCount); })(),
1864
+ });
1865
+ this.__tnCachedParams = params;
1866
+ return params;
1867
+ }
1868
+
1869
+ private __tnWriteInto(target: Uint8Array): void {
1870
+ target.set(this.buffer, 0);
1871
+ let cursor = this.buffer.length;
1872
+ const __tnLocal_data_bytes = this.__tnFam_data;
1873
+ if (!__tnLocal_data_bytes) throw new Error("WriteArgsBuilder: field 'data' must be written before build");
1874
+ target.set(__tnLocal_data_bytes, cursor);
1875
+ cursor += __tnLocal_data_bytes.length;
1876
+ }
1877
+
1878
+ private __tnValidateOrThrow(buffer: Uint8Array, params: WriteArgs.Params): void {
1879
+ const result = WriteArgs.validate(buffer, { params });
1880
+ if (!result.ok) {
1881
+ throw new Error(`${ WriteArgs }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1882
+ }
1883
+ this.__tnLastParams = result.params ?? params;
1884
+ this.__tnLastBuffer = buffer;
1885
+ }
1886
+ }
1887
+
1888
+ __tnRegisterFootprint("WriteArgs", (params) => WriteArgs.__tnInvokeFootprint(params));
1889
+ __tnRegisterValidate("WriteArgs", (buffer, params) => WriteArgs.__tnInvokeValidate(buffer, params));
1890
+ __tnRegisterDynamicValidate("WriteArgs", (buffer) => { const result = WriteArgs.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 }; });
1891
+
1892
+ /* ----- TYPE DEFINITION FOR CreateArgs ----- */
1893
+
1894
+ const __tn_ir_CreateArgs = {
1895
+ typeName: "CreateArgs",
1896
+ 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: "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: 1, node: { op: "const", value: 32n } } }, 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 } } } } }
1897
+ } as const;
1898
+
1899
+ export class CreateArgs {
1900
+ private view: DataView;
1901
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
1902
+ private __tnParams: CreateArgs.Params;
1903
+
1904
+ private constructor(private buffer: Uint8Array, params?: CreateArgs.Params, fieldContext?: Record<string, number | bigint>) {
1905
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1906
+ this.__tnFieldContext = fieldContext ?? null;
1907
+ if (params) {
1908
+ this.__tnParams = params;
1909
+ } else {
1910
+ const derived = CreateArgs.__tnExtractParams(this.view, buffer);
1911
+ if (!derived) {
1912
+ throw new Error("CreateArgs: failed to derive dynamic parameters");
1913
+ }
1914
+ this.__tnParams = derived.params;
1915
+ }
1916
+ }
1917
+
1918
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: CreateArgs.Params, fieldContext?: Record<string, number | bigint> }): CreateArgs {
1919
+ if (!buffer || buffer.length === undefined) throw new Error("CreateArgs.__tnCreateView requires a Uint8Array");
1920
+ let params = opts?.params ?? null;
1921
+ if (!params) {
1922
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1923
+ const derived = CreateArgs.__tnExtractParams(view, buffer);
1924
+ if (!derived) throw new Error("CreateArgs.__tnCreateView: failed to derive params");
1925
+ params = derived.params;
1926
+ }
1927
+ const instance = new CreateArgs(new Uint8Array(buffer), params, opts?.fieldContext);
1928
+ return instance;
1929
+ }
1930
+
1931
+ dynamicParams(): CreateArgs.Params {
1932
+ return this.__tnParams;
1933
+ }
1934
+
1935
+ withFieldContext(context: Record<string, number | bigint>): this {
1936
+ this.__tnFieldContext = context;
1937
+ return this;
1938
+ }
1939
+
1940
+ private __tnResolveFieldRef(path: string): number {
1941
+ const getterName = `get_${path.replace(/[.]/g, '_')}`;
1942
+ const getter = (this as any)[getterName];
1943
+ if (typeof getter === "function") {
1944
+ const value = getter.call(this);
1945
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "CreateArgs::__tnResolveFieldRef") : value;
1946
+ }
1947
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1948
+ const contextValue = this.__tnFieldContext[path];
1949
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "CreateArgs::__tnResolveFieldRef") : contextValue;
1950
+ }
1951
+ throw new Error("CreateArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1952
+ }
1953
+
1954
+ static builder(): CreateArgsBuilder {
1955
+ return new CreateArgsBuilder();
1956
+ }
1957
+
1958
+ static fromBuilder(builder: CreateArgsBuilder): CreateArgs | null {
1959
+ const buffer = builder.build();
1960
+ const params = builder.dynamicParams();
1961
+ return CreateArgs.from_array(buffer, { params });
1962
+ }
1963
+
1964
+ static readonly flexibleArrayWriters = Object.freeze([
1965
+ { field: "seed", method: "seed", sizeField: "seed_len", paramKey: "seed_len", elementSize: 1 },
1966
+ ] as const);
1967
+
1968
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: CreateArgs.Params; derived: Record<string, bigint> | null } | null {
1969
+ if (buffer.length < 46) {
1970
+ return null;
1971
+ }
1972
+ const __tnParam_seed_seed_len = __tnToBigInt(view.getUint32(42, true));
1973
+ const __tnExtractedParams = CreateArgs.Params.fromValues({
1974
+ seed_seed_len: __tnParam_seed_seed_len,
1975
+ });
1976
+ return { params: __tnExtractedParams, derived: null };
1977
+ }
1978
+
1979
+ get_buffer_account_idx(): number {
1980
+ const offset = 0;
1981
+ return this.view.getUint16(offset, true); /* little-endian */
1982
+ }
1983
+
1984
+ set_buffer_account_idx(value: number): void {
1985
+ const offset = 0;
1986
+ this.view.setUint16(offset, value, true); /* little-endian */
1987
+ }
1988
+
1989
+ get buffer_account_idx(): number {
1990
+ return this.get_buffer_account_idx();
1991
+ }
1992
+
1993
+ set buffer_account_idx(value: number) {
1994
+ this.set_buffer_account_idx(value);
1995
+ }
1996
+
1997
+ get_meta_account_idx(): number {
1998
+ const offset = 2;
1999
+ return this.view.getUint16(offset, true); /* little-endian */
2000
+ }
2001
+
2002
+ set_meta_account_idx(value: number): void {
2003
+ const offset = 2;
2004
+ this.view.setUint16(offset, value, true); /* little-endian */
2005
+ }
2006
+
2007
+ get meta_account_idx(): number {
2008
+ return this.get_meta_account_idx();
2009
+ }
2010
+
2011
+ set meta_account_idx(value: number) {
2012
+ this.set_meta_account_idx(value);
2013
+ }
2014
+
2015
+ get_authority_account_idx(): number {
2016
+ const offset = 4;
2017
+ return this.view.getUint16(offset, true); /* little-endian */
2018
+ }
2019
+
2020
+ set_authority_account_idx(value: number): void {
2021
+ const offset = 4;
2022
+ this.view.setUint16(offset, value, true); /* little-endian */
2023
+ }
2024
+
2025
+ get authority_account_idx(): number {
2026
+ return this.get_authority_account_idx();
2027
+ }
2028
+
2029
+ set authority_account_idx(value: number) {
2030
+ this.set_authority_account_idx(value);
2031
+ }
2032
+
2033
+ get_buffer_account_sz(): number {
2034
+ const offset = 6;
2035
+ return this.view.getUint32(offset, true); /* little-endian */
2036
+ }
2037
+
2038
+ set_buffer_account_sz(value: number): void {
2039
+ const offset = 6;
2040
+ this.view.setUint32(offset, value, true); /* little-endian */
2041
+ }
2042
+
2043
+ get buffer_account_sz(): number {
2044
+ return this.get_buffer_account_sz();
2045
+ }
2046
+
2047
+ set buffer_account_sz(value: number) {
2048
+ this.set_buffer_account_sz(value);
2049
+ }
2050
+
2051
+ get_expected_account_hash(): Hash {
2052
+ const offset = 10;
2053
+ const slice = this.buffer.subarray(offset, offset + 32);
2054
+ return Hash.from_array(slice)!;
2055
+ }
2056
+
2057
+ set_expected_account_hash(value: Hash): void {
2058
+ /* Copy bytes from source struct to this field */
2059
+ const sourceBytes = (value as any).buffer as Uint8Array;
2060
+ const offset = 10;
2061
+ this.buffer.set(sourceBytes, offset);
2062
+ }
2063
+
2064
+ get expected_account_hash(): Hash {
2065
+ return this.get_expected_account_hash();
2066
+ }
2067
+
2068
+ set expected_account_hash(value: Hash) {
2069
+ this.set_expected_account_hash(value);
2070
+ }
2071
+
2072
+ get_seed_len(): number {
2073
+ const offset = 42;
2074
+ return this.view.getUint32(offset, true); /* little-endian */
2075
+ }
2076
+
2077
+ set_seed_len(value: number): void {
2078
+ const offset = 42;
2079
+ this.view.setUint32(offset, value, true); /* little-endian */
2080
+ }
2081
+
2082
+ get seed_len(): number {
2083
+ return this.get_seed_len();
2084
+ }
2085
+
2086
+ set seed_len(value: number) {
2087
+ this.set_seed_len(value);
2088
+ }
2089
+
2090
+ get_seed_length(): number {
2091
+ return this.__tnResolveFieldRef("seed_len");
2092
+ }
2093
+
2094
+ get_seed_at(index: number): number {
2095
+ const offset = 46;
2096
+ return this.view.getUint8(offset + index * 1);
2097
+ }
2098
+
2099
+ get_seed(): number[] {
2100
+ const len = this.get_seed_length();
2101
+ const result: number[] = [];
2102
+ for (let i = 0; i < len; i++) {
2103
+ result.push(this.get_seed_at(i));
2104
+ }
2105
+ return result;
2106
+ }
2107
+
2108
+ set_seed_at(index: number, value: number): void {
2109
+ const offset = 46;
2110
+ this.view.setUint8((offset + index * 1), value);
2111
+ }
2112
+
2113
+ set_seed(value: number[]): void {
2114
+ const len = Math.min(this.get_seed_length(), value.length);
2115
+ for (let i = 0; i < len; i++) {
2116
+ this.set_seed_at(i, value[i]);
2117
+ }
2118
+ }
2119
+
2120
+ get seed(): number[] {
2121
+ return this.get_seed();
2122
+ }
2123
+
2124
+ set seed(value: number[]) {
2125
+ this.set_seed(value);
2126
+ }
2127
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2128
+ return __tnEvalFootprint(__tn_ir_CreateArgs.root, { params: __tnParams });
2129
+ }
2130
+
2131
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2132
+ return __tnValidateIrTree(__tn_ir_CreateArgs, buffer, __tnParams);
2133
+ }
2134
+
2135
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2136
+ return this.__tnFootprintInternal(__tnParams);
2137
+ }
2138
+
2139
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2140
+ return this.__tnValidateInternal(buffer, __tnParams);
2141
+ }
2142
+
2143
+ static footprintIr(seed_seed_len: number | bigint): bigint {
2144
+ const params = CreateArgs.Params.fromValues({
2145
+ seed_seed_len: seed_seed_len,
2146
+ });
2147
+ return this.footprintIrFromParams(params);
2148
+ }
2149
+
2150
+ private static __tnPackParams(params: CreateArgs.Params): Record<string, bigint> {
2151
+ const record: Record<string, bigint> = Object.create(null);
2152
+ record["seed.seed_len"] = params.seed_seed_len;
2153
+ return record;
2154
+ }
2155
+
2156
+ static footprintIrFromParams(params: CreateArgs.Params): bigint {
2157
+ const __tnParams = this.__tnPackParams(params);
2158
+ return this.__tnFootprintInternal(__tnParams);
2159
+ }
2160
+
2161
+ static footprintFromParams(params: CreateArgs.Params): number {
2162
+ const irResult = this.footprintIrFromParams(params);
2163
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2164
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for CreateArgs');
2165
+ return __tnBigIntToNumber(irResult, 'CreateArgs::footprintFromParams');
2166
+ }
2167
+
2168
+ static footprintFromValues(input: { seed_seed_len: number | bigint }): number {
2169
+ const params = CreateArgs.params(input);
2170
+ return this.footprintFromParams(params);
2171
+ }
2172
+
2173
+ static footprint(params: CreateArgs.Params): number {
2174
+ return this.footprintFromParams(params);
2175
+ }
2176
+
2177
+ static validate(buffer: Uint8Array, opts?: { params?: CreateArgs.Params }): { ok: boolean; code?: string; consumed?: number; params?: CreateArgs.Params } {
2178
+ if (!buffer || buffer.length === undefined) {
2179
+ return { ok: false, code: "tn.invalid_buffer" };
2180
+ }
2181
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2182
+ let params = opts?.params ?? null;
2183
+ if (!params) {
2184
+ const extracted = this.__tnExtractParams(view, buffer);
2185
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
2186
+ params = extracted.params;
2187
+ }
2188
+ const __tnParamsRec = this.__tnPackParams(params);
2189
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
2190
+ if (!irResult.ok) {
2191
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreateArgs::validate') : undefined, params };
2192
+ }
2193
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'CreateArgs::validate') : undefined;
2194
+ return { ok: true, consumed, params };
2195
+ }
2196
+
2197
+ static from_array(buffer: Uint8Array, opts?: { params?: CreateArgs.Params }): CreateArgs | null {
2198
+ if (!buffer || buffer.length === undefined) {
2199
+ return null;
2200
+ }
2201
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2202
+ let params = opts?.params ?? null;
2203
+ if (!params) {
2204
+ const derived = this.__tnExtractParams(view, buffer);
2205
+ if (!derived) return null;
2206
+ params = derived.params;
2207
+ }
2208
+ const validation = this.validate(buffer, { params });
2209
+ if (!validation.ok) {
2210
+ return null;
2211
+ }
2212
+ const cached = validation.params ?? params;
2213
+ const state = new CreateArgs(buffer, cached);
2214
+ return state;
2215
+ }
2216
+
2217
+
2218
+ }
2219
+
2220
+ export namespace CreateArgs {
2221
+ export type Params = {
2222
+ /** ABI path: seed.seed_len */
2223
+ readonly seed_seed_len: bigint;
2224
+ };
2225
+
2226
+ export const ParamKeys = Object.freeze({
2227
+ seed_seed_len: "seed.seed_len",
2228
+ } as const);
2229
+
2230
+ export const Params = {
2231
+ fromValues(input: { seed_seed_len: number | bigint }): Params {
2232
+ return {
2233
+ seed_seed_len: __tnToBigInt(input.seed_seed_len),
2234
+ };
2235
+ },
2236
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
2237
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
2238
+ return (source as { dynamicParams(): Params }).dynamicParams();
2239
+ }
2240
+ if ((source as { params?: Params }).params) {
2241
+ return (source as { params: Params }).params;
2242
+ }
2243
+ return source as Params;
2244
+ }
2245
+ };
2246
+
2247
+ export function params(input: { seed_seed_len: number | bigint }): Params {
2248
+ return Params.fromValues(input);
2249
+ }
2250
+ }
2251
+
2252
+ export class CreateArgsBuilder {
2253
+ private buffer: Uint8Array;
2254
+ private view: DataView;
2255
+ private __tnCachedParams: CreateArgs.Params | null = null;
2256
+ private __tnLastBuffer: Uint8Array | null = null;
2257
+ private __tnLastParams: CreateArgs.Params | null = null;
2258
+ private __tnFam_seed: Uint8Array | null = null;
2259
+ private __tnFam_seedCount: number | null = null;
2260
+ private __tnFamWriter_seed?: __TnFamWriterResult<CreateArgsBuilder>;
2261
+
2262
+ constructor() {
2263
+ this.buffer = new Uint8Array(46);
2264
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2265
+ }
2266
+
2267
+ private __tnInvalidate(): void {
2268
+ this.__tnCachedParams = null;
2269
+ this.__tnLastBuffer = null;
2270
+ this.__tnLastParams = null;
2271
+ }
2272
+
2273
+ set_buffer_account_idx(value: number): this {
2274
+ this.view.setUint16(0, value, true);
2275
+ this.__tnInvalidate();
2276
+ return this;
2277
+ }
2278
+
2279
+ set_meta_account_idx(value: number): this {
2280
+ this.view.setUint16(2, value, true);
2281
+ this.__tnInvalidate();
2282
+ return this;
2283
+ }
2284
+
2285
+ set_authority_account_idx(value: number): this {
2286
+ this.view.setUint16(4, value, true);
2287
+ this.__tnInvalidate();
2288
+ return this;
2289
+ }
2290
+
2291
+ set_buffer_account_sz(value: number): this {
2292
+ this.view.setUint32(6, value, true);
2293
+ this.__tnInvalidate();
2294
+ return this;
2295
+ }
2296
+
2297
+ set_expected_account_hash(value: Uint8Array): this {
2298
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
2299
+ this.buffer.set(value, 10);
2300
+ this.__tnInvalidate();
2301
+ return this;
2302
+ }
2303
+
2304
+ set_seed_len(value: number): this {
2305
+ this.view.setUint32(42, value, true);
2306
+ this.__tnInvalidate();
2307
+ return this;
2308
+ }
2309
+
2310
+ seed(): __TnFamWriterResult<CreateArgsBuilder> {
2311
+ if (!this.__tnFamWriter_seed) {
2312
+ this.__tnFamWriter_seed = __tnCreateFamWriter(this, "seed", (payload) => {
2313
+ const bytes = new Uint8Array(payload);
2314
+ const elementCount = bytes.length;
2315
+ this.__tnFam_seed = bytes;
2316
+ this.__tnFam_seedCount = elementCount;
2317
+ this.set_seed_len(elementCount);
2318
+ this.__tnInvalidate();
2319
+ });
2320
+ }
2321
+ return this.__tnFamWriter_seed!;
2322
+ }
2323
+
2324
+ build(): Uint8Array {
2325
+ const params = this.__tnComputeParams();
2326
+ const size = CreateArgs.footprintFromParams(params);
2327
+ const buffer = new Uint8Array(size);
2328
+ this.__tnWriteInto(buffer);
2329
+ this.__tnValidateOrThrow(buffer, params);
2330
+ return buffer;
2331
+ }
2332
+
2333
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2334
+ const params = this.__tnComputeParams();
2335
+ const size = CreateArgs.footprintFromParams(params);
2336
+ if (target.length - offset < size) throw new Error("CreateArgsBuilder: target buffer too small");
2337
+ const slice = target.subarray(offset, offset + size);
2338
+ this.__tnWriteInto(slice);
2339
+ this.__tnValidateOrThrow(slice, params);
2340
+ return target;
2341
+ }
2342
+
2343
+ finish(): CreateArgs {
2344
+ const buffer = this.build();
2345
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
2346
+ const view = CreateArgs.from_array(buffer, { params });
2347
+ if (!view) throw new Error("CreateArgsBuilder: failed to finalize view");
2348
+ return view;
2349
+ }
2350
+
2351
+ finishView(): CreateArgs {
2352
+ return this.finish();
2353
+ }
2354
+
2355
+ dynamicParams(): CreateArgs.Params {
2356
+ return this.__tnComputeParams();
2357
+ }
2358
+
2359
+ private __tnComputeParams(): CreateArgs.Params {
2360
+ if (this.__tnCachedParams) return this.__tnCachedParams;
2361
+ const params = CreateArgs.Params.fromValues({
2362
+ seed_seed_len: (() => { if (this.__tnFam_seedCount === null) throw new Error("CreateArgsBuilder: field 'seed' must be written before computing params"); return __tnToBigInt(this.__tnFam_seedCount); })(),
2363
+ });
2364
+ this.__tnCachedParams = params;
2365
+ return params;
2366
+ }
2367
+
2368
+ private __tnWriteInto(target: Uint8Array): void {
2369
+ target.set(this.buffer, 0);
2370
+ let cursor = this.buffer.length;
2371
+ const __tnLocal_seed_bytes = this.__tnFam_seed;
2372
+ if (!__tnLocal_seed_bytes) throw new Error("CreateArgsBuilder: field 'seed' must be written before build");
2373
+ target.set(__tnLocal_seed_bytes, cursor);
2374
+ cursor += __tnLocal_seed_bytes.length;
2375
+ }
2376
+
2377
+ private __tnValidateOrThrow(buffer: Uint8Array, params: CreateArgs.Params): void {
2378
+ const result = CreateArgs.validate(buffer, { params });
2379
+ if (!result.ok) {
2380
+ throw new Error(`${ CreateArgs }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
2381
+ }
2382
+ this.__tnLastParams = result.params ?? params;
2383
+ this.__tnLastBuffer = buffer;
2384
+ }
2385
+ }
2386
+
2387
+ __tnRegisterFootprint("CreateArgs", (params) => CreateArgs.__tnInvokeFootprint(params));
2388
+ __tnRegisterValidate("CreateArgs", (buffer, params) => CreateArgs.__tnInvokeValidate(buffer, params));
2389
+ __tnRegisterDynamicValidate("CreateArgs", (buffer) => { const result = CreateArgs.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 }; });
2390
+
2391
+ /* ----- TYPE DEFINITION FOR FinalizeArgs ----- */
2392
+
2393
+ const __tn_ir_FinalizeArgs = {
2394
+ typeName: "FinalizeArgs",
2395
+ root: { op: "const", value: 36n }
2396
+ } as const;
2397
+
2398
+ export class FinalizeArgs {
2399
+ private view: DataView;
2400
+
2401
+ private constructor(private buffer: Uint8Array) {
2402
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2403
+ }
2404
+
2405
+ static __tnCreateView(buffer: Uint8Array, opts?: { fieldContext?: Record<string, number | bigint> }): FinalizeArgs {
2406
+ if (!buffer || buffer.length === undefined) throw new Error("FinalizeArgs.__tnCreateView requires a Uint8Array");
2407
+ return new FinalizeArgs(new Uint8Array(buffer));
2408
+ }
2409
+
2410
+ static builder(): FinalizeArgsBuilder {
2411
+ return new FinalizeArgsBuilder();
2412
+ }
2413
+
2414
+ static fromBuilder(builder: FinalizeArgsBuilder): FinalizeArgs | null {
2415
+ const buffer = builder.build();
2416
+ return FinalizeArgs.from_array(buffer);
2417
+ }
2418
+
2419
+ get_buffer_account_idx(): number {
2420
+ const offset = 0;
2421
+ return this.view.getUint16(offset, true); /* little-endian */
2422
+ }
2423
+
2424
+ set_buffer_account_idx(value: number): void {
2425
+ const offset = 0;
2426
+ this.view.setUint16(offset, value, true); /* little-endian */
2427
+ }
2428
+
2429
+ get buffer_account_idx(): number {
2430
+ return this.get_buffer_account_idx();
2431
+ }
2432
+
2433
+ set buffer_account_idx(value: number) {
2434
+ this.set_buffer_account_idx(value);
2435
+ }
2436
+
2437
+ get_meta_account_idx(): number {
2438
+ const offset = 2;
2439
+ return this.view.getUint16(offset, true); /* little-endian */
2440
+ }
2441
+
2442
+ set_meta_account_idx(value: number): void {
2443
+ const offset = 2;
2444
+ this.view.setUint16(offset, value, true); /* little-endian */
2445
+ }
2446
+
2447
+ get meta_account_idx(): number {
2448
+ return this.get_meta_account_idx();
2449
+ }
2450
+
2451
+ set meta_account_idx(value: number) {
2452
+ this.set_meta_account_idx(value);
2453
+ }
2454
+
2455
+ get_expected_account_hash(): Hash {
2456
+ const offset = 4;
2457
+ const slice = this.buffer.subarray(offset, offset + 32);
2458
+ return Hash.from_array(slice)!;
2459
+ }
2460
+
2461
+ set_expected_account_hash(value: Hash): void {
2462
+ /* Copy bytes from source struct to this field */
2463
+ const sourceBytes = (value as any).buffer as Uint8Array;
2464
+ const offset = 4;
2465
+ this.buffer.set(sourceBytes, offset);
2466
+ }
2467
+
2468
+ get expected_account_hash(): Hash {
2469
+ return this.get_expected_account_hash();
2470
+ }
2471
+
2472
+ set expected_account_hash(value: Hash) {
2473
+ this.set_expected_account_hash(value);
2474
+ }
2475
+
2476
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2477
+ return __tnEvalFootprint(__tn_ir_FinalizeArgs.root, { params: __tnParams });
2478
+ }
2479
+
2480
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2481
+ return __tnValidateIrTree(__tn_ir_FinalizeArgs, buffer, __tnParams);
2482
+ }
2483
+
2484
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2485
+ return this.__tnFootprintInternal(__tnParams);
2486
+ }
2487
+
2488
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2489
+ return this.__tnValidateInternal(buffer, __tnParams);
2490
+ }
2491
+
2492
+ static footprintIr(): bigint {
2493
+ return this.__tnFootprintInternal(Object.create(null));
2494
+ }
2495
+
2496
+ static footprint(): number {
2497
+ const irResult = this.footprintIr();
2498
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2499
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2500
+ throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for FinalizeArgs');
2501
+ }
2502
+ return __tnBigIntToNumber(irResult, 'FinalizeArgs::footprint');
2503
+ }
2504
+
2505
+ static validate(buffer: Uint8Array, _opts?: { params?: never }): { ok: boolean; code?: string; consumed?: number } {
2506
+ if (buffer.length < 36) return { ok: false, code: "tn.buffer_too_small", consumed: 36 };
2507
+ return { ok: true, consumed: 36 };
2508
+ }
2509
+
2510
+ static from_array(buffer: Uint8Array): FinalizeArgs | null {
2511
+ if (!buffer || buffer.length === undefined) {
2512
+ return null;
2513
+ }
2514
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2515
+ const validation = this.validate(buffer);
2516
+ if (!validation.ok) {
2517
+ return null;
2518
+ }
2519
+ return new FinalizeArgs(buffer);
2520
+ }
2521
+
2522
+ }
2523
+
2524
+ export class FinalizeArgsBuilder {
2525
+ private buffer: Uint8Array;
2526
+ private view: DataView;
2527
+
2528
+ constructor() {
2529
+ this.buffer = new Uint8Array(36);
2530
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2531
+ }
2532
+
2533
+ set_buffer_account_idx(value: number): this {
2534
+ this.view.setUint16(0, value, true);
2535
+ return this;
2536
+ }
2537
+
2538
+ set_meta_account_idx(value: number): this {
2539
+ this.view.setUint16(2, value, true);
2540
+ return this;
2541
+ }
2542
+
2543
+ set_expected_account_hash(value: Uint8Array): this {
2544
+ if (value.length !== 32) throw new Error("expected_account_hash expects 32 bytes");
2545
+ this.buffer.set(value, 4);
2546
+ return this;
2547
+ }
2548
+
2549
+ build(): Uint8Array {
2550
+ return this.buffer.slice();
2551
+ }
2552
+
2553
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2554
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2555
+ target.set(this.buffer, offset);
2556
+ return target;
2557
+ }
2558
+
2559
+ finish(): FinalizeArgs {
2560
+ const view = FinalizeArgs.from_array(this.buffer.slice());
2561
+ if (!view) throw new Error("failed to build FinalizeArgs");
2562
+ return view;
2563
+ }
2564
+ }
2565
+
2566
+ __tnRegisterFootprint("FinalizeArgs", (params) => FinalizeArgs.__tnInvokeFootprint(params));
2567
+ __tnRegisterValidate("FinalizeArgs", (buffer, params) => FinalizeArgs.__tnInvokeValidate(buffer, params));
2568
+ __tnRegisterDynamicValidate("FinalizeArgs", (buffer) => { const result = FinalizeArgs.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 }; });
2569
+
2570
+ /* ----- TYPE DEFINITION FOR UploaderInstruction ----- */
2571
+
2572
+ const __tn_ir_UploaderInstruction = {
2573
+ typeName: "UploaderInstruction",
2574
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "align", alignment: 4, node: { op: "const", value: 4n } }, right: { op: "align", alignment: 1, node: { op: "field", param: "payload.payload_size" } } } }
2575
+ } as const;
2576
+
2577
+ export class UploaderInstruction_payload_Inner {
2578
+ private view: DataView;
2579
+ private __tnFieldContext: Record<string, number | bigint> | null = null;
2580
+ private constructor(private buffer: Uint8Array, private descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>) {
2581
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2582
+ this.__tnFieldContext = fieldContext ?? null;
2583
+ }
2584
+
2585
+ static __tnCreate(payload: Uint8Array, descriptor: __TnVariantDescriptor | null, fieldContext?: Record<string, number | bigint>): UploaderInstruction_payload_Inner {
2586
+ return new UploaderInstruction_payload_Inner(new Uint8Array(payload), descriptor, fieldContext);
2587
+ }
2588
+
2589
+ bytes(): Uint8Array {
2590
+ return new Uint8Array(this.buffer);
2591
+ }
2592
+
2593
+ variant(): __TnVariantDescriptor | null {
2594
+ return this.descriptor;
2595
+ }
2596
+
2597
+ asCreate(): CreateArgs | null {
2598
+ if (!this.descriptor || this.descriptor.tag !== 0) return null;
2599
+ return CreateArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
2600
+ }
2601
+
2602
+ asWrite(): WriteArgs | null {
2603
+ if (!this.descriptor || this.descriptor.tag !== 1) return null;
2604
+ return WriteArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
2605
+ }
2606
+
2607
+ asDestroy(): DestroyArgs | null {
2608
+ if (!this.descriptor || this.descriptor.tag !== 2) return null;
2609
+ return DestroyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
2610
+ }
2611
+
2612
+ asFinalize(): FinalizeArgs | null {
2613
+ if (!this.descriptor || this.descriptor.tag !== 3) return null;
2614
+ return FinalizeArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? undefined });
2615
+ }
2616
+
2617
+ }
2618
+
2619
+ export class UploaderInstruction {
2620
+ private view: DataView;
2621
+ private static readonly __tnFieldOffset_payload = 4;
2622
+ private __tnParams: UploaderInstruction.Params;
2623
+
2624
+ private constructor(private buffer: Uint8Array, params?: UploaderInstruction.Params) {
2625
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2626
+ if (params) {
2627
+ this.__tnParams = params;
2628
+ } else {
2629
+ const derived = UploaderInstruction.__tnExtractParams(this.view, buffer);
2630
+ if (!derived) {
2631
+ throw new Error("UploaderInstruction: failed to derive dynamic parameters");
2632
+ }
2633
+ this.__tnParams = derived.params;
2634
+ }
2635
+ }
2636
+
2637
+ static __tnCreateView(buffer: Uint8Array, opts?: { params?: UploaderInstruction.Params, fieldContext?: Record<string, number | bigint> }): UploaderInstruction {
2638
+ if (!buffer || buffer.length === undefined) throw new Error("UploaderInstruction.__tnCreateView requires a Uint8Array");
2639
+ let params = opts?.params ?? null;
2640
+ if (!params) {
2641
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2642
+ const derived = UploaderInstruction.__tnExtractParams(view, buffer);
2643
+ if (!derived) throw new Error("UploaderInstruction.__tnCreateView: failed to derive params");
2644
+ params = derived.params;
2645
+ }
2646
+ const instance = new UploaderInstruction(new Uint8Array(buffer), params);
2647
+ return instance;
2648
+ }
2649
+
2650
+ dynamicParams(): UploaderInstruction.Params {
2651
+ return this.__tnParams;
2652
+ }
2653
+
2654
+ static builder(): UploaderInstructionBuilder {
2655
+ return new UploaderInstructionBuilder();
2656
+ }
2657
+
2658
+ static fromBuilder(builder: UploaderInstructionBuilder): UploaderInstruction | null {
2659
+ const buffer = builder.build();
2660
+ const params = builder.dynamicParams();
2661
+ return UploaderInstruction.from_array(buffer, { params });
2662
+ }
2663
+
2664
+ static readonly payloadVariantDescriptors = Object.freeze([
2665
+ {
2666
+ name: "create",
2667
+ tag: 0,
2668
+ payloadSize: null,
2669
+ payloadType: "UploaderInstruction::payload::create",
2670
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreateArgs),
2671
+ },
2672
+ {
2673
+ name: "write",
2674
+ tag: 1,
2675
+ payloadSize: null,
2676
+ payloadType: "UploaderInstruction::payload::write",
2677
+ createPayloadBuilder: () => __tnMaybeCallBuilder(WriteArgs),
2678
+ },
2679
+ {
2680
+ name: "destroy",
2681
+ tag: 2,
2682
+ payloadSize: 4,
2683
+ payloadType: "UploaderInstruction::payload::destroy",
2684
+ createPayloadBuilder: () => __tnMaybeCallBuilder(DestroyArgs),
2685
+ },
2686
+ {
2687
+ name: "finalize",
2688
+ tag: 3,
2689
+ payloadSize: 36,
2690
+ payloadType: "UploaderInstruction::payload::finalize",
2691
+ createPayloadBuilder: () => __tnMaybeCallBuilder(FinalizeArgs),
2692
+ },
2693
+ ] as const);
2694
+
2695
+ static __tnComputeSequentialLayout(view: DataView, buffer: Uint8Array): { params: Record<string, bigint> | null; offsets: Record<string, number> | null; derived: Record<string, bigint> | null } | null {
2696
+ const __tnLength = buffer.length;
2697
+ let __tnParamSeq_payload_payload_size: bigint | null = null;
2698
+ let __tnFieldValue_tag: number | null = null;
2699
+ let __tnCursorMutable = 0;
2700
+ if (__tnCursorMutable + 4 > __tnLength) return null;
2701
+ const __tnRead_tag = view.getUint32(__tnCursorMutable, true);
2702
+ __tnFieldValue_tag = __tnRead_tag;
2703
+ __tnCursorMutable += 4;
2704
+ const __tnEnumTagValue_payload = __tnFieldValue_tag;
2705
+ if (__tnEnumTagValue_payload === null) return null;
2706
+ let __tnEnumSize_payload = 0;
2707
+ switch (Number(__tnEnumTagValue_payload)) {
2708
+ case 0: break;
2709
+ case 1: break;
2710
+ case 2: break;
2711
+ case 3: break;
2712
+ default: return null;
2713
+ }
2714
+ if (__tnCursorMutable > __tnLength) return null;
2715
+ __tnEnumSize_payload = __tnLength - __tnCursorMutable;
2716
+ __tnCursorMutable = __tnLength;
2717
+ __tnParamSeq_payload_payload_size = __tnToBigInt(__tnEnumSize_payload);
2718
+ const params: Record<string, bigint> = Object.create(null);
2719
+ if (__tnParamSeq_payload_payload_size === null) return null;
2720
+ params["payload_payload_size"] = __tnParamSeq_payload_payload_size as bigint;
2721
+ return { params, offsets: null, derived: null };
2722
+ }
2723
+
2724
+ private static __tnExtractParams(view: DataView, buffer: Uint8Array): { params: UploaderInstruction.Params; derived: Record<string, bigint> | null } | null {
2725
+ if (buffer.length < 4) {
2726
+ return null;
2727
+ }
2728
+ const __tnParam_payload_tag = __tnToBigInt(view.getUint32(0, true));
2729
+ const __tnLayout = UploaderInstruction.__tnComputeSequentialLayout(view, buffer);
2730
+ if (!__tnLayout || !__tnLayout.params) return null;
2731
+ const __tnSeqParams = __tnLayout.params;
2732
+ const __tnParamSeq_payload_payload_size = __tnSeqParams["payload_payload_size"];
2733
+ if (__tnParamSeq_payload_payload_size === undefined) return null;
2734
+ const __tnExtractedParams = UploaderInstruction.Params.fromValues({
2735
+ payload_payload_size: __tnParamSeq_payload_payload_size as bigint,
2736
+ payload_tag: __tnParam_payload_tag,
2737
+ });
2738
+ return { params: __tnExtractedParams, derived: null };
2739
+ }
2740
+
2741
+ get_tag(): number {
2742
+ const offset = 0;
2743
+ return this.view.getUint32(offset, true); /* little-endian */
2744
+ }
2745
+
2746
+ set_tag(value: number): void {
2747
+ const offset = 0;
2748
+ this.view.setUint32(offset, value, true); /* little-endian */
2749
+ }
2750
+
2751
+ get tag(): number {
2752
+ return this.get_tag();
2753
+ }
2754
+
2755
+ set tag(value: number) {
2756
+ this.set_tag(value);
2757
+ }
2758
+
2759
+ payloadVariant(): typeof UploaderInstruction.payloadVariantDescriptors[number] | null {
2760
+ const tag = this.view.getUint8(0);
2761
+ return UploaderInstruction.payloadVariantDescriptors.find((variant) => variant.tag === tag) ?? null;
2762
+ }
2763
+
2764
+ payload(): UploaderInstruction_payload_Inner {
2765
+ const descriptor = this.payloadVariant();
2766
+ if (!descriptor) throw new Error("UploaderInstruction: unknown payload variant");
2767
+ const offset = UploaderInstruction.__tnFieldOffset_payload;
2768
+ const remaining = this.buffer.length - offset;
2769
+ const payloadLength = descriptor.payloadSize ?? remaining;
2770
+ if (payloadLength < 0 || offset + payloadLength > this.buffer.length) throw new Error("UploaderInstruction: payload exceeds buffer bounds");
2771
+ const slice = this.buffer.subarray(offset, offset + payloadLength);
2772
+ return UploaderInstruction_payload_Inner.__tnCreate(slice, descriptor, undefined);
2773
+ }
2774
+ private static __tnFootprintInternal(__tnParams: Record<string, bigint>): bigint {
2775
+ return __tnEvalFootprint(__tn_ir_UploaderInstruction.root, { params: __tnParams });
2776
+ }
2777
+
2778
+ private static __tnValidateInternal(buffer: Uint8Array, __tnParams: Record<string, bigint>): { ok: boolean; code?: string; consumed?: bigint } {
2779
+ return __tnValidateIrTree(__tn_ir_UploaderInstruction, buffer, __tnParams);
2780
+ }
2781
+
2782
+ static __tnInvokeFootprint(__tnParams: Record<string, bigint>): bigint {
2783
+ return this.__tnFootprintInternal(__tnParams);
2784
+ }
2785
+
2786
+ static __tnInvokeValidate(buffer: Uint8Array, __tnParams: Record<string, bigint>): __TnValidateResult {
2787
+ return this.__tnValidateInternal(buffer, __tnParams);
2788
+ }
2789
+
2790
+ static footprintIr(payload_payload_size: number | bigint, payload_tag: number | bigint): bigint {
2791
+ const params = UploaderInstruction.Params.fromValues({
2792
+ payload_payload_size: payload_payload_size,
2793
+ payload_tag: payload_tag,
2794
+ });
2795
+ return this.footprintIrFromParams(params);
2796
+ }
2797
+
2798
+ private static __tnPackParams(params: UploaderInstruction.Params): Record<string, bigint> {
2799
+ const record: Record<string, bigint> = Object.create(null);
2800
+ record["payload.payload_size"] = params.payload_payload_size;
2801
+ record["payload.tag"] = params.payload_tag;
2802
+ return record;
2803
+ }
2804
+
2805
+ static footprintIrFromParams(params: UploaderInstruction.Params): bigint {
2806
+ const __tnParams = this.__tnPackParams(params);
2807
+ return this.__tnFootprintInternal(__tnParams);
2808
+ }
2809
+
2810
+ static footprintFromParams(params: UploaderInstruction.Params): number {
2811
+ const irResult = this.footprintIrFromParams(params);
2812
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2813
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error('footprint exceeds Number.MAX_SAFE_INTEGER for UploaderInstruction');
2814
+ return __tnBigIntToNumber(irResult, 'UploaderInstruction::footprintFromParams');
2815
+ }
2816
+
2817
+ static footprintFromValues(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): number {
2818
+ const params = UploaderInstruction.params(input);
2819
+ return this.footprintFromParams(params);
2820
+ }
2821
+
2822
+ static footprint(params: UploaderInstruction.Params): number {
2823
+ return this.footprintFromParams(params);
2824
+ }
2825
+
2826
+ static validate(buffer: Uint8Array, opts?: { params?: UploaderInstruction.Params }): { ok: boolean; code?: string; consumed?: number; params?: UploaderInstruction.Params } {
2827
+ if (!buffer || buffer.length === undefined) {
2828
+ return { ok: false, code: "tn.invalid_buffer" };
2829
+ }
2830
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2831
+ let params = opts?.params ?? null;
2832
+ if (!params) {
2833
+ const extracted = this.__tnExtractParams(view, buffer);
2834
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
2835
+ params = extracted.params;
2836
+ }
2837
+ const __tnParamsRec = this.__tnPackParams(params);
2838
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
2839
+ if (!irResult.ok) {
2840
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'UploaderInstruction::validate') : undefined, params };
2841
+ }
2842
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, 'UploaderInstruction::validate') : undefined;
2843
+ return { ok: true, consumed, params };
2844
+ }
2845
+
2846
+ static from_array(buffer: Uint8Array, opts?: { params?: UploaderInstruction.Params }): UploaderInstruction | null {
2847
+ if (!buffer || buffer.length === undefined) {
2848
+ return null;
2849
+ }
2850
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2851
+ let params = opts?.params ?? null;
2852
+ if (!params) {
2853
+ const derived = this.__tnExtractParams(view, buffer);
2854
+ if (!derived) return null;
2855
+ params = derived.params;
2856
+ }
2857
+ const validation = this.validate(buffer, { params });
2858
+ if (!validation.ok) {
2859
+ return null;
2860
+ }
2861
+ const cached = validation.params ?? params;
2862
+ const state = new UploaderInstruction(buffer, cached);
2863
+ return state;
2864
+ }
2865
+
2866
+
2867
+ }
2868
+
2869
+ export namespace UploaderInstruction {
2870
+ export type Params = {
2871
+ /** ABI path: payload.payload_size */
2872
+ readonly payload_payload_size: bigint;
2873
+ /** ABI path: payload.tag */
2874
+ readonly payload_tag: bigint;
2875
+ };
2876
+
2877
+ export const ParamKeys = Object.freeze({
2878
+ payload_payload_size: "payload.payload_size",
2879
+ payload_tag: "payload.tag",
2880
+ } as const);
2881
+
2882
+ export const Params = {
2883
+ fromValues(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): Params {
2884
+ return {
2885
+ payload_payload_size: __tnToBigInt(input.payload_payload_size),
2886
+ payload_tag: __tnToBigInt(input.payload_tag),
2887
+ };
2888
+ },
2889
+ fromBuilder(source: { dynamicParams(): Params } | { params: Params } | Params): Params {
2890
+ if ((source as { dynamicParams?: () => Params }).dynamicParams) {
2891
+ return (source as { dynamicParams(): Params }).dynamicParams();
2892
+ }
2893
+ if ((source as { params?: Params }).params) {
2894
+ return (source as { params: Params }).params;
2895
+ }
2896
+ return source as Params;
2897
+ }
2898
+ };
2899
+
2900
+ export function params(input: { payload_payload_size: number | bigint, payload_tag: number | bigint }): Params {
2901
+ return Params.fromValues(input);
2902
+ }
2903
+ }
2904
+
2905
+ export class UploaderInstructionBuilder {
2906
+ private __tnPrefixBuffer: Uint8Array;
2907
+ private __tnPrefixView: DataView;
2908
+ private __tnField_tag: number | null = null;
2909
+ private __tnPayload_payload: { descriptor: typeof UploaderInstruction.payloadVariantDescriptors[number]; bytes: Uint8Array } | null = null;
2910
+ private __tnCachedParams: UploaderInstruction.Params | null = null;
2911
+ private __tnLastBuffer: Uint8Array | null = null;
2912
+ private __tnLastParams: UploaderInstruction.Params | null = null;
2913
+ private __tnVariantSelector_payload?: __TnVariantSelectorResult<UploaderInstructionBuilder>;
2914
+
2915
+ constructor() {
2916
+ this.__tnPrefixBuffer = new Uint8Array(4);
2917
+ this.__tnPrefixView = new DataView(this.__tnPrefixBuffer.buffer, this.__tnPrefixBuffer.byteOffset, this.__tnPrefixBuffer.byteLength);
2918
+ }
2919
+
2920
+ private __tnInvalidate(): void {
2921
+ this.__tnCachedParams = null;
2922
+ this.__tnLastBuffer = null;
2923
+ this.__tnLastParams = null;
2924
+ }
2925
+
2926
+ private __tnAssign_tag(value: number): void {
2927
+ this.__tnField_tag = value;
2928
+ this.__tnInvalidate();
2929
+ }
2930
+
2931
+ set_tag(value: number): this {
2932
+ this.__tnAssign_tag(value);
2933
+ return this;
2934
+ }
2935
+
2936
+ payload(): __TnVariantSelectorResult<UploaderInstructionBuilder> {
2937
+ if (!this.__tnVariantSelector_payload) {
2938
+ this.__tnVariantSelector_payload = __tnCreateVariantSelector(this, UploaderInstruction.payloadVariantDescriptors, (descriptor, payload) => {
2939
+ this.__tnPayload_payload = { descriptor, bytes: new Uint8Array(payload) };
2940
+ this.__tnAssign_tag(descriptor.tag);
2941
+ });
2942
+ }
2943
+ return this.__tnVariantSelector_payload!;
2944
+ }
2945
+
2946
+ build(): Uint8Array {
2947
+ const params = this.__tnComputeParams();
2948
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
2949
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
2950
+ const payloadLength = this.__tnPayload_payload.bytes.length;
2951
+ const requiredSize = 4 + payloadLength;
2952
+ const footprintSize = UploaderInstruction.footprintFromParams(params);
2953
+ const size = Math.max(requiredSize, footprintSize);
2954
+ const buffer = new Uint8Array(size);
2955
+ this.__tnWriteInto(buffer);
2956
+ this.__tnValidateOrThrow(buffer, params);
2957
+ return buffer;
2958
+ }
2959
+
2960
+ buildInto(target: Uint8Array, offset = 0): Uint8Array {
2961
+ const params = this.__tnComputeParams();
2962
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
2963
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
2964
+ const payloadLength = this.__tnPayload_payload.bytes.length;
2965
+ const requiredSize = 4 + payloadLength;
2966
+ const footprintSize = UploaderInstruction.footprintFromParams(params);
2967
+ const size = Math.max(requiredSize, footprintSize);
2968
+ if (target.length - offset < size) throw new Error("UploaderInstructionBuilder: target buffer too small");
2969
+ const slice = target.subarray(offset, offset + size);
2970
+ this.__tnWriteInto(slice);
2971
+ this.__tnValidateOrThrow(slice, params);
2972
+ return target;
2973
+ }
2974
+
2975
+ finish(): UploaderInstruction {
2976
+ const buffer = this.build();
2977
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
2978
+ const view = UploaderInstruction.from_array(buffer, { params });
2979
+ if (!view) throw new Error("UploaderInstructionBuilder: failed to finalize view");
2980
+ return view;
2981
+ }
2982
+
2983
+ finishView(): UploaderInstruction {
2984
+ return this.finish();
2985
+ }
2986
+
2987
+ dynamicParams(): UploaderInstruction.Params {
2988
+ return this.__tnComputeParams();
2989
+ }
2990
+
2991
+ private __tnComputeParams(): UploaderInstruction.Params {
2992
+ if (this.__tnCachedParams) return this.__tnCachedParams;
2993
+ const params = UploaderInstruction.Params.fromValues({
2994
+ payload_payload_size: (() => { if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload 'payload' must be selected before build"); return __tnToBigInt(this.__tnPayload_payload.bytes.length); })(),
2995
+ payload_tag: (() => { if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: missing enum tag"); return __tnToBigInt(this.__tnField_tag); })(),
2996
+ });
2997
+ this.__tnCachedParams = params;
2998
+ return params;
2999
+ }
3000
+
3001
+ private __tnWriteInto(target: Uint8Array): void {
3002
+ if (this.__tnField_tag === null) throw new Error("UploaderInstructionBuilder: field 'tag' must be set before build");
3003
+ if (!this.__tnPayload_payload) throw new Error("UploaderInstructionBuilder: payload variant not selected");
3004
+ const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
3005
+ target.set(this.__tnPrefixBuffer, 0);
3006
+ view.setUint32(0, this.__tnField_tag, true);
3007
+ target.set(this.__tnPayload_payload.bytes, 4);
3008
+ }
3009
+
3010
+ private __tnValidateOrThrow(buffer: Uint8Array, params: UploaderInstruction.Params): void {
3011
+ const result = UploaderInstruction.validate(buffer, { params });
3012
+ if (!result.ok) {
3013
+ throw new Error(`${ UploaderInstruction }Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3014
+ }
3015
+ this.__tnLastParams = result.params ?? params;
3016
+ this.__tnLastBuffer = buffer;
3017
+ }
3018
+ }
3019
+
3020
+ __tnRegisterFootprint("UploaderInstruction", (params) => UploaderInstruction.__tnInvokeFootprint(params));
3021
+ __tnRegisterValidate("UploaderInstruction", (buffer, params) => UploaderInstruction.__tnInvokeValidate(buffer, params));
3022
+ __tnRegisterDynamicValidate("UploaderInstruction", (buffer) => { const result = UploaderInstruction.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 }; });