@gearbox-protocol/periphery-v3 1.2.4 → 1.2.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.
@@ -7,6 +7,8 @@ pragma experimental ABIEncoderV2;
7
7
  import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
8
8
 
9
9
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
10
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
11
+
10
12
  import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
11
13
 
12
14
  import {PERCENTAGE_FACTOR} from "@gearbox-protocol/core-v2/contracts/libraries/PercentageMath.sol";
@@ -23,6 +25,8 @@ import {PoolService} from "@gearbox-protocol/core-v2/contracts/pool/PoolService.
23
25
 
24
26
  import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol";
25
27
 
28
+ import {ACLNonReentrantTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLNonReentrantTrait.sol";
29
+
26
30
  import {IAddressProvider} from "@gearbox-protocol/core-v2/contracts/interfaces/IAddressProvider.sol";
27
31
  import {IDataCompressorV2_10} from "../interfaces/IDataCompressorV2_10.sol";
28
32
 
@@ -37,11 +41,21 @@ import {LinearInterestModelHelper} from "./LinearInterestModelHelper.sol";
37
41
  /// @title Data compressor 2.1.
38
42
  /// @notice Collects data from various contracts for use in the dApp
39
43
  /// Do not use for data from data compressor for state-changing functions
40
- contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, LinearInterestModelHelper {
44
+ contract DataCompressorV2_10 is
45
+ IDataCompressorV2_10,
46
+ ACLNonReentrantTrait,
47
+ ContractsRegisterTrait,
48
+ LinearInterestModelHelper
49
+ {
41
50
  // Contract version
42
51
  uint256 public constant version = 2_10;
43
52
 
44
- constructor(address _addressProvider) ContractsRegisterTrait(_addressProvider) {}
53
+ mapping(address => string) public cmDescriptions;
54
+
55
+ constructor(address _addressProvider)
56
+ ACLNonReentrantTrait(_addressProvider)
57
+ ContractsRegisterTrait(_addressProvider)
58
+ {}
45
59
 
46
60
  /// @dev Returns CreditAccountData for all opened accounts for particular borrower
47
61
  /// @param borrower Borrower address
@@ -170,6 +184,7 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
170
184
 
171
185
  result.addr = _creditManager;
172
186
  result.cfVersion = ver;
187
+ result.description = cmDescriptions[_creditManager];
173
188
 
174
189
  result.underlying = creditManagerV2.underlying();
175
190
 
@@ -257,6 +272,10 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
257
272
  result.baseInterestRate = pool.borrowAPY_RAY();
258
273
  result.underlying = pool.underlyingToken();
259
274
  result.dieselToken = pool.dieselToken();
275
+
276
+ result.symbol = IERC20Metadata(result.dieselToken).symbol();
277
+ result.name = IERC20Metadata(result.dieselToken).name();
278
+
260
279
  result.dieselRate_RAY = pool.getDieselRate_RAY();
261
280
  result.withdrawFee = pool.withdrawFee();
262
281
  result.baseInterestIndexLU = pool._timestampLU();
@@ -384,4 +403,8 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
384
403
  }
385
404
  }
386
405
  }
406
+
407
+ function setCreditManagerDescription(address _cm, string calldata description) external controllerOnly {
408
+ cmDescriptions[_cm] = description;
409
+ }
387
410
  }
@@ -6,6 +6,8 @@ pragma experimental ABIEncoderV2;
6
6
 
7
7
  import "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
8
8
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
9
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
10
+
9
11
  import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol";
10
12
 
11
13
  import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
@@ -54,7 +56,8 @@ import {
54
56
  GaugeQuotaParams,
55
57
  CreditManagerDebtParams,
56
58
  GaugeVote,
57
- ZapperInfo
59
+ ZapperInfo,
60
+ LinearModel
58
61
  } from "./Types.sol";
59
62
 
60
63
  // EXCEPTIONS
@@ -165,22 +168,22 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
165
168
  {
166
169
  ICreditAccountV3 creditAccount = ICreditAccountV3(_creditAccount);
167
170
 
168
- address _pool = creditAccount.creditManager();
169
- _ensureRegisteredCreditManager(_pool);
171
+ address _cm = creditAccount.creditManager();
172
+ _ensureRegisteredCreditManager(_cm);
170
173
 
171
- if (!_isContractV3(_pool)) revert CreditManagerIsNotV3Exception();
174
+ if (!_isContractV3(_cm)) revert CreditManagerIsNotV3Exception();
172
175
 
173
- _updatePrices(_pool, priceUpdates);
176
+ _updatePrices(_cm, priceUpdates);
174
177
 
175
- return _getCreditAccountData(_pool, _creditAccount);
178
+ return _getCreditAccountData(_cm, _creditAccount);
176
179
  }
