@thru/programs 0.4.1 → 0.4.2

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 (58) hide show
  1. package/dist/abi-manager/index.cjs +39 -2
  2. package/dist/abi-manager/index.cjs.map +1 -1
  3. package/dist/abi-manager/index.js +2 -2
  4. package/dist/amm/index.cjs +39 -2
  5. package/dist/amm/index.cjs.map +1 -1
  6. package/dist/amm/index.js +1 -1
  7. package/dist/bootstrap-addresses/index.cjs +41 -2
  8. package/dist/bootstrap-addresses/index.cjs.map +1 -1
  9. package/dist/bootstrap-addresses/index.d.cts +8 -1
  10. package/dist/bootstrap-addresses/index.d.ts +8 -1
  11. package/dist/bootstrap-addresses/index.js +1 -1
  12. package/dist/{chunk-TRPUGPZJ.js → chunk-2FFCNXCE.js} +58 -5
  13. package/dist/chunk-2FFCNXCE.js.map +1 -0
  14. package/dist/{chunk-QCJFKBAS.js → chunk-I3DLOUB4.js} +3 -3
  15. package/dist/{chunk-QCJFKBAS.js.map → chunk-I3DLOUB4.js.map} +1 -1
  16. package/dist/clob/index.cjs +41 -2
  17. package/dist/clob/index.cjs.map +1 -1
  18. package/dist/clob/index.d.cts +7 -1
  19. package/dist/clob/index.d.ts +7 -1
  20. package/dist/clob/index.js +3 -2
  21. package/dist/clob/index.js.map +1 -1
  22. package/dist/deploy/index.cjs +39 -2
  23. package/dist/deploy/index.cjs.map +1 -1
  24. package/dist/deploy/index.js +3 -3
  25. package/dist/oracle/index.cjs +39 -2
  26. package/dist/oracle/index.cjs.map +1 -1
  27. package/dist/oracle/index.js +1 -1
  28. package/dist/passkey-manager/index.cjs +42 -5
  29. package/dist/passkey-manager/index.cjs.map +1 -1
  30. package/dist/passkey-manager/index.js +1 -1
  31. package/dist/perp/index.cjs +1785 -162
  32. package/dist/perp/index.cjs.map +1 -1
  33. package/dist/perp/index.d.cts +558 -13
  34. package/dist/perp/index.d.ts +558 -13
  35. package/dist/perp/index.js +1749 -163
  36. package/dist/perp/index.js.map +1 -1
  37. package/dist/ratelimit/index.cjs +4757 -0
  38. package/dist/ratelimit/index.cjs.map +1 -0
  39. package/dist/ratelimit/index.d.cts +171 -0
  40. package/dist/ratelimit/index.d.ts +171 -0
  41. package/dist/ratelimit/index.js +4527 -0
  42. package/dist/ratelimit/index.js.map +1 -0
  43. package/package.json +7 -2
  44. package/src/bootstrap-addresses/index.test.ts +17 -0
  45. package/src/bootstrap-addresses/index.ts +12 -0
  46. package/src/clob/index.ts +7 -0
  47. package/src/perp/abi/thru/program/perp/types.ts +1949 -149
  48. package/src/perp/index.test.ts +189 -3
  49. package/src/perp/index.ts +316 -3
  50. package/src/ratelimit/abi/thru/program/ratelimit/types.ts +5448 -0
  51. package/src/ratelimit/accounts.ts +105 -0
  52. package/src/ratelimit/constants.ts +49 -0
  53. package/src/ratelimit/derivation.ts +93 -0
  54. package/src/ratelimit/index.test.ts +185 -0
  55. package/src/ratelimit/index.ts +30 -0
  56. package/src/ratelimit/instructions.ts +244 -0
  57. package/tsup.config.ts +1 -0
  58. package/dist/chunk-TRPUGPZJ.js.map +0 -1
