Skip to content

Instantly share code, notes, and snippets.

@publu
Last active June 9, 2023 10:36
Show Gist options
  • Select an option

  • Save publu/3707ad4c26eb99cdba104fddb4194c31 to your computer and use it in GitHub Desktop.

Select an option

Save publu/3707ad4c26eb99cdba104fddb4194c31 to your computer and use it in GitHub Desktop.

Revisions

  1. publu revised this gist Jun 9, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,6 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable {

    /**
    * @dev Initializes the TokenWrapper contract.
    * @param _token The address of the underlying ERC20 token.
    */
    constructor() ERC20("Wrapped MAI", "WMAI") {}

    @@ -70,10 +69,11 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable {

    /**
    * @dev Allows the owner to withdraw any ERC20 tokens sent here accidentally.
    * @param _token The address of the token to withdraw.
    * @param _tokenAddress The address of the token to withdraw.
    * @param _amount The amount of the token to withdraw.
    */
    function withdrawLostTokens(IERC20 _token, uint256 _amount) public onlyOwner {
    function withdrawLostTokens(address _tokenAddress, uint256 _amount) public onlyOwner {
    IERC20 _token = IERC20(_tokenAddress);
    require(_token != token, "Cannot withdraw the wrapped token");
    require(_token.balanceOf(address(this)) >= _amount, "Not enough balance");

  2. publu revised this gist Jun 9, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable {
    * @dev Initializes the TokenWrapper contract.
    * @param _token The address of the underlying ERC20 token.
    */
    constructor() ERC20("WrappedMAI", "WMAI") {}
    constructor() ERC20("Wrapped MAI", "WMAI") {}

    /**
    * @dev Allows users to deposit tokens into the contract and receive wrapped tokens in return.
  3. publu revised this gist Jun 9, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable {
    * @dev Initializes the TokenWrapper contract.
    * @param _token The address of the underlying ERC20 token.
    */
    constructor() ERC20("WrappedMAI", "wMAI") {}
    constructor() ERC20("WrappedMAI", "WMAI") {}

    /**
    * @dev Allows users to deposit tokens into the contract and receive wrapped tokens in return.
  4. publu revised this gist Jun 9, 2023. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ import "@openzeppelin/contracts/security/Pausable.sol";
    * it across various chains available in the Axelar bridge.
    */
    contract TokenWrapper is ERC20, Ownable2Step, Pausable {
    IERC20 public constant token; // The underlying ERC20 token to be wrapped
    IERC20 public constant token = IERC20(0x8D6CeBD76f18E1558D4DB88138e2DeFB3909fAD6); // MAI on ETH

    event Deposit(address indexed dst, uint256 wad);
    event Withdrawal(address indexed src, uint256 wad);
    @@ -24,9 +24,7 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable {
    * @dev Initializes the TokenWrapper contract.
    * @param _token The address of the underlying ERC20 token.
    */
    constructor(IERC20 _token) ERC20("WrappedMAI", "wMAI") {
    token = _token; // Sets the underlying token
    }
    constructor() ERC20("WrappedMAI", "wMAI") {}

    /**
    * @dev Allows users to deposit tokens into the contract and receive wrapped tokens in return.
  5. publu revised this gist Jun 9, 2023. 1 changed file with 39 additions and 6 deletions.
    45 changes: 39 additions & 6 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

    import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "@openzeppelin/contracts/access/Ownable2Step.sol"; // Updated import
    import "@openzeppelin/contracts/access/Ownable2Step.sol";
    import "@openzeppelin/contracts/security/Pausable.sol";

    /**
    @@ -14,14 +14,17 @@ import "@openzeppelin/contracts/security/Pausable.sol";
    * 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, Ownable2Step, Pausable { // Updated inheritance
    contract TokenWrapper is ERC20, Ownable2Step, Pausable {
    IERC20 public constant token; // The underlying ERC20 token to be wrapped

    event Deposit(address indexed dst, uint256 wad);
    event Withdrawal(address indexed src, uint256 wad);

    /**
    * @dev Initializes the TokenWrapper contract.
    * @param _token The address of the underlying ERC20 token.
    */
    constructor(IERC20 _token) ERC20("wrappedMAI", "MAI") {
    constructor(IERC20 _token) ERC20("WrappedMAI", "wMAI") {
    token = _token; // Sets the underlying token
    }

    @@ -30,8 +33,12 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable { // Updated inheritance
    * @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
    // Transfers tokens from the user to the contract
    bool transferSuccessful = token.transferFrom(_msgSender(), address(this), amount);
    require(transferSuccessful, "Token transfer was not successful.");
    _mint(_msgSender(), amount); // Mints wrapped tokens to the user

    emit Deposit(_msgSender(), amount); // Emits the Deposit event
    }

    /**
    @@ -40,7 +47,11 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable { // Updated inheritance
    */
    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
    // Transfers the underlying tokens to the user
    bool transferSuccessful = token.transfer(_msgSender(), amount);
    require(transferSuccessful, "Token transfer was not successful.");

    emit Withdrawal(_msgSender(), amount); // Emits the Withdrawal event
    }

    /**
    @@ -58,4 +69,26 @@ contract TokenWrapper is ERC20, Ownable2Step, Pausable { // Updated inheritance
    function unpause() public onlyOwner {
    _unpause(); // Unpauses token transfers
    }
    }

    /**
    * @dev Allows the owner to withdraw any ERC20 tokens sent here accidentally.
    * @param _token The address of the token to withdraw.
    * @param _amount The amount of the token to withdraw.
    */
    function withdrawLostTokens(IERC20 _token, uint256 _amount) public onlyOwner {
    require(_token != token, "Cannot withdraw the wrapped token");
    require(_token.balanceOf(address(this)) >= _amount, "Not enough balance");

    _token.transfer(_msgSender(), _amount);
    }

    /**
    * @dev Allows the owner to withdraw any extra balance of the underlying token.
    */
    function withdrawExtraBalance() public onlyOwner {
    uint256 extraBalance = token.balanceOf(address(this)) - totalSupply();
    require(extraBalance > 0, "No extra balance to withdraw");

    token.transfer(_msgSender(), extraBalance);
    }
    }
  6. publu revised this gist Jun 8, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ 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/access/Ownable2Step.sol"; // Updated import
    import "@openzeppelin/contracts/security/Pausable.sol";

    /**
    @@ -14,7 +14,7 @@ import "@openzeppelin/contracts/security/Pausable.sol";
    * 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 {
    contract TokenWrapper is ERC20, Ownable2Step, Pausable { // Updated inheritance
    IERC20 public constant token; // The underlying ERC20 token to be wrapped

    /**
  7. publu revised this gist Jun 8, 2023. 1 changed file with 36 additions and 8 deletions.
    44 changes: 36 additions & 8 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -6,28 +6,56 @@ 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;
    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;
    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);
    _mint(_msgSender(), amount);
    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);
    token.transfer(_msgSender(), amount);
    _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();
    _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();
    _unpause(); // Unpauses token transfers
    }
    }
  8. publu created this gist Jun 8, 2023.
    33 changes: 33 additions & 0 deletions wrappedMAI.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    // 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";

    contract TokenWrapper is ERC20, Ownable, Pausable {
    IERC20 public constant token;

    constructor(IERC20 _token) ERC20("wrappedMAI", "MAI") {
    token = _token;
    }

    function deposit(uint256 amount) public whenNotPaused {
    token.transferFrom(_msgSender(), address(this), amount);
    _mint(_msgSender(), amount);
    }

    function withdraw(uint256 amount) public whenNotPaused {
    _burn(_msgSender(), amount);
    token.transfer(_msgSender(), amount);
    }

    function pause() public onlyOwner {
    _pause();
    }

    function unpause() public onlyOwner {
    _unpause();
    }
    }