// this should be in SuperToken.sol
uint8 private constant _STANDARD_DECIMALS = 18;
function _fromUnderlyingAmount(ISuperToken superToken, uint256 amount)
private
view
returns (uint256 superTokenAmount, uint256 adjustedAmount)
{
uint256 factor;
uint8 _underlyingDecimals = superToken.getUnderlyingDecimals();
if (_underlyingDecimals < _STANDARD_DECIMALS) {
factor = 10 ** (_STANDARD_DECIMALS - _underlyingDecimals);
superTokenAmount = amount * factor;
adjustedAmount = amount;
} else if (_underlyingDecimals > _STANDARD_DECIMALS) {
factor = 10 ** (_underlyingDecimals - _STANDARD_DECIMALS);
superTokenAmount = amount / factor;
adjustedAmount = superTokenAmount * factor;
} else {
superTokenAmount = adjustedAmount = amount;
}
}
}