@gearbox-protocol/periphery-v3 1.0.4 → 1.0.6

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.
@@ -4,6 +4,8 @@
4
4
  pragma solidity ^0.8.10;
5
5
  pragma experimental ABIEncoderV2;
6
6
 
7
+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
8
+
7
9
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8
10
  import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
9
11
 
@@ -177,11 +179,12 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
177
179
  {
178
180
  result.pool = creditManagerV2.pool();
179
181
  PoolService pool = PoolService(result.pool);
180
- // result.canBorrow =;
181
182
  result.baseBorrowRate = pool.borrowAPY_RAY();
182
- // TODO: add limit calculation
183
- result.availableToBorrow = pool.creditManagersCanBorrow(_creditManager) ? pool.availableLiquidity() : 0;
184
183
 
184
+ (uint128 currentTotalDebt, uint128 totalDebtLimit) = creditFacade.totalDebt();
185
+ result.availableToBorrow = pool.creditManagersCanBorrow(_creditManager)
186
+ ? Math.min(pool.availableLiquidity(), totalDebtLimit - currentTotalDebt)
187
+ : 0;
185
188
  result.lirm = getLIRMData(address(pool.interestRateModel()));
186
189
  }
187
190
 
@@ -244,8 +247,7 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
244
247
 
245
248
  /// @dev Returns PoolData for a particular pool
246
249
  /// @param _pool Pool address
