@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.
package/dist/src/index.js CHANGED
@@ -331,6 +331,8 @@ var MixoorInstruction = /* @__PURE__ */ ((MixoorInstruction2) => {
331
331
  MixoorInstruction2[MixoorInstruction2["Deposit"] = 0] = "Deposit";
332
332
  MixoorInstruction2[MixoorInstruction2["InitializePool"] = 1] = "InitializePool";
333
333
  MixoorInstruction2[MixoorInstruction2["Transfer"] = 2] = "Transfer";
334
+ MixoorInstruction2[MixoorInstruction2["UpdateRoot"] = 3] = "UpdateRoot";
335
+ MixoorInstruction2[MixoorInstruction2["Withdraw"] = 4] = "Withdraw";
334
336
  return MixoorInstruction2;
335
337
  })(MixoorInstruction || {});
336
338
  function identifyMixoorInstruction(instruction) {
@@ -362,6 +364,24 @@ function identifyMixoorInstruction(instruction) {
362
364
  )) {
363
365
  return 2 /* Transfer */;
364
366
  }
367
+ if (kit.containsBytes(
368
+ data,
369
+ kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
370
+ new Uint8Array([58, 195, 57, 246, 116, 198, 170, 138])
371
+ ),
372
+ 0
373
+ )) {
374
+ return 3 /* UpdateRoot */;
375
+ }
376
+ if (kit.containsBytes(
377
+ data,
378
+ kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
379
+ new Uint8Array([183, 18, 70, 156, 148, 109, 161, 34])
380
+ ),
381
+ 0
382
+ )) {
383
+ return 4 /* Withdraw */;
384
+ }
365
385
  throw new Error(
366
386
  "The provided instruction could not be identified as a mixoor instruction."
367
387
  );
@@ -1085,6 +1105,263 @@ function parseTransferInstruction(instruction) {
1085
1105
  data: getTransferInstructionDataDecoder().decode(instruction.data)
1086
1106
  };
1087
1107
  }
