impermax-sdk 2.1.72 → 2.1.74

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 (59) 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 +53 -18
  47. package/lib/offchain/lendingPool/offchainLendingPoolV2.d.ts +17 -0
  48. package/lib/offchain/lendingPool/offchainLendingPoolV2.js +43 -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/vault/offchainHedgedVault.d.ts +2 -2
  54. package/lib/offchain/vault/offchainHedgedVault.js +2 -2
  55. package/lib/offchain/vault/offchainLeveragedVault.d.ts +2 -2
  56. package/lib/offchain/vault/offchainLeveragedVault.js +2 -2
  57. package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +3 -3
  58. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +3 -3
  59. 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 types_1 = require("../../../config/types");
16
+ const offchainAccountLendingPool_1 = __importDefault(require("./offchainAccountLendingPool"));
17
+ const offchainAccountCollateralV3_1 = __importDefault(require("./offchainAccountCollateralV3"));
18
+ const offchainAccountBorrowableV3_1 = __importDefault(require("./offchainAccountBorrowableV3"));
19
+ class OffchainAccountLendingPoolV3 extends offchainAccountLendingPool_1.default {
20
+ getNewCollateralObject() {
21
+ return new offchainAccountCollateralV3_1.default(this);
22
+ }
23
+ getNewBorrowableObject(borrowable) {
24
+ return new offchainAccountBorrowableV3_1.default(this, borrowable);
25
+ }
26
+ constructor(account, lendingPool) {
27
+ super(account, lendingPool);
28
+ // Shortcuts
29
+ this.getLendingPool = () => this.lendingPool;
30
+ this.getBorrowable = (borrowable) => this.borrowables[borrowable];
31
+ this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
32
+ this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
33
+ this.getCollateral = () => this.collateral;
34
+ // Shortcuts
35
+ this.getAccount = () => this.account;
36
+ this.getFactory = () => this.lendingPool.getFactory();
37
+ this.getId = () => this.getId();
38
+ this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getSafetyMargin(); });
39
+ this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getLiquidationPenalty(); });
40
+ this.getNftlp = () => this.collateral.getNftlp();
41
+ }
42
+ getLendingPoolPosition() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ // TODO rename and refactor
45
+ const userData = yield this.account.getUserData();
46
+ if (!userData)
47
+ return undefined;
48
+ const userDataOfFactory = userData[this.lendingPool.getFactory()];
49
+ if (!userDataOfFactory)
50
+ return undefined;
51
+ const pairAddress = this.lendingPool.getPairAddress();
52
+ const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
53
+ return {
54
+ [types_1.PoolTokenType.BorrowableA]: supplyPositions
55
+ ? supplyPositions[types_1.PoolTokenType.BorrowableA]
56
+ : undefined,
57
+ [types_1.PoolTokenType.BorrowableB]: supplyPositions
58
+ ? supplyPositions[types_1.PoolTokenType.BorrowableB]
59
+ : undefined,
60
+ };
61
+ });
62
+ }
63
+ getLeveragedPositions() {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return [];
66
+ });
67
+ }
68
+ getLeveragedPositionsTotalBalanceUSD() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ return 1;
71
+ });
72
+ }
73
+ getLeveragedPositionsNetAPR() {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ return 1;
76
+ });
77
+ }
78
+ }
79
+ exports.default = OffchainAccountLendingPoolV3;
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const lendingPool_1 = __importDefault(require("./lendingPool"));
16
15
  const offchainAccountVault_1 = __importDefault(require("./vault/offchainAccountVault"));
