use codama and solana kit

This commit is contained in:
thesn10
2026-05-23 12:30:53 +02:00
parent b4cea41a93
commit 186136722d
43 changed files with 5406 additions and 19 deletions

11
sdk/codama.descro.json Normal file
View File

@@ -0,0 +1,11 @@
{
"idl": "./src/idl/descro.json",
"scripts": {
"js": [
{
"from": "@codama/renderers-js",
"args": ["./src/generated/descro"]
}
]
}
}

11
sdk/codama.registry.json Normal file
View File

@@ -0,0 +1,11 @@
{
"idl": "./src/idl/descro_ext_resolvers.json",
"scripts": {
"js": [
{
"from": "@codama/renderers-js",
"args": ["./src/generated/descro_ext_resolvers"]
}
]
}
}

View File

@@ -4,13 +4,16 @@
"private": true,
"main": "./src/index.ts",
"types": "./src/index.ts",
"scripts": {
"generate": "codama run js --config codama.descro.json && codama run js --config codama.registry.json"
},
"dependencies": {
"@coral-xyz/anchor": "^0.32.1",
"@solana/web3.js": "^1.98.4",
"bn.js": "^5.2.3"
"@solana/kit": "^6.0.0"
},
"devDependencies": {
"@types/bn.js": "^5.2.0",
"@codama/nodes-from-anchor": "^1.4.1",
"@codama/renderers-js": "^2.2.0",
"codama": "^1.6.0",
"typescript": "^6.0.3"
}
}

View File

@@ -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.4.0"
},
"dependencies": {
"@solana/program-client-core": "^6.4.0"
}
}

View File

