import {z} from 'zod' export type GetApiInstructionsSellCancelArgs = {seller: string, auctionHouseAddress?: string | undefined, tokenMint: string, tokenAccount: string, price: number, sellerReferral?: string | undefined, expiry?: number | undefined, priorityFee?: number | undefined, prioFeeMicroLamports?: number | undefined, maxPrioFeeLamports?: number | undefined, exactPrioFeeLamports?: number | undefined}; export type GetApiInstructionsSellCancelOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const iBuffer = z.object({type: z.literal("Buffer"), data: z.array(z.number())}); export const transaction = z.object({tx: iBuffer, txSigned: iBuffer.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get instruction to cancel a sell * * GET /instructions/sell_cancel */ export const getApiInstructionsSellCancel = async (args: GetApiInstructionsSellCancelArgs, options?: GetApiInstructionsSellCancelOptions) => { const {baseUrl = "https://api-mainnet.magiceden.dev/v2", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.seller != null) query.append("seller", String(args.seller)) if (args.auctionHouseAddress != null) query.append("auctionHouseAddress", String(args.auctionHouseAddress)) if (args.tokenMint != null) query.append("tokenMint", String(args.tokenMint)) if (args.tokenAccount != null) query.append("tokenAccount", String(args.tokenAccount)) if (args.price != null) query.append("price", String(args.price)) if (args.sellerReferral != null) query.append("sellerReferral", String(args.sellerReferral)) if (args.expiry != null) query.append("expiry", String(args.expiry)) if (args.priorityFee != null) query.append("priorityFee", String(args.priorityFee)) if (args.prioFeeMicroLamports != null) query.append("prioFeeMicroLamports", String(args.prioFeeMicroLamports)) if (args.maxPrioFeeLamports != null) query.append("maxPrioFeeLamports", String(args.maxPrioFeeLamports)) if (args.exactPrioFeeLamports != null) query.append("exactPrioFeeLamports", String(args.exactPrioFeeLamports)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/instructions/sell_cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(transaction, await res.json()) };