17
16
  class OffchainAccount {
18
17
  constructor(offchain, account) {
@@ -26,7 +25,7 @@ class OffchainAccount {
26
25
  initializeLendingPool(factory, pair) {
27
26
  return __awaiter(this, void 0, void 0, function* () {
28
27
  const lendingPool = yield this.offchain.getLendingPool(factory, pair);
29
- return new lendingPool_1.default(this, lendingPool);
28
+ return lendingPool.getNewAccountLendingPoolObject(this);
30
29
  });
31
30
  }
32
31
  getLendingPool(factory, pair) {
@@ -0,0 +1,3 @@
1
+ import OffchainNftlp from './offchainNftlp';
2
+ export { OffchainNftlp, };
3
+ export default OffchainNftlp;
@@ -0,0 +1,9 @@
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
+ exports.OffchainNftlp = void 0;
7
+ const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
8
+ exports.OffchainNftlp = offchainNftlp_1.default;
9
+ exports.default = offchainNftlp_1.default;
@@ -0,0 +1,20 @@
1
+ import OffchainCollateralV3 from "../offchainCollateralV3";
2
+ import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
3
+ import OffchainAccountNftlp from "../../account/lendingPool/nftlp/offchainAccountNftlp";
4
+ export default abstract class OffchainNftlp {
5
+ protected readonly collateral: OffchainCollateralV3;
6
+ protected cache: {
7
+ marketPrice?: Promise<number>;
8
+ oraclePrice?: Promise<number>;
9
+ };
10
+ constructor(collateral: OffchainCollateralV3);
11
+ abstract getNewAccountNftlpObject(accountCollateral: OffchainAccountCollateralV3): OffchainAccountNftlp;
12
+ getLendingPool: () => import("../offchainLendingPoolV3").default;
13
+ getNftlpAddress: () => string;
14
+ protected abstract initializeMarketPrice(): Promise<number>;
15
+ protected abstract initializeOraclePrice(): Promise<number>;
16
+ getNftlp(): void;
17
+ getMarketPrice(): Promise<number>;
18
+ getOraclePrice(): Promise<number>;
19
+ cleanCache(): void;
20
+ }
@@ -0,0 +1,40 @@
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
+ class OffchainNftlp {
13
+ constructor(collateral) {
14
+ this.cache = {};
15
+ this.getLendingPool = () => this.collateral.getLendingPool();
16
+ this.getNftlpAddress = () => this.getLendingPool().getPairAddress();
17
+ this.collateral = collateral;
18
+ }
19
+ getNftlp() {
20
+ // Something
21
+ }
22
+ getMarketPrice() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ if (!this.cache.marketPrice)
25
+ this.cache.marketPrice = this.initializeMarketPrice();
26
+ return this.cache.marketPrice;
27
+ });
28
+ }
29
+ getOraclePrice() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ if (!this.cache.oraclePrice)
32
+ this.cache.oraclePrice = this.initializeOraclePrice();
33
+ return this.cache.oraclePrice;
34
+ });
35
+ }
36
+ cleanCache() {
37
+ this.cache = {};
38
+ }
39
+ }
40
+ exports.default = OffchainNftlp;
@@ -0,0 +1,20 @@
1
+ import OffchainNftlp from "./offchainNftlp";
2
+ import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
3
+ import OffchainAccountNftlpUniswapV3 from "../../account/lendingPool/nftlp/offchainAccountNftlp";
4
+ export default class OffchainNftlpUniswapV3 extends OffchainNftlp {
5
+ protected cache: {
6
+ marketPrice?: Promise<number>;
7
+ oraclePrice?: Promise<number>;
8
+ uniswapV3Pools?: {
9
+ [key in number]: Promise<number | null>;
10
+ };
11
+ };
12
+ getNewAccountNftlpObject(accountCollateral: OffchainAccountCollateralV3): OffchainAccountNftlpUniswapV3;
13
+ protected initializeUniswapV3Pool(fee: number): Promise<{
14
+ price: number;
15
+ liquidity: number;
16
+ } | null>;
17
+ getUniswapV3Pool(fee: number): Promise<void>;
18
+ protected initializeMarketPrice(): Promise<number>;
19
+ protected initializeOraclePrice(): Promise<number>;
20
+ }
@@ -0,0 +1,73 @@
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
+ // offchainNftlpUniswapV3.ts
16
+ const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
17
+ const offchainAccountNftlp_1 = __importDefault(require("../../account/lendingPool/nftlp/offchainAccountNftlp"));
18
+ const FEES = [100, 500, 3000, 10000];
19
+ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.cache = {};
23
+ }
24
+ getNewAccountNftlpObject(accountCollateral) {
25
+ return new offchainAccountNftlp_1.default(accountCollateral);
26
+ }
27
+ initializeUniswapV3Pool(fee) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const res = {
30
+ price: 0,
31
+ liquidity: 0
32
+ };
33
+ const lendingPool = this.collateral.getLendingPool();
34
+ const lendingPoolData = yield lendingPool.getLendingPoolData();
35
+ return res;
36
+ });
37
+ }
38
+ getUniswapV3Pool(fee) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ //if (!this.cache.uniswapV3Pools) this.cache.uniswapV3Pools = {};
41
+ //if (!this.cache.uniswapV3Pools[fee]) {
42
+ // this.cache.uniswapV3Pools[fee] = this.initializeUniswapV3Pool(fee);
43
+ //}
44
+ //return this.cache.uniswapV3Pools[fee];
45
+ });
46
+ }
47
+ initializeMarketPrice() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ //let priceCumulative = 0;
50
+ //let liquidityCumulative = 0;
51
+ //for (const fee of FEES) {
52
+ // const pool = await this.getUniswapV3Pool(fee);
53
+ // if (!pool) continue;
54
+ // const { price, liquidity } = pool;
55
+ // priceCumulative += price * liquidity;
56
+ // liquidityCumulative += liquidity;
57
+ //}
58
+ //return liquidityCumulative > 0 ? priceCumulative / liquidityCumulative : 0;
59
+ return 1;
60
+ });
61
+ }
62
+ initializeOraclePrice() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ //const lendingPool = await this.collateral.getLendingPool();
65
+ //const lendingPoolData = await lendingPool.getLendingPoolData();
66
+ //
67
+ //// This would come from offchain data
68
+ //return lendingPoolData.nftlp?.oraclePrice || 0;
69
+ return 1;
70
+ });
71
+ }
72
+ }
73
+ exports.default = OffchainNftlpUniswapV3;
@@ -1,16 +1,16 @@
1
1
  import { BorrowablePastData, PoolTokenData } from "../offchainTypes";
