Skip to content

Commit

Permalink
Inherit asset decimals in ERC4626 (OpenZeppelin#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx authored and JulissaDantes committed Nov 4, 2022
1 parent 6ff283b commit 41ca215
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -59,6 +59,10 @@

* `TimelockController`: During deployment, the TimelockController used to grant the `TIMELOCK_ADMIN_ROLE` to the deployer and to the timelock itself. The deployer was then expected to renounce this role once configuration of the timelock is over. Failing to renounce that role allows the deployer to change the timelock permissions (but not to bypass the delay for any time-locked actions). The role is no longer given to the deployer by default. A new parameter `admin` can be set to a non-zero address to grant the admin role during construction (to the deployer or any other address). Just like previously, this admin role should be renounced after configuration. If this param is given `address(0)`, the role is not allocated and doesn't need to be revoked. In any case, the timelock itself continues to have this role.

### Breaking changes

* `ERC4626`: Conversion from shares to assets (and vice-versa) in an empty vault used to consider the possible mismatch between the underlying asset's and the vault's decimals. This initial conversion rate is now set to 1-to-1 irrespective of decimals, which are meant for usability purposes only. The vault now uses the assets decimals by default, so off-chain the numbers should appear the same. Developers overriding the vault decimals to a value that does not match the underlying asset may want to override the `_initialConvertToShares` and `_initialConvertToAssets` to replicate the previous behavior.

### Deprecations

* `EIP712`: Added the file `EIP712.sol` and deprecated `draft-EIP712.sol` since the EIP is no longer a Draft. Developers are encouraged to update their imports. ([#3621](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3621))
Expand Down
6 changes: 6 additions & 0 deletions contracts/token/ERC20/extensions/ERC4626.sol
Expand Up @@ -36,6 +36,12 @@ abstract contract ERC4626 is ERC20, IERC4626 {
(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
_decimals = success ? assetDecimals : super.decimals();
_asset = asset_;
_decimals = decimals_;
}

/** @dev See {IERC20Metadata-decimals}. */
function decimals() public view virtual override(IERC20Metadata, ERC20) returns (uint8) {
return _decimals;
}

/**
Expand Down

0 comments on commit 41ca215

Please sign in to comment.