impermax-sdk 1.2.112 → 2.1.0

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 (171) hide show
  1. package/lib/abis/contracts/IAllowanceTransfer.json +3772 -0
  2. package/lib/abis/contracts/IERC721.json +3515 -0
  3. package/lib/abis/contracts/ITokenizedUniswapV2Position.json +4167 -0
  4. package/lib/abis/contracts/ITokenizedUniswapV3Position.json +5539 -0
  5. package/lib/abis/contracts/IUniswapV3Pool.json +6606 -0
  6. package/lib/abis/contracts/ImpermaxV3Borrowable.json +22131 -0
  7. package/lib/abis/contracts/ImpermaxV3Collateral.json +22988 -0
  8. package/lib/abis/contracts/ImpermaxV3Factory.json +17645 -0
  9. package/lib/abis/contracts/ImpermaxV3UniV2Router01.json +32488 -0
  10. package/lib/abis/contracts/ImpermaxV3UniV3Router01.json +37742 -0
  11. package/lib/abis/contracts/PoolTokenRouter01.json +9058 -0
  12. package/lib/config/amms.d.ts +0 -2
  13. package/lib/config/amms.js +0 -3
  14. package/lib/config/chainId.d.ts +2 -0
  15. package/lib/config/chainId.js +26 -0
  16. package/lib/config/contracts/routers.d.ts +3 -2
  17. package/lib/config/contracts/routers.js +46 -22
  18. package/lib/config/factories.js +1 -0
  19. package/lib/config/farms.d.ts +0 -2
  20. package/lib/config/farms.js +0 -3
  21. package/lib/config/types.d.ts +14 -1
  22. package/lib/config/types.js +15 -1
  23. package/lib/index.d.ts +6 -5
  24. package/lib/index.js +11 -4
  25. package/lib/offchain/account/index.d.ts +4 -2
  26. package/lib/offchain/account/index.js +7 -3
  27. package/lib/offchain/account/lendingPool/index.d.ts +2 -1
  28. package/lib/offchain/account/lendingPool/index.js +3 -1
  29. package/lib/offchain/account/lendingPool/offchainAccountBorrowable.d.ts +0 -3
  30. package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +1 -27
  31. package/lib/offchain/account/lendingPool/offchainAccountCollateral.d.ts +0 -2
  32. package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +2 -14
  33. package/lib/offchain/account/lendingPool/offchainAccountLendingPool.d.ts +11 -4
  34. package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +16 -15
  35. package/lib/offchain/account/lendingPool/offchainLeveragedPosition.d.ts +25 -0
  36. package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +116 -0
  37. package/lib/offchain/account/offchainAccount.d.ts +6 -6
  38. package/lib/offchain/account/offchainAccount.js +7 -7
  39. package/lib/offchain/account/offchainMultichainAccount.d.ts +34 -0
  40. package/lib/offchain/account/offchainMultichainAccount.js +66 -0
  41. package/lib/offchain/account/vault/index.d.ts +3 -0
  42. package/lib/offchain/account/vault/index.js +7 -0
  43. package/lib/offchain/account/vault/offchainAccountVault.d.ts +16 -0
  44. package/lib/offchain/account/{offchainAccountLendingVault.js → vault/offchainAccountVault.js} +14 -14
  45. package/lib/offchain/index.d.ts +3 -2
  46. package/lib/offchain/index.js +5 -3
  47. package/lib/offchain/lendingPool/offchainCollateral.d.ts +1 -0
  48. package/lib/offchain/lendingPool/offchainCollateral.js +6 -0
  49. package/lib/offchain/lendingPool/offchainLendingPool.d.ts +14 -1
  50. package/lib/offchain/lendingPool/offchainLendingPool.js +47 -0
  51. package/lib/offchain/offchain.d.ts +8 -15
  52. package/lib/offchain/offchain.js +16 -19
  53. package/lib/offchain/offchainAPRHelper.js +0 -1
  54. package/lib/offchain/offchainInitializer.d.ts +4 -4
  55. package/lib/offchain/offchainInitializer.js +4 -4
  56. package/lib/offchain/offchainMultichain.d.ts +50 -0
  57. package/lib/offchain/offchainMultichain.js +75 -0
  58. package/lib/offchain/offchainTypes.d.ts +1 -1
  59. package/lib/offchain/vault/index.d.ts +6 -0
  60. package/lib/offchain/vault/index.js +14 -0
  61. package/lib/offchain/vault/offchainHedgedVault.d.ts +9 -0
  62. package/lib/offchain/vault/offchainHedgedVault.js +57 -0
  63. package/lib/offchain/vault/offchainLendingVault.d.ts +16 -0
  64. package/lib/offchain/vault/offchainLendingVault.js +73 -0
  65. package/lib/offchain/vault/offchainLeveragedVault.d.ts +9 -0
  66. package/lib/offchain/vault/offchainLeveragedVault.js +57 -0
  67. package/lib/offchain/{offchainLendingVault.d.ts → vault/offchainVault.d.ts} +16 -7
  68. package/lib/offchain/{offchainLendingVault.js → vault/offchainVault.js} +33 -17
  69. package/lib/onchain/account/lendingPool/index.d.ts +8 -1
  70. package/lib/onchain/account/lendingPool/index.js +38 -1
  71. package/lib/onchain/account/lendingPool/nftlp/index.d.ts +4 -0
  72. package/lib/onchain/account/lendingPool/nftlp/index.js +11 -0
  73. package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.d.ts +7 -0
  74. package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.js +12 -0
  75. package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.d.ts +4 -0
  76. package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +13 -0
  77. package/lib/onchain/account/lendingPool/onchainAccountBorrowable.d.ts +12 -7
  78. package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +5 -50
  79. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.d.ts +10 -0
  80. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +55 -0
  81. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.d.ts +10 -0
  82. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +28 -0
  83. package/lib/onchain/account/lendingPool/onchainAccountCollateral.d.ts +6 -19
  84. package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +7 -90
  85. package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +25 -0
  86. package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +99 -0
  87. package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.d.ts +18 -0
  88. package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +44 -0
  89. package/lib/onchain/account/lendingPool/onchainAccountLendingPool.d.ts +19 -34
  90. package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +17 -227
  91. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.d.ts +44 -0
  92. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +285 -0
  93. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.d.ts +27 -0
  94. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.js +32 -0
  95. package/lib/onchain/account/onchainAccount.js +1 -2
  96. package/lib/onchain/account/onchainAccountLendingVault.d.ts +3 -3
  97. package/lib/onchain/impermaxFactory/index.d.ts +3 -1
  98. package/lib/onchain/impermaxFactory/index.js +5 -1
  99. package/lib/onchain/impermaxFactory/lendingPool/index.d.ts +8 -1
  100. package/lib/onchain/impermaxFactory/lendingPool/index.js +39 -1
  101. package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.d.ts +4 -0
  102. package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.js +11 -0
  103. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.d.ts +22 -0
  104. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +19 -0
  105. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.d.ts +24 -0
  106. package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +90 -0
  107. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +15 -11
  108. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +5 -24
  109. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.d.ts +9 -0
  110. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +36 -0
  111. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.d.ts +7 -0
  112. package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +23 -0
  113. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.d.ts +5 -16
  114. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +6 -43
  115. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +20 -0
  116. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +58 -0
  117. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.d.ts +13 -0
  118. package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +36 -0
  119. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +32 -47
  120. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +28 -314
  121. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.d.ts +76 -0
  122. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +338 -0
  123. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.d.ts +42 -0
  124. package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.js +39 -0
  125. package/lib/onchain/impermaxFactory/onchainImpermaxFactory.d.ts +19 -9
  126. package/lib/onchain/impermaxFactory/onchainImpermaxFactory.js +16 -26
  127. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.d.ts +16 -0
  128. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +81 -0
  129. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.d.ts +16 -0
  130. package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +88 -0
  131. package/lib/onchain/interactions/lendingPool/index.d.ts +8 -1
  132. package/lib/onchain/interactions/lendingPool/index.js +38 -1
  133. package/lib/onchain/interactions/lendingPool/nftlp/index.d.ts +4 -0
  134. package/lib/onchain/interactions/lendingPool/nftlp/index.js +11 -0
  135. package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.d.ts +7 -0
  136. package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.js +12 -0
  137. package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.d.ts +4 -0
  138. package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +13 -0
  139. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.d.ts +6 -10
  140. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.js +5 -37
  141. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.d.ts +15 -0
  142. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +63 -0
  143. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.d.ts +9 -0
  144. package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.js +14 -0
  145. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.d.ts +3 -15
  146. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.js +5 -37
  147. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.d.ts +20 -0
  148. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +48 -0
  149. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.d.ts +13 -0
  150. package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +20 -0
  151. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.d.ts +16 -31
  152. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.js +12 -94
  153. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.d.ts +42 -0
  154. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +114 -0
  155. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.d.ts +27 -0
  156. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.js +32 -0
  157. package/lib/onchain/interactions/onchainInteractions.js +3 -4
  158. package/lib/onchain/interactions/onchainInteractionsLendingVault.d.ts +1 -1
  159. package/lib/onchain/interactions/onchainInteractionsLendingVault.js +1 -1
  160. package/lib/onchain/interactions/onchainInteractionsPoolToken.d.ts +13 -13
  161. package/lib/onchain/interactions/onchainInteractionsPoolToken.js +33 -85
  162. package/lib/onchain/onchain.d.ts +3 -0
  163. package/lib/onchain/onchain.js +11 -3
  164. package/lib/onchain/onchainContractsHelper.d.ts +19 -8
  165. package/lib/onchain/onchainContractsHelper.js +55 -21
  166. package/lib/onchain/onchainLendingVault.d.ts +3 -3
  167. package/lib/onchain/onchainPermitHelper.d.ts +21 -0
  168. package/lib/onchain/onchainPermitHelper.js +198 -0
  169. package/lib/onchain/onchainTypes.d.ts +6 -0
  170. package/package.json +1 -1
  171. package/lib/offchain/account/offchainAccountLendingVault.d.ts +0 -16
