From 2ade798b72a6200e6f28af45420818160aec37ca Mon Sep 17 00:00:00 2001 From: slasher125 Date: Thu, 28 Nov 2024 11:51:39 +0400 Subject: [PATCH 1/5] osmosis-fix --- src/adaptors/osmosis-dex/index.js | 67 ++++++++++++------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/src/adaptors/osmosis-dex/index.js b/src/adaptors/osmosis-dex/index.js index 74d0f88f9f..6d71941005 100644 --- a/src/adaptors/osmosis-dex/index.js +++ b/src/adaptors/osmosis-dex/index.js @@ -1,57 +1,42 @@ const utils = require('../utils'); +const axios = require('axios'); -const uniquePools = new Set(); -const getApy = async () => { +const apy = async () => { const tvlData = await utils.getData( - 'https://api-osmosis.imperator.co/pools/v2/all?low_liquidity=false' + 'https://data.osmosis.zone/pairs/v2/summary' ); - const aprData = await utils.getData( - 'https://api-osmosis.imperator.co/apr/v2/all' - ); - - const data = Object.keys(tvlData).map((poolId) => { - const tvl = tvlData[poolId]; - const x = tvl[0]; - - const poolSplit = x.denom.split('/'); - const pool = poolSplit.length > 1 ? poolSplit[1] : poolSplit[0]; - const tvlUsd = x.liquidity; + const aprData = await axios.get('https://osmosis.numia.xyz/pools_apr_range', { + headers: { + Authorization: `Bearer ${process.env.OSMOSIS_API_KEY}`, + 'Content-Type': 'application/json', + }, + }); - const symbol = `${tvl[0]?.symbol}-${tvl[1]?.symbol}`; + const data = tvlData.data.map((pool) => { + const tvlUsd = pool.liquidity; + const symbol = `${pool.base_symbol}-${pool.quote_symbol}`; if (symbol.includes(undefined)) return null; - // base apr - const feeTier = x.fees.replace('%', '') / 100; - const fees24h = x.volume_24h * feeTier; - const fees7d = x.volume_7d * feeTier; - const aprBase = ((fees24h * 365) / tvlUsd) * 100; - const aprBase7d = ((fees7d * 52) / tvlUsd) * 100; - - // reward apr - const aprs = aprData.find((a) => String(a.pool_id) === poolId)?.apr_list; - - const aprReward = aprs?.reduce((acc, reward) => acc + reward.apr_14d, 0); - const aprSuperfluid = aprs?.reduce( - (acc, reward) => acc + reward.apr_superfluid, - 0 - ); - const apyReward = aprSuperfluid > 0 ? aprSuperfluid : aprReward; + const apr = aprData.data.find((i) => i.pool_id === pool.pool_id); + if (!apr) return null; + const apyBase = apr.swap_fees.lower; + const apyReward = apr.superfluid.lower; return { - pool: `osmosis-${poolId}`, + pool: `osmosis-${pool.pool_id}`, chain: 'Osmosis', project: 'osmosis-dex', symbol: utils.formatSymbol(symbol), - poolMeta: `${tvl[0].fees}`, - tvlUsd: x.liquidity, - apyBase: aprBase, - apyBase7d: aprBase7d, + tvlUsd: pool.liquidity, + apyBase, + apyBase7d: apyBase, apyReward, - rewardTokens: aprs?.map((a) => a?.symbol) ?? [], - volumeUsd1d: x.volume_24h, - volumeUsd7d: x.volume_7d, + rewardTokens: apyReward > 0 ? ['x'] : [], + volumeUsd1d: pool.volume_24h, + volumeUsd7d: pool.volume_7d, + url: `https://app.osmosis.zone/pool/${pool.pool_id}`, }; }); @@ -59,7 +44,5 @@ const getApy = async () => { }; module.exports = { - timetravel: false, - apy: getApy, - url: 'https://app.osmosis.zone/pools', + apy, }; From 66c9da54e76bce7112497100eda8bbb5423287ae Mon Sep 17 00:00:00 2001 From: slasher125 Date: Thu, 28 Nov 2024 11:53:44 +0400 Subject: [PATCH 2/5] superfluid = staking apr --- src/adaptors/osmosis-dex/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/adaptors/osmosis-dex/index.js b/src/adaptors/osmosis-dex/index.js index 6d71941005..28633076fc 100644 --- a/src/adaptors/osmosis-dex/index.js +++ b/src/adaptors/osmosis-dex/index.js @@ -14,15 +14,13 @@ const apy = async () => { }); const data = tvlData.data.map((pool) => { - const tvlUsd = pool.liquidity; const symbol = `${pool.base_symbol}-${pool.quote_symbol}`; if (symbol.includes(undefined)) return null; const apr = aprData.data.find((i) => i.pool_id === pool.pool_id); if (!apr) return null; - const apyBase = apr.swap_fees.lower; - const apyReward = apr.superfluid.lower; + const apyBase = apr.swap_fees.lower + apr.superfluid.lower; return { pool: `osmosis-${pool.pool_id}`, @@ -32,8 +30,6 @@ const apy = async () => { tvlUsd: pool.liquidity, apyBase, apyBase7d: apyBase, - apyReward, - rewardTokens: apyReward > 0 ? ['x'] : [], volumeUsd1d: pool.volume_24h, volumeUsd7d: pool.volume_7d, url: `https://app.osmosis.zone/pool/${pool.pool_id}`, From c8b38588670f99966a35f0b4d07f8323be09e604 Mon Sep 17 00:00:00 2001 From: slasher125 Date: Thu, 28 Nov 2024 13:47:36 +0400 Subject: [PATCH 3/5] remove superfluid which requires lockups --- src/adaptors/osmosis-dex/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adaptors/osmosis-dex/index.js b/src/adaptors/osmosis-dex/index.js index 28633076fc..95a2148745 100644 --- a/src/adaptors/osmosis-dex/index.js +++ b/src/adaptors/osmosis-dex/index.js @@ -20,7 +20,7 @@ const apy = async () => { const apr = aprData.data.find((i) => i.pool_id === pool.pool_id); if (!apr) return null; - const apyBase = apr.swap_fees.lower + apr.superfluid.lower; + const apyBase = apr.swap_fees.lower; return { pool: `osmosis-${pool.pool_id}`, From c4ca6075a18b0b80142f4239162b331df7e0bc24 Mon Sep 17 00:00:00 2001 From: slasher125 Date: Fri, 29 Nov 2024 10:09:46 +0400 Subject: [PATCH 4/5] drop dupes --- src/adaptors/osmosis-dex/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adaptors/osmosis-dex/index.js b/src/adaptors/osmosis-dex/index.js index 95a2148745..7a08b4e64d 100644 --- a/src/adaptors/osmosis-dex/index.js +++ b/src/adaptors/osmosis-dex/index.js @@ -33,10 +33,11 @@ const apy = async () => { volumeUsd1d: pool.volume_24h, volumeUsd7d: pool.volume_7d, url: `https://app.osmosis.zone/pool/${pool.pool_id}`, + poolMeta: `#${pool.pool_id}`, }; }); - return data.filter((p) => p && utils.keepFinite(p)); + return utils.removeDuplicates(data.filter((p) => p && utils.keepFinite(p))); }; module.exports = { From 77dcd848fb80b9f107a8d5fcf31941193dc1dbd0 Mon Sep 17 00:00:00 2001 From: slasher125 Date: Fri, 29 Nov 2024 10:15:51 +0400 Subject: [PATCH 5/5] add env var --- .github/workflows/master.yml | 1 + env.js | 1 + serverless.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 8a46f6f31e..d902a1ae44 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -44,3 +44,4 @@ jobs: VENDOR_FINANCE: ${{ secrets.VENDOR_FINANCE }} TRADERJOE: ${{ secrets.TRADERJOE }} GRAPH_API_KEY: ${{ secrets.GRAPH_API_KEY }} + OSMOSIS_API_KEY: ${{ secrets.OSMOSIS_API_KEY}} diff --git a/env.js b/env.js index 71ee55c311..1d68032268 100644 --- a/env.js +++ b/env.js @@ -26,4 +26,5 @@ module.exports = { GRAPH_API_KEY: process.env.GRAPH_API_KEY, // DB DATABASE_URL: process.env.DATABASE_URL, + OSMOSIS_API_KEY: process.env.OSMOSIS_API_KEY, }; diff --git a/serverless.yml b/serverless.yml index 95ac6cf6fe..9f4cb041b3 100644 --- a/serverless.yml +++ b/serverless.yml @@ -79,6 +79,7 @@ functions: SMARDEX_SUBGRAPH_API_KEY: ${file(./env.js):SMARDEX_SUBGRAPH_API_KEY} VENDOR_FINANCE: ${file(./env.js):VENDOR_FINANCE} TRADERJOE: ${file(./env.js):TRADERJOE} + OSMOSIS_API_KEY: ${file(./env.js):OSMOSIS_API_KEY} # --- data enrichment triggerEnrichment: