@smithii_io/mixoor 0.0.1

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/README.md +38 -0
  2. package/dist/src/index.js +1484 -0
  3. package/dist/src/index.js.map +1 -0
  4. package/dist/src/index.mjs +1363 -0
  5. package/dist/src/index.mjs.map +1 -0
  6. package/dist/types/src/generated/accounts/index.d.ts +11 -0
  7. package/dist/types/src/generated/accounts/index.d.ts.map +1 -0
  8. package/dist/types/src/generated/accounts/nullifierAccount.d.ts +33 -0
  9. package/dist/types/src/generated/accounts/nullifierAccount.d.ts.map +1 -0
  10. package/dist/types/src/generated/accounts/pool.d.ts +54 -0
  11. package/dist/types/src/generated/accounts/pool.d.ts.map +1 -0
  12. package/dist/types/src/generated/accounts/vault.d.ts +28 -0
  13. package/dist/types/src/generated/accounts/vault.d.ts.map +1 -0
  14. package/dist/types/src/generated/errors/index.d.ts +9 -0
  15. package/dist/types/src/generated/errors/index.d.ts.map +1 -0
  16. package/dist/types/src/generated/errors/mixoor.d.ts +46 -0
  17. package/dist/types/src/generated/errors/mixoor.d.ts.map +1 -0
  18. package/dist/types/src/generated/index.d.ts +13 -0
  19. package/dist/types/src/generated/index.d.ts.map +1 -0
  20. package/dist/types/src/generated/instructions/deposit.d.ts +88 -0
  21. package/dist/types/src/generated/instructions/deposit.d.ts.map +1 -0
  22. package/dist/types/src/generated/instructions/index.d.ts +11 -0
  23. package/dist/types/src/generated/instructions/index.d.ts.map +1 -0
  24. package/dist/types/src/generated/instructions/initializePool.d.ts +81 -0
  25. package/dist/types/src/generated/instructions/initializePool.d.ts.map +1 -0
  26. package/dist/types/src/generated/instructions/transfer.d.ts +120 -0
  27. package/dist/types/src/generated/instructions/transfer.d.ts.map +1 -0
  28. package/dist/types/src/generated/programs/index.d.ts +9 -0
  29. package/dist/types/src/generated/programs/index.d.ts.map +1 -0
  30. package/dist/types/src/generated/programs/mixoor.d.ts +34 -0
  31. package/dist/types/src/generated/programs/mixoor.d.ts.map +1 -0
  32. package/dist/types/src/generated/shared/index.d.ts +50 -0
  33. package/dist/types/src/generated/shared/index.d.ts.map +1 -0
  34. package/dist/types/src/generated/types/assetType.d.ts +17 -0
  35. package/dist/types/src/generated/types/assetType.d.ts.map +1 -0
  36. package/dist/types/src/generated/types/commitmentInserted.d.ts +18 -0
  37. package/dist/types/src/generated/types/commitmentInserted.d.ts.map +1 -0
  38. package/dist/types/src/generated/types/index.d.ts +11 -0
  39. package/dist/types/src/generated/types/index.d.ts.map +1 -0
  40. package/dist/types/src/generated/types/rootEntry.d.ts +20 -0
  41. package/dist/types/src/generated/types/rootEntry.d.ts.map +1 -0
  42. package/dist/types/src/index.d.ts +3 -0
  43. package/dist/types/src/index.d.ts.map +1 -0
  44. package/dist/types/src/utils/circuit.d.ts +32 -0
  45. package/dist/types/src/utils/circuit.d.ts.map +1 -0
  46. package/dist/types/src/utils/crypto.d.ts +4 -0
  47. package/dist/types/src/utils/crypto.d.ts.map +1 -0
  48. package/dist/types/src/utils/index.d.ts +5 -0
  49. package/dist/types/src/utils/index.d.ts.map +1 -0
  50. package/dist/types/src/utils/merkle.d.ts +33 -0
  51. package/dist/types/src/utils/merkle.d.ts.map +1 -0
  52. package/dist/types/src/utils/pda.d.ts +29 -0
  53. package/dist/types/src/utils/pda.d.ts.map +1 -0
  54. package/dist/types/test/_constants.d.ts +4 -0
  55. package/dist/types/test/_constants.d.ts.map +1 -0
  56. package/dist/types/test/_setup.d.ts +49 -0
  57. package/dist/types/test/_setup.d.ts.map +1 -0
  58. package/package.json +87 -0
