impermax-sdk 2.1.141 → 2.1.143

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 (100) hide show
  1. package/lib/config/subgraphs.js +3 -0
  2. package/lib/offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3.js +29 -59
  3. package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +54 -80
  4. package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +3 -14
  5. package/lib/offchain/account/lendingPool/offchainAccountCollateralV2.js +10 -24
  6. package/lib/offchain/account/lendingPool/offchainAccountCollateralV3.js +2 -13
  7. package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +8 -23
  8. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV2.js +25 -43
  9. package/lib/offchain/account/lendingPool/offchainAccountLendingPoolV3.js +33 -54
  10. package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +55 -102
  11. package/lib/offchain/account/offchainAccount.js +94 -127
  12. package/lib/offchain/account/offchainAccountPoolToken.js +4 -15
  13. package/lib/offchain/account/offchainMultichainAccount.js +171 -199
  14. package/lib/offchain/account/vault/offchainAccountVault.js +32 -49
  15. package/lib/offchain/configManager/offchainConfigManager.js +7 -20
  16. package/lib/offchain/configManager/offchainConfigManagerInitializer.js +23 -40
  17. package/lib/offchain/configManager/offchainPairConfig.js +25 -48
  18. package/lib/offchain/configManager/offchainProposal.js +15 -32
  19. package/lib/offchain/initializer/apollo.js +11 -22
  20. package/lib/offchain/initializer/blocks.js +13 -24
  21. package/lib/offchain/initializer/farming.js +30 -41
  22. package/lib/offchain/initializer/lendingPools.js +154 -173
  23. package/lib/offchain/initializer/lendingPoolsPast.js +114 -132
  24. package/lib/offchain/initializer/staking.js +9 -22
  25. package/lib/offchain/initializer/tvl.js +89 -102
  26. package/lib/offchain/initializer/user/lendingPools.js +58 -74
  27. package/lib/offchain/initializer/user/positionsV2.js +24 -35
  28. package/lib/offchain/initializer/user/positionsV3.js +39 -45
  29. package/lib/offchain/initializer/user/vaults.js +44 -56
  30. package/lib/offchain/initializer/vaults.js +61 -76
  31. package/lib/offchain/initializer/whitelist.js +37 -54
  32. package/lib/offchain/lendingPool/nftlp/offchainNftlp.js +8 -21
  33. package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +23 -42
  34. package/lib/offchain/lendingPool/offchainBorrowable.js +304 -398
  35. package/lib/offchain/lendingPool/offchainCollateralV2.js +24 -52
  36. package/lib/offchain/lendingPool/offchainCollateralV3.js +20 -43
  37. package/lib/offchain/lendingPool/offchainLendingPool.js +208 -273
  38. package/lib/offchain/lendingPool/offchainLendingPoolV2.js +9 -20
  39. package/lib/offchain/offchain.d.ts +1 -3
  40. package/lib/offchain/offchain.js +92 -130
  41. package/lib/offchain/offchainAPRHelper.js +176 -223
  42. package/lib/offchain/offchainEndpointManager.d.ts +11 -6
  43. package/lib/offchain/offchainEndpointManager.js +59 -72
  44. package/lib/offchain/offchainMultichain.d.ts +3 -0
  45. package/lib/offchain/offchainMultichain.js +36 -44
  46. package/lib/offchain/offchainPoolToken.js +55 -88
  47. package/lib/offchain/offchainPriceHelper.js +237 -265
  48. package/lib/offchain/offchainSolidexHelper.js +30 -43
  49. package/lib/offchain/queries/apis/ponder/index.js +3 -3
  50. package/lib/offchain/queries/apis/thegraph/index.js +5 -6
  51. package/lib/offchain/queries/index.js +5 -2
  52. package/lib/offchain/vault/offchainHedgedVault.js +4 -17
  53. package/lib/offchain/vault/offchainLendingVault.js +46 -67
  54. package/lib/offchain/vault/offchainLeveragedVault.js +4 -17
  55. package/lib/offchain/vault/offchainVault.js +86 -131
  56. package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +35 -66
  57. package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +6 -17
  58. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +79 -108
  59. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +14 -29
  60. package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +3 -14
  61. package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +36 -61
  62. package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +5 -18
  63. package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +13 -26
  64. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +169 -204
  65. package/lib/onchain/account/onchainAccount.js +53 -82
  66. package/lib/onchain/account/onchainAccountLendingVault.js +6 -19
  67. package/lib/onchain/account/onchainAccountPoolToken.js +37 -60
  68. package/lib/onchain/configManager/onchainPairConfig.js +30 -53
  69. package/lib/onchain/configManager/onchainProposal.js +16 -31
  70. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +8 -21
  71. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +54 -83
  72. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +72 -112
  73. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +8 -23
  74. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +2 -13
  75. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +4 -15
  76. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +11 -31
  77. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +10 -25
  78. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +22 -43
  79. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +206 -273
  80. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +7 -18
  81. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +14 -25
  82. package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +190 -209
  83. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +26 -43
  84. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +4 -15
  85. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +14 -29
  86. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +69 -90
  87. package/lib/onchain/interactions/onchainInteractions.js +21 -38
  88. package/lib/onchain/interactions/onchainInteractionsConfigManager.js +9 -24
  89. package/lib/onchain/interactions/onchainInteractionsPoolToken.js +92 -131
  90. package/lib/onchain/onchain.d.ts +2 -0
  91. package/lib/onchain/onchain.js +6 -0
  92. package/lib/onchain/onchainLendingVault.js +18 -39
  93. package/lib/onchain/onchainPermitHelper.js +84 -111
  94. package/lib/onchain/onchainPoolToken.js +68 -107
  95. package/lib/utils/ether-utils.js +1 -1
  96. package/lib/utils/lliquidity-math.js +4 -4
  97. package/lib/utils/nftlpMath/uniswapV3General.js +1 -1
  98. package/lib/utils/nftlpMath/uniswapV3Position.js +2 -2
  99. package/lib/utils/position/uniswapV3/index.js +2 -2
  100. package/package.json +4 -3
