@nosana/kit
Version:
Nosana KIT
106 lines • 4.29 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, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const STAKE_DISCRIMINATOR = new Uint8Array([
206, 176, 202, 18, 200, 209, 179, 108,
]);
export function getStakeDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(STAKE_DISCRIMINATOR);
}
export function getStakeInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['amount', getU64Encoder()],
['duration', getU128Encoder()],
]), (value) => ({ ...value, discriminator: STAKE_DISCRIMINATOR }));
}
export function getStakeInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['amount', getU64Decoder()],
['duration', getU128Decoder()],
]);
}
export function getStakeInstructionDataCodec() {
return combineCodec(getStakeInstructionDataEncoder(), getStakeInstructionDataDecoder());
}
export function getStakeInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
mint: { value: input.mint ?? null, isWritable: false },
user: { value: input.user ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
stake: { value: input.stake ?? null, isWritable: true },
authority: { value: input.authority ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
rent: { value: input.rent ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
if (!accounts.rent.value) {
accounts.rent.value =
'SysvarRent111111111111111111111111111111111';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.mint),
getAccountMeta(accounts.user),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.stake),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.rent),
],
data: getStakeInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseStakeInstruction(instruction) {
if (instruction.accounts.length < 8) {
// 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: {
mint: getNextAccount(),
user: getNextAccount(),
vault: getNextAccount(),
stake: getNextAccount(),
authority: getNextAccount(),
systemProgram: getNextAccount(),
tokenProgram: getNextAccount(),
rent: getNextAccount(),
},
data: getStakeInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=stake.js.map