Skip to content

Commit

Permalink
Merge pull request #11 from bgd-labs/feat/stata-oz-extensions-standards
Browse files Browse the repository at this point in the history
Changes on stata initializations, to follow more strict guidelines
  • Loading branch information
kyzia551 authored Aug 14, 2024
2 parents 24ede0b + 425c7db commit 589abf9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit 589abf9

Please sign in to comment.