@@ -27,12 +27,15 @@ exports.IMPERMAX_SUBGRAPH_URL = {
27
27
  [types_1.Networks.Arbitrum]: {
28
28
  [types_1.Factory.V2V1_1]: [
29
29
  "https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/3PMyaq269mDMwhJ7E285RYD1r43x996b6xZmJSCGvtkm",
30
+ "https://arbitrum-factory-production.up.railway.app/"
30
31
  ],
31
32
  [types_1.Factory.V2V2]: [
32
33
  "https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/BkMRb8mR5zgCbjFSgau6s27pnANhR6k64RGVKUbWaZdY",
34
+ "https://arbitrum-factory-production.up.railway.app/"
33
35
  ],
34
36
  [types_1.Factory.SOLV2]: [
35
37
  "https://gateway.thegraph.com/api/1350441d268f171aeb0934412dfadf3b/subgraphs/id/AdLbcSfG6JnpZ7RDdHNHq3bJ21waGnRi7AJ5x3YFGYFo",
38
+ "https://arbitrum-factory-production.up.railway.app/"
36
39
  ],
37
40
  },
38
41
  [types_1.Networks.Avalanche]: {
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -23,67 +14,46 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
23
14
  this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
24
15
  }
25
16
  // Returns all positions by token ID
26
- getTokenPositions() {
27
- var _a;
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const positions = (_a = (yield this.getLendingPool().getLendingPoolPosition())) === null || _a === void 0 ? void 0 : _a.positions;
30
- return positions;
31
- });
17
+ async getTokenPositions() {
18
+ const positions = (await this.getLendingPool().getLendingPoolPosition())?.positions;
19
+ return positions;
32
20
  }
33
21
  // Returns single position data
34
- getPositionData(tokenId) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const positions = yield this.getTokenPositions();
37
- return positions[tokenId].nftlp;
38
- });
22
+ async getPositionData(tokenId) {
23
+ const positions = await this.getTokenPositions();
24
+ return positions[tokenId].nftlp;
39
25
  }
40
26
  // Mirrored from Onchain
41
- getFee(tokenId) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- return (yield this.getPositionData(tokenId)).fee / 10000;
44
- });
27
+ async getFee(tokenId) {
28
+ return (await this.getPositionData(tokenId)).fee / 10000;
45
29
  }
46
- getTickLower(tokenId) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return (yield this.getPositionData(tokenId)).tickLower;
49
- });
30
+ async getTickLower(tokenId) {
31
+ return (await this.getPositionData(tokenId)).tickLower;
50
32
  }
51
- getTickUpper(tokenId) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- return (yield this.getPositionData(tokenId)).tickUpper;
54
- });
33
+ async getTickUpper(tokenId) {
34
+ return (await this.getPositionData(tokenId)).tickUpper;
55
35
  }
