Skip to content

Commit f418e44

Browse files
authored
Merge pull request #1762 from 0xd1esel/meridian
meridian endpoint
2 parents 8cf6cf8 + 97330df commit f418e44

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/adaptors/meridian-amm/index.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const utils = require('../utils');
2+
3+
const meridianAddress =
4+
'0x7730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5';
5+
const MERIDIAN_DAPP_URL = 'https://app.meridian.money';
6+
const MERIDIAN_POOL_API_URL = `${MERIDIAN_DAPP_URL}/api/liquidity-pool`;
7+
const MERIDIAN_COIN_INFO_URL = `${MERIDIAN_DAPP_URL}/api/coin-info`;
8+
9+
const coinInfoCache = {};
10+
11+
async function main() {
12+
// We use Meridian's API and not resources on chain as there are too many pools to parse and query
13+
// for TVL, APR, etc. metrics. This way we fetch all our pools with TVL attached, then can filter.
14+
const liquidityPools = (await utils.getData(`${MERIDIAN_POOL_API_URL}s`))
15+
?.data;
16+
if (!liquidityPools) {
17+
return [];
18+
}
19+
const filteredPools = liquidityPools.filter((pool) => pool.tvl > 10000);
20+
const v2Pools = filteredPools.filter((pool) => pool.metadata.isV2 === true);
21+
22+
const tvlArr = [];
23+
for (const liquidityPool of v2Pools) {
24+
const swapFeesApr = liquidityPool.apr.find(item => item.source === 'Swap Fees')?.apr;
25+
const rewardTokens = [];
26+
27+
const coinInfos = await Promise.all(liquidityPool.metadata.coinAddresses.map(async (address) => await getCoinInfoWithCache(address)));
28+
const coinNames = coinInfos.map((coinInfo) => coinInfo.symbol).join('-');
29+
tvlArr.push({
30+
pool:
31+
liquidityPool.metadata.type + '-move',
32+
chain: utils.formatChain('move'),
33+
project: 'meridian-amm',
34+
apyBase: (swapFeesApr ?? 0) * 100,
35+
apyReward: 0,
36+
rewardTokens,
37+
symbol: coinNames,
38+
tvlUsd: liquidityPool.tvl,
39+
underlyingTokens: liquidityPool.metadata.coinAddresses,
40+
url: `${MERIDIAN_DAPP_URL}/pools/${liquidityPool.metadata.type}`,
41+
});
42+
}
43+
44+
return tvlArr;
45+
}
46+
47+
async function getCoinInfoWithCache(coinAddress) {
48+
if (coinInfoCache[coinAddress]) {
49+
return coinInfoCache[coinAddress];
50+
}
51+
52+
const coinInfo = await utils.getData(`${MERIDIAN_COIN_INFO_URL}?coin=${coinAddress}`);
53+
coinInfoCache[coinAddress] = coinInfo?.data;
54+
55+
return coinInfo?.data;
56+
}
57+
58+
module.exports = {
59+
timetravel: false,
60+
apy: main,
61+
url: `${MERIDIAN_DAPP_URL}/pools`,
62+
};

0 commit comments

Comments
 (0)