|
| 1 | +import { z } from 'zod'; |
| 2 | + |
| 3 | +function createCursorPageSchema<TItem extends z.ZodTypeAny>(item: TItem) { |
| 4 | + return z.object({ |
| 5 | + count: z.number(), |
| 6 | + data: z.array(item), |
| 7 | + limit: z.number(), |
| 8 | + next_cursor: z.string(), |
| 9 | + }); |
| 10 | +} |
| 11 | + |
| 12 | +export const ClosedOnlyModeSchema = z.object({ |
| 13 | + closed_only: z.boolean(), |
| 14 | +}); |
| 15 | + |
| 16 | +export type ClosedOnlyMode = z.infer<typeof ClosedOnlyModeSchema>; |
| 17 | + |
| 18 | +export const OpenOrderSchema = z.object({ |
| 19 | + asset_id: z.string(), |
| 20 | + associate_trades: z.array(z.string()), |
| 21 | + created_at: z.number(), |
| 22 | + expiration: z.string(), |
| 23 | + id: z.string(), |
| 24 | + maker_address: z.string(), |
| 25 | + market: z.string(), |
| 26 | + order_type: z.string(), |
| 27 | + original_size: z.string(), |
| 28 | + outcome: z.string(), |
| 29 | + owner: z.string(), |
| 30 | + price: z.string(), |
| 31 | + side: z.string(), |
| 32 | + size_matched: z.string(), |
| 33 | + status: z.string(), |
| 34 | +}); |
| 35 | + |
| 36 | +export type OpenOrder = z.infer<typeof OpenOrderSchema>; |
| 37 | + |
| 38 | +export const OpenOrdersPageSchema = createCursorPageSchema(OpenOrderSchema); |
| 39 | + |
| 40 | +export type OpenOrdersPage = z.infer<typeof OpenOrdersPageSchema>; |
| 41 | + |
| 42 | +export const MakerOrderSchema = z.object({ |
| 43 | + asset_id: z.string(), |
| 44 | + fee_rate_bps: z.string(), |
| 45 | + maker_address: z.string(), |
| 46 | + matched_amount: z.string(), |
| 47 | + order_id: z.string(), |
| 48 | + outcome: z.string(), |
| 49 | + owner: z.string(), |
| 50 | + price: z.string(), |
| 51 | + side: z.string(), |
| 52 | +}); |
| 53 | + |
| 54 | +export const ClobTradeSchema = z.object({ |
| 55 | + asset_id: z.string(), |
| 56 | + bucket_index: z.number(), |
| 57 | + fee_rate_bps: z.string(), |
| 58 | + id: z.string(), |
| 59 | + last_update: z.string(), |
| 60 | + maker_address: z.string(), |
| 61 | + maker_orders: z.array(MakerOrderSchema), |
| 62 | + market: z.string(), |
| 63 | + match_time: z.string(), |
| 64 | + outcome: z.string(), |
| 65 | + owner: z.string(), |
| 66 | + price: z.string(), |
| 67 | + side: z.string(), |
| 68 | + size: z.string(), |
| 69 | + status: z.string(), |
| 70 | + taker_order_id: z.string(), |
| 71 | + trader_side: z.enum(['TAKER', 'MAKER']), |
| 72 | + transaction_hash: z.string(), |
| 73 | +}); |
| 74 | + |
| 75 | +export type ClobTrade = z.infer<typeof ClobTradeSchema>; |
| 76 | + |
| 77 | +export const ClobTradesPageSchema = createCursorPageSchema(ClobTradeSchema); |
| 78 | + |
| 79 | +export type ClobTradesPage = z.infer<typeof ClobTradesPageSchema>; |
| 80 | + |
| 81 | +export const NotificationSchema = z.object({ |
| 82 | + owner: z.string(), |
| 83 | + payload: z.unknown(), |
| 84 | + type: z.number(), |
| 85 | +}); |
| 86 | + |
| 87 | +export type Notification = z.infer<typeof NotificationSchema>; |
| 88 | + |
| 89 | +export const NotificationsResponseSchema = z.array(NotificationSchema); |
| 90 | + |
| 91 | +export type NotificationsResponse = z.infer<typeof NotificationsResponseSchema>; |
| 92 | + |
| 93 | +export enum AssetType { |
| 94 | + COLLATERAL = 'COLLATERAL', |
| 95 | + CONDITIONAL = 'CONDITIONAL', |
| 96 | +} |
| 97 | + |
| 98 | +export const AssetTypeSchema = z.nativeEnum(AssetType); |
| 99 | + |
| 100 | +export const BalanceAllowanceResponseSchema = z.object({ |
| 101 | + allowances: z.record(z.string(), z.string()), |
| 102 | + balance: z.string(), |
| 103 | +}); |
| 104 | + |
| 105 | +export type BalanceAllowanceResponse = z.infer< |
| 106 | + typeof BalanceAllowanceResponseSchema |
| 107 | +>; |
| 108 | + |
| 109 | +export const OrderScoringResponseSchema = z.object({ |
| 110 | + scoring: z.boolean(), |
| 111 | +}); |
| 112 | + |
| 113 | +export type OrderScoringResponse = z.infer<typeof OrderScoringResponseSchema>; |
| 114 | + |
| 115 | +export const OrdersScoringResponseSchema = z.record(z.string(), z.boolean()); |
| 116 | + |
| 117 | +export type OrdersScoringResponse = z.infer<typeof OrdersScoringResponseSchema>; |
| 118 | + |
| 119 | +export const UserEarningSchema = z.object({ |
| 120 | + asset_address: z.string(), |
| 121 | + asset_rate: z.number(), |
| 122 | + condition_id: z.string(), |
| 123 | + date: z.string(), |
| 124 | + earnings: z.number(), |
| 125 | + maker_address: z.string(), |
| 126 | +}); |
| 127 | + |
| 128 | +export type UserEarning = z.infer<typeof UserEarningSchema>; |
| 129 | + |
| 130 | +export const UserEarningsPageSchema = createCursorPageSchema(UserEarningSchema); |
| 131 | + |
| 132 | +export type UserEarningsPage = z.infer<typeof UserEarningsPageSchema>; |
| 133 | + |
| 134 | +export const TotalUserEarningSchema = z.object({ |
| 135 | + asset_address: z.string(), |
| 136 | + asset_rate: z.number(), |
| 137 | + date: z.string(), |
| 138 | + earnings: z.number(), |
| 139 | + maker_address: z.string(), |
| 140 | +}); |
| 141 | + |
| 142 | +export type TotalUserEarning = z.infer<typeof TotalUserEarningSchema>; |
| 143 | + |
| 144 | +export const TotalUserEarningsResponseSchema = z.array(TotalUserEarningSchema); |
| 145 | + |
| 146 | +export type TotalUserEarningsResponse = z.infer< |
| 147 | + typeof TotalUserEarningsResponseSchema |
| 148 | +>; |
| 149 | + |
| 150 | +export const RewardsPercentagesSchema = z.record(z.string(), z.number()); |
| 151 | + |
| 152 | +export type RewardsPercentages = z.infer<typeof RewardsPercentagesSchema>; |
| 153 | + |
| 154 | +export const TokenSchema = z.object({ |
| 155 | + outcome: z.string(), |
| 156 | + price: z.number(), |
| 157 | + token_id: z.string(), |
| 158 | +}); |
| 159 | + |
| 160 | +export const RewardsConfigSchema = z.object({ |
| 161 | + asset_address: z.string(), |
| 162 | + end_date: z.string(), |
| 163 | + rate_per_day: z.number(), |
| 164 | + start_date: z.string(), |
| 165 | + total_rewards: z.number(), |
| 166 | +}); |
| 167 | + |
| 168 | +export const EarningSchema = z.object({ |
| 169 | + asset_address: z.string(), |
| 170 | + asset_rate: z.number(), |
| 171 | + earnings: z.number(), |
| 172 | +}); |
| 173 | + |
| 174 | +export const UserRewardsEarningSchema = z.object({ |
| 175 | + condition_id: z.string(), |
| 176 | + earning_percentage: z.number(), |
| 177 | + earnings: z.array(EarningSchema), |
| 178 | + event_slug: z.string(), |
| 179 | + image: z.string(), |
| 180 | + maker_address: z.string(), |
| 181 | + market_competitiveness: z.number(), |
| 182 | + market_slug: z.string(), |
| 183 | + question: z.string(), |
| 184 | + rewards_config: z.array(RewardsConfigSchema), |
| 185 | + rewards_max_spread: z.number(), |
| 186 | + rewards_min_size: z.number(), |
| 187 | + tokens: z.array(TokenSchema), |
| 188 | +}); |
| 189 | + |
| 190 | +export type UserRewardsEarning = z.infer<typeof UserRewardsEarningSchema>; |
| 191 | + |
| 192 | +export const UserRewardsEarningsPageSchema = createCursorPageSchema( |
| 193 | + UserRewardsEarningSchema, |
| 194 | +); |
| 195 | + |
| 196 | +export type UserRewardsEarningsPage = z.infer< |
| 197 | + typeof UserRewardsEarningsPageSchema |
| 198 | +>; |
0 commit comments