impermax-sdk 1.2.138 → 1.2.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/offchain/offchain.js
CHANGED
|
@@ -171,23 +171,29 @@ class Offchain {
|
|
|
171
171
|
async getTotalValueLocked() {
|
|
172
172
|
// Try llama
|
|
173
173
|
const { tvl } = await this.getAPRHelper().getLlamaTvlAndBorrows(this.network);
|
|
174
|
+
if (tvl)
|
|
175
|
+
return tvl;
|
|
174
176
|
// Fallback to subgraph
|
|
175
177
|
const tvlData = await this.getTvlData();
|
|
176
|
-
return tvl
|
|
178
|
+
return tvl > tvlData.totalBalanceUSD ? tvl : tvlData.totalBalanceUSD;
|
|
177
179
|
}
|
|
178
180
|
async getTotalValueSupplied() {
|
|
179
181
|
// Try llama
|
|
180
182
|
const { totalSupplied } = await this.getAPRHelper().getLlamaTvlAndBorrows(this.network);
|
|
183
|
+
if (totalSupplied)
|
|
184
|
+
return totalSupplied;
|
|
181
185
|
// Fallback to subgraph
|
|
182
186
|
const tvlData = await this.getTvlData();
|
|
183
|
-
return totalSupplied
|
|
187
|
+
return totalSupplied > tvlData.totalSupplyUSD ? totalSupplied : tvlData.totalSupplyUSD;
|
|
184
188
|
}
|
|
185
189
|
async getTotalValueBorrowed() {
|
|
186
190
|
// Try llama
|
|
187
191
|
const { borrowed } = await this.getAPRHelper().getLlamaTvlAndBorrows(this.network);
|
|
192
|
+
if (borrowed)
|
|
193
|
+
return borrowed;
|
|
188
194
|
// Fallback to subgraph
|
|
189
195
|
const tvlData = await this.getTvlData();
|
|
190
|
-
return borrowed
|
|
196
|
+
return borrowed > tvlData.totalBorrowsUSD ? borrowed : tvlData.totalBorrowsUSD;
|
|
191
197
|
}
|
|
192
198
|
// IMX Staking
|
|
193
199
|
async getXIMXAPY() {
|
|
@@ -74,7 +74,9 @@ class OffchainAPRHelper {
|
|
|
74
74
|
// contracts exists on diff chains
|
|
75
75
|
this.llamaAllPools = filteredPools.reduce((acc, i) => {
|
|
76
76
|
const pool = i.pool_old.split("-")[0];
|
|
77
|
-
|
|
77
|
+
let llamaChain = i.chain.toLowerCase();
|
|
78
|
+
if (llamaChain === 'op mainnet')
|
|
79
|
+
llamaChain = 'optimism';
|
|
78
80
|
const llamaId = pool.concat("-", llamaChain).toLowerCase();
|
|
79
81
|
acc[llamaId] = i;
|
|
80
82
|
return acc;
|
|
@@ -96,12 +98,17 @@ class OffchainAPRHelper {
|
|
|
96
98
|
const protocolTvlChart = response.tvl;
|
|
97
99
|
// Get the chain tvls
|
|
98
100
|
this.chainTvls = Object.entries(currentChainTvls).reduce((acc, [chain, tvl]) => {
|
|
99
|
-
|
|
101
|
+
let llamaChain = chain.toLowerCase();
|
|
102
|
+
if (llamaChain === 'op mainnet')
|
|
103
|
+
llamaChain = 'optimism';
|
|
104
|
+
acc[llamaChain.toLowerCase()] = tvl;
|
|
100
105
|
return acc;
|
|
101
106
|
}, {});
|
|
102
|
-
// Get the chain tvls day data to build charts
|
|
103
107
|
this.chainTvlCharts = Object.entries(chainTvlCharts).reduce((acc, [chain, dayData]) => {
|
|
104
|
-
|
|
108
|
+
let llamaChain = chain.toLowerCase();
|
|
109
|
+
if (llamaChain === 'op mainnet')
|
|
110
|
+
llamaChain = 'optimism';
|
|
111
|
+
acc[llamaChain.toLowerCase()] = dayData.tvl;
|
|
105
112
|
return acc;
|
|
106
113
|
}, {});
|
|
107
114
|
this.protocolTvlChart = protocolTvlChart;
|
|
@@ -117,10 +124,13 @@ class OffchainAPRHelper {
|
|
|
117
124
|
async initializePoolsBorrow() {
|
|
118
125
|
try {
|
|
119
126
|
const response = await fetch("https://yields.llama.fi/poolsBorrow").then((i) => i.json());
|
|
120
|
-
const impermaxPools = response.data.filter((i) => i.project === "impermax-
|
|
127
|
+
const impermaxPools = response.data.filter((i) => i.project === "impermax-v2" || i.project === "impermax-v3");
|
|
121
128
|
this.chainsTotalSupplied = impermaxPools.reduce((acc, pool) => {
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
// OP is outdated, report to llama
|
|
130
|
+
let chain = pool.chain.toLowerCase();
|
|
131
|
+
if (chain === 'op mainnet')
|
|
132
|
+
chain = 'optimism';
|
|
133
|
+
acc[chain] = (acc[chain] || 0) + pool.totalSupplyUsd;
|
|
124
134
|
return acc;
|
|
125
135
|
}, {});
|
|
126
136
|
}
|