Skip to content

Commit 386772e

Browse files
avniculaeDhairyaSethiyan-man
authored
rft: risk premium cap -> risk premium threshold (#961)
Co-authored-by: DhairyaSethi <[email protected]> Co-authored-by: YBM <[email protected]>
1 parent 911dddb commit 386772e

23 files changed

+169
-155
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ snapshots
66
report
77
src/dependencies
88
tests/mocks/JsonBindings.sol
9+
tests/misc/prototype

src/hub/Hub.sol

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract Hub is IHub, AccessManaged {
3737
uint40 public constant MAX_ALLOWED_SPOKE_CAP = type(uint40).max;
3838

3939
/// @inheritdoc IHub
40-
uint24 public constant MAX_ALLOWED_RISK_PREMIUM_CAP = type(uint24).max;
40+
uint24 public constant MAX_RISK_PREMIUM_THRESHOLD = type(uint24).max;
4141

4242
uint256 internal _assetCount;
4343
mapping(uint256 assetId => Asset) internal _assets;
@@ -144,7 +144,7 @@ contract Hub is IHub, AccessManaged {
144144
_updateSpokeConfig(
145145
assetId,
146146
asset.feeReceiver,
147-
SpokeConfig({addCap: 0, drawCap: 0, riskPremiumCap: 0, active: true, paused: false})
147+
SpokeConfig({addCap: 0, drawCap: 0, riskPremiumThreshold: 0, active: true, paused: false})
148148
);
149149
asset.feeReceiver = config.feeReceiver;
150150
_addFeeReceiver(assetId, config.feeReceiver);
@@ -632,7 +632,7 @@ contract Hub is IHub, AccessManaged {
632632
SpokeConfig({
633633
addCap: spokeData.addCap,
634634
drawCap: spokeData.drawCap,
635-
riskPremiumCap: spokeData.riskPremiumCap,
635+
riskPremiumThreshold: spokeData.riskPremiumThreshold,
636636
active: spokeData.active,
637637
paused: spokeData.paused
638638
});
@@ -647,7 +647,7 @@ contract Hub is IHub, AccessManaged {
647647
SpokeConfig({
648648
addCap: MAX_ALLOWED_SPOKE_CAP,
649649
drawCap: 0,
650-
riskPremiumCap: 0,
650+
riskPremiumThreshold: 0,
651651
active: true,
652652
paused: false
653653
})
@@ -665,7 +665,7 @@ contract Hub is IHub, AccessManaged {
665665
SpokeData storage spokeData = _spokes[assetId][spoke];
666666
spokeData.addCap = config.addCap;
667667
spokeData.drawCap = config.drawCap;
668-
spokeData.riskPremiumCap = config.riskPremiumCap;
668+
spokeData.riskPremiumThreshold = config.riskPremiumThreshold;
669669
spokeData.active = config.active;
670670
spokeData.paused = config.paused;
671671
emit UpdateSpokeConfig(assetId, spoke, config);
@@ -682,9 +682,8 @@ contract Hub is IHub, AccessManaged {
682682
}
683683

684684
/// @dev Applies premium deltas on asset & spoke premium owed.
685-
/// @dev Checks premium owed does not increase by more than `premiumAmount`.
686-
/// @dev Checks updated risk premium is within allowed limit.
687-
/// @dev Can increase premium by 2 wei due to opposite rounding on premium shares and offset.
685+
/// @dev Checks premium owed does not increase by more than `premiumAmount` + 2 wei (due to opposite rounding on premium shares and offset); reverts with `InvalidPremiumChange()` otherwise.
686+
/// @dev Checks updated risk premium is within allowed threshold; reverts with `InvalidPremiumChange()` otherwise (even if risk premium decreases).
688687
function _applyPremiumDelta(
689688
Asset storage asset,
690689
SpokeData storage spoke,
@@ -713,10 +712,10 @@ contract Hub is IHub, AccessManaged {
713712
premiumAmount
714713
);
715714

716-
uint24 riskPremiumCap = spoke.riskPremiumCap;
715+
uint24 riskPremiumThreshold = spoke.riskPremiumThreshold;
717716
require(
718-
riskPremiumCap == MAX_ALLOWED_RISK_PREMIUM_CAP ||
719-
spoke.premiumShares <= spoke.drawnShares.percentMulUp(riskPremiumCap),
717+
riskPremiumThreshold == MAX_RISK_PREMIUM_THRESHOLD ||
718+
spoke.premiumShares <= spoke.drawnShares.percentMulUp(riskPremiumThreshold),
720719
InvalidPremiumChange()
721720
);
722721
}

src/hub/HubConfigurator.sol

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,15 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
227227
}
228228

229229
/// @inheritdoc IHubConfigurator
230-
function updateSpokeRiskPremiumCap(
230+
function updateSpokeRiskPremiumThreshold(
231231
address hub,
232232
uint256 assetId,
233233
address spoke,
234-
uint256 riskPremiumCap
234+
uint256 riskPremiumThreshold
235235
) external onlyOwner {
236236
IHub targetHub = IHub(hub);
237237
IHub.SpokeConfig memory config = targetHub.getSpokeConfig(assetId, spoke);
238-
config.riskPremiumCap = riskPremiumCap.toUint24();
238+
config.riskPremiumThreshold = riskPremiumThreshold.toUint24();
239239
targetHub.updateSpokeConfig(assetId, spoke, config);
240240
}
241241

@@ -245,10 +245,9 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
245245
uint256 assetId,
246246
address spoke,
247247
uint256 addCap,
248-
uint256 drawCap,
249-
uint256 riskPremiumCap
248+
uint256 drawCap
250249
) external onlyOwner {
251-
_updateSpokeCaps(IHub(hub), assetId, spoke, addCap, drawCap, riskPremiumCap);
250+
_updateSpokeCaps(IHub(hub), assetId, spoke, addCap, drawCap);
252251
}
253252

254253
/// @inheritdoc IHubConfigurator
@@ -306,13 +305,11 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
306305
uint256 assetId,
307306
address spoke,
308307
uint256 addCap,
309-
uint256 drawCap,
310-
uint256 riskPremiumCap
308+
uint256 drawCap
311309
) internal {
312310
IHub.SpokeConfig memory config = hub.getSpokeConfig(assetId, spoke);
313311
config.addCap = addCap.toUint40();
314312
config.drawCap = drawCap.toUint40();
315-
config.riskPremiumCap = riskPremiumCap.toUint24();
316313
hub.updateSpokeConfig(assetId, spoke, config);
317314
}
318315

src/hub/interfaces/IHub.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface IHub is IHubBase, IAccessManaged {
7171
/// @dev addedShares The added shares of a spoke for a given asset.
7272
/// @dev addCap The maximum amount that can be added by a spoke, expressed in whole assets (not scaled by decimals). A value of `MAX_ALLOWED_SPOKE_CAP` indicates no cap.
7373
/// @dev drawCap The maximum amount that can be drawn by a spoke, expressed in whole assets (not scaled by decimals). A value of `MAX_ALLOWED_SPOKE_CAP` indicates no cap.
74-
/// @dev riskPremiumCap The maximum proportion of drawn shares that a spoke can update, expressed in BPS. A value of `MAX_ALLOWED_RISK_PREMIUM_CAP` indicates no cap.
74+
/// @dev riskPremiumThreshold The maximum ratio of premium to drawn shares a spoke can have, expressed in BPS. A value of `MAX_RISK_PREMIUM_THRESHOLD` indicates no threshold.
7575
/// @dev active True if the spoke is prevented from performing any actions.
7676
/// @dev paused True if the spoke is prevented from performing actions that instantly update the liquidity.
7777
/// @dev deficit The deficit reported by a spoke for a given asset, expressed in asset units.
@@ -85,7 +85,7 @@ interface IHub is IHubBase, IAccessManaged {
8585
uint128 addedShares;
8686
uint40 addCap;
8787
uint40 drawCap;
88-
uint24 riskPremiumCap;
88+
uint24 riskPremiumThreshold;
8989
bool active;
9090
bool paused;
9191
//
@@ -96,7 +96,7 @@ interface IHub is IHubBase, IAccessManaged {
9696
struct SpokeConfig {
9797
uint40 addCap;
9898
uint40 drawCap;
99-
uint24 riskPremiumCap;
99+
uint24 riskPremiumThreshold;
100100
bool active;
101101
bool paused;
102102
}
@@ -372,5 +372,8 @@ interface IHub is IHubBase, IAccessManaged {
372372
/// @return The maximum cap value, expressed in asset units.
373373
function MAX_ALLOWED_SPOKE_CAP() external view returns (uint40);
374374

375-
function MAX_ALLOWED_RISK_PREMIUM_CAP() external view returns (uint24);
375+
/// @notice Returns the maximum value for any spoke risk premium threshold.
376+
/// @dev The value is not inclusive; using the maximum value indicates no threshold.
377+
/// @return The maximum risk premium threshold, expressed in BPS.
378+
function MAX_RISK_PREMIUM_THRESHOLD() external view returns (uint24);
376379
}

src/hub/interfaces/IHubConfigurator.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ interface IHubConfigurator {
177177
uint256 drawCap
178178
) external;
179179

180-
/// @notice Updates the risk premium cap of an asset's spoke.
180+
/// @notice Updates the risk premium threshold of an asset's spoke.
181181
/// @param hub The address of the Hub contract.
182182
/// @param assetId The identifier of the asset.
183183
/// @param spoke The address of the spoke.
184-
/// @param riskPremiumCap The new risk premium cap.
185-
function updateSpokeRiskPremiumCap(
184+
/// @param riskPremiumThreshold The new risk premium threshold.
185+
function updateSpokeRiskPremiumThreshold(
186186
address hub,
187187
uint256 assetId,
188188
address spoke,
189-
uint256 riskPremiumCap
189+
uint256 riskPremiumThreshold
190190
) external;
191191

192192
/// @notice Updates the caps of an asset's spoke.
@@ -195,14 +195,12 @@ interface IHubConfigurator {
195195
/// @param spoke The address of the spoke.
196196
/// @param addCap The new supply cap.
197197
/// @param drawCap The new draw cap.
198-
/// @param riskPremiumCap The new risk premium cap.
199198
function updateSpokeCaps(
200199
address hub,
201200
uint256 assetId,
202201
address spoke,
203202
uint256 addCap,
204-
uint256 drawCap,
205-
uint256 riskPremiumCap
203+
uint256 drawCap
206204
) external;
207205

208206
/// @notice Deactivates all assets of a spoke on a specified hub by setting the active flag to false.

src/spoke/interfaces/ISpokeBase.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ interface ISpokeBase {
5959
);
6060

6161
/// @dev Emitted when a borrower is liquidated.
62-
/// @param collateralAssetId The identifier of the asset used as collateral, to receive as result of the liquidation.
63-
/// @param debtAssetId The identifier of the asset to be repaid with the liquidation.
62+
/// @param collateralReserveId The identifier of the reserve used as collateral, to receive as a result of the liquidation.
63+
/// @param debtReserveId The identifier of the reserve to be repaid with the liquidation.
6464
/// @param user The address of the borrower getting liquidated.
65-
/// @param liquidatedDebt The debt amount of borrowed asset to be liquidated.
66-
/// @param liquidatedCollateral The amount of collateral received by the liquidator.
65+
/// @param debtToLiquidate The debt amount of borrowed reserve to be liquidated.
66+
/// @param collateralToLiquidate The total amount of collateral asset to be liquidated, inclusive of liquidation fee.
6767
/// @param liquidator The address of the liquidator.
68-
/// @param receiveShares Whether the liquidator receives collateral in supplied shares or in underlying assets.
68+
/// @param receiveShares True if the liquidator receives collateral in supplied shares rather than underlying assets.
6969
event LiquidationCall(
70-
uint256 indexed collateralAssetId,
71-
uint256 indexed debtAssetId,
70+
uint256 indexed collateralReserveId,
71+
uint256 indexed debtReserveId,
7272
address indexed user,
73-
uint256 liquidatedDebt,
74-
uint256 liquidatedCollateral,
73+
uint256 debtToLiquidate,
74+
uint256 collateralToLiquidate,
7575
address liquidator,
7676
bool receiveShares
7777
);

tests/Base.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ abstract contract Base is Test {
428428
paused: false,
429429
addCap: Constants.MAX_ALLOWED_SPOKE_CAP,
430430
drawCap: Constants.MAX_ALLOWED_SPOKE_CAP,
431-
riskPremiumCap: Constants.MAX_ALLOWED_COLLATERAL_RISK
431+
riskPremiumThreshold: Constants.MAX_ALLOWED_COLLATERAL_RISK
432432
});
433433

434434
bytes memory encodedIrData = abi.encode(
@@ -1264,14 +1264,14 @@ abstract contract Base is Test {
12641264
assertEq(hub.getSpokeConfig(assetId, spoke), spokeConfig);
12651265
}
12661266

1267-
function _updateSpokeRiskPremiumCap(
1267+
function _updateSpokeRiskPremiumThreshold(
12681268
IHub hub,
12691269
uint256 assetId,
12701270
address spoke,
1271-
uint24 newRiskPremiumCap
1271+
uint24 newRiskPremiumThreshold
12721272
) internal pausePrank {
12731273
IHub.SpokeConfig memory spokeConfig = hub.getSpokeConfig(assetId, spoke);
1274-
spokeConfig.riskPremiumCap = newRiskPremiumCap;
1274+
spokeConfig.riskPremiumThreshold = newRiskPremiumThreshold;
12751275
vm.prank(HUB_ADMIN);
12761276
hub.updateSpokeConfig(assetId, spoke, spokeConfig);
12771277

@@ -2077,7 +2077,7 @@ abstract contract Base is Test {
20772077
function assertEq(IHub.SpokeConfig memory a, IHub.SpokeConfig memory b) internal pure {
20782078
assertEq(a.addCap, b.addCap, 'addCap');
20792079
assertEq(a.drawCap, b.drawCap, 'drawCap');
2080-
assertEq(a.riskPremiumCap, b.riskPremiumCap, 'riskPremiumCap');
2080+
assertEq(a.riskPremiumThreshold, b.riskPremiumThreshold, 'riskPremiumThreshold');
20812081
assertEq(a.active, b.active, 'active');
20822082
assertEq(a.paused, b.paused, 'paused');
20832083
assertEq(abi.encode(a), abi.encode(b));

tests/Constants.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ library Constants {
77
uint8 public constant MAX_ALLOWED_UNDERLYING_DECIMALS = 18;
88
uint8 public constant MIN_ALLOWED_UNDERLYING_DECIMALS = 6;
99
uint40 public constant MAX_ALLOWED_SPOKE_CAP = type(uint40).max;
10-
uint24 public constant MAX_ALLOWED_RISK_PREMIUM_CAP = type(uint24).max; // 167772.15%
10+
uint24 public constant MAX_RISK_PREMIUM_THRESHOLD = type(uint24).max; // 167772.15%
1111

1212
/// @dev Spoke Constants
1313
uint8 public constant ORACLE_DECIMALS = 8;

0 commit comments

Comments
 (0)