From dd5f3a4ed4fab4f3880f261d95cfbfa3100e1a72 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 7 Oct 2024 15:52:38 +0100 Subject: [PATCH] Define IDL instructions for confidential transfer extension (#7) * Add initializeConfidentialTransferMint * Wrap transfer fee tests in same folder * Rename init transfer fee config test * Add test for initializeConfidentialTransferMint * Add updateConfidentialTransferMint * Add test for updateConfidentialTransferMint * Add configureConfidentialAccount * Add approveConfidentialAccount * Add emptyConfidentialAccount * Add confidentialDeposit * Add confidentialWithdraw * Add confidentialTransfer * Add confidentialTransferWithFee * Add applyConfidentialPendingBalance * Add enableConfidentialCredits * Add disableConfidentialCredits * Add enableNonConfidentialCredits * Add disableNonConfidentialCredits --- .../applyConfidentialPendingBalance.ts | 257 +++ .../approveConfidentialAccount.ts | 217 ++ .../instructions/confidentialDeposit.ts | 256 +++ .../instructions/confidentialTransfer.ts | 410 ++++ .../confidentialTransferWithFee.ts | 497 +++++ .../instructions/confidentialWithdraw.ts | 369 ++++ .../configureConfidentialAccount.ts | 347 +++ .../disableConfidentialCredits.ts | 218 ++ .../disableNonConfidentialCredits.ts | 218 ++ .../instructions/emptyConfidentialAccount.ts | 301 +++ .../instructions/enableConfidentialCredits.ts | 218 ++ .../enableNonConfidentialCredits.ts | 218 ++ .../js/src/generated/instructions/index.ts | 14 + .../initializeConfidentialTransferMint.ts | 252 +++ .../updateConfidentialTransferMint.ts | 243 +++ .../js/src/generated/programs/token2022.ts | 156 +- ...initializeConfidentialTransferMint.test.ts | 61 + .../updateConfidentialTransferMint.test.ts | 82 + .../initializeTransferFeeConfig.test.ts} | 4 +- .../transferCheckedWithFee.test.ts | 4 +- program/idl.json | 1880 +++++++++++++++++ 21 files changed, 6217 insertions(+), 5 deletions(-) create mode 100644 clients/js/src/generated/instructions/applyConfidentialPendingBalance.ts create mode 100644 clients/js/src/generated/instructions/approveConfidentialAccount.ts create mode 100644 clients/js/src/generated/instructions/confidentialDeposit.ts create mode 100644 clients/js/src/generated/instructions/confidentialTransfer.ts create mode 100644 clients/js/src/generated/instructions/confidentialTransferWithFee.ts create mode 100644 clients/js/src/generated/instructions/confidentialWithdraw.ts create mode 100644 clients/js/src/generated/instructions/configureConfidentialAccount.ts create mode 100644 clients/js/src/generated/instructions/disableConfidentialCredits.ts create mode 100644 clients/js/src/generated/instructions/disableNonConfidentialCredits.ts create mode 100644 clients/js/src/generated/instructions/emptyConfidentialAccount.ts create mode 100644 clients/js/src/generated/instructions/enableConfidentialCredits.ts create mode 100644 clients/js/src/generated/instructions/enableNonConfidentialCredits.ts create mode 100644 clients/js/src/generated/instructions/initializeConfidentialTransferMint.ts create mode 100644 clients/js/src/generated/instructions/updateConfidentialTransferMint.ts create mode 100644 clients/js/test/extensions/confidentialTransfer/initializeConfidentialTransferMint.test.ts create mode 100644 clients/js/test/extensions/confidentialTransfer/updateConfidentialTransferMint.test.ts rename clients/js/test/extensions/{transferFeeConfig.test.ts => transferFree/initializeTransferFeeConfig.test.ts} (98%) rename clients/js/test/extensions/{ => transferFree}/transferCheckedWithFee.test.ts (98%) diff --git a/clients/js/src/generated/instructions/applyConfidentialPendingBalance.ts b/clients/js/src/generated/instructions/applyConfidentialPendingBalance.ts new file mode 100644 index 0000000..bf7c823 --- /dev/null +++ b/clients/js/src/generated/instructions/applyConfidentialPendingBalance.ts @@ -0,0 +1,257 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; +import { + getDecryptableBalanceDecoder, + getDecryptableBalanceEncoder, + type DecryptableBalance, + type DecryptableBalanceArgs, +} from '../types'; + +export const APPLY_CONFIDENTIAL_PENDING_BALANCE_DISCRIMINATOR = 27; + +export function getApplyConfidentialPendingBalanceDiscriminatorBytes() { + return getU8Encoder().encode( + APPLY_CONFIDENTIAL_PENDING_BALANCE_DISCRIMINATOR + ); +} + +export const APPLY_CONFIDENTIAL_PENDING_BALANCE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 8; + +export function getApplyConfidentialPendingBalanceConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + APPLY_CONFIDENTIAL_PENDING_BALANCE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ApplyConfidentialPendingBalanceInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ApplyConfidentialPendingBalanceInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** + * The expected number of pending balance credits since the last successful + * `ApplyPendingBalance` instruction + */ + expectedPendingBalanceCreditCounter: bigint; + /** + * The new decryptable balance if the pending balance is applied + * successfully + */ + newDecryptableAvailableBalance: DecryptableBalance; +}; + +export type ApplyConfidentialPendingBalanceInstructionDataArgs = { + /** + * The expected number of pending balance credits since the last successful + * `ApplyPendingBalance` instruction + */ + expectedPendingBalanceCreditCounter: number | bigint; + /** + * The new decryptable balance if the pending balance is applied + * successfully + */ + newDecryptableAvailableBalance: DecryptableBalanceArgs; +}; + +export function getApplyConfidentialPendingBalanceInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['expectedPendingBalanceCreditCounter', getU64Encoder()], + ['newDecryptableAvailableBalance', getDecryptableBalanceEncoder()], + ]), + (value) => ({ + ...value, + discriminator: APPLY_CONFIDENTIAL_PENDING_BALANCE_DISCRIMINATOR, + confidentialTransferDiscriminator: + APPLY_CONFIDENTIAL_PENDING_BALANCE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getApplyConfidentialPendingBalanceInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['expectedPendingBalanceCreditCounter', getU64Decoder()], + ['newDecryptableAvailableBalance', getDecryptableBalanceDecoder()], + ]); +} + +export function getApplyConfidentialPendingBalanceInstructionDataCodec(): Codec< + ApplyConfidentialPendingBalanceInstructionDataArgs, + ApplyConfidentialPendingBalanceInstructionData +> { + return combineCodec( + getApplyConfidentialPendingBalanceInstructionDataEncoder(), + getApplyConfidentialPendingBalanceInstructionDataDecoder() + ); +} + +export type ApplyConfidentialPendingBalanceInput< + TAccountToken extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + expectedPendingBalanceCreditCounter: ApplyConfidentialPendingBalanceInstructionDataArgs['expectedPendingBalanceCreditCounter']; + newDecryptableAvailableBalance: ApplyConfidentialPendingBalanceInstructionDataArgs['newDecryptableAvailableBalance']; + multiSigners?: Array; +}; + +export function getApplyConfidentialPendingBalanceInstruction< + TAccountToken extends string, + TAccountAuthority extends string, +>( + input: ApplyConfidentialPendingBalanceInput +): ApplyConfidentialPendingBalanceInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getApplyConfidentialPendingBalanceInstructionDataEncoder().encode( + args as ApplyConfidentialPendingBalanceInstructionDataArgs + ), + } as ApplyConfidentialPendingBalanceInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedApplyConfidentialPendingBalanceInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[1]; + }; + data: ApplyConfidentialPendingBalanceInstructionData; +}; + +export function parseApplyConfidentialPendingBalanceInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedApplyConfidentialPendingBalanceInstruction { + 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: { + token: getNextAccount(), + authority: getNextAccount(), + }, + data: getApplyConfidentialPendingBalanceInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/approveConfidentialAccount.ts b/clients/js/src/generated/instructions/approveConfidentialAccount.ts new file mode 100644 index 0000000..78a8ec5 --- /dev/null +++ b/clients/js/src/generated/instructions/approveConfidentialAccount.ts @@ -0,0 +1,217 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const APPROVE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR = 27; + +export function getApproveConfidentialAccountDiscriminatorBytes() { + return getU8Encoder().encode(APPROVE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR); +} + +export const APPROVE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 3; + +export function getApproveConfidentialAccountConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + APPROVE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ApproveConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAuthority extends string + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ApproveConfidentialAccountInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; +}; + +export type ApproveConfidentialAccountInstructionDataArgs = {}; + +export function getApproveConfidentialAccountInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: APPROVE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR, + confidentialTransferDiscriminator: + APPROVE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getApproveConfidentialAccountInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ]); +} + +export function getApproveConfidentialAccountInstructionDataCodec(): Codec< + ApproveConfidentialAccountInstructionDataArgs, + ApproveConfidentialAccountInstructionData +> { + return combineCodec( + getApproveConfidentialAccountInstructionDataEncoder(), + getApproveConfidentialAccountInstructionDataDecoder() + ); +} + +export type ApproveConfidentialAccountInput< + TAccountToken extends string = string, + TAccountMint extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account to approve. */ + token: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** Confidential transfer mint authority. */ + authority: TransactionSigner; +}; + +export function getApproveConfidentialAccountInstruction< + TAccountToken extends string, + TAccountMint extends string, + TAccountAuthority extends string, +>( + input: ApproveConfidentialAccountInput< + TAccountToken, + TAccountMint, + TAccountAuthority + > +): ApproveConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.authority), + ], + programAddress, + data: getApproveConfidentialAccountInstructionDataEncoder().encode({}), + } as ApproveConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountAuthority + >; + + return instruction; +} + +export type ParsedApproveConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account to approve. */ + token: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** Confidential transfer mint authority. */ + authority: TAccountMetas[2]; + }; + data: ApproveConfidentialAccountInstructionData; +}; + +export function parseApproveConfidentialAccountInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedApproveConfidentialAccountInstruction { + 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: { + token: getNextAccount(), + mint: getNextAccount(), + authority: getNextAccount(), + }, + data: getApproveConfidentialAccountInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/confidentialDeposit.ts b/clients/js/src/generated/instructions/confidentialDeposit.ts new file mode 100644 index 0000000..b183b29 --- /dev/null +++ b/clients/js/src/generated/instructions/confidentialDeposit.ts @@ -0,0 +1,256 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const CONFIDENTIAL_DEPOSIT_DISCRIMINATOR = 27; + +export function getConfidentialDepositDiscriminatorBytes() { + return getU8Encoder().encode(CONFIDENTIAL_DEPOSIT_DISCRIMINATOR); +} + +export const CONFIDENTIAL_DEPOSIT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 5; + +export function getConfidentialDepositConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + CONFIDENTIAL_DEPOSIT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ConfidentialDepositInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ConfidentialDepositInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** The amount of tokens to deposit. */ + amount: bigint; + /** Expected number of base 10 digits to the right of the decimal place. */ + decimals: number; +}; + +export type ConfidentialDepositInstructionDataArgs = { + /** The amount of tokens to deposit. */ + amount: number | bigint; + /** Expected number of base 10 digits to the right of the decimal place. */ + decimals: number; +}; + +export function getConfidentialDepositInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['amount', getU64Encoder()], + ['decimals', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CONFIDENTIAL_DEPOSIT_DISCRIMINATOR, + confidentialTransferDiscriminator: + CONFIDENTIAL_DEPOSIT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getConfidentialDepositInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['amount', getU64Decoder()], + ['decimals', getU8Decoder()], + ]); +} + +export function getConfidentialDepositInstructionDataCodec(): Codec< + ConfidentialDepositInstructionDataArgs, + ConfidentialDepositInstructionData +> { + return combineCodec( + getConfidentialDepositInstructionDataEncoder(), + getConfidentialDepositInstructionDataDecoder() + ); +} + +export type ConfidentialDepositInput< + TAccountToken extends string = string, + TAccountMint extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + amount: ConfidentialDepositInstructionDataArgs['amount']; + decimals: ConfidentialDepositInstructionDataArgs['decimals']; + multiSigners?: Array; +}; + +export function getConfidentialDepositInstruction< + TAccountToken extends string, + TAccountMint extends string, + TAccountAuthority extends string, +>( + input: ConfidentialDepositInput< + TAccountToken, + TAccountMint, + TAccountAuthority + > +): ConfidentialDepositInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getConfidentialDepositInstructionDataEncoder().encode( + args as ConfidentialDepositInstructionDataArgs + ), + } as ConfidentialDepositInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedConfidentialDepositInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[2]; + }; + data: ConfidentialDepositInstructionData; +}; + +export function parseConfidentialDepositInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedConfidentialDepositInstruction { + 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: { + token: getNextAccount(), + mint: getNextAccount(), + authority: getNextAccount(), + }, + data: getConfidentialDepositInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/confidentialTransfer.ts b/clients/js/src/generated/instructions/confidentialTransfer.ts new file mode 100644 index 0000000..6edc7eb --- /dev/null +++ b/clients/js/src/generated/instructions/confidentialTransfer.ts @@ -0,0 +1,410 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getI8Decoder, + getI8Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; +import { + getDecryptableBalanceDecoder, + getDecryptableBalanceEncoder, + type DecryptableBalance, + type DecryptableBalanceArgs, +} from '../types'; + +export const CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 27; + +export function getConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode(CONFIDENTIAL_TRANSFER_DISCRIMINATOR); +} + +export const CONFIDENTIAL_TRANSFER_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 7; + +export function getConfidentialTransferConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + CONFIDENTIAL_TRANSFER_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ConfidentialTransferInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountDestinationToken extends string | IAccountMeta = string, + TAccountInstructionsSysvar extends string | IAccountMeta = string, + TAccountEqualityRecord extends string | IAccountMeta = string, + TAccountCiphertextValidityRecord extends + | string + | IAccountMeta = string, + TAccountRangeRecord extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountSourceToken extends string + ? WritableAccount + : TAccountSourceToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountDestinationToken extends string + ? WritableAccount + : TAccountDestinationToken, + TAccountInstructionsSysvar extends string + ? ReadonlyAccount + : TAccountInstructionsSysvar, + TAccountEqualityRecord extends string + ? ReadonlyAccount + : TAccountEqualityRecord, + TAccountCiphertextValidityRecord extends string + ? ReadonlyAccount + : TAccountCiphertextValidityRecord, + TAccountRangeRecord extends string + ? ReadonlyAccount + : TAccountRangeRecord, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ConfidentialTransferInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** The new source decryptable balance if the transfer succeeds. */ + newSourceDecryptableAvailableBalance: DecryptableBalance; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `Transfer` instruction in the transaction. If the offset is + * `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity` + * instruction to the `Transfer` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + ciphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU128Data` + * instruction to the `Transfer` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + rangeProofInstructionOffset: number; +}; + +export type ConfidentialTransferInstructionDataArgs = { + /** The new source decryptable balance if the transfer succeeds. */ + newSourceDecryptableAvailableBalance: DecryptableBalanceArgs; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `Transfer` instruction in the transaction. If the offset is + * `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity` + * instruction to the `Transfer` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + ciphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU128Data` + * instruction to the `Transfer` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + rangeProofInstructionOffset: number; +}; + +export function getConfidentialTransferInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['newSourceDecryptableAvailableBalance', getDecryptableBalanceEncoder()], + ['equalityProofInstructionOffset', getI8Encoder()], + ['ciphertextValidityProofInstructionOffset', getI8Encoder()], + ['rangeProofInstructionOffset', getI8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + confidentialTransferDiscriminator: + CONFIDENTIAL_TRANSFER_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getConfidentialTransferInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['newSourceDecryptableAvailableBalance', getDecryptableBalanceDecoder()], + ['equalityProofInstructionOffset', getI8Decoder()], + ['ciphertextValidityProofInstructionOffset', getI8Decoder()], + ['rangeProofInstructionOffset', getI8Decoder()], + ]); +} + +export function getConfidentialTransferInstructionDataCodec(): Codec< + ConfidentialTransferInstructionDataArgs, + ConfidentialTransferInstructionData +> { + return combineCodec( + getConfidentialTransferInstructionDataEncoder(), + getConfidentialTransferInstructionDataDecoder() + ); +} + +export type ConfidentialTransferInput< + TAccountSourceToken extends string = string, + TAccountMint extends string = string, + TAccountDestinationToken extends string = string, + TAccountInstructionsSysvar extends string = string, + TAccountEqualityRecord extends string = string, + TAccountCiphertextValidityRecord extends string = string, + TAccountRangeRecord extends string = string, + TAccountAuthority extends string = string, +> = { + /** The source SPL Token account. */ + sourceToken: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** The destination SPL Token account. */ + destinationToken: Address; + /** + * (Optional) Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + instructionsSysvar?: Address; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: Address; + /** (Optional) Ciphertext validity proof record account or context state account. */ + ciphertextValidityRecord?: Address; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + newSourceDecryptableAvailableBalance: ConfidentialTransferInstructionDataArgs['newSourceDecryptableAvailableBalance']; + equalityProofInstructionOffset: ConfidentialTransferInstructionDataArgs['equalityProofInstructionOffset']; + ciphertextValidityProofInstructionOffset: ConfidentialTransferInstructionDataArgs['ciphertextValidityProofInstructionOffset']; + rangeProofInstructionOffset: ConfidentialTransferInstructionDataArgs['rangeProofInstructionOffset']; + multiSigners?: Array; +}; + +export function getConfidentialTransferInstruction< + TAccountSourceToken extends string, + TAccountMint extends string, + TAccountDestinationToken extends string, + TAccountInstructionsSysvar extends string, + TAccountEqualityRecord extends string, + TAccountCiphertextValidityRecord extends string, + TAccountRangeRecord extends string, + TAccountAuthority extends string, +>( + input: ConfidentialTransferInput< + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountCiphertextValidityRecord, + TAccountRangeRecord, + TAccountAuthority + > +): ConfidentialTransferInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountCiphertextValidityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + sourceToken: { value: input.sourceToken ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + destinationToken: { + value: input.destinationToken ?? null, + isWritable: true, + }, + instructionsSysvar: { + value: input.instructionsSysvar ?? null, + isWritable: false, + }, + equalityRecord: { value: input.equalityRecord ?? null, isWritable: false }, + ciphertextValidityRecord: { + value: input.ciphertextValidityRecord ?? null, + isWritable: false, + }, + rangeRecord: { value: input.rangeRecord ?? null, isWritable: false }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.sourceToken), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.destinationToken), + getAccountMeta(accounts.instructionsSysvar), + getAccountMeta(accounts.equalityRecord), + getAccountMeta(accounts.ciphertextValidityRecord), + getAccountMeta(accounts.rangeRecord), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getConfidentialTransferInstructionDataEncoder().encode( + args as ConfidentialTransferInstructionDataArgs + ), + } as ConfidentialTransferInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountCiphertextValidityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedConfidentialTransferInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The source SPL Token account. */ + sourceToken: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** The destination SPL Token account. */ + destinationToken: TAccountMetas[2]; + /** + * (Optional) Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + + instructionsSysvar?: TAccountMetas[3] | undefined; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: TAccountMetas[4] | undefined; + /** (Optional) Ciphertext validity proof record account or context state account. */ + ciphertextValidityRecord?: TAccountMetas[5] | undefined; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: TAccountMetas[6] | undefined; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[7]; + }; + data: ConfidentialTransferInstructionData; +}; + +export function parseConfidentialTransferInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedConfidentialTransferInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + const getNextOptionalAccount = () => { + const accountMeta = getNextAccount(); + return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS + ? undefined + : accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + sourceToken: getNextAccount(), + mint: getNextAccount(), + destinationToken: getNextAccount(), + instructionsSysvar: getNextOptionalAccount(), + equalityRecord: getNextOptionalAccount(), + ciphertextValidityRecord: getNextOptionalAccount(), + rangeRecord: getNextOptionalAccount(), + authority: getNextAccount(), + }, + data: getConfidentialTransferInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/confidentialTransferWithFee.ts b/clients/js/src/generated/instructions/confidentialTransferWithFee.ts new file mode 100644 index 0000000..e2e2cf0 --- /dev/null +++ b/clients/js/src/generated/instructions/confidentialTransferWithFee.ts @@ -0,0 +1,497 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getI8Decoder, + getI8Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; +import { + getDecryptableBalanceDecoder, + getDecryptableBalanceEncoder, + type DecryptableBalance, + type DecryptableBalanceArgs, +} from '../types'; + +export const CONFIDENTIAL_TRANSFER_WITH_FEE_DISCRIMINATOR = 27; + +export function getConfidentialTransferWithFeeDiscriminatorBytes() { + return getU8Encoder().encode(CONFIDENTIAL_TRANSFER_WITH_FEE_DISCRIMINATOR); +} + +export const CONFIDENTIAL_TRANSFER_WITH_FEE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 13; + +export function getConfidentialTransferWithFeeConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + CONFIDENTIAL_TRANSFER_WITH_FEE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ConfidentialTransferWithFeeInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountDestinationToken extends string | IAccountMeta = string, + TAccountInstructionsSysvar extends string | IAccountMeta = string, + TAccountEqualityRecord extends string | IAccountMeta = string, + TAccountTransferAmountCiphertextValidityRecord extends + | string + | IAccountMeta = string, + TAccountFeeSigmaRecord extends string | IAccountMeta = string, + TAccountFeeCiphertextValidityRecord extends + | string + | IAccountMeta = string, + TAccountRangeRecord extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountSourceToken extends string + ? WritableAccount + : TAccountSourceToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountDestinationToken extends string + ? WritableAccount + : TAccountDestinationToken, + TAccountInstructionsSysvar extends string + ? ReadonlyAccount + : TAccountInstructionsSysvar, + TAccountEqualityRecord extends string + ? ReadonlyAccount + : TAccountEqualityRecord, + TAccountTransferAmountCiphertextValidityRecord extends string + ? ReadonlyAccount + : TAccountTransferAmountCiphertextValidityRecord, + TAccountFeeSigmaRecord extends string + ? ReadonlyAccount + : TAccountFeeSigmaRecord, + TAccountFeeCiphertextValidityRecord extends string + ? ReadonlyAccount + : TAccountFeeCiphertextValidityRecord, + TAccountRangeRecord extends string + ? ReadonlyAccount + : TAccountRangeRecord, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ConfidentialTransferWithFeeInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** The new source decryptable balance if the transfer succeeds. */ + newSourceDecryptableAvailableBalance: DecryptableBalance; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `TransferWithFee` instruction in the transaction. If the offset + * is `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + transferAmountCiphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::VerifyPercentageWithFee` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + feeSigmaProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext2HandlesValidity` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + feeCiphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU256Data` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + rangeProofInstructionOffset: number; +}; + +export type ConfidentialTransferWithFeeInstructionDataArgs = { + /** The new source decryptable balance if the transfer succeeds. */ + newSourceDecryptableAvailableBalance: DecryptableBalanceArgs; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `TransferWithFee` instruction in the transaction. If the offset + * is `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + transferAmountCiphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::VerifyPercentageWithFee` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + feeSigmaProofInstructionOffset: number; + /** + * Relative location of the + * `ProofInstruction::VerifyBatchedGroupedCiphertext2HandlesValidity` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + feeCiphertextValidityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU256Data` + * instruction to the `TransferWithFee` instruction in the transaction. + * If the offset is `0`, then use a context state account for the + * proof. + */ + rangeProofInstructionOffset: number; +}; + +export function getConfidentialTransferWithFeeInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['newSourceDecryptableAvailableBalance', getDecryptableBalanceEncoder()], + ['equalityProofInstructionOffset', getI8Encoder()], + [ + 'transferAmountCiphertextValidityProofInstructionOffset', + getI8Encoder(), + ], + ['feeSigmaProofInstructionOffset', getI8Encoder()], + ['feeCiphertextValidityProofInstructionOffset', getI8Encoder()], + ['rangeProofInstructionOffset', getI8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CONFIDENTIAL_TRANSFER_WITH_FEE_DISCRIMINATOR, + confidentialTransferDiscriminator: + CONFIDENTIAL_TRANSFER_WITH_FEE_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getConfidentialTransferWithFeeInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['newSourceDecryptableAvailableBalance', getDecryptableBalanceDecoder()], + ['equalityProofInstructionOffset', getI8Decoder()], + ['transferAmountCiphertextValidityProofInstructionOffset', getI8Decoder()], + ['feeSigmaProofInstructionOffset', getI8Decoder()], + ['feeCiphertextValidityProofInstructionOffset', getI8Decoder()], + ['rangeProofInstructionOffset', getI8Decoder()], + ]); +} + +export function getConfidentialTransferWithFeeInstructionDataCodec(): Codec< + ConfidentialTransferWithFeeInstructionDataArgs, + ConfidentialTransferWithFeeInstructionData +> { + return combineCodec( + getConfidentialTransferWithFeeInstructionDataEncoder(), + getConfidentialTransferWithFeeInstructionDataDecoder() + ); +} + +export type ConfidentialTransferWithFeeInput< + TAccountSourceToken extends string = string, + TAccountMint extends string = string, + TAccountDestinationToken extends string = string, + TAccountInstructionsSysvar extends string = string, + TAccountEqualityRecord extends string = string, + TAccountTransferAmountCiphertextValidityRecord extends string = string, + TAccountFeeSigmaRecord extends string = string, + TAccountFeeCiphertextValidityRecord extends string = string, + TAccountRangeRecord extends string = string, + TAccountAuthority extends string = string, +> = { + /** The source SPL Token account. */ + sourceToken: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** The destination SPL Token account. */ + destinationToken: Address; + /** + * (Optional) Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + instructionsSysvar?: Address; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: Address; + /** + * (Optional) Transfer amount ciphertext validity proof record + * account or context state account. + */ + transferAmountCiphertextValidityRecord?: Address; + /** (Optional) Fee sigma proof record account or context state account. */ + feeSigmaRecord?: Address; + /** (Optional) Fee ciphertext validity proof record account or context state account. */ + feeCiphertextValidityRecord?: Address; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + newSourceDecryptableAvailableBalance: ConfidentialTransferWithFeeInstructionDataArgs['newSourceDecryptableAvailableBalance']; + equalityProofInstructionOffset: ConfidentialTransferWithFeeInstructionDataArgs['equalityProofInstructionOffset']; + transferAmountCiphertextValidityProofInstructionOffset: ConfidentialTransferWithFeeInstructionDataArgs['transferAmountCiphertextValidityProofInstructionOffset']; + feeSigmaProofInstructionOffset: ConfidentialTransferWithFeeInstructionDataArgs['feeSigmaProofInstructionOffset']; + feeCiphertextValidityProofInstructionOffset: ConfidentialTransferWithFeeInstructionDataArgs['feeCiphertextValidityProofInstructionOffset']; + rangeProofInstructionOffset: ConfidentialTransferWithFeeInstructionDataArgs['rangeProofInstructionOffset']; + multiSigners?: Array; +}; + +export function getConfidentialTransferWithFeeInstruction< + TAccountSourceToken extends string, + TAccountMint extends string, + TAccountDestinationToken extends string, + TAccountInstructionsSysvar extends string, + TAccountEqualityRecord extends string, + TAccountTransferAmountCiphertextValidityRecord extends string, + TAccountFeeSigmaRecord extends string, + TAccountFeeCiphertextValidityRecord extends string, + TAccountRangeRecord extends string, + TAccountAuthority extends string, +>( + input: ConfidentialTransferWithFeeInput< + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountTransferAmountCiphertextValidityRecord, + TAccountFeeSigmaRecord, + TAccountFeeCiphertextValidityRecord, + TAccountRangeRecord, + TAccountAuthority + > +): ConfidentialTransferWithFeeInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountTransferAmountCiphertextValidityRecord, + TAccountFeeSigmaRecord, + TAccountFeeCiphertextValidityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + sourceToken: { value: input.sourceToken ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + destinationToken: { + value: input.destinationToken ?? null, + isWritable: true, + }, + instructionsSysvar: { + value: input.instructionsSysvar ?? null, + isWritable: false, + }, + equalityRecord: { value: input.equalityRecord ?? null, isWritable: false }, + transferAmountCiphertextValidityRecord: { + value: input.transferAmountCiphertextValidityRecord ?? null, + isWritable: false, + }, + feeSigmaRecord: { value: input.feeSigmaRecord ?? null, isWritable: false }, + feeCiphertextValidityRecord: { + value: input.feeCiphertextValidityRecord ?? null, + isWritable: false, + }, + rangeRecord: { value: input.rangeRecord ?? null, isWritable: false }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.sourceToken), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.destinationToken), + getAccountMeta(accounts.instructionsSysvar), + getAccountMeta(accounts.equalityRecord), + getAccountMeta(accounts.transferAmountCiphertextValidityRecord), + getAccountMeta(accounts.feeSigmaRecord), + getAccountMeta(accounts.feeCiphertextValidityRecord), + getAccountMeta(accounts.rangeRecord), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getConfidentialTransferWithFeeInstructionDataEncoder().encode( + args as ConfidentialTransferWithFeeInstructionDataArgs + ), + } as ConfidentialTransferWithFeeInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountSourceToken, + TAccountMint, + TAccountDestinationToken, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountTransferAmountCiphertextValidityRecord, + TAccountFeeSigmaRecord, + TAccountFeeCiphertextValidityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedConfidentialTransferWithFeeInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The source SPL Token account. */ + sourceToken: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** The destination SPL Token account. */ + destinationToken: TAccountMetas[2]; + /** + * (Optional) Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + + instructionsSysvar?: TAccountMetas[3] | undefined; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: TAccountMetas[4] | undefined; + /** + * (Optional) Transfer amount ciphertext validity proof record + * account or context state account. + */ + + transferAmountCiphertextValidityRecord?: TAccountMetas[5] | undefined; + /** (Optional) Fee sigma proof record account or context state account. */ + feeSigmaRecord?: TAccountMetas[6] | undefined; + /** (Optional) Fee ciphertext validity proof record account or context state account. */ + feeCiphertextValidityRecord?: TAccountMetas[7] | undefined; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: TAccountMetas[8] | undefined; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[9]; + }; + data: ConfidentialTransferWithFeeInstructionData; +}; + +export function parseConfidentialTransferWithFeeInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedConfidentialTransferWithFeeInstruction { + if (instruction.accounts.length < 10) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + const getNextOptionalAccount = () => { + const accountMeta = getNextAccount(); + return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS + ? undefined + : accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + sourceToken: getNextAccount(), + mint: getNextAccount(), + destinationToken: getNextAccount(), + instructionsSysvar: getNextOptionalAccount(), + equalityRecord: getNextOptionalAccount(), + transferAmountCiphertextValidityRecord: getNextOptionalAccount(), + feeSigmaRecord: getNextOptionalAccount(), + feeCiphertextValidityRecord: getNextOptionalAccount(), + rangeRecord: getNextOptionalAccount(), + authority: getNextAccount(), + }, + data: getConfidentialTransferWithFeeInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/confidentialWithdraw.ts b/clients/js/src/generated/instructions/confidentialWithdraw.ts new file mode 100644 index 0000000..f69b059 --- /dev/null +++ b/clients/js/src/generated/instructions/confidentialWithdraw.ts @@ -0,0 +1,369 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getI8Decoder, + getI8Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; +import { + getDecryptableBalanceDecoder, + getDecryptableBalanceEncoder, + type DecryptableBalance, + type DecryptableBalanceArgs, +} from '../types'; + +export const CONFIDENTIAL_WITHDRAW_DISCRIMINATOR = 27; + +export function getConfidentialWithdrawDiscriminatorBytes() { + return getU8Encoder().encode(CONFIDENTIAL_WITHDRAW_DISCRIMINATOR); +} + +export const CONFIDENTIAL_WITHDRAW_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 6; + +export function getConfidentialWithdrawConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + CONFIDENTIAL_WITHDRAW_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ConfidentialWithdrawInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountInstructionsSysvar extends string | IAccountMeta = string, + TAccountEqualityRecord extends string | IAccountMeta = string, + TAccountRangeRecord extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountInstructionsSysvar extends string + ? ReadonlyAccount + : TAccountInstructionsSysvar, + TAccountEqualityRecord extends string + ? ReadonlyAccount + : TAccountEqualityRecord, + TAccountRangeRecord extends string + ? ReadonlyAccount + : TAccountRangeRecord, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ConfidentialWithdrawInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** The amount of tokens to withdraw. */ + amount: bigint; + /** Expected number of base 10 digits to the right of the decimal place. */ + decimals: number; + /** The new decryptable balance if the withdrawal succeeds. */ + newDecryptableAvailableBalance: DecryptableBalance; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `Withdraw` instruction in the transaction. If the offset is + * `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU64` + * instruction to the `Withdraw` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + rangeProofInstructionOffset: number; +}; + +export type ConfidentialWithdrawInstructionDataArgs = { + /** The amount of tokens to withdraw. */ + amount: number | bigint; + /** Expected number of base 10 digits to the right of the decimal place. */ + decimals: number; + /** The new decryptable balance if the withdrawal succeeds. */ + newDecryptableAvailableBalance: DecryptableBalanceArgs; + /** + * Relative location of the + * `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction + * to the `Withdraw` instruction in the transaction. If the offset is + * `0`, then use a context state account for the proof. + */ + equalityProofInstructionOffset: number; + /** + * Relative location of the `ProofInstruction::BatchedRangeProofU64` + * instruction to the `Withdraw` instruction in the transaction. If the + * offset is `0`, then use a context state account for the proof. + */ + rangeProofInstructionOffset: number; +}; + +export function getConfidentialWithdrawInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['amount', getU64Encoder()], + ['decimals', getU8Encoder()], + ['newDecryptableAvailableBalance', getDecryptableBalanceEncoder()], + ['equalityProofInstructionOffset', getI8Encoder()], + ['rangeProofInstructionOffset', getI8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CONFIDENTIAL_WITHDRAW_DISCRIMINATOR, + confidentialTransferDiscriminator: + CONFIDENTIAL_WITHDRAW_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getConfidentialWithdrawInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['amount', getU64Decoder()], + ['decimals', getU8Decoder()], + ['newDecryptableAvailableBalance', getDecryptableBalanceDecoder()], + ['equalityProofInstructionOffset', getI8Decoder()], + ['rangeProofInstructionOffset', getI8Decoder()], + ]); +} + +export function getConfidentialWithdrawInstructionDataCodec(): Codec< + ConfidentialWithdrawInstructionDataArgs, + ConfidentialWithdrawInstructionData +> { + return combineCodec( + getConfidentialWithdrawInstructionDataEncoder(), + getConfidentialWithdrawInstructionDataDecoder() + ); +} + +export type ConfidentialWithdrawInput< + TAccountToken extends string = string, + TAccountMint extends string = string, + TAccountInstructionsSysvar extends string = string, + TAccountEqualityRecord extends string = string, + TAccountRangeRecord extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** + * Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + instructionsSysvar?: Address; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: Address; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + amount: ConfidentialWithdrawInstructionDataArgs['amount']; + decimals: ConfidentialWithdrawInstructionDataArgs['decimals']; + newDecryptableAvailableBalance: ConfidentialWithdrawInstructionDataArgs['newDecryptableAvailableBalance']; + equalityProofInstructionOffset: ConfidentialWithdrawInstructionDataArgs['equalityProofInstructionOffset']; + rangeProofInstructionOffset: ConfidentialWithdrawInstructionDataArgs['rangeProofInstructionOffset']; + multiSigners?: Array; +}; + +export function getConfidentialWithdrawInstruction< + TAccountToken extends string, + TAccountMint extends string, + TAccountInstructionsSysvar extends string, + TAccountEqualityRecord extends string, + TAccountRangeRecord extends string, + TAccountAuthority extends string, +>( + input: ConfidentialWithdrawInput< + TAccountToken, + TAccountMint, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountRangeRecord, + TAccountAuthority + > +): ConfidentialWithdrawInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + mint: { value: input.mint ?? null, isWritable: false }, + instructionsSysvar: { + value: input.instructionsSysvar ?? null, + isWritable: false, + }, + equalityRecord: { value: input.equalityRecord ?? null, isWritable: false }, + rangeRecord: { value: input.rangeRecord ?? null, isWritable: false }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.instructionsSysvar), + getAccountMeta(accounts.equalityRecord), + getAccountMeta(accounts.rangeRecord), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getConfidentialWithdrawInstructionDataEncoder().encode( + args as ConfidentialWithdrawInstructionDataArgs + ), + } as ConfidentialWithdrawInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountInstructionsSysvar, + TAccountEqualityRecord, + TAccountRangeRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedConfidentialWithdrawInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** + * Instructions sysvar if at least one of the + * `zk_elgamal_proof` instructions are included in the same + * transaction. + */ + + instructionsSysvar?: TAccountMetas[2] | undefined; + /** (Optional) Equality proof record account or context state account. */ + equalityRecord?: TAccountMetas[3] | undefined; + /** (Optional) Range proof record account or context state account. */ + rangeRecord?: TAccountMetas[4] | undefined; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[5]; + }; + data: ConfidentialWithdrawInstructionData; +}; + +export function parseConfidentialWithdrawInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedConfidentialWithdrawInstruction { + 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; + }; + const getNextOptionalAccount = () => { + const accountMeta = getNextAccount(); + return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS + ? undefined + : accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + token: getNextAccount(), + mint: getNextAccount(), + instructionsSysvar: getNextOptionalAccount(), + equalityRecord: getNextOptionalAccount(), + rangeRecord: getNextOptionalAccount(), + authority: getNextAccount(), + }, + data: getConfidentialWithdrawInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/configureConfidentialAccount.ts b/clients/js/src/generated/instructions/configureConfidentialAccount.ts new file mode 100644 index 0000000..ee6c3f7 --- /dev/null +++ b/clients/js/src/generated/instructions/configureConfidentialAccount.ts @@ -0,0 +1,347 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getI8Decoder, + getI8Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; +import { + getDecryptableBalanceDecoder, + getDecryptableBalanceEncoder, + type DecryptableBalance, + type DecryptableBalanceArgs, +} from '../types'; + +export const CONFIGURE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR = 27; + +export function getConfigureConfidentialAccountDiscriminatorBytes() { + return getU8Encoder().encode(CONFIGURE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR); +} + +export const CONFIGURE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 2; + +export function getConfigureConfidentialAccountConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + CONFIGURE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type ConfigureConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, + TAccountInstructionsSysvarOrContextState extends + | string + | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', + TAccountRecord extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountInstructionsSysvarOrContextState extends string + ? ReadonlyAccount + : TAccountInstructionsSysvarOrContextState, + TAccountRecord extends string + ? ReadonlyAccount + : TAccountRecord, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type ConfigureConfidentialAccountInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** The decryptable balance (always 0) once the configure account succeeds. */ + decryptableZeroBalance: DecryptableBalance; + /** + * The maximum number of despots and transfers that an account can receiver + * before the `ApplyPendingBalance` is executed + */ + maximumPendingBalanceCreditCounter: bigint; + /** + * Relative location of the `ProofInstruction::ZeroCiphertextProof` + * instruction to the `ConfigureAccount` instruction in the + * transaction. If the offset is `0`, then use a context state account + * for the proof. + */ + proofInstructionOffset: number; +}; + +export type ConfigureConfidentialAccountInstructionDataArgs = { + /** The decryptable balance (always 0) once the configure account succeeds. */ + decryptableZeroBalance: DecryptableBalanceArgs; + /** + * The maximum number of despots and transfers that an account can receiver + * before the `ApplyPendingBalance` is executed + */ + maximumPendingBalanceCreditCounter: number | bigint; + /** + * Relative location of the `ProofInstruction::ZeroCiphertextProof` + * instruction to the `ConfigureAccount` instruction in the + * transaction. If the offset is `0`, then use a context state account + * for the proof. + */ + proofInstructionOffset: number; +}; + +export function getConfigureConfidentialAccountInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['decryptableZeroBalance', getDecryptableBalanceEncoder()], + ['maximumPendingBalanceCreditCounter', getU64Encoder()], + ['proofInstructionOffset', getI8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CONFIGURE_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR, + confidentialTransferDiscriminator: + CONFIGURE_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getConfigureConfidentialAccountInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['decryptableZeroBalance', getDecryptableBalanceDecoder()], + ['maximumPendingBalanceCreditCounter', getU64Decoder()], + ['proofInstructionOffset', getI8Decoder()], + ]); +} + +export function getConfigureConfidentialAccountInstructionDataCodec(): Codec< + ConfigureConfidentialAccountInstructionDataArgs, + ConfigureConfidentialAccountInstructionData +> { + return combineCodec( + getConfigureConfidentialAccountInstructionDataEncoder(), + getConfigureConfidentialAccountInstructionDataDecoder() + ); +} + +export type ConfigureConfidentialAccountInput< + TAccountToken extends string = string, + TAccountMint extends string = string, + TAccountInstructionsSysvarOrContextState extends string = string, + TAccountRecord extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The corresponding SPL Token mint. */ + mint: Address; + /** + * Instructions sysvar if `VerifyPubkeyValidity` is included in + * the same transaction or context state account if + * `VerifyPubkeyValidity` is pre-verified into a context state + * account. + */ + instructionsSysvarOrContextState?: Address; + /** (Optional) Record account if the accompanying proof is to be read from a record account. */ + record?: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + decryptableZeroBalance: ConfigureConfidentialAccountInstructionDataArgs['decryptableZeroBalance']; + maximumPendingBalanceCreditCounter: ConfigureConfidentialAccountInstructionDataArgs['maximumPendingBalanceCreditCounter']; + proofInstructionOffset: ConfigureConfidentialAccountInstructionDataArgs['proofInstructionOffset']; + multiSigners?: Array; +}; + +export function getConfigureConfidentialAccountInstruction< + TAccountToken extends string, + TAccountMint extends string, + TAccountInstructionsSysvarOrContextState extends string, + TAccountRecord extends string, + TAccountAuthority extends string, +>( + input: ConfigureConfidentialAccountInput< + TAccountToken, + TAccountMint, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + TAccountAuthority + > +): ConfigureConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + 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 + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.instructionsSysvarOrContextState.value) { + accounts.instructionsSysvarOrContextState.value = + 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; + } + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.instructionsSysvarOrContextState), + getAccountMeta(accounts.record), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getConfigureConfidentialAccountInstructionDataEncoder().encode( + args as ConfigureConfidentialAccountInstructionDataArgs + ), + } as ConfigureConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountMint, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedConfigureConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The corresponding SPL Token mint. */ + mint: TAccountMetas[1]; + /** + * Instructions sysvar if `VerifyPubkeyValidity` is included in + * the same transaction or context state account if + * `VerifyPubkeyValidity` is pre-verified into a context state + * 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]; + }; + data: ConfigureConfidentialAccountInstructionData; +}; + +export function parseConfigureConfidentialAccountInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedConfigureConfidentialAccountInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + 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: getConfigureConfidentialAccountInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/disableConfidentialCredits.ts b/clients/js/src/generated/instructions/disableConfidentialCredits.ts new file mode 100644 index 0000000..03d59e5 --- /dev/null +++ b/clients/js/src/generated/instructions/disableConfidentialCredits.ts @@ -0,0 +1,218 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const DISABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR = 27; + +export function getDisableConfidentialCreditsDiscriminatorBytes() { + return getU8Encoder().encode(DISABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR); +} + +export const DISABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 10; + +export function getDisableConfidentialCreditsConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + DISABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type DisableConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type DisableConfidentialCreditsInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; +}; + +export type DisableConfidentialCreditsInstructionDataArgs = {}; + +export function getDisableConfidentialCreditsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DISABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR, + confidentialTransferDiscriminator: + DISABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getDisableConfidentialCreditsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ]); +} + +export function getDisableConfidentialCreditsInstructionDataCodec(): Codec< + DisableConfidentialCreditsInstructionDataArgs, + DisableConfidentialCreditsInstructionData +> { + return combineCodec( + getDisableConfidentialCreditsInstructionDataEncoder(), + getDisableConfidentialCreditsInstructionDataDecoder() + ); +} + +export type DisableConfidentialCreditsInput< + TAccountToken extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + multiSigners?: Array; +}; + +export function getDisableConfidentialCreditsInstruction< + TAccountToken extends string, + TAccountAuthority extends string, +>( + input: DisableConfidentialCreditsInput +): DisableConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getDisableConfidentialCreditsInstructionDataEncoder().encode({}), + } as DisableConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedDisableConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[1]; + }; + data: DisableConfidentialCreditsInstructionData; +}; + +export function parseDisableConfidentialCreditsInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedDisableConfidentialCreditsInstruction { + 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: { + token: getNextAccount(), + authority: getNextAccount(), + }, + data: getDisableConfidentialCreditsInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/disableNonConfidentialCredits.ts b/clients/js/src/generated/instructions/disableNonConfidentialCredits.ts new file mode 100644 index 0000000..f1e3a81 --- /dev/null +++ b/clients/js/src/generated/instructions/disableNonConfidentialCredits.ts @@ -0,0 +1,218 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const DISABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR = 27; + +export function getDisableNonConfidentialCreditsDiscriminatorBytes() { + return getU8Encoder().encode(DISABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR); +} + +export const DISABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 12; + +export function getDisableNonConfidentialCreditsConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + DISABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type DisableNonConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type DisableNonConfidentialCreditsInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; +}; + +export type DisableNonConfidentialCreditsInstructionDataArgs = {}; + +export function getDisableNonConfidentialCreditsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: DISABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR, + confidentialTransferDiscriminator: + DISABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getDisableNonConfidentialCreditsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ]); +} + +export function getDisableNonConfidentialCreditsInstructionDataCodec(): Codec< + DisableNonConfidentialCreditsInstructionDataArgs, + DisableNonConfidentialCreditsInstructionData +> { + return combineCodec( + getDisableNonConfidentialCreditsInstructionDataEncoder(), + getDisableNonConfidentialCreditsInstructionDataDecoder() + ); +} + +export type DisableNonConfidentialCreditsInput< + TAccountToken extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + multiSigners?: Array; +}; + +export function getDisableNonConfidentialCreditsInstruction< + TAccountToken extends string, + TAccountAuthority extends string, +>( + input: DisableNonConfidentialCreditsInput +): DisableNonConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getDisableNonConfidentialCreditsInstructionDataEncoder().encode({}), + } as DisableNonConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedDisableNonConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[1]; + }; + data: DisableNonConfidentialCreditsInstructionData; +}; + +export function parseDisableNonConfidentialCreditsInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedDisableNonConfidentialCreditsInstruction { + 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: { + token: getNextAccount(), + authority: getNextAccount(), + }, + data: getDisableNonConfidentialCreditsInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/emptyConfidentialAccount.ts b/clients/js/src/generated/instructions/emptyConfidentialAccount.ts new file mode 100644 index 0000000..10a2654 --- /dev/null +++ b/clients/js/src/generated/instructions/emptyConfidentialAccount.ts @@ -0,0 +1,301 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getI8Decoder, + getI8Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const EMPTY_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR = 27; + +export function getEmptyConfidentialAccountDiscriminatorBytes() { + return getU8Encoder().encode(EMPTY_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR); +} + +export const EMPTY_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 4; + +export function getEmptyConfidentialAccountConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + EMPTY_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type EmptyConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountInstructionsSysvarOrContextState extends + | string + | IAccountMeta = 'Sysvar1nstructions1111111111111111111111111', + TAccountRecord extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountInstructionsSysvarOrContextState extends string + ? ReadonlyAccount + : TAccountInstructionsSysvarOrContextState, + TAccountRecord extends string + ? ReadonlyAccount + : TAccountRecord, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type EmptyConfidentialAccountInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** + * Relative location of the `ProofInstruction::VerifyCloseAccount` + * instruction to the `EmptyAccount` instruction in the transaction. If + * the offset is `0`, then use a context state account for the proof. + */ + proofInstructionOffset: number; +}; + +export type EmptyConfidentialAccountInstructionDataArgs = { + /** + * Relative location of the `ProofInstruction::VerifyCloseAccount` + * instruction to the `EmptyAccount` instruction in the transaction. If + * the offset is `0`, then use a context state account for the proof. + */ + proofInstructionOffset: number; +}; + +export function getEmptyConfidentialAccountInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['proofInstructionOffset', getI8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: EMPTY_CONFIDENTIAL_ACCOUNT_DISCRIMINATOR, + confidentialTransferDiscriminator: + EMPTY_CONFIDENTIAL_ACCOUNT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getEmptyConfidentialAccountInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['proofInstructionOffset', getI8Decoder()], + ]); +} + +export function getEmptyConfidentialAccountInstructionDataCodec(): Codec< + EmptyConfidentialAccountInstructionDataArgs, + EmptyConfidentialAccountInstructionData +> { + return combineCodec( + getEmptyConfidentialAccountInstructionDataEncoder(), + getEmptyConfidentialAccountInstructionDataDecoder() + ); +} + +export type EmptyConfidentialAccountInput< + TAccountToken extends string = string, + TAccountInstructionsSysvarOrContextState extends string = string, + TAccountRecord extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** + * Instructions sysvar if `VerifyZeroCiphertext` is included in + * the same transaction or context state account if + * `VerifyZeroCiphertext` is pre-verified into a context state + * account. + */ + instructionsSysvarOrContextState?: Address; + /** (Optional) Record account if the accompanying proof is to be read from a record account. */ + record?: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + proofInstructionOffset: EmptyConfidentialAccountInstructionDataArgs['proofInstructionOffset']; + multiSigners?: Array; +}; + +export function getEmptyConfidentialAccountInstruction< + TAccountToken extends string, + TAccountInstructionsSysvarOrContextState extends string, + TAccountRecord extends string, + TAccountAuthority extends string, +>( + input: EmptyConfidentialAccountInput< + TAccountToken, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + TAccountAuthority + > +): EmptyConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + 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 + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.instructionsSysvarOrContextState.value) { + accounts.instructionsSysvarOrContextState.value = + 'Sysvar1nstructions1111111111111111111111111' as Address<'Sysvar1nstructions1111111111111111111111111'>; + } + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.instructionsSysvarOrContextState), + getAccountMeta(accounts.record), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getEmptyConfidentialAccountInstructionDataEncoder().encode( + args as EmptyConfidentialAccountInstructionDataArgs + ), + } as EmptyConfidentialAccountInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + TAccountInstructionsSysvarOrContextState, + TAccountRecord, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedEmptyConfidentialAccountInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** + * Instructions sysvar if `VerifyZeroCiphertext` is included in + * the same transaction or context state account if + * `VerifyZeroCiphertext` is pre-verified into a context state + * account. + */ + + instructionsSysvarOrContextState: TAccountMetas[1]; + /** (Optional) Record account if the accompanying proof is to be read from a record account. */ + record?: TAccountMetas[2] | undefined; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[3]; + }; + data: EmptyConfidentialAccountInstructionData; +}; + +export function parseEmptyConfidentialAccountInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedEmptyConfidentialAccountInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + 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(), + instructionsSysvarOrContextState: getNextAccount(), + record: getNextOptionalAccount(), + authority: getNextAccount(), + }, + data: getEmptyConfidentialAccountInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/enableConfidentialCredits.ts b/clients/js/src/generated/instructions/enableConfidentialCredits.ts new file mode 100644 index 0000000..d9d8372 --- /dev/null +++ b/clients/js/src/generated/instructions/enableConfidentialCredits.ts @@ -0,0 +1,218 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const ENABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR = 27; + +export function getEnableConfidentialCreditsDiscriminatorBytes() { + return getU8Encoder().encode(ENABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR); +} + +export const ENABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 9; + +export function getEnableConfidentialCreditsConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + ENABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type EnableConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type EnableConfidentialCreditsInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; +}; + +export type EnableConfidentialCreditsInstructionDataArgs = {}; + +export function getEnableConfidentialCreditsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: ENABLE_CONFIDENTIAL_CREDITS_DISCRIMINATOR, + confidentialTransferDiscriminator: + ENABLE_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getEnableConfidentialCreditsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ]); +} + +export function getEnableConfidentialCreditsInstructionDataCodec(): Codec< + EnableConfidentialCreditsInstructionDataArgs, + EnableConfidentialCreditsInstructionData +> { + return combineCodec( + getEnableConfidentialCreditsInstructionDataEncoder(), + getEnableConfidentialCreditsInstructionDataDecoder() + ); +} + +export type EnableConfidentialCreditsInput< + TAccountToken extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + multiSigners?: Array; +}; + +export function getEnableConfidentialCreditsInstruction< + TAccountToken extends string, + TAccountAuthority extends string, +>( + input: EnableConfidentialCreditsInput +): EnableConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getEnableConfidentialCreditsInstructionDataEncoder().encode({}), + } as EnableConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedEnableConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[1]; + }; + data: EnableConfidentialCreditsInstructionData; +}; + +export function parseEnableConfidentialCreditsInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedEnableConfidentialCreditsInstruction { + 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: { + token: getNextAccount(), + authority: getNextAccount(), + }, + data: getEnableConfidentialCreditsInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/enableNonConfidentialCredits.ts b/clients/js/src/generated/instructions/enableNonConfidentialCredits.ts new file mode 100644 index 0000000..b6e7866 --- /dev/null +++ b/clients/js/src/generated/instructions/enableNonConfidentialCredits.ts @@ -0,0 +1,218 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + AccountRole, + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const ENABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR = 27; + +export function getEnableNonConfidentialCreditsDiscriminatorBytes() { + return getU8Encoder().encode(ENABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR); +} + +export const ENABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 11; + +export function getEnableNonConfidentialCreditsConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + ENABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type EnableNonConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountToken extends string + ? WritableAccount + : TAccountToken, + TAccountAuthority extends string + ? ReadonlyAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type EnableNonConfidentialCreditsInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; +}; + +export type EnableNonConfidentialCreditsInstructionDataArgs = {}; + +export function getEnableNonConfidentialCreditsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: ENABLE_NON_CONFIDENTIAL_CREDITS_DISCRIMINATOR, + confidentialTransferDiscriminator: + ENABLE_NON_CONFIDENTIAL_CREDITS_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getEnableNonConfidentialCreditsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ]); +} + +export function getEnableNonConfidentialCreditsInstructionDataCodec(): Codec< + EnableNonConfidentialCreditsInstructionDataArgs, + EnableNonConfidentialCreditsInstructionData +> { + return combineCodec( + getEnableNonConfidentialCreditsInstructionDataEncoder(), + getEnableNonConfidentialCreditsInstructionDataDecoder() + ); +} + +export type EnableNonConfidentialCreditsInput< + TAccountToken extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token account. */ + token: Address; + /** The source account's owner/delegate or its multisignature account. */ + authority: Address | TransactionSigner; + multiSigners?: Array; +}; + +export function getEnableNonConfidentialCreditsInstruction< + TAccountToken extends string, + TAccountAuthority extends string, +>( + input: EnableNonConfidentialCreditsInput +): EnableNonConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + token: { value: input.token ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.token), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getEnableNonConfidentialCreditsInstructionDataEncoder().encode({}), + } as EnableNonConfidentialCreditsInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountToken, + (typeof input)['authority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedEnableNonConfidentialCreditsInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token account. */ + token: TAccountMetas[0]; + /** The source account's owner/delegate or its multisignature account. */ + authority: TAccountMetas[1]; + }; + data: EnableNonConfidentialCreditsInstructionData; +}; + +export function parseEnableNonConfidentialCreditsInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedEnableNonConfidentialCreditsInstruction { + 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: { + token: getNextAccount(), + authority: getNextAccount(), + }, + data: getEnableNonConfidentialCreditsInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index 9f418fe..4b6e47a 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -7,19 +7,32 @@ */ export * from './amountToUiAmount'; +export * from './applyConfidentialPendingBalance'; export * from './approve'; export * from './approveChecked'; +export * from './approveConfidentialAccount'; export * from './burn'; export * from './burnChecked'; export * from './closeAccount'; +export * from './confidentialDeposit'; +export * from './confidentialTransfer'; +export * from './confidentialTransferWithFee'; +export * from './confidentialWithdraw'; +export * from './configureConfidentialAccount'; export * from './createAssociatedToken'; export * from './createAssociatedTokenIdempotent'; +export * from './disableConfidentialCredits'; +export * from './disableNonConfidentialCredits'; +export * from './emptyConfidentialAccount'; +export * from './enableConfidentialCredits'; +export * from './enableNonConfidentialCredits'; export * from './freezeAccount'; export * from './getAccountDataSize'; export * from './harvestWithheldTokensToMint'; export * from './initializeAccount'; export * from './initializeAccount2'; export * from './initializeAccount3'; +export * from './initializeConfidentialTransferMint'; export * from './initializeImmutableOwner'; export * from './initializeMint'; export * from './initializeMint2'; @@ -39,5 +52,6 @@ export * from './transfer'; export * from './transferChecked'; export * from './transferCheckedWithFee'; export * from './uiAmountToAmount'; +export * from './updateConfidentialTransferMint'; export * from './withdrawWithheldTokensFromAccounts'; export * from './withdrawWithheldTokensFromMint'; diff --git a/clients/js/src/generated/instructions/initializeConfidentialTransferMint.ts b/clients/js/src/generated/instructions/initializeConfidentialTransferMint.ts new file mode 100644 index 0000000..d53d97b --- /dev/null +++ b/clients/js/src/generated/instructions/initializeConfidentialTransferMint.ts @@ -0,0 +1,252 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getBooleanDecoder, + getBooleanEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type Option, + type OptionOrNullable, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR = 27; + +export function getInitializeConfidentialTransferMintDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR + ); +} + +export const INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 0; + +export function getInitializeConfidentialTransferMintConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type InitializeConfidentialTransferMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + ...TRemainingAccounts, + ] + >; + +export type InitializeConfidentialTransferMintInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** + * Authority to modify the `ConfidentialTransferMint` configuration and to + * approve new accounts. + */ + authority: Option
; + /** + * Determines if newly configured accounts must be approved by the + * `authority` before they may be used by the user. + */ + autoApproveNewAccounts: boolean; + /** New authority to decode any transfer amount in a confidential transfer. */ + auditorElgamalPubkey: Option
; +}; + +export type InitializeConfidentialTransferMintInstructionDataArgs = { + /** + * Authority to modify the `ConfidentialTransferMint` configuration and to + * approve new accounts. + */ + authority: OptionOrNullable
; + /** + * Determines if newly configured accounts must be approved by the + * `authority` before they may be used by the user. + */ + autoApproveNewAccounts: boolean; + /** New authority to decode any transfer amount in a confidential transfer. */ + auditorElgamalPubkey: OptionOrNullable
; +}; + +export function getInitializeConfidentialTransferMintInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + [ + 'authority', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['autoApproveNewAccounts', getBooleanEncoder()], + [ + 'auditorElgamalPubkey', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR, + confidentialTransferDiscriminator: + INITIALIZE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getInitializeConfidentialTransferMintInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + [ + 'authority', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['autoApproveNewAccounts', getBooleanDecoder()], + [ + 'auditorElgamalPubkey', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]); +} + +export function getInitializeConfidentialTransferMintInstructionDataCodec(): Codec< + InitializeConfidentialTransferMintInstructionDataArgs, + InitializeConfidentialTransferMintInstructionData +> { + return combineCodec( + getInitializeConfidentialTransferMintInstructionDataEncoder(), + getInitializeConfidentialTransferMintInstructionDataDecoder() + ); +} + +export type InitializeConfidentialTransferMintInput< + TAccountMint extends string = string, +> = { + /** The SPL Token mint. */ + mint: Address; + authority: InitializeConfidentialTransferMintInstructionDataArgs['authority']; + autoApproveNewAccounts: InitializeConfidentialTransferMintInstructionDataArgs['autoApproveNewAccounts']; + auditorElgamalPubkey: InitializeConfidentialTransferMintInstructionDataArgs['auditorElgamalPubkey']; +}; + +export function getInitializeConfidentialTransferMintInstruction< + TAccountMint extends string, +>( + input: InitializeConfidentialTransferMintInput +): InitializeConfidentialTransferMintInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [getAccountMeta(accounts.mint)], + programAddress, + data: getInitializeConfidentialTransferMintInstructionDataEncoder().encode( + args as InitializeConfidentialTransferMintInstructionDataArgs + ), + } as InitializeConfidentialTransferMintInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint + >; + + return instruction; +} + +export type ParsedInitializeConfidentialTransferMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token mint. */ + mint: TAccountMetas[0]; + }; + data: InitializeConfidentialTransferMintInstructionData; +}; + +export function parseInitializeConfidentialTransferMintInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedInitializeConfidentialTransferMintInstruction< + TProgram, + TAccountMetas +> { + if (instruction.accounts.length < 1) { + // 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: { + mint: getNextAccount(), + }, + data: getInitializeConfidentialTransferMintInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/updateConfidentialTransferMint.ts b/clients/js/src/generated/instructions/updateConfidentialTransferMint.ts new file mode 100644 index 0000000..e97ce99 --- /dev/null +++ b/clients/js/src/generated/instructions/updateConfidentialTransferMint.ts @@ -0,0 +1,243 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/kinobi-so/kinobi + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getBooleanDecoder, + getBooleanEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const UPDATE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR = 27; + +export function getUpdateConfidentialTransferMintDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR); +} + +export const UPDATE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 1; + +export function getUpdateConfidentialTransferMintConfidentialTransferDiscriminatorBytes() { + return getU8Encoder().encode( + UPDATE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR + ); +} + +export type UpdateConfidentialTransferMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountAuthority extends string + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateConfidentialTransferMintInstructionData = { + discriminator: number; + confidentialTransferDiscriminator: number; + /** + * Determines if newly configured accounts must be approved by the + * `authority` before they may be used by the user. + */ + autoApproveNewAccounts: boolean; + /** New authority to decode any transfer amount in a confidential transfer. */ + auditorElgamalPubkey: Option
; +}; + +export type UpdateConfidentialTransferMintInstructionDataArgs = { + /** + * Determines if newly configured accounts must be approved by the + * `authority` before they may be used by the user. + */ + autoApproveNewAccounts: boolean; + /** New authority to decode any transfer amount in a confidential transfer. */ + auditorElgamalPubkey: OptionOrNullable
; +}; + +export function getUpdateConfidentialTransferMintInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['confidentialTransferDiscriminator', getU8Encoder()], + ['autoApproveNewAccounts', getBooleanEncoder()], + [ + 'auditorElgamalPubkey', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_CONFIDENTIAL_TRANSFER_MINT_DISCRIMINATOR, + confidentialTransferDiscriminator: + UPDATE_CONFIDENTIAL_TRANSFER_MINT_CONFIDENTIAL_TRANSFER_DISCRIMINATOR, + }) + ); +} + +export function getUpdateConfidentialTransferMintInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['confidentialTransferDiscriminator', getU8Decoder()], + ['autoApproveNewAccounts', getBooleanDecoder()], + [ + 'auditorElgamalPubkey', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]); +} + +export function getUpdateConfidentialTransferMintInstructionDataCodec(): Codec< + UpdateConfidentialTransferMintInstructionDataArgs, + UpdateConfidentialTransferMintInstructionData +> { + return combineCodec( + getUpdateConfidentialTransferMintInstructionDataEncoder(), + getUpdateConfidentialTransferMintInstructionDataDecoder() + ); +} + +export type UpdateConfidentialTransferMintInput< + TAccountMint extends string = string, + TAccountAuthority extends string = string, +> = { + /** The SPL Token mint. */ + mint: Address; + /** Confidential transfer mint authority. */ + authority: TransactionSigner; + autoApproveNewAccounts: UpdateConfidentialTransferMintInstructionDataArgs['autoApproveNewAccounts']; + auditorElgamalPubkey: UpdateConfidentialTransferMintInstructionDataArgs['auditorElgamalPubkey']; +}; + +export function getUpdateConfidentialTransferMintInstruction< + TAccountMint extends string, + TAccountAuthority extends string, +>( + input: UpdateConfidentialTransferMintInput +): UpdateConfidentialTransferMintInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint, + TAccountAuthority +> { + // Program address. + const programAddress = TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.mint), + getAccountMeta(accounts.authority), + ], + programAddress, + data: getUpdateConfidentialTransferMintInstructionDataEncoder().encode( + args as UpdateConfidentialTransferMintInstructionDataArgs + ), + } as UpdateConfidentialTransferMintInstruction< + typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint, + TAccountAuthority + >; + + return instruction; +} + +export type ParsedUpdateConfidentialTransferMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The SPL Token mint. */ + mint: TAccountMetas[0]; + /** Confidential transfer mint authority. */ + authority: TAccountMetas[1]; + }; + data: UpdateConfidentialTransferMintInstructionData; +}; + +export function parseUpdateConfidentialTransferMintInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedUpdateConfidentialTransferMintInstruction { + 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: { + mint: getNextAccount(), + authority: getNextAccount(), + }, + data: getUpdateConfidentialTransferMintInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/programs/token2022.ts b/clients/js/src/generated/programs/token2022.ts index 33c09ab..90f5356 100644 --- a/clients/js/src/generated/programs/token2022.ts +++ b/clients/js/src/generated/programs/token2022.ts @@ -14,17 +14,30 @@ import { } from '@solana/web3.js'; import { type ParsedAmountToUiAmountInstruction, + type ParsedApplyConfidentialPendingBalanceInstruction, type ParsedApproveCheckedInstruction, + type ParsedApproveConfidentialAccountInstruction, type ParsedApproveInstruction, type ParsedBurnCheckedInstruction, type ParsedBurnInstruction, type ParsedCloseAccountInstruction, + type ParsedConfidentialDepositInstruction, + type ParsedConfidentialTransferInstruction, + type ParsedConfidentialTransferWithFeeInstruction, + type ParsedConfidentialWithdrawInstruction, + type ParsedConfigureConfidentialAccountInstruction, + type ParsedDisableConfidentialCreditsInstruction, + type ParsedDisableNonConfidentialCreditsInstruction, + type ParsedEmptyConfidentialAccountInstruction, + type ParsedEnableConfidentialCreditsInstruction, + type ParsedEnableNonConfidentialCreditsInstruction, type ParsedFreezeAccountInstruction, type ParsedGetAccountDataSizeInstruction, type ParsedHarvestWithheldTokensToMintInstruction, type ParsedInitializeAccount2Instruction, type ParsedInitializeAccount3Instruction, type ParsedInitializeAccountInstruction, + type ParsedInitializeConfidentialTransferMintInstruction, type ParsedInitializeImmutableOwnerInstruction, type ParsedInitializeMint2Instruction, type ParsedInitializeMintCloseAuthorityInstruction, @@ -43,6 +56,7 @@ import { type ParsedTransferCheckedWithFeeInstruction, type ParsedTransferInstruction, type ParsedUiAmountToAmountInstruction, + type ParsedUpdateConfidentialTransferMintInstruction, type ParsedWithdrawWithheldTokensFromAccountsInstruction, type ParsedWithdrawWithheldTokensFromMintInstruction, } from '../instructions'; @@ -107,6 +121,20 @@ export enum Token2022Instruction { WithdrawWithheldTokensFromAccounts, HarvestWithheldTokensToMint, SetTransferFee, + InitializeConfidentialTransferMint, + UpdateConfidentialTransferMint, + ConfigureConfidentialAccount, + ApproveConfidentialAccount, + EmptyConfidentialAccount, + ConfidentialDeposit, + ConfidentialWithdraw, + ConfidentialTransfer, + ApplyConfidentialPendingBalance, + EnableConfidentialCredits, + DisableConfidentialCredits, + EnableNonConfidentialCredits, + DisableNonConfidentialCredits, + ConfidentialTransferWithFee, } export function identifyToken2022Instruction( @@ -227,6 +255,90 @@ export function identifyToken2022Instruction( ) { return Token2022Instruction.SetTransferFee; } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(0), 1) + ) { + return Token2022Instruction.InitializeConfidentialTransferMint; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(1), 1) + ) { + return Token2022Instruction.UpdateConfidentialTransferMint; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(2), 1) + ) { + return Token2022Instruction.ConfigureConfidentialAccount; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(3), 1) + ) { + return Token2022Instruction.ApproveConfidentialAccount; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(4), 1) + ) { + return Token2022Instruction.EmptyConfidentialAccount; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(5), 1) + ) { + return Token2022Instruction.ConfidentialDeposit; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(6), 1) + ) { + return Token2022Instruction.ConfidentialWithdraw; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(7), 1) + ) { + return Token2022Instruction.ConfidentialTransfer; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(8), 1) + ) { + return Token2022Instruction.ApplyConfidentialPendingBalance; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(9), 1) + ) { + return Token2022Instruction.EnableConfidentialCredits; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(10), 1) + ) { + return Token2022Instruction.DisableConfidentialCredits; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(11), 1) + ) { + return Token2022Instruction.EnableNonConfidentialCredits; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(12), 1) + ) { + return Token2022Instruction.DisableNonConfidentialCredits; + } + if ( + containsBytes(data, getU8Encoder().encode(27), 0) && + containsBytes(data, getU8Encoder().encode(13), 1) + ) { + return Token2022Instruction.ConfidentialTransferWithFee; + } throw new Error( 'The provided instruction could not be identified as a token-2022 instruction.' ); @@ -330,4 +442,46 @@ export type ParsedToken2022Instruction< } & ParsedHarvestWithheldTokensToMintInstruction) | ({ instructionType: Token2022Instruction.SetTransferFee; - } & ParsedSetTransferFeeInstruction); + } & ParsedSetTransferFeeInstruction) + | ({ + instructionType: Token2022Instruction.InitializeConfidentialTransferMint; + } & ParsedInitializeConfidentialTransferMintInstruction) + | ({ + instructionType: Token2022Instruction.UpdateConfidentialTransferMint; + } & ParsedUpdateConfidentialTransferMintInstruction) + | ({ + instructionType: Token2022Instruction.ConfigureConfidentialAccount; + } & ParsedConfigureConfidentialAccountInstruction) + | ({ + instructionType: Token2022Instruction.ApproveConfidentialAccount; + } & ParsedApproveConfidentialAccountInstruction) + | ({ + instructionType: Token2022Instruction.EmptyConfidentialAccount; + } & ParsedEmptyConfidentialAccountInstruction) + | ({ + instructionType: Token2022Instruction.ConfidentialDeposit; + } & ParsedConfidentialDepositInstruction) + | ({ + instructionType: Token2022Instruction.ConfidentialWithdraw; + } & ParsedConfidentialWithdrawInstruction) + | ({ + instructionType: Token2022Instruction.ConfidentialTransfer; + } & ParsedConfidentialTransferInstruction) + | ({ + instructionType: Token2022Instruction.ApplyConfidentialPendingBalance; + } & ParsedApplyConfidentialPendingBalanceInstruction) + | ({ + instructionType: Token2022Instruction.EnableConfidentialCredits; + } & ParsedEnableConfidentialCreditsInstruction) + | ({ + instructionType: Token2022Instruction.DisableConfidentialCredits; + } & ParsedDisableConfidentialCreditsInstruction) + | ({ + instructionType: Token2022Instruction.EnableNonConfidentialCredits; + } & ParsedEnableNonConfidentialCreditsInstruction) + | ({ + instructionType: Token2022Instruction.DisableNonConfidentialCredits; + } & ParsedDisableNonConfidentialCreditsInstruction) + | ({ + instructionType: Token2022Instruction.ConfidentialTransferWithFee; + } & ParsedConfidentialTransferWithFeeInstruction); diff --git a/clients/js/test/extensions/confidentialTransfer/initializeConfidentialTransferMint.test.ts b/clients/js/test/extensions/confidentialTransfer/initializeConfidentialTransferMint.test.ts new file mode 100644 index 0000000..316c862 --- /dev/null +++ b/clients/js/test/extensions/confidentialTransfer/initializeConfidentialTransferMint.test.ts @@ -0,0 +1,61 @@ +import { Account, address, generateKeyPairSigner, some } from '@solana/web3.js'; +import test from 'ava'; +import { + Mint, + extension, + fetchMint, + getInitializeConfidentialTransferMintInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + getCreateMintInstructions, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it initializes a mint account with confidential transfer', async (t) => { + // Given an authority and a mint account. + const client = createDefaultSolanaClient(); + const [authority, mint] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + ]); + + // And a confidential transfer extension. + const confidentialTransferExtension = extension('ConfidentialTransferMint', { + authority: some(address('6sPR6MzvjMMP5LSZzEtTe4ZBVX9rhBmtM1dmfFtkNTbW')), + autoApproveNewAccounts: true, + auditorElgamalPubkey: some( + address('BTNEPmmWuj7Sg4Fo5i1FC5eiV2Aj4jiv9boarvE5XeaX') + ), + }); + + // When we create and initialize a mint account with this extension. + const [createMintInstruction, initMintInstruction] = + await getCreateMintInstructions({ + authority: authority.address, + client, + extensions: [confidentialTransferExtension], + mint, + payer: authority, + }); + await sendAndConfirmInstructions(client, authority, [ + createMintInstruction, + getInitializeConfidentialTransferMintInstruction({ + mint: mint.address, + ...confidentialTransferExtension, + }), + initMintInstruction, + ]); + + // Then we expect the mint account to exist and have the following data. + const mintAccount = await fetchMint(client.rpc, mint.address); + t.like(mintAccount, >{ + address: mint.address, + data: { + mintAuthority: some(authority.address), + isInitialized: true, + extensions: some([confidentialTransferExtension]), + }, + }); +}); diff --git a/clients/js/test/extensions/confidentialTransfer/updateConfidentialTransferMint.test.ts b/clients/js/test/extensions/confidentialTransfer/updateConfidentialTransferMint.test.ts new file mode 100644 index 0000000..36ce8f1 --- /dev/null +++ b/clients/js/test/extensions/confidentialTransfer/updateConfidentialTransferMint.test.ts @@ -0,0 +1,82 @@ +import { + Account, + address, + generateKeyPairSigner, + none, + some, +} from '@solana/web3.js'; +import test from 'ava'; +import { + Mint, + extension, + fetchMint, + getInitializeConfidentialTransferMintInstruction, + getUpdateConfidentialTransferMintInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + getCreateMintInstructions, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it updates a mint account with confidential transfer', async (t) => { + // Given some signer accounts. + const client = createDefaultSolanaClient(); + const [authority, confidentialTransferAuthority, mint] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + generateKeyPairSigner(), + ]); + + // And a mint account initialized with a confidential transfer extension. + const confidentialTransferExtension = extension('ConfidentialTransferMint', { + authority: some(confidentialTransferAuthority.address), + autoApproveNewAccounts: true, + auditorElgamalPubkey: some( + address('BTNEPmmWuj7Sg4Fo5i1FC5eiV2Aj4jiv9boarvE5XeaX') + ), + }); + const [createMintInstruction, initMintInstruction] = + await getCreateMintInstructions({ + authority: authority.address, + client, + extensions: [confidentialTransferExtension], + mint, + payer: authority, + }); + await sendAndConfirmInstructions(client, authority, [ + createMintInstruction, + getInitializeConfidentialTransferMintInstruction({ + mint: mint.address, + ...confidentialTransferExtension, + }), + initMintInstruction, + ]); + + // When we update the mint account with new confidential transfer configs. + await sendAndConfirmInstructions(client, authority, [ + getUpdateConfidentialTransferMintInstruction({ + mint: mint.address, + authority: confidentialTransferAuthority, + autoApproveNewAccounts: false, + auditorElgamalPubkey: none(), + }), + ]); + + // Then we expect the mint account to have the following updated data. + const mintAccount = await fetchMint(client.rpc, mint.address); + t.like(mintAccount, >{ + address: mint.address, + data: { + mintAuthority: some(authority.address), + extensions: some([ + extension('ConfidentialTransferMint', { + authority: some(confidentialTransferAuthority.address), + autoApproveNewAccounts: false, + auditorElgamalPubkey: none(), + }), + ]), + }, + }); +}); diff --git a/clients/js/test/extensions/transferFeeConfig.test.ts b/clients/js/test/extensions/transferFree/initializeTransferFeeConfig.test.ts similarity index 98% rename from clients/js/test/extensions/transferFeeConfig.test.ts rename to clients/js/test/extensions/transferFree/initializeTransferFeeConfig.test.ts index b91f11c..d36f57e 100644 --- a/clients/js/test/extensions/transferFeeConfig.test.ts +++ b/clients/js/test/extensions/transferFree/initializeTransferFeeConfig.test.ts @@ -11,13 +11,13 @@ import { extension, fetchMint, getInitializeTransferFeeConfigInstruction, -} from '../../src'; +} from '../../../src'; import { createDefaultSolanaClient, generateKeyPairSignerWithSol, getCreateMintInstructions, sendAndConfirmInstructions, -} from '../_setup'; +} from '../../_setup'; test('it initializes a mint account with transfer fee configurations', async (t) => { // Given an authority and a mint account. diff --git a/clients/js/test/extensions/transferCheckedWithFee.test.ts b/clients/js/test/extensions/transferFree/transferCheckedWithFee.test.ts similarity index 98% rename from clients/js/test/extensions/transferCheckedWithFee.test.ts rename to clients/js/test/extensions/transferFree/transferCheckedWithFee.test.ts index 7ec8610..58ce2a5 100644 --- a/clients/js/test/extensions/transferCheckedWithFee.test.ts +++ b/clients/js/test/extensions/transferFree/transferCheckedWithFee.test.ts @@ -7,14 +7,14 @@ import { getInitializeTransferFeeConfigInstruction, getMintToInstruction, getTransferCheckedWithFeeInstruction, -} from '../../src'; +} from '../../../src'; import { createDefaultSolanaClient, generateKeyPairSignerWithSol, getCreateMintInstructions, getCreateTokenInstructions, sendAndConfirmInstructions, -} from '../_setup'; +} from '../../_setup'; test('it transfers tokens with pre-configured fees', async (t) => { // Given some signer accounts. diff --git a/program/idl.json b/program/idl.json index 7980623..4ae8bc0 100644 --- a/program/idl.json +++ b/program/idl.json @@ -3025,6 +3025,1886 @@ "offset": 1 } ] + }, + { + "kind": "instructionNode", + "name": "initializeConfidentialTransferMint", + "docs": [ + "Initializes confidential transfers for a mint.", + "", + "The `ConfidentialTransferInstruction::InitializeMint` instruction", + "requires no signers and MUST be included within the same Transaction", + "as `TokenInstruction::InitializeMint`. Otherwise another party can", + "initialize the configuration.", + "", + "The instruction fails if the `TokenInstruction::InitializeMint`", + "instruction has already executed for the mint." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token mint."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 0 + } + }, + { + "kind": "instructionArgumentNode", + "name": "authority", + "docs": [ + "Authority to modify the `ConfidentialTransferMint` configuration and to", + "approve new accounts." + ], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "autoApproveNewAccounts", + "docs": [ + "Determines if newly configured accounts must be approved by the", + "`authority` before they may be used by the user." + ], + "type": { + "kind": "booleanTypeNode", + "size": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "auditorElgamalPubkey", + "docs": [ + "New authority to decode any transfer amount in a confidential transfer." + ], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "updateConfidentialTransferMint", + "docs": [ + "Updates the confidential transfer mint configuration for a mint.", + "", + "Use `TokenInstruction::SetAuthority` to update the confidential transfer", + "mint authority." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": ["Confidential transfer mint authority."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 1 + } + }, + { + "kind": "instructionArgumentNode", + "name": "autoApproveNewAccounts", + "docs": [ + "Determines if newly configured accounts must be approved by the", + "`authority` before they may be used by the user." + ], + "type": { + "kind": "booleanTypeNode", + "size": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "auditorElgamalPubkey", + "docs": [ + "New authority to decode any transfer amount in a confidential transfer." + ], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "configureConfidentialAccount", + "docs": [ + "Configures confidential transfers for a token account.", + "", + "The instruction fails if the confidential transfers are already", + "configured, or if the mint was not initialized with confidential", + "transfer support.", + "", + "The instruction fails if the `TokenInstruction::InitializeAccount`", + "instruction has not yet successfully executed for the token account.", + "", + "Upon success, confidential and non-confidential deposits and transfers", + "are enabled. Use the `DisableConfidentialCredits` and", + "`DisableNonConfidentialCredits` instructions to disable.", + "", + "In order for this instruction to be successfully processed, it must be", + "accompanied by the `VerifyPubkeyValidity` instruction of the", + "`zk_elgamal_proof` program in the same transaction or the address of a", + "context state account for the proof must be provided." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "instructionsSysvarOrContextState", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [ + "Instructions sysvar if `VerifyPubkeyValidity` is included in", + "the same transaction or context state account if", + "`VerifyPubkeyValidity` is pre-verified into a context state", + "account." + ], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Sysvar1nstructions1111111111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "record", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Record account if the accompanying proof is to be read from a record account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 2 + } + }, + { + "kind": "instructionArgumentNode", + "name": "decryptableZeroBalance", + "docs": [ + "The decryptable balance (always 0) once the configure account succeeds." + ], + "type": { + "kind": "definedTypeLinkNode", + "name": "decryptableBalance" + } + }, + { + "kind": "instructionArgumentNode", + "name": "maximumPendingBalanceCreditCounter", + "docs": [ + "The maximum number of despots and transfers that an account can receiver", + "before the `ApplyPendingBalance` is executed" + ], + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "proofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::ZeroCiphertextProof`", + "instruction to the `ConfigureAccount` instruction in the", + "transaction. If the offset is `0`, then use a context state account", + "for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "approveConfidentialAccount", + "docs": [ + "Approves a token account for confidential transfers.", + "", + "Approval is only required when the", + "`ConfidentialTransferMint::approve_new_accounts` field is set in the", + "SPL Token mint. This instruction must be executed after the account", + "owner configures their account for confidential transfers with", + "`ConfidentialTransferInstruction::ConfigureAccount`." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account to approve."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": ["Confidential transfer mint authority."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 3 + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "emptyConfidentialAccount", + "docs": [ + "Empty the available balance in a confidential token account.", + "", + "A token account that is extended for confidential transfers can only be", + "closed if the pending and available balance ciphertexts are emptied.", + "The pending balance can be emptied", + "via the `ConfidentialTransferInstruction::ApplyPendingBalance`", + "instruction. Use the `ConfidentialTransferInstruction::EmptyAccount`", + "instruction to empty the available balance ciphertext.", + "", + "Note that a newly configured account is always empty, so this", + "instruction is not required prior to account closing if no", + "instructions beyond", + "`ConfidentialTransferInstruction::ConfigureAccount` have affected the", + "token account.", + "", + "In order for this instruction to be successfully processed, it must be", + "accompanied by the `VerifyZeroCiphertext` instruction of the", + "`zk_elgamal_proof` program in the same transaction or the address of a", + "context state account for the proof must be provided." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "instructionsSysvarOrContextState", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [ + "Instructions sysvar if `VerifyZeroCiphertext` is included in", + "the same transaction or context state account if", + "`VerifyZeroCiphertext` is pre-verified into a context state", + "account." + ], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "Sysvar1nstructions1111111111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "record", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Record account if the accompanying proof is to be read from a record account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 4 + } + }, + { + "kind": "instructionArgumentNode", + "name": "proofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::VerifyCloseAccount`", + "instruction to the `EmptyAccount` instruction in the transaction. If", + "the offset is `0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "confidentialDeposit", + "docs": [ + "Deposit SPL Tokens into the pending balance of a confidential token", + "account.", + "", + "The account owner can then invoke the `ApplyPendingBalance` instruction", + "to roll the deposit into their available balance at a time of their", + "choosing.", + "", + "Fails if the source or destination accounts are frozen.", + "Fails if the associated mint is extended as `NonTransferable`." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 5 + } + }, + { + "kind": "instructionArgumentNode", + "name": "amount", + "docs": ["The amount of tokens to deposit."], + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "decimals", + "docs": [ + "Expected number of base 10 digits to the right of the decimal place." + ], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "confidentialWithdraw", + "docs": [ + "Withdraw SPL Tokens from the available balance of a confidential token", + "account.", + "", + "In order for this instruction to be successfully processed, it must be", + "accompanied by the following list of `zk_elgamal_proof` program", + "instructions:", + "- `VerifyCiphertextCommitmentEquality`", + "- `VerifyBatchedRangeProofU64`", + "These instructions can be accompanied in the same transaction or can be", + "pre-verified into a context state account, in which case, only their", + "context state account address need to be provided.", + "", + "Fails if the source or destination accounts are frozen.", + "Fails if the associated mint is extended as `NonTransferable`." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "instructionsSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "Instructions sysvar if at least one of the", + "`zk_elgamal_proof` instructions are included in the same", + "transaction." + ] + }, + { + "kind": "instructionAccountNode", + "name": "equalityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Equality proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "rangeRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Range proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 6 + } + }, + { + "kind": "instructionArgumentNode", + "name": "amount", + "docs": ["The amount of tokens to withdraw."], + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "decimals", + "docs": [ + "Expected number of base 10 digits to the right of the decimal place." + ], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "newDecryptableAvailableBalance", + "docs": ["The new decryptable balance if the withdrawal succeeds."], + "type": { + "kind": "definedTypeLinkNode", + "name": "decryptableBalance" + } + }, + { + "kind": "instructionArgumentNode", + "name": "equalityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyCiphertextCommitmentEquality` instruction", + "to the `Withdraw` instruction in the transaction. If the offset is", + "`0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "rangeProofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::BatchedRangeProofU64`", + "instruction to the `Withdraw` instruction in the transaction. If the", + "offset is `0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "confidentialTransfer", + "docs": [ + "Transfer tokens confidentially.", + "", + "In order for this instruction to be successfully processed, it must be", + "accompanied by the following list of `zk_elgamal_proof` program", + "instructions:", + "- `VerifyCiphertextCommitmentEquality`", + "- `VerifyBatchedGroupedCiphertext3HandlesValidity`", + "- `VerifyBatchedRangeProofU128`", + "These instructions can be accompanied in the same transaction or can be", + "pre-verified into a context state account, in which case, only their", + "context state account addresses need to be provided.", + "", + "Fails if the associated mint is extended as `NonTransferable`." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "sourceToken", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The source SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "destinationToken", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The destination SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "instructionsSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Instructions sysvar if at least one of the", + "`zk_elgamal_proof` instructions are included in the same", + "transaction." + ] + }, + { + "kind": "instructionAccountNode", + "name": "equalityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Equality proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "ciphertextValidityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Ciphertext validity proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "rangeRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Range proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 7 + } + }, + { + "kind": "instructionArgumentNode", + "name": "newSourceDecryptableAvailableBalance", + "docs": [ + "The new source decryptable balance if the transfer succeeds." + ], + "type": { + "kind": "definedTypeLinkNode", + "name": "decryptableBalance" + } + }, + { + "kind": "instructionArgumentNode", + "name": "equalityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyCiphertextCommitmentEquality` instruction", + "to the `Transfer` instruction in the transaction. If the offset is", + "`0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "ciphertextValidityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity`", + "instruction to the `Transfer` instruction in the transaction. If the", + "offset is `0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "rangeProofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::BatchedRangeProofU128Data`", + "instruction to the `Transfer` instruction in the transaction. If the", + "offset is `0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "applyConfidentialPendingBalance", + "docs": [ + "Applies the pending balance to the available balance, based on the", + "history of `Deposit` and/or `Transfer` instructions.", + "", + "After submitting `ApplyPendingBalance`, the client should compare", + "`ConfidentialTransferAccount::expected_pending_balance_credit_counter`", + "with", + "`ConfidentialTransferAccount::actual_applied_pending_balance_instructions`. If they are", + "equal then the", + "`ConfidentialTransferAccount::decryptable_available_balance` is", + "consistent with `ConfidentialTransferAccount::available_balance`. If", + "they differ then there is more pending balance to be applied." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 8 + } + }, + { + "kind": "instructionArgumentNode", + "name": "expectedPendingBalanceCreditCounter", + "docs": [ + "The expected number of pending balance credits since the last successful", + "`ApplyPendingBalance` instruction" + ], + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "newDecryptableAvailableBalance", + "docs": [ + "The new decryptable balance if the pending balance is applied", + "successfully" + ], + "type": { + "kind": "definedTypeLinkNode", + "name": "decryptableBalance" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "enableConfidentialCredits", + "docs": [ + "Configure a confidential extension account to accept incoming", + "confidential transfers." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 9 + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "disableConfidentialCredits", + "docs": [ + "Configure a confidential extension account to reject any incoming", + "confidential transfers.", + "", + "If the `allow_non_confidential_credits` field is `true`, then the base", + "account can still receive non-confidential transfers.", + "", + "This instruction can be used to disable confidential payments after a", + "token account has already been extended for confidential transfers." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 10 + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "enableNonConfidentialCredits", + "docs": [ + "Configure an account with the confidential extension to accept incoming", + "non-confidential transfers." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 11 + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "disableNonConfidentialCredits", + "docs": [ + "Configure an account with the confidential extension to reject any", + "incoming non-confidential transfers.", + "", + "This instruction can be used to configure a confidential extension", + "account to exclusively receive confidential payments." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "token", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 12 + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "confidentialTransferWithFee", + "docs": [ + "Transfer tokens confidentially with fee.", + "", + "In order for this instruction to be successfully processed, it must be", + "accompanied by the following list of `zk_elgamal_proof` program", + "instructions:", + "- `VerifyCiphertextCommitmentEquality`", + "- `VerifyBatchedGroupedCiphertext3HandlesValidity` (transfer amount", + " ciphertext)", + "- `VerifyPercentageWithFee`", + "- `VerifyBatchedGroupedCiphertext2HandlesValidity` (fee ciphertext)", + "- `VerifyBatchedRangeProofU256`", + "These instructions can be accompanied in the same transaction or can be", + "pre-verified into a context state account, in which case, only their", + "context state account addresses need to be provided.", + "", + "The same restrictions for the `Transfer` applies to", + "`TransferWithFee`. Namely, the instruction fails if the", + "associated mint is extended as `NonTransferable`." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "sourceToken", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The source SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": ["The corresponding SPL Token mint."] + }, + { + "kind": "instructionAccountNode", + "name": "destinationToken", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The destination SPL Token account."] + }, + { + "kind": "instructionAccountNode", + "name": "instructionsSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Instructions sysvar if at least one of the", + "`zk_elgamal_proof` instructions are included in the same", + "transaction." + ] + }, + { + "kind": "instructionAccountNode", + "name": "equalityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Equality proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "transferAmountCiphertextValidityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Transfer amount ciphertext validity proof record", + "account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "feeSigmaRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Fee sigma proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "feeCiphertextValidityRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Fee ciphertext validity proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "rangeRecord", + "isWritable": false, + "isSigner": false, + "isOptional": true, + "docs": [ + "(Optional) Range proof record account or context state account." + ] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The source account's owner/delegate or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 27 + } + }, + { + "kind": "instructionArgumentNode", + "name": "confidentialTransferDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 13 + } + }, + { + "kind": "instructionArgumentNode", + "name": "newSourceDecryptableAvailableBalance", + "docs": [ + "The new source decryptable balance if the transfer succeeds." + ], + "type": { + "kind": "definedTypeLinkNode", + "name": "decryptableBalance" + } + }, + { + "kind": "instructionArgumentNode", + "name": "equalityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyCiphertextCommitmentEquality` instruction", + "to the `TransferWithFee` instruction in the transaction. If the offset", + "is `0`, then use a context state account for the proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "transferAmountCiphertextValidityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity`", + "instruction to the `TransferWithFee` instruction in the transaction.", + "If the offset is `0`, then use a context state account for the", + "proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "feeSigmaProofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::VerifyPercentageWithFee`", + "instruction to the `TransferWithFee` instruction in the transaction.", + "If the offset is `0`, then use a context state account for the", + "proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "feeCiphertextValidityProofInstructionOffset", + "docs": [ + "Relative location of the", + "`ProofInstruction::VerifyBatchedGroupedCiphertext2HandlesValidity`", + "instruction to the `TransferWithFee` instruction in the transaction.", + "If the offset is `0`, then use a context state account for the", + "proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "rangeProofInstructionOffset", + "docs": [ + "Relative location of the `ProofInstruction::BatchedRangeProofU256Data`", + "instruction to the `TransferWithFee` instruction in the transaction.", + "If the offset is `0`, then use a context state account for the", + "proof." + ], + "type": { + "kind": "numberTypeNode", + "format": "i8", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "confidentialTransferDiscriminator", + "offset": 1 + } + ] } ], "definedTypes": [