Skip to content

Commit 6d8fab4

Browse files
impermax-finance: separate fees into v2 and v3 (#4498)
* impermax-finance: separate fees into v2 and v3 * refactor code --------- Co-authored-by: Eden <[email protected]>
1 parent 45bbc34 commit 6d8fab4

File tree

3 files changed

+216
-5
lines changed

3 files changed

+216
-5
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* NOTE: Keep this in sync with UI
3+
* Blacklisted lending pools from UI due to bad debt or just dead.
4+
*/
5+
const blacklistedLendingPools = {
6+
ethereum: [
7+
"0xa00d47b4b304792eb07b09233467b690db847c91",
8+
"0x46af8ac1b82f73db6aacc1645d40c56191ab787b",
9+
"0x8dcba0b75c1038c4babbdc0ff3bd9a8f6979dd13",
10+
"0x08650bb9dc722c9c8c62e79c2bafa2d3fc5b3293",
11+
],
12+
polygon: [
13+
// QuickSwap
14+
"0x5ed3147F07708A269f744B43c489e6Cf3B60aEC4", //DAI-USDT
15+
"0x87B94444d0f2c1e4610A2De8504D5d7b81898221", //QUICK-POLYDOGE
16+
"0x5f819f510ca9b1469e6a3ffe4ecd7f0c1126f8f5", //IMX-ETH [OLD]
17+
"0xb957D5a232EEbD7C4c4B0A1af9F2043430304E65", //rUSD-USDC
18+
"0x23312FCEADb118381C33B34343A61c7812f7a6a3", //IMX-ETH
19+
"0x76483D4Ba1177F69FA1448dB58d2f1dBE0Fb65fa", //IMX-QUICK
20+
"0xD4f5F9643A4368324aC920414781B1c5655BaeD1", //IMX-QUICK
21+
"0x8ce3bf56767dD87E87487f3fae63e557B821Ea32", //IMX-WETH
22+
"0x8ce3bf56767dd87e87487f3fae63e557b821ea32", //IMX-ETH
23+
// Pearl
24+
"0x2712fbb291d8784b7bf75e50f472968d0bd43fc1", //USDR-ETH
25+
"0x7c91c66f7df3d23858937b0d419fd10b72bdc6d3", //USDR-BTC
26+
"0xbde0990EeB2509931a0f73f78010F00191D746BA", //USDR-MATIC
27+
"0x281Db118b0CB2865d9370c98AaC6e42523582AED", //USDR-PEARL
28+
"0x822363B6dFaa8C41c1ADa904F1829143375EA6Da", //USDR-TNGBL
29+
"0x6467FeF60a061f541967415fcBcDFb6Dc964f711", //USDR-IBEX
30+
// Satin
31+
"0x7166f0509bd1deedf90e42046025d929078089b4", //MATIC-LIBERA
32+
"0x06D3AE1Cfe7D3D27B8b9f541E2d76e5f33778923", //SATIN-CASH
33+
"0x3E626179241585235FF7B002cc4dC5439338990e", //IBEX-WETH
34+
"0xCB091859dd1d994d513721fB9722Ca9f8839A825", //ETH-CASH
35+
"0x7b750A5C4c0c7b36D206383353AB3c54DeE74deF", //MATIC-CASH
36+
],
37+
arbitrum: [
38+
// Sushiswap
39+
"0xB7E5e74B52b9aDa1042594Cfd8AbbdeE506cc6C5", //ETH-IMX
40+
"0x8884cc766b43ca10ea41b30192324c77efdd04cd", //ETH-NYAN
41+
// Swapr
42+
"0xCC5c1540683AFF992201d8922DF44898E1Cc9806", //IMX-ETH
43+
],
44+
optimism: [],
45+
fantom: [
46+
"0x877a330AF63094d88792b9Ca28AC36C71673EB1C", //IMX-FTM
47+
"0xb97B6eD451480FE6466a558E9C54EaAC32e6C696", //OXD-FTM
48+
"0xC64b5c901df0c4F6059059772F8440535C3bf5dd", //USDC-WeVE
49+
"0xBfBF0EBDC3D5E8692F9A27d47f250afe4867A647", //BIFI-MIMATIC
50+
"0xAC6542586c8A7b7aB522e77997414eafD9a83c11", //CRV-FTM
51+
"0x228BE1a38437312C649711f1BFf28d99e9E749B6", //SOLIDsex-FTM
52+
"0x76481a638edf95019cfbc2f49cc2645dac7d70ed", //ECO
53+
],
54+
base: [],
55+
scroll: [
56+
"0x94d81405985A4c34EaC4945d2b98c74258EdD07F", // tkn/chi - stakedlp
57+
"0xE8f4895DF06a0c69A9BA87509EfdBBFBAFe86c2d", // weth/tkn - stakedlp
58+
"0x7c80Be56a6f23A3E598822648baaFD7524fe1239", // chi/wUKRE stakedlp
59+
"0xDD14d0c651C63e1EeA5bd8b250cf99757425D68F", // chi/usdc stakedlp
60+
"0xc90073e1cabcf5069e00c5a6cb10023c9e1d5c4f", // wbtc/eth stakedlp
61+
],
62+
real: [],
63+
avax: [
64+
// Traderjoe
65+
"0x21249FC0Ad45fB3e33C12BE0fA2B81000A290C5f", //SPELL-AVAX
66+
"0xa34862a7de51a0e1aee6d3912c3767594390586d", //IMX-AVAX OLD
67+
// Pangolin V1
68+
"0xE9439f67201894C30F1C1c6b362F0e9195FB8e2C", //IMX-AVAX
69+
// Pangolin V2
70+
"0xde0037aFbE805C00d3CEc67093A40882880779b7", //IMX-AVAX
71+
"0x69c1C44e8742b66D892294a7EEB9aac51891B0EB", //USDC-UST
72+
"0xc6E68d77d0f4FA925A1cF2611dAB6b10900Eaf2B", //UST-AVAX
73+
// Thorus
74+
"0xd60709441b483453e84aD8E1C30F2e9EE116851D", //USDC-THO
75+
// Pangolin
76+
"0xE429Fbdc3275e29cA4c11F9c1EB4C8Cee1fCAda3", //WBTC-USDC
77+
"0xc532a2885027677c4BE61F710F7D41941dBaD1B1", //ETH-AVAX
78+
"0x677dCE0683e6Db30325cD97e8d04D138F34821A6", //PNG-AVAX
79+
"0x65A9a0b25A2397e67Fe688361Bf4113cf4Fa5313", //USDT-AVAX
80+
// Glacier
81+
"0x96f1F13865f11E2EC0E15051415f420dAC440EC1", //WETH-USDT.e
82+
"0x674A38dE6dC83FBde29784C9A974D38a11EbFB37", //BTC.b-AVAX
83+
"0x4ab56108FD36F5da28b56a43b17909f745d560e4", //AVAX-USDT
84+
"0x29327d37Ee0395a22dd419E2E81F3Bf2da066cfe", //GMX-USDC
85+
"0x0d4E0EaFA9002957371a0cadbD3BF168d6D0741A", //fBOMB-AVAX
86+
"0x7AEDD611c361cfc53d14953A6CbDC2d4Cd48AC94", //AVAX-WMEMO
87+
"0x8dc6fae7fedd7a60ecbb27c17af830f5811d773e", //MMTH-BTC.b
88+
],
89+
sonic: [
90+
"0xd9de9f15994182518a688933d09787a9a9fb5bc9" // s/shadow stakedlp
91+
]
92+
};
93+
94+
export const BLACKLIST = Object.fromEntries(
95+
Object.entries(blacklistedLendingPools).map(([chain, addresses] : [string, string[]]) => [
96+
chain,
97+
addresses.map((address: string) => address.toLowerCase())
98+
])
99+
);

fees/impermax-finance-v3/index.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { Adapter, FetchOptions } from "../../adapters/types";
2+
import { CHAIN } from "../../helpers/chains";
3+
import { gql, request } from "graphql-request";
4+
import { BLACKLIST } from "./blacklist";
5+
6+
const config: Record<string, Array<string>> = {
7+
[CHAIN.BASE]: [
8+
'https://api.studio.thegraph.com/query/46041/impermax-v-3-base/v0.0.3',
9+
],
10+
[CHAIN.UNICHAIN]: [
11+
'https://api.studio.thegraph.com/query/46041/impermax-v-3-unichain/v0.0.2',
12+
],
13+
[CHAIN.HYPERLIQUID]: [
14+
'https://api.goldsky.com/api/public/project_cm2d5q4l4w31601vz4swb3vmi/subgraphs/impermax-v3-hyperevm/0.0.1/gn',
15+
]
16+
};
17+
18+
const query = gql`
19+
{
20+
borrowables {
21+
id
22+
totalBalance
23+
totalBorrows
24+
reserveFactor
25+
borrowRate
26+
accrualTimestamp
27+
underlying {
28+
id
29+
name
30+
symbol
31+
decimals
32+
}
33+
lendingPool {
34+
id
35+
}
36+
}
37+
}
38+
`;
39+
40+
interface IBorrowable {
41+
id: string;
42+
borrowRate: string;
43+
reserveFactor: string;
44+
totalBorrows: string;
45+
accrualTimestamp: string;
46+
underlying: {
47+
id: string;
48+
decimals: string;
49+
};
50+
lendingPool: {
51+
id: string;
52+
};
53+
}
54+
55+
const getChainBorrowables = async (chain: CHAIN): Promise<IBorrowable[]> => {
56+
const urls = config[chain];
57+
let allBorrowables: IBorrowable[] = [];
58+
59+
for (const url of urls) {
60+
const queryResult = await request(url, query);
61+
allBorrowables = allBorrowables.concat(queryResult.borrowables);
62+
}
63+
64+
const blacklist = BLACKLIST[chain] || [];
65+
return allBorrowables.filter(i => !blacklist.map(i => i.toLowerCase()).includes(i.lendingPool.id.toLowerCase()));
66+
};
67+
68+
const calculate = (
69+
borrowable: IBorrowable,
70+
): { dailyFees: number; dailyRevenue: number } => {
71+
const { totalBorrows, borrowRate, reserveFactor } = borrowable;
72+
73+
const dailyBorrowAPR = Number(borrowRate) * 86400;
74+
const dailyFees = (Number(totalBorrows) * dailyBorrowAPR)
75+
const dailyRevenue = dailyFees * Number(reserveFactor);
76+
77+
return { dailyFees, dailyRevenue };
78+
};
79+
80+
async function fetch(_timestamp: number, _t: any, options: FetchOptions) {
81+
const borrowables: IBorrowable[] = await getChainBorrowables(options.chain as any);
82+
const dailyFees = options.createBalances();
83+
const dailyRevenue = options.createBalances();
84+
85+
borrowables.forEach((b: IBorrowable) => {
86+
const { dailyFees: df, dailyRevenue: dr } = calculate(b);
87+
const decimals = Number(b.underlying.decimals);
88+
dailyFees.add(b.underlying.id, df * (10 ** decimals));
89+
dailyRevenue.add(b.underlying.id, dr * (10 ** decimals));
90+
})
91+
92+
return {
93+
dailyFees,
94+
dailyRevenue,
95+
dailyProtocolRevenue: dailyRevenue,
96+
};
97+
};
98+
99+
const methodology = {
100+
Fees: "Fees is the interest rate paid by borrowers",
101+
Revenue: "Percentage of interest going to treasury, based on each lending pool's reserve factor.",
102+
ProtocolRevenue: "Percentage of interest going to treasury, based on each lending pool's reserve factor.",
103+
};
104+
105+
106+
const adapter: Adapter = {
107+
runAtCurrTime: true,
108+
fetch,
109+
methodology,
110+
adapter: {
111+
[CHAIN.BASE]: { start: '2023-10-23', },
112+
[CHAIN.UNICHAIN]: { start: '2023-10-23', },
113+
[CHAIN.HYPERLIQUID]: { start: '2023-10-23', },
114+
},
115+
};
116+
117+
export default adapter;

fees/impermax-finance/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const config = {
3131
'https://api.studio.thegraph.com/query/46041/impermax-base-solv2/v0.0.2',
3232
'https://api.studio.thegraph.com/query/46041/impermax-base-solv2-stable/v0.0.2',
3333
'https://api.studio.thegraph.com/query/46041/impermax-base-v2/v0.0.3',
34-
'https://api.studio.thegraph.com/query/46041/impermax-v-3-base/v0.0.3',
3534
],
3635
[CHAIN.SCROLL]: [
3736
'https://api.studio.thegraph.com/query/46041/impermax-scroll-solv2/v0.0.2',
@@ -57,9 +56,6 @@ const config = {
5756
[CHAIN.ZKSYNC]: [
5857
'https://api.studio.thegraph.com/query/46041/impermax-zksync-era-solv2/v0.0.2',
5958
],
60-
[CHAIN.UNICHAIN]: [
61-
'https://api.studio.thegraph.com/query/46041/impermax-v-3-unichain/v0.0.2',
62-
]
6359
};
6460

6561
interface IBorrowable {
@@ -145,7 +141,6 @@ const adapter: Adapter = {
145141
[CHAIN.BLAST]: { start: '2023-10-23', },
146142
[CHAIN.LINEA]: { start: '2023-10-23', },
147143
[CHAIN.ZKSYNC]: { start: '2023-10-23', },
148-
[CHAIN.UNICHAIN]: { start: '2023-10-23', },
149144
},
150145
};
151146

0 commit comments

Comments
 (0)