Skip to content

Commit ea6729e

Browse files
committed
Deployment scripts
1 parent 48f4121 commit ea6729e

File tree

8 files changed

+650
-890
lines changed

8 files changed

+650
-890
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules
33
coverage
44
coverage.json
55
typechain
6+
.openzeppelin
67

78
#Hardhat files
89
cache

contracts/ChildToken/Dimo.sol

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.10;
3+
4+
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
5+
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
6+
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
7+
8+
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
9+
10+
contract Dimo is
11+
ERC20Upgradeable,
12+
AccessControlUpgradeable,
13+
PausableUpgradeable,
14+
UUPSUpgradeable
15+
{
16+
bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE");
17+
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
18+
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
19+
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");
20+
21+
function initialize() public initializer {
22+
__ERC20_init("Dimo", "DIMO");
23+
__AccessControl_init();
24+
__Pausable_init();
25+
__UUPSUpgradeable_init();
26+
27+
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
28+
}
29+
30+
function pause() public onlyRole(PAUSER_ROLE) {
31+
_pause();
32+
}
33+
34+
function unpause() public onlyRole(PAUSER_ROLE) {
35+
_unpause();
36+
}
37+
38+
39+
/// @notice called when token is deposited on root chain
40+
/// @dev Should be callable only by ChildChainManager
41+
/// Should handle deposit by minting the required amount for user
42+
/// @param user user address for whom deposit is being done
43+
/// @param depositData abi encoded amount
44+
function deposit(address user, bytes calldata depositData)
45+
external
46+
onlyRole(DEPOSITOR_ROLE)
47+
{
48+
uint256 amount = abi.decode(depositData, (uint256));
49+
_mint(user, amount);
50+
}
51+
52+
53+
/// @notice called when user wants to withdraw tokens back to root chain
54+
/// @dev Should burn user's tokens. This transaction will be verified when exiting on root chain
55+
/// @param amount amount of tokens to withdraw
56+
function withdraw(uint256 amount) external {
57+
_burn(_msgSender(), amount);
58+
}
59+
60+
61+
function mint(address user, uint256 amount) public onlyRole(MINTER_ROLE) {
62+
_mint(user, amount);
63+
}
64+
65+
function _beforeTokenTransfer(
66+
address from,
67+
address to,
68+
uint256 amount
69+
) internal override whenNotPaused {
70+
super._beforeTokenTransfer(from, to, amount);
71+
}
72+
73+
function _authorizeUpgrade(address newImplementation)
74+
internal
75+
override
76+
onlyRole(UPGRADER_ROLE)
77+
{}
78+
}

hardhat.config.js

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ require("dotenv").config();
22
require("@nomiclabs/hardhat-ethers");
33
require("@nomiclabs/hardhat-etherscan");
44
require("@nomiclabs/hardhat-waffle");
5-
require('@openzeppelin/hardhat-upgrades');
5+
require("@openzeppelin/hardhat-upgrades");
66
require("hardhat-gas-reporter");
77
require("solidity-coverage");
8+
require("hardhat-contract-sizer");
9+
require("hardhat-storage-layout");
810

911
// This is a sample Hardhat task. To learn how to create your own go to
1012
// https://hardhat.org/guides/create-task.html
@@ -23,48 +25,78 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
2325
* @type import('hardhat/config').HardhatUserConfig
2426
*/
2527

26-
27-
/**
28-
* @type import('hardhat/config').HardhatUserConfig
29-
*/
30-
31-
require('dotenv').config();
32-
require("@nomiclabs/hardhat-ethers");
33-
34-
const { ETH_RINKEBY_API_URL, ETH_RINKEBY_PRIVATE_KEY, ETH_MAINNET_API_URL, ETH_MAINNET_PRIVATE_KEY, ETHERSCAN_API_KEY } = process.env;
28+
const {
29+
GOERLI_URL,
30+
MUMBAI_URL,
31+
PRIVATE_KEY,
32+
MAINNET_URL,
33+
POLYGON_URL,
34+
ETHERSCAN_API_KEY,
35+
POLYGONSCAN_API_KEY,
36+
} = process.env;
3537

3638
module.exports = {
3739
solidity: {
38-
version: "0.8.10",
40+
compilers: [
41+
{
42+
version: "0.6.6",
43+
},
44+
{
45+
version: "0.8.10",
46+
},
47+
],
3948
settings: {
4049
optimizer: {
4150
enabled: true,
42-
runs: 200
43-
}
44-
}
45-
},
46-
defaultNetwork: "rinkeby",
47-
networks: {
48-
hardhat: {},
49-
eth_rinkeby: {
50-
url: ETH_RINKEBY_API_URL,
51-
gas: 4000000,
52-
accounts: [`0x${ETH_RINKEBY_PRIVATE_KEY}`]
51+
runs: 200,
52+
},
53+
outputSelection: {
54+
"*": {
55+
"*": ["storageLayout"],
56+
},
5357
},
54-
eth_mainnet: {
55-
url: ETH_MAINNET_API_URL,
56-
gasPrice: 140000000000,
57-
gas: 3800000,
58-
accounts: [`0x${ETH_MAINNET_PRIVATE_KEY}`]
59-
}
60-
},
61-
etherscan: {
62-
apiKey: ETHERSCAN_API_KEY,
58+
},
59+
},
60+
defaultNetwork: "hardhat",
61+
networks: {
62+
hardhat: {
63+
allowUnlimitedContractSize: true,
64+
},
65+
goerli: {
66+
url: GOERLI_URL || "",
67+
accounts: PRIVATE_KEY !== undefined ? [`0x${PRIVATE_KEY}`] : [],
68+
allowUnlimitedContractSize: true,
69+
},
70+
mumbai: {
71+
url: MUMBAI_URL || "",
72+
accounts: PRIVATE_KEY !== undefined ? [`0x${PRIVATE_KEY}`] : [],
73+
},
74+
mainnet: {
75+
url: MAINNET_URL || "",
76+
gasPrice: 70000000000,
77+
gas: 3400000,
78+
accounts: PRIVATE_KEY !== undefined ? [`0x${PRIVATE_KEY}`] : [],
79+
},
80+
polygon: {
81+
url: POLYGON_URL || "",
82+
accounts: PRIVATE_KEY !== undefined ? [`0x${PRIVATE_KEY}`] : [],
83+
},
84+
},
85+
etherscan: {
86+
apiKey: POLYGONSCAN_API_KEY,
87+
},
88+
contractSizer: {
89+
alphaSort: true,
90+
runOnCompile: process.env.CONTRACT_SIZER !== undefined,
91+
disambiguatePaths: false,
6392
},
6493
paths: {
6594
sources: "./contracts",
6695
tests: "./test",
6796
cache: "./cache",
68-
artifacts: "./artifacts"
97+
artifacts: "./artifacts",
98+
},
99+
gasReporter: {
100+
enabled: !!process.env.REPORT_GAS,
69101
},
70-
}
102+
};

0 commit comments

Comments
 (0)