2
- import { Address, PoolTokenType } from '../../config/types';
2
+ import { Address, Borrowable } from '../../config/types';
3
3
  import OffchainPoolToken from '../offchainPoolToken';
4
4
  import OffchainLendingPool from './offchainLendingPool';
5
5
  export default class OffchainBorrowable extends OffchainPoolToken {
6
- private readonly lendingPool;
7
- private readonly poolTokenType;
6
+ protected readonly lendingPool: OffchainLendingPool;
7
+ protected readonly borrowable: Borrowable;
8
8
  private _accrueInterest;
9
9
  private _calculateBorrowRate;
10
- constructor(lendingPool: OffchainLendingPool, poolTokenType: PoolTokenType);
10
+ constructor(lendingPool: OffchainLendingPool, borrowable: Borrowable);
11
11
  getOffchain: () => import("..").default;
12
12
  getLendingPool: () => OffchainLendingPool;
13
- getPoolTokenType: () => PoolTokenType;
13
+ getBorrowableType: () => Borrowable;
14
14
  getPoolTokenData(): Promise<PoolTokenData>;
15
15
  getReserveFactor(): Promise<number>;
16
16
  getKinkBorrowRate(): Promise<number>;
@@ -92,18 +92,18 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
92
92
  return { borrowRate, kinkBorrowRate };
93
93
  });
94
94
  }
95
- constructor(lendingPool, poolTokenType) {
95
+ constructor(lendingPool, borrowable) {
96
96
  super();
97
97
  this.getOffchain = () => this.lendingPool.getOffchain();
98
98
  this.getLendingPool = () => this.lendingPool;
99
- this.getPoolTokenType = () => this.poolTokenType;
99
+ this.getBorrowableType = () => this.borrowable;
100
100
  this.lendingPool = lendingPool;
101
- this.poolTokenType = poolTokenType;
101
+ this.borrowable = borrowable;
102
102
  }
103
103
  getPoolTokenData() {
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  const lendingPoolData = yield this.lendingPool.getLendingPoolData();
106
- return lendingPoolData[this.poolTokenType];
106
+ return lendingPoolData[`borrowable${this.borrowable}`];
107
107
  });
