Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export type ConfigureConfidentialTransferAccountInstruction<
TAccountMint extends string | AccountMeta<string> = string,
TAccountInstructionsSysvarOrContextState extends string | AccountMeta<string> =
'Sysvar1nstructions1111111111111111111111111',
TAccountRecord extends string | AccountMeta<string> = string,
TAccountAuthority extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
Expand All @@ -72,7 +71,6 @@ export type ConfigureConfidentialTransferAccountInstruction<
TAccountInstructionsSysvarOrContextState extends string
? ReadonlyAccount<TAccountInstructionsSysvarOrContextState>
: TAccountInstructionsSysvarOrContextState,
TAccountRecord extends string ? ReadonlyAccount<TAccountRecord> : TAccountRecord,
TAccountAuthority extends string ? ReadonlyAccount<TAccountAuthority> : TAccountAuthority,
...TRemainingAccounts,
]
Expand Down Expand Up @@ -156,7 +154,6 @@ export type ConfigureConfidentialTransferAccountInput<
TAccountToken extends string = string,
TAccountMint extends string = string,
TAccountInstructionsSysvarOrContextState extends string = string,
TAccountRecord extends string = string,
TAccountAuthority extends string = string,
> = {
/** The SPL Token account. */
Expand All @@ -170,8 +167,6 @@ export type ConfigureConfidentialTransferAccountInput<
* account.
*/
instructionsSysvarOrContextState?: Address<TAccountInstructionsSysvarOrContextState>;
/** (Optional) Record account if the accompanying proof is to be read from a record account. */
record?: Address<TAccountRecord>;
/** The source account's owner/delegate or its multisignature account. */
authority: Address<TAccountAuthority> | TransactionSigner<TAccountAuthority>;
decryptableZeroBalance: ConfigureConfidentialTransferAccountInstructionDataArgs['decryptableZeroBalance'];
Expand All @@ -184,15 +179,13 @@ export function getConfigureConfidentialTransferAccountInstruction<
TAccountToken extends string,
TAccountMint extends string,
TAccountInstructionsSysvarOrContextState extends string,
TAccountRecord extends string,
TAccountAuthority extends string,
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS,
>(
input: ConfigureConfidentialTransferAccountInput<
TAccountToken,
TAccountMint,
TAccountInstructionsSysvarOrContextState,
TAccountRecord,
TAccountAuthority
>,
config?: { programAddress?: TProgramAddress },
Expand All @@ -201,7 +194,6 @@ export function getConfigureConfidentialTransferAccountInstruction<
TAccountToken,
TAccountMint,
TAccountInstructionsSysvarOrContextState,
TAccountRecord,
(typeof input)['authority'] extends TransactionSigner<TAccountAuthority>
? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority>
: TAccountAuthority
Expand All @@ -214,7 +206,6 @@ export function getConfigureConfidentialTransferAccountInstruction<
token: { value: input.token ?? null, isWritable: true },
mint: { value: input.mint ?? null, isWritable: false },
instructionsSysvarOrContextState: { value: input.instructionsSysvarOrContextState ?? null, isWritable: false },
record: { value: input.record ?? null, isWritable: false },
authority: { value: input.authority ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
Expand All @@ -241,7 +232,6 @@ export function getConfigureConfidentialTransferAccountInstruction<
getAccountMeta(accounts.token),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.instructionsSysvarOrContextState),
getAccountMeta(accounts.record),
getAccountMeta(accounts.authority),
...remainingAccounts,
],
Expand All @@ -254,7 +244,6 @@ export function getConfigureConfidentialTransferAccountInstruction<
TAccountToken,
TAccountMint,
TAccountInstructionsSysvarOrContextState,
TAccountRecord,
(typeof input)['authority'] extends TransactionSigner<TAccountAuthority>
? ReadonlySignerAccount<TAccountAuthority> & AccountSignerMeta<TAccountAuthority>
: TAccountAuthority
Expand All @@ -278,10 +267,8 @@ export type ParsedConfigureConfidentialTransferAccountInstruction<
* account.
*/
instructionsSysvarOrContextState: TAccountMetas[2];
/** (Optional) Record account if the accompanying proof is to be read from a record account. */
record?: TAccountMetas[3] | undefined;
/** The source account's owner/delegate or its multisignature account. */
authority: TAccountMetas[4];
authority: TAccountMetas[3];
};
data: ConfigureConfidentialTransferAccountInstructionData;
};
Expand All @@ -294,7 +281,7 @@ export function parseConfigureConfidentialTransferAccountInstruction<
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedConfigureConfidentialTransferAccountInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -304,17 +291,12 @@ export function parseConfigureConfidentialTransferAccountInstruction<
accountIndex += 1;
return accountMeta;
};
const getNextOptionalAccount = () => {
const accountMeta = getNextAccount();
return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS ? undefined : accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
token: getNextAccount(),
mint: getNextAccount(),
instructionsSysvarOrContextState: getNextAccount(),
record: getNextOptionalAccount(),
authority: getNextAccount(),
},
data: getConfigureConfidentialTransferAccountInstructionDataDecoder().decode(instruction.data),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/**
* 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,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
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 { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_DISCRIMINATOR = 27;

export function getConfigureConfidentialTransferAccountWithRegistryDiscriminatorBytes() {
return getU8Encoder().encode(CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_DISCRIMINATOR);
}

export const CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 14;

export function getConfigureConfidentialTransferAccountWithRegistryConfidentialTransferDiscriminatorBytes() {
return getU8Encoder().encode(
CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_CONFIDENTIAL_TRANSFER_DISCRIMINATOR,
);
}

export type ConfigureConfidentialTransferAccountWithRegistryInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountToken extends string | AccountMeta<string> = string,
TAccountMint extends string | AccountMeta<string> = string,
TAccountElgamalRegistry extends string | AccountMeta<string> = string,
TAccountPayer extends string | AccountMeta<string> | undefined = undefined,
TAccountSystemProgram extends string | AccountMeta<string> | undefined = undefined,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountToken extends string ? WritableAccount<TAccountToken> : TAccountToken,
TAccountMint extends string ? ReadonlyAccount<TAccountMint> : TAccountMint,
TAccountElgamalRegistry extends string ? ReadonlyAccount<TAccountElgamalRegistry> : TAccountElgamalRegistry,
...(TAccountPayer extends undefined
? []
: [
TAccountPayer extends string
? WritableSignerAccount<TAccountPayer> & AccountSignerMeta<TAccountPayer>
: TAccountPayer,
]),
...(TAccountSystemProgram extends undefined
? []
: [
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
]),
...TRemainingAccounts,
]
>;

export type ConfigureConfidentialTransferAccountWithRegistryInstructionData = {
discriminator: number;
confidentialTransferDiscriminator: number;
};

export type ConfigureConfidentialTransferAccountWithRegistryInstructionDataArgs = {};

export function getConfigureConfidentialTransferAccountWithRegistryInstructionDataEncoder(): FixedSizeEncoder<ConfigureConfidentialTransferAccountWithRegistryInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['confidentialTransferDiscriminator', getU8Encoder()],
]),
value => ({
...value,
discriminator: CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_DISCRIMINATOR,
confidentialTransferDiscriminator:
CONFIGURE_CONFIDENTIAL_TRANSFER_ACCOUNT_WITH_REGISTRY_CONFIDENTIAL_TRANSFER_DISCRIMINATOR,
}),
);
}

export function getConfigureConfidentialTransferAccountWithRegistryInstructionDataDecoder(): FixedSizeDecoder<ConfigureConfidentialTransferAccountWithRegistryInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['confidentialTransferDiscriminator', getU8Decoder()],
]);
}

export function getConfigureConfidentialTransferAccountWithRegistryInstructionDataCodec(): FixedSizeCodec<
ConfigureConfidentialTransferAccountWithRegistryInstructionDataArgs,
ConfigureConfidentialTransferAccountWithRegistryInstructionData
> {
return combineCodec(
getConfigureConfidentialTransferAccountWithRegistryInstructionDataEncoder(),
getConfigureConfidentialTransferAccountWithRegistryInstructionDataDecoder(),
);
}

export type ConfigureConfidentialTransferAccountWithRegistryInput<
TAccountToken extends string = string,
TAccountMint extends string = string,
TAccountElgamalRegistry extends string = string,
TAccountPayer extends string = string,
TAccountSystemProgram extends string = string,
> = {
/** The SPL Token account to configure. */
token: Address<TAccountToken>;
/** The corresponding SPL Token mint. */
mint: Address<TAccountMint>;
/** The ElGamal registry account that provides the encryption pubkey for the owner. */
elgamalRegistry: Address<TAccountElgamalRegistry>;
/**
* (Optional) Payer that funds the rent required to reallocate the token
* account when it does not yet have the `ConfidentialTransferAccount` extension.
*/
payer?: TransactionSigner<TAccountPayer>;
/** (Optional) System program, required when `payer` is provided. */
systemProgram?: Address<TAccountSystemProgram>;
};

