UNPKG

@nosana/kit

Version:

Nosana KIT

70 lines 2.86 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 SET_ADMIN_DISCRIMINATOR = new Uint8Array([ 251, 163, 0, 52, 91, 194, 187, 92, ]); export function getSetAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_ADMIN_DISCRIMINATOR); } export function getSetAdminInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: SET_ADMIN_DISCRIMINATOR })); } export function getSetAdminInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getSetAdminInstructionDataCodec() { return combineCodec(getSetAdminInstructionDataEncoder(), getSetAdminInstructionDataDecoder()); } export function getSetAdminInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? MERKLE_DISTRIBUTOR_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { distributor: { value: input.distributor ?? null, isWritable: true }, admin: { value: input.admin ?? null, isWritable: true }, newAdmin: { value: input.newAdmin ?? null, isWritable: true }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.distributor), getAccountMeta(accounts.admin), getAccountMeta(accounts.newAdmin), ], data: getSetAdminInstructionDataEncoder().encode({}), programAddress, }); } export function parseSetAdminInstruction(instruction) { if (instruction.accounts.length < 3) { // 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(), admin: getNextAccount(), newAdmin: getNextAccount(), }, data: getSetAdminInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=setAdmin.js.map