@@ -0,0 +1,181 @@
/**
* 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,
getOptionDecoder,
getOptionEncoder,
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 Option,
type OptionOrNullable,
type ReadonlyUint8Array,
} from "@solana/kit";
import {
getEscrowStateDecoder,
getEscrowStateEncoder,
type EscrowState,
type EscrowStateArgs,
} from "../types";
export const ESCROW_ACCOUNT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
36, 69, 48, 18, 128, 225, 125, 135,
]);
export function getEscrowAccountDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
ESCROW_ACCOUNT_DISCRIMINATOR,
);
}
export type EscrowAccount = {
discriminator: ReadonlyUint8Array;
seller: Address;
buyer: Address;
amount: bigint;
disputeResolver: Option<Address>;
state: EscrowState;
bump: number;
vaultBump: number;
escrowId: bigint;
};
export type EscrowAccountArgs = {
seller: Address;
buyer: Address;
amount: number | bigint;
disputeResolver: OptionOrNullable<Address>;
state: EscrowStateArgs;
bump: number;
vaultBump: number;
escrowId: number | bigint;
};
/** Gets the encoder for {@link EscrowAccountArgs} account data. */
export function getEscrowAccountEncoder(): Encoder<EscrowAccountArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["seller", getAddressEncoder()],
["buyer", getAddressEncoder()],
["amount", getU64Encoder()],
["disputeResolver", getOptionEncoder(getAddressEncoder())],
["state", getEscrowStateEncoder()],
["bump", getU8Encoder()],
["vaultBump", getU8Encoder()],
["escrowId", getU64Encoder()],
]),
(value) => ({ ...value, discriminator: ESCROW_ACCOUNT_DISCRIMINATOR }),
);
}
/** Gets the decoder for {@link EscrowAccount} account data. */
export function getEscrowAccountDecoder(): Decoder<EscrowAccount> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["seller", getAddressDecoder()],
["buyer", getAddressDecoder()],
["amount", getU64Decoder()],
["disputeResolver", getOptionDecoder(getAddressDecoder())],
["state", getEscrowStateDecoder()],
["bump", getU8Decoder()],
["vaultBump", getU8Decoder()],
["escrowId", getU64Decoder()],
]);
}
/** Gets the codec for {@link EscrowAccount} account data. */
export function getEscrowAccountCodec(): Codec<
EscrowAccountArgs,
EscrowAccount
> {
return combineCodec(getEscrowAccountEncoder(), getEscrowAccountDecoder());
}
export function decodeEscrowAccount<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>,
): Account<EscrowAccount, TAddress>;
export function decodeEscrowAccount<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>,
): MaybeAccount<EscrowAccount, TAddress>;
export function decodeEscrowAccount<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
): Account<EscrowAccount, TAddress> | MaybeAccount<EscrowAccount, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getEscrowAccountDecoder(),
);
}
export async function fetchEscrowAccount<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<EscrowAccount, TAddress>> {
const maybeAccount = await fetchMaybeEscrowAccount(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeEscrowAccount<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<EscrowAccount, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeEscrowAccount(maybeAccount);
}
export async function fetchAllEscrowAccount(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<EscrowAccount>[]> {
const maybeAccounts = await fetchAllMaybeEscrowAccount(
rpc,
addresses,
config,
);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeEscrowAccount(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<EscrowAccount>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeEscrowAccount(maybeAccount));
}

View File

@@ -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 "./escrowAccount";

View File

@@ -0,0 +1,68 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import {
isProgramError,
type Address,
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
type SolanaError,
} from "@solana/kit";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
/** InvalidState: Invalid state for this instruction */
export const DESCRO_ERROR__INVALID_STATE = 0x1770; // 6000
/** Unauthorized: Signer is not authorized */
export const DESCRO_ERROR__UNAUTHORIZED = 0x1771; // 6001
/** NoResolverConfigured: No resolver configured for this escrow */
export const DESCRO_ERROR__NO_RESOLVER_CONFIGURED = 0x1772; // 6002
/** UnauthorizedResolver: Signer is not the configured resolver */
export const DESCRO_ERROR__UNAUTHORIZED_RESOLVER = 0x1773; // 6003
/** Expired: Escrow has expired */
export const DESCRO_ERROR__EXPIRED = 0x1774; // 6004
export type DescroError =
| typeof DESCRO_ERROR__EXPIRED
| typeof DESCRO_ERROR__INVALID_STATE
| typeof DESCRO_ERROR__NO_RESOLVER_CONFIGURED
| typeof DESCRO_ERROR__UNAUTHORIZED
| typeof DESCRO_ERROR__UNAUTHORIZED_RESOLVER;
let descroErrorMessages: Record<DescroError, string> | undefined;
if (process.env["NODE_ENV"] !== "production") {
descroErrorMessages = {
[DESCRO_ERROR__EXPIRED]: `Escrow has expired`,
[DESCRO_ERROR__INVALID_STATE]: `Invalid state for this instruction`,
[DESCRO_ERROR__NO_RESOLVER_CONFIGURED]: `No resolver configured for this escrow`,
[DESCRO_ERROR__UNAUTHORIZED]: `Signer is not authorized`,
[DESCRO_ERROR__UNAUTHORIZED_RESOLVER]: `Signer is not the configured resolver`,
};
}
export function getDescroErrorMessage(code: DescroError): string {
if (process.env["NODE_ENV"] !== "production") {
return (descroErrorMessages as Record<DescroError, string>)[code];
}
return "Error message not available in production bundles.";
}
export function isDescroError<TProgramErrorCode extends DescroError>(
error: unknown,
transactionMessage: {
instructions: Record<number, { programAddress: Address }>;
},
code?: TProgramErrorCode,
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
return isProgramError<TProgramErrorCode>(
error,
transactionMessage,
DESCRO_PROGRAM_ADDRESS,
code,
);
}

View File

@@ -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 "./descro";

View File

@@ -0,0 +1,14 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
export * from "./accounts";
export * from "./errors";
export * from "./instructions";
export * from "./pdas";
export * from "./programs";
export * from "./types";

View File

@@ -0,0 +1,211 @@
/**
* 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 { DESCRO_PROGRAM_ADDRESS } from "../programs";
export const CANCEL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
232, 219, 223, 41, 219, 236, 220, 190,
]);
export function getCancelDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(CANCEL_DISCRIMINATOR);
}
export type CancelInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountSeller extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountSeller extends string
? WritableSignerAccount<TAccountSeller> &
AccountSignerMeta<TAccountSeller>
: TAccountSeller,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type CancelInstructionData = { discriminator: ReadonlyUint8Array };
export type CancelInstructionDataArgs = {};
export function getCancelInstructionDataEncoder(): FixedSizeEncoder<CancelInstructionDataArgs> {
return transformEncoder(
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
(value) => ({ ...value, discriminator: CANCEL_DISCRIMINATOR }),
);
}
export function getCancelInstructionDataDecoder(): FixedSizeDecoder<CancelInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getCancelInstructionDataCodec(): FixedSizeCodec<
CancelInstructionDataArgs,
CancelInstructionData
> {
return combineCodec(
getCancelInstructionDataEncoder(),
getCancelInstructionDataDecoder(),
);
}
export type CancelInput<
TAccountSeller extends string = string,
TAccountEscrowAccount extends string = string,
TAccountSystemProgram extends string = string,
> = {
seller: TransactionSigner<TAccountSeller>;
escrowAccount: Address<TAccountEscrowAccount>;
systemProgram?: Address<TAccountSystemProgram>;
};
export function getCancelInstruction<
TAccountSeller extends string,
TAccountEscrowAccount extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: CancelInput<
TAccountSeller,
TAccountEscrowAccount,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): CancelInstruction<
TProgramAddress,
TAccountSeller,
TAccountEscrowAccount,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
seller: { value: input.seller ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
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("escrowAccount", accounts.escrowAccount),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getCancelInstructionDataEncoder().encode({}),
programAddress,
} as CancelInstruction<
TProgramAddress,
TAccountSeller,
TAccountEscrowAccount,
TAccountSystemProgram
>);
}
export type ParsedCancelInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
seller: TAccountMetas[0];
escrowAccount: TAccountMetas[1];
systemProgram: TAccountMetas[2];
};
data: CancelInstructionData;
};
export function parseCancelInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedCancelInstruction<TProgram, TAccountMetas> {
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(),
escrowAccount: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCancelInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,332 @@
/**
* 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 ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
getAddressFromResolvedInstructionAccount,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { findVaultPda } from "../pdas";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
export const COMPLETE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
0, 77, 224, 147, 136, 25, 88, 76,
]);
export function getCompleteDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(COMPLETE_DISCRIMINATOR);
}
export type CompleteInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountBuyer extends string | AccountMeta<string> = string,
TAccountSeller extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TAccountVault extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountBuyer extends string
? ReadonlySignerAccount<TAccountBuyer> &
AccountSignerMeta<TAccountBuyer>
: TAccountBuyer,
TAccountSeller extends string
? WritableAccount<TAccountSeller>
: TAccountSeller,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
TAccountVault extends string
? WritableAccount<TAccountVault>
: TAccountVault,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type CompleteInstructionData = { discriminator: ReadonlyUint8Array };
export type CompleteInstructionDataArgs = {};
export function getCompleteInstructionDataEncoder(): FixedSizeEncoder<CompleteInstructionDataArgs> {
return transformEncoder(
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
(value) => ({ ...value, discriminator: COMPLETE_DISCRIMINATOR }),
);
}
export function getCompleteInstructionDataDecoder(): FixedSizeDecoder<CompleteInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getCompleteInstructionDataCodec(): FixedSizeCodec<
CompleteInstructionDataArgs,
CompleteInstructionData
> {
return combineCodec(
getCompleteInstructionDataEncoder(),
getCompleteInstructionDataDecoder(),
);
}
export type CompleteAsyncInput<
TAccountBuyer extends string = string,
TAccountSeller extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
buyer: TransactionSigner<TAccountBuyer>;
seller: Address<TAccountSeller>;
escrowAccount: Address<TAccountEscrowAccount>;
vault?: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
};
export async function getCompleteInstructionAsync<
TAccountBuyer extends string,
TAccountSeller extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: CompleteAsyncInput<
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): Promise<
CompleteInstruction<
TProgramAddress,
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
buyer: { value: input.buyer ?? null, isWritable: false },
seller: { value: input.seller ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
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 findVaultPda({
escrowAccount: 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("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getCompleteInstructionDataEncoder().encode({}),
programAddress,
} as CompleteInstruction<
TProgramAddress,
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type CompleteInput<
TAccountBuyer extends string = string,
TAccountSeller extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
buyer: TransactionSigner<TAccountBuyer>;
seller: Address<TAccountSeller>;
escrowAccount: Address<TAccountEscrowAccount>;
vault: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
};
export function getCompleteInstruction<
TAccountBuyer extends string,
TAccountSeller extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: CompleteInput<
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): CompleteInstruction<
TProgramAddress,
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
buyer: { value: input.buyer ?? null, isWritable: false },
seller: { value: input.seller ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
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("seller", accounts.seller),
getAccountMeta("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getCompleteInstructionDataEncoder().encode({}),
programAddress,
} as CompleteInstruction<
TProgramAddress,
TAccountBuyer,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type ParsedCompleteInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
buyer: TAccountMetas[0];
seller: TAccountMetas[1];
escrowAccount: TAccountMetas[2];
vault: TAccountMetas[3];
systemProgram: TAccountMetas[4];
};
data: CompleteInstructionData;
};
export function parseCompleteInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedCompleteInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
{
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 5,
},
);
}
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(),
escrowAccount: getNextAccount(),
vault: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCompleteInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,385 @@
/**
* 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,
getOptionDecoder,
getOptionEncoder,
getStructDecoder,
getStructEncoder,
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 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 { findEscrowAccountPda, findVaultPda } from "../pdas";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
export const CREATE_ESCROW_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
253, 215, 165, 116, 36, 108, 68, 80,
]);
export function getCreateEscrowDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
CREATE_ESCROW_DISCRIMINATOR,
);
}
export type CreateEscrowInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountSeller extends string | AccountMeta<string> = string,
TAccountBuyer extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TAccountVault extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountSeller extends string
? WritableSignerAccount<TAccountSeller> &
AccountSignerMeta<TAccountSeller>
: TAccountSeller,
TAccountBuyer extends string
? ReadonlyAccount<TAccountBuyer>
: TAccountBuyer,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
TAccountVault extends string
? WritableAccount<TAccountVault>
: TAccountVault,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type CreateEscrowInstructionData = {
discriminator: ReadonlyUint8Array;
amount: bigint;
disputeResolver: Option<Address>;
escrowId: bigint;
};
export type CreateEscrowInstructionDataArgs = {
amount: number | bigint;
disputeResolver: OptionOrNullable<Address>;
escrowId: number | bigint;
};
export function getCreateEscrowInstructionDataEncoder(): Encoder<CreateEscrowInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["amount", getU64Encoder()],
["disputeResolver", getOptionEncoder(getAddressEncoder())],
["escrowId", getU64Encoder()],
]),
(value) => ({ ...value, discriminator: CREATE_ESCROW_DISCRIMINATOR }),
);
}
export function getCreateEscrowInstructionDataDecoder(): Decoder<CreateEscrowInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["amount", getU64Decoder()],
["disputeResolver", getOptionDecoder(getAddressDecoder())],
["escrowId", getU64Decoder()],
]);
}
export function getCreateEscrowInstructionDataCodec(): Codec<
CreateEscrowInstructionDataArgs,
CreateEscrowInstructionData
> {
return combineCodec(
getCreateEscrowInstructionDataEncoder(),
getCreateEscrowInstructionDataDecoder(),
);
}
export type CreateEscrowAsyncInput<
TAccountSeller extends string = string,
TAccountBuyer extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
seller: TransactionSigner<TAccountSeller>;
buyer: Address<TAccountBuyer>;
escrowAccount?: Address<TAccountEscrowAccount>;
vault?: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
amount: CreateEscrowInstructionDataArgs["amount"];
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
escrowId: CreateEscrowInstructionDataArgs["escrowId"];
};
export async function getCreateEscrowInstructionAsync<
TAccountSeller extends string,
TAccountBuyer extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: CreateEscrowAsyncInput<
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): Promise<
CreateEscrowInstruction<
TProgramAddress,
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
seller: { value: input.seller ?? null, isWritable: true },
buyer: { value: input.buyer ?? null, isWritable: false },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? 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.escrowAccount.value) {
accounts.escrowAccount.value = await findEscrowAccountPda({
seller: getAddressFromResolvedInstructionAccount(
"seller",
accounts.seller.value,
),
escrowId: getNonNullResolvedInstructionInput("escrowId", args.escrowId),
});
}
if (!accounts.vault.value) {
accounts.vault.value = await findVaultPda({
escrowAccount: 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("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getCreateEscrowInstructionDataEncoder().encode(
args as CreateEscrowInstructionDataArgs,
),
programAddress,
} as CreateEscrowInstruction<
TProgramAddress,
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type CreateEscrowInput<
TAccountSeller extends string = string,
TAccountBuyer extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
seller: TransactionSigner<TAccountSeller>;
buyer: Address<TAccountBuyer>;
escrowAccount: Address<TAccountEscrowAccount>;
vault: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
amount: CreateEscrowInstructionDataArgs["amount"];
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
escrowId: CreateEscrowInstructionDataArgs["escrowId"];
};
export function getCreateEscrowInstruction<
TAccountSeller extends string,
TAccountBuyer extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: CreateEscrowInput<
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): CreateEscrowInstruction<
TProgramAddress,
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
seller: { value: input.seller ?? null, isWritable: true },
buyer: { value: input.buyer ?? null, isWritable: false },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? 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("buyer", accounts.buyer),
getAccountMeta("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getCreateEscrowInstructionDataEncoder().encode(
args as CreateEscrowInstructionDataArgs,
),
programAddress,
} as CreateEscrowInstruction<
TProgramAddress,
TAccountSeller,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type ParsedCreateEscrowInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
seller: TAccountMetas[0];
buyer: TAccountMetas[1];
escrowAccount: TAccountMetas[2];
vault: TAccountMetas[3];
systemProgram: TAccountMetas[4];
};
data: CreateEscrowInstructionData;
};
export function parseCreateEscrowInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedCreateEscrowInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
{
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 5,
},
);
}
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(),
escrowAccount: getNextAccount(),
vault: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCreateEscrowInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,310 @@
/**
* 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,
getAddressFromResolvedInstructionAccount,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { findVaultPda } from "../pdas";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
export const DEPOSIT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
242, 35, 198, 137, 82, 225, 242, 182,
]);
export function getDepositDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(DEPOSIT_DISCRIMINATOR);
}
export type DepositInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountBuyer extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TAccountVault extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountBuyer extends string
? WritableSignerAccount<TAccountBuyer> &
AccountSignerMeta<TAccountBuyer>
: TAccountBuyer,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
TAccountVault extends string
? WritableAccount<TAccountVault>
: TAccountVault,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type DepositInstructionData = { discriminator: ReadonlyUint8Array };
export type DepositInstructionDataArgs = {};
export function getDepositInstructionDataEncoder(): FixedSizeEncoder<DepositInstructionDataArgs> {
return transformEncoder(
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
(value) => ({ ...value, discriminator: DEPOSIT_DISCRIMINATOR }),
);
}
export function getDepositInstructionDataDecoder(): FixedSizeDecoder<DepositInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getDepositInstructionDataCodec(): FixedSizeCodec<
DepositInstructionDataArgs,
DepositInstructionData
> {
return combineCodec(
getDepositInstructionDataEncoder(),
getDepositInstructionDataDecoder(),
);
}
export type DepositAsyncInput<
TAccountBuyer extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
buyer: TransactionSigner<TAccountBuyer>;
escrowAccount: Address<TAccountEscrowAccount>;
vault?: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
};
export async function getDepositInstructionAsync<
TAccountBuyer extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: DepositAsyncInput<
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): Promise<
DepositInstruction<
TProgramAddress,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
buyer: { value: input.buyer ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
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 findVaultPda({
escrowAccount: 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("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getDepositInstructionDataEncoder().encode({}),
programAddress,
} as DepositInstruction<
TProgramAddress,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type DepositInput<
TAccountBuyer extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountSystemProgram extends string = string,
> = {
buyer: TransactionSigner<TAccountBuyer>;
escrowAccount: Address<TAccountEscrowAccount>;
vault: Address<TAccountVault>;
systemProgram?: Address<TAccountSystemProgram>;
};
export function getDepositInstruction<
TAccountBuyer extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: DepositInput<
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): DepositInstruction<
TProgramAddress,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
buyer: { value: input.buyer ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
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("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getDepositInstructionDataEncoder().encode({}),
programAddress,
} as DepositInstruction<
TProgramAddress,
TAccountBuyer,
TAccountEscrowAccount,
TAccountVault,
TAccountSystemProgram
>);
}
export type ParsedDepositInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
buyer: TAccountMetas[0];
escrowAccount: TAccountMetas[1];
vault: TAccountMetas[2];
systemProgram: TAccountMetas[3];
};
data: DepositInstructionData;
};
export function parseDepositInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedDepositInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 4) {
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
{
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 4,
},
);
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
buyer: getNextAccount(),
escrowAccount: getNextAccount(),
vault: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getDepositInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,183 @@
/**
* 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 ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
export const DISPUTE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
216, 92, 128, 146, 202, 85, 135, 73,
]);
export function getDisputeDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(DISPUTE_DISCRIMINATOR);
}
export type DisputeInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountInitiator extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountInitiator extends string
? ReadonlySignerAccount<TAccountInitiator> &
AccountSignerMeta<TAccountInitiator>
: TAccountInitiator,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
...TRemainingAccounts,
]
>;
export type DisputeInstructionData = { discriminator: ReadonlyUint8Array };
export type DisputeInstructionDataArgs = {};
export function getDisputeInstructionDataEncoder(): FixedSizeEncoder<DisputeInstructionDataArgs> {
return transformEncoder(
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
(value) => ({ ...value, discriminator: DISPUTE_DISCRIMINATOR }),
);
}
export function getDisputeInstructionDataDecoder(): FixedSizeDecoder<DisputeInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getDisputeInstructionDataCodec(): FixedSizeCodec<
DisputeInstructionDataArgs,
DisputeInstructionData
> {
return combineCodec(
getDisputeInstructionDataEncoder(),
getDisputeInstructionDataDecoder(),
);
}
export type DisputeInput<
TAccountInitiator extends string = string,
TAccountEscrowAccount extends string = string,
> = {
initiator: TransactionSigner<TAccountInitiator>;
escrowAccount: Address<TAccountEscrowAccount>;
};
export function getDisputeInstruction<
TAccountInitiator extends string,
TAccountEscrowAccount extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: DisputeInput<TAccountInitiator, TAccountEscrowAccount>,
config?: { programAddress?: TProgramAddress },
): DisputeInstruction<
TProgramAddress,
TAccountInitiator,
TAccountEscrowAccount
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
initiator: { value: input.initiator ?? null, isWritable: false },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedInstructionAccount
>;
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("initiator", accounts.initiator),
getAccountMeta("escrowAccount", accounts.escrowAccount),
],
data: getDisputeInstructionDataEncoder().encode({}),
programAddress,
} as DisputeInstruction<
TProgramAddress,
TAccountInitiator,
TAccountEscrowAccount
>);
}
export type ParsedDisputeInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
initiator: TAccountMetas[0];
escrowAccount: TAccountMetas[1];
};
data: DisputeInstructionData;
};
export function parseDisputeInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedDisputeInstruction<TProgram, TAccountMetas> {
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: { initiator: getNextAccount(), escrowAccount: getNextAccount() },
data: getDisputeInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,14 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
export * from "./cancel";
export * from "./complete";
export * from "./createEscrow";
export * from "./deposit";
export * from "./dispute";
export * from "./resolve";

View File

@@ -0,0 +1,460 @@
/**
* 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 ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
getAddressFromResolvedInstructionAccount,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { findEscrowAuthorityPda, findVaultPda } from "../pdas";
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
import {
getWinnerDecoder,
getWinnerEncoder,
type Winner,
type WinnerArgs,
} from "../types";
export const RESOLVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
246, 150, 236, 206, 108, 63, 58, 10,
]);
export function getResolveDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(RESOLVE_DISCRIMINATOR);
}
export type ResolveInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountResolver extends string | AccountMeta<string> = string,
TAccountWinner extends string | AccountMeta<string> = string,
TAccountSeller extends string | AccountMeta<string> = string,
TAccountEscrowAccount extends string | AccountMeta<string> = string,
TAccountVault extends string | AccountMeta<string> = string,
TAccountResolverEntry extends string | AccountMeta<string> = string,
TAccountEscrowAuthority extends string | AccountMeta<string> = string,
TAccountRegistryProgram extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountResolver extends string
? ReadonlySignerAccount<TAccountResolver> &
AccountSignerMeta<TAccountResolver>
: TAccountResolver,
TAccountWinner extends string
? WritableAccount<TAccountWinner>
: TAccountWinner,
TAccountSeller extends string
? WritableAccount<TAccountSeller>
: TAccountSeller,
TAccountEscrowAccount extends string
? WritableAccount<TAccountEscrowAccount>
: TAccountEscrowAccount,
TAccountVault extends string
? WritableAccount<TAccountVault>
: TAccountVault,
TAccountResolverEntry extends string
? WritableAccount<TAccountResolverEntry>
: TAccountResolverEntry,
TAccountEscrowAuthority extends string
? ReadonlyAccount<TAccountEscrowAuthority>
: TAccountEscrowAuthority,
TAccountRegistryProgram extends string
? ReadonlyAccount<TAccountRegistryProgram>
: TAccountRegistryProgram,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type ResolveInstructionData = {
discriminator: ReadonlyUint8Array;
winner: Winner;
};
export type ResolveInstructionDataArgs = { winner: WinnerArgs };
export function getResolveInstructionDataEncoder(): FixedSizeEncoder<ResolveInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["winner", getWinnerEncoder()],
]),
(value) => ({ ...value, discriminator: RESOLVE_DISCRIMINATOR }),
);
}
export function getResolveInstructionDataDecoder(): FixedSizeDecoder<ResolveInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["winner", getWinnerDecoder()],
]);
}
export function getResolveInstructionDataCodec(): FixedSizeCodec<
ResolveInstructionDataArgs,
ResolveInstructionData
> {
return combineCodec(
getResolveInstructionDataEncoder(),
getResolveInstructionDataDecoder(),
);
}
export type ResolveAsyncInput<
TAccountResolver extends string = string,
TAccountWinner extends string = string,
TAccountSeller extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountResolverEntry extends string = string,
TAccountEscrowAuthority extends string = string,
TAccountRegistryProgram extends string = string,
TAccountSystemProgram extends string = string,
> = {
resolver: TransactionSigner<TAccountResolver>;
winner: Address<TAccountWinner>;
seller: Address<TAccountSeller>;
escrowAccount: Address<TAccountEscrowAccount>;
vault?: Address<TAccountVault>;
resolverEntry: Address<TAccountResolverEntry>;
escrowAuthority?: Address<TAccountEscrowAuthority>;
registryProgram: Address<TAccountRegistryProgram>;
systemProgram?: Address<TAccountSystemProgram>;
winnerArg: ResolveInstructionDataArgs["winner"];
};
export async function getResolveInstructionAsync<
TAccountResolver extends string,
TAccountWinner extends string,
TAccountSeller extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountResolverEntry extends string,
TAccountEscrowAuthority extends string,
TAccountRegistryProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: ResolveAsyncInput<
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): Promise<
ResolveInstruction<
TProgramAddress,
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
>
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
resolver: { value: input.resolver ?? null, isWritable: false },
winner: { value: input.winner ?? null, isWritable: true },
seller: { value: input.seller ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
resolverEntry: { value: input.resolverEntry ?? null, isWritable: true },
escrowAuthority: {
value: input.escrowAuthority ?? null,
isWritable: false,
},
registryProgram: {
value: input.registryProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedInstructionAccount
>;
// Original args.
const args = { ...input, winner: input.winnerArg };
// Resolve default values.
if (!accounts.vault.value) {
accounts.vault.value = await findVaultPda({
escrowAccount: getAddressFromResolvedInstructionAccount(
"escrowAccount",
accounts.escrowAccount.value,
),
});
}
if (!accounts.escrowAuthority.value) {
accounts.escrowAuthority.value = await findEscrowAuthorityPda();
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("resolver", accounts.resolver),
getAccountMeta("winner", accounts.winner),
getAccountMeta("seller", accounts.seller),
getAccountMeta("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("resolverEntry", accounts.resolverEntry),
getAccountMeta("escrowAuthority", accounts.escrowAuthority),
getAccountMeta("registryProgram", accounts.registryProgram),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getResolveInstructionDataEncoder().encode(
args as ResolveInstructionDataArgs,
),
programAddress,
} as ResolveInstruction<
TProgramAddress,
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
>);
}
export type ResolveInput<
TAccountResolver extends string = string,
TAccountWinner extends string = string,
TAccountSeller extends string = string,
TAccountEscrowAccount extends string = string,
TAccountVault extends string = string,
TAccountResolverEntry extends string = string,
TAccountEscrowAuthority extends string = string,
TAccountRegistryProgram extends string = string,
TAccountSystemProgram extends string = string,
> = {
resolver: TransactionSigner<TAccountResolver>;
winner: Address<TAccountWinner>;
seller: Address<TAccountSeller>;
escrowAccount: Address<TAccountEscrowAccount>;
vault: Address<TAccountVault>;
resolverEntry: Address<TAccountResolverEntry>;
escrowAuthority: Address<TAccountEscrowAuthority>;
registryProgram: Address<TAccountRegistryProgram>;
systemProgram?: Address<TAccountSystemProgram>;
winnerArg: ResolveInstructionDataArgs["winner"];
};
export function getResolveInstruction<
TAccountResolver extends string,
TAccountWinner extends string,
TAccountSeller extends string,
TAccountEscrowAccount extends string,
TAccountVault extends string,
TAccountResolverEntry extends string,
TAccountEscrowAuthority extends string,
TAccountRegistryProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
>(
input: ResolveInput<
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): ResolveInstruction<
TProgramAddress,
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
> {
// Program address.
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
resolver: { value: input.resolver ?? null, isWritable: false },
winner: { value: input.winner ?? null, isWritable: true },
seller: { value: input.seller ?? null, isWritable: true },
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
vault: { value: input.vault ?? null, isWritable: true },
resolverEntry: { value: input.resolverEntry ?? null, isWritable: true },
escrowAuthority: {
value: input.escrowAuthority ?? null,
isWritable: false,
},
registryProgram: {
value: input.registryProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedInstructionAccount
>;
// Original args.
const args = { ...input, winner: input.winnerArg };
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("resolver", accounts.resolver),
getAccountMeta("winner", accounts.winner),
getAccountMeta("seller", accounts.seller),
getAccountMeta("escrowAccount", accounts.escrowAccount),
getAccountMeta("vault", accounts.vault),
getAccountMeta("resolverEntry", accounts.resolverEntry),
getAccountMeta("escrowAuthority", accounts.escrowAuthority),
getAccountMeta("registryProgram", accounts.registryProgram),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getResolveInstructionDataEncoder().encode(
args as ResolveInstructionDataArgs,
),
programAddress,
} as ResolveInstruction<
TProgramAddress,
TAccountResolver,
TAccountWinner,
TAccountSeller,
TAccountEscrowAccount,
TAccountVault,
TAccountResolverEntry,
TAccountEscrowAuthority,
TAccountRegistryProgram,
TAccountSystemProgram
>);
}
export type ParsedResolveInstruction<
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
resolver: TAccountMetas[0];
winner: TAccountMetas[1];
seller: TAccountMetas[2];
escrowAccount: TAccountMetas[3];
vault: TAccountMetas[4];
resolverEntry: TAccountMetas[5];
escrowAuthority: TAccountMetas[6];
registryProgram: TAccountMetas[7];
systemProgram: TAccountMetas[8];
};
data: ResolveInstructionData;
};
export function parseResolveInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedResolveInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 9) {
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
{
actualAccountMetas: instruction.accounts.length,
expectedAccountMetas: 9,
},
);
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
resolver: getNextAccount(),
winner: getNextAccount(),
seller: getNextAccount(),
escrowAccount: getNextAccount(),
vault: getNextAccount(),
resolverEntry: getNextAccount(),
escrowAuthority: getNextAccount(),
registryProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getResolveInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -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 EscrowAccountSeeds = {
seller: Address;
escrowId: number | bigint;
};
export async function findEscrowAccountPda(
seeds: EscrowAccountSeeds,
config: { programAddress?: Address | undefined } = {},
): Promise<ProgramDerivedAddress> {
const {
programAddress = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([101, 115, 99, 114, 111, 119])),
getAddressEncoder().encode(seeds.seller),
getU64Encoder().encode(seeds.escrowId),
],
});
}

View File

@@ -0,0 +1,33 @@
/**
* 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 {
getBytesEncoder,
getProgramDerivedAddress,
type Address,
type ProgramDerivedAddress,
} from "@solana/kit";
export async function findEscrowAuthorityPda(
config: { programAddress?: Address | undefined } = {},
): Promise<ProgramDerivedAddress> {
const {
programAddress = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(
new Uint8Array([
101, 115, 99, 114, 111, 119, 95, 97, 117, 116, 104, 111, 114, 105,
116, 121,
]),
),
],
});
}

View File

@@ -0,0 +1,11 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
export * from "./escrowAccount";
export * from "./escrowAuthority";
export * from "./vault";

View File

@@ -0,0 +1,35 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import {
getAddressEncoder,
getBytesEncoder,
getProgramDerivedAddress,
type Address,
type ProgramDerivedAddress,
} from "@solana/kit";
export type VaultSeeds = {
escrowAccount: Address;
};
export async function findVaultPda(
seeds: VaultSeeds,
config: { programAddress?: Address | undefined } = {},
): Promise<ProgramDerivedAddress> {
const {
programAddress = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([118, 97, 117, 108, 116])),
getAddressEncoder().encode(seeds.escrowAccount),
],
});
}

View File

@@ -0,0 +1,351 @@
/**
* 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 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 {
getEscrowAccountCodec,
type EscrowAccount,
type EscrowAccountArgs,
} from "../accounts";
import {
getCancelInstruction,
getCompleteInstructionAsync,
getCreateEscrowInstructionAsync,
getDepositInstructionAsync,
getDisputeInstruction,
getResolveInstructionAsync,
parseCancelInstruction,
parseCompleteInstruction,
parseCreateEscrowInstruction,
parseDepositInstruction,
parseDisputeInstruction,
parseResolveInstruction,
type CancelInput,
type CompleteAsyncInput,
type CreateEscrowAsyncInput,
type DepositAsyncInput,
type DisputeInput,
type ParsedCancelInstruction,
type ParsedCompleteInstruction,
type ParsedCreateEscrowInstruction,
type ParsedDepositInstruction,
type ParsedDisputeInstruction,
type ParsedResolveInstruction,
type ResolveAsyncInput,
} from "../instructions";
import {
findEscrowAccountPda,
findEscrowAuthorityPda,
findVaultPda,
} from "../pdas";
export const DESCRO_PROGRAM_ADDRESS =
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">;
export enum DescroAccount {
EscrowAccount,
}
export function identifyDescroAccount(
account: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): DescroAccount {
const data = "data" in account ? account.data : account;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([36, 69, 48, 18, 128, 225, 125, 135]),
),
0,
)
) {
return DescroAccount.EscrowAccount;
}
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT,
{ accountData: data, programName: "descro" },
);
}
export enum DescroInstruction {
Cancel,
Complete,
CreateEscrow,
Deposit,
Dispute,
Resolve,
}
export function identifyDescroInstruction(
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): DescroInstruction {
const data = "data" in instruction ? instruction.data : instruction;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([232, 219, 223, 41, 219, 236, 220, 190]),
),
0,
)
) {
return DescroInstruction.Cancel;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([0, 77, 224, 147, 136, 25, 88, 76]),
),
0,
)
) {
return DescroInstruction.Complete;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([253, 215, 165, 116, 36, 108, 68, 80]),
),
0,
)
) {
return DescroInstruction.CreateEscrow;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([242, 35, 198, 137, 82, 225, 242, 182]),
),
0,
)
) {
return DescroInstruction.Deposit;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([216, 92, 128, 146, 202, 85, 135, 73]),
),
0,
)
) {
return DescroInstruction.Dispute;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([246, 150, 236, 206, 108, 63, 58, 10]),
),
0,
)
) {
return DescroInstruction.Resolve;
}
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
{ instructionData: data, programName: "descro" },
);
}
export type ParsedDescroInstruction<
TProgram extends string = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3",
> =
| ({
instructionType: DescroInstruction.Cancel;
} & ParsedCancelInstruction<TProgram>)
| ({
instructionType: DescroInstruction.Complete;
} & ParsedCompleteInstruction<TProgram>)
| ({
instructionType: DescroInstruction.CreateEscrow;
} & ParsedCreateEscrowInstruction<TProgram>)
| ({
instructionType: DescroInstruction.Deposit;
} & ParsedDepositInstruction<TProgram>)
| ({
instructionType: DescroInstruction.Dispute;
} & ParsedDisputeInstruction<TProgram>)
| ({
instructionType: DescroInstruction.Resolve;
} & ParsedResolveInstruction<TProgram>);
export function parseDescroInstruction<TProgram extends string>(
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
): ParsedDescroInstruction<TProgram> {
const instructionType = identifyDescroInstruction(instruction);
switch (instructionType) {
case DescroInstruction.Cancel: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.Cancel,
...parseCancelInstruction(instruction),
};
}
case DescroInstruction.Complete: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.Complete,
...parseCompleteInstruction(instruction),
};
}
case DescroInstruction.CreateEscrow: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.CreateEscrow,
...parseCreateEscrowInstruction(instruction),
};
}
case DescroInstruction.Deposit: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.Deposit,
...parseDepositInstruction(instruction),
};
}
case DescroInstruction.Dispute: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.Dispute,
...parseDisputeInstruction(instruction),
};
}
case DescroInstruction.Resolve: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroInstruction.Resolve,
...parseResolveInstruction(instruction),
};
}
default:
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
{ instructionType: instructionType as string, programName: "descro" },
);
}
}
export type DescroPlugin = {
accounts: DescroPluginAccounts;
instructions: DescroPluginInstructions;
pdas: DescroPluginPdas;
};
export type DescroPluginAccounts = {
escrowAccount: ReturnType<typeof getEscrowAccountCodec> &
SelfFetchFunctions<EscrowAccountArgs, EscrowAccount>;
};
export type DescroPluginInstructions = {
cancel: (
input: CancelInput,
) => ReturnType<typeof getCancelInstruction> & SelfPlanAndSendFunctions;
complete: (
input: CompleteAsyncInput,
) => ReturnType<typeof getCompleteInstructionAsync> &
SelfPlanAndSendFunctions;
createEscrow: (
input: CreateEscrowAsyncInput,
) => ReturnType<typeof getCreateEscrowInstructionAsync> &
SelfPlanAndSendFunctions;
deposit: (
input: DepositAsyncInput,
) => ReturnType<typeof getDepositInstructionAsync> & SelfPlanAndSendFunctions;
dispute: (
input: DisputeInput,
) => ReturnType<typeof getDisputeInstruction> & SelfPlanAndSendFunctions;
resolve: (
input: ResolveAsyncInput,
) => ReturnType<typeof getResolveInstructionAsync> & SelfPlanAndSendFunctions;
};
export type DescroPluginPdas = {
vault: typeof findVaultPda;
escrowAccount: typeof findEscrowAccountPda;
escrowAuthority: typeof findEscrowAuthorityPda;
};
export type DescroPluginRequirements = ClientWithRpc<
GetAccountInfoApi & GetMultipleAccountsApi
> &
ClientWithTransactionPlanning &
ClientWithTransactionSending;
export function descroProgram() {
return <T extends DescroPluginRequirements>(
client: T,
): Omit<T, "descro"> & { descro: DescroPlugin } => {
return extendClient(client, {
descro: <DescroPlugin>{
accounts: {
escrowAccount: addSelfFetchFunctions(client, getEscrowAccountCodec()),
},
instructions: {
cancel: (input) =>
addSelfPlanAndSendFunctions(client, getCancelInstruction(input)),
complete: (input) =>
addSelfPlanAndSendFunctions(
client,
getCompleteInstructionAsync(input),
),
createEscrow: (input) =>
addSelfPlanAndSendFunctions(
client,
getCreateEscrowInstructionAsync(input),
),
deposit: (input) =>
addSelfPlanAndSendFunctions(
client,
getDepositInstructionAsync(input),
),
dispute: (input) =>
addSelfPlanAndSendFunctions(client, getDisputeInstruction(input)),
resolve: (input) =>
addSelfPlanAndSendFunctions(
client,
getResolveInstructionAsync(input),
),
},
pdas: {
vault: findVaultPda,
escrowAccount: findEscrowAccountPda,
escrowAuthority: findEscrowAuthorityPda,
},
},
});
};
}

View File

@@ -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 "./descro";

View File

@@ -0,0 +1,41 @@
/**
* 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,
getEnumDecoder,
getEnumEncoder,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
} from "@solana/kit";
export enum EscrowState {
AwaitingDeposit,
Active,
Disputed,
Complete,
Cancelled,
}
export type EscrowStateArgs = EscrowState;
export function getEscrowStateEncoder(): FixedSizeEncoder<EscrowStateArgs> {
return getEnumEncoder(EscrowState);
}
export function getEscrowStateDecoder(): FixedSizeDecoder<EscrowState> {
return getEnumDecoder(EscrowState);
}
export function getEscrowStateCodec(): FixedSizeCodec<
EscrowStateArgs,
EscrowState
> {
return combineCodec(getEscrowStateEncoder(), getEscrowStateDecoder());
}

View File

@@ -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 "./escrowState";
export * from "./winner";

View File

@@ -0,0 +1,35 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import {
combineCodec,
getEnumDecoder,
getEnumEncoder,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
} from "@solana/kit";
export enum Winner {
Buyer,
Seller,
}
export type WinnerArgs = Winner;
export function getWinnerEncoder(): FixedSizeEncoder<WinnerArgs> {
return getEnumEncoder(Winner);
}
export function getWinnerDecoder(): FixedSizeDecoder<Winner> {
return getEnumDecoder(Winner);
}
export function getWinnerCodec(): FixedSizeCodec<WinnerArgs, Winner> {
return combineCodec(getWinnerEncoder(), getWinnerDecoder());
}

View File

@@ -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.4.0"
},
"dependencies": {
"@solana/program-client-core": "^6.4.0"
}
}

View File

@@ -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 "./resolverEntry";

View File

@@ -0,0 +1,197 @@
/**
* 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,
getBytesDecoder,
getBytesEncoder,
getI64Decoder,
getI64Encoder,
getStructDecoder,
getStructEncoder,
getU16Decoder,
getU16Encoder,
getU32Decoder,
getU32Encoder,
getU64Decoder,
getU64Encoder,
getUtf8Decoder,
getUtf8Encoder,
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 {
getResolverTypeDecoder,
getResolverTypeEncoder,
type ResolverType,
type ResolverTypeArgs,
} from "../types";
export const RESOLVER_ENTRY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
0, 60, 55, 58, 157, 135, 51, 191,
]);
export function getResolverEntryDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
RESOLVER_ENTRY_DISCRIMINATOR,
);
}
export type ResolverEntry = {
discriminator: ReadonlyUint8Array;
authority: Address;
resolverType: ResolverType;
name: string;
description: string;
feeBps: number;
feeRecipient: Address;
metadataUri: string;
totalResolved: bigint;
ruledForBuyer: bigint;
ruledForSeller: bigint;
registeredAt: bigint;
};
export type ResolverEntryArgs = {
authority: Address;
resolverType: ResolverTypeArgs;
name: string;
description: string;
feeBps: number;
feeRecipient: Address;
metadataUri: string;
totalResolved: number | bigint;
ruledForBuyer: number | bigint;
ruledForSeller: number | bigint;
registeredAt: number | bigint;
};
/** Gets the encoder for {@link ResolverEntryArgs} account data. */
export function getResolverEntryEncoder(): Encoder<ResolverEntryArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["authority", getAddressEncoder()],
["resolverType", getResolverTypeEncoder()],
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["feeBps", getU16Encoder()],
["feeRecipient", getAddressEncoder()],
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["totalResolved", getU64Encoder()],
["ruledForBuyer", getU64Encoder()],
["ruledForSeller", getU64Encoder()],
["registeredAt", getI64Encoder()],
]),
(value) => ({ ...value, discriminator: RESOLVER_ENTRY_DISCRIMINATOR }),
);
}
/** Gets the decoder for {@link ResolverEntry} account data. */
export function getResolverEntryDecoder(): Decoder<ResolverEntry> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["authority", getAddressDecoder()],
["resolverType", getResolverTypeDecoder()],
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["feeBps", getU16Decoder()],
["feeRecipient", getAddressDecoder()],
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["totalResolved", getU64Decoder()],
["ruledForBuyer", getU64Decoder()],
["ruledForSeller", getU64Decoder()],
["registeredAt", getI64Decoder()],
]);
}
/** Gets the codec for {@link ResolverEntry} account data. */
export function getResolverEntryCodec(): Codec<
ResolverEntryArgs,
ResolverEntry
> {
return combineCodec(getResolverEntryEncoder(), getResolverEntryDecoder());
}
export function decodeResolverEntry<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>,
): Account<ResolverEntry, TAddress>;
export function decodeResolverEntry<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>,
): MaybeAccount<ResolverEntry, TAddress>;
export function decodeResolverEntry<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
): Account<ResolverEntry, TAddress> | MaybeAccount<ResolverEntry, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getResolverEntryDecoder(),
);
}
export async function fetchResolverEntry<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<Account<ResolverEntry, TAddress>> {
const maybeAccount = await fetchMaybeResolverEntry(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}
export async function fetchMaybeResolverEntry<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig,
): Promise<MaybeAccount<ResolverEntry, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeResolverEntry(maybeAccount);
}
export async function fetchAllResolverEntry(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<Account<ResolverEntry>[]> {
const maybeAccounts = await fetchAllMaybeResolverEntry(
rpc,
addresses,
config,
);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}
export async function fetchAllMaybeResolverEntry(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig,
): Promise<MaybeAccount<ResolverEntry>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeResolverEntry(maybeAccount));
}

