impermax-sdk 2.1.212 → 2.1.214
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/account/lendingPool/offchainAccountCollateralV2.js +1 -0
- package/lib/offchain/lendingPool/offchainBorrowable.d.ts +2 -2
- package/lib/offchain/lendingPool/offchainBorrowable.js +8 -4
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +3 -1
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +1 -1
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +1 -0
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
|
|
|
28
28
|
}
|
|
29
29
|
async getLiquidity() {
|
|
30
30
|
// todo check if growth factor works
|
|
31
|
+
console.log("Offchain `getAmount`: %s", await this.getAmount());
|
|
31
32
|
return await this.getAmount() * await this.getCollateral().getGrowthFactor();
|
|
32
33
|
}
|
|
33
34
|
// Notice: createNewPositionObject is not needed for V2
|
|
@@ -22,14 +22,14 @@ export default class OffchainBorrowable extends OffchainPoolToken {
|
|
|
22
22
|
getAccrualTimestamp(): Promise<number>;
|
|
23
23
|
getTotalBorrows(): Promise<number>;
|
|
24
24
|
getTotalBorrowsUSD(): Promise<number>;
|
|
25
|
-
getBorrowRate(): Promise<number>;
|
|
25
|
+
getBorrowRate(useStored?: boolean): Promise<number>;
|
|
26
26
|
getBorrowAPR(): Promise<number>;
|
|
27
27
|
getNextBorrowRate(borrowAmount: number): Promise<number>;
|
|
28
28
|
getNextBorrowAPR(borrowAmount: number): Promise<number>;
|
|
29
29
|
getSupply(): Promise<number>;
|
|
30
30
|
getSupplyUSD(): Promise<number>;
|
|
31
31
|
getUtilizationRate(): Promise<number>;
|
|
32
|
-
getSupplyRate(): Promise<number>;
|
|
32
|
+
getSupplyRate(useStored?: boolean): Promise<number>;
|
|
33
33
|
getSupplyAPR(): Promise<number>;
|
|
34
34
|
getNextSupplyRate(supplyAmount: number): Promise<number>;
|
|
35
35
|
getNextSupplyAPR(supplyAmount: number): Promise<number>;
|
|
@@ -141,7 +141,11 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
141
141
|
return totalBorrows * tokenPrice;
|
|
142
142
|
}
|
|
143
143
|
// Borrow rate
|
|
144
|
-
async getBorrowRate() {
|
|
144
|
+
async getBorrowRate(useStored) {
|
|
145
|
+
// Use stored is mainly used for onchain and `accrueFactor`.
|
|
146
|
+
// Offchain already simulates accruals.
|
|
147
|
+
if (useStored)
|
|
148
|
+
return await this.getPoolTokenParamFloat("borrowRate");
|
|
145
149
|
const { borrowRate } = await this._calculateBorrowRate();
|
|
146
150
|
return borrowRate;
|
|
147
151
|
}
|
|
@@ -182,8 +186,8 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
182
186
|
return totalBorrows / (totalBalance + totalBorrows);
|
|
183
187
|
}
|
|
184
188
|
// Supply Rate
|
|
185
|
-
async getSupplyRate() {
|
|
186
|
-
const borrowRate = await this.getBorrowRate();
|
|
189
|
+
async getSupplyRate(useStored) {
|
|
190
|
+
const borrowRate = await this.getBorrowRate(useStored);
|
|
187
191
|
const utilizationRate = await this.getUtilizationRate();
|
|
188
192
|
const reserveFactor = await this.getReserveFactor();
|
|
189
193
|
return borrowRate * utilizationRate * (1 - reserveFactor);
|
|
@@ -376,7 +380,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
|
376
380
|
async getAccrueFactor() {
|
|
377
381
|
const now = Date.now() / 1000;
|
|
378
382
|
const timeElapsed = now - await this.getAccrualTimestamp();
|
|
379
|
-
const supplyRate = await this.getSupplyRate();
|
|
383
|
+
const supplyRate = await this.getSupplyRate(true);
|
|
380
384
|
return 1 + timeElapsed * supplyRate;
|
|
381
385
|
}
|
|
382
386
|
async getCurrentExchangeRate() {
|
|
@@ -14,9 +14,11 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
|
|
|
14
14
|
this.getInteractionsBorrowable = this.getInteractionsPoolToken;
|
|
15
15
|
this.getOffchainAccountBorrowable = this.getOffchainAccountPoolToken;
|
|
16
16
|
// Shortcuts
|
|
17
|
+
// TODO: Should shortcuts be using stored param floats from subgraphs or updated one?.
|
|
18
|
+
// See note in `getBorrowRate` function in `offchainBorrowable.ts`
|
|
17
19
|
this.getBorrowableType = () => this.poolToken.getBorrowableType();
|
|
18
20
|
this.getSupplyAPR = async () => (await this.poolToken.getOffchainPoolToken()).getSupplyAPR();
|
|
19
|
-
this.getBorrowRate = async () => (await this.poolToken.getOffchainPoolToken()).getBorrowRate();
|
|
21
|
+
this.getBorrowRate = async () => (await this.poolToken.getOffchainPoolToken()).getBorrowRate(true);
|
|
20
22
|
this.getAccrualTimestamp = async () => (await this.poolToken.getOffchainPoolToken()).getAccrualTimestamp();
|
|
21
23
|
this.lendingPool = lendingPool;
|
|
22
24
|
this.poolToken = lendingPool.getLendingPool().getBorrowable(borrowable);
|
|
@@ -16,7 +16,7 @@ class OnchainAccountBorrowableV2 extends onchainAccountBorrowable_1.default {
|
|
|
16
16
|
async initializeBorrowed() {
|
|
17
17
|
const borrowable = await this.poolToken.getPoolToken();
|
|
18
18
|
const balance = await borrowable.methods.borrowBalance(this.getAccountAddress()).call();
|
|
19
|
-
const storedAmount = await
|
|
19
|
+
const storedAmount = await this.poolToken.normalize(balance);
|
|
20
20
|
const accrualTimestamp = await this.getAccrualTimestamp();
|
|
21
21
|
const borrowRate = await this.getBorrowRate();
|
|
22
22
|
return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
|
|
@@ -31,6 +31,7 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
|
|
|
31
31
|
this.collateralCache = {};
|
|
32
32
|
}
|
|
33
33
|
async getLiquidity() {
|
|
34
|
+
console.log("Onchain `getLiquidity`: %s", await this.getDeposited());
|
|
34
35
|
// todo check if growth factor works
|
|
35
36
|
return await this.getDeposited() * await this.getCollateral().getGrowthFactor();
|
|
36
37
|
}
|