@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 +205 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +198 -1
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/src/generated/instructions/index.d.ts +1 -0
- package/dist/types/src/generated/instructions/index.d.ts.map +1 -1
- package/dist/types/src/generated/instructions/withdraw.d.ts +80 -0
- package/dist/types/src/generated/instructions/withdraw.d.ts.map +1 -0
- package/dist/types/src/generated/programs/mixoor.d.ts +6 -3
- package/dist/types/src/generated/programs/mixoor.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/src/index.mjs
CHANGED
|
@@ -307,6 +307,7 @@ 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["Withdraw"] = 3] = "Withdraw";
|
|
310
311
|
return MixoorInstruction2;
|
|
311
312
|
})(MixoorInstruction || {});
|
|
312
313
|
function identifyMixoorInstruction(instruction) {
|
|
@@ -338,6 +339,15 @@ function identifyMixoorInstruction(instruction) {
|
|
|
338
339
|
)) {
|
|
339
340
|
return 2 /* Transfer */;
|
|
340
341
|
}
|
|
342
|
+
if (containsBytes(
|
|
343
|
+
data,
|
|
344
|
+
fixEncoderSize(getBytesEncoder(), 8).encode(
|
|
345
|
+
new Uint8Array([183, 18, 70, 156, 148, 109, 161, 34])
|
|
346
|
+
),
|
|
347
|
+
0
|
|
348
|
+
)) {
|
|
349
|
+
return 3 /* Withdraw */;
|
|
350
|
+
}
|
|
341
351
|
throw new Error(
|
|
342
352
|
"The provided instruction could not be identified as a mixoor instruction."
|
|
343
353
|
);
|
|
@@ -1061,6 +1071,193 @@ function parseTransferInstruction(instruction) {
|
|
|
1061
1071
|
data: getTransferInstructionDataDecoder().decode(instruction.data)
|
|
1062
1072
|
};
|
|
1063
1073
|
}
|
|
1074
|
+
var WITHDRAW_DISCRIMINATOR = new Uint8Array([
|
|
1075
|
+
183,
|
|
1076
|
+
18,
|
|
1077
|
+
70,
|
|
1078
|
+
156,
|
|
1079
|
+
148,
|
|
1080
|
+
109,
|
|
1081
|
+
161,
|
|
1082
|
+
34
|
|
1083
|
+
]);
|
|
1084
|
+
function getWithdrawDiscriminatorBytes() {
|
|
1085
|
+
return fixEncoderSize(getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
|
|
1086
|
+
}
|
|
1087
|
+
function getWithdrawInstructionDataEncoder() {
|
|
1088
|
+
return transformEncoder(
|
|
1089
|
+
getStructEncoder([
|
|
1090
|
+
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
|
1091
|
+
["amount", getU64Encoder()]
|
|
1092
|
+
]),
|
|
1093
|
+
(value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR })
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
function getWithdrawInstructionDataDecoder() {
|
|
1097
|
+
return getStructDecoder([
|
|
1098
|
+
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
|
1099
|
+
["amount", getU64Decoder()]
|
|
1100
|
+
]);
|
|
1101
|
+
}
|
|
1102
|
+
function getWithdrawInstructionDataCodec() {
|
|
1103
|
+
return combineCodec(
|
|
1104
|
+
getWithdrawInstructionDataEncoder(),
|
|
1105
|
+
getWithdrawInstructionDataDecoder()
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
async function getWithdrawInstructionAsync(input, config) {
|
|
1109
|
+
const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
|
|
1110
|
+
const originalAccounts = {
|
|
1111
|
+
authority: { value: input.authority ?? null, isWritable: true },
|
|
1112
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
1113
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
1114
|
+
vaultAta: { value: input.vaultAta ?? null, isWritable: false },
|
|
1115
|
+
authorityAta: { value: input.authorityAta ?? null, isWritable: false },
|
|
1116
|
+
mint: { value: input.mint ?? null, isWritable: true },
|
|
1117
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
1118
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
1119
|
+
associatedTokenProgram: {
|
|
1120
|
+
value: input.associatedTokenProgram ?? null,
|
|
1121
|
+
isWritable: false
|
|
1122
|
+
}
|
|
1123
|
+
};
|
|
1124
|
+
const accounts = originalAccounts;
|
|
1125
|
+
const args = { ...input };
|
|
1126
|
+
if (!accounts.authority.value) {
|
|
1127
|
+
accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
|
|
1128
|
+
}
|
|
1129
|
+
if (!accounts.vault.value) {
|
|
1130
|
+
accounts.vault.value = await getProgramDerivedAddress({
|
|
1131
|
+
programAddress,
|
|
1132
|
+
seeds: [
|
|
1133
|
+
getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
|
|
1134
|
+
getAddressEncoder().encode(expectAddress(accounts.pool.value))
|
|
1135
|
+
]
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
if (!accounts.tokenProgram.value) {
|
|
1139
|
+
accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
1140
|
+
}
|
|
1141
|
+
if (!accounts.vaultAta.value) {
|
|
1142
|
+
accounts.vaultAta.value = await getProgramDerivedAddress({
|
|
1143
|
+
programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
1144
|
+
seeds: [
|
|
1145
|
+
getAddressEncoder().encode(expectAddress(accounts.vault.value)),
|
|
1146
|
+
getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
|
|
1147
|
+
getAddressEncoder().encode(expectAddress(accounts.mint.value))
|
|
1148
|
+
]
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
if (!accounts.authorityAta.value) {
|
|
1152
|
+
accounts.authorityAta.value = await getProgramDerivedAddress({
|
|
1153
|
+
programAddress: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
|
|
1154
|
+
seeds: [
|
|
1155
|
+
getAddressEncoder().encode(expectAddress(accounts.authority.value)),
|
|
1156
|
+
getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)),
|
|
1157
|
+
getAddressEncoder().encode(expectAddress(accounts.mint.value))
|
|
1158
|
+
]
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
if (!accounts.systemProgram.value) {
|
|
1162
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1163
|
+
}
|
|
1164
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
1165
|
+
accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
1166
|
+
}
|
|
1167
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
1168
|
+
return Object.freeze({
|
|
1169
|
+
accounts: [
|
|
1170
|
+
getAccountMeta(accounts.authority),
|
|
1171
|
+
getAccountMeta(accounts.pool),
|
|
1172
|
+
getAccountMeta(accounts.vault),
|
|
1173
|
+
getAccountMeta(accounts.vaultAta),
|
|
1174
|
+
getAccountMeta(accounts.authorityAta),
|
|
1175
|
+
getAccountMeta(accounts.mint),
|
|
1176
|
+
getAccountMeta(accounts.systemProgram),
|
|
1177
|
+
getAccountMeta(accounts.tokenProgram),
|
|
1178
|
+
getAccountMeta(accounts.associatedTokenProgram)
|
|
1179
|
+
],
|
|
1180
|
+
data: getWithdrawInstructionDataEncoder().encode(
|
|
1181
|
+
args
|
|
1182
|
+
),
|
|
1183
|
+
programAddress
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
function getWithdrawInstruction(input, config) {
|
|
1187
|
+
const programAddress = config?.programAddress ?? MIXOOR_PROGRAM_ADDRESS;
|
|
1188
|
+
const originalAccounts = {
|
|
1189
|
+
authority: { value: input.authority ?? null, isWritable: true },
|
|
1190
|
+
pool: { value: input.pool ?? null, isWritable: true },
|
|
1191
|
+
vault: { value: input.vault ?? null, isWritable: true },
|
|
1192
|
+
vaultAta: { value: input.vaultAta ?? null, isWritable: false },
|
|
1193
|
+
authorityAta: { value: input.authorityAta ?? null, isWritable: false },
|
|
1194
|
+
mint: { value: input.mint ?? null, isWritable: true },
|
|
1195
|
+
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
|
1196
|
+
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
|
|
1197
|
+
associatedTokenProgram: {
|
|
1198
|
+
value: input.associatedTokenProgram ?? null,
|
|
1199
|
+
isWritable: false
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
const accounts = originalAccounts;
|
|
1203
|
+
const args = { ...input };
|
|
1204
|
+
if (!accounts.authority.value) {
|
|
1205
|
+
accounts.authority.value = "AdUKMLxLi18EfLqLFQvDaizXmvGoDFaNQfQU681vbTje";
|
|
1206
|
+
}
|
|
1207
|
+
if (!accounts.tokenProgram.value) {
|
|
1208
|
+
accounts.tokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
1209
|
+
}
|
|
1210
|
+
if (!accounts.systemProgram.value) {
|
|
1211
|
+
accounts.systemProgram.value = "11111111111111111111111111111111";
|
|
1212
|
+
}
|
|
1213
|
+
if (!accounts.associatedTokenProgram.value) {
|
|
1214
|
+
accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
1215
|
+
}
|
|
1216
|
+
const getAccountMeta = getAccountMetaFactory(programAddress);
|
|
1217
|
+
return Object.freeze({
|
|
1218
|
+
accounts: [
|
|
1219
|
+
getAccountMeta(accounts.authority),
|
|
1220
|
+
getAccountMeta(accounts.pool),
|
|
1221
|
+
getAccountMeta(accounts.vault),
|
|
1222
|
+
getAccountMeta(accounts.vaultAta),
|
|
1223
|
+
getAccountMeta(accounts.authorityAta),
|
|
1224
|
+
getAccountMeta(accounts.mint),
|
|
1225
|
+
getAccountMeta(accounts.systemProgram),
|
|
1226
|
+
getAccountMeta(accounts.tokenProgram),
|
|
1227
|
+
getAccountMeta(accounts.associatedTokenProgram)
|
|
1228
|
+
],
|
|
1229
|
+
data: getWithdrawInstructionDataEncoder().encode(
|
|
1230
|
+
args
|
|
1231
|
+
),
|
|
1232
|
+
programAddress
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
function parseWithdrawInstruction(instruction) {
|
|
1236
|
+
if (instruction.accounts.length < 9) {
|
|
1237
|
+
throw new Error("Not enough accounts");
|
|
1238
|
+
}
|
|
1239
|
+
let accountIndex = 0;
|
|
1240
|
+
const getNextAccount = () => {
|
|
1241
|
+
const accountMeta = instruction.accounts[accountIndex];
|
|
1242
|
+
accountIndex += 1;
|
|
1243
|
+
return accountMeta;
|
|
1244
|
+
};
|
|
1245
|
+
return {
|
|
1246
|
+
programAddress: instruction.programAddress,
|
|
1247
|
+
accounts: {
|
|
1248
|
+
authority: getNextAccount(),
|
|
1249
|
+
pool: getNextAccount(),
|
|
1250
|
+
vault: getNextAccount(),
|
|
1251
|
+
vaultAta: getNextAccount(),
|
|
1252
|
+
authorityAta: getNextAccount(),
|
|
1253
|
+
mint: getNextAccount(),
|
|
1254
|
+
systemProgram: getNextAccount(),
|
|
1255
|
+
tokenProgram: getNextAccount(),
|
|
1256
|
+
associatedTokenProgram: getNextAccount()
|
|
1257
|
+
},
|
|
1258
|
+
data: getWithdrawInstructionDataDecoder().decode(instruction.data)
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1064
1261
|
var poseidon;
|
|
1065
1262
|
async function initPoseidon() {
|
|
1066
1263
|
if (!poseidon) {
|
|
@@ -1372,6 +1569,6 @@ async function findNullifierAddress(seeds, config = {}) {
|
|
|
1372
1569
|
});
|
|
1373
1570
|
}
|
|
1374
1571
|
|
|
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 };
|
|
1572
|
+
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, 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, getVaultCodec, getVaultDecoder, getVaultDiscriminatorBytes, getVaultEncoder, getVaultSize, getWithdrawDiscriminatorBytes, getWithdrawInstruction, getWithdrawInstructionAsync, getWithdrawInstructionDataCodec, getWithdrawInstructionDataDecoder, getWithdrawInstructionDataEncoder, identifyMixoorAccount, identifyMixoorInstruction, isMixoorError, parseDepositInstruction, parseInitializePoolInstruction, parseTransferInstruction, parseWithdrawInstruction, poseidonHash, randomBytes, toHex };
|
|
1376
1573
|
//# sourceMappingURL=index.mjs.map
|
|
1377
1574
|
//# sourceMappingURL=index.mjs.map
|