UNPKG

@nosana/kit

Version:

Nosana KIT

120 lines 5.05 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { NOSANA_JOBS_PROGRAM_ADDRESS } from '../programs/index.js'; import { getAccountMetaFactory } from '../shared/index.js'; export const ASSIGN_DISCRIMINATOR = new Uint8Array([ 73, 66, 125, 203, 81, 41, 64, 135, ]); export function getAssignDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(ASSIGN_DISCRIMINATOR); } export function getAssignInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['ipfsJob', fixEncoderSize(getBytesEncoder(), 32)], ['timeout', getI64Encoder()], ]), (value) => ({ ...value, discriminator: ASSIGN_DISCRIMINATOR })); } export function getAssignInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['ipfsJob', fixDecoderSize(getBytesDecoder(), 32)], ['timeout', getI64Decoder()], ]); } export function getAssignInstructionDataCodec() { return combineCodec(getAssignInstructionDataEncoder(), getAssignInstructionDataDecoder()); } export function getAssignInstruction(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 }, run: { value: input.run ?? null, isWritable: true }, node: { value: input.node ?? null, isWritable: false }, user: { value: input.user ?? null, isWritable: true }, vault: { value: input.vault ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, rewardsReflection: { value: input.rewardsReflection ?? null, isWritable: true, }, rewardsVault: { value: input.rewardsVault ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, rewardsProgram: { value: input.rewardsProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.job), getAccountMeta(accounts.market), getAccountMeta(accounts.run), getAccountMeta(accounts.node), getAccountMeta(accounts.user), getAccountMeta(accounts.vault), getAccountMeta(accounts.payer), getAccountMeta(accounts.rewardsReflection), getAccountMeta(accounts.rewardsVault), getAccountMeta(accounts.authority), getAccountMeta(accounts.rewardsProgram), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.systemProgram), ], data: getAssignInstructionDataEncoder().encode(args), programAddress, }); } export function parseAssignInstruction(instruction) { if (instruction.accounts.length < 13) { // 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(), run: getNextAccount(), node: getNextAccount(), user: getNextAccount(), vault: getNextAccount(), payer: getNextAccount(), rewardsReflection: getNextAccount(), rewardsVault: getNextAccount(), authority: getNextAccount(), rewardsProgram: getNextAccount(), tokenProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getAssignInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=assign.js.map