Skip to content

Commit

Permalink
fix: make contracts pausable (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored Dec 23, 2024
1 parent ae1b1d8 commit 5dbab72
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 18 deletions.
27 changes: 22 additions & 5 deletions contracts/nft/contracts/evm/UniversalNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ import {ERC721URIStorageUpgradeable} from "@openzeppelin/contracts-upgradeable/t
import {ERC721BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {ERC721PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721PausableUpgradeable.sol";

import "../shared/UniversalNFTEvents.sol";

contract UniversalNFT is
Initializable,
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
ERC721URIStorageUpgradeable,
ERC721BurnableUpgradeable,
ERC721EnumerableUpgradeable,
ERC721PausableUpgradeable,
OwnableUpgradeable,
ERC721BurnableUpgradeable,
UUPSUpgradeable,
UniversalNFTEvents
{
Expand Down Expand Up @@ -74,7 +76,10 @@ contract UniversalNFT is
emit SetUniversal(contractAddress);
}

function safeMint(address to, string memory uri) public onlyOwner {
function safeMint(
address to,
string memory uri
) public whenNotPaused onlyOwner {
uint256 hash = uint256(
keccak256(
abi.encodePacked(address(this), block.number, _nextTokenId++)
Expand All @@ -92,7 +97,7 @@ contract UniversalNFT is
uint256 tokenId,
address receiver,
address destination
) external payable {
) external payable whenNotPaused {
if (receiver == address(0)) revert InvalidAddress();

string memory uri = tokenURI(tokenId);
Expand Down Expand Up @@ -171,7 +176,11 @@ contract UniversalNFT is
address auth
)
internal
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
override(
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
ERC721PausableUpgradeable
)
returns (address)
{
return super._update(to, tokenId, auth);
Expand Down Expand Up @@ -214,5 +223,13 @@ contract UniversalNFT is
address newImplementation
) internal override onlyOwner {}

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

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

receive() external payable {}
}
31 changes: 24 additions & 7 deletions contracts/nft/contracts/zetachain/UniversalNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IWZETA.sol";
import "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol";
import {SwapHelperLib} from "@zetachain/toolkit/contracts/SwapHelperLib.sol";
import {SystemContract} from "@zetachain/toolkit/contracts/SystemContract.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import {ERC721BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import {ERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import {ERC721PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721PausableUpgradeable.sol";
import {ERC721URIStorageUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import {ERC721BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

Expand All @@ -21,10 +22,11 @@ import "../shared/UniversalNFTEvents.sol";
contract UniversalNFT is
Initializable,
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
ERC721URIStorageUpgradeable,
ERC721BurnableUpgradeable,
ERC721EnumerableUpgradeable,
ERC721PausableUpgradeable,
OwnableUpgradeable,
ERC721BurnableUpgradeable,
UniversalContract,
UUPSUpgradeable,
UniversalNFTEvents
Expand Down Expand Up @@ -93,7 +95,7 @@ contract UniversalNFT is
uint256 tokenId,
address receiver,
address destination
) public payable {
) public payable whenNotPaused {
if (msg.value == 0) revert ZeroMsgValue();
if (receiver == address(0)) revert InvalidAddress();
string memory uri = tokenURI(tokenId);
Expand Down Expand Up @@ -153,7 +155,10 @@ contract UniversalNFT is
emit TokenTransfer(receiver, destination, tokenId, uri);
}

function safeMint(address to, string memory uri) public onlyOwner {
function safeMint(
address to,
string memory uri
) public onlyOwner whenNotPaused {
uint256 hash = uint256(
keccak256(
abi.encodePacked(address(this), block.number, _nextTokenId++)
Expand Down Expand Up @@ -239,7 +244,11 @@ contract UniversalNFT is
address auth
)
internal
override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
override(
ERC721Upgradeable,
ERC721EnumerableUpgradeable,
ERC721PausableUpgradeable
)
returns (address)
{
return super._update(to, tokenId, auth);
Expand Down Expand Up @@ -282,5 +291,13 @@ contract UniversalNFT is
address newImplementation
) internal override onlyOwner {}

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

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

receive() external payable {}
}
26 changes: 24 additions & 2 deletions contracts/token/contracts/evm/UniversalToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pragma solidity 0.8.26;
import "@zetachain/protocol-contracts/contracts/evm/GatewayEVM.sol";
import {RevertContext} from "@zetachain/protocol-contracts/contracts/Revert.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC20BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import {ERC20PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {ERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -15,7 +19,9 @@ contract UniversalToken is
Initializable,
ERC20Upgradeable,
ERC20BurnableUpgradeable,
ERC20PausableUpgradeable,
OwnableUpgradeable,
ERC20PermitUpgradeable,
UUPSUpgradeable,
UniversalTokenEvents
{
Expand Down Expand Up @@ -65,15 +71,15 @@ contract UniversalToken is
emit SetUniversal(contractAddress);
}

function mint(address to, uint256 amount) public onlyOwner {
function mint(address to, uint256 amount) public onlyOwner whenNotPaused {
_mint(to, amount);
}

function transferCrossChain(
address destination,
address receiver,
uint256 amount
) external payable {
) external payable whenNotPaused {
if (receiver == address(0)) revert InvalidAddress();
_burn(msg.sender, amount);

Expand Down Expand Up @@ -140,5 +146,21 @@ contract UniversalToken is
address newImplementation
) internal override onlyOwner {}

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

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

function _update(
address from,
address to,
uint256 value
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
super._update(from, to, value);
}

receive() external payable {}
}
29 changes: 26 additions & 3 deletions contracts/token/contracts/zetachain/UniversalToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/UniversalContrac
import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IGatewayZEVM.sol";
import "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol";
import {SwapHelperLib} from "@zetachain/toolkit/contracts/SwapHelperLib.sol";
import {SystemContract} from "@zetachain/toolkit/contracts/SystemContract.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC20BurnableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import {ERC20PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import {ERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
Expand All @@ -19,7 +22,9 @@ contract UniversalToken is
Initializable,
ERC20Upgradeable,
ERC20BurnableUpgradeable,
ERC20PausableUpgradeable,
OwnableUpgradeable,
ERC20PermitUpgradeable,
UUPSUpgradeable,
UniversalContract,
UniversalTokenEvents
Expand Down Expand Up @@ -87,7 +92,7 @@ contract UniversalToken is
address destination,
address receiver,
uint256 amount
) public payable {
) public payable whenNotPaused {
if (msg.value == 0) revert ZeroMsgValue();
if (receiver == address(0)) revert InvalidAddress();
_burn(msg.sender, amount);
Expand Down Expand Up @@ -140,7 +145,7 @@ contract UniversalToken is
emit TokenTransfer(destination, receiver, amount);
}

function mint(address to, uint256 amount) public onlyOwner {
function mint(address to, uint256 amount) public onlyOwner whenNotPaused {
_mint(to, amount);
}

Expand Down Expand Up @@ -200,9 +205,27 @@ contract UniversalToken is
emit TokenTransferReverted(sender, amount);
}

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

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

function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}

receive() external payable {}

// The following functions are overrides required by Solidity.

function _update(
address from,
address to,
uint256 value
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
super._update(from, to, value);
}
}
14 changes: 13 additions & 1 deletion contracts/token/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ const config: HardhatUserConfig = {
networks: {
...getHardhatConfigNetworks(),
},
solidity: "0.8.26",
solidity: {
compilers: [
{
settings: {
optimizer: {
enabled: true,
runs: 1000,
},
},
version: "0.8.26",
},
],
},
};

export default config;

0 comments on commit 5dbab72

Please sign in to comment.