track svm & haqq (#9669)

* track svm & haqq

* minor fix
This commit is contained in:
g1nt0ki
2024-04-03 12:42:52 +02:00
committed by GitHub
parent 1f1b07c2f1
commit 1e0d33cabe
9 changed files with 81 additions and 27 deletions

34
test.js
View File

@@ -1,6 +1,7 @@
#!/usr/bin/env node
const handleError = require('./utils/handleError')
const INTERNAL_CACHE_FILE = 'tvl-adapter-repo/sdkInternalCache.json'
process.on('unhandledRejection', handleError)
process.on('uncaughtException', handleError)
@@ -107,6 +108,7 @@ sdk.api.abi.call = async (...args) => {
} catch (e) {
console.log(e)
}
await initCache()
const chains = Object.keys(module).filter(item => typeof module[item] === 'object' && !Array.isArray(module[item]));
checkExportKeys(module, passedFile, chains)
const unixTimestamp = Math.round(Date.now() / 1000) - 60;
@@ -213,6 +215,7 @@ sdk.api.abi.call = async (...args) => {
});
console.log("\ntotal".padEnd(25, " "), humanizeNumber(usdTvls.tvl), "\n");
await preExit()
process.exit(0);
})();
@@ -414,4 +417,33 @@ setTimeout(() => {
console.log("Timeout reached, exiting...");
if (!process.env.NO_EXIT_ON_LONG_RUN_RPC)
process.exit(1);
}, 10 * 60 * 1000) // 10 minutes
}, 10 * 60 * 1000) // 10 minutes
async function initCache() {
let currentCache = await sdk.cache.readCache(INTERNAL_CACHE_FILE)
if (process.env.NO_EXIT_ON_LONG_RUN_RPC)
sdk.log('cache size:', JSON.stringify(currentCache).length, 'chains:', Object.keys(currentCache).length)
const ONE_WEEK = 60 * 60 * 24 * 31
if (!currentCache || !currentCache.startTime || (Date.now() / 1000 - currentCache.startTime > ONE_WEEK)) {
currentCache = {
startTime: Math.round(Date.now() / 1000),
}
await sdk.cache.writeCache(INTERNAL_CACHE_FILE, currentCache)
}
sdk.sdkCache.startCache(currentCache)
}
async function saveSdkInternalCache() {
await sdk.cache.writeCache(INTERNAL_CACHE_FILE, sdk.sdkCache.retriveCache(), { skipR2CacheWrite: true })
}
async function preExit() {
try {
await saveSdkInternalCache() // save sdk cache to r2
} catch (e) {
if (process.env.NO_EXIT_ON_LONG_RUN_RPC)
sdk.error(e)
}
}