import {z} from 'zod' export type GetApiV2OrdBtcRunesWalletActivitiesAddressArgs = {address: unknown | unknown | unknown, offset?: number | undefined}; export type GetApiV2OrdBtcRunesWalletActivitiesAddressOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const runeActivitySchema = z.object({id: z.string().optional(), kind: z.string().optional(), oldOwner: z.string().nullable().optional(), newOwner: z.string().nullable().optional(), rune: z.string().optional(), amount: z.string().nullable().optional(), txValue: z.string().nullable().optional(), txId: z.string().nullable().optional(), txBlockTime: z.string().nullable().optional(), txBlockHeight: z.number().int().nullable().optional(), txBlockHash: z.string().nullable().optional(), deletedAt: z.string().nullable().optional(), createdAt: z.string().optional(), listedPrice: z.string().nullable().optional(), listedMakerFeeBp: z.number().int().nullable().optional(), listedTakerFeeBp: z.number().int().nullable().optional(), btcUsdPrice: z.string().nullable().optional(), sellerPaymentReceiverAddress: z.string().nullable().optional(), buyerPaymentAddress: z.string().nullable().optional()}); export const getRuneActivitiesByAddressResultSchema = z.object({activities: z.array(runeActivitySchema).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 Rune activities for a specific wallet address * * GET /v2/ord/btc/runes/wallet/activities/{address} */ export const getApiV2OrdBtcRunesWalletActivitiesAddress = async (args: GetApiV2OrdBtcRunesWalletActivitiesAddressArgs, options?: GetApiV2OrdBtcRunesWalletActivitiesAddressOptions) => { const {baseUrl = "https://api-mainnet.magiceden.dev/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/v2/ord/btc/runes/wallet/activities/${encodeURIComponent(String(args.address))}${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(getRuneActivitiesByAddressResultSchema, await res.json()) };