@smithii_io/mixoor 0.0.12 → 0.0.14

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.
@@ -307,6 +307,8 @@ var MixoorInstruction = /* @__PURE__ */ ((MixoorInstruction2) => {
307
307
  MixoorInstruction2[MixoorInstruction2["Deposit"] = 0] = "Deposit";
308
308
  MixoorInstruction2[MixoorInstruction2["InitializePool"] = 1] = "InitializePool";
309
309
  MixoorInstruction2[MixoorInstruction2["Transfer"] = 2] = "Transfer";
310
+ MixoorInstruction2[MixoorInstruction2["UpdateRoot"] = 3] = "UpdateRoot";
311
+ MixoorInstruction2[MixoorInstruction2["Withdraw"] = 4] = "Withdraw";
310
312
  return MixoorInstruction2;
311
313
  })(MixoorInstruction || {});
312
314
  function identifyMixoorInstruction(instruction) {
@@ -338,6 +340,24 @@ function identifyMixoorInstruction(instruction) {
338
340
  )) {
339
341
  return 2 /* Transfer */;
340
342
  }
343
+ if (containsBytes(
344
+ data,
345
+ fixEncoderSize(getBytesEncoder(), 8).encode(
346
+ new Uint8Array([58, 195, 57, 246, 116, 198, 170, 138])
347
+ ),
348
+ 0
349
+ )) {
350
+ return 3 /* UpdateRoot */;
351
+ }
352
+ if (containsBytes(
353
+ data,
354
+ fixEncoderSize(getBytesEncoder(), 8).encode(
355
+ new Uint8Array([183, 18, 70, 156, 148, 109, 161, 34])
356
+ ),
357
+ 0
358
+ )) {
359
+ return 4 /* Withdraw */;
360
+ }
341
361
  throw new Error(
342
362
  "The provided instruction could not be identified as a mixoor instruction."
343
363
  );
@@ -1061,6 +1081,263 @@ function parseTransferInstruction(instruction) {
1061
1081
  data: getTransferInstructionDataDecoder().decode(instruction.data)
1062
1082
  };
1063
1083
  }
