/** * 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 { getProgramDerivedAddress, type Address } from '@solana/kit'; import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, type Codec, type Decoder, type Encoder, type ReadonlyUint8Array, } from '@solana/kit'; import { type IAccountMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { type IAccountSignerMeta, type TransactionSigner } from '@solana/kit'; import { SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS } from '../programs/index.js'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared/index.js'; export const ACCEPT_ADMIN_DISCRIMINATOR = new Uint8Array([112, 42, 45, 90, 116, 181, 13, 170]); export function getAcceptAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(ACCEPT_ADMIN_DISCRIMINATOR); } export type AcceptAdminInstruction< TProgram extends string = typeof SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS, TAccountPendingAdmin extends string | IAccountMeta = string, TAccountAdminSingleton extends string | IAccountMeta = string, TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & IInstructionWithData & IInstructionWithAccounts< [ TAccountPendingAdmin extends string ? WritableSignerAccount & IAccountSignerMeta : TAccountPendingAdmin, TAccountAdminSingleton extends string ? WritableAccount : TAccountAdminSingleton, ...TRemainingAccounts, ] >; export type AcceptAdminInstructionData = { discriminator: ReadonlyUint8Array }; export type AcceptAdminInstructionDataArgs = {}; export function getAcceptAdminInstructionDataEncoder(): Encoder { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: ACCEPT_ADMIN_DISCRIMINATOR, })); } export function getAcceptAdminInstructionDataDecoder(): Decoder { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getAcceptAdminInstructionDataCodec(): Codec< AcceptAdminInstructionDataArgs, AcceptAdminInstructionData > { return combineCodec(getAcceptAdminInstructionDataEncoder(), getAcceptAdminInstructionDataDecoder()); } export type AcceptAdminAsyncInput< TAccountPendingAdmin extends string = string, TAccountAdminSingleton extends string = string, > = { /** Pending Admin signer */ pendingAdmin: TransactionSigner; /** Admin singleton account that grants access to admin functions */ adminSingleton?: Address; }; export async function getAcceptAdminInstructionAsync< TAccountPendingAdmin extends string, TAccountAdminSingleton extends string, TProgramAddress extends Address = typeof SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS, >( input: AcceptAdminAsyncInput, config?: { programAddress?: TProgramAddress }, ): Promise> { // Program address. const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: true }, adminSingleton: { value: input.adminSingleton ?? null, isWritable: true }, }; const accounts = originalAccounts as Record; // Resolve default values. if (!accounts.adminSingleton.value) { accounts.adminSingleton.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([97, 100, 109, 105, 110]))], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [getAccountMeta(accounts.pendingAdmin), getAccountMeta(accounts.adminSingleton)], programAddress, data: getAcceptAdminInstructionDataEncoder().encode({}), } as AcceptAdminInstruction; return instruction; } export type AcceptAdminInput< TAccountPendingAdmin extends string = string, TAccountAdminSingleton extends string = string, > = { /** Pending Admin signer */ pendingAdmin: TransactionSigner; /** Admin singleton account that grants access to admin functions */ adminSingleton: Address; }; export function getAcceptAdminInstruction< TAccountPendingAdmin extends string, TAccountAdminSingleton extends string, TProgramAddress extends Address = typeof SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS, >( input: AcceptAdminInput, config?: { programAddress?: TProgramAddress }, ): AcceptAdminInstruction { // Program address. const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: true }, adminSingleton: { value: input.adminSingleton ?? null, isWritable: true }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [getAccountMeta(accounts.pendingAdmin), getAccountMeta(accounts.adminSingleton)], programAddress, data: getAcceptAdminInstructionDataEncoder().encode({}), } as AcceptAdminInstruction; return instruction; } export type ParsedAcceptAdminInstruction< TProgram extends string = typeof SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; accounts: { /** Pending Admin signer */ pendingAdmin: TAccountMetas[0]; /** Admin singleton account that grants access to admin functions */ adminSingleton: TAccountMetas[1]; }; data: AcceptAdminInstructionData; }; export function parseAcceptAdminInstruction( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData, ): ParsedAcceptAdminInstruction { if (instruction.accounts.length < 2) { // 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: { pendingAdmin: getNextAccount(), adminSingleton: getNextAccount(), }, data: getAcceptAdminInstructionDataDecoder().decode(instruction.data), }; }