Skip to content

Commit

Permalink
update erc20 contract
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Apr 16, 2024
1 parent 997a167 commit b96bb36
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
35 changes: 29 additions & 6 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract Token is ERC20, ERC20Permit, Ownable, ReentrancyGuard {
event SwapToNative(string to, uint256 amount);
event SwapToNative(address from, string to, uint256 amount);

uint8 private _scale;

Expand Down Expand Up @@ -67,12 +67,35 @@ contract Token is ERC20, ERC20Permit, Ownable, ReentrancyGuard {
* - `to` cannot be the zero address.
* - `amount` caller must have a balance of at least `amount`.
*/
function swapToNative(
function swapToNative(string memory to, uint256 amount)
public
nonReentrant
{
require(bytes(to).length > 0, "to must be vaild iaa address");

_burn(msg.sender, amount);
emit SwapToNative(msg.sender, to, amount);
}

/**
*
* Requirements:
*
* - `from` authorizer address.
* - `to` cannot be the zero address.
* - `amount` from must have a balance of at least `amount`.
*/
function swapToNativeFrom(
address from,
string memory to,
uint256 amount
) public nonReentrant {
require(bytes(to).length > 0, "to must be a vaild iaa address");
_burn(msg.sender, amount);
emit SwapToNative(to, amount);
require(bytes(to).length > 0, "to must be vaild iaa address");

address spender = _msgSender();
_spendAllowance(from, spender, amount);

_burn(from, amount);
emit SwapToNative(from, to, amount);
}
}
}
Loading

0 comments on commit b96bb36

Please sign in to comment.