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

Swap from ZetaChain tutorial #393

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Swap from ZetaChain tutorial #393

merged 1 commit into from
Jul 25, 2024

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Jul 17, 2024

zeta-chain/example-contracts#186

Summary by CodeRabbit

  • New Features

    • Added a new swap function for users to swap tokens on ZetaChain.
    • Created a new Swap task for easier interaction with the SwapToAnyToken contract.
  • Enhancements

    • Extended the estimated reading time for the "Swap Any Token" tutorial from 20 to 60 minutes.
    • Improved the SwapToAnyToken.sol contract with enhanced token swap and withdrawal functionality.

Copy link

vercel bot commented Jul 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2024 3:23pm

Copy link
Contributor

coderabbitai bot commented Jul 17, 2024

Walkthrough

The updates increase the estimated reading time for the "Swap Any Token" tutorial from 20 to 60 minutes and introduce significant changes to the SwapToAnyToken.sol and Swap.sol contracts. These changes include refining token swap and withdrawal processes, adding new functions, and improving code organization. The goal is to enhance the functionality and clarity of the token swapping process on ZetaChain.

Changes

Files Change Summaries
src/pages/developers/tutorials/_meta.json Updated the estimated reading time for the "Swap Any Token" tutorial from 20 to 60 minutes.
src/pages/developers/tutorials/swap-any.mdx Added receive function, modified onCrossChainCall parameters, updated swapAndWithdraw to handle token swaps and withdrawals, introduced a public swap function, and added a new Swap task for ZetaChain interaction.
src/pages/developers/tutorials/swap.mdx Refactored Swap.sol contract to replace withdrawGasFee call with an internal swapAndWithdraw function, thus streamlining the swapping and withdrawal process.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SwapToAnyToken
    participant ZetaChain
    participant ExternalContract

    User->>SwapToAnyToken: Initiate swap (swap function)
    SwapToAnyToken->>ZetaChain: Perform token swap
    ZetaChain-->>SwapToAnyToken: Swap result
    SwapToAnyToken->>User: Token swap complete

    User->>SwapToAnyToken: Initiate cross-chain call (onCrossChainCall)
    SwapToAnyToken->>ExternalContract: Call contract
    ExternalContract-->>SwapToAnyToken: Response
    SwapToAnyToken->>SwapToAnyToken: Execute swapAndWithdraw
    SwapToAnyToken->>User: Process withdrawal (if applicable)
Loading

Poem

Amidst the code, where tokens flow,
A rabbit hops, with changes to show.
Swaps refined, withdrawals clear,
On ZetaChain, no need to fear.
With functions new and tasks anew,
The blockchain's path, we now construe.
So swap with ease, and let it be,
A seamless, swift liquidity! 🌐🐇


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Outside diff range, codebase verification and nitpick comments (6)
src/pages/developers/tutorials/swap-any.mdx (5)

168-168: Grammar correction: Use "withdrawal" instead of "withdraw".

The word 'withdraw' is not a noun. The correct term is 'withdrawal'.

- all values: target token, recipient and the withdraw flag.
+ all values: target token, recipient and the withdrawal flag.
Tools
LanguageTool

[grammar] ~168-~168: The word ‘withdraw’ is not a noun. Did you mean “withdrawal”?
Context: ...values: target token, recipient and the withdraw flag. Next, add params.withdraw as t...

(PREPOSITION_VERB)


180-181: Grammar and article correction: Use "withdrawal" and add missing articles.

The word 'withdraw' is not a noun. The correct term is 'withdrawal'. Also, add missing articles for clarity.

- If a user withdraws token, subtract the withdraw fee in input token amount.
+ If a user withdraws the token, subtract the withdrawal fee from the input token amount.
Tools
LanguageTool

[uncategorized] ~180-~180: Possible missing article found.
Context: ...ctTokensForTokens`. If a user withdraws token, subtract the withdraw fee in input tok...

(AI_HYDRA_LEO_MISSING_A)


[grammar] ~181-~181: The word ‘withdraw’ is not a noun. Did you mean “withdrawal”?
Context: ...If a user withdraws token, subtract the withdraw fee in input token amount. Finally, ad...

(PREPOSITION_VERB)


[uncategorized] ~181-~181: The preposition “from” seems more likely in this position.
Context: ...hdraws token, subtract the withdraw fee in input token amount. Finally, add a con...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION)


[uncategorized] ~181-~181: You might be missing the article “the” here.
Context: ...aws token, subtract the withdraw fee in input token amount. Finally, add a condition...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


185-185: Grammar correction: Add missing comma.

Add a comma after 'token' for clarity.

- If a user doesn't want to withdraw a token you need to consider two scenarios:
+ If a user doesn't want to withdraw a token, you need to consider two scenarios:
Tools
LanguageTool

[uncategorized] ~185-~185: Possible missing comma found.
Context: ...n. If a user doesn't want to withdraw a token you need to consider two scenarios: - ...

(AI_HYDRA_LEO_MISSING_COMMA)


198-199: Grammar correction: Add missing comma.

Add a comma after 'tokens' for clarity.

- tokens they have on ZetaChain for other tokens and optionally also withdraw them.
+ tokens they have on ZetaChain for other tokens, and optionally also withdraw them.
Tools
LanguageTool

[uncategorized] ~198-~198: Possible missing comma found.
Context: ...tokens they have on ZetaChain for other tokens and optionally also withdraw them. For ...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~199-~199: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...or example, when a user has a ZRC-20 ETH and they want to swap it for ZRC-20 BTC (wi...

(COMMA_COMPOUND_SENTENCE)


225-225: Grammar correction: Add missing comma.

Add a comma after 'asset' for clarity.

- asset already on ZetaChain for a different asset optionally withdrawing it.
+ asset already on ZetaChain for a different asset, optionally withdrawing it.
Tools
LanguageTool

[uncategorized] ~225-~225: A comma might be missing here.
Context: ...et already on ZetaChain for a different asset optionally withdrawing it. ``` import ...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