247
- // TODO: add isPaused()
248
- // TODO: add interestRateModel address / data
250
+
249
251
  function getPoolData(address _pool) public view registeredPoolOnly(_pool) returns (PoolData memory result) {
250
252
  PoolService pool = PoolService(_pool);
251
253
 
@@ -160,3 +160,79 @@ struct GaugeVote {
160
160
  uint96 totalVotesLpSide;
161
161
  uint96 totalVotesCaSide;
162
162
  }
163
+
164
+ struct CreditManagerDataV2 {
165
+ address addr;
166
+ address underlying;
167
+ address pool;
168
+ bool isWETH;
169
+ bool canBorrow;
170
+ uint256 borrowRate;
171
+ uint256 minAmount;
172
+ uint256 maxAmount;
173
+ uint256 maxLeverageFactor; // for V1 only
174
+ uint256 availableLiquidity;
175
+ address[] collateralTokens;
176
+ ContractAdapter[] adapters;
177
+ uint256[] liquidationThresholds;
178
+ uint8 version;
179
+ address creditFacade; // V2 only: address of creditFacade
180
+ address creditConfigurator; // V2 only: address of creditConfigurator
181
+ bool isDegenMode; // V2 only: true if contract is in Degen mode
182
+ address degenNFT; // V2 only: degenNFT, address(0) if not in degen mode
183
+ bool isIncreaseDebtForbidden; // V2 only: true if increasing debt is forbidden
184
+ uint256 forbiddenTokenMask; // V2 only: mask which forbids some particular tokens
185
+ uint8 maxEnabledTokensLength; // V2 only: in V1 as many tokens as the CM can support (256)
186
+ uint16 feeInterest; // Interest fee protocol charges: fee = interest accrues * feeInterest
187
+ uint16 feeLiquidation; // Liquidation fee protocol charges: fee = totalValue * feeLiquidation
188
+ uint16 liquidationDiscount; // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
189
+ uint16 feeLiquidationExpired; // Liquidation fee protocol charges on expired accounts
190
+ uint16 liquidationDiscountExpired; // Multiplier for the amount the liquidator has to pay when closing an expired account
191
+ }
192
+
193
+ struct CreditAccountDataV2 {
194
+ address addr;
195
+ address borrower;
196
+ bool inUse;
197
+ address creditManager;
198
+ address underlying;
199
+ uint256 borrowedAmountPlusInterest;
200
+ uint256 borrowedAmountPlusInterestAndFees;
201
+ uint256 totalValue;
202
+ uint256 healthFactor;
203
+ uint256 borrowRate;
204
+ TokenBalance[] balances;
205
+ uint256 repayAmount; // for v1 accounts only
206
+ uint256 liquidationAmount; // for v1 accounts only
207
+ bool canBeClosed; // for v1 accounts only
208
+ uint256 borrowedAmount;
209
+ uint256 cumulativeIndexAtOpen;
210
+ uint256 since;
211
+ uint8 version;
212
+ uint256 enabledTokenMask;
213
+ }
214
+
215
+ struct PoolDataV2 {
216
+ address addr;
217
+ bool isWETH;
218
+ address underlying;
219
+ address dieselToken;
220
+ uint256 linearCumulativeIndex;
221
+ uint256 availableLiquidity;
222
+ uint256 expectedLiquidity;
223
+ uint256 expectedLiquidityLimit;
224
+ uint256 totalBorrowed;
225
+ uint256 depositAPY_RAY;
226
+ uint256 borrowAPY_RAY;
227
+ uint256 dieselRate_RAY;
228
+ uint256 withdrawFee;
229
+ uint256 cumulativeIndex_RAY;
230
+ uint256 timestampLU;
231
+ uint8 version;
232
+ }
233
+
234
+ struct TokenInfoV2 {
235
+ address addr;
236
+ string symbol;
237
+ uint8 decimals;
238
+ }
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Gearbox Protocol. Generalized leverage for DeFi protocols
3
+ // (c) Gearbox Holdings, 2022
4
+ pragma solidity ^0.8.10;
5
+
6
+ import {CreditAccountDataV2, CreditManagerDataV2, PoolDataV2, TokenInfoV2} from "../data/Types.sol";
7
+ import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol";
8
+
9
+ interface IDataCompressorV2Exceptions {
10
+ /// @dev Thrown if attempting to get data on a contract that is not a registered
11
+ /// Credit Manager
12
+ error NotCreditManagerException();
13
+
14
+ /// @dev Thrown if attempting the get data on a contract that is not a registered
15
+ /// pool
16
+ error NotPoolException();
17
+ }
18
+
19
+ interface IDataCompressorV2 is IDataCompressorV2Exceptions, IVersion {
20
+ /// @dev Returns CreditAccountData for all opened accounts for particular borrower
21
+ /// @param borrower Borrower address
22
+ function getCreditAccountList(address borrower) external view returns (CreditAccountDataV2[] memory);
23
+
24
+ /// @dev Returns whether the borrower has an open credit account with the credit manager
25
+ /// @param creditManager Credit manager to check
26
+ /// @param borrower Borrower to check
27
+ function hasOpenedCreditAccount(address creditManager, address borrower) external view returns (bool);
28
+
29
+ /// @dev Returns CreditAccountData for a particular Credit Account account, based on creditManager and borrower
30
+ /// @param _creditManager Credit manager address
31
+ /// @param borrower Borrower address
32
+ function getCreditAccountData(address _creditManager, address borrower)
33
+ external
34
+ view
35
+ returns (CreditAccountDataV2 memory);
36
+
37
+ /// @dev Returns CreditManagerData for all Credit Managers
38
+ function getCreditManagersList() external view returns (CreditManagerDataV2[] memory);
39
+
40
+ /// @dev Returns CreditManagerData for a particular _creditManager
41
+ /// @param _creditManager CreditManager address
42
+ function getCreditManagerData(address _creditManager) external view returns (CreditManagerDataV2 memory);
43
+
44
+ /// @dev Returns PoolData for a particular pool
45
+ /// @param _pool Pool address
46
+ function getPoolData(address _pool) external view returns (PoolDataV2 memory);
47
+
48
+ /// @dev Returns PoolData for all registered pools
49
+ function getPoolsList() external view returns (PoolDataV2[] memory);
50
+
51
+ /// @dev Returns the adapter address for a particular creditManager and targetContract
52
+ function getAdapter(address _creditManager, address _allowedContract) external view returns (address adapter);
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:Gearbox-protocol/periphery-v3.git",
6
6
  "author": "Mikael <26343374+0xmikko@users.noreply.github.com>",