From eea8b729b83b36d1c2652712e2eb1a617d101bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alim=20=C5=9Eahin?= <73793382+aalimsahin@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:53:47 +0300 Subject: [PATCH 1/3] feat: add clave aggregator tvl --- projects/clave/index.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/projects/clave/index.js b/projects/clave/index.js index 3ce9e9ba2d..6bc50691f6 100644 --- a/projects/clave/index.js +++ b/projects/clave/index.js @@ -1,11 +1,37 @@ +const utils = require('../helper/utils'); +const { toUSDT } = require('../helper/balances'); +let _response + +const getMultiplier = (decimals) => (decimals === 18 ? 1e18 : 1e6); + const ZtakeV1Address = "0x9248F1Ee8cBD029F3D22A92EB270333a39846fB2" + async function tvl(api) { + if (!_response) _response = utils.fetchURL('https://api.getclave.io/api/v1/invest/tvl') + const response = await _response; + const tvlData= response.data + + // Clave aggregator tvl + const claveAggregatorTVL = tvlData.reduce((accumulator, pool) => { + const key = `era:${pool.token}`; + const amount = toUSDT(pool.amount, getMultiplier(pool.decimals)); + + accumulator[key] = amount; + return accumulator; + }, {}); + + // Clave ztake tvl const ZK = await api.call({ abi: 'address:ZK', target: ZtakeV1Address}) - return api.sumTokens({ owner: ZtakeV1Address, tokens: [ZK] }) + const claveZtakeTVL = await api.sumTokens({ owner: ZtakeV1Address, tokens: [ZK] }) + + +return {...claveZtakeTVL, ...claveAggregatorTVL} } module.exports = { + timetravel: false, + doublecounted: true, era: { tvl, } From 4d01b407b40977a423d778b4376dd564a966966b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alim=20=C5=9Eahin?= <73793382+aalimsahin@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:40:38 +0300 Subject: [PATCH 2/3] feat: added comment --- projects/clave/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/clave/index.js b/projects/clave/index.js index 6bc50691f6..754fecf069 100644 --- a/projects/clave/index.js +++ b/projects/clave/index.js @@ -10,6 +10,7 @@ const ZtakeV1Address = "0x9248F1Ee8cBD029F3D22A92EB270333a39846fB2" async function tvl(api) { if (!_response) _response = utils.fetchURL('https://api.getclave.io/api/v1/invest/tvl') const response = await _response; + // This API returns the tvl of 0x7f73934f333a25b456dc9b8b62a19f211c991f1c contract in ZKsync Era const tvlData= response.data // Clave aggregator tvl From 6833bf358afe8e2557a6df89a0ec49311adffa1f Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:16:29 +0100 Subject: [PATCH 3/3] code refactor --- projects/clave/index.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/projects/clave/index.js b/projects/clave/index.js index 754fecf069..d010806c78 100644 --- a/projects/clave/index.js +++ b/projects/clave/index.js @@ -1,37 +1,27 @@ -const utils = require('../helper/utils'); -const { toUSDT } = require('../helper/balances'); -let _response - -const getMultiplier = (decimals) => (decimals === 18 ? 1e18 : 1e6); - const ZtakeV1Address = "0x9248F1Ee8cBD029F3D22A92EB270333a39846fB2" - async function tvl(api) { - if (!_response) _response = utils.fetchURL('https://api.getclave.io/api/v1/invest/tvl') - const response = await _response; - // This API returns the tvl of 0x7f73934f333a25b456dc9b8b62a19f211c991f1c contract in ZKsync Era - const tvlData= response.data - // Clave aggregator tvl - const claveAggregatorTVL = tvlData.reduce((accumulator, pool) => { - const key = `era:${pool.token}`; - const amount = toUSDT(pool.amount, getMultiplier(pool.decimals)); - - accumulator[key] = amount; - return accumulator; - }, {}); + const ownerTokens = [[ + [ + '0xd78abd81a3d57712a3af080dc4185b698fe9ac5a', + '0xd6cd2c0fc55936498726cacc497832052a9b2d1b', + '0x1Fa916C27c7C2c4602124A14C77Dbb40a5FF1BE8', + '0x69cDA960E3b20DFD480866fFfd377Ebe40bd0A46', + '0x84064c058F2EFea4AB648bB6Bd7e40f83fFDe39a', + '0x1aF23bD57c62A99C59aD48236553D0Dd11e49D2D', + '0x697a70779C1A03Ba2BD28b7627a902BFf831b616', + '0x5A7d6b2F92C77FAD6CCaBd7EE0624E64907Eaf3E', + ], '0x7f73934F333a25B456Dc9B8b62A19f211c991f1c' + ]] // Clave ztake tvl - const ZK = await api.call({ abi: 'address:ZK', target: ZtakeV1Address}) - const claveZtakeTVL = await api.sumTokens({ owner: ZtakeV1Address, tokens: [ZK] }) - - -return {...claveZtakeTVL, ...claveAggregatorTVL} + const ZK = await api.call({ abi: 'address:ZK', target: ZtakeV1Address }) + ownerTokens.push([[ZK], ZtakeV1Address]) + return api.sumTokens({ ownerTokens }) } module.exports = { - timetravel: false, doublecounted: true, era: { tvl,