@gearbox-protocol/periphery-v3 1.0.9 → 1.2.0

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.
@@ -116,6 +116,7 @@ contract DataCompressorV2_10 is IDataCompressorV2_10, ContractsRegisterTrait, Li
116
116
 
117
117
  address pool = creditManagerV2.pool();
118
118
  result.baseBorrowRate = IPoolService(pool).borrowAPY_RAY();
119
+ result.aggregatedBorrowRate = result.baseBorrowRate;
119
120
 
120
121
  uint256 collateralTokenCount = creditManagerV2.collateralTokensCount();
121
122
 
@@ -4,6 +4,7 @@
4
4
  pragma solidity ^0.8.10;
5
5
  pragma experimental ABIEncoderV2;
6
6
 
7
+ import "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
7
8
  import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
8
9
  import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol";
9
10
 
@@ -38,6 +39,7 @@ import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.
38
39
 
39
40
  import {AddressProvider} from "@gearbox-protocol/core-v2/contracts/core/AddressProvider.sol";
40
41
  import {IDataCompressorV3_00, PriceOnDemand} from "../interfaces/IDataCompressorV3_00.sol";
42
+ import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
41
43
 
42
44
  import {
43
45
  COUNT,
@@ -51,12 +53,14 @@ import {
51
53
  GaugeInfo,
52
54
  GaugeQuotaParams,
53
55
  CreditManagerDebtParams,
54
- GaugeVote
56
+ GaugeVote,
57
+ ZapperInfo
55
58
  } from "./Types.sol";
56
59
 
57
60
  // EXCEPTIONS
58
61
  import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
59
62
  import {LinearInterestModelHelper} from "./LinearInterestModelHelper.sol";
63
+ import {ZapperRegister} from "./ZapperRegister.sol";
60
64
 
61
65
  /// @title Data compressor 3.0.
62
66
  /// @notice Collects data from various contracts for use in the dApp
@@ -65,9 +69,14 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
65
69
  // Contract version
66
70
  uint256 public constant version = 3_00;
67
71
 
72
+ ZapperRegister public zapperRegister;
73
+
68
74
  error CreditManagerIsNotV3Exception();
69
75
 
70
- constructor(address _addressProvider) ContractsRegisterTrait(_addressProvider) {}
76
+ constructor(address _addressProvider) ContractsRegisterTrait(_addressProvider) {
77
+ zapperRegister =
78
+ ZapperRegister(IAddressProviderV3(_addressProvider).getAddressOrRevert("ZAPPER_REGISTER", 3_00));
79
+ }
71
80
 
72
81
  /// @dev Returns CreditAccountData for all opened accounts for particular borrower
73
82
  /// @param borrower Borrower address
@@ -194,6 +203,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
194
203
  result.enabledTokensMask = creditManager.enabledTokensMaskOf(_creditAccount);
195
204
 
196
205
  result.balances = new TokenBalance[](collateralTokenCount);
206
+
207
+ uint256 quotaRevenue = 0;
197
208
  {
198
209
  uint256 forbiddenTokenMask = creditFacade.forbiddenTokenMask();
199
210
  uint256 quotedTokensMask = creditManager.quotedTokensMask();
@@ -215,6 +226,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
215
226
  if (balance.isQuoted) {
216
227
  (balance.quota,) = pqk.getQuota(_creditAccount, balance.token);
217
228
  balance.quotaRate = pqk.getQuotaRate(balance.token);
229
+
230
+ quotaRevenue += balance.quota * balance.quotaRate;
218
231
  }
219
232
 
220
233
  result.balances[i] = balance;
@@ -222,6 +235,8 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
222
235
  }
223
236
  }
224
237
 
238
+ result.aggregatedBorrowRate = result.baseBorrowRate + RAY * quotaRevenue / PERCENTAGE_FACTOR / result.debt;
239
+
225
240
  // uint256 debt;
226
241
  // uint256 cumulativeIndexNow;
227
242
  // uint256 cumulativeIndexLastUpdate;
@@ -435,12 +450,26 @@ contract DataCompressorV3_00 is IDataCompressorV3_00, ContractsRegisterTrait, Li
435
450
 
436
451
  result.supplyRate = pool.supplyRate();
437
452
 
438
- result.version = uint8(pool.version());
453
+ result.version = pool.version();
439
454
 
440
455
  result.quotas = _getQuotas(_pool);
441
456
  result.lirm = getLIRMData(pool.interestRateModel());
442
457
  result.isPaused = pool.paused();
443
458
 
459
+ address[] memory zappers = zapperRegister.zappers(address(pool));
460
+ len = zappers.length;
461
+ result.zappers = new ZapperInfo[](len);
462
+
463
+ unchecked {
464
+ for (uint256 i; i < len; ++i) {
465
+ address tokenFrom = IZapper(zappers[i]).unwrappedToken();
466
+ result.zappers[i] = ZapperInfo({tokenFrom: tokenFrom, zapper: zappers[i]});
467
+ }
468
+ }
469
+
470
+ result.poolQuotaKeeper = pool.poolQuotaKeeper();
471
+ result.gauge = IPoolQuotaKeeperV3(result.poolQuotaKeeper).gauge();
472
+
444
473
  return result;
445
474
  }
446
475
 
@@ -32,6 +32,11 @@ struct ContractAdapter {
32
32
  address adapter;
33
33
  }
34
34
 
