Skip to content

Commit 38d9e74

Browse files
authored
fix: Rename user config key to dynamic config key for consistency (#952)
1 parent 3f6becb commit 38d9e74

File tree

13 files changed

+172
-129
lines changed

13 files changed

+172
-129
lines changed

src/spoke/Spoke.sol

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
6161
mapping(address user => PositionStatus) internal _positionStatus;
6262
mapping(uint256 reserveId => Reserve) internal _reserves;
6363
mapping(address positionManager => PositionManagerConfig) internal _positionManager;
64-
mapping(uint256 reserveId => mapping(uint16 configKey => DynamicReserveConfig))
64+
mapping(uint256 reserveId => mapping(uint16 dynamicConfigKey => DynamicReserveConfig))
6565
internal _dynamicConfig; // dictionary of dynamic configs per reserve
6666
LiquidationConfig internal _liquidationConfig;
6767
mapping(address hub => mapping(uint256 assetId => bool)) internal _reserveExists;
@@ -163,26 +163,26 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
163163
) external restricted returns (uint16) {
164164
require(reserveId < _reserveCount, ReserveNotListed());
165165
_validateDynamicReserveConfig(dynamicConfig);
166-
uint16 configKey;
166+
uint16 dynamicConfigKey;
167167
// overflow is desired, we implicitly invalidate & override stale config
168168
unchecked {
169-
configKey = ++_reserves[reserveId].dynamicConfigKey;
169+
dynamicConfigKey = ++_reserves[reserveId].dynamicConfigKey;
170170
}
171-
_dynamicConfig[reserveId][configKey] = dynamicConfig;
172-
emit AddDynamicReserveConfig(reserveId, configKey, dynamicConfig);
173-
return configKey;
171+
_dynamicConfig[reserveId][dynamicConfigKey] = dynamicConfig;
172+
emit AddDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicConfig);
173+
return dynamicConfigKey;
174174
}
175175

176176
/// @inheritdoc ISpoke
177177
function updateDynamicReserveConfig(
178178
uint256 reserveId,
179-
uint16 configKey,
179+
uint16 dynamicConfigKey,
180180
DynamicReserveConfig calldata dynamicConfig
181181
) external restricted {
182182
require(reserveId < _reserveCount, ReserveNotListed());
183-
_validateUpdateDynamicReserveConfig(_dynamicConfig[reserveId][configKey], dynamicConfig);
184-
_dynamicConfig[reserveId][configKey] = dynamicConfig;
185-
emit UpdateDynamicReserveConfig(reserveId, configKey, dynamicConfig);
183+
_validateUpdateDynamicReserveConfig(_dynamicConfig[reserveId][dynamicConfigKey], dynamicConfig);
184+
_dynamicConfig[reserveId][dynamicConfigKey] = dynamicConfig;
185+
emit UpdateDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicConfig);
186186
}
187187

188188
/// @inheritdoc ISpoke
@@ -346,7 +346,7 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
346346
);
347347

348348
DynamicReserveConfig storage collateralDynConfig = _dynamicConfig[collateralReserveId][
349-
_userPositions[user][collateralReserveId].configKey
349+
_userPositions[user][collateralReserveId].dynamicConfigKey
350350
];
351351

352352
bool isUserInDeficit = LiquidationLogic.liquidateUser(
@@ -538,10 +538,10 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
538538
/// @inheritdoc ISpoke
539539
function getDynamicReserveConfig(
540540
uint256 reserveId,
541-
uint16 configKey
541+
uint16 dynamicConfigKey
542542
) external view returns (DynamicReserveConfig memory) {
543543
_getReserve(reserveId);
544-
return _dynamicConfig[reserveId][configKey];
544+
return _dynamicConfig[reserveId][dynamicConfigKey];
545545
}
546546

547547
/// @inheritdoc ISpoke
@@ -617,8 +617,9 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
617617
healthFactorForMaxBonus: _liquidationConfig.healthFactorForMaxBonus,
618618
liquidationBonusFactor: _liquidationConfig.liquidationBonusFactor,
619619
healthFactor: healthFactor,
620-
maxLiquidationBonus: _dynamicConfig[reserveId][_userPositions[user][reserveId].configKey]
621-
.maxLiquidationBonus
620+
maxLiquidationBonus: _dynamicConfig[reserveId][
621+
_userPositions[user][reserveId].dynamicConfigKey
622+
].maxLiquidationBonus
622623
});
623624
}
624625

