@nosana/kit
Version:
Nosana KIT
122 lines • 5.19 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
import { MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const NEW_DISTRIBUTOR_DISCRIMINATOR = new Uint8Array([
32, 139, 112, 171, 0, 2, 225, 155,
]);
export function getNewDistributorDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(NEW_DISTRIBUTOR_DISCRIMINATOR);
}
export function getNewDistributorInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['version', getU64Encoder()],
['root', fixEncoderSize(getBytesEncoder(), 32)],
['maxTotalClaim', getU64Encoder()],
['maxNumNodes', getU64Encoder()],
['startVestingTs', getI64Encoder()],
['endVestingTs', getI64Encoder()],
['clawbackStartTs', getI64Encoder()],
['enableSlot', getU64Encoder()],
['closable', getBooleanEncoder()],
]), (value) => ({ ...value, discriminator: NEW_DISTRIBUTOR_DISCRIMINATOR }));
}
export function getNewDistributorInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['version', getU64Decoder()],
['root', fixDecoderSize(getBytesDecoder(), 32)],
['maxTotalClaim', getU64Decoder()],
['maxNumNodes', getU64Decoder()],
['startVestingTs', getI64Decoder()],
['endVestingTs', getI64Decoder()],
['clawbackStartTs', getI64Decoder()],
['enableSlot', getU64Decoder()],
['closable', getBooleanDecoder()],
]);
}
export function getNewDistributorInstructionDataCodec() {
return combineCodec(getNewDistributorInstructionDataEncoder(), getNewDistributorInstructionDataDecoder());
}
export function getNewDistributorInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
distributor: { value: input.distributor ?? null, isWritable: true },
clawbackReceiver: {
value: input.clawbackReceiver ?? null,
isWritable: true,
},
mint: { value: input.mint ?? null, isWritable: false },
tokenVault: { value: input.tokenVault ?? null, isWritable: false },
admin: { value: input.admin ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
associatedTokenProgram: {
value: input.associatedTokenProgram ?? null,
isWritable: false,
},
tokenProgram: { value: input.tokenProgram ?? 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';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.distributor),
getAccountMeta(accounts.clawbackReceiver),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.tokenVault),
getAccountMeta(accounts.admin),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.tokenProgram),
],
data: getNewDistributorInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseNewDistributorInstruction(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: {
distributor: getNextAccount(),
clawbackReceiver: getNextAccount(),
mint: getNextAccount(),
tokenVault: getNextAccount(),
admin: getNextAccount(),
systemProgram: getNextAccount(),
associatedTokenProgram: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getNewDistributorInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=newDistributor.js.map