UNPKG

@nosana/kit

Version:

Nosana KIT

88 lines 3.65 kB
/** * 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 CLAWBACK_DISCRIMINATOR = new Uint8Array([ 111, 92, 142, 79, 33, 234, 82, 27, ]); export function getClawbackDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLAWBACK_DISCRIMINATOR); } export function getClawbackInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLAWBACK_DISCRIMINATOR })); } export function getClawbackInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getClawbackInstructionDataCodec() { return combineCodec(getClawbackInstructionDataEncoder(), getClawbackInstructionDataDecoder()); } export function getClawbackInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { distributor: { value: input.distributor ?? null, isWritable: true }, from: { value: input.from ?? null, isWritable: true }, to: { value: input.to ?? null, isWritable: true }, claimant: { value: input.claimant ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // 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.from), getAccountMeta(accounts.to), getAccountMeta(accounts.claimant), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.tokenProgram), ], data: getClawbackInstructionDataEncoder().encode({}), programAddress, }); } export function parseClawbackInstruction(instruction) { if (instruction.accounts.length < 6) { // 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(), from: getNextAccount(), to: getNextAccount(), claimant: getNextAccount(), systemProgram: getNextAccount(), tokenProgram: getNextAccount(), }, data: getClawbackInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=clawback.js.map