Skip to content

Commit 5a1a25c

Browse files
feat: aToken vault factory (#99)
* feat: aToken vault factory * update comment * update gitignore for jetbrains IDEs * update optimizer-runs * misc: Make variables' name to follow code conventions * feat: Lib introduced to avoid factory exceeding the contract size limit * misc: Compilation optimizer runs raised to 30k * misc: Dependency fixes - package-lock.json updated * feat: DeployFactory script added * misc: Remove all warnings from the code * feat: Use CREATE opcode for deployments instead of CREATE2 * test: bound fee and initial deposit * test: assert against getVaultsByUnderlying too * test: Reverts when attempts a deployment exceeding max fee * feat: VaultParams added into VaultDeployed event * feat: Use safeTransferFrom for underlying * misc: bgd-labs/solidity-utils dependency installed * misc: bgd-labs/aave-address-book dependency installed * misc: remappings updated * misc: Remove unused storage fields * misc: pcaversaccio/createx installed as dependency * misc: oz contracts v5.3 added, aave-v3-core updated & solc 0.8.22 * feat: Require renounced ownership for the vault proxy admin constructor param * feat: DeployFactory script uses keystore & CREATE3 deterministic addresses * fix: Deploy proxy admin with CREATE & fix expected factory address * misc: Unused dependencies removed * feat: OZ v5.3 dependency removed, keeping v4.7 only instead * feat: Remove _allVaults field and related view functions --------- Co-authored-by: Alan Donoso Naumczuk <[email protected]>
1 parent dc25b5a commit 5a1a25c

File tree

12 files changed

+1157
-56
lines changed

12 files changed

+1157
-56
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
.gas-snapshot
99
lcov.info
1010
.certora_internal/
11-
.certora_recent_jobs.json
11+
.certora_recent_jobs.json
12+
.idea

.gitmodules

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
[submodule "lib/openzeppelin-contracts"]
88
path = lib/openzeppelin-contracts
99
url = https://github.com/OpenZeppelin/openzeppelin-contracts
10+
branch = v4.7.0
1011
[submodule "lib/aave-v3-core"]
1112
path = lib/aave-v3-core
1213
url = https://github.com/aave/aave-v3-core
13-
branch = v1.17.1
14+
branch = v1.19.4
1415
[submodule "lib/aave-v3-periphery"]
1516
path = lib/aave-v3-periphery
1617
url = https://github.com/aave/aave-v3-periphery
@@ -22,3 +23,6 @@
2223
[submodule "lib/erc4626-tests"]
2324
path = lib/erc4626-tests
2425
url = https://github.com/a16z/erc4626-tests
26+
[submodule "lib/createx"]
27+
path = lib/createx
28+
url = https://github.com/pcaversaccio/createx

foundry.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[profile.default]
2-
solc = "0.8.10"
2+
solc = "0.8.22"
33
bytecode_hash = "none"
44
optimizer = true
5-
optimizer-runs = 10_000_000
5+
optimizer-runs = 30_000
66
via_ir = false
77
runs = 256
88
gas_reports = ["ATokenVault"]
99
isolate = true
10+
ignored_warnings_from = ["lib/", "node_modules/"] # Ignore warnings from dependencies
1011

1112
[fuzz]
1213
max_test_rejects = 65536

lib/aave-v3-core

Submodule aave-v3-core updated 227 files

lib/createx

Submodule createx added at cbac803

package-lock.json

Lines changed: 10 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

remappings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ erc4626-tests/=lib/erc4626-tests/
55
forge-std/=lib/forge-std/src/
66
solmate/=lib/solmate/src/
77
@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
8+
@openzeppelin-v5/=lib/openzeppelin-contracts-v5.3.0/contracts
89
@openzeppelin/=lib/openzeppelin-contracts/contracts
10+
@pcaversaccio/createx/=lib/createx/src/

script/DeployFactory.s.sol

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.10;
4+
5+
import "forge-std/Script.sol";
6+
import {ATokenVaultFactory} from "../src/ATokenVaultFactory.sol";
7+
import {ICreateX} from "@pcaversaccio/createx/ICreateX.sol";
8+
import {ProxyAdmin} from "@openzeppelin/proxy/transparent/ProxyAdmin.sol";
9+
import {TransparentUpgradeableProxy} from "@openzeppelin/proxy/transparent/TransparentUpgradeableProxy.sol";
10+
11+
/**
12+
* @title DeployFactory
13+
* @author Aave Labs
14+
* @notice Script to deploy the aTokenVaultFactory contract with deterministic address even when future versions change
15+
* @dev Run the script with the following command first:
16+
*
17+
* forge script script/DeployFactory.s.sol:DeployFactory -vvvv --rpc-url {$RPC_URL} --account ${ACCOUNT} --slow
18+
*
19+
* If succeeds, then add the --broadcast flag in order to send the transaction to the network.
20+
*/
21+
contract DeployFactory is Script {
22+
/////////////////// DEPLOYMENT PARAMETERS //////////////////////////
23+
/**
24+
* @notice The aTokenVaultFactory's Proxy Admin
25+
*/
26+
address constant FACTORY_PROXY_ADMIN = address(0);
27+
////////////////////////////////////////////////////////////////////
28+
29+
address constant EXPECTED_FACTORY_ADDRESS = address(0xa35995bb2fFC5F2b33379C2e95d00C20FbF71E70);
30+
31+
address constant DEPLOYER_ADDRESS = address(0xFAC70d880Da5923673C502dbC8CeD1675c57e155);
32+
33+
/**
34+
* @notice CREATE3 Salt for the deterministic aTokenVaultFactory deployment
35+
*
36+
* @dev Generated through following steps:
37+
*
38+
* Base Salt: keccak256("aave.aTokenVaultFactory")
39+
* = 0x36275659667d979dfee1891a4bc3f4c14e3c2bb6a5b996d2f8dec69a6f19c4be
40+
*
41+
* 0x 36275659667d979dfee1891a4bc3f4c14e3c2bb6 a5 b996d2f8dec69a6f19c4be
42+
*
43+
* Add deployer address (0xFAC70d880Da5923673C502dbC8CeD1675c57e155) at the beginning for protection:
44+
* 0x FAC70d880Da5923673C502dbC8CeD1675c57e155 a5 b996d2f8dec69a6f19c4be
45+
*
46+
* Set the next byte to 0x00 in order to turn off the cross-chain protection:
47+
* 0x FAC70d880Da5923673C502dbC8CeD1675c57e155 00 b996d2f8dec69a6f19c4be
48+
*
49+
* Keep the final bytes from the base salt
50+
*/
51+
bytes32 constant FACTORY_SALT = 0xFAC70d880Da5923673C502dbC8CeD1675c57e15500b996d2f8dec69a6f19c4be;
52+
53+
/**
54+
* @notice @pcaversaccio/createx's address
55+
*
56+
* @dev Used as CREATE3 factory for deterministic deployments, not depending on the init code.
57+
*/
58+
address constant CREATEX_ADDRESS = address(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed);
59+
60+
ICreateX CREATE3_FACTORY = ICreateX(CREATEX_ADDRESS);
61+
62+
function run() external {
63+
64+
console.log("Deployer balance: ", address(DEPLOYER_ADDRESS).balance);
65+
66+
console.log("BlockNumber: ", block.number);
67+
68+
console.log("ChainId: ", block.chainid);
69+
70+
require(FACTORY_PROXY_ADMIN != address(0), "FACTORY_PROXY_ADMIN is not set");
71+
console.log("Factory proxy admin owner: ", FACTORY_PROXY_ADMIN);
72+
73+
74+
vm.startBroadcast();
75+
76+
77+
/////// Deploy Renounced ProxyAdmin
78+
79+
console.log("Deploying vault's renounced proxy admin");
80+
81+
address renouncedProxyAdmin = address(new ProxyAdmin());
82+
83+
console.log("Renounced proxy admin deployed at: ", renouncedProxyAdmin);
84+
85+
ProxyAdmin(renouncedProxyAdmin).renounceOwnership();
86+
87+
88+
/////// Deploy aTokenVaultFactory Implementation (pass Renounced ProxyAdmin as argument)
89+
90+
console.log("Deploying aTokenVaultFactory implementation...");
91+
92+
ATokenVaultFactory factoryImplementation = new ATokenVaultFactory({proxyAdmin: renouncedProxyAdmin});
93+
94+
console.log("aTokenVaultFactory implementation deployed at: ", address(factoryImplementation));
95+
96+
97+
98+
/////// Deploy aTokenVaultFactory Proxy
99+
100+
console.log("Deploying aTokenVaultFactory proxy - Expected at: ", address(EXPECTED_FACTORY_ADDRESS));
101+
102+
address factoryProxy = CREATE3_FACTORY.deployCreate3({
103+
salt: FACTORY_SALT,
104+
initCode: abi.encodePacked(
105+
type(TransparentUpgradeableProxy).creationCode,
106+
abi.encode(factoryImplementation, FACTORY_PROXY_ADMIN, "")
107+
)
108+
});
109+
110+
console.log("aTokenVaultFactory proxy deployed at: ", factoryProxy);
111+
112+
require(address(factoryProxy) == EXPECTED_FACTORY_ADDRESS, "aTokenVaultFactory Proxy address mismatch");
113+
114+
115+
vm.stopBroadcast();
116+
}
117+
}

0 commit comments

Comments
 (0)