@@ -0,0 +1,4757 @@
1
+ 'use strict';
2
+
3
+ var sdk = require('@thru/sdk');
4
+ var helpers = require('@thru/sdk/helpers');
5
+ var helpers_star = require('@thru/sdk/programs/utils/helpers');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var helpers_star__namespace = /*#__PURE__*/_interopNamespace(helpers_star);
26
+
27
+ var __defProp = Object.defineProperty;
28
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
29
+ var __getOwnPropNames = Object.getOwnPropertyNames;
30
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
31
+ var __copyProps = (to, from, except, desc) => {
32
+ if (from && typeof from === "object" || typeof from === "function") {
33
+ for (let key of __getOwnPropNames(from))
34
+ if (!__hasOwnProp.call(to, key) && key !== except)
35
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
36
+ }
37
+ return to;
38
+ };
39
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget);
40
+
41
+ // src/utils/helpers.ts
42
+ var helpers_exports = {};
43
+ __reExport(helpers_exports, helpers_star__namespace);
44
+
45
+ // src/manager/constants.ts
46
+ var ROOT_MANAGER_PROGRAM_PUBKEY = (0, helpers_exports.systemProgramPubkey)(1);
47
+ var ROOT_MANAGER_PROGRAM_ADDRESS = helpers.encodeAddress(ROOT_MANAGER_PROGRAM_PUBKEY);
48
+ var MANAGER_PROGRAM_SEED = "thru-main-manager:949457";
49
+ var managerMeta = sdk.deriveProgramAddress({
50
+ programAddress: ROOT_MANAGER_PROGRAM_ADDRESS,
51
+ seed: (0, helpers_exports.padSeed)(MANAGER_PROGRAM_SEED)
52
+ });
53
+ var MANAGER_PROGRAM_PUBKEY = sdk.deriveProgramAddress({
54
+ programAddress: ROOT_MANAGER_PROGRAM_ADDRESS,
55
+ seed: managerMeta.bytes
56
+ }).bytes;
57
+ var MANAGER_PROGRAM_ADDRESS = helpers.encodeAddress(MANAGER_PROGRAM_PUBKEY);
58
+
59
+ // src/manager/derivation.ts
60
+ function deriveManagedProgramAddresses(seed, ephemeral = false, managerProgramAddress = MANAGER_PROGRAM_ADDRESS) {
61
+ const manager = (0, helpers_exports.pubkeyBytes)(managerProgramAddress, "manager program address");
62
+ const meta = sdk.deriveProgramAddress({
63
+ programAddress: manager,
64
+ seed: (0, helpers_exports.padSeed)(seed),
65
+ ephemeral
66
+ });
67
+ const program = sdk.deriveProgramAddress({
68
+ programAddress: manager,
69
+ seed: meta.bytes,
70
+ ephemeral
71
+ });
72
+ return {
73
+ programMetaAccountAddress: meta.address,
74
+ programMetaAccountBytes: meta.bytes,
75
+ programAccountAddress: program.address,
76
+ programAccountBytes: program.bytes
77
+ };
78
+ }
79
+ var encoder = new TextEncoder();
80
+ var POLICY_SEED_TAG = encoder.encode("tn_ratelimit_policy_v1");
81
+ var VERIFIED_POLICY_SEED_TAG = encoder.encode("tn_ratelimit_verified_policy_v1");
82
+ var BUCKET_SEED_TAG = encoder.encode("tn_ratelimit_bucket_v1");
83
+ var AUTHORITY_SEED_TAG = encoder.encode("tn_ratelimit_authority_v1");
84
+ function u64le(value, label) {
85
+ if (typeof value === "number" ? !Number.isSafeInteger(value) || value < 0 : typeof value !== "bigint" || value < 0n || value >= 1n << 64n) {
86
+ throw new Error(`${label} must be a u64`);
87
+ }
88
+ const out = new Uint8Array(8);
89
+ new DataView(out.buffer).setBigUint64(0, BigInt(value), true);
90
+ return out;
91
+ }
92
+ function pda(program, seed) {
93
+ const derived = sdk.deriveProgramAddress({
94
+ programAddress: (0, helpers_exports.pubkeyBytes)(program, "rate limiter program address"),
95
+ seed
96
+ });
97
+ return { address: derived.address, bytes: derived.bytes, seed };
98
+ }
99
+ function ratelimitPolicySeed(options) {
100
+ const target = (0, helpers_exports.pubkeyBytes)(options.target, "target");
101
+ const id = u64le(options.policyId, "policyId");
102
+ if (options.verified) {
103
+ return (0, helpers_exports.hashBytes)(VERIFIED_POLICY_SEED_TAG, target, id);
104
+ }
105
+ if (options.admin === void 0) throw new Error("an unverified policy seed requires admin");
106
+ return (0, helpers_exports.hashBytes)(POLICY_SEED_TAG, (0, helpers_exports.pubkeyBytes)(options.admin, "admin"), target, id);
107
+ }
108
+ function deriveRatelimitPolicyAddress(programAddress, options) {
109
+ return pda(programAddress, ratelimitPolicySeed(options));
110
+ }
111
+ var RATELIMIT_GLOBAL_KEY = new Uint8Array(32);
112
+ function deriveRatelimitBucketAddress(programAddress, policy, ruleIdx, key) {
113
+ if (!Number.isInteger(ruleIdx) || ruleIdx < 0 || ruleIdx > 255) throw new Error("ruleIdx must be a u8");
114
+ return pda(programAddress, (0, helpers_exports.hashBytes)(
115
+ BUCKET_SEED_TAG,
116
+ (0, helpers_exports.pubkeyBytes)(policy, "policy"),
117
+ Uint8Array.of(ruleIdx),
118
+ (0, helpers_exports.pubkeyBytes)(key, "bucket key")
119
+ ));
120
+ }
121
+ function deriveRatelimitAuthorityAddress(programAddress, policy) {
122
+ return pda(programAddress, (0, helpers_exports.hashBytes)(AUTHORITY_SEED_TAG, (0, helpers_exports.pubkeyBytes)(policy, "policy")));
123
+ }
124
+ var BOOTSTRAP_PROGRAM_SEEDS = Object.freeze({
125
+ noop: "thru-program:22654259",
126
+ faucet: "thru-program:310129",
127
+ name_service: "thru-program:2236909",
128
+ oracle: "thru-program:87959905",
129
+ multicall: "thru-program:3153525730",
130
+ abi_manager: "thru-program:167497",
131
+ token: "thru-program:3767426089",
132
+ amm: "thru-program:4614050",
133
+ clob: "thru-program:79287062",
134
+ thru_registrar: "thru-program:449594",
135
+ wthru: "thru-program:1687299648",
136
+ passkey_manager: "thru-program:1746189",
137
+ nft: "thru-program:1654635",
138
+ block_producer: "thru-program:8222",
139
+ consensus_validator: "thru-program:35555736",
140
+ eoa: "thru-program:207434",
141
+ uploader: "thru-program:1073768",
142
+ compression: "thru-compression:v1",
143
+ ratelimit: "thru-program:1697627"
144
+ });
145
+ function managedProgramAddress(seed) {
146
+ return deriveManagedProgramAddresses(seed).programAccountAddress;
147
+ }
148
+ var GENESIS_EOA_PROGRAM_SEED = BOOTSTRAP_PROGRAM_SEEDS.eoa;
149
+ managedProgramAddress(GENESIS_EOA_PROGRAM_SEED);
150
+ var BOOTSTRAP_PROGRAM_ADDRESSES = Object.freeze({
151
+ noop: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.noop),
152
+ faucet: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.faucet),
153
+ name_service: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.name_service),
154
+ oracle: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.oracle),
155
+ multicall: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.multicall),
156
+ abi_manager: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.abi_manager),
157
+ token: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.token),
158
+ amm: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.amm),
159
+ clob: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.clob),
160
+ thru_registrar: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.thru_registrar),
161
+ wthru: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.wthru),
162
+ passkey_manager: managedProgramAddress(
163
+ BOOTSTRAP_PROGRAM_SEEDS.passkey_manager
164
+ ),
165
+ nft: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.nft),
166
+ block_producer: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.block_producer),
167
+ consensus_validator: managedProgramAddress(
168
+ BOOTSTRAP_PROGRAM_SEEDS.consensus_validator
169
+ ),
170
+ eoa: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.eoa),
171
+ uploader: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.uploader),
172
+ compression: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.compression),
173
+ ratelimit: managedProgramAddress(BOOTSTRAP_PROGRAM_SEEDS.ratelimit)
174
+ });
175
+ function stateAddress(program, label) {
176
+ const seed = new Uint8Array(32);
177
+ seed.set(new TextEncoder().encode(label));
178
+ return sdk.deriveProgramAddress({ programAddress: program, seed }).address;
179
+ }
180
+ var wthruSeed = new Uint8Array(32);
181
+ stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.faucet, "vault");
182
+ var BOOTSTRAP_FAUCET_RATE_LIMIT_POLICY_ID = 0n;
183
+ deriveRatelimitPolicyAddress(
184
+ BOOTSTRAP_PROGRAM_ADDRESSES.ratelimit,
185
+ { target: BOOTSTRAP_PROGRAM_ADDRESSES.faucet, policyId: BOOTSTRAP_FAUCET_RATE_LIMIT_POLICY_ID, verified: true }
186
+ ).address;
187
+ wthruSeed.set(new TextEncoder().encode("wthru"));
188
+ var wthruMintSeed = sdk.deriveAddress([
189
+ sdk.Pubkey.from(BOOTSTRAP_PROGRAM_ADDRESSES.wthru).toBytes(),
190
+ wthruSeed
191
+ ]).bytes;
192
+ Object.freeze({
193
+ attestor_table: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.consensus_validator, "attestor_table"),
194
+ attestor_mint: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.consensus_validator, "attestor_mint"),
195
+ converted_vault: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.consensus_validator, "converted_vault"),
196
+ unclaimed_vault: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.consensus_validator, "unclaimed_vault"),
197
+ validator_token_base: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.consensus_validator, "validator_token"),
198
+ wthru_mint: sdk.deriveProgramAddress({
199
+ programAddress: BOOTSTRAP_PROGRAM_ADDRESSES.token,
200
+ seed: wthruMintSeed
201
+ }).address,
202
+ wthru_vault: stateAddress(BOOTSTRAP_PROGRAM_ADDRESSES.wthru, "vault")
203
+ });
204
+
205
+ // src/ratelimit/constants.ts
206
+ var RATELIMIT_INSTRUCTION_CALL = 4;
207
+ var RATELIMIT_ERRORS = Object.freeze({
208
+ INVALID_INSTRUCTION: 0x5201n,
209
+ INVALID_ACCOUNT: 0x5202n,
210
+ INVALID_CONFIG: 0x5203n,
211
+ UNAUTHORIZED: 0x5204n,
212
+ CREATE_FAILED: 0x5205n,
213
+ WRITE_FAILED: 0x5206n,
214
+ PAUSED: 0x5207n,
215
+ TARGET_MISMATCH: 0x5208n,
216
+ INSTRUCTION_REJECTED: 0x5209n,
217
+ AMOUNT_PER_CALL_EXCEEDED: 0x520an,
218
+ BUCKET_MISMATCH: 0x520bn,
219
+ ATTESTER_REQUIRED: 0x520cn,
220
+ CALL_LIMIT_EXCEEDED: 0x520dn,
221
+ AMOUNT_LIMIT_EXCEEDED: 0x520en,
222
+ TARGET_FAILED: 0x520fn,
223
+ /* Reverted by gated targets (tn_ratelimit_gate.h). */
224
+ GATE_NOT_RATE_LIMITED: 0x52a1n
225
+ });
226
+ var RATELIMIT_POLICY_MAGIC = 0x7261746c706f6c31n;
227
+ var RATELIMIT_BUCKET_MAGIC = 0x7261746c62636b31n;
228
+ var RATELIMIT_RULE_MAX = 4;
229
+ var RATELIMIT_CONSTRAINT_MAX = 4;
230
+ var RATELIMIT_NO_ACCOUNT = 65535;
231
+ var RATELIMIT_POLICY_FLAG_PAUSED = 1;
232
+ var RATELIMIT_POLICY_FLAG_VERIFIED = 128;
233
+ var RATELIMIT_KEY_GLOBAL = 0;
234
+ var RATELIMIT_KEY_FEE_PAYER = 1;
235
+ var RATELIMIT_KEY_INSTR_ACCOUNT = 2;
236
+ var RATELIMIT_KEY_ATTESTED = 3;
237
+ var RATELIMIT_CLOCK_SLOT = 0;
238
+ var RATELIMIT_CLOCK_UNIX_SECONDS = 1;
239
+ var RATELIMIT_CONFIG_SIZE = 309;
240
+ var RATELIMIT_POLICY_SIZE = 390;
241
+ var RATELIMIT_BUCKET_SIZE = 113;
242
+ var RATELIMIT_CALL_ARGS_SIZE = 8;
243
+ var RATELIMIT_CALL_BUCKET_SIZE = 36;
244
+
245
+ // src/ratelimit/abi/thru/program/ratelimit/types.ts
246
+ var __tnWarnings = /* @__PURE__ */ new Set();
247
+ var __tnHasNativeBigInt = typeof BigInt === "function";
248
+ var __tnHasBigIntDataView = typeof DataView !== "undefined" && typeof DataView.prototype.getBigInt64 === "function" && typeof DataView.prototype.getBigUint64 === "function" && typeof DataView.prototype.setBigInt64 === "function" && typeof DataView.prototype.setBigUint64 === "function";
249
+ var __tnConsole = typeof globalThis !== "undefined" ? globalThis.console : void 0;
250
+ function __tnLogWarn(message) {
251
+ if (__tnConsole && typeof __tnConsole.warn === "function") {
252
+ __tnConsole.warn(message);
253
+ }
254
+ }
255
+ function __tnWarnOnce(message) {
256
+ if (!__tnWarnings.has(message)) {
257
+ __tnWarnings.add(message);
258
+ __tnLogWarn(message);
259
+ }
260
+ }
261
+ function __tnResolveBuilderInput(input, context) {
262
+ if (input instanceof Uint8Array) {
263
+ return new Uint8Array(input);
264
+ }
265
+ if (input && typeof input.build === "function") {
266
+ const built = input.build();
267
+ if (!(built instanceof Uint8Array)) {
268
+ throw new Error(`${context}: builder did not return Uint8Array`);
269
+ }
270
+ return new Uint8Array(built);
271
+ }
272
+ throw new Error(`${context}: expected Uint8Array or builder`);
273
+ }
274
+ function __tnMaybeCallBuilder(ctor) {
275
+ if (!ctor) {
276
+ return null;
277
+ }
278
+ const builderFn = ctor.builder;
279
+ return typeof builderFn === "function" ? builderFn() : null;
280
+ }
281
+ function __tnCreateVariantSelector(parent, descriptors, assign) {
282
+ return {
283
+ select(name) {
284
+ const descriptor = descriptors.find((variant) => variant.name === name);
285
+ if (!descriptor) {
286
+ throw new Error(`Unknown variant '${name}'`);
287
+ }
288
+ return {
289
+ writePayload(payload) {
290
+ const bytes2 = __tnResolveBuilderInput(
291
+ payload,
292
+ `variant ${descriptor.name}`
293
+ );
294
+ if (descriptor.payloadSize !== null && bytes2.length !== descriptor.payloadSize) {
295
+ throw new Error(
296
+ `Payload for ${descriptor.name} must be ${descriptor.payloadSize} bytes`
297
+ );
298
+ }
299
+ assign(descriptor, bytes2);
300
+ return {
301
+ finish() {
302
+ return parent;
303
+ }
304
+ };
305
+ }
306
+ };
307
+ },
308
+ finish() {
309
+ return parent;
310
+ }
311
+ };
312
+ }
313
+ function __tnCreateFamWriter(parent, fieldName, assign) {
314
+ let hasWritten = false;
315
+ return {
316
+ write(payload) {
317
+ const bytes2 = __tnResolveBuilderInput(
318
+ payload,
319
+ `flexible array '${fieldName}'`
320
+ );
321
+ const copy = new Uint8Array(bytes2);
322
+ assign(copy);
323
+ hasWritten = true;
324
+ return {
325
+ finish() {
326
+ return parent;
327
+ }
328
+ };
329
+ },
330
+ finish() {
331
+ if (!hasWritten) {
332
+ throw new Error(
333
+ `flexible array '${fieldName}' requires write() before finish()`
334
+ );
335
+ }
336
+ return parent;
337
+ }
338
+ };
339
+ }
340
+ var __tnMask32 = __tnHasNativeBigInt ? (BigInt(1) << BigInt(32)) - BigInt(1) : 4294967295;
341
+ var __tnSignBit32 = __tnHasNativeBigInt ? BigInt(1) << BigInt(31) : 2147483648;
342
+ function __tnToBigInt(value) {
343
+ if (__tnHasNativeBigInt) {
344
+ return typeof value === "bigint" ? value : BigInt(value);
345
+ }
346
+ if (typeof value === "bigint") return value;
347
+ if (!Number.isFinite(value)) {
348
+ throw new Error("IR runtime received non-finite numeric input");
349
+ }
350
+ if (!Number.isSafeInteger(value)) {
351
+ __tnWarnOnce(
352
+ `[thru-net] Precision loss while polyfilling BigInt (value=${value})`
353
+ );
354
+ }
355
+ return value;
356
+ }
357
+ function __tnBigIntToNumber(value, context) {
358
+ if (__tnHasNativeBigInt) {
359
+ const converted = Number(value);
360
+ if (!Number.isFinite(converted)) {
361
+ throw new Error(`${context} overflowed Number range`);
362
+ }
363
+ return converted;
364
+ }
365
+ return value;
366
+ }
367
+ function __tnBigIntEquals(lhs, rhs) {
368
+ if (__tnHasNativeBigInt) return lhs === rhs;
369
+ return lhs === rhs;
370
+ }
371
+ function __tnBigIntGreaterThan(lhs, rhs) {
372
+ if (__tnHasNativeBigInt) return lhs > rhs;
373
+ return lhs > rhs;
374
+ }
375
+ function __tnRaiseIrError(code, message) {
376
+ const err = new Error(message);
377
+ err.code = code;
378
+ throw err;
379
+ }
380
+ function __tnCheckedAdd(lhs, rhs) {
381
+ if (__tnHasNativeBigInt) {
382
+ const result = lhs + rhs;
383
+ if (result < BigInt(0)) {
384
+ __tnRaiseIrError(
385
+ "tn.ir.overflow",
386
+ "IR runtime detected negative size via addition"
387
+ );
388
+ }
389
+ return result;
390
+ }
391
+ const left = lhs;
392
+ const right = rhs;
393
+ const sum = left + right;
394
+ if (sum < 0 || !Number.isFinite(sum)) {
395
+ __tnRaiseIrError(
396
+ "tn.ir.overflow",
397
+ "IR runtime detected invalid addition result"
398
+ );
399
+ }
400
+ if (!Number.isSafeInteger(sum)) {
401
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt addition");
402
+ }
403
+ return sum;
404
+ }
405
+ function __tnCheckedSub(lhs, rhs) {
406
+ if (__tnHasNativeBigInt) {
407
+ const result = lhs - rhs;
408
+ if (result < BigInt(0)) {
409
+ __tnRaiseIrError(
410
+ "tn.ir.overflow",
411
+ "IR runtime detected negative size via subtraction"
412
+ );
413
+ }
414
+ return result;
415
+ }
416
+ const left = lhs;
417
+ const right = rhs;
418
+ const diff = left - right;
419
+ if (diff < 0 || !Number.isFinite(diff)) {
420
+ __tnRaiseIrError(
421
+ "tn.ir.overflow",
422
+ "IR runtime detected invalid subtraction result"
423
+ );
424
+ }
425
+ if (!Number.isSafeInteger(diff)) {
426
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt subtraction");
427
+ }
428
+ return diff;
429
+ }
430
+ function __tnCheckedMul(lhs, rhs) {
431
+ if (__tnHasNativeBigInt) {
432
+ const result = lhs * rhs;
433
+ if (result < BigInt(0)) {
434
+ __tnRaiseIrError(
435
+ "tn.ir.overflow",
436
+ "IR runtime detected negative size via multiplication"
437
+ );
438
+ }
439
+ return result;
440
+ }
441
+ const left = lhs;
442
+ const right = rhs;
443
+ const product = left * right;
444
+ if (product < 0 || !Number.isFinite(product)) {
445
+ __tnRaiseIrError(
446
+ "tn.ir.overflow",
447
+ "IR runtime detected invalid multiplication result"
448
+ );
449
+ }
450
+ if (!Number.isSafeInteger(product)) {
451
+ __tnWarnOnce(
452
+ "[thru-net] Precision loss while polyfilling BigInt multiplication"
453
+ );
454
+ }
455
+ return product;
456
+ }
457
+ function __tnCheckedDiv(lhs, rhs) {
458
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
459
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime division by zero");
460
+ }
461
+ if (__tnHasNativeBigInt) return lhs / rhs;
462
+ const quotient = Math.floor(lhs / rhs);
463
+ return quotient;
464
+ }
465
+ function __tnCheckedMod(lhs, rhs) {
466
+ if (__tnBigIntEquals(rhs, __tnToBigInt(0))) {
467
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime modulo by zero");
468
+ }
469
+ if (__tnHasNativeBigInt) return lhs % rhs;
470
+ return lhs % rhs;
471
+ }
472
+ function __tnBitwise(lhs, rhs, op) {
473
+ if (__tnHasNativeBigInt) {
474
+ if (op === "and") return lhs & rhs;
475
+ if (op === "or") return lhs | rhs;
476
+ return lhs ^ rhs;
477
+ }
478
+ const left = lhs;
479
+ const right = rhs;
480
+ const maxU32 = 4294967295;
481
+ if (!Number.isInteger(left) || !Number.isInteger(right) || left < 0 || right < 0 || left > maxU32 || right > maxU32) {
482
+ __tnRaiseIrError(
483
+ "tn.ir.overflow",
484
+ "IR runtime bitwise operation requires BigInt for values outside u32 range"
485
+ );
486
+ }
487
+ const result = op === "and" ? left & right : op === "or" ? left | right : left ^ right;
488
+ return result >>> 0;
489
+ }
490
+ function __tnCheckedShift(lhs, rhs, direction) {
491
+ const amount = __tnBigIntToNumber(rhs, "IR shift amount");
492
+ if (amount < 0 || amount >= 64 || !Number.isInteger(amount)) {
493
+ __tnRaiseIrError("tn.ir.overflow", "IR runtime invalid shift amount");
494
+ }
495
+ if (__tnHasNativeBigInt) {
496
+ const shift = BigInt(amount);
497
+ return direction === "left" ? lhs << shift : lhs >> shift;
498
+ }
499
+ const value = lhs;
500
+ const result = direction === "left" ? value * 2 ** amount : Math.floor(value / 2 ** amount);
501
+ if (!Number.isSafeInteger(result)) {
502
+ __tnWarnOnce("[thru-net] Precision loss while polyfilling BigInt shift");
503
+ }
504
+ return result;
505
+ }
506
+ function __tnAlign(value, alignment) {
507
+ if (alignment <= 1) return value;
508
+ const alignBig = __tnToBigInt(alignment);
509
+ if (__tnHasNativeBigInt) {
510
+ const remainder2 = value % alignBig;
511
+ if (__tnBigIntEquals(remainder2, __tnToBigInt(0))) {
512
+ return value;
513
+ }
514
+ const delta = alignBig - remainder2;
515
+ return __tnCheckedAdd(value, delta);
516
+ }
517
+ const current = __tnBigIntToNumber(value, "IR align");
518
+ const alignNum = alignment >>> 0;
519
+ const remainder = current % alignNum;
520
+ const next = remainder === 0 ? current : current + (alignNum - remainder);
521
+ return __tnToBigInt(next);
522
+ }
523
+ function __tnSplitUint64(value) {
524
+ if (__tnHasNativeBigInt) {
525
+ const low2 = Number(value & __tnMask32);
526
+ const high2 = Number(value >> BigInt(32) & __tnMask32);
527
+ return { high: high2, low: low2 };
528
+ }
529
+ const num = __tnBigIntToNumber(value, "DataView.setBigUint64");
530
+ const low = num >>> 0;
531
+ const high = Math.floor(num / 4294967296) >>> 0;
532
+ return { high, low };
533
+ }
534
+ function __tnSplitInt64(value) {
535
+ if (__tnHasNativeBigInt) {
536
+ const low2 = Number(value & __tnMask32);
537
+ let high2 = Number(value >> BigInt(32) & __tnMask32);
538
+ if ((BigInt(high2) & __tnSignBit32) !== BigInt(0)) {
539
+ high2 -= 4294967296;
540
+ }
541
+ return { high: high2, low: low2 };
542
+ }
543
+ const num = __tnBigIntToNumber(value, "DataView.setBigInt64");
544
+ const low = num >>> 0;
545
+ const high = Math.floor(num / 4294967296);
546
+ return { high, low };
547
+ }
548
+ function __tnPolyfillReadUint64(view, offset, littleEndian) {
549
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
550
+ const high = littleEndian ? view.getUint32(offset + 4, true) : view.getUint32(offset, false);
551
+ if (__tnHasNativeBigInt) {
552
+ return BigInt(high) << BigInt(32) | BigInt(low);
553
+ }
554
+ const value = high * 4294967296 + low;
555
+ if (!Number.isSafeInteger(value)) {
556
+ __tnWarnOnce(
557
+ "[thru-net] Precision loss while polyfilling DataView.getBigUint64"
558
+ );
559
+ }
560
+ return value;
561
+ }
562
+ function __tnPolyfillReadInt64(view, offset, littleEndian) {
563
+ const low = littleEndian ? view.getUint32(offset, true) : view.getUint32(offset + 4, false);
564
+ const high = littleEndian ? view.getInt32(offset + 4, true) : view.getInt32(offset, false);
565
+ if (__tnHasNativeBigInt) {
566
+ return BigInt(high) << BigInt(32) | BigInt(low);
567
+ }
568
+ const value = high * 4294967296 + low;
569
+ if (!Number.isSafeInteger(value)) {
570
+ __tnWarnOnce(
571
+ "[thru-net] Precision loss while polyfilling DataView.getBigInt64"
572
+ );
573
+ }
574
+ return value;
575
+ }
576
+ function __tnPolyfillWriteUint64(view, offset, value, littleEndian) {
577
+ const parts = __tnSplitUint64(value);
578
+ if (littleEndian) {
579
+ view.setUint32(offset, parts.low, true);
580
+ view.setUint32(offset + 4, parts.high, true);
581
+ } else {
582
+ view.setUint32(offset, parts.high, false);
583
+ view.setUint32(offset + 4, parts.low, false);
584
+ }
585
+ }
586
+ function __tnPolyfillWriteInt64(view, offset, value, littleEndian) {
587
+ const parts = __tnSplitInt64(value);
588
+ if (littleEndian) {
589
+ view.setUint32(offset, parts.low >>> 0, true);
590
+ view.setInt32(offset + 4, parts.high | 0, true);
591
+ } else {
592
+ view.setInt32(offset, parts.high | 0, false);
593
+ view.setUint32(offset + 4, parts.low >>> 0, false);
594
+ }
595
+ }
596
+ if (typeof DataView !== "undefined" && !__tnHasBigIntDataView) {
597
+ const proto = DataView.prototype;
598
+ if (typeof proto.getBigUint64 !== "function") {
599
+ proto.getBigUint64 = function(offset, littleEndian) {
600
+ __tnWarnOnce(
601
+ "[thru-net] Polyfilling DataView.getBigUint64; precision may be lost"
602
+ );
603
+ return __tnPolyfillReadUint64(this, offset, !!littleEndian);
604
+ };
605
+ }
606
+ if (typeof proto.getBigInt64 !== "function") {
607
+ proto.getBigInt64 = function(offset, littleEndian) {
608
+ __tnWarnOnce(
609
+ "[thru-net] Polyfilling DataView.getBigInt64; precision may be lost"
610
+ );
611
+ return __tnPolyfillReadInt64(this, offset, !!littleEndian);
612
+ };
613
+ }
614
+ if (typeof proto.setBigUint64 !== "function") {
615
+ proto.setBigUint64 = function(offset, value, littleEndian) {
616
+ __tnWarnOnce(
617
+ "[thru-net] Polyfilling DataView.setBigUint64; precision may be lost"
618
+ );
619
+ __tnPolyfillWriteUint64(this, offset, value, !!littleEndian);
620
+ };
621
+ }
622
+ if (typeof proto.setBigInt64 !== "function") {
623
+ proto.setBigInt64 = function(offset, value, littleEndian) {
624
+ __tnWarnOnce(
625
+ "[thru-net] Polyfilling DataView.setBigInt64; precision may be lost"
626
+ );
627
+ __tnPolyfillWriteInt64(this, offset, value, !!littleEndian);
628
+ };
629
+ }
630
+ if (!__tnHasNativeBigInt) {
631
+ __tnWarnOnce(
632
+ "[thru-net] BigInt is unavailable; falling back to lossy 64-bit polyfill"
633
+ );
634
+ }
635
+ }
636
+ var __tnFootprintRegistry = {};
637
+ var __tnValidateRegistry = {};
638
+ var __tnDynamicValidateRegistry = {};
639
+ function __tnRegisterFootprint(typeName, fn) {
640
+ __tnFootprintRegistry[typeName] = fn;
641
+ }
642
+ function __tnRegisterValidate(typeName, fn) {
643
+ __tnValidateRegistry[typeName] = fn;
644
+ }
645
+ function __tnRegisterDynamicValidate(typeName, fn) {
646
+ __tnDynamicValidateRegistry[typeName] = fn;
647
+ }
648
+ function __tnInvokeFootprint(typeName, params) {
649
+ const fn = __tnFootprintRegistry[typeName];
650
+ if (!fn) throw new Error(`IR runtime missing footprint for ${typeName}`);
651
+ return fn(params);
652
+ }
653
+ function __tnInvokeValidate(typeName, buffer, params) {
654
+ const fn = __tnValidateRegistry[typeName];
655
+ if (!fn) throw new Error(`IR runtime missing validate helper for ${typeName}`);
656
+ return fn(buffer, params);
657
+ }
658
+ function __tnInvokeDynamicValidate(typeName, buffer) {
659
+ const fn = __tnDynamicValidateRegistry[typeName];
660
+ if (!fn) throw new Error(`IR runtime missing dynamic validate helper for ${typeName}`);
661
+ return fn(buffer);
662
+ }
663
+ function __tnEvalFootprint(node, ctx) {
664
+ return __tnEvalIrNode(node, ctx, __tnToBigInt(0));
665
+ }
666
+ function __tnTryEvalIr(node, ctx) {
667
+ try {
668
+ return { ok: true, value: __tnEvalIrNode(node, ctx, __tnToBigInt(0)) };
669
+ } catch (err) {
670
+ return { ok: false, code: __tnNormalizeIrError(err) };
671
+ }
672
+ }
673
+ function __tnIsEvalError(result) {
674
+ return result.ok === false;
675
+ }
676
+ function __tnValidateIrTree(ir, buffer, params) {
677
+ const evalResult = __tnTryEvalIr(ir.root, {
678
+ params,
679
+ buffer,
680
+ typeName: ir.typeName
681
+ });
682
+ if (__tnIsEvalError(evalResult)) {
683
+ return { ok: false, code: evalResult.code };
684
+ }
685
+ const required = evalResult.value;
686
+ const available = __tnToBigInt(buffer.length);
687
+ if (__tnBigIntGreaterThan(required, available)) {
688
+ return { ok: false, code: "tn.buffer_too_small", consumed: required };
689
+ }
690
+ return { ok: true, consumed: required };
691
+ }
692
+ function __tnEvalIrNode(node, ctx, baseOffset) {
693
+ switch (node.op) {
694
+ case "zero":
695
+ return __tnToBigInt(0);
696
+ case "const":
697
+ return node.value;
698
+ case "field": {
699
+ if (node.param === "__buffer_size" && ctx.buffer) {
700
+ return __tnToBigInt(ctx.buffer.length);
701
+ }
702
+ const val = ctx.params[node.param];
703
+ if (val === void 0) {
704
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
705
+ __tnRaiseIrError(
706
+ "tn.ir.missing_param",
707
+ `${prefix}Missing IR parameter '${node.param}'`
708
+ );
709
+ }
710
+ return val;
711
+ }
712
+ case "add": {
713
+ const left = __tnEvalIrNode(node.left, ctx, baseOffset);
714
+ const right = __tnEvalIrNode(
715
+ node.right,
716
+ ctx,
717
+ __tnCheckedAdd(baseOffset, left)
718
+ );
719
+ return __tnCheckedAdd(left, right);
720
+ }
721
+ case "sub":
722
+ return __tnCheckedSub(
723
+ __tnEvalIrNode(node.left, ctx, baseOffset),
724
+ __tnEvalIrNode(node.right, ctx, baseOffset)
725
+ );
726
+ case "mul":
727
+ return __tnCheckedMul(
728
+ __tnEvalIrNode(node.left, ctx, baseOffset),
729
+ __tnEvalIrNode(node.right, ctx, baseOffset)
730
+ );
731
+ case "div":
732
+ return __tnCheckedDiv(
733
+ __tnEvalIrNode(node.left, ctx, baseOffset),
734
+ __tnEvalIrNode(node.right, ctx, baseOffset)
735
+ );
736
+ case "mod":
737
+ return __tnCheckedMod(
738
+ __tnEvalIrNode(node.left, ctx, baseOffset),
739
+ __tnEvalIrNode(node.right, ctx, baseOffset)
740
+ );
741
+ case "bitAnd":
742
+ return __tnBitwise(
743
+ __tnEvalIrNode(node.left, ctx, baseOffset),
744
+ __tnEvalIrNode(node.right, ctx, baseOffset),
745
+ "and"
746
+ );
747
+ case "bitOr":
748
+ return __tnBitwise(
749
+ __tnEvalIrNode(node.left, ctx, baseOffset),
750
+ __tnEvalIrNode(node.right, ctx, baseOffset),
751
+ "or"
752
+ );
753
+ case "bitXor":
754
+ return __tnBitwise(
755
+ __tnEvalIrNode(node.left, ctx, baseOffset),
756
+ __tnEvalIrNode(node.right, ctx, baseOffset),
757
+ "xor"
758
+ );
759
+ case "leftShift":
760
+ return __tnCheckedShift(
761
+ __tnEvalIrNode(node.left, ctx, baseOffset),
762
+ __tnEvalIrNode(node.right, ctx, baseOffset),
763
+ "left"
764
+ );
765
+ case "rightShift":
766
+ return __tnCheckedShift(
767
+ __tnEvalIrNode(node.left, ctx, baseOffset),
768
+ __tnEvalIrNode(node.right, ctx, baseOffset),
769
+ "right"
770
+ );
771
+ case "align":
772
+ return __tnAlign(__tnEvalIrNode(node.node, ctx, baseOffset), node.alignment);
773
+ case "switch": {
774
+ const tagVal = ctx.params[node.tag];
775
+ if (tagVal === void 0) {
776
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
777
+ __tnRaiseIrError(
778
+ "tn.ir.missing_param",
779
+ `${prefix}Missing IR switch tag '${node.tag}'`
780
+ );
781
+ }
782
+ const tagNumber = Number(tagVal);
783
+ for (const caseNode of node.cases) {
784
+ if (caseNode.value === tagNumber) {
785
+ return __tnEvalIrNode(caseNode.node, ctx, baseOffset);
786
+ }
787
+ }
788
+ if (node.default) return __tnEvalIrNode(node.default, ctx, baseOffset);
789
+ __tnRaiseIrError(
790
+ "tn.ir.invalid_tag",
791
+ `Unhandled IR switch value ${tagNumber} for '${node.tag}'`
792
+ );
793
+ }
794
+ case "call": {
795
+ const nestedParams = /* @__PURE__ */ Object.create(null);
796
+ for (const arg of node.args) {
797
+ const val = ctx.params[arg.source];
798
+ if (val === void 0) {
799
+ const prefix = ctx.typeName ? `${ctx.typeName}: ` : "";
800
+ __tnRaiseIrError(
801
+ "tn.ir.missing_param",
802
+ `${prefix}Missing IR parameter '${arg.source}' for nested call`
803
+ );
804
+ }
805
+ nestedParams[arg.name] = val;
806
+ }
807
+ if (ctx.buffer) {
808
+ const nestedOffset = __tnBigIntToNumber(baseOffset, "IR nested offset");
809
+ const nestedResult = __tnInvokeValidate(
810
+ node.typeName,
811
+ ctx.buffer.subarray(nestedOffset),
812
+ nestedParams
813
+ );
814
+ if (!nestedResult.ok) {
815
+ const nestedCode = nestedResult.code ?? `tn.ir.runtime_error: ${node.typeName}`;
816
+ const prefixed = nestedCode.startsWith("tn.") ? nestedCode : `tn.ir.runtime_error: ${node.typeName} -> ${nestedCode}`;
817
+ __tnRaiseIrError(
818
+ prefixed,
819
+ `Nested validator ${node.typeName} failed`
820
+ );
821
+ }
822
+ if (nestedResult.consumed !== void 0) {
823
+ return nestedResult.consumed;
824
+ }
825
+ }
826
+ return __tnInvokeFootprint(node.typeName, nestedParams);
827
+ }
828
+ case "sumOverArray": {
829
+ if (!ctx.buffer) {
830
+ __tnRaiseIrError(
831
+ "tn.ir.missing_buffer",
832
+ `Jagged array '${node.fieldName}' requires buffer-backed validation`
833
+ );
834
+ }
835
+ const count = __tnBigIntToNumber(
836
+ __tnEvalIrNode(node.count, ctx, baseOffset),
837
+ `Jagged array '${node.fieldName}' count`
838
+ );
839
+ let cursor = __tnBigIntToNumber(baseOffset, "IR jagged array offset");
840
+ let total = __tnToBigInt(0);
841
+ for (let i = 0; i < count; i++) {
842
+ const result = __tnInvokeDynamicValidate(
843
+ node.elementTypeName,
844
+ ctx.buffer.subarray(cursor)
845
+ );
846
+ if (!result.ok || result.consumed === void 0) {
847
+ const code = result.code ?? "tn.ir.runtime_error";
848
+ __tnRaiseIrError(
849
+ code,
850
+ `Jagged array '${node.fieldName}' element ${i} failed validation`
851
+ );
852
+ }
853
+ cursor += __tnBigIntToNumber(result.consumed, "IR jagged element size");
854
+ total = __tnCheckedAdd(total, result.consumed);
855
+ }
856
+ return total;
857
+ }
858
+ default:
859
+ __tnRaiseIrError(
860
+ "tn.ir.runtime_error",
861
+ `Unsupported IR node ${node.op}`
862
+ );
863
+ }
864
+ }
865
+ function __tnNormalizeIrError(err) {
866
+ if (err && typeof err === "object" && "code" in err) {
867
+ const maybeCode = err.code;
868
+ if (typeof maybeCode === "string" && maybeCode.length > 0) {
869
+ return maybeCode;
870
+ }
871
+ }
872
+ const message = err && typeof err === "object" && "message" in err ? String(err.message ?? "") : typeof err === "string" ? err : "";
873
+ if (message.includes("Missing IR parameter")) return "tn.ir.missing_param";
874
+ if (message.includes("Unhandled IR switch value")) return "tn.ir.invalid_tag";
875
+ if (message.includes("invalid") || message.includes("overflow") || message.includes("negative size")) {
876
+ return "tn.ir.overflow";
877
+ }
878
+ if (message.length > 0) return `tn.ir.runtime_error: ${message}`;
879
+ return "tn.ir.runtime_error";
880
+ }
881
+ var __tn_ir_CallArgs = {
882
+ typeName: "CallArgs",
883
+ root: { op: "const", value: 8n }
884
+ };
885
+ var CallArgs = class _CallArgs {
886
+ constructor(buffer) {
887
+ this.buffer = buffer;
888
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
889
+ }
890
+ static __tnCreateView(buffer, opts) {
891
+ if (!buffer || buffer.length === void 0) throw new Error("CallArgs.__tnCreateView requires a Uint8Array");
892
+ return new _CallArgs(new Uint8Array(buffer));
893
+ }
894
+ static builder() {
895
+ return new CallArgsBuilder();
896
+ }
897
+ static fromBuilder(builder) {
898
+ const buffer = builder.build();
899
+ return _CallArgs.from_array(buffer);
900
+ }
901
+ get_policy_account_idx() {
902
+ const offset = 0;
903
+ return this.view.getUint16(offset, true);
904
+ }
905
+ set_policy_account_idx(value) {
906
+ const offset = 0;
907
+ this.view.setUint16(offset, value, true);
908
+ }
909
+ get policy_account_idx() {
910
+ return this.get_policy_account_idx();
911
+ }
912
+ set policy_account_idx(value) {
913
+ this.set_policy_account_idx(value);
914
+ }
915
+ get_target_account_idx() {
916
+ const offset = 2;
917
+ return this.view.getUint16(offset, true);
918
+ }
919
+ set_target_account_idx(value) {
920
+ const offset = 2;
921
+ this.view.setUint16(offset, value, true);
922
+ }
923
+ get target_account_idx() {
924
+ return this.get_target_account_idx();
925
+ }
926
+ set target_account_idx(value) {
927
+ this.set_target_account_idx(value);
928
+ }
929
+ get_authority_account_idx() {
930
+ const offset = 4;
931
+ return this.view.getUint16(offset, true);
932
+ }
933
+ set_authority_account_idx(value) {
934
+ const offset = 4;
935
+ this.view.setUint16(offset, value, true);
936
+ }
937
+ get authority_account_idx() {
938
+ return this.get_authority_account_idx();
939
+ }
940
+ set authority_account_idx(value) {
941
+ this.set_authority_account_idx(value);
942
+ }
943
+ get_inner_sz() {
944
+ const offset = 6;
945
+ return this.view.getUint16(offset, true);
946
+ }
947
+ set_inner_sz(value) {
948
+ const offset = 6;
949
+ this.view.setUint16(offset, value, true);
950
+ }
951
+ get inner_sz() {
952
+ return this.get_inner_sz();
953
+ }
954
+ set inner_sz(value) {
955
+ this.set_inner_sz(value);
956
+ }
957
+ static __tnFootprintInternal(__tnParams) {
958
+ return __tnEvalFootprint(__tn_ir_CallArgs.root, { params: __tnParams });
959
+ }
960
+ static __tnValidateInternal(buffer, __tnParams) {
961
+ return __tnValidateIrTree(__tn_ir_CallArgs, buffer, __tnParams);
962
+ }
963
+ static __tnInvokeFootprint(__tnParams) {
964
+ return this.__tnFootprintInternal(__tnParams);
965
+ }
966
+ static __tnInvokeValidate(buffer, __tnParams) {
967
+ return this.__tnValidateInternal(buffer, __tnParams);
968
+ }
969
+ static footprintIr() {
970
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
971
+ }
972
+ static footprint() {
973
+ const irResult = this.footprintIr();
974
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
975
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
976
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CallArgs");
977
+ }
978
+ return __tnBigIntToNumber(irResult, "CallArgs::footprint");
979
+ }
980
+ static validate(buffer, _opts) {
981
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
982
+ return { ok: true, consumed: 8 };
983
+ }
984
+ static new(policy_account_idx, target_account_idx, authority_account_idx, inner_sz) {
985
+ const buffer = new Uint8Array(8);
986
+ const view = new DataView(buffer.buffer);
987
+ view.setUint16(0, policy_account_idx, true);
988
+ view.setUint16(2, target_account_idx, true);
989
+ view.setUint16(4, authority_account_idx, true);
990
+ view.setUint16(6, inner_sz, true);
991
+ return new _CallArgs(buffer);
992
+ }
993
+ static from_array(buffer) {
994
+ if (!buffer || buffer.length === void 0) {
995
+ return null;
996
+ }
997
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
998
+ const validation = this.validate(buffer);
999
+ if (!validation.ok) {
1000
+ return null;
1001
+ }
1002
+ return new _CallArgs(buffer);
1003
+ }
1004
+ };
1005
+ var CallArgsBuilder = class {
1006
+ constructor() {
1007
+ this.buffer = new Uint8Array(8);
1008
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1009
+ }
1010
+ set_policy_account_idx(value) {
1011
+ this.view.setUint16(0, value, true);
1012
+ return this;
1013
+ }
1014
+ set_target_account_idx(value) {
1015
+ this.view.setUint16(2, value, true);
1016
+ return this;
1017
+ }
1018
+ set_authority_account_idx(value) {
1019
+ this.view.setUint16(4, value, true);
1020
+ return this;
1021
+ }
1022
+ set_inner_sz(value) {
1023
+ this.view.setUint16(6, value, true);
1024
+ return this;
1025
+ }
1026
+ build() {
1027
+ return this.buffer.slice();
1028
+ }
1029
+ buildInto(target, offset = 0) {
1030
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1031
+ target.set(this.buffer, offset);
1032
+ return target;
1033
+ }
1034
+ finish() {
1035
+ const view = CallArgs.from_array(this.buffer.slice());
1036
+ if (!view) throw new Error("failed to build CallArgs");
1037
+ return view;
1038
+ }
1039
+ };
1040
+ __tnRegisterFootprint("CallArgs", (params) => CallArgs.__tnInvokeFootprint(params));
1041
+ __tnRegisterValidate("CallArgs", (buffer, params) => CallArgs.__tnInvokeValidate(buffer, params));
1042
+ __tnRegisterDynamicValidate("CallArgs", (buffer) => {
1043
+ const result = CallArgs.validate(buffer);
1044
+ const params = result.params;
1045
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1046
+ });
1047
+ var __tn_ir_CreateAuthorityArgs = {
1048
+ typeName: "CreateAuthorityArgs",
1049
+ root: { op: "align", alignment: 1, node: { 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: 1, node: { op: "mul", left: { op: "field", param: "proof.proof_sz" }, right: { op: "const", value: 1n } } } } }
1050
+ };
1051
+ var _CreateAuthorityArgs = class _CreateAuthorityArgs {
1052
+ constructor(buffer, params, fieldContext) {
1053
+ this.buffer = buffer;
1054
+ this.__tnFieldContext = null;
1055
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1056
+ this.__tnFieldContext = fieldContext ?? null;
1057
+ if (params) {
1058
+ this.__tnParams = params;
1059
+ } else {
1060
+ const derived = _CreateAuthorityArgs.__tnExtractParams(this.view, buffer);
1061
+ if (!derived) {
1062
+ throw new Error("CreateAuthorityArgs: failed to derive dynamic parameters");
1063
+ }
1064
+ this.__tnParams = derived.params;
1065
+ }
1066
+ }
1067
+ static __tnCreateView(buffer, opts) {
1068
+ if (!buffer || buffer.length === void 0) throw new Error("CreateAuthorityArgs.__tnCreateView requires a Uint8Array");
1069
+ let params = opts?.params ?? null;
1070
+ if (!params) {
1071
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1072
+ const derived = _CreateAuthorityArgs.__tnExtractParams(view, buffer);
1073
+ if (!derived) throw new Error("CreateAuthorityArgs.__tnCreateView: failed to derive params");
1074
+ params = derived.params;
1075
+ }
1076
+ const instance = new _CreateAuthorityArgs(new Uint8Array(buffer), params, opts?.fieldContext);
1077
+ return instance;
1078
+ }
1079
+ dynamicParams() {
1080
+ return this.__tnParams;
1081
+ }
1082
+ withFieldContext(context) {
1083
+ this.__tnFieldContext = context;
1084
+ return this;
1085
+ }
1086
+ __tnResolveFieldRef(path) {
1087
+ const getterName = `get_${path.replace(/[.]/g, "_")}`;
1088
+ const getter = this[getterName];
1089
+ if (typeof getter === "function") {
1090
+ const value = getter.call(this);
1091
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "CreateAuthorityArgs::__tnResolveFieldRef") : value;
1092
+ }
1093
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
1094
+ const contextValue = this.__tnFieldContext[path];
1095
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "CreateAuthorityArgs::__tnResolveFieldRef") : contextValue;
1096
+ }
1097
+ throw new Error("CreateAuthorityArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
1098
+ }
1099
+ static builder() {
1100
+ return new CreateAuthorityArgsBuilder();
1101
+ }
1102
+ static fromBuilder(builder) {
1103
+ const buffer = builder.build();
1104
+ const params = builder.dynamicParams();
1105
+ return _CreateAuthorityArgs.from_array(buffer, { params });
1106
+ }
1107
+ static __tnExtractParams(view, buffer) {
1108
+ if (buffer.length < 6) {
1109
+ return null;
1110
+ }
1111
+ const __tnParam_proof_proof_sz = __tnToBigInt(view.getUint16(4, true));
1112
+ const __tnExtractedParams = _CreateAuthorityArgs.Params.fromValues({
1113
+ proof_proof_sz: __tnParam_proof_proof_sz
1114
+ });
1115
+ return { params: __tnExtractedParams, derived: null };
1116
+ }
1117
+ get_policy_account_idx() {
1118
+ const offset = 0;
1119
+ return this.view.getUint16(offset, true);
1120
+ }
1121
+ set_policy_account_idx(value) {
1122
+ const offset = 0;
1123
+ this.view.setUint16(offset, value, true);
1124
+ }
1125
+ get policy_account_idx() {
1126
+ return this.get_policy_account_idx();
1127
+ }
1128
+ set policy_account_idx(value) {
1129
+ this.set_policy_account_idx(value);
1130
+ }
1131
+ get_authority_account_idx() {
1132
+ const offset = 2;
1133
+ return this.view.getUint16(offset, true);
1134
+ }
1135
+ set_authority_account_idx(value) {
1136
+ const offset = 2;
1137
+ this.view.setUint16(offset, value, true);
1138
+ }
1139
+ get authority_account_idx() {
1140
+ return this.get_authority_account_idx();
1141
+ }
1142
+ set authority_account_idx(value) {
1143
+ this.set_authority_account_idx(value);
1144
+ }
1145
+ get_proof_sz() {
1146
+ const offset = 4;
1147
+ return this.view.getUint16(offset, true);
1148
+ }
1149
+ set_proof_sz(value) {
1150
+ const offset = 4;
1151
+ this.view.setUint16(offset, value, true);
1152
+ }
1153
+ get proof_sz() {
1154
+ return this.get_proof_sz();
1155
+ }
1156
+ set proof_sz(value) {
1157
+ this.set_proof_sz(value);
1158
+ }
1159
+ get_proof_length() {
1160
+ return this.__tnResolveFieldRef("proof_sz");
1161
+ }
1162
+ get_proof_at(index) {
1163
+ const offset = 6;
1164
+ return this.view.getUint8(offset + index * 1);
1165
+ }
1166
+ get_proof() {
1167
+ const len = this.get_proof_length();
1168
+ const result = [];
1169
+ for (let i = 0; i < len; i++) {
1170
+ result.push(this.get_proof_at(i));
1171
+ }
1172
+ return result;
1173
+ }
1174
+ set_proof_at(index, value) {
1175
+ const offset = 6;
1176
+ this.view.setUint8(offset + index * 1, value);
1177
+ }
1178
+ set_proof(value) {
1179
+ const len = Math.min(this.get_proof_length(), value.length);
1180
+ for (let i = 0; i < len; i++) {
1181
+ this.set_proof_at(i, value[i]);
1182
+ }
1183
+ }
1184
+ get proof() {
1185
+ return this.get_proof();
1186
+ }
1187
+ set proof(value) {
1188
+ this.set_proof(value);
1189
+ }
1190
+ static __tnFootprintInternal(__tnParams) {
1191
+ return __tnEvalFootprint(__tn_ir_CreateAuthorityArgs.root, { params: __tnParams });
1192
+ }
1193
+ static __tnValidateInternal(buffer, __tnParams) {
1194
+ return __tnValidateIrTree(__tn_ir_CreateAuthorityArgs, buffer, __tnParams);
1195
+ }
1196
+ static __tnInvokeFootprint(__tnParams) {
1197
+ return this.__tnFootprintInternal(__tnParams);
1198
+ }
1199
+ static __tnInvokeValidate(buffer, __tnParams) {
1200
+ return this.__tnValidateInternal(buffer, __tnParams);
1201
+ }
1202
+ static footprintIr(proof_proof_sz) {
1203
+ const params = _CreateAuthorityArgs.Params.fromValues({
1204
+ proof_proof_sz
1205
+ });
1206
+ return this.footprintIrFromParams(params);
1207
+ }
1208
+ static __tnPackParams(params) {
1209
+ const record = /* @__PURE__ */ Object.create(null);
1210
+ record["proof.proof_sz"] = params.proof_proof_sz;
1211
+ return record;
1212
+ }
1213
+ static footprintIrFromParams(params) {
1214
+ const __tnParams = this.__tnPackParams(params);
1215
+ return this.__tnFootprintInternal(__tnParams);
1216
+ }
1217
+ static footprintFromParams(params) {
1218
+ const irResult = this.footprintIrFromParams(params);
1219
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1220
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CreateAuthorityArgs");
1221
+ return __tnBigIntToNumber(irResult, "CreateAuthorityArgs::footprintFromParams");
1222
+ }
1223
+ static footprintFromValues(input) {
1224
+ const params = _CreateAuthorityArgs.params(input);
1225
+ return this.footprintFromParams(params);
1226
+ }
1227
+ static footprint(params) {
1228
+ return this.footprintFromParams(params);
1229
+ }
1230
+ static validate(buffer, opts) {
1231
+ if (!buffer || buffer.length === void 0) {
1232
+ return { ok: false, code: "tn.invalid_buffer" };
1233
+ }
1234
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1235
+ let params = opts?.params ?? null;
1236
+ if (!params) {
1237
+ const extracted = this.__tnExtractParams(view, buffer);
1238
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
1239
+ params = extracted.params;
1240
+ }
1241
+ const __tnParamsRec = this.__tnPackParams(params);
1242
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
1243
+ if (!irResult.ok) {
1244
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "CreateAuthorityArgs::validate") : void 0, params };
1245
+ }
1246
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "CreateAuthorityArgs::validate") : void 0;
1247
+ return { ok: true, consumed, params };
1248
+ }
1249
+ static from_array(buffer, opts) {
1250
+ if (!buffer || buffer.length === void 0) {
1251
+ return null;
1252
+ }
1253
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1254
+ let params = opts?.params ?? null;
1255
+ if (!params) {
1256
+ const derived = this.__tnExtractParams(view, buffer);
1257
+ if (!derived) return null;
1258
+ params = derived.params;
1259
+ }
1260
+ const validation = this.validate(buffer, { params });
1261
+ if (!validation.ok) {
1262
+ return null;
1263
+ }
1264
+ const cached = validation.params ?? params;
1265
+ const state = new _CreateAuthorityArgs(buffer, cached);
1266
+ return state;
1267
+ }
1268
+ };
1269
+ _CreateAuthorityArgs.flexibleArrayWriters = Object.freeze([
1270
+ { field: "proof", method: "proof", sizeField: "proof_sz", paramKey: "proof_sz", elementSize: 1 }
1271
+ ]);
1272
+ var CreateAuthorityArgs = _CreateAuthorityArgs;
1273
+ ((CreateAuthorityArgs2) => {
1274
+ CreateAuthorityArgs2.ParamKeys = Object.freeze({
1275
+ proof_proof_sz: "proof.proof_sz"
1276
+ });
1277
+ CreateAuthorityArgs2.Params = {
1278
+ fromValues(input) {
1279
+ return {
1280
+ proof_proof_sz: __tnToBigInt(input.proof_proof_sz)
1281
+ };
1282
+ },
1283
+ fromBuilder(source) {
1284
+ if (source.dynamicParams) {
1285
+ return source.dynamicParams();
1286
+ }
1287
+ if (source.params) {
1288
+ return source.params;
1289
+ }
1290
+ return source;
1291
+ }
1292
+ };
1293
+ function params(input) {
1294
+ return CreateAuthorityArgs2.Params.fromValues(input);
1295
+ }
1296
+ CreateAuthorityArgs2.params = params;
1297
+ })(CreateAuthorityArgs || (CreateAuthorityArgs = {}));
1298
+ var CreateAuthorityArgsBuilder = class {
1299
+ constructor() {
1300
+ this.__tnCachedParams = null;
1301
+ this.__tnLastBuffer = null;
1302
+ this.__tnLastParams = null;
1303
+ this.__tnFam_proof = null;
1304
+ this.__tnFam_proofCount = null;
1305
+ this.buffer = new Uint8Array(6);
1306
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1307
+ }
1308
+ __tnInvalidate() {
1309
+ this.__tnCachedParams = null;
1310
+ this.__tnLastBuffer = null;
1311
+ this.__tnLastParams = null;
1312
+ }
1313
+ set_policy_account_idx(value) {
1314
+ this.view.setUint16(0, value, true);
1315
+ this.__tnInvalidate();
1316
+ return this;
1317
+ }
1318
+ set_authority_account_idx(value) {
1319
+ this.view.setUint16(2, value, true);
1320
+ this.__tnInvalidate();
1321
+ return this;
1322
+ }
1323
+ set_proof_sz(value) {
1324
+ this.view.setUint16(4, value, true);
1325
+ this.__tnInvalidate();
1326
+ return this;
1327
+ }
1328
+ proof() {
1329
+ if (!this.__tnFamWriter_proof) {
1330
+ this.__tnFamWriter_proof = __tnCreateFamWriter(this, "proof", (payload) => {
1331
+ const bytes2 = new Uint8Array(payload);
1332
+ const elementCount = bytes2.length;
1333
+ this.__tnFam_proof = bytes2;
1334
+ this.__tnFam_proofCount = elementCount;
1335
+ this.set_proof_sz(elementCount);
1336
+ this.__tnInvalidate();
1337
+ });
1338
+ }
1339
+ return this.__tnFamWriter_proof;
1340
+ }
1341
+ build() {
1342
+ const params = this.__tnComputeParams();
1343
+ const size = CreateAuthorityArgs.footprintFromParams(params);
1344
+ const buffer = new Uint8Array(size);
1345
+ this.__tnWriteInto(buffer);
1346
+ this.__tnValidateOrThrow(buffer, params);
1347
+ return buffer;
1348
+ }
1349
+ buildInto(target, offset = 0) {
1350
+ const params = this.__tnComputeParams();
1351
+ const size = CreateAuthorityArgs.footprintFromParams(params);
1352
+ if (target.length - offset < size) throw new Error("CreateAuthorityArgsBuilder: target buffer too small");
1353
+ const slice = target.subarray(offset, offset + size);
1354
+ this.__tnWriteInto(slice);
1355
+ this.__tnValidateOrThrow(slice, params);
1356
+ return target;
1357
+ }
1358
+ finish() {
1359
+ const buffer = this.build();
1360
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
1361
+ const view = CreateAuthorityArgs.from_array(buffer, { params });
1362
+ if (!view) throw new Error("CreateAuthorityArgsBuilder: failed to finalize view");
1363
+ return view;
1364
+ }
1365
+ finishView() {
1366
+ return this.finish();
1367
+ }
1368
+ dynamicParams() {
1369
+ return this.__tnComputeParams();
1370
+ }
1371
+ __tnComputeParams() {
1372
+ if (this.__tnCachedParams) return this.__tnCachedParams;
1373
+ const params = CreateAuthorityArgs.Params.fromValues({
1374
+ proof_proof_sz: (() => {
1375
+ if (this.__tnFam_proofCount === null) throw new Error("CreateAuthorityArgsBuilder: field 'proof' must be written before computing params");
1376
+ return __tnToBigInt(this.__tnFam_proofCount);
1377
+ })()
1378
+ });
1379
+ this.__tnCachedParams = params;
1380
+ return params;
1381
+ }
1382
+ __tnWriteInto(target) {
1383
+ target.set(this.buffer, 0);
1384
+ let cursor = this.buffer.length;
1385
+ const __tnLocal_proof_bytes = this.__tnFam_proof;
1386
+ if (!__tnLocal_proof_bytes) throw new Error("CreateAuthorityArgsBuilder: field 'proof' must be written before build");
1387
+ target.set(__tnLocal_proof_bytes, cursor);
1388
+ cursor += __tnLocal_proof_bytes.length;
1389
+ }
1390
+ __tnValidateOrThrow(buffer, params) {
1391
+ const result = CreateAuthorityArgs.validate(buffer, { params });
1392
+ if (!result.ok) {
1393
+ throw new Error(`${CreateAuthorityArgs}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
1394
+ }
1395
+ this.__tnLastParams = result.params ?? params;
1396
+ this.__tnLastBuffer = buffer;
1397
+ }
1398
+ };
1399
+ __tnRegisterFootprint("CreateAuthorityArgs", (params) => CreateAuthorityArgs.__tnInvokeFootprint(params));
1400
+ __tnRegisterValidate("CreateAuthorityArgs", (buffer, params) => CreateAuthorityArgs.__tnInvokeValidate(buffer, params));
1401
+ __tnRegisterDynamicValidate("CreateAuthorityArgs", (buffer) => {
1402
+ const result = CreateAuthorityArgs.validate(buffer);
1403
+ const params = result.params;
1404
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1405
+ });
1406
+ var __tn_ir_Pubkey = {
1407
+ typeName: "Pubkey",
1408
+ root: { op: "const", value: 32n }
1409
+ };
1410
+ var Pubkey2 = class _Pubkey {
1411
+ constructor(buffer) {
1412
+ this.buffer = buffer;
1413
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1414
+ }
1415
+ static __tnCreateView(buffer, opts) {
1416
+ if (!buffer || buffer.length === void 0) throw new Error("Pubkey.__tnCreateView requires a Uint8Array");
1417
+ return new _Pubkey(new Uint8Array(buffer));
1418
+ }
1419
+ static builder() {
1420
+ return new PubkeyBuilder();
1421
+ }
1422
+ static fromBuilder(builder) {
1423
+ const buffer = builder.build();
1424
+ return _Pubkey.from_array(buffer);
1425
+ }
1426
+ get_bytes() {
1427
+ const offset = 0;
1428
+ const result = [];
1429
+ for (let i = 0; i < 32; i++) {
1430
+ result.push(this.view.getUint8(offset + i * 1));
1431
+ }
1432
+ return result;
1433
+ }
1434
+ set_bytes(value) {
1435
+ const offset = 0;
1436
+ if (value.length !== 32) {
1437
+ throw new Error("Array length must be 32");
1438
+ }
1439
+ for (let i = 0; i < 32; i++) {
1440
+ this.view.setUint8(offset + i * 1, value[i]);
1441
+ }
1442
+ }
1443
+ get bytes() {
1444
+ return this.get_bytes();
1445
+ }
1446
+ set bytes(value) {
1447
+ this.set_bytes(value);
1448
+ }
1449
+ static __tnFootprintInternal(__tnParams) {
1450
+ return __tnEvalFootprint(__tn_ir_Pubkey.root, { params: __tnParams });
1451
+ }
1452
+ static __tnValidateInternal(buffer, __tnParams) {
1453
+ return __tnValidateIrTree(__tn_ir_Pubkey, buffer, __tnParams);
1454
+ }
1455
+ static __tnInvokeFootprint(__tnParams) {
1456
+ return this.__tnFootprintInternal(__tnParams);
1457
+ }
1458
+ static __tnInvokeValidate(buffer, __tnParams) {
1459
+ return this.__tnValidateInternal(buffer, __tnParams);
1460
+ }
1461
+ static footprintIr() {
1462
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1463
+ }
1464
+ static footprint() {
1465
+ const irResult = this.footprintIr();
1466
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1467
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1468
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for Pubkey");
1469
+ }
1470
+ return __tnBigIntToNumber(irResult, "Pubkey::footprint");
1471
+ }
1472
+ static validate(buffer, _opts) {
1473
+ if (buffer.length < 32) return { ok: false, code: "tn.buffer_too_small", consumed: 32 };
1474
+ return { ok: true, consumed: 32 };
1475
+ }
1476
+ static from_array(buffer) {
1477
+ if (!buffer || buffer.length === void 0) {
1478
+ return null;
1479
+ }
1480
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1481
+ const validation = this.validate(buffer);
1482
+ if (!validation.ok) {
1483
+ return null;
1484
+ }
1485
+ return new _Pubkey(buffer);
1486
+ }
1487
+ };
1488
+ var PubkeyBuilder = class {
1489
+ constructor() {
1490
+ this.buffer = new Uint8Array(32);
1491
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1492
+ }
1493
+ set_bytes(values) {
1494
+ if (values.length !== 32) throw new Error("bytes expects 32 elements");
1495
+ for (let i = 0; i < values.length; i++) {
1496
+ const byteOffset = 0 + i * 1;
1497
+ this.view.setUint8(byteOffset, values[i]);
1498
+ }
1499
+ return this;
1500
+ }
1501
+ build() {
1502
+ return this.buffer.slice();
1503
+ }
1504
+ buildInto(target, offset = 0) {
1505
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1506
+ target.set(this.buffer, offset);
1507
+ return target;
1508
+ }
1509
+ finish() {
1510
+ const view = Pubkey2.from_array(this.buffer.slice());
1511
+ if (!view) throw new Error("failed to build Pubkey");
1512
+ return view;
1513
+ }
1514
+ };
1515
+ __tnRegisterFootprint("Pubkey", (params) => Pubkey2.__tnInvokeFootprint(params));
1516
+ __tnRegisterValidate("Pubkey", (buffer, params) => Pubkey2.__tnInvokeValidate(buffer, params));
1517
+ __tnRegisterDynamicValidate("Pubkey", (buffer) => {
1518
+ const result = Pubkey2.validate(buffer);
1519
+ const params = result.params;
1520
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1521
+ });
1522
+ var __tn_ir_RatelimitAuthority = {
1523
+ typeName: "RatelimitAuthority",
1524
+ root: { op: "const", value: 40n }
1525
+ };
1526
+ var RatelimitAuthority = class _RatelimitAuthority {
1527
+ constructor(buffer) {
1528
+ this.buffer = buffer;
1529
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1530
+ }
1531
+ static __tnCreateView(buffer, opts) {
1532
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitAuthority.__tnCreateView requires a Uint8Array");
1533
+ return new _RatelimitAuthority(new Uint8Array(buffer));
1534
+ }
1535
+ static builder() {
1536
+ return new RatelimitAuthorityBuilder();
1537
+ }
1538
+ static fromBuilder(builder) {
1539
+ const buffer = builder.build();
1540
+ return _RatelimitAuthority.from_array(buffer);
1541
+ }
1542
+ get_magic() {
1543
+ const offset = 0;
1544
+ return this.view.getBigUint64(offset, true);
1545
+ }
1546
+ set_magic(value) {
1547
+ const offset = 0;
1548
+ this.view.setBigUint64(offset, value, true);
1549
+ }
1550
+ get magic() {
1551
+ return this.get_magic();
1552
+ }
1553
+ set magic(value) {
1554
+ this.set_magic(value);
1555
+ }
1556
+ get_policy() {
1557
+ const offset = 8;
1558
+ const slice = this.buffer.subarray(offset, offset + 32);
1559
+ return Pubkey2.from_array(slice);
1560
+ }
1561
+ set_policy(value) {
1562
+ const sourceBytes = value.buffer;
1563
+ const offset = 8;
1564
+ this.buffer.set(sourceBytes, offset);
1565
+ }
1566
+ get policy() {
1567
+ return this.get_policy();
1568
+ }
1569
+ set policy(value) {
1570
+ this.set_policy(value);
1571
+ }
1572
+ static __tnFootprintInternal(__tnParams) {
1573
+ return __tnEvalFootprint(__tn_ir_RatelimitAuthority.root, { params: __tnParams });
1574
+ }
1575
+ static __tnValidateInternal(buffer, __tnParams) {
1576
+ return __tnValidateIrTree(__tn_ir_RatelimitAuthority, buffer, __tnParams);
1577
+ }
1578
+ static __tnInvokeFootprint(__tnParams) {
1579
+ return this.__tnFootprintInternal(__tnParams);
1580
+ }
1581
+ static __tnInvokeValidate(buffer, __tnParams) {
1582
+ return this.__tnValidateInternal(buffer, __tnParams);
1583
+ }
1584
+ static footprintIr() {
1585
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1586
+ }
1587
+ static footprint() {
1588
+ const irResult = this.footprintIr();
1589
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1590
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1591
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitAuthority");
1592
+ }
1593
+ return __tnBigIntToNumber(irResult, "RatelimitAuthority::footprint");
1594
+ }
1595
+ static validate(buffer, _opts) {
1596
+ if (buffer.length < 40) return { ok: false, code: "tn.buffer_too_small", consumed: 40 };
1597
+ return { ok: true, consumed: 40 };
1598
+ }
1599
+ static from_array(buffer) {
1600
+ if (!buffer || buffer.length === void 0) {
1601
+ return null;
1602
+ }
1603
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1604
+ const validation = this.validate(buffer);
1605
+ if (!validation.ok) {
1606
+ return null;
1607
+ }
1608
+ return new _RatelimitAuthority(buffer);
1609
+ }
1610
+ };
1611
+ var RatelimitAuthorityBuilder = class {
1612
+ constructor() {
1613
+ this.buffer = new Uint8Array(40);
1614
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1615
+ }
1616
+ set_magic(value) {
1617
+ const cast = __tnToBigInt(value);
1618
+ this.view.setBigUint64(0, cast, true);
1619
+ return this;
1620
+ }
1621
+ set_policy(value) {
1622
+ if (value.length !== 32) throw new Error("policy expects 32 bytes");
1623
+ this.buffer.set(value, 8);
1624
+ return this;
1625
+ }
1626
+ build() {
1627
+ return this.buffer.slice();
1628
+ }
1629
+ buildInto(target, offset = 0) {
1630
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1631
+ target.set(this.buffer, offset);
1632
+ return target;
1633
+ }
1634
+ finish() {
1635
+ const view = RatelimitAuthority.from_array(this.buffer.slice());
1636
+ if (!view) throw new Error("failed to build RatelimitAuthority");
1637
+ return view;
1638
+ }
1639
+ };
1640
+ __tnRegisterFootprint("RatelimitAuthority", (params) => RatelimitAuthority.__tnInvokeFootprint(params));
1641
+ __tnRegisterValidate("RatelimitAuthority", (buffer, params) => RatelimitAuthority.__tnInvokeValidate(buffer, params));
1642
+ __tnRegisterDynamicValidate("RatelimitAuthority", (buffer) => {
1643
+ const result = RatelimitAuthority.validate(buffer);
1644
+ const params = result.params;
1645
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1646
+ });
1647
+ var __tn_ir_RatelimitBucket = {
1648
+ typeName: "RatelimitBucket",
1649
+ root: { op: "const", value: 113n }
1650
+ };
1651
+ var RatelimitBucket = class _RatelimitBucket {
1652
+ constructor(buffer) {
1653
+ this.buffer = buffer;
1654
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1655
+ }
1656
+ static __tnCreateView(buffer, opts) {
1657
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitBucket.__tnCreateView requires a Uint8Array");
1658
+ return new _RatelimitBucket(new Uint8Array(buffer));
1659
+ }
1660
+ static builder() {
1661
+ return new RatelimitBucketBuilder();
1662
+ }
1663
+ static fromBuilder(builder) {
1664
+ const buffer = builder.build();
1665
+ return _RatelimitBucket.from_array(buffer);
1666
+ }
1667
+ get_magic() {
1668
+ const offset = 0;
1669
+ return this.view.getBigUint64(offset, true);
1670
+ }
1671
+ set_magic(value) {
1672
+ const offset = 0;
1673
+ this.view.setBigUint64(offset, value, true);
1674
+ }
1675
+ get magic() {
1676
+ return this.get_magic();
1677
+ }
1678
+ set magic(value) {
1679
+ this.set_magic(value);
1680
+ }
1681
+ get_policy() {
1682
+ const offset = 8;
1683
+ const slice = this.buffer.subarray(offset, offset + 32);
1684
+ return Pubkey2.from_array(slice);
1685
+ }
1686
+ set_policy(value) {
1687
+ const sourceBytes = value.buffer;
1688
+ const offset = 8;
1689
+ this.buffer.set(sourceBytes, offset);
1690
+ }
1691
+ get policy() {
1692
+ return this.get_policy();
1693
+ }
1694
+ set policy(value) {
1695
+ this.set_policy(value);
1696
+ }
1697
+ get_key() {
1698
+ const offset = 40;
1699
+ const slice = this.buffer.subarray(offset, offset + 32);
1700
+ return Pubkey2.from_array(slice);
1701
+ }
1702
+ set_key(value) {
1703
+ const sourceBytes = value.buffer;
1704
+ const offset = 40;
1705
+ this.buffer.set(sourceBytes, offset);
1706
+ }
1707
+ get key() {
1708
+ return this.get_key();
1709
+ }
1710
+ set key(value) {
1711
+ this.set_key(value);
1712
+ }
1713
+ get_rule_idx() {
1714
+ const offset = 72;
1715
+ return this.view.getUint8(offset);
1716
+ }
1717
+ set_rule_idx(value) {
1718
+ const offset = 72;
1719
+ this.view.setUint8(offset, value);
1720
+ }
1721
+ get rule_idx() {
1722
+ return this.get_rule_idx();
1723
+ }
1724
+ set rule_idx(value) {
1725
+ this.set_rule_idx(value);
1726
+ }
1727
+ get_window_start() {
1728
+ const offset = 73;
1729
+ return this.view.getBigUint64(offset, true);
1730
+ }
1731
+ set_window_start(value) {
1732
+ const offset = 73;
1733
+ this.view.setBigUint64(offset, value, true);
1734
+ }
1735
+ get window_start() {
1736
+ return this.get_window_start();
1737
+ }
1738
+ set window_start(value) {
1739
+ this.set_window_start(value);
1740
+ }
1741
+ get_calls() {
1742
+ const offset = 81;
1743
+ return this.view.getBigUint64(offset, true);
1744
+ }
1745
+ set_calls(value) {
1746
+ const offset = 81;
1747
+ this.view.setBigUint64(offset, value, true);
1748
+ }
1749
+ get calls() {
1750
+ return this.get_calls();
1751
+ }
1752
+ set calls(value) {
1753
+ this.set_calls(value);
1754
+ }
1755
+ get_amount() {
1756
+ const offset = 89;
1757
+ return this.view.getBigUint64(offset, true);
1758
+ }
1759
+ set_amount(value) {
1760
+ const offset = 89;
1761
+ this.view.setBigUint64(offset, value, true);
1762
+ }
1763
+ get amount() {
1764
+ return this.get_amount();
1765
+ }
1766
+ set amount(value) {
1767
+ this.set_amount(value);
1768
+ }
1769
+ get_total_calls() {
1770
+ const offset = 97;
1771
+ return this.view.getBigUint64(offset, true);
1772
+ }
1773
+ set_total_calls(value) {
1774
+ const offset = 97;
1775
+ this.view.setBigUint64(offset, value, true);
1776
+ }
1777
+ get total_calls() {
1778
+ return this.get_total_calls();
1779
+ }
1780
+ set total_calls(value) {
1781
+ this.set_total_calls(value);
1782
+ }
1783
+ get_total_amount() {
1784
+ const offset = 105;
1785
+ return this.view.getBigUint64(offset, true);
1786
+ }
1787
+ set_total_amount(value) {
1788
+ const offset = 105;
1789
+ this.view.setBigUint64(offset, value, true);
1790
+ }
1791
+ get total_amount() {
1792
+ return this.get_total_amount();
1793
+ }
1794
+ set total_amount(value) {
1795
+ this.set_total_amount(value);
1796
+ }
1797
+ static __tnFootprintInternal(__tnParams) {
1798
+ return __tnEvalFootprint(__tn_ir_RatelimitBucket.root, { params: __tnParams });
1799
+ }
1800
+ static __tnValidateInternal(buffer, __tnParams) {
1801
+ return __tnValidateIrTree(__tn_ir_RatelimitBucket, buffer, __tnParams);
1802
+ }
1803
+ static __tnInvokeFootprint(__tnParams) {
1804
+ return this.__tnFootprintInternal(__tnParams);
1805
+ }
1806
+ static __tnInvokeValidate(buffer, __tnParams) {
1807
+ return this.__tnValidateInternal(buffer, __tnParams);
1808
+ }
1809
+ static footprintIr() {
1810
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1811
+ }
1812
+ static footprint() {
1813
+ const irResult = this.footprintIr();
1814
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1815
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1816
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitBucket");
1817
+ }
1818
+ return __tnBigIntToNumber(irResult, "RatelimitBucket::footprint");
1819
+ }
1820
+ static validate(buffer, _opts) {
1821
+ if (buffer.length < 113) return { ok: false, code: "tn.buffer_too_small", consumed: 113 };
1822
+ return { ok: true, consumed: 113 };
1823
+ }
1824
+ static from_array(buffer) {
1825
+ if (!buffer || buffer.length === void 0) {
1826
+ return null;
1827
+ }
1828
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1829
+ const validation = this.validate(buffer);
1830
+ if (!validation.ok) {
1831
+ return null;
1832
+ }
1833
+ return new _RatelimitBucket(buffer);
1834
+ }
1835
+ };
1836
+ var RatelimitBucketBuilder = class {
1837
+ constructor() {
1838
+ this.buffer = new Uint8Array(113);
1839
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
1840
+ }
1841
+ set_magic(value) {
1842
+ const cast = __tnToBigInt(value);
1843
+ this.view.setBigUint64(0, cast, true);
1844
+ return this;
1845
+ }
1846
+ set_policy(value) {
1847
+ if (value.length !== 32) throw new Error("policy expects 32 bytes");
1848
+ this.buffer.set(value, 8);
1849
+ return this;
1850
+ }
1851
+ set_key(value) {
1852
+ if (value.length !== 32) throw new Error("key expects 32 bytes");
1853
+ this.buffer.set(value, 40);
1854
+ return this;
1855
+ }
1856
+ set_rule_idx(value) {
1857
+ this.view.setUint8(72, value);
1858
+ return this;
1859
+ }
1860
+ set_window_start(value) {
1861
+ const cast = __tnToBigInt(value);
1862
+ this.view.setBigUint64(73, cast, true);
1863
+ return this;
1864
+ }
1865
+ set_calls(value) {
1866
+ const cast = __tnToBigInt(value);
1867
+ this.view.setBigUint64(81, cast, true);
1868
+ return this;
1869
+ }
1870
+ set_amount(value) {
1871
+ const cast = __tnToBigInt(value);
1872
+ this.view.setBigUint64(89, cast, true);
1873
+ return this;
1874
+ }
1875
+ set_total_calls(value) {
1876
+ const cast = __tnToBigInt(value);
1877
+ this.view.setBigUint64(97, cast, true);
1878
+ return this;
1879
+ }
1880
+ set_total_amount(value) {
1881
+ const cast = __tnToBigInt(value);
1882
+ this.view.setBigUint64(105, cast, true);
1883
+ return this;
1884
+ }
1885
+ build() {
1886
+ return this.buffer.slice();
1887
+ }
1888
+ buildInto(target, offset = 0) {
1889
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
1890
+ target.set(this.buffer, offset);
1891
+ return target;
1892
+ }
1893
+ finish() {
1894
+ const view = RatelimitBucket.from_array(this.buffer.slice());
1895
+ if (!view) throw new Error("failed to build RatelimitBucket");
1896
+ return view;
1897
+ }
1898
+ };
1899
+ __tnRegisterFootprint("RatelimitBucket", (params) => RatelimitBucket.__tnInvokeFootprint(params));
1900
+ __tnRegisterValidate("RatelimitBucket", (buffer, params) => RatelimitBucket.__tnInvokeValidate(buffer, params));
1901
+ __tnRegisterDynamicValidate("RatelimitBucket", (buffer) => {
1902
+ const result = RatelimitBucket.validate(buffer);
1903
+ const params = result.params;
1904
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
1905
+ });
1906
+ var __tn_ir_RatelimitCallBucket = {
1907
+ typeName: "RatelimitCallBucket",
1908
+ root: { op: "const", value: 36n }
1909
+ };
1910
+ var RatelimitCallBucket = class _RatelimitCallBucket {
1911
+ constructor(buffer) {
1912
+ this.buffer = buffer;
1913
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1914
+ }
1915
+ static __tnCreateView(buffer, opts) {
1916
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitCallBucket.__tnCreateView requires a Uint8Array");
1917
+ return new _RatelimitCallBucket(new Uint8Array(buffer));
1918
+ }
1919
+ static builder() {
1920
+ return new RatelimitCallBucketBuilder();
1921
+ }
1922
+ static fromBuilder(builder) {
1923
+ const buffer = builder.build();
1924
+ return _RatelimitCallBucket.from_array(buffer);
1925
+ }
1926
+ get_bucket_account_idx() {
1927
+ const offset = 0;
1928
+ return this.view.getUint16(offset, true);
1929
+ }
1930
+ set_bucket_account_idx(value) {
1931
+ const offset = 0;
1932
+ this.view.setUint16(offset, value, true);
1933
+ }
1934
+ get bucket_account_idx() {
1935
+ return this.get_bucket_account_idx();
1936
+ }
1937
+ set bucket_account_idx(value) {
1938
+ this.set_bucket_account_idx(value);
1939
+ }
1940
+ get_proof_sz() {
1941
+ const offset = 2;
1942
+ return this.view.getUint16(offset, true);
1943
+ }
1944
+ set_proof_sz(value) {
1945
+ const offset = 2;
1946
+ this.view.setUint16(offset, value, true);
1947
+ }
1948
+ get proof_sz() {
1949
+ return this.get_proof_sz();
1950
+ }
1951
+ set proof_sz(value) {
1952
+ this.set_proof_sz(value);
1953
+ }
1954
+ get_key() {
1955
+ const offset = 4;
1956
+ const slice = this.buffer.subarray(offset, offset + 32);
1957
+ return Pubkey2.from_array(slice);
1958
+ }
1959
+ set_key(value) {
1960
+ const sourceBytes = value.buffer;
1961
+ const offset = 4;
1962
+ this.buffer.set(sourceBytes, offset);
1963
+ }
1964
+ get key() {
1965
+ return this.get_key();
1966
+ }
1967
+ set key(value) {
1968
+ this.set_key(value);
1969
+ }
1970
+ static __tnFootprintInternal(__tnParams) {
1971
+ return __tnEvalFootprint(__tn_ir_RatelimitCallBucket.root, { params: __tnParams });
1972
+ }
1973
+ static __tnValidateInternal(buffer, __tnParams) {
1974
+ return __tnValidateIrTree(__tn_ir_RatelimitCallBucket, buffer, __tnParams);
1975
+ }
1976
+ static __tnInvokeFootprint(__tnParams) {
1977
+ return this.__tnFootprintInternal(__tnParams);
1978
+ }
1979
+ static __tnInvokeValidate(buffer, __tnParams) {
1980
+ return this.__tnValidateInternal(buffer, __tnParams);
1981
+ }
1982
+ static footprintIr() {
1983
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
1984
+ }
1985
+ static footprint() {
1986
+ const irResult = this.footprintIr();
1987
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
1988
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
1989
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitCallBucket");
1990
+ }
1991
+ return __tnBigIntToNumber(irResult, "RatelimitCallBucket::footprint");
1992
+ }
1993
+ static validate(buffer, _opts) {
1994
+ if (buffer.length < 36) return { ok: false, code: "tn.buffer_too_small", consumed: 36 };
1995
+ return { ok: true, consumed: 36 };
1996
+ }
1997
+ static from_array(buffer) {
1998
+ if (!buffer || buffer.length === void 0) {
1999
+ return null;
2000
+ }
2001
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2002
+ const validation = this.validate(buffer);
2003
+ if (!validation.ok) {
2004
+ return null;
2005
+ }
2006
+ return new _RatelimitCallBucket(buffer);
2007
+ }
2008
+ };
2009
+ var RatelimitCallBucketBuilder = class {
2010
+ constructor() {
2011
+ this.buffer = new Uint8Array(36);
2012
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2013
+ }
2014
+ set_bucket_account_idx(value) {
2015
+ this.view.setUint16(0, value, true);
2016
+ return this;
2017
+ }
2018
+ set_proof_sz(value) {
2019
+ this.view.setUint16(2, value, true);
2020
+ return this;
2021
+ }
2022
+ set_key(value) {
2023
+ if (value.length !== 32) throw new Error("key expects 32 bytes");
2024
+ this.buffer.set(value, 4);
2025
+ return this;
2026
+ }
2027
+ build() {
2028
+ return this.buffer.slice();
2029
+ }
2030
+ buildInto(target, offset = 0) {
2031
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2032
+ target.set(this.buffer, offset);
2033
+ return target;
2034
+ }
2035
+ finish() {
2036
+ const view = RatelimitCallBucket.from_array(this.buffer.slice());
2037
+ if (!view) throw new Error("failed to build RatelimitCallBucket");
2038
+ return view;
2039
+ }
2040
+ };
2041
+ __tnRegisterFootprint("RatelimitCallBucket", (params) => RatelimitCallBucket.__tnInvokeFootprint(params));
2042
+ __tnRegisterValidate("RatelimitCallBucket", (buffer, params) => RatelimitCallBucket.__tnInvokeValidate(buffer, params));
2043
+ __tnRegisterDynamicValidate("RatelimitCallBucket", (buffer) => {
2044
+ const result = RatelimitCallBucket.validate(buffer);
2045
+ const params = result.params;
2046
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2047
+ });
2048
+ var __tn_ir_RatelimitCallEvent = {
2049
+ typeName: "RatelimitCallEvent",
2050
+ root: { op: "const", value: 136n }
2051
+ };
2052
+ var RatelimitCallEvent = class _RatelimitCallEvent {
2053
+ constructor(buffer) {
2054
+ this.buffer = buffer;
2055
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2056
+ }
2057
+ static __tnCreateView(buffer, opts) {
2058
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitCallEvent.__tnCreateView requires a Uint8Array");
2059
+ return new _RatelimitCallEvent(new Uint8Array(buffer));
2060
+ }
2061
+ static builder() {
2062
+ return new RatelimitCallEventBuilder();
2063
+ }
2064
+ static fromBuilder(builder) {
2065
+ const buffer = builder.build();
2066
+ return _RatelimitCallEvent.from_array(buffer);
2067
+ }
2068
+ get_policy() {
2069
+ const offset = 0;
2070
+ const slice = this.buffer.subarray(offset, offset + 32);
2071
+ return Pubkey2.from_array(slice);
2072
+ }
2073
+ set_policy(value) {
2074
+ const sourceBytes = value.buffer;
2075
+ const offset = 0;
2076
+ this.buffer.set(sourceBytes, offset);
2077
+ }
2078
+ get policy() {
2079
+ return this.get_policy();
2080
+ }
2081
+ set policy(value) {
2082
+ this.set_policy(value);
2083
+ }
2084
+ get_amount() {
2085
+ const offset = 32;
2086
+ return this.view.getBigUint64(offset, true);
2087
+ }
2088
+ set_amount(value) {
2089
+ const offset = 32;
2090
+ this.view.setBigUint64(offset, value, true);
2091
+ }
2092
+ get amount() {
2093
+ return this.get_amount();
2094
+ }
2095
+ set amount(value) {
2096
+ this.set_amount(value);
2097
+ }
2098
+ get_window_start() {
2099
+ const offset = 40;
2100
+ const result = [];
2101
+ for (let i = 0; i < 4; i++) {
2102
+ result.push(this.view.getBigUint64(offset + i * 8, true));
2103
+ }
2104
+ return result;
2105
+ }
2106
+ set_window_start(value) {
2107
+ const offset = 40;
2108
+ if (value.length !== 4) {
2109
+ throw new Error("Array length must be 4");
2110
+ }
2111
+ for (let i = 0; i < 4; i++) {
2112
+ this.view.setBigUint64(offset + i * 8, value[i], true);
2113
+ }
2114
+ }
2115
+ get window_start() {
2116
+ return this.get_window_start();
2117
+ }
2118
+ set window_start(value) {
2119
+ this.set_window_start(value);
2120
+ }
2121
+ get_calls() {
2122
+ const offset = 72;
2123
+ const result = [];
2124
+ for (let i = 0; i < 4; i++) {
2125
+ result.push(this.view.getBigUint64(offset + i * 8, true));
2126
+ }
2127
+ return result;
2128
+ }
2129
+ set_calls(value) {
2130
+ const offset = 72;
2131
+ if (value.length !== 4) {
2132
+ throw new Error("Array length must be 4");
2133
+ }
2134
+ for (let i = 0; i < 4; i++) {
2135
+ this.view.setBigUint64(offset + i * 8, value[i], true);
2136
+ }
2137
+ }
2138
+ get calls() {
2139
+ return this.get_calls();
2140
+ }
2141
+ set calls(value) {
2142
+ this.set_calls(value);
2143
+ }
2144
+ get_amounts() {
2145
+ const offset = 104;
2146
+ const result = [];
2147
+ for (let i = 0; i < 4; i++) {
2148
+ result.push(this.view.getBigUint64(offset + i * 8, true));
2149
+ }
2150
+ return result;
2151
+ }
2152
+ set_amounts(value) {
2153
+ const offset = 104;
2154
+ if (value.length !== 4) {
2155
+ throw new Error("Array length must be 4");
2156
+ }
2157
+ for (let i = 0; i < 4; i++) {
2158
+ this.view.setBigUint64(offset + i * 8, value[i], true);
2159
+ }
2160
+ }
2161
+ get amounts() {
2162
+ return this.get_amounts();
2163
+ }
2164
+ set amounts(value) {
2165
+ this.set_amounts(value);
2166
+ }
2167
+ static __tnFootprintInternal(__tnParams) {
2168
+ return __tnEvalFootprint(__tn_ir_RatelimitCallEvent.root, { params: __tnParams });
2169
+ }
2170
+ static __tnValidateInternal(buffer, __tnParams) {
2171
+ return __tnValidateIrTree(__tn_ir_RatelimitCallEvent, buffer, __tnParams);
2172
+ }
2173
+ static __tnInvokeFootprint(__tnParams) {
2174
+ return this.__tnFootprintInternal(__tnParams);
2175
+ }
2176
+ static __tnInvokeValidate(buffer, __tnParams) {
2177
+ return this.__tnValidateInternal(buffer, __tnParams);
2178
+ }
2179
+ static footprintIr() {
2180
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2181
+ }
2182
+ static footprint() {
2183
+ const irResult = this.footprintIr();
2184
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2185
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2186
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitCallEvent");
2187
+ }
2188
+ return __tnBigIntToNumber(irResult, "RatelimitCallEvent::footprint");
2189
+ }
2190
+ static validate(buffer, _opts) {
2191
+ if (buffer.length < 136) return { ok: false, code: "tn.buffer_too_small", consumed: 136 };
2192
+ return { ok: true, consumed: 136 };
2193
+ }
2194
+ static from_array(buffer) {
2195
+ if (!buffer || buffer.length === void 0) {
2196
+ return null;
2197
+ }
2198
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2199
+ const validation = this.validate(buffer);
2200
+ if (!validation.ok) {
2201
+ return null;
2202
+ }
2203
+ return new _RatelimitCallEvent(buffer);
2204
+ }
2205
+ };
2206
+ var RatelimitCallEventBuilder = class {
2207
+ constructor() {
2208
+ this.buffer = new Uint8Array(136);
2209
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2210
+ }
2211
+ set_policy(value) {
2212
+ if (value.length !== 32) throw new Error("policy expects 32 bytes");
2213
+ this.buffer.set(value, 0);
2214
+ return this;
2215
+ }
2216
+ set_amount(value) {
2217
+ const cast = __tnToBigInt(value);
2218
+ this.view.setBigUint64(32, cast, true);
2219
+ return this;
2220
+ }
2221
+ set_window_start(values) {
2222
+ if (values.length !== 4) throw new Error("window_start expects 4 elements");
2223
+ for (let i = 0; i < values.length; i++) {
2224
+ const byteOffset = 40 + i * 8;
2225
+ this.view.setBigUint64(byteOffset, values[i], true);
2226
+ }
2227
+ return this;
2228
+ }
2229
+ set_calls(values) {
2230
+ if (values.length !== 4) throw new Error("calls expects 4 elements");
2231
+ for (let i = 0; i < values.length; i++) {
2232
+ const byteOffset = 72 + i * 8;
2233
+ this.view.setBigUint64(byteOffset, values[i], true);
2234
+ }
2235
+ return this;
2236
+ }
2237
+ set_amounts(values) {
2238
+ if (values.length !== 4) throw new Error("amounts expects 4 elements");
2239
+ for (let i = 0; i < values.length; i++) {
2240
+ const byteOffset = 104 + i * 8;
2241
+ this.view.setBigUint64(byteOffset, values[i], true);
2242
+ }
2243
+ return this;
2244
+ }
2245
+ build() {
2246
+ return this.buffer.slice();
2247
+ }
2248
+ buildInto(target, offset = 0) {
2249
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2250
+ target.set(this.buffer, offset);
2251
+ return target;
2252
+ }
2253
+ finish() {
2254
+ const view = RatelimitCallEvent.from_array(this.buffer.slice());
2255
+ if (!view) throw new Error("failed to build RatelimitCallEvent");
2256
+ return view;
2257
+ }
2258
+ };
2259
+ __tnRegisterFootprint("RatelimitCallEvent", (params) => RatelimitCallEvent.__tnInvokeFootprint(params));
2260
+ __tnRegisterValidate("RatelimitCallEvent", (buffer, params) => RatelimitCallEvent.__tnInvokeValidate(buffer, params));
2261
+ __tnRegisterDynamicValidate("RatelimitCallEvent", (buffer) => {
2262
+ const result = RatelimitCallEvent.validate(buffer);
2263
+ const params = result.params;
2264
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2265
+ });
2266
+ var __tn_ir_RatelimitConstraint = {
2267
+ typeName: "RatelimitConstraint",
2268
+ root: { op: "const", value: 34n }
2269
+ };
2270
+ var RatelimitConstraint = class _RatelimitConstraint {
2271
+ constructor(buffer) {
2272
+ this.buffer = buffer;
2273
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2274
+ }
2275
+ static __tnCreateView(buffer, opts) {
2276
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitConstraint.__tnCreateView requires a Uint8Array");
2277
+ return new _RatelimitConstraint(new Uint8Array(buffer));
2278
+ }
2279
+ static builder() {
2280
+ return new RatelimitConstraintBuilder();
2281
+ }
2282
+ static fromBuilder(builder) {
2283
+ const buffer = builder.build();
2284
+ return _RatelimitConstraint.from_array(buffer);
2285
+ }
2286
+ get_idx_offset() {
2287
+ const offset = 0;
2288
+ return this.view.getUint16(offset, true);
2289
+ }
2290
+ set_idx_offset(value) {
2291
+ const offset = 0;
2292
+ this.view.setUint16(offset, value, true);
2293
+ }
2294
+ get idx_offset() {
2295
+ return this.get_idx_offset();
2296
+ }
2297
+ set idx_offset(value) {
2298
+ this.set_idx_offset(value);
2299
+ }
2300
+ get_expected() {
2301
+ const offset = 2;
2302
+ const slice = this.buffer.subarray(offset, offset + 32);
2303
+ return Pubkey2.from_array(slice);
2304
+ }
2305
+ set_expected(value) {
2306
+ const sourceBytes = value.buffer;
2307
+ const offset = 2;
2308
+ this.buffer.set(sourceBytes, offset);
2309
+ }
2310
+ get expected() {
2311
+ return this.get_expected();
2312
+ }
2313
+ set expected(value) {
2314
+ this.set_expected(value);
2315
+ }
2316
+ static __tnFootprintInternal(__tnParams) {
2317
+ return __tnEvalFootprint(__tn_ir_RatelimitConstraint.root, { params: __tnParams });
2318
+ }
2319
+ static __tnValidateInternal(buffer, __tnParams) {
2320
+ return __tnValidateIrTree(__tn_ir_RatelimitConstraint, buffer, __tnParams);
2321
+ }
2322
+ static __tnInvokeFootprint(__tnParams) {
2323
+ return this.__tnFootprintInternal(__tnParams);
2324
+ }
2325
+ static __tnInvokeValidate(buffer, __tnParams) {
2326
+ return this.__tnValidateInternal(buffer, __tnParams);
2327
+ }
2328
+ static footprintIr() {
2329
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2330
+ }
2331
+ static footprint() {
2332
+ const irResult = this.footprintIr();
2333
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2334
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2335
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitConstraint");
2336
+ }
2337
+ return __tnBigIntToNumber(irResult, "RatelimitConstraint::footprint");
2338
+ }
2339
+ static validate(buffer, _opts) {
2340
+ if (buffer.length < 34) return { ok: false, code: "tn.buffer_too_small", consumed: 34 };
2341
+ return { ok: true, consumed: 34 };
2342
+ }
2343
+ static from_array(buffer) {
2344
+ if (!buffer || buffer.length === void 0) {
2345
+ return null;
2346
+ }
2347
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2348
+ const validation = this.validate(buffer);
2349
+ if (!validation.ok) {
2350
+ return null;
2351
+ }
2352
+ return new _RatelimitConstraint(buffer);
2353
+ }
2354
+ };
2355
+ var RatelimitConstraintBuilder = class {
2356
+ constructor() {
2357
+ this.buffer = new Uint8Array(34);
2358
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2359
+ }
2360
+ set_idx_offset(value) {
2361
+ this.view.setUint16(0, value, true);
2362
+ return this;
2363
+ }
2364
+ set_expected(value) {
2365
+ if (value.length !== 32) throw new Error("expected expects 32 bytes");
2366
+ this.buffer.set(value, 2);
2367
+ return this;
2368
+ }
2369
+ build() {
2370
+ return this.buffer.slice();
2371
+ }
2372
+ buildInto(target, offset = 0) {
2373
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2374
+ target.set(this.buffer, offset);
2375
+ return target;
2376
+ }
2377
+ finish() {
2378
+ const view = RatelimitConstraint.from_array(this.buffer.slice());
2379
+ if (!view) throw new Error("failed to build RatelimitConstraint");
2380
+ return view;
2381
+ }
2382
+ };
2383
+ __tnRegisterFootprint("RatelimitConstraint", (params) => RatelimitConstraint.__tnInvokeFootprint(params));
2384
+ __tnRegisterValidate("RatelimitConstraint", (buffer, params) => RatelimitConstraint.__tnInvokeValidate(buffer, params));
2385
+ __tnRegisterDynamicValidate("RatelimitConstraint", (buffer) => {
2386
+ const result = RatelimitConstraint.validate(buffer);
2387
+ const params = result.params;
2388
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2389
+ });
2390
+ var __tn_ir_RatelimitError = {
2391
+ typeName: "RatelimitError",
2392
+ root: { op: "const", value: 8n }
2393
+ };
2394
+ var RatelimitError = class _RatelimitError {
2395
+ constructor(buffer) {
2396
+ this.buffer = buffer;
2397
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2398
+ }
2399
+ static __tnCreateView(buffer, opts) {
2400
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitError.__tnCreateView requires a Uint8Array");
2401
+ return new _RatelimitError(new Uint8Array(buffer));
2402
+ }
2403
+ static builder() {
2404
+ return new RatelimitErrorBuilder();
2405
+ }
2406
+ static fromBuilder(builder) {
2407
+ const buffer = builder.build();
2408
+ return _RatelimitError.from_array(buffer);
2409
+ }
2410
+ get_code() {
2411
+ const offset = 0;
2412
+ return this.view.getBigUint64(offset, true);
2413
+ }
2414
+ set_code(value) {
2415
+ const offset = 0;
2416
+ this.view.setBigUint64(offset, value, true);
2417
+ }
2418
+ get code() {
2419
+ return this.get_code();
2420
+ }
2421
+ set code(value) {
2422
+ this.set_code(value);
2423
+ }
2424
+ static __tnFootprintInternal(__tnParams) {
2425
+ return __tnEvalFootprint(__tn_ir_RatelimitError.root, { params: __tnParams });
2426
+ }
2427
+ static __tnValidateInternal(buffer, __tnParams) {
2428
+ return __tnValidateIrTree(__tn_ir_RatelimitError, buffer, __tnParams);
2429
+ }
2430
+ static __tnInvokeFootprint(__tnParams) {
2431
+ return this.__tnFootprintInternal(__tnParams);
2432
+ }
2433
+ static __tnInvokeValidate(buffer, __tnParams) {
2434
+ return this.__tnValidateInternal(buffer, __tnParams);
2435
+ }
2436
+ static footprintIr() {
2437
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2438
+ }
2439
+ static footprint() {
2440
+ const irResult = this.footprintIr();
2441
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2442
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2443
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitError");
2444
+ }
2445
+ return __tnBigIntToNumber(irResult, "RatelimitError::footprint");
2446
+ }
2447
+ static validate(buffer, _opts) {
2448
+ if (buffer.length < 8) return { ok: false, code: "tn.buffer_too_small", consumed: 8 };
2449
+ return { ok: true, consumed: 8 };
2450
+ }
2451
+ static new(code) {
2452
+ const buffer = new Uint8Array(8);
2453
+ const view = new DataView(buffer.buffer);
2454
+ view.setBigUint64(0, code, true);
2455
+ return new _RatelimitError(buffer);
2456
+ }
2457
+ static from_array(buffer) {
2458
+ if (!buffer || buffer.length === void 0) {
2459
+ return null;
2460
+ }
2461
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2462
+ const validation = this.validate(buffer);
2463
+ if (!validation.ok) {
2464
+ return null;
2465
+ }
2466
+ return new _RatelimitError(buffer);
2467
+ }
2468
+ };
2469
+ var RatelimitErrorBuilder = class {
2470
+ constructor() {
2471
+ this.buffer = new Uint8Array(8);
2472
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2473
+ }
2474
+ set_code(value) {
2475
+ const cast = __tnToBigInt(value);
2476
+ this.view.setBigUint64(0, cast, true);
2477
+ return this;
2478
+ }
2479
+ build() {
2480
+ return this.buffer.slice();
2481
+ }
2482
+ buildInto(target, offset = 0) {
2483
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2484
+ target.set(this.buffer, offset);
2485
+ return target;
2486
+ }
2487
+ finish() {
2488
+ const view = RatelimitError.from_array(this.buffer.slice());
2489
+ if (!view) throw new Error("failed to build RatelimitError");
2490
+ return view;
2491
+ }
2492
+ };
2493
+ __tnRegisterFootprint("RatelimitError", (params) => RatelimitError.__tnInvokeFootprint(params));
2494
+ __tnRegisterValidate("RatelimitError", (buffer, params) => RatelimitError.__tnInvokeValidate(buffer, params));
2495
+ __tnRegisterDynamicValidate("RatelimitError", (buffer) => {
2496
+ const result = RatelimitError.validate(buffer);
2497
+ const params = result.params;
2498
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2499
+ });
2500
+ var __tn_ir_RatelimitRule = {
2501
+ typeName: "RatelimitRule",
2502
+ root: { op: "const", value: 28n }
2503
+ };
2504
+ var RatelimitRule = class _RatelimitRule {
2505
+ constructor(buffer) {
2506
+ this.buffer = buffer;
2507
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2508
+ }
2509
+ static __tnCreateView(buffer, opts) {
2510
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitRule.__tnCreateView requires a Uint8Array");
2511
+ return new _RatelimitRule(new Uint8Array(buffer));
2512
+ }
2513
+ static builder() {
2514
+ return new RatelimitRuleBuilder();
2515
+ }
2516
+ static fromBuilder(builder) {
2517
+ const buffer = builder.build();
2518
+ return _RatelimitRule.from_array(buffer);
2519
+ }
2520
+ get_key_kind() {
2521
+ const offset = 0;
2522
+ return this.view.getUint8(offset);
2523
+ }
2524
+ set_key_kind(value) {
2525
+ const offset = 0;
2526
+ this.view.setUint8(offset, value);
2527
+ }
2528
+ get key_kind() {
2529
+ return this.get_key_kind();
2530
+ }
2531
+ set key_kind(value) {
2532
+ this.set_key_kind(value);
2533
+ }
2534
+ get_clock() {
2535
+ const offset = 1;
2536
+ return this.view.getUint8(offset);
2537
+ }
2538
+ set_clock(value) {
2539
+ const offset = 1;
2540
+ this.view.setUint8(offset, value);
2541
+ }
2542
+ get clock() {
2543
+ return this.get_clock();
2544
+ }
2545
+ set clock(value) {
2546
+ this.set_clock(value);
2547
+ }
2548
+ get_key_offset() {
2549
+ const offset = 2;
2550
+ return this.view.getUint16(offset, true);
2551
+ }
2552
+ set_key_offset(value) {
2553
+ const offset = 2;
2554
+ this.view.setUint16(offset, value, true);
2555
+ }
2556
+ get key_offset() {
2557
+ return this.get_key_offset();
2558
+ }
2559
+ set key_offset(value) {
2560
+ this.set_key_offset(value);
2561
+ }
2562
+ get_window() {
2563
+ const offset = 4;
2564
+ return this.view.getBigUint64(offset, true);
2565
+ }
2566
+ set_window(value) {
2567
+ const offset = 4;
2568
+ this.view.setBigUint64(offset, value, true);
2569
+ }
2570
+ get window() {
2571
+ return this.get_window();
2572
+ }
2573
+ set window(value) {
2574
+ this.set_window(value);
2575
+ }
2576
+ get_max_calls() {
2577
+ const offset = 12;
2578
+ return this.view.getBigUint64(offset, true);
2579
+ }
2580
+ set_max_calls(value) {
2581
+ const offset = 12;
2582
+ this.view.setBigUint64(offset, value, true);
2583
+ }
2584
+ get max_calls() {
2585
+ return this.get_max_calls();
2586
+ }
2587
+ set max_calls(value) {
2588
+ this.set_max_calls(value);
2589
+ }
2590
+ get_max_amount() {
2591
+ const offset = 20;
2592
+ return this.view.getBigUint64(offset, true);
2593
+ }
2594
+ set_max_amount(value) {
2595
+ const offset = 20;
2596
+ this.view.setBigUint64(offset, value, true);
2597
+ }
2598
+ get max_amount() {
2599
+ return this.get_max_amount();
2600
+ }
2601
+ set max_amount(value) {
2602
+ this.set_max_amount(value);
2603
+ }
2604
+ static __tnFootprintInternal(__tnParams) {
2605
+ return __tnEvalFootprint(__tn_ir_RatelimitRule.root, { params: __tnParams });
2606
+ }
2607
+ static __tnValidateInternal(buffer, __tnParams) {
2608
+ return __tnValidateIrTree(__tn_ir_RatelimitRule, buffer, __tnParams);
2609
+ }
2610
+ static __tnInvokeFootprint(__tnParams) {
2611
+ return this.__tnFootprintInternal(__tnParams);
2612
+ }
2613
+ static __tnInvokeValidate(buffer, __tnParams) {
2614
+ return this.__tnValidateInternal(buffer, __tnParams);
2615
+ }
2616
+ static footprintIr() {
2617
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2618
+ }
2619
+ static footprint() {
2620
+ const irResult = this.footprintIr();
2621
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2622
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2623
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitRule");
2624
+ }
2625
+ return __tnBigIntToNumber(irResult, "RatelimitRule::footprint");
2626
+ }
2627
+ static validate(buffer, _opts) {
2628
+ if (buffer.length < 28) return { ok: false, code: "tn.buffer_too_small", consumed: 28 };
2629
+ return { ok: true, consumed: 28 };
2630
+ }
2631
+ static new(key_kind, clock, key_offset, window, max_calls, max_amount) {
2632
+ const buffer = new Uint8Array(28);
2633
+ const view = new DataView(buffer.buffer);
2634
+ view.setUint8(0, key_kind);
2635
+ view.setUint8(1, clock);
2636
+ view.setUint16(2, key_offset, true);
2637
+ view.setBigUint64(4, window, true);
2638
+ view.setBigUint64(12, max_calls, true);
2639
+ view.setBigUint64(20, max_amount, true);
2640
+ return new _RatelimitRule(buffer);
2641
+ }
2642
+ static from_array(buffer) {
2643
+ if (!buffer || buffer.length === void 0) {
2644
+ return null;
2645
+ }
2646
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2647
+ const validation = this.validate(buffer);
2648
+ if (!validation.ok) {
2649
+ return null;
2650
+ }
2651
+ return new _RatelimitRule(buffer);
2652
+ }
2653
+ };
2654
+ var RatelimitRuleBuilder = class {
2655
+ constructor() {
2656
+ this.buffer = new Uint8Array(28);
2657
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2658
+ }
2659
+ set_key_kind(value) {
2660
+ this.view.setUint8(0, value);
2661
+ return this;
2662
+ }
2663
+ set_clock(value) {
2664
+ this.view.setUint8(1, value);
2665
+ return this;
2666
+ }
2667
+ set_key_offset(value) {
2668
+ this.view.setUint16(2, value, true);
2669
+ return this;
2670
+ }
2671
+ set_window(value) {
2672
+ const cast = __tnToBigInt(value);
2673
+ this.view.setBigUint64(4, cast, true);
2674
+ return this;
2675
+ }
2676
+ set_max_calls(value) {
2677
+ const cast = __tnToBigInt(value);
2678
+ this.view.setBigUint64(12, cast, true);
2679
+ return this;
2680
+ }
2681
+ set_max_amount(value) {
2682
+ const cast = __tnToBigInt(value);
2683
+ this.view.setBigUint64(20, cast, true);
2684
+ return this;
2685
+ }
2686
+ build() {
2687
+ return this.buffer.slice();
2688
+ }
2689
+ buildInto(target, offset = 0) {
2690
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2691
+ target.set(this.buffer, offset);
2692
+ return target;
2693
+ }
2694
+ finish() {
2695
+ const view = RatelimitRule.from_array(this.buffer.slice());
2696
+ if (!view) throw new Error("failed to build RatelimitRule");
2697
+ return view;
2698
+ }
2699
+ };
2700
+ __tnRegisterFootprint("RatelimitRule", (params) => RatelimitRule.__tnInvokeFootprint(params));
2701
+ __tnRegisterValidate("RatelimitRule", (buffer, params) => RatelimitRule.__tnInvokeValidate(buffer, params));
2702
+ __tnRegisterDynamicValidate("RatelimitRule", (buffer) => {
2703
+ const result = RatelimitRule.validate(buffer);
2704
+ const params = result.params;
2705
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2706
+ });
2707
+ var __tn_ir_SetAdminArgs = {
2708
+ typeName: "SetAdminArgs",
2709
+ root: { op: "const", value: 34n }
2710
+ };
2711
+ var SetAdminArgs = class _SetAdminArgs {
2712
+ constructor(buffer) {
2713
+ this.buffer = buffer;
2714
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2715
+ }
2716
+ static __tnCreateView(buffer, opts) {
2717
+ if (!buffer || buffer.length === void 0) throw new Error("SetAdminArgs.__tnCreateView requires a Uint8Array");
2718
+ return new _SetAdminArgs(new Uint8Array(buffer));
2719
+ }
2720
+ static builder() {
2721
+ return new SetAdminArgsBuilder();
2722
+ }
2723
+ static fromBuilder(builder) {
2724
+ const buffer = builder.build();
2725
+ return _SetAdminArgs.from_array(buffer);
2726
+ }
2727
+ get_policy_account_idx() {
2728
+ const offset = 0;
2729
+ return this.view.getUint16(offset, true);
2730
+ }
2731
+ set_policy_account_idx(value) {
2732
+ const offset = 0;
2733
+ this.view.setUint16(offset, value, true);
2734
+ }
2735
+ get policy_account_idx() {
2736
+ return this.get_policy_account_idx();
2737
+ }
2738
+ set policy_account_idx(value) {
2739
+ this.set_policy_account_idx(value);
2740
+ }
2741
+ get_new_admin() {
2742
+ const offset = 2;
2743
+ const slice = this.buffer.subarray(offset, offset + 32);
2744
+ return Pubkey2.from_array(slice);
2745
+ }
2746
+ set_new_admin(value) {
2747
+ const sourceBytes = value.buffer;
2748
+ const offset = 2;
2749
+ this.buffer.set(sourceBytes, offset);
2750
+ }
2751
+ get new_admin() {
2752
+ return this.get_new_admin();
2753
+ }
2754
+ set new_admin(value) {
2755
+ this.set_new_admin(value);
2756
+ }
2757
+ static __tnFootprintInternal(__tnParams) {
2758
+ return __tnEvalFootprint(__tn_ir_SetAdminArgs.root, { params: __tnParams });
2759
+ }
2760
+ static __tnValidateInternal(buffer, __tnParams) {
2761
+ return __tnValidateIrTree(__tn_ir_SetAdminArgs, buffer, __tnParams);
2762
+ }
2763
+ static __tnInvokeFootprint(__tnParams) {
2764
+ return this.__tnFootprintInternal(__tnParams);
2765
+ }
2766
+ static __tnInvokeValidate(buffer, __tnParams) {
2767
+ return this.__tnValidateInternal(buffer, __tnParams);
2768
+ }
2769
+ static footprintIr() {
2770
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
2771
+ }
2772
+ static footprint() {
2773
+ const irResult = this.footprintIr();
2774
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
2775
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
2776
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for SetAdminArgs");
2777
+ }
2778
+ return __tnBigIntToNumber(irResult, "SetAdminArgs::footprint");
2779
+ }
2780
+ static validate(buffer, _opts) {
2781
+ if (buffer.length < 34) return { ok: false, code: "tn.buffer_too_small", consumed: 34 };
2782
+ return { ok: true, consumed: 34 };
2783
+ }
2784
+ static from_array(buffer) {
2785
+ if (!buffer || buffer.length === void 0) {
2786
+ return null;
2787
+ }
2788
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2789
+ const validation = this.validate(buffer);
2790
+ if (!validation.ok) {
2791
+ return null;
2792
+ }
2793
+ return new _SetAdminArgs(buffer);
2794
+ }
2795
+ };
2796
+ var SetAdminArgsBuilder = class {
2797
+ constructor() {
2798
+ this.buffer = new Uint8Array(34);
2799
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
2800
+ }
2801
+ set_policy_account_idx(value) {
2802
+ this.view.setUint16(0, value, true);
2803
+ return this;
2804
+ }
2805
+ set_new_admin(value) {
2806
+ if (value.length !== 32) throw new Error("new_admin expects 32 bytes");
2807
+ this.buffer.set(value, 2);
2808
+ return this;
2809
+ }
2810
+ build() {
2811
+ return this.buffer.slice();
2812
+ }
2813
+ buildInto(target, offset = 0) {
2814
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
2815
+ target.set(this.buffer, offset);
2816
+ return target;
2817
+ }
2818
+ finish() {
2819
+ const view = SetAdminArgs.from_array(this.buffer.slice());
2820
+ if (!view) throw new Error("failed to build SetAdminArgs");
2821
+ return view;
2822
+ }
2823
+ };
2824
+ __tnRegisterFootprint("SetAdminArgs", (params) => SetAdminArgs.__tnInvokeFootprint(params));
2825
+ __tnRegisterValidate("SetAdminArgs", (buffer, params) => SetAdminArgs.__tnInvokeValidate(buffer, params));
2826
+ __tnRegisterDynamicValidate("SetAdminArgs", (buffer) => {
2827
+ const result = SetAdminArgs.validate(buffer);
2828
+ const params = result.params;
2829
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
2830
+ });
2831
+ var __tn_ir_RatelimitConfig = {
2832
+ typeName: "RatelimitConfig",
2833
+ root: { op: "const", value: 309n }
2834
+ };
2835
+ var RatelimitConfig = class _RatelimitConfig {
2836
+ constructor(buffer) {
2837
+ this.buffer = buffer;
2838
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
2839
+ }
2840
+ static __tnCreateView(buffer, opts) {
2841
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitConfig.__tnCreateView requires a Uint8Array");
2842
+ return new _RatelimitConfig(new Uint8Array(buffer));
2843
+ }
2844
+ static builder() {
2845
+ return new RatelimitConfigBuilder();
2846
+ }
2847
+ static fromBuilder(builder) {
2848
+ const buffer = builder.build();
2849
+ return _RatelimitConfig.from_array(buffer);
2850
+ }
2851
+ get_flags() {
2852
+ const offset = 0;
2853
+ return this.view.getUint8(offset);
2854
+ }
2855
+ set_flags(value) {
2856
+ const offset = 0;
2857
+ this.view.setUint8(offset, value);
2858
+ }
2859
+ get flags() {
2860
+ return this.get_flags();
2861
+ }
2862
+ set flags(value) {
2863
+ this.set_flags(value);
2864
+ }
2865
+ get_rule_cnt() {
2866
+ const offset = 1;
2867
+ return this.view.getUint8(offset);
2868
+ }
2869
+ set_rule_cnt(value) {
2870
+ const offset = 1;
2871
+ this.view.setUint8(offset, value);
2872
+ }
2873
+ get rule_cnt() {
2874
+ return this.get_rule_cnt();
2875
+ }
2876
+ set rule_cnt(value) {
2877
+ this.set_rule_cnt(value);
2878
+ }
2879
+ get_constraint_cnt() {
2880
+ const offset = 2;
2881
+ return this.view.getUint8(offset);
2882
+ }
2883
+ set_constraint_cnt(value) {
2884
+ const offset = 2;
2885
+ this.view.setUint8(offset, value);
2886
+ }
2887
+ get constraint_cnt() {
2888
+ return this.get_constraint_cnt();
2889
+ }
2890
+ set constraint_cnt(value) {
2891
+ this.set_constraint_cnt(value);
2892
+ }
2893
+ get_selector_sz() {
2894
+ const offset = 3;
2895
+ return this.view.getUint8(offset);
2896
+ }
2897
+ set_selector_sz(value) {
2898
+ const offset = 3;
2899
+ this.view.setUint8(offset, value);
2900
+ }
2901
+ get selector_sz() {
2902
+ return this.get_selector_sz();
2903
+ }
2904
+ set selector_sz(value) {
2905
+ this.set_selector_sz(value);
2906
+ }
2907
+ get_selector_offset() {
2908
+ const offset = 4;
2909
+ return this.view.getUint16(offset, true);
2910
+ }
2911
+ set_selector_offset(value) {
2912
+ const offset = 4;
2913
+ this.view.setUint16(offset, value, true);
2914
+ }
2915
+ get selector_offset() {
2916
+ return this.get_selector_offset();
2917
+ }
2918
+ set selector_offset(value) {
2919
+ this.set_selector_offset(value);
2920
+ }
2921
+ get_selector_value() {
2922
+ const offset = 6;
2923
+ return this.view.getBigUint64(offset, true);
2924
+ }
2925
+ set_selector_value(value) {
2926
+ const offset = 6;
2927
+ this.view.setBigUint64(offset, value, true);
2928
+ }
2929
+ get selector_value() {
2930
+ return this.get_selector_value();
2931
+ }
2932
+ set selector_value(value) {
2933
+ this.set_selector_value(value);
2934
+ }
2935
+ get_instr_sz_min() {
2936
+ const offset = 14;
2937
+ return this.view.getUint16(offset, true);
2938
+ }
2939
+ set_instr_sz_min(value) {
2940
+ const offset = 14;
2941
+ this.view.setUint16(offset, value, true);
2942
+ }
2943
+ get instr_sz_min() {
2944
+ return this.get_instr_sz_min();
2945
+ }
2946
+ set instr_sz_min(value) {
2947
+ this.set_instr_sz_min(value);
2948
+ }
2949
+ get_instr_sz_max() {
2950
+ const offset = 16;
2951
+ return this.view.getUint16(offset, true);
2952
+ }
2953
+ set_instr_sz_max(value) {
2954
+ const offset = 16;
2955
+ this.view.setUint16(offset, value, true);
2956
+ }
2957
+ get instr_sz_max() {
2958
+ return this.get_instr_sz_max();
2959
+ }
2960
+ set instr_sz_max(value) {
2961
+ this.set_instr_sz_max(value);
2962
+ }
2963
+ get_amount_sz() {
2964
+ const offset = 18;
2965
+ return this.view.getUint8(offset);
2966
+ }
2967
+ set_amount_sz(value) {
2968
+ const offset = 18;
2969
+ this.view.setUint8(offset, value);
2970
+ }
2971
+ get amount_sz() {
2972
+ return this.get_amount_sz();
2973
+ }
2974
+ set amount_sz(value) {
2975
+ this.set_amount_sz(value);
2976
+ }
2977
+ get_amount_offset() {
2978
+ const offset = 19;
2979
+ return this.view.getUint16(offset, true);
2980
+ }
2981
+ set_amount_offset(value) {
2982
+ const offset = 19;
2983
+ this.view.setUint16(offset, value, true);
2984
+ }
2985
+ get amount_offset() {
2986
+ return this.get_amount_offset();
2987
+ }
2988
+ set amount_offset(value) {
2989
+ this.set_amount_offset(value);
2990
+ }
2991
+ get_max_amount_per_call() {
2992
+ const offset = 21;
2993
+ return this.view.getBigUint64(offset, true);
2994
+ }
2995
+ set_max_amount_per_call(value) {
2996
+ const offset = 21;
2997
+ this.view.setBigUint64(offset, value, true);
2998
+ }
2999
+ get max_amount_per_call() {
3000
+ return this.get_max_amount_per_call();
3001
+ }
3002
+ set max_amount_per_call(value) {
3003
+ this.set_max_amount_per_call(value);
3004
+ }
3005
+ get_attester() {
3006
+ const offset = 29;
3007
+ const slice = this.buffer.subarray(offset, offset + 32);
3008
+ return Pubkey2.from_array(slice);
3009
+ }
3010
+ set_attester(value) {
3011
+ const sourceBytes = value.buffer;
3012
+ const offset = 29;
3013
+ this.buffer.set(sourceBytes, offset);
3014
+ }
3015
+ get attester() {
3016
+ return this.get_attester();
3017
+ }
3018
+ set attester(value) {
3019
+ this.set_attester(value);
3020
+ }
3021
+ get_constraints() {
3022
+ const offset = 61;
3023
+ const result = [];
3024
+ for (let i = 0; i < 4; i++) {
3025
+ const slice = this.buffer.subarray(offset + i * 34, offset + (i + 1) * 34);
3026
+ result.push(RatelimitConstraint.from_array(slice));
3027
+ }
3028
+ return result;
3029
+ }
3030
+ set_constraints(value) {
3031
+ const offset = 61;
3032
+ if (value.length !== 4) {
3033
+ throw new Error("Array length must be 4");
3034
+ }
3035
+ for (let i = 0; i < 4; i++) {
3036
+ const slice = this.buffer.subarray(offset + i * 34, offset + (i + 1) * 34);
3037
+ slice.set(value[i]["buffer"]);
3038
+ }
3039
+ }
3040
+ get constraints() {
3041
+ return this.get_constraints();
3042
+ }
3043
+ set constraints(value) {
3044
+ this.set_constraints(value);
3045
+ }
3046
+ get_rules() {
3047
+ const offset = 197;
3048
+ const result = [];
3049
+ for (let i = 0; i < 4; i++) {
3050
+ const slice = this.buffer.subarray(offset + i * 28, offset + (i + 1) * 28);
3051
+ result.push(RatelimitRule.from_array(slice));
3052
+ }
3053
+ return result;
3054
+ }
3055
+ set_rules(value) {
3056
+ const offset = 197;
3057
+ if (value.length !== 4) {
3058
+ throw new Error("Array length must be 4");
3059
+ }
3060
+ for (let i = 0; i < 4; i++) {
3061
+ const slice = this.buffer.subarray(offset + i * 28, offset + (i + 1) * 28);
3062
+ slice.set(value[i]["buffer"]);
3063
+ }
3064
+ }
3065
+ get rules() {
3066
+ return this.get_rules();
3067
+ }
3068
+ set rules(value) {
3069
+ this.set_rules(value);
3070
+ }
3071
+ static __tnFootprintInternal(__tnParams) {
3072
+ return __tnEvalFootprint(__tn_ir_RatelimitConfig.root, { params: __tnParams });
3073
+ }
3074
+ static __tnValidateInternal(buffer, __tnParams) {
3075
+ return __tnValidateIrTree(__tn_ir_RatelimitConfig, buffer, __tnParams);
3076
+ }
3077
+ static __tnInvokeFootprint(__tnParams) {
3078
+ return this.__tnFootprintInternal(__tnParams);
3079
+ }
3080
+ static __tnInvokeValidate(buffer, __tnParams) {
3081
+ return this.__tnValidateInternal(buffer, __tnParams);
3082
+ }
3083
+ static footprintIr() {
3084
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
3085
+ }
3086
+ static footprint() {
3087
+ const irResult = this.footprintIr();
3088
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3089
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
3090
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitConfig");
3091
+ }
3092
+ return __tnBigIntToNumber(irResult, "RatelimitConfig::footprint");
3093
+ }
3094
+ static validate(buffer, _opts) {
3095
+ if (buffer.length < 309) return { ok: false, code: "tn.buffer_too_small", consumed: 309 };
3096
+ return { ok: true, consumed: 309 };
3097
+ }
3098
+ static from_array(buffer) {
3099
+ if (!buffer || buffer.length === void 0) {
3100
+ return null;
3101
+ }
3102
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3103
+ const validation = this.validate(buffer);
3104
+ if (!validation.ok) {
3105
+ return null;
3106
+ }
3107
+ return new _RatelimitConfig(buffer);
3108
+ }
3109
+ };
3110
+ var RatelimitConfigBuilder = class {
3111
+ constructor() {
3112
+ this.buffer = new Uint8Array(309);
3113
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3114
+ }
3115
+ set_flags(value) {
3116
+ this.view.setUint8(0, value);
3117
+ return this;
3118
+ }
3119
+ set_rule_cnt(value) {
3120
+ this.view.setUint8(1, value);
3121
+ return this;
3122
+ }
3123
+ set_constraint_cnt(value) {
3124
+ this.view.setUint8(2, value);
3125
+ return this;
3126
+ }
3127
+ set_selector_sz(value) {
3128
+ this.view.setUint8(3, value);
3129
+ return this;
3130
+ }
3131
+ set_selector_offset(value) {
3132
+ this.view.setUint16(4, value, true);
3133
+ return this;
3134
+ }
3135
+ set_selector_value(value) {
3136
+ const cast = __tnToBigInt(value);
3137
+ this.view.setBigUint64(6, cast, true);
3138
+ return this;
3139
+ }
3140
+ set_instr_sz_min(value) {
3141
+ this.view.setUint16(14, value, true);
3142
+ return this;
3143
+ }
3144
+ set_instr_sz_max(value) {
3145
+ this.view.setUint16(16, value, true);
3146
+ return this;
3147
+ }
3148
+ set_amount_sz(value) {
3149
+ this.view.setUint8(18, value);
3150
+ return this;
3151
+ }
3152
+ set_amount_offset(value) {
3153
+ this.view.setUint16(19, value, true);
3154
+ return this;
3155
+ }
3156
+ set_max_amount_per_call(value) {
3157
+ const cast = __tnToBigInt(value);
3158
+ this.view.setBigUint64(21, cast, true);
3159
+ return this;
3160
+ }
3161
+ set_attester(value) {
3162
+ if (value.length !== 32) throw new Error("attester expects 32 bytes");
3163
+ this.buffer.set(value, 29);
3164
+ return this;
3165
+ }
3166
+ set_constraints(values) {
3167
+ if (values.length !== 4) throw new Error("constraints expects 4 elements");
3168
+ for (let i = 0; i < values.length; i++) {
3169
+ const slice = this.buffer.subarray(61 + i * 34, 61 + (i + 1) * 34);
3170
+ const source = values[i];
3171
+ const raw = source.buffer ? new Uint8Array(source.buffer, source.byteOffset ?? 0, 34) : values[i];
3172
+ slice.set(raw);
3173
+ }
3174
+ return this;
3175
+ }
3176
+ set_rules(values) {
3177
+ if (values.length !== 4) throw new Error("rules expects 4 elements");
3178
+ for (let i = 0; i < values.length; i++) {
3179
+ const slice = this.buffer.subarray(197 + i * 28, 197 + (i + 1) * 28);
3180
+ const source = values[i];
3181
+ const raw = source.buffer ? new Uint8Array(source.buffer, source.byteOffset ?? 0, 28) : values[i];
3182
+ slice.set(raw);
3183
+ }
3184
+ return this;
3185
+ }
3186
+ build() {
3187
+ return this.buffer.slice();
3188
+ }
3189
+ buildInto(target, offset = 0) {
3190
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
3191
+ target.set(this.buffer, offset);
3192
+ return target;
3193
+ }
3194
+ finish() {
3195
+ const view = RatelimitConfig.from_array(this.buffer.slice());
3196
+ if (!view) throw new Error("failed to build RatelimitConfig");
3197
+ return view;
3198
+ }
3199
+ };
3200
+ __tnRegisterFootprint("RatelimitConfig", (params) => RatelimitConfig.__tnInvokeFootprint(params));
3201
+ __tnRegisterValidate("RatelimitConfig", (buffer, params) => RatelimitConfig.__tnInvokeValidate(buffer, params));
3202
+ __tnRegisterDynamicValidate("RatelimitConfig", (buffer) => {
3203
+ const result = RatelimitConfig.validate(buffer);
3204
+ const params = result.params;
3205
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
3206
+ });
3207
+ var __tn_ir_RatelimitPolicy = {
3208
+ typeName: "RatelimitPolicy",
3209
+ root: { op: "const", value: 390n }
3210
+ };
3211
+ var RatelimitPolicy = class _RatelimitPolicy {
3212
+ constructor(buffer) {
3213
+ this.buffer = buffer;
3214
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3215
+ }
3216
+ static __tnCreateView(buffer, opts) {
3217
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitPolicy.__tnCreateView requires a Uint8Array");
3218
+ return new _RatelimitPolicy(new Uint8Array(buffer));
3219
+ }
3220
+ static builder() {
3221
+ return new RatelimitPolicyBuilder();
3222
+ }
3223
+ static fromBuilder(builder) {
3224
+ const buffer = builder.build();
3225
+ return _RatelimitPolicy.from_array(buffer);
3226
+ }
3227
+ get_magic() {
3228
+ const offset = 0;
3229
+ return this.view.getBigUint64(offset, true);
3230
+ }
3231
+ set_magic(value) {
3232
+ const offset = 0;
3233
+ this.view.setBigUint64(offset, value, true);
3234
+ }
3235
+ get magic() {
3236
+ return this.get_magic();
3237
+ }
3238
+ set magic(value) {
3239
+ this.set_magic(value);
3240
+ }
3241
+ get_admin() {
3242
+ const offset = 8;
3243
+ const slice = this.buffer.subarray(offset, offset + 32);
3244
+ return Pubkey2.from_array(slice);
3245
+ }
3246
+ set_admin(value) {
3247
+ const sourceBytes = value.buffer;
3248
+ const offset = 8;
3249
+ this.buffer.set(sourceBytes, offset);
3250
+ }
3251
+ get admin() {
3252
+ return this.get_admin();
3253
+ }
3254
+ set admin(value) {
3255
+ this.set_admin(value);
3256
+ }
3257
+ get_target() {
3258
+ const offset = 40;
3259
+ const slice = this.buffer.subarray(offset, offset + 32);
3260
+ return Pubkey2.from_array(slice);
3261
+ }
3262
+ set_target(value) {
3263
+ const sourceBytes = value.buffer;
3264
+ const offset = 40;
3265
+ this.buffer.set(sourceBytes, offset);
3266
+ }
3267
+ get target() {
3268
+ return this.get_target();
3269
+ }
3270
+ set target(value) {
3271
+ this.set_target(value);
3272
+ }
3273
+ get_policy_id() {
3274
+ const offset = 72;
3275
+ return this.view.getBigUint64(offset, true);
3276
+ }
3277
+ set_policy_id(value) {
3278
+ const offset = 72;
3279
+ this.view.setBigUint64(offset, value, true);
3280
+ }
3281
+ get policy_id() {
3282
+ return this.get_policy_id();
3283
+ }
3284
+ set policy_id(value) {
3285
+ this.set_policy_id(value);
3286
+ }
3287
+ get_state_flags() {
3288
+ const offset = 80;
3289
+ return this.view.getUint8(offset);
3290
+ }
3291
+ set_state_flags(value) {
3292
+ const offset = 80;
3293
+ this.view.setUint8(offset, value);
3294
+ }
3295
+ get state_flags() {
3296
+ return this.get_state_flags();
3297
+ }
3298
+ set state_flags(value) {
3299
+ this.set_state_flags(value);
3300
+ }
3301
+ get_config() {
3302
+ const offset = 81;
3303
+ const slice = this.buffer.subarray(offset, offset + 309);
3304
+ return RatelimitConfig.from_array(slice);
3305
+ }
3306
+ set_config(value) {
3307
+ const sourceBytes = value.buffer;
3308
+ const offset = 81;
3309
+ this.buffer.set(sourceBytes, offset);
3310
+ }
3311
+ get config() {
3312
+ return this.get_config();
3313
+ }
3314
+ set config(value) {
3315
+ this.set_config(value);
3316
+ }
3317
+ static __tnFootprintInternal(__tnParams) {
3318
+ return __tnEvalFootprint(__tn_ir_RatelimitPolicy.root, { params: __tnParams });
3319
+ }
3320
+ static __tnValidateInternal(buffer, __tnParams) {
3321
+ return __tnValidateIrTree(__tn_ir_RatelimitPolicy, buffer, __tnParams);
3322
+ }
3323
+ static __tnInvokeFootprint(__tnParams) {
3324
+ return this.__tnFootprintInternal(__tnParams);
3325
+ }
3326
+ static __tnInvokeValidate(buffer, __tnParams) {
3327
+ return this.__tnValidateInternal(buffer, __tnParams);
3328
+ }
3329
+ static footprintIr() {
3330
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
3331
+ }
3332
+ static footprint() {
3333
+ const irResult = this.footprintIr();
3334
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3335
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
3336
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitPolicy");
3337
+ }
3338
+ return __tnBigIntToNumber(irResult, "RatelimitPolicy::footprint");
3339
+ }
3340
+ static validate(buffer, _opts) {
3341
+ if (buffer.length < 390) return { ok: false, code: "tn.buffer_too_small", consumed: 390 };
3342
+ return { ok: true, consumed: 390 };
3343
+ }
3344
+ static from_array(buffer) {
3345
+ if (!buffer || buffer.length === void 0) {
3346
+ return null;
3347
+ }
3348
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3349
+ const validation = this.validate(buffer);
3350
+ if (!validation.ok) {
3351
+ return null;
3352
+ }
3353
+ return new _RatelimitPolicy(buffer);
3354
+ }
3355
+ };
3356
+ var RatelimitPolicyBuilder = class {
3357
+ constructor() {
3358
+ this.buffer = new Uint8Array(390);
3359
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3360
+ }
3361
+ set_magic(value) {
3362
+ const cast = __tnToBigInt(value);
3363
+ this.view.setBigUint64(0, cast, true);
3364
+ return this;
3365
+ }
3366
+ set_admin(value) {
3367
+ if (value.length !== 32) throw new Error("admin expects 32 bytes");
3368
+ this.buffer.set(value, 8);
3369
+ return this;
3370
+ }
3371
+ set_target(value) {
3372
+ if (value.length !== 32) throw new Error("target expects 32 bytes");
3373
+ this.buffer.set(value, 40);
3374
+ return this;
3375
+ }
3376
+ set_policy_id(value) {
3377
+ const cast = __tnToBigInt(value);
3378
+ this.view.setBigUint64(72, cast, true);
3379
+ return this;
3380
+ }
3381
+ set_state_flags(value) {
3382
+ this.view.setUint8(80, value);
3383
+ return this;
3384
+ }
3385
+ set_config(value) {
3386
+ if (value.length !== 309) throw new Error("config expects 309 bytes");
3387
+ this.buffer.set(value, 81);
3388
+ return this;
3389
+ }
3390
+ build() {
3391
+ return this.buffer.slice();
3392
+ }
3393
+ buildInto(target, offset = 0) {
3394
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
3395
+ target.set(this.buffer, offset);
3396
+ return target;
3397
+ }
3398
+ finish() {
3399
+ const view = RatelimitPolicy.from_array(this.buffer.slice());
3400
+ if (!view) throw new Error("failed to build RatelimitPolicy");
3401
+ return view;
3402
+ }
3403
+ };
3404
+ __tnRegisterFootprint("RatelimitPolicy", (params) => RatelimitPolicy.__tnInvokeFootprint(params));
3405
+ __tnRegisterValidate("RatelimitPolicy", (buffer, params) => RatelimitPolicy.__tnInvokeValidate(buffer, params));
3406
+ __tnRegisterDynamicValidate("RatelimitPolicy", (buffer) => {
3407
+ const result = RatelimitPolicy.validate(buffer);
3408
+ const params = result.params;
3409
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
3410
+ });
3411
+ var __tn_ir_UpdatePolicyArgs = {
3412
+ typeName: "UpdatePolicyArgs",
3413
+ root: { op: "const", value: 311n }
3414
+ };
3415
+ var UpdatePolicyArgs = class _UpdatePolicyArgs {
3416
+ constructor(buffer) {
3417
+ this.buffer = buffer;
3418
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3419
+ }
3420
+ static __tnCreateView(buffer, opts) {
3421
+ if (!buffer || buffer.length === void 0) throw new Error("UpdatePolicyArgs.__tnCreateView requires a Uint8Array");
3422
+ return new _UpdatePolicyArgs(new Uint8Array(buffer));
3423
+ }
3424
+ static builder() {
3425
+ return new UpdatePolicyArgsBuilder();
3426
+ }
3427
+ static fromBuilder(builder) {
3428
+ const buffer = builder.build();
3429
+ return _UpdatePolicyArgs.from_array(buffer);
3430
+ }
3431
+ get_policy_account_idx() {
3432
+ const offset = 0;
3433
+ return this.view.getUint16(offset, true);
3434
+ }
3435
+ set_policy_account_idx(value) {
3436
+ const offset = 0;
3437
+ this.view.setUint16(offset, value, true);
3438
+ }
3439
+ get policy_account_idx() {
3440
+ return this.get_policy_account_idx();
3441
+ }
3442
+ set policy_account_idx(value) {
3443
+ this.set_policy_account_idx(value);
3444
+ }
3445
+ get_config() {
3446
+ const offset = 2;
3447
+ const slice = this.buffer.subarray(offset, offset + 309);
3448
+ return RatelimitConfig.from_array(slice);
3449
+ }
3450
+ set_config(value) {
3451
+ const sourceBytes = value.buffer;
3452
+ const offset = 2;
3453
+ this.buffer.set(sourceBytes, offset);
3454
+ }
3455
+ get config() {
3456
+ return this.get_config();
3457
+ }
3458
+ set config(value) {
3459
+ this.set_config(value);
3460
+ }
3461
+ static __tnFootprintInternal(__tnParams) {
3462
+ return __tnEvalFootprint(__tn_ir_UpdatePolicyArgs.root, { params: __tnParams });
3463
+ }
3464
+ static __tnValidateInternal(buffer, __tnParams) {
3465
+ return __tnValidateIrTree(__tn_ir_UpdatePolicyArgs, buffer, __tnParams);
3466
+ }
3467
+ static __tnInvokeFootprint(__tnParams) {
3468
+ return this.__tnFootprintInternal(__tnParams);
3469
+ }
3470
+ static __tnInvokeValidate(buffer, __tnParams) {
3471
+ return this.__tnValidateInternal(buffer, __tnParams);
3472
+ }
3473
+ static footprintIr() {
3474
+ return this.__tnFootprintInternal(/* @__PURE__ */ Object.create(null));
3475
+ }
3476
+ static footprint() {
3477
+ const irResult = this.footprintIr();
3478
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3479
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) {
3480
+ throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for UpdatePolicyArgs");
3481
+ }
3482
+ return __tnBigIntToNumber(irResult, "UpdatePolicyArgs::footprint");
3483
+ }
3484
+ static validate(buffer, _opts) {
3485
+ if (buffer.length < 311) return { ok: false, code: "tn.buffer_too_small", consumed: 311 };
3486
+ return { ok: true, consumed: 311 };
3487
+ }
3488
+ static from_array(buffer) {
3489
+ if (!buffer || buffer.length === void 0) {
3490
+ return null;
3491
+ }
3492
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3493
+ const validation = this.validate(buffer);
3494
+ if (!validation.ok) {
3495
+ return null;
3496
+ }
3497
+ return new _UpdatePolicyArgs(buffer);
3498
+ }
3499
+ };
3500
+ var UpdatePolicyArgsBuilder = class {
3501
+ constructor() {
3502
+ this.buffer = new Uint8Array(311);
3503
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3504
+ }
3505
+ set_policy_account_idx(value) {
3506
+ this.view.setUint16(0, value, true);
3507
+ return this;
3508
+ }
3509
+ set_config(value) {
3510
+ if (value.length !== 309) throw new Error("config expects 309 bytes");
3511
+ this.buffer.set(value, 2);
3512
+ return this;
3513
+ }
3514
+ build() {
3515
+ return this.buffer.slice();
3516
+ }
3517
+ buildInto(target, offset = 0) {
3518
+ if (target.length - offset < this.buffer.length) throw new Error("target buffer too small");
3519
+ target.set(this.buffer, offset);
3520
+ return target;
3521
+ }
3522
+ finish() {
3523
+ const view = UpdatePolicyArgs.from_array(this.buffer.slice());
3524
+ if (!view) throw new Error("failed to build UpdatePolicyArgs");
3525
+ return view;
3526
+ }
3527
+ };
3528
+ __tnRegisterFootprint("UpdatePolicyArgs", (params) => UpdatePolicyArgs.__tnInvokeFootprint(params));
3529
+ __tnRegisterValidate("UpdatePolicyArgs", (buffer, params) => UpdatePolicyArgs.__tnInvokeValidate(buffer, params));
3530
+ __tnRegisterDynamicValidate("UpdatePolicyArgs", (buffer) => {
3531
+ const result = UpdatePolicyArgs.validate(buffer);
3532
+ const params = result.params;
3533
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
3534
+ });
3535
+ var __tn_ir_CreatePolicyArgs = {
3536
+ typeName: "CreatePolicyArgs",
3537
+ root: { op: "align", alignment: 1, node: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "add", left: { op: "align", alignment: 2, node: { op: "const", value: 2n } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 1, node: { op: "const", value: 32n } } }, right: { op: "align", alignment: 1, node: { op: "const", value: 32n } } }, right: { op: "align", alignment: 8, node: { op: "const", value: 8n } } }, right: { op: "align", alignment: 1, node: { op: "const", value: 309n } } }, right: { op: "align", alignment: 2, node: { op: "const", value: 2n } } }, right: { op: "align", alignment: 1, node: { op: "mul", left: { op: "field", param: "proof.proof_sz" }, right: { op: "const", value: 1n } } } } }
3538
+ };
3539
+ var _CreatePolicyArgs = class _CreatePolicyArgs {
3540
+ constructor(buffer, params, fieldContext) {
3541
+ this.buffer = buffer;
3542
+ this.__tnFieldContext = null;
3543
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3544
+ this.__tnFieldContext = fieldContext ?? null;
3545
+ if (params) {
3546
+ this.__tnParams = params;
3547
+ } else {
3548
+ const derived = _CreatePolicyArgs.__tnExtractParams(this.view, buffer);
3549
+ if (!derived) {
3550
+ throw new Error("CreatePolicyArgs: failed to derive dynamic parameters");
3551
+ }
3552
+ this.__tnParams = derived.params;
3553
+ }
3554
+ }
3555
+ static __tnCreateView(buffer, opts) {
3556
+ if (!buffer || buffer.length === void 0) throw new Error("CreatePolicyArgs.__tnCreateView requires a Uint8Array");
3557
+ let params = opts?.params ?? null;
3558
+ if (!params) {
3559
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3560
+ const derived = _CreatePolicyArgs.__tnExtractParams(view, buffer);
3561
+ if (!derived) throw new Error("CreatePolicyArgs.__tnCreateView: failed to derive params");
3562
+ params = derived.params;
3563
+ }
3564
+ const instance = new _CreatePolicyArgs(new Uint8Array(buffer), params, opts?.fieldContext);
3565
+ return instance;
3566
+ }
3567
+ dynamicParams() {
3568
+ return this.__tnParams;
3569
+ }
3570
+ withFieldContext(context) {
3571
+ this.__tnFieldContext = context;
3572
+ return this;
3573
+ }
3574
+ __tnResolveFieldRef(path) {
3575
+ const getterName = `get_${path.replace(/[.]/g, "_")}`;
3576
+ const getter = this[getterName];
3577
+ if (typeof getter === "function") {
3578
+ const value = getter.call(this);
3579
+ return typeof value === "bigint" ? __tnBigIntToNumber(value, "CreatePolicyArgs::__tnResolveFieldRef") : value;
3580
+ }
3581
+ if (this.__tnFieldContext && Object.prototype.hasOwnProperty.call(this.__tnFieldContext, path)) {
3582
+ const contextValue = this.__tnFieldContext[path];
3583
+ return typeof contextValue === "bigint" ? __tnBigIntToNumber(contextValue, "CreatePolicyArgs::__tnResolveFieldRef") : contextValue;
3584
+ }
3585
+ throw new Error("CreatePolicyArgs: field reference '" + path + "' is not available; provide fieldContext when creating this view");
3586
+ }
3587
+ static builder() {
3588
+ return new CreatePolicyArgsBuilder();
3589
+ }
3590
+ static fromBuilder(builder) {
3591
+ const buffer = builder.build();
3592
+ const params = builder.dynamicParams();
3593
+ return _CreatePolicyArgs.from_array(buffer, { params });
3594
+ }
3595
+ static __tnExtractParams(view, buffer) {
3596
+ if (buffer.length < 387) {
3597
+ return null;
3598
+ }
3599
+ const __tnParam_proof_proof_sz = __tnToBigInt(view.getUint16(385, true));
3600
+ const __tnExtractedParams = _CreatePolicyArgs.Params.fromValues({
3601
+ proof_proof_sz: __tnParam_proof_proof_sz
3602
+ });
3603
+ return { params: __tnExtractedParams, derived: null };
3604
+ }
3605
+ get_policy_account_idx() {
3606
+ const offset = 0;
3607
+ return this.view.getUint16(offset, true);
3608
+ }
3609
+ set_policy_account_idx(value) {
3610
+ const offset = 0;
3611
+ this.view.setUint16(offset, value, true);
3612
+ }
3613
+ get policy_account_idx() {
3614
+ return this.get_policy_account_idx();
3615
+ }
3616
+ set policy_account_idx(value) {
3617
+ this.set_policy_account_idx(value);
3618
+ }
3619
+ get_meta_account_idx() {
3620
+ const offset = 2;
3621
+ return this.view.getUint16(offset, true);
3622
+ }
3623
+ set_meta_account_idx(value) {
3624
+ const offset = 2;
3625
+ this.view.setUint16(offset, value, true);
3626
+ }
3627
+ get meta_account_idx() {
3628
+ return this.get_meta_account_idx();
3629
+ }
3630
+ set meta_account_idx(value) {
3631
+ this.set_meta_account_idx(value);
3632
+ }
3633
+ get_admin() {
3634
+ const offset = 4;
3635
+ const slice = this.buffer.subarray(offset, offset + 32);
3636
+ return Pubkey2.from_array(slice);
3637
+ }
3638
+ set_admin(value) {
3639
+ const sourceBytes = value.buffer;
3640
+ const offset = 4;
3641
+ this.buffer.set(sourceBytes, offset);
3642
+ }
3643
+ get admin() {
3644
+ return this.get_admin();
3645
+ }
3646
+ set admin(value) {
3647
+ this.set_admin(value);
3648
+ }
3649
+ get_target() {
3650
+ const offset = 36;
3651
+ const slice = this.buffer.subarray(offset, offset + 32);
3652
+ return Pubkey2.from_array(slice);
3653
+ }
3654
+ set_target(value) {
3655
+ const sourceBytes = value.buffer;
3656
+ const offset = 36;
3657
+ this.buffer.set(sourceBytes, offset);
3658
+ }
3659
+ get target() {
3660
+ return this.get_target();
3661
+ }
3662
+ set target(value) {
3663
+ this.set_target(value);
3664
+ }
3665
+ get_policy_id() {
3666
+ const offset = 68;
3667
+ return this.view.getBigUint64(offset, true);
3668
+ }
3669
+ set_policy_id(value) {
3670
+ const offset = 68;
3671
+ this.view.setBigUint64(offset, value, true);
3672
+ }
3673
+ get policy_id() {
3674
+ return this.get_policy_id();
3675
+ }
3676
+ set policy_id(value) {
3677
+ this.set_policy_id(value);
3678
+ }
3679
+ get_config() {
3680
+ const offset = 76;
3681
+ const slice = this.buffer.subarray(offset, offset + 309);
3682
+ return RatelimitConfig.from_array(slice);
3683
+ }
3684
+ set_config(value) {
3685
+ const sourceBytes = value.buffer;
3686
+ const offset = 76;
3687
+ this.buffer.set(sourceBytes, offset);
3688
+ }
3689
+ get config() {
3690
+ return this.get_config();
3691
+ }
3692
+ set config(value) {
3693
+ this.set_config(value);
3694
+ }
3695
+ get_proof_sz() {
3696
+ const offset = 385;
3697
+ return this.view.getUint16(offset, true);
3698
+ }
3699
+ set_proof_sz(value) {
3700
+ const offset = 385;
3701
+ this.view.setUint16(offset, value, true);
3702
+ }
3703
+ get proof_sz() {
3704
+ return this.get_proof_sz();
3705
+ }
3706
+ set proof_sz(value) {
3707
+ this.set_proof_sz(value);
3708
+ }
3709
+ get_proof_length() {
3710
+ return this.__tnResolveFieldRef("proof_sz");
3711
+ }
3712
+ get_proof_at(index) {
3713
+ const offset = 387;
3714
+ return this.view.getUint8(offset + index * 1);
3715
+ }
3716
+ get_proof() {
3717
+ const len = this.get_proof_length();
3718
+ const result = [];
3719
+ for (let i = 0; i < len; i++) {
3720
+ result.push(this.get_proof_at(i));
3721
+ }
3722
+ return result;
3723
+ }
3724
+ set_proof_at(index, value) {
3725
+ const offset = 387;
3726
+ this.view.setUint8(offset + index * 1, value);
3727
+ }
3728
+ set_proof(value) {
3729
+ const len = Math.min(this.get_proof_length(), value.length);
3730
+ for (let i = 0; i < len; i++) {
3731
+ this.set_proof_at(i, value[i]);
3732
+ }
3733
+ }
3734
+ get proof() {
3735
+ return this.get_proof();
3736
+ }
3737
+ set proof(value) {
3738
+ this.set_proof(value);
3739
+ }
3740
+ static __tnFootprintInternal(__tnParams) {
3741
+ return __tnEvalFootprint(__tn_ir_CreatePolicyArgs.root, { params: __tnParams });
3742
+ }
3743
+ static __tnValidateInternal(buffer, __tnParams) {
3744
+ return __tnValidateIrTree(__tn_ir_CreatePolicyArgs, buffer, __tnParams);
3745
+ }
3746
+ static __tnInvokeFootprint(__tnParams) {
3747
+ return this.__tnFootprintInternal(__tnParams);
3748
+ }
3749
+ static __tnInvokeValidate(buffer, __tnParams) {
3750
+ return this.__tnValidateInternal(buffer, __tnParams);
3751
+ }
3752
+ static footprintIr(proof_proof_sz) {
3753
+ const params = _CreatePolicyArgs.Params.fromValues({
3754
+ proof_proof_sz
3755
+ });
3756
+ return this.footprintIrFromParams(params);
3757
+ }
3758
+ static __tnPackParams(params) {
3759
+ const record = /* @__PURE__ */ Object.create(null);
3760
+ record["proof.proof_sz"] = params.proof_proof_sz;
3761
+ return record;
3762
+ }
3763
+ static footprintIrFromParams(params) {
3764
+ const __tnParams = this.__tnPackParams(params);
3765
+ return this.__tnFootprintInternal(__tnParams);
3766
+ }
3767
+ static footprintFromParams(params) {
3768
+ const irResult = this.footprintIrFromParams(params);
3769
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
3770
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for CreatePolicyArgs");
3771
+ return __tnBigIntToNumber(irResult, "CreatePolicyArgs::footprintFromParams");
3772
+ }
3773
+ static footprintFromValues(input) {
3774
+ const params = _CreatePolicyArgs.params(input);
3775
+ return this.footprintFromParams(params);
3776
+ }
3777
+ static footprint(params) {
3778
+ return this.footprintFromParams(params);
3779
+ }
3780
+ static validate(buffer, opts) {
3781
+ if (!buffer || buffer.length === void 0) {
3782
+ return { ok: false, code: "tn.invalid_buffer" };
3783
+ }
3784
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3785
+ let params = opts?.params ?? null;
3786
+ if (!params) {
3787
+ const extracted = this.__tnExtractParams(view, buffer);
3788
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
3789
+ params = extracted.params;
3790
+ }
3791
+ const __tnParamsRec = this.__tnPackParams(params);
3792
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
3793
+ if (!irResult.ok) {
3794
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "CreatePolicyArgs::validate") : void 0, params };
3795
+ }
3796
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "CreatePolicyArgs::validate") : void 0;
3797
+ return { ok: true, consumed, params };
3798
+ }
3799
+ static from_array(buffer, opts) {
3800
+ if (!buffer || buffer.length === void 0) {
3801
+ return null;
3802
+ }
3803
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3804
+ let params = opts?.params ?? null;
3805
+ if (!params) {
3806
+ const derived = this.__tnExtractParams(view, buffer);
3807
+ if (!derived) return null;
3808
+ params = derived.params;
3809
+ }
3810
+ const validation = this.validate(buffer, { params });
3811
+ if (!validation.ok) {
3812
+ return null;
3813
+ }
3814
+ const cached = validation.params ?? params;
3815
+ const state = new _CreatePolicyArgs(buffer, cached);
3816
+ return state;
3817
+ }
3818
+ };
3819
+ _CreatePolicyArgs.flexibleArrayWriters = Object.freeze([
3820
+ { field: "proof", method: "proof", sizeField: "proof_sz", paramKey: "proof_sz", elementSize: 1 }
3821
+ ]);
3822
+ var CreatePolicyArgs = _CreatePolicyArgs;
3823
+ ((CreatePolicyArgs2) => {
3824
+ CreatePolicyArgs2.ParamKeys = Object.freeze({
3825
+ proof_proof_sz: "proof.proof_sz"
3826
+ });
3827
+ CreatePolicyArgs2.Params = {
3828
+ fromValues(input) {
3829
+ return {
3830
+ proof_proof_sz: __tnToBigInt(input.proof_proof_sz)
3831
+ };
3832
+ },
3833
+ fromBuilder(source) {
3834
+ if (source.dynamicParams) {
3835
+ return source.dynamicParams();
3836
+ }
3837
+ if (source.params) {
3838
+ return source.params;
3839
+ }
3840
+ return source;
3841
+ }
3842
+ };
3843
+ function params(input) {
3844
+ return CreatePolicyArgs2.Params.fromValues(input);
3845
+ }
3846
+ CreatePolicyArgs2.params = params;
3847
+ })(CreatePolicyArgs || (CreatePolicyArgs = {}));
3848
+ var CreatePolicyArgsBuilder = class {
3849
+ constructor() {
3850
+ this.__tnCachedParams = null;
3851
+ this.__tnLastBuffer = null;
3852
+ this.__tnLastParams = null;
3853
+ this.__tnFam_proof = null;
3854
+ this.__tnFam_proofCount = null;
3855
+ this.buffer = new Uint8Array(387);
3856
+ this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
3857
+ }
3858
+ __tnInvalidate() {
3859
+ this.__tnCachedParams = null;
3860
+ this.__tnLastBuffer = null;
3861
+ this.__tnLastParams = null;
3862
+ }
3863
+ set_policy_account_idx(value) {
3864
+ this.view.setUint16(0, value, true);
3865
+ this.__tnInvalidate();
3866
+ return this;
3867
+ }
3868
+ set_meta_account_idx(value) {
3869
+ this.view.setUint16(2, value, true);
3870
+ this.__tnInvalidate();
3871
+ return this;
3872
+ }
3873
+ set_admin(value) {
3874
+ if (value.length !== 32) throw new Error("admin expects 32 bytes");
3875
+ this.buffer.set(value, 4);
3876
+ this.__tnInvalidate();
3877
+ return this;
3878
+ }
3879
+ set_target(value) {
3880
+ if (value.length !== 32) throw new Error("target expects 32 bytes");
3881
+ this.buffer.set(value, 36);
3882
+ this.__tnInvalidate();
3883
+ return this;
3884
+ }
3885
+ set_policy_id(value) {
3886
+ const cast = __tnToBigInt(value);
3887
+ this.view.setBigUint64(68, cast, true);
3888
+ this.__tnInvalidate();
3889
+ return this;
3890
+ }
3891
+ set_config(value) {
3892
+ if (value.length !== 309) throw new Error("config expects 309 bytes");
3893
+ this.buffer.set(value, 76);
3894
+ this.__tnInvalidate();
3895
+ return this;
3896
+ }
3897
+ set_proof_sz(value) {
3898
+ this.view.setUint16(385, value, true);
3899
+ this.__tnInvalidate();
3900
+ return this;
3901
+ }
3902
+ proof() {
3903
+ if (!this.__tnFamWriter_proof) {
3904
+ this.__tnFamWriter_proof = __tnCreateFamWriter(this, "proof", (payload) => {
3905
+ const bytes2 = new Uint8Array(payload);
3906
+ const elementCount = bytes2.length;
3907
+ this.__tnFam_proof = bytes2;
3908
+ this.__tnFam_proofCount = elementCount;
3909
+ this.set_proof_sz(elementCount);
3910
+ this.__tnInvalidate();
3911
+ });
3912
+ }
3913
+ return this.__tnFamWriter_proof;
3914
+ }
3915
+ build() {
3916
+ const params = this.__tnComputeParams();
3917
+ const size = CreatePolicyArgs.footprintFromParams(params);
3918
+ const buffer = new Uint8Array(size);
3919
+ this.__tnWriteInto(buffer);
3920
+ this.__tnValidateOrThrow(buffer, params);
3921
+ return buffer;
3922
+ }
3923
+ buildInto(target, offset = 0) {
3924
+ const params = this.__tnComputeParams();
3925
+ const size = CreatePolicyArgs.footprintFromParams(params);
3926
+ if (target.length - offset < size) throw new Error("CreatePolicyArgsBuilder: target buffer too small");
3927
+ const slice = target.subarray(offset, offset + size);
3928
+ this.__tnWriteInto(slice);
3929
+ this.__tnValidateOrThrow(slice, params);
3930
+ return target;
3931
+ }
3932
+ finish() {
3933
+ const buffer = this.build();
3934
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
3935
+ const view = CreatePolicyArgs.from_array(buffer, { params });
3936
+ if (!view) throw new Error("CreatePolicyArgsBuilder: failed to finalize view");
3937
+ return view;
3938
+ }
3939
+ finishView() {
3940
+ return this.finish();
3941
+ }
3942
+ dynamicParams() {
3943
+ return this.__tnComputeParams();
3944
+ }
3945
+ __tnComputeParams() {
3946
+ if (this.__tnCachedParams) return this.__tnCachedParams;
3947
+ const params = CreatePolicyArgs.Params.fromValues({
3948
+ proof_proof_sz: (() => {
3949
+ if (this.__tnFam_proofCount === null) throw new Error("CreatePolicyArgsBuilder: field 'proof' must be written before computing params");
3950
+ return __tnToBigInt(this.__tnFam_proofCount);
3951
+ })()
3952
+ });
3953
+ this.__tnCachedParams = params;
3954
+ return params;
3955
+ }
3956
+ __tnWriteInto(target) {
3957
+ target.set(this.buffer, 0);
3958
+ let cursor = this.buffer.length;
3959
+ const __tnLocal_proof_bytes = this.__tnFam_proof;
3960
+ if (!__tnLocal_proof_bytes) throw new Error("CreatePolicyArgsBuilder: field 'proof' must be written before build");
3961
+ target.set(__tnLocal_proof_bytes, cursor);
3962
+ cursor += __tnLocal_proof_bytes.length;
3963
+ }
3964
+ __tnValidateOrThrow(buffer, params) {
3965
+ const result = CreatePolicyArgs.validate(buffer, { params });
3966
+ if (!result.ok) {
3967
+ throw new Error(`${CreatePolicyArgs}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
3968
+ }
3969
+ this.__tnLastParams = result.params ?? params;
3970
+ this.__tnLastBuffer = buffer;
3971
+ }
3972
+ };
3973
+ __tnRegisterFootprint("CreatePolicyArgs", (params) => CreatePolicyArgs.__tnInvokeFootprint(params));
3974
+ __tnRegisterValidate("CreatePolicyArgs", (buffer, params) => CreatePolicyArgs.__tnInvokeValidate(buffer, params));
3975
+ __tnRegisterDynamicValidate("CreatePolicyArgs", (buffer) => {
3976
+ const result = CreatePolicyArgs.validate(buffer);
3977
+ const params = result.params;
3978
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
3979
+ });
3980
+ var __tn_ir_RatelimitAccount = {
3981
+ typeName: "RatelimitAccount",
3982
+ root: { op: "align", alignment: 1, node: { op: "align", alignment: 1, node: { op: "switch", tag: "RatelimitAccount::data.payload_size", cases: [{ value: 390, node: { op: "align", alignment: 1, node: { op: "const", value: 390n } } }, { value: 113, node: { op: "align", alignment: 1, node: { op: "const", value: 113n } } }, { value: 40, node: { op: "align", alignment: 1, node: { op: "const", value: 40n } } }] } } }
3983
+ };
3984
+ var RatelimitAccount = class _RatelimitAccount {
3985
+ constructor(buffer, params) {
3986
+ this.buffer = buffer;
3987
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
3988
+ if (params) {
3989
+ this.__tnParams = params;
3990
+ } else {
3991
+ const derived = _RatelimitAccount.__tnExtractParams(this.view, buffer);
3992
+ if (!derived) {
3993
+ throw new Error("RatelimitAccount: failed to derive dynamic parameters");
3994
+ }
3995
+ this.__tnParams = derived.params;
3996
+ }
3997
+ }
3998
+ static __tnCreateView(buffer, opts) {
3999
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitAccount.__tnCreateView requires a Uint8Array");
4000
+ let params = opts?.params ?? null;
4001
+ if (!params) {
4002
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4003
+ const derived = _RatelimitAccount.__tnExtractParams(view, buffer);
4004
+ if (!derived) throw new Error("RatelimitAccount.__tnCreateView: failed to derive params");
4005
+ params = derived.params;
4006
+ }
4007
+ const instance = new _RatelimitAccount(new Uint8Array(buffer), params);
4008
+ return instance;
4009
+ }
4010
+ dynamicParams() {
4011
+ return this.__tnParams;
4012
+ }
4013
+ static __tnComputeSequentialLayout(view, buffer) {
4014
+ const __tnLength = buffer.length;
4015
+ let __tnParamSeq_data_payload_size = null;
4016
+ let __tnCursorMutable = 0;
4017
+ const __tnSduAvailable_data = __tnLength - __tnCursorMutable;
4018
+ let __tnSduSize_data = -1;
4019
+ switch (__tnSduAvailable_data) {
4020
+ case 390:
4021
+ __tnSduSize_data = 390;
4022
+ break;
4023
+ case 113:
4024
+ __tnSduSize_data = 113;
4025
+ break;
4026
+ case 40:
4027
+ __tnSduSize_data = 40;
4028
+ break;
4029
+ default:
4030
+ return null;
4031
+ }
4032
+ __tnParamSeq_data_payload_size = __tnToBigInt(__tnSduSize_data);
4033
+ __tnCursorMutable += __tnSduSize_data;
4034
+ const params = /* @__PURE__ */ Object.create(null);
4035
+ if (__tnParamSeq_data_payload_size === null) return null;
4036
+ params["data_payload_size"] = __tnParamSeq_data_payload_size;
4037
+ return { params, offsets: null, derived: null };
4038
+ }
4039
+ static __tnExtractParams(view, buffer) {
4040
+ const __tnLayout = _RatelimitAccount.__tnComputeSequentialLayout(view, buffer);
4041
+ if (!__tnLayout || !__tnLayout.params) return null;
4042
+ const __tnSeqParams = __tnLayout.params;
4043
+ const __tnParamSeq_data_payload_size = __tnSeqParams["data_payload_size"];
4044
+ if (__tnParamSeq_data_payload_size === void 0) return null;
4045
+ const __tnExtractedParams = _RatelimitAccount.Params.fromValues({
4046
+ data_payload_size: __tnParamSeq_data_payload_size
4047
+ });
4048
+ return { params: __tnExtractedParams, derived: null };
4049
+ }
4050
+ static __tnFootprintInternal(__tnParams) {
4051
+ return __tnEvalFootprint(__tn_ir_RatelimitAccount.root, { params: __tnParams });
4052
+ }
4053
+ static __tnValidateInternal(buffer, __tnParams) {
4054
+ return __tnValidateIrTree(__tn_ir_RatelimitAccount, buffer, __tnParams);
4055
+ }
4056
+ static __tnInvokeFootprint(__tnParams) {
4057
+ return this.__tnFootprintInternal(__tnParams);
4058
+ }
4059
+ static __tnInvokeValidate(buffer, __tnParams) {
4060
+ return this.__tnValidateInternal(buffer, __tnParams);
4061
+ }
4062
+ static footprintIr(data_payload_size) {
4063
+ const params = _RatelimitAccount.Params.fromValues({
4064
+ data_payload_size
4065
+ });
4066
+ return this.footprintIrFromParams(params);
4067
+ }
4068
+ static __tnPackParams(params) {
4069
+ const record = /* @__PURE__ */ Object.create(null);
4070
+ record["data.payload_size"] = params.data_payload_size;
4071
+ record["RatelimitAccount::data.payload_size"] = params.data_payload_size;
4072
+ return record;
4073
+ }
4074
+ static footprintIrFromParams(params) {
4075
+ const __tnParams = this.__tnPackParams(params);
4076
+ return this.__tnFootprintInternal(__tnParams);
4077
+ }
4078
+ static footprintFromParams(params) {
4079
+ const irResult = this.footprintIrFromParams(params);
4080
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
4081
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitAccount");
4082
+ return __tnBigIntToNumber(irResult, "RatelimitAccount::footprintFromParams");
4083
+ }
4084
+ static footprintFromValues(input) {
4085
+ const params = _RatelimitAccount.params(input);
4086
+ return this.footprintFromParams(params);
4087
+ }
4088
+ static footprint(params) {
4089
+ return this.footprintFromParams(params);
4090
+ }
4091
+ static validate(buffer, opts) {
4092
+ if (!buffer || buffer.length === void 0) {
4093
+ return { ok: false, code: "tn.invalid_buffer" };
4094
+ }
4095
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4096
+ let params = opts?.params ?? null;
4097
+ if (!params) {
4098
+ const extracted = this.__tnExtractParams(view, buffer);
4099
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
4100
+ params = extracted.params;
4101
+ }
4102
+ const __tnParamsRec = this.__tnPackParams(params);
4103
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
4104
+ if (!irResult.ok) {
4105
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "RatelimitAccount::validate") : void 0, params };
4106
+ }
4107
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "RatelimitAccount::validate") : void 0;
4108
+ return { ok: true, consumed, params };
4109
+ }
4110
+ static from_array(buffer, opts) {
4111
+ if (!buffer || buffer.length === void 0) {
4112
+ return null;
4113
+ }
4114
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4115
+ let params = opts?.params ?? null;
4116
+ if (!params) {
4117
+ const derived = this.__tnExtractParams(view, buffer);
4118
+ if (!derived) return null;
4119
+ params = derived.params;
4120
+ }
4121
+ const validation = this.validate(buffer, { params });
4122
+ if (!validation.ok) {
4123
+ return null;
4124
+ }
4125
+ const cached = validation.params ?? params;
4126
+ const state = new _RatelimitAccount(buffer, cached);
4127
+ return state;
4128
+ }
4129
+ };
4130
+ ((RatelimitAccount2) => {
4131
+ RatelimitAccount2.ParamKeys = Object.freeze({
4132
+ data_payload_size: "data.payload_size"
4133
+ });
4134
+ RatelimitAccount2.Params = {
4135
+ fromValues(input) {
4136
+ return {
4137
+ data_payload_size: __tnToBigInt(input.data_payload_size)
4138
+ };
4139
+ },
4140
+ fromBuilder(source) {
4141
+ if (source.dynamicParams) {
4142
+ return source.dynamicParams();
4143
+ }
4144
+ if (source.params) {
4145
+ return source.params;
4146
+ }
4147
+ return source;
4148
+ }
4149
+ };
4150
+ function params(input) {
4151
+ return RatelimitAccount2.Params.fromValues(input);
4152
+ }
4153
+ RatelimitAccount2.params = params;
4154
+ })(RatelimitAccount || (RatelimitAccount = {}));
4155
+ __tnRegisterFootprint("RatelimitAccount", (params) => RatelimitAccount.__tnInvokeFootprint(params));
4156
+ __tnRegisterValidate("RatelimitAccount", (buffer, params) => RatelimitAccount.__tnInvokeValidate(buffer, params));
4157
+ __tnRegisterDynamicValidate("RatelimitAccount", (buffer) => {
4158
+ const result = RatelimitAccount.validate(buffer);
4159
+ const params = result.params;
4160
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
4161
+ });
4162
+ var __tn_ir_RatelimitInstruction = {
4163
+ typeName: "RatelimitInstruction",
4164
+ 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" } } } }
4165
+ };
4166
+ var RatelimitInstruction_payload_Inner = class _RatelimitInstruction_payload_Inner {
4167
+ constructor(buffer, descriptor, fieldContext) {
4168
+ this.buffer = buffer;
4169
+ this.descriptor = descriptor;
4170
+ this.__tnFieldContext = null;
4171
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4172
+ this.__tnFieldContext = fieldContext ?? null;
4173
+ }
4174
+ static __tnCreate(payload, descriptor, fieldContext) {
4175
+ return new _RatelimitInstruction_payload_Inner(new Uint8Array(payload), descriptor, fieldContext);
4176
+ }
4177
+ bytes() {
4178
+ return new Uint8Array(this.buffer);
4179
+ }
4180
+ variant() {
4181
+ return this.descriptor;
4182
+ }
4183
+ asCreatePolicy() {
4184
+ if (!this.descriptor || this.descriptor.tag !== 0) return null;
4185
+ return CreatePolicyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
4186
+ }
4187
+ asUpdatePolicy() {
4188
+ if (!this.descriptor || this.descriptor.tag !== 1) return null;
4189
+ return UpdatePolicyArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
4190
+ }
4191
+ asSetAdmin() {
4192
+ if (!this.descriptor || this.descriptor.tag !== 2) return null;
4193
+ return SetAdminArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
4194
+ }
4195
+ asCreateAuthority() {
4196
+ if (!this.descriptor || this.descriptor.tag !== 3) return null;
4197
+ return CreateAuthorityArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
4198
+ }
4199
+ asCall() {
4200
+ if (!this.descriptor || this.descriptor.tag !== 4) return null;
4201
+ return CallArgs.__tnCreateView(new Uint8Array(this.buffer), { fieldContext: this.__tnFieldContext ?? void 0 });
4202
+ }
4203
+ };
4204
+ var _RatelimitInstruction = class _RatelimitInstruction {
4205
+ constructor(buffer, params) {
4206
+ this.buffer = buffer;
4207
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4208
+ if (params) {
4209
+ this.__tnParams = params;
4210
+ } else {
4211
+ const derived = _RatelimitInstruction.__tnExtractParams(this.view, buffer);
4212
+ if (!derived) {
4213
+ throw new Error("RatelimitInstruction: failed to derive dynamic parameters");
4214
+ }
4215
+ this.__tnParams = derived.params;
4216
+ }
4217
+ }
4218
+ static __tnCreateView(buffer, opts) {
4219
+ if (!buffer || buffer.length === void 0) throw new Error("RatelimitInstruction.__tnCreateView requires a Uint8Array");
4220
+ let params = opts?.params ?? null;
4221
+ if (!params) {
4222
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4223
+ const derived = _RatelimitInstruction.__tnExtractParams(view, buffer);
4224
+ if (!derived) throw new Error("RatelimitInstruction.__tnCreateView: failed to derive params");
4225
+ params = derived.params;
4226
+ }
4227
+ const instance = new _RatelimitInstruction(new Uint8Array(buffer), params);
4228
+ return instance;
4229
+ }
4230
+ dynamicParams() {
4231
+ return this.__tnParams;
4232
+ }
4233
+ static builder() {
4234
+ return new RatelimitInstructionBuilder();
4235
+ }
4236
+ static fromBuilder(builder) {
4237
+ const buffer = builder.build();
4238
+ const params = builder.dynamicParams();
4239
+ return _RatelimitInstruction.from_array(buffer, { params });
4240
+ }
4241
+ static __tnComputeSequentialLayout(view, buffer) {
4242
+ const __tnLength = buffer.length;
4243
+ let __tnParamSeq_payload_payload_size = null;
4244
+ let __tnFieldValue_tag = null;
4245
+ let __tnCursorMutable = 0;
4246
+ if (__tnCursorMutable + 4 > __tnLength) return null;
4247
+ const __tnRead_tag = view.getUint32(__tnCursorMutable, true);
4248
+ __tnFieldValue_tag = __tnRead_tag;
4249
+ __tnCursorMutable += 4;
4250
+ const __tnEnumTagValue_payload = __tnFieldValue_tag;
4251
+ if (__tnEnumTagValue_payload === null) return null;
4252
+ let __tnEnumSize_payload = 0;
4253
+ switch (Number(__tnEnumTagValue_payload)) {
4254
+ case 0:
4255
+ break;
4256
+ case 1:
4257
+ break;
4258
+ case 2:
4259
+ break;
4260
+ case 3:
4261
+ break;
4262
+ case 4:
4263
+ break;
4264
+ default:
4265
+ return null;
4266
+ }
4267
+ if (__tnCursorMutable > __tnLength) return null;
4268
+ __tnEnumSize_payload = __tnLength - __tnCursorMutable;
4269
+ __tnCursorMutable = __tnLength;
4270
+ __tnParamSeq_payload_payload_size = __tnToBigInt(__tnEnumSize_payload);
4271
+ const params = /* @__PURE__ */ Object.create(null);
4272
+ if (__tnParamSeq_payload_payload_size === null) return null;
4273
+ params["payload_payload_size"] = __tnParamSeq_payload_payload_size;
4274
+ return { params, offsets: null, derived: null };
4275
+ }
4276
+ static __tnExtractParams(view, buffer) {
4277
+ if (buffer.length < 4) {
4278
+ return null;
4279
+ }
4280
+ const __tnParam_payload_tag = __tnToBigInt(view.getUint32(0, true));
4281
+ const __tnLayout = _RatelimitInstruction.__tnComputeSequentialLayout(view, buffer);
4282
+ if (!__tnLayout || !__tnLayout.params) return null;
4283
+ const __tnSeqParams = __tnLayout.params;
4284
+ const __tnParamSeq_payload_payload_size = __tnSeqParams["payload_payload_size"];
4285
+ if (__tnParamSeq_payload_payload_size === void 0) return null;
4286
+ const __tnExtractedParams = _RatelimitInstruction.Params.fromValues({
4287
+ payload_payload_size: __tnParamSeq_payload_payload_size,
4288
+ payload_tag: __tnParam_payload_tag
4289
+ });
4290
+ return { params: __tnExtractedParams, derived: null };
4291
+ }
4292
+ get_tag() {
4293
+ const offset = 0;
4294
+ return this.view.getUint32(offset, true);
4295
+ }
4296
+ set_tag(value) {
4297
+ const offset = 0;
4298
+ this.view.setUint32(offset, value, true);
4299
+ }
4300
+ get tag() {
4301
+ return this.get_tag();
4302
+ }
4303
+ set tag(value) {
4304
+ this.set_tag(value);
4305
+ }
4306
+ payloadVariant() {
4307
+ const tag = this.view.getUint8(0);
4308
+ return _RatelimitInstruction.payloadVariantDescriptors.find((variant) => variant.tag === tag) ?? null;
4309
+ }
4310
+ payload() {
4311
+ const descriptor = this.payloadVariant();
4312
+ if (!descriptor) throw new Error("RatelimitInstruction: unknown payload variant");
4313
+ const offset = _RatelimitInstruction.__tnFieldOffset_payload;
4314
+ const remaining = this.buffer.length - offset;
4315
+ const payloadLength = descriptor.payloadSize ?? remaining;
4316
+ if (payloadLength < 0 || offset + payloadLength > this.buffer.length) throw new Error("RatelimitInstruction: payload exceeds buffer bounds");
4317
+ const slice = this.buffer.subarray(offset, offset + payloadLength);
4318
+ return RatelimitInstruction_payload_Inner.__tnCreate(slice, descriptor, void 0);
4319
+ }
4320
+ static __tnFootprintInternal(__tnParams) {
4321
+ return __tnEvalFootprint(__tn_ir_RatelimitInstruction.root, { params: __tnParams });
4322
+ }
4323
+ static __tnValidateInternal(buffer, __tnParams) {
4324
+ return __tnValidateIrTree(__tn_ir_RatelimitInstruction, buffer, __tnParams);
4325
+ }
4326
+ static __tnInvokeFootprint(__tnParams) {
4327
+ return this.__tnFootprintInternal(__tnParams);
4328
+ }
4329
+ static __tnInvokeValidate(buffer, __tnParams) {
4330
+ return this.__tnValidateInternal(buffer, __tnParams);
4331
+ }
4332
+ static footprintIr(payload_payload_size, payload_tag) {
4333
+ const params = _RatelimitInstruction.Params.fromValues({
4334
+ payload_payload_size,
4335
+ payload_tag
4336
+ });
4337
+ return this.footprintIrFromParams(params);
4338
+ }
4339
+ static __tnPackParams(params) {
4340
+ const record = /* @__PURE__ */ Object.create(null);
4341
+ record["payload.payload_size"] = params.payload_payload_size;
4342
+ record["payload.tag"] = params.payload_tag;
4343
+ return record;
4344
+ }
4345
+ static footprintIrFromParams(params) {
4346
+ const __tnParams = this.__tnPackParams(params);
4347
+ return this.__tnFootprintInternal(__tnParams);
4348
+ }
4349
+ static footprintFromParams(params) {
4350
+ const irResult = this.footprintIrFromParams(params);
4351
+ const maxSafe = __tnToBigInt(Number.MAX_SAFE_INTEGER);
4352
+ if (__tnBigIntGreaterThan(irResult, maxSafe)) throw new Error("footprint exceeds Number.MAX_SAFE_INTEGER for RatelimitInstruction");
4353
+ return __tnBigIntToNumber(irResult, "RatelimitInstruction::footprintFromParams");
4354
+ }
4355
+ static footprintFromValues(input) {
4356
+ const params = _RatelimitInstruction.params(input);
4357
+ return this.footprintFromParams(params);
4358
+ }
4359
+ static footprint(params) {
4360
+ return this.footprintFromParams(params);
4361
+ }
4362
+ static validate(buffer, opts) {
4363
+ if (!buffer || buffer.length === void 0) {
4364
+ return { ok: false, code: "tn.invalid_buffer" };
4365
+ }
4366
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4367
+ let params = opts?.params ?? null;
4368
+ if (!params) {
4369
+ const extracted = this.__tnExtractParams(view, buffer);
4370
+ if (!extracted) return { ok: false, code: "tn.param_extraction_failed" };
4371
+ params = extracted.params;
4372
+ }
4373
+ const __tnParamsRec = this.__tnPackParams(params);
4374
+ const irResult = this.__tnValidateInternal(buffer, __tnParamsRec);
4375
+ if (!irResult.ok) {
4376
+ return { ok: false, code: irResult.code, consumed: irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "RatelimitInstruction::validate") : void 0, params };
4377
+ }
4378
+ const consumed = irResult.consumed ? __tnBigIntToNumber(irResult.consumed, "RatelimitInstruction::validate") : void 0;
4379
+ return { ok: true, consumed, params };
4380
+ }
4381
+ static from_array(buffer, opts) {
4382
+ if (!buffer || buffer.length === void 0) {
4383
+ return null;
4384
+ }
4385
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4386
+ let params = opts?.params ?? null;
4387
+ if (!params) {
4388
+ const derived = this.__tnExtractParams(view, buffer);
4389
+ if (!derived) return null;
4390
+ params = derived.params;
4391
+ }
4392
+ const validation = this.validate(buffer, { params });
4393
+ if (!validation.ok) {
4394
+ return null;
4395
+ }
4396
+ const cached = validation.params ?? params;
4397
+ const state = new _RatelimitInstruction(buffer, cached);
4398
+ return state;
4399
+ }
4400
+ };
4401
+ _RatelimitInstruction.__tnFieldOffset_payload = 4;
4402
+ _RatelimitInstruction.payloadVariantDescriptors = Object.freeze([
4403
+ {
4404
+ name: "create_policy",
4405
+ tag: 0,
4406
+ payloadSize: null,
4407
+ payloadType: "RatelimitInstruction::payload::create_policy",
4408
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreatePolicyArgs)
4409
+ },
4410
+ {
4411
+ name: "update_policy",
4412
+ tag: 1,
4413
+ payloadSize: 311,
4414
+ payloadType: "RatelimitInstruction::payload::update_policy",
4415
+ createPayloadBuilder: () => __tnMaybeCallBuilder(UpdatePolicyArgs)
4416
+ },
4417
+ {
4418
+ name: "set_admin",
4419
+ tag: 2,
4420
+ payloadSize: 34,
4421
+ payloadType: "RatelimitInstruction::payload::set_admin",
4422
+ createPayloadBuilder: () => __tnMaybeCallBuilder(SetAdminArgs)
4423
+ },
4424
+ {
4425
+ name: "create_authority",
4426
+ tag: 3,
4427
+ payloadSize: null,
4428
+ payloadType: "RatelimitInstruction::payload::create_authority",
4429
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CreateAuthorityArgs)
4430
+ },
4431
+ {
4432
+ name: "call",
4433
+ tag: 4,
4434
+ payloadSize: 8,
4435
+ payloadType: "RatelimitInstruction::payload::call",
4436
+ createPayloadBuilder: () => __tnMaybeCallBuilder(CallArgs)
4437
+ }
4438
+ ]);
4439
+ var RatelimitInstruction = _RatelimitInstruction;
4440
+ ((RatelimitInstruction2) => {
4441
+ RatelimitInstruction2.ParamKeys = Object.freeze({
4442
+ payload_payload_size: "payload.payload_size",
4443
+ payload_tag: "payload.tag"
4444
+ });
4445
+ RatelimitInstruction2.Params = {
4446
+ fromValues(input) {
4447
+ return {
4448
+ payload_payload_size: __tnToBigInt(input.payload_payload_size),
4449
+ payload_tag: __tnToBigInt(input.payload_tag)
4450
+ };
4451
+ },
4452
+ fromBuilder(source) {
4453
+ if (source.dynamicParams) {
4454
+ return source.dynamicParams();
4455
+ }
4456
+ if (source.params) {
4457
+ return source.params;
4458
+ }
4459
+ return source;
4460
+ }
4461
+ };
4462
+ function params(input) {
4463
+ return RatelimitInstruction2.Params.fromValues(input);
4464
+ }
4465
+ RatelimitInstruction2.params = params;
4466
+ })(RatelimitInstruction || (RatelimitInstruction = {}));
4467
+ var RatelimitInstructionBuilder = class {
4468
+ constructor() {
4469
+ this.__tnField_tag = null;
4470
+ this.__tnPayload_payload = null;
4471
+ this.__tnCachedParams = null;
4472
+ this.__tnLastBuffer = null;
4473
+ this.__tnLastParams = null;
4474
+ this.__tnPrefixBuffer = new Uint8Array(4);
4475
+ this.__tnPrefixView = new DataView(this.__tnPrefixBuffer.buffer, this.__tnPrefixBuffer.byteOffset, this.__tnPrefixBuffer.byteLength);
4476
+ }
4477
+ __tnInvalidate() {
4478
+ this.__tnCachedParams = null;
4479
+ this.__tnLastBuffer = null;
4480
+ this.__tnLastParams = null;
4481
+ }
4482
+ __tnAssign_tag(value) {
4483
+ this.__tnField_tag = value;
4484
+ this.__tnInvalidate();
4485
+ }
4486
+ set_tag(value) {
4487
+ this.__tnAssign_tag(value);
4488
+ return this;
4489
+ }
4490
+ payload() {
4491
+ if (!this.__tnVariantSelector_payload) {
4492
+ this.__tnVariantSelector_payload = __tnCreateVariantSelector(this, RatelimitInstruction.payloadVariantDescriptors, (descriptor, payload) => {
4493
+ this.__tnPayload_payload = { descriptor, bytes: new Uint8Array(payload) };
4494
+ this.__tnAssign_tag(descriptor.tag);
4495
+ });
4496
+ }
4497
+ return this.__tnVariantSelector_payload;
4498
+ }
4499
+ build() {
4500
+ const params = this.__tnComputeParams();
4501
+ if (this.__tnField_tag === null) throw new Error("RatelimitInstructionBuilder: field 'tag' must be set before build");
4502
+ if (!this.__tnPayload_payload) throw new Error("RatelimitInstructionBuilder: payload variant not selected");
4503
+ const payloadLength = this.__tnPayload_payload.bytes.length;
4504
+ const requiredSize = 4 + payloadLength;
4505
+ const footprintSize = RatelimitInstruction.footprintFromParams(params);
4506
+ const size = Math.max(requiredSize, footprintSize);
4507
+ const buffer = new Uint8Array(size);
4508
+ this.__tnWriteInto(buffer);
4509
+ this.__tnValidateOrThrow(buffer, params);
4510
+ return buffer;
4511
+ }
4512
+ buildInto(target, offset = 0) {
4513
+ const params = this.__tnComputeParams();
4514
+ if (this.__tnField_tag === null) throw new Error("RatelimitInstructionBuilder: field 'tag' must be set before build");
4515
+ if (!this.__tnPayload_payload) throw new Error("RatelimitInstructionBuilder: payload variant not selected");
4516
+ const payloadLength = this.__tnPayload_payload.bytes.length;
4517
+ const requiredSize = 4 + payloadLength;
4518
+ const footprintSize = RatelimitInstruction.footprintFromParams(params);
4519
+ const size = Math.max(requiredSize, footprintSize);
4520
+ if (target.length - offset < size) throw new Error("RatelimitInstructionBuilder: target buffer too small");
4521
+ const slice = target.subarray(offset, offset + size);
4522
+ this.__tnWriteInto(slice);
4523
+ this.__tnValidateOrThrow(slice, params);
4524
+ return target;
4525
+ }
4526
+ finish() {
4527
+ const buffer = this.build();
4528
+ const params = this.__tnLastParams ?? this.__tnComputeParams();
4529
+ const view = RatelimitInstruction.from_array(buffer, { params });
4530
+ if (!view) throw new Error("RatelimitInstructionBuilder: failed to finalize view");
4531
+ return view;
4532
+ }
4533
+ finishView() {
4534
+ return this.finish();
4535
+ }
4536
+ dynamicParams() {
4537
+ return this.__tnComputeParams();
4538
+ }
4539
+ __tnComputeParams() {
4540
+ if (this.__tnCachedParams) return this.__tnCachedParams;
4541
+ const params = RatelimitInstruction.Params.fromValues({
4542
+ payload_payload_size: (() => {
4543
+ if (!this.__tnPayload_payload) throw new Error("RatelimitInstructionBuilder: payload 'payload' must be selected before build");
4544
+ return __tnToBigInt(this.__tnPayload_payload.bytes.length);
4545
+ })(),
4546
+ payload_tag: (() => {
4547
+ if (this.__tnField_tag === null) throw new Error("RatelimitInstructionBuilder: missing enum tag");
4548
+ return __tnToBigInt(this.__tnField_tag);
4549
+ })()
4550
+ });
4551
+ this.__tnCachedParams = params;
4552
+ return params;
4553
+ }
4554
+ __tnWriteInto(target) {
4555
+ if (this.__tnField_tag === null) throw new Error("RatelimitInstructionBuilder: field 'tag' must be set before build");
4556
+ if (!this.__tnPayload_payload) throw new Error("RatelimitInstructionBuilder: payload variant not selected");
4557
+ const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
4558
+ target.set(this.__tnPrefixBuffer, 0);
4559
+ view.setUint32(0, this.__tnField_tag, true);
4560
+ target.set(this.__tnPayload_payload.bytes, 4);
4561
+ }
4562
+ __tnValidateOrThrow(buffer, params) {
4563
+ const result = RatelimitInstruction.validate(buffer, { params });
4564
+ if (!result.ok) {
4565
+ throw new Error(`${RatelimitInstruction}Builder: builder produced invalid buffer (code=${result.code ?? "unknown"})`);
4566
+ }
4567
+ this.__tnLastParams = result.params ?? params;
4568
+ this.__tnLastBuffer = buffer;
4569
+ }
4570
+ };
4571
+ __tnRegisterFootprint("RatelimitInstruction", (params) => RatelimitInstruction.__tnInvokeFootprint(params));
4572
+ __tnRegisterValidate("RatelimitInstruction", (buffer, params) => RatelimitInstruction.__tnInvokeValidate(buffer, params));
4573
+ __tnRegisterDynamicValidate("RatelimitInstruction", (buffer) => {
4574
+ const result = RatelimitInstruction.validate(buffer);
4575
+ const params = result.params;
4576
+ return { ok: result.ok, code: result.code, consumed: result.consumed === void 0 ? void 0 : __tnToBigInt(result.consumed), params };
4577
+ });
4578
+
4579
+ // src/ratelimit/instructions.ts
4580
+ var INT_SIZES = /* @__PURE__ */ new Set([0, 1, 2, 4, 8]);
4581
+ function u16(value, label) {
4582
+ if (!Number.isInteger(value) || value < 0 || value > 65535) throw new Error(`${label} must be a u16`);
4583
+ return value;
4584
+ }
4585
+ var U64_MAX = (1n << 64n) - 1n;
4586
+ function u64(value, label) {
4587
+ if (typeof value !== "bigint" || value < 0n || value > U64_MAX) throw new Error(`${label} must be a u64`);
4588
+ return value;
4589
+ }
4590
+ function u8(value, label) {
4591
+ if (!Number.isInteger(value) || value < 0 || value > 255) throw new Error(`${label} must be a u8`);
4592
+ return value;
4593
+ }
4594
+ function assertCreationProof(proof, label) {
4595
+ if (!proof.length || proof.length > 65535) throw new Error(`${label} creation proof must be 1..65535 bytes`);
4596
+ }
4597
+ function encodeRatelimitConfig(config) {
4598
+ const constraints = config.constraints ?? [];
4599
+ if (config.rules.length < 1 || config.rules.length > RATELIMIT_RULE_MAX) {
4600
+ throw new Error(`a policy needs 1..${RATELIMIT_RULE_MAX} rules`);
4601
+ }
4602
+ if (constraints.length > RATELIMIT_CONSTRAINT_MAX) {
4603
+ throw new Error(`a policy allows at most ${RATELIMIT_CONSTRAINT_MAX} constraints`);
4604
+ }
4605
+ if (!INT_SIZES.has(config.selectorSz) || !INT_SIZES.has(config.amountSz)) {
4606
+ throw new Error("selectorSz and amountSz must be 0, 1, 2, 4 or 8");
4607
+ }
4608
+ const rules = Array.from({ length: RATELIMIT_RULE_MAX }, (_, i) => {
4609
+ const rule = config.rules[i];
4610
+ const builder = new RatelimitRuleBuilder();
4611
+ if (rule) {
4612
+ if (u64(rule.window, `rule ${i} window`) === 0n) throw new Error(`rule ${i} window must be positive`);
4613
+ builder.set_key_kind(u8(rule.keyKind, "keyKind")).set_clock(u8(rule.clock, "clock")).set_key_offset(u16(rule.keyOffset ?? 0, "keyOffset")).set_window(rule.window).set_max_calls(u64(rule.maxCalls, `rule ${i} maxCalls`)).set_max_amount(u64(rule.maxAmount, `rule ${i} maxAmount`));
4614
+ }
4615
+ return builder.finish();
4616
+ });
4617
+ const constraintViews = Array.from({ length: RATELIMIT_CONSTRAINT_MAX }, (_, i) => {
4618
+ const constraint = constraints[i];
4619
+ const builder = new RatelimitConstraintBuilder();
4620
+ if (constraint) {
4621
+ builder.set_idx_offset(u16(constraint.idxOffset, "idxOffset")).set_expected((0, helpers_exports.pubkeyBytes)(constraint.expected, "constraint address"));
4622
+ }
4623
+ return builder.finish();
4624
+ });
4625
+ return new RatelimitConfigBuilder().set_flags(u8(config.flags ?? 0, "flags")).set_rule_cnt(config.rules.length).set_constraint_cnt(constraints.length).set_selector_sz(config.selectorSz).set_selector_offset(u16(config.selectorOffset, "selectorOffset")).set_selector_value(u64(config.selectorValue, "selectorValue")).set_instr_sz_min(u16(config.instrSzMin, "instrSzMin")).set_instr_sz_max(u16(config.instrSzMax, "instrSzMax")).set_amount_sz(config.amountSz).set_amount_offset(u16(config.amountOffset, "amountOffset")).set_max_amount_per_call(u64(config.maxAmountPerCall, "maxAmountPerCall")).set_attester(config.attester === void 0 ? new Uint8Array(32) : (0, helpers_exports.pubkeyBytes)(config.attester, "attester")).set_constraints(constraintViews).set_rules(rules).build();
4626
+ }
4627
+ function instruction(variant, payload) {
4628
+ const builder = new RatelimitInstructionBuilder();
4629
+ builder.payload().select(variant).writePayload(payload);
4630
+ return builder.build();
4631
+ }
4632
+ function buildCreateRatelimitPolicyInstruction(options) {
4633
+ assertCreationProof(options.proof, "policy");
4634
+ const args = new CreatePolicyArgsBuilder().set_policy_account_idx(u16(options.policyAccountIdx, "policyAccountIdx")).set_meta_account_idx(u16(options.metaAccountIdx ?? RATELIMIT_NO_ACCOUNT, "metaAccountIdx")).set_admin((0, helpers_exports.pubkeyBytes)(options.admin, "admin")).set_target((0, helpers_exports.pubkeyBytes)(options.target, "target")).set_policy_id(u64(options.policyId, "policyId")).set_config(encodeRatelimitConfig(options.config));
4635
+ args.proof().write(options.proof);
4636
+ return instruction("create_policy", args.build());
4637
+ }
4638
+ function buildUpdateRatelimitPolicyInstruction(policyAccountIdx, config) {
4639
+ return instruction("update_policy", new UpdatePolicyArgsBuilder().set_policy_account_idx(u16(policyAccountIdx, "policyAccountIdx")).set_config(encodeRatelimitConfig(config)).build());
4640
+ }
4641
+ function buildSetRatelimitAdminInstruction(policyAccountIdx, newAdmin) {
4642
+ return instruction("set_admin", new SetAdminArgsBuilder().set_policy_account_idx(u16(policyAccountIdx, "policyAccountIdx")).set_new_admin((0, helpers_exports.pubkeyBytes)(newAdmin, "new admin")).build());
4643
+ }
4644
+ function buildCreateRatelimitAuthorityInstruction(policyAccountIdx, authorityAccountIdx, proof) {
4645
+ assertCreationProof(proof, "authority");
4646
+ const args = new CreateAuthorityArgsBuilder().set_policy_account_idx(u16(policyAccountIdx, "policyAccountIdx")).set_authority_account_idx(u16(authorityAccountIdx, "authorityAccountIdx"));
4647
+ args.proof().write(proof);
4648
+ return instruction("create_authority", args.build());
4649
+ }
4650
+ function buildRatelimitCallInstruction(options) {
4651
+ if (options.buckets.length < 1 || options.buckets.length > RATELIMIT_RULE_MAX) {
4652
+ throw new Error(`CALL needs one bucket per policy rule (1..${RATELIMIT_RULE_MAX})`);
4653
+ }
4654
+ const header = new CallArgsBuilder().set_policy_account_idx(u16(options.policyAccountIdx, "policyAccountIdx")).set_target_account_idx(u16(options.targetAccountIdx, "targetAccountIdx")).set_authority_account_idx(u16(options.authorityAccountIdx ?? RATELIMIT_NO_ACCOUNT, "authorityAccountIdx")).set_inner_sz(u16(options.inner.length, "inner instruction size")).build();
4655
+ const entries = options.buckets.map((bucket) => new RatelimitCallBucketBuilder().set_bucket_account_idx(u16(bucket.bucketAccountIdx, "bucketAccountIdx")).set_proof_sz(u16(bucket.proof?.length ?? 0, "bucket proof size")).set_key(bucket.key === void 0 ? new Uint8Array(32) : (0, helpers_exports.pubkeyBytes)(bucket.key, "bucket key")).build());
4656
+ const proofs = options.buckets.flatMap((bucket) => bucket.proof?.length ? [bucket.proof] : []);
4657
+ const tag = new Uint8Array(4);
4658
+ new DataView(tag.buffer).setUint32(0, RATELIMIT_INSTRUCTION_CALL, true);
4659
+ return (0, helpers_exports.concatBytes)(tag, header, ...entries, ...proofs, options.inner);
4660
+ }
4661
+
4662
+ // src/ratelimit/accounts.ts
4663
+ var bytes = (pubkey) => Uint8Array.from(pubkey.get_bytes());
4664
+ var address = (pubkey) => (0, helpers_exports.pubkeyAddress)(bytes(pubkey));
4665
+ function decodeConfig(config) {
4666
+ return {
4667
+ flags: config.get_flags(),
4668
+ selectorSz: config.get_selector_sz(),
4669
+ selectorOffset: config.get_selector_offset(),
4670
+ selectorValue: config.get_selector_value(),
4671
+ instrSzMin: config.get_instr_sz_min(),
4672
+ instrSzMax: config.get_instr_sz_max(),
4673
+ amountSz: config.get_amount_sz(),
4674
+ amountOffset: config.get_amount_offset(),
4675
+ maxAmountPerCall: config.get_max_amount_per_call(),
4676
+ attester: bytes(config.get_attester()),
4677
+ constraints: config.get_constraints().slice(0, Math.min(config.get_constraint_cnt(), RATELIMIT_CONSTRAINT_MAX)).map((constraint) => ({
4678
+ idxOffset: constraint.get_idx_offset(),
4679
+ expected: address(constraint.get_expected())
4680
+ })),
4681
+ rules: config.get_rules().slice(0, Math.min(config.get_rule_cnt(), RATELIMIT_RULE_MAX)).map((rule) => ({
4682
+ keyKind: rule.get_key_kind(),
4683
+ clock: rule.get_clock(),
4684
+ keyOffset: rule.get_key_offset(),
4685
+ window: rule.get_window(),
4686
+ maxCalls: rule.get_max_calls(),
4687
+ maxAmount: rule.get_max_amount()
4688
+ }))
4689
+ };
4690
+ }
4691
+ function parseRatelimitPolicyAccount(data) {
4692
+ if (data.length !== RATELIMIT_POLICY_SIZE) return null;
4693
+ const policy = RatelimitPolicy.from_array(data);
4694
+ if (!policy || policy.get_magic() !== RATELIMIT_POLICY_MAGIC) return null;
4695
+ return {
4696
+ admin: address(policy.get_admin()),
4697
+ target: address(policy.get_target()),
4698
+ policyId: policy.get_policy_id(),
4699
+ stateFlags: policy.get_state_flags(),
4700
+ config: decodeConfig(policy.get_config()),
4701
+ configBytes: data.slice(RATELIMIT_POLICY_SIZE - RATELIMIT_CONFIG_SIZE)
4702
+ };
4703
+ }
4704
+ function parseRatelimitBucketAccount(data) {
4705
+ if (data.length !== RATELIMIT_BUCKET_SIZE) return null;
4706
+ const bucket = RatelimitBucket.from_array(data);
4707
+ if (!bucket || bucket.get_magic() !== RATELIMIT_BUCKET_MAGIC) return null;
4708
+ return {
4709
+ policy: address(bucket.get_policy()),
4710
+ key: bytes(bucket.get_key()),
4711
+ ruleIdx: bucket.get_rule_idx(),
4712
+ windowStart: bucket.get_window_start(),
4713
+ calls: bucket.get_calls(),
4714
+ amount: bucket.get_amount(),
4715
+ totalCalls: bucket.get_total_calls(),
4716
+ totalAmount: bucket.get_total_amount()
4717
+ };
4718
+ }
4719
+
4720
+ // src/ratelimit/index.ts
4721
+ var RATELIMIT_PROGRAM_ADDRESS = BOOTSTRAP_PROGRAM_ADDRESSES.ratelimit;
4722
+
4723
+ exports.RATELIMIT_BUCKET_MAGIC = RATELIMIT_BUCKET_MAGIC;
4724
+ exports.RATELIMIT_BUCKET_SIZE = RATELIMIT_BUCKET_SIZE;
4725
+ exports.RATELIMIT_CALL_ARGS_SIZE = RATELIMIT_CALL_ARGS_SIZE;
4726
+ exports.RATELIMIT_CALL_BUCKET_SIZE = RATELIMIT_CALL_BUCKET_SIZE;
4727
+ exports.RATELIMIT_CLOCK_SLOT = RATELIMIT_CLOCK_SLOT;
4728
+ exports.RATELIMIT_CLOCK_UNIX_SECONDS = RATELIMIT_CLOCK_UNIX_SECONDS;
4729
+ exports.RATELIMIT_CONFIG_SIZE = RATELIMIT_CONFIG_SIZE;
4730
+ exports.RATELIMIT_CONSTRAINT_MAX = RATELIMIT_CONSTRAINT_MAX;
4731
+ exports.RATELIMIT_ERRORS = RATELIMIT_ERRORS;
4732
+ exports.RATELIMIT_GLOBAL_KEY = RATELIMIT_GLOBAL_KEY;
4733
+ exports.RATELIMIT_INSTRUCTION_CALL = RATELIMIT_INSTRUCTION_CALL;
4734
+ exports.RATELIMIT_KEY_ATTESTED = RATELIMIT_KEY_ATTESTED;
4735
+ exports.RATELIMIT_KEY_FEE_PAYER = RATELIMIT_KEY_FEE_PAYER;
4736
+ exports.RATELIMIT_KEY_GLOBAL = RATELIMIT_KEY_GLOBAL;
4737
+ exports.RATELIMIT_KEY_INSTR_ACCOUNT = RATELIMIT_KEY_INSTR_ACCOUNT;
4738
+ exports.RATELIMIT_NO_ACCOUNT = RATELIMIT_NO_ACCOUNT;
4739
+ exports.RATELIMIT_POLICY_FLAG_PAUSED = RATELIMIT_POLICY_FLAG_PAUSED;
4740
+ exports.RATELIMIT_POLICY_FLAG_VERIFIED = RATELIMIT_POLICY_FLAG_VERIFIED;
4741
+ exports.RATELIMIT_POLICY_MAGIC = RATELIMIT_POLICY_MAGIC;
4742
+ exports.RATELIMIT_POLICY_SIZE = RATELIMIT_POLICY_SIZE;
4743
+ exports.RATELIMIT_PROGRAM_ADDRESS = RATELIMIT_PROGRAM_ADDRESS;
4744
+ exports.RATELIMIT_RULE_MAX = RATELIMIT_RULE_MAX;
4745
+ exports.buildCreateRatelimitAuthorityInstruction = buildCreateRatelimitAuthorityInstruction;
4746
+ exports.buildCreateRatelimitPolicyInstruction = buildCreateRatelimitPolicyInstruction;
4747
+ exports.buildRatelimitCallInstruction = buildRatelimitCallInstruction;
4748
+ exports.buildSetRatelimitAdminInstruction = buildSetRatelimitAdminInstruction;
4749
+ exports.buildUpdateRatelimitPolicyInstruction = buildUpdateRatelimitPolicyInstruction;
4750
+ exports.deriveRatelimitAuthorityAddress = deriveRatelimitAuthorityAddress;
4751
+ exports.deriveRatelimitBucketAddress = deriveRatelimitBucketAddress;
4752
+ exports.deriveRatelimitPolicyAddress = deriveRatelimitPolicyAddress;
4753
+ exports.encodeRatelimitConfig = encodeRatelimitConfig;
4754
+ exports.parseRatelimitBucketAccount = parseRatelimitBucketAccount;
4755
+ exports.parseRatelimitPolicyAccount = parseRatelimitPolicyAccount;
4756
+ //# sourceMappingURL=index.cjs.map
4757
+ //# sourceMappingURL=index.cjs.map