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

Changes on stata initializations, to follow more strict guidelines #11

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {IERC20AaveLM} from './interfaces/IERC20AaveLM.sol';

/**
* @title ERC20AaveLMUpgradeable.sol
* @notice Wrapper smart contract that supports tracking and claiming liquidity mining rewards from the Aave system.
* @notice Wrapper smart contract that supports tracking and claiming liquidity mining rewards from the Aave system
* @dev ERC20 extension, so ERC20 initialization should be done by the children contract/s
* @author BGD labs
*/
abstract contract ERC20AaveLMUpgradeable is ERC20Upgradeable, IERC20AaveLM {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import {IERC4626StataToken} from './interfaces/IERC4626StataToken.sol';
* @title ERC4626StataTokenUpgradeable.sol.sol
* @notice Wrapper smart contract that allows to deposit tokens on the Aave protocol and receive
* a token which balance doesn't increase automatically, but uses an ever-increasing exchange rate.
* @dev ERC20 extension, so ERC20 initialization should be done by the children contract/s
* @author BGD labs
*/
abstract contract ERC4626StataTokenUpgradeable is ERC4626Upgradeable, IERC4626StataToken {
using Math for uint256;

/// @custom:storage-location erc7201:aave-dao.storage.Stata4626
/// @custom:storage-location erc7201:aave-dao.storage.ERC4626StataToken
struct ERC4626StataTokenStorage {
IERC20 _aToken;
}
Expand Down Expand Up @@ -51,22 +52,25 @@ abstract contract ERC4626StataTokenUpgradeable is ERC4626Upgradeable, IERC4626St
}

function __ERC4626StataToken_init(address newAToken) internal onlyInitializing {
// TODO: maybe to do some movements here
__ERC4626StataToken_init_unchained(newAToken);
IERC20 aTokenUnderlying = __ERC4626StataToken_init_unchained(newAToken);
__ERC4626_init_unchained(aTokenUnderlying);
}

function __ERC4626StataToken_init_unchained(address newAToken) internal onlyInitializing {
function __ERC4626StataToken_init_unchained(
address newAToken
) internal onlyInitializing returns (IERC20) {
// sanity check, to be sure that we support that version of the aToken
address poolOfAToken = IAToken(newAToken).POOL();
if (poolOfAToken != address(POOL)) revert PoolAddressMismatch(poolOfAToken);

IERC20 aTokenUnderlying = IERC20(IAToken(newAToken).UNDERLYING_ASSET_ADDRESS());
__ERC4626_init(aTokenUnderlying);

ERC4626StataTokenStorage storage $ = _getERC4626StataTokenStorage();
$._aToken = IERC20(newAToken);

SafeERC20.forceApprove(aTokenUnderlying, address(POOL), type(uint256).max);

return aTokenUnderlying;
}

///@inheritdoc IERC4626StataToken
Expand Down
2 changes: 2 additions & 0 deletions src/periphery/contracts/static-a-token/StataTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ contract StataTokenV2 is
}

function decimals() public view override(ERC20Upgradeable, ERC4626Upgradeable) returns (uint8) {
/// @notice The initialization of ERC4626Upgradeable already assures that decimal are
/// the same as the underlying asset of the StataTokenV2, e.g. decimals of WETH for stataWETH
return ERC4626Upgradeable.decimals();
}

Expand Down