Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give _fromUnderlyingAmount a home #2030

Open
hellwolf opened this issue Oct 16, 2024 · 0 comments
Open

Give _fromUnderlyingAmount a home #2030

hellwolf opened this issue Oct 16, 2024 · 0 comments

Comments

@hellwolf
Copy link
Contributor

hellwolf commented Oct 16, 2024

    // 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;
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@hellwolf and others