Last active
June 9, 2023 10:36
-
-
Save publu/3707ad4c26eb99cdba104fddb4194c31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | |
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
| import "@openzeppelin/contracts/access/Ownable.sol"; | |
| import "@openzeppelin/contracts/security/Pausable.sol"; | |
| /** | |
| * @title TokenWrapper | |
| * @dev A contract that allows users to wrap and unwrap an ERC20 token. | |
| * It provides a bridging functionality with Axelar using POL (Protocol-Owned Liquidity), | |
| * and an additional layer of security for users in case of bridge issues. | |
| * Users and the protocol can wrap the MAI token into the Axelar ecosystem to bridge | |
| * it across various chains available in the Axelar bridge. | |
| */ | |
| contract TokenWrapper is ERC20, Ownable, Pausable { | |
| IERC20 public constant token; // The underlying ERC20 token to be wrapped | |
| /** | |
| * @dev Initializes the TokenWrapper contract. | |
| * @param _token The address of the underlying ERC20 token. | |
| */ | |
| constructor(IERC20 _token) ERC20("wrappedMAI", "MAI") { | |
| token = _token; // Sets the underlying token | |
| } | |
| /** | |
| * @dev Allows users to deposit tokens into the contract and receive wrapped tokens in return. | |
| * @param amount The amount of tokens to deposit. | |
| */ | |
| function deposit(uint256 amount) public whenNotPaused { | |
| token.transferFrom(_msgSender(), address(this), amount); // Transfers tokens from the user to the contract | |
| _mint(_msgSender(), amount); // Mints wrapped tokens to the user | |
| } | |
| /** | |
| * @dev Allows users to withdraw wrapped tokens and receive the underlying tokens in return. | |
| * @param amount The amount of wrapped tokens to withdraw. | |
| */ | |
| function withdraw(uint256 amount) public whenNotPaused { | |
| _burn(_msgSender(), amount); // Burns the wrapped tokens from the user | |
| token.transfer(_msgSender(), amount); // Transfers the underlying tokens to the user | |
| } | |
| /** | |
| * @dev Allows the owner of the contract to pause token transfers. | |
| * Only the contract owner can call this function. | |
| */ | |
| function pause() public onlyOwner { | |
| _pause(); // Pauses token transfers | |
| } | |
| /** | |
| * @dev Allows the owner of the contract to unpause token transfers. | |
| * Only the contract owner can call this function. | |
| */ | |
| function unpause() public onlyOwner { | |
| _unpause(); // Unpauses token transfers | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment