Skip to content

Commit fd04606

Browse files
Merge branch 'DefiLlama:master' into feat/add-rocky
2 parents 798c90d + 1726b29 commit fd04606

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

.github/workflows/master.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ jobs:
4747
OSMOSIS_API_KEY: ${{ secrets.OSMOSIS_API_KEY}}
4848
DUNE_API_KEY: ${{ secrets.DUNE_API_KEY}}
4949
HYPERLIQUID_RPC: ${{ secrets.HYPERLIQUID_RPC }}
50+
PLASMA_RPC: ${{ secrets.PLASMA_RPC }}

env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ module.exports = {
2929
OSMOSIS_API_KEY: process.env.OSMOSIS_API_KEY,
3030
DUNE_API_KEY: process.env.DUNE_API_KEY,
3131
HYPERLIQUID_RPC: process.env.HYPERLIQUID_RPC,
32+
PLASMA_RPC: process.env.PLASMA_RPC,
3233
};

serverless.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ functions:
8282
OSMOSIS_API_KEY: ${file(./env.js):OSMOSIS_API_KEY}
8383
DUNE_API_KEY: ${file(./env.js):DUNE_API_KEY}
8484
HYPERLIQUID_RPC: ${file(./env.js):HYPERLIQUID_RPC}
85+
PLASMA_RPC: ${file(./env.js):PLASMA_RPC}
8586

8687
# --- data enrichment
8788
triggerEnrichment:

src/adaptors/frankencoin/index.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
const { request, gql } = require('graphql-request');
2+
const { getPrices } = require('../utils.js');
3+
4+
const GRAPH_URL = 'https://ponder.frankencoin.com';
5+
const CHAINS = {
6+
ethereum: 1,
7+
polygon: 137,
8+
arbitrum: 42161,
9+
optimism: 10,
10+
base: 8453,
11+
avalanche: 43114,
12+
gnosis: 100,
13+
sonic: 146,
14+
};
15+
16+
// @dev: all relevant addresses across all supported chains
17+
const ChainAddressMap = {
18+
ethereum: {
19+
frankencoin: '0xB58E61C3098d85632Df34EecfB899A1Ed80921cB',
20+
equity: '0x1bA26788dfDe592fec8bcB0Eaff472a42BE341B2',
21+
savingsV2: '0x3BF301B0e2003E75A3e86AB82bD1EFF6A9dFB2aE',
22+
savingsReferral: '0x27d9AD987BdE08a0d083ef7e0e4043C857A17B38',
23+
},
24+
polygon: {
25+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
26+
bridgedSavings: '0xB519BAE359727e69990C27241Bef29b394A0ACbD',
27+
},
28+
arbitrum: {
29+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
30+
bridgedSavings: '0xb41715e54e9f0827821A149AE8eC1aF70aa70180',
31+
},
32+
optimism: {
33+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
34+
bridgedSavings: '0x6426324Af1b14Df3cd03b2d500529083c5ea61BC',
35+
},
36+
base: {
37+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
38+
bridgedSavings: '0x6426324Af1b14Df3cd03b2d500529083c5ea61BC',
39+
},
40+
avalanche: {
41+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
42+
bridgedSavings: '0x8e7c2a697751a1cE7a8DB51f01B883A27c5c8325',
43+
},
44+
gnosis: {
45+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
46+
bridgedSavings: '0xbF594D0feD79AE56d910Cb01b5dD4f4c57B04402',
47+
},
48+
sonic: {
49+
bridgedFrankencoin: '0xD4dD9e2F021BB459D5A5f6c24C12fE09c5D45553',
50+
bridgedSavings: '0x4E104918908293cd6A93E1A9bbe06C345d751235',
51+
},
52+
};
53+
54+
const gqlQueries = {
55+
// Query for Lending SavingsReferral - Multichain
56+
lending: gql`
57+
{
58+
savingsStatuss {
59+
items {
60+
chainId
61+
module
62+
balance
63+
rate
64+
}
65+
}
66+
}
67+
`,
68+
// Query for Borrow PositionV2 Positions - Mainnet
69+
borrowing: gql`
70+
{
71+
mintingHubV2PositionV2s(where: { closed: false, denied: false }) {
72+
items {
73+
position
74+
collateral
75+
collateralSymbol
76+
collateralBalance
77+
collateralDecimals
78+
riskPremiumPPM
79+
limitForClones
80+
availableForClones
81+
minted
82+
}
83+
}
84+
}
85+
`,
86+
};
87+
88+
const getChainName = (chainId) => {
89+
return Object.keys(CHAINS).find((c) => CHAINS[c] == chainId);
90+
};
91+
92+
// apy callback function
93+
const apy = async () => {
94+
const { savingsStatuss } = await request(GRAPH_URL, gqlQueries.lending, {});
95+
96+
const defaultFrankencoin =
97+
ChainAddressMap['ethereum'].frankencoin.toLowerCase();
98+
const leadrateModuleId =
99+
'savings-0x3bf301b0e2003e75a3e86ab82bd1eff6a9dfb2ae-ethereum';
100+
101+
const price = (await getPrices([defaultFrankencoin], 'ethereum'))
102+
.pricesByAddress[defaultFrankencoin];
103+
104+
const earnPools = savingsStatuss.items.map((savings) => {
105+
const chain = getChainName(savings.chainId);
106+
const token = (
107+
chain == 'ethereum'
108+
? defaultFrankencoin
109+
: ChainAddressMap[chain].bridgedFrankencoin
110+
).toLowerCase();
111+
112+
return {
113+
pool: `savings-${savings.module.toLowerCase()}-${chain}`,
114+
chain,
115+
project: 'frankencoin',
116+
symbol: `ZCHF`,
117+
apyBase: savings.rate / 10000 || 0, // converted from PPM to PCT
118+
tvlUsd: (savings.balance / 1e18) * price || 0,
119+
underlyingTokens: [token],
120+
url: `https://app.frankencoin.com/savings?chain=${chain}`,
121+
poolMeta: `Savings`,
122+
};
123+
});
124+
125+
const queryPositionData = await request(GRAPH_URL, gqlQueries.borrowing, {});
126+
const positionData = queryPositionData.mintingHubV2PositionV2s.items;
127+
128+
const collateralAddresses = [];
129+
positionData.forEach((pos) => {
130+
if (collateralAddresses.includes(pos.collateral)) return;
131+
collateralAddresses.push(pos.collateral);
132+
});
133+
134+
const collateralPrices = await getPrices(collateralAddresses, 'ethereum');
135+
const leadratePool = earnPools.find((p) => p.pool == leadrateModuleId);
136+
const leadrate = leadratePool ? leadratePool.apyBase : 0;
137+
138+
const borrowPools = positionData.map((pos) => {
139+
const chain = 'ethereum';
140+
141+
const collateralBalance =
142+
pos.collateralBalance / 10 ** pos.collateralDecimals;
143+
const collateralPrice = collateralPrices.pricesByAddress[pos.collateral];
144+
const collateralValueUsd = collateralBalance * collateralPrice;
145+
146+
const loanBalance = pos.minted / 10 ** 18;
147+
const loanValueUsd = loanBalance * price;
148+
149+
const ltv = loanValueUsd / collateralValueUsd;
150+
151+
return {
152+
pool: `position-v2-${pos.position.toLowerCase()}-${chain}`,
153+
chain,
154+
project: 'frankencoin',
155+
symbol: pos.collateralSymbol,
156+
apy: 0,
157+
tvlUsd: collateralValueUsd,
158+
underlyingTokens: [pos.collateral],
159+
apyBaseBorrow: leadrate + pos.riskPremiumPPM / 10000,
160+
totalSupplyUsd: (pos.limitForClones / 10 ** 18) * price,
161+
totalBorrowUsd: (pos.minted / 10 ** 18) * price,
162+
debtCeilingUsd: (pos.availableForClones / 10 ** 18) * price,
163+
ltv,
164+
mintedCoin: 'ZCHF',
165+
url: `https://app.frankencoin.com/monitoring/${pos.position}?chain=${chain}`,
166+
poolMeta: `PositionV2`,
167+
};
168+
});
169+
170+
return [...earnPools, ...borrowPools];
171+
};
172+
173+
// export
174+
module.exports = {
175+
apy,
176+
};

0 commit comments

Comments
 (0)