Skip to content

Commit 4f3a58a

Browse files
fix: add p2p-lending adapter (DefiLlama#14605)
Co-authored-by: estebgonza <[email protected]> Co-authored-by: Esteban <[email protected]>
1 parent ff40f54 commit 4f3a58a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

projects/p2p-lending/index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const headers = {
2+
origin: "https://subgraph.smardex.io",
3+
referer: "https://subgraph.smardex.io",
4+
"x-api-key": process.env.SMARDEX_SUBGRAPH_API_KEY,
5+
};
6+
7+
const subgraphUrl = "https://subgraph.smardex.io/ethereum/spro";
8+
9+
const getTokenMetrics = async () => {
10+
const tokenMetricsQuery = `{
11+
tokenMetrics_collection {
12+
id
13+
totalCollateralAmount
14+
totalBorrowedAmount
15+
}
16+
}`;
17+
18+
const result = await fetch(subgraphUrl, {
19+
method: "POST",
20+
headers,
21+
body: JSON.stringify({
22+
query: tokenMetricsQuery,
23+
}),
24+
}).then((res) => res.json());
25+
return result?.data?.tokenMetrics_collection || [];
26+
};
27+
28+
async function getData(isBorrowed = false) {
29+
const tokenMetrics = await getTokenMetrics();
30+
31+
return tokenMetrics.reduce((acc, token) => {
32+
const totalBorrowedAmount = parseFloat(token.totalBorrowedAmount);
33+
34+
return {
35+
...acc,
36+
[token.id]:
37+
// We only need to add the total collateral amount if it's not borrowed
38+
totalBorrowedAmount + parseFloat(isBorrowed ? 0 : token.totalCollateralAmount),
39+
};
40+
}, {});
41+
}
42+
43+
module.exports = {
44+
ethereum: {
45+
tvl: () => getData(),
46+
borrowed: () => getData(true),
47+
},
48+
};
49+
// node test.js projects/p2p-lending/index.js

0 commit comments

Comments
 (0)