@smithii_io/mixoor 0.0.12 → 0.0.13

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,7 @@ 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["Withdraw"] = 3] = "Withdraw";
334
335
  return MixoorInstruction2;
335
336
  })(MixoorInstruction || {});
336
337
  function identifyMixoorInstruction(instruction) {
@@ -362,6 +363,15 @@ function identifyMixoorInstruction(instruction) {
362
363
  )) {
363
364
  return 2 /* Transfer */;
364
365
  }
366
+ if (kit.containsBytes(
367
+ data,
368
+ kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(
369
+ new Uint8Array([183, 18, 70, 156, 148, 109, 161, 34])
370
+ ),
371
+ 0
372
+ )) {
373
+ return 3 /* Withdraw */;
374
+ }
365
375
  throw new Error(
366
376
  "The provided instruction could not be identified as a mixoor instruction."
367
377
  );
@@ -1085,6 +1095,193 @@ function parseTransferInstruction(instruction) {
1085
1095
  data: getTransferInstructionDataDecoder().decode(instruction.data)
1086
1096
  };
1087
1097
  }
1098
+ var WITHDRAW_DISCRIMINATOR = new Uint8Array([
1099
+ 183,
1100
+ 18,
1101
+ 70,
1102
+ 156,
1103
+ 148,
1104
+ 109,
1105
+ 161,
1106
+ 34
1107
+ ]);
1108
+ function getWithdrawDiscriminatorBytes() {
1109
+ return kit.fixEncoderSize(kit.getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
1110
+ }
1111
+ function getWithdrawInstructionDataEncoder() {
1112
+ return kit.transformEncoder(
1113
+ kit.getStructEncoder([
1114
+ ["discriminator", kit.fixEncoderSize(kit.getBytesEncoder(), 8)],
1115
+ ["amount", kit.getU64Encoder()]
1116
+ ]),
1117
+ (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR })
1118
+ );
1119
+ }
1120
+ function getWithdrawInstructionDataDecoder() {
1121
+ return kit.getStructDecoder([
1122
+ ["discriminator", kit.fixDecoderSize(kit.getBytesDecoder(), 8)],
1123
+ ["amount", kit.getU64Decoder()]
1124
+ ]);
1125
+ }
1126
+ function getWithdrawInstructionDataCodec() {
1127
+ return kit.combineCodec(
1128
+ getWithdrawInstructionDataEncoder(),
1129
+ getWithdrawInstructionDataDecoder()
1130
+ );
1131
+ }
1132
+ async function getWithdrawInstructionAsync(input, config) {
1133
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1134
+ const originalAccounts = {
1135
+ authority: { value: input.authority ?? null, isWritable: true },
1136
+ pool: { value: input.pool ?? null, isWritable: true },
1137
+ vault: { value: input.vault ?? null, isWritable: true },
1138
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1139
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1140
+ mint: { value: input.mint ?? null, isWritable: true },
1141
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1142
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1143
+ associatedTokenProgram: {
1144
+ value: input.associatedTokenProgram ?? null,
1145
+ isWritable: false
1146
+ }
1147
+ };
1148
+ const accounts = originalAccounts;
1149
+ const args = { ...input };
1150
+ if (!accounts.authority.value) {
1151
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1152
+ }
1153
+ if (!accounts.vault.value) {
1154
+ accounts.vault.value = await kit.getProgramDerivedAddress({
1155
+ programAddress,
1156
+ seeds: [
1157
+ kit.getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
1158
+ kit.getAddressEncoder().encode(expectAddress(accounts.pool.value))
1159
+ ]
1160
+ });
1161
+ }
1162
+ if (!accounts.tokenProgram.value) {
1163
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1164
+ }
1165
+ if (!accounts.vaultAta.value) {
1166
+ accounts.vaultAta.value = await kit.getProgramDerivedAddress({
1167
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1168
+ seeds: [
1169
+ kit.getAddressEncoder().encode(expectAddress(accounts.vault.value)),
1170
+ kit.getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1171
+ kit.getAddressEncoder().encode(expectAddress(accounts.mint.value))
1172
+ ]
1173
+ });
1174
+ }
1175
+ if (!accounts.authorityAta.value) {
1176
+ accounts.authorityAta.value = await kit.getProgramDerivedAddress({
1177
+ programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
1178
+ seeds: [
1179
+ kit.getAddressEncoder().encode(expectAddress(accounts.authority.value)),
1180
+ kit.getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
1181
+ kit.getAddressEncoder().encode(expectAddress(accounts.mint.value))
1182
+ ]
1183
+ });
1184
+ }
1185
+ if (!accounts.systemProgram.value) {
1186
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1187
+ }
1188
+ if (!accounts.associatedTokenProgram.value) {
1189
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1190
+ }
1191
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1192
+ return Object.freeze({
1193
+ accounts: [
1194
+ getAccountMeta(accounts.authority),
1195
+ getAccountMeta(accounts.pool),
1196
+ getAccountMeta(accounts.vault),
1197
+ getAccountMeta(accounts.vaultAta),
1198
+ getAccountMeta(accounts.authorityAta),
1199
+ getAccountMeta(accounts.mint),
1200
+ getAccountMeta(accounts.systemProgram),
1201
+ getAccountMeta(accounts.tokenProgram),
1202
+ getAccountMeta(accounts.associatedTokenProgram)
1203
+ ],
1204
+ data: getWithdrawInstructionDataEncoder().encode(
1205
+ args
1206
+ ),
1207
+ programAddress
1208
+ });
1209
+ }
1210
+ function getWithdrawInstruction(input, config) {
1211
+ const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
1212
+ const originalAccounts = {
1213
+ authority: { value: input.authority ?? null, isWritable: true },
1214
+ pool: { value: input.pool ?? null, isWritable: true },
1215
+ vault: { value: input.vault ?? null, isWritable: true },
1216
+ vaultAta: { value: input.vaultAta ?? null, isWritable: false },
1217
+ authorityAta: { value: input.authorityAta ?? null, isWritable: false },
1218
+ mint: { value: input.mint ?? null, isWritable: true },
1219
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
1220
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
1221
+ associatedTokenProgram: {
1222
+ value: input.associatedTokenProgram ?? null,
1223
+ isWritable: false
1224
+ }
1225
+ };
1226
+ const accounts = originalAccounts;
1227
+ const args = { ...input };
1228
+ if (!accounts.authority.value) {
1229
+ accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
1230
+ }
1231
+ if (!accounts.tokenProgram.value) {
1232
+ accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1233
+ }
1234
+ if (!accounts.systemProgram.value) {
1235
+ accounts.systemProgram.value = "11111111111111111111111111111111";
1236
+ }
1237
+ if (!accounts.associatedTokenProgram.value) {
1238
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
1239
+ }
1240
+ const getAccountMeta = getAccountMetaFactory(programAddress);
1241
+ return Object.freeze({
1242
+ accounts: [
1243
+ getAccountMeta(accounts.authority),
1244
+ getAccountMeta(accounts.pool),
1245
+ getAccountMeta(accounts.vault),
1246
+ getAccountMeta(accounts.vaultAta),
1247
+ getAccountMeta(accounts.authorityAta),
1248
+ getAccountMeta(accounts.mint),
1249
+ getAccountMeta(accounts.systemProgram),
1250
+ getAccountMeta(accounts.tokenProgram),
1251
+ getAccountMeta(accounts.associatedTokenProgram)
1252
+ ],
1253
+ data: getWithdrawInstructionDataEncoder().encode(
1254
+ args
1255
+ ),
1256
+ programAddress
1257
+ });
1258
+ }
1259
+ function parseWithdrawInstruction(instruction) {
1260
+ if (instruction.accounts.length < 9) {
1261
+ throw new Error("Not enough accounts");
1262
+ }
1263
+ let accountIndex = 0;
1264
+ const getNextAccount = () => {
1265
+ const accountMeta = instruction.accounts[accountIndex];
1266
+ accountIndex += 1;
1267
+ return accountMeta;
1268
+ };
1269
+ return {
1270
+ programAddress: instruction.programAddress,
1271
+ accounts: {
1272
+ authority: getNextAccount(),
1273
+ pool: getNextAccount(),
1274
+ vault: getNextAccount(),
1275
+ vaultAta: getNextAccount(),
1276
+ authorityAta: getNextAccount(),
1277
+ mint: getNextAccount(),
1278
+ systemProgram: getNextAccount(),
1279
+ tokenProgram: getNextAccount(),
1280
+ associatedTokenProgram: getNextAccount()
1281
+ },
1282
+ data: getWithdrawInstructionDataDecoder().decode(instruction.data)
1283
+ };
1284
+ }
1088
1285
  var poseidon;