@@ -8,36 +8,27 @@ 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
  const types_1 = require("../../../config/types");
16
- const onchainCollateral_1 = __importDefault(require("./onchainCollateral"));
17
- const onchainBorrowable_1 = __importDefault(require("./onchainBorrowable"));
18
- const factories_1 = require("../../../config/factories");
19
- const lliquidity_math_1 = require("../../../utils/lliquidity-math");
20
13
  class OnchainLendingPool {
21
- constructor(impermaxFactory, pairAddress) {
14
+ constructor(impermaxFactory, id) {
22
15
  this.cache = {};
23
16
  this.getImpermaxFactory = () => this.impermaxFactory;
24
- this.getPairAddress = () => this.pairAddress;
17
+ this.getId = () => this.id;
18
+ this.getBorrowable = (borrowable) => this.borrowables[borrowable];
25
19
  // Shortcuts
26
- this.getBorrowableA = () => this.poolTokens[types_1.PoolTokenType.BorrowableA];
27
- this.getBorrowableB = () => this.poolTokens[types_1.PoolTokenType.BorrowableB];
28
- this.getCollateral = () => this.poolTokens[types_1.PoolTokenType.Collateral];
20
+ this.getBorrowableA = () => this.getBorrowable(types_1.Borrowable.A);
21
+ this.getBorrowableB = () => this.getBorrowable(types_1.Borrowable.B);
22
+ this.getCollateral = () => this.collateral;
29
23
  this.getContractHelper = () => this.impermaxFactory.getOnchain().getContractHelper();
30
24
  this.impermaxFactory = impermaxFactory;
31
- this.pairAddress = pairAddress;
32
- this.poolTokens = {
33
- [types_1.PoolTokenType.Collateral]: new onchainCollateral_1.default(this),
34
- [types_1.PoolTokenType.BorrowableA]: new onchainBorrowable_1.default(this, types_1.PoolTokenType.BorrowableA),
35
- [types_1.PoolTokenType.BorrowableB]: new onchainBorrowable_1.default(this, types_1.PoolTokenType.BorrowableB),
25
+ this.id = id;
26
+ this.collateral = this.getNewCollateralObject();
27
+ this.borrowables = {
28
+ [types_1.Borrowable.A]: this.getNewBorrowableObject(types_1.Borrowable.A),
29
+ [types_1.Borrowable.B]: this.getNewBorrowableObject(types_1.Borrowable.B),
36
30
  };
37
31
  }
38
- getPoolToken(poolTokenType) {
39
- return this.poolTokens[poolTokenType];
40
- }
41
32
  cleanCache() {
42
33
  this.cache = {};
43
34
  this.getBorrowableA().cleanCache();
@@ -46,317 +37,40 @@ class OnchainLendingPool {
46
37
  }
47
38
  getOffchainLendingPool() {
48
39
  return __awaiter(this, void 0, void 0, function* () {
49
- return this.impermaxFactory.getOnchain().getOffchain().getLendingPool(this.impermaxFactory.getFactory(), this.pairAddress);
40
+ return this.impermaxFactory.getOnchain().getOffchain().getLendingPool(this.impermaxFactory.getFactory(), this.id);
50
41
  });
51
42
  }
52
- initializePoolTokenAddresses() {
43
+ initializeLendingPoolAddresses() {
53
44
  return __awaiter(this, void 0, void 0, function* () {
54
- const lPool = yield this.impermaxFactory.getRouter().methods.getLendingPool(this.pairAddress).call();
45
+ const lPool = yield (yield this.impermaxFactory.getFactoryContract()).methods.getLendingPool(this.id).call();
55
46
  return {
56
- [types_1.PoolTokenType.Collateral]: lPool.collateral,
57
- [types_1.PoolTokenType.BorrowableA]: lPool.borrowableA,
58
- [types_1.PoolTokenType.BorrowableB]: lPool.borrowableB,
59
- };
60
- });
61
- }
62
- getPoolTokenAddresses() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- if (!this.cache.poolTokenAddresses)
65
- this.cache.poolTokenAddresses = this.initializePoolTokenAddresses();
66
- return this.cache.poolTokenAddresses;
67
- });
68
- }
69
- initializeIsStakedLPToken() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- try {
72
- return yield this.impermaxFactory.getRouter().methods.isStakedLPToken(this.pairAddress).call();
73
- }
74
- catch (e) {
75
- return false;
76
- }
77
- });
78
- }
79
- getIsStakedLPToken() {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (!this.cache.isStakedLPToken)
82
- this.cache.isStakedLPToken = this.initializeIsStakedLPToken();
83
- return this.cache.isStakedLPToken;
84
- });
85
- }
86
- initializeStakedLPToken() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- if (!(yield this.getIsStakedLPToken()))
89
- return null;
90
- return this.getContractHelper().newStakedLPToken(this.pairAddress);
91
- });
92
- }
93
- getStakedLPToken() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- if (!this.cache.stakedLPToken)
96
- this.cache.stakedLPToken = this.initializeStakedLPToken();
97
- return this.cache.stakedLPToken;
98
- });
99
- }
100
- initializeUniswapV2Pair() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const stakedLPToken = yield this.getStakedLPToken();
103
- return this.getContractHelper().newUniswapV2Pair(stakedLPToken
104
- ? yield (stakedLPToken.methods.underlying().call())
105
- : this.pairAddress);
106
- });
107
- }
108
- getUniswapV2Pair() {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- if (!this.cache.uniswapV2Pair)
111
- this.cache.uniswapV2Pair = this.initializeUniswapV2Pair();
112
- return this.cache.uniswapV2Pair;
113
- });
114
- }
115
- // Reserves
116
- initializeReserves() {
117
- return __awaiter(this, void 0, void 0, function* () {
118
- const uniswapV2Pair = yield this.getUniswapV2Pair();
119
- const { reserve0, reserve1 } = yield uniswapV2Pair.methods.getReserves().call();
120
- return [
121
- yield this.getBorrowableA().normalize(reserve0),
122
- yield this.getBorrowableB().normalize(reserve1),
123
- ];
124
- });
125
- }
126
- getReserves() {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- if (!this.cache.reserves)
129
- this.cache.reserves = this.initializeReserves();
130
- return this.cache.reserves;
131
- });
132
- }
133
- // LP Total Supply
134
- initializeLPTotalSupply() {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const uniswapV2Pair = yield this.getUniswapV2Pair();
137
- const totalSupply = yield uniswapV2Pair.methods.totalSupply().call();
138
- return this.getCollateral().normalize(totalSupply);
139
- });
140
- }
141
- getLPTotalSupply() {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- if (!this.cache.LPTotalSupply)
144
- this.cache.LPTotalSupply = this.initializeLPTotalSupply();
145
- return this.cache.LPTotalSupply;
146
- });
147
- }
148
- // Price Denom LP
149
- initializePriceDenomLP() {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const collateral = yield this.getCollateral().getPoolToken();
152
- const { price0, price1 } = yield collateral.methods.getPrices().call();
153
- const decimalsA = yield this.getBorrowableA().getDecimals();
154
- const decimalsB = yield this.getBorrowableB().getDecimals();
155
- let stakedLPExchangeRate = yield this.getStakedLPExchangeRate();
156
- return [
157
- price0 / 1e18 / 1e18 * Math.pow(10, decimalsA) * stakedLPExchangeRate,
158
- price1 / 1e18 / 1e18 * Math.pow(10, decimalsB) * stakedLPExchangeRate
159
- ];
160
- });
161
- }
162
- getPriceDenomLP() {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- if (!this.cache.priceDenomLP)
165
- this.cache.priceDenomLP = this.initializePriceDenomLP();
166
- return this.cache.priceDenomLP;
167
- });
168
- }
169
- getMarketPriceDenomLP() {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- const [reserve0, reserve1] = yield this.getReserves();
172
- const totalSupply = yield this.getLPTotalSupply();
173
- const [reservesWeight0, reservesWeight1] = yield this.getMarketReservesWeights();
174
- return [
175
- totalSupply / reserve0 * reservesWeight0,
176
- totalSupply / reserve1 * reservesWeight1,
177
- ];
178
- });
179
- }
180
- // Market Price
181
- getMarketPrice() {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const [reserve0, reserve1] = yield this.getReserves();
184
- const priceInverted = this.impermaxFactory.getOnchain().priceInverted;
185
- if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory()))
186
- return (0, lliquidity_math_1.solidlyStable_getPriceFromReserves)(reserve0, reserve1, priceInverted);
187
- else
188
- return (0, lliquidity_math_1.uniswapV2_getPriceFromReserves)(reserve0, reserve1, priceInverted);
189
- });
190
- }
191
- // Value of reserveA / reserveB
192
- initializeTwapReservesValueRatio() {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
195
- const collateral = yield this.getCollateral().getPoolToken();
196
- let { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
197
- const [price0, price1] = yield this.getPriceDenomLP();
198
- twapReserve0 = yield this.getBorrowableA().normalize(twapReserve0);
199
- twapReserve1 = yield this.getBorrowableB().normalize(twapReserve1);
200
- return twapReserve0 * price0 / (twapReserve1 * price1);
201
- }
202
- else {
203
- return 1;
204
- }
205
- });
206
- }
207
- getTwapReservesValueRatio() {
208
- return __awaiter(this, void 0, void 0, function* () {
209
- if (!this.cache.twapReservesValueRatio)
210
- this.cache.twapReservesValueRatio = this.initializeTwapReservesValueRatio();
211
- return this.cache.twapReservesValueRatio;
212
- });
213
- }
214
- getTwapReservesWeights() {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- const reservesRatio = yield this.getTwapReservesValueRatio();
217
- const reservesWeight0 = reservesRatio / (1 + reservesRatio);
218
- const reservesWeight1 = 1 / (1 + reservesRatio);
219
- return [reservesWeight0, reservesWeight1];
220
- });
221
- }
222
- initializeMarketReservesValueRatio() {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
225
- const [reserve0, reserve1] = yield this.getReserves();
226
- const price = (0, lliquidity_math_1.solidlyStable_getPriceFromReserves)(reserve0, reserve1);
227
- return reserve0 * price / reserve1;
228
- }
229
- else {
230
- return 1;
231
- }
232
- });
233
- }
234
- getMarketReservesValueRatio() {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- if (!this.cache.marketReservesValueRatio)
237
- this.cache.marketReservesValueRatio = this.initializeMarketReservesValueRatio();
238
- return this.cache.marketReservesValueRatio;
239
- });
240
- }
241
- getMarketReservesWeights() {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- const reservesRatio = yield this.getMarketReservesValueRatio();
244
- const reservesWeight0 = reservesRatio / (1 + reservesRatio);
245
- const reservesWeight1 = 1 / (1 + reservesRatio);
246
- return [reservesWeight0, reservesWeight1];
247
- });
248
- }
249
- // TWAP Price
250
- initializeTWAPPrice() {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- try {
253
- const collateral = yield this.getCollateral().getPoolToken();
254
- const decimalsA = yield this.getBorrowableA().getDecimals();
255
- const decimalsB = yield this.getBorrowableB().getDecimals();
256
- if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
257
- const { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
258
- return (0, lliquidity_math_1.solidlyStable_getPriceFromReserves)(twapReserve0 / Math.pow(10, decimalsA), twapReserve1 / Math.pow(10, decimalsB));
47
+ collateral: lPool.collateral,
48
+ borrowables: {
49
+ [types_1.Borrowable.A]: lPool.borrowable0,
50
+ [types_1.Borrowable.B]: lPool.borrowable1,
259
51
  }
260
- let price;
261
- if (factories_1.SOLIDEX_FACTORIES.includes(this.impermaxFactory.getFactory())) {
262
- price = yield collateral.methods.getTwapPrice112x112().call();
263
- }
264
- else {
265
- price = (yield this.impermaxFactory.getSimpleUniswapOracle().methods.getResult(this.pairAddress).call()).price;
266
- }
267
- return price / Math.pow(2, 112) * Math.pow(10, decimalsA) / Math.pow(10, decimalsB);
268
- }
269
- catch (e) {
270
- // Oracle is not initialized yet
271
- return 0;
272
- }
273
- });
274
- }
275
- getTWAPPrice() {
276
- return __awaiter(this, void 0, void 0, function* () {
277
- if (!this.cache.TWAPPrice)
278
- this.cache.TWAPPrice = this.initializeTWAPPrice();
279
- return !this.impermaxFactory.getOnchain().priceInverted ? (yield this.cache.TWAPPrice) : 1 / (yield this.cache.TWAPPrice);
280
- });
281
- }
282
- // Exchange rate
283
- initializeStakedLPExchangeRate() {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- const stakedLPToken = yield this.getStakedLPToken();
286
- if (!stakedLPToken)
287
- return 1;
288
- return (yield stakedLPToken.methods.exchangeRate().call()) / 1e18;
289
- });
290
- }
291
- getStakedLPExchangeRate() {
292
- return __awaiter(this, void 0, void 0, function* () {
293
- if (!this.cache.stakedLPExchangeRate)
294
- this.cache.stakedLPExchangeRate = this.initializeStakedLPExchangeRate();
295
- return this.cache.stakedLPExchangeRate;
296
- });
297
- }
298
- // Pending Reward
299
- initializePendingReward() {
300
- return __awaiter(this, void 0, void 0, function* () {
301
- const stakedLPToken = yield this.getStakedLPToken();
302
- if (!stakedLPToken)
303
- return null;
304
- const rewardTokenAddress = yield stakedLPToken.methods.rewardsToken().call();
305
- const rewardToken = this.getContractHelper().newERC20(rewardTokenAddress);
306
- const decimals = yield rewardToken.methods.decimals().call();
307
- let result = {
308
- amount: 0,
309
- symbol: yield rewardToken.methods.symbol().call(),
310
52
  };
311
- try {
312
- const pendingReward = yield stakedLPToken.methods.getReward().call();
313
- result.amount = pendingReward / Math.pow(10, decimals);
314
- }
315
- catch (_a) {
316
- try {
317
- const stakingRewardsAddress = yield stakedLPToken.methods.stakingRewards().call();
318
- const stakingRewards = this.getContractHelper().newStakingRewards(stakingRewardsAddress);
319
- const earned = yield stakingRewards.methods.earned(stakedLPToken._address).call();
320
- result.amount = earned / Math.pow(10, decimals);
321
- }
322
- catch (_b) { }
323
- }
324
- return result;
325
- });
326
- }
327
- getPendingReward() {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- if (!this.cache.pendingReward)
330
- this.cache.pendingReward = this.initializePendingReward();
331
- return this.cache.pendingReward;
332
53
  });
