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: diff --git a/src/adaptors/osmosis-dex/index.js b/src/adaptors/osmosis-dex/index.js index 74d0f88f9f..7a08b4e64d 100644 --- a/src/adaptors/osmosis-dex/index.js +++ b/src/adaptors/osmosis-dex/index.js @@ -1,65 +1,45 @@ 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 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; 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, - apyReward, - rewardTokens: aprs?.map((a) => a?.symbol) ?? [], - volumeUsd1d: x.volume_24h, - volumeUsd7d: x.volume_7d, + tvlUsd: pool.liquidity, + apyBase, + apyBase7d: apyBase, + 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 = { - timetravel: false, - apy: getApy, - url: 'https://app.osmosis.zone/pools', + apy, };