UNPKG

@nosana/kit

Version:

Nosana KIT

90 lines 3.64 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, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit'; import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs/index.js'; import { getAccountMetaFactory } from '../shared/index.js'; export const SLASH_DISCRIMINATOR = new Uint8Array([ 204, 141, 18, 161, 8, 177, 92, 142, ]); export function getSlashDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SLASH_DISCRIMINATOR); } export function getSlashInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['amount', getU64Encoder()], ]), (value) => ({ ...value, discriminator: SLASH_DISCRIMINATOR })); } export function getSlashInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['amount', getU64Decoder()], ]); } export function getSlashInstructionDataCodec() { return combineCodec(getSlashInstructionDataEncoder(), getSlashInstructionDataDecoder()); } export function getSlashInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { vault: { value: input.vault ?? null, isWritable: true }, stake: { value: input.stake ?? null, isWritable: true }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, settings: { value: input.settings ?? null, isWritable: false }, 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'); return Object.freeze({ accounts: [ getAccountMeta(accounts.vault), getAccountMeta(accounts.stake), getAccountMeta(accounts.tokenAccount), getAccountMeta(accounts.settings), getAccountMeta(accounts.authority), getAccountMeta(accounts.tokenProgram), ], data: getSlashInstructionDataEncoder().encode(args), programAddress, }); } export function parseSlashInstruction(instruction) { if (instruction.accounts.length < 6) { // 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: { vault: getNextAccount(), stake: getNextAccount(), tokenAccount: getNextAccount(), settings: getNextAccount(), authority: getNextAccount(), tokenProgram: getNextAccount(), }, data: getSlashInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=slash.js.map