Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Osmosis fix #1623

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
1 change: 1 addition & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
1 change: 1 addition & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
68 changes: 24 additions & 44 deletions src/adaptors/osmosis-dex/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
Loading