@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
109 lines • 4.93 kB
JavaScript
;
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DELETE_CONTRACT_DISCRIMINATOR = void 0;
exports.getDeleteContractDiscriminatorBytes = getDeleteContractDiscriminatorBytes;
exports.getDeleteContractInstructionDataEncoder = getDeleteContractInstructionDataEncoder;
exports.getDeleteContractInstructionDataDecoder = getDeleteContractInstructionDataDecoder;
exports.getDeleteContractInstructionDataCodec = getDeleteContractInstructionDataCodec;
exports.getDeleteContractInstructionAsync = getDeleteContractInstructionAsync;
exports.getDeleteContractInstruction = getDeleteContractInstruction;
exports.parseDeleteContractInstruction = parseDeleteContractInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.DELETE_CONTRACT_DISCRIMINATOR = new Uint8Array([189, 115, 12, 22, 241, 49, 35, 6]);
function getDeleteContractDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.DELETE_CONTRACT_DISCRIMINATOR);
}
function getDeleteContractInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), value => ({ ...value, discriminator: exports.DELETE_CONTRACT_DISCRIMINATOR }));
}
function getDeleteContractInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)]]);
}
function getDeleteContractInstructionDataCodec() {
return (0, kit_1.combineCodec)(getDeleteContractInstructionDataEncoder(), getDeleteContractInstructionDataDecoder());
}
async function getDeleteContractInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
owner: { value: input.owner ?? null, isWritable: true },
contract: { value: input.contract ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.config.value) {
accounts.config.value = await (0, kit_1.getProgramDerivedAddress)({
programAddress,
seeds: [(0, kit_1.getBytesEncoder)().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))],
});
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.admin),
getAccountMeta(accounts.config),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contract),
],
data: getDeleteContractInstructionDataEncoder().encode({}),
programAddress,
});
}
function getDeleteContractInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
owner: { value: input.owner ?? null, isWritable: true },
contract: { value: input.contract ?? null, isWritable: true },
};
const accounts = originalAccounts;
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.admin),
getAccountMeta(accounts.config),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contract),
],
data: getDeleteContractInstructionDataEncoder().encode({}),
programAddress,
});
}
function parseDeleteContractInstruction(instruction) {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
admin: getNextAccount(),
config: getNextAccount(),
owner: getNextAccount(),
contract: getNextAccount(),
},
data: getDeleteContractInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=deleteContract.js.map