impermax-sdk 1.2.129 → 1.2.130
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.
|
@@ -222,6 +222,12 @@ class OffchainLendingPool {
|
|
|
222
222
|
const apr = yield this.offchain.getAPRHelper().getLlamaAPR(uniswapV2Pair, this.offchain.network);
|
|
223
223
|
if (apr > 0)
|
|
224
224
|
return apr;
|
|
225
|
+
// Try shadow on Sonic network
|
|
226
|
+
if (this.offchain.network === types_1.Networks.Sonic) {
|
|
227
|
+
const shadowAPR = yield this.offchain.getAPRHelper().getShadowAPR(uniswapV2Pair, this.offchain.network);
|
|
228
|
+
if (shadowAPR > 0)
|
|
229
|
+
return shadowAPR;
|
|
230
|
+
}
|
|
225
231
|
const [uniswapAPR, stakingAPR] = yield Promise.all([this.getUniswapAPR(), this.getStakingAPR()]);
|
|
226
232
|
return uniswapAPR + stakingAPR;
|
|
227
233
|
});
|
|
@@ -21,6 +21,8 @@ export default class OffchainAPRHelper {
|
|
|
21
21
|
private totalSuppliedInitialized;
|
|
22
22
|
private chainTvlCharts;
|
|
23
23
|
private protocolTvlChart;
|
|
24
|
+
private shadowAllPools;
|
|
25
|
+
private shadowInitialized;
|
|
24
26
|
private readonly blacklistedProjects;
|
|
25
27
|
offchain: Offchain;
|
|
26
28
|
constructor(offchain: Offchain);
|
|
@@ -29,10 +31,13 @@ export default class OffchainAPRHelper {
|
|
|
29
31
|
private initializeYields;
|
|
30
32
|
private initializeTvls;
|
|
31
33
|
private initializePoolsBorrow;
|
|
34
|
+
private initializeShadowPools;
|
|
32
35
|
private getLlamaYields;
|
|
33
36
|
private getLlamaTvls;
|
|
34
37
|
private getChainsTotalSupplied;
|
|
38
|
+
private getShadowPools;
|
|
35
39
|
getLlamaAPR(pool: Address, chain: Networks): Promise<number>;
|
|
40
|
+
getShadowAPR(pool: Address, chain: Networks): Promise<number>;
|
|
36
41
|
getLlamaTvlAndBorrows(chain: Networks): Promise<{
|
|
37
42
|
tvl: number;
|
|
38
43
|
borrowed: number;
|
|
@@ -47,10 +47,12 @@ class OffchainAPRHelper {
|
|
|
47
47
|
// Charts
|
|
48
48
|
this.chainTvlCharts = {};
|
|
49
49
|
this.protocolTvlChart = [];
|
|
50
|
+
this.shadowAllPools = {};
|
|
51
|
+
this.shadowInitialized = null;
|
|
50
52
|
this.blacklistedProjects = new Set([
|
|
51
53
|
"extra-finance",
|
|
52
54
|
"beefy",
|
|
53
|
-
"impermax-finance"
|
|
55
|
+
"impermax-finance",
|
|
54
56
|
]);
|
|
55
57
|
this.offchain = offchain;
|
|
56
58
|
}
|
|
@@ -127,9 +129,10 @@ class OffchainAPRHelper {
|
|
|
127
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
130
|
try {
|
|
129
131
|
const response = yield fetch("https://yields.llama.fi/poolsBorrow").then((i) => i.json());
|
|
130
|
-
const impermaxPools = response.data.filter((i) => i.project ===
|
|
132
|
+
const impermaxPools = response.data.filter((i) => i.project === "impermax-finance");
|
|
131
133
|
this.chainsTotalSupplied = impermaxPools.reduce((acc, pool) => {
|
|
132
|
-
acc[pool.chain.toLowerCase()] =
|
|
134
|
+
acc[pool.chain.toLowerCase()] =
|
|
135
|
+
(acc[pool.chain.toLowerCase()] || 0) + pool.totalSupplyUsd;
|
|
133
136
|
return acc;
|
|
134
137
|
}, {});
|
|
135
138
|
}
|
|
@@ -139,6 +142,21 @@ class OffchainAPRHelper {
|
|
|
139
142
|
}
|
|
140
143
|
});
|
|
141
144
|
}
|
|
145
|
+
initializeShadowPools() {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
try {
|
|
148
|
+
const response = yield fetch("https://api.shadow.so/mixed-pairs").then((i) => i.json());
|
|
149
|
+
this.shadowAllPools = response.pairs.reduce((acc, pool) => {
|
|
150
|
+
acc[pool.id.toLowerCase()] = pool;
|
|
151
|
+
return acc;
|
|
152
|
+
}, {});
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
console.warn("Shadow API down?");
|
|
156
|
+
this.shadowAllPools = {};
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
142
160
|
getLlamaYields() {
|
|
143
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
162
|
// First call initializes
|
|
@@ -167,6 +185,14 @@ class OffchainAPRHelper {
|
|
|
167
185
|
return this.chainsTotalSupplied;
|
|
168
186
|
});
|
|
169
187
|
}
|
|
188
|
+
getShadowPools() {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
if (!this.shadowInitialized)
|
|
191
|
+
this.shadowInitialized = this.initializeShadowPools();
|
|
192
|
+
yield this.shadowInitialized;
|
|
193
|
+
return this.shadowAllPools;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
170
196
|
// ---------------- Getters ---------------- //
|
|
171
197
|
getLlamaAPR(pool, chain) {
|
|
172
198
|
var _a;
|
|
@@ -185,12 +211,27 @@ class OffchainAPRHelper {
|
|
|
185
211
|
return apy || 0;
|
|
186
212
|
});
|
|
187
213
|
}
|
|
214
|
+
// Shadow APRs for Sonic chain only
|
|
215
|
+
getShadowAPR(pool, chain) {
|
|
216
|
+
var _a;
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
// Guard for Sonic network only (for now..)
|
|
219
|
+
if (chain !== types_1.Networks.Sonic)
|
|
220
|
+
return 0;
|
|
221
|
+
// Get or initialize the Shadow pools
|
|
222
|
+
const shadowPools = yield this.getShadowPools();
|
|
223
|
+
// `initializeShadowPools` keys by pool address
|
|
224
|
+
// Convert to decimals to match `getUniswapAPR` and `getStakingAPR`
|
|
225
|
+
const apy = ((_a = shadowPools[pool.toLowerCase()]) === null || _a === void 0 ? void 0 : _a.lpApr) / 100;
|
|
226
|
+
return apy || 0;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
188
229
|
getLlamaTvlAndBorrows(chain) {
|
|
189
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
190
231
|
// Get or initialize the tvl for all chains
|
|
191
232
|
const [llamaTvls, totalSuppliedYields] = yield Promise.all([
|
|
192
233
|
this.getLlamaTvls(),
|
|
193
|
-
this.getChainsTotalSupplied()
|
|
234
|
+
this.getChainsTotalSupplied(),
|
|
194
235
|
]);
|
|
195
236
|
const llamaChain = LlamaChains[chain];
|
|
196
237
|
if (!llamaChain)
|