@nosana/kit
Version:
Nosana KIT
70 lines • 2.81 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, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const RESTAKE_DISCRIMINATOR = new Uint8Array([
97, 161, 241, 167, 6, 32, 213, 53,
]);
export function getRestakeDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(RESTAKE_DISCRIMINATOR);
}
export function getRestakeInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: RESTAKE_DISCRIMINATOR }));
}
export function getRestakeInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getRestakeInstructionDataCodec() {
return combineCodec(getRestakeInstructionDataEncoder(), getRestakeInstructionDataDecoder());
}
export function getRestakeInstruction(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 },
authority: { value: input.authority ?? null, isWritable: false },
};
const accounts = originalAccounts;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.vault),
getAccountMeta(accounts.stake),
getAccountMeta(accounts.authority),
],
data: getRestakeInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseRestakeInstruction(instruction) {
if (instruction.accounts.length < 3) {
// 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(),
authority: getNextAccount(),
},
data: getRestakeInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=restake.js.map