-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48f4121
commit ea6729e
Showing
8 changed files
with
650 additions
and
890 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ node_modules | |
coverage | ||
coverage.json | ||
typechain | ||
.openzeppelin | ||
|
||
#Hardhat files | ||
cache | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.10; | ||
|
||
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; | ||
|
||
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; | ||
|
||
contract Dimo is | ||
ERC20Upgradeable, | ||
AccessControlUpgradeable, | ||
PausableUpgradeable, | ||
UUPSUpgradeable | ||
{ | ||
bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE"); | ||
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); | ||
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); | ||
bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE"); | ||
|
||
function initialize() public initializer { | ||
__ERC20_init("Dimo", "DIMO"); | ||
__AccessControl_init(); | ||
__Pausable_init(); | ||
__UUPSUpgradeable_init(); | ||
|
||
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
} | ||
|
||
function pause() public onlyRole(PAUSER_ROLE) { | ||
_pause(); | ||
} | ||
|
||
function unpause() public onlyRole(PAUSER_ROLE) { | ||
_unpause(); | ||
} | ||
|
||
|
||
/// @notice called when token is deposited on root chain | ||
/// @dev Should be callable only by ChildChainManager | ||
/// Should handle deposit by minting the required amount for user | ||
/// @param user user address for whom deposit is being done | ||
/// @param depositData abi encoded amount | ||
function deposit(address user, bytes calldata depositData) | ||
external | ||
onlyRole(DEPOSITOR_ROLE) | ||
{ | ||
uint256 amount = abi.decode(depositData, (uint256)); | ||
_mint(user, amount); | ||
} | ||
|
||
|
||
/// @notice called when user wants to withdraw tokens back to root chain | ||
/// @dev Should burn user's tokens. This transaction will be verified when exiting on root chain | ||
/// @param amount amount of tokens to withdraw | ||
function withdraw(uint256 amount) external { | ||
_burn(_msgSender(), amount); | ||
} | ||
|
||
|
||
function mint(address user, uint256 amount) public onlyRole(MINTER_ROLE) { | ||
_mint(user, amount); | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal override whenNotPaused { | ||
super._beforeTokenTransfer(from, to, amount); | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) | ||
internal | ||
override | ||
onlyRole(UPGRADER_ROLE) | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.