impermax-sdk 1.2.60 → 1.2.62
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/config/contracts/impermax-config-manager.js +1 -1
- package/lib/config/subgraphs.js +2 -2
- package/lib/offchain/offchainPriceHelper.js +2 -0
- package/lib/offchain/query.js +247 -247
- package/package.json +1 -1
- package/lib/offchain/account/lendingPool/borrowable.d.ts +0 -14
- package/lib/offchain/account/lendingPool/borrowable.js +0 -73
- package/lib/offchain/account/lendingPool/collateral.d.ts +0 -12
- package/lib/offchain/account/lendingPool/collateral.js +0 -42
- package/lib/offchain/account/lendingVault.d.ts +0 -11
- package/lib/offchain/account/lendingVault.js +0 -38
- package/lib/offchain/account/poolToken.d.ts +0 -6
- package/lib/offchain/account/poolToken.js +0 -21
- package/lib/offchain/initializer.d.ts +0 -32
- package/lib/offchain/initializer.js +0 -627
- package/lib/offchain/lendingPool/borrowable.d.ts +0 -55
- package/lib/offchain/lendingPool/borrowable.js +0 -351
- package/lib/offchain/lendingPool/collateral.d.ts +0 -17
- package/lib/offchain/lendingPool/collateral.js +0 -72
- package/lib/offchain/lendingVault.d.ts +0 -22
- package/lib/offchain/lendingVault.js +0 -115
- package/lib/offchain/poolToken.d.ts +0 -20
- package/lib/offchain/poolToken.js +0 -120
- package/lib/offchain/priceHelper.d.ts +0 -21
- package/lib/offchain/priceHelper.js +0 -195
- package/lib/offchain/solidexHelper.d.ts +0 -16
- package/lib/offchain/solidexHelper.js +0 -58
- package/lib/offchain/types.d.ts +0 -150
- package/lib/offchain/types.js +0 -3
- package/lib/onchain/account/interactions/index.d.ts +0 -28
- package/lib/onchain/account/interactions/index.js +0 -158
- package/lib/onchain/account/interactions/lendingPool/borrowable.d.ts +0 -16
- package/lib/onchain/account/interactions/lendingPool/borrowable.js +0 -49
- package/lib/onchain/account/interactions/lendingPool/collateral.d.ts +0 -15
- package/lib/onchain/account/interactions/lendingPool/collateral.js +0 -33
- package/lib/onchain/account/interactions/lendingPool/index.d.ts +0 -41
- package/lib/onchain/account/interactions/lendingPool/index.js +0 -120
- package/lib/onchain/account/interactions/lendingVault.d.ts +0 -10
- package/lib/onchain/account/interactions/lendingVault.js +0 -12
- package/lib/onchain/account/interactions/poolToken.d.ts +0 -33
- package/lib/onchain/account/interactions/poolToken.js +0 -180
- package/lib/onchain/account/lendingPool/borrowable.d.ts +0 -29
- package/lib/onchain/account/lendingPool/borrowable.js +0 -135
- package/lib/onchain/account/lendingPool/collateral.d.ts +0 -15
- package/lib/onchain/account/lendingPool/collateral.js +0 -66
- package/lib/onchain/account/lendingVault.d.ts +0 -10
- package/lib/onchain/account/lendingVault.js +0 -35
- package/lib/onchain/account/poolToken.d.ts +0 -24
- package/lib/onchain/account/poolToken.js +0 -84
- package/lib/onchain/contractsHelper.d.ts +0 -29
- package/lib/onchain/contractsHelper.js +0 -52
- package/lib/onchain/impermaxFactory/lendingPool/borrowable.d.ts +0 -36
- package/lib/onchain/impermaxFactory/lendingPool/borrowable.js +0 -153
- package/lib/onchain/impermaxFactory/lendingPool/collateral.d.ts +0 -17
- package/lib/onchain/impermaxFactory/lendingPool/collateral.js +0 -59
- package/lib/onchain/interactions/lendingPool/borrowable.d.ts +0 -14
- package/lib/onchain/interactions/lendingPool/borrowable.js +0 -47
- package/lib/onchain/interactions/lendingPool/collateral.d.ts +0 -13
- package/lib/onchain/interactions/lendingPool/collateral.js +0 -31
- package/lib/onchain/interactions/lendingVault.d.ts +0 -8
- package/lib/onchain/interactions/lendingVault.js +0 -15
- package/lib/onchain/interactions/poolToken.d.ts +0 -31
- package/lib/onchain/interactions/poolToken.js +0 -181
- package/lib/onchain/lendingVault.d.ts +0 -17
- package/lib/onchain/lendingVault.js +0 -56
- package/lib/onchain/poolToken.d.ts +0 -32
- package/lib/onchain/poolToken.js +0 -121
- package/lib/onchain/types.d.ts +0 -45
- package/lib/onchain/types.js +0 -14
- package/lib/utils/price-from-reserves.d.ts +0 -2
- package/lib/utils/price-from-reserves.js +0 -19
|
@@ -1,351 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const utils_1 = require("../../utils");
|
|
16
|
-
const imxes_1 = require("../../config/contracts/imxes");
|
|
17
|
-
const poolToken_1 = __importDefault(require("../poolToken"));
|
|
18
|
-
class Borrowable extends poolToken_1.default {
|
|
19
|
-
constructor(lendingPool, poolTokenType) {
|
|
20
|
-
super();
|
|
21
|
-
this.getOffchain = () => this.lendingPool.offchain;
|
|
22
|
-
this.lendingPool = lendingPool;
|
|
23
|
-
this.poolTokenType = poolTokenType;
|
|
24
|
-
}
|
|
25
|
-
getPoolTokenData() {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const lendingPoolData = yield this.lendingPool.getLendingPoolData();
|
|
28
|
-
return lendingPoolData[this.poolTokenType];
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
// Reserve Factor
|
|
32
|
-
getReserveFactor() {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return this.getPoolTokenParamFloat("reserveFactor");
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// Kink Borrow Rate
|
|
38
|
-
getKinkBorrowRate() {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
return this.getPoolTokenParamFloat("kinkBorrowRate");
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// Kink Utilization Rate
|
|
44
|
-
getKinkUtilizationRate() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return this.getPoolTokenParamFloat("kinkUtilizationRate");
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
// Borrow Index
|
|
50
|
-
getBorrowIndex() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
return this.getPoolTokenParamFloat("borrowIndex");
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// Accrue Timestamp
|
|
56
|
-
getAccrualTimestamp() {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
return this.getPoolTokenParamFloat("accrualTimestamp");
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// Total borrows
|
|
62
|
-
getTotalBorrows() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return this.getPoolTokenParamFloat("totalBorrows");
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
getCurrentTotalBorrows() {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const storedAmount = yield this.getTotalBorrows();
|
|
70
|
-
const accrualTimestamp = yield this.getAccrualTimestamp();
|
|
71
|
-
const borrowRate = yield this.getBorrowRate();
|
|
72
|
-
return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getTotalBorrowsUSD() {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const totalBorrows = yield this.getCurrentTotalBorrows();
|
|
78
|
-
const tokenPrice = yield this.getTokenPriceFast();
|
|
79
|
-
return totalBorrows * tokenPrice;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
// Borrow rate
|
|
83
|
-
getBorrowRate() {
|
|
84
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
return this.getPoolTokenParamFloat("borrowRate");
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
getBorrowAPR() {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const borrowRate = yield this.getBorrowRate();
|
|
91
|
-
return (0, utils_1.toAPR)(borrowRate);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
getNextBorrowRate(borrowAmount) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const totalBorrows = yield this.getTotalBorrows();
|
|
97
|
-
const supply = yield this.getSupply();
|
|
98
|
-
const UR = (borrowAmount + totalBorrows) / supply;
|
|
99
|
-
const kinkBR = yield this.getKinkBorrowRate();
|
|
100
|
-
const kinkUR = yield this.getKinkUtilizationRate();
|
|
101
|
-
if (UR < kinkUR)
|
|
102
|
-
return UR / kinkUR * kinkBR;
|
|
103
|
-
const kinkMultiplier = this.lendingPool.getKinkMultiplier();
|
|
104
|
-
return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
getNextBorrowAPR(borrowAmount) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
const borrowRate = yield this.getNextBorrowRate(borrowAmount);
|
|
110
|
-
return (0, utils_1.toAPR)(borrowRate);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
// Supply
|
|
114
|
-
getSupply() {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const totalBalance = yield this.getTotalBalance();
|
|
117
|
-
const totalBorrows = yield this.getTotalBorrows();
|
|
118
|
-
return totalBalance + totalBorrows;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
getCurrentSupply() {
|
|
122
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
const storedAmount = yield this.getSupply();
|
|
124
|
-
const accrualTimestamp = yield this.getAccrualTimestamp();
|
|
125
|
-
const supplyRate = yield this.getSupplyRate();
|
|
126
|
-
return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * supplyRate);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
getSupplyUSD() {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
const supply = yield this.getCurrentSupply();
|
|
132
|
-
const tokenPrice = yield this.getTokenPriceFast();
|
|
133
|
-
return supply * tokenPrice;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
// Utilization Rate
|
|
137
|
-
getUtilizationRate() {
|
|
138
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
const supply = yield this.getSupply();
|
|
140
|
-
if (supply == 0)
|
|
141
|
-
return 0;
|
|
142
|
-
const totalBalance = yield this.getTotalBorrows();
|
|
143
|
-
return totalBalance / supply;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
// Supply Rate
|
|
147
|
-
getSupplyRate() {
|
|
148
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
const borrowRate = yield this.getBorrowRate();
|
|
150
|
-
const utilizationRate = yield this.getUtilizationRate();
|
|
151
|
-
const reserveFactor = yield this.getReserveFactor();
|
|
152
|
-
return borrowRate * utilizationRate * (1 - reserveFactor);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
getSupplyAPR() {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const supplyRate = yield this.getSupplyRate();
|
|
158
|
-
return (0, utils_1.toAPR)(supplyRate);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
getNextSupplyRate(supplyAmount) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
const totalBorrows = yield this.getTotalBorrows();
|
|
164
|
-
const supply = yield this.getSupply();
|
|
165
|
-
const UR = totalBorrows / (supply + supplyAmount);
|
|
166
|
-
const kinkBR = yield this.getKinkBorrowRate();
|
|
167
|
-
const kinkUR = yield this.getKinkUtilizationRate();
|
|
168
|
-
const reserveFactor = yield this.getReserveFactor();
|
|
169
|
-
if (UR < kinkUR)
|
|
170
|
-
return UR / kinkUR * kinkBR * UR * (1 - reserveFactor);
|
|
171
|
-
const kinkMultiplier = this.lendingPool.getKinkMultiplier();
|
|
172
|
-
return ((UR - kinkUR) / (1 - kinkUR) * (kinkMultiplier - 1) + 1) * kinkBR * UR * (1 - reserveFactor);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
getNextSupplyAPR(supplyAmount) {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
const supplyRate = yield this.getNextSupplyRate(supplyAmount);
|
|
178
|
-
return (0, utils_1.toAPR)(supplyRate);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// Reward Speed
|
|
182
|
-
getFarmingRewardsRate() {
|
|
183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
const poolTokenData = yield this.getPoolTokenData();
|
|
185
|
-
const rewards = poolTokenData.rewards;
|
|
186
|
-
if (rewards && rewards.length > 0)
|
|
187
|
-
return rewards;
|
|
188
|
-
const FINISH_DELAY = 3600 * 24;
|
|
189
|
-
const farmingPoolData = poolTokenData.farmingPool;
|
|
190
|
-
if (farmingPoolData === null)
|
|
191
|
-
return [];
|
|
192
|
-
const segmentLength = parseInt(farmingPoolData.segmentLength);
|
|
193
|
-
const epochAmount = parseFloat(farmingPoolData.epochAmount);
|
|
194
|
-
const epochBegin = parseInt(farmingPoolData.epochBegin);
|
|
195
|
-
const epochEnd = epochBegin + segmentLength;
|
|
196
|
-
const timestamp = (new Date()).getTime() / 1000;
|
|
197
|
-
if (timestamp - FINISH_DELAY > epochEnd) {
|
|
198
|
-
// How to manage better this case? Maybe check shares on distributor
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
return [{
|
|
202
|
-
rewardToken: imxes_1.IMX[this.lendingPool.offchain.network],
|
|
203
|
-
rewardRate: epochAmount / segmentLength
|
|
204
|
-
}];
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
// Farming
|
|
208
|
-
getFarmingRewards() {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
-
return this.getNextFarmingRewards(0);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
getNextFarmingRewards(borrowAmount) {
|
|
214
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
-
const farmingRewards = yield this.getFarmingRewardsRate();
|
|
216
|
-
const currentBorrowedUSD = yield this.getTotalBorrowsUSD();
|
|
217
|
-
const tokenPrice = yield this.getTokenPriceFast();
|
|
218
|
-
const additionalBorrowsUSD = borrowAmount * tokenPrice;
|
|
219
|
-
const totalBorrowedUSD = currentBorrowedUSD + additionalBorrowsUSD;
|
|
220
|
-
if (totalBorrowedUSD === 0)
|
|
221
|
-
return [];
|
|
222
|
-
const rewards = [];
|
|
223
|
-
for (const reward of farmingRewards) {
|
|
224
|
-
const rewardPrice = yield this.lendingPool.offchain.priceHelper.getDebankTokenPrice(reward.rewardToken);
|
|
225
|
-
rewards.push({
|
|
226
|
-
APR: (0, utils_1.toAPR)((rewardPrice * reward.rewardRate) / totalBorrowedUSD),
|
|
227
|
-
symbol: reward.rewardToken == "0x98878b06940ae243284ca214f92bb71a2b032b8a" ? "WMOVR" :
|
|
228
|
-
reward.rewardToken == "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270" ? "WMATIC" :
|
|
229
|
-
reward.rewardToken == "0x6659a9c5cd313974343e30b4fdffd95bd4b4dcd2" ? "IMX" :
|
|
230
|
-
reward.rewardToken == "0x7b35ce522cb72e4077baeb96cb923a5529764a00" ? "IMX" :
|
|
231
|
-
reward.rewardToken == "0x60bb3d364b765c497c8ce50ae0ae3f0882c5bd05" ? "IMX" :
|
|
232
|
-
reward.rewardToken == "0x9c67ee39e3c4954396b9142010653f17257dd39c" ? "IMX" :
|
|
233
|
-
reward.rewardToken == "0xea6887e4a9cda1b77e70129e5fba830cdb5cddef" ? "IMX" :
|
|
234
|
-
reward.rewardToken == "0x900f1Ec5819FA087d368877cD03B265Bf1802667" ? "IMX" :
|
|
235
|
-
reward.rewardToken == "0xea38f1ccf77bf43f352636241b05dd8f6f5f52b2" ? "IMX" :
|
|
236
|
-
"IBEX",
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
return rewards;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
getFarmingAPR() {
|
|
243
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
return this.getNextFarmingAPR(0);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
getNextFarmingAPR(borrowAmount) {
|
|
248
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
const rewards = yield this.getNextFarmingRewards(borrowAmount);
|
|
250
|
-
let APR = 0;
|
|
251
|
-
for (const reward of rewards) {
|
|
252
|
-
APR += reward.APR;
|
|
253
|
-
}
|
|
254
|
-
return APR;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
// Past Data
|
|
258
|
-
getPoolTokenDataPast24h() {
|
|
259
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
-
const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast24h();
|
|
261
|
-
if (!lendingPoolDataPast)
|
|
262
|
-
return undefined;
|
|
263
|
-
return lendingPoolDataPast[this.poolTokenType];
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
getPoolTokenDataPast7d() {
|
|
267
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast7d();
|
|
269
|
-
if (!lendingPoolDataPast)
|
|
270
|
-
return undefined;
|
|
271
|
-
return lendingPoolDataPast[this.poolTokenType];
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
// Average Borrow APR
|
|
275
|
-
getAverageBorrowAPR(poolTokenDataPast, fallback) {
|
|
276
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
if (poolTokenDataPast) {
|
|
278
|
-
const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
|
|
279
|
-
const borrowIndexPast = parseFloat(poolTokenDataPast.borrowIndex);
|
|
280
|
-
const accrualTimestampNow = yield this.getAccrualTimestamp();
|
|
281
|
-
const borrowIndexNow = yield this.getBorrowIndex();
|
|
282
|
-
if (accrualTimestampNow > accrualTimestampPast) {
|
|
283
|
-
const borrowRate = (borrowIndexNow / borrowIndexPast - 1) / (accrualTimestampNow - accrualTimestampPast);
|
|
284
|
-
return borrowRate * 3600 * 24 * 365;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return fallback;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
getAverage24hBorrowAPR() {
|
|
291
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
|
|
293
|
-
return this.getAverageBorrowAPR(poolTokenDataPast, this.getBorrowAPR());
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
getAverage7dBorrowAPR() {
|
|
297
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
298
|
-
const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
|
|
299
|
-
return this.getAverageBorrowAPR(poolTokenDataPast, this.getAverage24hBorrowAPR());
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
// Average Supply APR
|
|
303
|
-
getAverageSupplyAPR(poolTokenDataPast, fallback) {
|
|
304
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
-
if (poolTokenDataPast) {
|
|
306
|
-
const accrualTimestampPast = parseFloat(poolTokenDataPast.accrualTimestamp);
|
|
307
|
-
const exchangeRatePast = parseFloat(poolTokenDataPast.exchangeRate);
|
|
308
|
-
const accrualTimestampNow = yield this.getAccrualTimestamp();
|
|
309
|
-
const exchangeRateNow = yield this.getExchangeRate();
|
|
310
|
-
if (accrualTimestampNow > accrualTimestampPast) {
|
|
311
|
-
const supplyRate = (exchangeRateNow / exchangeRatePast - 1) / (accrualTimestampNow - accrualTimestampPast);
|
|
312
|
-
return supplyRate * 3600 * 24 * 365;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
return fallback;
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
getAverage24hSupplyAPR() {
|
|
319
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
const poolTokenDataPast = yield this.getPoolTokenDataPast24h();
|
|
321
|
-
return this.getAverageSupplyAPR(poolTokenDataPast, this.getSupplyAPR());
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
getAverage7dSupplyAPR() {
|
|
325
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
-
const poolTokenDataPast = yield this.getPoolTokenDataPast7d();
|
|
327
|
-
return this.getAverageSupplyAPR(poolTokenDataPast, this.getAverage24hSupplyAPR());
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
// Token price getters
|
|
331
|
-
getTokenPriceFast(fallback = true) {
|
|
332
|
-
const _super = Object.create(null, {
|
|
333
|
-
getTokenPriceFast: { get: () => super.getTokenPriceFast }
|
|
334
|
-
});
|
|
335
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
let tokenAddress = yield this.getUnderlyingAddress();
|
|
337
|
-
let tokenPrices = yield this.lendingPool.offchain.priceHelper.getSubgraphTokensPrice();
|
|
338
|
-
let tokenPrice = tokenPrices[tokenAddress];
|
|
339
|
-
if (tokenPrice !== undefined && tokenPrice > 0)
|
|
340
|
-
return tokenPrice;
|
|
341
|
-
return _super.getTokenPriceFast.call(this, fallback);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
getTokenPriceAccurate() {
|
|
345
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
let tokenAddress = yield this.getUnderlyingAddress();
|
|
347
|
-
return this.lendingPool.offchain.priceHelper.getDebankTokenPrice(tokenAddress);
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
exports.default = Borrowable;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PoolTokenData } from "../types";
|
|
2
|
-
import LendingPool from './';
|
|
3
|
-
import { Address, PoolTokenType } from '../../config/types';
|
|
4
|
-
import PoolToken from '../poolToken';
|
|
5
|
-
export default class Collateral extends PoolToken {
|
|
6
|
-
lendingPool: LendingPool;
|
|
7
|
-
poolTokenType: PoolTokenType;
|
|
8
|
-
constructor(lendingPool: LendingPool, poolTokenType: PoolTokenType);
|
|
9
|
-
getOffchain: () => import("..").default;
|
|
10
|
-
getPoolTokenData(): Promise<PoolTokenData>;
|
|
11
|
-
getName(): Promise<string>;
|
|
12
|
-
getSymbol(): Promise<string>;
|
|
13
|
-
getDecimals(): Promise<number>;
|
|
14
|
-
getUnderlyingAddress(): Promise<Address>;
|
|
15
|
-
getTokenPriceFast(fallback?: boolean): Promise<number>;
|
|
16
|
-
getTokenPriceAccurate(): Promise<number>;
|
|
17
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const types_1 = require("../../config/types");
|
|
16
|
-
const poolToken_1 = __importDefault(require("../poolToken"));
|
|
17
|
-
class Collateral extends poolToken_1.default {
|
|
18
|
-
constructor(lendingPool, poolTokenType) {
|
|
19
|
-
super();
|
|
20
|
-
this.getOffchain = () => this.lendingPool.offchain;
|
|
21
|
-
this.lendingPool = lendingPool;
|
|
22
|
-
this.poolTokenType = poolTokenType;
|
|
23
|
-
}
|
|
24
|
-
getPoolTokenData() {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const lendingPoolData = yield this.lendingPool.getLendingPoolData();
|
|
27
|
-
return lendingPoolData[this.poolTokenType];
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
getName() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const nameA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getName();
|
|
33
|
-
const nameB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getName();
|
|
34
|
-
return nameA + '-' + nameB + ' LP';
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
getSymbol() {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const symbolA = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableA].getSymbol();
|
|
40
|
-
const symbolB = yield this.lendingPool.poolTokens[types_1.PoolTokenType.BorrowableB].getSymbol();
|
|
41
|
-
return symbolA + '-' + symbolB;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
getDecimals() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return 18;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
getUnderlyingAddress() {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return this.lendingPool.pairAddress;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// Token price getters
|
|
55
|
-
getTokenPriceFast(fallback = true) {
|
|
56
|
-
const _super = Object.create(null, {
|
|
57
|
-
getTokenPriceFast: { get: () => super.getTokenPriceFast }
|
|
58
|
-
});
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
let tokenPrice = yield this.lendingPool.getCollateralPrice(false);
|
|
61
|
-
if (tokenPrice > 0)
|
|
62
|
-
return tokenPrice;
|
|
63
|
-
return _super.getTokenPriceFast.call(this, fallback);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
getTokenPriceAccurate() {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
return this.lendingPool.getCollateralPrice(false);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.default = Collateral;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Offchain from "./index";
|
|
2
|
-
import { Address } from '../config/types';
|
|
3
|
-
import PoolToken from './poolToken';
|
|
4
|
-
import { PoolTokenData } from './types';
|
|
5
|
-
export default class LendingVault extends PoolToken {
|
|
6
|
-
offchain: Offchain;
|
|
7
|
-
vaultAddress: Address;
|
|
8
|
-
constructor(offchain: Offchain, vaultAddress: Address);
|
|
9
|
-
getOffchain: () => Offchain;
|
|
10
|
-
getPoolTokenData(): Promise<PoolTokenData>;
|
|
11
|
-
getAccrualTimestamp(): Promise<number>;
|
|
12
|
-
getVaultSupply(): Promise<number>;
|
|
13
|
-
getCurrentVaultSupply(): Promise<number>;
|
|
14
|
-
getVaultSupplyUSD(): Promise<number>;
|
|
15
|
-
getAvailableLiquidity(): Promise<number>;
|
|
16
|
-
getCurrentAvailableLiquidity(): Promise<number>;
|
|
17
|
-
getAvailableLiquidityUSD(): Promise<number>;
|
|
18
|
-
getSupplyRate(): Promise<number>;
|
|
19
|
-
getSupplyAPR(): Promise<number>;
|
|
20
|
-
getTokenPriceFast(fallback?: boolean): Promise<number>;
|
|
21
|
-
getTokenPriceAccurate(): Promise<number>;
|
|
22
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const poolToken_1 = __importDefault(require("./poolToken"));
|
|
16
|
-
class LendingVault extends poolToken_1.default {
|
|
17
|
-
constructor(offchain, vaultAddress) {
|
|
18
|
-
super();
|
|
19
|
-
this.getOffchain = () => this.offchain;
|
|
20
|
-
this.offchain = offchain;
|
|
21
|
-
this.vaultAddress = vaultAddress;
|
|
22
|
-
}
|
|
23
|
-
getPoolTokenData() {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
return {
|
|
26
|
-
id: "0x0",
|
|
27
|
-
totalBalance: "0",
|
|
28
|
-
exchangeRate: "1",
|
|
29
|
-
totalBalanceUSD: "0",
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
// Accrue Timestamp
|
|
34
|
-
getAccrualTimestamp() {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
return 0;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
// Vault Supply
|
|
40
|
-
getVaultSupply() {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
return 0;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
getCurrentVaultSupply() {
|
|
46
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
return 0;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
getVaultSupplyUSD() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
return 0;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/*// Total Supply
|
|
56
|
-
async getTotalSupply() : Promise<number> {
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
async getCurrentTotalSupply() : Promise<number> {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Total Borrows
|
|
64
|
-
async getTotalBorrows() : Promise<number> {
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
async getCurrentTotalBorrows() : Promise<number> {
|
|
68
|
-
return 0;
|
|
69
|
-
}
|
|
70
|
-
async getTotalBorrowsUSD() : Promise<number> {
|
|
71
|
-
return 0;
|
|
72
|
-
}*/
|
|
73
|
-
// Available Liquidity
|
|
74
|
-
getAvailableLiquidity() {
|
|
75
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
return 0;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
getCurrentAvailableLiquidity() {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
return 0;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
getAvailableLiquidityUSD() {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
return 0;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
// Supply Rate
|
|
90
|
-
getSupplyRate() {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
return 0;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
getSupplyAPR() {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return 0;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
// Token price getters
|
|
101
|
-
getTokenPriceFast(fallback = true) {
|
|
102
|
-
const _super = Object.create(null, {
|
|
103
|
-
getTokenPriceFast: { get: () => super.getTokenPriceFast }
|
|
104
|
-
});
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
return _super.getTokenPriceFast.call(this, fallback);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
getTokenPriceAccurate() {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
return 0;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.default = LendingVault;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Address } from '../config/types';
|
|
2
|
-
import { PoolTokenData } from './types';
|
|
3
|
-
import Offchain from './index';
|
|
4
|
-
export default abstract class PoolToken {
|
|
5
|
-
abstract getOffchain(): Offchain;
|
|
6
|
-
abstract getPoolTokenData(): Promise<PoolTokenData>;
|
|
7
|
-
protected getPoolTokenParam(param: string): Promise<string>;
|
|
8
|
-
protected getPoolTokenParamFloat(param: string): Promise<number>;
|
|
9
|
-
protected getUnderlyingParam(param: string): Promise<string>;
|
|
10
|
-
getName(): Promise<string>;
|
|
11
|
-
getSymbol(): Promise<string>;
|
|
12
|
-
getDecimals(): Promise<number>;
|
|
13
|
-
getExchangeRate(): Promise<number>;
|
|
14
|
-
getUnderlyingAddress(): Promise<Address>;
|
|
15
|
-
getTotalBalance(): Promise<number>;
|
|
16
|
-
getTotalBalanceUSD(): Promise<number>;
|
|
17
|
-
calculateCollateralPrice(reserve0: number, reserve1: number, totalSupply: number, price0: number, price1: number): number;
|
|
18
|
-
getTokenPriceFast(fallback?: boolean): Promise<number>;
|
|
19
|
-
abstract getTokenPriceAccurate(): Promise<number>;
|
|
20
|
-
}
|