108
108
  }
109
109
  // Reserve Factor
@@ -337,7 +337,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
337
337
  const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast24h();
338
338
  if (!lendingPoolDataPast)
339
339
  return undefined;
340
- return lendingPoolDataPast[this.poolTokenType];
340
+ return lendingPoolDataPast[this.borrowable];
341
341
  });
342
342
  }
343
343
  getPoolTokenDataPast7d() {
@@ -345,7 +345,7 @@ class OffchainBorrowable extends offchainPoolToken_1.default {
345
345
  const lendingPoolDataPast = yield this.lendingPool.getLendingPoolDataPast7d();
346
346
  if (!lendingPoolDataPast)
347
347
  return undefined;
348
- return lendingPoolDataPast[this.poolTokenType];
348
+ return lendingPoolDataPast[this.borrowable];
349
349
  });
350
350
  }
351
351
  // Average Borrow APR
@@ -0,0 +1,8 @@
1
+ import { Borrowable } from '../../config/types';
2
+ import OffchainBorrowable from './offchainBorrowable';
3
+ import OffchainLendingPoolV2 from './offchainLendingPoolV2';
4
+ export default class OffchainBorrowableV2 extends OffchainBorrowable {
5
+ protected readonly lendingPool: OffchainLendingPoolV2;
6
+ protected readonly borrowable: Borrowable;
7
+ constructor(lendingPool: OffchainLendingPoolV2, borrowable: Borrowable);
8
+ }
@@ -0,0 +1,14 @@
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 offchainBorrowable_1 = __importDefault(require("./offchainBorrowable"));
7
+ class OffchainBorrowableV2 extends offchainBorrowable_1.default {
8
+ constructor(lendingPool, borrowable) {
9
+ super(lendingPool, borrowable);
10
+ this.lendingPool = lendingPool;
11
+ this.borrowable = borrowable;
12
+ }
13
+ }
14
+ exports.default = OffchainBorrowableV2;
@@ -0,0 +1,8 @@
1
+ import { Borrowable } from '../../config/types';
2
+ import OffchainBorrowable from './offchainBorrowable';
3
+ import OffchainLendingPoolV3 from './offchainLendingPoolV3';
4
+ export default class OffchainBorrowableV3 extends OffchainBorrowable {
5
+ protected readonly lendingPool: OffchainLendingPoolV3;
6
+ protected readonly borrowable: Borrowable;
7
+ constructor(lendingPool: OffchainLendingPoolV3, borrowable: Borrowable);
8
+ }
@@ -0,0 +1,14 @@
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 offchainBorrowable_1 = __importDefault(require("./offchainBorrowable"));
7
+ class OffchainBorrowableV3 extends offchainBorrowable_1.default {
8
+ constructor(lendingPool, borrowable) {
9
+ super(lendingPool, borrowable);
10
+ this.lendingPool = lendingPool;
11
+ this.borrowable = borrowable;
12
+ }
13
+ }
14
+ exports.default = OffchainBorrowableV3;
@@ -1,20 +1,15 @@
1
- import { PoolTokenData } from "../offchainTypes";
2
- import { Address } from '../../config/types';
3
- import OffchainPoolToken from '../offchainPoolToken';
4
1
  import OffchainLendingPool from './offchainLendingPool';
