-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-7d-apr.ts
More file actions
66 lines (53 loc) · 1.34 KB
/
fetch-7d-apr.ts
File metadata and controls
66 lines (53 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Address } from 'viem';
import { getApiURL } from 'config';
import { vaultApiRoutes } from '../consts';
export type TimestampRange = {
fromTimestamp: number;
toTimestamp: number;
};
export type ReportMeta = {
reportCid: string;
timestamp: number;
};
export type Apr7dSeries = {
sma: number;
aprs: number[];
};
export type Vault7DApr = {
outdated: boolean;
days: number;
count: number;
range: TimestampRange;
meta: ReportMeta[];
grossStakingApr: Apr7dSeries;
netStakingApr: Apr7dSeries;
carrySpreadApr: Apr7dSeries;
};
type FetchVaultMetricsParams = {
vaultAddress: Address;
};
export const fetchVault7dApr = async (
vaultAddress: Address,
): Promise<Vault7DApr> => {
const apiURL = getApiURL('vaultsApiBasePath');
if (!apiURL) {
throw new Error('[fetchVault7dApr] API URL not found');
}
const res = await fetch(vaultApiRoutes.vault7dApr(apiURL, vaultAddress));
if (!res.ok) {
throw new Error(
`[fetchVault7dApr] Error fetching vault 7d APR: ${res.statusText}`,
);
}
return await res.json();
};
export const fetch7dApr = async ({
vaultAddress,
}: FetchVaultMetricsParams): Promise<Vault7DApr | null> => {
try {
return await fetchVault7dApr(vaultAddress);
} catch (error) {
console.warn('[fetch7dApr] Error fetching 7 days APR from api:', error);
return null;
}
};