View File

@@ -0,0 +1,72 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import {
isProgramError,
type Address,
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
type SolanaError,
} from "@solana/kit";
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
/** Unauthorized: Signer is not the registered authority */
export const DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED = 0x1770; // 6000
/** UnauthorizedCaller: Caller is not the authorized escrow program */
export const DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED_CALLER = 0x1771; // 6001
/** InvalidFeeBps: Fee basis points must be <= 10000 */
export const DESCRO_EXT_RESOLVERS_ERROR__INVALID_FEE_BPS = 0x1772; // 6002
/** EmptyName: Name must not be empty */
export const DESCRO_EXT_RESOLVERS_ERROR__EMPTY_NAME = 0x1773; // 6003
export type DescroExtResolversError =
| typeof DESCRO_EXT_RESOLVERS_ERROR__EMPTY_NAME
| typeof DESCRO_EXT_RESOLVERS_ERROR__INVALID_FEE_BPS
| typeof DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED
| typeof DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED_CALLER;
let descroExtResolversErrorMessages:
| Record<DescroExtResolversError, string>
| undefined;
if (process.env["NODE_ENV"] !== "production") {
descroExtResolversErrorMessages = {
[DESCRO_EXT_RESOLVERS_ERROR__EMPTY_NAME]: `Name must not be empty`,
[DESCRO_EXT_RESOLVERS_ERROR__INVALID_FEE_BPS]: `Fee basis points must be <= 10000`,
[DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED]: `Signer is not the registered authority`,
[DESCRO_EXT_RESOLVERS_ERROR__UNAUTHORIZED_CALLER]: `Caller is not the authorized escrow program`,
};
}
export function getDescroExtResolversErrorMessage(
code: DescroExtResolversError,
): string {
if (process.env["NODE_ENV"] !== "production") {
return (
descroExtResolversErrorMessages as Record<DescroExtResolversError, string>
)[code];
}
return "Error message not available in production bundles.";
}
export function isDescroExtResolversError<
TProgramErrorCode extends DescroExtResolversError,
>(
error: unknown,
transactionMessage: {
instructions: Record<number, { programAddress: Address }>;
},
code?: TProgramErrorCode,
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
return isProgramError<TProgramErrorCode>(
error,
transactionMessage,
DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
code,
);
}