1084
+ var UPDATE_ROOT_DISCRIMINATOR = new Uint8Array([
1085
+ 58,
1086
+ 195,
1087
+ 57,
1088
+ 246,
1089
+ 116,
1090
+ 198,
1091
+ 170,
1092
+ 138
1093
+ ]);
1094
+ function getUpdateRootDiscriminatorBytes() {
1095
+ return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_ROOT_DISCRIMINATOR);
1096
+ }
1097
+ function getUpdateRootInstructionDataEncoder() {
1098
+ return transformEncoder(
1099
+ getStructEncoder([
1100
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
1101
+ ["root", fixEncoderSize(getBytesEncoder(), 32)]
1102
+ ]),
1103
+ (value) => ({ ...value, discriminator: UPDATE_ROOT_DISCRIMINATOR })
1104
+ );
1105
+ }
1106
+ function getUpdateRootInstructionDataDecoder() {
1107
+ return getStructDecoder([
1108
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
1109
+ ["root", fixDecoderSize(getBytesDecoder(), 32)]
1110
+ ]);
1111
+ }
1112
+ function getUpdateRootInstructionDataCodec() {
1113
+ return combineCodec(
1114
+ getUpdateRootInstructionDataEncoder(),
1115
+ getUpdateRootInstructionDataDecoder()
1116
+ );
1117
+ }
1118
+ function getUpdateRootInstruction(input, config) {
1119
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1120
+ const originalAccounts = {
1121
+ relayer: { value: input.relayer ?? null, isWritable: true },
1122
+ pool: { value: input.pool ?? null, isWritable: true }
1123
+ };
1124
+ const accounts = originalAccounts;
1125
+ const args = { ...input };
1126
+ if (!accounts.relayer.value) {
1127
+ accounts.relayer.value = "re1R63DiMLtDyHMAS1ohszqfFTHcF9Q3uEXSYdHzHWU";
1128
+ }
1129
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1130
+ return Object.freeze({
1131
+ accounts: [getAccountMeta(accounts.relayer), getAccountMeta(accounts.pool)],
1132
+ data: getUpdateRootInstructionDataEncoder().encode(
1133
+ args
1134
+ ),
1135
+ programAddress
1136
+ });
1137
+ }
1138
+ function parseUpdateRootInstruction(instruction) {
1139
+ if (instruction.accounts.length < 2) {
1140
+ throw new Error("Not enough accounts");
1141
+ }
1142
+ let accountIndex = 0;
1143
+ const getNextAccount = () => {
1144
+ const accountMeta = instruction.accounts[accountIndex];
1145
+ accountIndex += 1;
1146
+ return accountMeta;
1147
+ };
1148
+ return {
1149
+ programAddress: instruction.programAddress,
1150
+ accounts: { relayer: getNextAccount(), pool: getNextAccount() },
1151
+ data: getUpdateRootInstructionDataDecoder().decode(instruction.data)
1152
+ };
1153
+ }
1154
+ var WITHDRAW_DISCRIMINATOR = new Uint8Array([
1155
+ 183,
1156
+ 18,
1157
+ 70,
1158
+ 156,
1159
+ 148,
1160
+ 109,
1161
+ 161,
1162
+ 34
1163
+ ]);
1164
+ function getWithdrawDiscriminatorBytes() {
1165
+ return fixEncoderSize(getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
1166
+ }
1167
+ function getWithdrawInstructionDataEncoder() {
1168
+ return transformEncoder(
1169
+ getStructEncoder([
1170
+ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
1171
+ ["amount", getU64Encoder()]
1172
+ ]),
1173
+ (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR })
1174
+ );
1175
+ }
1176
+ function getWithdrawInstructionDataDecoder() {
1177
+ return getStructDecoder([
1178
+ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
1179
+ ["amount", getU64Decoder()]
1180
+ ]);
1181
+ }
1182
+ function getWithdrawInstructionDataCodec() {
1183
+ return combineCodec(
1184
+ getWithdrawInstructionDataEncoder(),
1185
+ getWithdrawInstructionDataDecoder()
1186
+ );
1187
+ }
1188
+ async function getWithdrawInstructionAsync(input, config) {
1189
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1190
+ const originalAccounts = {
1191
+ authority: { value: input.authority ?? null, isWritable: true },
1192
+ pool: { value: input.pool ?? null, isWritable: true },
1193
+ vault: { value: input.vault ?? null, isWritable: true },
1194
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1195
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1196
+ mint: { value: input.mint ?? null, isWritable: true },
1197
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1198
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1199
+ associatedTokenProgram: {
1200
+ value: input.associatedTokenProgram ?? null,
1201
+ isWritable: false
1202
+ }
1203
+ };
1204
+ const accounts = originalAccounts;
1205
+ const args = { ...input };
1206
+ if (!accounts.authority.value) {
1207
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1208
+ }
1209
+ if (!accounts.vault.value) {
1210
+ accounts.vault.value = await getProgramDerivedAddress({
1211
+ programAddress,
1212
+ seeds: [
1213
+ getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
1214
+ getAddressEncoder().encode(expectAddress(accounts.pool.value))
1215
+ ]
1216
+ });
1217
+ }
1218
+ if (!accounts.tokenProgram.value) {
1219
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1220
+ }
1221
+ if (!accounts.vaultAta.value) {
1222
+ accounts.vaultAta.value = await getProgramDerivedAddress({
1223
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1224
+ seeds: [
1225
+ getAddressEncoder().encode(expectAddress(accounts.vault.value)),
1226
+ getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1227
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
1228
+ ]
1229
+ });
1230
+ }
1231
+ if (!accounts.authorityAta.value) {
1232
+ accounts.authorityAta.value = await getProgramDerivedAddress({
1233
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1234
+ seeds: [
1235
+ getAddressEncoder().encode(expectAddress(accounts.authority.value)),
1236
+ getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1237
+ getAddressEncoder().encode(expectAddress(accounts.mint.value))
1238
+ ]
1239
+ });
1240
+ }
1241
+ if (!accounts.systemProgram.value) {
1242
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1243
+ }
1244
+ if (!accounts.associatedTokenProgram.value) {
1245
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1246
+ }
1247
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1248
+ return Object.freeze({
1249
+ accounts: [
1250
+ getAccountMeta(accounts.authority),
1251
+ getAccountMeta(accounts.pool),
1252
+ getAccountMeta(accounts.vault),
1253
+ getAccountMeta(accounts.vaultAta),
1254
+ getAccountMeta(accounts.authorityAta),
1255
+ getAccountMeta(accounts.mint),
1256
+ getAccountMeta(accounts.systemProgram),
1257
+ getAccountMeta(accounts.tokenProgram),
1258
+ getAccountMeta(accounts.associatedTokenProgram)
1259
+ ],
1260
+ data: getWithdrawInstructionDataEncoder().encode(
1261
+ args
1262
+ ),
1263
+ programAddress
1264
+ });
1265
+ }
1266
+ function getWithdrawInstruction(input, config) {
1267
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1268
+ const originalAccounts = {
1269
+ authority: { value: input.authority ?? null, isWritable: true },
1270
+ pool: { value: input.pool ?? null, isWritable: true },
1271
+ vault: { value: input.vault ?? null, isWritable: true },
1272
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1273
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1274
+ mint: { value: input.mint ?? null, isWritable: true },
1275
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1276
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1277
+ associatedTokenProgram: {
1278
+ value: input.associatedTokenProgram ?? null,
1279
+ isWritable: false
1280
+ }
1281
+ };
1282
+ const accounts = originalAccounts;
1283
+ const args = { ...input };
1284
+ if (!accounts.authority.value) {
1285
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1286
+ }
1287
+ if (!accounts.tokenProgram.value) {
1288
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1289
+ }
1290
+ if (!accounts.systemProgram.value) {
1291
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1292
+ }
1293
+ if (!accounts.associatedTokenProgram.value) {
1294
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1295
+ }
1296
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1297
+ return Object.freeze({
1298
+ accounts: [
1299
+ getAccountMeta(accounts.authority),
1300
+ getAccountMeta(accounts.pool),
1301
+ getAccountMeta(accounts.vault),
1302
+ getAccountMeta(accounts.vaultAta),
1303
+ getAccountMeta(accounts.authorityAta),
1304
+ getAccountMeta(accounts.mint),
1305
+ getAccountMeta(accounts.systemProgram),
1306
+ getAccountMeta(accounts.tokenProgram),
1307
+ getAccountMeta(accounts.associatedTokenProgram)
1308
+ ],
1309
+ data: getWithdrawInstructionDataEncoder().encode(
1310
+ args
1311
+ ),
1312
+ programAddress
1313
+ });
1314
+ }
1315
+ function parseWithdrawInstruction(instruction) {
1316
+ if (instruction.accounts.length < 9) {
1317
+ throw new Error("Not enough accounts");
1318
+ }
1319
+ let accountIndex = 0;
1320
+ const getNextAccount = () => {
1321
+ const accountMeta = instruction.accounts[accountIndex];
1322
+ accountIndex += 1;
1323
+ return accountMeta;
1324
+ };
1325
+ return {
1326
+ programAddress: instruction.programAddress,
1327
+ accounts: {
1328
+ authority: getNextAccount(),
1329
+ pool: getNextAccount(),
1330
+ vault: getNextAccount(),
1331
+ vaultAta: getNextAccount(),
1332
+ authorityAta: getNextAccount(),
1333
+ mint: getNextAccount(),
1334
+ systemProgram: getNextAccount(),
1335
+ tokenProgram: getNextAccount(),
1336
+ associatedTokenProgram: getNextAccount()
1337
+ },
1338
+ data: getWithdrawInstructionDataDecoder().decode(instruction.data)
1339
+ };
1340
+ }
1064
1341
  var poseidon;
