|
1 | | -import { array, number, record, string, type } from '@metamask/superstruct'; |
| 1 | +import { |
| 2 | + array, |
| 3 | + number, |
| 4 | + optional, |
| 5 | + record, |
| 6 | + string, |
| 7 | + type, |
| 8 | +} from '@metamask/superstruct'; |
2 | 9 |
|
3 | 10 | /** |
4 | 11 | * Superstruct schema for {@link VaultApyResponse}. |
5 | 12 | * |
6 | 13 | * Uses `type()` (loose validation) so that unknown fields returned by the |
7 | 14 | * Veda API do not cause validation failures. |
| 15 | + * |
| 16 | + * Only `apy` and `timestamp` are required — all other fields are optional |
| 17 | + * because the Veda API omits some fields when the vault has no activity. |
8 | 18 | */ |
9 | 19 | export const VaultApyResponseStruct = type({ |
10 | 20 | Response: type({ |
11 | | - aggregation_period: string(), |
| 21 | + aggregation_period: optional(string()), |
12 | 22 | apy: number(), |
13 | | - chain_allocation: record(string(), number()), |
14 | | - fees: number(), |
15 | | - global_apy_breakdown: type({ |
16 | | - fee: number(), |
17 | | - maturity_apy: number(), |
18 | | - real_apy: number(), |
19 | | - }), |
20 | | - performance_fees: number(), |
21 | | - real_apy_breakdown: array( |
| 23 | + chain_allocation: optional(record(string(), number())), |
| 24 | + fees: optional(number()), |
| 25 | + global_apy_breakdown: optional( |
22 | 26 | type({ |
23 | | - allocation: number(), |
24 | | - apy: number(), |
25 | | - apy_net: number(), |
26 | | - chain: string(), |
27 | | - protocol: string(), |
| 27 | + fee: optional(number()), |
| 28 | + maturity_apy: optional(number()), |
| 29 | + real_apy: optional(number()), |
28 | 30 | }), |
29 | 31 | ), |
| 32 | + performance_fees: optional(number()), |
| 33 | + real_apy_breakdown: optional( |
| 34 | + array( |
| 35 | + type({ |
| 36 | + allocation: optional(number()), |
| 37 | + apy: optional(number()), |
| 38 | + apy_net: optional(number()), |
| 39 | + chain: optional(string()), |
| 40 | + protocol: optional(string()), |
| 41 | + }), |
| 42 | + ), |
| 43 | + ), |
30 | 44 | timestamp: string(), |
31 | 45 | }), |
32 | 46 | }); |
0 commit comments