Skip to content

Commit

Permalink
Add contracts for DMC 2.0 and test for devidend comtract
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed Apr 21, 2024
1 parent c9dc050 commit de9de7e
Show file tree
Hide file tree
Showing 5 changed files with 810 additions and 0 deletions.
44 changes: 44 additions & 0 deletions contracts/dmc2.sol
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;
}
}
35 changes: 35 additions & 0 deletions contracts/exchange2.sol
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);
}
}
34 changes: 34 additions & 0 deletions contracts/gwt2.sol
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);
}
}
Loading

0 comments on commit de9de7e

Please sign in to comment.