export function getConfigureConfidentialTransferAccountWithRegistryInstruction<
TAccountToken extends string,
TAccountMint extends string,
TAccountElgamalRegistry extends string,
TAccountPayer extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS,
>(
input: ConfigureConfidentialTransferAccountWithRegistryInput<
TAccountToken,
TAccountMint,
TAccountElgamalRegistry,
TAccountPayer,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): ConfigureConfidentialTransferAccountWithRegistryInstruction<
TProgramAddress,
TAccountToken,
TAccountMint,
TAccountElgamalRegistry,
TAccountPayer,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
token: { value: input.token ?? null, isWritable: true },
mint: { value: input.mint ?? null, isWritable: false },
elgamalRegistry: { value: input.elgamalRegistry ?? null, isWritable: false },
payer: { value: input.payer ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
return Object.freeze({
accounts: [
getAccountMeta(accounts.token),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.elgamalRegistry),
getAccountMeta(accounts.payer),
getAccountMeta(accounts.systemProgram),
].filter(<T>(x: T | undefined): x is T => x !== undefined),
data: getConfigureConfidentialTransferAccountWithRegistryInstructionDataEncoder().encode({}),
programAddress,
} as ConfigureConfidentialTransferAccountWithRegistryInstruction<
TProgramAddress,
TAccountToken,
TAccountMint,
TAccountElgamalRegistry,
TAccountPayer,
TAccountSystemProgram
>);
}

