Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/yoVault/yoVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,19 @@ contract yoVault is ERC4626Upgradeable, Compatible, IyoVault, AuthUpgradeable, P
function onUnderlyingBalanceUpdate(uint256 newAggregatedBalance) external requiresAuth {
require(block.number > lastBlockUpdated, Errors.UpdateAlreadyCompletedInThisBlock());

emit UnderlyingBalanceUpdated(aggregatedUnderlyingBalances, newAggregatedBalance);
aggregatedUnderlyingBalances = newAggregatedBalance;

/// @dev the price per share is calculated taking into account the new aggregated underlying balances
uint256 newPricePerShare = convertToAssets(1e18);
uint256 newPricePerShare = _totalAssets(newAggregatedBalance).mulDiv(DENOMINATOR, totalSupply());
uint256 percentageChange = _calculatePercentageChange(lastPricePerShare, newPricePerShare);

/// @dev Pause the vault if the percentage change is greater than the threshold (works in both directions)
if (percentageChange > maxPercentageChange) {
_pause();
return;
}

emit UnderlyingBalanceUpdated(aggregatedUnderlyingBalances, newAggregatedBalance);
aggregatedUnderlyingBalances = newAggregatedBalance;

lastPricePerShare = newPricePerShare;
lastBlockUpdated = block.number;
}
Expand Down Expand Up @@ -275,7 +276,7 @@ contract yoVault is ERC4626Upgradeable, Compatible, IyoVault, AuthUpgradeable, P
/// @notice Override the default `totalAssets` function to return the total assets held by the vault and the
/// aggregated underlying balances across all strategies/chains.
function totalAssets() public view override returns (uint256) {
return IERC20(asset()).balanceOf(address(this)) + aggregatedUnderlyingBalances;
return _totalAssets(aggregatedUnderlyingBalances);
}

/// @dev Override the default `deposit` function to add the `whenNotPaused` modifier.
Expand Down Expand Up @@ -391,6 +392,10 @@ contract yoVault is ERC4626Upgradeable, Compatible, IyoVault, AuthUpgradeable, P
}
}

function _totalAssets(uint256 _underlyingBalances) internal view returns (uint256) {
return IERC20(asset()).balanceOf(address(this)) + _underlyingBalances;
}

//============================== PRIVATE FUNCTIONS ===============================

/// @dev Used to calculate the percentage change between two prices. 1e18 = 100%.
Expand Down
Loading