impermax-sdk 2.1.71 → 2.1.73

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.
Files changed (61) hide show
  1. package/lib/offchain/account/lendingPool/index.d.ts +4 -4
  2. package/lib/offchain/account/lendingPool/nftlp/index.d.ts +0 -0
  3. package/lib/offchain/account/lendingPool/nftlp/index.js +0 -0
  4. package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlp.d.ts +10 -0
  5. package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlp.js +14 -0
  6. package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.d.ts +4 -0
  7. package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.js +13 -0
  8. package/lib/offchain/account/lendingPool/offchainAccountBorrowable.d.ts +8 -8
  9. package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +4 -4
  10. package/lib/offchain/account/lendingPool/offchainAccountBorrowableV2.d.ts +10 -0
  11. package/lib/offchain/account/lendingPool/offchainAccountBorrowableV2.js +16 -0
  12. package/lib/offchain/account/lendingPool/offchainAccountBorrowableV3.d.ts +10 -0
  13. package/lib/offchain/account/lendingPool/offchainAccountBorrowableV3.js +16 -0
  14. package/lib/offchain/account/lendingPool/offchainAccountCollateral.d.ts +4 -9
  15. package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +4 -11
  16. package/lib/offchain/account/lendingPool/offchainAccountCollateralV2.d.ts +12 -0
  17. package/lib/offchain/account/lendingPool/offchainAccountCollateralV2.js +29 -0
  18. package/lib/offchain/account/lendingPool/offchainAccountCollateralV3.d.ts +18 -0
  19. package/lib/offchain/account/lendingPool/offchainAccountCollateralV3.js +45 -0
  20. package/lib/offchain/account/lendingPool/offchainAccountLendingPool.d.ts +20 -12
  21. package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +19 -19
  22. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV2.d.ts +38 -0
  23. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV2.js +85 -0
  24. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.d.ts +39 -0
  25. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.js +79 -0
  26. package/lib/offchain/account/offchainAccount.js +1 -2
  27. package/lib/offchain/lendingPool/nftlp/index.d.ts +3 -0
  28. package/lib/offchain/lendingPool/nftlp/index.js +9 -0
  29. package/lib/offchain/lendingPool/nftlp/offchainNftlp.d.ts +20 -0
  30. package/lib/offchain/lendingPool/nftlp/offchainNftlp.js +40 -0
  31. package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.d.ts +20 -0
  32. package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +73 -0
  33. package/lib/offchain/lendingPool/offchainBorrowable.d.ts +5 -5
  34. package/lib/offchain/lendingPool/offchainBorrowable.js +6 -6
  35. package/lib/offchain/lendingPool/offchainBorrowableV2.d.ts +8 -0
  36. package/lib/offchain/lendingPool/offchainBorrowableV2.js +14 -0
  37. package/lib/offchain/lendingPool/offchainBorrowableV3.d.ts +8 -0
  38. package/lib/offchain/lendingPool/offchainBorrowableV3.js +14 -0
  39. package/lib/offchain/lendingPool/offchainCollateral.d.ts +13 -18
  40. package/lib/offchain/lendingPool/offchainCollateral.js +1 -77
  41. package/lib/offchain/lendingPool/offchainCollateralV2.d.ts +21 -0
  42. package/lib/offchain/lendingPool/offchainCollateralV2.js +86 -0
  43. package/lib/offchain/lendingPool/offchainCollateralV3.d.ts +21 -0
  44. package/lib/offchain/lendingPool/offchainCollateralV3.js +79 -0
  45. package/lib/offchain/lendingPool/offchainLendingPool.d.ts +25 -5
  46. package/lib/offchain/lendingPool/offchainLendingPool.js +55 -18
  47. package/lib/offchain/lendingPool/offchainLendingPoolV2.d.ts +17 -0
  48. package/lib/offchain/lendingPool/offchainLendingPoolV2.js +22 -0
  49. package/lib/offchain/lendingPool/offchainLendingPoolV3.d.ts +21 -0
  50. package/lib/offchain/lendingPool/offchainLendingPoolV3.js +31 -0
  51. package/lib/offchain/offchainEndpointManager.js +2 -0
  52. package/lib/offchain/offchainInitializer.js +9 -5
  53. package/lib/offchain/offchainPriceHelper.js +4 -2
  54. package/lib/offchain/queries/apis/ponder/index.js +0 -20
  55. package/lib/offchain/vault/offchainHedgedVault.d.ts +2 -2
  56. package/lib/offchain/vault/offchainHedgedVault.js +2 -2
  57. package/lib/offchain/vault/offchainLeveragedVault.d.ts +2 -2
  58. package/lib/offchain/vault/offchainLeveragedVault.js +2 -2
  59. package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +3 -3
  60. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +3 -3
  61. package/package.json +1 -1
@@ -0,0 +1,79 @@
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 offchainCollateral_1 = __importDefault(require("./offchainCollateral"));
16
+ const offchainNftlpUniswapV3_1 = __importDefault(require("./nftlp/offchainNftlpUniswapV3"));
17
+ class OffchainCollateralV3 extends offchainCollateral_1.default {
18
+ constructor(lendingPool) {
19
+ super();
20
+ //
21
+ // Implementation
22
+ //
23
+ this.getOffchain = () => this.lendingPool.getOffchain();
24
+ this.getLendingPool = () => this.lendingPool;
25
+ this.getBorrowableA = () => this.lendingPool.getBorrowableA();
26
+ this.getBorrowableB = () => this.lendingPool.getBorrowableB();
27
+ //
28
+ // V3 Specifics
29
+ //
30
+ this.getNftlp = () => this.nftlp;
31
+ this.lendingPool = lendingPool;
32
+ this.nftlp = new offchainNftlpUniswapV3_1.default(this);
33
+ }
34
+ getName() {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const nameA = yield this.getBorrowableA().getName();
37
+ const nameB = yield this.getBorrowableB().getName();
38
+ return `${nameA}/${nameB} LP`;
39
+ });
40
+ }
41
+ getSymbol() {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const symbolA = yield this.getBorrowableA().getSymbol();
44
+ const symbolB = yield this.getBorrowableB().getSymbol();
45
+ return `${symbolA}/${symbolB}`;
46
+ });
47
+ }
48
+ getDecimals() {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ return 18;
51
+ });
52
+ }
53
+ getUnderlyingAddress() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return this.getLendingPool().getPairAddress();
56
+ });
57
+ }
58
+ //
59
+ // Pricing
60
+ //
61
+ getTokenPriceAccurate() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ return this.lendingPool.getCollateralPrice(false);
64
+ });
65
+ }
66
+ getTokenPriceFast(fallback = true) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (fallback)
69
+ return this.getTokenPriceAccurate();
70
+ return 0;
71
+ });
72
+ }
73
+ getTWAP() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return 1;
76
+ });
77
+ }
78
+ }
79
+ exports.default = OffchainCollateralV3;
@@ -1,30 +1,46 @@
1
1
  import Offchain from "../index";
2
- import { Address, Borrowable, Factory, PoolTokenType, WhitelistState } from "../../config/types";
2
+ import { Address, Borrowable, Factory, WhitelistState } from "../../config/types";
3
3
  import OffchainCollateral from "./offchainCollateral";
4
4
  import OffchainBorrowable from "./offchainBorrowable";
5
- import OffchainPoolToken from "../offchainPoolToken";
6
5
  import { LendingPoolData, LendingPoolPastData } from "../offchainTypes";
7
6
  import { Farms } from "../../config/farms";
8
7
  import { Amms } from "../../config/amms";
8
+ import OffchainAccountLendingPool from "../account/lendingPool";
9
+ import OffchainAccount from "../account";
9
10
  export declare enum LendingPoolVersion {
10
11
  V1 = "V1",
11
12
  V2 = "V2",
12
13
  V3 = "V3"
13
14
  }