1065
1342
  async function initPoseidon() {
1066
1343
  if (!poseidon) {
@@ -1372,6 +1649,6 @@ async function findNullifierAddress(seeds, config = {}) {
1372
1649
  });
1373
1650
  }
1374
1651
 
1375
- 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__PUBLIC_INPUT_MISMATCH, 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, findNullifierAddress, 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 };
1652
+ 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__PUBLIC_INPUT_MISMATCH, MIXOOR_ERROR__UNKNOWN_ROOT, MIXOOR_PROGRAM_ADDRESS, MerkleTree, MixoorAccount, MixoorInstruction, NULLIFIER_ACCOUNT_DISCRIMINATOR, POOL_DISCRIMINATOR, TRANSFER_DISCRIMINATOR, UPDATE_ROOT_DISCRIMINATOR, VAULT_DISCRIMINATOR, WITHDRAW_DISCRIMINATOR, decodeNullifierAccount, decodePool, decodeVault, extractMerkleRootFromAccount, fetchAllMaybeNullifierAccount, fetchAllMaybePool, fetchAllMaybeVault, fetchAllNullifierAccount, fetchAllPool, fetchAllVault, fetchMaybeNullifierAccount, fetchMaybePool, fetchMaybeVault, fetchNullifierAccount, fetchPool, fetchVault, findMerkleTreeAddress, findNullifierAddress, 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, getUpdateRootDiscriminatorBytes, getUpdateRootInstruction, getUpdateRootInstructionDataCodec, getUpdateRootInstructionDataDecoder, getUpdateRootInstructionDataEncoder, getVaultCodec, getVaultDecoder, getVaultDiscriminatorBytes, getVaultEncoder, getVaultSize, getWithdrawDiscriminatorBytes, getWithdrawInstruction, getWithdrawInstructionAsync, getWithdrawInstructionDataCodec, getWithdrawInstructionDataDecoder, getWithdrawInstructionDataEncoder, identifyMixoorAccount, identifyMixoorInstruction, isMixoorError, parseDepositInstruction, parseInitializePoolInstruction, parseTransferInstruction, parseUpdateRootInstruction, parseWithdrawInstruction, poseidonHash, randomBytes, toHex };
1376
1653
  //# sourceMappingURL=index.mjs.map
1377
1654
  //# sourceMappingURL=index.mjs.map