@gearbox-protocol/periphery-v3 1.0.2 → 1.0.4

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.
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: BUSL-1.1
2
2
  // Gearbox Protocol. Generalized leverage for DeFi protocols
3
- // (c) Gearbox Holdings, 2022
3
+ // (c) Gearbox Holdings, 2023
4
4
  pragma solidity ^0.8.10;
5
5
  pragma experimental ABIEncoderV2;
6
6
 
@@ -17,6 +17,7 @@ import {ICreditFacadeV2} from "@gearbox-protocol/core-v2/contracts/interfaces/IC
17
17
  import {ICreditConfiguratorV2} from "@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfiguratorV2.sol";
18
18
  import {ICreditAccount} from "@gearbox-protocol/core-v2/contracts/interfaces/ICreditAccount.sol";
19
19
  import {IPoolService} from "@gearbox-protocol/core-v2/contracts/interfaces/IPoolService.sol";
20
+ import {PoolService} from "@gearbox-protocol/core-v2/contracts/pool/PoolService.sol";
20
21
 
21
22
  import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol";
22
23
 
@@ -27,11 +28,12 @@ import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAd
27
28
 
28
29
  // EXCEPTIONS
29
30
  import {ZeroAddressException} from "@gearbox-protocol/core-v2/contracts/interfaces/IErrors.sol";
31
+ import {LinearInterestModelHelper} from "./LinearInterestModelHelper.sol";
30
32
 
31
33
  /// @title Data compressor 2.1.
32
34
  /// @notice Collects data from various contracts for use in the dApp
33
35
  /// Do not use for data from data compressor for state-changing functions
