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.
@@ -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 await this.poolToken.normalize(balance);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.212",
3
+ "version": "2.1.214",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",