Skip to content
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

NFT & Fungible token contracts #1

Merged
merged 16 commits into from
Nov 27, 2024
Merged

NFT & Fungible token contracts #1

merged 16 commits into from
Nov 27, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Nov 26, 2024

No description provided.

@fadeev fadeev marked this pull request as ready for review November 26, 2024 17:21
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Comment on lines 62 to 99
function transferCrossChain(
uint256 tokenId,
address receiver,
address destination
) external payable {
if (receiver == address(0)) revert InvalidAddress();

string memory uri = tokenURI(tokenId);
_burn(tokenId);
bytes memory message = abi.encode(
destination,
receiver,
tokenId,
uri,
msg.sender
);
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),
gasLimit
)
);
}

emit TokenTransfer(destination, receiver, tokenId, uri);
}
Comment on lines 101 to 123
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) {
(bool success, ) = sender.call{value: gasAmount}("");
if (!success) revert GasTokenTransferFailed();
}
emit TokenTransferReceived(receiver, tokenId, uri);
return "";
}

Check warning

Code scanning / Slither

Low-level calls Warning

contracts/nft/contracts/evm/UniversalNFT.sol Fixed Show resolved Hide resolved
contracts/nft/contracts/example/Connected.sol Fixed Show resolved Hide resolved
contracts/nft/contracts/example/Universal.sol Fixed Show resolved Hide resolved
Comment on lines 64 to 107
function transferCrossChain(
uint256 tokenId,
address receiver,
address destination
) public {
if (receiver == address(0)) revert InvalidAddress();
string memory uri = tokenURI(tokenId);
_burn(tokenId);

(, uint256 gasFee) = IZRC20(destination).withdrawGasFeeWithGasLimit(
gasLimit
);
if (
!IZRC20(destination).transferFrom(msg.sender, address(this), gasFee)
) revert TransferFailed();
IZRC20(destination).approve(address(gateway), gasFee);
bytes memory message = abi.encode(
receiver,
tokenId,
uri,
0,
msg.sender
);

CallOptions memory callOptions = CallOptions(gasLimit, false);

RevertOptions memory revertOptions = RevertOptions(
address(this),
true,
address(0),
abi.encode(tokenId, uri, msg.sender),
gasLimit
);

gateway.call(
abi.encodePacked(connected[destination]),
destination,
message,
callOptions,
revertOptions
);

emit TokenTransfer(receiver, destination, tokenId, uri);
}
contracts/nft/contracts/zetachain/UniversalNFT.sol Fixed Show resolved Hide resolved
Comment on lines +195 to +200
function _increaseBalance(
address account,
uint128 value
) internal override(ERC721, ERC721Enumerable) {
super._increaseBalance(account, value);
}

Check warning

Code scanning / Slither

Dead-code Warning

UniversalNFT._increaseBalance(address,uint128) is never used and should be removed
Comment on lines 41 to 76
function transferCrossChain(
address destination,
address receiver,
uint256 amount
) external payable {
if (receiver == address(0)) revert InvalidAddress();
_burn(msg.sender, amount);

bytes memory message = abi.encode(
destination,
receiver,
amount,
msg.sender
);
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(amount, msg.sender),
gasLimit
)
);
}

emit TokenTransfer(destination, receiver, amount);
}
Comment on lines 78 to 96
function onCall(
MessageContext calldata context,
bytes calldata message
) external payable onlyGateway returns (bytes4) {
if (context.sender != universal) revert Unauthorized();
(
address receiver,
uint256 amount,
uint256 gasAmount,
address sender
) = abi.decode(message, (address, uint256, uint256, address));
_mint(receiver, amount);
if (gasAmount > 0) {
(bool success, ) = sender.call{value: amount}("");
if (!success) revert GasTokenTransferFailed();
}
emit TokenTransferReceived(receiver, amount);
return "";
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

Comment on lines 78 to 96
function onCall(
MessageContext calldata context,
bytes calldata message
) external payable onlyGateway returns (bytes4) {
if (context.sender != universal) revert Unauthorized();
(
address receiver,
uint256 amount,
uint256 gasAmount,
address sender
) = abi.decode(message, (address, uint256, uint256, address));
_mint(receiver, amount);
if (gasAmount > 0) {
(bool success, ) = sender.call{value: amount}("");
if (!success) revert GasTokenTransferFailed();
}
emit TokenTransferReceived(receiver, amount);
return "";
}

Check warning

Code scanning / Slither

Low-level calls Warning

Comment on lines 59 to 94
function transferCrossChain(
address destination,
address receiver,
uint256 amount
) public {
if (receiver == address(0)) revert InvalidAddress();
_burn(msg.sender, amount);

(, uint256 gasFee) = IZRC20(destination).withdrawGasFeeWithGasLimit(
gasLimit
);
if (
!IZRC20(destination).transferFrom(msg.sender, address(this), gasFee)
) revert TransferFailed();
IZRC20(destination).approve(address(gateway), gasFee);
bytes memory message = abi.encode(receiver, amount, 0, msg.sender);

CallOptions memory callOptions = CallOptions(gasLimit, false);

RevertOptions memory revertOptions = RevertOptions(
address(this),
true,
address(0),
abi.encode(amount, msg.sender),
gasLimit
);

gateway.call(
abi.encodePacked(connected[destination]),
destination,
message,
callOptions,
revertOptions
);
emit TokenTransfer(destination, receiver, amount);
}
Comment on lines 100 to 143
function onCall(
MessageContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external override onlyGateway {
if (context.sender != connected[zrc20]) revert Unauthorized();
(
address destination,
address receiver,
uint256 tokenAmount,
address sender
) = abi.decode(message, (address, address, uint256, address));
if (destination == address(0)) {
_mint(receiver, tokenAmount);
} else {
(, uint256 gasFee) = IZRC20(destination).withdrawGasFeeWithGasLimit(
gasLimit
);
uint256 out = SwapHelperLib.swapExactTokensForTokens(
uniswapRouter,
zrc20,
amount,
destination,
0
);
IZRC20(destination).approve(address(gateway), out);
gateway.withdrawAndCall(
abi.encodePacked(connected[destination]),
out - gasFee,
destination,
abi.encode(receiver, tokenAmount, out - gasFee, sender),
CallOptions(gasLimit, false),
RevertOptions(
address(this),
true,
address(0),
abi.encode(tokenAmount, sender),
0
)
);
}
emit TokenTransferToDestination(destination, receiver, amount);
}
@fadeev fadeev merged commit 0ce2172 into main Nov 27, 2024
7 checks passed
@fadeev fadeev deleted the nft-token-contracts branch November 27, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants