Skip to content

Commit

Permalink
update gwt exchange code
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed Dec 27, 2023
1 parent 952b216 commit 47f0d10
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions contracts/gwt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ contract GWTToken is ERC20, Ownable {
}
}

function _calcGWTAmount(uint256 amount, uint256 remainSupply) internal pure returns(uint256) {
function _calcGWTAmount(uint256 amount) internal pure returns(uint256) {
// 1 : 210
return amount * 210;
}

function _calcDMCAmount(uint256 amount, uint256 remainSupply) internal pure returns(uint256) {
function _calcDMCAmount(uint256 amount) internal pure returns(uint256) {
// 210 : 1
return amount / 210;
}
Expand All @@ -40,4 +40,18 @@ contract GWTToken is ERC20, Ownable {
require(allow_transfer[sender] || allow_transfer[to], "transfer not allowed");
super._update(sender, to, amount);
}

function exchange(uint256 amount) public {
uint256 gwtAmount = _calcGWTAmount(amount);

dmcToken.transferFrom(msg.sender, address(this), amount);
_mint(msg.sender, gwtAmount);
}

function burn(uint256 amount) public {
uint256 dmcAmount = _calcDMCAmount(amount);

dmcToken.transfer(msg.sender, dmcAmount);
_burn(msg.sender, amount);
}
}

0 comments on commit 47f0d10

Please sign in to comment.