update sdk
This commit is contained in:
@@ -19,6 +19,8 @@ import {
|
|||||||
getAddressEncoder,
|
getAddressEncoder,
|
||||||
getBytesDecoder,
|
getBytesDecoder,
|
||||||
getBytesEncoder,
|
getBytesEncoder,
|
||||||
|
getI64Decoder,
|
||||||
|
getI64Encoder,
|
||||||
getOptionDecoder,
|
getOptionDecoder,
|
||||||
getOptionEncoder,
|
getOptionEncoder,
|
||||||
getStructDecoder,
|
getStructDecoder,
|
||||||
@@ -69,6 +71,7 @@ export type EscrowAccount = {
|
|||||||
bump: number;
|
bump: number;
|
||||||
vaultBump: number;
|
vaultBump: number;
|
||||||
escrowId: bigint;
|
escrowId: bigint;
|
||||||
|
disputeRaisedAt: Option<bigint>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EscrowAccountArgs = {
|
export type EscrowAccountArgs = {
|
||||||
@@ -80,6 +83,7 @@ export type EscrowAccountArgs = {
|
|||||||
bump: number;
|
bump: number;
|
||||||
vaultBump: number;
|
vaultBump: number;
|
||||||
escrowId: number | bigint;
|
escrowId: number | bigint;
|
||||||
|
disputeRaisedAt: OptionOrNullable<number | bigint>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Gets the encoder for {@link EscrowAccountArgs} account data. */
|
/** Gets the encoder for {@link EscrowAccountArgs} account data. */
|
||||||
@@ -95,6 +99,7 @@ export function getEscrowAccountEncoder(): Encoder<EscrowAccountArgs> {
|
|||||||
["bump", getU8Encoder()],
|
["bump", getU8Encoder()],
|
||||||
["vaultBump", getU8Encoder()],
|
["vaultBump", getU8Encoder()],
|
||||||
["escrowId", getU64Encoder()],
|
["escrowId", getU64Encoder()],
|
||||||
|
["disputeRaisedAt", getOptionEncoder(getI64Encoder())],
|
||||||
]),
|
]),
|
||||||
(value) => ({ ...value, discriminator: ESCROW_ACCOUNT_DISCRIMINATOR }),
|
(value) => ({ ...value, discriminator: ESCROW_ACCOUNT_DISCRIMINATOR }),
|
||||||
);
|
);
|
||||||
@@ -112,6 +117,7 @@ export function getEscrowAccountDecoder(): Decoder<EscrowAccount> {
|
|||||||
["bump", getU8Decoder()],
|
["bump", getU8Decoder()],
|
||||||
["vaultBump", getU8Decoder()],
|
["vaultBump", getU8Decoder()],
|
||||||
["escrowId", getU64Decoder()],
|
["escrowId", getU64Decoder()],
|
||||||
|
["disputeRaisedAt", getOptionDecoder(getI64Decoder())],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,20 +24,36 @@ export const DESCRO_ERROR__NO_RESOLVER_CONFIGURED = 0x1772; // 6002
|
|||||||
export const DESCRO_ERROR__UNAUTHORIZED_RESOLVER = 0x1773; // 6003
|
export const DESCRO_ERROR__UNAUTHORIZED_RESOLVER = 0x1773; // 6003
|
||||||
/** Expired: Escrow has expired */
|
/** Expired: Escrow has expired */
|
||||||
export const DESCRO_ERROR__EXPIRED = 0x1774; // 6004
|
export const DESCRO_ERROR__EXPIRED = 0x1774; // 6004
|
||||||
|
/** DisputeTimeoutNotReached: Dispute timeout period has not elapsed yet */
|
||||||
|
export const DESCRO_ERROR__DISPUTE_TIMEOUT_NOT_REACHED = 0x1775; // 6005
|
||||||
|
/** InsufficientVaultBalance: Vault balance is insufficient for the requested escrow amount */
|
||||||
|
export const DESCRO_ERROR__INSUFFICIENT_VAULT_BALANCE = 0x1776; // 6006
|
||||||
|
/** AmountBelowRentMinimum: Amount must be at least rent-exempt minimum for the vault (~890880 lamports) */
|
||||||
|
export const DESCRO_ERROR__AMOUNT_BELOW_RENT_MINIMUM = 0x1777; // 6007
|
||||||
|
/** ResolverSignatureRequired: Resolver must co-sign this transaction (SignatureGated acceptance policy) */
|
||||||
|
export const DESCRO_ERROR__RESOLVER_SIGNATURE_REQUIRED = 0x1778; // 6008
|
||||||
|
|
||||||
export type DescroError =
|
export type DescroError =
|
||||||
|
| typeof DESCRO_ERROR__AMOUNT_BELOW_RENT_MINIMUM
|
||||||
|
| typeof DESCRO_ERROR__DISPUTE_TIMEOUT_NOT_REACHED
|
||||||
| typeof DESCRO_ERROR__EXPIRED
|
| typeof DESCRO_ERROR__EXPIRED
|
||||||
|
| typeof DESCRO_ERROR__INSUFFICIENT_VAULT_BALANCE
|
||||||
| typeof DESCRO_ERROR__INVALID_STATE
|
| typeof DESCRO_ERROR__INVALID_STATE
|
||||||
| typeof DESCRO_ERROR__NO_RESOLVER_CONFIGURED
|
| typeof DESCRO_ERROR__NO_RESOLVER_CONFIGURED
|
||||||
|
| typeof DESCRO_ERROR__RESOLVER_SIGNATURE_REQUIRED
|
||||||
| typeof DESCRO_ERROR__UNAUTHORIZED
|
| typeof DESCRO_ERROR__UNAUTHORIZED
|
||||||
| typeof DESCRO_ERROR__UNAUTHORIZED_RESOLVER;
|
| typeof DESCRO_ERROR__UNAUTHORIZED_RESOLVER;
|
||||||
|
|
||||||
let descroErrorMessages: Record<DescroError, string> | undefined;
|
let descroErrorMessages: Record<DescroError, string> | undefined;
|
||||||
if (process.env["NODE_ENV"] !== "production") {
|
if (process.env["NODE_ENV"] !== "production") {
|
||||||
descroErrorMessages = {
|
descroErrorMessages = {
|
||||||
|
[DESCRO_ERROR__AMOUNT_BELOW_RENT_MINIMUM]: `Amount must be at least rent-exempt minimum for the vault (~890880 lamports)`,
|
||||||
|
[DESCRO_ERROR__DISPUTE_TIMEOUT_NOT_REACHED]: `Dispute timeout period has not elapsed yet`,
|
||||||
[DESCRO_ERROR__EXPIRED]: `Escrow has expired`,
|
[DESCRO_ERROR__EXPIRED]: `Escrow has expired`,
|
||||||
|
[DESCRO_ERROR__INSUFFICIENT_VAULT_BALANCE]: `Vault balance is insufficient for the requested escrow amount`,
|
||||||
[DESCRO_ERROR__INVALID_STATE]: `Invalid state for this instruction`,
|
[DESCRO_ERROR__INVALID_STATE]: `Invalid state for this instruction`,
|
||||||
[DESCRO_ERROR__NO_RESOLVER_CONFIGURED]: `No resolver configured for this escrow`,
|
[DESCRO_ERROR__NO_RESOLVER_CONFIGURED]: `No resolver configured for this escrow`,
|
||||||
|
[DESCRO_ERROR__RESOLVER_SIGNATURE_REQUIRED]: `Resolver must co-sign this transaction (SignatureGated acceptance policy)`,
|
||||||
[DESCRO_ERROR__UNAUTHORIZED]: `Signer is not authorized`,
|
[DESCRO_ERROR__UNAUTHORIZED]: `Signer is not authorized`,
|
||||||
[DESCRO_ERROR__UNAUTHORIZED_RESOLVER]: `Signer is not the configured resolver`,
|
[DESCRO_ERROR__UNAUTHORIZED_RESOLVER]: `Signer is not the configured resolver`,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,384 @@
|
|||||||
|
/**
|
||||||
|
* 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 BUYER_CREATE_ESCROW_DISCRIMINATOR: ReadonlyUint8Array =
|
||||||
|
new Uint8Array([79, 199, 251, 30, 163, 86, 13, 73]);
|
||||||
|
|
||||||
|
export function getBuyerCreateEscrowDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
BUYER_CREATE_ESCROW_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BuyerCreateEscrowInstruction<
|
||||||
|
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
|
||||||
|
? WritableSignerAccount<TAccountBuyer> &
|
||||||
|
AccountSignerMeta<TAccountBuyer>
|
||||||
|
: TAccountBuyer,
|
||||||
|
TAccountSeller extends string
|
||||||
|
? ReadonlyAccount<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountVault extends string
|
||||||
|
? WritableAccount<TAccountVault>
|
||||||
|
: TAccountVault,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type BuyerCreateEscrowInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
amount: bigint;
|
||||||
|
disputeResolver: Option<Address>;
|
||||||
|
escrowId: bigint;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BuyerCreateEscrowInstructionDataArgs = {
|
||||||
|
amount: number | bigint;
|
||||||
|
disputeResolver: OptionOrNullable<Address>;
|
||||||
|
escrowId: number | bigint;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getBuyerCreateEscrowInstructionDataEncoder(): Encoder<BuyerCreateEscrowInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["amount", getU64Encoder()],
|
||||||
|
["disputeResolver", getOptionEncoder(getAddressEncoder())],
|
||||||
|
["escrowId", getU64Encoder()],
|
||||||
|
]),
|
||||||
|
(value) => ({ ...value, discriminator: BUYER_CREATE_ESCROW_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBuyerCreateEscrowInstructionDataDecoder(): Decoder<BuyerCreateEscrowInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["amount", getU64Decoder()],
|
||||||
|
["disputeResolver", getOptionDecoder(getAddressDecoder())],
|
||||||
|
["escrowId", getU64Decoder()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBuyerCreateEscrowInstructionDataCodec(): Codec<
|
||||||
|
BuyerCreateEscrowInstructionDataArgs,
|
||||||
|
BuyerCreateEscrowInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getBuyerCreateEscrowInstructionDataEncoder(),
|
||||||
|
getBuyerCreateEscrowInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BuyerCreateEscrowAsyncInput<
|
||||||
|
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>;
|
||||||
|
amount: BuyerCreateEscrowInstructionDataArgs["amount"];
|
||||||
|
disputeResolver: BuyerCreateEscrowInstructionDataArgs["disputeResolver"];
|
||||||
|
escrowId: BuyerCreateEscrowInstructionDataArgs["escrowId"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getBuyerCreateEscrowInstructionAsync<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: BuyerCreateEscrowAsyncInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
BuyerCreateEscrowInstruction<
|
||||||
|
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: true },
|
||||||
|
seller: { value: input.seller ?? 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("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getBuyerCreateEscrowInstructionDataEncoder().encode(
|
||||||
|
args as BuyerCreateEscrowInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as BuyerCreateEscrowInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BuyerCreateEscrowInput<
|
||||||
|
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>;
|
||||||
|
amount: BuyerCreateEscrowInstructionDataArgs["amount"];
|
||||||
|
disputeResolver: BuyerCreateEscrowInstructionDataArgs["disputeResolver"];
|
||||||
|
escrowId: BuyerCreateEscrowInstructionDataArgs["escrowId"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getBuyerCreateEscrowInstruction<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: BuyerCreateEscrowInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): BuyerCreateEscrowInstruction<
|
||||||
|
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: true },
|
||||||
|
seller: { value: input.seller ?? 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("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getBuyerCreateEscrowInstructionDataEncoder().encode(
|
||||||
|
args as BuyerCreateEscrowInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as BuyerCreateEscrowInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedBuyerCreateEscrowInstruction<
|
||||||
|
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: BuyerCreateEscrowInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseBuyerCreateEscrowInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedBuyerCreateEscrowInstruction<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: getBuyerCreateEscrowInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -34,8 +34,10 @@ import {
|
|||||||
} from "@solana/kit";
|
} from "@solana/kit";
|
||||||
import {
|
import {
|
||||||
getAccountMetaFactory,
|
getAccountMetaFactory,
|
||||||
|
getAddressFromResolvedInstructionAccount,
|
||||||
type ResolvedInstructionAccount,
|
type ResolvedInstructionAccount,
|
||||||
} from "@solana/program-client-core";
|
} from "@solana/program-client-core";
|
||||||
|
import { findVaultPda } from "../pdas";
|
||||||
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
|
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
export const CANCEL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
export const CANCEL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
@@ -48,8 +50,10 @@ export function getCancelDiscriminatorBytes(): ReadonlyUint8Array {
|
|||||||
|
|
||||||
export type CancelInstruction<
|
export type CancelInstruction<
|
||||||
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
TAccountSeller extends string | AccountMeta<string> = string,
|
TAccountCanceller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountVault extends string | AccountMeta<string> = string,
|
||||||
TAccountSystemProgram extends string | AccountMeta<string> =
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
"11111111111111111111111111111111",
|
"11111111111111111111111111111111",
|
||||||
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
@@ -57,13 +61,19 @@ export type CancelInstruction<
|
|||||||
InstructionWithData<ReadonlyUint8Array> &
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
InstructionWithAccounts<
|
InstructionWithAccounts<
|
||||||
[
|
[
|
||||||
TAccountSeller extends string
|
TAccountCanceller extends string
|
||||||
? WritableSignerAccount<TAccountSeller> &
|
? WritableSignerAccount<TAccountCanceller> &
|
||||||
AccountSignerMeta<TAccountSeller>
|
AccountSignerMeta<TAccountCanceller>
|
||||||
: TAccountSeller,
|
: TAccountCanceller,
|
||||||
|
TAccountBuyer extends string
|
||||||
|
? WritableAccount<TAccountBuyer>
|
||||||
|
: TAccountBuyer,
|
||||||
TAccountEscrowAccount extends string
|
TAccountEscrowAccount extends string
|
||||||
? WritableAccount<TAccountEscrowAccount>
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
: TAccountEscrowAccount,
|
: TAccountEscrowAccount,
|
||||||
|
TAccountVault extends string
|
||||||
|
? WritableAccount<TAccountVault>
|
||||||
|
: TAccountVault,
|
||||||
TAccountSystemProgram extends string
|
TAccountSystemProgram extends string
|
||||||
? ReadonlyAccount<TAccountSystemProgram>
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
: TAccountSystemProgram,
|
: TAccountSystemProgram,
|
||||||
@@ -98,32 +108,133 @@ export function getCancelInstructionDataCodec(): FixedSizeCodec<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CancelInput<
|
export type CancelAsyncInput<
|
||||||
TAccountSeller extends string = string,
|
TAccountCanceller extends string = string,
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
TAccountEscrowAccount extends string = string,
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
TAccountSystemProgram extends string = string,
|
TAccountSystemProgram extends string = string,
|
||||||
> = {
|
> = {
|
||||||
seller: TransactionSigner<TAccountSeller>;
|
canceller: TransactionSigner<TAccountCanceller>;
|
||||||
|
buyer: Address<TAccountBuyer>;
|
||||||
escrowAccount: Address<TAccountEscrowAccount>;
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault?: Address<TAccountVault>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getCancelInstructionAsync<
|
||||||
|
TAccountCanceller extends string,
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: CancelAsyncInput<
|
||||||
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
CancelInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
canceller: { value: input.canceller ?? null, isWritable: true },
|
||||||
|
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("canceller", accounts.canceller),
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getCancelInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as CancelInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CancelInput<
|
||||||
|
TAccountCanceller extends string = string,
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
canceller: TransactionSigner<TAccountCanceller>;
|
||||||
|
buyer: Address<TAccountBuyer>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault: Address<TAccountVault>;
|
||||||
systemProgram?: Address<TAccountSystemProgram>;
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getCancelInstruction<
|
export function getCancelInstruction<
|
||||||
TAccountSeller extends string,
|
TAccountCanceller extends string,
|
||||||
|
TAccountBuyer extends string,
|
||||||
TAccountEscrowAccount extends string,
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
TAccountSystemProgram extends string,
|
TAccountSystemProgram extends string,
|
||||||
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
>(
|
>(
|
||||||
input: CancelInput<
|
input: CancelInput<
|
||||||
TAccountSeller,
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>,
|
>,
|
||||||
config?: { programAddress?: TProgramAddress },
|
config?: { programAddress?: TProgramAddress },
|
||||||
): CancelInstruction<
|
): CancelInstruction<
|
||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
> {
|
> {
|
||||||
// Program address.
|
// Program address.
|
||||||
@@ -131,8 +242,10 @@ export function getCancelInstruction<
|
|||||||
|
|
||||||
// Original accounts.
|
// Original accounts.
|
||||||
const originalAccounts = {
|
const originalAccounts = {
|
||||||
seller: { value: input.seller ?? null, isWritable: true },
|
canceller: { value: input.canceller ?? null, isWritable: true },
|
||||||
|
buyer: { value: input.buyer ?? null, isWritable: true },
|
||||||
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
};
|
};
|
||||||
const accounts = originalAccounts as Record<
|
const accounts = originalAccounts as Record<
|
||||||
@@ -149,16 +262,20 @@ export function getCancelInstruction<
|
|||||||
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
return Object.freeze({
|
return Object.freeze({
|
||||||
accounts: [
|
accounts: [
|
||||||
getAccountMeta("seller", accounts.seller),
|
getAccountMeta("canceller", accounts.canceller),
|
||||||
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
getAccountMeta("systemProgram", accounts.systemProgram),
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
],
|
],
|
||||||
data: getCancelInstructionDataEncoder().encode({}),
|
data: getCancelInstructionDataEncoder().encode({}),
|
||||||
programAddress,
|
programAddress,
|
||||||
} as CancelInstruction<
|
} as CancelInstruction<
|
||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountCanceller,
|
||||||
|
TAccountBuyer,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>);
|
>);
|
||||||
}
|
}
|
||||||
@@ -169,9 +286,11 @@ export type ParsedCancelInstruction<
|
|||||||
> = {
|
> = {
|
||||||
programAddress: Address<TProgram>;
|
programAddress: Address<TProgram>;
|
||||||
accounts: {
|
accounts: {
|
||||||
seller: TAccountMetas[0];
|
canceller: TAccountMetas[0];
|
||||||
escrowAccount: TAccountMetas[1];
|
buyer: TAccountMetas[1];
|
||||||
systemProgram: TAccountMetas[2];
|
escrowAccount: TAccountMetas[2];
|
||||||
|
vault: TAccountMetas[3];
|
||||||
|
systemProgram: TAccountMetas[4];
|
||||||
};
|
};
|
||||||
data: CancelInstructionData;
|
data: CancelInstructionData;
|
||||||
};
|
};
|
||||||
@@ -184,12 +303,12 @@ export function parseCancelInstruction<
|
|||||||
InstructionWithAccounts<TAccountMetas> &
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
InstructionWithData<ReadonlyUint8Array>,
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
): ParsedCancelInstruction<TProgram, TAccountMetas> {
|
): ParsedCancelInstruction<TProgram, TAccountMetas> {
|
||||||
if (instruction.accounts.length < 3) {
|
if (instruction.accounts.length < 5) {
|
||||||
throw new SolanaError(
|
throw new SolanaError(
|
||||||
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
{
|
{
|
||||||
actualAccountMetas: instruction.accounts.length,
|
actualAccountMetas: instruction.accounts.length,
|
||||||
expectedAccountMetas: 3,
|
expectedAccountMetas: 5,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -202,8 +321,10 @@ export function parseCancelInstruction<
|
|||||||
return {
|
return {
|
||||||
programAddress: instruction.programAddress,
|
programAddress: instruction.programAddress,
|
||||||
accounts: {
|
accounts: {
|
||||||
seller: getNextAccount(),
|
canceller: getNextAccount(),
|
||||||
|
buyer: getNextAccount(),
|
||||||
escrowAccount: getNextAccount(),
|
escrowAccount: getNextAccount(),
|
||||||
|
vault: getNextAccount(),
|
||||||
systemProgram: getNextAccount(),
|
systemProgram: getNextAccount(),
|
||||||
},
|
},
|
||||||
data: getCancelInstructionDataDecoder().decode(instruction.data),
|
data: getCancelInstructionDataDecoder().decode(instruction.data),
|
||||||
|
|||||||
@@ -63,8 +63,10 @@ export type CreateEscrowInstruction<
|
|||||||
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
TAccountSeller extends string | AccountMeta<string> = string,
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
TAccountBuyer extends string | AccountMeta<string> = string,
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolver extends string | AccountMeta<string> = string,
|
||||||
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
TAccountVault extends string | AccountMeta<string> = string,
|
TAccountVault extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolverEntry extends string | AccountMeta<string> = string,
|
||||||
TAccountSystemProgram extends string | AccountMeta<string> =
|
TAccountSystemProgram extends string | AccountMeta<string> =
|
||||||
"11111111111111111111111111111111",
|
"11111111111111111111111111111111",
|
||||||
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
@@ -79,12 +81,18 @@ export type CreateEscrowInstruction<
|
|||||||
TAccountBuyer extends string
|
TAccountBuyer extends string
|
||||||
? ReadonlyAccount<TAccountBuyer>
|
? ReadonlyAccount<TAccountBuyer>
|
||||||
: TAccountBuyer,
|
: TAccountBuyer,
|
||||||
|
TAccountResolver extends string
|
||||||
|
? ReadonlyAccount<TAccountResolver>
|
||||||
|
: TAccountResolver,
|
||||||
TAccountEscrowAccount extends string
|
TAccountEscrowAccount extends string
|
||||||
? WritableAccount<TAccountEscrowAccount>
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
: TAccountEscrowAccount,
|
: TAccountEscrowAccount,
|
||||||
TAccountVault extends string
|
TAccountVault extends string
|
||||||
? WritableAccount<TAccountVault>
|
? WritableAccount<TAccountVault>
|
||||||
: TAccountVault,
|
: TAccountVault,
|
||||||
|
TAccountResolverEntry extends string
|
||||||
|
? ReadonlyAccount<TAccountResolverEntry>
|
||||||
|
: TAccountResolverEntry,
|
||||||
TAccountSystemProgram extends string
|
TAccountSystemProgram extends string
|
||||||
? ReadonlyAccount<TAccountSystemProgram>
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
: TAccountSystemProgram,
|
: TAccountSystemProgram,
|
||||||
@@ -139,14 +147,18 @@ export function getCreateEscrowInstructionDataCodec(): Codec<
|
|||||||
export type CreateEscrowAsyncInput<
|
export type CreateEscrowAsyncInput<
|
||||||
TAccountSeller extends string = string,
|
TAccountSeller extends string = string,
|
||||||
TAccountBuyer extends string = string,
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountResolver extends string = string,
|
||||||
TAccountEscrowAccount extends string = string,
|
TAccountEscrowAccount extends string = string,
|
||||||
TAccountVault extends string = string,
|
TAccountVault extends string = string,
|
||||||
|
TAccountResolverEntry extends string = string,
|
||||||
TAccountSystemProgram extends string = string,
|
TAccountSystemProgram extends string = string,
|
||||||
> = {
|
> = {
|
||||||
seller: TransactionSigner<TAccountSeller>;
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
buyer: Address<TAccountBuyer>;
|
buyer: Address<TAccountBuyer>;
|
||||||
|
resolver: Address<TAccountResolver>;
|
||||||
escrowAccount?: Address<TAccountEscrowAccount>;
|
escrowAccount?: Address<TAccountEscrowAccount>;
|
||||||
vault?: Address<TAccountVault>;
|
vault?: Address<TAccountVault>;
|
||||||
|
resolverEntry: Address<TAccountResolverEntry>;
|
||||||
systemProgram?: Address<TAccountSystemProgram>;
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
amount: CreateEscrowInstructionDataArgs["amount"];
|
amount: CreateEscrowInstructionDataArgs["amount"];
|
||||||
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
|
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
|
||||||
@@ -156,16 +168,20 @@ export type CreateEscrowAsyncInput<
|
|||||||
export async function getCreateEscrowInstructionAsync<
|
export async function getCreateEscrowInstructionAsync<
|
||||||
TAccountSeller extends string,
|
TAccountSeller extends string,
|
||||||
TAccountBuyer extends string,
|
TAccountBuyer extends string,
|
||||||
|
TAccountResolver extends string,
|
||||||
TAccountEscrowAccount extends string,
|
TAccountEscrowAccount extends string,
|
||||||
TAccountVault extends string,
|
TAccountVault extends string,
|
||||||
|
TAccountResolverEntry extends string,
|
||||||
TAccountSystemProgram extends string,
|
TAccountSystemProgram extends string,
|
||||||
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
>(
|
>(
|
||||||
input: CreateEscrowAsyncInput<
|
input: CreateEscrowAsyncInput<
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>,
|
>,
|
||||||
config?: { programAddress?: TProgramAddress },
|
config?: { programAddress?: TProgramAddress },
|
||||||
@@ -174,8 +190,10 @@ export async function getCreateEscrowInstructionAsync<
|
|||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>
|
>
|
||||||
> {
|
> {
|
||||||
@@ -186,8 +204,10 @@ export async function getCreateEscrowInstructionAsync<
|
|||||||
const originalAccounts = {
|
const originalAccounts = {
|
||||||
seller: { value: input.seller ?? null, isWritable: true },
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
buyer: { value: input.buyer ?? null, isWritable: false },
|
buyer: { value: input.buyer ?? null, isWritable: false },
|
||||||
|
resolver: { value: input.resolver ?? null, isWritable: false },
|
||||||
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
vault: { value: input.vault ?? null, isWritable: true },
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
resolverEntry: { value: input.resolverEntry ?? null, isWritable: false },
|
||||||
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
};
|
};
|
||||||
const accounts = originalAccounts as Record<
|
const accounts = originalAccounts as Record<
|
||||||
@@ -226,8 +246,10 @@ export async function getCreateEscrowInstructionAsync<
|
|||||||
accounts: [
|
accounts: [
|
||||||
getAccountMeta("seller", accounts.seller),
|
getAccountMeta("seller", accounts.seller),
|
||||||
getAccountMeta("buyer", accounts.buyer),
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("resolver", accounts.resolver),
|
||||||
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
getAccountMeta("vault", accounts.vault),
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("resolverEntry", accounts.resolverEntry),
|
||||||
getAccountMeta("systemProgram", accounts.systemProgram),
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
],
|
],
|
||||||
data: getCreateEscrowInstructionDataEncoder().encode(
|
data: getCreateEscrowInstructionDataEncoder().encode(
|
||||||
@@ -238,8 +260,10 @@ export async function getCreateEscrowInstructionAsync<
|
|||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>);
|
>);
|
||||||
}
|
}
|
||||||
@@ -247,14 +271,18 @@ export async function getCreateEscrowInstructionAsync<
|
|||||||
export type CreateEscrowInput<
|
export type CreateEscrowInput<
|
||||||
TAccountSeller extends string = string,
|
TAccountSeller extends string = string,
|
||||||
TAccountBuyer extends string = string,
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountResolver extends string = string,
|
||||||
TAccountEscrowAccount extends string = string,
|
TAccountEscrowAccount extends string = string,
|
||||||
TAccountVault extends string = string,
|
TAccountVault extends string = string,
|
||||||
|
TAccountResolverEntry extends string = string,
|
||||||
TAccountSystemProgram extends string = string,
|
TAccountSystemProgram extends string = string,
|
||||||
> = {
|
> = {
|
||||||
seller: TransactionSigner<TAccountSeller>;
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
buyer: Address<TAccountBuyer>;
|
buyer: Address<TAccountBuyer>;
|
||||||
|
resolver: Address<TAccountResolver>;
|
||||||
escrowAccount: Address<TAccountEscrowAccount>;
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
vault: Address<TAccountVault>;
|
vault: Address<TAccountVault>;
|
||||||
|
resolverEntry: Address<TAccountResolverEntry>;
|
||||||
systemProgram?: Address<TAccountSystemProgram>;
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
amount: CreateEscrowInstructionDataArgs["amount"];
|
amount: CreateEscrowInstructionDataArgs["amount"];
|
||||||
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
|
disputeResolver: CreateEscrowInstructionDataArgs["disputeResolver"];
|
||||||
@@ -264,16 +292,20 @@ export type CreateEscrowInput<
|
|||||||
export function getCreateEscrowInstruction<
|
export function getCreateEscrowInstruction<
|
||||||
TAccountSeller extends string,
|
TAccountSeller extends string,
|
||||||
TAccountBuyer extends string,
|
TAccountBuyer extends string,
|
||||||
|
TAccountResolver extends string,
|
||||||
TAccountEscrowAccount extends string,
|
TAccountEscrowAccount extends string,
|
||||||
TAccountVault extends string,
|
TAccountVault extends string,
|
||||||
|
TAccountResolverEntry extends string,
|
||||||
TAccountSystemProgram extends string,
|
TAccountSystemProgram extends string,
|
||||||
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
>(
|
>(
|
||||||
input: CreateEscrowInput<
|
input: CreateEscrowInput<
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>,
|
>,
|
||||||
config?: { programAddress?: TProgramAddress },
|
config?: { programAddress?: TProgramAddress },
|
||||||
@@ -281,8 +313,10 @@ export function getCreateEscrowInstruction<
|
|||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
> {
|
> {
|
||||||
// Program address.
|
// Program address.
|
||||||
@@ -292,8 +326,10 @@ export function getCreateEscrowInstruction<
|
|||||||
const originalAccounts = {
|
const originalAccounts = {
|
||||||
seller: { value: input.seller ?? null, isWritable: true },
|
seller: { value: input.seller ?? null, isWritable: true },
|
||||||
buyer: { value: input.buyer ?? null, isWritable: false },
|
buyer: { value: input.buyer ?? null, isWritable: false },
|
||||||
|
resolver: { value: input.resolver ?? null, isWritable: false },
|
||||||
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
vault: { value: input.vault ?? null, isWritable: true },
|
vault: { value: input.vault ?? null, isWritable: true },
|
||||||
|
resolverEntry: { value: input.resolverEntry ?? null, isWritable: false },
|
||||||
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
|
||||||
};
|
};
|
||||||
const accounts = originalAccounts as Record<
|
const accounts = originalAccounts as Record<
|
||||||
@@ -315,8 +351,10 @@ export function getCreateEscrowInstruction<
|
|||||||
accounts: [
|
accounts: [
|
||||||
getAccountMeta("seller", accounts.seller),
|
getAccountMeta("seller", accounts.seller),
|
||||||
getAccountMeta("buyer", accounts.buyer),
|
getAccountMeta("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("resolver", accounts.resolver),
|
||||||
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
getAccountMeta("vault", accounts.vault),
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("resolverEntry", accounts.resolverEntry),
|
||||||
getAccountMeta("systemProgram", accounts.systemProgram),
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
],
|
],
|
||||||
data: getCreateEscrowInstructionDataEncoder().encode(
|
data: getCreateEscrowInstructionDataEncoder().encode(
|
||||||
@@ -327,8 +365,10 @@ export function getCreateEscrowInstruction<
|
|||||||
TProgramAddress,
|
TProgramAddress,
|
||||||
TAccountSeller,
|
TAccountSeller,
|
||||||
TAccountBuyer,
|
TAccountBuyer,
|
||||||
|
TAccountResolver,
|
||||||
TAccountEscrowAccount,
|
TAccountEscrowAccount,
|
||||||
TAccountVault,
|
TAccountVault,
|
||||||
|
TAccountResolverEntry,
|
||||||
TAccountSystemProgram
|
TAccountSystemProgram
|
||||||
>);
|
>);
|
||||||
}
|
}
|
||||||
@@ -341,9 +381,11 @@ export type ParsedCreateEscrowInstruction<
|
|||||||
accounts: {
|
accounts: {
|
||||||
seller: TAccountMetas[0];
|
seller: TAccountMetas[0];
|
||||||
buyer: TAccountMetas[1];
|
buyer: TAccountMetas[1];
|
||||||
escrowAccount: TAccountMetas[2];
|
resolver: TAccountMetas[2];
|
||||||
vault: TAccountMetas[3];
|
escrowAccount: TAccountMetas[3];
|
||||||
systemProgram: TAccountMetas[4];
|
vault: TAccountMetas[4];
|
||||||
|
resolverEntry: TAccountMetas[5];
|
||||||
|
systemProgram: TAccountMetas[6];
|
||||||
};
|
};
|
||||||
data: CreateEscrowInstructionData;
|
data: CreateEscrowInstructionData;
|
||||||
};
|
};
|
||||||
@@ -356,12 +398,12 @@ export function parseCreateEscrowInstruction<
|
|||||||
InstructionWithAccounts<TAccountMetas> &
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
InstructionWithData<ReadonlyUint8Array>,
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
): ParsedCreateEscrowInstruction<TProgram, TAccountMetas> {
|
): ParsedCreateEscrowInstruction<TProgram, TAccountMetas> {
|
||||||
if (instruction.accounts.length < 5) {
|
if (instruction.accounts.length < 7) {
|
||||||
throw new SolanaError(
|
throw new SolanaError(
|
||||||
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
{
|
{
|
||||||
actualAccountMetas: instruction.accounts.length,
|
actualAccountMetas: instruction.accounts.length,
|
||||||
expectedAccountMetas: 5,
|
expectedAccountMetas: 7,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -376,8 +418,10 @@ export function parseCreateEscrowInstruction<
|
|||||||
accounts: {
|
accounts: {
|
||||||
seller: getNextAccount(),
|
seller: getNextAccount(),
|
||||||
buyer: getNextAccount(),
|
buyer: getNextAccount(),
|
||||||
|
resolver: getNextAccount(),
|
||||||
escrowAccount: getNextAccount(),
|
escrowAccount: getNextAccount(),
|
||||||
vault: getNextAccount(),
|
vault: getNextAccount(),
|
||||||
|
resolverEntry: getNextAccount(),
|
||||||
systemProgram: getNextAccount(),
|
systemProgram: getNextAccount(),
|
||||||
},
|
},
|
||||||
data: getCreateEscrowInstructionDataDecoder().decode(instruction.data),
|
data: getCreateEscrowInstructionDataDecoder().decode(instruction.data),
|
||||||
|
|||||||
@@ -0,0 +1,382 @@
|
|||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
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";
|
||||||
|
import {
|
||||||
|
getWinnerDecoder,
|
||||||
|
getWinnerEncoder,
|
||||||
|
type Winner,
|
||||||
|
type WinnerArgs,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
export const EMERGENCY_RESOLVE_DISCRIMINATOR: ReadonlyUint8Array =
|
||||||
|
new Uint8Array([63, 112, 185, 42, 47, 61, 232, 79]);
|
||||||
|
|
||||||
|
export function getEmergencyResolveDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
EMERGENCY_RESOLVE_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EmergencyResolveInstruction<
|
||||||
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
TAccountBuyer extends string | AccountMeta<string> = string,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountWinner 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
|
||||||
|
? WritableSignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountWinner extends string
|
||||||
|
? WritableAccount<TAccountWinner>
|
||||||
|
: TAccountWinner,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountVault extends string
|
||||||
|
? WritableAccount<TAccountVault>
|
||||||
|
: TAccountVault,
|
||||||
|
TAccountSystemProgram extends string
|
||||||
|
? ReadonlyAccount<TAccountSystemProgram>
|
||||||
|
: TAccountSystemProgram,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type EmergencyResolveInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
winner: Winner;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EmergencyResolveInstructionDataArgs = { winner: WinnerArgs };
|
||||||
|
|
||||||
|
export function getEmergencyResolveInstructionDataEncoder(): FixedSizeEncoder<EmergencyResolveInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([
|
||||||
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
|
["winner", getWinnerEncoder()],
|
||||||
|
]),
|
||||||
|
(value) => ({ ...value, discriminator: EMERGENCY_RESOLVE_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEmergencyResolveInstructionDataDecoder(): FixedSizeDecoder<EmergencyResolveInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
["winner", getWinnerDecoder()],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getEmergencyResolveInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
EmergencyResolveInstructionDataArgs,
|
||||||
|
EmergencyResolveInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getEmergencyResolveInstructionDataEncoder(),
|
||||||
|
getEmergencyResolveInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EmergencyResolveAsyncInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountWinner extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
winner: Address<TAccountWinner>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault?: Address<TAccountVault>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
winnerArg: EmergencyResolveInstructionDataArgs["winner"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getEmergencyResolveInstructionAsync<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountWinner extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: EmergencyResolveAsyncInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): Promise<
|
||||||
|
EmergencyResolveInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
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 },
|
||||||
|
winner: { value: input.winner ?? 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
|
||||||
|
>;
|
||||||
|
|
||||||
|
// 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.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("winner", accounts.winner),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getEmergencyResolveInstructionDataEncoder().encode(
|
||||||
|
args as EmergencyResolveInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as EmergencyResolveInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EmergencyResolveInput<
|
||||||
|
TAccountBuyer extends string = string,
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountWinner extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountVault extends string = string,
|
||||||
|
TAccountSystemProgram extends string = string,
|
||||||
|
> = {
|
||||||
|
buyer: TransactionSigner<TAccountBuyer>;
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
winner: Address<TAccountWinner>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
vault: Address<TAccountVault>;
|
||||||
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
|
winnerArg: EmergencyResolveInstructionDataArgs["winner"];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getEmergencyResolveInstruction<
|
||||||
|
TAccountBuyer extends string,
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountWinner extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountVault extends string,
|
||||||
|
TAccountSystemProgram extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: EmergencyResolveInput<
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): EmergencyResolveInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
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 },
|
||||||
|
winner: { value: input.winner ?? 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
|
||||||
|
>;
|
||||||
|
|
||||||
|
// 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("buyer", accounts.buyer),
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("winner", accounts.winner),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("vault", accounts.vault),
|
||||||
|
getAccountMeta("systemProgram", accounts.systemProgram),
|
||||||
|
],
|
||||||
|
data: getEmergencyResolveInstructionDataEncoder().encode(
|
||||||
|
args as EmergencyResolveInstructionDataArgs,
|
||||||
|
),
|
||||||
|
programAddress,
|
||||||
|
} as EmergencyResolveInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountBuyer,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountWinner,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountVault,
|
||||||
|
TAccountSystemProgram
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedEmergencyResolveInstruction<
|
||||||
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
buyer: TAccountMetas[0];
|
||||||
|
seller: TAccountMetas[1];
|
||||||
|
winner: TAccountMetas[2];
|
||||||
|
escrowAccount: TAccountMetas[3];
|
||||||
|
vault: TAccountMetas[4];
|
||||||
|
systemProgram: TAccountMetas[5];
|
||||||
|
};
|
||||||
|
data: EmergencyResolveInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseEmergencyResolveInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedEmergencyResolveInstruction<TProgram, TAccountMetas> {
|
||||||
|
if (instruction.accounts.length < 6) {
|
||||||
|
throw new SolanaError(
|
||||||
|
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
||||||
|
{
|
||||||
|
actualAccountMetas: instruction.accounts.length,
|
||||||
|
expectedAccountMetas: 6,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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(),
|
||||||
|
winner: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
vault: getNextAccount(),
|
||||||
|
systemProgram: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getEmergencyResolveInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -6,9 +6,12 @@
|
|||||||
* @see https://github.com/codama-idl/codama
|
* @see https://github.com/codama-idl/codama
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export * from "./buyerCreateEscrow";
|
||||||
export * from "./cancel";
|
export * from "./cancel";
|
||||||
export * from "./complete";
|
export * from "./complete";
|
||||||
export * from "./createEscrow";
|
export * from "./createEscrow";
|
||||||
export * from "./deposit";
|
export * from "./deposit";
|
||||||
export * from "./dispute";
|
export * from "./dispute";
|
||||||
|
export * from "./emergencyResolve";
|
||||||
export * from "./resolve";
|
export * from "./resolve";
|
||||||
|
export * from "./sellerConfirm";
|
||||||
|
|||||||
@@ -0,0 +1,222 @@
|
|||||||
|
/**
|
||||||
|
* This code was AUTOGENERATED using the Codama library.
|
||||||
|
* Please DO NOT EDIT THIS FILE, instead use visitors
|
||||||
|
* to add features, then rerun Codama to update it.
|
||||||
|
*
|
||||||
|
* @see https://github.com/codama-idl/codama
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
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,
|
||||||
|
type ResolvedInstructionAccount,
|
||||||
|
} from "@solana/program-client-core";
|
||||||
|
import { DESCRO_PROGRAM_ADDRESS } from "../programs";
|
||||||
|
|
||||||
|
export const SELLER_CONFIRM_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
|
||||||
|
21, 244, 3, 109, 138, 95, 198, 242,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export function getSellerConfirmDiscriminatorBytes(): ReadonlyUint8Array {
|
||||||
|
return fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
SELLER_CONFIRM_DISCRIMINATOR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SellerConfirmInstruction<
|
||||||
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
TAccountSeller extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolver extends string | AccountMeta<string> = string,
|
||||||
|
TAccountEscrowAccount extends string | AccountMeta<string> = string,
|
||||||
|
TAccountResolverEntry extends string | AccountMeta<string> = string,
|
||||||
|
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
||||||
|
> = Instruction<TProgram> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array> &
|
||||||
|
InstructionWithAccounts<
|
||||||
|
[
|
||||||
|
TAccountSeller extends string
|
||||||
|
? ReadonlySignerAccount<TAccountSeller> &
|
||||||
|
AccountSignerMeta<TAccountSeller>
|
||||||
|
: TAccountSeller,
|
||||||
|
TAccountResolver extends string
|
||||||
|
? ReadonlyAccount<TAccountResolver>
|
||||||
|
: TAccountResolver,
|
||||||
|
TAccountEscrowAccount extends string
|
||||||
|
? WritableAccount<TAccountEscrowAccount>
|
||||||
|
: TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry extends string
|
||||||
|
? ReadonlyAccount<TAccountResolverEntry>
|
||||||
|
: TAccountResolverEntry,
|
||||||
|
...TRemainingAccounts,
|
||||||
|
]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type SellerConfirmInstructionData = {
|
||||||
|
discriminator: ReadonlyUint8Array;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SellerConfirmInstructionDataArgs = {};
|
||||||
|
|
||||||
|
export function getSellerConfirmInstructionDataEncoder(): FixedSizeEncoder<SellerConfirmInstructionDataArgs> {
|
||||||
|
return transformEncoder(
|
||||||
|
getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]),
|
||||||
|
(value) => ({ ...value, discriminator: SELLER_CONFIRM_DISCRIMINATOR }),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSellerConfirmInstructionDataDecoder(): FixedSizeDecoder<SellerConfirmInstructionData> {
|
||||||
|
return getStructDecoder([
|
||||||
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSellerConfirmInstructionDataCodec(): FixedSizeCodec<
|
||||||
|
SellerConfirmInstructionDataArgs,
|
||||||
|
SellerConfirmInstructionData
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getSellerConfirmInstructionDataEncoder(),
|
||||||
|
getSellerConfirmInstructionDataDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SellerConfirmInput<
|
||||||
|
TAccountSeller extends string = string,
|
||||||
|
TAccountResolver extends string = string,
|
||||||
|
TAccountEscrowAccount extends string = string,
|
||||||
|
TAccountResolverEntry extends string = string,
|
||||||
|
> = {
|
||||||
|
seller: TransactionSigner<TAccountSeller>;
|
||||||
|
resolver: Address<TAccountResolver>;
|
||||||
|
escrowAccount: Address<TAccountEscrowAccount>;
|
||||||
|
resolverEntry: Address<TAccountResolverEntry>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getSellerConfirmInstruction<
|
||||||
|
TAccountSeller extends string,
|
||||||
|
TAccountResolver extends string,
|
||||||
|
TAccountEscrowAccount extends string,
|
||||||
|
TAccountResolverEntry extends string,
|
||||||
|
TProgramAddress extends Address = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
>(
|
||||||
|
input: SellerConfirmInput<
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry
|
||||||
|
>,
|
||||||
|
config?: { programAddress?: TProgramAddress },
|
||||||
|
): SellerConfirmInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry
|
||||||
|
> {
|
||||||
|
// Program address.
|
||||||
|
const programAddress = config?.programAddress ?? DESCRO_PROGRAM_ADDRESS;
|
||||||
|
|
||||||
|
// Original accounts.
|
||||||
|
const originalAccounts = {
|
||||||
|
seller: { value: input.seller ?? null, isWritable: false },
|
||||||
|
resolver: { value: input.resolver ?? null, isWritable: false },
|
||||||
|
escrowAccount: { value: input.escrowAccount ?? null, isWritable: true },
|
||||||
|
resolverEntry: { value: input.resolverEntry ?? null, isWritable: false },
|
||||||
|
};
|
||||||
|
const accounts = originalAccounts as Record<
|
||||||
|
keyof typeof originalAccounts,
|
||||||
|
ResolvedInstructionAccount
|
||||||
|
>;
|
||||||
|
|
||||||
|
const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
|
||||||
|
return Object.freeze({
|
||||||
|
accounts: [
|
||||||
|
getAccountMeta("seller", accounts.seller),
|
||||||
|
getAccountMeta("resolver", accounts.resolver),
|
||||||
|
getAccountMeta("escrowAccount", accounts.escrowAccount),
|
||||||
|
getAccountMeta("resolverEntry", accounts.resolverEntry),
|
||||||
|
],
|
||||||
|
data: getSellerConfirmInstructionDataEncoder().encode({}),
|
||||||
|
programAddress,
|
||||||
|
} as SellerConfirmInstruction<
|
||||||
|
TProgramAddress,
|
||||||
|
TAccountSeller,
|
||||||
|
TAccountResolver,
|
||||||
|
TAccountEscrowAccount,
|
||||||
|
TAccountResolverEntry
|
||||||
|
>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ParsedSellerConfirmInstruction<
|
||||||
|
TProgram extends string = typeof DESCRO_PROGRAM_ADDRESS,
|
||||||
|
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
||||||
|
> = {
|
||||||
|
programAddress: Address<TProgram>;
|
||||||
|
accounts: {
|
||||||
|
seller: TAccountMetas[0];
|
||||||
|
resolver: TAccountMetas[1];
|
||||||
|
escrowAccount: TAccountMetas[2];
|
||||||
|
resolverEntry: TAccountMetas[3];
|
||||||
|
};
|
||||||
|
data: SellerConfirmInstructionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function parseSellerConfirmInstruction<
|
||||||
|
TProgram extends string,
|
||||||
|
TAccountMetas extends readonly AccountMeta[],
|
||||||
|
>(
|
||||||
|
instruction: Instruction<TProgram> &
|
||||||
|
InstructionWithAccounts<TAccountMetas> &
|
||||||
|
InstructionWithData<ReadonlyUint8Array>,
|
||||||
|
): ParsedSellerConfirmInstruction<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: {
|
||||||
|
seller: getNextAccount(),
|
||||||
|
resolver: getNextAccount(),
|
||||||
|
escrowAccount: getNextAccount(),
|
||||||
|
resolverEntry: getNextAccount(),
|
||||||
|
},
|
||||||
|
data: getSellerConfirmInstructionDataDecoder().decode(instruction.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -38,30 +38,42 @@ import {
|
|||||||
type EscrowAccountArgs,
|
type EscrowAccountArgs,
|
||||||
} from "../accounts";
|
} from "../accounts";
|
||||||
import {
|
import {
|
||||||
getCancelInstruction,
|
getBuyerCreateEscrowInstructionAsync,
|
||||||
|
getCancelInstructionAsync,
|
||||||
getCompleteInstructionAsync,
|
getCompleteInstructionAsync,
|
||||||
getCreateEscrowInstructionAsync,
|
getCreateEscrowInstructionAsync,
|
||||||
getDepositInstructionAsync,
|
getDepositInstructionAsync,
|
||||||
getDisputeInstruction,
|
getDisputeInstruction,
|
||||||
|
getEmergencyResolveInstructionAsync,
|
||||||
getResolveInstructionAsync,
|
getResolveInstructionAsync,
|
||||||
|
getSellerConfirmInstruction,
|
||||||
|
parseBuyerCreateEscrowInstruction,
|
||||||
parseCancelInstruction,
|
parseCancelInstruction,
|
||||||
parseCompleteInstruction,
|
parseCompleteInstruction,
|
||||||
parseCreateEscrowInstruction,
|
parseCreateEscrowInstruction,
|
||||||
parseDepositInstruction,
|
parseDepositInstruction,
|
||||||
parseDisputeInstruction,
|
parseDisputeInstruction,
|
||||||
|
parseEmergencyResolveInstruction,
|
||||||
parseResolveInstruction,
|
parseResolveInstruction,
|
||||||
type CancelInput,
|
parseSellerConfirmInstruction,
|
||||||
|
type BuyerCreateEscrowAsyncInput,
|
||||||
|
type CancelAsyncInput,
|
||||||
type CompleteAsyncInput,
|
type CompleteAsyncInput,
|
||||||
type CreateEscrowAsyncInput,
|
type CreateEscrowAsyncInput,
|
||||||
type DepositAsyncInput,
|
type DepositAsyncInput,
|
||||||
type DisputeInput,
|
type DisputeInput,
|
||||||
|
type EmergencyResolveAsyncInput,
|
||||||
|
type ParsedBuyerCreateEscrowInstruction,
|
||||||
type ParsedCancelInstruction,
|
type ParsedCancelInstruction,
|
||||||
type ParsedCompleteInstruction,
|
type ParsedCompleteInstruction,
|
||||||
type ParsedCreateEscrowInstruction,
|
type ParsedCreateEscrowInstruction,
|
||||||
type ParsedDepositInstruction,
|
type ParsedDepositInstruction,
|
||||||
type ParsedDisputeInstruction,
|
type ParsedDisputeInstruction,
|
||||||
|
type ParsedEmergencyResolveInstruction,
|
||||||
type ParsedResolveInstruction,
|
type ParsedResolveInstruction,
|
||||||
|
type ParsedSellerConfirmInstruction,
|
||||||
type ResolveAsyncInput,
|
type ResolveAsyncInput,
|
||||||
|
type SellerConfirmInput,
|
||||||
} from "../instructions";
|
} from "../instructions";
|
||||||
import {
|
import {
|
||||||
findEscrowAccountPda,
|
findEscrowAccountPda,
|
||||||
@@ -98,18 +110,32 @@ export function identifyDescroAccount(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum DescroInstruction {
|
export enum DescroInstruction {
|
||||||
|
BuyerCreateEscrow,
|
||||||
Cancel,
|
Cancel,
|
||||||
Complete,
|
Complete,
|
||||||
CreateEscrow,
|
CreateEscrow,
|
||||||
Deposit,
|
Deposit,
|
||||||
Dispute,
|
Dispute,
|
||||||
|
EmergencyResolve,
|
||||||
Resolve,
|
Resolve,
|
||||||
|
SellerConfirm,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function identifyDescroInstruction(
|
export function identifyDescroInstruction(
|
||||||
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
|
instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
|
||||||
): DescroInstruction {
|
): DescroInstruction {
|
||||||
const data = "data" in instruction ? instruction.data : instruction;
|
const data = "data" in instruction ? instruction.data : instruction;
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([79, 199, 251, 30, 163, 86, 13, 73]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return DescroInstruction.BuyerCreateEscrow;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
containsBytes(
|
containsBytes(
|
||||||
data,
|
data,
|
||||||
@@ -165,6 +191,17 @@ export function identifyDescroInstruction(
|
|||||||
) {
|
) {
|
||||||
return DescroInstruction.Dispute;
|
return DescroInstruction.Dispute;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([63, 112, 185, 42, 47, 61, 232, 79]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return DescroInstruction.EmergencyResolve;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
containsBytes(
|
containsBytes(
|
||||||
data,
|
data,
|
||||||
@@ -176,6 +213,17 @@ export function identifyDescroInstruction(
|
|||||||
) {
|
) {
|
||||||
return DescroInstruction.Resolve;
|
return DescroInstruction.Resolve;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
containsBytes(
|
||||||
|
data,
|
||||||
|
fixEncoderSize(getBytesEncoder(), 8).encode(
|
||||||
|
new Uint8Array([21, 244, 3, 109, 138, 95, 198, 242]),
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return DescroInstruction.SellerConfirm;
|
||||||
|
}
|
||||||
throw new SolanaError(
|
throw new SolanaError(
|
||||||
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
|
SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
|
||||||
{ instructionData: data, programName: "descro" },
|
{ instructionData: data, programName: "descro" },
|
||||||
@@ -185,6 +233,9 @@ export function identifyDescroInstruction(
|
|||||||
export type ParsedDescroInstruction<
|
export type ParsedDescroInstruction<
|
||||||
TProgram extends string = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3",
|
TProgram extends string = "DjVR4EuYV6USMJFfsGZwhZ3y8rtWsmG8EvDY96GTqqi3",
|
||||||
> =
|
> =
|
||||||
|
| ({
|
||||||
|
instructionType: DescroInstruction.BuyerCreateEscrow;
|
||||||
|
} & ParsedBuyerCreateEscrowInstruction<TProgram>)
|
||||||
| ({
|
| ({
|
||||||
instructionType: DescroInstruction.Cancel;
|
instructionType: DescroInstruction.Cancel;
|
||||||
} & ParsedCancelInstruction<TProgram>)
|
} & ParsedCancelInstruction<TProgram>)
|
||||||
@@ -200,15 +251,28 @@ export type ParsedDescroInstruction<
|
|||||||
| ({
|
| ({
|
||||||
instructionType: DescroInstruction.Dispute;
|
instructionType: DescroInstruction.Dispute;
|
||||||
} & ParsedDisputeInstruction<TProgram>)
|
} & ParsedDisputeInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: DescroInstruction.EmergencyResolve;
|
||||||
|
} & ParsedEmergencyResolveInstruction<TProgram>)
|
||||||
| ({
|
| ({
|
||||||
instructionType: DescroInstruction.Resolve;
|
instructionType: DescroInstruction.Resolve;
|
||||||
} & ParsedResolveInstruction<TProgram>);
|
} & ParsedResolveInstruction<TProgram>)
|
||||||
|
| ({
|
||||||
|
instructionType: DescroInstruction.SellerConfirm;
|
||||||
|
} & ParsedSellerConfirmInstruction<TProgram>);
|
||||||
|
|
||||||
export function parseDescroInstruction<TProgram extends string>(
|
export function parseDescroInstruction<TProgram extends string>(
|
||||||
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
|
instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
|
||||||
): ParsedDescroInstruction<TProgram> {
|
): ParsedDescroInstruction<TProgram> {
|
||||||
const instructionType = identifyDescroInstruction(instruction);
|
const instructionType = identifyDescroInstruction(instruction);
|
||||||
switch (instructionType) {
|
switch (instructionType) {
|
||||||
|
case DescroInstruction.BuyerCreateEscrow: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: DescroInstruction.BuyerCreateEscrow,
|
||||||
|
...parseBuyerCreateEscrowInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
case DescroInstruction.Cancel: {
|
case DescroInstruction.Cancel: {
|
||||||
assertIsInstructionWithAccounts(instruction);
|
assertIsInstructionWithAccounts(instruction);
|
||||||
return {
|
return {
|
||||||
@@ -244,6 +308,13 @@ export function parseDescroInstruction<TProgram extends string>(
|
|||||||
...parseDisputeInstruction(instruction),
|
...parseDisputeInstruction(instruction),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case DescroInstruction.EmergencyResolve: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: DescroInstruction.EmergencyResolve,
|
||||||
|
...parseEmergencyResolveInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
case DescroInstruction.Resolve: {
|
case DescroInstruction.Resolve: {
|
||||||
assertIsInstructionWithAccounts(instruction);
|
assertIsInstructionWithAccounts(instruction);
|
||||||
return {
|
return {
|
||||||
@@ -251,6 +322,13 @@ export function parseDescroInstruction<TProgram extends string>(
|
|||||||
...parseResolveInstruction(instruction),
|
...parseResolveInstruction(instruction),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case DescroInstruction.SellerConfirm: {
|
||||||
|
assertIsInstructionWithAccounts(instruction);
|
||||||
|
return {
|
||||||
|
instructionType: DescroInstruction.SellerConfirm,
|
||||||
|
...parseSellerConfirmInstruction(instruction),
|
||||||
|
};
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new SolanaError(
|
throw new SolanaError(
|
||||||
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
|
SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
|
||||||
@@ -271,9 +349,13 @@ export type DescroPluginAccounts = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type DescroPluginInstructions = {
|
export type DescroPluginInstructions = {
|
||||||
|
buyerCreateEscrow: (
|
||||||
|
input: BuyerCreateEscrowAsyncInput,
|
||||||
|
) => ReturnType<typeof getBuyerCreateEscrowInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
cancel: (
|
cancel: (
|
||||||
input: CancelInput,
|
input: CancelAsyncInput,
|
||||||
) => ReturnType<typeof getCancelInstruction> & SelfPlanAndSendFunctions;
|
) => ReturnType<typeof getCancelInstructionAsync> & SelfPlanAndSendFunctions;
|
||||||
complete: (
|
complete: (
|
||||||
input: CompleteAsyncInput,
|
input: CompleteAsyncInput,
|
||||||
) => ReturnType<typeof getCompleteInstructionAsync> &
|
) => ReturnType<typeof getCompleteInstructionAsync> &
|
||||||
@@ -288,14 +370,22 @@ export type DescroPluginInstructions = {
|
|||||||
dispute: (
|
dispute: (
|
||||||
input: DisputeInput,
|
input: DisputeInput,
|
||||||
) => ReturnType<typeof getDisputeInstruction> & SelfPlanAndSendFunctions;
|
) => ReturnType<typeof getDisputeInstruction> & SelfPlanAndSendFunctions;
|
||||||
|
emergencyResolve: (
|
||||||
|
input: EmergencyResolveAsyncInput,
|
||||||
|
) => ReturnType<typeof getEmergencyResolveInstructionAsync> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
resolve: (
|
resolve: (
|
||||||
input: ResolveAsyncInput,
|
input: ResolveAsyncInput,
|
||||||
) => ReturnType<typeof getResolveInstructionAsync> & SelfPlanAndSendFunctions;
|
) => ReturnType<typeof getResolveInstructionAsync> & SelfPlanAndSendFunctions;
|
||||||
|
sellerConfirm: (
|
||||||
|
input: SellerConfirmInput,
|
||||||
|
) => ReturnType<typeof getSellerConfirmInstruction> &
|
||||||
|
SelfPlanAndSendFunctions;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DescroPluginPdas = {
|
export type DescroPluginPdas = {
|
||||||
vault: typeof findVaultPda;
|
|
||||||
escrowAccount: typeof findEscrowAccountPda;
|
escrowAccount: typeof findEscrowAccountPda;
|
||||||
|
vault: typeof findVaultPda;
|
||||||
escrowAuthority: typeof findEscrowAuthorityPda;
|
escrowAuthority: typeof findEscrowAuthorityPda;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -315,8 +405,16 @@ export function descroProgram() {
|
|||||||
escrowAccount: addSelfFetchFunctions(client, getEscrowAccountCodec()),
|
escrowAccount: addSelfFetchFunctions(client, getEscrowAccountCodec()),
|
||||||
},
|
},
|
||||||
instructions: {
|
instructions: {
|
||||||
|
buyerCreateEscrow: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getBuyerCreateEscrowInstructionAsync(input),
|
||||||
|
),
|
||||||
cancel: (input) =>
|
cancel: (input) =>
|
||||||
addSelfPlanAndSendFunctions(client, getCancelInstruction(input)),
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getCancelInstructionAsync(input),
|
||||||
|
),
|
||||||
complete: (input) =>
|
complete: (input) =>
|
||||||
addSelfPlanAndSendFunctions(
|
addSelfPlanAndSendFunctions(
|
||||||
client,
|
client,
|
||||||
@@ -334,15 +432,25 @@ export function descroProgram() {
|
|||||||
),
|
),
|
||||||
dispute: (input) =>
|
dispute: (input) =>
|
||||||
addSelfPlanAndSendFunctions(client, getDisputeInstruction(input)),
|
addSelfPlanAndSendFunctions(client, getDisputeInstruction(input)),
|
||||||
|
emergencyResolve: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getEmergencyResolveInstructionAsync(input),
|
||||||
|
),
|
||||||
resolve: (input) =>
|
resolve: (input) =>
|
||||||
addSelfPlanAndSendFunctions(
|
addSelfPlanAndSendFunctions(
|
||||||
client,
|
client,
|
||||||
getResolveInstructionAsync(input),
|
getResolveInstructionAsync(input),
|
||||||
),
|
),
|
||||||
|
sellerConfirm: (input) =>
|
||||||
|
addSelfPlanAndSendFunctions(
|
||||||
|
client,
|
||||||
|
getSellerConfirmInstruction(input),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
pdas: {
|
pdas: {
|
||||||
vault: findVaultPda,
|
|
||||||
escrowAccount: findEscrowAccountPda,
|
escrowAccount: findEscrowAccountPda,
|
||||||
|
vault: findVaultPda,
|
||||||
escrowAuthority: findEscrowAuthorityPda,
|
escrowAuthority: findEscrowAuthorityPda,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
|
|
||||||
export enum EscrowState {
|
export enum EscrowState {
|
||||||
AwaitingDeposit,
|
AwaitingDeposit,
|
||||||
|
AwaitingSellerConfirm,
|
||||||
Active,
|
Active,
|
||||||
Disputed,
|
Disputed,
|
||||||
Complete,
|
Complete,
|
||||||
|
|||||||
@@ -47,8 +47,12 @@ import {
|
|||||||
type ReadonlyUint8Array,
|
type ReadonlyUint8Array,
|
||||||
} from "@solana/kit";
|
} from "@solana/kit";
|
||||||
import {
|
import {
|
||||||
|
getAcceptancePolicyDecoder,
|
||||||
|
getAcceptancePolicyEncoder,
|
||||||
getResolverTypeDecoder,
|
getResolverTypeDecoder,
|
||||||
getResolverTypeEncoder,
|
getResolverTypeEncoder,
|
||||||
|
type AcceptancePolicy,
|
||||||
|
type AcceptancePolicyArgs,
|
||||||
type ResolverType,
|
type ResolverType,
|
||||||
type ResolverTypeArgs,
|
type ResolverTypeArgs,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
@@ -67,6 +71,7 @@ export type ResolverEntry = {
|
|||||||
discriminator: ReadonlyUint8Array;
|
discriminator: ReadonlyUint8Array;
|
||||||
authority: Address;
|
authority: Address;
|
||||||
resolverType: ResolverType;
|
resolverType: ResolverType;
|
||||||
|
acceptancePolicy: AcceptancePolicy;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
feeBps: number;
|
feeBps: number;
|
||||||
@@ -81,6 +86,7 @@ export type ResolverEntry = {
|
|||||||
export type ResolverEntryArgs = {
|
export type ResolverEntryArgs = {
|
||||||
authority: Address;
|
authority: Address;
|
||||||
resolverType: ResolverTypeArgs;
|
resolverType: ResolverTypeArgs;
|
||||||
|
acceptancePolicy: AcceptancePolicyArgs;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
feeBps: number;
|
feeBps: number;
|
||||||
@@ -99,6 +105,7 @@ export function getResolverEntryEncoder(): Encoder<ResolverEntryArgs> {
|
|||||||
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
["authority", getAddressEncoder()],
|
["authority", getAddressEncoder()],
|
||||||
["resolverType", getResolverTypeEncoder()],
|
["resolverType", getResolverTypeEncoder()],
|
||||||
|
["acceptancePolicy", getAcceptancePolicyEncoder()],
|
||||||
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
["feeBps", getU16Encoder()],
|
["feeBps", getU16Encoder()],
|
||||||
@@ -119,6 +126,7 @@ export function getResolverEntryDecoder(): Decoder<ResolverEntry> {
|
|||||||
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
["authority", getAddressDecoder()],
|
["authority", getAddressDecoder()],
|
||||||
["resolverType", getResolverTypeDecoder()],
|
["resolverType", getResolverTypeDecoder()],
|
||||||
|
["acceptancePolicy", getAcceptancePolicyDecoder()],
|
||||||
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
["feeBps", getU16Decoder()],
|
["feeBps", getU16Decoder()],
|
||||||
|
|||||||
@@ -50,8 +50,12 @@ import {
|
|||||||
import { findResolverEntryPda } from "../pdas";
|
import { findResolverEntryPda } from "../pdas";
|
||||||
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
|
import { DESCRO_EXT_RESOLVERS_PROGRAM_ADDRESS } from "../programs";
|
||||||
import {
|
import {
|
||||||
|
getAcceptancePolicyDecoder,
|
||||||
|
getAcceptancePolicyEncoder,
|
||||||
getResolverTypeDecoder,
|
getResolverTypeDecoder,
|
||||||
getResolverTypeEncoder,
|
getResolverTypeEncoder,
|
||||||
|
type AcceptancePolicy,
|
||||||
|
type AcceptancePolicyArgs,
|
||||||
type ResolverType,
|
type ResolverType,
|
||||||
type ResolverTypeArgs,
|
type ResolverTypeArgs,
|
||||||
} from "../types";
|
} from "../types";
|
||||||
@@ -93,6 +97,7 @@ export type RegisterResolverInstruction<
|
|||||||
export type RegisterResolverInstructionData = {
|
export type RegisterResolverInstructionData = {
|
||||||
discriminator: ReadonlyUint8Array;
|
discriminator: ReadonlyUint8Array;
|
||||||
resolverType: ResolverType;
|
resolverType: ResolverType;
|
||||||
|
acceptancePolicy: AcceptancePolicy;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
feeBps: number;
|
feeBps: number;
|
||||||
@@ -102,6 +107,7 @@ export type RegisterResolverInstructionData = {
|
|||||||
|
|
||||||
export type RegisterResolverInstructionDataArgs = {
|
export type RegisterResolverInstructionDataArgs = {
|
||||||
resolverType: ResolverTypeArgs;
|
resolverType: ResolverTypeArgs;
|
||||||
|
acceptancePolicy: AcceptancePolicyArgs;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
feeBps: number;
|
feeBps: number;
|
||||||
@@ -114,6 +120,7 @@ export function getRegisterResolverInstructionDataEncoder(): Encoder<RegisterRes
|
|||||||
getStructEncoder([
|
getStructEncoder([
|
||||||
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
["discriminator", fixEncoderSize(getBytesEncoder(), 8)],
|
||||||
["resolverType", getResolverTypeEncoder()],
|
["resolverType", getResolverTypeEncoder()],
|
||||||
|
["acceptancePolicy", getAcceptancePolicyEncoder()],
|
||||||
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
["name", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
["description", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
|
||||||
["feeBps", getU16Encoder()],
|
["feeBps", getU16Encoder()],
|
||||||
@@ -128,6 +135,7 @@ export function getRegisterResolverInstructionDataDecoder(): Decoder<RegisterRes
|
|||||||
return getStructDecoder([
|
return getStructDecoder([
|
||||||
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
["discriminator", fixDecoderSize(getBytesDecoder(), 8)],
|
||||||
["resolverType", getResolverTypeDecoder()],
|
["resolverType", getResolverTypeDecoder()],
|
||||||
|
["acceptancePolicy", getAcceptancePolicyDecoder()],
|
||||||
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
["name", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
["description", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
|
||||||
["feeBps", getU16Decoder()],
|
["feeBps", getU16Decoder()],
|
||||||
@@ -155,6 +163,7 @@ export type RegisterResolverAsyncInput<
|
|||||||
resolverEntry?: Address<TAccountResolverEntry>;
|
resolverEntry?: Address<TAccountResolverEntry>;
|
||||||
systemProgram?: Address<TAccountSystemProgram>;
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
|
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
|
||||||
|
acceptancePolicy: RegisterResolverInstructionDataArgs["acceptancePolicy"];
|
||||||
name: RegisterResolverInstructionDataArgs["name"];
|
name: RegisterResolverInstructionDataArgs["name"];
|
||||||
description: RegisterResolverInstructionDataArgs["description"];
|
description: RegisterResolverInstructionDataArgs["description"];
|
||||||
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
|
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
|
||||||
@@ -242,6 +251,7 @@ export type RegisterResolverInput<
|
|||||||
resolverEntry: Address<TAccountResolverEntry>;
|
resolverEntry: Address<TAccountResolverEntry>;
|
||||||
systemProgram?: Address<TAccountSystemProgram>;
|
systemProgram?: Address<TAccountSystemProgram>;
|
||||||
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
|
resolverType: RegisterResolverInstructionDataArgs["resolverType"];
|
||||||
|
acceptancePolicy: RegisterResolverInstructionDataArgs["acceptancePolicy"];
|
||||||
name: RegisterResolverInstructionDataArgs["name"];
|
name: RegisterResolverInstructionDataArgs["name"];
|
||||||
description: RegisterResolverInstructionDataArgs["description"];
|
description: RegisterResolverInstructionDataArgs["description"];
|
||||||
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
|
feeBps: RegisterResolverInstructionDataArgs["feeBps"];
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* 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 AcceptancePolicy {
|
||||||
|
Open,
|
||||||
|
SignatureGated,
|
||||||
|
ProgramGated,
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AcceptancePolicyArgs = AcceptancePolicy;
|
||||||
|
|
||||||
|
export function getAcceptancePolicyEncoder(): FixedSizeEncoder<AcceptancePolicyArgs> {
|
||||||
|
return getEnumEncoder(AcceptancePolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAcceptancePolicyDecoder(): FixedSizeDecoder<AcceptancePolicy> {
|
||||||
|
return getEnumDecoder(AcceptancePolicy);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAcceptancePolicyCodec(): FixedSizeCodec<
|
||||||
|
AcceptancePolicyArgs,
|
||||||
|
AcceptancePolicy
|
||||||
|
> {
|
||||||
|
return combineCodec(
|
||||||
|
getAcceptancePolicyEncoder(),
|
||||||
|
getAcceptancePolicyDecoder(),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,5 +6,6 @@
|
|||||||
* @see https://github.com/codama-idl/codama
|
* @see https://github.com/codama-idl/codama
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export * from "./acceptancePolicy";
|
||||||
export * from "./resolverType";
|
export * from "./resolverType";
|
||||||
export * from "./ruling";
|
export * from "./ruling";
|
||||||
|
|||||||
@@ -7,6 +7,98 @@
|
|||||||
"description": "Created with Anchor"
|
"description": "Created with Anchor"
|
||||||
},
|
},
|
||||||
"instructions": [
|
"instructions": [
|
||||||
|
{
|
||||||
|
"name": "buyer_create_escrow",
|
||||||
|
"discriminator": [
|
||||||
|
79,
|
||||||
|
199,
|
||||||
|
251,
|
||||||
|
30,
|
||||||
|
163,
|
||||||
|
86,
|
||||||
|
13,
|
||||||
|
73
|
||||||
|
],
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"name": "buyer",
|
||||||
|
"writable": true,
|
||||||
|
"signer": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seller"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "escrow_account",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
101,
|
||||||
|
115,
|
||||||
|
99,
|
||||||
|
114,
|
||||||
|
111,
|
||||||
|
119
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "seller"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "arg",
|
||||||
|
"path": "escrow_id"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vault",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
118,
|
||||||
|
97,
|
||||||
|
117,
|
||||||
|
108,
|
||||||
|
116
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "system_program",
|
||||||
|
"address": "11111111111111111111111111111111"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"args": [
|
||||||
|
{
|
||||||
|
"name": "amount",
|
||||||
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dispute_resolver",
|
||||||
|
"type": {
|
||||||
|
"option": "pubkey"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "escrow_id",
|
||||||
|
"type": "u64"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "cancel",
|
"name": "cancel",
|
||||||
"discriminator": [
|
"discriminator": [
|
||||||
@@ -21,10 +113,14 @@
|
|||||||
],
|
],
|
||||||
"accounts": [
|
"accounts": [
|
||||||
{
|
{
|
||||||
"name": "seller",
|
"name": "canceller",
|
||||||
"writable": true,
|
"writable": true,
|
||||||
"signer": true
|
"signer": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "buyer",
|
||||||
|
"writable": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "escrow_account",
|
"name": "escrow_account",
|
||||||
"writable": true,
|
"writable": true,
|
||||||
@@ -54,6 +150,28 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "vault",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
118,
|
||||||
|
97,
|
||||||
|
117,
|
||||||
|
108,
|
||||||
|
116
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"address": "11111111111111111111111111111111"
|
||||||
@@ -161,6 +279,9 @@
|
|||||||
{
|
{
|
||||||
"name": "buyer"
|
"name": "buyer"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "resolver"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "escrow_account",
|
"name": "escrow_account",
|
||||||
"writable": true,
|
"writable": true,
|
||||||
@@ -210,6 +331,9 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "resolver_entry"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "system_program",
|
"name": "system_program",
|
||||||
"address": "11111111111111111111111111111111"
|
"address": "11111111111111111111111111111111"
|
||||||
@@ -357,6 +481,99 @@
|
|||||||
],
|
],
|
||||||
"args": []
|
"args": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "emergency_resolve",
|
||||||
|
"discriminator": [
|
||||||
|
63,
|
||||||
|
112,
|
||||||
|
185,
|
||||||
|
42,
|
||||||
|
47,
|
||||||
|
61,
|
||||||
|
232,
|
||||||
|
79
|
||||||
|
],
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"name": "buyer",
|
||||||
|
"signer": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seller",
|
||||||
|
"writable": true,
|
||||||
|
"signer": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "winner",
|
||||||
|
"writable": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "escrow_account",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
101,
|
||||||
|
115,
|
||||||
|
99,
|
||||||
|
114,
|
||||||
|
111,
|
||||||
|
119
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account.seller",
|
||||||
|
"account": "EscrowAccount"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account.escrow_id",
|
||||||
|
"account": "EscrowAccount"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "vault",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
118,
|
||||||
|
97,
|
||||||
|
117,
|
||||||
|
108,
|
||||||
|
116
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "system_program",
|
||||||
|
"address": "11111111111111111111111111111111"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"args": [
|
||||||
|
{
|
||||||
|
"name": "winner",
|
||||||
|
"type": {
|
||||||
|
"defined": {
|
||||||
|
"name": "Winner"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "resolve",
|
"name": "resolve",
|
||||||
"discriminator": [
|
"discriminator": [
|
||||||
@@ -542,6 +759,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "seller_confirm",
|
||||||
|
"discriminator": [
|
||||||
|
21,
|
||||||
|
244,
|
||||||
|
3,
|
||||||
|
109,
|
||||||
|
138,
|
||||||
|
95,
|
||||||
|
198,
|
||||||
|
242
|
||||||
|
],
|
||||||
|
"accounts": [
|
||||||
|
{
|
||||||
|
"name": "seller",
|
||||||
|
"signer": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "resolver"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "escrow_account",
|
||||||
|
"writable": true,
|
||||||
|
"pda": {
|
||||||
|
"seeds": [
|
||||||
|
{
|
||||||
|
"kind": "const",
|
||||||
|
"value": [
|
||||||
|
101,
|
||||||
|
115,
|
||||||
|
99,
|
||||||
|
114,
|
||||||
|
111,
|
||||||
|
119
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "seller"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "account",
|
||||||
|
"path": "escrow_account.escrow_id",
|
||||||
|
"account": "EscrowAccount"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "resolver_entry"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"args": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"accounts": [
|
"accounts": [
|
||||||
@@ -584,6 +855,26 @@
|
|||||||
"code": 6004,
|
"code": 6004,
|
||||||
"name": "Expired",
|
"name": "Expired",
|
||||||
"msg": "Escrow has expired"
|
"msg": "Escrow has expired"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 6005,
|
||||||
|
"name": "DisputeTimeoutNotReached",
|
||||||
|
"msg": "Dispute timeout period has not elapsed yet"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 6006,
|
||||||
|
"name": "InsufficientVaultBalance",
|
||||||
|
"msg": "Vault balance is insufficient for the requested escrow amount"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 6007,
|
||||||
|
"name": "AmountBelowRentMinimum",
|
||||||
|
"msg": "Amount must be at least rent-exempt minimum for the vault (~890880 lamports)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code": 6008,
|
||||||
|
"name": "ResolverSignatureRequired",
|
||||||
|
"msg": "Resolver must co-sign this transaction (SignatureGated acceptance policy)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
@@ -629,6 +920,12 @@
|
|||||||
{
|
{
|
||||||
"name": "escrow_id",
|
"name": "escrow_id",
|
||||||
"type": "u64"
|
"type": "u64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dispute_raised_at",
|
||||||
|
"type": {
|
||||||
|
"option": "i64"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -641,6 +938,9 @@
|
|||||||
{
|
{
|
||||||
"name": "AwaitingDeposit"
|
"name": "AwaitingDeposit"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "AwaitingSellerConfirm"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Active"
|
"name": "Active"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -64,6 +64,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "acceptance_policy",
|
||||||
|
"type": {
|
||||||
|
"defined": {
|
||||||
|
"name": "AcceptancePolicy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -285,6 +293,23 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "AcceptancePolicy",
|
||||||
|
"type": {
|
||||||
|
"kind": "enum",
|
||||||
|
"variants": [
|
||||||
|
{
|
||||||
|
"name": "Open"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SignatureGated"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ProgramGated"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "ResolverEntry",
|
"name": "ResolverEntry",
|
||||||
"type": {
|
"type": {
|
||||||
@@ -302,6 +327,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "acceptance_policy",
|
||||||
|
"type": {
|
||||||
|
"defined": {
|
||||||
|
"name": "AcceptancePolicy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "name",
|
"name": "name",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|||||||
Reference in New Issue
Block a user