Skip to content

Commit 05c8ac0

Browse files
authored
[OUSD-16] Miscellaneous General Comments (#2788)
* replace interface to fetch decimals * add comment * add link to readme * removed TODO * rename oUSD to oToken * add function for reverse compatibility and mark deprecated * rename
1 parent 327a6eb commit 05c8ac0

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

contracts/contracts/strategies/BridgedWOETHStrategy.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ contract BridgedWOETHStrategy is InitializableAbstractStrategy {
267267
_asset != address(bridgedWOETH) && _asset != address(weth),
268268
"Cannot transfer supported asset"
269269
);
270+
// Use SafeERC20 only for rescuing unknown assets; core tokens are standard.
270271
IERC20(_asset).safeTransfer(governor(), _amount);
271272
}
272273

contracts/contracts/vault/VaultCore.sol

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ abstract contract VaultCore is VaultInitializer {
8585
}
8686

8787
// Mint oTokens
88-
oUSD.mint(msg.sender, scaledAmount);
88+
oToken.mint(msg.sender, scaledAmount);
8989

9090
IERC20(asset).safeTransferFrom(msg.sender, address(this), _amount);
9191

@@ -129,14 +129,13 @@ abstract contract VaultCore is VaultInitializer {
129129

130130
emit Mint(msg.sender, _amount);
131131
// Mint matching amount of OTokens
132-
oUSD.mint(msg.sender, _amount);
132+
oToken.mint(msg.sender, _amount);
133133
}
134134

