UNPKG

@nosana/kit

Version:

Nosana KIT

70 lines 2.8 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 EXTEND_DISCRIMINATOR = new Uint8Array([ 228, 127, 0, 1, 227, 154, 54, 168, ]); export function getExtendDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(EXTEND_DISCRIMINATOR); } export function getExtendInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['duration', getU64Encoder()], ]), (value) => ({ ...value, discriminator: EXTEND_DISCRIMINATOR })); } export function getExtendInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['duration', getU64Decoder()], ]); } export function getExtendInstructionDataCodec() { return combineCodec(getExtendInstructionDataEncoder(), getExtendInstructionDataDecoder()); } export function getExtendInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { stake: { value: input.stake ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.stake), getAccountMeta(accounts.authority), ], data: getExtendInstructionDataEncoder().encode(args), programAddress, }); } export function parseExtendInstruction(instruction) { if (instruction.accounts.length < 2) { // 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: { stake: getNextAccount(), authority: getNextAccount() }, data: getExtendInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=extend.js.map