UNPKG

@nosana/kit

Version:

Nosana KIT

81 lines 3.28 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_STAKING_PROGRAM_ADDRESS } from '../programs/index.js'; import { getAccountMetaFactory } from '../shared/index.js'; export const CLOSE_DISCRIMINATOR = new Uint8Array([ 98, 165, 201, 177, 108, 65, 206, 96, ]); export function getCloseDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_DISCRIMINATOR); } export function getCloseInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_DISCRIMINATOR })); } export function getCloseInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseInstructionDataCodec() { return combineCodec(getCloseInstructionDataEncoder(), getCloseInstructionDataDecoder()); } export function getCloseInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { user: { value: input.user ?? null, isWritable: true }, stake: { value: input.stake ?? null, isWritable: true }, vault: { value: input.vault ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.user), getAccountMeta(accounts.stake), getAccountMeta(accounts.vault), getAccountMeta(accounts.authority), getAccountMeta(accounts.tokenProgram), ], data: getCloseInstructionDataEncoder().encode({}), programAddress, }); } export function parseCloseInstruction(instruction) { if (instruction.accounts.length < 5) { // 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: { user: getNextAccount(), stake: getNextAccount(), vault: getNextAccount(), authority: getNextAccount(), tokenProgram: getNextAccount(), }, data: getCloseInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=close.js.map