@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
99 lines • 4.26 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
*/
import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory } from '../shared';
export const DELETE_CONTRACT_DISCRIMINATOR = new Uint8Array([189, 115, 12, 22, 241, 49, 35, 6]);
export function getDeleteContractDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(DELETE_CONTRACT_DISCRIMINATOR);
}
export function getDeleteContractInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: DELETE_CONTRACT_DISCRIMINATOR }));
}
export function getDeleteContractInstructionDataDecoder() {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getDeleteContractInstructionDataCodec() {
return combineCodec(getDeleteContractInstructionDataEncoder(), getDeleteContractInstructionDataDecoder());
}
export async function getDeleteContractInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? 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 getProgramDerivedAddress({
programAddress,
seeds: [getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))],
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.admin),
getAccountMeta(accounts.config),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contract),
],
data: getDeleteContractInstructionDataEncoder().encode({}),
programAddress,
});
}
export function getDeleteContractInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? 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 = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.admin),
getAccountMeta(accounts.config),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contract),
],
data: getDeleteContractInstructionDataEncoder().encode({}),
programAddress,
});
}
export 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