135135
/**
136136
* @notice Burn OTokens for an allowed Strategy
137137
* @param _amount Amount of OToken to burn
138138
*
139-
* Todo: Maybe this is a comment that we can remove now?
140139
* @dev Notice: can't use `nonReentrant` modifier since the `redeem` function could
141140
* require withdrawal on an AMO strategy and that one can call `burnForStrategy`
142141
* while the execution of the `redeem` has not yet completed -> causing a `nonReentrant` collision.
@@ -163,7 +162,7 @@ abstract contract VaultCore is VaultInitializer {
163162
emit Redeem(msg.sender, _amount);
164163

165164
// Burn OTokens
166-
oUSD.burn(msg.sender, _amount);
165+
oToken.burn(msg.sender, _amount);
167166
}
168167

169168
////////////////////////////////////////////////////
@@ -215,7 +214,7 @@ abstract contract VaultCore is VaultInitializer {
215214
});
216215

217216
// Burn the user's OToken
218-
oUSD.burn(msg.sender, _amount);
217+
oToken.burn(msg.sender, _amount);
219218

220219
// Prevent withdrawal if the vault is solvent by more than the allowed percentage
221220
_postRedeem(_amount);
@@ -362,7 +361,7 @@ abstract contract VaultCore is VaultInitializer {
362361

363362
// Allow a max difference of maxSupplyDiff% between
364363
// asset value and OUSD total supply
365-
uint256 diff = oUSD.totalSupply().divPrecisely(totalUnits);
364+
uint256 diff = oToken.totalSupply().divPrecisely(totalUnits);
366365
require(
367366
(diff > 1e18 ? diff - 1e18 : 1e18 - diff) <= maxSupplyDiff,
368367
"Backing supply liquidity error"
@@ -396,7 +395,7 @@ abstract contract VaultCore is VaultInitializer {
396395
if (assetAvailableInVault == 0) return;
397396

398397
// Calculate the target buffer for the vault using the total supply
399-
uint256 totalSupply = oUSD.totalSupply();
398+
uint256 totalSupply = oToken.totalSupply();
400399
// Scaled to asset decimals
401400
uint256 targetBuffer = totalSupply.mulTruncate(vaultBuffer).scaleBy(
402401
assetDecimals,
@@ -432,7 +431,7 @@ abstract contract VaultCore is VaultInitializer {
432431
* @return totalUnits Total balance of Vault in units
433432
*/
434433
function _rebase() internal whenNotRebasePaused returns (uint256) {
435-
uint256 supply = oUSD.totalSupply();
434+
uint256 supply = oToken.totalSupply();
436435
uint256 vaultValue = _totalValue();
437436
// If no supply yet, do not rebase
438437
if (supply == 0) {
@@ -457,15 +456,15 @@ abstract contract VaultCore is VaultInitializer {
457456
fee = (yield * trusteeFeeBps) / 1e4;
458457
if (fee > 0) {
459458
require(fee < yield, "Fee must not be greater than yield");
460-
oUSD.mint(_trusteeAddress, fee);
459+
oToken.mint(_trusteeAddress, fee);
461460
}
462461
}
463462
emit YieldDistribution(_trusteeAddress, yield, fee);
464463

465464
// Only ratchet OToken supply upwards
466465
// Final check uses latest totalSupply
467-
if (newSupply > oUSD.totalSupply()) {
468-
oUSD.changeSupply(newSupply);
466+
if (newSupply > oToken.totalSupply()) {
467+
oToken.changeSupply(newSupply);
469468
}
470469
return vaultValue;
471470
}
@@ -476,17 +475,22 @@ abstract contract VaultCore is VaultInitializer {
476475
* @return yield amount of expected yield
477476
*/
478477
function previewYield() external view returns (uint256 yield) {
479-
(yield, ) = _nextYield(oUSD.totalSupply(), _totalValue());
478+
(yield, ) = _nextYield(oToken.totalSupply(), _totalValue());
480479
return yield;
481480
}
482481

482+
/**
483+
* @dev Calculates the amount that would rebase at next rebase.
484+
* See this Readme for detailed explanation:
485+
* contracts/contracts/vault/README - Yield Limits.md
486+
*/
483487
function _nextYield(uint256 supply, uint256 vaultValue)
484488
internal
485489
view
486490
virtual
487491
returns (uint256 yield, uint256 targetRate)
488492
{
489-
uint256 nonRebasing = oUSD.nonRebasingSupply();
493+
uint256 nonRebasing = oToken.nonRebasingSupply();
490494
uint256 rebasing = supply - nonRebasing;
491495
uint256 elapsed = block.timestamp - lastRebase;
492496
targetRate = rebasePerSecondTarget;

contracts/contracts/vault/VaultInitializer.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract contract VaultInitializer is VaultStorage {
1515
function initialize(address _oToken) external onlyGovernor initializer {
1616
require(_oToken != address(0), "oToken address is zero");
1717

18-
oUSD = OUSD(_oToken);
18+
oToken = OUSD(_oToken);
1919

2020
rebasePaused = false;
2121
capitalPaused = true;

contracts/contracts/vault/VaultStorage.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
1212
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
1313

1414
import { IStrategy } from "../interfaces/IStrategy.sol";
15-
import { IWETH9 } from "../interfaces/IWETH9.sol";
15+
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
1616
import { Governable } from "../governance/Governable.sol";
1717
import { OUSD } from "../token/OUSD.sol";
1818
import { Initializable } from "../utils/Initializable.sol";
@@ -95,7 +95,7 @@ abstract contract VaultStorage is Initializable, Governable {
9595
uint256 public rebaseThreshold;
9696

9797
/// @dev Address of the OToken token. eg OUSD or OETH.
98-
OUSD public oUSD;
98+
OUSD public oToken;
9999

100100
/// @dev Address of the contract responsible for post rebase syncs with AMMs
101101
address private _deprecated_rebaseHooksAddr = address(0);
@@ -217,9 +217,15 @@ abstract contract VaultStorage is Initializable, Governable {
217217
// slither-disable-end uninitialized-state
218218

219219
constructor(address _asset) {
220-
uint8 _decimals = IWETH9(_asset).decimals();
220+
uint8 _decimals = IERC20Metadata(_asset).decimals();
221221
require(_decimals <= 18, "invalid asset decimals");
222222
asset = _asset;
223223
assetDecimals = _decimals;
224224
}
225+
226+
227+
/// @notice Deprecated: use `oToken()` instead.
228+
function oUSD() external view returns (OUSD) {
229+
return oToken;
230+
}
225231
}

0 commit comments

Comments
 (0)