Skip to content

Commit

Permalink
rename merger and 4626 contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
kyzia551 committed Aug 14, 2024
1 parent 08c95d1 commit cef08a2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import '../../interfaces/IMarketReportTypes.sol';
import {TransparentProxyFactory, ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {StataMerger} from 'aave-v3-periphery/contracts/static-a-token/StataMerger.sol';
import {StataTokenV2} from 'aave-v3-periphery/contracts/static-a-token/StataTokenV2.sol';
import {StaticATokenFactory} from 'aave-v3-periphery/contracts/static-a-token/StaticATokenFactory.sol';
import {IErrors} from '../../interfaces/IErrors.sol';

Expand All @@ -17,7 +17,7 @@ contract AaveV3HelpersProcedureTwo is IErrors {

staticATokenReport.transparentProxyFactory = address(new TransparentProxyFactory());
staticATokenReport.staticATokenImplementation = address(
new StataMerger(IPool(pool), IRewardsController(rewardsController))
new StataTokenV2(IPool(pool), IRewardsController(rewardsController))
);
staticATokenReport.staticATokenFactoryImplementation = address(
new StaticATokenFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ import {IAToken} from './interfaces/IAToken.sol';
import {IStata4626} from './interfaces/IStata4626.sol';

/**
* @title Stata4626Upgradable
* @title ERC4626StataTokenUpgradable.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.
* @author BGD labs
*/
abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
abstract contract ERC4626StataTokenUpgradable is ERC4626Upgradeable, IStata4626 {
using Math for uint256;

/// @custom:storage-location erc7201:aave-dao.storage.Stata4626
struct Stata4626Storage {
struct ERC4626StataTokenStorage {
IERC20 _aToken;
}

// keccak256(abi.encode(uint256(keccak256("aave-dao.storage.Stata4626")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant Stata4626StorageLocation =
0x4865e395e8f896b2ca01e8489fd809975f6c70c69fd3d1cf5d2263a21a649200;
// keccak256(abi.encode(uint256(keccak256("aave-dao.storage.ERC4626StataToken")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC4626StataTokenStorageLocation =
0x55029d3f54709e547ed74b2fc842d93107ab1490ab7555dd9dd0bf6451101900;

function _getStata4626Storage() private pure returns (Stata4626Storage storage $) {
function _getERC4626StataTokenStorage()
private
pure
returns (ERC4626StataTokenStorage storage $)
{
assembly {
$.slot := Stata4626StorageLocation
$.slot := ERC4626StataTokenStorageLocation
}
}

Expand Down Expand Up @@ -60,7 +64,7 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
IERC20 aTokenUnderlying = IERC20(IAToken(newAToken).UNDERLYING_ASSET_ADDRESS());
__ERC4626_init(aTokenUnderlying);

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

SafeERC20.forceApprove(aTokenUnderlying, address(POOL), type(uint256).max);
Expand All @@ -83,7 +87,7 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
bool depositToAave
) public returns (uint256) {
// TODO: add tests
Stata4626Storage storage $ = _getStata4626Storage();
ERC4626StataTokenStorage storage $ = _getERC4626StataTokenStorage();
IERC20Permit assetToDeposit = IERC20Permit(depositToAave ? asset() : address($._aToken));

try
Expand All @@ -103,7 +107,7 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {

///@inheritdoc IStata4626
function aToken() public view returns (IERC20) {
Stata4626Storage storage $ = _getStata4626Storage();
ERC4626StataTokenStorage storage $ = _getERC4626StataTokenStorage();
return $._aToken;
}

Expand Down Expand Up @@ -195,7 +199,7 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
SafeERC20.safeTransferFrom(IERC20(cachedAsset), caller, address(this), assets);
POOL.deposit(cachedAsset, assets, address(this), 0);
} else {
Stata4626Storage storage $ = _getStata4626Storage();
ERC4626StataTokenStorage storage $ = _getERC4626StataTokenStorage();
SafeERC20.safeTransferFrom($._aToken, caller, address(this), assets);
}
_mint(receiver, shares);
Expand Down Expand Up @@ -234,7 +238,7 @@ abstract contract Stata4626Upgradable is ERC4626Upgradeable, IStata4626 {
if (withdrawFromAave) {
POOL.withdraw(asset(), assets, receiver);
} else {
Stata4626Storage storage $ = _getStata4626Storage();
ERC4626StataTokenStorage storage $ = _getERC4626StataTokenStorage();
SafeERC20.safeTransfer($._aToken, receiver, assets);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import {PausableUpgradeable} from 'openzeppelin-contracts-upgradeable/contracts/
import {IRescuable, Rescuable} from 'solidity-utils/contracts/utils/Rescuable.sol';

import {IACLManager} from '../../../core/contracts/interfaces/IACLManager.sol';
import {ERC4626Upgradeable, Stata4626Upgradable, IPool} from './Stata4626Upgradable.sol';
import {ERC4626Upgradeable, ERC4626StataTokenUpgradable, IPool} from './ERC4626StataTokenUpgradable.sol';
import {ERC20AaveLMUpgradable, IRewardsController} from './ERC20AaveLMUpgradable.sol';
import {IStataMerger} from './interfaces/IStataMerger.sol';
import {IStataTokenV2} from './interfaces/IStataTokenV2.sol';

contract StataMerger is
contract StataTokenV2 is
ERC20PermitUpgradeable,
ERC20AaveLMUpgradable,
Stata4626Upgradable,
ERC4626StataTokenUpgradable,
PausableUpgradeable,
Rescuable,
IStataMerger
IStataTokenV2
{
constructor(
IPool pool,
IRewardsController rewardsController
) ERC20AaveLMUpgradable(rewardsController) Stata4626Upgradable(pool) {}
) ERC20AaveLMUpgradable(rewardsController) ERC4626StataTokenUpgradable(pool) {}
modifier onlyPauseGuardian() {
if (!canPause(_msgSender())) revert OnlyPauseGuardian(_msgSender());
_;
Expand All @@ -39,7 +39,7 @@ contract StataMerger is
__Pausable_init();
}

///@inheritdoc IStataMerger
///@inheritdoc IStataTokenV2
function setPaused(bool paused) external onlyPauseGuardian {
if (paused) _pause();
else _unpause();
Expand All @@ -50,7 +50,7 @@ contract StataMerger is
return POOL_ADDRESSES_PROVIDER.getACLAdmin();
}

///@inheritdoc IStataMerger
///@inheritdoc IStataTokenV2
function canPause(address actor) public view returns (bool) {
return IACLManager(POOL_ADDRESSES_PROVIDER.getACLManager()).isEmergencyAdmin(actor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IPool, DataTypes} from '../../../core/contracts/interfaces/IPool.sol';
import {IERC20Metadata} from 'solidity-utils/contracts/oz-common/interfaces/IERC20Metadata.sol';
import {ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {Initializable} from 'solidity-utils/contracts/transparent-proxy/Initializable.sol';
import {StataMerger} from './StataMerger.sol';
import {StataTokenV2} from './StataTokenV2.sol';
import {IStaticATokenFactory} from './interfaces/IStaticATokenFactory.sol';

/**
Expand Down Expand Up @@ -57,7 +57,7 @@ contract StaticATokenFactory is Initializable, IStaticATokenFactory {
STATIC_A_TOKEN_IMPL,
PROXY_ADMIN,
abi.encodeWithSelector(
StataMerger.initialize.selector,
StataTokenV2.initialize.selector,
reserveData.aTokenAddress,
string(abi.encodePacked('Static ', IERC20Metadata(reserveData.aTokenAddress).name())),
string(symbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStataMerger {
interface IStataTokenV2 {
/**
* @notice Checks if the passed actor is permissioned emergency admin.
* @param actor The reward to claim
Expand Down
6 changes: 3 additions & 3 deletions tests/periphery/static-a-token/Stata4626LM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {IERC20Metadata, IERC20} from 'openzeppelin-contracts/contracts/token/ERC

import {AToken} from '../../../src/core/contracts/protocol/tokenization/AToken.sol';
import {DataTypes} from '../../../src/core/contracts/protocol/libraries/configuration/ReserveConfiguration.sol';
import {Math} from '../../../src/periphery/contracts/static-a-token/Stata4626Upgradable.sol';
import {StataMerger} from '../../../src/periphery/contracts/static-a-token/StataMerger.sol'; // TODO: change import to isolate to 4626
import {Math} from '../../../src/periphery/contracts/static-a-token/ERC4626StataTokenUpgradable.sol';
import {StataTokenV2} from '../../../src/periphery/contracts/static-a-token/StataTokenV2.sol'; // TODO: change import to isolate to 4626
import {SigUtils} from '../../utils/SigUtils.sol';
import {BaseTest, TestnetERC20} from './TestBase.sol';
import {IPool} from '../../../src/core/contracts/interfaces/IPool.sol';
Expand All @@ -27,7 +27,7 @@ contract Stata4626LMTest is BaseTest {
function test_initializeShouldRevert() public {
address impl = factory.STATIC_A_TOKEN_IMPL();
vm.expectRevert(Initializable.InvalidInitialization.selector);
StataMerger(impl).initialize(A_TOKEN, 'hey', 'ho');
StataTokenV2(impl).initialize(A_TOKEN, 'hey', 'ho');
}

function test_getters() public view {
Expand Down
6 changes: 3 additions & 3 deletions tests/periphery/static-a-token/StataOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.10;

import {StataOracle} from '../../../src/periphery/contracts/static-a-token/StataOracle.sol';
import {StataMerger} from '../../../src/periphery/contracts/static-a-token/StataMerger.sol';
import {StataTokenV2} from '../../../src/periphery/contracts/static-a-token/StataTokenV2.sol';
import {BaseTest} from './TestBase.sol';
import {IPool} from '../../../src/core/contracts/interfaces/IPool.sol';

Expand Down Expand Up @@ -33,13 +33,13 @@ contract StataOracleTest is BaseTest {
address staticAToken = staticATokens[i];
uint256 stataPrice = stataPrices[i];

address underlying = StataMerger(staticAToken).asset();
address underlying = StataTokenV2(staticAToken).asset();
uint256 underlyingPrice = contracts.aaveOracle.getAssetPrice(underlying);

assertGe(stataPrice, underlyingPrice);
assertEq(
stataPrice,
(underlyingPrice * StataMerger(staticAToken).convertToAssets(1e18)) / 1e18
(underlyingPrice * StataTokenV2(staticAToken).convertToAssets(1e18)) / 1e18
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/periphery/static-a-token/TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-
import {ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {IPool} from '../../../src/core/contracts/interfaces/IPool.sol';
import {StaticATokenFactory} from '../../../src/periphery/contracts/static-a-token/StaticATokenFactory.sol';
import {StataMerger} from '../../../src/periphery/contracts/static-a-token/StataMerger.sol';
import {StataTokenV2} from '../../../src/periphery/contracts/static-a-token/StataTokenV2.sol';
import {IERC20AaveLM} from '../../../src/periphery/contracts/static-a-token/interfaces/IERC20AaveLM.sol';
import {IAToken} from '../../../src/core/contracts/interfaces/IAToken.sol';
import {TestnetProcedures, TestnetERC20} from '../../utils/TestnetProcedures.sol';
Expand All @@ -31,7 +31,7 @@ abstract contract BaseTest is TestnetProcedures {
uint256 internal userPrivateKey;
uint256 internal spenderPrivateKey;

StataMerger public staticATokenLM;
StataTokenV2 public staticATokenLM;
address public proxyAdmin;
ITransparentProxyFactory public proxyFactory;
StaticATokenFactory public factory;
Expand Down Expand Up @@ -68,7 +68,7 @@ abstract contract BaseTest is TestnetProcedures {
factory = StaticATokenFactory(report.staticATokenFactoryProxy);
factory.createStaticATokens(POOL.getReservesList());

staticATokenLM = StataMerger(factory.getStaticAToken(UNDERLYING));
staticATokenLM = StataTokenV2(factory.getStaticAToken(UNDERLYING));
}

function _configureLM() internal {
Expand Down

0 comments on commit cef08a2

Please sign in to comment.