import {z} from 'zod' export type Int32Parameter = {eq?: (number | null) | undefined, ne?: (number | null) | undefined, gt?: (number | null) | undefined, ge?: (number | null) | undefined, lt?: (number | null) | undefined, le?: (number | null) | undefined, in?: (Array | null) | undefined, ni?: (Array | null) | undefined}; export type SortParameter = {asc?: (string | null) | undefined, desc?: (string | null) | undefined}; export type OffsetParameter = {el?: (number | null) | undefined, pg?: (number | null) | undefined, cr?: (number | null) | undefined}; export type SelectionParameter = {fields?: (Array | null) | undefined, values?: (Array | null) | undefined}; export type Symbols = 'None' | 'Btc' | 'Eur' | 'Usd' | 'Cny' | 'Jpy' | 'Krw' | 'Eth' | 'Gbp'; export type GetApiV1RewardsStakersAddressArgs = {address: string, cycle?: (Int32Parameter | null) | undefined, sort?: (SortParameter | null) | undefined, offset?: (OffsetParameter | null) | undefined, limit?: number | undefined, select?: (SelectionParameter | null) | undefined, quote?: Symbols | undefined}; export type GetApiV1RewardsStakersAddressOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const alias = z.object({alias: z.string().nullable().optional(), address: z.string()}); export const quoteShort = z.object({btc: z.number().nullable().optional(), eur: z.number().nullable().optional(), usd: z.number().nullable().optional(), cny: z.number().nullable().optional(), jpy: z.number().nullable().optional(), krw: z.number().nullable().optional(), eth: z.number().nullable().optional(), gbp: z.number().nullable().optional()}); export const bakerRewards = z.object({cycle: z.number().int().optional(), ownDelegatedBalance: z.number().int().optional(), externalDelegatedBalance: z.number().int().optional(), delegatorsCount: z.number().int().optional(), ownStakedBalance: z.number().int().optional(), externalStakedBalance: z.number().int().optional(), stakersCount: z.number().int().optional(), issuedPseudotokens: z.string().nullable().optional(), bakingPower: z.number().int().optional(), totalBakingPower: z.number().int().optional(), expectedBlocks: z.number().optional(), futureBlocks: z.number().int().optional(), futureBlockRewards: z.number().int().optional(), blocks: z.number().int().optional(), blockRewardsDelegated: z.number().int().optional(), blockRewardsStakedOwn: z.number().int().optional(), blockRewardsStakedEdge: z.number().int().optional(), blockRewardsStakedShared: z.number().int().optional(), missedBlocks: z.number().int().optional(), missedBlockRewards: z.number().int().optional(), expectedAttestations: z.number().optional(), futureAttestations: z.number().int().optional(), futureAttestationRewards: z.number().int().optional(), attestations: z.number().int().optional(), attestationRewardsDelegated: z.number().int().optional(), attestationRewardsStakedOwn: z.number().int().optional(), attestationRewardsStakedEdge: z.number().int().optional(), attestationRewardsStakedShared: z.number().int().optional(), missedAttestations: z.number().int().optional(), missedAttestationRewards: z.number().int().optional(), expectedDalAttestations: z.number().int().optional(), futureDalAttestationRewards: z.number().int().optional(), dalAttestationRewardsDelegated: z.number().int().optional(), dalAttestationRewardsStakedOwn: z.number().int().optional(), dalAttestationRewardsStakedEdge: z.number().int().optional(), dalAttestationRewardsStakedShared: z.number().int().optional(), missedDalAttestationRewards: z.number().int().optional(), blockFees: z.number().int().optional(), missedBlockFees: z.number().int().optional(), doubleBakingRewards: z.number().int().optional(), doubleBakingLostStaked: z.number().int().optional(), doubleBakingLostUnstaked: z.number().int().optional(), doubleBakingLostExternalStaked: z.number().int().optional(), doubleBakingLostExternalUnstaked: z.number().int().optional(), doubleConsensusRewards: z.number().int().optional(), doubleConsensusLostStaked: z.number().int().optional(), doubleConsensusLostUnstaked: z.number().int().optional(), doubleConsensusLostExternalStaked: z.number().int().optional(), doubleConsensusLostExternalUnstaked: z.number().int().optional(), vdfRevelationRewardsDelegated: z.number().int().optional(), vdfRevelationRewardsStakedOwn: z.number().int().optional(), vdfRevelationRewardsStakedEdge: z.number().int().optional(), vdfRevelationRewardsStakedShared: z.number().int().optional(), nonceRevelationRewardsDelegated: z.number().int().optional(), nonceRevelationRewardsStakedOwn: z.number().int().optional(), nonceRevelationRewardsStakedEdge: z.number().int().optional(), nonceRevelationRewardsStakedShared: z.number().int().optional(), nonceRevelationLosses: z.number().int().optional(), quote: quoteShort.nullable().optional(), expectedDalShards: z.number().int().optional(), expectedEndorsements: z.number().optional(), futureEndorsements: z.number().int().optional(), futureEndorsementRewards: z.number().int().optional(), endorsements: z.number().int().optional(), endorsementRewardsDelegated: z.number().int().optional(), endorsementRewardsStakedOwn: z.number().int().optional(), endorsementRewardsStakedEdge: z.number().int().optional(), endorsementRewardsStakedShared: z.number().int().optional(), missedEndorsements: z.number().int().optional(), missedEndorsementRewards: z.number().int().optional(), doubleEndorsingRewards: z.number().int().optional(), doubleEndorsingLostStaked: z.number().int().optional(), doubleEndorsingLostUnstaked: z.number().int().optional(), doubleEndorsingLostExternalStaked: z.number().int().optional(), doubleEndorsingLostExternalUnstaked: z.number().int().optional(), doublePreendorsingRewards: z.number().int().optional(), doublePreendorsingLostStaked: z.number().int().optional(), doublePreendorsingLostUnstaked: z.number().int().optional(), doublePreendorsingLostExternalStaked: z.number().int().optional(), doublePreendorsingLostExternalUnstaked: z.number().int().optional()}); export const stakerRewards = z.object({cycle: z.number().int().optional(), baker: alias, initialStake: z.number().int().optional(), addedStake: z.number().int().optional(), removedStake: z.number().int().optional(), finalStake: z.number().int().optional(), avgStake: z.number().int().optional(), rewards: z.number().int().optional(), bakerRewards: bakerRewards, quote: quoteShort.nullable().optional()}); export const getApiV1RewardsStakersAddressResponse = z.array(stakerRewards); 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 staker cycle rewards * * GET /v1/rewards/stakers/{address} */ export const getApiV1RewardsStakersAddress = async (args: GetApiV1RewardsStakersAddressArgs, options?: GetApiV1RewardsStakersAddressOptions) => { const {baseUrl = "https://api.tzkt.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cycle != null) query.append("cycle", JSON.stringify(args.cycle)) if (args.sort != null) query.append("sort", JSON.stringify(args.sort)) if (args.offset != null) query.append("offset", JSON.stringify(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.select != null) query.append("select", JSON.stringify(args.select)) if (args.quote != null) query.append("quote", String(args.quote)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/rewards/stakers/${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(getApiV1RewardsStakersAddressResponse, await res.json()) };