Skip to content

Commit 395690f

Browse files
committed
feat: sGHO ready for review
1 parent 05eb815 commit 395690f

File tree

4 files changed

+317
-107
lines changed

4 files changed

+317
-107
lines changed

src/contracts/extensions/sgho/interfaces/IsGHO.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ interface IsGHO {
3737
* @dev Throws if the GHO token is being rescued.
3838
*/
3939
error CannotRescueGHO();
40-
40+
41+
/**
42+
* @dev Throws if the rate is greater than 50%.
43+
*/
44+
error RateMustBeLessThan50Percent();
45+
4146
// --- State Variables (as view functions) ---
4247

4348
/**

src/contracts/extensions/sgho/sGHO.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ contract sGHO is ERC4626, ERC20Permit, Initializable, IsGHO {
282282
) internal view virtual override returns (uint256) {
283283
uint256 currentYieldIndex = _getCurrentYieldIndex();
284284
if (currentYieldIndex == 0) return 0;
285-
return Math.mulDiv(assets, WadRayMath.RAY, currentYieldIndex, rounding);
285+
return assets.mulDiv(WadRayMath.RAY, currentYieldIndex, rounding);
286286
}
287287

288288
function _convertToAssets(
289289
uint256 shares,
290290
Math.Rounding rounding
291291
) internal view virtual override returns (uint256) {
292292
uint256 currentYieldIndex = _getCurrentYieldIndex();
293-
return Math.mulDiv(shares, currentYieldIndex, WadRayMath.RAY, rounding);
293+
return shares.mulDiv(currentYieldIndex, WadRayMath.RAY, rounding);
294294
}
295295

296296
/**
@@ -304,11 +304,11 @@ contract sGHO is ERC4626, ERC20Permit, Initializable, IsGHO {
304304

305305

306306
// Calculate the rate per second based on the target rate
307-
uint256 annualRateRay = targetRate.rayMul(WadRayMath.RAY).rayDiv(10000);
307+
uint256 annualRateRay = targetRate.rayMul(WadRayMath.RAY);
308308
uint256 currentRatePerSecond = annualRateRay.rayDiv(ONE_YEAR);
309309

310310
// Calculate the index change per second
311-
uint256 currentIndexChangePerSecond = yieldIndex.rayMul(currentRatePerSecond);
311+
uint256 currentIndexChangePerSecond = yieldIndex.rayMul(currentRatePerSecond).rayDiv(10000);
312312

313313
uint256 yieldIndexChange = currentIndexChangePerSecond.rayMul(timeSinceLastUpdate);
314314

@@ -325,12 +325,12 @@ contract sGHO is ERC4626, ERC20Permit, Initializable, IsGHO {
325325
if (timeSinceLastUpdate == 0) return;
326326

327327
// Calculate the rate per second based on the target rate
328-
uint256 annualRateRay = targetRate.rayMul(WadRayMath.RAY).rayDiv(10000);
328+
uint256 annualRateRay = targetRate.rayMul(WadRayMath.RAY);
329329

330330
uint256 currentRatePerSecond = annualRateRay.rayDiv(ONE_YEAR);
331331

332332
// Calculate the index change per second
333-
uint256 currentIndexChangePerSecond = yieldIndex.rayMul(currentRatePerSecond);
333+
uint256 currentIndexChangePerSecond = yieldIndex.rayMul(currentRatePerSecond).rayDiv(10000);
334334

335335
uint256 yieldIndexChange = currentIndexChangePerSecond.rayMul(timeSinceLastUpdate);
336336
// Update the yield index
@@ -354,6 +354,7 @@ contract sGHO is ERC4626, ERC20Permit, Initializable, IsGHO {
354354
*/
355355
function setTargetRate(uint256 newRate) public onlyYieldManager {
356356
// Update the yield index before changing the rate to ensure proper accrual
357+
if(newRate > 5000) revert RateMustBeLessThan50Percent();
357358
_updateYieldIndex();
358359
targetRate = newRate;
359360
}

0 commit comments

Comments
 (0)