@gearbox-protocol/periphery-v3 1.3.6 → 1.3.8

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.
package/README.md CHANGED
@@ -1,2 +1,2 @@
1
- ## Gearbox Periphery
1
+ ## Gearbox PeripheryV3
2
2
 
@@ -31,7 +31,14 @@ import {IAddressProvider} from "@gearbox-protocol/core-v2/contracts/interfaces/I
31
31
  import {IDataCompressorV2_10} from "../interfaces/IDataCompressorV2_10.sol";
32
32
 
33
33
  import {
34
- COUNT, QUERY, CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter
34
+ COUNT,
35
+ QUERY,
36
+ CreditAccountData,
37
+ CreditManagerData,
38
+ PoolData,
39
+ TokenBalance,
40
+ ContractAdapter,
41
+ CreditManagerDebtParams
35
42
  } from "./Types.sol";
36
43
 
37
44
  // EXCEPTIONS
@@ -113,6 +120,7 @@ contract DataCompressorV2_10 is
113
120
 
114
121
  result.borrower = borrower;
115
122
  result.creditManager = _creditManager;
123
+ result.cmName = cmDescriptions[_creditManager];
116
124
  result.creditFacade = address(creditFacade);
117
125
  result.addr = creditAccount;
118
126
 
@@ -157,6 +165,8 @@ contract DataCompressorV2_10 is
157
165
  result.cumulativeIndexLastUpdate = ICreditAccount(creditAccount).cumulativeIndexAtOpen();
158
166
 
159
167
  result.since = uint64(ICreditAccount(creditAccount).since());
168
+ (,, uint40 ed,) = creditFacade.params();
169
+ result.expirationDate = ed;
160
170
  }
161
171
 
162
172
  /// @dev Returns CreditManagerData for all Credit Managers
@@ -186,6 +196,8 @@ contract DataCompressorV2_10 is
186
196
  result.addr = _creditManager;
187
197
  result.cfVersion = ver;
188
198
  result.name = cmDescriptions[_creditManager];
199
+ result.creditFacade = address(creditFacade);
200
+ result.creditConfigurator = creditManagerV2.creditConfigurator();
189
201
 
190
202
  result.underlying = creditManagerV2.underlying();
191
203
 
@@ -195,6 +207,9 @@ contract DataCompressorV2_10 is
195
207
  result.baseBorrowRate = pool.borrowAPY_RAY();
196
208
 
197
209
  (uint128 currentTotalDebt, uint128 totalDebtLimit) = creditFacade.totalDebt();
210
+
211
+ result.totalDebt = currentTotalDebt;
212
+ result.totalDebtLimit = totalDebtLimit;
198
213
  result.availableToBorrow = pool.creditManagersCanBorrow(_creditManager)
199
214
  ? Math.min(pool.availableLiquidity(), totalDebtLimit - currentTotalDebt)
200
215
  : 0;
@@ -231,9 +246,8 @@ contract DataCompressorV2_10 is
231
246
  }
232
247
  }
233
248
 
234
- result.creditFacade = address(creditFacade);
235
- result.creditConfigurator = creditManagerV2.creditConfigurator();
236
249
  result.degenNFT = creditFacade.degenNFT();