35
+ struct ZapperInfo {
36
+ address tokenFrom;
37
+ address zapper;
38
+ }
39
+
35
40
  struct CreditAccountData {
36
41
  // if not successful, priceFeedsNeeded are filled with the data
37
42
  bool isSuccessful;
@@ -137,7 +142,10 @@ struct PoolData {
137
142
  uint256 cumulativeIndex_RAY;
138
143
  uint256 baseInterestIndexLU;
139
144
  uint256 version;
145
+ address poolQuotaKeeper;
146
+ address gauge;
140
147
  QuotaInfo[] quotas;
148
+ ZapperInfo[] zappers;
141
149
  LinearModel lirm;
142
150
  bool isPaused;
143
151
  }
@@ -0,0 +1,44 @@
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.10;
5
+
6
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
7
+ import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
8
+ import {IZapperRegistry} from "../interfaces/IZapperRegistry.sol";
9
+ import {ACLNonReentrantTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLNonReentrantTrait.sol";
10
+ import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
11
+
12
+ contract ZapperRegister is ACLNonReentrantTrait, ContractsRegisterTrait, IZapperRegistry {
13
+ using EnumerableSet for EnumerableSet.AddressSet;
14
+
15
+ mapping(address => EnumerableSet.AddressSet) internal _zappersMap;
16
+
17
+ constructor(address addressProvider)
18
+ ACLNonReentrantTrait(addressProvider)
19
+ ContractsRegisterTrait(addressProvider)
20
+ {}
21
+
22
+ function addZapper(address zapper) external nonZeroAddress(zapper) controllerOnly {
23
+ address pool = IZapper(zapper).pool();
24
+ _ensureRegisteredPool(pool);
25
+
26
+ EnumerableSet.AddressSet storage zapperSet = _zappersMap[pool];
27
+ if (!zapperSet.contains(zapper)) {
28
+ zapperSet.add(zapper);
29
+ emit AddZapper(zapper);
30
+ }
31
+ }
32
+
33
+ function removeZapper(address zapper) external nonZeroAddress(zapper) controllerOnly {
34
+ EnumerableSet.AddressSet storage zapperSet = _zappersMap[IZapper(zapper).pool()];
35
+ if (zapperSet.contains(zapper)) {
36
+ zapperSet.remove(zapper);
37
+ emit RemoveZapper(zapper);
38
+ }
39
+ }
40
+
41
+ function zappers(address pool) external view override returns (address[] memory) {
42
+ return _zappersMap[pool].values();
43
+ }
44
+ }
@@ -0,0 +1,11 @@
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.10;
5
+
6
+ interface IZapperRegistry {
7
+ event AddZapper(address);
8
+ event RemoveZapper(address);
9
+
10
+ function zappers(address pool) external view returns (address[] memory);
11
+ }
@@ -9,6 +9,8 @@ import {DataCompressorV2_10} from "../data/DataCompressor_2_1.sol";
9
9
  import {DataCompressorV3_00} from "../data/DataCompressor_3_0.sol";
10
10
  import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter} from "../data/Types.sol";
11
11
 
12
+ import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
13
+
12
14
  import "forge-std/console.sol";
13
15
 
14
16
  address constant ap = 0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4;
@@ -17,7 +19,20 @@ contract DCTest {
17
19
  DataCompressorV2_10 public dc2;
18
20
  DataCompressorV3_00 public dc3;
19
21
 
20
- function setUp() public {
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 {
21
36
  dc2 = new DataCompressorV2_10(ap);
22
37
  dc3 = new DataCompressorV3_00(ap);
23
38
  }
@@ -94,7 +109,7 @@ contract DCTest {
94
109
  }
95
110
  }
96
111
 
97
- function test_dc_01_pools() public view {
112
+ function test_dc_01_pools() public view liveTestOnly {
98
113
  PoolData[] memory pools = dc2.getPoolsV1List();
99
114
  console.log("V1 pools");
100
115
  _printPools(pools);
@@ -104,7 +119,7 @@ contract DCTest {
104
119
  _printPools(pools);
105
120
  }
106
121
 
107
- function test_dc_02_credit_managers() public view {
122
+ function test_dc_02_credit_managers() public view liveTestOnly {
108
123
  CreditManagerData[] memory cms = dc2.getCreditManagersV2List();
109
124
  console.log("V2 credit managers");
110
125
  _printCreditManagers(cms);
@@ -114,7 +129,7 @@ contract DCTest {
114
129
  _printCreditManagers(cms);
115
130
  }
116
131
 
117
- function test_dc_03_credit_accounts() public view {
132
+ function test_dc_03_credit_accounts() public view liveTestOnly {
118
133
  CreditAccountData[] memory cas = dc2.getCreditAccountsByBorrower(address(this));
119
134
  console.log("V2 credit accounts", cas.length);
120
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/periphery-v3",
3
- "version": "1.0.9",
3
+ "version": "1.2.0",
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>",
@@ -21,7 +21,10 @@
21
21
  "@gearbox-protocol/core-v3": "^1.39.0",
22
22
  "@gearbox-protocol/oracles-v3": "^1.7.2",
23
23
  "@gearbox-protocol/sdk-gov": "^1.5.10",
24
- "@openzeppelin/contracts": "4.8.3",
24
+ "@gearbox-protocol/integrations-v3": "^1.16.0",
25
+ "@openzeppelin/contracts": "4.8.3"
26
+ },
27
+ "dependencies": {
25
28
  "husky": "^8.0.3",
26
29
  "lint-staged": "^13.0.3",
27
30
  "prettier": "^3.0.3"