UNPKG

@nosana/kit

Version:

Nosana KIT

82 lines (81 loc) 3.32 kB
/** * 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, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { NOSANA_JOBS_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory } from '../shared'; export const CLOSE_ADMIN_DISCRIMINATOR = new Uint8Array([ 202, 182, 185, 142, 208, 161, 145, 189, ]); export function getCloseAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_ADMIN_DISCRIMINATOR); } export function getCloseAdminInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_ADMIN_DISCRIMINATOR })); } export function getCloseAdminInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseAdminInstructionDataCodec() { return combineCodec(getCloseAdminInstructionDataEncoder(), getCloseAdminInstructionDataDecoder()); } export function getCloseAdminInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { market: { value: input.market ?? null, isWritable: true }, vault: { value: input.vault ?? null, isWritable: true }, user: { value: input.user ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.market), getAccountMeta(accounts.vault), getAccountMeta(accounts.user), getAccountMeta(accounts.authority), getAccountMeta(accounts.tokenProgram), ], programAddress, data: getCloseAdminInstructionDataEncoder().encode({}), }; return instruction; } export function parseCloseAdminInstruction(instruction) { if (instruction.accounts.length < 5) { // 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: { market: getNextAccount(), vault: getNextAccount(), user: getNextAccount(), authority: getNextAccount(), tokenProgram: getNextAccount(), }, data: getCloseAdminInstructionDataDecoder().decode(instruction.data), }; }