@gearbox-protocol/periphery-v3 1.7.0-next.25 → 1.7.0-next.26
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/PoolCompressor.sol +23 -90
- package/contracts/compressors/PriceFeedCompressor.sol +55 -46
- package/contracts/interfaces/IPriceFeedCompressor.sol +1 -1
- package/contracts/libraries/BaseLib.sol +42 -0
- package/contracts/types/PriceOracleState.sol +4 -7
- package/package.json +1 -1
- package/contracts/types/ZapperRegisterState.sol +0 -10
|
@@ -24,8 +24,8 @@ import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v3/contracts/librar
|
|
|
24
24
|
import {IRateKeeper} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IRateKeeper.sol";
|
|
25
25
|
|
|
26
26
|
// Serializers
|
|
27
|
-
import {
|
|
28
|
-
|
|
27
|
+
import {BaseLib} from "../libraries/BaseLib.sol";
|
|
28
|
+
|
|
29
29
|
import {GaugeSerializer} from "../serializers/pool/GaugeSerializer.sol";
|
|
30
30
|
import {LinearInterestModelSerializer} from "../serializers/pool/LinearInterestModelSerializer.sol";
|
|
31
31
|
|
|
@@ -42,19 +42,15 @@ contract PoolCompressorV3 {
|
|
|
42
42
|
|
|
43
43
|
constructor() {
|
|
44
44
|
gaugeSerializer = address(new GaugeSerializer());
|
|
45
|
-
linearInterestModelSerializer = address(
|
|
46
|
-
new LinearInterestModelSerializer()
|
|
47
|
-
);
|
|
45
|
+
linearInterestModelSerializer = address(new LinearInterestModelSerializer());
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
function getPoolState(
|
|
51
|
-
address pool
|
|
52
|
-
) public view returns (PoolState memory result) {
|
|
48
|
+
function getPoolState(address pool) public view returns (PoolState memory result) {
|
|
53
49
|
PoolV3 _pool = PoolV3(pool);
|
|
54
50
|
//
|
|
55
51
|
// CONTRACT PARAMETERS
|
|
56
52
|
//
|
|
57
|
-
result.baseParams = getBaseParams(pool, "POOL", address(0));
|
|
53
|
+
result.baseParams = BaseLib.getBaseParams(pool, "POOL", address(0));
|
|
58
54
|
|
|
59
55
|
//
|
|
60
56
|
// ERC20 Properties
|
|
@@ -139,12 +135,10 @@ contract PoolCompressorV3 {
|
|
|
139
135
|
result.isPaused = _pool.paused();
|
|
140
136
|
}
|
|
141
137
|
|
|
142
|
-
function getPoolQuotaKeeperState(
|
|
143
|
-
address pqk
|
|
144
|
-
) external view returns (PoolQuotaKeeperState memory result) {
|
|
138
|
+
function getPoolQuotaKeeperState(address pqk) external view returns (PoolQuotaKeeperState memory result) {
|
|
145
139
|
IPoolQuotaKeeperV3 _pqk = IPoolQuotaKeeperV3(pqk);
|
|
146
140
|
|
|
147
|
-
result.baseParams = getBaseParams(pqk, "POOL_QUOTA_KEEPER", address(0));
|
|
141
|
+
result.baseParams = BaseLib.getBaseParams(pqk, "POOL_QUOTA_KEEPER", address(0));
|
|
148
142
|
|
|
149
143
|
// address rateKeeper;
|
|
150
144
|
result.rateKeeper = _pqk.gauge();
|
|
@@ -173,18 +167,14 @@ contract PoolCompressorV3 {
|
|
|
173
167
|
result.lastQuotaRateUpdate = _pqk.lastQuotaRateUpdate();
|
|
174
168
|
}
|
|
175
169
|
|
|
176
|
-
function getRateKeeperState(
|
|
177
|
-
address rateKeeper
|
|
178
|
-
) external view returns (RateKeeperState memory result) {
|
|
170
|
+
function getRateKeeperState(address rateKeeper) external view returns (RateKeeperState memory result) {
|
|
179
171
|
IRateKeeper _rateKeeper = IRateKeeper(rateKeeper);
|
|
180
172
|
|
|
181
173
|
bytes32 contractType;
|
|
182
174
|
|
|
183
|
-
result.baseParams = getBaseParams(rateKeeper, "GAUGE", gaugeSerializer);
|
|
175
|
+
result.baseParams = BaseLib.getBaseParams(rateKeeper, "GAUGE", gaugeSerializer);
|
|
184
176
|
|
|
185
|
-
IPoolQuotaKeeperV3 _pqk = IPoolQuotaKeeperV3(
|
|
186
|
-
PoolV3(_rateKeeper.pool()).poolQuotaKeeper()
|
|
187
|
-
);
|
|
177
|
+
IPoolQuotaKeeperV3 _pqk = IPoolQuotaKeeperV3(PoolV3(_rateKeeper.pool()).poolQuotaKeeper());
|
|
188
178
|
|
|
189
179
|
address[] memory quotaTokens = _pqk.quotedTokens();
|
|
190
180
|
uint256 quotaTokensLen = quotaTokens.length;
|
|
@@ -200,18 +190,12 @@ contract PoolCompressorV3 {
|
|
|
200
190
|
|
|
201
191
|
/// @dev Returns CreditManagerData for a particular _cm
|
|
202
192
|
/// @param _cm CreditManager address
|
|
203
|
-
function getCreditManagerState(
|
|
204
|
-
address _cm
|
|
205
|
-
) public view returns (CreditManagerState memory result) {
|
|
193
|
+
function getCreditManagerState(address _cm) public view returns (CreditManagerState memory result) {
|
|
206
194
|
ICreditManagerV3 creditManager = ICreditManagerV3(_cm);
|
|
207
|
-
ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
creditManager.creditFacade()
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
result.baseParams = getBaseParams(_cm, "CREDIT_MANAGER", address(0));
|
|
195
|
+
ICreditConfiguratorV3 creditConfigurator = ICreditConfiguratorV3(creditManager.creditConfigurator());
|
|
196
|
+
CreditFacadeV3 creditFacade = CreditFacadeV3(creditManager.creditFacade());
|
|
197
|
+
|
|
198
|
+
result.baseParams = BaseLib.getBaseParams(_cm, "CREDIT_MANAGER", address(0));
|
|
215
199
|
// string name;
|
|
216
200
|
result.name = ICreditManagerV3(_cm).name();
|
|
217
201
|
|
|
@@ -232,18 +216,15 @@ contract PoolCompressorV3 {
|
|
|
232
216
|
// address[] collateralTokens;
|
|
233
217
|
// uint16[] liquidationThresholds;
|
|
234
218
|
{
|
|
235
|
-
uint256 collateralTokenCount = creditManager
|
|
236
|
-
.collateralTokensCount();
|
|
219
|
+
uint256 collateralTokenCount = creditManager.collateralTokensCount();
|
|
237
220
|
|
|
238
221
|
result.collateralTokens = new address[](collateralTokenCount);
|
|
239
222
|
result.liquidationThresholds = new uint16[](collateralTokenCount);
|
|
240
223
|
|
|
241
224
|
unchecked {
|
|
242
225
|
for (uint256 i = 0; i < collateralTokenCount; ++i) {
|
|
243
|
-
(
|
|
244
|
-
|
|
245
|
-
result.liquidationThresholds[i]
|
|
246
|
-
) = creditManager.collateralTokenByMask(1 << i);
|
|
226
|
+
(result.collateralTokens[i], result.liquidationThresholds[i]) =
|
|
227
|
+
creditManager.collateralTokenByMask(1 << i);
|
|
247
228
|
}
|
|
248
229
|
}
|
|
249
230
|
}
|
|
@@ -265,12 +246,10 @@ contract PoolCompressorV3 {
|
|
|
265
246
|
|
|
266
247
|
/// @dev Returns CreditManagerData for a particular _cm
|
|
267
248
|
/// @param _cf CreditFacade address
|
|
268
|
-
function getCreditFacadeState(
|
|
269
|
-
address _cf
|
|
270
|
-
) public view returns (CreditFacadeState memory result) {
|
|
249
|
+
function getCreditFacadeState(address _cf) public view returns (CreditFacadeState memory result) {
|
|
271
250
|
CreditFacadeV3 creditFacade = CreditFacadeV3(_cf);
|
|
272
251
|
|
|
273
|
-
result.baseParams = getBaseParams(_cf, "CREDIT_FACADE", address(0));
|
|
252
|
+
result.baseParams = BaseLib.getBaseParams(_cf, "CREDIT_FACADE", address(0));
|
|
274
253
|
//
|
|
275
254
|
result.maxQuotaMultiplier = creditFacade.maxQuotaMultiplier();
|
|
276
255
|
// address treasury;
|
|
@@ -282,8 +261,7 @@ contract PoolCompressorV3 {
|
|
|
282
261
|
// uint40 expirationDate;
|
|
283
262
|
result.expirationDate = creditFacade.expirationDate();
|
|
284
263
|
// uint8 maxDebtPerBlockMultiplier;
|
|
285
|
-
result.maxDebtPerBlockMultiplier = creditFacade
|
|
286
|
-
.maxDebtPerBlockMultiplier();
|
|
264
|
+
result.maxDebtPerBlockMultiplier = creditFacade.maxDebtPerBlockMultiplier();
|
|
287
265
|
// address botList;
|
|
288
266
|
result.botList = creditFacade.botList();
|
|
289
267
|
// uint256 minDebt;
|
|
@@ -297,52 +275,7 @@ contract PoolCompressorV3 {
|
|
|
297
275
|
result.isPaused = creditFacade.paused();
|
|
298
276
|
}
|
|
299
277
|
|
|
300
|
-
function
|
|
301
|
-
|
|
302
|
-
bytes32 defaultContractType,
|
|
303
|
-
address legacySerializer
|
|
304
|
-
) public view returns (BaseParams memory baseParams) {
|
|
305
|
-
baseParams.addr = addr;
|
|
306
|
-
try IVersion(addr).contractType() returns (bytes32 contractType) {
|
|
307
|
-
baseParams.contractType = contractType;
|
|
308
|
-
} catch {
|
|
309
|
-
baseParams.version = 3_00;
|
|
310
|
-
baseParams.contractType = defaultContractType;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
baseParams.version = IVersion(addr).version();
|
|
314
|
-
try IStateSerializer(addr).serialize() returns (
|
|
315
|
-
bytes memory serializedParams
|
|
316
|
-
) {
|
|
317
|
-
baseParams.serializedParams = serializedParams;
|
|
318
|
-
} catch {
|
|
319
|
-
if (legacySerializer != address(0)) {
|
|
320
|
-
baseParams.serializedParams = IStateSerializerLegacy(
|
|
321
|
-
legacySerializer
|
|
322
|
-
).serialize(addr);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function getBaseState(
|
|
328
|
-
address addr,
|
|
329
|
-
bytes32 defaultContractType,
|
|
330
|
-
address legacySerializer
|
|
331
|
-
) public view returns (BaseState memory baseState) {
|
|
332
|
-
baseState.baseParams = getBaseParams(
|
|
333
|
-
addr,
|
|
334
|
-
defaultContractType,
|
|
335
|
-
legacySerializer
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function getInterestModelState(
|
|
340
|
-
address addr
|
|
341
|
-
) public view returns (BaseState memory baseState) {
|
|
342
|
-
baseState = getBaseState(
|
|
343
|
-
addr,
|
|
344
|
-
"INTEREST_MODEL",
|
|
345
|
-
linearInterestModelSerializer
|
|
346
|
-
);
|
|
278
|
+
function getInterestModelState(address addr) public view returns (BaseState memory baseState) {
|
|
279
|
+
baseState = BaseLib.getBaseState(addr, "INTEREST_MODEL", linearInterestModelSerializer);
|
|
347
280
|
}
|
|
348
281
|
}
|
|
@@ -10,6 +10,8 @@ import {IPriceFeedCompressor} from "../interfaces/IPriceFeedCompressor.sol";
|
|
|
10
10
|
import {PriceFeedType} from "@gearbox-protocol/sdk-gov/contracts/PriceFeedType.sol";
|
|
11
11
|
import {IVersion} from "../interfaces/IVersion.sol";
|
|
12
12
|
|
|
13
|
+
import {BaseLib} from "../libraries/BaseLib.sol";
|
|
14
|
+
|
|
13
15
|
import {IStateSerializerLegacy} from "../interfaces/IStateSerializerLegacy.sol";
|
|
14
16
|
import {IStateSerializer} from "../interfaces/IStateSerializer.sol";
|
|
15
17
|
import {NestedPriceFeeds} from "../libraries/NestedPriceFeeds.sol";
|
|
@@ -45,32 +47,50 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
45
47
|
|
|
46
48
|
/// @notice Map of state serializers for different price feed types
|
|
47
49
|
/// @dev Serializers only apply to feeds that don't implement `IStateSerializer` themselves
|
|
48
|
-
mapping(
|
|
50
|
+
mapping(bytes32 => address) public serializers;
|
|
51
|
+
|
|
52
|
+
mapping(uint8 => bytes32) public contractTypes;
|
|
49
53
|
|
|
50
54
|
/// @notice Constructor
|
|
51
55
|
/// @dev Sets serializers for existing price feed types.
|
|
52
56
|
/// It is recommended to implement `IStateSerializer` in new price feeds.
|
|
53
57
|
constructor() {
|
|
54
58
|
address lpSerializer = address(new LPPriceFeedSerializer());
|
|
59
|
+
|
|
60
|
+
contractTypes[uint8(PriceFeedType.BALANCER_STABLE_LP_ORACLE)] = "PF_BALANCER_STABLE_LP_ORACLE";
|
|
61
|
+
contractTypes[uint8(PriceFeedType.COMPOUND_V2_ORACLE)] = "NOT_USED";
|
|
62
|
+
contractTypes[uint8(PriceFeedType.CURVE_2LP_ORACLE)] = "PF_CURVE_STABLE_LP_ORACLE";
|
|
63
|
+
contractTypes[uint8(PriceFeedType.CURVE_3LP_ORACLE)] = "PF_CURVE_STABLE_LP_ORACLE";
|
|
64
|
+
contractTypes[uint8(PriceFeedType.CURVE_4LP_ORACLE)] = "PF_CURVE_STABLE_LP_ORACLE";
|
|
65
|
+
contractTypes[uint8(PriceFeedType.CURVE_CRYPTO_ORACLE)] = "PF_CURVE_CRYPTO_LP_ORACLE";
|
|
66
|
+
contractTypes[uint8(PriceFeedType.CURVE_USD_ORACLE)] = "PF_CURVE_USD_ORACLE";
|
|
67
|
+
contractTypes[uint8(PriceFeedType.ERC4626_VAULT_ORACLE)] = "PF_ERC4626_ORACLE";
|
|
68
|
+
contractTypes[uint8(PriceFeedType.WRAPPED_AAVE_V2_ORACLE)] = "NOT_USER";
|
|
69
|
+
contractTypes[uint8(PriceFeedType.WSTETH_ORACLE)] = "PF_WSTETH_ORACLE";
|
|
70
|
+
contractTypes[uint8(PriceFeedType.YEARN_ORACLE)] = "PF_YEARN_ORACLE";
|
|
71
|
+
contractTypes[uint8(PriceFeedType.MELLOW_LRT_ORACLE)] = "PF_MELLOW_LRT_ORACLE";
|
|
72
|
+
|
|
73
|
+
// these types need special serialization
|
|
74
|
+
contractTypes[uint8(PriceFeedType.BALANCER_WEIGHTED_LP_ORACLE)] = "PF_BALANCER_WEIGHTED_LP_ORACLE";
|
|
75
|
+
contractTypes[uint8(PriceFeedType.BOUNDED_ORACLE)] = "PF_BOUNDED_ORACLE";
|
|
76
|
+
contractTypes[uint8(PriceFeedType.PYTH_ORACLE)] = "PF_PYTH_ORACLE";
|
|
77
|
+
contractTypes[uint8(PriceFeedType.REDSTONE_ORACLE)] = "PF_REDSTONE_ORACLE";
|
|
78
|
+
|
|
55
79
|
// these types can be serialized as generic LP price feeds
|
|
56
|
-
_setSerializer(
|
|
57
|
-
_setSerializer(
|
|
58
|
-
_setSerializer(
|
|
59
|
-
_setSerializer(
|
|
60
|
-
_setSerializer(
|
|
61
|
-
_setSerializer(
|
|
62
|
-
_setSerializer(
|
|
63
|
-
_setSerializer(
|
|
64
|
-
_setSerializer(uint8(PriceFeedType.WRAPPED_AAVE_V2_ORACLE), lpSerializer);
|
|
65
|
-
_setSerializer(uint8(PriceFeedType.WSTETH_ORACLE), lpSerializer);
|
|
66
|
-
_setSerializer(uint8(PriceFeedType.YEARN_ORACLE), lpSerializer);
|
|
67
|
-
_setSerializer(uint8(PriceFeedType.MELLOW_LRT_ORACLE), lpSerializer);
|
|
80
|
+
_setSerializer("PF_BALANCER_STABLE_LP_ORACLE", lpSerializer);
|
|
81
|
+
_setSerializer("PF_CURVE_STABLE_LP_ORACLE", lpSerializer);
|
|
82
|
+
_setSerializer("PF_CURVE_CRYPTO_LP_ORACLE", lpSerializer);
|
|
83
|
+
_setSerializer("PF_CURVE_USD_ORACLE", lpSerializer);
|
|
84
|
+
_setSerializer("PF_ERC4626_ORACLE", lpSerializer);
|
|
85
|
+
_setSerializer("PF_WSTETH_ORACLE", lpSerializer);
|
|
86
|
+
_setSerializer("PF_YEARN_ORACLE", lpSerializer);
|
|
87
|
+
_setSerializer("PF_MELLOW_LRT_ORACLE", lpSerializer);
|
|
68
88
|
|
|
69
89
|
// these types need special serialization
|
|
70
|
-
_setSerializer(
|
|
71
|
-
_setSerializer(
|
|
72
|
-
_setSerializer(
|
|
73
|
-
_setSerializer(
|
|
90
|
+
_setSerializer("PF_BALANCER_WEIGHTED_LP_ORACLE", address(new BPTWeightedPriceFeedSerializer()));
|
|
91
|
+
_setSerializer("PF_BOUNDED_ORACLE", address(new BoundedPriceFeedSerializer()));
|
|
92
|
+
_setSerializer("PF_PYTH_ORACLE", address(new PythPriceFeedSerializer()));
|
|
93
|
+
_setSerializer("PF_REDSTONE_ORACLE", address(new RedstonePriceFeedSerializer()));
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
/// @notice Returns all potentially useful price feeds data for a given price oracle in the form of two arrays:
|
|
@@ -94,14 +114,7 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
94
114
|
view
|
|
95
115
|
returns (PriceOracleState memory result)
|
|
96
116
|
{
|
|
97
|
-
result.
|
|
98
|
-
result.version = IPriceOracleV3(priceOracle).version();
|
|
99
|
-
try IVersion(priceOracle).contractType() returns (bytes32 contractType) {
|
|
100
|
-
result.contractType = contractType;
|
|
101
|
-
} catch {
|
|
102
|
-
result.contractType = "PRICE_ORACLE";
|
|
103
|
-
}
|
|
104
|
-
|
|
117
|
+
result.baseParams = BaseLib.getBaseParams(priceOracle, "PRICE_ORACLE", address(0));
|
|
105
118
|
(result.priceFeedMapping, result.priceFeedStructure) = getPriceFeeds(priceOracle, tokens);
|
|
106
119
|
}
|
|
107
120
|
|
|
@@ -177,10 +190,10 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
177
190
|
// --------- //
|
|
178
191
|
|
|
179
192
|
/// @dev Sets `serializer` for `priceFeedType`
|
|
180
|
-
function _setSerializer(
|
|
181
|
-
if (serializers[
|
|
182
|
-
serializers[
|
|
183
|
-
emit SetSerializer(
|
|
193
|
+
function _setSerializer(bytes32 contractType, address serializer) internal {
|
|
194
|
+
if (serializers[contractType] != serializer) {
|
|
195
|
+
serializers[contractType] = serializer;
|
|
196
|
+
emit SetSerializer(contractType, serializer);
|
|
184
197
|
}
|
|
185
198
|
}
|
|
186
199
|
|
|
@@ -218,7 +231,7 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
218
231
|
// duplicates are possible since price feed can be in `priceFeedMap` for more than one (token, reserve) pair
|
|
219
232
|
// or serve as an underlying in more than one nested feed, and the whole subtree can be skipped in this case
|
|
220
233
|
for (uint256 i; i < offset; ++i) {
|
|
221
|
-
if (priceFeedTree[i].
|
|
234
|
+
if (priceFeedTree[i].baseParams.addr == priceFeed) return offset;
|
|
222
235
|
}
|
|
223
236
|
|
|
224
237
|
PriceFeedTreeNode memory node = _getPriceFeedTreeNode(priceFeed);
|
|
@@ -231,16 +244,21 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
231
244
|
|
|
232
245
|
/// @dev Returns price feed tree node, see `PriceFeedTreeNode` for detailed description of struct fields
|
|
233
246
|
function _getPriceFeedTreeNode(address priceFeed) internal view returns (PriceFeedTreeNode memory data) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
data.version = IPriceFeed(priceFeed).version();
|
|
237
|
-
|
|
238
|
-
try ImplementsPriceFeedType(priceFeed).priceFeedType() returns (uint8 priceFeedType) {
|
|
239
|
-
data.priceFeedType = priceFeedType;
|
|
247
|
+
try IVersion(priceFeed).contractType() returns (bytes32 contractType) {
|
|
248
|
+
data.baseParams.contractType = contractType;
|
|
240
249
|
} catch {
|
|
241
|
-
|
|
250
|
+
try ImplementsPriceFeedType(priceFeed).priceFeedType() returns (uint8 priceFeedType) {
|
|
251
|
+
data.baseParams.contractType = contractTypes[priceFeedType];
|
|
252
|
+
} catch {
|
|
253
|
+
data.baseParams.contractType = "PF_CHAINLINK_ORACLE";
|
|
254
|
+
}
|
|
242
255
|
}
|
|
243
256
|
|
|
257
|
+
data.baseParams =
|
|
258
|
+
BaseLib.getBaseParams(priceFeed, data.baseParams.contractType, serializers[data.baseParams.contractType]);
|
|
259
|
+
|
|
260
|
+
data.decimals = IPriceFeed(priceFeed).decimals();
|
|
261
|
+
|
|
244
262
|
try IPriceFeed(priceFeed).skipPriceCheck() returns (bool skipCheck) {
|
|
245
263
|
data.skipCheck = skipCheck;
|
|
246
264
|
} catch {}
|
|
@@ -249,15 +267,6 @@ contract PriceFeedCompressor is IPriceFeedCompressor {
|
|
|
249
267
|
data.updatable = updatable;
|
|
250
268
|
} catch {}
|
|
251
269
|
|
|
252
|
-
try IStateSerializer(priceFeed).serialize() returns (bytes memory specificParams) {
|
|
253
|
-
data.specificParams = specificParams;
|
|
254
|
-
} catch {
|
|
255
|
-
address serializer = serializers[data.priceFeedType];
|
|
256
|
-
if (serializer != address(0)) {
|
|
257
|
-
data.specificParams = IStateSerializerLegacy(serializer).serialize(priceFeed);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
270
|
(data.underlyingFeeds, data.underlyingStalenessPeriods) = IPriceFeed(priceFeed).getUnderlyingFeeds();
|
|
262
271
|
|
|
263
272
|
try IPriceFeed(priceFeed).latestRoundData() returns (uint80, int256 price, uint256, uint256 updatedAt, uint80) {
|
|
@@ -9,7 +9,7 @@ import {IVersion} from "@gearbox-protocol/core-v3/contracts/interfaces/base/IVer
|
|
|
9
9
|
|
|
10
10
|
interface IPriceFeedCompressor is IVersion {
|
|
11
11
|
/// @notice Emitted when new state serializer is set for a given price feed type
|
|
12
|
-
event SetSerializer(
|
|
12
|
+
event SetSerializer(bytes32 indexed contractType, address indexed serializer);
|
|
13
13
|
|
|
14
14
|
function getPriceFeeds(address priceOracle)
|
|
15
15
|
external
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import {BaseParams, BaseState} from "../types/BaseState.sol";
|
|
7
|
+
import {IVersion} from "../interfaces/IVersion.sol";
|
|
8
|
+
import {IStateSerializer} from "../interfaces/IStateSerializer.sol";
|
|
9
|
+
import {IStateSerializerLegacy} from "../interfaces/IStateSerializerLegacy.sol";
|
|
10
|
+
|
|
11
|
+
library BaseLib {
|
|
12
|
+
function getBaseParams(address addr, bytes32 defaultContractType, address legacySerializer)
|
|
13
|
+
internal
|
|
14
|
+
view
|
|
15
|
+
returns (BaseParams memory baseParams)
|
|
16
|
+
{
|
|
17
|
+
baseParams.addr = addr;
|
|
18
|
+
try IVersion(addr).contractType() returns (bytes32 contractType) {
|
|
19
|
+
baseParams.contractType = contractType;
|
|
20
|
+
} catch {
|
|
21
|
+
baseParams.version = 3_00;
|
|
22
|
+
baseParams.contractType = defaultContractType;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
baseParams.version = IVersion(addr).version();
|
|
26
|
+
try IStateSerializer(addr).serialize() returns (bytes memory serializedParams) {
|
|
27
|
+
baseParams.serializedParams = serializedParams;
|
|
28
|
+
} catch {
|
|
29
|
+
if (legacySerializer != address(0)) {
|
|
30
|
+
baseParams.serializedParams = IStateSerializerLegacy(legacySerializer).serialize(addr);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getBaseState(address addr, bytes32 defaultContractType, address legacySerializer)
|
|
36
|
+
internal
|
|
37
|
+
view
|
|
38
|
+
returns (BaseState memory baseState)
|
|
39
|
+
{
|
|
40
|
+
baseState.baseParams = getBaseParams(addr, defaultContractType, legacySerializer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// (c) Gearbox Holdings, 2024
|
|
4
4
|
pragma solidity ^0.8.17;
|
|
5
5
|
|
|
6
|
+
import {BaseParams} from "./BaseState.sol";
|
|
7
|
+
|
|
6
8
|
struct PriceOracleState {
|
|
7
|
-
|
|
8
|
-
uint256 version;
|
|
9
|
-
bytes32 contractType;
|
|
9
|
+
BaseParams baseParams;
|
|
10
10
|
PriceFeedMapEntry[] priceFeedMapping;
|
|
11
11
|
PriceFeedTreeNode[] priceFeedStructure;
|
|
12
12
|
}
|
|
@@ -45,9 +45,7 @@ struct PriceFeedMapEntry {
|
|
|
45
45
|
/// @param underlyingStalenessPeriods Staleness periods of underlying feeds, filled when `priceFeed` is nested
|
|
46
46
|
/// @param answer Price feed answer packed in a struct
|
|
47
47
|
struct PriceFeedTreeNode {
|
|
48
|
-
|
|
49
|
-
uint8 priceFeedType;
|
|
50
|
-
uint256 version;
|
|
48
|
+
BaseParams baseParams;
|
|
51
49
|
uint8 decimals;
|
|
52
50
|
bool skipCheck;
|
|
53
51
|
bool updatable;
|
|
@@ -55,5 +53,4 @@ struct PriceFeedTreeNode {
|
|
|
55
53
|
address[] underlyingFeeds;
|
|
56
54
|
uint32[] underlyingStalenessPeriods;
|
|
57
55
|
PriceFeedAnswer answer;
|
|
58
|
-
bytes specificParams;
|
|
59
56
|
}
|
package/package.json
CHANGED