5
- export default class OffchainCollateral extends OffchainPoolToken {
6
- private readonly lendingPool;
7
- constructor(lendingPool: OffchainLendingPool);
8
- getOffchain: () => import("..").default;
9
- getLendingPool: () => OffchainLendingPool;
10
- private getBorrowableA;
11
- private getBorrowableB;
12
- getPoolTokenData(): Promise<PoolTokenData>;
13
- getName(): Promise<string>;
14
- getSymbol(): Promise<string>;
15
- getDecimals(): Promise<number>;
16
- getUnderlyingAddress(): Promise<Address>;
17
- getTWAP(): Promise<number>;
18
- getTokenPriceFast(fallback?: boolean): Promise<number>;
19
- getTokenPriceAccurate(): Promise<number>;
2
+ import Offchain from '../offchain';
3
+ import OffchainBorrowable from "./offchainBorrowable";
4
+ import { Address } from '../../config/types';
5
+ export default abstract class OffchainCollateral {
6
+ abstract getOffchain(): Offchain;
7
+ abstract getLendingPool(): OffchainLendingPool;
8
+ abstract getBorrowableA(): OffchainBorrowable;
9
+ abstract getBorrowableB(): OffchainBorrowable;
10
+ abstract getUnderlyingAddress(): Promise<Address>;
11
+ abstract getName(): Promise<string>;
12
+ abstract getSymbol(): Promise<string>;
13
+ abstract getDecimals(): Promise<number>;
14
+ abstract getTWAP(): Promise<number>;
20
15
  }
@@ -1,81 +1,5 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const types_1 = require("../../config/types");
16
- const offchainPoolToken_1 = __importDefault(require("../offchainPoolToken"));
17
- class OffchainCollateral extends offchainPoolToken_1.default {
18
- constructor(lendingPool) {
19
- super();
20
- this.getOffchain = () => this.lendingPool.getOffchain();
21
- this.getLendingPool = () => this.lendingPool;
22
- // shortcuts
23
- this.getBorrowableA = () => this.lendingPool.getPoolToken(types_1.PoolTokenType.BorrowableA);
24
- this.getBorrowableB = () => this.lendingPool.getPoolToken(types_1.PoolTokenType.BorrowableB);
25
- this.lendingPool = lendingPool;
26
- }
27
- getPoolTokenData() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const lendingPoolData = yield this.lendingPool.getLendingPoolData();
30
- return lendingPoolData[types_1.PoolTokenType.Collateral];
31
- });
32
- }
33
- getName() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const nameA = yield this.getBorrowableA().getName();
36
- const nameB = yield this.getBorrowableB().getName();
37
- return nameA + '-' + nameB + ' LP';
38
- });
39
- }
40
- getSymbol() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const symbolA = yield this.getBorrowableA().getSymbol();
43
- const symbolB = yield this.getBorrowableB().getSymbol();
44
- return symbolA + '/' + symbolB;
45
- });
46
- }
47
- getDecimals() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return 18;
50
- });
51
- }
52
- getUnderlyingAddress() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- return this.lendingPool.getPairAddress();
55
- });
56
- }
57
- getTWAP() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- // TODO
60
- return 1;
61
- });
62
- }
63
- // Token price getters
64
- getTokenPriceFast(fallback = true) {
65
- const _super = Object.create(null, {
66
- getTokenPriceFast: { get: () => super.getTokenPriceFast }
67
- });
68
- return __awaiter(this, void 0, void 0, function* () {
69
- let tokenPrice = yield this.lendingPool.getCollateralPrice(false);
70
- if (tokenPrice > 0)
71
- return tokenPrice;
72
- return _super.getTokenPriceFast.call(this, fallback);
73
- });
74
- }
75
- getTokenPriceAccurate() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- return this.lendingPool.getCollateralPrice(false);
78
- });
79
- }
3
+ class OffchainCollateral {
80
4
  }
81
5
  exports.default = OffchainCollateral;