@@ -708,8 +709,8 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
708709
if (collateral) {
709710
uint256 collateralFactor = _dynamicConfig[reserveId][
710711
refreshConfig
711-
? (userPosition.configKey = reserve.dynamicConfigKey)
712-
: userPosition.configKey
712+
? (userPosition.dynamicConfigKey = reserve.dynamicConfigKey)
713+
: userPosition.dynamicConfigKey
713714
].collateralFactor;
714715
if (collateralFactor > 0) {
715716
uint256 suppliedShares = userPosition.suppliedShares;
@@ -785,7 +786,7 @@ abstract contract Spoke is ISpoke, Multicall, NoncesKeyed, AccessManagedUpgradea
785786
}
786787

787788
function _refreshDynamicConfig(address user, uint256 reserveId) internal {
788-
_userPositions[user][reserveId].configKey = _reserves[reserveId].dynamicConfigKey;
789+
_userPositions[user][reserveId].dynamicConfigKey = _reserves[reserveId].dynamicConfigKey;
789790
emit RefreshSingleUserDynamicConfig(user, reserveId);
790791
}
791792

src/spoke/SpokeConfigurator.sol

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ contract SpokeConfigurator is Ownable2Step, ISpokeConfigurator {
134134
function updateCollateralFactor(
135135
address spoke,
136136
uint256 reserveId,
137-
uint16 configKey,
137+
uint16 dynamicConfigKey,
138138
uint16 collateralFactor
139139
) external onlyOwner {
140140
ISpoke targetSpoke = ISpoke(spoke);
141141
ISpoke.DynamicReserveConfig memory dynamicReserveConfig = targetSpoke.getDynamicReserveConfig(
142142
reserveId,
143-
configKey
143+
dynamicConfigKey
144144
);
145145
dynamicReserveConfig.collateralFactor = collateralFactor;
146-
targetSpoke.updateDynamicReserveConfig(reserveId, configKey, dynamicReserveConfig);
146+
targetSpoke.updateDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicReserveConfig);
147147
}
148148

149149
/// @inheritdoc ISpokeConfigurator
@@ -164,16 +164,16 @@ contract SpokeConfigurator is Ownable2Step, ISpokeConfigurator {
164164
function updateMaxLiquidationBonus(
165165
address spoke,
166166
uint256 reserveId,
167-
uint16 configKey,
167+
uint16 dynamicConfigKey,
168168
uint256 maxLiquidationBonus
169169
) external onlyOwner {
170170
ISpoke targetSpoke = ISpoke(spoke);
171171
ISpoke.DynamicReserveConfig memory dynamicReserveConfig = targetSpoke.getDynamicReserveConfig(
172172
reserveId,
173-
configKey
173+
dynamicConfigKey
174174
);
175175
dynamicReserveConfig.maxLiquidationBonus = maxLiquidationBonus.toUint32();
176-
targetSpoke.updateDynamicReserveConfig(reserveId, configKey, dynamicReserveConfig);
176+
targetSpoke.updateDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicReserveConfig);
177177
}
178178

179179
/// @inheritdoc ISpokeConfigurator
@@ -194,16 +194,16 @@ contract SpokeConfigurator is Ownable2Step, ISpokeConfigurator {
194194
function updateLiquidationFee(
195195
address spoke,
196196
uint256 reserveId,
197-
uint16 configKey,
197+
uint16 dynamicConfigKey,
198198
uint256 liquidationFee
199199
) external onlyOwner {
200200
ISpoke targetSpoke = ISpoke(spoke);
201201
ISpoke.DynamicReserveConfig memory dynamicReserveConfig = targetSpoke.getDynamicReserveConfig(
202202
reserveId,
203-
configKey
203+
dynamicConfigKey
204204
);
205205
dynamicReserveConfig.liquidationFee = liquidationFee.toUint16();
206-
targetSpoke.updateDynamicReserveConfig(reserveId, configKey, dynamicReserveConfig);
206+
targetSpoke.updateDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicReserveConfig);
207207
}
208208

209209
/// @inheritdoc ISpokeConfigurator
@@ -219,10 +219,10 @@ contract SpokeConfigurator is Ownable2Step, ISpokeConfigurator {
219219
function updateDynamicReserveConfig(
220220
address spoke,
221221
uint256 reserveId,
222-
uint16 configKey,
222+
uint16 dynamicConfigKey,
223223
ISpoke.DynamicReserveConfig calldata dynamicConfig
224224
) external onlyOwner {
225-
ISpoke(spoke).updateDynamicReserveConfig(reserveId, configKey, dynamicConfig);
225+
ISpoke(spoke).updateDynamicReserveConfig(reserveId, dynamicConfigKey, dynamicConfig);
226226
}
227227

228228
/// @inheritdoc ISpokeConfigurator

src/spoke/interfaces/ISpoke.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface ISpoke is ISpokeBase, IMulticall, INoncesKeyed, IAccessManaged {
5252
uint128 premiumOffset;
5353
//
5454
uint128 suppliedShares;
55-
uint16 configKey; // key of the last user config
55+
uint16 dynamicConfigKey; // key of the last user config
5656
}
5757

5858
struct PositionManagerConfig {
@@ -100,21 +100,21 @@ interface ISpoke is ISpokeBase, IMulticall, INoncesKeyed, IAccessManaged {
100100
/// key of the reserve. It can be an existing key that was previously used and is now being
101101
/// overridden.
102102
/// @param reserveId The identifier of the reserve.
103-
/// @param configKey The key of the added dynamic config.
103+
/// @param dynamicConfigKey The key of the added dynamic config.
104104
/// @param config The dynamic reserve config.
105105
event AddDynamicReserveConfig(
106106
uint256 indexed reserveId,
107-
uint16 indexed configKey,
107+
uint16 indexed dynamicConfigKey,
108108
DynamicReserveConfig config
109109
);
110110

111111
/// @notice Emitted when a dynamic reserve config is updated.
112112
/// @param reserveId The identifier of the reserve.
113-
/// @param configKey The key of the updated dynamic config.
113+
/// @param dynamicConfigKey The key of the updated dynamic config.
114114
/// @param config The dynamic reserve config.
115115
event UpdateDynamicReserveConfig(
116116
uint256 indexed reserveId,
117-
uint16 indexed configKey,
117+
uint16 indexed dynamicConfigKey,
118118
DynamicReserveConfig config
119119
);
120120

@@ -285,22 +285,22 @@ interface ISpoke is ISpokeBase, IMulticall, INoncesKeyed, IAccessManaged {
285285
/// @dev Appends dynamic config to the next valid config key, and overrides existing config if the key is already used.
286286
/// @param reserveId The identifier of the reserve.
287287
/// @param dynamicConfig The new dynamic reserve config.
288-
/// @return configKey The key of the added dynamic config.
288+
/// @return dynamicConfigKey The key of the added dynamic config.
289289
function addDynamicReserveConfig(
290290
uint256 reserveId,
291291
DynamicReserveConfig calldata dynamicConfig
292-
) external returns (uint16 configKey);
292+
) external returns (uint16 dynamicConfigKey);
293293

294294
/// @notice Updates the dynamic reserve config for a given reserve at the specified key.
295295
/// @dev It reverts if the reserve associated with the given reserve identifier is not listed.
296296
/// @dev Reverts with `ConfigKeyUninitialized` if the config key has not been initialized yet.
297297
/// @dev Reverts with `InvalidCollateralFactor` if the collateral factor is 0.
298298
/// @param reserveId The identifier of the reserve.
299-
/// @param configKey The key of the config to update.
299+
/// @param dynamicConfigKey The key of the config to update.
300300
/// @param dynamicConfig The new dynamic reserve config.
301301
function updateDynamicReserveConfig(
302302
uint256 reserveId,
303-
uint16 configKey,
303+
uint16 dynamicConfigKey,
304304
DynamicReserveConfig calldata dynamicConfig
305305
) external;
306306

@@ -400,12 +400,12 @@ interface ISpoke is ISpokeBase, IMulticall, INoncesKeyed, IAccessManaged {
400400

401401
/// @notice Returns the dynamic reserve configuration struct at the specified key.
402402
/// @dev It reverts if the reserve associated with the given reserve identifier is not listed.
403-
/// @dev Does not revert if `configKey` is unset.
403+
/// @dev Does not revert if `dynamicConfigKey` is unset.
404404
/// @param reserveId The identifier of the reserve.
405-
/// @param configKey The key of the dynamic config.
405+
/// @param dynamicConfigKey The key of the dynamic config.
406406
function getDynamicReserveConfig(
407407
uint256 reserveId,
408-
uint16 configKey
408+
uint16 dynamicConfigKey
409409
) external view returns (DynamicReserveConfig memory);
410410

411411
/// @notice Returns true if the reserve is set as collateral for the user.

src/spoke/interfaces/ISpokeConfigurator.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ interface ISpokeConfigurator {
8585
/// @param spoke The address of the spoke.
8686
/// @param reserveId The identifier of the reserve.
8787
/// @param collateralFactor The new collateral factor.
88-
/// @return The configKey of the added dynamic configuration.
88+
/// @return The dynamicConfigKey of the added dynamic configuration.
8989
function addCollateralFactor(
9090
address spoke,
9191
uint256 reserveId,
@@ -95,20 +95,20 @@ interface ISpokeConfigurator {
9595
/// @notice Updates an existing collateral factor of a reserve at the specified key.
9696
/// @param spoke The address of the spoke.
9797
/// @param reserveId The identifier of the reserve.
98-
/// @param configKey The key of the dynamic config to update.
98+
/// @param dynamicConfigKey The key of the dynamic config to update.
9999
/// @param collateralFactor The new collateral factor.
100100
function updateCollateralFactor(
101101
address spoke,
102102
uint256 reserveId,
103-
uint16 configKey,
103+
uint16 dynamicConfigKey,
104104
uint16 collateralFactor
105105
) external;
106106

107107
/// @notice Adds a dynamic config to a reserve, identical to the latest one but with the specified max liquidation bonus.
108108
/// @param spoke The address of the spoke.
109109
/// @param reserveId The identifier of the reserve.
110110
/// @param maxLiquidationBonus The new max liquidation bonus.
111-
/// @return The configKey of the added dynamic configuration.
111+
/// @return The dynamicConfigKey of the added dynamic configuration.
112112
function addMaxLiquidationBonus(
113113
address spoke,
114114
uint256 reserveId,
@@ -118,20 +118,20 @@ interface ISpokeConfigurator {
118118
/// @notice Updates an existing liquidation bonus of a reserve at the specified key.
119119
/// @param spoke The address of the spoke.
120120
/// @param reserveId The identifier of the reserve.
121-
/// @param configKey The key of the dynamic config to update.
121+
/// @param dynamicConfigKey The key of the dynamic config to update.
122122
/// @param maxLiquidationBonus The new liquidation bonus.
123123
function updateMaxLiquidationBonus(
124124
address spoke,
125125
uint256 reserveId,
126-
uint16 configKey,
126+
uint16 dynamicConfigKey,
127127
uint256 maxLiquidationBonus
128128
) external;
129129

130130
/// @notice Adds a dynamic config to a reserve, identical to the latest one but with the specified liquidation fee.
131131
/// @param spoke The address of the spoke.
132132
/// @param reserveId The identifier of the reserve.
133133
/// @param liquidationFee The new liquidation fee.
134-
/// @return The configKey of the added dynamic configuration.
134+
/// @return The dynamicConfigKey of the added dynamic configuration.
135135
function addLiquidationFee(
136136
address spoke,
137137
uint256 reserveId,
@@ -141,20 +141,20 @@ interface ISpokeConfigurator {
141141
/// @notice Updates an existing liquidation fee of a reserve at the specified key.
142142
/// @param spoke The address of the spoke.
143143
/// @param reserveId The identifier of the reserve.
144-
/// @param configKey The key of the dynamic config to update.
144+
/// @param dynamicConfigKey The key of the dynamic config to update.
145145
/// @param liquidationFee The new liquidation fee.
146146
function updateLiquidationFee(
147147
address spoke,
148148
uint256 reserveId,
149-
uint16 configKey,
149+
uint16 dynamicConfigKey,
150150
uint256 liquidationFee
151151
) external;
152152

153153
/// @notice Adds a dynamic config to a reserve.
154154
/// @param spoke The address of the spoke.
155155
/// @param reserveId The identifier of the reserve.
156156
/// @param dynamicConfig The new dynamic config.
157-
/// @return configKey The key of the added dynamic config.
157+
/// @return dynamicConfigKey The key of the added dynamic config.
158158
function addDynamicReserveConfig(
159159
address spoke,
160160
uint256 reserveId,
@@ -164,12 +164,12 @@ interface ISpokeConfigurator {
164164
/// @notice Updates the dynamic config of a reserve at the specified key.
165165
/// @param spoke The address of the spoke.
166166
/// @param reserveId The identifier of the reserve.
167-
/// @param configKey The key of the dynamic config to update.
167+
/// @param dynamicConfigKey The key of the dynamic config to update.
168168
/// @param dynamicConfig The new dynamic config.
169169
function updateDynamicReserveConfig(
170170
address spoke,
171171
uint256 reserveId,
172-
uint16 configKey,
172+
uint16 dynamicConfigKey,
173173
ISpoke.DynamicReserveConfig calldata dynamicConfig
174174
) external;
175175

0 commit comments

Comments
 (0)