View File

@@ -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 "./descroExtResolvers";

View File

@@ -0,0 +1,14 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
export * from "./accounts";
export * from "./errors";
export * from "./instructions";
export * from "./pdas";
export * from "./programs";
export * from "./types";

View File

@@ -0,0 +1,11 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
export * from "./registerResolver";
export * from "./updateResolver";
export * from "./updateStats";

View File

@@ -0,0 +1,358 @@
/**
* 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,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
getStructEncoder,
getU16Decoder,
getU16Encoder,
getU32Decoder,
getU32Encoder,
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 ReadonlyAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
type WritableSignerAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
getAddressFromResolvedInstructionAccount,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { findResolverEntryPda } from "../pdas";
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
import {
getResolverTypeDecoder,
getResolverTypeEncoder,
type ResolverType,
type ResolverTypeArgs,
} from "../types";
export const REGISTER_RESOLVER_DISCRIMINATOR: ReadonlyUint8Array =
new Uint8Array([76, 101, 253, 229, 153, 242, 212, 230]);
export function getRegisterResolverDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
REGISTER_RESOLVER_DISCRIMINATOR,
);
}
export type RegisterResolverInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountAuthority extends string | AccountMeta<string> = string,
TAccountResolverEntry extends string | AccountMeta<string> = string,
TAccountSystemProgram extends string | AccountMeta<string> =
"11111111111111111111111111111111",
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountAuthority extends string
? WritableSignerAccount<TAccountAuthority> &
AccountSignerMeta<TAccountAuthority>
: TAccountAuthority,
TAccountResolverEntry extends string
? WritableAccount<TAccountResolverEntry>
: TAccountResolverEntry,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
...TRemainingAccounts,
]
>;
export type RegisterResolverInstructionData = {
discriminator: ReadonlyUint8Array;
resolverType: ResolverType;
name: string;
description: string;
feeBps: number;
feeRecipient: Address;
metadataUri: string;
};
export type RegisterResolverInstructionDataArgs = {
resolverType: ResolverTypeArgs;
name: string;
description: string;
feeBps: number;
feeRecipient: Address;
metadataUri: string;
};
export function getRegisterResolverInstructionDataEncoder(): Encoder<RegisterResolverInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["resolverType", getResolverTypeEncoder()],
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["feeBps", getU16Encoder()],
["feeRecipient", getAddressEncoder()],
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
]),
(value) => ({ ...value, discriminator: REGISTER_RESOLVER_DISCRIMINATOR }),
);
}
export function getRegisterResolverInstructionDataDecoder(): Decoder<RegisterResolverInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["resolverType", getResolverTypeDecoder()],
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["feeBps", getU16Decoder()],
["feeRecipient", getAddressDecoder()],
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
]);
}
export function getRegisterResolverInstructionDataCodec(): Codec<
RegisterResolverInstructionDataArgs,
RegisterResolverInstructionData
> {
return combineCodec(
getRegisterResolverInstructionDataEncoder(),
getRegisterResolverInstructionDataDecoder(),
);
}
export type RegisterResolverAsyncInput<
TAccountAuthority extends string = string,
TAccountResolverEntry extends string = string,
TAccountSystemProgram extends string = string,
> = {
authority: TransactionSigner<TAccountAuthority>;
resolverEntry?: Address<TAccountResolverEntry>;
systemProgram?: Address<TAccountSystemProgram>;
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
name: RegisterResolverInstructionDataArgs["name"];
description: RegisterResolverInstructionDataArgs["description"];
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
feeRecipient: RegisterResolverInstructionDataArgs["feeRecipient"];
metadataUri: RegisterResolverInstructionDataArgs["metadataUri"];
};
export async function getRegisterResolverInstructionAsync<
TAccountAuthority extends string,
TAccountResolverEntry extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: RegisterResolverAsyncInput<
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): Promise<
RegisterResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
>
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: true },
resolverEntry: { value: input.resolverEntry ?? 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.resolverEntry.value) {
accounts.resolverEntry.value = await findResolverEntryPda({
authority: getAddressFromResolvedInstructionAccount(
"authority",
accounts.authority.value,
),
});
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
"11111111111111111111111111111111" as Address<"11111111111111111111111111111111">;
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("authority", accounts.authority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getRegisterResolverInstructionDataEncoder().encode(
args as RegisterResolverInstructionDataArgs,
),
programAddress,
} as RegisterResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
>);
}
export type RegisterResolverInput<
TAccountAuthority extends string = string,
TAccountResolverEntry extends string = string,
TAccountSystemProgram extends string = string,
> = {
authority: TransactionSigner<TAccountAuthority>;
resolverEntry: Address<TAccountResolverEntry>;
systemProgram?: Address<TAccountSystemProgram>;
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
name: RegisterResolverInstructionDataArgs["name"];
description: RegisterResolverInstructionDataArgs["description"];
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
feeRecipient: RegisterResolverInstructionDataArgs["feeRecipient"];
metadataUri: RegisterResolverInstructionDataArgs["metadataUri"];
};
export function getRegisterResolverInstruction<
TAccountAuthority extends string,
TAccountResolverEntry extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: RegisterResolverInput<
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress },
): RegisterResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: true },
resolverEntry: { value: input.resolverEntry ?? 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("authority", accounts.authority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
getAccountMeta("systemProgram", accounts.systemProgram),
],
data: getRegisterResolverInstructionDataEncoder().encode(
args as RegisterResolverInstructionDataArgs,
),
programAddress,
} as RegisterResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry,
TAccountSystemProgram
>);
}
export type ParsedRegisterResolverInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
authority: TAccountMetas[0];
resolverEntry: TAccountMetas[1];
systemProgram: TAccountMetas[2];
};
data: RegisterResolverInstructionData;
};
export function parseRegisterResolverInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedRegisterResolverInstruction<TProgram, TAccountMetas> {
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: {
authority: getNextAccount(),
resolverEntry: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getRegisterResolverInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,296 @@
/**
* 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,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
getStructEncoder,
getU16Decoder,
getU16Encoder,
getU32Decoder,
getU32Encoder,
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 ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
getAddressFromResolvedInstructionAccount,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { findResolverEntryPda } from "../pdas";
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
export const UPDATE_RESOLVER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array(
[108, 227, 28, 163, 123, 230, 190, 84],
);
export function getUpdateResolverDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
UPDATE_RESOLVER_DISCRIMINATOR,
);
}
export type UpdateResolverInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountAuthority extends string | AccountMeta<string> = string,
TAccountResolverEntry extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountAuthority extends string
? ReadonlySignerAccount<TAccountAuthority> &
AccountSignerMeta<TAccountAuthority>
: TAccountAuthority,
TAccountResolverEntry extends string
? WritableAccount<TAccountResolverEntry>
: TAccountResolverEntry,
...TRemainingAccounts,
]
>;
export type UpdateResolverInstructionData = {
discriminator: ReadonlyUint8Array;
name: string;
description: string;
feeBps: number;
metadataUri: string;
};
export type UpdateResolverInstructionDataArgs = {
name: string;
description: string;
feeBps: number;
metadataUri: string;
};
export function getUpdateResolverInstructionDataEncoder(): Encoder<UpdateResolverInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
["feeBps", getU16Encoder()],
["metadataUri", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
]),
(value) => ({ ...value, discriminator: UPDATE_RESOLVER_DISCRIMINATOR }),
);
}
export function getUpdateResolverInstructionDataDecoder(): Decoder<UpdateResolverInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
["feeBps", getU16Decoder()],
["metadataUri", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
]);
}
export function getUpdateResolverInstructionDataCodec(): Codec<
UpdateResolverInstructionDataArgs,
UpdateResolverInstructionData
> {
return combineCodec(
getUpdateResolverInstructionDataEncoder(),
getUpdateResolverInstructionDataDecoder(),
);
}
export type UpdateResolverAsyncInput<
TAccountAuthority extends string = string,
TAccountResolverEntry extends string = string,
> = {
authority: TransactionSigner<TAccountAuthority>;
resolverEntry?: Address<TAccountResolverEntry>;
name: UpdateResolverInstructionDataArgs["name"];
description: UpdateResolverInstructionDataArgs["description"];
feeBps: UpdateResolverInstructionDataArgs["feeBps"];
metadataUri: UpdateResolverInstructionDataArgs["metadataUri"];
};
export async function getUpdateResolverInstructionAsync<
TAccountAuthority extends string,
TAccountResolverEntry extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: UpdateResolverAsyncInput<TAccountAuthority, TAccountResolverEntry>,
config?: { programAddress?: TProgramAddress },
): Promise<
UpdateResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry
>
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: false },
resolverEntry: { value: input.resolverEntry ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedInstructionAccount
>;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.resolverEntry.value) {
accounts.resolverEntry.value = await findResolverEntryPda({
authority: getAddressFromResolvedInstructionAccount(
"authority",
accounts.authority.value,
),
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("authority", accounts.authority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
],
data: getUpdateResolverInstructionDataEncoder().encode(
args as UpdateResolverInstructionDataArgs,
),
programAddress,
} as UpdateResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry
>);
}
export type UpdateResolverInput<
TAccountAuthority extends string = string,
TAccountResolverEntry extends string = string,
> = {
authority: TransactionSigner<TAccountAuthority>;
resolverEntry: Address<TAccountResolverEntry>;
name: UpdateResolverInstructionDataArgs["name"];
description: UpdateResolverInstructionDataArgs["description"];
feeBps: UpdateResolverInstructionDataArgs["feeBps"];
metadataUri: UpdateResolverInstructionDataArgs["metadataUri"];
};
export function getUpdateResolverInstruction<
TAccountAuthority extends string,
TAccountResolverEntry extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: UpdateResolverInput<TAccountAuthority, TAccountResolverEntry>,
config?: { programAddress?: TProgramAddress },
): UpdateResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: false },
resolverEntry: { value: input.resolverEntry ?? 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("authority", accounts.authority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
],
data: getUpdateResolverInstructionDataEncoder().encode(
args as UpdateResolverInstructionDataArgs,
),
programAddress,
} as UpdateResolverInstruction<
TProgramAddress,
TAccountAuthority,
TAccountResolverEntry
>);
}
export type ParsedUpdateResolverInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
authority: TAccountMetas[0];
resolverEntry: TAccountMetas[1];
};
data: UpdateResolverInstructionData;
};
export function parseUpdateResolverInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedUpdateResolverInstruction<TProgram, TAccountMetas> {
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: { authority: getNextAccount(), resolverEntry: getNextAccount() },
data: getUpdateResolverInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -0,0 +1,291 @@
/**
* 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,
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 ReadonlySignerAccount,
type ReadonlyUint8Array,
type TransactionSigner,
type WritableAccount,
} from "@solana/kit";
import {
getAccountMetaFactory,
type ResolvedInstructionAccount,
} from "@solana/program-client-core";
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
import {
getRulingDecoder,
getRulingEncoder,
type Ruling,
type RulingArgs,
} from "../types";
export const UPDATE_STATS_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
145, 138, 9, 150, 178, 31, 158, 244,
]);
export function getUpdateStatsDiscriminatorBytes(): ReadonlyUint8Array {
return fixEncoderSize(getBytesEncoder(), 8).encode(
UPDATE_STATS_DISCRIMINATOR,
);
}
export type UpdateStatsInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountEscrowAuthority extends string | AccountMeta<string> = string,
TAccountResolverEntry extends string | AccountMeta<string> = string,
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountEscrowAuthority extends string
? ReadonlySignerAccount<TAccountEscrowAuthority> &
AccountSignerMeta<TAccountEscrowAuthority>
: TAccountEscrowAuthority,
TAccountResolverEntry extends string
? WritableAccount<TAccountResolverEntry>
: TAccountResolverEntry,
...TRemainingAccounts,
]
>;
export type UpdateStatsInstructionData = {
discriminator: ReadonlyUint8Array;
ruling: Ruling;
};
export type UpdateStatsInstructionDataArgs = { ruling: RulingArgs };
export function getUpdateStatsInstructionDataEncoder(): FixedSizeEncoder<UpdateStatsInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
["ruling", getRulingEncoder()],
]),
(value) => ({ ...value, discriminator: UPDATE_STATS_DISCRIMINATOR }),
);
}
export function getUpdateStatsInstructionDataDecoder(): FixedSizeDecoder<UpdateStatsInstructionData> {
return getStructDecoder([
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
["ruling", getRulingDecoder()],
]);
}
export function getUpdateStatsInstructionDataCodec(): FixedSizeCodec<
UpdateStatsInstructionDataArgs,
UpdateStatsInstructionData
> {
return combineCodec(
getUpdateStatsInstructionDataEncoder(),
getUpdateStatsInstructionDataDecoder(),
);
}
export type UpdateStatsAsyncInput<
TAccountEscrowAuthority extends string = string,
TAccountResolverEntry extends string = string,
> = {
/** Must be the Escrow Program's authority PDA — only it can sign this. */
escrowAuthority?: TransactionSigner<TAccountEscrowAuthority>;
resolverEntry: Address<TAccountResolverEntry>;
ruling: UpdateStatsInstructionDataArgs["ruling"];
};
export async function getUpdateStatsInstructionAsync<
TAccountEscrowAuthority extends string,
TAccountResolverEntry extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: UpdateStatsAsyncInput<TAccountEscrowAuthority, TAccountResolverEntry>,
config?: { programAddress?: TProgramAddress },
): Promise<
UpdateStatsInstruction<
TProgramAddress,
TAccountEscrowAuthority,
TAccountResolverEntry
>
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
escrowAuthority: {
value: input.escrowAuthority ?? null,
isWritable: false,
},
resolverEntry: { value: input.resolverEntry ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedInstructionAccount
>;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.escrowAuthority.value) {
accounts.escrowAuthority.value = await getProgramDerivedAddress({
programAddress:
"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3" as Address<"DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3">,
seeds: [
getBytesEncoder().encode(
new Uint8Array([
101, 115, 99, 114, 111, 119, 95, 97, 117, 116, 104, 111, 114, 105,
116, 121,
]),
),
],
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
return Object.freeze({
accounts: [
getAccountMeta("escrowAuthority", accounts.escrowAuthority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
],
data: getUpdateStatsInstructionDataEncoder().encode(
args as UpdateStatsInstructionDataArgs,
),
programAddress,
} as UpdateStatsInstruction<
TProgramAddress,
TAccountEscrowAuthority,
TAccountResolverEntry
>);
}
export type UpdateStatsInput<
TAccountEscrowAuthority extends string = string,
TAccountResolverEntry extends string = string,
> = {
/** Must be the Escrow Program's authority PDA — only it can sign this. */
escrowAuthority: TransactionSigner<TAccountEscrowAuthority>;
resolverEntry: Address<TAccountResolverEntry>;
ruling: UpdateStatsInstructionDataArgs["ruling"];
};
export function getUpdateStatsInstruction<
TAccountEscrowAuthority extends string,
TAccountResolverEntry extends string,
TProgramAddress extends Address = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
>(
input: UpdateStatsInput<TAccountEscrowAuthority, TAccountResolverEntry>,
config?: { programAddress?: TProgramAddress },
): UpdateStatsInstruction<
TProgramAddress,
TAccountEscrowAuthority,
TAccountResolverEntry
> {
// Program address.
const programAddress =
config?.programAddress ?? DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
escrowAuthority: {
value: input.escrowAuthority ?? null,
isWritable: false,
},
resolverEntry: { value: input.resolverEntry ?? 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("escrowAuthority", accounts.escrowAuthority),
getAccountMeta("resolverEntry", accounts.resolverEntry),
],
data: getUpdateStatsInstructionDataEncoder().encode(
args as UpdateStatsInstructionDataArgs,
),
programAddress,
} as UpdateStatsInstruction<
TProgramAddress,
TAccountEscrowAuthority,
TAccountResolverEntry
>);
}
export type ParsedUpdateStatsInstruction<
TProgram extends string = typeof DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS,
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
/** Must be the Escrow Program's authority PDA — only it can sign this. */
escrowAuthority: TAccountMetas[0];
resolverEntry: TAccountMetas[1];
};
data: UpdateStatsInstructionData;
};
export function parseUpdateStatsInstruction<
TProgram extends string,
TAccountMetas extends readonly AccountMeta[],
>(
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>,
): ParsedUpdateStatsInstruction<TProgram, TAccountMetas> {
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: {
escrowAuthority: getNextAccount(),
resolverEntry: getNextAccount(),
},
data: getUpdateStatsInstructionDataDecoder().decode(instruction.data),
};
}