56
- getPriceA(tokenId) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- return this.getNftlp().tickToPrice(yield this.getTickLower(tokenId));
59
- });
36
+ async getPriceA(tokenId) {
37
+ return this.getNftlp().tickToPrice(await this.getTickLower(tokenId));
60
38
  }
61
- getPriceB(tokenId) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return this.getNftlp().tickToPrice(yield this.getTickUpper(tokenId));
64
- });
39
+ async getPriceB(tokenId) {
40
+ return this.getNftlp().tickToPrice(await this.getTickUpper(tokenId));
65
41
  }
66
- getLiquidity(tokenId) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const decimalsA = yield this.getNftlp().getLendingPool().getBorrowableA().getDecimals();
69
- const decimalsB = yield this.getNftlp().getLendingPool().getBorrowableB().getDecimals();
70
- const liquidity = (yield this.getPositionData(tokenId)).liquidity;
71
- return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
72
- });
42
+ async getLiquidity(tokenId) {
43
+ const decimalsA = await this.getNftlp().getLendingPool().getBorrowableA().getDecimals();
44
+ const decimalsB = await this.getNftlp().getLendingPool().getBorrowableB().getDecimals();
45
+ const liquidity = (await this.getPositionData(tokenId)).liquidity;
46
+ return (0, uniswapV3General_1.formatUniV3Liquidity)(liquidity, decimalsA, decimalsB);
73
47
  }
74
- createPositionObject(tokenId, lockStateChange = true) {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- return new uniswapV3_1.default(yield this.getLiquidity(tokenId), yield this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), yield this.getLendingPool().getBorrowableB().getBorrowedAmount(tokenId), yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), yield this.getPriceA(tokenId), yield this.getPriceB(tokenId), yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
77
- });
48
+ async createPositionObject(tokenId, lockStateChange = true) {
49
+ return new uniswapV3_1.default(await this.getLiquidity(tokenId), await this.getLendingPool().getBorrowableA().getBorrowedAmount(tokenId), await this.getLendingPool().getBorrowableB().getBorrowedAmount(tokenId), await this.getNftlp().getMarketPrice(), await this.getNftlp().getOraclePrice(), await this.getPriceA(tokenId), await this.getPriceB(tokenId), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
78
50
  }
79
- getPositionObject(tokenId) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (!this.cache.positionsObject)
82
- this.cache.positionsObject = {};
83
- if (!this.cache.positionsObject[tokenId])
84
- this.cache.positionsObject[tokenId] = this.createPositionObject(tokenId);
85
- return this.cache.positionsObject[tokenId];
86
- });
51
+ async getPositionObject(tokenId) {
52
+ if (!this.cache.positionsObject)
53
+ this.cache.positionsObject = {};
54
+ if (!this.cache.positionsObject[tokenId])
55
+ this.cache.positionsObject[tokenId] = this.createPositionObject(tokenId);
56
+ return this.cache.positionsObject[tokenId];
87
57
  }
88
58
  }
89
59
  exports.default = OffchainAccountNftlpUniswapV3;
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -26,91 +17,74 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
26
17
  * Supply Positions *
27
18
  *--------------------------------------------------------------------------*/
28
19
  // Lending position //
29
- getSupplyPosition() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
32
- if (!lendingPoolPosition)
33
- return undefined;
34
- return lendingPoolPosition[`borrowable${this.borrowable}`];
35
- });
20
+ async getSupplyPosition() {
21
+ const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
22
+ if (!lendingPoolPosition)
23
+ return undefined;
24
+ return lendingPoolPosition[`borrowable${this.borrowable}`];
36
25
  }
37
- getAmount() {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const supplyPosition = yield this.getSupplyPosition();
40
- if (!supplyPosition)
41
- return 0;
42
- const exchangeRate = yield this.poolToken.getCurrentExchangeRate();
43
- const supplyBalance = parseFloat(supplyPosition.balance);
44
- return supplyBalance * exchangeRate;
45
- });
26
+ async getAmount() {
27
+ const supplyPosition = await this.getSupplyPosition();
28
+ if (!supplyPosition)
29
+ return 0;
30
+ const exchangeRate = await this.poolToken.getCurrentExchangeRate();
31
+ const supplyBalance = parseFloat(supplyPosition.balance);
32
+ return supplyBalance * exchangeRate;
46
33
  }
47
- getValue() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const tokenPrice = yield this.poolToken.getTokenPriceAccurate();
50
- const borrowedAmount = yield this.getAmount();
51
- return borrowedAmount * tokenPrice;
52
- });
34
+ async getValue() {
35
+ const tokenPrice = await this.poolToken.getTokenPriceAccurate();
36
+ const borrowedAmount = await this.getAmount();
37
+ return borrowedAmount * tokenPrice;
53
38
  }