177
180
 
178
- function _getCreditAccountData(address _pool, address _creditAccount)
181
+ function _getCreditAccountData(address _cm, address _creditAccount)
179
182
  internal
180
183
  view
181
184
  returns (CreditAccountData memory result)
182
185
  {
183
- ICreditManagerV3 creditManager = ICreditManagerV3(_pool);
186
+ ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
184
187
  ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
185
188
  // ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
186
189
 
@@ -189,15 +192,15 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
189
192
  address borrower = _getBorrowerOrRevert(address(creditManager), _creditAccount);
190
193
 
191
194
  result.borrower = borrower;
192
- result.creditManager = _pool;
195
+ result.creditManager = _cm;
193
196
  result.addr = _creditAccount;
194
197
 
195
198
  result.underlying = creditManager.underlying();
196
199
 
197
- address pool = creditManager.pool();
200
+ address pool = _getPool(_cm);
198
201
  result.baseBorrowRate = _getBaseInterestRate(pool);
199
202
 
200
- uint256 collateralTokenCount = creditManager.collateralTokensCount();
203
+ uint256 collateralTokenCount = _getCollateralTokensCount(address(creditManager));
201
204
 
202
205
  result.enabledTokensMask = creditManager.enabledTokensMaskOf(_creditAccount);
203
206
 
@@ -259,7 +262,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
259
262
  result.totalValue = collateralDebtData.totalValue;
260
263
  result.isSuccessful = true;
261
264
  } catch {
262
- _getPriceFeedFailedList(_pool, result.balances);
265
+ _getPriceFeedFailedList(_cm, result.balances);
263
266
  result.isSuccessful = false;
264
267
  }
265
268
 
@@ -276,13 +279,13 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
276
279
  // address borrower;
277
280
 
278
281
  (result.debt, result.cumulativeIndexLastUpdate, result.cumulativeQuotaInterest,,,, result.since,) =
279
- CreditManagerV3(_pool).creditAccountInfo(_creditAccount);
282
+ CreditManagerV3(_cm).creditAccountInfo(_creditAccount);
280
283
 
281
284
  result.expirationDate = creditFacade.expirationDate();
282
285
  result.maxApprovedBots = CreditFacadeV3(address(creditFacade)).maxApprovedBots();
283
286
 
284
287
  result.activeBots =
285
- IBotListV3(CreditFacadeV3(address(creditFacade)).botList()).getActiveBots(_pool, _creditAccount);
288
+ IBotListV3(CreditFacadeV3(address(creditFacade)).botList()).getActiveBots(_cm, _creditAccount);
286
289
 
287
290
  // QuotaInfo[] quotas;
288
291
  result.schedultedWithdrawals = IWithdrawalManagerV3(CreditFacadeV3(address(creditFacade)).withdrawalManager())
@@ -303,10 +306,10 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
303
306
  }
304
307
 
305
308
  for (uint256 i = 0; i < len; ++i) {
306
- address _pool = IContractsRegister(contractsRegister).creditManagers(i);
309
+ address _cm = IContractsRegister(contractsRegister).creditManagers(i);
307
310
 
308
- if (_isContractV3(_pool)) {
309
- if (op == QUERY) result[index] = _pool;
311
+ if (_isContractV3(_cm)) {
312
+ if (op == QUERY) result[index] = _cm;
310
313
  ++index;
311
314
  }
312
315
  }
@@ -314,8 +317,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
314
317
  }
315
318
  }
316
319
 
