@nosana/kit
Version:
Nosana KIT
113 lines (112 loc) • 4.59 kB
JavaScript
/**
* 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, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from '@solana/kit';
import { NOSANA_JOBS_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory } from '../shared';
export const OPEN_DISCRIMINATOR = new Uint8Array([
228, 220, 155, 71, 199, 189, 60, 45,
]);
export function getOpenDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(OPEN_DISCRIMINATOR);
}
export function getOpenInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['jobExpiration', getI64Encoder()],
['jobPrice', getU64Encoder()],
['jobTimeout', getI64Encoder()],
['jobType', getU8Encoder()],
['nodeXnosMinimum', getU128Encoder()],
]), (value) => ({ ...value, discriminator: OPEN_DISCRIMINATOR }));
}
export function getOpenInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['jobExpiration', getI64Decoder()],
['jobPrice', getU64Decoder()],
['jobTimeout', getI64Decoder()],
['jobType', getU8Decoder()],
['nodeXnosMinimum', getU128Decoder()],
]);
}
export function getOpenInstructionDataCodec() {
return combineCodec(getOpenInstructionDataEncoder(), getOpenInstructionDataDecoder());
}
export function getOpenInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
mint: { value: input.mint ?? null, isWritable: false },
market: { value: input.market ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
authority: { value: input.authority ?? null, isWritable: true },
accessKey: { value: input.accessKey ?? null, isWritable: false },
rent: { value: input.rent ?? null, isWritable: false },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.rent.value) {
accounts.rent.value =
'SysvarRent111111111111111111111111111111111';
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.mint),
getAccountMeta(accounts.market),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.accessKey),
getAccountMeta(accounts.rent),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.tokenProgram),
],
programAddress,
data: getOpenInstructionDataEncoder().encode(args),
};
return instruction;
}
export function parseOpenInstruction(instruction) {
if (instruction.accounts.length < 8) {
// 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: {
mint: getNextAccount(),
market: getNextAccount(),
vault: getNextAccount(),
authority: getNextAccount(),
accessKey: getNextAccount(),
rent: getNextAccount(),
systemProgram: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getOpenInstructionDataDecoder().decode(instruction.data),
};
}