Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
EnzoPlayer0ne committed Jan 18, 2025
1 parent ce9fb26 commit 2423fe5
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/adaptors/waterneuron/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const utils = require('../utils');

async function fetchPrice() {
try {
const response = await fetch('https://min-api.cryptocompare.com/data/generateAvg?fsym=ICP&tsym=USD&e=coinbase');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
return data.RAW.PRICE;
} catch (error) {
throw new Error('There was a problem with the fetch operation:');
}
}

function parsePrometheusMetrics(data) {
const lines = data.split('\n');
let metrics = new Map();
for (const line of lines) {
if (line.startsWith('#')) {
continue;
} else {
const [name, value, timestamp] = line.split(' ');
metrics.set(name, value);
}
}
return metrics;
}

async function fetchAndParseMetrics(url) {
try {
const response = await fetch(url, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const rawData = await response.text();
return parsePrometheusMetrics(rawData);
} catch (error) {
console.error('Error fetching metrics:', error);
throw error;
}
}

async function fetchData() {
const URL = "https://tsbvt-pyaaa-aaaar-qafva-cai.raw.icp0.io/metrics";
const res = await fetchAndParseMetrics(URL);
const icp_price = await fetchPrice();
const E8S = 100000000;

const tvl = Number(res.get("total_icp_deposited")) / E8S * icp_price || 0;

const apy = Number(res.get("apy")) * 100 || 0;

return [{
pool: `waterneuron-icp`,
chain: 'icp',
project: 'waterneuron',
symbol: 'nICP',
tvlUsd: tvl,
apyBase: apy,
underlyingTokens: ['nICP'],
}];
}

module.exports = {
timetravel: false,
apy: fetchData,
url: 'https://waterneuron.fi',
};

0 comments on commit 2423fe5

Please sign in to comment.