Skip to content

Commit

Permalink
feat: upgrade factory (aave-dao#95)
Browse files Browse the repository at this point in the history
* feat: upgrade factory

* fix: cleanup

* fix: use local copy

* fix: tests

* fix: remove deployment of proxyAdmin

* fix: update tests

* fix: update utils to latest

---------

Co-authored-by: Harsh Pandey <[email protected]>
  • Loading branch information
sakulstra and brotherlymite authored Jan 29, 2025
1 parent 37bb873 commit 7d706f0
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 89 deletions.
8 changes: 4 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ test = 'tests'
script = 'scripts'
optimizer = true
optimizer_runs = 200
solc = '0.8.20'
solc = '0.8.22'
evm_version = 'shanghai'
bytecode_hash = 'none'
ignored_warnings_from = ["src/periphery/contracts/treasury/RevenueSplitter.sol"]
out = 'out'
libs = ['lib']
remappings = []
fs_permissions = [
{ access = "write", path = "./reports" },
{ access = "read", path = "./out" },
{ access = "read", path = "./config" },
{ access = "write", path = "./reports" },
{ access = "read", path = "./out" },
{ access = "read", path = "./config" },
]
ffi = true

Expand Down
2 changes: 1 addition & 1 deletion lib/solidity-utils
Submodule solidity-utils updated 45 files
+1 −0 .gitmodules
+5 −9 Makefile
+35 −36 foundry.toml
+1 −1 lib/forge-std
+1 −1 lib/openzeppelin-contracts-upgradeable
+2 −2 script/DeployTransparentProxyFactory.s.sol
+5 −4 src/contracts/access-control/OwnableWithGuardian.sol
+0 −10 src/contracts/access-control/UpgradeableOwnableWithGuardian.sol
+10 −0 src/contracts/access-control/interfaces/IWithGuardian.sol
+0 −248 src/contracts/oz-common/Address.sol
+0 −25 src/contracts/oz-common/Context.sol
+0 −378 src/contracts/oz-common/EnumerableSet.sol
+0 −84 src/contracts/oz-common/Ownable.sol
+0 −1,136 src/contracts/oz-common/SafeCast.sol
+0 −141 src/contracts/oz-common/SafeERC20.sol
+0 −89 src/contracts/oz-common/StorageSlot.sol
+0 −79 src/contracts/oz-common/interfaces/IERC20.sol
+0 −29 src/contracts/oz-common/interfaces/IERC20Metadata.sol
+0 −60 src/contracts/oz-common/interfaces/IERC20Permit.sol
+2 −2 src/contracts/oz-common/interfaces/IERC20WithPermit.sol
+0 −157 src/contracts/transparent-proxy/Initializable.sol
+0 −92 src/contracts/transparent-proxy/Proxy.sol
+0 −45 src/contracts/transparent-proxy/ProxyAdmin.sol
+0 −1 src/contracts/transparent-proxy/TransparentProxyFactory.sol
+55 −17 src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol
+0 −125 src/contracts/transparent-proxy/TransparentUpgradeableProxy.sol
+15 −0 src/contracts/transparent-proxy/interfaces/IProxyAdminOzV4.sol
+16 −14 src/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol
+1 −1 src/contracts/utils/PermissionlessRescuable.sol
+1 −1 src/contracts/utils/Rescuable.sol
+1 −1 src/contracts/utils/RescuableACL.sol
+2 −2 src/contracts/utils/RescuableBase.sol
+3 −3 src/mocks/ERC20.sol
+894 −893 src/mocks/ERC721.sol
+1 −1 src/mocks/MockImpl.sol
+10 −4 test/OwnableWithGuardian.t.sol
+3 −3 test/PermissionlessRescuable.t.sol
+2 −2 test/Rescuable.t.sol
+1 −1 test/Rescuable721.t.sol
+2 −2 test/RescuableACL.t.sol
+27 −19 test/TransparentProxyFactory.t.sol
+5 −14 test/UpgradeableOwnableWithGuardian.t.sol
+2 −3 test/create3Test.t.sol
+10 −1 zksync/src/contracts/transparent-proxy/TransparentProxyFactoryZkSync.sol
+25 −11 zksync/test/TransparentProxyFactoryZkSync.t.sol
8 changes: 4 additions & 4 deletions snapshots/StataTokenV2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"deposit": "284677",
"depositATokens": "220136",
"redeem": "205767",
"redeemAToken": "153413"
"deposit": "283763",
"depositATokens": "219223",
"redeem": "205909",
"redeemAToken": "152567"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.17;
import {ERC20Upgradeable} from 'openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol';
import {IERC20} from 'openzeppelin-contracts/contracts/interfaces/IERC20.sol';
import {SafeERC20} from 'openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';

import {IRewardsController} from '../../rewards/interfaces/IRewardsController.sol';
import {IERC20AaveLM} from './interfaces/IERC20AaveLM.sol';
Expand Down
14 changes: 7 additions & 7 deletions src/contracts/extensions/stata-token/StataTokenFactory.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;

import {IERC20Metadata} from 'solidity-utils/contracts/oz-common/interfaces/IERC20Metadata.sol';
import {ITransparentProxyFactory, ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {Initializable} from 'solidity-utils/contracts/transparent-proxy/Initializable.sol';
import {IERC20Metadata} from 'openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol';
import {Initializable} from 'openzeppelin-contracts/contracts/proxy/utils/Initializable.sol';
import {ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {IPool, DataTypes} from '../../../contracts/interfaces/IPool.sol';
import {StataTokenV2} from './StataTokenV2.sol';
import {IStataTokenFactory} from './interfaces/IStataTokenFactory.sol';
Expand All @@ -20,7 +20,7 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {
IPool public immutable POOL;

///@inheritdoc IStataTokenFactory
address public immutable PROXY_ADMIN;
address public immutable INITIAL_OWNER;

///@inheritdoc IStataTokenFactory
ITransparentProxyFactory public immutable TRANSPARENT_PROXY_FACTORY;
Expand All @@ -35,12 +35,12 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {

constructor(
IPool pool,
address proxyAdmin,
address initialOwner,
ITransparentProxyFactory transparentProxyFactory,
address stataTokenImpl
) {
POOL = pool;
PROXY_ADMIN = proxyAdmin;
INITIAL_OWNER = initialOwner;
TRANSPARENT_PROXY_FACTORY = transparentProxyFactory;
STATA_TOKEN_IMPL = stataTokenImpl;
}
Expand All @@ -62,7 +62,7 @@ contract StataTokenFactory is Initializable, IStataTokenFactory {
);
address stataToken = TRANSPARENT_PROXY_FACTORY.createDeterministic(
STATA_TOKEN_IMPL,
ProxyAdmin(PROXY_ADMIN),
INITIAL_OWNER,
abi.encodeWithSelector(
StataTokenV2.initialize.selector,
reserveData.aTokenAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ interface IStataTokenFactory {
function POOL() external view returns (IPool);

/**
* @notice The proxy admin used for all tokens created via the factory.
* @return The proxy admin address.
* @notice The initial owner used for all tokens created via the factory.
* @return The address of the initial owner.
*/
function PROXY_ADMIN() external view returns (address);
function INITIAL_OWNER() external view returns (address);

/**
* @notice The proxy factory used for all tokens created via the stata factory.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {CapsEngine} from './libraries/CapsEngine.sol';
import {BorrowEngine} from './libraries/BorrowEngine.sol';
import {CollateralEngine} from './libraries/CollateralEngine.sol';
import {RateEngine} from './libraries/RateEngine.sol';
import {PriceFeedEngine} from './libraries/PriceFeedEngine.sol';
import {EModeEngine} from './libraries/EModeEngine.sol';
import {ListingEngine} from './libraries/ListingEngine.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import './IAaveV3ConfigEngine.sol';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {WadRayMath} from '../../protocol/libraries/math/WadRayMath.sol';
import {IAaveV3ConfigEngine as IEngine} from './IAaveV3ConfigEngine.sol';
import {EngineFlags} from './EngineFlags.sol';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {SafeCast} from 'openzeppelin-contracts/contracts/utils/math/SafeCast.sol';
import {EngineFlags} from '../EngineFlags.sol';
import {DataTypes} from '../../../protocol/libraries/types/DataTypes.sol';
import {SafeCast} from 'solidity-utils/contracts/oz-common/SafeCast.sol';
import {PercentageMath} from '../../../protocol/libraries/math/PercentageMath.sol';
import {IAaveV3ConfigEngine as IEngine, IPoolConfigurator, IPool} from '../IAaveV3ConfigEngine.sol';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.18;

import {Address} from 'openzeppelin-contracts/contracts/utils/Address.sol';
import {IAaveV3ConfigEngine as IEngine, IPoolConfigurator, IPool, IDefaultInterestRateStrategyV2} from '../IAaveV3ConfigEngine.sol';
import {PriceFeedEngine} from './PriceFeedEngine.sol';
import {CapsEngine} from './CapsEngine.sol';
import {BorrowEngine} from './BorrowEngine.sol';
import {CollateralEngine} from './CollateralEngine.sol';
import {EModeEngine} from './EModeEngine.sol';
import {ConfiguratorInputTypes} from '../../../protocol/libraries/types/ConfiguratorInputTypes.sol';
import {Address} from 'solidity-utils/contracts/oz-common/Address.sol';
import {SafeCast} from '../../../dependencies/openzeppelin/contracts/SafeCast.sol';

library ListingEngine {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import '../../interfaces/IMarketReportTypes.sol';
import {ITransparentProxyFactory, ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {ITransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol';
import {TransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {StataTokenV2} from '../../../contracts/extensions/stata-token/StataTokenV2.sol';
import {StataTokenFactory} from '../../../contracts/extensions/stata-token/StataTokenFactory.sol';
Expand All @@ -12,9 +12,9 @@ contract AaveV3HelpersProcedureTwo is IErrors {
function _deployStaticAToken(
address pool,
address rewardsController,
address proxyAdmin
address poolAdmin
) internal returns (StaticATokenReport memory staticATokenReport) {
if (proxyAdmin == address(0)) revert ProxyAdminNotFound();
if (poolAdmin == address(0)) revert PoolAdminNotFound();

staticATokenReport.transparentProxyFactory = address(new TransparentProxyFactory());
staticATokenReport.staticATokenImplementation = address(
Expand All @@ -23,7 +23,7 @@ contract AaveV3HelpersProcedureTwo is IErrors {
staticATokenReport.staticATokenFactoryImplementation = address(
new StataTokenFactory(
IPool(pool),
proxyAdmin,
poolAdmin,
ITransparentProxyFactory(staticATokenReport.transparentProxyFactory),
staticATokenReport.staticATokenImplementation
)
Expand All @@ -33,7 +33,7 @@ contract AaveV3HelpersProcedureTwo is IErrors {
staticATokenReport.transparentProxyFactory
).create(
staticATokenReport.staticATokenFactoryImplementation,
ProxyAdmin(proxyAdmin),
poolAdmin,
abi.encodeWithSelector(StataTokenFactory.initialize.selector)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {TransparentUpgradeableProxy} from 'openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {Collector} from '../../../contracts/treasury/Collector.sol';
import '../../interfaces/IMarketReportTypes.sol';

Expand All @@ -14,7 +13,6 @@ contract AaveV3TreasuryProcedure {

function _deployAaveV3Treasury(
address poolAdmin,
address deployedProxyAdmin,
bytes32 collectorSalt
) internal returns (TreasuryReport memory) {
TreasuryReport memory treasuryReport;
Expand All @@ -29,7 +27,7 @@ contract AaveV3TreasuryProcedure {
treasuryReport.treasury = address(
new TransparentUpgradeableProxy{salt: salt}(
treasuryReport.treasuryImplementation,
ProxyAdmin(deployedProxyAdmin),
poolAdmin,
abi.encodeWithSelector(
treasuryImplementation.initialize.selector,
address(treasuryOwner),
Expand All @@ -45,7 +43,7 @@ contract AaveV3TreasuryProcedure {
treasuryReport.treasury = address(
new TransparentUpgradeableProxy(
treasuryReport.treasuryImplementation,
ProxyAdmin(deployedProxyAdmin),
poolAdmin,
abi.encodeWithSelector(
treasuryImplementation.initialize.selector,
address(treasuryOwner),
Expand Down
1 change: 0 additions & 1 deletion src/deployments/contracts/utilities/MarketReportUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ library MarketReportUtils {
defaultInterestRateStrategy: IDefaultInterestRateStrategyV2(
report.defaultInterestRateStrategy
),
proxyAdmin: ProxyAdmin(report.proxyAdmin),
treasuryImplementation: ICollector(report.treasuryImplementation),
wrappedTokenGateway: IWrappedTokenGatewayV3(report.wrappedTokenGateway),
walletBalanceProvider: WalletBalanceProvider(payable(report.walletBalanceProvider)),
Expand Down
1 change: 0 additions & 1 deletion src/deployments/contracts/utilities/MetadataReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ contract MetadataReporter is IMetadataReporter {
);
vm.serializeAddress(jsonReport, 'aaveOracle', report.aaveOracle);
vm.serializeAddress(jsonReport, 'treasury', report.treasury);
vm.serializeAddress(jsonReport, 'proxyAdmin', report.proxyAdmin);
vm.serializeAddress(jsonReport, 'wrappedTokenGateway', report.wrappedTokenGateway);
vm.serializeAddress(jsonReport, 'walletBalanceProvider', report.walletBalanceProvider);
vm.serializeAddress(jsonReport, 'uiIncentiveDataProvider', report.uiIncentiveDataProvider);
Expand Down
2 changes: 1 addition & 1 deletion src/deployments/interfaces/IErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ interface IErrors {
error L2MustBeEnabled();
error L2MustBeDisabled();
error ProviderNotFound();
error ProxyAdminNotFound();
error PoolAdminNotFound();
}
5 changes: 0 additions & 5 deletions src/deployments/interfaces/IMarketReportTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import '../../contracts/extensions/paraswap-adapters/ParaSwapWithdrawSwapAdapter
import '../../contracts/helpers/interfaces/IWrappedTokenGatewayV3.sol';
import '../../contracts/helpers/L2Encoder.sol';
import {ICollector} from '../../contracts/treasury/ICollector.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';

struct ContractsReport {
IPoolAddressesProviderRegistry poolAddressesProviderRegistry;
Expand All @@ -36,7 +35,6 @@ struct ContractsReport {
IACLManager aclManager;
ICollector treasury;
IDefaultInterestRateStrategyV2 defaultInterestRateStrategy;
ProxyAdmin proxyAdmin;
ICollector treasuryImplementation;
IWrappedTokenGatewayV3 wrappedTokenGateway;
WalletBalanceProvider walletBalanceProvider;
Expand Down Expand Up @@ -66,7 +64,6 @@ struct MarketReport {
address priceOracleSentinel;
address aclManager;
address treasury;
address proxyAdmin;
address treasuryImplementation;
address wrappedTokenGateway;
address walletBalanceProvider;
Expand Down Expand Up @@ -117,7 +114,6 @@ struct MarketConfig {
uint256 providerId;
bytes32 salt;
address wrappedNativeToken;
address proxyAdmin;
uint128 flashLoanPremiumTotal;
uint128 flashLoanPremiumToProtocol;
address incentivesProxy;
Expand Down Expand Up @@ -172,7 +168,6 @@ struct SetupReport {

struct PeripheryReport {
address aaveOracle;
address proxyAdmin;
address treasury;
address treasuryImplementation;
address emissionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ library AaveV3BatchOrchestration {

AaveV3TokensBatch.TokensReport memory tokensReport = _deployTokens(setupReport.poolProxy);

// to avoid issues when running without --via-ir we copy the variable
address pa = roles.poolAdmin;
ConfigEngineReport memory configEngineReport = _deployHelpersBatch1(
setupReport,
miscReport,
Expand All @@ -98,7 +100,7 @@ library AaveV3BatchOrchestration {
StaticATokenReport memory staticATokenReport = _deployHelpersBatch2(
setupReport.poolProxy,
setupReport.rewardsControllerProxy,
peripheryReport.proxyAdmin
pa
);

// Save final report at AaveV3SetupBatch contract
Expand Down Expand Up @@ -191,12 +193,12 @@ library AaveV3BatchOrchestration {
function _deployHelpersBatch2(
address pool,
address rewardsController,
address proxyAdmin
address poolAdmin
) internal returns (StaticATokenReport memory) {
AaveV3HelpersBatchTwo helpersBatchTwo = new AaveV3HelpersBatchTwo(
pool,
rewardsController,
proxyAdmin
poolAdmin
);

return helpersBatchTwo.staticATokenReport();
Expand Down Expand Up @@ -311,7 +313,6 @@ library AaveV3BatchOrchestration {
report.paraSwapRepayAdapter = paraswapReport.paraSwapRepayAdapter;
report.paraSwapWithdrawSwapAdapter = paraswapReport.paraSwapWithdrawSwapAdapter;
report.treasuryImplementation = peripheryReport.treasuryImplementation;
report.proxyAdmin = peripheryReport.proxyAdmin;
report.treasury = peripheryReport.treasury;
report.poolProxy = setupReport.poolProxy;
report.poolConfiguratorProxy = setupReport.poolConfiguratorProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '../../../interfaces/IMarketReportTypes.sol';
contract AaveV3HelpersBatchTwo is AaveV3HelpersProcedureTwo {
StaticATokenReport internal _report;

constructor(address pool, address rewardsController, address proxyAdmin) {
_report = _deployStaticAToken(pool, rewardsController, proxyAdmin);
constructor(address pool, address rewardsController, address poolAdmin) {
_report = _deployStaticAToken(pool, rewardsController, poolAdmin);
}

function staticATokenReport() external view returns (StaticATokenReport memory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,10 @@ contract AaveV3PeripheryBatch is
address poolAddressesProvider,
address setupBatch
) {
if (config.proxyAdmin == address(0)) {
_report.proxyAdmin = address(new ProxyAdmin{salt: config.salt}(poolAdmin));
} else {
_report.proxyAdmin = config.proxyAdmin;
}

_report.aaveOracle = _deployAaveOracle(config.oracleDecimals, poolAddressesProvider);

if (config.treasury == address(0)) {
TreasuryReport memory treasuryReport = _deployAaveV3Treasury(
poolAdmin,
_report.proxyAdmin,
config.salt
);
TreasuryReport memory treasuryReport = _deployAaveV3Treasury(poolAdmin, config.salt);

_report.treasury = treasuryReport.treasury;
_report.treasuryImplementation = treasuryReport.treasuryImplementation;
Expand Down
1 change: 0 additions & 1 deletion tests/deployments/AaveV3BatchDeployment.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ contract AaveV3BatchDeployment is BatchTestProcedures {
8080,
emptySalt,
weth9,
address(0),
0.0005e4,
0.0004e4,
address(0),
Expand Down
3 changes: 1 addition & 2 deletions tests/deployments/AaveV3BatchTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ contract AaveV3BatchTests is BatchTestProcedures {
8080,
emptySalt,
address(new WETH9()),
address(0),
0.0005e4,
0.0004e4,
address(0),
Expand Down Expand Up @@ -200,7 +199,7 @@ contract AaveV3BatchTests is BatchTestProcedures {
new AaveV3HelpersBatchTwo(
setupReportTwo.poolProxy,
setupReportTwo.rewardsControllerProxy,
peripheryReportOne.proxyAdmin
roles.poolAdmin
);
}
}
Loading

0 comments on commit 7d706f0

Please sign in to comment.