Skip to content

Commit

Permalink
Adding AccessManager (and Upgradeability) from OpenZeppelin lib (#84)
Browse files Browse the repository at this point in the history
* feat(accessManager): adding accessManager contract and adapting contracts

* feat(accessManager): a lot

* feat(accessManager): submodules

* feat(accessManager): submodules

* feat(accessManager): submodules

* feat(accessManager): submodules

* feat(accessManager): submodulesssssssss

* feat(AccessMananger) Adding tests and deploy script

---------

Co-authored-by: Vincent Rainaud <[email protected]>
  • Loading branch information
Ronfflex and Vincent Rainaud authored Apr 28, 2024
1 parent 3fdb4f5 commit 2920df5
Show file tree
Hide file tree
Showing 26 changed files with 423 additions and 359 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/contracts/.yarn/** linguist-vendored
/contracts/.yarn/releases/* binary
/contracts/.yarn/plugins/**/* binary
/contracts/.pnp.* binary linguist-generated
36 changes: 34 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
node_modules
.env
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
broadcast/

# Docs
docs/

# Dotenv file
.env

# Node modules
!/node_modules
node_modules/*

# Package lock files
package-lock.json

# Yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# System files
.DS_Store
11 changes: 7 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/lib/openzeppelin-contracts-upgradeable"]
path = contracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
Binary file added ArchitectureDEX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Network (e.g. MAINNET)
DEPLOYMENT_NETWORK=

# RPC URL
SEPOLIA_RPC=
MAINNET_RPC=

# Private keys
PRIVATE_KEY=
ETHERSCAN_API_KEY=

# ------------------------------
# ------- SEPOLIA CONFIG -------
# ------------------------------

# Deployer address
DEPLOYER_ADDRESS_SEPOLIA=

# For AccessManager
ACCESS_MANAGER_ADMIN_SEPOLIA=
ACCESS_MANAGER_ADDRESS_SEPOLIA=

# ------------------------------
# ------- MAINNET CONFIG -------
# ------------------------------

# Deployer address
DEPLOYER_ADDRESS_MAINNET=

# For AccessManager
ACCESS_MANAGER_ADMIN_MAINNET=
ACCESS_MANAGER_ADDRESS_MAINNET=
15 changes: 0 additions & 15 deletions contracts/.gitignore

This file was deleted.

Empty file removed contracts/.gitkeep
Empty file.
6 changes: 0 additions & 6 deletions contracts/.gitmodules

This file was deleted.

4 changes: 4 additions & 0 deletions contracts/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib
node_modules
cache
out
16 changes: 16 additions & 0 deletions contracts/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}
36 changes: 19 additions & 17 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,42 @@ $ forge build
$ forge test
```

### Format
### Deploy
1.Create wallet for deployer

```shell
$ forge fmt
$ cast wallet import deployer --interactive
```

### Gas Snapshots

2.Set environment variables and source them
```shell
$ forge snapshot
$ source .env
```

### Anvil

3.Deploy AccessManager contract
```shell
$ anvil
$ forge script script/DeployAccessManager.s.sol:AccessManagerDeploymentScript --rpc-url $SEPOLIA_RPC --broadcast --verify --account deployer -vvvv
```

### Deploy
### Help

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
$ forge --help
$ anvil --help
$ cast --help
```

### Cast
## Setup

### Install dependencies

```shell
$ cast <subcommand>
$ yarn install
```

### Help
### Install submodules

```shell
$ forge --help
$ anvil --help
$ cast --help
```
$ ../
$ git submodule update --init --recursive
```
10 changes: 9 additions & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
src = "src"
out = "out"
libs = ["lib"]
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"]
solc = "0.8.25"
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/"]

[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"

[etherscan]
sepolia = { key = "${ETHERSCAN_API_KEY}" }
1 change: 1 addition & 0 deletions contracts/lib/openzeppelin-contracts-upgradeable
24 changes: 24 additions & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "dex",
"version": "1.0.0",
"description": "Decentralized Exchange",
"main": "index.js",
"license": "MIT",
"files": [
"src/**/*.sol"
],
"devDependencies": {
"prettier": "3.2.5",
"prettier-plugin-solidity": "1.3.1"
},
"scripts": {
"prettier": "prettier --write --plugin=prettier-plugin-solidity 'contracts/**/*.sol'",
"lint": "prettier --list-different --plugin=prettier-plugin-solidity 'contracts/**/*.sol'",
"gas-report": "forge test --gas-report",
"deploy-access-manager": "forge script script/00_deployAccessManager.s.sol --rpc-url $RPC_URL --private-key $ACCOUNT_PRIVATE_KEY --broadcast --verify -vvvv",
"deploy-registry": "forge script script/01_deployRegistry.s.sol --rpc-url $RPC_URL --private-key $ACCOUNT_PRIVATE_KEY --broadcast --verify -vvvv"
},
"dependencies": {
"dotenv": "16.4.5"
}
}
6 changes: 6 additions & 0 deletions contracts/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/
erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/
forge-std/=lib/forge-std/src/
openzeppelin-contracts/=lib/openzeppelin-contracts/
58 changes: 58 additions & 0 deletions contracts/script/00_DeployAccessManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Script.sol";
import "forge-std/console.sol";
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/access/manager/AccessManager.sol";

contract AccessManagerDeploymentScript is Script {
address private testRes;
address private initialSuperAdmin;
bool private forTest;

function run() public {
vm.startBroadcast();
if (forTest) {
address accessManagerInstance = address(new AccessManager(initialSuperAdmin));
console.log(
"AccessManager instance deployed at",
accessManagerInstance,
"with super admin",
initialSuperAdmin
);
testRes = accessManagerInstance;
} else {
string memory deploymentNetwork = vm.envString("DEPLOYMENT_NETWORK");
if (bytes(deploymentNetwork).length == 0) {
revert("DEPLOYMENT_NETWORK is not set in .env file");
}

string memory envVar = string.concat("ACCESS_MANAGER_ADMIN_", deploymentNetwork);
if (bytes(vm.envString(envVar)).length == 0) {
revert(string.concat(envVar, " is not set in .env file"));
}
initialSuperAdmin = vm.envAddress(envVar);

address accessManagerInstance = address(new AccessManager(initialSuperAdmin));
console.log(
"AccessManager instance deployed at",
accessManagerInstance,
"with super admin",
initialSuperAdmin
);
}
vm.stopBroadcast();
}

function deployForTest(address _initialSuperAdmin) public returns (address _testRes) {
forTest = true;
initialSuperAdmin = _initialSuperAdmin;
run();
_testRes = testRes;
// Reset the variables for the next test
forTest = false;
testRes = address(0);
initialSuperAdmin = address(0);
}
}
31 changes: 0 additions & 31 deletions contracts/src/DEX.sol

This file was deleted.

Loading

0 comments on commit 2920df5

Please sign in to comment.