@gearbox-protocol/periphery-v3 1.7.0-next.16 → 1.7.0-next.18
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/contracts/compressors/AdapterCompressor.sol +7 -7
- package/contracts/compressors/CreditAccountCompressor.sol +2 -1
- package/contracts/compressors/MarketCompressorV3.sol +68 -0
- package/contracts/compressors/PoolCompressor.sol +76 -2
- package/contracts/compressors/PriceFeedCompressor.sol +16 -2
- package/contracts/data/DataCompressorV3.sol +2 -1
- package/contracts/data/ZapperRegister.sol +9 -7
- package/contracts/emergency/MultiPause.sol +19 -11
- package/contracts/interfaces/IVersion.sol +13 -0
- package/contracts/serializers/oracles/LPPriceFeedSerializer.sol +2 -2
- package/contracts/test/ForkTest.sol +3 -3
- package/contracts/test/MultiPause.t.sol +9 -15
- package/contracts/test/interfaces/IACLExt.sol +1 -1
- package/contracts/test/interfaces/IContractsRegisterExt.sol +1 -1
- package/contracts/types/CreditManagerState.sol +5 -6
- package/contracts/types/PoolState.sol +1 -1
- package/contracts/types/PriceOracleState.sol +2 -2
- package/package.json +3 -7
- package/contracts/market/MarketCompressor.sol +0 -451
|
@@ -31,13 +31,13 @@ contract AdaptgerCompressorV3 {
|
|
|
31
31
|
|
|
32
32
|
/// add try{} catch for serialisation
|
|
33
33
|
|
|
34
|
-
adapters[i] = ContractAdapter({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
34
|
+
// adapters[i] = ContractAdapter({
|
|
35
|
+
// targetContract: ICreditManagerV3(creditManager).adapterToContract(allowedAdapter),
|
|
36
|
+
// adapter: allowedAdapter,
|
|
37
|
+
// adapterType: uint8(IAdapter(allowedAdapter)._gearboxAdapterType()),
|
|
38
|
+
// version: IAdapter(allowedAdapter)._gearboxAdapterVersion(),
|
|
39
|
+
// stateSerialised: stateSerialised
|
|
40
|
+
// });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
@@ -6,7 +6,7 @@ pragma solidity ^0.8.17;
|
|
|
6
6
|
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
7
|
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
|
|
8
8
|
|
|
9
|
-
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/IContractsRegister.sol";
|
|
9
|
+
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
|
|
10
10
|
import {ICreditAccountV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditAccountV3.sol";
|
|
11
11
|
import {
|
|
12
12
|
CollateralCalcTask,
|
|
@@ -30,6 +30,7 @@ import {CreditAccountData, CreditAccountFilter, CreditManagerFilter, TokenInfo}
|
|
|
30
30
|
contract CreditAccountCompressor is IVersion, SanityCheckTrait {
|
|
31
31
|
/// @notice Contract version
|
|
32
32
|
uint256 public constant override version = 3_10;
|
|
33
|
+
bytes32 public constant override contractType = "CREDIT_ACCOUNT_COMPRESSOR";
|
|
33
34
|
|
|
34
35
|
/// @notice Address provider contract address
|
|
35
36
|
address public immutable ADDRESS_PROVIDER;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
+
// (c) Gearbox Holdings, 2024
|
|
4
|
+
pragma solidity ^0.8.17;
|
|
5
|
+
|
|
6
|
+
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
7
|
+
import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
|
|
8
|
+
|
|
9
|
+
import {PoolCompressorV3} from "./PoolCompressor.sol";
|
|
10
|
+
import {PriceFeedCompressor} from "./PriceFeedCompressor.sol";
|
|
11
|
+
|
|
12
|
+
// // EXCEPTIONS
|
|
13
|
+
// import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
|
|
14
|
+
|
|
15
|
+
import {MarketData} from "../types/MarketData.sol";
|
|
16
|
+
import {PoolState} from "../types/PoolState.sol";
|
|
17
|
+
|
|
18
|
+
import "forge-std/console.sol";
|
|
19
|
+
|
|
20
|
+
// struct PriceOnDemand {
|
|
21
|
+
// address priceFeed;
|
|
22
|
+
// bytes callData;
|
|
23
|
+
// }
|
|
24
|
+
|
|
25
|
+
/// @title Data compressor 3.0.
|
|
26
|
+
/// @notice Collects data from various contracts for use in the dApp
|
|
27
|
+
/// Do not use for data from data compressor for state-changing functions
|
|
28
|
+
contract MarketCompressorV3 {
|
|
29
|
+
// Contract version
|
|
30
|
+
uint256 public constant version = 3_10;
|
|
31
|
+
|
|
32
|
+
PriceFeedCompressor priceOracleCompressor;
|
|
33
|
+
PoolCompressorV3 poolCompressor;
|
|
34
|
+
|
|
35
|
+
error CreditManagerIsNotV3Exception();
|
|
36
|
+
|
|
37
|
+
constructor(address priceOracleCompressorAddress) {
|
|
38
|
+
poolCompressor = new PoolCompressorV3();
|
|
39
|
+
priceOracleCompressor = PriceFeedCompressor(priceOracleCompressorAddress);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getMarketData(address pool) public view returns (MarketData memory result) {
|
|
43
|
+
result.pool = poolCompressor.getPoolState(pool);
|
|
44
|
+
result.poolQuotaKeeper = poolCompressor.getPoolQuotaKeeperState(result.pool.poolQuotaKeeper);
|
|
45
|
+
result.rateKeeper = poolCompressor.getRateKeeperState(result.poolQuotaKeeper.rateKeeper);
|
|
46
|
+
result.interestRateModel = poolCompressor.getInterestRateModelState(result.pool.interestRateModel);
|
|
47
|
+
|
|
48
|
+
address priceOracle = _getPriceOracle(result.pool);
|
|
49
|
+
address[] memory tokens = IPoolQuotaKeeperV3(result.pool.poolQuotaKeeper).quotedTokens();
|
|
50
|
+
|
|
51
|
+
result.tokens = new address[](tokens.length + 1);
|
|
52
|
+
result.tokens[0] = result.pool.underlying;
|
|
53
|
+
|
|
54
|
+
for (uint256 i = 0; i < tokens.length; i++) {
|
|
55
|
+
result.tokens[i + 1] = tokens[i];
|
|
56
|
+
}
|
|
57
|
+
// How to query if no credit mangers are deployed?
|
|
58
|
+
result.priceOracleData = priceOracleCompressor.getPriceOracleState(priceOracle, result.tokens);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _getPriceOracle(PoolState memory ps) internal view returns (address) {
|
|
62
|
+
if (ps.creditManagerDebtParams.length == 0) {
|
|
63
|
+
return address(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return ICreditManagerV3(ps.creditManagerDebtParams[0].creditManager).priceOracle();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -7,16 +7,25 @@ pragma experimental ABIEncoderV2;
|
|
|
7
7
|
import {PoolV3} from "@gearbox-protocol/core-v3/contracts/pool/PoolV3.sol";
|
|
8
8
|
import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
|
|
9
9
|
import {IGaugeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IGaugeV3.sol";
|
|
10
|
+
import {IVersion} from "../interfaces/IVersion.sol";
|
|
11
|
+
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
12
|
+
import {ICreditConfiguratorV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditConfiguratorV3.sol";
|
|
13
|
+
import {ICreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol";
|
|
10
14
|
|
|
11
15
|
import {PoolState, CreditManagerDebtParams} from "../types/PoolState.sol";
|
|
12
16
|
import {PoolQuotaKeeperState, QuotaTokenParams} from "../types/PoolQuotaKeeperState.sol";
|
|
13
17
|
import {RateKeeperState, Rate} from "../types/RateKeeperState.sol";
|
|
18
|
+
import {InterestRateModelState} from "../types/InterestRateModelState.sol";
|
|
19
|
+
import {CreditManagerState} from "../types/CreditManagerState.sol";
|
|
20
|
+
|
|
14
21
|
import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v3/contracts/libraries/Constants.sol";
|
|
15
22
|
import {IRateKeeper} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IRateKeeper.sol";
|
|
16
23
|
|
|
17
24
|
import {RateKeeperType} from "../types/Enums.sol";
|
|
25
|
+
|
|
18
26
|
// Serializers
|
|
19
27
|
import {GaugeSerializer} from "../serializers/pool/GaugeSerializer.sol";
|
|
28
|
+
import {LinearInterestModelSerializer} from "../serializers/pool/LinearInterestModelSerializer.sol";
|
|
20
29
|
|
|
21
30
|
/// @title Pool compressor
|
|
22
31
|
/// @notice Collects data from pool related contracts
|
|
@@ -26,9 +35,11 @@ contract PoolCompressorV3 {
|
|
|
26
35
|
uint256 public constant version = 3_10;
|
|
27
36
|
|
|
28
37
|
address public immutable gaugeSerializer;
|
|
38
|
+
address public immutable linearInterestModelSerializer;
|
|
29
39
|
|
|
30
40
|
constructor() {
|
|
31
41
|
gaugeSerializer = address(new GaugeSerializer());
|
|
42
|
+
linearInterestModelSerializer = address(new LinearInterestModelSerializer());
|
|
32
43
|
}
|
|
33
44
|
|
|
34
45
|
function getPoolState(address pool) public view returns (PoolState memory result) {
|
|
@@ -73,8 +84,8 @@ contract PoolCompressorV3 {
|
|
|
73
84
|
result.baseInterestIndex = _pool.baseInterestIndex();
|
|
74
85
|
// uint256 baseInterestRate;
|
|
75
86
|
result.baseInterestRate = _pool.baseInterestRate();
|
|
76
|
-
// uint256
|
|
77
|
-
result.
|
|
87
|
+
// uint256 dieselRate;
|
|
88
|
+
result.dieselRate = _pool.convertToAssets(RAY);
|
|
78
89
|
// uint256 totalBorrowed;
|
|
79
90
|
result.totalBorrowed = _pool.totalBorrowed();
|
|
80
91
|
// uint256 totalDebtLimit;
|
|
@@ -173,4 +184,67 @@ contract PoolCompressorV3 {
|
|
|
173
184
|
result.rates[i].rate = rawRates[i];
|
|
174
185
|
}
|
|
175
186
|
}
|
|
187
|
+
|
|
188
|
+
function getInterestRateModelState(address irm) external view returns (InterestRateModelState memory result) {
|
|
189
|
+
InterestRateModelState memory irmState;
|
|
190
|
+
irmState.addr = irm;
|
|
191
|
+
irmState.version = IVersion(irm).version();
|
|
192
|
+
|
|
193
|
+
try IVersion(irm).contractType() returns (bytes32 contractType) {
|
|
194
|
+
irmState.contractType = contractType;
|
|
195
|
+
} catch {
|
|
196
|
+
irmState.contractType = "IRM_LINEAR";
|
|
197
|
+
}
|
|
198
|
+
// add serialiser
|
|
199
|
+
irmState.serializedParams = LinearInterestModelSerializer(linearInterestModelSerializer).serialize(irm);
|
|
200
|
+
return irmState;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/// @dev Returns CreditManagerData for a particular _cm
|
|
204
|
+
/// @param _cm CreditManager address
|
|
205
|
+
function getCreditManagerData(address _cm) public view returns (CreditManagerState memory result) {
|
|
206
|
+
ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
|
|
207
|
+
ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
|
|
208
|
+
ICreditFacadeV3 creditFacade = ICreditFacadeV3(creditManager.creditFacade());
|
|
209
|
+
|
|
210
|
+
result.addr = _cm;
|
|
211
|
+
result.name = ICreditManagerV3(_cm).name();
|
|
212
|
+
result.cfVersion = IVersion(address(creditFacade)).version();
|
|
213
|
+
|
|
214
|
+
result.creditFacade = address(creditFacade);
|
|
215
|
+
result.creditConfigurator = address(creditConfigurator);
|
|
216
|
+
|
|
217
|
+
result.underlying = creditManager.underlying();
|
|
218
|
+
|
|
219
|
+
(result.minDebt, result.maxDebt) = creditFacade.debtLimits();
|
|
220
|
+
|
|
221
|
+
{
|
|
222
|
+
uint256 collateralTokenCount = creditManager.collateralTokensCount();
|
|
223
|
+
|
|
224
|
+
result.collateralTokens = new address[](collateralTokenCount);
|
|
225
|
+
result.liquidationThresholds = new uint256[](collateralTokenCount);
|
|
226
|
+
|
|
227
|
+
unchecked {
|
|
228
|
+
for (uint256 i = 0; i < collateralTokenCount; ++i) {
|
|
229
|
+
(result.collateralTokens[i], result.liquidationThresholds[i]) =
|
|
230
|
+
creditManager.collateralTokenByMask(1 << i);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
result.degenNFT = creditFacade.degenNFT();
|
|
236
|
+
|
|
237
|
+
// (, result.isIncreaseDebtForbidden,,) = creditFacade.params(); // V2 only: true if increasing debt is forbidden
|
|
238
|
+
result.forbiddenTokenMask = creditFacade.forbiddenTokenMask(); // V2 only: mask which forbids some particular tokens
|
|
239
|
+
result.maxEnabledTokensLength = creditManager.maxEnabledTokens(); // V2 only: a limit on enabled tokens imposed for security
|
|
240
|
+
{
|
|
241
|
+
(
|
|
242
|
+
result.feeInterest,
|
|
243
|
+
result.feeLiquidation,
|
|
244
|
+
result.liquidationDiscount,
|
|
245
|
+
result.feeLiquidationExpired,
|
|
246
|
+
result.liquidationDiscountExpired
|
|
247
|
+
) = creditManager.fees();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
176
250
|
}
|
|
@@ -8,6 +8,7 @@ import {IPriceOracleV3, PriceFeedParams} from "@gearbox-protocol/core-v3/contrac
|
|
|
8
8
|
import {IPriceFeed, IUpdatablePriceFeed} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeed.sol";
|
|
9
9
|
import {IPriceFeedCompressor} from "../interfaces/IPriceFeedCompressor.sol";
|
|
10
10
|
import {PriceFeedType} from "@gearbox-protocol/sdk-gov/contracts/PriceFeedType.sol";
|
|
11
|
+
import {IVersion} from "../interfaces/IVersion.sol";
|
|
11
12
|
|
|
12
13
|
import {IStateSerializerLegacy} from "../interfaces/IStateSerializerLegacy.sol";
|
|
13
14
|
import {IStateSerializer} from "../interfaces/IStateSerializer.sol";
|
|
@@ -17,7 +18,7 @@ import {BPTWeightedPriceFeedSerializer} from "../serializers/oracles/BPTWeighted
|
|
|
17
18
|
import {LPPriceFeedSerializer} from "../serializers/oracles/LPPriceFeedSerializer.sol";
|
|
18
19
|
import {PythPriceFeedSerializer} from "../serializers/oracles/PythPriceFeedSerializer.sol";
|
|
19
20
|
import {RedstonePriceFeedSerializer} from "../serializers/oracles/RedstonePriceFeedSerializer.sol";
|
|
20
|
-
import {PriceFeedAnswer, PriceFeedMapEntry, PriceFeedTreeNode} from "../types/PriceOracleState.sol";
|
|
21
|
+
import {PriceFeedAnswer, PriceFeedMapEntry, PriceFeedTreeNode, PriceOracleState} from "../types/PriceOracleState.sol";
|
|
21
22
|
|
|
22
23
|
interface ImplementsPriceFeedType {
|
|
23
24
|
/// @dev Annotates `priceFeedType` as `uint8` instead of `PriceFeedType` enum to support future types
|
|
@@ -40,6 +41,7 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
40
41
|
|
|
41
42
|
/// @notice Contract version
|
|
42
43
|
uint256 public constant override version = 3_10;
|
|
44
|
+
bytes32 public constant override contractType = "PRICE_FEED_COMPRESSOR";
|
|
43
45
|
|
|
44
46
|
/// @notice Map of state serializers for different price feed types
|
|
45
47
|
/// @dev Serializers only apply to feeds that don't implement `IStateSerializer` themselves
|
|
@@ -78,7 +80,7 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
78
80
|
/// from `priceFeedMap` and their underlying feeds, in case former are nested, which can help to determine
|
|
79
81
|
/// what underlying feeds should be updated to query the nested one.
|
|
80
82
|
function getPriceFeeds(address priceOracle)
|
|
81
|
-
|
|
83
|
+
public
|
|
82
84
|
view
|
|
83
85
|
override
|
|
84
86
|
returns (PriceFeedMapEntry[] memory priceFeedMap, PriceFeedTreeNode[] memory priceFeedTree)
|
|
@@ -87,6 +89,18 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
87
89
|
return getPriceFeeds(priceOracle, tokens);
|
|
88
90
|
}
|
|
89
91
|
|
|
92
|
+
function getPriceOracleState(address priceOracle, address[] memory tokens)
|
|
93
|
+
external
|
|
94
|
+
view
|
|
95
|
+
returns (PriceOracleState memory result)
|
|
96
|
+
{
|
|
97
|
+
result.addr = priceOracle;
|
|
98
|
+
result.version = IPriceOracleV3(priceOracle).version();
|
|
99
|
+
result.contractType = IVersion(priceOracle).contractType();
|
|
100
|
+
|
|
101
|
+
(result.priceFeedMapping, result.priceFeedStructure) = getPriceFeeds(priceOracle, tokens);
|
|
102
|
+
}
|
|
103
|
+
|
|
90
104
|
/// @dev Same as the above but takes the list of tokens as argument as legacy oracle doesn't implement `getTokens`
|
|
91
105
|
function getPriceFeeds(address priceOracle, address[] memory tokens)
|
|
92
106
|
public
|
|
@@ -10,7 +10,7 @@ import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
|
|
|
10
10
|
import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v3/contracts/libraries/Constants.sol";
|
|
11
11
|
|
|
12
12
|
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
13
|
-
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/IContractsRegister.sol";
|
|
13
|
+
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
|
|
14
14
|
import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol";
|
|
15
15
|
|
|
16
16
|
import {
|
|
@@ -64,6 +64,7 @@ import {IZapperRegister} from "../interfaces/IZapperRegister.sol";
|
|
|
64
64
|
contract DataCompressorV3 is IDataCompressorV3, ContractsRegisterTrait {
|
|
65
65
|
// Contract version
|
|
66
66
|
uint256 public constant version = 3_00;
|
|
67
|
+
bytes32 public constant contractType = "DATA_COMPRESSOR";
|
|
67
68
|
|
|
68
69
|
IZapperRegister public zapperRegister;
|
|
69
70
|
|
|
@@ -6,10 +6,12 @@ pragma solidity ^0.8.10;
|
|
|
6
6
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
|
7
7
|
import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
|
|
8
8
|
import {IZapperRegister} from "../interfaces/IZapperRegister.sol";
|
|
9
|
-
import {
|
|
9
|
+
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
|
|
10
10
|
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
11
|
+
import {SanityCheckTrait} from "@gearbox-protocol/core-v3/contracts/traits/SanityCheckTrait.sol";
|
|
12
|
+
import {ControlledTrait} from "@gearbox-protocol/core-v3/contracts/traits/ControlledTrait.sol";
|
|
11
13
|
|
|
12
|
-
contract ZapperRegister is
|
|
14
|
+
contract ZapperRegister is ContractsRegisterTrait, SanityCheckTrait, ControlledTrait, IZapperRegister {
|
|
13
15
|
using EnumerableSet for EnumerableSet.AddressSet;
|
|
14
16
|
|
|
15
17
|
// Contract version
|
|
@@ -17,12 +19,12 @@ contract ZapperRegister is ACLNonReentrantTrait, ContractsRegisterTrait, IZapper
|
|
|
17
19
|
|
|
18
20
|
mapping(address => EnumerableSet.AddressSet) internal _zappersMap;
|
|
19
21
|
|
|
20
|
-
constructor(address
|
|
21
|
-
|
|
22
|
-
ContractsRegisterTrait(
|
|
22
|
+
constructor(address acl, address contractsRegister)
|
|
23
|
+
ControlledTrait(acl)
|
|
24
|
+
ContractsRegisterTrait(contractsRegister)
|
|
23
25
|
{}
|
|
24
26
|
|
|
25
|
-
function addZapper(address zapper) external nonZeroAddress(zapper)
|
|
27
|
+
function addZapper(address zapper) external nonZeroAddress(zapper) controllerOrConfiguratorOnly {
|
|
26
28
|
address pool = IZapper(zapper).pool();
|
|
27
29
|
_ensureRegisteredPool(pool);
|
|
28
30
|
|
|
@@ -33,7 +35,7 @@ contract ZapperRegister is ACLNonReentrantTrait, ContractsRegisterTrait, IZapper
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
function removeZapper(address zapper) external nonZeroAddress(zapper)
|
|
38
|
+
function removeZapper(address zapper) external nonZeroAddress(zapper) controllerOrConfiguratorOnly {
|
|
37
39
|
EnumerableSet.AddressSet storage zapperSet = _zappersMap[IZapper(zapper).pool()];
|
|
38
40
|
if (zapperSet.contains(zapper)) {
|
|
39
41
|
zapperSet.remove(zapper);
|
|
@@ -4,24 +4,32 @@
|
|
|
4
4
|
pragma solidity ^0.8.17;
|
|
5
5
|
|
|
6
6
|
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
7
|
-
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/IContractsRegister.sol";
|
|
8
|
-
import {
|
|
7
|
+
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
|
|
8
|
+
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
|
|
9
9
|
import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
10
|
+
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
|
|
10
11
|
|
|
11
12
|
enum PausableAction {
|
|
12
13
|
Pause,
|
|
13
14
|
Unpause
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
interface PausableContract {
|
|
18
|
+
/// @notice Pauses contract, can only be called by an account with pausable admin role
|
|
19
|
+
/// @dev Reverts if contract is already paused
|
|
20
|
+
function pause() external;
|
|
21
|
+
|
|
22
|
+
/// @notice Unpauses contract, can only be called by an account with unpausable admin role
|
|
23
|
+
/// @dev Reverts if contract is already unpaused
|
|
24
|
+
function unpause() external;
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
/// @title MultiPause
|
|
17
28
|
/// @author Gearbox Foundation
|
|
18
29
|
/// @notice Allows pausable admins to pause multiple contracts in a single transaction
|
|
19
30
|
/// @dev This contract is expected to be one of pausable admins in the ACL contract
|
|
20
|
-
contract MultiPause is
|
|
21
|
-
constructor(address acl_, address contractsRegister_)
|
|
22
|
-
ACLNonReentrantTrait(acl_)
|
|
23
|
-
ContractsRegisterTrait(contractsRegister_)
|
|
24
|
-
{}
|
|
31
|
+
contract MultiPause is ACLTrait, ContractsRegisterTrait {
|
|
32
|
+
constructor(address acl_, address contractsRegister_) ACLTrait(acl_) ContractsRegisterTrait(contractsRegister_) {}
|
|
25
33
|
|
|
26
34
|
/// @notice Pauses contracts from the given list
|
|
27
35
|
/// @dev Ignores contracts that are already paused
|
|
@@ -85,11 +93,11 @@ contract MultiPause is ACLNonReentrantTrait, ContractsRegisterTrait {
|
|
|
85
93
|
unchecked {
|
|
86
94
|
for (uint256 i; i < len; ++i) {
|
|
87
95
|
if (action == PausableAction.Pause) {
|
|
88
|
-
if (
|
|
89
|
-
|
|
96
|
+
if (Pausable(contracts[i]).paused()) continue;
|
|
97
|
+
PausableContract(contracts[i]).pause();
|
|
90
98
|
} else {
|
|
91
|
-
if (!
|
|
92
|
-
|
|
99
|
+
if (!Pausable(contracts[i]).paused()) continue;
|
|
100
|
+
PausableContract(contracts[i]).unpause();
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
+
// (c) Gearbox Foundation, 2024.
|
|
4
|
+
pragma solidity ^0.8.17;
|
|
5
|
+
|
|
6
|
+
/// @title Version interface
|
|
7
|
+
/// @notice Defines contract version
|
|
8
|
+
interface IVersion {
|
|
9
|
+
/// @notice Contract version
|
|
10
|
+
function version() external view returns (uint256);
|
|
11
|
+
|
|
12
|
+
function contractType() external view returns (bytes32);
|
|
13
|
+
}
|
|
@@ -23,8 +23,8 @@ contract LPPriceFeedSerializer is IStateSerializerLegacy {
|
|
|
23
23
|
pf.lpContract(),
|
|
24
24
|
pf.lowerBound(),
|
|
25
25
|
pf.upperBound(),
|
|
26
|
-
pf.updateBoundsAllowed(),
|
|
27
|
-
pf.lastBoundsUpdate(),
|
|
26
|
+
// pf.updateBoundsAllowed(),
|
|
27
|
+
// pf.lastBoundsUpdate(),
|
|
28
28
|
_getPriceData(pf)
|
|
29
29
|
);
|
|
30
30
|
}
|
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
NO_VERSION_CONTROL
|
|
13
13
|
} from "@gearbox-protocol/core-v3/contracts/test/interfaces/IAddressProviderV3.sol";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {ACL} from "@gearbox-protocol/governance/contracts/market/ACL.sol";
|
|
16
16
|
import {IContractsRegisterExt} from "./interfaces/IContractsRegisterExt.sol";
|
|
17
17
|
|
|
18
18
|
abstract contract ForkTest is Test {
|
|
19
19
|
IAddressProviderV3 addressProvider;
|
|
20
|
-
|
|
20
|
+
ACL acl;
|
|
21
21
|
IContractsRegisterExt register;
|
|
22
22
|
address configurator;
|
|
23
23
|
|
|
@@ -37,7 +37,7 @@ abstract contract ForkTest is Test {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
addressProvider = IAddressProviderV3(vm.envAddress("FORK_ADDRESS_PROVIDER"));
|
|
40
|
-
acl =
|
|
40
|
+
acl = ACL(addressProvider.getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL));
|
|
41
41
|
register = IContractsRegisterExt(addressProvider.getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL));
|
|
42
42
|
configurator = acl.owner();
|
|
43
43
|
}
|
|
@@ -5,9 +5,9 @@ pragma solidity ^0.8.17;
|
|
|
5
5
|
|
|
6
6
|
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
7
7
|
import {CallerNotPausableAdminException} from "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import {
|
|
8
|
+
import {ACLTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLTrait.sol";
|
|
9
|
+
import {MultiPause, PausableContract} from "../emergency/MultiPause.sol";
|
|
10
|
+
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
|
|
11
11
|
|
|
12
12
|
import {ForkTest} from "./ForkTest.sol";
|
|
13
13
|
|
|
@@ -45,9 +45,9 @@ contract MultiPauseTest is ForkTest {
|
|
|
45
45
|
address[] memory pools = register.getPools();
|
|
46
46
|
|
|
47
47
|
// ensure that at least one contract is paused
|
|
48
|
-
if (!
|
|
48
|
+
if (!Pausable(pools[0]).paused()) {
|
|
49
49
|
vm.prank(admin);
|
|
50
|
-
|
|
50
|
+
PausableContract(pools[0]).pause();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
vm.prank(admin);
|
|
@@ -78,8 +78,7 @@ contract MultiPauseTest is ForkTest {
|
|
|
78
78
|
function _assert_contractsPaused(address[] memory contracts) internal {
|
|
79
79
|
for (uint256 i; i < contracts.length; ++i) {
|
|
80
80
|
assertTrue(
|
|
81
|
-
|
|
82
|
-
string.concat("Contract ", vm.toString(contracts[i]), " is not paused")
|
|
81
|
+
Pausable(contracts[i]).paused(), string.concat("Contract ", vm.toString(contracts[i]), " is not paused")
|
|
83
82
|
);
|
|
84
83
|
}
|
|
85
84
|
}
|
|
@@ -87,9 +86,7 @@ contract MultiPauseTest is ForkTest {
|
|
|
87
86
|
function _assert_allPoolsPaused() internal {
|
|
88
87
|
address[] memory pools = register.getPools();
|
|
89
88
|
for (uint256 i; i < pools.length; ++i) {
|
|
90
|
-
assertTrue(
|
|
91
|
-
ACLNonReentrantTrait(pools[i]).paused(), string.concat("Pool ", vm.toString(pools[i]), " is not paused")
|
|
92
|
-
);
|
|
89
|
+
assertTrue(Pausable(pools[i]).paused(), string.concat("Pool ", vm.toString(pools[i]), " is not paused"));
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
|
|
@@ -98,15 +95,12 @@ contract MultiPauseTest is ForkTest {
|
|
|
98
95
|
for (uint256 i; i < creditManagers.length; ++i) {
|
|
99
96
|
if (ICreditManagerV3(creditManagers[i]).version() < 3_00) {
|
|
100
97
|
assertTrue(
|
|
101
|
-
|
|
98
|
+
Pausable(creditManagers[i]).paused(),
|
|
102
99
|
string.concat("Manager ", vm.toString(creditManagers[i]), " is not paused")
|
|
103
100
|
);
|
|
104
101
|
} else {
|
|
105
102
|
address facade = ICreditManagerV3(creditManagers[i]).creditFacade();
|
|
106
|
-
assertTrue(
|
|
107
|
-
ACLNonReentrantTrait(facade).paused(),
|
|
108
|
-
string.concat("Facade ", vm.toString(facade), " is not paused")
|
|
109
|
-
);
|
|
103
|
+
assertTrue(Pausable(facade).paused(), string.concat("Facade ", vm.toString(facade), " is not paused"));
|
|
110
104
|
}
|
|
111
105
|
}
|
|
112
106
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (c) Gearbox Foundation, 2024.
|
|
4
4
|
pragma solidity ^0.8.17;
|
|
5
5
|
|
|
6
|
-
import {IACL} from "@gearbox-protocol/core-v3/contracts/interfaces/IACL.sol";
|
|
6
|
+
import {IACL} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IACL.sol";
|
|
7
7
|
|
|
8
8
|
interface IACLExt is IACL {
|
|
9
9
|
function addPausableAdmin(address addr) external;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (c) Gearbox Foundation, 2024.
|
|
4
4
|
pragma solidity ^0.8.17;
|
|
5
5
|
|
|
6
|
-
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/IContractsRegister.sol";
|
|
6
|
+
import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IContractsRegister.sol";
|
|
7
7
|
|
|
8
8
|
interface IContractsRegisterExt is IContractsRegister {
|
|
9
9
|
function addPool(address pool) external;
|
|
@@ -8,20 +8,21 @@ struct CreditManagerState {
|
|
|
8
8
|
uint256 version;
|
|
9
9
|
bytes32 contractType;
|
|
10
10
|
string name;
|
|
11
|
-
address creditFacade;
|
|
12
|
-
|
|
11
|
+
address creditFacade;
|
|
12
|
+
uint256 cfVersion;
|
|
13
|
+
bytes32 cfContractType;
|
|
14
|
+
address creditConfigurator;
|
|
13
15
|
address underlying;
|
|
14
16
|
address pool;
|
|
15
17
|
uint256 totalDebt;
|
|
16
18
|
uint256 totalDebtLimit;
|
|
17
19
|
uint256 minDebt;
|
|
18
20
|
uint256 maxDebt;
|
|
21
|
+
address degenNFT;
|
|
19
22
|
uint256 availableToBorrow;
|
|
20
23
|
address[] collateralTokens;
|
|
21
24
|
ContractAdapter[] adapters;
|
|
22
25
|
uint256[] liquidationThresholds;
|
|
23
|
-
bool isDegenMode; // V2 only: true if contract is in Degen mode
|
|
24
|
-
address degenNFT; // V2 only: degenNFT, address(0) if not in degen mode
|
|
25
26
|
uint256 forbiddenTokenMask; // V2 only: mask which forbids some particular tokens
|
|
26
27
|
uint8 maxEnabledTokensLength; // V2 only: in V1 as many tokens as the CM can support (256)
|
|
27
28
|
uint16 feeInterest; // Interest fee protocol charges: fee = interest accrues * feeInterest
|
|
@@ -29,8 +30,6 @@ struct CreditManagerState {
|
|
|
29
30
|
uint16 liquidationDiscount; // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount
|
|
30
31
|
uint16 feeLiquidationExpired; // Liquidation fee protocol charges on expired accounts
|
|
31
32
|
uint16 liquidationDiscountExpired; // Multiplier for the amount the liquidator has to pay when closing an expired account
|
|
32
|
-
// V3 Fileds
|
|
33
|
-
bool isPaused;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
struct ContractAdapter {
|
|
@@ -7,8 +7,8 @@ struct PriceOracleState {
|
|
|
7
7
|
address addr;
|
|
8
8
|
uint256 version;
|
|
9
9
|
bytes32 contractType;
|
|
10
|
-
PriceFeedMapEntry priceFeedMapping;
|
|
11
|
-
PriceFeedTreeNode priceFeedStructure;
|
|
10
|
+
PriceFeedMapEntry[] priceFeedMapping;
|
|
11
|
+
PriceFeedTreeNode[] priceFeedStructure;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/// @notice Price feed answer packed in a struct
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/periphery-v3",
|
|
3
|
-
"version": "1.7.0-next.
|
|
3
|
+
"version": "1.7.0-next.18",
|
|
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>",
|
|
@@ -18,13 +18,9 @@
|
|
|
18
18
|
"@chainlink/contracts": "^0.4.0",
|
|
19
19
|
"@commitlint/cli": "^17.6.3",
|
|
20
20
|
"@commitlint/config-conventional": "17.6.0",
|
|
21
|
-
"@gearbox-protocol/
|
|
22
|
-
"@gearbox-protocol/governance": "^1.4.0-next.5",
|
|
23
|
-
"@gearbox-protocol/integrations-v3": "^1.23.1",
|
|
24
|
-
"@gearbox-protocol/oracles-v3": "^1.11.0-next.3",
|
|
25
|
-
"@gearbox-protocol/sdk-gov": "^2.14.1",
|
|
21
|
+
"@gearbox-protocol/sdk-gov": "^2.18.2",
|
|
26
22
|
"@openzeppelin/contracts": "^4.9.3",
|
|
27
|
-
"@redstone-finance/evm-connector": "0.
|
|
23
|
+
"@redstone-finance/evm-connector": "^0.6.1",
|
|
28
24
|
"ds-test": "dapphub/ds-test",
|
|
29
25
|
"forge-std": "foundry-rs/forge-std"
|
|
30
26
|
},
|
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
-
// (c) Gearbox Holdings, 2024
|
|
4
|
-
pragma solidity ^0.8.17;
|
|
5
|
-
|
|
6
|
-
// import {IAddressProviderV3} from "@gearbox-protocol/governance/contracts/interfaces/IAddressProviderV3.sol";
|
|
7
|
-
// import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
8
|
-
// import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
9
|
-
// import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
|
|
10
|
-
// import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v3/contracts/libraries/Constants.sol";
|
|
11
|
-
|
|
12
|
-
// import {ContractsRegisterTrait} from "@gearbox-protocol/core-v3/contracts/traits/ContractsRegisterTrait.sol";
|
|
13
|
-
// import {IContractsRegister} from "@gearbox-protocol/core-v3/contracts/interfaces/IContractsRegister.sol";
|
|
14
|
-
// import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol";
|
|
15
|
-
|
|
16
|
-
// import {
|
|
17
|
-
// ICreditManagerV3,
|
|
18
|
-
// CollateralDebtData,
|
|
19
|
-
// CollateralCalcTask
|
|
20
|
-
// } from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
21
|
-
// import {ICreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditFacadeV3.sol";
|
|
22
|
-
// import {ICreditConfiguratorV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditConfiguratorV3.sol";
|
|
23
|
-
// import {IPriceOracleV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPriceOracleV3.sol";
|
|
24
|
-
// import {ICreditAccountV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditAccountV3.sol";
|
|
25
|
-
// import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol";
|
|
26
|
-
// import {IPoolV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolV3.sol";
|
|
27
|
-
// import {PoolV3} from "@gearbox-protocol/core-v3/contracts/pool/PoolV3.sol";
|
|
28
|
-
|
|
29
|
-
// import {CreditManagerV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditManagerV3.sol";
|
|
30
|
-
|
|
31
|
-
// import {CreditFacadeV3} from "@gearbox-protocol/core-v3/contracts/credit/CreditFacadeV3.sol";
|
|
32
|
-
// import {IBotListV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IBotListV3.sol";
|
|
33
|
-
// import {IGaugeV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IGaugeV3.sol";
|
|
34
|
-
|
|
35
|
-
// import {IPriceFeed, IUpdatablePriceFeed} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IPriceFeed.sol";
|
|
36
|
-
|
|
37
|
-
// import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVersion.sol";
|
|
38
|
-
|
|
39
|
-
// import {IZapper} from "@gearbox-protocol/integrations-v3/contracts/interfaces/zappers/IZapper.sol";
|
|
40
|
-
|
|
41
|
-
// import {
|
|
42
|
-
// CreditManagerData,
|
|
43
|
-
// PoolData,
|
|
44
|
-
// TokenBalance,
|
|
45
|
-
// ContractAdapter,
|
|
46
|
-
// QuotaInfo,
|
|
47
|
-
// GaugeInfo,
|
|
48
|
-
// GaugeQuotaParams,
|
|
49
|
-
// CreditManagerDebtParams,
|
|
50
|
-
// ZapperInfo,
|
|
51
|
-
// LinearModel
|
|
52
|
-
// } from "./Types.sol";
|
|
53
|
-
|
|
54
|
-
// // EXCEPTIONS
|
|
55
|
-
// import "@gearbox-protocol/core-v3/contracts/interfaces/IExceptions.sol";
|
|
56
|
-
|
|
57
|
-
// import {MarketData} from "./Types.sol";
|
|
58
|
-
|
|
59
|
-
// import "forge-std/console.sol";
|
|
60
|
-
|
|
61
|
-
// struct PriceOnDemand {
|
|
62
|
-
// address priceFeed;
|
|
63
|
-
// bytes callData;
|
|
64
|
-
// }
|
|
65
|
-
|
|
66
|
-
// /// @title Data compressor 3.0.
|
|
67
|
-
// /// @notice Collects data from various contracts for use in the dApp
|
|
68
|
-
// /// Do not use for data from data compressor for state-changing functions
|
|
69
|
-
// contract MarketCompressorV3 is ContractsRegisterTrait {
|
|
70
|
-
// // Contract version
|
|
71
|
-
// uint256 public constant version = 3_10;
|
|
72
|
-
|
|
73
|
-
// error CreditManagerIsNotV3Exception();
|
|
74
|
-
|
|
75
|
-
// constructor(address _addressProvider) ContractsRegisterTrait(_addressProvider) {
|
|
76
|
-
// // zapperRegister =
|
|
77
|
-
// // IZapperRegister(IAddressProviderV3(_addressProvider).getAddressOrRevert("ZAPPER_REGISTER", 3_00));
|
|
78
|
-
// }
|
|
79
|
-
|
|
80
|
-
// function getMarketDataByPool(address pool) external returns (MarketData memory marketData) {}
|
|
81
|
-
|
|
82
|
-
// function getMarketDataByRiskCurtator(address riskCurator) external returns (MarketData[] memory marketData) {}
|
|
83
|
-
|
|
84
|
-
// function getMarketDataAll() external returns (MarketData[] memory marketData) {}
|
|
85
|
-
|
|
86
|
-
// /// @dev Returns CreditManagerData for a particular _cm
|
|
87
|
-
// /// @param _cm CreditManager address
|
|
88
|
-
// function getCreditManagerData(address _cm) public view returns (CreditManagerData memory result) {
|
|
89
|
-
// ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
|
|
90
|
-
// ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
|
|
91
|
-
// ICreditFacadeV3 creditFacade = _getCreditFacade(address(creditManager));
|
|
92
|
-
|
|
93
|
-
// result.addr = _cm;
|
|
94
|
-
// result.name = _getName(_cm);
|
|
95
|
-
// result.cfVersion = _getVersion(address(creditFacade));
|
|
96
|
-
|
|
97
|
-
// result.creditFacade = address(creditFacade);
|
|
98
|
-
// result.creditConfigurator = address(creditConfigurator);
|
|
99
|
-
|
|
100
|
-
// result.underlying = _getUnderlying(creditManager);
|
|
101
|
-
|
|
102
|
-
// {
|
|
103
|
-
// result.pool = _getPool(_cm);
|
|
104
|
-
// IPoolV3 pool = IPoolV3(result.pool);
|
|
105
|
-
// result.totalDebt = pool.creditManagerBorrowed(_cm);
|
|
106
|
-
// result.totalDebtLimit = pool.creditManagerDebtLimit(_cm);
|
|
107
|
-
|
|
108
|
-
// result.baseBorrowRate = _getBaseInterestRate(address(pool));
|
|
109
|
-
// result.availableToBorrow = pool.creditManagerBorrowable(_cm);
|
|
110
|
-
// result.lirm = _getInterestRateModel(address(pool));
|
|
111
|
-
// }
|
|
112
|
-
|
|
113
|
-
// (result.minDebt, result.maxDebt) = creditFacade.debtLimits();
|
|
114
|
-
|
|
115
|
-
// {
|
|
116
|
-
// uint256 collateralTokenCount = _getCollateralTokensCount(address(creditManager));
|
|
117
|
-
|
|
118
|
-
// result.collateralTokens = new address[](collateralTokenCount);
|
|
119
|
-
// result.liquidationThresholds = new uint256[](collateralTokenCount);
|
|
120
|
-
|
|
121
|
-
// unchecked {
|
|
122
|
-
// for (uint256 i = 0; i < collateralTokenCount; ++i) {
|
|
123
|
-
// (result.collateralTokens[i], result.liquidationThresholds[i]) =
|
|
124
|
-
// creditManager.collateralTokenByMask(1 << i);
|
|
125
|
-
// }
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
|
-
|
|
129
|
-
// address[] memory allowedAdapters = creditConfigurator.allowedAdapters();
|
|
130
|
-
// uint256 len = allowedAdapters.length;
|
|
131
|
-
// result.adapters = new ContractAdapter[](len);
|
|
132
|
-
|
|
133
|
-
// // unchecked {
|
|
134
|
-
// // for (uint256 i = 0; i < len; ++i) {
|
|
135
|
-
// // address allowedAdapter = allowedAdapters[i];
|
|
136
|
-
|
|
137
|
-
// // result.adapters[i] = ContractAdapter({
|
|
138
|
-
// // targetContract: creditManager.adapterToContract(allowedAdapter),
|
|
139
|
-
// // adapter: allowedAdapter
|
|
140
|
-
// // });
|
|
141
|
-
// // }
|
|
142
|
-
// // }
|
|
143
|
-
|
|
144
|
-
// result.degenNFT = creditFacade.degenNFT();
|
|
145
|
-
// result.isDegenMode = result.degenNFT != address(0);
|
|
146
|
-
// // (, result.isIncreaseDebtForbidden,,) = creditFacade.params(); // V2 only: true if increasing debt is forbidden
|
|
147
|
-
// result.forbiddenTokenMask = creditFacade.forbiddenTokenMask(); // V2 only: mask which forbids some particular tokens
|
|
148
|
-
// result.maxEnabledTokensLength = creditManager.maxEnabledTokens(); // V2 only: a limit on enabled tokens imposed for security
|
|
149
|
-
// {
|
|
150
|
-
// (
|
|
151
|
-
// result.feeInterest,
|
|
152
|
-
// result.feeLiquidation,
|
|
153
|
-
// result.liquidationDiscount,
|
|
154
|
-
// result.feeLiquidationExpired,
|
|
155
|
-
// result.liquidationDiscountExpired
|
|
156
|
-
// ) = creditManager.fees();
|
|
157
|
-
// }
|
|
158
|
-
|
|
159
|
-
// result.quotas = _getQuotas(result.pool);
|
|
160
|
-
|
|
161
|
-
// result.isPaused = _getPaused(address(creditFacade));
|
|
162
|
-
// }
|
|
163
|
-
|
|
164
|
-
// /// @dev Returns PoolData for a particular pool
|
|
165
|
-
// /// @param _pool Pool address
|
|
166
|
-
// function getPoolData(address _pool) public view registeredPoolOnly(_pool) returns (PoolData memory result) {
|
|
167
|
-
// PoolV3 pool = PoolV3(_pool);
|
|
168
|
-
|
|
169
|
-
// result.addr = _pool;
|
|
170
|
-
// result.expectedLiquidity = pool.expectedLiquidity();
|
|
171
|
-
// result.availableLiquidity = pool.availableLiquidity();
|
|
172
|
-
|
|
173
|
-
// result.dieselRate_RAY = pool.convertToAssets(RAY);
|
|
174
|
-
// result.baseInterestIndex = pool.baseInterestIndex();
|
|
175
|
-
// result.baseInterestRate = _getBaseInterestRate(address(pool));
|
|
176
|
-
// result.underlying = pool.underlyingToken();
|
|
177
|
-
// result.dieselToken = address(pool);
|
|
178
|
-
// (result.symbol, result.name) = _getSymbolAndName(_pool);
|
|
179
|
-
|
|
180
|
-
// result.dieselRate_RAY = pool.convertToAssets(RAY);
|
|
181
|
-
// result.withdrawFee = pool.withdrawFee();
|
|
182
|
-
// result.baseInterestIndexLU = pool.baseInterestIndexLU();
|
|
183
|
-
// result.lastBaseInterestUpdate = pool.lastBaseInterestUpdate();
|
|
184
|
-
// // result.cumulativeIndex_RAY = pool.calcLinearCumulative_RAY();
|
|
185
|
-
|
|
186
|
-
// // Borrowing limits
|
|
187
|
-
// result.totalBorrowed = pool.totalBorrowed();
|
|
188
|
-
// result.totalDebtLimit = pool.totalDebtLimit();
|
|
189
|
-
|
|
190
|
-
// address[] memory creditManagers = pool.creditManagers();
|
|
191
|
-
// uint256 len = creditManagers.length;
|
|
192
|
-
// result.creditManagerDebtParams = new CreditManagerDebtParams[](len);
|
|
193
|
-
|
|
194
|
-
// unchecked {
|
|
195
|
-
// for (uint256 i; i < len; ++i) {
|
|
196
|
-
// address creditManager = creditManagers[i];
|
|
197
|
-
// result.creditManagerDebtParams[i] = CreditManagerDebtParams({
|
|
198
|
-
// creditManager: creditManager,
|
|
199
|
-
// borrowed: pool.creditManagerBorrowed(creditManager),
|
|
200
|
-
// limit: pool.creditManagerDebtLimit(creditManager),
|
|
201
|
-
// availableToBorrow: pool.creditManagerBorrowable(creditManager)
|
|
202
|
-
// });
|
|
203
|
-
// }
|
|
204
|
-
// }
|
|
205
|
-
|
|
206
|
-
// result.totalSupply = pool.totalSupply();
|
|
207
|
-
// result.totalAssets = pool.totalAssets();
|
|
208
|
-
// result.supplyRate = pool.supplyRate();
|
|
209
|
-
|
|
210
|
-
// result.version = _getVersion(address(pool));
|
|
211
|
-
|
|
212
|
-
// result.quotas = _getQuotas(_pool);
|
|
213
|
-
// result.lirm = _getInterestRateModel(_pool);
|
|
214
|
-
// result.isPaused = _getPaused(_pool);
|
|
215
|
-
|
|
216
|
-
// // Adding zappers
|
|
217
|
-
// // address[] memory zappers = zapperRegister.zappers(address(pool));
|
|
218
|
-
// // len = zappers.length;
|
|
219
|
-
// // result.zappers = new ZapperInfo[](len);
|
|
220
|
-
|
|
221
|
-
// // unchecked {
|
|
222
|
-
// // for (uint256 i; i < len; ++i) {
|
|
223
|
-
// // address tokenIn = IZapper(zappers[i]).tokenIn();
|
|
224
|
-
// // address tokenOut = IZapper(zappers[i]).tokenOut();
|
|
225
|
-
// // result.zappers[i] = ZapperInfo({tokenIn: tokenIn, tokenOut: tokenOut, zapper: zappers[i]});
|
|
226
|
-
// // }
|
|
227
|
-
// // }
|
|
228
|
-
|
|
229
|
-
// result.poolQuotaKeeper = address(_getPoolQuotaKeeper(_pool));
|
|
230
|
-
// result.gauge = _getGauge(IPoolQuotaKeeperV3(result.poolQuotaKeeper));
|
|
231
|
-
|
|
232
|
-
// return result;
|
|
233
|
-
// }
|
|
234
|
-
|
|
235
|
-
// /// @dev Returns PoolData for all registered pools
|
|
236
|
-
// function getPoolsV3List() external view returns (PoolData[] memory result) {
|
|
237
|
-
// address[] memory poolsV3 = _listPoolsV3();
|
|
238
|
-
// uint256 len = poolsV3.length;
|
|
239
|
-
// result = new PoolData[](len);
|
|
240
|
-
|
|
241
|
-
// unchecked {
|
|
242
|
-
// for (uint256 i = 0; i < len; ++i) {
|
|
243
|
-
// result[i] = getPoolData(poolsV3[i]);
|
|
244
|
-
// }
|
|
245
|
-
// }
|
|
246
|
-
// }
|
|
247
|
-
|
|
248
|
-
// function _listPoolsV3() internal view returns (address[] memory result) {
|
|
249
|
-
// uint256 len = IContractsRegister(contractsRegister).getPools().length;
|
|
250
|
-
|
|
251
|
-
// // uint256 index;
|
|
252
|
-
// // unchecked {
|
|
253
|
-
// // for (uint256 op = COUNT; op <= QUERY; ++op) {
|
|
254
|
-
// // if (op == QUERY && index == 0) {
|
|
255
|
-
// // break;
|
|
256
|
-
// // } else {
|
|
257
|
-
// // result = new address[](index);
|
|
258
|
-
// // index = 0;
|
|
259
|
-
// // }
|
|
260
|
-
|
|
261
|
-
// // for (uint256 i = 0; i < len; ++i) {
|
|
262
|
-
// // address _pool = IContractsRegister(contractsRegister).pools(i);
|
|
263
|
-
|
|
264
|
-
// // if (_isContractV3(_pool)) {
|
|
265
|
-
// // if (op == QUERY) result[index] = _pool;
|
|
266
|
-
// // ++index;
|
|
267
|
-
// // }
|
|
268
|
-
// // }
|
|
269
|
-
// // }
|
|
270
|
-
// // }
|
|
271
|
-
// }
|
|
272
|
-
|
|
273
|
-
// function _updatePrices(address creditManager, PriceOnDemand[] memory priceUpdates) internal {
|
|
274
|
-
// uint256 len = priceUpdates.length;
|
|
275
|
-
// unchecked {
|
|
276
|
-
// for (uint256 i; i < len; ++i) {
|
|
277
|
-
// address priceFeed = _getPriceOracle(creditManager).priceFeeds(priceUpdates[i].priceFeed);
|
|
278
|
-
// if (priceFeed == address(0)) revert PriceFeedDoesNotExistException();
|
|
279
|
-
|
|
280
|
-
// IUpdatablePriceFeed(priceFeed).updatePrice(priceUpdates[i].callData);
|
|
281
|
-
// }
|
|
282
|
-
// }
|
|
283
|
-
// }
|
|
284
|
-
|
|
285
|
-
// function _getPriceFeedFailedList(address _cm, TokenBalance[] memory balances)
|
|
286
|
-
// internal
|
|
287
|
-
// view
|
|
288
|
-
// returns (address[] memory priceFeedFailed)
|
|
289
|
-
// {
|
|
290
|
-
// uint256 len = balances.length;
|
|
291
|
-
|
|
292
|
-
// IPriceOracleV3 priceOracle = _getPriceOracle(_cm);
|
|
293
|
-
|
|
294
|
-
// uint256 index;
|
|
295
|
-
|
|
296
|
-
// /// It counts on the first iteration how many price feeds failed and then fill the array on the second iteration
|
|
297
|
-
// // for (uint256 op = COUNT; op <= QUERY; ++op) {
|
|
298
|
-
// // if (op == QUERY && index == 0) {
|
|
299
|
-
// // break;
|
|
300
|
-
// // } else {
|
|
301
|
-
// // priceFeedFailed = new address[](index);
|
|
302
|
-
// // index = 0;
|
|
303
|
-
// // }
|
|
304
|
-
// // unchecked {
|
|
305
|
-
// // for (uint256 i = 0; i < len; ++i) {
|
|
306
|
-
// // TokenBalance memory balance = balances[i];
|
|
307
|
-
|
|
308
|
-
// // if (balance.balance > 1 && balance.isEnabled) {
|
|
309
|
-
// // try priceOracle.getPrice(balance.token) returns (uint256) {}
|
|
310
|
-
// // catch {
|
|
311
|
-
// // if (op == QUERY) priceFeedFailed[index] = balance.token;
|
|
312
|
-
// // ++index;
|
|
313
|
-
// // }
|
|
314
|
-
// // }
|
|
315
|
-
// // }
|
|
316
|
-
// // }
|
|
317
|
-
// // }
|
|
318
|
-
// }
|
|
319
|
-
|
|
320
|
-
// function _getPoolQuotaKeeper(address pool) internal view returns (IPoolQuotaKeeperV3) {
|
|
321
|
-
// return IPoolQuotaKeeperV3(IPoolV3(pool).poolQuotaKeeper());
|
|
322
|
-
// }
|
|
323
|
-
|
|
324
|
-
// function _getPriceOracle(address _cm) internal view returns (IPriceOracleV3) {
|
|
325
|
-
// return IPriceOracleV3(ICreditManagerV3(_cm).priceOracle());
|
|
326
|
-
// }
|
|
327
|
-
|
|
328
|
-
// function _getBaseInterestRate(address pool) internal view returns (uint256) {
|
|
329
|
-
// return IPoolV3(pool).baseInterestRate();
|
|
330
|
-
// }
|
|
331
|
-
|
|
332
|
-
// function _getBorrowerOrRevert(address cm, address creditAccount) internal view returns (address) {
|
|
333
|
-
// return ICreditManagerV3(cm).getBorrowerOrRevert(creditAccount);
|
|
334
|
-
// }
|
|
335
|
-
|
|
336
|
-
// function _getVersion(address versionedContract) internal view returns (uint256) {
|
|
337
|
-
// return IVersion(versionedContract).version();
|
|
338
|
-
// }
|
|
339
|
-
|
|
340
|
-
// function _getCreditFacade(address cm) internal view returns (ICreditFacadeV3) {
|
|
341
|
-
// return ICreditFacadeV3(ICreditManagerV3(cm).creditFacade());
|
|
342
|
-
// }
|
|
343
|
-
|
|
344
|
-
// function _getSymbolAndName(address token) internal view returns (string memory symbol, string memory name) {
|
|
345
|
-
// symbol = IERC20Metadata(token).symbol();
|
|
346
|
-
// name = _getName(token);
|
|
347
|
-
// }
|
|
348
|
-
|
|
349
|
-
// function _getInterestRateModel(address pool) internal view returns (LinearModel memory) {
|
|
350
|
-
// // return getLIRMData(IPoolV3(pool).interestRateModel());
|
|
351
|
-
// }
|
|
352
|
-
|
|
353
|
-
// function _getQuotedTokens(IPoolQuotaKeeperV3 pqk) internal view returns (address[] memory result) {
|
|
354
|
-
// result = pqk.quotedTokens();
|
|
355
|
-
// }
|
|
356
|
-
|
|
357
|
-
// function _getPool(address cnt) internal view returns (address) {
|
|
358
|
-
// return ICreditManagerV3(cnt).pool();
|
|
359
|
-
// }
|
|
360
|
-
|
|
361
|
-
// function _getName(address _cm) internal view returns (string memory) {
|
|
362
|
-
// return IERC20Metadata(_cm).name();
|
|
363
|
-
// }
|
|
364
|
-
|
|
365
|
-
// function _getCollateralTokensCount(address _cm) internal view returns (uint256) {
|
|
366
|
-
// return ICreditManagerV3(_cm).collateralTokensCount();
|
|
367
|
-
// }
|
|
368
|
-
|
|
369
|
-
// function _getGauge(IPoolQuotaKeeperV3 pqk) internal view returns (address) {
|
|
370
|
-
// return pqk.gauge();
|
|
371
|
-
// }
|
|
372
|
-
|
|
373
|
-
// function _getPaused(address pausableContract) internal view returns (bool) {
|
|
374
|
-
// return Pausable(pausableContract).paused();
|
|
375
|
-
// }
|
|
376
|
-
|
|
377
|
-
// function _getUnderlying(ICreditManagerV3 cm) internal view returns (address) {
|
|
378
|
-
// return cm.underlying();
|
|
379
|
-
// }
|
|
380
|
-
|
|
381
|
-
// function _getQuotas(address _pool) internal view returns (QuotaInfo[] memory quotas) {
|
|
382
|
-
// IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(_pool);
|
|
383
|
-
|
|
384
|
-
// address[] memory quotaTokens = _getQuotedTokens(pqk);
|
|
385
|
-
// uint256 len = quotaTokens.length;
|
|
386
|
-
// quotas = new QuotaInfo[](len);
|
|
387
|
-
// unchecked {
|
|
388
|
-
// for (uint256 i; i < len; ++i) {
|
|
389
|
-
// quotas[i].token = quotaTokens[i];
|
|
390
|
-
// (
|
|
391
|
-
// quotas[i].rate,
|
|
392
|
-
// ,
|
|
393
|
-
// quotas[i].quotaIncreaseFee,
|
|
394
|
-
// quotas[i].totalQuoted,
|
|
395
|
-
// quotas[i].limit,
|
|
396
|
-
// quotas[i].isActive
|
|
397
|
-
// ) = pqk.getTokenQuotaParams(quotaTokens[i]);
|
|
398
|
-
// }
|
|
399
|
-
// }
|
|
400
|
-
// }
|
|
401
|
-
|
|
402
|
-
// function getGaugesV3Data(address staker) external view returns (GaugeInfo[] memory result) {
|
|
403
|
-
// address[] memory poolsV3 = _listPoolsV3();
|
|
404
|
-
// uint256 len = poolsV3.length;
|
|
405
|
-
// result = new GaugeInfo[](len);
|
|
406
|
-
|
|
407
|
-
// unchecked {
|
|
408
|
-
// for (uint256 i; i < len; ++i) {
|
|
409
|
-
// GaugeInfo memory gaugeInfo = result[i];
|
|
410
|
-
// IPoolQuotaKeeperV3 pqk = _getPoolQuotaKeeper(poolsV3[i]);
|
|
411
|
-
// address gauge = _getGauge(pqk);
|
|
412
|
-
// gaugeInfo.addr = gauge;
|
|
413
|
-
// gaugeInfo.pool = _getPool(gauge);
|
|
414
|
-
// (gaugeInfo.symbol, gaugeInfo.name) = _getSymbolAndName(gaugeInfo.pool);
|
|
415
|
-
// gaugeInfo.underlying = IPoolV3(gaugeInfo.pool).asset();
|
|
416
|
-
|
|
417
|
-
// address[] memory quotaTokens = _getQuotedTokens(pqk);
|
|
418
|
-
// uint256 quotaTokensLen = quotaTokens.length;
|
|
419
|
-
// gaugeInfo.quotaParams = new GaugeQuotaParams[](quotaTokensLen);
|
|
420
|
-
|
|
421
|
-
// gaugeInfo.currentEpoch = IGaugeV3(gauge).epochLastUpdate();
|
|
422
|
-
// gaugeInfo.epochFrozen = IGaugeV3(gauge).epochFrozen();
|
|
423
|
-
|
|
424
|
-
// for (uint256 j; j < quotaTokensLen; ++j) {
|
|
425
|
-
// GaugeQuotaParams memory quotaParams = gaugeInfo.quotaParams[j];
|
|
426
|
-
// address token = quotaTokens[j];
|
|
427
|
-
// quotaParams.token = token;
|
|
428
|
-
|
|
429
|
-
// (
|
|
430
|
-
// quotaParams.rate,
|
|
431
|
-
// ,
|
|
432
|
-
// quotaParams.quotaIncreaseFee,
|
|
433
|
-
// quotaParams.totalQuoted,
|
|
434
|
-
// quotaParams.limit,
|
|
435
|
-
// quotaParams.isActive
|
|
436
|
-
// ) = pqk.getTokenQuotaParams(token);
|
|
437
|
-
|
|
438
|
-
// (
|
|
439
|
-
// quotaParams.minRate,
|
|
440
|
-
// quotaParams.maxRate,
|
|
441
|
-
// quotaParams.totalVotesLpSide,
|
|
442
|
-
// quotaParams.totalVotesCaSide
|
|
443
|
-
// ) = IGaugeV3(gauge).quotaRateParams(token);
|
|
444
|
-
|
|
445
|
-
// (quotaParams.stakerVotesLpSide, quotaParams.stakerVotesCaSide) =
|
|
446
|
-
// IGaugeV3(gauge).userTokenVotes(staker, token);
|
|
447
|
-
// }
|
|
448
|
-
// }
|
|
449
|
-
// }
|
|
450
|
-
// }
|
|
451
|
-
// }
|