Ex-rate calculation
getExchangeRate()
/// @notice Returns the unit 'exchange rate'; assuming 1 unit of underlying was deposited, how much shares would be received
/// @dev wrapperMinted = (underlyingDeposited,(1) * wrapperSupply) / underlyingInWrapper
/// Note: Exchange rate is floating, it's dynamic based on capital in/out-flows
/// Note: _totalSupply returns a value extended over decimal precision, in this case 18 dp. hence the scaling before divsion.
function getExchangeRate() internal view returns(uint256) {
uint256 sharesMinted;
return _totalSupply == 0 ? sharesMinted = 1e18 : sharesMinted = (_totalSupply * 1e18) / underlying.balanceOf(address(this));
}
/// @notice Calculate how much yvDAI user should get based on flaoting exchange rate
/// @dev getExchangeRate() returns shares minted per unit of underlying asset deposited; at present moment.
/// @param assets Amount of underlying tokens (assets) to be converted to wrapped tokens (shares)
function convertToShares(uint256 assets) internal view returns(uint256 shares){
return assets * getExchangeRate() / 1e18;
}
/// @notice Calculate how much DAI user should get based on floating exchange rate
/// @dev getExchangeRate() returns shares minted per unit of underlying asset deposited; at present moment.
/// @param shares Amount of wrapped tokens (shares) to be converted to underlying tokens (assets)
function convertToAssets(uint256 shares) internal view returns(uint256 assets){
return shares * 1e18 / getExchangeRate();
}totalSupply
Last updated