src/pages/developers/tutorials/swap.mdx (1)

188-189: Grammar correction: Add missing comma.

Add a comma after 'function' for clarity.

- function called `swapAndWithdraw`. Use the `withdrawGasFee` method
+ function called `swapAndWithdraw`. Use the `withdrawGasFee` method,
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0ee5ae4 and a7a8871.

Files selected for processing (3)
  • src/pages/developers/tutorials/_meta.json (1 hunks)
  • src/pages/developers/tutorials/swap-any.mdx (6 hunks)
  • src/pages/developers/tutorials/swap.mdx (3 hunks)
Additional context used
LanguageTool
src/pages/developers/tutorials/swap-any.mdx

[grammar] ~168-~168: The word ‘withdraw’ is not a noun. Did you mean “withdrawal”?
Context: ...values: target token, recipient and the withdraw flag. Next, add params.withdraw as t...

(PREPOSITION_VERB)


[uncategorized] ~180-~180: Possible missing article found.
Context: ...ctTokensForTokens`. If a user withdraws token, subtract the withdraw fee in input tok...

(AI_HYDRA_LEO_MISSING_A)


[grammar] ~181-~181: The word ‘withdraw’ is not a noun. Did you mean “withdrawal”?
Context: ...If a user withdraws token, subtract the withdraw fee in input token amount. Finally, ad...

(PREPOSITION_VERB)


[uncategorized] ~181-~181: The preposition “from” seems more likely in this position.
Context: ...hdraws token, subtract the withdraw fee in input token amount. Finally, add a con...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION)


[uncategorized] ~181-~181: You might be missing the article “the” here.
Context: ...aws token, subtract the withdraw fee in input token amount. Finally, add a condition...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~185-~185: Possible missing comma found.
Context: ...n. If a user doesn't want to withdraw a token you need to consider two scenarios: - ...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~198-~198: Possible missing comma found.
Context: ...tokens they have on ZetaChain for other tokens and optionally also withdraw them. For ...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~199-~199: Use a comma before ‘and’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...or example, when a user has a ZRC-20 ETH and they want to swap it for ZRC-20 BTC (wi...

(COMMA_COMPOUND_SENTENCE)


[uncategorized] ~225-~225: A comma might be missing here.
Context: ...et already on ZetaChain for a different asset optionally withdrawing it. ``` import ...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

Additional comments not posted (9)
src/pages/developers/tutorials/_meta.json (1)

19-19: Update to reading time is appropriate.

The change reflects an increase in the estimated reading time for the "Swap Any Token" tutorial from 20 minutes to 60 minutes, which aligns with the significant changes introduced in the tutorial.

src/pages/developers/tutorials/swap-any.mdx (6)

50-50: Addition of receive function is appropriate.

The receive function allows the contract to accept Ether, which is necessary for handling external payments.


Line range hint 51-90:
Refactoring of onCrossChainCall function is appropriate.

The function now includes additional parameters and a call to swapAndWithdraw, enhancing the functionality and clarity of the token swapping process.


Line range hint 92-137:
Modification of swapAndWithdraw function is appropriate.

The function now handles token swaps and withdrawals based on conditions, improving the flexibility and functionality of the contract.


141-151: Addition of new swap function is appropriate.

The new public swap function allows users to swap tokens on ZetaChain, enhancing the contract's usability.


221-221: Addition of optional withdraw parameter is appropriate.

The optional parameter enhances the functionality of the Interact task by allowing users to specify whether they want to withdraw the target token to the destination chain.


223-276: Addition of Swap task is appropriate.

The new task allows users to interact with the SwapToAnyToken contract on ZetaChain, enhancing the tutorial's functionality.

Tools
LanguageTool

[uncategorized] ~225-~225: A comma might be missing here.
Context: ...et already on ZetaChain for a different asset optionally withdrawing it. ``` import ...

(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)

src/pages/developers/tutorials/swap.mdx (2)

124-125: Refactoring of swapAndWithdraw function is appropriate.

The function now consolidates the token swapping and withdrawal steps, improving code organization and readability.


127-156: Modification of swapAndWithdraw function is appropriate.

The function now handles token swaps and withdrawals based on conditions, improving the flexibility and functionality of the contract.

@fadeev fadeev merged commit 360fb6f into main Jul 25, 2024
6 checks passed
@fadeev fadeev deleted the swap-from-zetachain branch July 25, 2024 17:31
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