@nosana/kit
Version:
Nosana KIT
81 lines • 3.32 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 WITHDRAW_DISCRIMINATOR = new Uint8Array([
183, 18, 70, 156, 148, 109, 161, 34,
]);
export function getWithdrawDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
}
export function getWithdrawInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR }));
}
export function getWithdrawInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getWithdrawInstructionDataCodec() {
return combineCodec(getWithdrawInstructionDataEncoder(), getWithdrawInstructionDataDecoder());
}
export function getWithdrawInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
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 },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.user),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.stake),
getAccountMeta(accounts.authority),
getAccountMeta(accounts.tokenProgram),
],
data: getWithdrawInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseWithdrawInstruction(instruction) {
if (instruction.accounts.length < 5) {
// 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: {
user: getNextAccount(),
vault: getNextAccount(),
stake: getNextAccount(),
authority: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getWithdrawInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=withdraw.js.map