333
54
  }
334
- // Reinvest Bounty Factor
335
- initializeReinvestBountyFactor() {
55
+ getLendingPoolAddresses() {
336
56
  return __awaiter(this, void 0, void 0, function* () {
337
- const stakedLPToken = yield this.getStakedLPToken();
338
- if (!stakedLPToken)
339
- return 0;
340
- return (yield stakedLPToken.methods.REINVEST_BOUNTY().call()) / 1e18;
57
+ if (!this.cache.lendingPoolAddresses)
58
+ this.cache.lendingPoolAddresses = this.initializeLendingPoolAddresses();
59
+ return this.cache.lendingPoolAddresses;
341
60
  });
342
61
  }
343
- getReinvestBountyFactor() {
62
+ getCollateralAddress() {
344
63
  return __awaiter(this, void 0, void 0, function* () {
345
- if (!this.cache.reinvestBountyFactor)
346
- this.cache.reinvestBountyFactor = this.initializeReinvestBountyFactor();
347
- return this.cache.reinvestBountyFactor;
64
+ return (yield this.getLendingPoolAddresses()).collateral;
348
65
  });
349
66
  }
350
- // Reinvest Bounty
351
- getReinvestBounty() {
67
+ ;
68
+ getBorrowableAddress(borrowable) {
352
69
  return __awaiter(this, void 0, void 0, function* () {
353
- const pendingReward = yield this.getPendingReward();
354
- if (!pendingReward)
355
- return 0;
356
- const reinvestBountyFactor = yield this.getReinvestBountyFactor();
357
- return pendingReward.amount * reinvestBountyFactor;
70
+ return (yield this.getLendingPoolAddresses()).borrowables[borrowable];
358
71
  });
359
72
  }
73
+ ;
360
74
  // Has Farming
361
75
  hasFarming() {
362
76
  return __awaiter(this, void 0, void 0, function* () {
@@ -0,0 +1,76 @@
1
+ import { Address, Borrowable } from '../../../config/types';
2
+ import { Contract, PendingRewardUI } from '../../onchainTypes';
3
+ import OnchainLendingPool from "./onchainLendingPool";
4
+ import OnchainCollateralV2 from "./onchainCollateralV2";
5
+ import OnchainBorrowableV2 from "./onchainBorrowableV2";
6
+ import OnchainImpermaxFactoryV2 from "../onchainImpermaxFactoryV2";
7
+ import { OnchainAccountLendingPoolV2 } from "../../account/lendingPool";
8
+ import OnchainAccount from "../../account";
9
+ import OnchainInteractionsLendingPoolV2 from "../../interactions/lendingPool/onchainInteractionsLendingPoolV2";
10
+ import OnchainInteractions from "../../interactions";
11
+ export default class OnchainLendingPoolV2 extends OnchainLendingPool {
12
+ protected readonly impermaxFactory: OnchainImpermaxFactoryV2;
13
+ protected readonly collateral: OnchainCollateralV2;
14
+ protected readonly borrowables: {
15
+ [Borrowable.A]: OnchainBorrowableV2;
16
+ [Borrowable.B]: OnchainBorrowableV2;
17
+ };
18
+ protected cache: {
19
+ lendingPoolAddresses?: Promise<{
20
+ collateral: Address;
21
+ borrowables: {
22
+ [key in Borrowable]: Address;
23
+ };
24
+ }>;
25
+ isStakedLPToken?: Promise<boolean>;
26
+ uniswapV2Pair?: Promise<Contract>;
27
+ stakedLPToken?: Promise<Contract | null>;
28
+ reserves?: Promise<[number, number]>;
29
+ LPTotalSupply?: Promise<number>;
30
+ marketPrice?: Promise<number>;
31
+ priceDenomLP?: Promise<[number, number]>;
32
+ twapReservesValueRatio?: Promise<number>;
33
+ marketReservesValueRatio?: Promise<number>;
34
+ TWAPPrice?: Promise<number>;
35
+ pendingReward?: Promise<PendingRewardUI | null>;
36
+ reinvestBountyFactor?: Promise<number>;
37
+ stakedLPExchangeRate?: Promise<number>;
38
+ };
39
+ protected getNewCollateralObject(): OnchainCollateralV2;
40
+ protected getNewBorrowableObject(borrowable: Borrowable): OnchainBorrowableV2;
41
+ getNewAccountLendingPoolObject(account: OnchainAccount): OnchainAccountLendingPoolV2;
42
+ getNewInteractionLendingPoolObject(interactions: OnchainInteractions): OnchainInteractionsLendingPoolV2;
43
+ getBorrowable: (borrowable: Borrowable) => OnchainBorrowableV2;
44
+ getBorrowableA: () => OnchainBorrowableV2;
45
+ getBorrowableB: () => OnchainBorrowableV2;
46
+ getCollateral: () => OnchainCollateralV2;
47
+ private initializeIsStakedLPToken;
48
+ getIsStakedLPToken(): Promise<boolean>;
49
+ private initializeStakedLPToken;
50
+ getStakedLPToken(): Promise<any>;
51
+ private initializeUniswapV2Pair;
52
+ getUniswapV2Pair(): Promise<any>;
53
+ private initializeReserves;
54
+ getReserves(): Promise<[number, number]>;
55
+ private initializeLPTotalSupply;
56
+ getLPTotalSupply(): Promise<number>;
57
+ private initializePriceDenomLP;
58
+ getPriceDenomLP(): Promise<[number, number]>;
59
+ getMarketPriceDenomLP(): Promise<[number, number]>;
60
+ getMarketPrice(): Promise<number>;
61
+ private initializeTwapReservesValueRatio;
62
+ getTwapReservesValueRatio(): Promise<number>;
63
+ getTwapReservesWeights(): Promise<[number, number]>;
64
+ private initializeMarketReservesValueRatio;
65
+ getMarketReservesValueRatio(): Promise<number>;
66
+ getMarketReservesWeights(): Promise<[number, number]>;
67
+ private initializeTWAPPrice;
68
+ getTWAPPrice(): Promise<number>;
69
+ private initializeStakedLPExchangeRate;
70
+ getStakedLPExchangeRate(): Promise<number>;
71
+ private initializePendingReward;
72
+ getPendingReward(): Promise<PendingRewardUI | null>;
73
+ private initializeReinvestBountyFactor;
74
+ getReinvestBountyFactor(): Promise<number>;
75
+ getReinvestBounty(): Promise<number>;
76
+ }