Skip to content

Commit c651ae9

Browse files
authored
feat: remove permissionless updateUserRiskPremium logic (#722)
1 parent d16d9d6 commit c651ae9

File tree

4 files changed

+23
-81
lines changed

4 files changed

+23
-81
lines changed

snapshots/Spoke.Operations.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"borrow: first": "248096",
3-
"borrow: second action, same reserve": "211568",
4-
"liquidationCall: full": "316501",
5-
"liquidationCall: partial": "340172",
6-
"permitReserve + repay (multicall)": "268517",
7-
"permitReserve + supply (multicall)": "140632",
8-
"permitReserve + supply + enable collateral (multicall)": "174117",
9-
"repay: full": "172778",
10-
"repay: partial": "227277",
2+
"borrow: first": "248044",
3+
"borrow: second action, same reserve": "211516",
4+
"liquidationCall: full": "316449",
5+
"liquidationCall: partial": "340120",
6+
"permitReserve + repay (multicall)": "268464",
7+
"permitReserve + supply (multicall)": "140631",
8+
"permitReserve + supply + enable collateral (multicall)": "174116",
9+
"repay: full": "172756",
10+
"repay: partial": "227225",
1111
"setUserPositionManagerWithSig: disable": "42808",
1212
"setUserPositionManagerWithSig: enable": "66831",
1313
"supply + enable collateral (multicall)": "152550",
@@ -17,12 +17,12 @@
1717
"supply: second action, same reserve": "102491",
1818
"updateUserDynamicConfig: 1 collateral": "53152",
1919
"updateUserDynamicConfig: 2 collaterals": "58433",
20-
"updateUserRiskPremium: 1 borrow": "121368",
21-
"updateUserRiskPremium: 2 borrows": "157278",
20+
"updateUserRiskPremium: 1 borrow": "121382",
21+
"updateUserRiskPremium: 2 borrows": "157262",
2222
"usingAsCollateral: 0 borrows, enable": "54026",
23-
"usingAsCollateral: 1 borrow, disable": "131660",
23+
"usingAsCollateral: 1 borrow, disable": "131608",
2424
"usingAsCollateral: 1 borrow, enable": "24786",
25-
"withdraw: 0 borrows, full": "135190",
26-
"withdraw: 0 borrows, partial": "137293",
27-
"withdraw: 1 borrow, partial": "238008"
25+
"withdraw: 0 borrows, full": "135168",
26+
"withdraw: 0 borrows, partial": "137271",
27+
"withdraw: 1 borrow, partial": "237956"
2828
}

src/contracts/Spoke.sol

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,10 @@ contract Spoke is ISpoke, Multicall, AccessManaged, EIP712 {
394394

395395
/// @inheritdoc ISpoke
396396
function updateUserRiskPremium(address onBehalfOf) external {
397-
DataTypes.UserAccountData memory userAccountData = _calculateUserAccountData(onBehalfOf);
398-
bool premiumIncrease = _notifyRiskPremiumUpdate(onBehalfOf, userAccountData.userRiskPremium);
399-
400-
// check permissions if premium increases and not called by user
401-
if (premiumIncrease && !_isPositionManager({user: onBehalfOf, manager: msg.sender})) {
397+
if (!_isPositionManager({user: onBehalfOf, manager: msg.sender})) {
402398
_checkCanCall(msg.sender, msg.data);
403399
}
400+
_notifyRiskPremiumUpdate(onBehalfOf, _calculateUserAccountData(onBehalfOf).userRiskPremium);
404401
}
405402

406403
/// @inheritdoc ISpoke
@@ -916,17 +913,12 @@ contract Spoke is ISpoke, Multicall, AccessManaged, EIP712 {
916913
* @dev Trigger risk premium update on all drawn reserves of `user`.
917914
* @param user The address of the user whose risk premium is being updated.
918915
* @param newUserRiskPremium The new risk premium of the user.
919-
* @return premiumIncrease True if the risk premium increased, false otherwise.
920916
*/
921-
function _notifyRiskPremiumUpdate(
922-
address user,
923-
uint256 newUserRiskPremium
924-
) internal returns (bool) {
917+
function _notifyRiskPremiumUpdate(address user, uint256 newUserRiskPremium) internal {
925918
uint256 reserveCount = _reserveCount;
926919
DataTypes.PositionStatus storage positionStatus = _positionStatus[user];
927920

928921
uint256 reserveId;
929-
bool premiumIncrease;
930922
while (
931923
(reserveId = positionStatus.nextBorrowing(reserveId, reserveCount)) !=
932924
PositionStatus.NOT_FOUND
@@ -957,15 +949,11 @@ contract Spoke is ISpoke, Multicall, AccessManaged, EIP712 {
957949
realizedDelta: accruedUserPremium.toInt256()
958950
});
959951

960-
if (!premiumIncrease) premiumIncrease = premiumDelta.sharesDelta > 0;
961-
962952
hub.refreshPremium(assetId, premiumDelta);
963953
emit RefreshPremiumDebt(reserveId, user, premiumDelta);
964954
reserveId = reserveId.uncheckedAdd(1);
965955
}
966956
emit UserRiskPremiumUpdate(user, newUserRiskPremium);
967-
968-
return premiumIncrease;
969957
}
970958

971959
/**

src/interfaces/ISpoke.sol

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,14 @@ interface ISpoke is ISpokeBase, IMulticall, IAccessManaged {
193193
) external;
194194

195195
/**
196-
* @notice Allows updating the risk premium on user position.
197-
* @dev If the risk premium has increased, the caller must be `user`, an authorized position manager
198-
* of `user`, or admin.
199-
* @param user The address of the user.
196+
* @notice Allows updating the risk premium on onBehalfOf position.
197+
* @dev Caller must be `onBehalfOf`, an authorized position manager for `onBehalfOf`, or admin.
198+
* @param onBehalfOf The owner of the position being modified.
200199
*/
201-
function updateUserRiskPremium(address user) external;
200+
function updateUserRiskPremium(address onBehalfOf) external;
202201

203202
/**
204-
* @notice Allows updating the dynamic configuration for all collateral reserves of a user position.
203+
* @notice Allows updating the dynamic configuration for all collateral reserves on onBehalfOf position.
205204
* @dev Caller must be `onBehalfOf`, an authorized position manager for `onBehalfOf`, or admin.
206205
* @param onBehalfOf The owner of the position being modified.
207206
*/

tests/unit/Spoke/Spoke.UpdateUserRiskPremium.t.sol

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)