import {z} from 'zod' export type GetApiInstructionsMmmUpdatePoolArgs = {pool: string, spotPrice: number, curveType: string, curveDelta: number, reinvestBuy: boolean, reinvestSell: boolean, expiry: number, lpFeeBp: number, buysideCreatorRoyaltyBp: number, priorityFee?: number | undefined, sharedEscrowCount?: number | undefined}; export type GetApiInstructionsMmmUpdatePoolOptions = {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 update an existing pool * * GET /instructions/mmm/update-pool */ export const getApiInstructionsMmmUpdatePool = async (args: GetApiInstructionsMmmUpdatePoolArgs, options?: GetApiInstructionsMmmUpdatePoolOptions) => { 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.pool != null) query.append("pool", String(args.pool)) if (args.spotPrice != null) query.append("spotPrice", String(args.spotPrice)) if (args.curveType != null) query.append("curveType", String(args.curveType)) if (args.curveDelta != null) query.append("curveDelta", String(args.curveDelta)) if (args.reinvestBuy != null) query.append("reinvestBuy", String(args.reinvestBuy)) if (args.reinvestSell != null) query.append("reinvestSell", String(args.reinvestSell)) if (args.expiry != null) query.append("expiry", String(args.expiry)) if (args.lpFeeBp != null) query.append("lpFeeBp", String(args.lpFeeBp)) if (args.buysideCreatorRoyaltyBp != null) query.append("buysideCreatorRoyaltyBp", String(args.buysideCreatorRoyaltyBp)) if (args.priorityFee != null) query.append("priorityFee", String(args.priorityFee)) if (args.sharedEscrowCount != null) query.append("sharedEscrowCount", String(args.sharedEscrowCount)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/instructions/mmm/update-pool${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()) };