impermax-sdk 1.2.57 → 1.2.59
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/lendingPool/offchainLendingPool.d.ts +1 -0
- package/lib/offchain/lendingPool/offchainLendingPool.js +12 -0
- package/lib/offchain/offchainAPRHelper.d.ts +4 -0
- package/lib/offchain/offchainAPRHelper.js +50 -0
- package/lib/offchain/offchainPriceHelper.d.ts +1 -0
- package/lib/offchain/offchainPriceHelper.js +31 -19
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ const farms_1 = require("../../config/farms");
|
|
|
19
19
|
const utils_1 = require("../../utils");
|
|
20
20
|
const amms_1 = require("../../config/amms");
|
|
21
21
|
const factories_1 = require("../../config/factories");
|
|
22
|
+
const offchainAPRHelper_1 = require("../offchainAPRHelper");
|
|
22
23
|
class OffchainLendingPool {
|
|
23
24
|
constructor(offchain, factory, pairAddress) {
|
|
24
25
|
this.getOffchain = () => this.offchain;
|
|
@@ -215,5 +216,16 @@ class OffchainLendingPool {
|
|
|
215
216
|
return totalBorrowsUSDA + totalBorrowsUSDB;
|
|
216
217
|
});
|
|
217
218
|
}
|
|
219
|
+
// Try get APR from defillama
|
|
220
|
+
getTotalAPR() {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
const uniswapV2Pair = (yield this.getLendingPoolData()).pair.uniswapV2PairAddress.toLowerCase();
|
|
223
|
+
if (Object.keys(offchainAPRHelper_1.defillama_ids).includes(uniswapV2Pair)) {
|
|
224
|
+
return yield (0, offchainAPRHelper_1.getDefiLlamaAPR)(offchainAPRHelper_1.defillama_ids[uniswapV2Pair]);
|
|
225
|
+
}
|
|
226
|
+
const [uniswapAPR, stakingAPR] = yield Promise.all([this.getUniswapAPR(), this.getStakingAPR()]);
|
|
227
|
+
return uniswapAPR + stakingAPR;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
218
230
|
}
|
|
219
231
|
exports.default = OffchainLendingPool;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDefiLlamaAPR = exports.defillama_ids = void 0;
|
|
13
|
+
const ids = {
|
|
14
|
+
// -------------------------------------- FANTOM ------------------------------------
|
|
15
|
+
// FTM/PLUS
|
|
16
|
+
"0x964cc3a9dbad0ddddc25601abc662b6e193f92f3": "1277ae6c-58cf-43a1-a130-55c9f80e9316",
|
|
17
|
+
// FSONIC/WFTM
|
|
18
|
+
"0x767520fA98e1E24b3326fD42B24c9DCFCe8BcE14": "d3e4b430-f2e5-44b0-a9f1-196d3bf54a2d",
|
|
19
|
+
// WFTM/TANGO
|
|
20
|
+
"0x997fBfb238125dB4e90a62b423bbED2e202edd5A": "c8523f56-c4bb-4213-acdf-6799f20c9ec1",
|
|
21
|
+
// WFTM/SGOAT
|
|
22
|
+
"0xAcB5B7A37310854A6E74dD9889f6a98dA0Ef9975": "dc1f2a39-7952-4460-98eb-ec2e5d9f181c",
|
|
23
|
+
// WFTM/BAY
|
|
24
|
+
"0xA169AF5669A1d5b0a57260918CB035E152Aa3269": "bd208a0f-d9ee-4692-930e-6bcf6e50228c",
|
|
25
|
+
// EQUAL/HOOPS
|
|
26
|
+
"0xfe02fd5b3F8904e2f4108505bEE7cf91E1D179E4": "bc0ada32-62b3-44b4-963d-f09a6484b366",
|
|
27
|
+
// WFTM/ECO
|
|
28
|
+
"0xC2D4eA5547AB3d642f61A2aDadA89c9E85299e69": "48faaded-4501-4a3d-bd60-6ca9b7233dc7",
|
|
29
|
+
// WFTM/EQUAL
|
|
30
|
+
"0x3d6c56f6855b7Cc746fb80848755B0a9c3770122": "2bae2b5d-e3c9-4a3b-ad4e-923d19bb9a2f",
|
|
31
|
+
// MCLB/FBOMB
|
|
32
|
+
"0x68ca64CABbB3d40dBB0de37101A8C0b701f66fD6": "e0d0bad2-1664-49c0-9a67-345b25ec03f8",
|
|
33
|
+
};
|
|
34
|
+
// https://stackoverflow.com/questions/12539574/whats-the-best-way-most-efficient-to-turn-all-the-keys-of-an-object-to-lower
|
|
35
|
+
// Convert all keys to lowercase just in case and export this
|
|
36
|
+
exports.defillama_ids = Object.fromEntries(Object.entries(ids).map(([k, v]) => [k.toLowerCase(), v]));
|
|
37
|
+
// Get the DefiLlama APR for `poolID`
|
|
38
|
+
const getDefiLlamaAPR = (poolId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
let apy;
|
|
40
|
+
try {
|
|
41
|
+
const res = yield fetch(`https://yields.llama.fi/chart/${poolId}`).then(i => i.json());
|
|
42
|
+
apy = res.data[res.data.length - 1].apy;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
apy = 0;
|
|
46
|
+
}
|
|
47
|
+
// in percentage to match uniswapAPR and stakingAPR
|
|
48
|
+
return apy / 100;
|
|
49
|
+
});
|
|
50
|
+
exports.getDefiLlamaAPR = getDefiLlamaAPR;
|
|
@@ -46,9 +46,6 @@ const coingecko_ids = {
|
|
|
46
46
|
"0x4200000000000000000000000000000000000006": "ethereum",
|
|
47
47
|
"0x54016a4848a38f257b6e96331f7404073fd9c32c": "equalizer-base",
|
|
48
48
|
"0xa3d1a8deb97b111454b294e2324efad13a9d8396": "overnight-finance",
|
|
49
|
-
// fantom
|
|
50
|
-
"0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6": "equalizer-dex",
|
|
51
|
-
"0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83": "wrapped-fantom"
|
|
52
49
|
};
|
|
53
50
|
const dexscreener_ids = {
|
|
54
51
|
// ibex on scroll
|
|
@@ -61,8 +58,12 @@ const dexscreener_ids = {
|
|
|
61
58
|
"0xbe9f8c0d6f0fd7e46cdacca340747ea2f247991d": "zksync",
|
|
62
59
|
// fantom-bomb on scroll
|
|
63
60
|
"0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979": "scroll",
|
|
61
|
+
// more on scroll
|
|
62
|
+
"0x25ea98ac87a38142561ea70143fd44c4772a16b6": "scroll",
|
|
64
63
|
// axlOP on base
|
|
65
64
|
"0x994ac01750047B9d35431a7Ae4Ed312ee955E030": "base",
|
|
65
|
+
};
|
|
66
|
+
const fantom_ids = {
|
|
66
67
|
// uponly on ftm
|
|
67
68
|
"0x28f1d1c509495e5afc23fb47acf6cc5b217ab598": "fantom",
|
|
68
69
|
// plus-bet on ftm
|
|
@@ -81,6 +82,10 @@ const dexscreener_ids = {
|
|
|
81
82
|
"0xd361474bb19c8b98870bb67f5759cdf277dee7f9": "fantom",
|
|
82
83
|
// thc on fantom
|
|
83
84
|
"0x479673391b3818f5e3ed2fa69a58e13d685becf6": "fantom",
|
|
85
|
+
// equal
|
|
86
|
+
"0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6": "equalizer-dex",
|
|
87
|
+
// wftm
|
|
88
|
+
"0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83": "wrapped-fantom",
|
|
84
89
|
};
|
|
85
90
|
class OffchainPriceHelper {
|
|
86
91
|
constructor(offchain) {
|
|
@@ -130,7 +135,6 @@ class OffchainPriceHelper {
|
|
|
130
135
|
return this.subgraphTokensPrice;
|
|
131
136
|
});
|
|
132
137
|
}
|
|
133
|
-
// Second source of token price: Debank (more accurate, slower)
|
|
134
138
|
getCoingeckoTokenPrice(tokenAddress) {
|
|
135
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
140
|
try {
|
|
@@ -167,8 +171,31 @@ class OffchainPriceHelper {
|
|
|
167
171
|
}
|
|
168
172
|
});
|
|
169
173
|
}
|
|
174
|
+
getFantomTokenPrice(tokenAddress) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
try {
|
|
177
|
+
const response = yield fetch("https://eqapi-beta-8868m.ondigitalocean.app/fantom/v4/tokens");
|
|
178
|
+
if (response.status != 200)
|
|
179
|
+
return 0;
|
|
180
|
+
const data = yield response.json();
|
|
181
|
+
if (!data || !data.data)
|
|
182
|
+
return 0;
|
|
183
|
+
const priceData = data.data;
|
|
184
|
+
const priceItem = Object.keys(priceData).filter((keyId) => keyId.toLowerCase() == tokenAddress);
|
|
185
|
+
return priceItem.length > 0 ? Number(priceData[priceItem[0]].priceUsd) : 0;
|
|
186
|
+
}
|
|
187
|
+
catch (_a) {
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
170
192
|
initializeDebankTokenPrice(tokenAddress) {
|
|
171
193
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
if (Object.keys(fantom_ids).includes(tokenAddress.toLowerCase())) {
|
|
195
|
+
const result = yield this.getFantomTokenPrice(tokenAddress);
|
|
196
|
+
if (result)
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
172
199
|
if (Object.keys(dexscreener_ids).includes(tokenAddress.toLowerCase())) {
|
|
173
200
|
const result = yield this.getDexscreenerTokenPrice(tokenAddress.toLowerCase());
|
|
174
201
|
if (result)
|
|
@@ -180,21 +207,6 @@ class OffchainPriceHelper {
|
|
|
180
207
|
return result;
|
|
181
208
|
}
|
|
182
209
|
return 0;
|
|
183
|
-
// openapi is currently failing always so just commented out
|
|
184
|
-
// try {
|
|
185
|
-
// const response = await fetch("https://openapi.debank.com/v1/token?chain_id=" + DEBANK_IDS[this.offchain.network] + "&id=" + tokenAddress);
|
|
186
|
-
// /*const response = await fetch(
|
|
187
|
-
// "https://pro-openapi.debank.com/v1/token?chain_id=" + debank_chain_ids[this.offchain.network] + "&id=" + tokenAddress,
|
|
188
|
-
// {headers: {"AccessKey": "0ac0fba6aeb0905b4c9a1c5cfd9d48d74fbc60e0"}}
|
|
189
|
-
// );*/
|
|
190
|
-
// if (response.status != 200) return 0;
|
|
191
|
-
// const data = await response.json();
|
|
192
|
-
// if (!data) return 0;
|
|
193
|
-
// return data.price ? data.price : 0;
|
|
194
|
-
// }
|
|
195
|
-
// catch {
|
|
196
|
-
// return 0;
|
|
197
|
-
// }
|
|
198
210
|
});
|
|
199
211
|
}
|
|
200
212
|
getDebankTokenPrice(tokenAddress) {
|