@@ -0,0 +1,1363 @@
1
+ import { fixEncoderSize, getBytesEncoder, transformEncoder, getStructEncoder, getI64Encoder, getStructDecoder, fixDecoderSize, getI64Decoder, getBytesDecoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, getEnumEncoder, getEnumDecoder, getU32Encoder, getAddressEncoder, getU32Decoder, getAddressDecoder, getArrayEncoder, getU64Encoder, getU8Encoder, getArrayDecoder, getU64Decoder, getU8Decoder, containsBytes, isProgramError, getProgramDerivedAddress, AccountRole, upgradeRoleToSigner, isTransactionSigner as isTransactionSigner$1 } from '@solana/kit';
2
+ import { buildPoseidon } from 'circomlibjs';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import { groth16 } from 'snarkjs';
6
+ import { randomBytes as randomBytes$1 } from 'crypto';
7
+
8
+ // src/generated/accounts/nullifierAccount.ts
9
+ var NULLIFIER_ACCOUNT_DISCRIMINATOR = new Uint8Array([
10
+ 250,
11
+ 31,
12
+ 238,
13
+ 177,
14
+ 213,
15
+ 98,
16
+ 48,
17
+ 172
18
+ ]);
19
+ function getNullifierAccountDiscriminatorBytes() {
20
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
21
+ NULLIFIER_ACCOUNT_DISCRIMINATOR
22
+ );
23
+ }
24
+ function getNullifierAccountEncoder() {
25
+ return transformEncoder(
26
+ getStructEncoder([
27
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
28
+ ["nullifierHash", fixEncoderSize(getBytesEncoder(), 32)],
29
+ ["spentAt", getI64Encoder()]
30
+ ]),
31
+ (value) => ({ ...value, discriminator: NULLIFIER_ACCOUNT_DISCRIMINATOR })
32
+ );
33
+ }
34
+ function getNullifierAccountDecoder() {
35
+ return getStructDecoder([
36
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
37
+ ["nullifierHash", fixDecoderSize(getBytesDecoder(), 32)],
38
+ ["spentAt", getI64Decoder()]
39
+ ]);
40
+ }
41
+ function getNullifierAccountCodec() {
42
+ return combineCodec(
43
+ getNullifierAccountEncoder(),
44
+ getNullifierAccountDecoder()
45
+ );
46
+ }
47
+ function decodeNullifierAccount(encodedAccount) {
48
+ return decodeAccount(
49
+ encodedAccount,
50
+ getNullifierAccountDecoder()
51
+ );
52
+ }
53
+ async function fetchNullifierAccount(rpc, address, config) {
54
+ const maybeAccount = await fetchMaybeNullifierAccount(rpc, address, config);
55
+ assertAccountExists(maybeAccount);
56
+ return maybeAccount;
57
+ }
58
+ async function fetchMaybeNullifierAccount(rpc, address, config) {
59
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
60
+ return decodeNullifierAccount(maybeAccount);
61
+ }
62
+ async function fetchAllNullifierAccount(rpc, addresses, config) {
63
+ const maybeAccounts = await fetchAllMaybeNullifierAccount(
64
+ rpc,
65
+ addresses,
66
+ config
67
+ );
68
+ assertAccountsExist(maybeAccounts);
69
+ return maybeAccounts;
70
+ }
71
+ async function fetchAllMaybeNullifierAccount(rpc, addresses, config) {
72
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
73
+ return maybeAccounts.map(
74
+ (maybeAccount) => decodeNullifierAccount(maybeAccount)
75
+ );
76
+ }
77
+ function getNullifierAccountSize() {
78
+ return 48;
79
+ }
80
+ var AssetType = /* @__PURE__ */ ((AssetType2) => {
81
+ AssetType2[AssetType2["Sol"] = 0] = "Sol";
82
+ AssetType2[AssetType2["SplToken"] = 1] = "SplToken";
83
+ return AssetType2;
84
+ })(AssetType || {});
85
+ function getAssetTypeEncoder() {
86
+ return getEnumEncoder(AssetType);
87
+ }
88
+ function getAssetTypeDecoder() {
89
+ return getEnumDecoder(AssetType);
90
+ }
91
+ function getAssetTypeCodec() {
92
+ return combineCodec(getAssetTypeEncoder(), getAssetTypeDecoder());
93
+ }
94
+ function getCommitmentInsertedEncoder() {
95
+ return getStructEncoder([
96
+ ["commitment", fixEncoderSize(getBytesEncoder(), 32)],
97
+ ["leafIndex", getU32Encoder()],
98
+ ["pool", getAddressEncoder()]
99
+ ]);
100
+ }
101
+ function getCommitmentInsertedDecoder() {
102
+ return getStructDecoder([
103
+ ["commitment", fixDecoderSize(getBytesDecoder(), 32)],
104
+ ["leafIndex", getU32Decoder()],
105
+ ["pool", getAddressDecoder()]
106
+ ]);
107
+ }
108
+ function getCommitmentInsertedCodec() {
109
+ return combineCodec(
110
+ getCommitmentInsertedEncoder(),
111
+ getCommitmentInsertedDecoder()
112
+ );
113
+ }
114
+ function getRootEntryEncoder() {
115
+ return getStructEncoder([
116
+ ["root", fixEncoderSize(getBytesEncoder(), 32)],
117
+ ["timestamp", getI64Encoder()]
118
+ ]);
119
+ }
120
+ function getRootEntryDecoder() {
121
+ return getStructDecoder([
122
+ ["root", fixDecoderSize(getBytesDecoder(), 32)],
123
+ ["timestamp", getI64Decoder()]
124
+ ]);
125
+ }
126
+ function getRootEntryCodec() {
127
+ return combineCodec(getRootEntryEncoder(), getRootEntryDecoder());
128
+ }
129
+
130
+ // src/generated/accounts/pool.ts
131
+ var POOL_DISCRIMINATOR = new Uint8Array([
132
+ 241,
133
+ 154,
134
+ 109,
135
+ 4,
136
+ 17,
137
+ 177,
138
+ 109,
139
+ 188
140
+ ]);
141
+ function getPoolDiscriminatorBytes() {
142
+ return fixEncoderSize(getBytesEncoder(), 8).encode(POOL_DISCRIMINATOR);
143
+ }
144
+ function getPoolEncoder() {
145
+ return transformEncoder(
146
+ getStructEncoder([
147
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
148
+ ["authority", getAddressEncoder()],
149
+ ["mint", getAddressEncoder()],
150
+ ["vault", getAddressEncoder()],
151
+ ["feeCollector", getAddressEncoder()],
152
+ ["rootHistory", getArrayEncoder(getRootEntryEncoder(), { size: 30 })],
153
+ ["totalDeposited", getU64Encoder()],
154
+ ["totalWithdrawn", getU64Encoder()],
155
+ ["nextLeafIndex", getU32Encoder()],
156
+ ["assetType", getU8Encoder()],
157
+ ["rootHistoryIndex", getU8Encoder()],
158
+ ["bump", getU8Encoder()],
159
+ ["padding", fixEncoderSize(getBytesEncoder(), 1)]
160
+ ]),
161
+ (value) => ({ ...value, discriminator: POOL_DISCRIMINATOR })
162
+ );
163
+ }
164
+ function getPoolDecoder() {
165
+ return getStructDecoder([
166
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
167
+ ["authority", getAddressDecoder()],
168
+ ["mint", getAddressDecoder()],
169
+ ["vault", getAddressDecoder()],
170
+ ["feeCollector", getAddressDecoder()],
171
+ ["rootHistory", getArrayDecoder(getRootEntryDecoder(), { size: 30 })],
172
+ ["totalDeposited", getU64Decoder()],
173
+ ["totalWithdrawn", getU64Decoder()],
174
+ ["nextLeafIndex", getU32Decoder()],
175
+ ["assetType", getU8Decoder()],
176
+ ["rootHistoryIndex", getU8Decoder()],
177
+ ["bump", getU8Decoder()],
178
+ ["padding", fixDecoderSize(getBytesDecoder(), 1)]
179
+ ]);
180
+ }
181
+ function getPoolCodec() {
182
+ return combineCodec(getPoolEncoder(), getPoolDecoder());
183
+ }
184
+ function decodePool(encodedAccount) {
185
+ return decodeAccount(
186
+ encodedAccount,
187
+ getPoolDecoder()
188
+ );
189
+ }
190
+ async function fetchPool(rpc, address, config) {
191
+ const maybeAccount = await fetchMaybePool(rpc, address, config);
192
+ assertAccountExists(maybeAccount);
193
+ return maybeAccount;
194
+ }
195
+ async function fetchMaybePool(rpc, address, config) {
196
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
197
+ return decodePool(maybeAccount);
198
+ }
199
+ async function fetchAllPool(rpc, addresses, config) {
200
+ const maybeAccounts = await fetchAllMaybePool(rpc, addresses, config);
201
+ assertAccountsExist(maybeAccounts);
202
+ return maybeAccounts;
203
+ }
204
+ async function fetchAllMaybePool(rpc, addresses, config) {
205
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
206
+ return maybeAccounts.map((maybeAccount) => decodePool(maybeAccount));
207
+ }
208
+ function getPoolSize() {
209
+ return 1360;
210
+ }
211
+ var VAULT_DISCRIMINATOR = new Uint8Array([
212
+ 211,
213
+ 8,
214
+ 232,
215
+ 43,
216
+ 2,
217
+ 152,
218
+ 117,
219
+ 119
220
+ ]);
221
+ function getVaultDiscriminatorBytes() {
222
+ return fixEncoderSize(getBytesEncoder(), 8).encode(VAULT_DISCRIMINATOR);
223
+ }
224
+ function getVaultEncoder() {
225
+ return transformEncoder(
226
+ getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
227
+ (value) => ({ ...value, discriminator: VAULT_DISCRIMINATOR })
228
+ );
229
+ }
230
+ function getVaultDecoder() {
231
+ return getStructDecoder([
232
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)]
233
+ ]);
234
+ }
235
+ function getVaultCodec() {
236
+ return combineCodec(getVaultEncoder(), getVaultDecoder());
237
+ }
238
+ function decodeVault(encodedAccount) {
239
+ return decodeAccount(
240
+ encodedAccount,
241
+ getVaultDecoder()
242
+ );
243
+ }
244
+ async function fetchVault(rpc, address, config) {
245
+ const maybeAccount = await fetchMaybeVault(rpc, address, config);
246
+ assertAccountExists(maybeAccount);
247
+ return maybeAccount;
248
+ }
249
+ async function fetchMaybeVault(rpc, address, config) {
250
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
251
+ return decodeVault(maybeAccount);
252
+ }
253
+ async function fetchAllVault(rpc, addresses, config) {
254
+ const maybeAccounts = await fetchAllMaybeVault(rpc, addresses, config);
255
+ assertAccountsExist(maybeAccounts);
256
+ return maybeAccounts;
257
+ }
258
+ async function fetchAllMaybeVault(rpc, addresses, config) {
259
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
260
+ return maybeAccounts.map((maybeAccount) => decodeVault(maybeAccount));
261
+ }
262
+ function getVaultSize() {
263
+ return 8;
264
+ }
265
+ var MIXOOR_PROGRAM_ADDRESS = "mixmC791jTymqvJR2Zgvd8NAvXpXw99GdCW5uQcMBj8";
266
+ var MixoorAccount = /* @__PURE__ */ ((MixoorAccount2) => {
267
+ MixoorAccount2[MixoorAccount2["NullifierAccount"] = 0] = "NullifierAccount";
268
+ MixoorAccount2[MixoorAccount2["Pool"] = 1] = "Pool";
269
+ MixoorAccount2[MixoorAccount2["Vault"] = 2] = "Vault";
270
+ return MixoorAccount2;
271
+ })(MixoorAccount || {});
272
+ function identifyMixoorAccount(account) {
273
+ const data = "data" in account ? account.data : account;
274
+ if (containsBytes(
275
+ data,
276
+ fixEncoderSize(getBytesEncoder(), 8).encode(
277
+ new Uint8Array([250, 31, 238, 177, 213, 98, 48, 172])
278
+ ),
279
+ 0
280
+ )) {
281
+ return 0 /* NullifierAccount */;
282
+ }
283
+ if (containsBytes(
284
+ data,
285
+ fixEncoderSize(getBytesEncoder(), 8).encode(
286
+ new Uint8Array([241, 154, 109, 4, 17, 177, 109, 188])
287
+ ),
288
+ 0
289
+ )) {
290
+ return 1 /* Pool */;
291
+ }
292
+ if (containsBytes(
293
+ data,
294
+ fixEncoderSize(getBytesEncoder(), 8).encode(
295
+ new Uint8Array([211, 8, 232, 43, 2, 152, 117, 119])
296
+ ),
297
+ 0
298
+ )) {
299
+ return 2 /* Vault */;
300
+ }
301
+ throw new Error(
302
+ "The provided account could not be identified as a mixoor account."
303
+ );
304
+ }
305
+ var MixoorInstruction = /* @__PURE__ */ ((MixoorInstruction2) => {
306
+ MixoorInstruction2[MixoorInstruction2["Deposit"] = 0] = "Deposit";
307
+ MixoorInstruction2[MixoorInstruction2["InitializePool"] = 1] = "InitializePool";
308
+ MixoorInstruction2[MixoorInstruction2["Transfer"] = 2] = "Transfer";
309
+ return MixoorInstruction2;
310
+ })(MixoorInstruction || {});
311
+ function identifyMixoorInstruction(instruction) {
312
+ const data = "data" in instruction ? instruction.data : instruction;
313
+ if (containsBytes(
314
+ data,
315
+ fixEncoderSize(getBytesEncoder(), 8).encode(
316
+ new Uint8Array([242, 35, 198, 137, 82, 225, 242, 182])
317
+ ),
318
+ 0
319
+ )) {
320
+ return 0 /* Deposit */;
321
+ }
322
+ if (containsBytes(
323
+ data,
324
+ fixEncoderSize(getBytesEncoder(), 8).encode(
325
+ new Uint8Array([95, 180, 10, 172, 84, 174, 232, 40])
326
+ ),
327
+ 0
328
+ )) {
329
+ return 1 /* InitializePool */;
330
+ }
331
+ if (containsBytes(
332
+ data,
333
+ fixEncoderSize(getBytesEncoder(), 8).encode(
334
+ new Uint8Array([163, 52, 200, 231, 140, 3, 69, 186])
335
+ ),
336
+ 0
337
+ )) {
338
+ return 2 /* Transfer */;
339
+ }
340
+ throw new Error(
341
+ "The provided instruction could not be identified as a mixoor instruction."
342
+ );
343
+ }
344
+
345
+ // src/generated/errors/mixoor.ts
346
+ var MIXOOR_ERROR__INVALID_PROOF = 6e3;
347
+ var MIXOOR_ERROR__UNKNOWN_ROOT = 6001;
348
+ var MIXOOR_ERROR__INVALID_AMOUNT = 6002;
349
+ var MIXOOR_ERROR__INSUFFICIENT_FUNDS = 6003;
350
+ var MIXOOR_ERROR__MISSING_TOKEN_ACCOUNT = 6004;
351
+ var MIXOOR_ERROR__OVERFLOW = 6005;
352
+ var MIXOOR_ERROR__INVALID_PUBLIC_INPUTS = 6006;
353
+ var MIXOOR_ERROR__INVALID_ASSET_TYPE = 6007;
354
+ var MIXOOR_ERROR__INVALID_MERKLE_TREE_ADDRESS = 6008;
355
+ var MIXOOR_ERROR__INVALID_MERKLE_TREE = 6009;
356
+ var MIXOOR_ERROR__POSEIDON_HASH_ERROR = 6010;
357
+ var MIXOOR_ERROR__MERKLE_TREE_FULL = 6011;
358
+ var MIXOOR_ERROR__INVALID_MERKLE_PROOF = 6012;
359
+ var mixoorErrorMessages;
360
+ if (process.env.NODE_ENV !== "production") {
361
+ mixoorErrorMessages = {
362
+ [MIXOOR_ERROR__INSUFFICIENT_FUNDS]: `Insufficient funds`,
363
+ [MIXOOR_ERROR__INVALID_AMOUNT]: `Invalid amount`,
364
+ [MIXOOR_ERROR__INVALID_ASSET_TYPE]: `Invalid asset type deserialized`,
365
+ [MIXOOR_ERROR__INVALID_MERKLE_PROOF]: `Invalid merkle proof`,
366
+ [MIXOOR_ERROR__INVALID_MERKLE_TREE]: `Invalid merkle tree structure or out of bounds access`,
367
+ [MIXOOR_ERROR__INVALID_MERKLE_TREE_ADDRESS]: `Invalid merkle tree address`,
368
+ [MIXOOR_ERROR__INVALID_PROOF]: `Invalid proof`,
369
+ [MIXOOR_ERROR__INVALID_PUBLIC_INPUTS]: `Invalid number of public inputs`,
370
+ [MIXOOR_ERROR__MERKLE_TREE_FULL]: `Merkle tree is full`,
371
+ [MIXOOR_ERROR__MISSING_TOKEN_ACCOUNT]: `Missing token account`,
372
+ [MIXOOR_ERROR__OVERFLOW]: `Overflow`,
373
+ [MIXOOR_ERROR__POSEIDON_HASH_ERROR]: `Poseidon hash error`,
374
+ [MIXOOR_ERROR__UNKNOWN_ROOT]: `Unknown merkle root`
375
+ };
376
+ }
377
+ function getMixoorErrorMessage(code) {
378
+ if (process.env.NODE_ENV !== "production") {
379
+ return mixoorErrorMessages[code];
380
+ }
381
+ return "Error message not available in production bundles.";
382
+ }
383
+ function isMixoorError(error, transactionMessage, code) {
384
+ return isProgramError(
385
+ error,
386
+ transactionMessage,
387
+ MIXOOR_PROGRAM_ADDRESS,
388
+ code
389
+ );
390
+ }
391
+ function expectSome(value) {
392
+ if (value === null || value === void 0) {
393
+ throw new Error("Expected a value but received null or undefined.");
394
+ }
395
+ return value;
396
+ }
397
+ function expectAddress(value) {
398
+ if (!value) {
399
+ throw new Error("Expected a Address.");
400
+ }
401
+ if (typeof value === "object" && "address" in value) {
402
+ return value.address;
403
+ }
404
+ if (Array.isArray(value)) {
405
+ return value[0];
406
+ }
407
+ return value;
408
+ }
409
+ function getAccountMetaFactory(programAddress, optionalAccountStrategy) {
410
+ return (account) => {
411
+ if (!account.value) {
412
+ return Object.freeze({
413
+ address: programAddress,
414
+ role: AccountRole.READONLY
415
+ });
416
+ }
417
+ const writableRole = account.isWritable ? AccountRole.WRITABLE : AccountRole.READONLY;
418
+ return Object.freeze({
419
+ address: expectAddress(account.value),
420
+ role: isTransactionSigner(account.value) ? upgradeRoleToSigner(writableRole) : writableRole,
421
+ ...isTransactionSigner(account.value) ? { signer: account.value } : {}
422
+ });
423
+ };
424
+ }
425
+ function isTransactionSigner(value) {
426
+ return !!value && typeof value === "object" && "address" in value && isTransactionSigner$1(value);
427
+ }
428
+
429
+ // src/generated/instructions/deposit.ts
430
+ var DEPOSIT_DISCRIMINATOR = new Uint8Array([
431
+ 242,
432
+ 35,
433
+ 198,
434
+ 137,
435
+ 82,
436
+ 225,
437
+ 242,
438
+ 182
439
+ ]);
440
+ function getDepositDiscriminatorBytes() {
441
+ return fixEncoderSize(getBytesEncoder(), 8).encode(DEPOSIT_DISCRIMINATOR);
442
+ }
443
+ function getDepositInstructionDataEncoder() {
444
+ return transformEncoder(
445
+ getStructEncoder([
446
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
447
+ ["amount", getU64Encoder()],
448
+ ["commitment", fixEncoderSize(getBytesEncoder(), 32)],
449
+ ["newRoot", fixEncoderSize(getBytesEncoder(), 32)]
450
+ ]),
451
+ (value) => ({ ...value, discriminator: DEPOSIT_DISCRIMINATOR })
452
+ );
453
+ }
454
+ function getDepositInstructionDataDecoder() {
455
+ return getStructDecoder([
456
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
457
+ ["amount", getU64Decoder()],
458
+ ["commitment", fixDecoderSize(getBytesDecoder(), 32)],
459
+ ["newRoot", fixDecoderSize(getBytesDecoder(), 32)]
460
+ ]);
461
+ }
462
+ function getDepositInstructionDataCodec() {
463
+ return combineCodec(
464
+ getDepositInstructionDataEncoder(),
465
+ getDepositInstructionDataDecoder()
466
+ );
467
+ }
468
+ async function getDepositInstructionAsync(input, config) {
469
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
470
+ const originalAccounts = {
471
+ depositor: { value: input.depositor ?? null, isWritable: true },
472
+ pool: { value: input.pool ?? null, isWritable: true },
473
+ mint: { value: input.mint ?? null, isWritable: true },
474
+ vault: { value: input.vault ?? null, isWritable: true },
475
+ depositorTokenAccount: {
476
+ value: input.depositorTokenAccount ?? null,
477
+ isWritable: true
478
+ },
479
+ vaultTokenAccount: {
480
+ value: input.vaultTokenAccount ?? null,
481
+ isWritable: true
482
+ },
483
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
484
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
485
+ associatedTokenProgram: {
486
+ value: input.associatedTokenProgram ?? null,
487
+ isWritable: false
488
+ }
489
+ };
490
+ const accounts = originalAccounts;
491
+ const args = { ...input };
492
+ if (!accounts.vault.value) {
493
+ accounts.vault.value = await getProgramDerivedAddress({
494
+ programAddress,
495
+ seeds: [
496
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
497
+ getAddressEncoder().encode(expectAddress(accounts.pool.value))
498
+ ]
499
+ });
500
+ }
501
+ if (!accounts.systemProgram.value) {
502
+ accounts.systemProgram.value = "11111111111111111111111111111111";
503
+ }
504
+ if (!accounts.tokenProgram.value) {
505
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
506
+ }
507
+ if (!accounts.associatedTokenProgram.value) {
508
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
509
+ }
510
+ const getAccountMeta = getAccountMetaFactory(programAddress);
511
+ return Object.freeze({
512
+ accounts: [
513
+ getAccountMeta(accounts.depositor),
514
+ getAccountMeta(accounts.pool),
515
+ getAccountMeta(accounts.mint),
516
+ getAccountMeta(accounts.vault),
517
+ getAccountMeta(accounts.depositorTokenAccount),
518
+ getAccountMeta(accounts.vaultTokenAccount),
519
+ getAccountMeta(accounts.systemProgram),
520
+ getAccountMeta(accounts.tokenProgram),
521
+ getAccountMeta(accounts.associatedTokenProgram)
522
+ ],
523
+ data: getDepositInstructionDataEncoder().encode(
524
+ args
525
+ ),
526
+ programAddress
527
+ });
528
+ }
529
+ function getDepositInstruction(input, config) {
530
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
531
+ const originalAccounts = {
532
+ depositor: { value: input.depositor ?? null, isWritable: true },
533
+ pool: { value: input.pool ?? null, isWritable: true },
534
+ mint: { value: input.mint ?? null, isWritable: true },
535
+ vault: { value: input.vault ?? null, isWritable: true },
536
+ depositorTokenAccount: {
537
+ value: input.depositorTokenAccount ?? null,
538
+ isWritable: true
539
+ },
540
+ vaultTokenAccount: {
541
+ value: input.vaultTokenAccount ?? null,
542
+ isWritable: true
543
+ },
544
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
545
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
546
+ associatedTokenProgram: {
547
+ value: input.associatedTokenProgram ?? null,
548
+ isWritable: false
549
+ }
550
+ };
551
+ const accounts = originalAccounts;
552
+ const args = { ...input };
553
+ if (!accounts.systemProgram.value) {
554
+ accounts.systemProgram.value = "11111111111111111111111111111111";
555
+ }
556
+ if (!accounts.tokenProgram.value) {
557
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
558
+ }
559
+ if (!accounts.associatedTokenProgram.value) {
560
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
561
+ }
562
+ const getAccountMeta = getAccountMetaFactory(programAddress);
563
+ return Object.freeze({
564
+ accounts: [
565
+ getAccountMeta(accounts.depositor),
566
+ getAccountMeta(accounts.pool),
567
+ getAccountMeta(accounts.mint),
568
+ getAccountMeta(accounts.vault),
569
+ getAccountMeta(accounts.depositorTokenAccount),
570
+ getAccountMeta(accounts.vaultTokenAccount),
571
+ getAccountMeta(accounts.systemProgram),
572
+ getAccountMeta(accounts.tokenProgram),
573
+ getAccountMeta(accounts.associatedTokenProgram)
574
+ ],
575
+ data: getDepositInstructionDataEncoder().encode(
576
+ args
577
+ ),
578
+ programAddress
579
+ });
580
+ }
581
+ function parseDepositInstruction(instruction) {
582
+ if (instruction.accounts.length < 9) {
583
+ throw new Error("Not enough accounts");
584
+ }
585
+ let accountIndex = 0;
586
+ const getNextAccount = () => {
587
+ const accountMeta = instruction.accounts[accountIndex];
588
+ accountIndex += 1;
589
+ return accountMeta;
590
+ };
591
+ const getNextOptionalAccount = () => {
592
+ const accountMeta = getNextAccount();
593
+ return accountMeta.address === MIXOOR_PROGRAM_ADDRESS ? void 0 : accountMeta;
594
+ };
595
+ return {
596
+ programAddress: instruction.programAddress,
597
+ accounts: {
598
+ depositor: getNextAccount(),
599
+ pool: getNextAccount(),
600
+ mint: getNextAccount(),
601
+ vault: getNextAccount(),
602
+ depositorTokenAccount: getNextOptionalAccount(),
603
+ vaultTokenAccount: getNextOptionalAccount(),
604
+ systemProgram: getNextAccount(),
605
+ tokenProgram: getNextAccount(),
606
+ associatedTokenProgram: getNextAccount()
607
+ },
608
+ data: getDepositInstructionDataDecoder().decode(instruction.data)
609
+ };
610
+ }
611
+ var INITIALIZE_POOL_DISCRIMINATOR = new Uint8Array([
612
+ 95,
613
+ 180,
614
+ 10,
615
+ 172,
616
+ 84,
617
+ 174,
618
+ 232,
619
+ 40
620
+ ]);
621
+ function getInitializePoolDiscriminatorBytes() {
622
+ return fixEncoderSize(getBytesEncoder(), 8).encode(
623
+ INITIALIZE_POOL_DISCRIMINATOR
624
+ );
625
+ }
626
+ function getInitializePoolInstructionDataEncoder() {
627
+ return transformEncoder(
628
+ getStructEncoder([
629
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
630
+ ["assetType", getAssetTypeEncoder()]
631
+ ]),
632
+ (value) => ({ ...value, discriminator: INITIALIZE_POOL_DISCRIMINATOR })
633
+ );
634
+ }
635
+ function getInitializePoolInstructionDataDecoder() {
636
+ return getStructDecoder([
637
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
638
+ ["assetType", getAssetTypeDecoder()]
639
+ ]);
640
+ }
641
+ function getInitializePoolInstructionDataCodec() {
642
+ return combineCodec(
643
+ getInitializePoolInstructionDataEncoder(),
644
+ getInitializePoolInstructionDataDecoder()
645
+ );
646
+ }
647
+ async function getInitializePoolInstructionAsync(input, config) {
648
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
649
+ const originalAccounts = {
650
+ authority: { value: input.authority ?? null, isWritable: true },
651
+ pool: { value: input.pool ?? null, isWritable: true },
652
+ vault: { value: input.vault ?? null, isWritable: true },
653
+ vaultAta: { value: input.vaultAta ?? null, isWritable: true },
654
+ mint: { value: input.mint ?? null, isWritable: true },
655
+ feeCollector: { value: input.feeCollector ?? null, isWritable: false },
656
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
657
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
658
+ associatedTokenProgram: {
659
+ value: input.associatedTokenProgram ?? null,
660
+ isWritable: false
661
+ }
662
+ };
663
+ const accounts = originalAccounts;
664
+ const args = { ...input };
665
+ if (!accounts.pool.value) {
666
+ accounts.pool.value = await getProgramDerivedAddress({
667
+ programAddress,
668
+ seeds: [
669
+ getBytesEncoder().encode(new Uint8Array([112, 111, 111, 108])),
670
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
671
+ ]
672
+ });
673
+ }
674
+ if (!accounts.vault.value) {
675
+ accounts.vault.value = await getProgramDerivedAddress({
676
+ programAddress,
677
+ seeds: [
678
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
679
+ getAddressEncoder().encode(expectAddress(accounts.pool.value))
680
+ ]
681
+ });
682
+ }
683
+ if (!accounts.tokenProgram.value) {
684
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
685
+ }
686
+ if (!accounts.vaultAta.value) {
687
+ accounts.vaultAta.value = await getProgramDerivedAddress({
688
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
689
+ seeds: [
690
+ getAddressEncoder().encode(expectAddress(accounts.vault.value)),
691
+ getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
692
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
693
+ ]
694
+ });
695
+ }
696
+ if (!accounts.feeCollector.value) {
697
+ accounts.feeCollector.value = "5KgfWjGePnbFgDAuCqxB5oymuFxQskvCtrw6eYfDa7fj";
698
+ }
699
+ if (!accounts.systemProgram.value) {
700
+ accounts.systemProgram.value = "11111111111111111111111111111111";
701
+ }
702
+ if (!accounts.associatedTokenProgram.value) {
703
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
704
+ }
705
+ const getAccountMeta = getAccountMetaFactory(programAddress);
706
+ return Object.freeze({
707
+ accounts: [
708
+ getAccountMeta(accounts.authority),
709
+ getAccountMeta(accounts.pool),
710
+ getAccountMeta(accounts.vault),
711
+ getAccountMeta(accounts.vaultAta),
712
+ getAccountMeta(accounts.mint),
713
+ getAccountMeta(accounts.feeCollector),
714
+ getAccountMeta(accounts.systemProgram),
715
+ getAccountMeta(accounts.tokenProgram),
716
+ getAccountMeta(accounts.associatedTokenProgram)
717
+ ],
718
+ data: getInitializePoolInstructionDataEncoder().encode(
719
+ args
720
+ ),
721
+ programAddress
722
+ });
723
+ }
724
+ function getInitializePoolInstruction(input, config) {
725
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
726
+ const originalAccounts = {
727
+ authority: { value: input.authority ?? null, isWritable: true },
728
+ pool: { value: input.pool ?? null, isWritable: true },
729
+ vault: { value: input.vault ?? null, isWritable: true },
730
+ vaultAta: { value: input.vaultAta ?? null, isWritable: true },
731
+ mint: { value: input.mint ?? null, isWritable: true },
732
+ feeCollector: { value: input.feeCollector ?? null, isWritable: false },
733
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
734
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
735
+ associatedTokenProgram: {
736
+ value: input.associatedTokenProgram ?? null,
737
+ isWritable: false
738
+ }
739
+ };
740
+ const accounts = originalAccounts;
741
+ const args = { ...input };
742
+ if (!accounts.tokenProgram.value) {
743
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
744
+ }
745
+ if (!accounts.feeCollector.value) {
746
+ accounts.feeCollector.value = "5KgfWjGePnbFgDAuCqxB5oymuFxQskvCtrw6eYfDa7fj";
747
+ }
748
+ if (!accounts.systemProgram.value) {
749
+ accounts.systemProgram.value = "11111111111111111111111111111111";
750
+ }
751
+ if (!accounts.associatedTokenProgram.value) {
752
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
753
+ }
754
+ const getAccountMeta = getAccountMetaFactory(programAddress);
755
+ return Object.freeze({
756
+ accounts: [
757
+ getAccountMeta(accounts.authority),
758
+ getAccountMeta(accounts.pool),
759
+ getAccountMeta(accounts.vault),
760
+ getAccountMeta(accounts.vaultAta),
761
+ getAccountMeta(accounts.mint),
762
+ getAccountMeta(accounts.feeCollector),
763
+ getAccountMeta(accounts.systemProgram),
764
+ getAccountMeta(accounts.tokenProgram),
765
+ getAccountMeta(accounts.associatedTokenProgram)
766
+ ],
767
+ data: getInitializePoolInstructionDataEncoder().encode(
768
+ args
769
+ ),
770
+ programAddress
771
+ });
772
+ }
773
+ function parseInitializePoolInstruction(instruction) {
774
+ if (instruction.accounts.length < 9) {
775
+ throw new Error("Not enough accounts");
776
+ }
777
+ let accountIndex = 0;
778
+ const getNextAccount = () => {
779
+ const accountMeta = instruction.accounts[accountIndex];
780
+ accountIndex += 1;
781
+ return accountMeta;
782
+ };
783
+ return {
784
+ programAddress: instruction.programAddress,
785
+ accounts: {
786
+ authority: getNextAccount(),
787
+ pool: getNextAccount(),
788
+ vault: getNextAccount(),
789
+ vaultAta: getNextAccount(),
790
+ mint: getNextAccount(),
791
+ feeCollector: getNextAccount(),
792
+ systemProgram: getNextAccount(),
793
+ tokenProgram: getNextAccount(),
794
+ associatedTokenProgram: getNextAccount()
795
+ },
796
+ data: getInitializePoolInstructionDataDecoder().decode(instruction.data)
797
+ };
798
+ }
799
+ var TRANSFER_DISCRIMINATOR = new Uint8Array([
800
+ 163,
801
+ 52,
802
+ 200,
803
+ 231,
804
+ 140,
805
+ 3,
806
+ 69,
807
+ 186
808
+ ]);
809
+ function getTransferDiscriminatorBytes() {
810
+ return fixEncoderSize(getBytesEncoder(), 8).encode(TRANSFER_DISCRIMINATOR);
811
+ }
812
+ function getTransferInstructionDataEncoder() {
813
+ return transformEncoder(
814
+ getStructEncoder([
815
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
816
+ ["proofA", fixEncoderSize(getBytesEncoder(), 64)],
817
+ ["proofB", fixEncoderSize(getBytesEncoder(), 128)],
818
+ ["proofC", fixEncoderSize(getBytesEncoder(), 64)],
819
+ [
820
+ "publicInputs",
821
+ getArrayEncoder(fixEncoderSize(getBytesEncoder(), 32), { size: 7 })
822
+ ],
823
+ ["nullifierHash", fixEncoderSize(getBytesEncoder(), 32)],
824
+ ["amount", getU64Encoder()],
825
+ ["fee", getU64Encoder()]
826
+ ]),
827
+ (value) => ({ ...value, discriminator: TRANSFER_DISCRIMINATOR })
828
+ );
829
+ }
830
+ function getTransferInstructionDataDecoder() {
831
+ return getStructDecoder([
832
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
833
+ ["proofA", fixDecoderSize(getBytesDecoder(), 64)],
834
+ ["proofB", fixDecoderSize(getBytesDecoder(), 128)],
835
+ ["proofC", fixDecoderSize(getBytesDecoder(), 64)],
836
+ [
837
+ "publicInputs",
838
+ getArrayDecoder(fixDecoderSize(getBytesDecoder(), 32), { size: 7 })
839
+ ],
840
+ ["nullifierHash", fixDecoderSize(getBytesDecoder(), 32)],
841
+ ["amount", getU64Decoder()],
842
+ ["fee", getU64Decoder()]
843
+ ]);
844
+ }
845
+ function getTransferInstructionDataCodec() {
846
+ return combineCodec(
847
+ getTransferInstructionDataEncoder(),
848
+ getTransferInstructionDataDecoder()
849
+ );
850
+ }
851
+ async function getTransferInstructionAsync(input, config) {
852
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
853
+ const originalAccounts = {
854
+ relayer: { value: input.relayer ?? null, isWritable: true },
855
+ pool: { value: input.pool ?? null, isWritable: true },
856
+ mint: { value: input.mint ?? null, isWritable: true },
857
+ vault: { value: input.vault ?? null, isWritable: true },
858
+ nullifier: { value: input.nullifier ?? null, isWritable: true },
859
+ recipient: { value: input.recipient ?? null, isWritable: true },
860
+ vaultTokenAccount: {
861
+ value: input.vaultTokenAccount ?? null,
862
+ isWritable: true
863
+ },
864
+ recipientTokenAccount: {
865
+ value: input.recipientTokenAccount ?? null,
866
+ isWritable: true
867
+ },
868
+ feeCollector: { value: input.feeCollector ?? null, isWritable: true },
869
+ feeCollectorTokenAccount: {
870
+ value: input.feeCollectorTokenAccount ?? null,
871
+ isWritable: true
872
+ },
873
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
874
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
875
+ associatedTokenProgram: {
876
+ value: input.associatedTokenProgram ?? null,
877
+ isWritable: false
878
+ }
879
+ };
880
+ const accounts = originalAccounts;
881
+ const args = { ...input };
882
+ if (!accounts.vault.value) {
883
+ accounts.vault.value = await getProgramDerivedAddress({
884
+ programAddress,
885
+ seeds: [
886
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
887
+ getAddressEncoder().encode(expectAddress(accounts.pool.value))
888
+ ]
889
+ });
890
+ }
891
+ if (!accounts.nullifier.value) {
892
+ accounts.nullifier.value = await getProgramDerivedAddress({
893
+ programAddress,
894
+ seeds: [
895
+ getBytesEncoder().encode(
896
+ new Uint8Array([110, 117, 108, 108, 105, 102, 105, 101, 114])
897
+ ),
898
+ fixEncoderSize(getBytesEncoder(), 32).encode(
899
+ expectSome(args.nullifierHash)
900
+ )
901
+ ]
902
+ });
903
+ }
904
+ if (!accounts.tokenProgram.value) {
905
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
906
+ }
907
+ if (!accounts.recipientTokenAccount.value) {
908
+ accounts.recipientTokenAccount.value = await getProgramDerivedAddress({
909
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
910
+ seeds: [
911
+ getAddressEncoder().encode(expectAddress(accounts.recipient.value)),
912
+ getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
913
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
914
+ ]
915
+ });
916
+ }
917
+ if (!accounts.feeCollector.value) {
918
+ accounts.feeCollector.value = "5KgfWjGePnbFgDAuCqxB5oymuFxQskvCtrw6eYfDa7fj";
919
+ }
920
+ if (!accounts.feeCollectorTokenAccount.value) {
921
+ accounts.feeCollectorTokenAccount.value = await getProgramDerivedAddress({
922
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
923
+ seeds: [
924
+ getAddressEncoder().encode(expectAddress(accounts.feeCollector.value)),
925
+ getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
926
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
927
+ ]
928
+ });
929
+ }
930
+ if (!accounts.systemProgram.value) {
931
+ accounts.systemProgram.value = "11111111111111111111111111111111";
932
+ }
933
+ if (!accounts.associatedTokenProgram.value) {
934
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
935
+ }
936
+ const getAccountMeta = getAccountMetaFactory(programAddress);
937
+ return Object.freeze({
938
+ accounts: [
939
+ getAccountMeta(accounts.relayer),
940
+ getAccountMeta(accounts.pool),
941
+ getAccountMeta(accounts.mint),
942
+ getAccountMeta(accounts.vault),
943
+ getAccountMeta(accounts.nullifier),
944
+ getAccountMeta(accounts.recipient),
945
+ getAccountMeta(accounts.vaultTokenAccount),
946
+ getAccountMeta(accounts.recipientTokenAccount),
947
+ getAccountMeta(accounts.feeCollector),
948
+ getAccountMeta(accounts.feeCollectorTokenAccount),
949
+ getAccountMeta(accounts.systemProgram),
950
+ getAccountMeta(accounts.tokenProgram),
951
+ getAccountMeta(accounts.associatedTokenProgram)
952
+ ],
953
+ data: getTransferInstructionDataEncoder().encode(
954
+ args
955
+ ),
956
+ programAddress
957
+ });
958
+ }
959
+ function getTransferInstruction(input, config) {
960
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
961
+ const originalAccounts = {
962
+ relayer: { value: input.relayer ?? null, isWritable: true },
963
+ pool: { value: input.pool ?? null, isWritable: true },
964
+ mint: { value: input.mint ?? null, isWritable: true },
965
+ vault: { value: input.vault ?? null, isWritable: true },
966
+ nullifier: { value: input.nullifier ?? null, isWritable: true },
967
+ recipient: { value: input.recipient ?? null, isWritable: true },
968
+ vaultTokenAccount: {
969
+ value: input.vaultTokenAccount ?? null,
970
+ isWritable: true
971
+ },
972
+ recipientTokenAccount: {
973
+ value: input.recipientTokenAccount ?? null,
974
+ isWritable: true
975
+ },
976
+ feeCollector: { value: input.feeCollector ?? null, isWritable: true },
977
+ feeCollectorTokenAccount: {
978
+ value: input.feeCollectorTokenAccount ?? null,
979
+ isWritable: true
980
+ },
981
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
982
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
983
+ associatedTokenProgram: {
984
+ value: input.associatedTokenProgram ?? null,
985
+ isWritable: false
986
+ }
987
+ };
988
+ const accounts = originalAccounts;
989
+ const args = { ...input };
990
+ if (!accounts.tokenProgram.value) {
991
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
992
+ }
993
+ if (!accounts.feeCollector.value) {
994
+ accounts.feeCollector.value = "5KgfWjGePnbFgDAuCqxB5oymuFxQskvCtrw6eYfDa7fj";
995
+ }
996
+ if (!accounts.systemProgram.value) {
997
+ accounts.systemProgram.value = "11111111111111111111111111111111";
998
+ }
999
+ if (!accounts.associatedTokenProgram.value) {
1000
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1001
+ }
1002
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1003
+ return Object.freeze({
1004
+ accounts: [
1005
+ getAccountMeta(accounts.relayer),
1006
+ getAccountMeta(accounts.pool),
1007
+ getAccountMeta(accounts.mint),
1008
+ getAccountMeta(accounts.vault),
1009
+ getAccountMeta(accounts.nullifier),
1010
+ getAccountMeta(accounts.recipient),
1011
+ getAccountMeta(accounts.vaultTokenAccount),
1012
+ getAccountMeta(accounts.recipientTokenAccount),
1013
+ getAccountMeta(accounts.feeCollector),
1014
+ getAccountMeta(accounts.feeCollectorTokenAccount),
1015
+ getAccountMeta(accounts.systemProgram),
1016
+ getAccountMeta(accounts.tokenProgram),
1017
+ getAccountMeta(accounts.associatedTokenProgram)
1018
+ ],
1019
+ data: getTransferInstructionDataEncoder().encode(
1020
+ args
1021
+ ),
1022
+ programAddress
1023
+ });
1024
+ }
1025
+ function parseTransferInstruction(instruction) {
1026
+ if (instruction.accounts.length < 13) {
1027
+ throw new Error("Not enough accounts");
1028
+ }
1029
+ let accountIndex = 0;
1030
+ const getNextAccount = () => {
1031
+ const accountMeta = instruction.accounts[accountIndex];
1032
+ accountIndex += 1;
1033
+ return accountMeta;
1034
+ };
1035
+ const getNextOptionalAccount = () => {
1036
+ const accountMeta = getNextAccount();
1037
+ return accountMeta.address === MIXOOR_PROGRAM_ADDRESS ? void 0 : accountMeta;
1038
+ };
1039
+ return {
1040
+ programAddress: instruction.programAddress,
1041
+ accounts: {
1042
+ relayer: getNextAccount(),
1043
+ pool: getNextAccount(),
1044
+ mint: getNextAccount(),
1045
+ vault: getNextAccount(),
1046
+ nullifier: getNextAccount(),
1047
+ recipient: getNextAccount(),
1048
+ vaultTokenAccount: getNextOptionalAccount(),
1049
+ recipientTokenAccount: getNextOptionalAccount(),
1050
+ feeCollector: getNextAccount(),
1051
+ feeCollectorTokenAccount: getNextOptionalAccount(),
1052
+ systemProgram: getNextAccount(),
1053
+ tokenProgram: getNextAccount(),
1054
+ associatedTokenProgram: getNextAccount()
1055
+ },
1056
+ data: getTransferInstructionDataDecoder().decode(instruction.data)
1057
+ };
1058
+ }
1059
+ var poseidon;
1060
+ async function initPoseidon() {
1061
+ if (!poseidon) {
1062
+ poseidon = await buildPoseidon();
1063
+ }
1064
+ return poseidon;
1065
+ }
1066
+ var SNARK_FIELD_SIZE = BigInt(
1067
+ "21888242871839275222246405745257275088548364400416034343698204186575808495617"
1068
+ );
1069
+ function toFieldElement(bytes) {
1070
+ let bigInt = 0n;
1071
+ for (let i = 0; i < bytes.length; i++) {
1072
+ bigInt = bigInt << 8n | BigInt(bytes[i]);
1073
+ }
1074
+ return (bigInt % SNARK_FIELD_SIZE).toString();
1075
+ }
1076
+ async function poseidonHash(inputs) {
1077
+ await initPoseidon();
1078
+ const hash = poseidon(inputs.map((x) => BigInt(toFieldElement(x))));
1079
+ const hashBigInt = poseidon.F.toObject(hash);
1080
+ const bytes = new Uint8Array(32);
1081
+ let temp = BigInt(hashBigInt);
1082
+ for (let i = 31; i >= 0; i--) {
1083
+ bytes[i] = Number(temp & BigInt(255));
1084
+ temp = temp >> BigInt(8);
1085
+ }
1086
+ return bytes;
1087
+ }
1088
+ async function generateCommitment(secret, nullifier, amount, poolId) {
1089
+ await initPoseidon();
1090
+ const poolIdBytes = getAddressEncoder().encode(poolId);
1091
+ const secretField = BigInt(toFieldElement(secret));
1092
+ const nullifierField = BigInt(toFieldElement(nullifier));
1093
+ const amountField = BigInt(amount);
1094
+ const poolIdField = BigInt(toFieldElement(Uint8Array.from(poolIdBytes)));
1095
+ const hash = poseidon([
1096
+ secretField,
1097
+ nullifierField,
1098
+ amountField,
1099
+ poolIdField
1100
+ ]);
1101
+ const hashBigInt = poseidon.F.toObject(hash);
1102
+ const bytes = new Uint8Array(32);
1103
+ let temp = BigInt(hashBigInt);
1104
+ for (let i = 31; i >= 0; i--) {
1105
+ bytes[i] = Number(temp & BigInt(255));
1106
+ temp = temp >> BigInt(8);
1107
+ }
1108
+ return bytes;
1109
+ }
1110
+ async function generateNullifier(nullifier, poolId) {
1111
+ const poolIdBytes = getAddressEncoder().encode(poolId);
1112
+ return await poseidonHash([nullifier, Uint8Array.from(poolIdBytes)]);
1113
+ }
1114
+ function fieldElementToBytes(element) {
1115
+ const bigInt = BigInt(element);
1116
+ const bytes = new Uint8Array(32);
1117
+ for (let i = 0; i < 32; i++) {
1118
+ bytes[31 - i] = Number(bigInt >> BigInt(i * 8) & BigInt(255));
1119
+ }
1120
+ return bytes;
1121
+ }
1122
+ function publicSignalToBytes(signal) {
1123
+ const bigInt = BigInt(signal);
1124
+ const bytes = new Uint8Array(32);
1125
+ for (let i = 0; i < 32; i++) {
1126
+ bytes[31 - i] = Number(bigInt >> BigInt(i * 8) & BigInt(255));
1127
+ }
1128
+ return bytes;
1129
+ }
1130
+ function g1PointToBytes(point) {
1131
+ const x = fieldElementToBytes(point[0]);
1132
+ const y = fieldElementToBytes(point[1]);
1133
+ const result = new Uint8Array(64);
1134
+ result.set(x, 0);
1135
+ result.set(y, 32);
1136
+ return result;
1137
+ }
1138
+ function g2PointToBytes(point) {
1139
+ const x1 = fieldElementToBytes(point[0][1]);
1140
+ const x0 = fieldElementToBytes(point[0][0]);
1141
+ const y1 = fieldElementToBytes(point[1][1]);
1142
+ const y0 = fieldElementToBytes(point[1][0]);
1143
+ const result = new Uint8Array(128);
1144
+ result.set(x1, 0);
1145
+ result.set(x0, 32);
1146
+ result.set(y1, 64);
1147
+ result.set(y0, 96);
1148
+ return result;
1149
+ }
1150
+ async function generateProof(input) {
1151
+ await initPoseidon();
1152
+ const poolIdBytes = getAddressEncoder().encode(input.poolAddress);
1153
+ const circuitInputs = {
1154
+ root: toFieldElement(input.root),
1155
+ nullifierHash: toFieldElement(
1156
+ await generateNullifier(input.nullifier, input.poolAddress)
1157
+ ),
1158
+ recipient: toFieldElement(input.recipient),
1159
+ relayer: toFieldElement(input.relayer),
1160
+ fee: input.fee,
1161
+ refund: input.refund,
1162
+ poolId: toFieldElement(Uint8Array.from(poolIdBytes)),
1163
+ secret: toFieldElement(input.secret),
1164
+ nullifier: toFieldElement(input.nullifier),
1165
+ pathElements: input.pathElements.map((x) => toFieldElement(x)),
1166
+ pathIndices: input.pathIndices,
1167
+ amount: BigInt(input.amount).toString()
1168
+ };
1169
+ const wasmPath = path.join(
1170
+ __dirname,
1171
+ "../../../../circuits/build/transaction_js/transaction.wasm"
1172
+ );
1173
+ const zkeyPath = path.join(
1174
+ __dirname,
1175
+ "../../../../circuits/transaction_0001.zkey"
1176
+ );
1177
+ const { proof, publicSignals } = await groth16.fullProve(
1178
+ circuitInputs,
1179
+ wasmPath,
1180
+ zkeyPath
1181
+ );
1182
+ const vKeyPath = path.join(
1183
+ __dirname,
1184
+ "../../../../circuits/verification_key.json"
1185
+ );
1186
+ const isValid = await groth16.verify(
1187
+ JSON.parse(fs.readFileSync(vKeyPath, "utf8")),
1188
+ publicSignals,
1189
+ proof
1190
+ );
1191
+ console.log("Local proof verification:", isValid ? "VALID \u2713" : "INVALID \u2717");
1192
+ if (!isValid) {
1193
+ throw new Error("Generated proof is invalid - check circuit inputs");
1194
+ }
1195
+ const publicInputs = publicSignals.map(
1196
+ (signal) => publicSignalToBytes(signal)
1197
+ );
1198
+ console.log(
1199
+ "DEBUG: Generated Public Inputs (Keys: root, nullifierHash, recipient, relayer, fee, refund, poolId):"
1200
+ );
1201
+ publicInputs.forEach((input2, i) => {
1202
+ const hexBE = Buffer.from(input2).toString("hex");
1203
+ const hexLE = Buffer.from(input2.slice().reverse()).toString("hex");
1204
+ console.log(`Input ${i}: BE=${hexBE} | LE=${hexLE}`);
1205
+ });
1206
+ const proof_a = g1PointToBytes([proof.pi_a[0], proof.pi_a[1]]);
1207
+ const proof_b = g2PointToBytes([
1208
+ [proof.pi_b[0][0], proof.pi_b[0][1]],
1209
+ [proof.pi_b[1][0], proof.pi_b[1][1]]
1210
+ ]);
1211
+ const proof_c = g1PointToBytes([proof.pi_c[0], proof.pi_c[1]]);
1212
+ return {
1213
+ proofData: {
1214
+ proofA: proof_a,
1215
+ proofB: proof_b,
1216
+ proofC: proof_c
1217
+ },
1218
+ publicInputs
1219
+ };
1220
+ }
1221
+ function randomBytes(size) {
1222
+ return new Uint8Array(randomBytes$1(size));
1223
+ }
1224
+ function toHex(bytes) {
1225
+ return Buffer.from(bytes).toString("hex");
1226
+ }
1227
+ function fromHex(hex) {
1228
+ return new Uint8Array(Buffer.from(hex, "hex"));
1229
+ }
1230
+ var MerkleTree = class {
1231
+ levels;
1232
+ _leaves;
1233
+ _zeros;
1234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1235
+ poseidon;
1236
+ initialized = false;
1237
+ constructor(levels) {
1238
+ this.levels = levels;
1239
+ this._leaves = [];
1240
+ this._zeros = [];
1241
+ }
1242
+ async initialize() {
1243
+ if (this.initialized) return;
1244
+ this.poseidon = await buildPoseidon();
1245
+ this._zeros[0] = new Uint8Array(32);
1246
+ this.initialized = true;
1247
+ for (let i = 1; i <= this.levels; i++) {
1248
+ this._zeros[i] = this.hash(this._zeros[i - 1], this._zeros[i - 1]);
1249
+ }
1250
+ }
1251
+ hash(left, right) {
1252
+ if (!this.poseidon) {
1253
+ throw new Error("MerkleTree not initialized. Call initialize() first");
1254
+ }
1255
+ const SNARK_FIELD_SIZE2 = BigInt(
1256
+ "21888242871839275222246405745257275088548364400416034343698204186575808495617"
1257
+ );
1258
+ const leftBigInt = this.uint8ArrayToBigInt(left) % SNARK_FIELD_SIZE2;
1259
+ const rightBigInt = this.uint8ArrayToBigInt(right) % SNARK_FIELD_SIZE2;
1260
+ const result = this.poseidon([leftBigInt, rightBigInt]);
1261
+ const resultBytes = this.poseidon.F.toObject(result);
1262
+ return this.bigIntToUint8Array(BigInt(resultBytes));
1263
+ }
1264
+ uint8ArrayToBigInt(arr) {
1265
+ let hex = "0x";
1266
+ for (let i = 0; i < arr.length; i++) {
1267
+ hex += arr[i].toString(16).padStart(2, "0");
1268
+ }
1269
+ return BigInt(hex);
1270
+ }
1271
+ bigIntToUint8Array(value) {
1272
+ const bytes = new Uint8Array(32);
1273
+ let temp = value;
1274
+ for (let i = 31; i >= 0; i--) {
1275
+ bytes[i] = Number(temp & BigInt(255));
1276
+ temp = temp >> BigInt(8);
1277
+ }
1278
+ return bytes;
1279
+ }
1280
+ insert(leaf) {
1281
+ if (!this.initialized) {
1282
+ throw new Error("MerkleTree not initialized. Call initialize() first");
1283
+ }
1284
+ this._leaves.push(leaf);
1285
+ }
1286
+ root() {
1287
+ if (!this.initialized) {
1288
+ throw new Error("MerkleTree not initialized. Call initialize() first");
1289
+ }
1290
+ if (this._leaves.length === 0) {
1291
+ return this._zeros[this.levels];
1292
+ }
1293
+ let currentLevel = [...this._leaves];
1294
+ for (let level = 0; level < this.levels; level++) {
1295
+ const nextLevel = [];
1296
+ for (let i = 0; i < currentLevel.length; i += 2) {
1297
+ const left = currentLevel[i];
1298
+ const right = i + 1 < currentLevel.length ? currentLevel[i + 1] : this._zeros[level];
1299
+ nextLevel.push(this.hash(left, right));
1300
+ }
1301
+ currentLevel = nextLevel;
1302
+ }
1303
+ return currentLevel[0];
1304
+ }
1305
+ getProof(index) {
1306
+ if (!this.initialized) {
1307
+ throw new Error("MerkleTree not initialized. Call initialize() first");
1308
+ }
1309
+ if (index >= this._leaves.length) {
1310
+ throw new Error("Leaf index out of bounds");
1311
+ }
1312
+ const pathElements = [];
1313
+ const pathIndices = [];
1314
+ let currentLevel = [...this._leaves];
1315
+ let currentIndex = index;
1316
+ for (let level = 0; level < this.levels; level++) {
1317
+ const isLeft = currentIndex % 2 === 0;
1318
+ const siblingIndex = isLeft ? currentIndex + 1 : currentIndex - 1;
1319
+ const sibling = siblingIndex < currentLevel.length ? currentLevel[siblingIndex] : this._zeros[level];
1320
+ pathElements.push(sibling);
1321
+ pathIndices.push(isLeft ? 0 : 1);
1322
+ const nextLevel = [];
1323
+ for (let i = 0; i < currentLevel.length; i += 2) {
1324
+ const left = currentLevel[i];
1325
+ const right = i + 1 < currentLevel.length ? currentLevel[i + 1] : this._zeros[level];
1326
+ nextLevel.push(this.hash(left, right));
1327
+ }
1328
+ currentLevel = nextLevel;
1329
+ currentIndex = Math.floor(currentIndex / 2);
1330
+ }
1331
+ return { pathElements, pathIndices };
1332
+ }
1333
+ };
1334
+ function extractMerkleRootFromAccount(_client, _poolAddress) {
1335
+ throw new Error(
1336
+ "Merkle tree is off-chain now. Build it locally from CommitmentInserted events. For tests, use your MerkleTree instance: merkleTree.root()"
1337
+ );
1338
+ }
1339
+ async function findPoolAddress(seeds, config = {}) {
1340
+ const { programAddress = MIXOOR_PROGRAM_ADDRESS } = config;
1341
+ return await getProgramDerivedAddress({
1342
+ programAddress,
1343
+ seeds: ["pool", getAddressEncoder().encode(seeds.mint)]
1344
+ });
1345
+ }
1346
+ async function findMerkleTreeAddress(seeds, config = {}) {
1347
+ const { programAddress = MIXOOR_PROGRAM_ADDRESS } = config;
1348
+ return await getProgramDerivedAddress({
1349
+ programAddress,
1350
+ seeds: ["merkle", getAddressEncoder().encode(seeds.pool)]
1351
+ });
1352
+ }
1353
+ async function findVaultAddress(seeds, config = {}) {
1354
+ const { programAddress = MIXOOR_PROGRAM_ADDRESS } = config;
1355
+ return await getProgramDerivedAddress({
1356
+ programAddress,
1357
+ seeds: ["vault", getAddressEncoder().encode(seeds.pool)]
1358
+ });
1359
+ }
1360
+
1361
+ export { AssetType, DEPOSIT_DISCRIMINATOR, INITIALIZE_POOL_DISCRIMINATOR, MIXOOR_ERROR__INSUFFICIENT_FUNDS, MIXOOR_ERROR__INVALID_AMOUNT, MIXOOR_ERROR__INVALID_ASSET_TYPE, MIXOOR_ERROR__INVALID_MERKLE_PROOF, MIXOOR_ERROR__INVALID_MERKLE_TREE, MIXOOR_ERROR__INVALID_MERKLE_TREE_ADDRESS, MIXOOR_ERROR__INVALID_PROOF, MIXOOR_ERROR__INVALID_PUBLIC_INPUTS, MIXOOR_ERROR__MERKLE_TREE_FULL, MIXOOR_ERROR__MISSING_TOKEN_ACCOUNT, MIXOOR_ERROR__OVERFLOW, MIXOOR_ERROR__POSEIDON_HASH_ERROR, MIXOOR_ERROR__UNKNOWN_ROOT, MIXOOR_PROGRAM_ADDRESS, MerkleTree, MixoorAccount, MixoorInstruction, NULLIFIER_ACCOUNT_DISCRIMINATOR, POOL_DISCRIMINATOR, TRANSFER_DISCRIMINATOR, VAULT_DISCRIMINATOR, decodeNullifierAccount, decodePool, decodeVault, extractMerkleRootFromAccount, fetchAllMaybeNullifierAccount, fetchAllMaybePool, fetchAllMaybeVault, fetchAllNullifierAccount, fetchAllPool, fetchAllVault, fetchMaybeNullifierAccount, fetchMaybePool, fetchMaybeVault, fetchNullifierAccount, fetchPool, fetchVault, findMerkleTreeAddress, findPoolAddress, findVaultAddress, fromHex, generateCommitment, generateNullifier, generateProof, getAssetTypeCodec, getAssetTypeDecoder, getAssetTypeEncoder, getCommitmentInsertedCodec, getCommitmentInsertedDecoder, getCommitmentInsertedEncoder, getDepositDiscriminatorBytes, getDepositInstruction, getDepositInstructionAsync, getDepositInstructionDataCodec, getDepositInstructionDataDecoder, getDepositInstructionDataEncoder, getInitializePoolDiscriminatorBytes, getInitializePoolInstruction, getInitializePoolInstructionAsync, getInitializePoolInstructionDataCodec, getInitializePoolInstructionDataDecoder, getInitializePoolInstructionDataEncoder, getMixoorErrorMessage, getNullifierAccountCodec, getNullifierAccountDecoder, getNullifierAccountDiscriminatorBytes, getNullifierAccountEncoder, getNullifierAccountSize, getPoolCodec, getPoolDecoder, getPoolDiscriminatorBytes, getPoolEncoder, getPoolSize, getRootEntryCodec, getRootEntryDecoder, getRootEntryEncoder, getTransferDiscriminatorBytes, getTransferInstruction, getTransferInstructionAsync, getTransferInstructionDataCodec, getTransferInstructionDataDecoder, getTransferInstructionDataEncoder, getVaultCodec, getVaultDecoder, getVaultDiscriminatorBytes, getVaultEncoder, getVaultSize, identifyMixoorAccount, identifyMixoorInstruction, isMixoorError, parseDepositInstruction, parseInitializePoolInstruction, parseTransferInstruction, poseidonHash, randomBytes, toHex };
1362
+ //# sourceMappingURL=index.mjs.map
1363
+ //# sourceMappingURL=index.mjs.map