@superstateinc/allowlist
Version:
TypeScript library for interacting with the Superstate Allowlist program on Solana
45 lines • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createThawInstruction = createThawInstruction;
const web3_js_1 = require("@solana/web3.js");
const pda_1 = require("./pda");
const constants_1 = require("./constants");
/**
* Creates a thaw instruction for the allowlist program
*
* This instruction thaws a user's token account if they are allowed on either
* the public allowlist or the private allowlist for the specific mint.
*
* @param params Parameters for creating the thaw instruction
* @returns A TransactionInstruction that can be added to a transaction
*/
function createThawInstruction(params) {
const { allowlistProgramId, mint, userTokenAccountOwner, userTokenAccount, tokenProgramId = constants_1.TOKEN_2022_PROGRAM_ID, } = params;
// For the thaw instruction, we need to serialize the user_system_account (PublicKey)
// The instruction data is just the 32-byte public key
const serializedData = userTokenAccountOwner.toBuffer();
// Derive all required PDAs
const [publicAllowedAccountPda] = (0, pda_1.getPublicAllowedAccountPda)(userTokenAccountOwner, allowlistProgramId);
const [privateAllowedAccountPda] = (0, pda_1.getPrivateAllowedAccountPda)(userTokenAccountOwner, mint, allowlistProgramId);
const [privateAllowlistPda] = (0, pda_1.getPrivateAllowlistPda)(mint, allowlistProgramId);
const [allowlistProgramPda] = (0, pda_1.getAllowlistProgramPda)(allowlistProgramId);
// Build the account list in the correct order
const keys = [
{ pubkey: mint, isSigner: false, isWritable: false },
{ pubkey: userTokenAccount, isSigner: false, isWritable: true },
{ pubkey: publicAllowedAccountPda, isSigner: false, isWritable: false },
{ pubkey: privateAllowedAccountPda, isSigner: false, isWritable: false },
{ pubkey: privateAllowlistPda, isSigner: false, isWritable: false },
{ pubkey: tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: allowlistProgramPda, isSigner: false, isWritable: false },
];
// Create the instruction with discriminant and data
const instructionDiscriminant = Buffer.from([constants_1.AllowlistInstruction.Thaw]);
const data = Buffer.concat([instructionDiscriminant, Buffer.from(serializedData)]);
return new web3_js_1.TransactionInstruction({
programId: allowlistProgramId,
keys,
data,
});
}
//# sourceMappingURL=instructions.js.map