-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow incoming and outgoing transfers #30
Closed
Closed
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
560abc1
upgradeable wip
fadeev 9cbb94d
wip
fadeev 6b8e43c
wip
fadeev 76b927b
wip
fadeev 76ecec6
wip
fadeev 7b75695
NFT works
fadeev e56a27b
yarn lock
fadeev 3299510
Remove initialize task
fadeev c10a0c4
token contract now upgradeable
fadeev 2703523
solidity version
fadeev 2d20568
remove comment
fadeev 510ad53
gitignore
fadeev 41115ea
feat: use ZETA for gas when sending from ZetaChain (#10)
fadeev 9ca161f
rename ft contracts
fadeev a3f58ba
FT: pay with ZETA when transferring tokens from ZetaChain
fadeev fd3d640
Merge branch 'main' into upgradeable
fadeev d7e824c
feat: allow incoming and outgoing transfers
fadeev 52f5118
add imports back
fadeev 6f608b2
allow outgoing/incoming on EVM
fadeev c313c24
set variables in initialize
fadeev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ cache_forge | |
access_token | ||
|
||
localnet.json | ||
|
||
.openzeppelin |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,49 +2,85 @@ | |
pragma solidity 0.8.26; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; | ||
import "@openzeppelin/contracts/access/Ownable2Step.sol"; | ||
import "@zetachain/protocol-contracts/contracts/evm/GatewayEVM.sol"; | ||
import {RevertContext} from "@zetachain/protocol-contracts/contracts/Revert.sol"; | ||
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; | ||
import {ERC721EnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; | ||
import {ERC721URIStorageUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; | ||
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 "../shared/Events.sol"; | ||
|
||
abstract contract UniversalNFT is | ||
ERC721, | ||
ERC721Enumerable, | ||
ERC721URIStorage, | ||
Ownable2Step, | ||
contract UniversalNFT is | ||
Initializable, | ||
ERC721Upgradeable, | ||
ERC721EnumerableUpgradeable, | ||
ERC721URIStorageUpgradeable, | ||
ERC721BurnableUpgradeable, | ||
OwnableUpgradeable, | ||
UUPSUpgradeable, | ||
Events | ||
{ | ||
GatewayEVM public immutable gateway; | ||
GatewayEVM public gateway; | ||
uint256 private _nextTokenId; | ||
address public universal; | ||
uint256 public immutable gasLimitAmount; | ||
uint256 public gasLimitAmount; | ||
|
||
bool public allowOutgoing = true; | ||
bool public allowIncoming = true; | ||
|
||
error InvalidAddress(); | ||
error Unauthorized(); | ||
error InvalidGasLimit(); | ||
error GasTokenTransferFailed(); | ||
|
||
function setUniversal(address contractAddress) external onlyOwner { | ||
if (contractAddress == address(0)) revert InvalidAddress(); | ||
universal = contractAddress; | ||
emit SetUniversal(contractAddress); | ||
} | ||
error OutgoingTransfersNotAllowed(); | ||
error IncomingTransfersNotAllowed(); | ||
|
||
modifier onlyGateway() { | ||
if (msg.sender != address(gateway)) revert Unauthorized(); | ||
_; | ||
} | ||
|
||
constructor(address payable gatewayAddress, uint256 gas) { | ||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize( | ||
address initialOwner, | ||
string memory name, | ||
string memory symbol, | ||
address payable gatewayAddress, | ||
uint256 gas | ||
) public initializer { | ||
__ERC721_init(name, symbol); | ||
__ERC721Enumerable_init(); | ||
__ERC721URIStorage_init(); | ||
__Ownable_init(initialOwner); | ||
__UUPSUpgradeable_init(); | ||
if (gatewayAddress == address(0)) revert InvalidAddress(); | ||
if (gas == 0) revert InvalidGasLimit(); | ||
gasLimitAmount = gas; | ||
gateway = GatewayEVM(gatewayAddress); | ||
} | ||
|
||
function setAllowOutgoing(bool _allowOutgoing) external onlyOwner { | ||
allowOutgoing = _allowOutgoing; | ||
} | ||
|
||
function setAllowIncoming(bool _allowIncoming) external onlyOwner { | ||
Check warning Code scanning / Slither Conformance to Solidity naming conventions Warning
Parameter UniversalNFT.setAllowIncoming(bool)._allowIncoming is not in mixedCase
|
||
allowIncoming = _allowIncoming; | ||
} | ||
|
||
function setUniversal(address contractAddress) external onlyOwner { | ||
if (contractAddress == address(0)) revert InvalidAddress(); | ||
universal = contractAddress; | ||
emit SetUniversal(contractAddress); | ||
} | ||
|
||
function safeMint(address to, string memory uri) public onlyOwner { | ||
uint256 hash = uint256( | ||
keccak256( | ||
|
@@ -64,6 +100,7 @@ | |
address receiver, | ||
address destination | ||
) external payable { | ||
if (!allowOutgoing) revert OutgoingTransfersNotAllowed(); | ||
if (receiver == address(0)) revert InvalidAddress(); | ||
|
||
string memory uri = tokenURI(tokenId); | ||
|
@@ -102,6 +139,7 @@ | |
MessageContext calldata context, | ||
bytes calldata message | ||
) external payable onlyGateway returns (bytes4) { | ||
if (!allowIncoming) revert IncomingTransfersNotAllowed(); | ||
if (context.sender != universal) revert Unauthorized(); | ||
|
||
( | ||
|
@@ -144,20 +182,29 @@ | |
address to, | ||
uint256 tokenId, | ||
address auth | ||
) internal override(ERC721, ERC721Enumerable) returns (address) { | ||
) | ||
internal | ||
override(ERC721Upgradeable, ERC721EnumerableUpgradeable) | ||
returns (address) | ||
{ | ||
return super._update(to, tokenId, auth); | ||
} | ||
|
||
function _increaseBalance( | ||
address account, | ||
uint128 value | ||
) internal override(ERC721, ERC721Enumerable) { | ||
) internal override(ERC721Upgradeable, ERC721EnumerableUpgradeable) { | ||
super._increaseBalance(account, value); | ||
} | ||
|
||
function tokenURI( | ||
uint256 tokenId | ||
) public view override(ERC721, ERC721URIStorage) returns (string memory) { | ||
) | ||
public | ||
view | ||
override(ERC721Upgradeable, ERC721URIStorageUpgradeable) | ||
returns (string memory) | ||
{ | ||
return super.tokenURI(tokenId); | ||
} | ||
|
||
|
@@ -166,9 +213,17 @@ | |
) | ||
public | ||
view | ||
override(ERC721, ERC721Enumerable, ERC721URIStorage) | ||
override( | ||
ERC721Upgradeable, | ||
ERC721EnumerableUpgradeable, | ||
ERC721URIStorageUpgradeable | ||
) | ||
returns (bool) | ||
{ | ||
return super.supportsInterface(interfaceId); | ||
} | ||
|
||
function _authorizeUpgrade( | ||
address newImplementation | ||
) internal override onlyOwner {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.26; | ||
|
||
import "../evm/UniversalNFT.sol"; | ||
|
||
contract EVMUniversalNFT is UniversalNFT {} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import "../zetachain/UniversalNFT.sol"; | ||
|
||
contract ZetaChainUniversalNFT is UniversalNFT {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning