@nosana/kit
Version:
Nosana KIT
82 lines • 3.25 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 INIT_DISCRIMINATOR = new Uint8Array([
220, 59, 207, 236, 108, 250, 47, 100,
]);
export function getInitDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(INIT_DISCRIMINATOR);
}
export function getInitInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: INIT_DISCRIMINATOR }));
}
export function getInitInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getInitInstructionDataCodec() {
return combineCodec(getInitInstructionDataEncoder(), getInitInstructionDataDecoder());
}
export function getInitInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
settings: { value: input.settings ?? null, isWritable: true },
authority: { value: input.authority ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
rent: { value: input.rent ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
if (!accounts.rent.value) {
accounts.rent.value =
'SysvarRent111111111111111111111111111111111';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.settings),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.rent),
],
data: getInitInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseInitInstruction(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: {
settings: getNextAccount(),
authority: getNextAccount(),
systemProgram: getNextAccount(),
rent: getNextAccount(),
},
data: getInitInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=init.js.map