34
- contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait {
36
+ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, LinearInterestModelHelper {
35
37
  // Contract version
36
38
  uint256 public constant version = 2_10;
37
39
 
@@ -174,10 +176,13 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait {
174
176
 
175
177
  {
176
178
  result.pool = creditManagerV2.pool();
177
- IPoolService pool = IPoolService(result.pool);
179
+ PoolService pool = PoolService(result.pool);
178
180
  // result.canBorrow =;
179
181
  result.baseBorrowRate = pool.borrowAPY_RAY();
182
+ // TODO: add limit calculation
180
183
  result.availableToBorrow = pool.creditManagersCanBorrow(_creditManager) ? pool.availableLiquidity() : 0;
184
+
185
+ result.lirm = getLIRMData(address(pool.interestRateModel()));
181
186
  }
182
187
 
183
188
  (result.minDebt, result.maxDebt) = creditFacade.limits();
@@ -239,8 +244,10 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait {
239
244
 
240
245
  /// @dev Returns PoolData for a particular pool
241
246
  /// @param _pool Pool address
247
+ // TODO: add isPaused()
248
+ // TODO: add interestRateModel address / data
242
249
  function getPoolData(address _pool) public view registeredPoolOnly(_pool) returns (PoolData memory result) {
243
- IPoolService pool = IPoolService(_pool);
250
+ PoolService pool = PoolService(_pool);
244
251
 
245
252
  result.addr = _pool;
246
253
  result.expectedLiquidity = pool.expectedLiquidity();
@@ -264,6 +271,9 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait {
264
271
  / PERCENTAGE_FACTOR;
265
272
 
266
273
  result.version = uint8(pool.version());
274
+ result.lirm = getLIRMData(address(pool.interestRateModel()));
275
+
276
+ result.isPaused = pool.paused();
267
277
 
268
278
  return result;
269
279
  }
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: BUSL-1.1
2
2
  // Gearbox Protocol. Generalized leverage for DeFi protocols
3
- // (c) Gearbox Holdings, 2022
3
+ // (c) Gearbox Holdings, 2023
4
4
  pragma solidity ^0.8.10;
5
5
  pragma experimental ABIEncoderV2;
6
6
 
@@ -22,6 +22,7 @@ import {IPriceOracleV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPr
22
22
  import {ICreditAccountV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditAccountV3.sol";
23
23
  import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
24
24
  import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";
25
+ import {PoolV3} from "@gearbox-protocol/core-v3/contracts/pool/PoolV3.sol";
25
26
 
26
27
  import {CreditManagerV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditManagerV3.sol";
27
28
 
@@ -53,6 +54,7 @@ import {
53
54
 
54
55
  // EXCEPTIONS
55
56
  import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
57
+ import {LinearInterestModelHelper} from "./LinearInterestModelHelper.sol";
56
58
 
57
59
  uint256 constant COUNT = 0;
58
60
  uint256 constant QUERY = 1;
@@ -60,7 +62,7 @@ uint256 constant QUERY = 1;
60
62
  /// @title Data compressor 3.0.
61
63
  /// @notice Collects data from various contracts for use in the dApp
62
64
  /// Do not use for data from data compressor for state-changing functions
63
- contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait {
65
+ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, LinearInterestModelHelper {
64
66
  // Contract version
65
67
  uint256 public constant version = 3_00;
66
68
 
@@ -334,6 +336,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait {
334
336
  IPoolV3 pool = IPoolV3(result.pool);
335
337
  result.baseBorrowRate = pool.baseInterestRate();
336
338
  result.availableToBorrow = pool.creditManagerBorrowable(_pool);
339
+ result.lirm = getLIRMData(pool.interestRateModel());
337
340
  }
338
341
 
339
342
  (result.minDebt, result.maxDebt) = creditFacade.debtLimits();
@@ -391,7 +394,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait {
391
394
  /// @dev Returns PoolData for a particular pool
392
395
  /// @param _pool Pool address
393
396
  function getPoolData(address _pool) public view registeredPoolOnly(_pool) returns (PoolData memory result) {
394
- IPoolV3 pool = IPoolV3(_pool);
397
+ PoolV3 pool = PoolV3(_pool);
395
398
 
396
399
  result.addr = _pool;
397
400
  result.expectedLiquidity = pool.expectedLiquidity();
@@ -436,6 +439,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait {
436
439
  result.version = uint8(pool.version());
437
440
 
438
441
  result.quotas = _getQuotas(_pool);
442
+ result.lirm = getLIRMData(pool.interestRateModel());
443
+ result.isPaused = pool.paused();
439
444
 
440
445
  return result;
441
446
  }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // Gearbox Protocol. Generalized leverage for DeFi protocols
3
+ // (c) Gearbox Holdings, 2023
4
+ pragma solidity ^0.8.17;
5
+
6
+ import {LinearInterestRateModelV3} from "@gearbox-protocol/core-v3/contracts/pool/LinearInterestRateModelV3.sol";
7
+ import {LinearModel} from "./Types.sol";
8
+
9
+ contract LinearInterestModelHelper {
10
+ function getLIRMData(address _model) internal view returns (LinearModel memory irm) {
11
+ irm.interestModel = _model;
12
+
13
+ (irm.U_1, irm.U_2, irm.R_base, irm.R_slope1, irm.R_slope2, irm.R_slope3) =
14
+ LinearInterestRateModelV3(_model).getModelParameters();
15
+ }
16
+ }
@@ -62,6 +62,16 @@ struct CreditAccountData {
62
62
  ScheduledWithdrawal[2] schedultedWithdrawals;
63
63
  }
64
64
 
65
+ struct LinearModel {
66
+ address interestModel;
67
+ uint16 U_1;
68
+ uint16 U_2;
69
+ uint16 R_base;
70
+ uint16 R_slope1;
71
+ uint16 R_slope2;
72
+ uint16 R_slope3;
73
+ }
74
+
65
75
  struct CreditManagerData {
66
76
  address addr;
67
77
  uint256 cfVersion;
@@ -89,8 +99,10 @@ struct CreditManagerData {
89
99
  uint16 liquidationDiscountExpired; // Multiplier for the amount the liquidator has to pay when closing an expired account
90
100
  // V3 Fileds
91
101
  QuotaInfo[] quotas;
102
+ LinearModel lirm;
92
103
  bool isPaused;
93
104
  }
105
+ // LIR
94
106
 
95
107
  struct CreditManagerDebtParams {
96
108
  address creditManager;
@@ -121,6 +133,8 @@ struct PoolData {
121
133
  uint256 baseInterestIndexLU;
122
134
  uint256 version;
123
135
  QuotaInfo[] quotas;
136
+ LinearModel lirm;
137
+ bool isPaused;
124
138
  }
125
139
 
126
140
  struct GaugeQuotaParams {
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Gearbox Protocol. Generalized leverage for DeFi protocols
3
- // (c) Gearbox Holdings, 2022
3
+ // (c) Gearbox Holdings, 2023
4
4
  pragma solidity ^0.8.10;
5
5
 
6
6
  import {CreditAccountData, CreditManagerData, PoolData} from "../data/Types.sol";
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Gearbox Protocol. Generalized leverage for DeFi protocols
3
- // (c) Gearbox Holdings, 2022
3
+ // (c) Gearbox Holdings, 2023
4
4
  pragma solidity ^0.8.10;
5
5
 
6
6
  import {CreditAccountData, CreditManagerData, PoolData} from "../data/Types.sol";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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>",