UNPKG

@nosana/kit

Version:

Nosana KIT

88 lines (87 loc) 3.56 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 DELIST_DISCRIMINATOR = new Uint8Array([ 55, 136, 205, 107, 107, 173, 4, 31, ]); export function getDelistDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(DELIST_DISCRIMINATOR); } export function getDelistInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: DELIST_DISCRIMINATOR })); } export function getDelistInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getDelistInstructionDataCodec() { return combineCodec(getDelistInstructionDataEncoder(), getDelistInstructionDataDecoder()); } export function getDelistInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { job: { value: input.job ?? null, isWritable: true }, market: { value: input.market ?? null, isWritable: true }, deposit: { value: input.deposit ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, vault: { value: input.vault ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: true }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.job), getAccountMeta(accounts.market), getAccountMeta(accounts.deposit), getAccountMeta(accounts.payer), getAccountMeta(accounts.vault), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.authority), ], programAddress, data: getDelistInstructionDataEncoder().encode({}), }; return instruction; } export function parseDelistInstruction(instruction) { if (instruction.accounts.length < 7) { // 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: { job: getNextAccount(), market: getNextAccount(), deposit: getNextAccount(), payer: getNextAccount(), vault: getNextAccount(), tokenProgram: getNextAccount(), authority: getNextAccount(), }, data: getDelistInstructionDataDecoder().decode(instruction.data), }; }