impermax-sdk 1.2.104 → 1.2.106
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.
|
@@ -9,6 +9,7 @@ import { Address, AddressIndex, Factory, FactoryIndex, LendingPoolIndex, Network
|
|
|
9
9
|
import { LendingPoolData, LendingVaultData, LendingVaultPosition, TvlData, UserData, XimxData } from './offchainTypes';
|
|
10
10
|
import OffchainLendingVault from './offchainLendingVault';
|
|
11
11
|
import OffchainConfigManager from './configManager';
|
|
12
|
+
import { LlamaTvlChart } from './offchainAPRHelper';
|
|
12
13
|
export interface OffchainCfg {
|
|
13
14
|
network: Networks;
|
|
14
15
|
chainId: number;
|
|
@@ -107,4 +108,6 @@ export default class Offchain {
|
|
|
107
108
|
getTotalValueSupplied(): Promise<number>;
|
|
108
109
|
getTotalValueBorrowed(): Promise<number>;
|
|
109
110
|
getXIMXAPY(): Promise<number>;
|
|
111
|
+
getProtocolChart(): Promise<LlamaTvlChart>;
|
|
112
|
+
getProtocolChainChart(chain: Networks): Promise<LlamaTvlChart>;
|
|
110
113
|
}
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -235,5 +235,17 @@ class Offchain {
|
|
|
235
235
|
return Math.pow(1 + parseFloat(ximxData.dailyAPR), 365) - 1;
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
|
+
getProtocolChart() {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
const protocolTvlChart = yield this.getAPRHelper().getProtocolTvlChart();
|
|
241
|
+
return protocolTvlChart;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
getProtocolChainChart(chain) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
const chainTvlCharts = yield this.getAPRHelper().getChainTvlChart(chain);
|
|
247
|
+
return chainTvlCharts;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
238
250
|
}
|
|
239
251
|
exports.default = Offchain;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { Address, Networks } from "../config/types";
|
|
2
2
|
import Offchain from "./index";
|
|
3
|
+
export type LlamaTvlChart = {
|
|
4
|
+
date: number;
|
|
5
|
+
totalLiquidityUSD: number;
|
|
6
|
+
}[];
|
|
7
|
+
export type LlamaChainChart = {
|
|
8
|
+
tokens: string[];
|
|
9
|
+
tokensInUsd: number[];
|
|
10
|
+
tvl: {
|
|
11
|
+
date: number;
|
|
12
|
+
totalLiquidityUSD: number;
|
|
13
|
+
}[];
|
|
14
|
+
}[];
|
|
3
15
|
export default class OffchainAPRHelper {
|
|
4
16
|
private llamaAllPools;
|
|
5
17
|
private initialized;
|
|
@@ -7,6 +19,8 @@ export default class OffchainAPRHelper {
|
|
|
7
19
|
private tvlInitialized;
|
|
8
20
|
private chainsTotalSupplied;
|
|
9
21
|
private totalSuppliedInitialized;
|
|
22
|
+
private chainTvlCharts;
|
|
23
|
+
private protocolTvlChart;
|
|
10
24
|
private readonly blacklistedProjects;
|
|
11
25
|
offchain: Offchain;
|
|
12
26
|
constructor(offchain: Offchain);
|
|
@@ -26,4 +40,6 @@ export default class OffchainAPRHelper {
|
|
|
26
40
|
}>;
|
|
27
41
|
getImpermaxBorrows(): Promise<number>;
|
|
28
42
|
getImpermaxTvl(): Promise<number>;
|
|
43
|
+
getProtocolTvlChart(): Promise<LlamaTvlChart>;
|
|
44
|
+
getChainTvlChart(chain: Networks): Promise<LlamaTvlChart>;
|
|
29
45
|
}
|
|
@@ -42,6 +42,9 @@ class OffchainAPRHelper {
|
|
|
42
42
|
this.tvlInitialized = null;
|
|
43
43
|
this.chainsTotalSupplied = {};
|
|
44
44
|
this.totalSuppliedInitialized = null;
|
|
45
|
+
// Charts
|
|
46
|
+
this.chainTvlCharts = {};
|
|
47
|
+
this.protocolTvlChart = [];
|
|
45
48
|
this.blacklistedProjects = new Set([
|
|
46
49
|
"extra-finance",
|
|
47
50
|
"beefy"
|
|
@@ -75,7 +78,7 @@ class OffchainAPRHelper {
|
|
|
75
78
|
this.llamaAllPools = filteredPools.reduce((acc, i) => {
|
|
76
79
|
const pool = i.pool_old.split("-")[0];
|
|
77
80
|
const llamaChain = i.chain;
|
|
78
|
-
const llamaId = pool.
|
|
81
|
+
const llamaId = pool.concat("-", llamaChain).toLowerCase();
|
|
79
82
|
acc[llamaId] = i;
|
|
80
83
|
return acc;
|
|
81
84
|
}, {});
|
|
@@ -91,16 +94,28 @@ class OffchainAPRHelper {
|
|
|
91
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
95
|
try {
|
|
93
96
|
const response = yield fetch("https://api.llama.fi/protocol/impermax-finance").then((i) => i.json());
|
|
97
|
+
// Simple TVL of all chains
|
|
94
98
|
const currentChainTvls = response.currentChainTvls;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
// For charts of our tvl and tvl by chains
|
|
100
|
+
const chainTvlCharts = response.chainTvls;
|
|
101
|
+
const protocolTvlChart = response.tvl;
|
|
102
|
+
// Get the chain tvls
|
|
103
|
+
this.chainTvls = Object.entries(currentChainTvls).reduce((acc, [chain, tvl]) => {
|
|
104
|
+
acc[chain.toLowerCase()] = tvl;
|
|
98
105
|
return acc;
|
|
99
106
|
}, {});
|
|
107
|
+
// Get the chain tvls day data to build charts
|
|
108
|
+
this.chainTvlCharts = Object.entries(chainTvlCharts).reduce((acc, [chain, dayData]) => {
|
|
109
|
+
acc[chain.toLowerCase()] = dayData.tvl;
|
|
110
|
+
return acc;
|
|
111
|
+
}, {});
|
|
112
|
+
this.protocolTvlChart = protocolTvlChart;
|
|
100
113
|
}
|
|
101
114
|
catch (err) {
|
|
102
115
|
console.warn("The llamas TVL down?");
|
|
103
116
|
this.chainTvls = {};
|
|
117
|
+
this.protocolTvlChart = [];
|
|
118
|
+
this.chainTvlCharts = {};
|
|
104
119
|
}
|
|
105
120
|
});
|
|
106
121
|
}
|
|
@@ -160,7 +175,7 @@ class OffchainAPRHelper {
|
|
|
160
175
|
if (!llamaChain)
|
|
161
176
|
return 0;
|
|
162
177
|
// Make pool unique ({poolAddress}-{chain})
|
|
163
|
-
const llamaId = pool.
|
|
178
|
+
const llamaId = pool.concat("-", llamaChain).toLowerCase();
|
|
164
179
|
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
165
180
|
const apy = ((_a = llamaAllPools[llamaId]) === null || _a === void 0 ? void 0 : _a.apy) / 100;
|
|
166
181
|
// If 0 then should fetch native way to make sure
|
|
@@ -202,5 +217,23 @@ class OffchainAPRHelper {
|
|
|
202
217
|
return crossChainTvl;
|
|
203
218
|
});
|
|
204
219
|
}
|
|
220
|
+
// Charts
|
|
221
|
+
// Impermax historic TVL chart
|
|
222
|
+
getProtocolTvlChart() {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
// Initialize tvls
|
|
225
|
+
yield this.getLlamaTvls();
|
|
226
|
+
return this.protocolTvlChart;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
// Impermax historic TVL chart by chain
|
|
230
|
+
getChainTvlChart(chain) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
// Initialize tvls
|
|
233
|
+
yield this.getLlamaTvls();
|
|
234
|
+
const llamaChain = LlamaChains[chain];
|
|
235
|
+
return this.chainTvlCharts[llamaChain];
|
|
236
|
+
});
|
|
237
|
+
}
|
|
205
238
|
}
|
|
206
239
|
exports.default = OffchainAPRHelper;
|
|
@@ -13,7 +13,8 @@ class QueryBuilderFactory {
|
|
|
13
13
|
static getQuery(endpoint) {
|
|
14
14
|
if (endpoint.includes("thegraph"))
|
|
15
15
|
return new thegraph_1.TheGraphQueryBuilder();
|
|
16
|
-
|
|
16
|
+
if (endpoint.includes("goldsky"))
|
|
17
|
+
return new thegraph_1.TheGraphQueryBuilder(); // Same as thegraph
|
|
17
18
|
// Default to ponder (ie. includes('railway')) but helps local test
|
|
18
19
|
return new ponder_1.PonderQueryBuilder();
|
|
19
20
|
}
|