import {z} from 'zod' export type GetApiSapiV1EthStakingEthHistoryWbethRewardsHistoryArgs = {startTime?: number | undefined, endTime?: number | undefined, current?: number | undefined, size?: number | undefined, recvWindow?: number | undefined, timestamp: number, signature: string}; export type GetApiSapiV1EthStakingEthHistoryWbethRewardsHistoryOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSapiV1EthStakingEthHistoryWbethRewardsHistoryResponse = z.object({estRewardsInETH: z.string(), rows: z.array(z.object({time: z.number().int(), amountInETH: z.string(), holding: z.string(), holdingInETH: z.string(), annualPercentageRate: z.string()})), total: z.number().int()}); 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 WBETH rewards history(USER_DATA) * * GET /sapi/v1/eth-staking/eth/history/wbethRewardsHistory */ export const getApiSapiV1EthStakingEthHistoryWbethRewardsHistory = async (args: GetApiSapiV1EthStakingEthHistoryWbethRewardsHistoryArgs, options?: GetApiSapiV1EthStakingEthHistoryWbethRewardsHistoryOptions) => { const {baseUrl = "https://api.binance.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.current != null) query.append("current", String(args.current)) if (args.size != null) query.append("size", String(args.size)) if (args.recvWindow != null) query.append("recvWindow", String(args.recvWindow)) if (args.timestamp != null) query.append("timestamp", String(args.timestamp)) if (args.signature != null) query.append("signature", String(args.signature)) if (ApiKeyAuth !== undefined) headers.set("X-MBX-APIKEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/sapi/v1/eth-staking/eth/history/wbethRewardsHistory${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(getApiSapiV1EthStakingEthHistoryWbethRewardsHistoryResponse, await res.json()) };