@@ -0,0 +1,21 @@
1
+ import { PoolTokenData } from "../offchainTypes";
2
+ import OffchainPoolToken from '../offchainPoolToken';
3
+ import OffchainCollateral from './offchainCollateral';
4
+ import OffchainLendingPoolV2 from './offchainLendingPoolV2';
5
+ import { Address } from '../../config/types';
6
+ export default class OffchainCollateralV2 extends OffchainPoolToken implements OffchainCollateral {
7
+ protected readonly lendingPool: OffchainLendingPoolV2;
8
+ constructor(lendingPool: OffchainLendingPoolV2);
9
+ getOffchain: () => import("..").default;
10
+ getLendingPool: () => OffchainLendingPoolV2;
11
+ getBorrowableA: () => import("./offchainBorrowable").default;
12
+ getBorrowableB: () => import("./offchainBorrowable").default;
13
+ getName(): Promise<string>;
14
+ getSymbol(): Promise<string>;
15
+ getDecimals(): Promise<number>;
16
+ getUnderlyingAddress(): Promise<Address>;
17
+ protected getPoolTokenData(): Promise<PoolTokenData>;
18
+ getTokenPriceFast(fallback?: boolean): Promise<number>;
19
+ getTokenPriceAccurate(): Promise<number>;
20
+ getTWAP(): Promise<number>;
21
+ }
@@ -0,0 +1,86 @@
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 offchainPoolToken_1 = __importDefault(require("../offchainPoolToken"));
16
+ class OffchainCollateralV2 extends offchainPoolToken_1.default {
17
+ constructor(lendingPool) {
18
+ super();
19
+ //
20
+ // Implementation
21
+ //
22
+ this.getOffchain = () => this.lendingPool.getOffchain();
23
+ this.getLendingPool = () => this.lendingPool;
24
+ this.getBorrowableA = () => this.lendingPool.getBorrowableA();
25
+ this.getBorrowableB = () => this.lendingPool.getBorrowableB();
26
+ this.lendingPool = lendingPool;
27
+ }
28
+ getName() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const nameA = yield this.getBorrowableA().getName();
31
+ const nameB = yield this.getBorrowableB().getName();
32
+ return `${nameA}/${nameB} LP`;
33
+ });
34
+ }
35
+ getSymbol() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const symbolA = yield this.getBorrowableA().getSymbol();
38
+ const symbolB = yield this.getBorrowableB().getSymbol();
39
+ return `${symbolA}/${symbolB}`;
40
+ });
41
+ }
42
+ getDecimals() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return 18;
45
+ });
46
+ }
47
+ getUnderlyingAddress() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return this.getLendingPool().getPairAddress();
50
+ });
51
+ }
52
+ //
53
+ // V2 Specifics
54
+ //
55
+ getPoolTokenData() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const lendingPoolData = yield this.lendingPool.getLendingPoolData();
58
+ return lendingPoolData.collateral;
59
+ });
60
+ }
61
+ //
62
+ // Pricing
63
+ //
64
+ getTokenPriceFast(fallback = true) {
65
+ const _super = Object.create(null, {
66
+ getTokenPriceFast: { get: () => super.getTokenPriceFast }
67
+ });
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const tokenPrice = yield this.lendingPool.getCollateralPrice(false);
70
+ if (tokenPrice > 0)
71
+ return tokenPrice;
72
+ return _super.getTokenPriceFast.call(this, fallback);
73
+ });
74
+ }
75
+ getTokenPriceAccurate() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this.lendingPool.getCollateralPrice(false);
78
+ });
79
+ }
80
+ getTWAP() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ return 1;
83
+ });
84
+ }
85
+ }
86
+ exports.default = OffchainCollateralV2;
@@ -0,0 +1,21 @@
1
+ import OffchainCollateral from './offchainCollateral';
2
+ import OffchainLendingPoolV3 from './offchainLendingPoolV3';
3
+ import OffchainNftlp from './nftlp/offchainNftlp';
4
+ import { Address } from '../../config/types';
5
+ export default class OffchainCollateralV3 extends OffchainCollateral {
6
+ protected readonly lendingPool: OffchainLendingPoolV3;
7
+ private readonly nftlp;
8
+ constructor(lendingPool: OffchainLendingPoolV3);
9
+ getOffchain: () => import("..").default;
10
+ getLendingPool: () => OffchainLendingPoolV3;
11
+ getBorrowableA: () => import("./offchainBorrowableV3").default;
12
+ getBorrowableB: () => import("./offchainBorrowableV3").default;
13
+ getName(): Promise<string>;
14
+ getSymbol(): Promise<string>;
15
+ getDecimals(): Promise<number>;
16
+ getUnderlyingAddress(): Promise<Address>;
17
+ getNftlp: () => OffchainNftlp;
18
+ getTokenPriceAccurate(): Promise<number>;
19
+ getTokenPriceFast(fallback?: boolean): Promise<number>;
20
+ getTWAP(): Promise<number>;
21
+ }