14
- export default class OffchainLendingPool {
15
+ export default abstract class OffchainLendingPool {
15
16
  private readonly offchain;
16
17
  private readonly factory;
17
18
  private readonly pairAddress;
18
- private readonly poolTokens;
19
+ protected readonly collateral: OffchainCollateral;
20
+ protected readonly borrowables: {
21
+ [Borrowable.A]: OffchainBorrowable;
22
+ [Borrowable.B]: OffchainBorrowable;
23
+ };
24
+ protected cache: {
25
+ lendingPoolAddresses?: Promise<{
26
+ collateral: Address;
27
+ borrowables: {
28
+ [key in Borrowable]: Address;
29
+ };
30
+ }>;
31
+ };
32
+ protected abstract getNewCollateralObject(): OffchainCollateral;
33
+ protected abstract getNewBorrowableObject(borrowable: Borrowable): OffchainBorrowable;
34
+ abstract getNewAccountLendingPoolObject(account: OffchainAccount): OffchainAccountLendingPool;
19
35
  constructor(offchain: Offchain, factory: Factory, pairAddress: Address);
20
36
  getOffchain: () => Offchain;
21
37
  getFactory: () => Factory;
22
38
  getPairAddress: () => string;
23
- getPoolToken(poolTokenType: PoolTokenType): OffchainPoolToken;
24
39
  getBorrowable: (borrowable: Borrowable) => OffchainBorrowable;
25
40
  getBorrowableA: () => OffchainBorrowable;
26
41
  getBorrowableB: () => OffchainBorrowable;
27
42
  getCollateral: () => OffchainCollateral;
43
+ cleanCache(): void;
28
44
  getLendingPoolData(): Promise<LendingPoolData>;
29
45
  getWhitelistState(): Promise<WhitelistState>;
30
46
  getSafetyMargin(): Promise<number>;
@@ -58,4 +74,8 @@ export default class OffchainLendingPool {
58
74
  getLendingPoolVersion(): LendingPoolVersion;
59
75
  getTotalBorrowsUSD(): Promise<number>;
60
76
  getUniswapV2PairAddress(): Promise<Address>;
77
+ private initializeLendingPoolAddresses;
78
+ private getLendingPoolAddresses;
79
+ getCollateralAddress(): Promise<string>;
80
+ getBorrowableAddress(borrowable: Borrowable): Promise<string>;
61
81
  }
@@ -8,14 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.LendingPoolVersion = void 0;
16
13
  const types_1 = require("../../config/types");
17
- const offchainCollateral_1 = __importDefault(require("./offchainCollateral"));
18
- const offchainBorrowable_1 = __importDefault(require("./offchainBorrowable"));
19
14
  const farms_1 = require("../../config/farms");
20
15
  const utils_1 = require("../../utils");
21
16
  const amms_1 = require("../../config/amms");
@@ -31,25 +26,26 @@ const LOW_TVL = 25000;
31
26
  const HIGH_TVL = 100000;
32
27
  class OffchainLendingPool {
33
28
  constructor(offchain, factory, pairAddress) {
29
+ this.cache = {};
34
30
  this.getOffchain = () => this.offchain;
35
31
  this.getFactory = () => this.factory;
36
32
  this.getPairAddress = () => this.pairAddress;
37
33
  this.getBorrowable = (borrowable) => borrowable == types_1.Borrowable.A ? this.getBorrowableA() : this.getBorrowableB();
38
34
  // Shortcuts
39
- this.getBorrowableA = () => this.poolTokens[types_1.PoolTokenType.BorrowableA];
40
- this.getBorrowableB = () => this.poolTokens[types_1.PoolTokenType.BorrowableB];
41
- this.getCollateral = () => this.poolTokens[types_1.PoolTokenType.Collateral];
35
+ this.getBorrowableA = () => this.borrowables[types_1.Borrowable.A];
36
+ this.getBorrowableB = () => this.borrowables[types_1.Borrowable.B];
37
+ this.getCollateral = () => this.collateral;
42
38
  this.offchain = offchain;
43
39
  this.factory = factory;
44
40
  this.pairAddress = pairAddress;
45
- this.poolTokens = {
46
- [types_1.PoolTokenType.Collateral]: new offchainCollateral_1.default(this),
47
- [types_1.PoolTokenType.BorrowableA]: new offchainBorrowable_1.default(this, types_1.PoolTokenType.BorrowableA),
48
- [types_1.PoolTokenType.BorrowableB]: new offchainBorrowable_1.default(this, types_1.PoolTokenType.BorrowableB),
41
+ this.collateral = this.getNewCollateralObject();
42
+ this.borrowables = {
43
+ [types_1.Borrowable.A]: this.getNewBorrowableObject(types_1.Borrowable.A),
44
+ [types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
49
45
  };
50
46
  }
51
- getPoolToken(poolTokenType) {
52
- return this.poolTokens[poolTokenType];
47
+ cleanCache() {
48
+ this.cache = {};
53
49
  }
54
50
  // Offchain calls
55
51
  getLendingPoolData() {
@@ -128,6 +124,8 @@ class OffchainLendingPool {
128
124
  const rewards = [];
129
125
  const stakedTotalSupply = parseFloat(lendingPoolData.pair.stakedTotalSupply);
130
126
  const underlyingLPPrice = yield this.getUnderlyingLPPrice(true);
127
+ if (!lendingPoolData.pair.rewards)
128
+ return rewards;
131
129
  for (const reward of lendingPoolData.pair.rewards) {
132
130
  const multiplier = farm === farms_1.Farms.traderJoeV2 ? 0.5 : 1;
133
131
  const periodFinish = parseInt(reward.periodFinish);
@@ -249,16 +247,24 @@ class OffchainLendingPool {
249
247
  return uniswapAPR + stakingAPR;
250
248
  });
251
249
  }
250
+ // TODO: How to get total LP $ in V3?
252
251
  getTVL() {
253
252
  return __awaiter(this, void 0, void 0, function* () {
254
- const [supply0USD, supply1USD, totalBalanceUSD] = yield Promise.all([
253
+ const [supply0USD, supply1USD] = yield Promise.all([
255
254
  this.getBorrowableA().getTotalBalanceUSD(),
256
255
  this.getBorrowableB().getTotalBalanceUSD(),
257
- this.getCollateral().getTotalBalanceUSD(),
258
256
  ]);
259
- if (supply0USD && supply1USD && totalBalanceUSD)
260
- return supply0USD + supply1USD + totalBalanceUSD;
257
+ if (supply0USD && supply1USD)
258
+ return supply0USD + supply1USD;
261
259
  return 0;
260
+ // const [supply0USD, supply1USD, totalBalanceUSD] = await Promise.all([
261
+ // this.getBorrowableA().getTotalBalanceUSD(),
262
+ // this.getBorrowableB().getTotalBalanceUSD(),
263
+ // this.getCollateral().getTotalBalanceUSD(),
264
+ // ]);
265
+ // if (supply0USD && supply1USD && totalBalanceUSD)
266
+ // return supply0USD + supply1USD + totalBalanceUSD;
267
+ // return 0;
262
268
  });
263
269
  }
264
270
  // Flags
@@ -330,5 +336,36 @@ class OffchainLendingPool {
330
336
  return lendingPoolData.pair.uniswapV2PairAddress;
331
337
  });
332
338
  }
339
+ initializeLendingPoolAddresses() {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ const lPool = yield this.getLendingPoolData();
342
+ return {
343
+ collateral: lPool.collateral.id,
344
+ borrowables: {
345
+ [types_1.Borrowable.A]: lPool.borrowable0.id,
346
+ [types_1.Borrowable.B]: lPool.borrowable1.id,
347
+ }
348
+ };
349
+ });
350
+ }
351
+ getLendingPoolAddresses() {
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ if (!this.cache.lendingPoolAddresses)
354
+ this.cache.lendingPoolAddresses = this.initializeLendingPoolAddresses();
355
+ return this.cache.lendingPoolAddresses;
356
+ });
357
+ }
358
+ getCollateralAddress() {
359
+ return __awaiter(this, void 0, void 0, function* () {
360
+ return (yield this.getLendingPoolAddresses()).collateral;
361
+ });
362
+ }
363
+ ;
364
+ getBorrowableAddress(borrowable) {
365
+ return __awaiter(this, void 0, void 0, function* () {
366
+ return (yield this.getLendingPoolAddresses()).borrowables[borrowable];
367
+ });
368
+ }
369
+ ;
333
370
  }
334
371
  exports.default = OffchainLendingPool;
@@ -0,0 +1,17 @@
1
+ import { Borrowable } from "../../config/types";
2
+ import OffchainCollateral from "./offchainCollateral";
3
+ import OffchainLendingPool from "./offchainLendingPool";
4
+ import OffchainCollateralV2 from "./offchainCollateralV2";
5
+ import OffchainBorrowableV2 from "./offchainBorrowableV2";
6
+ import OffchainAccount from "../account";
7
+ import OffchainAccountLendingPoolV2 from "../account/lendingPool/offchainAccountLendingPoolV2";
8
+ export default class OffchainLendingPoolV2 extends OffchainLendingPool {
9
+ protected readonly collateral: OffchainCollateral;
10
+ protected readonly borrowables: {
11
+ [Borrowable.A]: OffchainBorrowableV2;
12
+ [Borrowable.B]: OffchainBorrowableV2;
13
+ };
14
+ protected getNewCollateralObject(): OffchainCollateralV2;
15
+ protected getNewBorrowableObject(borrowable: Borrowable): OffchainBorrowableV2;
16
+ getNewAccountLendingPoolObject(account: OffchainAccount): OffchainAccountLendingPoolV2;
17
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const types_1 = require("../../config/types");
7
+ const offchainLendingPool_1 = __importDefault(require("./offchainLendingPool"));
8
+ const offchainCollateralV2_1 = __importDefault(require("./offchainCollateralV2"));
9
+ const offchainBorrowableV2_1 = __importDefault(require("./offchainBorrowableV2"));
10
+ const offchainAccountLendingPoolV2_1 = __importDefault(require("../account/lendingPool/offchainAccountLendingPoolV2"));
11
+ class OffchainLendingPoolV2 extends offchainLendingPool_1.default {
12
+ getNewCollateralObject() {
13
+ return new offchainCollateralV2_1.default(this);
14
+ }
15
+ getNewBorrowableObject(borrowable) {
16
+ return new offchainBorrowableV2_1.default(this, borrowable);
17
+ }
18
+ getNewAccountLendingPoolObject(account) {
19
+ return new offchainAccountLendingPoolV2_1.default(account, this);
20
+ }
21
+ }
22
+ exports.default = OffchainLendingPoolV2;
@@ -0,0 +1,21 @@
1
+ import { Borrowable } from "../../config/types";
2
+ import OffchainCollateralV3 from "./offchainCollateralV3";
3
+ import OffchainLendingPool from "./offchainLendingPool";
4
+ import OffchainBorrowableV3 from "./offchainBorrowableV3";
5
+ import OffchainAccount from "../account";
6
+ import OffchainAccountLendingPoolV3 from "../account/lendingPool/offchainAccountLendingPoolV3";
7
+ export default class OffchainLendingPoolV3 extends OffchainLendingPool {
8
+ protected readonly collateral: OffchainCollateralV3;
9
+ protected readonly borrowables: {
10
+ [Borrowable.A]: OffchainBorrowableV3;
11
+ [Borrowable.B]: OffchainBorrowableV3;
12
+ };
13
+ protected getNewCollateralObject(): OffchainCollateralV3;
14
+ protected getNewBorrowableObject(borrowable: Borrowable): OffchainBorrowableV3;
15
+ getNewAccountLendingPoolObject(account: OffchainAccount): OffchainAccountLendingPoolV3;
16
+ getBorrowable: (borrowable: Borrowable) => OffchainBorrowableV3;
17
+ getBorrowableA: () => OffchainBorrowableV3;
18
+ getBorrowableB: () => OffchainBorrowableV3;
19
+ getCollateral: () => OffchainCollateralV3;
20
+ getNftlp: () => import("./nftlp").OffchainNftlp;
21
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const types_1 = require("../../config/types");
7
+ const offchainCollateralV3_1 = __importDefault(require("./offchainCollateralV3"));
8
+ const offchainLendingPool_1 = __importDefault(require("./offchainLendingPool"));
9
+ const offchainBorrowableV3_1 = __importDefault(require("./offchainBorrowableV3"));
10
+ const offchainAccountLendingPoolV3_1 = __importDefault(require("../account/lendingPool/offchainAccountLendingPoolV3"));
11
+ class OffchainLendingPoolV3 extends offchainLendingPool_1.default {
12
+ constructor() {
13
+ super(...arguments);
14
+ // Shortcuts
15
+ this.getBorrowable = (borrowable) => this.borrowables[borrowable];
16
+ this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
17
+ this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
18
+ this.getCollateral = () => this.collateral;
19
+ this.getNftlp = () => this.collateral.getNftlp();
20
+ }
21
+ getNewCollateralObject() {
22
+ return new offchainCollateralV3_1.default(this);
23
+ }
24
+ getNewBorrowableObject(borrowable) {
25
+ return new offchainBorrowableV3_1.default(this, borrowable);
26
+ }
27
+ getNewAccountLendingPoolObject(account) {
28
+ return new offchainAccountLendingPoolV3_1.default(account, this);
29
+ }
30
+ }
31
+ exports.default = OffchainLendingPoolV3;
@@ -46,6 +46,8 @@ class OffchainEndpointManager {
46
46
  endpoint,
47
47
  query: queryBuilder(queries_1.QueryBuilderFactory.getQuery(endpoint)),
48
48
  }));
49
+ // An alternative here would be to use `Promise.any` and forget about endpoint block...
50
+ // Promise.any will race all endpoints passed and return the first one that is fullfilled.
49
51
  const endpointResults = yield Promise.allSettled(endpointQueries.map(eq => this.fetchFromEndpoint(eq)));
50
52
  // If one endpoint breaks then it shouldnt break, filter it out and report
51
53
  const responses = endpointResults
@@ -17,7 +17,8 @@ const apollo_client_1 = __importDefault(require("apollo-client"));
17
17
  const apollo_link_http_1 = require("apollo-link-http");
18
18
  const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
19
19
  const queries_1 = require("./queries");
20
- const lendingPool_1 = __importDefault(require("./lendingPool"));
20
+ const offchainLendingPoolV2_1 = __importDefault(require("./lendingPool/offchainLendingPoolV2"));
21
+ const offchainLendingPoolV3_1 = __importDefault(require("./lendingPool/offchainLendingPoolV3"));
21
22
  const subgraphs_1 = require("../config/subgraphs");
22
23
  const types_1 = require("../config/types");
23
24
  const amms_1 = require("../config/amms");
@@ -377,7 +378,10 @@ function initializeLendingPoolsData() {
377
378
  for (const factory in lendingPools) {
378
379
  this.lendingPools[factory] = {};
379
380
  for (const lendingPool of lendingPools[factory]) {
380
- this.lendingPools[factory][lendingPool.id] = new lendingPool_1.default(this, factory, lendingPool.id);
381
+ const isV2 = Number(factory) < 8;
382
+ this.lendingPools[factory][lendingPool.id] = isV2 ?
383
+ new offchainLendingPoolV2_1.default(this, factory, lendingPool.id)
384
+ : new offchainLendingPoolV3_1.default(this, factory, lendingPool.id);
381
385
  }
382
386
  }
383
387
  // Quickfix for MIM and SPELL
@@ -613,7 +617,7 @@ function initializeUserData(account) {
613
617
  for (const supplyPositions of rawUserData.supplyPositions) {
614
618
  const uniswapV2PairAddress = supplyPositions.borrowable.lendingPool.id;
615
619
  const underlyingAddress = supplyPositions.borrowable.underlying.id;
616
- const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
620
+ const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getBorrowableA();
617
621
  const addressA = yield borrowableA.getUnderlyingAddress();
618
622
  const poolTokenType = underlyingAddress === addressA
619
623
  ? types_1.PoolTokenType.BorrowableA
@@ -627,8 +631,8 @@ function initializeUserData(account) {
627
631
  for (const borrowPositions of rawUserData.borrowPositions) {
628
632
  const uniswapV2PairAddress = borrowPositions.borrowable.lendingPool.id;
629
633
  const underlyingAddress = borrowPositions.borrowable.underlying.id;
630
- const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
631
- const addressA = yield borrowableA.getUnderlyingAddress();
634
+ const borrowableB = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getBorrowableB();
635
+ const addressA = yield borrowableB.getUnderlyingAddress();
632
636
  const poolTokenType = underlyingAddress === addressA
633
637
  ? types_1.PoolTokenType.BorrowableA
634
638
  : types_1.PoolTokenType.BorrowableB;
@@ -164,8 +164,10 @@ class OffchainPriceHelper {
164
164
  const lendingPool = lendingPoolsData[factory][id];
165
165
  this.addPriceIfMissing(offchainTokenPrice, lendingPool.borrowable0.underlying);
166
166
  this.addPriceIfMissing(offchainTokenPrice, lendingPool.borrowable1.underlying);
167
- for (const reward of lendingPool.pair.rewards) {
168
- this.addPriceIfMissing(offchainTokenPrice, reward.rewardsToken);
167
+ if (lendingPool.pair.rewards) {
168
+ for (const reward of lendingPool.pair.rewards) {
169
+ this.addPriceIfMissing(offchainTokenPrice, reward.rewardsToken);
170
+ }
169
171
  }
170
172
  }
171
173
  }
@@ -34,17 +34,6 @@ class PonderQueryBuilder {
34
34
  name
35
35
  decimals
36
36
  derivedUSD
37
- }`;
38
- const distributorStr = `{
39
- id
40
- }`;
41
- const farmingPoolStr = `{
42
- epochAmount
43
- epochBegin
44
- segmentLength
45
- vestingBegin
46
- sharePercentage
47
- distributor ${distributorStr}
48
37
  }`;
49
38
  const borrowableStr = `{
50
39
  id
@@ -60,7 +49,6 @@ class PonderQueryBuilder {
60
49
  accrualTimestamp
61
50
  exchangeRate
62
51
  borrowTracker
63
- farmingPool ${farmingPoolStr}
64
52
  }`;
65
53
  const collateralStr = `{
66
54
  id
@@ -74,14 +62,6 @@ class PonderQueryBuilder {
74
62
  dexFactory
75
63
  token1Price
76
64
  token0Price
77
- rewards {
78
- items {
79
- id
80
- rewardRate
81
- rewardsToken ${tokenStr}
82
- periodFinish
83
- }
84
- }
85
65
  }`;
86
66
  const id_in_string = (addressesFilter === null || addressesFilter === void 0 ? void 0 : addressesFilter.length) > 0 ? `id_in: ["${addressesFilter.join('","').toLowerCase()}"]` : "";
87
67
  return (0, graphql_tag_1.default) `{
@@ -1,9 +1,9 @@
1
1
  import Offchain from "../index";
2
2
  import { Address } from '../../config/types';
3
3
  import OffchainVault from "./offchainVault";
4
- import OffchainLendingPool from "../lendingPool";
4
+ import OffchainLendingPoolV2 from "../lendingPool/offchainLendingPoolV2";
5
5
  export default class OffchainHedgedVaultVault extends OffchainVault {
6
6
  constructor(offchain: Offchain, vaultAddress: Address);
7
7
  getLeverage(): Promise<number>;
8
- getPair(): Promise<OffchainLendingPool>;
8
+ getPair(): Promise<OffchainLendingPoolV2>;
9
9
  }
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const types_1 = require("../../config/types");
16
16
  const offchainVault_1 = __importDefault(require("./offchainVault"));
17
- const lendingPool_1 = __importDefault(require("../lendingPool"));
17
+ const offchainLendingPoolV2_1 = __importDefault(require("../lendingPool/offchainLendingPoolV2"));
18
18
  class OffchainHedgedVaultVault extends offchainVault_1.default {
19
19
  constructor(offchain, vaultAddress) {
20
20
  super(offchain, vaultAddress);
@@ -27,7 +27,7 @@ class OffchainHedgedVaultVault extends offchainVault_1.default {
27
27
  }
28
28
  getPair() {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- return new lendingPool_1.default(this.getOffchain(), types_1.Factory.V2V2, "0x");
30
+ return new offchainLendingPoolV2_1.default(this.getOffchain(), types_1.Factory.V2V2, "0x");
31
31
  });
32
32
  }
33
33
  }
@@ -1,9 +1,9 @@
1
1
  import Offchain from "../index";
2
2
  import { Address } from '../../config/types';
3
3
  import OffchainVault from "./offchainVault";
4
- import OffchainLendingPool from "../lendingPool";
4
+ import OffchainLendingPoolV2 from "../lendingPool/offchainLendingPoolV2";
5
5
  export default class OffchainLeveragedVault extends OffchainVault {
6
6
  constructor(offchain: Offchain, vaultAddress: Address);
7
7
  getLeverage(): Promise<number>;
8
- getPair(): Promise<OffchainLendingPool>;
8
+ getPair(): Promise<OffchainLendingPoolV2>;
9
9
  }
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const types_1 = require("../../config/types");
16
16
  const offchainVault_1 = __importDefault(require("./offchainVault"));
17
- const lendingPool_1 = __importDefault(require("../lendingPool"));
17
+ const offchainLendingPoolV2_1 = __importDefault(require("../lendingPool/offchainLendingPoolV2"));
18
18
  class OffchainLeveragedVault extends offchainVault_1.default {
19
19
  constructor(offchain, vaultAddress) {
20
20
  super(offchain, vaultAddress);
@@ -27,7 +27,7 @@ class OffchainLeveragedVault extends offchainVault_1.default {
27
27
  }
28
28
  getPair() {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- return new lendingPool_1.default(this.getOffchain(), types_1.Factory.V2V2, "0x");
30
+ return new offchainLendingPoolV2_1.default(this.getOffchain(), types_1.Factory.V2V2, "0x");
31
31
  });
32
32
  }
33
33
  }
@@ -1,5 +1,5 @@
1
1
  import OnchainAccountPoolToken from '../onchainAccountPoolToken';
2
- import OffchainAccountCollateral from '../../../offchain/account/lendingPool/offchainAccountCollateral';
2
+ import OffchainAccountCollateralV2 from '../../../offchain/account/lendingPool/offchainAccountCollateralV2';
3
3
  import OnchainAccountCollateral from "./onchainAccountCollateral";
4
4
  import { OnchainCollateralV2 } from "../../impermaxFactory/lendingPool";
5
5
  import OnchainAccountLendingPoolV2 from "./onchainAccountLendingPoolV2";
@@ -15,8 +15,8 @@ export default class OnchainAccountCollateralV2 extends OnchainAccountPoolToken
15
15
  getAccount: () => import("..").default;
16
16
  getInteractionsPoolToken(): OnchainInteractionsCollateralV2;
17
17
  getInteractionsCollateral: () => OnchainInteractionsCollateralV2;
18
- getOffchainAccountPoolToken(): Promise<OffchainAccountCollateral>;
19
- getOffchainAccountCollateral: () => Promise<OffchainAccountCollateral>;
18
+ getOffchainAccountPoolToken(): Promise<OffchainAccountCollateralV2>;
19
+ getOffchainAccountCollateral: () => Promise<OffchainAccountCollateralV2>;
20
20
  cleanCache(): void;
21
21
  fixStakedLPExchangeRate(n: Promise<number>): Promise<number>;
22
22
  getAvailableBalanceUSD(): Promise<number>;
@@ -1,6 +1,6 @@
1
1
  import { Contract } from "../../onchainTypes";
2
2
  import OnchainPoolToken from '../../onchainPoolToken';
3
- import OffchainCollateral from '../../../offchain/lendingPool/offchainCollateral';
3
+ import OffchainCollateralV2 from '../../../offchain/lendingPool/offchainCollateralV2';
4
4
  import OnchainCollateral from "./onchainCollateral";
5
5
  import OnchainLendingPoolV2 from "./onchainLendingPoolV2";
6
6
  export default class OnchainCollateralV2 extends OnchainPoolToken implements OnchainCollateral {
@@ -11,9 +11,9 @@ export default class OnchainCollateralV2 extends OnchainPoolToken implements Onc
11
11
  cleanCache(): void;
12
12
  private getContractHelper;
13
13
  getCollateralAddress: () => Promise<string>;
14
- getOffchainCollateral(): Promise<OffchainCollateral>;
14
+ getOffchainCollateral(): Promise<OffchainCollateralV2>;
15
15
  getPoolTokenAddress: () => Promise<string>;
16
- getOffchainPoolToken: () => Promise<OffchainCollateral>;
16
+ getOffchainPoolToken: () => Promise<OffchainCollateralV2>;
17
17
  protected initializePoolToken(): Promise<Contract>;
18
18
  protected initializeToken(): Promise<Contract>;
19
19
  protected initializeExchangeRate(): Promise<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.71",
3
+ "version": "2.1.73",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",