@gearbox-protocol/periphery-v3 1.2.2 → 1.2.3

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.
@@ -62,6 +62,8 @@ import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
62
62
  import {LinearInterestModelHelper} from "./LinearInterestModelHelper.sol";
63
63
  import {IZapperRegister} from "../interfaces/IZapperRegister.sol";
64
64
 
65
+ import "forge-std/console.sol";
66
+
65
67
  /// @title Data compressor 3.0.
66
68
  /// @notice Collects data from various contracts for use in the dApp
67
69
  /// Do not use for data from data compressor for state-changing functions
@@ -137,10 +139,10 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
137
139
  uint256 caLen = creditAccounts.length;
138
140
  for (uint256 j; j < caLen; ++j) {
139
141
  if (
140
- (borrower == address(0) || _getBorrowerOrRevert(_cm, creditAccounts[i]) == borrower)
142
+ (borrower == address(0) || _getBorrowerOrRevert(_cm, creditAccounts[j]) == borrower)
141
143
  && (
142
144
  !liquidatableOnly
143
- || ICreditManagerV3(_cm).isLiquidatable(creditAccounts[i], PERCENTAGE_FACTOR)
145
+ || ICreditManagerV3(_cm).isLiquidatable(creditAccounts[j], PERCENTAGE_FACTOR)
144
146
  )
145
147
  ) {
146
148
  if (op == QUERY) {
@@ -232,7 +234,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
232
234
  }
233
235
  }
234
236
 
235
- result.aggregatedBorrowRate = result.baseBorrowRate + RAY * quotaRevenue / PERCENTAGE_FACTOR / result.debt;
237
+ result.aggregatedBorrowRate =
238
+ result.baseBorrowRate + (result.debt == 0 ? 0 : RAY * quotaRevenue / PERCENTAGE_FACTOR / result.debt);
236
239
 
237
240
  // uint256 debt;
238
241
  // uint256 cumulativeIndexNow;
@@ -22,6 +22,8 @@ contract LinearInterestModelHelper {
22
22
  } else {
23
23
  (irm.U_1, irm.U_2, irm.R_base, irm.R_slope1, irm.R_slope2, irm.R_slope3) =
24
24
  LinearInterestRateModelV3(_model).getModelParameters();
25
+
26
+ irm.isBorrowingMoreU2Forbidden = LinearInterestRateModelV3(_model).isBorrowingMoreU2Forbidden();
25
27
  }
26
28
  }
27
29
  }
@@ -80,6 +80,7 @@ struct LinearModel {
80
80
  uint16 R_slope1;
81
81
  uint16 R_slope2;
82
82
  uint16 R_slope3;
83
+ bool isBorrowingMoreU2Forbidden;
83
84
  }
84
85
 