1108
+ var UPDATE_ROOT_DISCRIMINATOR = new Uint8Array([
1109
+ 58,
1110
+ 195,
1111
+ 57,
1112
+ 246,
1113
+ 116,
1114
+ 198,
1115
+ 170,
1116
+ 138
1117
+ ]);
1118
+ function getUpdateRootDiscriminatorBytes() {
1119
+ return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(UPDATE_ROOT_DISCRIMINATOR);
1120
+ }
1121
+ function getUpdateRootInstructionDataEncoder() {
1122
+ return kit.transformEncoder(
1123
+ kit.getStructEncoder([
1124
+ ["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
1125
+ ["root", kit.fixEncoderSize(kit.getBytesEncoder(), 32)]
1126
+ ]),
1127
+ (value) => ({ ...value, discriminator: UPDATE_ROOT_DISCRIMINATOR })
1128
+ );
1129
+ }
1130
+ function getUpdateRootInstructionDataDecoder() {
1131
+ return kit.getStructDecoder([
1132
+ ["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
1133
+ ["root", kit.fixDecoderSize(kit.getBytesDecoder(), 32)]
1134
+ ]);
1135
+ }
1136
+ function getUpdateRootInstructionDataCodec() {
1137
+ return kit.combineCodec(
1138
+ getUpdateRootInstructionDataEncoder(),
1139
+ getUpdateRootInstructionDataDecoder()
1140
+ );
1141
+ }
1142
+ function getUpdateRootInstruction(input, config) {
1143
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1144
+ const originalAccounts = {
1145
+ relayer: { value: input.relayer ?? null, isWritable: true },
1146
+ pool: { value: input.pool ?? null, isWritable: true }
1147
+ };
1148
+ const accounts = originalAccounts;
1149
+ const args = { ...input };
1150
+ if (!accounts.relayer.value) {
1151
+ accounts.relayer.value = "re1R63DiMLtDyHMAS1ohszqfFTHcF9Q3uEXSYdHzHWU";
1152
+ }
1153
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1154
+ return Object.freeze({
1155
+ accounts: [getAccountMeta(accounts.relayer), getAccountMeta(accounts.pool)],
1156
+ data: getUpdateRootInstructionDataEncoder().encode(
1157
+ args
1158
+ ),
1159
+ programAddress
1160
+ });
1161
+ }
1162
+ function parseUpdateRootInstruction(instruction) {
1163
+ if (instruction.accounts.length < 2) {
1164
+ throw new Error("Not enough accounts");
1165
+ }
1166
+ let accountIndex = 0;
1167
+ const getNextAccount = () => {
1168
+ const accountMeta = instruction.accounts[accountIndex];
1169
+ accountIndex += 1;
1170
+ return accountMeta;
1171
+ };
1172
+ return {
1173
+ programAddress: instruction.programAddress,
1174
+ accounts: { relayer: getNextAccount(), pool: getNextAccount() },
1175
+ data: getUpdateRootInstructionDataDecoder().decode(instruction.data)
1176
+ };
1177
+ }
1178
+ var WITHDRAW_DISCRIMINATOR = new Uint8Array([
1179
+ 183,
1180
+ 18,
1181
+ 70,
1182
+ 156,
1183
+ 148,
1184
+ 109,
1185
+ 161,
1186
+ 34
1187
+ ]);
1188
+ function getWithdrawDiscriminatorBytes() {
1189
+ return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
1190
+ }
1191
+ function getWithdrawInstructionDataEncoder() {
1192
+ return kit.transformEncoder(
1193
+ kit.getStructEncoder([
1194
+ ["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
1195
+ ["amount", kit.getU64Encoder()]
1196
+ ]),
1197
+ (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR })
1198
+ );
1199
+ }
1200
+ function getWithdrawInstructionDataDecoder() {
1201
+ return kit.getStructDecoder([
1202
+ ["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
1203
+ ["amount", kit.getU64Decoder()]
1204
+ ]);
1205
+ }
1206
+ function getWithdrawInstructionDataCodec() {
1207
+ return kit.combineCodec(
1208
+ getWithdrawInstructionDataEncoder(),
1209
+ getWithdrawInstructionDataDecoder()
1210
+ );
1211
+ }
1212
+ async function getWithdrawInstructionAsync(input, config) {
1213
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1214
+ const originalAccounts = {
1215
+ authority: { value: input.authority ?? null, isWritable: true },
1216
+ pool: { value: input.pool ?? null, isWritable: true },
1217
+ vault: { value: input.vault ?? null, isWritable: true },
1218
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1219
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1220
+ mint: { value: input.mint ?? null, isWritable: true },
1221
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1222
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1223
+ associatedTokenProgram: {
1224
+ value: input.associatedTokenProgram ?? null,
1225
+ isWritable: false
1226
+ }
1227
+ };
1228
+ const accounts = originalAccounts;
1229
+ const args = { ...input };
1230
+ if (!accounts.authority.value) {
1231
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1232
+ }
1233
+ if (!accounts.vault.value) {
1234
+ accounts.vault.value = await kit.getProgramDerivedAddress({
1235
+ programAddress,
1236
+ seeds: [
1237
+ kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
1238
+ kit.getAddressEncoder().encode(expectAddress(accounts.pool.value))
1239
+ ]
1240
+ });
1241
+ }
1242
+ if (!accounts.tokenProgram.value) {
1243
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1244
+ }
1245
+ if (!accounts.vaultAta.value) {
1246
+ accounts.vaultAta.value = await kit.getProgramDerivedAddress({
1247
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1248
+ seeds: [
1249
+ kit.getAddressEncoder().encode(expectAddress(accounts.vault.value)),
1250
+ kit.getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1251
+ kit.getAddressEncoder().encode(expectAddress(accounts.mint.value))
1252
+ ]
1253
+ });
1254
+ }
1255
+ if (!accounts.authorityAta.value) {
1256
+ accounts.authorityAta.value = await kit.getProgramDerivedAddress({
1257
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1258
+ seeds: [
1259
+ kit.getAddressEncoder().encode(expectAddress(accounts.authority.value)),
1260
+ kit.getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1261
+ kit.getAddressEncoder().encode(expectAddress(accounts.mint.value))
1262
+ ]
1263
+ });
1264
+ }
1265
+ if (!accounts.systemProgram.value) {
1266
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1267
+ }
1268
+ if (!accounts.associatedTokenProgram.value) {
1269
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1270
+ }
1271
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1272
+ return Object.freeze({
1273
+ accounts: [
1274
+ getAccountMeta(accounts.authority),
1275
+ getAccountMeta(accounts.pool),
1276
+ getAccountMeta(accounts.vault),
1277
+ getAccountMeta(accounts.vaultAta),
1278
+ getAccountMeta(accounts.authorityAta),
1279
+ getAccountMeta(accounts.mint),
1280
+ getAccountMeta(accounts.systemProgram),
1281
+ getAccountMeta(accounts.tokenProgram),
1282
+ getAccountMeta(accounts.associatedTokenProgram)
1283
+ ],
1284
+ data: getWithdrawInstructionDataEncoder().encode(
1285
+ args
1286
+ ),
1287
+ programAddress
1288
+ });
1289
+ }
1290
+ function getWithdrawInstruction(input, config) {
1291
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1292
+ const originalAccounts = {
1293
+ authority: { value: input.authority ?? null, isWritable: true },
1294
+ pool: { value: input.pool ?? null, isWritable: true },
1295
+ vault: { value: input.vault ?? null, isWritable: true },
1296
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1297
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1298
+ mint: { value: input.mint ?? null, isWritable: true },
1299
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1300
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1301
+ associatedTokenProgram: {
1302
+ value: input.associatedTokenProgram ?? null,
1303
+ isWritable: false
1304
+ }
1305
+ };
1306
+ const accounts = originalAccounts;
1307
+ const args = { ...input };
1308
+ if (!accounts.authority.value) {
1309
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1310
+ }
1311
+ if (!accounts.tokenProgram.value) {
1312
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1313
+ }
1314
+ if (!accounts.systemProgram.value) {
1315
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1316
+ }
1317
+ if (!accounts.associatedTokenProgram.value) {
1318
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1319
+ }
1320
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1321
+ return Object.freeze({
1322
+ accounts: [
1323
+ getAccountMeta(accounts.authority),
1324
+ getAccountMeta(accounts.pool),
1325
+ getAccountMeta(accounts.vault),
1326
+ getAccountMeta(accounts.vaultAta),
1327
+ getAccountMeta(accounts.authorityAta),
1328
+ getAccountMeta(accounts.mint),
1329
+ getAccountMeta(accounts.systemProgram),
1330
+ getAccountMeta(accounts.tokenProgram),
1331
+ getAccountMeta(accounts.associatedTokenProgram)
1332
+ ],
1333
+ data: getWithdrawInstructionDataEncoder().encode(
1334
+ args
1335
+ ),
1336
+ programAddress
1337
+ });
1338
+ }
1339
+ function parseWithdrawInstruction(instruction) {
1340
+ if (instruction.accounts.length < 9) {
1341
+ throw new Error("Not enough accounts");
1342
+ }
1343
+ let accountIndex = 0;
1344
+ const getNextAccount = () => {
1345
+ const accountMeta = instruction.accounts[accountIndex];
1346
+ accountIndex += 1;
1347
+ return accountMeta;
1348
+ };
1349
+ return {
1350
+ programAddress: instruction.programAddress,
1351
+ accounts: {
1352
+ authority: getNextAccount(),
1353
+ pool: getNextAccount(),
1354
+ vault: getNextAccount(),
1355
+ vaultAta: getNextAccount(),
1356
+ authorityAta: getNextAccount(),
1357
+ mint: getNextAccount(),
1358
+ systemProgram: getNextAccount(),
1359
+ tokenProgram: getNextAccount(),
1360
+ associatedTokenProgram: getNextAccount()
1361
+ },
1362
+ data: getWithdrawInstructionDataDecoder().decode(instruction.data)
1363
+ };
1364
+ }
1088
1365
  var poseidon;
1089
1366
  async function initPoseidon() {
1090
1367
  if (!poseidon) {
@@ -1420,7 +1697,9 @@ exports.MixoorInstruction = MixoorInstruction;
1420
1697
  exports.NULLIFIER_ACCOUNT_DISCRIMINATOR = NULLIFIER_ACCOUNT_DISCRIMINATOR;
1421
1698
  exports.POOL_DISCRIMINATOR = POOL_DISCRIMINATOR;
1422
1699
  exports.TRANSFER_DISCRIMINATOR = TRANSFER_DISCRIMINATOR;
1700
+ exports.UPDATE_ROOT_DISCRIMINATOR = UPDATE_ROOT_DISCRIMINATOR;
1423
1701
  exports.VAULT_DISCRIMINATOR = VAULT_DISCRIMINATOR;
1702
+ exports.WITHDRAW_DISCRIMINATOR = WITHDRAW_DISCRIMINATOR;
1424
1703
  exports.decodeNullifierAccount = decodeNullifierAccount;
1425
1704
  exports.decodePool = decodePool;
1426
1705
  exports.decodeVault = decodeVault;
@@ -1483,17 +1762,30 @@ exports.getTransferInstructionAsync = getTransferInstructionAsync;
1483
1762
  exports.getTransferInstructionDataCodec = getTransferInstructionDataCodec;
1484
1763
  exports.getTransferInstructionDataDecoder = getTransferInstructionDataDecoder;
1485
1764
  exports.getTransferInstructionDataEncoder = getTransferInstructionDataEncoder;
1765
+ exports.getUpdateRootDiscriminatorBytes = getUpdateRootDiscriminatorBytes;
1766
+ exports.getUpdateRootInstruction = getUpdateRootInstruction;
1767
+ exports.getUpdateRootInstructionDataCodec = getUpdateRootInstructionDataCodec;
1768
+ exports.getUpdateRootInstructionDataDecoder = getUpdateRootInstructionDataDecoder;
1769
+ exports.getUpdateRootInstructionDataEncoder = getUpdateRootInstructionDataEncoder;
1486
1770
  exports.getVaultCodec = getVaultCodec;
1487
1771
  exports.getVaultDecoder = getVaultDecoder;
1488
1772
  exports.getVaultDiscriminatorBytes = getVaultDiscriminatorBytes;
1489
1773
  exports.getVaultEncoder = getVaultEncoder;
1490
1774
  exports.getVaultSize = getVaultSize;
1775
+ exports.getWithdrawDiscriminatorBytes = getWithdrawDiscriminatorBytes;
1776
+ exports.getWithdrawInstruction = getWithdrawInstruction;
1777
+ exports.getWithdrawInstructionAsync = getWithdrawInstructionAsync;
1778
+ exports.getWithdrawInstructionDataCodec = getWithdrawInstructionDataCodec;
1779
+ exports.getWithdrawInstructionDataDecoder = getWithdrawInstructionDataDecoder;
1780
+ exports.getWithdrawInstructionDataEncoder = getWithdrawInstructionDataEncoder;
1491
1781
  exports.identifyMixoorAccount = identifyMixoorAccount;
1492
1782
  exports.identifyMixoorInstruction = identifyMixoorInstruction;
1493
1783
  exports.isMixoorError = isMixoorError;
1494
1784
  exports.parseDepositInstruction = parseDepositInstruction;
1495
1785
  exports.parseInitializePoolInstruction = parseInitializePoolInstruction;
1496
1786
  exports.parseTransferInstruction = parseTransferInstruction;
1787
+ exports.parseUpdateRootInstruction = parseUpdateRootInstruction;
1788
+ exports.parseWithdrawInstruction = parseWithdrawInstruction;
1497
1789
  exports.poseidonHash = poseidonHash;
1498
1790
  exports.randomBytes = randomBytes;
1499
1791
  exports.toHex = toHex;