UNPKG

@nosana/kit

Version:

Nosana KIT

82 lines (81 loc) 3.25 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_DISCRIMINATOR = new Uint8Array([ 98, 165, 201, 177, 108, 65, 206, 96, ]); export function getCloseDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_DISCRIMINATOR); } export function getCloseInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_DISCRIMINATOR })); } export function getCloseInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseInstructionDataCodec() { return combineCodec(getCloseInstructionDataEncoder(), getCloseInstructionDataDecoder()); } export function getCloseInstruction(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: getCloseInstructionDataEncoder().encode({}), }; return instruction; } export function parseCloseInstruction(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: getCloseInstructionDataDecoder().decode(instruction.data), }; }