317
- function _isContractV3(address _pool) internal view returns (bool) {
318
- uint256 cmVersion = _getVersion(_pool);
320
+ function _isContractV3(address _cm) internal view returns (bool) {
321
+ uint256 cmVersion = _getVersion(_cm);
319
322
  return cmVersion >= 3_00 && cmVersion < 3_99;
320
323
  }
321
324
 
@@ -341,22 +344,23 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
341
344
  ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
342
345
 
343
346
  result.addr = _cm;
347
+ result.description = _getDescription(_cm);
344
348
  result.cfVersion = _getVersion(address(creditFacade));
345
349
 
346
350
  result.underlying = creditManager.underlying();
347
351
 
348
352
  {
349
- result.pool = creditManager.pool();
353
+ result.pool = _getPool(_cm);
350
354
  IPoolV3 pool = IPoolV3(result.pool);
351
355
  result.baseBorrowRate = _getBaseInterestRate(address(pool));
352
356
  result.availableToBorrow = pool.creditManagerBorrowable(_cm);
353
- result.lirm = getLIRMData(pool.interestRateModel());
357
+ result.lirm = _getInterestRateModel(address(pool));
354
358
  }
355
359
 
356
360
  (result.minDebt, result.maxDebt) = creditFacade.debtLimits();
357
361
 
358
362
  {
359
- uint256 collateralTokenCount = creditManager.collateralTokensCount();
363
+ uint256 collateralTokenCount = _getCollateralTokensCount(address(creditManager));
360
364
 
361
365
  result.collateralTokens = new address[](collateralTokenCount);
362
366
  result.liquidationThresholds = new uint256[](collateralTokenCount);
@@ -419,6 +423,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
419
423
  result.baseInterestRate = _getBaseInterestRate(address(pool));
420
424
  result.underlying = pool.underlyingToken();
421
425
  result.dieselToken = address(pool);
426
+ (result.symbol, result.name) = _getSymbolAndName(_pool);
422
427
 
423
428
  result.dieselRate_RAY = pool.convertToAssets(RAY);
424
429
  result.withdrawFee = pool.withdrawFee();
@@ -435,7 +440,6 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
435
440
 
436
441
  unchecked {
437
442
  for (uint256 i; i < len; ++i) {
438
- console.log("i: ", i);
439
443
  address creditManager = creditManagers[i];
440
444
  result.creditManagerDebtParams[i] = CreditManagerDebtParams({
441
445
  creditManager: creditManager,
@@ -454,7 +458,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
454
458
  result.version = _getVersion(address(pool));
455
459
 
456
460
  result.quotas = _getQuotas(_pool);
457
- result.lirm = getLIRMData(pool.interestRateModel());
461
+ result.lirm = _getInterestRateModel(_pool);
462
+
458
463
  result.isPaused = pool.paused();
459
464
 
460
465
  address[] memory zappers = zapperRegister.zappers(address(pool));
@@ -584,10 +589,35 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
584
589
  return ICreditFacadeV3(ICreditManagerV3(cm).creditFacade());
585
590
  }
586
591
 
592
+ function _getSymbolAndName(address token) internal view returns (string memory symbol, string memory name) {
593
+ symbol = IERC20Metadata(token).symbol();
594
+ name = IERC20Metadata(token).name();
595
+ }
596
+
597
+ function _getInterestRateModel(address pool) internal view returns (LinearModel memory) {
598
+ return getLIRMData(IPoolV3(pool).interestRateModel());
599
+ }
600
+
601
+ function _getQuotedTokens(IPoolQuotaKeeperV3 pqk) internal view returns (address[] memory result) {
602
+ result = pqk.quotedTokens();
603
+ }
604
+
605
+ function _getPool(address cnt) internal view returns (address) {
606
+ return ICreditManagerV3(cnt).pool();
607
+ }
608
+
609
+ function _getDescription(address _cm) internal view returns (string memory) {
610
+ return ICreditManagerV3(_cm).description();
611
+ }
612
+
613
+ function _getCollateralTokensCount(address _cm) internal view returns (uint256) {
614
+ return ICreditManagerV3(_cm).collateralTokensCount();
615
+ }
616
+
587
617
  function _getQuotas(address _pool) internal view returns (QuotaInfo[] memory quotas) {
588
618
  IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(_pool);
589
619
 
590
- address[] memory quotaTokens = pqk.quotedTokens();
620
+ address[] memory quotaTokens = _getQuotedTokens(pqk);
591
621
  uint256 len = quotaTokens.length;
592
622
  quotas = new QuotaInfo[](len);
593
623
  unchecked {
@@ -616,8 +646,10 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
616
646
  IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(poolsV3[i]);
617
647
  address gauge = pqk.gauge();
618
648
  gaugeInfo.addr = gauge;
649
+ gaugeInfo.pool = _getPool(gauge);
650
+ (gaugeInfo.symbol, gaugeInfo.name) = _getSymbolAndName(gaugeInfo.pool);
619
651
 
620
- address[] memory quotaTokens = pqk.quotedTokens();
652
+ address[] memory quotaTokens = _getQuotedTokens(pqk);
621
653
  uint256 quotaTokensLen = quotaTokens.length;
622
654
  gaugeInfo.quotaParams = new GaugeQuotaParams[](quotaTokensLen);
623
655
 
@@ -666,7 +698,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
666
698
  IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(poolsV3[i]);
667
699
  gauge = pqk.gauge();
668
700
 
669
- quotaTokens = pqk.quotedTokens();
701
+ quotaTokens = _getQuotedTokens(pqk);
670
702
  }
671
703
  uint256 quotaTokensLen = quotaTokens.length;
672
704
 
@@ -44,6 +44,7 @@ struct CreditAccountData {
44
44
  address addr;
45
45
  address borrower;
46
46
  address creditManager;
47
+ string cmDescription;
47
48
  address creditFacade;
48
49
  address underlying;
49
50
  uint256 debt;
@@ -85,6 +86,7 @@ struct LinearModel {
85
86
 
86
87
  struct CreditManagerData {
87
88
  address addr;
89
+ string description;
88
90
  uint256 cfVersion;
89
91
  address creditFacade; // V2 only: address of creditFacade
90
92
  address creditConfigurator; // V2 only: address of creditConfigurator
@@ -126,6 +128,8 @@ struct PoolData {
126
128
  address addr;
127
129
  address underlying;
128
130
  address dieselToken;
131
+ string symbol;
132
+ string name;
129
133
  ///
130
134
  uint256 linearCumulativeIndex;
131
135
  uint256 availableLiquidity;
@@ -166,6 +170,9 @@ struct GaugeQuotaParams {
166
170
 
167
171
  struct GaugeInfo {
168
172
  address addr;
173
+ address pool;
174
+ string symbol;
175
+ string name;
169
176
  GaugeQuotaParams[] quotaParams;
170
177
  }
171
178
 
@@ -175,79 +182,3 @@ struct GaugeVote {
175
182
  uint96 totalVotesLpSide;
176
183
  uint96 totalVotesCaSide;
177
184
  }
178
-
179
- struct CreditManagerDataV2 {
180
- address addr;
181
- address underlying;
182
- address pool;
183
- bool isWETH;
184
- bool canBorrow;
185
- uint256 borrowRate;
186
- uint256 minAmount;
187
- uint256 maxAmount;
188
- uint256 maxLeverageFactor; // for V1 only
189
- uint256 availableLiquidity;
190
- address[] collateralTokens;
191
- ContractAdapter[] adapters;
192
- uint256[] liquidationThresholds;
193
- uint8 version;
194
- address creditFacade; // V2 only: address of creditFacade
195
- address creditConfigurator; // V2 only: address of creditConfigurator
196
- bool isDegenMode; // V2 only: true if contract is in Degen mode
197
- address degenNFT; // V2 only: degenNFT, address(0) if not in degen mode
198
- bool isIncreaseDebtForbidden; // V2 only: true if increasing debt is forbidden
199
- uint256 forbiddenTokenMask; // V2 only: mask which forbids some particular tokens
200
- uint8 maxEnabledTokensLength; // V2 only: in V1 as many tokens as the CM can support (256)
201
- uint16 feeInterest; // Interest fee protocol charges: fee = interest accrues * feeInterest
202
- uint16 feeLiquidation; // Liquidation fee protocol charges: fee = totalValue * feeLiquidation
203
- uint16 liquidationDiscount; // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
204
- uint16 feeLiquidationExpired; // Liquidation fee protocol charges on expired accounts
205
- uint16 liquidationDiscountExpired; // Multiplier for the amount the liquidator has to pay when closing an expired account
206
- }
207
-
208
- struct CreditAccountDataV2 {
209
- address addr;
210
- address borrower;
211
- bool inUse;
212
- address creditManager;
213
- address underlying;
214
- uint256 borrowedAmountPlusInterest;
215
- uint256 borrowedAmountPlusInterestAndFees;
216
- uint256 totalValue;
217
- uint256 healthFactor;
218
- uint256 borrowRate;
219
- TokenBalance[] balances;
220
- uint256 repayAmount; // for v1 accounts only
221
- uint256 liquidationAmount; // for v1 accounts only
222
- bool canBeClosed; // for v1 accounts only
223
- uint256 borrowedAmount;
224
- uint256 cumulativeIndexAtOpen;
225
- uint256 since;
226
- uint8 version;
227
- uint256 enabledTokenMask;
228
- }
229
-
230
- struct PoolDataV2 {
231
- address addr;
232
- bool isWETH;
233
- address underlying;
234
- address dieselToken;
235
- uint256 linearCumulativeIndex;
236
- uint256 availableLiquidity;
237
- uint256 expectedLiquidity;
238
- uint256 expectedLiquidityLimit;
239
- uint256 totalBorrowed;
240
- uint256 depositAPY_RAY;
241
- uint256 borrowAPY_RAY;
242
- uint256 dieselRate_RAY;
243
- uint256 withdrawFee;
244
- uint256 cumulativeIndex_RAY;
245
- uint256 timestampLU;
246
- uint8 version;
247
- }
248
-
249
- struct TokenInfoV2 {
250
- address addr;
251
- string symbol;
252
- uint8 decimals;
253
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.2.4",
3
+ "version": "1.2.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>",
@@ -1,53 +0,0 @@
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
- }