import {z} from 'zod' export type GetApiV1CompetitionLeaderboardEntryArgs = {address?: string | undefined, type?: ('COMPETITION_LEADERBOARD_TYPE_ACTIVE' | 'COMPETITION_LEADERBOARD_TYPE_ALL_TIME') | undefined}; export type GetApiV1CompetitionLeaderboardEntryOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const apiCompetitionLeaderboardEntry = z.object({rank: z.string().optional(), address: z.string().optional(), username: z.string().optional(), equity: z.string().optional(), roi_percent: z.string().optional(), trades_executed: z.string().optional(), account_equity: z.string().optional(), total_volume: z.string().optional(), unrealized_pnl: z.string().optional(), reward_wallet: z.string().optional(), profile_image_url: z.string().optional(), x_profile: z.object({}).optional()}); export const apiGetCompetitionLeaderboardEntryResponse = z.object({entry: apiCompetitionLeaderboardEntry.optional(), start_time: z.string().optional(), end_time: z.string().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 competition leaderboard entry * * GET /v1/competition/leaderboard/entry */ export const getApiV1CompetitionLeaderboardEntry = async (args: GetApiV1CompetitionLeaderboardEntryArgs, options?: GetApiV1CompetitionLeaderboardEntryOptions) => { const {baseUrl = "https://api.testnet.rise.trade", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.address != null) query.append("address", String(args.address)) if (args.type != null) query.append("type", String(args.type)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/competition/leaderboard/entry${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(apiGetCompetitionLeaderboardEntryResponse, await res.json()) };