UNPKG

@nosana/kit

Version:

Nosana KIT

103 lines (102 loc) 4.19 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 FINISH_DISCRIMINATOR = new Uint8Array([ 67, 74, 170, 132, 125, 233, 182, 37, ]); export function getFinishDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(FINISH_DISCRIMINATOR); } export function getFinishInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['ipfsResult', fixEncoderSize(getBytesEncoder(), 32)], ]), (value) => ({ ...value, discriminator: FINISH_DISCRIMINATOR })); } export function getFinishInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['ipfsResult', fixDecoderSize(getBytesDecoder(), 32)], ]); } export function getFinishInstructionDataCodec() { return combineCodec(getFinishInstructionDataEncoder(), getFinishInstructionDataDecoder()); } export function getFinishInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { job: { value: input.job ?? null, isWritable: true }, run: { value: input.run ?? null, isWritable: true }, market: { value: input.market ?? null, isWritable: false }, vault: { value: input.vault ?? null, isWritable: true }, deposit: { value: input.deposit ?? null, isWritable: true }, user: { value: input.user ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, project: { value: input.project ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.job), getAccountMeta(accounts.run), getAccountMeta(accounts.market), getAccountMeta(accounts.vault), getAccountMeta(accounts.deposit), getAccountMeta(accounts.user), getAccountMeta(accounts.payer), getAccountMeta(accounts.project), getAccountMeta(accounts.authority), getAccountMeta(accounts.tokenProgram), ], programAddress, data: getFinishInstructionDataEncoder().encode(args), }; return instruction; } export function parseFinishInstruction(instruction) { if (instruction.accounts.length < 10) { // 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(), run: getNextAccount(), market: getNextAccount(), vault: getNextAccount(), deposit: getNextAccount(), user: getNextAccount(), payer: getNextAccount(), project: getNextAccount(), authority: getNextAccount(), tokenProgram: getNextAccount(), }, data: getFinishInstructionDataDecoder().decode(instruction.data), }; }