-
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
base: main
Are you sure you want to change the base?
feat: tests #39
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
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 ""; | ||
} |
Check warning
Code scanning / Slither
Low-level calls Warning
function transferCrossChain( | ||
uint256 tokenId, | ||
address receiver, | ||
address destination | ||
) public payable { | ||
if (msg.value == 0) revert ZeroMsgValue(); | ||
if (receiver == address(0)) revert InvalidAddress(); | ||
|
||
string memory uri = tokenURI(tokenId); | ||
_burn(tokenId); | ||
|
||
emit TokenTransfer(receiver, destination, tokenId, uri); | ||
|
||
(address gasZRC20, uint256 gasFee) = IZRC20(destination) | ||
.withdrawGasFeeWithGasLimit(gasLimitAmount); | ||
if (destination != gasZRC20) revert InvalidAddress(); | ||
|
||
address WZETA = gateway.zetaToken(); | ||
IWETH9(WZETA).deposit{value: msg.value}(); | ||
if (!IWETH9(WZETA).approve(uniswapRouter, msg.value)) { | ||
revert ApproveFailed(); | ||
} | ||
|
||
uint256 out = SwapHelperLib.swapTokensForExactTokens( | ||
uniswapRouter, | ||
WZETA, | ||
gasFee, | ||
gasZRC20, | ||
msg.value | ||
); | ||
|
||
uint256 remaining = msg.value - out; | ||
if (remaining > 0) { | ||
IWETH9(WZETA).withdraw(remaining); | ||
(bool success, ) = msg.sender.call{value: remaining}(""); | ||
if (!success) revert TransferFailed(); | ||
} | ||
|
||
bytes memory message = abi.encode( | ||
receiver, | ||
tokenId, | ||
uri, | ||
0, | ||
msg.sender | ||
); | ||
CallOptions memory callOptions = CallOptions(gasLimitAmount, false); | ||
|
||
RevertOptions memory revertOptions = RevertOptions( | ||
address(this), | ||
true, | ||
address(0), | ||
abi.encode(tokenId, uri, msg.sender), | ||
gasLimitAmount | ||
); | ||
|
||
if (!IZRC20(gasZRC20).approve(address(gateway), gasFee)) { | ||
revert ApproveFailed(); | ||
} | ||
|
||
gateway.call( | ||
abi.encodePacked(connected[destination]), | ||
destination, | ||
message, | ||
callOptions, | ||
revertOptions | ||
); | ||
} |
Check warning
Code scanning / Slither
Low-level calls Warning
function __UniversalTokenCore_init( | ||
address gatewayAddress, | ||
address universalAddress, | ||
uint256 gas | ||
) internal { | ||
if (gatewayAddress == address(0)) revert InvalidAddress(); | ||
if (universalAddress == address(0)) revert InvalidAddress(); | ||
if (gas == 0) revert InvalidGasLimit(); | ||
gateway = GatewayEVM(gatewayAddress); | ||
universal = universalAddress; | ||
gasLimitAmount = gas; | ||
} |
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning
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) { | ||
if (sender == address(0)) revert InvalidAddress(); | ||
(bool success, ) = payable(sender).call{value: gasAmount}(""); | ||
if (!success) revert GasTokenTransferFailed(); | ||
} | ||
emit TokenTransferReceived(receiver, amount); | ||
return ""; | ||
} |
Check notice
Code scanning / Slither
Reentrancy vulnerabilities Low
External calls:
- (success,None) = address(sender).call{value: gasAmount}()
Event emitted after the call(s):
- TokenTransferReceived(receiver,amount)
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) { | ||
if (sender == address(0)) revert InvalidAddress(); | ||
(bool success, ) = payable(sender).call{value: gasAmount}(""); | ||
if (!success) revert GasTokenTransferFailed(); | ||
} | ||
emit TokenTransferReceived(receiver, amount); | ||
return ""; | ||
} |
Check warning
Code scanning / Slither
Low-level calls Warning
function __UniversalTokenCore_init( | ||
address gatewayAddress, | ||
uint256 gas, | ||
address uniswapRouterAddress | ||
) internal { | ||
if (gatewayAddress == address(0) || uniswapRouterAddress == address(0)) | ||
revert InvalidAddress(); | ||
if (gas == 0) revert InvalidGasLimit(); | ||
gateway = GatewayZEVM(payable(gatewayAddress)); | ||
uniswapRouter = uniswapRouterAddress; | ||
gasLimitAmount = gas; | ||
} |
Check warning
Code scanning / Slither
Conformance to Solidity naming conventions Warning
function transferCrossChain( | ||
address destination, | ||
address receiver, | ||
uint256 amount | ||
) public payable { | ||
if (msg.value == 0) revert ZeroMsgValue(); | ||
if (receiver == address(0)) revert InvalidAddress(); | ||
|
||
_burn(msg.sender, amount); | ||
|
||
emit TokenTransfer(destination, receiver, amount); | ||
|
||
(address gasZRC20, uint256 gasFee) = IZRC20(destination) | ||
.withdrawGasFeeWithGasLimit(gasLimitAmount); | ||
if (destination != gasZRC20) revert InvalidAddress(); | ||
|
||
address WZETA = gateway.zetaToken(); | ||
|
||
IWETH9(WZETA).deposit{value: msg.value}(); | ||
if (!IWETH9(WZETA).approve(uniswapRouter, msg.value)) { | ||
revert ApproveFailed(); | ||
} | ||
|
||
uint256 out = SwapHelperLib.swapTokensForExactTokens( | ||
uniswapRouter, | ||
WZETA, | ||
gasFee, | ||
gasZRC20, | ||
msg.value | ||
); | ||
|
||
uint256 remaining = msg.value - out; | ||
|
||
if (remaining > 0) { | ||
IWETH9(WZETA).withdraw(remaining); | ||
(bool success, ) = msg.sender.call{value: remaining}(""); | ||
if (!success) revert TransferFailed(); | ||
} | ||
|
||
bytes memory message = abi.encode(receiver, amount, 0, msg.sender); | ||
|
||
CallOptions memory callOptions = CallOptions(gasLimitAmount, false); | ||
|
||
RevertOptions memory revertOptions = RevertOptions( | ||
address(this), | ||
true, | ||
address(0), | ||
abi.encode(amount, msg.sender), | ||
gasLimitAmount | ||
); | ||
|
||
if (!IZRC20(gasZRC20).approve(address(gateway), gasFee)) { | ||
revert ApproveFailed(); | ||
} | ||
gateway.call( | ||
abi.encodePacked(connected[destination]), | ||
destination, | ||
message, | ||
callOptions, | ||
revertOptions | ||
); | ||
} |
Check warning
Code scanning / Slither
Low-level calls Warning
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 { | ||
(address gasZRC20, uint256 gasFee) = IZRC20(destination) | ||
.withdrawGasFeeWithGasLimit(gasLimitAmount); | ||
if (destination != gasZRC20) revert InvalidAddress(); | ||
uint256 out = SwapHelperLib.swapExactTokensForTokens( | ||
uniswapRouter, | ||
zrc20, | ||
amount, | ||
destination, | ||
0 | ||
); | ||
if (!IZRC20(destination).approve(address(gateway), out)) { | ||
revert ApproveFailed(); | ||
} | ||
gateway.withdrawAndCall( | ||
abi.encodePacked(connected[destination]), | ||
out - gasFee, | ||
destination, | ||
abi.encode(receiver, tokenAmount, out - gasFee, sender), | ||
CallOptions(gasLimitAmount, false), | ||
RevertOptions( | ||
address(this), | ||
true, | ||
address(0), | ||
abi.encode(tokenAmount, sender), | ||
0 | ||
) | ||
); | ||
} | ||
emit TokenTransferToDestination(destination, receiver, amount); | ||
} |
Check notice
Code scanning / Slither
Reentrancy vulnerabilities Low
External calls:
- 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(gasLimitAmount,false),RevertOptions(address(this),true,address(0),abi.encode(tokenAmount,sender),0))
Event emitted after the call(s):
- TokenTransferToDestination(destination,receiver,amount)
Throws an error when adding liquidity:
|
router.addLiquidity( // throws error | ||
address(zetaToken), | ||
address(zrc20), | ||
10 ether, | ||
10 ether, | ||
1 ether, | ||
1 ether, | ||
owner, | ||
block.timestamp + 300 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skosito I'm getting errors when trying to add liquidity. Is there anything wrong I'm doing here?
No description provided.