From bf0dcf171574d72a8e9ec580625d49b95254a0f5 Mon Sep 17 00:00:00 2001 From: Ilan Gitter <8359193+gitteri@users.noreply.github.com> Date: Thu, 19 Feb 2026 19:10:55 -0700 Subject: [PATCH] feat: commit Codama-generated TypeScript clients for escrow and withdraw programs Un-ignore the generated TS client directories so admin-ui and user-ui Docker builds can reference them. Also add .pnpm-store/ to gitignore. --- .gitignore | 5 + .../src/generated/accounts/allowedMint.ts | 112 ++++ .../src/generated/accounts/index.ts | 11 + .../src/generated/accounts/instance.ts | 144 ++++ .../src/generated/accounts/operator.ts | 109 +++ .../generated/errors/contraEscrowProgram.ts | 115 ++++ .../typescript/src/generated/errors/index.ts | 9 + .../clients/typescript/src/generated/index.ts | 14 + .../src/generated/instructions/addOperator.ts | 469 +++++++++++++ .../src/generated/instructions/allowMint.ts | 580 ++++++++++++++++ .../src/generated/instructions/blockMint.ts | 440 ++++++++++++ .../generated/instructions/createInstance.ts | 444 +++++++++++++ .../src/generated/instructions/deposit.ts | 625 +++++++++++++++++ .../src/generated/instructions/index.ts | 17 + .../generated/instructions/releaseFunds.ts | 629 ++++++++++++++++++ .../generated/instructions/removeOperator.ts | 440 ++++++++++++ .../generated/instructions/resetSmtRoot.ts | 380 +++++++++++ .../src/generated/instructions/setNewAdmin.ts | 264 ++++++++ .../src/generated/pdas/allowedMint.ts | 37 ++ .../src/generated/pdas/eventAuthority.ts | 26 + .../typescript/src/generated/pdas/index.ts | 12 + .../typescript/src/generated/pdas/instance.ts | 35 + .../typescript/src/generated/pdas/operator.ts | 37 ++ .../generated/programs/contraEscrowProgram.ts | 113 ++++ .../src/generated/programs/index.ts | 9 + .../typescript/src/generated/shared/index.ts | 164 +++++ .../src/generated/types/addOperatorEvent.ts | 55 ++ .../src/generated/types/allowMintEvent.ts | 55 ++ .../src/generated/types/blockMintEvent.ts | 52 ++ .../generated/types/createInstanceEvent.ts | 55 ++ .../src/generated/types/depositEvent.ts | 70 ++ .../typescript/src/generated/types/index.ts | 17 + .../src/generated/types/releaseFundsEvent.ts | 82 +++ .../generated/types/removeOperatorEvent.ts | 55 ++ .../src/generated/types/resetSmtRootEvent.ts | 55 ++ .../src/generated/types/setNewAdminEvent.ts | 58 ++ .../generated/errors/contraWithdrawProgram.ts | 63 ++ .../typescript/src/generated/errors/index.ts | 9 + .../clients/typescript/src/generated/index.ts | 12 + .../src/generated/instructions/index.ts | 9 + .../generated/instructions/withdrawFunds.ts | 394 +++++++++++ .../programs/contraWithdrawProgram.ts | 40 ++ .../src/generated/programs/index.ts | 9 + .../typescript/src/generated/shared/index.ts | 164 +++++ .../typescript/src/generated/types/index.ts | 9 + .../src/generated/types/withdrawFundsEvent.ts | 52 ++ 46 files changed, 6555 insertions(+) create mode 100644 contra-escrow-program/clients/typescript/src/generated/accounts/allowedMint.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/accounts/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/accounts/instance.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/accounts/operator.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/errors/contraEscrowProgram.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/errors/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/addOperator.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/allowMint.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/blockMint.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/createInstance.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/deposit.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/releaseFunds.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/removeOperator.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/resetSmtRoot.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/instructions/setNewAdmin.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/pdas/allowedMint.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/pdas/eventAuthority.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/pdas/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/pdas/instance.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/pdas/operator.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/programs/contraEscrowProgram.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/programs/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/shared/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/addOperatorEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/allowMintEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/blockMintEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/createInstanceEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/depositEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/index.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/releaseFundsEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/removeOperatorEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/resetSmtRootEvent.ts create mode 100644 contra-escrow-program/clients/typescript/src/generated/types/setNewAdminEvent.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/errors/contraWithdrawProgram.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/errors/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/instructions/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/instructions/withdrawFunds.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/programs/contraWithdrawProgram.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/programs/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/shared/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/types/index.ts create mode 100644 contra-withdraw-program/clients/typescript/src/generated/types/withdrawFundsEvent.ts diff --git a/.gitignore b/.gitignore index 2577dd9a..b7bc4d27 100644 --- a/.gitignore +++ b/.gitignore @@ -12,9 +12,14 @@ **/escrow-generated/ **/withdraw-generated/ +# Un-ignore TypeScript generated clients (needed for admin-ui Docker build) +!contra-escrow-program/clients/typescript/src/generated/ +!contra-withdraw-program/clients/typescript/src/generated/ + # Javascript / Typescript **/node_modules/ **/dist/ +.pnpm-store/ # AI .claude/ diff --git a/contra-escrow-program/clients/typescript/src/generated/accounts/allowedMint.ts b/contra-escrow-program/clients/typescript/src/generated/accounts/allowedMint.ts new file mode 100644 index 00000000..68ec1c1d --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/accounts/allowedMint.ts @@ -0,0 +1,112 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; + +export type AllowedMint = { discriminator: number; bump: number }; + +export type AllowedMintArgs = AllowedMint; + +export function getAllowedMintEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]); +} + +export function getAllowedMintDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getAllowedMintCodec(): FixedSizeCodec< + AllowedMintArgs, + AllowedMint +> { + return combineCodec(getAllowedMintEncoder(), getAllowedMintDecoder()); +} + +export function decodeAllowedMint( + encodedAccount: EncodedAccount +): Account; +export function decodeAllowedMint( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeAllowedMint( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getAllowedMintDecoder() + ); +} + +export async function fetchAllowedMint( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeAllowedMint(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeAllowedMint( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeAllowedMint(maybeAccount); +} + +export async function fetchAllAllowedMint( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeAllowedMint(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeAllowedMint( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeAllowedMint(maybeAccount)); +} + +export function getAllowedMintSize(): number { + return 2; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/accounts/index.ts b/contra-escrow-program/clients/typescript/src/generated/accounts/index.ts new file mode 100644 index 00000000..af51b956 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/accounts/index.ts @@ -0,0 +1,11 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './allowedMint'; +export * from './instance'; +export * from './operator'; diff --git a/contra-escrow-program/clients/typescript/src/generated/accounts/instance.ts b/contra-escrow-program/clients/typescript/src/generated/accounts/instance.ts new file mode 100644 index 00000000..a3606cc8 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/accounts/instance.ts @@ -0,0 +1,144 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, + type ReadonlyUint8Array, +} from '@solana/kit'; + +export type Instance = { + discriminator: number; + bump: number; + version: number; + instanceSeed: Address; + admin: Address; + withdrawalTransactionsRoot: ReadonlyUint8Array; + currentTreeIndex: bigint; +}; + +export type InstanceArgs = { + discriminator: number; + bump: number; + version: number; + instanceSeed: Address; + admin: Address; + withdrawalTransactionsRoot: ReadonlyUint8Array; + currentTreeIndex: number | bigint; +}; + +export function getInstanceEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ['version', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['admin', getAddressEncoder()], + ['withdrawalTransactionsRoot', fixEncoderSize(getBytesEncoder(), 32)], + ['currentTreeIndex', getU64Encoder()], + ]); +} + +export function getInstanceDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ['version', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['admin', getAddressDecoder()], + ['withdrawalTransactionsRoot', fixDecoderSize(getBytesDecoder(), 32)], + ['currentTreeIndex', getU64Decoder()], + ]); +} + +export function getInstanceCodec(): FixedSizeCodec { + return combineCodec(getInstanceEncoder(), getInstanceDecoder()); +} + +export function decodeInstance( + encodedAccount: EncodedAccount +): Account; +export function decodeInstance( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeInstance( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getInstanceDecoder() + ); +} + +export async function fetchInstance( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeInstance(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeInstance( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeInstance(maybeAccount); +} + +export async function fetchAllInstance( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeInstance(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeInstance( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeInstance(maybeAccount)); +} + +export function getInstanceSize(): number { + return 107; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/accounts/operator.ts b/contra-escrow-program/clients/typescript/src/generated/accounts/operator.ts new file mode 100644 index 00000000..e2266df2 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/accounts/operator.ts @@ -0,0 +1,109 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Account, + type Address, + type EncodedAccount, + type FetchAccountConfig, + type FetchAccountsConfig, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type MaybeAccount, + type MaybeEncodedAccount, +} from '@solana/kit'; + +export type Operator = { discriminator: number; bump: number }; + +export type OperatorArgs = Operator; + +export function getOperatorEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]); +} + +export function getOperatorDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getOperatorCodec(): FixedSizeCodec { + return combineCodec(getOperatorEncoder(), getOperatorDecoder()); +} + +export function decodeOperator( + encodedAccount: EncodedAccount +): Account; +export function decodeOperator( + encodedAccount: MaybeEncodedAccount +): MaybeAccount; +export function decodeOperator( + encodedAccount: EncodedAccount | MaybeEncodedAccount +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getOperatorDecoder() + ); +} + +export async function fetchOperator( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchMaybeOperator(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeOperator( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeOperator(maybeAccount); +} + +export async function fetchAllOperator( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchAllMaybeOperator(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeOperator( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeOperator(maybeAccount)); +} + +export function getOperatorSize(): number { + return 2; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/errors/contraEscrowProgram.ts b/contra-escrow-program/clients/typescript/src/generated/errors/contraEscrowProgram.ts new file mode 100644 index 00000000..45a09ce6 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/errors/contraEscrowProgram.ts @@ -0,0 +1,115 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + isProgramError, + type Address, + type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + type SolanaError, +} from '@solana/kit'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; + +/** InvalidEventAuthority: Invalid event authority provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY = 0x0; // 0 +/** InvalidAta: Invalid ATA provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ATA = 0x1; // 1 +/** InvalidMint: Invalid mint provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_MINT = 0x2; // 2 +/** InvalidInstanceId: Instance ID invalid or does not respect rules */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE_ID = 0x3; // 3 +/** InvalidInstance: Invalid instance provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE = 0x4; // 4 +/** InvalidAdmin: Invalid admin provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ADMIN = 0x5; // 5 +/** PermanentDelegateNotAllowed: Permanent delegate extension not allowed */ +export const CONTRA_ESCROW_PROGRAM_ERROR__PERMANENT_DELEGATE_NOT_ALLOWED = 0x6; // 6 +/** PausableMintNotAllowed: Pausable mint extension not allowed */ +export const CONTRA_ESCROW_PROGRAM_ERROR__PAUSABLE_MINT_NOT_ALLOWED = 0x7; // 7 +/** InvalidOperatorPda: Invalid operator PDA provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_OPERATOR_PDA = 0x8; // 8 +/** InvalidTokenAccount: Invalid token account provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TOKEN_ACCOUNT = 0x9; // 9 +/** InvalidEscrowBalance: Invalid escrow balance */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ESCROW_BALANCE = 0xa; // 10 +/** InvalidAllowedMint: Invalid allowed mint */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ALLOWED_MINT = 0xb; // 11 +/** InvalidSmtProof: Invalid SMT proof provided */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_SMT_PROOF = 0xc; // 12 +/** InvalidTransactionNonceForCurrentTreeIndex: Invalid transaction nonce for current tree index */ +export const CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TRANSACTION_NONCE_FOR_CURRENT_TREE_INDEX = 0xd; // 13 + +export type ContraEscrowProgramError = + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ADMIN + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ALLOWED_MINT + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ATA + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ESCROW_BALANCE + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE_ID + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_MINT + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_OPERATOR_PDA + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_SMT_PROOF + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TOKEN_ACCOUNT + | typeof CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TRANSACTION_NONCE_FOR_CURRENT_TREE_INDEX + | typeof CONTRA_ESCROW_PROGRAM_ERROR__PAUSABLE_MINT_NOT_ALLOWED + | typeof CONTRA_ESCROW_PROGRAM_ERROR__PERMANENT_DELEGATE_NOT_ALLOWED; + +let contraEscrowProgramErrorMessages: + | Record + | undefined; +if (process.env.NODE_ENV !== 'production') { + contraEscrowProgramErrorMessages = { + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ADMIN]: `Invalid admin provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ALLOWED_MINT]: `Invalid allowed mint`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ATA]: `Invalid ATA provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_ESCROW_BALANCE]: `Invalid escrow balance`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_EVENT_AUTHORITY]: `Invalid event authority provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE]: `Invalid instance provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_INSTANCE_ID]: `Instance ID invalid or does not respect rules`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_MINT]: `Invalid mint provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_OPERATOR_PDA]: `Invalid operator PDA provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_SMT_PROOF]: `Invalid SMT proof provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TOKEN_ACCOUNT]: `Invalid token account provided`, + [CONTRA_ESCROW_PROGRAM_ERROR__INVALID_TRANSACTION_NONCE_FOR_CURRENT_TREE_INDEX]: `Invalid transaction nonce for current tree index`, + [CONTRA_ESCROW_PROGRAM_ERROR__PAUSABLE_MINT_NOT_ALLOWED]: `Pausable mint extension not allowed`, + [CONTRA_ESCROW_PROGRAM_ERROR__PERMANENT_DELEGATE_NOT_ALLOWED]: `Permanent delegate extension not allowed`, + }; +} + +export function getContraEscrowProgramErrorMessage( + code: ContraEscrowProgramError +): string { + if (process.env.NODE_ENV !== 'production') { + return ( + contraEscrowProgramErrorMessages as Record< + ContraEscrowProgramError, + string + > + )[code]; + } + + return 'Error message not available in production bundles.'; +} + +export function isContraEscrowProgramError< + TProgramErrorCode extends ContraEscrowProgramError, +>( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + code + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/errors/index.ts b/contra-escrow-program/clients/typescript/src/generated/errors/index.ts new file mode 100644 index 00000000..9934d78e --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/errors/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './contraEscrowProgram'; diff --git a/contra-escrow-program/clients/typescript/src/generated/index.ts b/contra-escrow-program/clients/typescript/src/generated/index.ts new file mode 100644 index 00000000..157d6f19 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/index.ts @@ -0,0 +1,14 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './accounts'; +export * from './errors'; +export * from './instructions'; +export * from './pdas'; +export * from './programs'; +export * from './types'; diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/addOperator.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/addOperator.ts new file mode 100644 index 00000000..19565755 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/addOperator.ts @@ -0,0 +1,469 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ProgramDerivedAddress, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findOperatorPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + expectProgramDerivedAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const ADD_OPERATOR_DISCRIMINATOR = 3; + +export function getAddOperatorDiscriminatorBytes() { + return getU8Encoder().encode(ADD_OPERATOR_DISCRIMINATOR); +} + +export type AddOperatorInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAdmin extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountOperatorPda extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAdmin, + TAccountInstance extends string + ? ReadonlyAccount + : TAccountInstance, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountOperatorPda extends string + ? WritableAccount + : TAccountOperatorPda, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type AddOperatorInstructionData = { + discriminator: number; + bump: number; +}; + +export type AddOperatorInstructionDataArgs = { bump: number }; + +export function getAddOperatorInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: ADD_OPERATOR_DISCRIMINATOR }) + ); +} + +export function getAddOperatorInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getAddOperatorInstructionDataCodec(): FixedSizeCodec< + AddOperatorInstructionDataArgs, + AddOperatorInstructionData +> { + return combineCodec( + getAddOperatorInstructionDataEncoder(), + getAddOperatorInstructionDataDecoder() + ); +} + +export type AddOperatorAsyncInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountOperator extends string = string, + TAccountOperatorPda extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Operator public key to be added */ + operator: Address; + /** Operator PDA to be created */ + operatorPda?: ProgramDerivedAddress; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: AddOperatorInstructionDataArgs['bump']; +}; + +export async function getAddOperatorInstructionAsync< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountOperator extends string, + TAccountOperatorPda extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: AddOperatorAsyncInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + AddOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + operatorPda: { value: input.operatorPda ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.operatorPda.value) { + accounts.operatorPda.value = await findOperatorPda({ + instance: expectAddress(accounts.instance.value), + wallet: expectAddress(accounts.operator.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.operatorPda.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getAddOperatorInstructionDataEncoder().encode( + args as AddOperatorInstructionDataArgs + ), + programAddress, + } as AddOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type AddOperatorInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountOperator extends string = string, + TAccountOperatorPda extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Operator public key to be added */ + operator: Address; + /** Operator PDA to be created */ + operatorPda: ProgramDerivedAddress; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: AddOperatorInstructionDataArgs['bump']; +}; + +export function getAddOperatorInstruction< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountOperator extends string, + TAccountOperatorPda extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: AddOperatorInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): AddOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + operatorPda: { value: input.operatorPda ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.operatorPda.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getAddOperatorInstructionDataEncoder().encode( + args as AddOperatorInstructionDataArgs + ), + programAddress, + } as AddOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedAddOperatorInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Admin of Instance */ + admin: TAccountMetas[1]; + /** Instance PDA to validate admin authority */ + instance: TAccountMetas[2]; + /** Operator public key to be added */ + operator: TAccountMetas[3]; + /** Operator PDA to be created */ + operatorPda: TAccountMetas[4]; + /** System program */ + systemProgram: TAccountMetas[5]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[6]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[7]; + }; + data: AddOperatorInstructionData; +}; + +export function parseAddOperatorInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedAddOperatorInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + admin: getNextAccount(), + instance: getNextAccount(), + operator: getNextAccount(), + operatorPda: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getAddOperatorInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/allowMint.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/allowMint.ts new file mode 100644 index 00000000..e15823c7 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/allowMint.ts @@ -0,0 +1,580 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ProgramDerivedAddress, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findAllowedMintPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + expectProgramDerivedAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const ALLOW_MINT_DISCRIMINATOR = 1; + +export function getAllowMintDiscriminatorBytes() { + return getU8Encoder().encode(ALLOW_MINT_DISCRIMINATOR); +} + +export type AllowMintInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAdmin extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountAllowedMint extends string | AccountMeta = string, + TAccountInstanceAta extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountAssociatedTokenProgram extends + | string + | AccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAdmin, + TAccountInstance extends string + ? ReadonlyAccount + : TAccountInstance, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAllowedMint extends string + ? WritableAccount + : TAccountAllowedMint, + TAccountInstanceAta extends string + ? WritableAccount + : TAccountInstanceAta, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type AllowMintInstructionData = { discriminator: number; bump: number }; + +export type AllowMintInstructionDataArgs = { bump: number }; + +export function getAllowMintInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: ALLOW_MINT_DISCRIMINATOR }) + ); +} + +export function getAllowMintInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getAllowMintInstructionDataCodec(): FixedSizeCodec< + AllowMintInstructionDataArgs, + AllowMintInstructionData +> { + return combineCodec( + getAllowMintInstructionDataEncoder(), + getAllowMintInstructionDataDecoder() + ); +} + +export type AllowMintAsyncInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountInstanceAta extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Token mint to be allowed */ + mint: Address; + /** PDA of the Allowed Mint */ + allowedMint?: ProgramDerivedAddress; + /** Instance Escrow account for specified mint */ + instanceAta?: Address; + /** System program */ + systemProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: AllowMintInstructionDataArgs['bump']; +}; + +export async function getAllowMintInstructionAsync< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountInstanceAta extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: AllowMintAsyncInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + AllowMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.allowedMint.value) { + accounts.allowedMint.value = await findAllowedMintPda({ + instance: expectAddress(accounts.instance.value), + mint: expectAddress(accounts.mint.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.instanceAta.value) { + accounts.instanceAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.instance.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.allowedMint.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getAllowMintInstructionDataEncoder().encode( + args as AllowMintInstructionDataArgs + ), + programAddress, + } as AllowMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type AllowMintInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountInstanceAta extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Token mint to be allowed */ + mint: Address; + /** PDA of the Allowed Mint */ + allowedMint: ProgramDerivedAddress; + /** Instance Escrow account for specified mint */ + instanceAta: Address; + /** System program */ + systemProgram?: Address; + /** Token program */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: AllowMintInstructionDataArgs['bump']; +}; + +export function getAllowMintInstruction< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountInstanceAta extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: AllowMintInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): AllowMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.allowedMint.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getAllowMintInstructionDataEncoder().encode( + args as AllowMintInstructionDataArgs + ), + programAddress, + } as AllowMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedAllowMintInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Admin of Instance */ + admin: TAccountMetas[1]; + /** Instance PDA to validate admin authority */ + instance: TAccountMetas[2]; + /** Token mint to be allowed */ + mint: TAccountMetas[3]; + /** PDA of the Allowed Mint */ + allowedMint: TAccountMetas[4]; + /** Instance Escrow account for specified mint */ + instanceAta: TAccountMetas[5]; + /** System program */ + systemProgram: TAccountMetas[6]; + /** Token program */ + tokenProgram: TAccountMetas[7]; + /** Associated Token program */ + associatedTokenProgram: TAccountMetas[8]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[9]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[10]; + }; + data: AllowMintInstructionData; +}; + +export function parseAllowMintInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedAllowMintInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + admin: getNextAccount(), + instance: getNextAccount(), + mint: getNextAccount(), + allowedMint: getNextAccount(), + instanceAta: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getAllowMintInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/blockMint.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/blockMint.ts new file mode 100644 index 00000000..5bed925a --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/blockMint.ts @@ -0,0 +1,440 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findAllowedMintPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const BLOCK_MINT_DISCRIMINATOR = 2; + +export function getBlockMintDiscriminatorBytes() { + return getU8Encoder().encode(BLOCK_MINT_DISCRIMINATOR); +} + +export type BlockMintInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAdmin extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountAllowedMint extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAdmin, + TAccountInstance extends string + ? ReadonlyAccount + : TAccountInstance, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAllowedMint extends string + ? WritableAccount + : TAccountAllowedMint, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type BlockMintInstructionData = { discriminator: number }; + +export type BlockMintInstructionDataArgs = {}; + +export function getBlockMintInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: BLOCK_MINT_DISCRIMINATOR }) + ); +} + +export function getBlockMintInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getBlockMintInstructionDataCodec(): FixedSizeCodec< + BlockMintInstructionDataArgs, + BlockMintInstructionData +> { + return combineCodec( + getBlockMintInstructionDataEncoder(), + getBlockMintInstructionDataDecoder() + ); +} + +export type BlockMintAsyncInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Token mint to be blocked */ + mint: Address; + /** Existing Allowed Mint PDA */ + allowedMint?: Address; + /** System program for account creation */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export async function getBlockMintInstructionAsync< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: BlockMintAsyncInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + BlockMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.allowedMint.value) { + accounts.allowedMint.value = await findAllowedMintPda({ + instance: expectAddress(accounts.instance.value), + mint: expectAddress(accounts.mint.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getBlockMintInstructionDataEncoder().encode({}), + programAddress, + } as BlockMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type BlockMintInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Token mint to be blocked */ + mint: Address; + /** Existing Allowed Mint PDA */ + allowedMint: Address; + /** System program for account creation */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export function getBlockMintInstruction< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: BlockMintInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): BlockMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getBlockMintInstructionDataEncoder().encode({}), + programAddress, + } as BlockMintInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedBlockMintInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Admin of Instance */ + admin: TAccountMetas[1]; + /** Instance PDA to validate admin authority */ + instance: TAccountMetas[2]; + /** Token mint to be blocked */ + mint: TAccountMetas[3]; + /** Existing Allowed Mint PDA */ + allowedMint: TAccountMetas[4]; + /** System program for account creation */ + systemProgram: TAccountMetas[5]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[6]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[7]; + }; + data: BlockMintInstructionData; +}; + +export function parseBlockMintInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedBlockMintInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + admin: getNextAccount(), + instance: getNextAccount(), + mint: getNextAccount(), + allowedMint: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getBlockMintInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/createInstance.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/createInstance.ts new file mode 100644 index 00000000..b257d968 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/createInstance.ts @@ -0,0 +1,444 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ProgramDerivedAddress, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findInstancePda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + expectProgramDerivedAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const CREATE_INSTANCE_DISCRIMINATOR = 0; + +export function getCreateInstanceDiscriminatorBytes() { + return getU8Encoder().encode(CREATE_INSTANCE_DISCRIMINATOR); +} + +export type CreateInstanceInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAdmin extends string | AccountMeta = string, + TAccountInstanceSeed extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAdmin, + TAccountInstanceSeed extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountInstanceSeed, + TAccountInstance extends string + ? WritableAccount + : TAccountInstance, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type CreateInstanceInstructionData = { + discriminator: number; + bump: number; +}; + +export type CreateInstanceInstructionDataArgs = { bump: number }; + +export function getCreateInstanceInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['bump', getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: CREATE_INSTANCE_DISCRIMINATOR }) + ); +} + +export function getCreateInstanceInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['bump', getU8Decoder()], + ]); +} + +export function getCreateInstanceInstructionDataCodec(): FixedSizeCodec< + CreateInstanceInstructionDataArgs, + CreateInstanceInstructionData +> { + return combineCodec( + getCreateInstanceInstructionDataEncoder(), + getCreateInstanceInstructionDataDecoder() + ); +} + +export type CreateInstanceAsyncInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstanceSeed extends string = string, + TAccountInstance extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance seed signer for PDA derivation */ + instanceSeed: TransactionSigner; + /** Instance PDA to be created */ + instance?: ProgramDerivedAddress; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: CreateInstanceInstructionDataArgs['bump']; +}; + +export async function getCreateInstanceInstructionAsync< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstanceSeed extends string, + TAccountInstance extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: CreateInstanceAsyncInput< + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + CreateInstanceInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instanceSeed: { value: input.instanceSeed ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.instance.value) { + accounts.instance.value = await findInstancePda({ + instanceSeed: expectAddress(accounts.instanceSeed.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.instance.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instanceSeed), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getCreateInstanceInstructionDataEncoder().encode( + args as CreateInstanceInstructionDataArgs + ), + programAddress, + } as CreateInstanceInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type CreateInstanceInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstanceSeed extends string = string, + TAccountInstance extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance seed signer for PDA derivation */ + instanceSeed: TransactionSigner; + /** Instance PDA to be created */ + instance: ProgramDerivedAddress; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + bump?: CreateInstanceInstructionDataArgs['bump']; +}; + +export function getCreateInstanceInstruction< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstanceSeed extends string, + TAccountInstance extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: CreateInstanceInput< + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): CreateInstanceInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instanceSeed: { value: input.instanceSeed ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + if (!args.bump) { + args.bump = expectProgramDerivedAddress(accounts.instance.value)[1]; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instanceSeed), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getCreateInstanceInstructionDataEncoder().encode( + args as CreateInstanceInstructionDataArgs + ), + programAddress, + } as CreateInstanceInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstanceSeed, + TAccountInstance, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedCreateInstanceInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Admin of Instance */ + admin: TAccountMetas[1]; + /** Instance seed signer for PDA derivation */ + instanceSeed: TAccountMetas[2]; + /** Instance PDA to be created */ + instance: TAccountMetas[3]; + /** System program */ + systemProgram: TAccountMetas[4]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[5]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[6]; + }; + data: CreateInstanceInstructionData; +}; + +export function parseCreateInstanceInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedCreateInstanceInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + admin: getNextAccount(), + instanceSeed: getNextAccount(), + instance: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getCreateInstanceInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/deposit.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/deposit.ts new file mode 100644 index 00000000..1e970731 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/deposit.ts @@ -0,0 +1,625 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getOptionDecoder, + getOptionEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findAllowedMintPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const DEPOSIT_DISCRIMINATOR = 6; + +export function getDepositDiscriminatorBytes() { + return getU8Encoder().encode(DEPOSIT_DISCRIMINATOR); +} + +export type DepositInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountUser extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountAllowedMint extends string | AccountMeta = string, + TAccountUserAta extends string | AccountMeta = string, + TAccountInstanceAta extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountAssociatedTokenProgram extends + | string + | AccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountUser extends string + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountUser, + TAccountInstance extends string + ? ReadonlyAccount + : TAccountInstance, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAllowedMint extends string + ? ReadonlyAccount + : TAccountAllowedMint, + TAccountUserAta extends string + ? WritableAccount + : TAccountUserAta, + TAccountInstanceAta extends string + ? WritableAccount + : TAccountInstanceAta, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type DepositInstructionData = { + discriminator: number; + amount: bigint; + recipient: Option
; +}; + +export type DepositInstructionDataArgs = { + amount: number | bigint; + recipient: OptionOrNullable
; +}; + +export function getDepositInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['amount', getU64Encoder()], + ['recipient', getOptionEncoder(getAddressEncoder())], + ]), + (value) => ({ ...value, discriminator: DEPOSIT_DISCRIMINATOR }) + ); +} + +export function getDepositInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['amount', getU64Decoder()], + ['recipient', getOptionDecoder(getAddressDecoder())], + ]); +} + +export function getDepositInstructionDataCodec(): Codec< + DepositInstructionDataArgs, + DepositInstructionData +> { + return combineCodec( + getDepositInstructionDataEncoder(), + getDepositInstructionDataDecoder() + ); +} + +export type DepositAsyncInput< + TAccountPayer extends string = string, + TAccountUser extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountUserAta extends string = string, + TAccountInstanceAta extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** User depositing tokens */ + user: TransactionSigner; + /** Instance PDA to validate */ + instance: Address; + /** Token mint being deposited */ + mint: Address; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint?: Address; + /** User's Associated Token Account for this mint */ + userAta?: Address; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta?: Address; + /** System program */ + systemProgram?: Address; + /** Token program for the mint */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + amount: DepositInstructionDataArgs['amount']; + recipient: DepositInstructionDataArgs['recipient']; +}; + +export async function getDepositInstructionAsync< + TAccountPayer extends string, + TAccountUser extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountUserAta extends string, + TAccountInstanceAta extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: DepositAsyncInput< + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + DepositInstruction< + TProgramAddress, + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + user: { value: input.user ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: false }, + userAta: { value: input.userAta ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.allowedMint.value) { + accounts.allowedMint.value = await findAllowedMintPda({ + instance: expectAddress(accounts.instance.value), + mint: expectAddress(accounts.mint.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.userAta.value) { + accounts.userAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.user.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.instanceAta.value) { + accounts.instanceAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.instance.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.user), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getDepositInstructionDataEncoder().encode( + args as DepositInstructionDataArgs + ), + programAddress, + } as DepositInstruction< + TProgramAddress, + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type DepositInput< + TAccountPayer extends string = string, + TAccountUser extends string = string, + TAccountInstance extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountUserAta extends string = string, + TAccountInstanceAta extends string = string, + TAccountSystemProgram extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** User depositing tokens */ + user: TransactionSigner; + /** Instance PDA to validate */ + instance: Address; + /** Token mint being deposited */ + mint: Address; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint: Address; + /** User's Associated Token Account for this mint */ + userAta: Address; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta: Address; + /** System program */ + systemProgram?: Address; + /** Token program for the mint */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + amount: DepositInstructionDataArgs['amount']; + recipient: DepositInstructionDataArgs['recipient']; +}; + +export function getDepositInstruction< + TAccountPayer extends string, + TAccountUser extends string, + TAccountInstance extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountUserAta extends string, + TAccountInstanceAta extends string, + TAccountSystemProgram extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: DepositInput< + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): DepositInstruction< + TProgramAddress, + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + user: { value: input.user ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: false }, + userAta: { value: input.userAta ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.user), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getDepositInstructionDataEncoder().encode( + args as DepositInstructionDataArgs + ), + programAddress, + } as DepositInstruction< + TProgramAddress, + TAccountPayer, + TAccountUser, + TAccountInstance, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountSystemProgram, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedDepositInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** User depositing tokens */ + user: TAccountMetas[1]; + /** Instance PDA to validate */ + instance: TAccountMetas[2]; + /** Token mint being deposited */ + mint: TAccountMetas[3]; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint: TAccountMetas[4]; + /** User's Associated Token Account for this mint */ + userAta: TAccountMetas[5]; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta: TAccountMetas[6]; + /** System program */ + systemProgram: TAccountMetas[7]; + /** Token program for the mint */ + tokenProgram: TAccountMetas[8]; + /** Associated Token program */ + associatedTokenProgram: TAccountMetas[9]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[10]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[11]; + }; + data: DepositInstructionData; +}; + +export function parseDepositInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedDepositInstruction { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + user: getNextAccount(), + instance: getNextAccount(), + mint: getNextAccount(), + allowedMint: getNextAccount(), + userAta: getNextAccount(), + instanceAta: getNextAccount(), + systemProgram: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getDepositInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/index.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/index.ts new file mode 100644 index 00000000..e64d4f63 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/index.ts @@ -0,0 +1,17 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './addOperator'; +export * from './allowMint'; +export * from './blockMint'; +export * from './createInstance'; +export * from './deposit'; +export * from './releaseFunds'; +export * from './removeOperator'; +export * from './resetSmtRoot'; +export * from './setNewAdmin'; diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/releaseFunds.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/releaseFunds.ts new file mode 100644 index 00000000..e94ee4df --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/releaseFunds.ts @@ -0,0 +1,629 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findAllowedMintPda, findOperatorPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const RELEASE_FUNDS_DISCRIMINATOR = 7; + +export function getReleaseFundsDiscriminatorBytes() { + return getU8Encoder().encode(RELEASE_FUNDS_DISCRIMINATOR); +} + +export type ReleaseFundsInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountOperatorPda extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountAllowedMint extends string | AccountMeta = string, + TAccountUserAta extends string | AccountMeta = string, + TAccountInstanceAta extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountAssociatedTokenProgram extends + | string + | AccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountOperator extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperator, + TAccountInstance extends string + ? WritableAccount + : TAccountInstance, + TAccountOperatorPda extends string + ? ReadonlyAccount + : TAccountOperatorPda, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, + TAccountAllowedMint extends string + ? ReadonlyAccount + : TAccountAllowedMint, + TAccountUserAta extends string + ? WritableAccount + : TAccountUserAta, + TAccountInstanceAta extends string + ? WritableAccount + : TAccountInstanceAta, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type ReleaseFundsInstructionData = { + discriminator: number; + amount: bigint; + user: Address; + newWithdrawalRoot: ReadonlyUint8Array; + transactionNonce: bigint; + siblingProofs: ReadonlyUint8Array; +}; + +export type ReleaseFundsInstructionDataArgs = { + amount: number | bigint; + user: Address; + newWithdrawalRoot: ReadonlyUint8Array; + transactionNonce: number | bigint; + siblingProofs: ReadonlyUint8Array; +}; + +export function getReleaseFundsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['amount', getU64Encoder()], + ['user', getAddressEncoder()], + ['newWithdrawalRoot', fixEncoderSize(getBytesEncoder(), 32)], + ['transactionNonce', getU64Encoder()], + ['siblingProofs', fixEncoderSize(getBytesEncoder(), 512)], + ]), + (value) => ({ ...value, discriminator: RELEASE_FUNDS_DISCRIMINATOR }) + ); +} + +export function getReleaseFundsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['amount', getU64Decoder()], + ['user', getAddressDecoder()], + ['newWithdrawalRoot', fixDecoderSize(getBytesDecoder(), 32)], + ['transactionNonce', getU64Decoder()], + ['siblingProofs', fixDecoderSize(getBytesDecoder(), 512)], + ]); +} + +export function getReleaseFundsInstructionDataCodec(): FixedSizeCodec< + ReleaseFundsInstructionDataArgs, + ReleaseFundsInstructionData +> { + return combineCodec( + getReleaseFundsInstructionDataEncoder(), + getReleaseFundsInstructionDataDecoder() + ); +} + +export type ReleaseFundsAsyncInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountInstance extends string = string, + TAccountOperatorPda extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountUserAta extends string = string, + TAccountInstanceAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Operator releasing the funds */ + operator: TransactionSigner; + /** Instance PDA to validate and update */ + instance: Address; + /** Operator PDA to validate operator permissions */ + operatorPda?: Address; + /** Token mint being released */ + mint: Address; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint?: Address; + /** User's Associated Token Account for this mint */ + userAta: Address; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta?: Address; + /** Token program for the mint */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + amount: ReleaseFundsInstructionDataArgs['amount']; + user: ReleaseFundsInstructionDataArgs['user']; + newWithdrawalRoot: ReleaseFundsInstructionDataArgs['newWithdrawalRoot']; + transactionNonce: ReleaseFundsInstructionDataArgs['transactionNonce']; + siblingProofs: ReleaseFundsInstructionDataArgs['siblingProofs']; +}; + +export async function getReleaseFundsInstructionAsync< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountInstance extends string, + TAccountOperatorPda extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountUserAta extends string, + TAccountInstanceAta extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: ReleaseFundsAsyncInput< + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + ReleaseFundsInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + operatorPda: { value: input.operatorPda ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: false }, + userAta: { value: input.userAta ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.operatorPda.value) { + accounts.operatorPda.value = await findOperatorPda({ + instance: expectAddress(accounts.instance.value), + wallet: expectAddress(accounts.operator.value), + }); + } + if (!accounts.allowedMint.value) { + accounts.allowedMint.value = await findAllowedMintPda({ + instance: expectAddress(accounts.instance.value), + mint: expectAddress(accounts.mint.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.instanceAta.value) { + accounts.instanceAta.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.instance.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getReleaseFundsInstructionDataEncoder().encode( + args as ReleaseFundsInstructionDataArgs + ), + programAddress, + } as ReleaseFundsInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ReleaseFundsInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountInstance extends string = string, + TAccountOperatorPda extends string = string, + TAccountMint extends string = string, + TAccountAllowedMint extends string = string, + TAccountUserAta extends string = string, + TAccountInstanceAta extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Operator releasing the funds */ + operator: TransactionSigner; + /** Instance PDA to validate and update */ + instance: Address; + /** Operator PDA to validate operator permissions */ + operatorPda: Address; + /** Token mint being released */ + mint: Address; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint: Address; + /** User's Associated Token Account for this mint */ + userAta: Address; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta: Address; + /** Token program for the mint */ + tokenProgram?: Address; + /** Associated Token program */ + associatedTokenProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; + amount: ReleaseFundsInstructionDataArgs['amount']; + user: ReleaseFundsInstructionDataArgs['user']; + newWithdrawalRoot: ReleaseFundsInstructionDataArgs['newWithdrawalRoot']; + transactionNonce: ReleaseFundsInstructionDataArgs['transactionNonce']; + siblingProofs: ReleaseFundsInstructionDataArgs['siblingProofs']; +}; + +export function getReleaseFundsInstruction< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountInstance extends string, + TAccountOperatorPda extends string, + TAccountMint extends string, + TAccountAllowedMint extends string, + TAccountUserAta extends string, + TAccountInstanceAta extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: ReleaseFundsInput< + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): ReleaseFundsInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + operatorPda: { value: input.operatorPda ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: false }, + allowedMint: { value: input.allowedMint ?? null, isWritable: false }, + userAta: { value: input.userAta ?? null, isWritable: true }, + instanceAta: { value: input.instanceAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.allowedMint), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.instanceAta), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getReleaseFundsInstructionDataEncoder().encode( + args as ReleaseFundsInstructionDataArgs + ), + programAddress, + } as ReleaseFundsInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountMint, + TAccountAllowedMint, + TAccountUserAta, + TAccountInstanceAta, + TAccountTokenProgram, + TAccountAssociatedTokenProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedReleaseFundsInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Operator releasing the funds */ + operator: TAccountMetas[1]; + /** Instance PDA to validate and update */ + instance: TAccountMetas[2]; + /** Operator PDA to validate operator permissions */ + operatorPda: TAccountMetas[3]; + /** Token mint being released */ + mint: TAccountMetas[4]; + /** AllowedMint PDA to validate mint is allowed */ + allowedMint: TAccountMetas[5]; + /** User's Associated Token Account for this mint */ + userAta: TAccountMetas[6]; + /** Instance's Associated Token Account (escrow) for this mint */ + instanceAta: TAccountMetas[7]; + /** Token program for the mint */ + tokenProgram: TAccountMetas[8]; + /** Associated Token program */ + associatedTokenProgram: TAccountMetas[9]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[10]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[11]; + }; + data: ReleaseFundsInstructionData; +}; + +export function parseReleaseFundsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedReleaseFundsInstruction { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + operator: getNextAccount(), + instance: getNextAccount(), + operatorPda: getNextAccount(), + mint: getNextAccount(), + allowedMint: getNextAccount(), + userAta: getNextAccount(), + instanceAta: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getReleaseFundsInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/removeOperator.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/removeOperator.ts new file mode 100644 index 00000000..2df401ba --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/removeOperator.ts @@ -0,0 +1,440 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findOperatorPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const REMOVE_OPERATOR_DISCRIMINATOR = 4; + +export function getRemoveOperatorDiscriminatorBytes() { + return getU8Encoder().encode(REMOVE_OPERATOR_DISCRIMINATOR); +} + +export type RemoveOperatorInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountAdmin extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountOperatorPda extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = '11111111111111111111111111111111', + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountAdmin, + TAccountInstance extends string + ? ReadonlyAccount + : TAccountInstance, + TAccountOperator extends string + ? ReadonlyAccount + : TAccountOperator, + TAccountOperatorPda extends string + ? WritableAccount + : TAccountOperatorPda, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type RemoveOperatorInstructionData = { discriminator: number }; + +export type RemoveOperatorInstructionDataArgs = {}; + +export function getRemoveOperatorInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: REMOVE_OPERATOR_DISCRIMINATOR }) + ); +} + +export function getRemoveOperatorInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getRemoveOperatorInstructionDataCodec(): FixedSizeCodec< + RemoveOperatorInstructionDataArgs, + RemoveOperatorInstructionData +> { + return combineCodec( + getRemoveOperatorInstructionDataEncoder(), + getRemoveOperatorInstructionDataDecoder() + ); +} + +export type RemoveOperatorAsyncInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountOperator extends string = string, + TAccountOperatorPda extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Operator public key to be removed */ + operator: Address; + /** Existing Operator PDA */ + operatorPda?: Address; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export async function getRemoveOperatorInstructionAsync< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountOperator extends string, + TAccountOperatorPda extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: RemoveOperatorAsyncInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + RemoveOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + operatorPda: { value: input.operatorPda ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operatorPda.value) { + accounts.operatorPda.value = await findOperatorPda({ + instance: expectAddress(accounts.instance.value), + wallet: expectAddress(accounts.operator.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getRemoveOperatorInstructionDataEncoder().encode({}), + programAddress, + } as RemoveOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type RemoveOperatorInput< + TAccountPayer extends string = string, + TAccountAdmin extends string = string, + TAccountInstance extends string = string, + TAccountOperator extends string = string, + TAccountOperatorPda extends string = string, + TAccountSystemProgram extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Admin of Instance */ + admin: TransactionSigner; + /** Instance PDA to validate admin authority */ + instance: Address; + /** Operator public key to be removed */ + operator: Address; + /** Existing Operator PDA */ + operatorPda: Address; + /** System program */ + systemProgram?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export function getRemoveOperatorInstruction< + TAccountPayer extends string, + TAccountAdmin extends string, + TAccountInstance extends string, + TAccountOperator extends string, + TAccountOperatorPda extends string, + TAccountSystemProgram extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: RemoveOperatorInput< + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): RemoveOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + admin: { value: input.admin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: false }, + operator: { value: input.operator ?? null, isWritable: false }, + operatorPda: { value: input.operatorPda ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.admin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getRemoveOperatorInstructionDataEncoder().encode({}), + programAddress, + } as RemoveOperatorInstruction< + TProgramAddress, + TAccountPayer, + TAccountAdmin, + TAccountInstance, + TAccountOperator, + TAccountOperatorPda, + TAccountSystemProgram, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedRemoveOperatorInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Admin of Instance */ + admin: TAccountMetas[1]; + /** Instance PDA to validate admin authority */ + instance: TAccountMetas[2]; + /** Operator public key to be removed */ + operator: TAccountMetas[3]; + /** Existing Operator PDA */ + operatorPda: TAccountMetas[4]; + /** System program */ + systemProgram: TAccountMetas[5]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[6]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[7]; + }; + data: RemoveOperatorInstructionData; +}; + +export function parseRemoveOperatorInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedRemoveOperatorInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + admin: getNextAccount(), + instance: getNextAccount(), + operator: getNextAccount(), + operatorPda: getNextAccount(), + systemProgram: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getRemoveOperatorInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/resetSmtRoot.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/resetSmtRoot.ts new file mode 100644 index 00000000..1d03a9be --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/resetSmtRoot.ts @@ -0,0 +1,380 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { findOperatorPda } from '../pdas'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const RESET_SMT_ROOT_DISCRIMINATOR = 8; + +export function getResetSmtRootDiscriminatorBytes() { + return getU8Encoder().encode(RESET_SMT_ROOT_DISCRIMINATOR); +} + +export type ResetSmtRootInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountOperator extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountOperatorPda extends string | AccountMeta = string, + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountOperator extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOperator, + TAccountInstance extends string + ? WritableAccount + : TAccountInstance, + TAccountOperatorPda extends string + ? ReadonlyAccount + : TAccountOperatorPda, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type ResetSmtRootInstructionData = { discriminator: number }; + +export type ResetSmtRootInstructionDataArgs = {}; + +export function getResetSmtRootInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: RESET_SMT_ROOT_DISCRIMINATOR }) + ); +} + +export function getResetSmtRootInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getResetSmtRootInstructionDataCodec(): FixedSizeCodec< + ResetSmtRootInstructionDataArgs, + ResetSmtRootInstructionData +> { + return combineCodec( + getResetSmtRootInstructionDataEncoder(), + getResetSmtRootInstructionDataDecoder() + ); +} + +export type ResetSmtRootAsyncInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountInstance extends string = string, + TAccountOperatorPda extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Operator resetting the SMT root */ + operator: TransactionSigner; + /** Instance PDA to reset */ + instance: Address; + /** Operator PDA to validate operator permissions */ + operatorPda?: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export async function getResetSmtRootInstructionAsync< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountInstance extends string, + TAccountOperatorPda extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: ResetSmtRootAsyncInput< + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + ResetSmtRootInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + operatorPda: { value: input.operatorPda ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.operatorPda.value) { + accounts.operatorPda.value = await findOperatorPda({ + instance: expectAddress(accounts.instance.value), + wallet: expectAddress(accounts.operator.value), + }); + } + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getResetSmtRootInstructionDataEncoder().encode({}), + programAddress, + } as ResetSmtRootInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ResetSmtRootInput< + TAccountPayer extends string = string, + TAccountOperator extends string = string, + TAccountInstance extends string = string, + TAccountOperatorPda extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Operator resetting the SMT root */ + operator: TransactionSigner; + /** Instance PDA to reset */ + instance: Address; + /** Operator PDA to validate operator permissions */ + operatorPda: Address; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export function getResetSmtRootInstruction< + TAccountPayer extends string, + TAccountOperator extends string, + TAccountInstance extends string, + TAccountOperatorPda extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: ResetSmtRootInput< + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): ResetSmtRootInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + operator: { value: input.operator ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + operatorPda: { value: input.operatorPda ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.operator), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.operatorPda), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getResetSmtRootInstructionDataEncoder().encode({}), + programAddress, + } as ResetSmtRootInstruction< + TProgramAddress, + TAccountPayer, + TAccountOperator, + TAccountInstance, + TAccountOperatorPda, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedResetSmtRootInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Operator resetting the SMT root */ + operator: TAccountMetas[1]; + /** Instance PDA to reset */ + instance: TAccountMetas[2]; + /** Operator PDA to validate operator permissions */ + operatorPda: TAccountMetas[3]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[4]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[5]; + }; + data: ResetSmtRootInstructionData; +}; + +export function parseResetSmtRootInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedResetSmtRootInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + operator: getNextAccount(), + instance: getNextAccount(), + operatorPda: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getResetSmtRootInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/instructions/setNewAdmin.ts b/contra-escrow-program/clients/typescript/src/generated/instructions/setNewAdmin.ts new file mode 100644 index 00000000..e48e0bf7 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/instructions/setNewAdmin.ts @@ -0,0 +1,264 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const SET_NEW_ADMIN_DISCRIMINATOR = 5; + +export function getSetNewAdminDiscriminatorBytes() { + return getU8Encoder().encode(SET_NEW_ADMIN_DISCRIMINATOR); +} + +export type SetNewAdminInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountCurrentAdmin extends string | AccountMeta = string, + TAccountInstance extends string | AccountMeta = string, + TAccountNewAdmin extends string | AccountMeta = string, + TAccountEventAuthority extends + | string + | AccountMeta = 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm', + TAccountContraEscrowProgram extends + | string + | AccountMeta = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountCurrentAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountCurrentAdmin, + TAccountInstance extends string + ? WritableAccount + : TAccountInstance, + TAccountNewAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountNewAdmin, + TAccountEventAuthority extends string + ? ReadonlyAccount + : TAccountEventAuthority, + TAccountContraEscrowProgram extends string + ? ReadonlyAccount + : TAccountContraEscrowProgram, + ...TRemainingAccounts, + ] + >; + +export type SetNewAdminInstructionData = { discriminator: number }; + +export type SetNewAdminInstructionDataArgs = {}; + +export function getSetNewAdminInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([['discriminator', getU8Encoder()]]), + (value) => ({ ...value, discriminator: SET_NEW_ADMIN_DISCRIMINATOR }) + ); +} + +export function getSetNewAdminInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([['discriminator', getU8Decoder()]]); +} + +export function getSetNewAdminInstructionDataCodec(): FixedSizeCodec< + SetNewAdminInstructionDataArgs, + SetNewAdminInstructionData +> { + return combineCodec( + getSetNewAdminInstructionDataEncoder(), + getSetNewAdminInstructionDataDecoder() + ); +} + +export type SetNewAdminInput< + TAccountPayer extends string = string, + TAccountCurrentAdmin extends string = string, + TAccountInstance extends string = string, + TAccountNewAdmin extends string = string, + TAccountEventAuthority extends string = string, + TAccountContraEscrowProgram extends string = string, +> = { + /** Transaction fee payer */ + payer: TransactionSigner; + /** Current admin of Instance */ + currentAdmin: TransactionSigner; + /** Instance PDA to update admin */ + instance: Address; + /** New admin public key */ + newAdmin: TransactionSigner; + /** Event authority PDA for emitting events */ + eventAuthority?: Address; + /** Current program for CPI */ + contraEscrowProgram?: Address; +}; + +export function getSetNewAdminInstruction< + TAccountPayer extends string, + TAccountCurrentAdmin extends string, + TAccountInstance extends string, + TAccountNewAdmin extends string, + TAccountEventAuthority extends string, + TAccountContraEscrowProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, +>( + input: SetNewAdminInput< + TAccountPayer, + TAccountCurrentAdmin, + TAccountInstance, + TAccountNewAdmin, + TAccountEventAuthority, + TAccountContraEscrowProgram + >, + config?: { programAddress?: TProgramAddress } +): SetNewAdminInstruction< + TProgramAddress, + TAccountPayer, + TAccountCurrentAdmin, + TAccountInstance, + TAccountNewAdmin, + TAccountEventAuthority, + TAccountContraEscrowProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + currentAdmin: { value: input.currentAdmin ?? null, isWritable: false }, + instance: { value: input.instance ?? null, isWritable: true }, + newAdmin: { value: input.newAdmin ?? null, isWritable: false }, + eventAuthority: { value: input.eventAuthority ?? null, isWritable: false }, + contraEscrowProgram: { + value: input.contraEscrowProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.eventAuthority.value) { + accounts.eventAuthority.value = + 'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm' as Address<'G9CCHrvvmKuoM9vqcEWCxmbFiyJqXTLJBJjpSFv5v3Fm'>; + } + if (!accounts.contraEscrowProgram.value) { + accounts.contraEscrowProgram.value = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.currentAdmin), + getAccountMeta(accounts.instance), + getAccountMeta(accounts.newAdmin), + getAccountMeta(accounts.eventAuthority), + getAccountMeta(accounts.contraEscrowProgram), + ], + data: getSetNewAdminInstructionDataEncoder().encode({}), + programAddress, + } as SetNewAdminInstruction< + TProgramAddress, + TAccountPayer, + TAccountCurrentAdmin, + TAccountInstance, + TAccountNewAdmin, + TAccountEventAuthority, + TAccountContraEscrowProgram + >); +} + +export type ParsedSetNewAdminInstruction< + TProgram extends string = typeof CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** Transaction fee payer */ + payer: TAccountMetas[0]; + /** Current admin of Instance */ + currentAdmin: TAccountMetas[1]; + /** Instance PDA to update admin */ + instance: TAccountMetas[2]; + /** New admin public key */ + newAdmin: TAccountMetas[3]; + /** Event authority PDA for emitting events */ + eventAuthority: TAccountMetas[4]; + /** Current program for CPI */ + contraEscrowProgram: TAccountMetas[5]; + }; + data: SetNewAdminInstructionData; +}; + +export function parseSetNewAdminInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedSetNewAdminInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + currentAdmin: getNextAccount(), + instance: getNextAccount(), + newAdmin: getNextAccount(), + eventAuthority: getNextAccount(), + contraEscrowProgram: getNextAccount(), + }, + data: getSetNewAdminInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-escrow-program/clients/typescript/src/generated/pdas/allowedMint.ts b/contra-escrow-program/clients/typescript/src/generated/pdas/allowedMint.ts new file mode 100644 index 00000000..0d7b00b3 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/pdas/allowedMint.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type AllowedMintSeeds = { + instance: Address; + mint: Address; +}; + +export async function findAllowedMintPda( + seeds: AllowedMintSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('allowed_mint'), + getAddressEncoder().encode(seeds.instance), + getAddressEncoder().encode(seeds.mint), + ], + }); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/pdas/eventAuthority.ts b/contra-escrow-program/clients/typescript/src/generated/pdas/eventAuthority.ts new file mode 100644 index 00000000..318118d6 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/pdas/eventAuthority.ts @@ -0,0 +1,26 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export async function findEventAuthorityPda( + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [getUtf8Encoder().encode('event_authority')], + }); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/pdas/index.ts b/contra-escrow-program/clients/typescript/src/generated/pdas/index.ts new file mode 100644 index 00000000..87e9eabd --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/pdas/index.ts @@ -0,0 +1,12 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './allowedMint'; +export * from './eventAuthority'; +export * from './instance'; +export * from './operator'; diff --git a/contra-escrow-program/clients/typescript/src/generated/pdas/instance.ts b/contra-escrow-program/clients/typescript/src/generated/pdas/instance.ts new file mode 100644 index 00000000..4926ff62 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/pdas/instance.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type InstanceSeeds = { + instanceSeed: Address; +}; + +export async function findInstancePda( + seeds: InstanceSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('instance'), + getAddressEncoder().encode(seeds.instanceSeed), + ], + }); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/pdas/operator.ts b/contra-escrow-program/clients/typescript/src/generated/pdas/operator.ts new file mode 100644 index 00000000..b9230719 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/pdas/operator.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, + type Address, + type ProgramDerivedAddress, +} from '@solana/kit'; + +export type OperatorSeeds = { + instance: Address; + wallet: Address; +}; + +export async function findOperatorPda( + seeds: OperatorSeeds, + config: { programAddress?: Address | undefined } = {} +): Promise { + const { + programAddress = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode('operator'), + getAddressEncoder().encode(seeds.instance), + getAddressEncoder().encode(seeds.wallet), + ], + }); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/programs/contraEscrowProgram.ts b/contra-escrow-program/clients/typescript/src/generated/programs/contraEscrowProgram.ts new file mode 100644 index 00000000..33aeb3bd --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/programs/contraEscrowProgram.ts @@ -0,0 +1,113 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + containsBytes, + getU8Encoder, + type Address, + type ReadonlyUint8Array, +} from '@solana/kit'; +import { + type ParsedAddOperatorInstruction, + type ParsedAllowMintInstruction, + type ParsedBlockMintInstruction, + type ParsedCreateInstanceInstruction, + type ParsedDepositInstruction, + type ParsedReleaseFundsInstruction, + type ParsedRemoveOperatorInstruction, + type ParsedResetSmtRootInstruction, + type ParsedSetNewAdminInstruction, +} from '../instructions'; + +export const CONTRA_ESCROW_PROGRAM_PROGRAM_ADDRESS = + 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83' as Address<'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83'>; + +export enum ContraEscrowProgramAccount { + AllowedMint, + Instance, + Operator, +} + +export enum ContraEscrowProgramInstruction { + CreateInstance, + AllowMint, + BlockMint, + AddOperator, + RemoveOperator, + SetNewAdmin, + Deposit, + ReleaseFunds, + ResetSmtRoot, +} + +export function identifyContraEscrowProgramInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array +): ContraEscrowProgramInstruction { + const data = 'data' in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return ContraEscrowProgramInstruction.CreateInstance; + } + if (containsBytes(data, getU8Encoder().encode(1), 0)) { + return ContraEscrowProgramInstruction.AllowMint; + } + if (containsBytes(data, getU8Encoder().encode(2), 0)) { + return ContraEscrowProgramInstruction.BlockMint; + } + if (containsBytes(data, getU8Encoder().encode(3), 0)) { + return ContraEscrowProgramInstruction.AddOperator; + } + if (containsBytes(data, getU8Encoder().encode(4), 0)) { + return ContraEscrowProgramInstruction.RemoveOperator; + } + if (containsBytes(data, getU8Encoder().encode(5), 0)) { + return ContraEscrowProgramInstruction.SetNewAdmin; + } + if (containsBytes(data, getU8Encoder().encode(6), 0)) { + return ContraEscrowProgramInstruction.Deposit; + } + if (containsBytes(data, getU8Encoder().encode(7), 0)) { + return ContraEscrowProgramInstruction.ReleaseFunds; + } + if (containsBytes(data, getU8Encoder().encode(8), 0)) { + return ContraEscrowProgramInstruction.ResetSmtRoot; + } + throw new Error( + 'The provided instruction could not be identified as a contraEscrowProgram instruction.' + ); +} + +export type ParsedContraEscrowProgramInstruction< + TProgram extends string = 'GokvZqD2yP696rzNBNbQvcZ4VsLW7jNvFXU1kW9m7k83', +> = + | ({ + instructionType: ContraEscrowProgramInstruction.CreateInstance; + } & ParsedCreateInstanceInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.AllowMint; + } & ParsedAllowMintInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.BlockMint; + } & ParsedBlockMintInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.AddOperator; + } & ParsedAddOperatorInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.RemoveOperator; + } & ParsedRemoveOperatorInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.SetNewAdmin; + } & ParsedSetNewAdminInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.Deposit; + } & ParsedDepositInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.ReleaseFunds; + } & ParsedReleaseFundsInstruction) + | ({ + instructionType: ContraEscrowProgramInstruction.ResetSmtRoot; + } & ParsedResetSmtRootInstruction); diff --git a/contra-escrow-program/clients/typescript/src/generated/programs/index.ts b/contra-escrow-program/clients/typescript/src/generated/programs/index.ts new file mode 100644 index 00000000..9934d78e --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/programs/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './contraEscrowProgram'; diff --git a/contra-escrow-program/clients/typescript/src/generated/shared/index.ts b/contra-escrow-program/clients/typescript/src/generated/shared/index.ts new file mode 100644 index 00000000..83a31834 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/shared/index.ts @@ -0,0 +1,164 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + type AccountMeta, + type AccountSignerMeta, + type Address, + type ProgramDerivedAddress, + type TransactionSigner, + upgradeRoleToSigner, +} from '@solana/kit'; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error('Expected a value but received null or undefined.'); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): Address { + if (!value) { + throw new Error('Expected a Address.'); + } + if (typeof value === 'object' && 'address' in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): ProgramDerivedAddress { + if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) { + throw new Error('Expected a ProgramDerivedAddress.'); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): TransactionSigner { + if (!value || !isTransactionSigner(value)) { + throw new Error('Expected a TransactionSigner.'); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export type ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> = { + isWritable: boolean; + value: U; +}; + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export type InstructionWithByteDelta = { + byteDelta: number; +}; + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: 'omitted' | 'programId' +) { + return ( + account: ResolvedAccount + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === 'omitted') return; + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner +): value is TransactionSigner { + return ( + !!value && + typeof value === 'object' && + 'address' in value && + kitIsTransactionSigner(value) + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/addOperatorEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/addOperatorEvent.ts new file mode 100644 index 00000000..b7f3d806 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/addOperatorEvent.ts @@ -0,0 +1,55 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type AddOperatorEvent = { + eventDiscriminator: number; + instanceSeed: Address; + operator: Address; +}; + +export type AddOperatorEventArgs = AddOperatorEvent; + +export function getAddOperatorEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['operator', getAddressEncoder()], + ]); +} + +export function getAddOperatorEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['operator', getAddressDecoder()], + ]); +} + +export function getAddOperatorEventCodec(): FixedSizeCodec< + AddOperatorEventArgs, + AddOperatorEvent +> { + return combineCodec( + getAddOperatorEventEncoder(), + getAddOperatorEventDecoder() + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/allowMintEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/allowMintEvent.ts new file mode 100644 index 00000000..d44b5851 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/allowMintEvent.ts @@ -0,0 +1,55 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type AllowMintEvent = { + eventDiscriminator: number; + instanceSeed: Address; + mint: Address; + decimals: number; +}; + +export type AllowMintEventArgs = AllowMintEvent; + +export function getAllowMintEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['mint', getAddressEncoder()], + ['decimals', getU8Encoder()], + ]); +} + +export function getAllowMintEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['mint', getAddressDecoder()], + ['decimals', getU8Decoder()], + ]); +} + +export function getAllowMintEventCodec(): FixedSizeCodec< + AllowMintEventArgs, + AllowMintEvent +> { + return combineCodec(getAllowMintEventEncoder(), getAllowMintEventDecoder()); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/blockMintEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/blockMintEvent.ts new file mode 100644 index 00000000..3d5b9e08 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/blockMintEvent.ts @@ -0,0 +1,52 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type BlockMintEvent = { + eventDiscriminator: number; + instanceSeed: Address; + mint: Address; +}; + +export type BlockMintEventArgs = BlockMintEvent; + +export function getBlockMintEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['mint', getAddressEncoder()], + ]); +} + +export function getBlockMintEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['mint', getAddressDecoder()], + ]); +} + +export function getBlockMintEventCodec(): FixedSizeCodec< + BlockMintEventArgs, + BlockMintEvent +> { + return combineCodec(getBlockMintEventEncoder(), getBlockMintEventDecoder()); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/createInstanceEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/createInstanceEvent.ts new file mode 100644 index 00000000..1342f3a5 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/createInstanceEvent.ts @@ -0,0 +1,55 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type CreateInstanceEvent = { + eventDiscriminator: number; + instanceSeed: Address; + admin: Address; +}; + +export type CreateInstanceEventArgs = CreateInstanceEvent; + +export function getCreateInstanceEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['admin', getAddressEncoder()], + ]); +} + +export function getCreateInstanceEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['admin', getAddressDecoder()], + ]); +} + +export function getCreateInstanceEventCodec(): FixedSizeCodec< + CreateInstanceEventArgs, + CreateInstanceEvent +> { + return combineCodec( + getCreateInstanceEventEncoder(), + getCreateInstanceEventDecoder() + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/depositEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/depositEvent.ts new file mode 100644 index 00000000..88168e50 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/depositEvent.ts @@ -0,0 +1,70 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type DepositEvent = { + eventDiscriminator: number; + instanceSeed: Address; + user: Address; + amount: bigint; + recipient: Address; + mint: Address; +}; + +export type DepositEventArgs = { + eventDiscriminator: number; + instanceSeed: Address; + user: Address; + amount: number | bigint; + recipient: Address; + mint: Address; +}; + +export function getDepositEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['user', getAddressEncoder()], + ['amount', getU64Encoder()], + ['recipient', getAddressEncoder()], + ['mint', getAddressEncoder()], + ]); +} + +export function getDepositEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['user', getAddressDecoder()], + ['amount', getU64Decoder()], + ['recipient', getAddressDecoder()], + ['mint', getAddressDecoder()], + ]); +} + +export function getDepositEventCodec(): FixedSizeCodec< + DepositEventArgs, + DepositEvent +> { + return combineCodec(getDepositEventEncoder(), getDepositEventDecoder()); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/index.ts b/contra-escrow-program/clients/typescript/src/generated/types/index.ts new file mode 100644 index 00000000..39c6d17b --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/index.ts @@ -0,0 +1,17 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './addOperatorEvent'; +export * from './allowMintEvent'; +export * from './blockMintEvent'; +export * from './createInstanceEvent'; +export * from './depositEvent'; +export * from './releaseFundsEvent'; +export * from './removeOperatorEvent'; +export * from './resetSmtRootEvent'; +export * from './setNewAdminEvent'; diff --git a/contra-escrow-program/clients/typescript/src/generated/types/releaseFundsEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/releaseFundsEvent.ts new file mode 100644 index 00000000..abe246b7 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/releaseFundsEvent.ts @@ -0,0 +1,82 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type ReadonlyUint8Array, +} from '@solana/kit'; + +export type ReleaseFundsEvent = { + eventDiscriminator: number; + instanceSeed: Address; + operator: Address; + amount: bigint; + user: Address; + mint: Address; + newWithdrawalRoot: ReadonlyUint8Array; +}; + +export type ReleaseFundsEventArgs = { + eventDiscriminator: number; + instanceSeed: Address; + operator: Address; + amount: number | bigint; + user: Address; + mint: Address; + newWithdrawalRoot: ReadonlyUint8Array; +}; + +export function getReleaseFundsEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['operator', getAddressEncoder()], + ['amount', getU64Encoder()], + ['user', getAddressEncoder()], + ['mint', getAddressEncoder()], + ['newWithdrawalRoot', fixEncoderSize(getBytesEncoder(), 32)], + ]); +} + +export function getReleaseFundsEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['operator', getAddressDecoder()], + ['amount', getU64Decoder()], + ['user', getAddressDecoder()], + ['mint', getAddressDecoder()], + ['newWithdrawalRoot', fixDecoderSize(getBytesDecoder(), 32)], + ]); +} + +export function getReleaseFundsEventCodec(): FixedSizeCodec< + ReleaseFundsEventArgs, + ReleaseFundsEvent +> { + return combineCodec( + getReleaseFundsEventEncoder(), + getReleaseFundsEventDecoder() + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/removeOperatorEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/removeOperatorEvent.ts new file mode 100644 index 00000000..ad8b8418 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/removeOperatorEvent.ts @@ -0,0 +1,55 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type RemoveOperatorEvent = { + eventDiscriminator: number; + instanceSeed: Address; + operator: Address; +}; + +export type RemoveOperatorEventArgs = RemoveOperatorEvent; + +export function getRemoveOperatorEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['operator', getAddressEncoder()], + ]); +} + +export function getRemoveOperatorEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['operator', getAddressDecoder()], + ]); +} + +export function getRemoveOperatorEventCodec(): FixedSizeCodec< + RemoveOperatorEventArgs, + RemoveOperatorEvent +> { + return combineCodec( + getRemoveOperatorEventEncoder(), + getRemoveOperatorEventDecoder() + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/resetSmtRootEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/resetSmtRootEvent.ts new file mode 100644 index 00000000..ddeffd96 --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/resetSmtRootEvent.ts @@ -0,0 +1,55 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type ResetSmtRootEvent = { + eventDiscriminator: number; + instanceSeed: Address; + operator: Address; +}; + +export type ResetSmtRootEventArgs = ResetSmtRootEvent; + +export function getResetSmtRootEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['operator', getAddressEncoder()], + ]); +} + +export function getResetSmtRootEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['operator', getAddressDecoder()], + ]); +} + +export function getResetSmtRootEventCodec(): FixedSizeCodec< + ResetSmtRootEventArgs, + ResetSmtRootEvent +> { + return combineCodec( + getResetSmtRootEventEncoder(), + getResetSmtRootEventDecoder() + ); +} diff --git a/contra-escrow-program/clients/typescript/src/generated/types/setNewAdminEvent.ts b/contra-escrow-program/clients/typescript/src/generated/types/setNewAdminEvent.ts new file mode 100644 index 00000000..4cf71d4d --- /dev/null +++ b/contra-escrow-program/clients/typescript/src/generated/types/setNewAdminEvent.ts @@ -0,0 +1,58 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type SetNewAdminEvent = { + eventDiscriminator: number; + instanceSeed: Address; + oldAdmin: Address; + newAdmin: Address; +}; + +export type SetNewAdminEventArgs = SetNewAdminEvent; + +export function getSetNewAdminEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['eventDiscriminator', getU8Encoder()], + ['instanceSeed', getAddressEncoder()], + ['oldAdmin', getAddressEncoder()], + ['newAdmin', getAddressEncoder()], + ]); +} + +export function getSetNewAdminEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['eventDiscriminator', getU8Decoder()], + ['instanceSeed', getAddressDecoder()], + ['oldAdmin', getAddressDecoder()], + ['newAdmin', getAddressDecoder()], + ]); +} + +export function getSetNewAdminEventCodec(): FixedSizeCodec< + SetNewAdminEventArgs, + SetNewAdminEvent +> { + return combineCodec( + getSetNewAdminEventEncoder(), + getSetNewAdminEventDecoder() + ); +} diff --git a/contra-withdraw-program/clients/typescript/src/generated/errors/contraWithdrawProgram.ts b/contra-withdraw-program/clients/typescript/src/generated/errors/contraWithdrawProgram.ts new file mode 100644 index 00000000..0a66b226 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/errors/contraWithdrawProgram.ts @@ -0,0 +1,63 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + isProgramError, + type Address, + type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + type SolanaError, +} from '@solana/kit'; +import { CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; + +/** InvalidMint: Invalid mint provided */ +export const CONTRA_WITHDRAW_PROGRAM_ERROR__INVALID_MINT = 0x0; // 0 + +export type ContraWithdrawProgramError = + typeof CONTRA_WITHDRAW_PROGRAM_ERROR__INVALID_MINT; + +let contraWithdrawProgramErrorMessages: + | Record + | undefined; +if (process.env.NODE_ENV !== 'production') { + contraWithdrawProgramErrorMessages = { + [CONTRA_WITHDRAW_PROGRAM_ERROR__INVALID_MINT]: `Invalid mint provided`, + }; +} + +export function getContraWithdrawProgramErrorMessage( + code: ContraWithdrawProgramError +): string { + if (process.env.NODE_ENV !== 'production') { + return ( + contraWithdrawProgramErrorMessages as Record< + ContraWithdrawProgramError, + string + > + )[code]; + } + + return 'Error message not available in production bundles.'; +} + +export function isContraWithdrawProgramError< + TProgramErrorCode extends ContraWithdrawProgramError, +>( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS, + code + ); +} diff --git a/contra-withdraw-program/clients/typescript/src/generated/errors/index.ts b/contra-withdraw-program/clients/typescript/src/generated/errors/index.ts new file mode 100644 index 00000000..53dcffd7 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/errors/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './contraWithdrawProgram'; diff --git a/contra-withdraw-program/clients/typescript/src/generated/index.ts b/contra-withdraw-program/clients/typescript/src/generated/index.ts new file mode 100644 index 00000000..95deb59e --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/index.ts @@ -0,0 +1,12 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './errors'; +export * from './instructions'; +export * from './programs'; +export * from './types'; diff --git a/contra-withdraw-program/clients/typescript/src/generated/instructions/index.ts b/contra-withdraw-program/clients/typescript/src/generated/instructions/index.ts new file mode 100644 index 00000000..ba63e08a --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/instructions/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './withdrawFunds'; diff --git a/contra-withdraw-program/clients/typescript/src/generated/instructions/withdrawFunds.ts b/contra-withdraw-program/clients/typescript/src/generated/instructions/withdrawFunds.ts new file mode 100644 index 00000000..1a597c94 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/instructions/withdrawFunds.ts @@ -0,0 +1,394 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getOptionDecoder, + getOptionEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlyAccount, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from '@solana/kit'; +import { CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS } from '../programs'; +import { + expectAddress, + getAccountMetaFactory, + type ResolvedAccount, +} from '../shared'; + +export const WITHDRAW_FUNDS_DISCRIMINATOR = 0; + +export function getWithdrawFundsDiscriminatorBytes() { + return getU8Encoder().encode(WITHDRAW_FUNDS_DISCRIMINATOR); +} + +export type WithdrawFundsInstruction< + TProgram extends string = typeof CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS, + TAccountUser extends string | AccountMeta = string, + TAccountMint extends string | AccountMeta = string, + TAccountTokenAccount extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + TAccountAssociatedTokenProgram extends + | string + | AccountMeta = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountUser extends string + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountUser, + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountTokenAccount extends string + ? WritableAccount + : TAccountTokenAccount, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export type WithdrawFundsInstructionData = { + discriminator: number; + amount: bigint; + destination: Option
; +}; + +export type WithdrawFundsInstructionDataArgs = { + amount: number | bigint; + destination: OptionOrNullable
; +}; + +export function getWithdrawFundsInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['amount', getU64Encoder()], + ['destination', getOptionEncoder(getAddressEncoder())], + ]), + (value) => ({ ...value, discriminator: WITHDRAW_FUNDS_DISCRIMINATOR }) + ); +} + +export function getWithdrawFundsInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['amount', getU64Decoder()], + ['destination', getOptionDecoder(getAddressDecoder())], + ]); +} + +export function getWithdrawFundsInstructionDataCodec(): Codec< + WithdrawFundsInstructionDataArgs, + WithdrawFundsInstructionData +> { + return combineCodec( + getWithdrawFundsInstructionDataEncoder(), + getWithdrawFundsInstructionDataDecoder() + ); +} + +export type WithdrawFundsAsyncInput< + TAccountUser extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + /** User initiating the withdrawal */ + user: TransactionSigner; + /** Token mint */ + mint: Address; + /** Source token account */ + tokenAccount?: Address; + /** Token program */ + tokenProgram?: Address; + /** Associated token program */ + associatedTokenProgram?: Address; + amount: WithdrawFundsInstructionDataArgs['amount']; + destination: WithdrawFundsInstructionDataArgs['destination']; +}; + +export async function getWithdrawFundsInstructionAsync< + TAccountUser extends string, + TAccountMint extends string, + TAccountTokenAccount extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS, +>( + input: WithdrawFundsAsyncInput< + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress } +): Promise< + WithdrawFundsInstruction< + TProgramAddress, + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + user: { value: input.user ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: true }, + tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.tokenAccount.value) { + accounts.tokenAccount.value = await getProgramDerivedAddress({ + programAddress: + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.user.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.mint.value)), + ], + }); + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.user), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getWithdrawFundsInstructionDataEncoder().encode( + args as WithdrawFundsInstructionDataArgs + ), + programAddress, + } as WithdrawFundsInstruction< + TProgramAddress, + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type WithdrawFundsInput< + TAccountUser extends string = string, + TAccountMint extends string = string, + TAccountTokenAccount extends string = string, + TAccountTokenProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> = { + /** User initiating the withdrawal */ + user: TransactionSigner; + /** Token mint */ + mint: Address; + /** Source token account */ + tokenAccount: Address; + /** Token program */ + tokenProgram?: Address; + /** Associated token program */ + associatedTokenProgram?: Address; + amount: WithdrawFundsInstructionDataArgs['amount']; + destination: WithdrawFundsInstructionDataArgs['destination']; +}; + +export function getWithdrawFundsInstruction< + TAccountUser extends string, + TAccountMint extends string, + TAccountTokenAccount extends string, + TAccountTokenProgram extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends + Address = typeof CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS, +>( + input: WithdrawFundsInput< + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress } +): WithdrawFundsInstruction< + TProgramAddress, + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = + config?.programAddress ?? CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + user: { value: input.user ?? null, isWritable: false }, + mint: { value: input.mint ?? null, isWritable: true }, + tokenAccount: { value: input.tokenAccount ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' as Address<'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'>; + } + if (!accounts.associatedTokenProgram.value) { + accounts.associatedTokenProgram.value = + 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL' as Address<'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'>; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.user), + getAccountMeta(accounts.mint), + getAccountMeta(accounts.tokenAccount), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.associatedTokenProgram), + ], + data: getWithdrawFundsInstructionDataEncoder().encode( + args as WithdrawFundsInstructionDataArgs + ), + programAddress, + } as WithdrawFundsInstruction< + TProgramAddress, + TAccountUser, + TAccountMint, + TAccountTokenAccount, + TAccountTokenProgram, + TAccountAssociatedTokenProgram + >); +} + +export type ParsedWithdrawFundsInstruction< + TProgram extends string = typeof CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + /** User initiating the withdrawal */ + user: TAccountMetas[0]; + /** Token mint */ + mint: TAccountMetas[1]; + /** Source token account */ + tokenAccount: TAccountMetas[2]; + /** Token program */ + tokenProgram: TAccountMetas[3]; + /** Associated token program */ + associatedTokenProgram: TAccountMetas[4]; + }; + data: WithdrawFundsInstructionData; +}; + +export function parseWithdrawFundsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData +): ParsedWithdrawFundsInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + user: getNextAccount(), + mint: getNextAccount(), + tokenAccount: getNextAccount(), + tokenProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getWithdrawFundsInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/contra-withdraw-program/clients/typescript/src/generated/programs/contraWithdrawProgram.ts b/contra-withdraw-program/clients/typescript/src/generated/programs/contraWithdrawProgram.ts new file mode 100644 index 00000000..65795504 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/programs/contraWithdrawProgram.ts @@ -0,0 +1,40 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + containsBytes, + getU8Encoder, + type Address, + type ReadonlyUint8Array, +} from '@solana/kit'; +import { type ParsedWithdrawFundsInstruction } from '../instructions'; + +export const CONTRA_WITHDRAW_PROGRAM_PROGRAM_ADDRESS = + 'J231K9UEpS4y4KAPwGc4gsMNCjKFRMYcQBcjVW7vBhVi' as Address<'J231K9UEpS4y4KAPwGc4gsMNCjKFRMYcQBcjVW7vBhVi'>; + +export enum ContraWithdrawProgramInstruction { + WithdrawFunds, +} + +export function identifyContraWithdrawProgramInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array +): ContraWithdrawProgramInstruction { + const data = 'data' in instruction ? instruction.data : instruction; + if (containsBytes(data, getU8Encoder().encode(0), 0)) { + return ContraWithdrawProgramInstruction.WithdrawFunds; + } + throw new Error( + 'The provided instruction could not be identified as a contraWithdrawProgram instruction.' + ); +} + +export type ParsedContraWithdrawProgramInstruction< + TProgram extends string = 'J231K9UEpS4y4KAPwGc4gsMNCjKFRMYcQBcjVW7vBhVi', +> = { + instructionType: ContraWithdrawProgramInstruction.WithdrawFunds; +} & ParsedWithdrawFundsInstruction; diff --git a/contra-withdraw-program/clients/typescript/src/generated/programs/index.ts b/contra-withdraw-program/clients/typescript/src/generated/programs/index.ts new file mode 100644 index 00000000..53dcffd7 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/programs/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './contraWithdrawProgram'; diff --git a/contra-withdraw-program/clients/typescript/src/generated/shared/index.ts b/contra-withdraw-program/clients/typescript/src/generated/shared/index.ts new file mode 100644 index 00000000..83a31834 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/shared/index.ts @@ -0,0 +1,164 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + type AccountMeta, + type AccountSignerMeta, + type Address, + type ProgramDerivedAddress, + type TransactionSigner, + upgradeRoleToSigner, +} from '@solana/kit'; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error('Expected a value but received null or undefined.'); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): Address { + if (!value) { + throw new Error('Expected a Address.'); + } + if (typeof value === 'object' && 'address' in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): ProgramDerivedAddress { + if (!value || !Array.isArray(value) || !isProgramDerivedAddress(value)) { + throw new Error('Expected a ProgramDerivedAddress.'); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined +): TransactionSigner { + if (!value || !isTransactionSigner(value)) { + throw new Error('Expected a TransactionSigner.'); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export type ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> = { + isWritable: boolean; + value: U; +}; + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export type InstructionWithByteDelta = { + byteDelta: number; +}; + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: 'omitted' | 'programId' +) { + return ( + account: ResolvedAccount + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === 'omitted') return; + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner +): value is TransactionSigner { + return ( + !!value && + typeof value === 'object' && + 'address' in value && + kitIsTransactionSigner(value) + ); +} diff --git a/contra-withdraw-program/clients/typescript/src/generated/types/index.ts b/contra-withdraw-program/clients/typescript/src/generated/types/index.ts new file mode 100644 index 00000000..c48dbed9 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/types/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from './withdrawFundsEvent'; diff --git a/contra-withdraw-program/clients/typescript/src/generated/types/withdrawFundsEvent.ts b/contra-withdraw-program/clients/typescript/src/generated/types/withdrawFundsEvent.ts new file mode 100644 index 00000000..45b08ee7 --- /dev/null +++ b/contra-withdraw-program/clients/typescript/src/generated/types/withdrawFundsEvent.ts @@ -0,0 +1,52 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, +} from '@solana/kit'; + +export type WithdrawFundsEvent = { amount: bigint; destination: Address }; + +export type WithdrawFundsEventArgs = { + amount: number | bigint; + destination: Address; +}; + +export function getWithdrawFundsEventEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ['amount', getU64Encoder()], + ['destination', getAddressEncoder()], + ]); +} + +export function getWithdrawFundsEventDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ['amount', getU64Decoder()], + ['destination', getAddressDecoder()], + ]); +} + +export function getWithdrawFundsEventCodec(): FixedSizeCodec< + WithdrawFundsEventArgs, + WithdrawFundsEvent +> { + return combineCodec( + getWithdrawFundsEventEncoder(), + getWithdrawFundsEventDecoder() + ); +}