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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 65 additions & 17 deletions clients/js/src/generated/instructions/confidentialTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
import {
getDecryptableBalanceDecoder,
getDecryptableBalanceEncoder,
getEncryptedBalanceDecoder,
getEncryptedBalanceEncoder,
type DecryptableBalance,
type DecryptableBalanceArgs,
type EncryptedBalance,
type EncryptedBalanceArgs,
} from '../types';

export const CONFIDENTIAL_TRANSFER_DISCRIMINATOR = 27;
Expand All @@ -57,10 +61,10 @@ export type ConfidentialTransferInstruction<
TAccountSourceToken extends string | AccountMeta<string> = string,
TAccountMint extends string | AccountMeta<string> = string,
TAccountDestinationToken extends string | AccountMeta<string> = string,
TAccountInstructionsSysvar extends string | AccountMeta<string> = string,
TAccountEqualityRecord extends string | AccountMeta<string> = string,
TAccountCiphertextValidityRecord extends string | AccountMeta<string> = string,
TAccountRangeRecord extends string | AccountMeta<string> = string,
TAccountInstructionsSysvar extends string | AccountMeta<string> | undefined = undefined,
TAccountEqualityRecord extends string | AccountMeta<string> | undefined = undefined,
TAccountCiphertextValidityRecord extends string | AccountMeta<string> | undefined = undefined,
TAccountRangeRecord extends string | AccountMeta<string> | undefined = undefined,
TAccountAuthority extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
Expand All @@ -72,14 +76,30 @@ export type ConfidentialTransferInstruction<
TAccountDestinationToken extends string
? WritableAccount<TAccountDestinationToken>
: TAccountDestinationToken,
TAccountInstructionsSysvar extends string
? ReadonlyAccount<TAccountInstructionsSysvar>
: TAccountInstructionsSysvar,
TAccountEqualityRecord extends string ? ReadonlyAccount<TAccountEqualityRecord> : TAccountEqualityRecord,
TAccountCiphertextValidityRecord extends string
? ReadonlyAccount<TAccountCiphertextValidityRecord>
: TAccountCiphertextValidityRecord,
TAccountRangeRecord extends string ? ReadonlyAccount<TAccountRangeRecord> : TAccountRangeRecord,
...(TAccountInstructionsSysvar extends undefined
? []
: [
TAccountInstructionsSysvar extends string
? ReadonlyAccount<TAccountInstructionsSysvar>
: TAccountInstructionsSysvar,
]),
...(TAccountEqualityRecord extends undefined
? []
: [
TAccountEqualityRecord extends string
? ReadonlyAccount<TAccountEqualityRecord>
: TAccountEqualityRecord,
]),
...(TAccountCiphertextValidityRecord extends undefined
? []
: [
TAccountCiphertextValidityRecord extends string
? ReadonlyAccount<TAccountCiphertextValidityRecord>
: TAccountCiphertextValidityRecord,
]),
...(TAccountRangeRecord extends undefined
? []
: [TAccountRangeRecord extends string ? ReadonlyAccount<TAccountRangeRecord> : TAccountRangeRecord]),
TAccountAuthority extends string ? ReadonlyAccount<TAccountAuthority> : TAccountAuthority,
...TRemainingAccounts,
]
Expand All @@ -90,6 +110,16 @@ export type ConfidentialTransferInstructionData = {
confidentialTransferDiscriminator: number;
/** The new source decryptable balance if the transfer succeeds. */
newSourceDecryptableAvailableBalance: DecryptableBalance;
/**
* The low 16 bits of the transfer amount encrypted under the auditor
* ElGamal public key.
*/
transferAmountAuditorCiphertextLo: EncryptedBalance;
/**
* The high 32 bits of the transfer amount encrypted under the auditor
* ElGamal public key.
*/
transferAmountAuditorCiphertextHi: EncryptedBalance;
/**
* Relative location of the
* `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction
Expand All @@ -115,6 +145,16 @@ export type ConfidentialTransferInstructionData = {
export type ConfidentialTransferInstructionDataArgs = {
/** The new source decryptable balance if the transfer succeeds. */
newSourceDecryptableAvailableBalance: DecryptableBalanceArgs;
/**
* The low 16 bits of the transfer amount encrypted under the auditor
* ElGamal public key.
*/
transferAmountAuditorCiphertextLo: EncryptedBalanceArgs;
/**
* The high 32 bits of the transfer amount encrypted under the auditor
* ElGamal public key.
*/
transferAmountAuditorCiphertextHi: EncryptedBalanceArgs;
/**
* Relative location of the
* `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction
Expand Down Expand Up @@ -143,6 +183,8 @@ export function getConfidentialTransferInstructionDataEncoder(): FixedSizeEncode
['discriminator', getU8Encoder()],
['confidentialTransferDiscriminator', getU8Encoder()],
['newSourceDecryptableAvailableBalance', getDecryptableBalanceEncoder()],
['transferAmountAuditorCiphertextLo', getEncryptedBalanceEncoder()],
['transferAmountAuditorCiphertextHi', getEncryptedBalanceEncoder()],
['equalityProofInstructionOffset', getI8Encoder()],
['ciphertextValidityProofInstructionOffset', getI8Encoder()],
['rangeProofInstructionOffset', getI8Encoder()],
Expand All @@ -160,6 +202,8 @@ export function getConfidentialTransferInstructionDataDecoder(): FixedSizeDecode
['discriminator', getU8Decoder()],
['confidentialTransferDiscriminator', getU8Decoder()],
['newSourceDecryptableAvailableBalance', getDecryptableBalanceDecoder()],
['transferAmountAuditorCiphertextLo', getEncryptedBalanceDecoder()],
['transferAmountAuditorCiphertextHi', getEncryptedBalanceDecoder()],
['equalityProofInstructionOffset', getI8Decoder()],
['ciphertextValidityProofInstructionOffset', getI8Decoder()],
['rangeProofInstructionOffset', getI8Decoder()],
Expand Down Expand Up @@ -207,6 +251,8 @@ export type ConfidentialTransferInput<
/** The source account's owner/delegate or its multisignature account. */
authority: Address<TAccountAuthority> | TransactionSigner<TAccountAuthority>;
newSourceDecryptableAvailableBalance: ConfidentialTransferInstructionDataArgs['newSourceDecryptableAvailableBalance'];
transferAmountAuditorCiphertextLo: ConfidentialTransferInstructionDataArgs['transferAmountAuditorCiphertextLo'];
transferAmountAuditorCiphertextHi: ConfidentialTransferInstructionDataArgs['transferAmountAuditorCiphertextHi'];
equalityProofInstructionOffset: ConfidentialTransferInstructionDataArgs['equalityProofInstructionOffset'];
ciphertextValidityProofInstructionOffset: ConfidentialTransferInstructionDataArgs['ciphertextValidityProofInstructionOffset'];
rangeProofInstructionOffset: ConfidentialTransferInstructionDataArgs['rangeProofInstructionOffset'];
Expand Down Expand Up @@ -274,7 +320,7 @@ export function getConfidentialTransferInstruction<
signer,
}));

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
return Object.freeze({
accounts: [
getAccountMeta(accounts.sourceToken),
Expand All @@ -286,7 +332,7 @@ export function getConfidentialTransferInstruction<
getAccountMeta(accounts.rangeRecord),
getAccountMeta(accounts.authority),
...remainingAccounts,
],
].filter(<T>(x: T | undefined): x is T => x !== undefined),
data: getConfidentialTransferInstructionDataEncoder().encode(args as ConfidentialTransferInstructionDataArgs),
programAddress,
} as ConfidentialTransferInstruction<
Expand Down Expand Up @@ -342,7 +388,7 @@ export function parseConfidentialTransferInstruction<
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedConfidentialTransferInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 8) {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -352,9 +398,11 @@ export function parseConfidentialTransferInstruction<
accountIndex += 1;
return accountMeta;
};
let optionalAccountsRemaining = instruction.accounts.length - 4;
const getNextOptionalAccount = () => {
const accountMeta = getNextAccount();
return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS ? undefined : accountMeta;
if (optionalAccountsRemaining === 0) return undefined;
optionalAccountsRemaining -= 1;
return getNextAccount();
};
return {
programAddress: instruction.programAddress,
Expand Down
40 changes: 27 additions & 13 deletions clients/js/src/generated/instructions/confidentialWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export type ConfidentialWithdrawInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountToken extends string | AccountMeta<string> = string,
TAccountMint extends string | AccountMeta<string> = string,
TAccountInstructionsSysvar extends string | AccountMeta<string> = string,
TAccountEqualityRecord extends string | AccountMeta<string> = string,
TAccountRangeRecord extends string | AccountMeta<string> = string,
TAccountInstructionsSysvar extends string | AccountMeta<string> | undefined = undefined,
TAccountEqualityRecord extends string | AccountMeta<string> | undefined = undefined,
TAccountRangeRecord extends string | AccountMeta<string> | undefined = undefined,
TAccountAuthority extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
Expand All @@ -69,11 +69,23 @@ export type ConfidentialWithdrawInstruction<
[
TAccountToken extends string ? WritableAccount<TAccountToken> : TAccountToken,
TAccountMint extends string ? ReadonlyAccount<TAccountMint> : TAccountMint,
TAccountInstructionsSysvar extends string
? ReadonlyAccount<TAccountInstructionsSysvar>
: TAccountInstructionsSysvar,
TAccountEqualityRecord extends string ? ReadonlyAccount<TAccountEqualityRecord> : TAccountEqualityRecord,
TAccountRangeRecord extends string ? ReadonlyAccount<TAccountRangeRecord> : TAccountRangeRecord,
...(TAccountInstructionsSysvar extends undefined
? []
: [
TAccountInstructionsSysvar extends string
? ReadonlyAccount<TAccountInstructionsSysvar>
: TAccountInstructionsSysvar,
]),
...(TAccountEqualityRecord extends undefined
? []
: [
TAccountEqualityRecord extends string
? ReadonlyAccount<TAccountEqualityRecord>
: TAccountEqualityRecord,
]),
...(TAccountRangeRecord extends undefined
? []
: [TAccountRangeRecord extends string ? ReadonlyAccount<TAccountRangeRecord> : TAccountRangeRecord]),
TAccountAuthority extends string ? ReadonlyAccount<TAccountAuthority> : TAccountAuthority,
...TRemainingAccounts,
]
Expand Down Expand Up @@ -251,7 +263,7 @@ export function getConfidentialWithdrawInstruction<
signer,
}));

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
return Object.freeze({
accounts: [
getAccountMeta(accounts.token),
Expand All @@ -261,7 +273,7 @@ export function getConfidentialWithdrawInstruction<
getAccountMeta(accounts.rangeRecord),
getAccountMeta(accounts.authority),
...remainingAccounts,
],
].filter(<T>(x: T | undefined): x is T => x !== undefined),
data: getConfidentialWithdrawInstructionDataEncoder().encode(args as ConfidentialWithdrawInstructionDataArgs),
programAddress,
} as ConfidentialWithdrawInstruction<
Expand Down Expand Up @@ -311,7 +323,7 @@ export function parseConfidentialWithdrawInstruction<
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedConfidentialWithdrawInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 6) {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -321,9 +333,11 @@ export function parseConfidentialWithdrawInstruction<
accountIndex += 1;
return accountMeta;
};
let optionalAccountsRemaining = instruction.accounts.length - 3;
const getNextOptionalAccount = () => {
const accountMeta = getNextAccount();
return accountMeta.address === TOKEN_2022_PROGRAM_ADDRESS ? undefined : accountMeta;
if (optionalAccountsRemaining === 0) return undefined;
optionalAccountsRemaining -= 1;
return getNextAccount();
};
return {
programAddress: instruction.programAddress,
Expand Down
Loading