diff --git a/sdk/src/generated/solisting/package.json b/sdk/src/generated/solisting/package.json new file mode 100644 index 0000000..e4687c9 --- /dev/null +++ b/sdk/src/generated/solisting/package.json @@ -0,0 +1,22 @@ +{ + "name": "js-client", + "version": "1.0.0", + "description": "", + "main": "src/index.ts", + "files": [ + "./dist/src", + "./dist/types", + "./src/" + ], + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "peerDependencies": { + "@solana/kit": "^6.10.0" + }, + "dependencies": { + "@solana/program-client-core": "^6.10.0" + } +} diff --git a/sdk/src/generated/solisting/src/generated/accounts/index.ts b/sdk/src/generated/solisting/src/generated/accounts/index.ts new file mode 100644 index 0000000..8108f37 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/accounts/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./solistingStateListingAccount"; +export * from "./solistingStateOrderAccount"; diff --git a/sdk/src/generated/solisting/src/generated/accounts/solistingStateListingAccount.ts b/sdk/src/generated/solisting/src/generated/accounts/solistingStateListingAccount.ts new file mode 100644 index 0000000..6c877ce --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/accounts/solistingStateListingAccount.ts @@ -0,0 +1,268 @@ +/** + * 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 { + addDecoderSizePrefix, + addEncoderSizePrefix, + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + getUtf8Decoder, + getUtf8Encoder, + transformEncoder, + type Account, + type Address, + type Codec, + type Decoder, + type EncodedAccount, + type Encoder, + type FetchAccountConfig, + type FetchAccountsConfig, + type MaybeAccount, + type MaybeEncodedAccount, + type Option, + type OptionOrNullable, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { + getSolistingStateAltCurrencyConfigDecoder, + getSolistingStateAltCurrencyConfigEncoder, + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateAltCurrencyConfig, + type SolistingStateAltCurrencyConfigArgs, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "../types"; + +export const SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([59, 89, 136, 25, 21, 196, 183, 13]); + +export function getSolistingStateListingAccountDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR, + ); +} + +export type SolistingStateListingAccount = { + discriminator: ReadonlyUint8Array; + seller: Address; + /** Sole source of truth for price. All alt_currencies are derived from this via oracle. */ + canonicalCurrency: SolistingStateCurrency; + /** Price in canonical_currency's smallest unit. */ + price: bigint; + /** + * Pyth V2 PriceFeedAccount for the canonical currency priced in USD. + * `None` = canonical is a $1.00 USD stablecoin. + * For Sol canonical: set to the SOL/USD Pyth feed. + */ + canonicalOracle: Option
; + /** + * Alt currencies the seller accepts. Amounts are oracle-computed at create_order time. + * Empty = no oracle ever needed. + */ + altCurrencies: Array; + /** Resolvers the seller accepts for dispute resolution. Empty = any resolver ok. */ + acceptedResolvers: Array
; + /** Total units the seller offers (includes quantity_reserved). */ + quantity: number; + /** Units held by pending orders. available = quantity - quantity_reserved. */ + quantityReserved: number; + metadataUri: string; + listingId: bigint; + isActive: boolean; + bump: number; +}; + +export type SolistingStateListingAccountArgs = { + seller: Address; + /** Sole source of truth for price. All alt_currencies are derived from this via oracle. */ + canonicalCurrency: SolistingStateCurrencyArgs; + /** Price in canonical_currency's smallest unit. */ + price: number | bigint; + /** + * Pyth V2 PriceFeedAccount for the canonical currency priced in USD. + * `None` = canonical is a $1.00 USD stablecoin. + * For Sol canonical: set to the SOL/USD Pyth feed. + */ + canonicalOracle: OptionOrNullable
; + /** + * Alt currencies the seller accepts. Amounts are oracle-computed at create_order time. + * Empty = no oracle ever needed. + */ + altCurrencies: Array; + /** Resolvers the seller accepts for dispute resolution. Empty = any resolver ok. */ + acceptedResolvers: Array
; + /** Total units the seller offers (includes quantity_reserved). */ + quantity: number; + /** Units held by pending orders. available = quantity - quantity_reserved. */ + quantityReserved: number; + metadataUri: string; + listingId: number | bigint; + isActive: boolean; + bump: number; +}; + +/** Gets the encoder for {@link SolistingStateListingAccountArgs} account data. */ +export function getSolistingStateListingAccountEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["seller", getAddressEncoder()], + ["canonicalCurrency", getSolistingStateCurrencyEncoder()], + ["price", getU64Encoder()], + ["canonicalOracle", getOptionEncoder(getAddressEncoder())], + [ + "altCurrencies", + getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()), + ], + ["acceptedResolvers", getArrayEncoder(getAddressEncoder())], + ["quantity", getU32Encoder()], + ["quantityReserved", getU32Encoder()], + ["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ["listingId", getU64Encoder()], + ["isActive", getBooleanEncoder()], + ["bump", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SOLISTING_STATE_LISTING_ACCOUNT_DISCRIMINATOR, + }), + ); +} + +/** Gets the decoder for {@link SolistingStateListingAccount} account data. */ +export function getSolistingStateListingAccountDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["seller", getAddressDecoder()], + ["canonicalCurrency", getSolistingStateCurrencyDecoder()], + ["price", getU64Decoder()], + ["canonicalOracle", getOptionDecoder(getAddressDecoder())], + [ + "altCurrencies", + getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()), + ], + ["acceptedResolvers", getArrayDecoder(getAddressDecoder())], + ["quantity", getU32Decoder()], + ["quantityReserved", getU32Decoder()], + ["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ["listingId", getU64Decoder()], + ["isActive", getBooleanDecoder()], + ["bump", getU8Decoder()], + ]); +} + +/** Gets the codec for {@link SolistingStateListingAccount} account data. */ +export function getSolistingStateListingAccountCodec(): Codec< + SolistingStateListingAccountArgs, + SolistingStateListingAccount +> { + return combineCodec( + getSolistingStateListingAccountEncoder(), + getSolistingStateListingAccountDecoder(), + ); +} + +export function decodeSolistingStateListingAccount< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount, +): Account; +export function decodeSolistingStateListingAccount< + TAddress extends string = string, +>( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeSolistingStateListingAccount< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getSolistingStateListingAccountDecoder(), + ); +} + +export async function fetchSolistingStateListingAccount< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeSolistingStateListingAccount( + rpc, + address, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeSolistingStateListingAccount< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeSolistingStateListingAccount(maybeAccount); +} + +export async function fetchAllSolistingStateListingAccount( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeSolistingStateListingAccount( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeSolistingStateListingAccount( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeSolistingStateListingAccount(maybeAccount), + ); +} diff --git a/sdk/src/generated/solisting/src/generated/accounts/solistingStateOrderAccount.ts b/sdk/src/generated/solisting/src/generated/accounts/solistingStateOrderAccount.ts new file mode 100644 index 0000000..33bb7fc --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/accounts/solistingStateOrderAccount.ts @@ -0,0 +1,222 @@ +/** + * 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, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Account, + type Address, + type Codec, + type Decoder, + type EncodedAccount, + type Encoder, + type FetchAccountConfig, + type FetchAccountsConfig, + type MaybeAccount, + type MaybeEncodedAccount, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "../types"; + +export const SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([79, 67, 112, 155, 214, 14, 32, 55]); + +export function getSolistingStateOrderAccountDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR, + ); +} + +export type SolistingStateOrderAccount = { + discriminator: ReadonlyUint8Array; + listing: Address; + buyer: Address; + seller: Address; + resolver: Address; + /** The currency the buyer chose to pay in. */ + paymentCurrency: SolistingStateCurrency; + /** Actual amount paid (may differ from price when oracle-converted). */ + amount: bigint; + /** The descro EscrowAccount PDA for this order. */ + escrowAccount: Address; + /** Derived from order_account PDA bytes[0..8]; used as descro escrow_id seed. */ + escrowId: bigint; + orderId: bigint; + createdAt: bigint; + bump: number; +}; + +export type SolistingStateOrderAccountArgs = { + listing: Address; + buyer: Address; + seller: Address; + resolver: Address; + /** The currency the buyer chose to pay in. */ + paymentCurrency: SolistingStateCurrencyArgs; + /** Actual amount paid (may differ from price when oracle-converted). */ + amount: number | bigint; + /** The descro EscrowAccount PDA for this order. */ + escrowAccount: Address; + /** Derived from order_account PDA bytes[0..8]; used as descro escrow_id seed. */ + escrowId: number | bigint; + orderId: number | bigint; + createdAt: number | bigint; + bump: number; +}; + +/** Gets the encoder for {@link SolistingStateOrderAccountArgs} account data. */ +export function getSolistingStateOrderAccountEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["listing", getAddressEncoder()], + ["buyer", getAddressEncoder()], + ["seller", getAddressEncoder()], + ["resolver", getAddressEncoder()], + ["paymentCurrency", getSolistingStateCurrencyEncoder()], + ["amount", getU64Encoder()], + ["escrowAccount", getAddressEncoder()], + ["escrowId", getU64Encoder()], + ["orderId", getU64Encoder()], + ["createdAt", getI64Encoder()], + ["bump", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SOLISTING_STATE_ORDER_ACCOUNT_DISCRIMINATOR, + }), + ); +} + +/** Gets the decoder for {@link SolistingStateOrderAccount} account data. */ +export function getSolistingStateOrderAccountDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["listing", getAddressDecoder()], + ["buyer", getAddressDecoder()], + ["seller", getAddressDecoder()], + ["resolver", getAddressDecoder()], + ["paymentCurrency", getSolistingStateCurrencyDecoder()], + ["amount", getU64Decoder()], + ["escrowAccount", getAddressDecoder()], + ["escrowId", getU64Decoder()], + ["orderId", getU64Decoder()], + ["createdAt", getI64Decoder()], + ["bump", getU8Decoder()], + ]); +} + +/** Gets the codec for {@link SolistingStateOrderAccount} account data. */ +export function getSolistingStateOrderAccountCodec(): Codec< + SolistingStateOrderAccountArgs, + SolistingStateOrderAccount +> { + return combineCodec( + getSolistingStateOrderAccountEncoder(), + getSolistingStateOrderAccountDecoder(), + ); +} + +export function decodeSolistingStateOrderAccount< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount, +): Account; +export function decodeSolistingStateOrderAccount< + TAddress extends string = string, +>( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeSolistingStateOrderAccount< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getSolistingStateOrderAccountDecoder(), + ); +} + +export async function fetchSolistingStateOrderAccount< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeSolistingStateOrderAccount( + rpc, + address, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeSolistingStateOrderAccount< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeSolistingStateOrderAccount(maybeAccount); +} + +export async function fetchAllSolistingStateOrderAccount( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeSolistingStateOrderAccount( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeSolistingStateOrderAccount( + rpc: Parameters[0], + addresses: Array
, + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeSolistingStateOrderAccount(maybeAccount), + ); +} diff --git a/sdk/src/generated/solisting/src/generated/index.ts b/sdk/src/generated/solisting/src/generated/index.ts new file mode 100644 index 0000000..af1e907 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/index.ts @@ -0,0 +1,13 @@ +/** + * 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 "./instructions"; +export * from "./pdas"; +export * from "./programs"; +export * from "./types"; diff --git a/sdk/src/generated/solisting/src/generated/instructions/acceptOrder.ts b/sdk/src/generated/solisting/src/generated/instructions/acceptOrder.ts new file mode 100644 index 0000000..cd063bb --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/acceptOrder.ts @@ -0,0 +1,283 @@ +/** + * 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, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const ACCEPT_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 118, 157, 62, 39, 239, 234, 231, 193, +]); + +export function getAcceptOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + ACCEPT_ORDER_DISCRIMINATOR, + ); +} + +export type AcceptOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountSeller extends string | AccountMeta = string, + TAccountResolver extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TAccountOrderAccount extends string | AccountMeta = string, + TAccountEscrowAccount extends string | AccountMeta = string, + TAccountResolverEntry extends string | AccountMeta = string, + TAccountDescroProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSeller extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSeller, + TAccountResolver extends string + ? ReadonlyAccount + : TAccountResolver, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + TAccountOrderAccount extends string + ? WritableAccount + : TAccountOrderAccount, + TAccountEscrowAccount extends string + ? WritableAccount + : TAccountEscrowAccount, + TAccountResolverEntry extends string + ? ReadonlyAccount + : TAccountResolverEntry, + TAccountDescroProgram extends string + ? ReadonlyAccount + : TAccountDescroProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type AcceptOrderInstructionData = { discriminator: ReadonlyUint8Array }; + +export type AcceptOrderInstructionDataArgs = {}; + +export function getAcceptOrderInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: ACCEPT_ORDER_DISCRIMINATOR }), + ); +} + +export function getAcceptOrderInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getAcceptOrderInstructionDataCodec(): FixedSizeCodec< + AcceptOrderInstructionDataArgs, + AcceptOrderInstructionData +> { + return combineCodec( + getAcceptOrderInstructionDataEncoder(), + getAcceptOrderInstructionDataDecoder(), + ); +} + +export type AcceptOrderInput< + TAccountSeller extends string = string, + TAccountResolver extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountResolverEntry extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + seller: TransactionSigner; + resolver: Address; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + resolverEntry: Address; + descroProgram: Address; + systemProgram?: Address; +}; + +export function getAcceptOrderInstruction< + TAccountSeller extends string, + TAccountResolver extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountResolverEntry extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: AcceptOrderInput< + TAccountSeller, + TAccountResolver, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountResolverEntry, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): AcceptOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountResolver, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountResolverEntry, + TAccountDescroProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + resolver: { value: input.resolver ?? null, isWritable: false }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + resolverEntry: { value: input.resolverEntry ?? null, isWritable: false }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("resolver", accounts.resolver), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("resolverEntry", accounts.resolverEntry), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getAcceptOrderInstructionDataEncoder().encode({}), + programAddress, + } as AcceptOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountResolver, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountResolverEntry, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type ParsedAcceptOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + seller: TAccountMetas[0]; + resolver: TAccountMetas[1]; + listingAccount: TAccountMetas[2]; + orderAccount: TAccountMetas[3]; + escrowAccount: TAccountMetas[4]; + resolverEntry: TAccountMetas[5]; + descroProgram: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + }; + data: AcceptOrderInstructionData; +}; + +export function parseAcceptOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedAcceptOrderInstruction { + if (instruction.accounts.length < 8) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 8, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + seller: getNextAccount(), + resolver: getNextAccount(), + listingAccount: getNextAccount(), + orderAccount: getNextAccount(), + escrowAccount: getNextAccount(), + resolverEntry: getNextAccount(), + descroProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getAcceptOrderInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/cancelOrder.ts b/sdk/src/generated/solisting/src/generated/instructions/cancelOrder.ts new file mode 100644 index 0000000..95cbaa2 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/cancelOrder.ts @@ -0,0 +1,386 @@ +/** + * 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, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + getAddressFromResolvedInstructionAccount, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const CANCEL_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 95, 129, 237, 240, 8, 49, 223, 132, +]); + +export function getCancelOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CANCEL_ORDER_DISCRIMINATOR, + ); +} + +export type CancelOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountBuyer extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TAccountOrderAccount extends string | AccountMeta = string, + TAccountEscrowAccount extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountDescroProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBuyer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountBuyer, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + TAccountOrderAccount extends string + ? WritableAccount + : TAccountOrderAccount, + TAccountEscrowAccount extends string + ? WritableAccount + : TAccountEscrowAccount, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountDescroProgram extends string + ? ReadonlyAccount + : TAccountDescroProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CancelOrderInstructionData = { discriminator: ReadonlyUint8Array }; + +export type CancelOrderInstructionDataArgs = {}; + +export function getCancelOrderInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: CANCEL_ORDER_DISCRIMINATOR }), + ); +} + +export function getCancelOrderInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCancelOrderInstructionDataCodec(): FixedSizeCodec< + CancelOrderInstructionDataArgs, + CancelOrderInstructionData +> { + return combineCodec( + getCancelOrderInstructionDataEncoder(), + getCancelOrderInstructionDataDecoder(), + ); +} + +export type CancelOrderAsyncInput< + TAccountBuyer extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountVault extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + buyer: TransactionSigner; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + vault?: Address; + descroProgram: Address; + systemProgram?: Address; +}; + +export async function getCancelOrderInstructionAsync< + TAccountBuyer extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountVault extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CancelOrderAsyncInput< + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + CancelOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + buyer: { value: input.buyer ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Resolve default values. + if (!accounts.vault.value) { + accounts.vault.value = await getProgramDerivedAddress({ + programAddress: + "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">, + seeds: [ + getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])), + getAddressEncoder().encode( + getAddressFromResolvedInstructionAccount( + "escrowAccount", + accounts.escrowAccount.value, + ), + ), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("vault", accounts.vault), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCancelOrderInstructionDataEncoder().encode({}), + programAddress, + } as CancelOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type CancelOrderInput< + TAccountBuyer extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountVault extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + buyer: TransactionSigner; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + vault: Address; + descroProgram: Address; + systemProgram?: Address; +}; + +export function getCancelOrderInstruction< + TAccountBuyer extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountVault extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CancelOrderInput< + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CancelOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + buyer: { value: input.buyer ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("vault", accounts.vault), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCancelOrderInstructionDataEncoder().encode({}), + programAddress, + } as CancelOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type ParsedCancelOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + buyer: TAccountMetas[0]; + listingAccount: TAccountMetas[1]; + orderAccount: TAccountMetas[2]; + escrowAccount: TAccountMetas[3]; + vault: TAccountMetas[4]; + descroProgram: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + }; + data: CancelOrderInstructionData; +}; + +export function parseCancelOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCancelOrderInstruction { + if (instruction.accounts.length < 7) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 7, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + buyer: getNextAccount(), + listingAccount: getNextAccount(), + orderAccount: getNextAccount(), + escrowAccount: getNextAccount(), + vault: getNextAccount(), + descroProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCancelOrderInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/closeListing.ts b/sdk/src/generated/solisting/src/generated/instructions/closeListing.ts new file mode 100644 index 0000000..29abf8c --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/closeListing.ts @@ -0,0 +1,185 @@ +/** + * 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, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const CLOSE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 33, 15, 192, 81, 78, 175, 159, 97, +]); + +export function getCloseListingDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CLOSE_LISTING_DISCRIMINATOR, + ); +} + +export type CloseListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountSeller extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSeller extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSeller, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + ...TRemainingAccounts, + ] + >; + +export type CloseListingInstructionData = { discriminator: ReadonlyUint8Array }; + +export type CloseListingInstructionDataArgs = {}; + +export function getCloseListingInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: CLOSE_LISTING_DISCRIMINATOR }), + ); +} + +export function getCloseListingInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCloseListingInstructionDataCodec(): FixedSizeCodec< + CloseListingInstructionDataArgs, + CloseListingInstructionData +> { + return combineCodec( + getCloseListingInstructionDataEncoder(), + getCloseListingInstructionDataDecoder(), + ); +} + +export type CloseListingInput< + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, +> = { + seller: TransactionSigner; + listingAccount: Address; +}; + +export function getCloseListingInstruction< + TAccountSeller extends string, + TAccountListingAccount extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CloseListingInput, + config?: { programAddress?: TProgramAddress }, +): CloseListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + ], + data: getCloseListingInstructionDataEncoder().encode({}), + programAddress, + } as CloseListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount + >); +} + +export type ParsedCloseListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + seller: TAccountMetas[0]; + listingAccount: TAccountMetas[1]; + }; + data: CloseListingInstructionData; +}; + +export function parseCloseListingInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCloseListingInstruction { + if (instruction.accounts.length < 2) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 2, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { seller: getNextAccount(), listingAccount: getNextAccount() }, + data: getCloseListingInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/closeStaleOrder.ts b/sdk/src/generated/solisting/src/generated/instructions/closeStaleOrder.ts new file mode 100644 index 0000000..ae54369 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/closeStaleOrder.ts @@ -0,0 +1,207 @@ +/** + * 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, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const CLOSE_STALE_ORDER_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([167, 12, 32, 252, 132, 106, 131, 250]); + +export function getCloseStaleOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CLOSE_STALE_ORDER_DISCRIMINATOR, + ); +} + +export type CloseStaleOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountCaller extends string | AccountMeta = string, + TAccountOrderAccount extends string | AccountMeta = string, + TAccountEscrowAccount extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountCaller extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountCaller, + TAccountOrderAccount extends string + ? WritableAccount + : TAccountOrderAccount, + TAccountEscrowAccount extends string + ? ReadonlyAccount + : TAccountEscrowAccount, + ...TRemainingAccounts, + ] + >; + +export type CloseStaleOrderInstructionData = { + discriminator: ReadonlyUint8Array; +}; + +export type CloseStaleOrderInstructionDataArgs = {}; + +export function getCloseStaleOrderInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: CLOSE_STALE_ORDER_DISCRIMINATOR }), + ); +} + +export function getCloseStaleOrderInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCloseStaleOrderInstructionDataCodec(): FixedSizeCodec< + CloseStaleOrderInstructionDataArgs, + CloseStaleOrderInstructionData +> { + return combineCodec( + getCloseStaleOrderInstructionDataEncoder(), + getCloseStaleOrderInstructionDataDecoder(), + ); +} + +export type CloseStaleOrderInput< + TAccountCaller extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, +> = { + caller: TransactionSigner; + orderAccount: Address; + escrowAccount: Address; +}; + +export function getCloseStaleOrderInstruction< + TAccountCaller extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CloseStaleOrderInput< + TAccountCaller, + TAccountOrderAccount, + TAccountEscrowAccount + >, + config?: { programAddress?: TProgramAddress }, +): CloseStaleOrderInstruction< + TProgramAddress, + TAccountCaller, + TAccountOrderAccount, + TAccountEscrowAccount +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + caller: { value: input.caller ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("caller", accounts.caller), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + ], + data: getCloseStaleOrderInstructionDataEncoder().encode({}), + programAddress, + } as CloseStaleOrderInstruction< + TProgramAddress, + TAccountCaller, + TAccountOrderAccount, + TAccountEscrowAccount + >); +} + +export type ParsedCloseStaleOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + caller: TAccountMetas[0]; + orderAccount: TAccountMetas[1]; + escrowAccount: TAccountMetas[2]; + }; + data: CloseStaleOrderInstructionData; +}; + +export function parseCloseStaleOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCloseStaleOrderInstruction { + if (instruction.accounts.length < 3) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 3, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + caller: getNextAccount(), + orderAccount: getNextAccount(), + escrowAccount: getNextAccount(), + }, + data: getCloseStaleOrderInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/createListing.ts b/sdk/src/generated/solisting/src/generated/instructions/createListing.ts new file mode 100644 index 0000000..e0668ff --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/createListing.ts @@ -0,0 +1,390 @@ +/** + * 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 { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getUtf8Decoder, + getUtf8Encoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + 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 ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + getAddressFromResolvedInstructionAccount, + getNonNullResolvedInstructionInput, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { findListingAccountPda } from "../pdas"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; +import { + getSolistingStateAltCurrencyConfigDecoder, + getSolistingStateAltCurrencyConfigEncoder, + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateAltCurrencyConfig, + type SolistingStateAltCurrencyConfigArgs, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "../types"; + +export const CREATE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 18, 168, 45, 24, 191, 31, 117, 54, +]); + +export function getCreateListingDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CREATE_LISTING_DISCRIMINATOR, + ); +} + +export type CreateListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountSeller extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSeller extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSeller, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CreateListingInstructionData = { + discriminator: ReadonlyUint8Array; + listingId: bigint; + canonicalCurrency: SolistingStateCurrency; + price: bigint; + canonicalOracle: Option
; + altCurrencies: Array; + acceptedResolvers: Array
; + quantity: number; + metadataUri: string; +}; + +export type CreateListingInstructionDataArgs = { + listingId: number | bigint; + canonicalCurrency: SolistingStateCurrencyArgs; + price: number | bigint; + canonicalOracle: OptionOrNullable
; + altCurrencies: Array; + acceptedResolvers: Array
; + quantity: number; + metadataUri: string; +}; + +export function getCreateListingInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["listingId", getU64Encoder()], + ["canonicalCurrency", getSolistingStateCurrencyEncoder()], + ["price", getU64Encoder()], + ["canonicalOracle", getOptionEncoder(getAddressEncoder())], + [ + "altCurrencies", + getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()), + ], + ["acceptedResolvers", getArrayEncoder(getAddressEncoder())], + ["quantity", getU32Encoder()], + ["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ]), + (value) => ({ ...value, discriminator: CREATE_LISTING_DISCRIMINATOR }), + ); +} + +export function getCreateListingInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["listingId", getU64Decoder()], + ["canonicalCurrency", getSolistingStateCurrencyDecoder()], + ["price", getU64Decoder()], + ["canonicalOracle", getOptionDecoder(getAddressDecoder())], + [ + "altCurrencies", + getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()), + ], + ["acceptedResolvers", getArrayDecoder(getAddressDecoder())], + ["quantity", getU32Decoder()], + ["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ]); +} + +export function getCreateListingInstructionDataCodec(): Codec< + CreateListingInstructionDataArgs, + CreateListingInstructionData +> { + return combineCodec( + getCreateListingInstructionDataEncoder(), + getCreateListingInstructionDataDecoder(), + ); +} + +export type CreateListingAsyncInput< + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, + TAccountSystemProgram extends string = string, +> = { + seller: TransactionSigner; + listingAccount?: Address; + systemProgram?: Address; + listingId: CreateListingInstructionDataArgs["listingId"]; + canonicalCurrency: CreateListingInstructionDataArgs["canonicalCurrency"]; + price: CreateListingInstructionDataArgs["price"]; + canonicalOracle: CreateListingInstructionDataArgs["canonicalOracle"]; + altCurrencies: CreateListingInstructionDataArgs["altCurrencies"]; + acceptedResolvers: CreateListingInstructionDataArgs["acceptedResolvers"]; + quantity: CreateListingInstructionDataArgs["quantity"]; + metadataUri: CreateListingInstructionDataArgs["metadataUri"]; +}; + +export async function getCreateListingInstructionAsync< + TAccountSeller extends string, + TAccountListingAccount extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CreateListingAsyncInput< + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + CreateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.listingAccount.value) { + accounts.listingAccount.value = await findListingAccountPda({ + seller: getAddressFromResolvedInstructionAccount( + "seller", + accounts.seller.value, + ), + listingId: getNonNullResolvedInstructionInput( + "listingId", + args.listingId, + ), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCreateListingInstructionDataEncoder().encode( + args as CreateListingInstructionDataArgs, + ), + programAddress, + } as CreateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram + >); +} + +export type CreateListingInput< + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, + TAccountSystemProgram extends string = string, +> = { + seller: TransactionSigner; + listingAccount: Address; + systemProgram?: Address; + listingId: CreateListingInstructionDataArgs["listingId"]; + canonicalCurrency: CreateListingInstructionDataArgs["canonicalCurrency"]; + price: CreateListingInstructionDataArgs["price"]; + canonicalOracle: CreateListingInstructionDataArgs["canonicalOracle"]; + altCurrencies: CreateListingInstructionDataArgs["altCurrencies"]; + acceptedResolvers: CreateListingInstructionDataArgs["acceptedResolvers"]; + quantity: CreateListingInstructionDataArgs["quantity"]; + metadataUri: CreateListingInstructionDataArgs["metadataUri"]; +}; + +export function getCreateListingInstruction< + TAccountSeller extends string, + TAccountListingAccount extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CreateListingInput< + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCreateListingInstructionDataEncoder().encode( + args as CreateListingInstructionDataArgs, + ), + programAddress, + } as CreateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount, + TAccountSystemProgram + >); +} + +export type ParsedCreateListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + seller: TAccountMetas[0]; + listingAccount: TAccountMetas[1]; + systemProgram: TAccountMetas[2]; + }; + data: CreateListingInstructionData; +}; + +export function parseCreateListingInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateListingInstruction { + if (instruction.accounts.length < 3) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 3, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + seller: getNextAccount(), + listingAccount: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateListingInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/createOrder.ts b/sdk/src/generated/solisting/src/generated/instructions/createOrder.ts new file mode 100644 index 0000000..26b7b6b --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/createOrder.ts @@ -0,0 +1,559 @@ +/** + * 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, + getU16Decoder, + getU16Encoder, + getU64Decoder, + getU64Encoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + getAddressFromResolvedInstructionAccount, + getNonNullResolvedInstructionInput, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { findOrderAccountPda } from "../pdas"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; +import { + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "../types"; + +export const CREATE_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 141, 54, 37, 207, 237, 210, 250, 215, +]); + +export function getCreateOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CREATE_ORDER_DISCRIMINATOR, + ); +} + +export type CreateOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountBuyer extends string | AccountMeta = string, + TAccountSeller extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TAccountOrderAccount extends string | AccountMeta = string, + TAccountEscrowAccount extends string | AccountMeta = string, + TAccountDescroVault extends string | AccountMeta = string, + TAccountCanonicalOracle extends string | AccountMeta = string, + TAccountTargetOracle extends string | AccountMeta = string, + TAccountDescroProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBuyer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountBuyer, + TAccountSeller extends string + ? ReadonlyAccount + : TAccountSeller, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + TAccountOrderAccount extends string + ? WritableAccount + : TAccountOrderAccount, + TAccountEscrowAccount extends string + ? WritableAccount + : TAccountEscrowAccount, + TAccountDescroVault extends string + ? WritableAccount + : TAccountDescroVault, + TAccountCanonicalOracle extends string + ? ReadonlyAccount + : TAccountCanonicalOracle, + TAccountTargetOracle extends string + ? ReadonlyAccount + : TAccountTargetOracle, + TAccountDescroProgram extends string + ? ReadonlyAccount + : TAccountDescroProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type CreateOrderInstructionData = { + discriminator: ReadonlyUint8Array; + orderId: bigint; + escrowId: bigint; + resolver: Address; + paymentCurrency: SolistingStateCurrency; + expectedAmount: bigint; + maxSlippageBps: number; +}; + +export type CreateOrderInstructionDataArgs = { + orderId: number | bigint; + escrowId: number | bigint; + resolver: Address; + paymentCurrency: SolistingStateCurrencyArgs; + expectedAmount: number | bigint; + maxSlippageBps: number; +}; + +export function getCreateOrderInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["orderId", getU64Encoder()], + ["escrowId", getU64Encoder()], + ["resolver", getAddressEncoder()], + ["paymentCurrency", getSolistingStateCurrencyEncoder()], + ["expectedAmount", getU64Encoder()], + ["maxSlippageBps", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: CREATE_ORDER_DISCRIMINATOR }), + ); +} + +export function getCreateOrderInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["orderId", getU64Decoder()], + ["escrowId", getU64Decoder()], + ["resolver", getAddressDecoder()], + ["paymentCurrency", getSolistingStateCurrencyDecoder()], + ["expectedAmount", getU64Decoder()], + ["maxSlippageBps", getU16Decoder()], + ]); +} + +export function getCreateOrderInstructionDataCodec(): Codec< + CreateOrderInstructionDataArgs, + CreateOrderInstructionData +> { + return combineCodec( + getCreateOrderInstructionDataEncoder(), + getCreateOrderInstructionDataDecoder(), + ); +} + +export type CreateOrderAsyncInput< + TAccountBuyer extends string = string, + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountDescroVault extends string = string, + TAccountCanonicalOracle extends string = string, + TAccountTargetOracle extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + buyer: TransactionSigner; + seller: Address; + listingAccount: Address; + orderAccount?: Address; + escrowAccount?: Address; + descroVault?: Address; + /** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */ + canonicalOracle: Address; + /** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */ + targetOracle: Address; + descroProgram: Address; + systemProgram?: Address; + orderId: CreateOrderInstructionDataArgs["orderId"]; + escrowId: CreateOrderInstructionDataArgs["escrowId"]; + resolver: CreateOrderInstructionDataArgs["resolver"]; + paymentCurrency: CreateOrderInstructionDataArgs["paymentCurrency"]; + expectedAmount: CreateOrderInstructionDataArgs["expectedAmount"]; + maxSlippageBps: CreateOrderInstructionDataArgs["maxSlippageBps"]; +}; + +export async function getCreateOrderInstructionAsync< + TAccountBuyer extends string, + TAccountSeller extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountDescroVault extends string, + TAccountCanonicalOracle extends string, + TAccountTargetOracle extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CreateOrderAsyncInput< + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + CreateOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + buyer: { value: input.buyer ?? null, isWritable: true }, + seller: { value: input.seller ?? null, isWritable: false }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + descroVault: { value: input.descroVault ?? null, isWritable: true }, + canonicalOracle: { + value: input.canonicalOracle ?? null, + isWritable: false, + }, + targetOracle: { value: input.targetOracle ?? null, isWritable: false }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.orderAccount.value) { + accounts.orderAccount.value = await findOrderAccountPda({ + listingAccount: getAddressFromResolvedInstructionAccount( + "listingAccount", + accounts.listingAccount.value, + ), + buyer: getAddressFromResolvedInstructionAccount( + "buyer", + accounts.buyer.value, + ), + orderId: getNonNullResolvedInstructionInput("orderId", args.orderId), + }); + } + if (!accounts.escrowAccount.value) { + accounts.escrowAccount.value = await getProgramDerivedAddress({ + programAddress: + "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">, + seeds: [ + getBytesEncoder().encode(new Uint8Array([101, 115, 99, 114, 111, 119])), + getAddressEncoder().encode( + getAddressFromResolvedInstructionAccount( + "seller", + accounts.seller.value, + ), + ), + getU64Encoder().encode( + getNonNullResolvedInstructionInput("escrowId", args.escrowId), + ), + ], + }); + } + if (!accounts.descroVault.value) { + accounts.descroVault.value = await getProgramDerivedAddress({ + programAddress: + "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">, + seeds: [ + getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])), + getAddressEncoder().encode( + getAddressFromResolvedInstructionAccount( + "escrowAccount", + accounts.escrowAccount.value, + ), + ), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("descroVault", accounts.descroVault), + getAccountMeta("canonicalOracle", accounts.canonicalOracle), + getAccountMeta("targetOracle", accounts.targetOracle), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCreateOrderInstructionDataEncoder().encode( + args as CreateOrderInstructionDataArgs, + ), + programAddress, + } as CreateOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type CreateOrderInput< + TAccountBuyer extends string = string, + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountDescroVault extends string = string, + TAccountCanonicalOracle extends string = string, + TAccountTargetOracle extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + buyer: TransactionSigner; + seller: Address; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + descroVault: Address; + /** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */ + canonicalOracle: Address; + /** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */ + targetOracle: Address; + descroProgram: Address; + systemProgram?: Address; + orderId: CreateOrderInstructionDataArgs["orderId"]; + escrowId: CreateOrderInstructionDataArgs["escrowId"]; + resolver: CreateOrderInstructionDataArgs["resolver"]; + paymentCurrency: CreateOrderInstructionDataArgs["paymentCurrency"]; + expectedAmount: CreateOrderInstructionDataArgs["expectedAmount"]; + maxSlippageBps: CreateOrderInstructionDataArgs["maxSlippageBps"]; +}; + +export function getCreateOrderInstruction< + TAccountBuyer extends string, + TAccountSeller extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountDescroVault extends string, + TAccountCanonicalOracle extends string, + TAccountTargetOracle extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: CreateOrderInput< + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + buyer: { value: input.buyer ?? null, isWritable: true }, + seller: { value: input.seller ?? null, isWritable: false }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + descroVault: { value: input.descroVault ?? null, isWritable: true }, + canonicalOracle: { + value: input.canonicalOracle ?? null, + isWritable: false, + }, + targetOracle: { value: input.targetOracle ?? null, isWritable: false }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("descroVault", accounts.descroVault), + getAccountMeta("canonicalOracle", accounts.canonicalOracle), + getAccountMeta("targetOracle", accounts.targetOracle), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getCreateOrderInstructionDataEncoder().encode( + args as CreateOrderInstructionDataArgs, + ), + programAddress, + } as CreateOrderInstruction< + TProgramAddress, + TAccountBuyer, + TAccountSeller, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountDescroVault, + TAccountCanonicalOracle, + TAccountTargetOracle, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type ParsedCreateOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + buyer: TAccountMetas[0]; + seller: TAccountMetas[1]; + listingAccount: TAccountMetas[2]; + orderAccount: TAccountMetas[3]; + escrowAccount: TAccountMetas[4]; + descroVault: TAccountMetas[5]; + /** Pass SystemProgram as placeholder when canonical_oracle is None (stablecoin). */ + canonicalOracle: TAccountMetas[6]; + /** Pass SystemProgram as placeholder when usd_oracle is None or paying canonical. */ + targetOracle: TAccountMetas[7]; + descroProgram: TAccountMetas[8]; + systemProgram: TAccountMetas[9]; + }; + data: CreateOrderInstructionData; +}; + +export function parseCreateOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateOrderInstruction { + if (instruction.accounts.length < 10) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 10, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + buyer: getNextAccount(), + seller: getNextAccount(), + listingAccount: getNextAccount(), + orderAccount: getNextAccount(), + escrowAccount: getNextAccount(), + descroVault: getNextAccount(), + canonicalOracle: getNextAccount(), + targetOracle: getNextAccount(), + descroProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateOrderInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/index.ts b/sdk/src/generated/solisting/src/generated/instructions/index.ts new file mode 100644 index 0000000..6b42259 --- /dev/null +++ b/sdk/src/generated/solisting/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 "./acceptOrder"; +export * from "./cancelOrder"; +export * from "./closeListing"; +export * from "./closeStaleOrder"; +export * from "./createListing"; +export * from "./createOrder"; +export * from "./initialize"; +export * from "./rejectOrder"; +export * from "./updateListing"; diff --git a/sdk/src/generated/solisting/src/generated/instructions/initialize.ts b/sdk/src/generated/solisting/src/generated/instructions/initialize.ts new file mode 100644 index 0000000..f579383 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/initialize.ts @@ -0,0 +1,99 @@ +/** + * 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, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, + type AccountMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const INITIALIZE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 175, 175, 109, 31, 13, 152, 155, 237, +]); + +export function getInitializeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_DISCRIMINATOR); +} + +export type InitializeInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts; + +export type InitializeInstructionData = { discriminator: ReadonlyUint8Array }; + +export type InitializeInstructionDataArgs = {}; + +export function getInitializeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: INITIALIZE_DISCRIMINATOR }), + ); +} + +export function getInitializeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitializeInstructionDataCodec(): FixedSizeCodec< + InitializeInstructionDataArgs, + InitializeInstructionData +> { + return combineCodec( + getInitializeInstructionDataEncoder(), + getInitializeInstructionDataDecoder(), + ); +} + +export type InitializeInput = {}; + +export function getInitializeInstruction< + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>(config?: { + programAddress?: TProgramAddress; +}): InitializeInstruction { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + return Object.freeze({ + data: getInitializeInstructionDataEncoder().encode({}), + programAddress, + } as InitializeInstruction); +} + +export type ParsedInitializeInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, +> = { programAddress: Address; data: InitializeInstructionData }; + +export function parseInitializeInstruction( + instruction: Instruction & InstructionWithData, +): ParsedInitializeInstruction { + return { + programAddress: instruction.programAddress, + data: getInitializeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/rejectOrder.ts b/sdk/src/generated/solisting/src/generated/instructions/rejectOrder.ts new file mode 100644 index 0000000..6383077 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/rejectOrder.ts @@ -0,0 +1,408 @@ +/** + * 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, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getProgramDerivedAddress, + getStructDecoder, + getStructEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type FixedSizeCodec, + type FixedSizeDecoder, + type FixedSizeEncoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type ReadonlyAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + getAddressFromResolvedInstructionAccount, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; + +export const REJECT_ORDER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 216, 154, 15, 81, 179, 14, 75, 62, +]); + +export function getRejectOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + REJECT_ORDER_DISCRIMINATOR, + ); +} + +export type RejectOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountSeller extends string | AccountMeta = string, + TAccountBuyer extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TAccountOrderAccount extends string | AccountMeta = string, + TAccountEscrowAccount extends string | AccountMeta = string, + TAccountVault extends string | AccountMeta = string, + TAccountDescroProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = + "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSeller extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountSeller, + TAccountBuyer extends string + ? WritableAccount + : TAccountBuyer, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + TAccountOrderAccount extends string + ? WritableAccount + : TAccountOrderAccount, + TAccountEscrowAccount extends string + ? WritableAccount + : TAccountEscrowAccount, + TAccountVault extends string + ? WritableAccount + : TAccountVault, + TAccountDescroProgram extends string + ? ReadonlyAccount + : TAccountDescroProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export type RejectOrderInstructionData = { discriminator: ReadonlyUint8Array }; + +export type RejectOrderInstructionDataArgs = {}; + +export function getRejectOrderInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: REJECT_ORDER_DISCRIMINATOR }), + ); +} + +export function getRejectOrderInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getRejectOrderInstructionDataCodec(): FixedSizeCodec< + RejectOrderInstructionDataArgs, + RejectOrderInstructionData +> { + return combineCodec( + getRejectOrderInstructionDataEncoder(), + getRejectOrderInstructionDataDecoder(), + ); +} + +export type RejectOrderAsyncInput< + TAccountSeller extends string = string, + TAccountBuyer extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountVault extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + seller: TransactionSigner; + buyer: Address; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + vault?: Address; + descroProgram: Address; + systemProgram?: Address; +}; + +export async function getRejectOrderInstructionAsync< + TAccountSeller extends string, + TAccountBuyer extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountVault extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: RejectOrderAsyncInput< + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RejectOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + buyer: { value: input.buyer ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Resolve default values. + if (!accounts.vault.value) { + accounts.vault.value = await getProgramDerivedAddress({ + programAddress: + "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">, + seeds: [ + getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])), + getAddressEncoder().encode( + getAddressFromResolvedInstructionAccount( + "escrowAccount", + accounts.escrowAccount.value, + ), + ), + ], + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("vault", accounts.vault), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getRejectOrderInstructionDataEncoder().encode({}), + programAddress, + } as RejectOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type RejectOrderInput< + TAccountSeller extends string = string, + TAccountBuyer extends string = string, + TAccountListingAccount extends string = string, + TAccountOrderAccount extends string = string, + TAccountEscrowAccount extends string = string, + TAccountVault extends string = string, + TAccountDescroProgram extends string = string, + TAccountSystemProgram extends string = string, +> = { + seller: TransactionSigner; + buyer: Address; + listingAccount: Address; + orderAccount: Address; + escrowAccount: Address; + vault: Address; + descroProgram: Address; + systemProgram?: Address; +}; + +export function getRejectOrderInstruction< + TAccountSeller extends string, + TAccountBuyer extends string, + TAccountListingAccount extends string, + TAccountOrderAccount extends string, + TAccountEscrowAccount extends string, + TAccountVault extends string, + TAccountDescroProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: RejectOrderInput< + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): RejectOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: true }, + buyer: { value: input.buyer ?? null, isWritable: true }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + orderAccount: { value: input.orderAccount ?? null, isWritable: true }, + escrowAccount: { value: input.escrowAccount ?? null, isWritable: true }, + vault: { value: input.vault ?? null, isWritable: true }, + descroProgram: { value: input.descroProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("buyer", accounts.buyer), + getAccountMeta("listingAccount", accounts.listingAccount), + getAccountMeta("orderAccount", accounts.orderAccount), + getAccountMeta("escrowAccount", accounts.escrowAccount), + getAccountMeta("vault", accounts.vault), + getAccountMeta("descroProgram", accounts.descroProgram), + getAccountMeta("systemProgram", accounts.systemProgram), + ], + data: getRejectOrderInstructionDataEncoder().encode({}), + programAddress, + } as RejectOrderInstruction< + TProgramAddress, + TAccountSeller, + TAccountBuyer, + TAccountListingAccount, + TAccountOrderAccount, + TAccountEscrowAccount, + TAccountVault, + TAccountDescroProgram, + TAccountSystemProgram + >); +} + +export type ParsedRejectOrderInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + seller: TAccountMetas[0]; + buyer: TAccountMetas[1]; + listingAccount: TAccountMetas[2]; + orderAccount: TAccountMetas[3]; + escrowAccount: TAccountMetas[4]; + vault: TAccountMetas[5]; + descroProgram: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + }; + data: RejectOrderInstructionData; +}; + +export function parseRejectOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedRejectOrderInstruction { + if (instruction.accounts.length < 8) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 8, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + seller: getNextAccount(), + buyer: getNextAccount(), + listingAccount: getNextAccount(), + orderAccount: getNextAccount(), + escrowAccount: getNextAccount(), + vault: getNextAccount(), + descroProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getRejectOrderInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/instructions/updateListing.ts b/sdk/src/generated/solisting/src/generated/instructions/updateListing.ts new file mode 100644 index 0000000..14d8241 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/instructions/updateListing.ts @@ -0,0 +1,262 @@ +/** + * 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 { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getU64Decoder, + getU64Encoder, + getUtf8Decoder, + getUtf8Encoder, + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + SolanaError, + transformEncoder, + type AccountMeta, + type AccountSignerMeta, + type Address, + type Codec, + type Decoder, + type Encoder, + type Instruction, + type InstructionWithAccounts, + type InstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlySignerAccount, + type ReadonlyUint8Array, + type TransactionSigner, + type WritableAccount, +} from "@solana/kit"; +import { + getAccountMetaFactory, + type ResolvedInstructionAccount, +} from "@solana/program-client-core"; +import { SOLISTING_PROGRAM_ADDRESS } from "../programs"; +import { + getSolistingStateAltCurrencyConfigDecoder, + getSolistingStateAltCurrencyConfigEncoder, + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateAltCurrencyConfig, + type SolistingStateAltCurrencyConfigArgs, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "../types"; + +export const UPDATE_LISTING_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 192, 174, 210, 68, 116, 40, 242, 253, +]); + +export function getUpdateListingDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + UPDATE_LISTING_DISCRIMINATOR, + ); +} + +export type UpdateListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountSeller extends string | AccountMeta = string, + TAccountListingAccount extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountSeller extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSeller, + TAccountListingAccount extends string + ? WritableAccount + : TAccountListingAccount, + ...TRemainingAccounts, + ] + >; + +export type UpdateListingInstructionData = { + discriminator: ReadonlyUint8Array; + canonicalCurrency: SolistingStateCurrency; + price: bigint; + canonicalOracle: Option
; + altCurrencies: Array; + acceptedResolvers: Array
; + quantity: number; + metadataUri: string; +}; + +export type UpdateListingInstructionDataArgs = { + canonicalCurrency: SolistingStateCurrencyArgs; + price: number | bigint; + canonicalOracle: OptionOrNullable
; + altCurrencies: Array; + acceptedResolvers: Array
; + quantity: number; + metadataUri: string; +}; + +export function getUpdateListingInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["canonicalCurrency", getSolistingStateCurrencyEncoder()], + ["price", getU64Encoder()], + ["canonicalOracle", getOptionEncoder(getAddressEncoder())], + [ + "altCurrencies", + getArrayEncoder(getSolistingStateAltCurrencyConfigEncoder()), + ], + ["acceptedResolvers", getArrayEncoder(getAddressEncoder())], + ["quantity", getU32Encoder()], + ["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + ]), + (value) => ({ ...value, discriminator: UPDATE_LISTING_DISCRIMINATOR }), + ); +} + +export function getUpdateListingInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["canonicalCurrency", getSolistingStateCurrencyDecoder()], + ["price", getU64Decoder()], + ["canonicalOracle", getOptionDecoder(getAddressDecoder())], + [ + "altCurrencies", + getArrayDecoder(getSolistingStateAltCurrencyConfigDecoder()), + ], + ["acceptedResolvers", getArrayDecoder(getAddressDecoder())], + ["quantity", getU32Decoder()], + ["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + ]); +} + +export function getUpdateListingInstructionDataCodec(): Codec< + UpdateListingInstructionDataArgs, + UpdateListingInstructionData +> { + return combineCodec( + getUpdateListingInstructionDataEncoder(), + getUpdateListingInstructionDataDecoder(), + ); +} + +export type UpdateListingInput< + TAccountSeller extends string = string, + TAccountListingAccount extends string = string, +> = { + seller: TransactionSigner; + listingAccount: Address; + canonicalCurrency: UpdateListingInstructionDataArgs["canonicalCurrency"]; + price: UpdateListingInstructionDataArgs["price"]; + canonicalOracle: UpdateListingInstructionDataArgs["canonicalOracle"]; + altCurrencies: UpdateListingInstructionDataArgs["altCurrencies"]; + acceptedResolvers: UpdateListingInstructionDataArgs["acceptedResolvers"]; + quantity: UpdateListingInstructionDataArgs["quantity"]; + metadataUri: UpdateListingInstructionDataArgs["metadataUri"]; +}; + +export function getUpdateListingInstruction< + TAccountSeller extends string, + TAccountListingAccount extends string, + TProgramAddress extends Address = typeof SOLISTING_PROGRAM_ADDRESS, +>( + input: UpdateListingInput, + config?: { programAddress?: TProgramAddress }, +): UpdateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount +> { + // Program address. + const programAddress = config?.programAddress ?? SOLISTING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + seller: { value: input.seller ?? null, isWritable: false }, + listingAccount: { value: input.listingAccount ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedInstructionAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta("seller", accounts.seller), + getAccountMeta("listingAccount", accounts.listingAccount), + ], + data: getUpdateListingInstructionDataEncoder().encode( + args as UpdateListingInstructionDataArgs, + ), + programAddress, + } as UpdateListingInstruction< + TProgramAddress, + TAccountSeller, + TAccountListingAccount + >); +} + +export type ParsedUpdateListingInstruction< + TProgram extends string = typeof SOLISTING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> = { + programAddress: Address; + accounts: { + seller: TAccountMetas[0]; + listingAccount: TAccountMetas[1]; + }; + data: UpdateListingInstructionData; +}; + +export function parseUpdateListingInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUpdateListingInstruction { + if (instruction.accounts.length < 2) { + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, + { + actualAccountMetas: instruction.accounts.length, + expectedAccountMetas: 2, + }, + ); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { seller: getNextAccount(), listingAccount: getNextAccount() }, + data: getUpdateListingInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/sdk/src/generated/solisting/src/generated/pdas/index.ts b/sdk/src/generated/solisting/src/generated/pdas/index.ts new file mode 100644 index 0000000..62870f9 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/pdas/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./listingAccount"; +export * from "./orderAccount"; diff --git a/sdk/src/generated/solisting/src/generated/pdas/listingAccount.ts b/sdk/src/generated/solisting/src/generated/pdas/listingAccount.ts new file mode 100644 index 0000000..6f1f053 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/pdas/listingAccount.ts @@ -0,0 +1,38 @@ +/** + * 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, + getBytesEncoder, + getProgramDerivedAddress, + getU64Encoder, + type Address, + type ProgramDerivedAddress, +} from "@solana/kit"; + +export type ListingAccountSeeds = { + seller: Address; + listingId: number | bigint; +}; + +export async function findListingAccountPda( + seeds: ListingAccountSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { programAddress = "" as Address<""> } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getBytesEncoder().encode( + new Uint8Array([108, 105, 115, 116, 105, 110, 103]), + ), + getAddressEncoder().encode(seeds.seller), + getU64Encoder().encode(seeds.listingId), + ], + }); +} diff --git a/sdk/src/generated/solisting/src/generated/pdas/orderAccount.ts b/sdk/src/generated/solisting/src/generated/pdas/orderAccount.ts new file mode 100644 index 0000000..fe256e7 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/pdas/orderAccount.ts @@ -0,0 +1,38 @@ +/** + * 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, + getBytesEncoder, + getProgramDerivedAddress, + getU64Encoder, + type Address, + type ProgramDerivedAddress, +} from "@solana/kit"; + +export type OrderAccountSeeds = { + listingAccount: Address; + buyer: Address; + orderId: number | bigint; +}; + +export async function findOrderAccountPda( + seeds: OrderAccountSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { programAddress = "" as Address<""> } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getBytesEncoder().encode(new Uint8Array([111, 114, 100, 101, 114])), + getAddressEncoder().encode(seeds.listingAccount), + getAddressEncoder().encode(seeds.buyer), + getU64Encoder().encode(seeds.orderId), + ], + }); +} diff --git a/sdk/src/generated/solisting/src/generated/programs/index.ts b/sdk/src/generated/solisting/src/generated/programs/index.ts new file mode 100644 index 0000000..36d6b12 --- /dev/null +++ b/sdk/src/generated/solisting/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 "./solisting"; diff --git a/sdk/src/generated/solisting/src/generated/programs/solisting.ts b/sdk/src/generated/solisting/src/generated/programs/solisting.ts new file mode 100644 index 0000000..7698e5b --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/programs/solisting.ts @@ -0,0 +1,497 @@ +/** + * 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 { + assertIsInstructionWithAccounts, + containsBytes, + extendClient, + fixEncoderSize, + getBytesEncoder, + SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, + SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, + SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, + SolanaError, + type Address, + type ClientWithRpc, + type ClientWithTransactionPlanning, + type ClientWithTransactionSending, + type ExtendedClient, + type GetAccountInfoApi, + type GetMultipleAccountsApi, + type Instruction, + type InstructionWithData, + type ReadonlyUint8Array, +} from "@solana/kit"; +import { + addSelfFetchFunctions, + addSelfPlanAndSendFunctions, + type SelfFetchFunctions, + type SelfPlanAndSendFunctions, +} from "@solana/program-client-core"; +import { + getSolistingStateListingAccountCodec, + getSolistingStateOrderAccountCodec, + type SolistingStateListingAccount, + type SolistingStateListingAccountArgs, + type SolistingStateOrderAccount, + type SolistingStateOrderAccountArgs, +} from "../accounts"; +import { + getAcceptOrderInstruction, + getCancelOrderInstructionAsync, + getCloseListingInstruction, + getCloseStaleOrderInstruction, + getCreateListingInstructionAsync, + getCreateOrderInstructionAsync, + getInitializeInstruction, + getRejectOrderInstructionAsync, + getUpdateListingInstruction, + parseAcceptOrderInstruction, + parseCancelOrderInstruction, + parseCloseListingInstruction, + parseCloseStaleOrderInstruction, + parseCreateListingInstruction, + parseCreateOrderInstruction, + parseInitializeInstruction, + parseRejectOrderInstruction, + parseUpdateListingInstruction, + type AcceptOrderInput, + type CancelOrderAsyncInput, + type CloseListingInput, + type CloseStaleOrderInput, + type CreateListingAsyncInput, + type CreateOrderAsyncInput, + type InitializeInput, + type ParsedAcceptOrderInstruction, + type ParsedCancelOrderInstruction, + type ParsedCloseListingInstruction, + type ParsedCloseStaleOrderInstruction, + type ParsedCreateListingInstruction, + type ParsedCreateOrderInstruction, + type ParsedInitializeInstruction, + type ParsedRejectOrderInstruction, + type ParsedUpdateListingInstruction, + type RejectOrderAsyncInput, + type UpdateListingInput, +} from "../instructions"; +import { findListingAccountPda, findOrderAccountPda } from "../pdas"; + +export const SOLISTING_PROGRAM_ADDRESS = "" as Address<"">; + +export enum SolistingAccount { + SolistingStateListingAccount, + SolistingStateOrderAccount, +} + +export function identifySolistingAccount( + account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): SolistingAccount { + const data = "data" in account ? account.data : account; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([59, 89, 136, 25, 21, 196, 183, 13]), + ), + 0, + ) + ) { + return SolistingAccount.SolistingStateListingAccount; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([79, 67, 112, 155, 214, 14, 32, 55]), + ), + 0, + ) + ) { + return SolistingAccount.SolistingStateOrderAccount; + } + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, + { accountData: data, programName: "solisting" }, + ); +} + +export enum SolistingInstruction { + Initialize, + CreateListing, + UpdateListing, + CloseListing, + CreateOrder, + AcceptOrder, + RejectOrder, + CancelOrder, + CloseStaleOrder, +} + +export function identifySolistingInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): SolistingInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([175, 175, 109, 31, 13, 152, 155, 237]), + ), + 0, + ) + ) { + return SolistingInstruction.Initialize; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([18, 168, 45, 24, 191, 31, 117, 54]), + ), + 0, + ) + ) { + return SolistingInstruction.CreateListing; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([192, 174, 210, 68, 116, 40, 242, 253]), + ), + 0, + ) + ) { + return SolistingInstruction.UpdateListing; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([33, 15, 192, 81, 78, 175, 159, 97]), + ), + 0, + ) + ) { + return SolistingInstruction.CloseListing; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([141, 54, 37, 207, 237, 210, 250, 215]), + ), + 0, + ) + ) { + return SolistingInstruction.CreateOrder; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([118, 157, 62, 39, 239, 234, 231, 193]), + ), + 0, + ) + ) { + return SolistingInstruction.AcceptOrder; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([216, 154, 15, 81, 179, 14, 75, 62]), + ), + 0, + ) + ) { + return SolistingInstruction.RejectOrder; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([95, 129, 237, 240, 8, 49, 223, 132]), + ), + 0, + ) + ) { + return SolistingInstruction.CancelOrder; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([167, 12, 32, 252, 132, 106, 131, 250]), + ), + 0, + ) + ) { + return SolistingInstruction.CloseStaleOrder; + } + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, + { instructionData: data, programName: "solisting" }, + ); +} + +export type ParsedSolistingInstruction = + | ({ + instructionType: SolistingInstruction.Initialize; + } & ParsedInitializeInstruction) + | ({ + instructionType: SolistingInstruction.CreateListing; + } & ParsedCreateListingInstruction) + | ({ + instructionType: SolistingInstruction.UpdateListing; + } & ParsedUpdateListingInstruction) + | ({ + instructionType: SolistingInstruction.CloseListing; + } & ParsedCloseListingInstruction) + | ({ + instructionType: SolistingInstruction.CreateOrder; + } & ParsedCreateOrderInstruction) + | ({ + instructionType: SolistingInstruction.AcceptOrder; + } & ParsedAcceptOrderInstruction) + | ({ + instructionType: SolistingInstruction.RejectOrder; + } & ParsedRejectOrderInstruction) + | ({ + instructionType: SolistingInstruction.CancelOrder; + } & ParsedCancelOrderInstruction) + | ({ + instructionType: SolistingInstruction.CloseStaleOrder; + } & ParsedCloseStaleOrderInstruction); + +export function parseSolistingInstruction( + instruction: Instruction & InstructionWithData, +): ParsedSolistingInstruction { + const instructionType = identifySolistingInstruction(instruction); + switch (instructionType) { + case SolistingInstruction.Initialize: { + return { + instructionType: SolistingInstruction.Initialize, + ...parseInitializeInstruction(instruction), + }; + } + case SolistingInstruction.CreateListing: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.CreateListing, + ...parseCreateListingInstruction(instruction), + }; + } + case SolistingInstruction.UpdateListing: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.UpdateListing, + ...parseUpdateListingInstruction(instruction), + }; + } + case SolistingInstruction.CloseListing: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.CloseListing, + ...parseCloseListingInstruction(instruction), + }; + } + case SolistingInstruction.CreateOrder: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.CreateOrder, + ...parseCreateOrderInstruction(instruction), + }; + } + case SolistingInstruction.AcceptOrder: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.AcceptOrder, + ...parseAcceptOrderInstruction(instruction), + }; + } + case SolistingInstruction.RejectOrder: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.RejectOrder, + ...parseRejectOrderInstruction(instruction), + }; + } + case SolistingInstruction.CancelOrder: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.CancelOrder, + ...parseCancelOrderInstruction(instruction), + }; + } + case SolistingInstruction.CloseStaleOrder: { + assertIsInstructionWithAccounts(instruction); + return { + instructionType: SolistingInstruction.CloseStaleOrder, + ...parseCloseStaleOrderInstruction(instruction), + }; + } + default: + throw new SolanaError( + SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, + { + instructionType: instructionType as string, + programName: "solisting", + }, + ); + } +} + +export type SolistingPlugin = { + accounts: SolistingPluginAccounts; + instructions: SolistingPluginInstructions; + pdas: SolistingPluginPdas; + identifyAccount: typeof identifySolistingAccount; + identifyInstruction: typeof identifySolistingInstruction; + parseInstruction: typeof parseSolistingInstruction; +}; + +export type SolistingPluginAccounts = { + solistingStateListingAccount: ReturnType< + typeof getSolistingStateListingAccountCodec + > & + SelfFetchFunctions< + SolistingStateListingAccountArgs, + SolistingStateListingAccount + >; + solistingStateOrderAccount: ReturnType< + typeof getSolistingStateOrderAccountCodec + > & + SelfFetchFunctions< + SolistingStateOrderAccountArgs, + SolistingStateOrderAccount + >; +}; + +export type SolistingPluginInstructions = { + initialize: ( + input: InitializeInput, + ) => ReturnType & SelfPlanAndSendFunctions; + createListing: ( + input: CreateListingAsyncInput, + ) => ReturnType & + SelfPlanAndSendFunctions; + updateListing: ( + input: UpdateListingInput, + ) => ReturnType & + SelfPlanAndSendFunctions; + closeListing: ( + input: CloseListingInput, + ) => ReturnType & SelfPlanAndSendFunctions; + createOrder: ( + input: CreateOrderAsyncInput, + ) => ReturnType & + SelfPlanAndSendFunctions; + acceptOrder: ( + input: AcceptOrderInput, + ) => ReturnType & SelfPlanAndSendFunctions; + rejectOrder: ( + input: RejectOrderAsyncInput, + ) => ReturnType & + SelfPlanAndSendFunctions; + cancelOrder: ( + input: CancelOrderAsyncInput, + ) => ReturnType & + SelfPlanAndSendFunctions; + closeStaleOrder: ( + input: CloseStaleOrderInput, + ) => ReturnType & + SelfPlanAndSendFunctions; +}; + +export type SolistingPluginPdas = { + listingAccount: typeof findListingAccountPda; + orderAccount: typeof findOrderAccountPda; +}; + +export type SolistingPluginRequirements = ClientWithRpc< + GetAccountInfoApi & GetMultipleAccountsApi +> & + ClientWithTransactionPlanning & + ClientWithTransactionSending; + +export function solistingProgram() { + return ( + client: T, + ): ExtendedClient => { + return extendClient(client, { + solisting: { + accounts: { + solistingStateListingAccount: addSelfFetchFunctions( + client, + getSolistingStateListingAccountCodec(), + ), + solistingStateOrderAccount: addSelfFetchFunctions( + client, + getSolistingStateOrderAccountCodec(), + ), + }, + instructions: { + initialize: (input) => + addSelfPlanAndSendFunctions( + client, + getInitializeInstruction(input), + ), + createListing: (input) => + addSelfPlanAndSendFunctions( + client, + getCreateListingInstructionAsync(input), + ), + updateListing: (input) => + addSelfPlanAndSendFunctions( + client, + getUpdateListingInstruction(input), + ), + closeListing: (input) => + addSelfPlanAndSendFunctions( + client, + getCloseListingInstruction(input), + ), + createOrder: (input) => + addSelfPlanAndSendFunctions( + client, + getCreateOrderInstructionAsync(input), + ), + acceptOrder: (input) => + addSelfPlanAndSendFunctions( + client, + getAcceptOrderInstruction(input), + ), + rejectOrder: (input) => + addSelfPlanAndSendFunctions( + client, + getRejectOrderInstructionAsync(input), + ), + cancelOrder: (input) => + addSelfPlanAndSendFunctions( + client, + getCancelOrderInstructionAsync(input), + ), + closeStaleOrder: (input) => + addSelfPlanAndSendFunctions( + client, + getCloseStaleOrderInstruction(input), + ), + }, + pdas: { + listingAccount: findListingAccountPda, + orderAccount: findOrderAccountPda, + }, + identifyAccount: identifySolistingAccount, + identifyInstruction: identifySolistingInstruction, + parseInstruction: parseSolistingInstruction, + }, + }); + }; +} diff --git a/sdk/src/generated/solisting/src/generated/types/index.ts b/sdk/src/generated/solisting/src/generated/types/index.ts new file mode 100644 index 0000000..2694d6d --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/types/index.ts @@ -0,0 +1,10 @@ +/** + * 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 "./solistingStateAltCurrencyConfig"; +export * from "./solistingStateCurrency"; diff --git a/sdk/src/generated/solisting/src/generated/types/solistingStateAltCurrencyConfig.ts b/sdk/src/generated/solisting/src/generated/types/solistingStateAltCurrencyConfig.ts new file mode 100644 index 0000000..48834d2 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/types/solistingStateAltCurrencyConfig.ts @@ -0,0 +1,75 @@ +/** + * 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, + getStructDecoder, + getStructEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type Option, + type OptionOrNullable, +} from "@solana/kit"; +import { + getSolistingStateCurrencyDecoder, + getSolistingStateCurrencyEncoder, + type SolistingStateCurrency, + type SolistingStateCurrencyArgs, +} from "."; + +/** + * Per-alt-currency oracle configuration. Each alt currency carries its own Pyth feed + * because different tokens have different price feeds. + */ +export type SolistingStateAltCurrencyConfig = { + currency: SolistingStateCurrency; + /** + * Pyth V2 PriceFeedAccount for this token priced in USD (TOKEN/USD). + * `None` = treat as a $1.00 USD stablecoin — no oracle account required at order time. + */ + usdOracle: Option
; +}; + +export type SolistingStateAltCurrencyConfigArgs = { + currency: SolistingStateCurrencyArgs; + /** + * Pyth V2 PriceFeedAccount for this token priced in USD (TOKEN/USD). + * `None` = treat as a $1.00 USD stablecoin — no oracle account required at order time. + */ + usdOracle: OptionOrNullable
; +}; + +export function getSolistingStateAltCurrencyConfigEncoder(): Encoder { + return getStructEncoder([ + ["currency", getSolistingStateCurrencyEncoder()], + ["usdOracle", getOptionEncoder(getAddressEncoder())], + ]); +} + +export function getSolistingStateAltCurrencyConfigDecoder(): Decoder { + return getStructDecoder([ + ["currency", getSolistingStateCurrencyDecoder()], + ["usdOracle", getOptionDecoder(getAddressDecoder())], + ]); +} + +export function getSolistingStateAltCurrencyConfigCodec(): Codec< + SolistingStateAltCurrencyConfigArgs, + SolistingStateAltCurrencyConfig +> { + return combineCodec( + getSolistingStateAltCurrencyConfigEncoder(), + getSolistingStateAltCurrencyConfigDecoder(), + ); +} diff --git a/sdk/src/generated/solisting/src/generated/types/solistingStateCurrency.ts b/sdk/src/generated/solisting/src/generated/types/solistingStateCurrency.ts new file mode 100644 index 0000000..9097e26 --- /dev/null +++ b/sdk/src/generated/solisting/src/generated/types/solistingStateCurrency.ts @@ -0,0 +1,103 @@ +/** + * 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, + getDiscriminatedUnionDecoder, + getDiscriminatedUnionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getUnitDecoder, + getUnitEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type GetDiscriminatedUnionVariant, + type GetDiscriminatedUnionVariantContent, +} from "@solana/kit"; + +/** + * Payment currency identifier. Amounts are always in the currency's smallest unit: + * Sol → Lamports (u64), Spl → token units (smallest unit per `decimals`). + */ +export type SolistingStateCurrency = + | { __kind: "Sol" } + | { __kind: "Spl"; mint: Address; decimals: number }; + +export type SolistingStateCurrencyArgs = SolistingStateCurrency; + +export function getSolistingStateCurrencyEncoder(): Encoder { + return getDiscriminatedUnionEncoder([ + ["Sol", getUnitEncoder()], + [ + "Spl", + getStructEncoder([ + ["mint", getAddressEncoder()], + ["decimals", getU8Encoder()], + ]), + ], + ]); +} + +export function getSolistingStateCurrencyDecoder(): Decoder { + return getDiscriminatedUnionDecoder([ + ["Sol", getUnitDecoder()], + [ + "Spl", + getStructDecoder([ + ["mint", getAddressDecoder()], + ["decimals", getU8Decoder()], + ]), + ], + ]); +} + +export function getSolistingStateCurrencyCodec(): Codec< + SolistingStateCurrencyArgs, + SolistingStateCurrency +> { + return combineCodec( + getSolistingStateCurrencyEncoder(), + getSolistingStateCurrencyDecoder(), + ); +} + +// Data Enum Helpers. +export function solistingStateCurrency( + kind: "Sol", +): GetDiscriminatedUnionVariant; +export function solistingStateCurrency( + kind: "Spl", + data: GetDiscriminatedUnionVariantContent< + SolistingStateCurrencyArgs, + "__kind", + "Spl" + >, +): GetDiscriminatedUnionVariant; +export function solistingStateCurrency< + K extends SolistingStateCurrencyArgs["__kind"], + Data, +>(kind: K, data?: Data) { + return Array.isArray(data) + ? { __kind: kind, fields: data } + : { __kind: kind, ...(data ?? {}) }; +} + +export function isSolistingStateCurrency< + K extends SolistingStateCurrency["__kind"], +>( + kind: K, + value: SolistingStateCurrency, +): value is SolistingStateCurrency & { __kind: K } { + return value.__kind === kind; +}