@nosana/kit
Version:
Nosana KIT
101 lines • 4.28 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, 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_CLAIM_DISCRIMINATOR = new Uint8Array([
78, 177, 98, 123, 210, 21, 187, 83,
]);
export function getNewClaimDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(NEW_CLAIM_DISCRIMINATOR);
}
export function getNewClaimInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['amountUnlocked', getU64Encoder()],
['amountLocked', getU64Encoder()],
['proof', getArrayEncoder(fixEncoderSize(getBytesEncoder(), 32))],
]), (value) => ({ ...value, discriminator: NEW_CLAIM_DISCRIMINATOR }));
}
export function getNewClaimInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['amountUnlocked', getU64Decoder()],
['amountLocked', getU64Decoder()],
['proof', getArrayDecoder(fixDecoderSize(getBytesDecoder(), 32))],
]);
}
export function getNewClaimInstructionDataCodec() {
return combineCodec(getNewClaimInstructionDataEncoder(), getNewClaimInstructionDataDecoder());
}
export function getNewClaimInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
distributor: { value: input.distributor ?? null, isWritable: true },
claimStatus: { value: input.claimStatus ?? null, isWritable: true },
from: { value: input.from ?? null, isWritable: true },
to: { value: input.to ?? null, isWritable: true },
claimant: { value: input.claimant ?? null, isWritable: true },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.distributor),
getAccountMeta(accounts.claimStatus),
getAccountMeta(accounts.from),
getAccountMeta(accounts.to),
getAccountMeta(accounts.claimant),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getNewClaimInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseNewClaimInstruction(instruction) {
if (instruction.accounts.length < 7) {
// 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(),
claimStatus: getNextAccount(),
from: getNextAccount(),
to: getNextAccount(),
claimant: getNextAccount(),
tokenProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getNewClaimInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=newClaim.js.map