Skip to content

Commit

Permalink
GWT test mint use transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed May 13, 2024
1 parent 0a44e31 commit 2193ee6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 10 additions & 3 deletions contracts/dmc_bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ contract DMCBridge is Ownable {
dmc2 = DMC(_dmc2);
}

function registerDMC1(address recvAddress, string calldata cookie, uint256 dmc1Amount) onlyOwner public {
dmc1_to_dmc2[keccak256(abi.encodePacked(recvAddress, cookie))] = dmc1Amount;
function getClaimableDMC2(string calldata cookie) public view returns (uint256) {
return dmc1_to_dmc2[keccak256(abi.encodePacked(msg.sender, cookie))] * 79 / 100;
}

function registerDMC1(address[] calldata recvAddress, string[] calldata cookie, uint256[] calldata dmc1Amount) onlyOwner public {
for (uint i = 0; i < recvAddress.length; i++) {
dmc1_to_dmc2[keccak256(abi.encodePacked(recvAddress[i], cookie[i]))] = dmc1Amount[i];
}

}

function claimDMC2(string calldata cookie) public {
bytes32 key = keccak256(abi.encodePacked(msg.sender, cookie));
require(dmc1_to_dmc2[key] > 0, "no dmc1 amount");
uint256 dmc2Amount = dmc1_to_dmc2[key] * 4 / 5;
uint256 dmc2Amount = dmc1_to_dmc2[key] * 79 / 100;
dmc1_to_dmc2[key] = 0;

dmc2.transfer(msg.sender, dmc2Amount);
Expand Down
17 changes: 11 additions & 6 deletions contracts/exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ contract Exchange is Initializable, UUPSUpgradeable, OwnableUpgradeable {
function initialize(address _dmcToken, address _gwtToken, address _fundationIncome, uint256 _min_circle_time) public initializer {
__UUPSUpgradeable_init();
__Ownable_init(msg.sender);
__Exchange2Upgradable_init(_dmcToken, _gwtToken, _fundationIncome, _min_circle_time);
__ExchangeUpgradable_init(_dmcToken, _gwtToken, _fundationIncome, _min_circle_time);
}

function __Exchange2Upgradable_init(address _dmcToken, address _gwtToken, address _fundationIncome, uint256 _min_circle_time) public onlyInitializing {
function __ExchangeUpgradable_init(address _dmcToken, address _gwtToken, address _fundationIncome, uint256 _min_circle_time) public onlyInitializing {
require(_min_circle_time > 0);
dmcToken = _dmcToken;
gwtToken = _gwtToken;
Expand Down Expand Up @@ -186,8 +186,12 @@ contract Exchange is Initializable, UUPSUpgradeable, OwnableUpgradeable {

is_free_minted[msg.sender] = true;
free_mint_balance -= 210 ether;
GWT(gwtToken).mint(msg.sender, 210 ether);
}
GWT(gwtToken).transfer(msg.sender, 210 ether);
}

function canFreeMint() view public returns (bool) {
return !is_free_minted[msg.sender];
}

function DMCtoGWT(uint256 amount) public {
DMC(dmcToken).burnFrom(msg.sender, amount);
Expand Down Expand Up @@ -241,8 +245,9 @@ contract Exchange is Initializable, UUPSUpgradeable, OwnableUpgradeable {

// 手工将累积的收入打给分红合约
function transferIncome() public {
GWT(gwtToken).approve(fundationIncome, GWT(gwtToken).balanceOf(address(this)));
DividendContract(payable(fundationIncome)).deposit(GWT(gwtToken).balanceOf(address(this)), address(gwtToken));
uint256 income = GWT(gwtToken).balanceOf(address(this)) - free_mint_balance;
GWT(gwtToken).approve(fundationIncome, income);
DividendContract(payable(fundationIncome)).deposit(income, address(gwtToken));
}

function getCycleInfo() public view returns (uint256, uint256, uint256) {
Expand Down

0 comments on commit 2193ee6

Please sign in to comment.