85
86
  struct CreditManagerData {
@@ -15,7 +15,7 @@ import "forge-std/console.sol";
15
15
 
16
16
  address constant ap = 0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4;
17
17
 
18
- contract DCTest {
18
+ contract DCPrinterTest {
19
19
  DataCompressorV2_10 public dc2;
20
20
  DataCompressorV3_00 public dc3;
21
21
 
@@ -0,0 +1,140 @@
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 {IDataCompressorV3_00, PriceOnDemand} from "../interfaces/IDataCompressorV3_00.sol";
11
+ import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter} from "../data/Types.sol";
12
+
13
+ import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
14
+
15
+ import "forge-std/console.sol";
16
+
17
+ address constant ap = 0x0Bf1626d4925F8A872801968be11c052862AC2D3;
18
+
19
+ contract DCTest {
20
+ DataCompressorV2_10 public dc2;
21
+ DataCompressorV3_00 public dc3;
22
+
23
+ uint256 chainId;
24
+
25
+ constructor() {
26
+ NetworkDetector nd = new NetworkDetector();
27
+ chainId = nd.chainId();
28
+ }
29
+
30
+ modifier liveTestOnly() {
31
+ if (chainId == 1) {
32
+ _;
33
+ }
34
+ }
35
+
36
+ function setUp() public liveTestOnly {
37
+ dc2 = new DataCompressorV2_10(ap);
38
+ dc3 = new DataCompressorV3_00(ap);
39
+ }
40
+
41
+ function _printPools(PoolData[] memory pools) internal view {
42
+ uint256 len = pools.length;
43
+ unchecked {
44
+ for (uint256 i; i < len; ++i) {
45
+ PoolData memory pool = pools[i];
46
+ console.log("\n\n");
47
+ console.log(IERC20Metadata(pool.underlying).symbol(), pool.addr);
48
+ console.log("-------------------------------");
49
+
50
+ console.log("dieselToken: ", pool.dieselToken);
51
+ ///
52
+ console.log("linearCumulativeIndex: ", pool.linearCumulativeIndex);
53
+ console.log("availableLiquidity: ", pool.availableLiquidity);
54
+ console.log("expectedLiquidity: ", pool.expectedLiquidity);
55
+ //
56
+ console.log("totalBorrowed: ", pool.totalBorrowed);
57
+ console.log("totalDebtLimit: ", pool.totalDebtLimit);
58
+ // CreditManagerDebtParams[] creditManagerDebtParams;
59
+ console.log("totalAssets: ", pool.totalAssets);
60
+ console.log("totalSupply: ", pool.totalSupply);
61
+ console.log("supplyRate", pool.supplyRate);
62
+ console.log("baseInterestRate: ", pool.baseInterestRate);
63
+ console.log("dieselRate_RAY: ", pool.dieselRate_RAY);
64
+ console.log("withdrawFee", pool.withdrawFee);
65
+ console.log("cumulativeIndex_RAY:", pool.cumulativeIndex_RAY);
66
+ console.log("baseInterestIndexLU:", pool.baseInterestIndexLU);
67
+ console.log("version: ", pool.version);
68
+ // QuotaInfo[] quotas;
69
+ // LinearModel lirm;
70
+ console.log("isPaused", pool.isPaused);
71
+ }
72
+ }
73
+ }
74
+
75
+ function _printCreditManagers(CreditManagerData[] memory cms) internal view {
76
+ uint256 len = cms.length;
77
+ unchecked {
78
+ for (uint256 i; i < len; ++i) {
79
+ CreditManagerData memory cm = cms[i];
80
+ console.log("\n\n");
81
+ console.log(IERC20Metadata(cm.underlying).symbol(), cm.addr);
82
+ console.log("-------------------------------");
83
+ console.log("cfVersion: ", cm.cfVersion);
84
+ console.log("creditFacace: ", cm.creditFacade); // V2 only: address of creditFacade
85
+ console.log("creditConfigurator: ", cm.creditConfigurator); // V2 only: address of creditConfigurator
86
+ console.log("pool: ", cm.pool);
87
+ console.log("totalDebt: ", cm.totalDebt);
88
+ console.log("totalDebtLimit: ", cm.totalDebtLimit);
89
+ console.log("baseBorrowRate: ", cm.baseBorrowRate);
90
+ console.log("minDebt: ", cm.minDebt);
91
+ console.log("maxDebt: ", cm.maxDebt);
92
+ console.log("availableToBorrow: ", cm.availableToBorrow);
93
+ // address[] collateralTokens);
94
+ // ContractAdapter[] adapters);
95
+ // uint256[] liquidationThresholds);
96
+ console.log("isDegenMode: ", cm.isDegenMode); // V2 only: true if contract is in Degen mode
97
+ console.log("degenNFT: ", cm.degenNFT); // V2 only: degenNFT, address(0) if not in degen mode
98
+ console.log("forbiddenTokenMask: ", cm.forbiddenTokenMask); // V2 only: mask which forbids some particular tokens
99
+ console.log("maxEnabledTokensLength: ", cm.maxEnabledTokensLength); // V2 only: in V1 as many tokens as the CM can support (256)
100
+ console.log("feeInterest: ", cm.feeInterest); // Interest fee protocol charges: fee = interest accrues * feeInterest
101
+ console.log("feeLiquidation: ", cm.feeLiquidation); // Liquidation fee protocol charges: fee = totalValue * feeLiquidation
102
+ console.log("liquidationDiscount: ", cm.liquidationDiscount); // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
103
+ console.log("feeLiquidationExpired: ", cm.feeLiquidationExpired); // Liquidation fee protocol charges on expired accounts
104
+ console.log("liquidationDiscountExpired: ", cm.liquidationDiscountExpired); // Multiplier for the amount the liquidator has to pay when closing an expired account
105
+ // V3 Fileds
106
+ // QuotaInfo[] quotas);
107
+ // LinearModel lirm);
108
+ console.log("sPaused: ", cm.isPaused);
109
+ }
110
+ }
111
+ }
112
+
113
+ function test_dc_01_pools() public view liveTestOnly {
114
+ PoolData[] memory pools = dc2.getPoolsV1List();
115
+ console.log("V1 pools");
116
+ _printPools(pools);
117
+
118
+ pools = dc3.getPoolsV3List();
119
+ console.log("\nV3 pools");
120
+ _printPools(pools);
121
+ }
122
+
123
+ function test_dc_02_credit_managers() public view liveTestOnly {
124
+ CreditManagerData[] memory cms = dc2.getCreditManagersV2List();
125
+ console.log("V2 credit managers");
126
+ _printCreditManagers(cms);
127
+
128
+ cms = dc3.getCreditManagersV3List();
129
+ console.log("\n\nV3 credit managers");
130
+ _printCreditManagers(cms);
131
+ }
132
+
133
+ function test_dc_03_credit_accounts() public liveTestOnly {
134
+ CreditAccountData[] memory cas = dc2.getCreditAccountsByBorrower(address(this));
135
+ console.log("V2 credit accounts", cas.length);
136
+
137
+ cas = dc3.getCreditAccountsByBorrower(address(this), new PriceOnDemand[](0));
138
+ console.log("V3 credit accounts", cas.length);
139
+ }
140
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
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>",