import {z} from 'zod' export type TransitResponseFormat = 'encoded' | 'full' | 'structured'; export type TransitFeeTier = 'zeroFee' | 'standardFee'; export type GetApiPaxosTransitOrdersQuoteArgs = {userAddress: string, offerAsset: string, wantAsset: string, offerAmount: string, sourceChainId: number, destinationChainId: number, permitSignature?: string | undefined, permitDeadline?: number | undefined, responseFormat?: TransitResponseFormat | undefined, feeTier?: TransitFeeTier | undefined}; export type GetApiPaxosTransitOrdersQuoteOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const paxosResponseBody = z.record(z.string(), z.unknown()); 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 }; /** * Signed submitOrder calldata. feeTier=zeroFee needs a whitelisted address, the USDC/USDG route on this chain and enough capacity. * * GET /paxos/transit/orders/quote */ export const getApiPaxosTransitOrdersQuote = async (args: GetApiPaxosTransitOrdersQuoteArgs, options?: GetApiPaxosTransitOrdersQuoteOptions) => { const {baseUrl = "https://arbitrum.gmxapi.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userAddress != null) query.append("userAddress", String(args.userAddress)) if (args.offerAsset != null) query.append("offerAsset", String(args.offerAsset)) if (args.wantAsset != null) query.append("wantAsset", String(args.wantAsset)) if (args.offerAmount != null) query.append("offerAmount", String(args.offerAmount)) if (args.sourceChainId != null) query.append("sourceChainId", String(args.sourceChainId)) if (args.destinationChainId != null) query.append("destinationChainId", String(args.destinationChainId)) if (args.permitSignature != null) query.append("permitSignature", String(args.permitSignature)) if (args.permitDeadline != null) query.append("permitDeadline", String(args.permitDeadline)) if (args.responseFormat != null) query.append("responseFormat", String(args.responseFormat)) if (args.feeTier != null) query.append("feeTier", String(args.feeTier)) const url = `${baseUrl.replace(/\/+$/, '')}/paxos/transit/orders/quote${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(paxosResponseBody, await res.json()) };