export type ParsedConfigureConfidentialTransferAccountWithRegistryInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
/** The SPL Token account to configure. */
token: TAccountMetas[0];
/** The corresponding SPL Token mint. */
mint: TAccountMetas[1];
/** The ElGamal registry account that provides the encryption pubkey for the owner. */
elgamalRegistry: TAccountMetas[2];
/**
* (Optional) Payer that funds the rent required to reallocate the token
* account when it does not yet have the `ConfidentialTransferAccount` extension.
*/
payer?: TAccountMetas[3] | undefined;
/** (Optional) System program, required when `payer` is provided. */
systemProgram?: TAccountMetas[4] | undefined;
};
data: ConfigureConfidentialTransferAccountWithRegistryInstructionData;
};

export function parseConfigureConfidentialTransferAccountWithRegistryInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedConfigureConfidentialTransferAccountWithRegistryInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 3) {
// 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;
};
let optionalAccountsRemaining = instruction.accounts.length - 3;
const getNextOptionalAccount = () => {
if (optionalAccountsRemaining === 0) return undefined;
optionalAccountsRemaining -= 1;
return getNextAccount();
};
return {
programAddress: instruction.programAddress,
accounts: {
token: getNextAccount(),
mint: getNextAccount(),
elgamalRegistry: getNextAccount(),
payer: getNextOptionalAccount(),
systemProgram: getNextOptionalAccount(),
},
data: getConfigureConfidentialTransferAccountWithRegistryInstructionDataDecoder().decode(instruction.data),
};
}
1 change: 1 addition & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './confidentialTransfer';
export * from './confidentialTransferWithFee';
export * from './confidentialWithdraw';
export * from './configureConfidentialTransferAccount';
export * from './configureConfidentialTransferAccountWithRegistry';
export * from './createAssociatedToken';
export * from './createAssociatedTokenIdempotent';
export * from './createNativeMint';
Expand Down
Loading