UNPKG

@nosana/kit

Version:

Nosana KIT

73 lines 3.13 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 UPDATE_SETTINGS_DISCRIMINATOR = new Uint8Array([ 81, 166, 51, 213, 158, 84, 157, 108, ]); export function getUpdateSettingsDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_SETTINGS_DISCRIMINATOR); } export function getUpdateSettingsInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: UPDATE_SETTINGS_DISCRIMINATOR })); } export function getUpdateSettingsInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getUpdateSettingsInstructionDataCodec() { return combineCodec(getUpdateSettingsInstructionDataEncoder(), getUpdateSettingsInstructionDataDecoder()); } export function getUpdateSettingsInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { newAuthority: { value: input.newAuthority ?? null, isWritable: false }, tokenAccount: { value: input.tokenAccount ?? null, isWritable: false }, settings: { value: input.settings ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.newAuthority), getAccountMeta(accounts.tokenAccount), getAccountMeta(accounts.settings), getAccountMeta(accounts.authority), ], data: getUpdateSettingsInstructionDataEncoder().encode({}), programAddress, }); } export function parseUpdateSettingsInstruction(instruction) { if (instruction.accounts.length < 4) { // 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: { newAuthority: getNextAccount(), tokenAccount: getNextAccount(), settings: getNextAccount(), authority: getNextAccount(), }, data: getUpdateSettingsInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=updateSettings.js.map