/** * 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, getAddressEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, getUtf8Encoder, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount, } from '@solana/kit'; import { COMMERCE_PROGRAM_PROGRAM_ADDRESS } from '../programs'; import { expectAddress, getAccountMetaFactory, type ResolvedAccount, } from '../shared'; export const UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR = 7; export function getUpdateMerchantAuthorityDiscriminatorBytes() { return getU8Encoder().encode(UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR); } export type UpdateMerchantAuthorityInstruction< TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, TAccountPayer extends string | AccountMeta = string, TAccountAuthority extends string | AccountMeta = string, TAccountMerchant extends string | AccountMeta = string, TAccountNewAuthority extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountPayer extends string ? WritableSignerAccount & AccountSignerMeta : TAccountPayer, TAccountAuthority extends string ? WritableSignerAccount & AccountSignerMeta : TAccountAuthority, TAccountMerchant extends string ? WritableAccount : TAccountMerchant, TAccountNewAuthority extends string ? ReadonlyAccount : TAccountNewAuthority, ...TRemainingAccounts, ] >; export type UpdateMerchantAuthorityInstructionData = { discriminator: number }; export type UpdateMerchantAuthorityInstructionDataArgs = {}; export function getUpdateMerchantAuthorityInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([['discriminator', getU8Encoder()]]), (value) => ({ ...value, discriminator: UPDATE_MERCHANT_AUTHORITY_DISCRIMINATOR, }) ); } export function getUpdateMerchantAuthorityInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getUpdateMerchantAuthorityInstructionDataCodec(): FixedSizeCodec< UpdateMerchantAuthorityInstructionDataArgs, UpdateMerchantAuthorityInstructionData > { return combineCodec( getUpdateMerchantAuthorityInstructionDataEncoder(), getUpdateMerchantAuthorityInstructionDataDecoder() ); } export type UpdateMerchantAuthorityAsyncInput< TAccountPayer extends string = string, TAccountAuthority extends string = string, TAccountMerchant extends string = string, TAccountNewAuthority extends string = string, > = { payer: TransactionSigner; authority: TransactionSigner; /** Merchant PDA */ merchant?: Address; newAuthority: Address; }; export async function getUpdateMerchantAuthorityInstructionAsync< TAccountPayer extends string, TAccountAuthority extends string, TAccountMerchant extends string, TAccountNewAuthority extends string, TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, >( input: UpdateMerchantAuthorityAsyncInput< TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority >, config?: { programAddress?: TProgramAddress } ): Promise< UpdateMerchantAuthorityInstruction< TProgramAddress, TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority > > { // Program address. const programAddress = config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: true }, merchant: { value: input.merchant ?? null, isWritable: true }, newAuthority: { value: input.newAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; // Resolve default values. if (!accounts.merchant.value) { accounts.merchant.value = await getProgramDerivedAddress({ programAddress: 'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT' as Address<'commkU28d52cwo2Ma3Marxz4Qr9REtfJtuUfqnDnbhT'>, seeds: [ getUtf8Encoder().encode('merchant'), getAddressEncoder().encode(expectAddress(accounts.authority.value)), ], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.payer), getAccountMeta(accounts.authority), getAccountMeta(accounts.merchant), getAccountMeta(accounts.newAuthority), ], data: getUpdateMerchantAuthorityInstructionDataEncoder().encode({}), programAddress, } as UpdateMerchantAuthorityInstruction< TProgramAddress, TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority >); } export type UpdateMerchantAuthorityInput< TAccountPayer extends string = string, TAccountAuthority extends string = string, TAccountMerchant extends string = string, TAccountNewAuthority extends string = string, > = { payer: TransactionSigner; authority: TransactionSigner; /** Merchant PDA */ merchant: Address; newAuthority: Address; }; export function getUpdateMerchantAuthorityInstruction< TAccountPayer extends string, TAccountAuthority extends string, TAccountMerchant extends string, TAccountNewAuthority extends string, TProgramAddress extends Address = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, >( input: UpdateMerchantAuthorityInput< TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority >, config?: { programAddress?: TProgramAddress } ): UpdateMerchantAuthorityInstruction< TProgramAddress, TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority > { // Program address. const programAddress = config?.programAddress ?? COMMERCE_PROGRAM_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { payer: { value: input.payer ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: true }, merchant: { value: input.merchant ?? null, isWritable: true }, newAuthority: { value: input.newAuthority ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedAccount >; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.payer), getAccountMeta(accounts.authority), getAccountMeta(accounts.merchant), getAccountMeta(accounts.newAuthority), ], data: getUpdateMerchantAuthorityInstructionDataEncoder().encode({}), programAddress, } as UpdateMerchantAuthorityInstruction< TProgramAddress, TAccountPayer, TAccountAuthority, TAccountMerchant, TAccountNewAuthority >); } export type ParsedUpdateMerchantAuthorityInstruction< TProgram extends string = typeof COMMERCE_PROGRAM_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { payer: TAccountMetas[0]; authority: TAccountMetas[1]; /** Merchant PDA */ merchant: TAccountMetas[2]; newAuthority: TAccountMetas[3]; }; data: UpdateMerchantAuthorityInstructionData; }; export function parseUpdateMerchantAuthorityInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData ): ParsedUpdateMerchantAuthorityInstruction { if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), authority: getNextAccount(), merchant: getNextAccount(), newAuthority: getNextAccount(), }, data: getUpdateMerchantAuthorityInstructionDataDecoder().decode( instruction.data ), }; }