Skip to content

Commit 70293a4

Browse files
authored
Merge pull request #1915 from DefiLlama/add-fluid-mav-curve-vol
[WIP] Add fluid mav curve vol
2 parents 11f5112 + 8e3f796 commit 70293a4

File tree

7 files changed

+772
-2
lines changed

7 files changed

+772
-2
lines changed

src/adaptors/curve-dex/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
exports.CRV_API_BASE_URL = 'https://api.curve.finance/api';
2+
exports.CRV_API_BASE_URL_V1 = 'https://api.curve.finance/v1';
23
exports.BLOCKCHAINIDS = [
34
'ethereum',
45
'polygon',

src/adaptors/curve-dex/index.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const utils = require('../utils');
55

66
const {
77
CRV_API_BASE_URL,
8+
CRV_API_BASE_URL_V1,
89
BLOCKCHAINIDS,
910
BLOCKCHAINID_TO_REGISTRIES,
1011
OVERRIDE_DATA,
@@ -50,6 +51,25 @@ const getPools = async (blockchainId) => {
5051
return poolsByAddress;
5152
};
5253

54+
const getPoolsVolumes = async (blockchainId) => {
55+
const poolsByAddress = {};
56+
for (const registry of BLOCKCHAINID_TO_REGISTRIES[blockchainId]) {
57+
const uri = `/getVolumes/${blockchainId}`;
58+
let response;
59+
try {
60+
response = await utils.getData(CRV_API_BASE_URL_V1 + uri);
61+
} catch (error) {
62+
continue;
63+
}
64+
if (response?.success && response?.data?.pools?.length) {
65+
for (const pool of response.data.pools) {
66+
poolsByAddress[String(pool.address).toLowerCase()] = pool;
67+
}
68+
}
69+
}
70+
return poolsByAddress;
71+
};
72+
5373
const getSubGraphData = async (blockchainId) => {
5474
const uri = `/getSubgraphData/${blockchainId}`;
5575
let response;
@@ -208,6 +228,9 @@ const main = async () => {
208228
const blockchainToPoolPromise = Object.fromEntries(
209229
BLOCKCHAINIDS.map((blockchainId) => [blockchainId, getPools(blockchainId)])
210230
);
231+
const blockchainToPoolsVolumesPromise = Object.fromEntries(
232+
BLOCKCHAINIDS.map((blockchainId) => [blockchainId, getPoolsVolumes(blockchainId)])
233+
);
211234

212235
// we need the ethereum data first for the crv prive and await extra query to CG
213236
const ethereumPools = await blockchainToPoolPromise.ethereum;
@@ -233,6 +256,7 @@ const main = async () => {
233256
const [
234257
addressToPool,
235258
addressToPoolSubgraph,
259+
addressToPoolVolumes,
236260
addressToGauge,
237261
gaugeAddressToExtraRewards,
238262
] = poolData;
@@ -355,7 +379,7 @@ const main = async () => {
355379
const url =
356380
overrideData?.url || `https://curve.finance/#/${blockchainId}/pools`;
357381

358-
defillamaPooldata.push({
382+
const yieldPool = {
359383
pool: address + '-' + blockchainId,
360384
chain: utils.formatChain(blockchainId),
361385
project: 'curve-dex',
@@ -377,7 +401,17 @@ const main = async () => {
377401
.filter((i) => i !== '0x5A98FcBEA516Cf06857215779Fd812CA3beF1B32'),
378402
underlyingTokens,
379403
url,
380-
});
404+
}
405+
406+
if (addressToPoolVolumes) {
407+
const normalAddress = String(address).toLowerCase();
408+
if (addressToPoolVolumes[normalAddress]) {
409+
yieldPool.volumeUsd1d = addressToPoolVolumes[normalAddress].volumeUSD
410+
yieldPool.volumeUsd7d = yieldPool.volumeUsd1d * 7 * Number(addressToPoolVolumes[normalAddress].latestWeeklyApyPcent) / Number(addressToPoolVolumes[normalAddress].latestDailyApyPcent);
411+
}
412+
}
413+
414+
defillamaPooldata.push(yieldPool);
381415
}
382416
};
383417

@@ -390,6 +424,7 @@ const main = async () => {
390424
Promise.all([
391425
poolPromise,
392426
blockchainToPoolSubgraphPromise[blockchainId],
427+
blockchainToPoolsVolumesPromise[blockchainId],
393428
gaugePromise,
394429
extraRewardPromise,
395430
]).then((poolData) => feedLlama(poolData, blockchainId))

src/adaptors/fluid-dex/abi.json

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "getAllPoolsReserves",
5+
"outputs": [
6+
{
7+
"components": [
8+
{
9+
"internalType": "address",
10+
"name": "pool",
11+
"type": "address"
12+
},
13+
{
14+
"internalType": "address",
15+
"name": "token0",
16+
"type": "address"
17+
},
18+
{
19+
"internalType": "address",
20+
"name": "token1",
21+
"type": "address"
22+
},
23+
{
24+
"internalType": "uint256",
25+
"name": "fee",
26+
"type": "uint256"
27+
},
28+
{
29+
"internalType": "uint256",
30+
"name": "centerPrice",
31+
"type": "uint256"
32+
},
33+
{
34+
"components": [
35+
{
36+
"internalType": "uint256",
37+
"name": "token0RealReserves",
38+
"type": "uint256"
39+
},
40+
{
41+
"internalType": "uint256",
42+
"name": "token1RealReserves",
43+
"type": "uint256"
44+
},
45+
{
46+
"internalType": "uint256",
47+
"name": "token0ImaginaryReserves",
48+
"type": "uint256"
49+
},
50+
{
51+
"internalType": "uint256",
52+
"name": "token1ImaginaryReserves",
53+
"type": "uint256"
54+
}
55+
],
56+
"internalType": "struct IFluidDexT1.CollateralReserves",
57+
"name": "collateralReserves",
58+
"type": "tuple"
59+
},
60+
{
61+
"components": [
62+
{
63+
"internalType": "uint256",
64+
"name": "token0Debt",
65+
"type": "uint256"
66+
},
67+
{
68+
"internalType": "uint256",
69+
"name": "token1Debt",
70+
"type": "uint256"
71+
},
72+
{
73+
"internalType": "uint256",
74+
"name": "token0RealReserves",
75+
"type": "uint256"
76+
},
77+
{
78+
"internalType": "uint256",
79+
"name": "token1RealReserves",
80+
"type": "uint256"
81+
},
82+
{
83+
"internalType": "uint256",
84+
"name": "token0ImaginaryReserves",
85+
"type": "uint256"
86+
},
87+
{
88+
"internalType": "uint256",
89+
"name": "token1ImaginaryReserves",
90+
"type": "uint256"
91+
}
92+
],
93+
"internalType": "struct IFluidDexT1.DebtReserves",
94+
"name": "debtReserves",
95+
"type": "tuple"
96+
},
97+
{
98+
"components": [
99+
{
100+
"components": [
101+
{
102+
"internalType": "uint256",
103+
"name": "available",
104+
"type": "uint256"
105+
},
106+
{
107+
"internalType": "uint256",
108+
"name": "expandsTo",
109+
"type": "uint256"
110+
},
111+
{
112+
"internalType": "uint256",
113+
"name": "expandDuration",
114+
"type": "uint256"
115+
}
116+
],
117+
"internalType": "struct Structs.TokenLimit",
118+
"name": "withdrawableToken0",
119+
"type": "tuple"
120+
},
121+
{
122+
"components": [
123+
{
124+
"internalType": "uint256",
125+
"name": "available",
126+
"type": "uint256"
127+
},
128+
{
129+
"internalType": "uint256",
130+
"name": "expandsTo",
131+
"type": "uint256"
132+
},
133+
{
134+
"internalType": "uint256",
135+
"name": "expandDuration",
136+
"type": "uint256"
137+
}
138+
],
139+
"internalType": "struct Structs.TokenLimit",
140+
"name": "withdrawableToken1",
141+
"type": "tuple"
142+
},
143+
{
144+
"components": [
145+
{
146+
"internalType": "uint256",
147+
"name": "available",
148+
"type": "uint256"
149+
},
150+
{
151+
"internalType": "uint256",
152+
"name": "expandsTo",
153+
"type": "uint256"
154+
},
155+
{
156+
"internalType": "uint256",
157+
"name": "expandDuration",
158+
"type": "uint256"
159+
}
160+
],
161+
"internalType": "struct Structs.TokenLimit",
162+
"name": "borrowableToken0",
163+
"type": "tuple"
164+
},
165+
{
166+
"components": [
167+
{
168+
"internalType": "uint256",
169+
"name": "available",
170+
"type": "uint256"
171+
},
172+
{
173+
"internalType": "uint256",
174+
"name": "expandsTo",
175+
"type": "uint256"
176+
},
177+
{
178+
"internalType": "uint256",
179+
"name": "expandDuration",
180+
"type": "uint256"
181+
}
182+
],
183+
"internalType": "struct Structs.TokenLimit",
184+
"name": "borrowableToken1",
185+
"type": "tuple"
186+
}
187+
],
188+
"internalType": "struct Structs.DexLimits",
189+
"name": "limits",
190+
"type": "tuple"
191+
}
192+
],
193+
"internalType": "struct Structs.PoolWithReserves[]",
194+
"name": "poolsReserves_",
195+
"type": "tuple[]"
196+
}
197+
],
198+
"stateMutability": "view",
199+
"type": "function"
200+
}
201+
]

0 commit comments

Comments
 (0)