54
39
  // Earnings //
55
40
  // WARN: Not all networks support cumulativeEarnings for now, see the `userQuery` in
56
41
  // queries/apis/thegraph/index.ts. atm only available on Blast
57
- getEarnings() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- const supplyPosition = yield this.getSupplyPosition();
60
- if (!supplyPosition)
61
- return 0;
62
- const exchangeRate = yield this.poolToken.getCurrentExchangeRate();
63
- if (!supplyPosition.cumulativeEarnings)
64
- return 0;
65
- const cumulativeEarnings = parseFloat(supplyPosition.cumulativeEarnings);
66
- const lastExchangeRate = parseFloat(supplyPosition.lastExchangeRate);
67
- const tokenBalance = parseFloat(supplyPosition.balance);
68
- const newEarnings = (exchangeRate - lastExchangeRate) * tokenBalance;
69
- return cumulativeEarnings + newEarnings;
70
- });
42
+ async getEarnings() {
43
+ const supplyPosition = await this.getSupplyPosition();
44
+ if (!supplyPosition)
45
+ return 0;
46
+ const exchangeRate = await this.poolToken.getCurrentExchangeRate();
47
+ if (!supplyPosition.cumulativeEarnings)
48
+ return 0;
49
+ const cumulativeEarnings = parseFloat(supplyPosition.cumulativeEarnings);
50
+ const lastExchangeRate = parseFloat(supplyPosition.lastExchangeRate);
51
+ const tokenBalance = parseFloat(supplyPosition.balance);
52
+ const newEarnings = (exchangeRate - lastExchangeRate) * tokenBalance;
53
+ return cumulativeEarnings + newEarnings;
71
54
  }
72
- getEarningsUSD() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const tokenPrice = yield this.poolToken.getTokenPriceAccurate();
75
- const earnings = yield this.getEarnings();
76
- return earnings * tokenPrice;
77
- });
55
+ async getEarningsUSD() {
56
+ const tokenPrice = await this.poolToken.getTokenPriceAccurate();
57
+ const earnings = await this.getEarnings();
58
+ return earnings * tokenPrice;
78
59
  }
79
60
  /*--------------------------------------------------------------------------*
80
61
  * Borrow Positions *
81
62
  *--------------------------------------------------------------------------*/
82
- getBorrowPosition(tokenId) {
83
- var _a, _b, _c;
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
86
- // For V2 borrow positions
87
- if (tokenId === undefined)
88
- return (_a = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.borrowPositions) === null || _a === void 0 ? void 0 : _a[`borrowable${this.borrowable}`];
89
- // For V3 borrow positions with tokenId
90
- // Find the corresponding borrow position for this borrowable using underlying address
91
- const borrowPositions = (_c = (_b = lendingPoolPosition === null || lendingPoolPosition === void 0 ? void 0 : lendingPoolPosition.positions) === null || _b === void 0 ? void 0 : _b[tokenId]) === null || _c === void 0 ? void 0 : _c.borrowPositions;
92
- const borrowableId = yield this.getPoolToken().getUnderlyingAddress();
93
- return borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions.find(i => i.borrowable.underlying.id === borrowableId);
94
- });
63
+ async getBorrowPosition(tokenId) {
64
+ const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
65
+ // For V2 borrow positions
66
+ if (tokenId === undefined)
67
+ return lendingPoolPosition?.borrowPositions?.[`borrowable${this.borrowable}`];
68
+ // For V3 borrow positions with tokenId
69
+ // Find the corresponding borrow position for this borrowable using underlying address
70
+ const borrowPositions = lendingPoolPosition?.positions?.[tokenId]?.borrowPositions;
71
+ const borrowableId = await this.getPoolToken().getUnderlyingAddress();
72
+ return borrowPositions?.find(i => i.borrowable.underlying.id === borrowableId);
95
73
  }
96
74
  // Borrowing position