250
+ result.isDegenMode = result.degenNFT != address(0);
237
251
  {
238
252
  bool isIncreaseDebtForbidden;
239
253
  (, isIncreaseDebtForbidden,,) = creditFacade.params(); // V2 only: true if increasing debt is forbidden
@@ -265,29 +279,58 @@ contract DataCompressorV2_10 is
265
279
  PoolService pool = PoolService(_pool);
266
280
 
267
281
  result.addr = _pool;
268
- result.expectedLiquidity = pool.expectedLiquidity();
269
- result.availableLiquidity = pool.availableLiquidity();
270
- result.totalBorrowed = pool.totalBorrowed();
271
- result.dieselRate_RAY = pool.getDieselRate_RAY();
272
- result.baseInterestIndex = pool.calcLinearCumulative_RAY();
273
- result.baseInterestRate = pool.borrowAPY_RAY();
274
282
  result.underlying = pool.underlyingToken();
275
283
  result.dieselToken = pool.dieselToken();
276
284
 
277
285
  result.symbol = IERC20Metadata(result.dieselToken).symbol();
278
286
  result.name = IERC20Metadata(result.dieselToken).name();
279
287
 
288
+ result.baseInterestIndex = pool.calcLinearCumulative_RAY();
289
+ result.availableLiquidity = pool.availableLiquidity();
290
+ result.expectedLiquidity = pool.expectedLiquidity();
291
+
292
+ result.totalBorrowed = pool.totalBorrowed();
293
+
294
+ result.totalSupply = IERC20(result.dieselToken).totalSupply();
295
+ result.totalAssets = pool.fromDiesel(result.totalSupply);
296
+
297
+ result.dieselRate_RAY = pool.getDieselRate_RAY();
298
+
299
+ result.baseInterestRate = pool.borrowAPY_RAY();
300
+
280
301
  result.dieselRate_RAY = pool.getDieselRate_RAY();
302
+
281
303
  result.withdrawFee = pool.withdrawFee();
282
304
  result.lastBaseInterestUpdate = pool._timestampLU();
283
305
  result.baseInterestIndexLU = pool._cumulativeIndex_RAY();
284
306
 
285
- uint256 dieselSupply = IERC20(result.dieselToken).totalSupply();
286
- uint256 totalLP = pool.fromDiesel(dieselSupply);
287
- result.supplyRate = totalLP == 0
307
+ result.supplyRate = result.totalAssets == 0
288
308
  ? result.baseInterestRate
289
- : (result.baseInterestRate * result.totalBorrowed) * (PERCENTAGE_FACTOR - result.withdrawFee) / totalLP
290
- / PERCENTAGE_FACTOR;
309
+ : (result.baseInterestRate * result.totalBorrowed) * (PERCENTAGE_FACTOR - result.withdrawFee)
310
+ / result.totalAssets / PERCENTAGE_FACTOR;
311
+
312
+ uint256 len = pool.creditManagersCount();
313
+ result.creditManagerDebtParams = new CreditManagerDebtParams[](len);
314
+
315
+ unchecked {
316
+ for (uint256 i; i < len; ++i) {
317
+ address creditManager = pool.creditManagers(i);
318
+
319
+ uint128 currentTotalDebt;
320
+ uint128 totalDebtLimit;
321
+ if (_isContractV2(creditManager)) {
322
+ (,, ICreditFacadeV2 creditFacade,) = getCreditContracts(creditManager);
323
+ (currentTotalDebt, totalDebtLimit) = creditFacade.totalDebt();
324
+ }
325
+
326
+ result.creditManagerDebtParams[i] = CreditManagerDebtParams({
327
+ creditManager: creditManager,
328
+ borrowed: currentTotalDebt,
329
+ limit: pool.creditManagersCanBorrow(creditManager) ? totalDebtLimit : 0,
330
+ availableToBorrow: pool.creditManagersCanBorrow(creditManager) ? result.availableLiquidity : 0
331
+ });
332
+ }
333
+ }
291
334
 
292
335
  result.version = uint8(pool.version());
293
336
  result.lirm = getLIRMData(address(pool.interestRateModel()));
@@ -187,7 +187,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
187
187
  ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
188
188
  ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
189
189
  // ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
190
-
190
+ result.creditFacade = address(creditFacade);
191
191
  result.cfVersion = _getVersion(address(creditFacade));
192
192
 
193
193
  address borrower = _getBorrowerOrRevert(address(creditManager), _creditAccount);
@@ -197,6 +197,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
197
197
  result.addr = _creditAccount;
198
198
 
199
199
  result.underlying = _getUnderlying(creditManager);
200
+ result.cmName = _getName(_cm);
200
201
 
201
202
  address pool = _getPool(_cm);
202
203
  result.baseBorrowRate = _getBaseInterestRate(pool);
@@ -259,6 +260,9 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
259
260
  returns (CollateralDebtData memory collateralDebtData) {
260
261
  result.accruedInterest = collateralDebtData.accruedInterest;
261
262
  result.accruedFees = collateralDebtData.accruedFees;
263
+ result.totalDebtUSD = collateralDebtData.totalDebtUSD;
264
+ result.totalValueUSD = collateralDebtData.totalValueUSD;
265
+ result.twvUSD = collateralDebtData.twvUSD;
262
266
  result.healthFactor = collateralDebtData.twvUSD * PERCENTAGE_FACTOR / collateralDebtData.totalDebtUSD;
263
267
  result.totalValue = collateralDebtData.totalValue;
264
268
  result.isSuccessful = true;
@@ -348,6 +352,9 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
348
352
  result.name = _getName(_cm);
349
353
  result.cfVersion = _getVersion(address(creditFacade));
350
354
 
355
+ result.creditFacade = address(creditFacade);
356
+ result.creditConfigurator = address(creditConfigurator);
357
+
351
358
  result.underlying = _getUnderlying(creditManager);
352
359
 
353
360
  {
@@ -392,9 +399,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
392
399
  }
393
400
  }
394
401
 
395
- result.creditFacade = address(creditFacade);
396
- result.creditConfigurator = address(creditConfigurator);
397
402
  result.degenNFT = creditFacade.degenNFT();
403
+ result.isDegenMode = result.degenNFT != address(0);
398
404
  // (, result.isIncreaseDebtForbidden,,) = creditFacade.params(); // V2 only: true if increasing debt is forbidden
399
405
  result.forbiddenTokenMask = creditFacade.forbiddenTokenMask(); // V2 only: mask which forbids some particular tokens
400
406
  result.maxEnabledTokensLength = creditManager.maxEnabledTokens(); // V2 only: a limit on enabled tokens imposed for security
@@ -665,6 +671,7 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
665
671
  gaugeInfo.addr = gauge;
666
672
  gaugeInfo.pool = _getPool(gauge);
667
673
  (gaugeInfo.symbol, gaugeInfo.name) = _getSymbolAndName(gaugeInfo.pool);
674
+ gaugeInfo.underlying = IPoolV3(gaugeInfo.pool).asset();
668
675
 
669
676
  address[] memory quotaTokens = _getQuotedTokens(pqk);
670
677
  uint256 quotaTokensLen = quotaTokens.length;
@@ -6,24 +6,18 @@ pragma solidity ^0.8.17;
6
6
  import {LinearInterestRateModelV3} from "@gearbox-protocol/core-v3/contracts/pool/LinearInterestRateModelV3.sol";
7
7
  import {LinearInterestRateModel} from "@gearbox-protocol/core-v2/contracts/pool/LinearInterestRateModel.sol";
8
8
  import {LinearModel} from "./Types.sol";
9
+ import "forge-std/console.sol";
9
10
 
10
11
  contract LinearInterestModelHelper {
11
12
  function getLIRMData(address _model) internal view returns (LinearModel memory irm) {
12
13
  irm.interestModel = _model;
13
14
  irm.version = LinearInterestRateModel(_model).version();
14
15
 
15
- if (irm.version == 1) {
16
- (uint256 U_1, uint256 R_base, uint256 R_slope1, uint256 R_slope2) =
17
- LinearInterestRateModel(_model).getModelParameters();
18
- irm.U_1 = uint16(U_1);
19
- irm.R_base = uint16(R_base);
20
- irm.R_slope1 = uint16(R_slope1);
21
- irm.R_slope2 = uint16(R_slope2);
22
- } else {
23
- (irm.U_1, irm.U_2, irm.R_base, irm.R_slope1, irm.R_slope2, irm.R_slope3) =
24
- LinearInterestRateModelV3(_model).getModelParameters();
16
+ console.log(irm.version);
25
17
 
26
- irm.isBorrowingMoreU2Forbidden = LinearInterestRateModelV3(_model).isBorrowingMoreU2Forbidden();
27
- }
18
+ (irm.U_1, irm.U_2, irm.R_base, irm.R_slope1, irm.R_slope2, irm.R_slope3) =
19
+ LinearInterestRateModelV3(_model).getModelParameters();
20
+
21
+ irm.isBorrowingMoreU2Forbidden = LinearInterestRateModelV3(_model).isBorrowingMoreU2Forbidden();
28
22
  }
29
23
  }
@@ -46,11 +46,10 @@ struct CreditAccountData {
46
46
  address addr;
47
47
  address borrower;
48
48
  address creditManager;
49
- string cmDescription;
49
+ string cmName;
50
50
  address creditFacade;
51
51
  address underlying;
52
52
  uint256 debt;
53
- uint256 cumulativeIndexNow;
54
53
  uint256 cumulativeIndexLastUpdate;
55
54
  uint128 cumulativeQuotaInterest;
56
55
  uint256 accruedInterest;
@@ -177,6 +176,7 @@ struct GaugeInfo {
177
176
  address pool;
178
177
  string symbol;
179
178
  string name;
179
+ address underlying;
180
180
  uint16 currentEpoch;
181
181
  bool epochFrozen;
182
182
  GaugeQuotaParams[] quotaParams;
@@ -14,7 +14,7 @@ import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetect
14
14
 
15
15
  import "forge-std/console.sol";
16
16
 
17
- address constant ap = 0xfb78A83730aBd595A362645368D10fE5a20525a6;
17
+ address constant ap = 0x9ea7b04Da02a5373317D745c1571c84aaD03321D;
18
18
 
19
19
  contract DCTest {
20
20
  DataCompressorV2_10 public dc2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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,136 +0,0 @@
1
- // SPDX-License-Identifier: UNLICENSED
2
- // Gearbox Protocol. Generalized leverage for DeFi protocols
3
- // (c) Gearbox Foundation, 2023.
4
- pragma solidity ^0.8.17;
5
-
6
- import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
7
-
8
- import {DataCompressorV2_10} from "../data/DataCompressor_2_1.sol";
9
- import {DataCompressorV3_00} from "../data/DataCompressor_3_0.sol";
10
- import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter} from "../data/Types.sol";
11
-
12
- import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
13
-
14
- import "forge-std/console.sol";
15
-
16
- address constant ap = 0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4;
17
-
18
- contract DCPrinterTest {
19
- DataCompressorV2_10 public dc2;
20
- DataCompressorV3_00 public dc3;
21
-
22
- uint256 chainId;
23
-
24
- constructor() {
25
- NetworkDetector nd = new NetworkDetector();
26
- chainId = nd.chainId();
27
- }
28
-
29
- modifier liveTestOnly() {
30
- if (chainId == 1) {
31
- _;
32
- }
33
- }
34
-
35
- function setUp() public liveTestOnly {
36
- dc2 = new DataCompressorV2_10(ap);
37
- dc3 = new DataCompressorV3_00(ap);
38
- }
39
-
40
- function _printPools(PoolData[] memory pools) internal view {
41
- uint256 len = pools.length;
42
- unchecked {
43
- for (uint256 i; i < len; ++i) {
44
- PoolData memory pool = pools[i];
45
- console.log("\n\n");
46
- console.log(IERC20Metadata(pool.underlying).symbol(), pool.addr);
47
- console.log("-------------------------------");
48
-
49
- console.log("dieselToken: ", pool.dieselToken);
50
- ///
51
- console.log("baseInterestIndex: ", pool.baseInterestIndex);
52
- console.log("availableLiquidity: ", pool.availableLiquidity);
53
- console.log("expectedLiquidity: ", pool.expectedLiquidity);
54
- //
55
- console.log("totalBorrowed: ", pool.totalBorrowed);
56
- console.log("totalDebtLimit: ", pool.totalDebtLimit);
57
- // CreditManagerDebtParams[] creditManagerDebtParams;
58
- console.log("totalAssets: ", pool.totalAssets);
59
- console.log("totalSupply: ", pool.totalSupply);
60
- console.log("supplyRate", pool.supplyRate);
61
- console.log("baseInterestRate: ", pool.baseInterestRate);
62
- console.log("dieselRate_RAY: ", pool.dieselRate_RAY);
63
- console.log("withdrawFee", pool.withdrawFee);
64
- console.log("lastBaseInterestUpdate:", pool.lastBaseInterestUpdate);
65
- console.log("baseInterestIndexLU:", pool.baseInterestIndexLU);
66
- console.log("version: ", pool.version);
67
- // QuotaInfo[] quotas;
68
- // LinearModel lirm;
69
- console.log("isPaused", pool.isPaused);
70
- }
71
- }
72
- }
73
-
74
- function _printCreditManagers(CreditManagerData[] memory cms) internal view {
75
- uint256 len = cms.length;
76
- unchecked {
77
- for (uint256 i; i < len; ++i) {
78
- CreditManagerData memory cm = cms[i];
79
- console.log("\n\n");
80
- console.log(IERC20Metadata(cm.underlying).symbol(), cm.addr);
81
- console.log("-------------------------------");
82
- console.log("cfVersion: ", cm.cfVersion);
83
- console.log("creditFacace: ", cm.creditFacade); // V2 only: address of creditFacade
84
- console.log("creditConfigurator: ", cm.creditConfigurator); // V2 only: address of creditConfigurator
85
- console.log("pool: ", cm.pool);
86
- console.log("totalDebt: ", cm.totalDebt);
87
- console.log("totalDebtLimit: ", cm.totalDebtLimit);
88
- console.log("baseBorrowRate: ", cm.baseBorrowRate);
89
- console.log("minDebt: ", cm.minDebt);
90
- console.log("maxDebt: ", cm.maxDebt);
91
- console.log("availableToBorrow: ", cm.availableToBorrow);
92
- // address[] collateralTokens);
93
- // ContractAdapter[] adapters);
94
- // uint256[] liquidationThresholds);
95
- console.log("isDegenMode: ", cm.isDegenMode); // V2 only: true if contract is in Degen mode
96
- console.log("degenNFT: ", cm.degenNFT); // V2 only: degenNFT, address(0) if not in degen mode
97
- console.log("forbiddenTokenMask: ", cm.forbiddenTokenMask); // V2 only: mask which forbids some particular tokens
98
- console.log("maxEnabledTokensLength: ", cm.maxEnabledTokensLength); // V2 only: in V1 as many tokens as the CM can support (256)
99
- console.log("feeInterest: ", cm.feeInterest); // Interest fee protocol charges: fee = interest accrues * feeInterest
100
- console.log("feeLiquidation: ", cm.feeLiquidation); // Liquidation fee protocol charges: fee = totalValue * feeLiquidation
101
- console.log("liquidationDiscount: ", cm.liquidationDiscount); // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
102
- console.log("feeLiquidationExpired: ", cm.feeLiquidationExpired); // Liquidation fee protocol charges on expired accounts
103
- console.log("liquidationDiscountExpired: ", cm.liquidationDiscountExpired); // Multiplier for the amount the liquidator has to pay when closing an expired account
104
- // V3 Fileds
105
- // QuotaInfo[] quotas);
106
- // LinearModel lirm);
107
- console.log("sPaused: ", cm.isPaused);
108
- }
109
- }
110
- }
111
-
112
- function test_dc_01_pools() public view liveTestOnly {
113
- PoolData[] memory pools = dc2.getPoolsV1List();
114
- console.log("V1 pools");
115
- _printPools(pools);
116
-
117
- pools = dc3.getPoolsV3List();
118
- console.log("\nV3 pools");
119
- _printPools(pools);
120
- }
121
-
122
- function test_dc_02_credit_managers() public view liveTestOnly {
123
- CreditManagerData[] memory cms = dc2.getCreditManagersV2List();
124
- console.log("V2 credit managers");
125
- _printCreditManagers(cms);
126
-
127
- cms = dc3.getCreditManagersV3List();
128
- console.log("\n\nV3 credit managers");
129
- _printCreditManagers(cms);
130
- }
131
-
132
- function test_dc_03_credit_accounts() public view liveTestOnly {
133
- CreditAccountData[] memory cas = dc2.getCreditAccountsByBorrower(address(this));
134
- console.log("V2 credit accounts", cas.length);
135
- }
136
- }