-
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: tests #39
Draft
fadeev
wants to merge
27
commits into
main
Choose a base branch
from
tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: tests #39
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f0e314d
nft: refactor to extract transferCrossChain into an abstract contract
fadeev 340382c
moved onCall
fadeev d85352d
wip
fadeev a4ed35c
setGasLimit
fadeev 33e6534
UniversalNFTCore
fadeev fe51dcd
refactor
fadeev 3ea0deb
wip
fadeev 0d82aa5
wip
fadeev b3a4f98
rename args in task
fadeev e805e07
solidity version
fadeev 4ddd500
token: refactor evm
fadeev e02e7c8
token: refactor evm
fadeev 7556e00
token: refactor zetachain
fadeev d525935
fix: Reentrancy vulnerabilities
fadeev 9a70620
approve failed
fadeev 8da771b
fix: wrong amount when refunding
fadeev 00db9b7
wip
fadeev 9bb8434
wip
fadeev 292c92a
wip
fadeev 17a6847
wip
fadeev 3df2c24
wip
fadeev a609579
wip
fadeev 32c6157
wip
fadeev 742a8b0
wip
fadeev b5164d7
wip
fadeev dae05a4
wip
fadeev 0d3a373
wip
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 |
---|---|---|
|
@@ -18,4 +18,6 @@ access_token | |
|
||
localnet.json | ||
|
||
.openzeppelin | ||
.openzeppelin | ||
|
||
remappings.txt |
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
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,164 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import "@zetachain/protocol-contracts/contracts/evm/GatewayEVM.sol"; | ||
import {RevertOptions} from "@zetachain/protocol-contracts/contracts/evm/GatewayEVM.sol"; | ||
import "../shared/UniversalNFTEvents.sol"; | ||
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; | ||
import {ERC721URIStorageUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
|
||
abstract contract UniversalNFTCore is | ||
ERC721Upgradeable, | ||
ERC721URIStorageUpgradeable, | ||
OwnableUpgradeable, | ||
UniversalNFTEvents | ||
{ | ||
GatewayEVM public gateway; | ||
address public universal; | ||
uint256 public gasLimitAmount; | ||
|
||
error InvalidAddress(); | ||
error Unauthorized(); | ||
error InvalidGasLimit(); | ||
error GasTokenTransferFailed(); | ||
|
||
modifier onlyGateway() { | ||
if (msg.sender != address(gateway)) revert Unauthorized(); | ||
_; | ||
} | ||
|
||
function setGasLimit(uint256 gas) external onlyOwner { | ||
if (gas == 0) revert InvalidGasLimit(); | ||
gasLimitAmount = gas; | ||
} | ||
|
||
function setUniversal(address contractAddress) external onlyOwner { | ||
if (contractAddress == address(0)) revert InvalidAddress(); | ||
universal = contractAddress; | ||
emit SetUniversal(contractAddress); | ||
} | ||
|
||
function __UniversalNFTCore_init( | ||
address gatewayAddress, | ||
address universalAddress, | ||
uint256 gas | ||
) internal virtual onlyInitializing { | ||
if (gatewayAddress == address(0)) revert InvalidAddress(); | ||
if (universalAddress == address(0)) revert InvalidAddress(); | ||
if (gas == 0) revert InvalidGasLimit(); | ||
gateway = GatewayEVM(gatewayAddress); | ||
universal = universalAddress; | ||
gasLimitAmount = gas; | ||
} | ||
|
||
/** | ||
* @notice Transfers an NFT to another chain. | ||
* @dev Burns the NFT locally, then sends an encoded message to the | ||
* Gateway to recreate it on the destination chain (or revert if needed). | ||
* @param tokenId The ID of the NFT to transfer. | ||
* @param receiver The address on the destination chain that will receive the NFT. | ||
* @param destination The contract address on the destination chain (or address(0) if same chain). | ||
*/ | ||
function transferCrossChain( | ||
uint256 tokenId, | ||
address receiver, | ||
address destination | ||
) external payable virtual { | ||
if (receiver == address(0)) revert InvalidAddress(); | ||
|
||
string memory uri = tokenURI(tokenId); | ||
|
||
_burn(tokenId); | ||
|
||
bytes memory message = abi.encode( | ||
destination, | ||
receiver, | ||
tokenId, | ||
uri, | ||
msg.sender | ||
); | ||
|
||
emit TokenTransfer(destination, receiver, tokenId, uri); | ||
|
||
if (destination == address(0)) { | ||
gateway.call( | ||
universal, | ||
message, | ||
RevertOptions(address(this), false, address(0), message, 0) | ||
); | ||
} else { | ||
gateway.depositAndCall{value: msg.value}( | ||
universal, | ||
message, | ||
RevertOptions( | ||
address(this), | ||
true, | ||
address(0), | ||
abi.encode(receiver, tokenId, uri, msg.sender), | ||
gasLimitAmount | ||
) | ||
); | ||
} | ||
} | ||
|
||
function onCall( | ||
MessageContext calldata context, | ||
bytes calldata message | ||
) external payable onlyGateway returns (bytes4) { | ||
if (context.sender != universal) revert Unauthorized(); | ||
|
||
( | ||
address receiver, | ||
uint256 tokenId, | ||
string memory uri, | ||
uint256 gasAmount, | ||
address sender | ||
) = abi.decode(message, (address, uint256, string, uint256, address)); | ||
|
||
_safeMint(receiver, tokenId); | ||
_setTokenURI(tokenId, uri); | ||
if (gasAmount > 0) { | ||
if (sender == address(0)) revert InvalidAddress(); | ||
(bool success, ) = payable(sender).call{value: gasAmount}(""); | ||
if (!success) revert GasTokenTransferFailed(); | ||
} | ||
emit TokenTransferReceived(receiver, tokenId, uri); | ||
return ""; | ||
} | ||
|
||
function onRevert(RevertContext calldata context) external onlyGateway { | ||
(, uint256 tokenId, string memory uri, address sender) = abi.decode( | ||
context.revertMessage, | ||
(address, uint256, string, address) | ||
); | ||
|
||
_safeMint(sender, tokenId); | ||
_setTokenURI(tokenId, uri); | ||
emit TokenTransferReverted(sender, tokenId, uri); | ||
} | ||
|
||
function tokenURI( | ||
uint256 tokenId | ||
) | ||
public | ||
view | ||
virtual | ||
override(ERC721Upgradeable, ERC721URIStorageUpgradeable) | ||
returns (string memory) | ||
{ | ||
return super.tokenURI(tokenId); | ||
} | ||
|
||
function supportsInterface( | ||
bytes4 interfaceId | ||
) | ||
public | ||
view | ||
virtual | ||
override(ERC721Upgradeable, ERC721URIStorageUpgradeable) | ||
returns (bool) | ||
{ | ||
return super.supportsInterface(interfaceId); | ||
} | ||
} |
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
Low-level calls Warning