import {z} from 'zod' export type GetApiV1WalletsWalletIdEthereumYieldVaultArgs = {wallet_id: string, vault_id: string, include_archived?: boolean | undefined, 'privy-app-id': string}; export type GetApiV1WalletsWalletIdEthereumYieldVaultOptions = {baseUrl?: string | undefined, appSecretAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const vaultAsset = z.object({address: z.string(), symbol: z.string()}); export const ethereumYieldPositionResponse = z.object({asset: vaultAsset, total_deposited: z.string(), total_withdrawn: z.string(), assets_in_vault: z.string(), shares_in_vault: z.string()}); 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 Ethereum Yield Vault Position * * GET /v1/wallets/{wallet_id}/ethereum_yield_vault */ export const getApiV1WalletsWalletIdEthereumYieldVault = async (args: GetApiV1WalletsWalletIdEthereumYieldVaultArgs, options?: GetApiV1WalletsWalletIdEthereumYieldVaultOptions) => { const {baseUrl = "https://api.privy.io", fetch: fetchFn = fetch, appSecretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.vault_id != null) query.append("vault_id", String(args.vault_id)) if (args.include_archived != null) query.append("include_archived", String(args.include_archived)) if (args['privy-app-id'] != null) headers.set("privy-app-id", String(args['privy-app-id'])) if (appSecretAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${appSecretAuth.username}:${appSecretAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/wallets/${encodeURIComponent(String(args.wallet_id))}/ethereum_yield_vault${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(ethereumYieldPositionResponse, await res.json()) };