View File

@@ -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 "./resolverEntry";

View File

@@ -0,0 +1,37 @@
/**
* This code was AUTOGENERATED using the Codama library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun Codama to update it.
*
* @see https://github.com/codama-idl/codama
*/
import {
getAddressEncoder,
getBytesEncoder,
getProgramDerivedAddress,
type Address,
type ProgramDerivedAddress,
} from "@solana/kit";
export type ResolverEntrySeeds = {
authority: Address;
};
export async function findResolverEntryPda(
seeds: ResolverEntrySeeds,
config: { programAddress?: Address | undefined } = {},
): Promise<ProgramDerivedAddress> {
const {
programAddress = "GwUPAKs3HHzCpj8uhet4NAnxk9GWNwfrYbpihu5DyFp" as Address<"GwUPAKs3HHzCpj8uhet4NAnxk9GWNwfrYbpihu5DyFp">,
} = config;
return await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(
new Uint8Array([114, 101, 115, 111, 108, 118, 101, 114]),
),
getAddressEncoder().encode(seeds.authority),
],
});
}

View File

@@ -0,0 +1,251 @@
/**
* 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 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 {
getResolverEntryCodec,
type ResolverEntry,
type ResolverEntryArgs,
} from "../accounts";
import {
getRegisterResolverInstructionAsync,
getUpdateResolverInstructionAsync,
getUpdateStatsInstructionAsync,
parseRegisterResolverInstruction,
parseUpdateResolverInstruction,
parseUpdateStatsInstruction,
type ParsedRegisterResolverInstruction,
type ParsedUpdateResolverInstruction,
type ParsedUpdateStatsInstruction,
type RegisterResolverAsyncInput,
type UpdateResolverAsyncInput,
type UpdateStatsAsyncInput,
} from "../instructions";
import { findResolverEntryPda } from "../pdas";
export const DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS =
"GwUPAKs3HHzCpj8uhet4NAnxk9GWNwfrYbpihu5DyFp" as Address<"GwUPAKs3HHzCpj8uhet4NAnxk9GWNwfrYbpihu5DyFp">;
export enum DescroExtResolversAccount {
ResolverEntry,
}
export function identifyDescroExtResolversAccount(
account: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): DescroExtResolversAccount {
const data = "data" in account ? account.data : account;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([0, 60, 55, 58, 157, 135, 51, 191]),
),
0,
)
) {
return DescroExtResolversAccount.ResolverEntry;
}
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT,
{ accountData: data, programName: "descroExtResolvers" },
);
}
export enum DescroExtResolversInstruction {
RegisterResolver,
UpdateResolver,
UpdateStats,
}
export function identifyDescroExtResolversInstruction(
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
): DescroExtResolversInstruction {
const data = "data" in instruction ? instruction.data : instruction;
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([76, 101, 253, 229, 153, 242, 212, 230]),
),
0,
)
) {
return DescroExtResolversInstruction.RegisterResolver;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([108, 227, 28, 163, 123, 230, 190, 84]),
),
0,
)
) {
return DescroExtResolversInstruction.UpdateResolver;
}
if (
containsBytes(
data,
fixEncoderSize(getBytesEncoder(), 8).encode(
new Uint8Array([145, 138, 9, 150, 178, 31, 158, 244]),
),
0,
)
) {
return DescroExtResolversInstruction.UpdateStats;
}
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
{ instructionData: data, programName: "descroExtResolvers" },
);
}
export type ParsedDescroExtResolversInstruction<
TProgram extends string = "GwUPAKs3HHzCpj8uhet4NAnxk9GWNwfrYbpihu5DyFp",
> =
| ({
instructionType: DescroExtResolversInstruction.RegisterResolver;
} & ParsedRegisterResolverInstruction<TProgram>)
| ({
instructionType: DescroExtResolversInstruction.UpdateResolver;
} & ParsedUpdateResolverInstruction<TProgram>)
| ({
instructionType: DescroExtResolversInstruction.UpdateStats;
} & ParsedUpdateStatsInstruction<TProgram>);
export function parseDescroExtResolversInstruction<TProgram extends string>(
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
): ParsedDescroExtResolversInstruction<TProgram> {
const instructionType = identifyDescroExtResolversInstruction(instruction);
switch (instructionType) {
case DescroExtResolversInstruction.RegisterResolver: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroExtResolversInstruction.RegisterResolver,
...parseRegisterResolverInstruction(instruction),
};
}
case DescroExtResolversInstruction.UpdateResolver: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroExtResolversInstruction.UpdateResolver,
...parseUpdateResolverInstruction(instruction),
};
}
case DescroExtResolversInstruction.UpdateStats: {
assertIsInstructionWithAccounts(instruction);
return {
instructionType: DescroExtResolversInstruction.UpdateStats,
...parseUpdateStatsInstruction(instruction),
};
}
default:
throw new SolanaError(
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
{
instructionType: instructionType as string,
programName: "descroExtResolvers",
},
);
}
}
export type DescroExtResolversPlugin = {
accounts: DescroExtResolversPluginAccounts;
instructions: DescroExtResolversPluginInstructions;
pdas: DescroExtResolversPluginPdas;
};
export type DescroExtResolversPluginAccounts = {
resolverEntry: ReturnType<typeof getResolverEntryCodec> &
SelfFetchFunctions<ResolverEntryArgs, ResolverEntry>;
};
export type DescroExtResolversPluginInstructions = {
registerResolver: (
input: RegisterResolverAsyncInput,
) => ReturnType<typeof getRegisterResolverInstructionAsync> &
SelfPlanAndSendFunctions;
updateResolver: (
input: UpdateResolverAsyncInput,
) => ReturnType<typeof getUpdateResolverInstructionAsync> &
SelfPlanAndSendFunctions;
updateStats: (
input: UpdateStatsAsyncInput,
) => ReturnType<typeof getUpdateStatsInstructionAsync> &
SelfPlanAndSendFunctions;
};
export type DescroExtResolversPluginPdas = {
resolverEntry: typeof findResolverEntryPda;
};
export type DescroExtResolversPluginRequirements = ClientWithRpc<
GetAccountInfoApi & GetMultipleAccountsApi
> &
ClientWithTransactionPlanning &
ClientWithTransactionSending;
export function descroExtResolversProgram() {
return <T extends DescroExtResolversPluginRequirements>(
client: T,
): Omit<T, "descroExtResolvers"> & {
descroExtResolvers: DescroExtResolversPlugin;
} => {
return extendClient(client, {
descroExtResolvers: <DescroExtResolversPlugin>{
accounts: {
resolverEntry: addSelfFetchFunctions(client, getResolverEntryCodec()),
},
instructions: {
registerResolver: (input) =>
addSelfPlanAndSendFunctions(
client,
getRegisterResolverInstructionAsync(input),
),
updateResolver: (input) =>
addSelfPlanAndSendFunctions(
client,
getUpdateResolverInstructionAsync(input),
),
updateStats: (input) =>
addSelfPlanAndSendFunctions(
client,
getUpdateStatsInstructionAsync(input),
),
},
pdas: { resolverEntry: findResolverEntryPda },
},
});
};
}

View File

@@ -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 "./descroExtResolvers";

View File

@@ -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 "./resolverType";
export * from "./ruling";

View File

@@ -0,0 +1,41 @@
/**
* 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,
getEnumDecoder,
getEnumEncoder,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
} from "@solana/kit";
export enum ResolverType {
CentralAuthority,
JuryDAO,
MAD,
Algorithmic,
Multisig,
}
export type ResolverTypeArgs = ResolverType;
export function getResolverTypeEncoder(): FixedSizeEncoder<ResolverTypeArgs> {
return getEnumEncoder(ResolverType);
}
export function getResolverTypeDecoder(): FixedSizeDecoder<ResolverType> {
return getEnumDecoder(ResolverType);
}
export function getResolverTypeCodec(): FixedSizeCodec<
ResolverTypeArgs,
ResolverType
> {
return combineCodec(getResolverTypeEncoder(), getResolverTypeDecoder());
}

View File

@@ -0,0 +1,36 @@
/**
* 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,
getEnumDecoder,
getEnumEncoder,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
} from "@solana/kit";
/** Passed to update_stats; mirrors the Escrow program's Winner enum. */
export enum Ruling {
Buyer,
Seller,
}
export type RulingArgs = Ruling;
export function getRulingEncoder(): FixedSizeEncoder<RulingArgs> {
return getEnumEncoder(Ruling);
}
export function getRulingDecoder(): FixedSizeDecoder<Ruling> {
return getEnumDecoder(Ruling);
}
export function getRulingCodec(): FixedSizeCodec<RulingArgs, Ruling> {
return combineCodec(getRulingEncoder(), getRulingDecoder());
}