1089
1286
  async function initPoseidon() {
1090
1287
  if (!poseidon) {
@@ -1421,6 +1618,7 @@ exports.NULLIFIER_ACCOUNT_DISCRIMINATOR = NULLIFIER_ACCOUNT_DISCRIMINATOR;
1421
1618
  exports.POOL_DISCRIMINATOR = POOL_DISCRIMINATOR;
1422
1619
  exports.TRANSFER_DISCRIMINATOR = TRANSFER_DISCRIMINATOR;
1423
1620
  exports.VAULT_DISCRIMINATOR = VAULT_DISCRIMINATOR;
1621
+ exports.WITHDRAW_DISCRIMINATOR = WITHDRAW_DISCRIMINATOR;
1424
1622
  exports.decodeNullifierAccount = decodeNullifierAccount;
1425
1623
  exports.decodePool = decodePool;
1426
1624
  exports.decodeVault = decodeVault;
@@ -1488,12 +1686,19 @@ exports.getVaultDecoder = getVaultDecoder;
1488
1686
  exports.getVaultDiscriminatorBytes = getVaultDiscriminatorBytes;
1489
1687
  exports.getVaultEncoder = getVaultEncoder;
1490
1688
  exports.getVaultSize = getVaultSize;
1689
+ exports.getWithdrawDiscriminatorBytes = getWithdrawDiscriminatorBytes;
1690
+ exports.getWithdrawInstruction = getWithdrawInstruction;
1691
+ exports.getWithdrawInstructionAsync = getWithdrawInstructionAsync;
1692
+ exports.getWithdrawInstructionDataCodec = getWithdrawInstructionDataCodec;
1693
+ exports.getWithdrawInstructionDataDecoder = getWithdrawInstructionDataDecoder;
1694
+ exports.getWithdrawInstructionDataEncoder = getWithdrawInstructionDataEncoder;
1491
1695
  exports.identifyMixoorAccount = identifyMixoorAccount;
1492
1696
  exports.identifyMixoorInstruction = identifyMixoorInstruction;
1493
1697
  exports.isMixoorError = isMixoorError;
1494
1698
  exports.parseDepositInstruction = parseDepositInstruction;
1495
1699
  exports.parseInitializePoolInstruction = parseInitializePoolInstruction;
1496
1700
  exports.parseTransferInstruction = parseTransferInstruction;
1701
+ exports.parseWithdrawInstruction = parseWithdrawInstruction;
1497
1702
  exports.poseidonHash = poseidonHash;
1498
1703
  exports.randomBytes = randomBytes;
1499
1704
  exports.toHex = toHex;