-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contracts for DMC 2.0 and test for devidend comtract
- Loading branch information
Showing
5 changed files
with
810 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract DMC2 is ERC20Burnable, Ownable { | ||
uint256 unReleaseSupply; | ||
mapping (address => bool) allow_minter; | ||
|
||
modifier onlyMinter() { | ||
require(allow_minter[msg.sender], "mint not allowed"); | ||
_; | ||
} | ||
|
||
constructor(uint256 _unReleaseSupply, address[] memory initAddress, uint[] memory initAmount) ERC20("Datamall Chain Token", "DMC") Ownable(msg.sender) { | ||
|
||
uint256 _totalSupply = _unReleaseSupply; | ||
for (uint i = 0; i < initAddress.length; i++) { | ||
_mint(initAddress[i], initAmount[i]); | ||
_totalSupply -= initAmount[i]; | ||
} | ||
|
||
unReleaseSupply = _totalSupply; | ||
} | ||
|
||
function enableMinter(address[] calldata addresses) public onlyOwner { | ||
for (uint i = 0; i < addresses.length; i++) { | ||
allow_minter[addresses[i]] = true; | ||
} | ||
} | ||
|
||
function disableMinter(address[] calldata addresses) public onlyOwner { | ||
for (uint i = 0; i < addresses.length; i++) { | ||
allow_minter[addresses[i]] = false; | ||
} | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyMinter { | ||
require(unReleaseSupply >= amount, "max supply exceeded"); | ||
_mint(to, amount); | ||
unReleaseSupply -= amount; | ||
} | ||
} |
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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./dmc2.sol"; | ||
import "./gwt2.sol"; | ||
import "./public_data_storage2.sol"; | ||
|
||
contract Exchange2 { | ||
DMC2 dmcToken; | ||
GWTToken2 gwtToken; | ||
PublicDataStorage2 publicDataStorage; | ||
address fundationIncome; | ||
constructor(address _dmcToken, address _gwtToken, address _publicDataStorage, address _fundationIncome) { | ||
dmcToken = DMC2(_dmcToken); | ||
gwtToken = GWTToken2(_gwtToken); | ||
publicDataStorage = PublicDataStorage2(_publicDataStorage); | ||
fundationIncome = _fundationIncome; | ||
} | ||
|
||
function getExchangeRate() public view returns (uint256) { | ||
return publicDataStorage.getExchangeRate(); | ||
} | ||
|
||
function exchangeGWT(uint256 amount) public { | ||
uint256 rate = getExchangeRate(); | ||
dmcToken.burnFrom(msg.sender, amount); | ||
gwtToken.mint(msg.sender, amount * rate); | ||
} | ||
|
||
function exchangeDMC(uint256 amount) public { | ||
uint256 rate = getExchangeRate(); | ||
gwtToken.transferFrom(msg.sender, fundationIncome, amount); | ||
dmcToken.mint(msg.sender, amount / rate); | ||
} | ||
} |
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,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract GWTToken2 is ERC20, Ownable { | ||
mapping (address => bool) allow_minter; | ||
|
||
constructor() ERC20("Gb storage per Week Token", "GWT") Ownable(msg.sender) { | ||
|
||
} | ||
|
||
modifier onlyMinter() { | ||
require(allow_minter[msg.sender], "mint not allowed"); | ||
_; | ||
} | ||
|
||
function enableMinter(address[] calldata addresses) public onlyOwner { | ||
for (uint i = 0; i < addresses.length; i++) { | ||
allow_minter[addresses[i]] = true; | ||
} | ||
} | ||
|
||
function disableMinter(address[] calldata addresses) public onlyOwner { | ||
for (uint i = 0; i < addresses.length; i++) { | ||
allow_minter[addresses[i]] = false; | ||
} | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyMinter { | ||
_mint(to, amount); | ||
} | ||
} |
Oops, something went wrong.