97
- getBorrowedAmount(tokenId) {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const borrowPosition = yield this.getBorrowPosition(tokenId);
100
- const borrowIndex = yield this.poolToken.getBorrowIndex();
101
- if (!borrowPosition)
102
- return 0;
103
- const borrowBalance = parseFloat(borrowPosition.borrowBalance);
104
- const userBorrowIndex = parseFloat(borrowPosition.borrowIndex);
105
- return borrowBalance * borrowIndex / userBorrowIndex;
106
- });
75
+ async getBorrowedAmount(tokenId) {
76
+ const borrowPosition = await this.getBorrowPosition(tokenId);
77
+ const borrowIndex = await this.poolToken.getBorrowIndex();
78
+ if (!borrowPosition)
79
+ return 0;
80
+ const borrowBalance = parseFloat(borrowPosition.borrowBalance);
81
+ const userBorrowIndex = parseFloat(borrowPosition.borrowIndex);
82
+ return borrowBalance * borrowIndex / userBorrowIndex;
107
83
  }
108
- getBorrowedValue(tokenId) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const tokenPrice = yield this.poolToken.getTokenPriceAccurate();
111
- const borrowedAmount = yield this.getBorrowedAmount(tokenId);
112
- return borrowedAmount * tokenPrice;
113
- });
84
+ async getBorrowedValue(tokenId) {
85
+ const tokenPrice = await this.poolToken.getTokenPriceAccurate();
86
+ const borrowedAmount = await this.getBorrowedAmount(tokenId);
87
+ return borrowedAmount * tokenPrice;
114
88
  }
115
89
  }
116
90
  exports.default = OffchainAccountBorrowable;
@@ -1,24 +1,13 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  class OffchainAccountCollateral {
13
4
  constructor() {
14
5
  //public abstract cleanCache();
15
6
  this.getAccount = () => this.getLendingPool().getAccount();
16
7
  }
17
- getAmount() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- // TODO remove this class?
20
- return 0;
21
- });
8
+ async getAmount() {
9
+ // TODO remove this class?
10
+ return 0;
22
11
  }
23
12
  }
24
13
  exports.default = OffchainAccountCollateral;
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -20,22 +11,17 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
20
11
  this.getLendingPool = () => this.lendingPool;
21
12
  this.lendingPool = lendingPool;
22
13
  }
23
- getCollateralPosition() {
24
- var _a;
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const lendingPoolPosition = yield this.lendingPool.getLendingPoolPosition();
27
- if (!lendingPoolPosition)
28
- return undefined;
29
- return (_a = lendingPoolPosition[`collateralPosition`]) === null || _a === void 0 ? void 0 : _a[0];
30
- });
14
+ async getCollateralPosition() {
15
+ const lendingPoolPosition = await this.lendingPool.getLendingPoolPosition();
16
+ if (!lendingPoolPosition)
17
+ return undefined;
18
+ return lendingPoolPosition[`collateralPosition`]?.[0];
31
19
  }
32
- getAmount() {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const collateralPosition = yield this.getCollateralPosition();
35
- if (!collateralPosition)
36
- return 0;
37
- return parseFloat(collateralPosition.balance);
38
- });
20
+ async getAmount() {
21
+ const collateralPosition = await this.getCollateralPosition();
22
+ if (!collateralPosition)
23
+ return 0;
24
+ return parseFloat(collateralPosition.balance);
39
25
  }
40
26
  }
41
27
  exports.default = OffchainAccountCollateralV2;
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -31,10 +22,8 @@ class OffchainAccountCollateralV3 extends offchainAccountCollateral_1.default {
31
22
  cleanCache() {
32
23
  this.collateralCache = {};
33
24
  }
34
- getAmount() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return 1;
37
- });
25
+ async getAmount() {
26
+ return 1;
38
27
  }
39
28
  }
40
29
  exports.default = OffchainAccountCollateralV3;
@@ -1,13 +1,4 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const types_1 = require("../../../config/types");
13
4
  class OffchainAccountLendingPool {
@@ -21,8 +12,8 @@ class OffchainAccountLendingPool {
21
12
  this.getCollateral = () => this.collateral;
22
13
  this.getFactory = () => this.lendingPool.getFactory();
23
14
  this.getId = () => this.getId();
24
- this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getSafetyMargin(); });
25
- this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return yield this.lendingPool.getLiquidationPenalty(); });
15
+ this.getSafetyMargin = async () => await this.lendingPool.getSafetyMargin();
16
+ this.getLiquidationPenalty = async () => await this.lendingPool.getLiquidationPenalty();
26
17
  this.account = account;
27
18
  this.lendingPool = lendingPool;
28
19
  this.collateral = this.getNewCollateralObject();
@@ -31,20 +22,14 @@ class OffchainAccountLendingPool {
31
22
  [types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
32
23
  };
33
24
  }
34
- getLeveragedPositions() {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return [];
37
- });
25
+ async getLeveragedPositions() {
26
+ return [];
38
27
  }
