UNPKG

@nosana/kit

Version:

Nosana KIT

71 lines (70 loc) 2.73 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 CLEAN_DISCRIMINATOR = new Uint8Array([ 250, 191, 56, 128, 150, 251, 1, 103, ]); export function getCleanDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLEAN_DISCRIMINATOR); } export function getCleanInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLEAN_DISCRIMINATOR })); } export function getCleanInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCleanInstructionDataCodec() { return combineCodec(getCleanInstructionDataEncoder(), getCleanInstructionDataDecoder()); } export function getCleanInstruction(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: false }, payer: { value: input.payer ?? null, isWritable: true }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.job), getAccountMeta(accounts.market), getAccountMeta(accounts.payer), ], programAddress, data: getCleanInstructionDataEncoder().encode({}), }; return instruction; } export function parseCleanInstruction(instruction) { if (instruction.accounts.length < 3) { // 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(), payer: getNextAccount(), }, data: getCleanInstructionDataDecoder().decode(instruction.data), }; }