-
Notifications
You must be signed in to change notification settings - Fork 49
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: added ability to swap token on and from ZetaChain #186
Conversation
@andresaiello please, review. |
@andresaiello please, review. |
WalkthroughThe recent updates enhance token swapping functionality in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Hardhat
participant SwapContract
participant SwapToAnyTokenContract
participant ERC20TokenContract
User->>Hardhat: Initiate swap task
Hardhat->>SwapContract: Validate parameters
Hardhat->>ERC20TokenContract: Approve tokens
ERC20TokenContract-->>Hardhat: Approval complete
Hardhat->>SwapContract: Execute swapAndWithdraw
SwapContract->>SwapToAnyTokenContract: Call swapAndWithdraw
SwapToAnyTokenContract->>ERC20TokenContract: Perform swap
ERC20TokenContract-->>SwapToAnyTokenContract: Swap complete
SwapToAnyTokenContract-->>SwapContract: SwapAndWithdraw complete
SwapContract-->>Hardhat: Swap task complete
Hardhat-->>User: Swap successful
Poem
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
function swap( | ||
address inputToken, | ||
uint256 amount, | ||
address targetToken, | ||
bytes memory recipient, | ||
bool withdraw | ||
) public { | ||
IZRC20(inputToken).transferFrom(msg.sender, address(this), amount); | ||
|
||
swapAndWithdraw(inputToken, amount, targetToken, recipient, withdraw); | ||
} |
Check failure
Code scanning / Slither
Unchecked transfer High
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.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- omnichain/swap/contracts/Swap.sol (1 hunks)
- omnichain/swap/contracts/SwapToAnyToken.sol (3 hunks)
- omnichain/swap/tasks/swap.ts (1 hunks)
Additional context used
GitHub Check: Slither
omnichain/swap/contracts/SwapToAnyToken.sol
[failure] 117-127: Unchecked transfer
SwapToAnyToken.swap(address,uint256,address,bytes,bool) (contracts/SwapToAnyToken.sol#117-127) ignores return value by IZRC20(inputToken).transferFrom(msg.sender,address(this),amount) (contracts/SwapToAnyToken.sol#124)
Additional comments not posted (1)
omnichain/swap/contracts/Swap.sol (1)
48-77
: Ensure consistent token handling and gas optimization inswapAndWithdraw
.The
swapAndWithdraw
function has been updated to usetargetToken
consistently and introduces a new parameterrecipient
. The logic for handling gas fees and token swaps appears sound, but ensure that the gas fee calculations and token approvals are optimized to prevent unnecessary costs or vulnerabilities.Consider verifying the gas fee logic and token approval steps to ensure they align with the expected behavior and security standards. Additionally, ensure that the
recipient
parameter is validated to prevent potential security issues.Tools
GitHub Check: Slither
[warning] 48-78: Unused return
Swap.swapAndWithdraw(address,uint256,address,bytes) (contracts/Swap.sol#48-78) ignores return value by IZRC20(targetToken).withdraw(recipient,outputAmount) (contracts/Swap.sol#77)
[warning] 48-78: Unused return
Swap.swapAndWithdraw(address,uint256,address,bytes) (contracts/Swap.sol#48-78) ignores return value by IZRC20(gasZRC20).approve(targetToken,gasFee) (contracts/Swap.sol#76)
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- omnichain/swap/contracts/SwapToAnyToken.sol (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- omnichain/swap/contracts/SwapToAnyToken.sol
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- omnichain/swap/contracts/SwapToAnyToken.sol (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- omnichain/swap/contracts/SwapToAnyToken.sol
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.
So I had zetachain (mainnet) on Atomic's wallet and I wasn't aware that I couldn't send directly to my Coinbase account which is. Er20 or something like that so I never recived it can anyone help me please
Extracting the swap logic into a separate function makes it easy to add a set of additional swap features:
Summary by CodeRabbit
New Features
Refactor
Improvements