39
- getLeveragedPositionsTotalBalanceUSD() {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return 1;
42
- });
28
+ async getLeveragedPositionsTotalBalanceUSD() {
29
+ return 1;
43
30
  }
44
- getLeveragedPositionsNetAPR() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return 1;
47
- });
31
+ async getLeveragedPositionsNetAPR() {
32
+ return 1;
48
33
  }
49
34
  }
50
35
  exports.default = OffchainAccountLendingPool;
@@ -1,13 +1,4 @@
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -35,8 +26,8 @@ class OffchainAccountLendingPoolV2 extends offchainAccountLendingPool_1.default
35
26
  this.getAccount = () => this.account;
36
27
  this.getFactory = () => this.lendingPool.getFactory();
37
28
  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(); });
29
+ this.getSafetyMargin = async () => await this.lendingPool.getSafetyMargin();
30
+ this.getLiquidationPenalty = async () => await this.lendingPool.getLiquidationPenalty();
40
31
  this.account = account;
41
32
  this.lendingPool = lendingPool;
42
33
  this.collateral = this.getNewCollateralObject();
@@ -48,41 +39,32 @@ class OffchainAccountLendingPoolV2 extends offchainAccountLendingPool_1.default
48
39
  /*--------------------------------------------------------------------------*
49
40
  * User Lending Pool Data (PoolToken) *
50
41
  *--------------------------------------------------------------------------*/
51
- getLendingPoolPosition() {
52
- var _a, _b;
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const userData = yield this.account.getUserData();
55
- const userDataOfFactory = userData === null || userData === void 0 ? void 0 : userData[this.lendingPool.getFactory()];
56
- if (!userDataOfFactory)
57
- return;
58
- const pairAddress = this.lendingPool.getPairAddress();
59
- const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
60
- const borrowPositions = (_a = userDataOfFactory === null || userDataOfFactory === void 0 ? void 0 : userDataOfFactory.borrowPositions) === null || _a === void 0 ? void 0 : _a[pairAddress];
61
- return {
62
- borrowable0: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableA],
63
- borrowable1: supplyPositions === null || supplyPositions === void 0 ? void 0 : supplyPositions[types_1.PoolTokenType.BorrowableB],
64
- collateralPosition: (_b = userDataOfFactory === null || userDataOfFactory === void 0 ? void 0 : userDataOfFactory.collateralPositions) === null || _b === void 0 ? void 0 : _b[pairAddress],
65
- borrowPositions: {
66
- borrowable0: borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions[types_1.PoolTokenType.BorrowableA],
67
- borrowable1: borrowPositions === null || borrowPositions === void 0 ? void 0 : borrowPositions[types_1.PoolTokenType.BorrowableB]
68
- },
69
- };
70
- });
42
+ async getLendingPoolPosition() {
43
+ const userData = await this.account.getUserData();
44
+ const userDataOfFactory = userData?.[this.lendingPool.getFactory()];
45
+ if (!userDataOfFactory)
46
+ return;
47
+ const pairAddress = this.lendingPool.getPairAddress();
48
+ const supplyPositions = userDataOfFactory.supplyPositions[pairAddress];
49
+ const borrowPositions = userDataOfFactory?.borrowPositions?.[pairAddress];
50
+ return {
51
+ borrowable0: supplyPositions?.[types_1.PoolTokenType.BorrowableA],
52
+ borrowable1: supplyPositions?.[types_1.PoolTokenType.BorrowableB],
53
+ collateralPosition: userDataOfFactory?.collateralPositions?.[pairAddress],
54
+ borrowPositions: {
55
+ borrowable0: borrowPositions?.[types_1.PoolTokenType.BorrowableA],
56
+ borrowable1: borrowPositions?.[types_1.PoolTokenType.BorrowableB]
57
+ },
58
+ };
71
59
  }
72
- getLeveragedPositions() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- return [];
75
- });
60
+ async getLeveragedPositions() {
61
+ return [];
76
62
  }
77
- getLeveragedPositionsTotalBalanceUSD() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- return 1;
80
- });
63
+ async getLeveragedPositionsTotalBalanceUSD() {
64
+ return 1;
81
65
  }
82
- getLeveragedPositionsNetAPR() {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- return 1;
85
- });
66
+ async getLeveragedPositionsNetAPR() {
67
+ return 1;
86
68
  }
87
69
  }
88
70
  exports.default = OffchainAccountLendingPoolV2;