Skip to content

[WIP] Add fluid mav curve vol #1915

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

Merged
merged 5 commits into from
Jun 13, 2025
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 src/adaptors/curve-dex/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
exports.CRV_API_BASE_URL = 'https://api.curve.finance/api';
exports.CRV_API_BASE_URL_V1 = 'https://api.curve.finance/v1';
exports.BLOCKCHAINIDS = [
'ethereum',
'polygon',
Expand Down
39 changes: 37 additions & 2 deletions src/adaptors/curve-dex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const utils = require('../utils');

const {
CRV_API_BASE_URL,
CRV_API_BASE_URL_V1,
BLOCKCHAINIDS,
BLOCKCHAINID_TO_REGISTRIES,
OVERRIDE_DATA,
Expand Down Expand Up @@ -50,6 +51,25 @@ const getPools = async (blockchainId) => {
return poolsByAddress;
};

const getPoolsVolumes = async (blockchainId) => {
const poolsByAddress = {};
for (const registry of BLOCKCHAINID_TO_REGISTRIES[blockchainId]) {
const uri = `/getVolumes/${blockchainId}`;
let response;
try {
response = await utils.getData(CRV_API_BASE_URL_V1 + uri);
} catch (error) {
continue;
}
if (response?.success && response?.data?.pools?.length) {
for (const pool of response.data.pools) {
poolsByAddress[String(pool.address).toLowerCase()] = pool;
}
}
}
return poolsByAddress;
};

const getSubGraphData = async (blockchainId) => {
const uri = `/getSubgraphData/${blockchainId}`;
let response;
Expand Down Expand Up @@ -208,6 +228,9 @@ const main = async () => {
const blockchainToPoolPromise = Object.fromEntries(
BLOCKCHAINIDS.map((blockchainId) => [blockchainId, getPools(blockchainId)])
);
const blockchainToPoolsVolumesPromise = Object.fromEntries(
BLOCKCHAINIDS.map((blockchainId) => [blockchainId, getPoolsVolumes(blockchainId)])
);

// we need the ethereum data first for the crv prive and await extra query to CG
const ethereumPools = await blockchainToPoolPromise.ethereum;
Expand All @@ -233,6 +256,7 @@ const main = async () => {
const [
addressToPool,
addressToPoolSubgraph,
addressToPoolVolumes,
addressToGauge,
gaugeAddressToExtraRewards,
] = poolData;
Expand Down Expand Up @@ -355,7 +379,7 @@ const main = async () => {
const url =
overrideData?.url || `https://curve.finance/#/${blockchainId}/pools`;

defillamaPooldata.push({
const yieldPool = {
pool: address + '-' + blockchainId,
chain: utils.formatChain(blockchainId),
project: 'curve-dex',
Expand All @@ -377,7 +401,17 @@ const main = async () => {
.filter((i) => i !== '0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32'),
underlyingTokens,
url,
});
}

if (addressToPoolVolumes) {
const normalAddress = String(address).toLowerCase();
if (addressToPoolVolumes[normalAddress]) {
yieldPool.volumeUsd1d = addressToPoolVolumes[normalAddress].volumeUSD
yieldPool.volumeUsd7d = yieldPool.volumeUsd1d * 7 * Number(addressToPoolVolumes[normalAddress].latestWeeklyApyPcent) / Number(addressToPoolVolumes[normalAddress].latestDailyApyPcent);
}
}

defillamaPooldata.push(yieldPool);
}
};

Expand All @@ -390,6 +424,7 @@ const main = async () => {
Promise.all([
poolPromise,
blockchainToPoolSubgraphPromise[blockchainId],
blockchainToPoolsVolumesPromise[blockchainId],
gaugePromise,
extraRewardPromise,
]).then((poolData) => feedLlama(poolData, blockchainId))
Expand Down
201 changes: 201 additions & 0 deletions src/adaptors/fluid-dex/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
[
{
"inputs": [],
"name": "getAllPoolsReserves",
"outputs": [
{
"components": [
{
"internalType": "address",
"name": "pool",
"type": "address"
},
{
"internalType": "address",
"name": "token0",
"type": "address"
},
{
"internalType": "address",
"name": "token1",
"type": "address"
},
{
"internalType": "uint256",
"name": "fee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "centerPrice",
"type": "uint256"
},
{
"components": [
{
"internalType": "uint256",
"name": "token0RealReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token1RealReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token0ImaginaryReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token1ImaginaryReserves",
"type": "uint256"
}
],
"internalType": "struct IFluidDexT1.CollateralReserves",
"name": "collateralReserves",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "token0Debt",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token1Debt",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token0RealReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token1RealReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token0ImaginaryReserves",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "token1ImaginaryReserves",
"type": "uint256"
}
],
"internalType": "struct IFluidDexT1.DebtReserves",
"name": "debtReserves",
"type": "tuple"
},
{
"components": [
{
"components": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandsTo",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandDuration",
"type": "uint256"
}
],
"internalType": "struct Structs.TokenLimit",
"name": "withdrawableToken0",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandsTo",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandDuration",
"type": "uint256"
}
],
"internalType": "struct Structs.TokenLimit",
"name": "withdrawableToken1",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandsTo",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandDuration",
"type": "uint256"
}
],
"internalType": "struct Structs.TokenLimit",
"name": "borrowableToken0",
"type": "tuple"
},
{
"components": [
{
"internalType": "uint256",
"name": "available",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandsTo",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "expandDuration",
"type": "uint256"
}
],
"internalType": "struct Structs.TokenLimit",
"name": "borrowableToken1",
"type": "tuple"
}
],
"internalType": "struct Structs.DexLimits",
"name": "limits",
"type": "tuple"
}
],
"internalType": "struct Structs.PoolWithReserves[]",
"name": "poolsReserves_",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
}
]
Loading
Loading