@nosana/kit
Version:
Nosana KIT
84 lines • 3.58 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 { MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const CLOSE_DISTRIBUTOR_DISCRIMINATOR = new Uint8Array([
202, 56, 180, 143, 46, 104, 106, 112,
]);
export function getCloseDistributorDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_DISTRIBUTOR_DISCRIMINATOR);
}
export function getCloseDistributorInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_DISTRIBUTOR_DISCRIMINATOR }));
}
export function getCloseDistributorInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getCloseDistributorInstructionDataCodec() {
return combineCodec(getCloseDistributorInstructionDataEncoder(), getCloseDistributorInstructionDataDecoder());
}
export function getCloseDistributorInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
distributor: { value: input.distributor ?? null, isWritable: true },
tokenVault: { value: input.tokenVault ?? null, isWritable: true },
admin: { value: input.admin ?? null, isWritable: true },
destinationTokenAccount: {
value: input.destinationTokenAccount ?? 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.distributor),
getAccountMeta(accounts.tokenVault),
getAccountMeta(accounts.admin),
getAccountMeta(accounts.destinationTokenAccount),
getAccountMeta(accounts.tokenProgram),
],
data: getCloseDistributorInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseCloseDistributorInstruction(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: {
distributor: getNextAccount(),
tokenVault: getNextAccount(),
admin: getNextAccount(),
destinationTokenAccount: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getCloseDistributorInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=closeDistributor.js.map