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

Update examples to use gateway and localnet #470

Merged
merged 10 commits into from
Sep 24, 2024
Merged

Conversation

fadeev
Copy link
Member

@fadeev fadeev commented Sep 13, 2024

  • Updated Hello tutorial with gateway and localnet
  • Updated Swap tutorial with gateway and localnet
  • Moved Bitcoin frontend tutorial to the frontend section
  • Removed staking, NFT and multioutput tutorials
  • Removed transactions page, because we'll have a completely different set of tasks for gateway

Depends on zeta-chain/example-contracts#199

Summary by CodeRabbit

Release Notes

  • New Features

    • The swap contract has been renamed to "SwapToAnyToken," enhancing its capabilities.
    • Introduced a new withdraw option, allowing users to choose whether to withdraw swapped tokens to a connected chain or keep them on ZetaChain.
    • Added a public swap function for direct token swaps on ZetaChain without cross-chain calls.
  • Refactor

    • Enhanced the onCrossChainCall and swapAndWithdraw functions for improved flexibility and gas fee management based on the withdraw flag.

Copy link

vercel bot commented Sep 13, 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 Sep 16, 2024 4:02pm

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

Walkthrough

The pull request introduces significant enhancements to the swap contract, renaming it from Swap to SwapToAnyToken. Key changes include the addition of a withdraw flag in the Params struct, updates to the onCrossChainCall function for improved message decoding, and the introduction of a new public swap function. These modifications provide users with greater flexibility in managing token swaps and withdrawals across chains.

Changes

Files Change Summary
contracts/SwapToAnyToken.sol Renamed contract from Swap to SwapToAnyToken, added Params struct with target, to, and withdraw fields, introduced new swap function, modified onCrossChainCall and swapAndWithdraw functions.

Possibly related PRs

The changes introduced in this pull request may be related to the following pull requests:

  • Swap from ZetaChain tutorial #393: This PR modifies the SwapToAnyToken.sol contract, including the addition of a new public swap function and updates to the onCrossChainCall and swapAndWithdraw functions, which are directly related to the changes made in the main PR.

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>, please review it.
    -- 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 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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@fadeev fadeev changed the title Hello example Update examples to use gateway and localnet Sep 13, 2024
@fadeev fadeev marked this pull request as ready for review September 13, 2024 08:46
@fadeev fadeev marked this pull request as draft September 13, 2024 08:47
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 and nitpick comments (2)
src/pages/developers/tutorials/swap-any.mdx (2)

206-250: The explanations provide a comprehensive overview of the key differences between the Swap and SwapToAnyToken contracts.

The explanations clearly articulate the purpose and functionality of the withdraw flag and how it impacts the onCrossChainCall and swapAndWithdraw functions. They also highlight the benefits of the new swap function for direct interaction on ZetaChain.

To further enhance clarity, consider adding a brief explanation of the IWETH9 interface and its role in facilitating direct token transfers when withdraw is false.

Tools
LanguageTool

[uncategorized] ~230-~230: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ... fee handling and simply swaps the full amount of tokens. Once the tokens are swapped...

(AMOUNTOF_TO_NUMBEROF)


283-294: The instructions for swapping tokens from a connected EVM chain and withdrawing them to the destination chain are well-explained.

The provided command and the explanations of the required parameters make it easy for users to understand and execute the swap and withdrawal process.

To further improve clarity, consider adding a brief explanation of the --types parameter and its significance in encoding the function arguments.

Tools
LanguageTool

[uncategorized] ~292-~292: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...he receiver address (the contract), the amount of tokens to swap, the target token add...

(AMOUNTOF_TO_NUMBEROF)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d7cc615 and 6da7c87.

Files selected for processing (8)
  • src/pages/developers/frontend/bitcoin.mdx (1 hunks)
  • src/pages/developers/reference/_meta.json (0 hunks)
  • src/pages/developers/reference/transactions.mdx (0 hunks)
  • src/pages/developers/tutorials/_meta.json (1 hunks)
  • src/pages/developers/tutorials/hello.mdx (2 hunks)
  • src/pages/developers/tutorials/swap-any.mdx (4 hunks)
  • src/pages/developers/tutorials/swap-tss.mdx (1 hunks)
  • src/pages/developers/tutorials/swap.mdx (4 hunks)
Files not reviewed due to no reviewable changes (2)
  • src/pages/developers/reference/_meta.json
  • src/pages/developers/reference/transactions.mdx
Additional context used
LanguageTool
src/pages/developers/tutorials/swap-any.mdx

[style] ~49-~49: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it.
Context: ...y makes the contract more versatile for a variety of use cases. ```solidity // SPDX-License...

(A_VARIETY_OF)


[uncategorized] ~230-~230: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ... fee handling and simply swaps the full amount of tokens. Once the tokens are swapped...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~292-~292: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...he receiver address (the contract), the amount of tokens to swap, the target token add...

(AMOUNTOF_TO_NUMBEROF)


[style] ~318-~318: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it.
Context: ...hain, providing greater flexibility for a variety of use cases. ## Source Code You can fin...

(A_VARIETY_OF)

src/pages/developers/tutorials/swap-tss.mdx

[typographical] ~7-7: It appears that a comma is missing.
Context: ... } from "
/components/shared"; In this tutorial you will create a cross-chain swap cont...

(DURING_THAT_TIME_COMMA)


[uncategorized] ~171-~171: Loose punctuation mark.
Context: ...ill hold two values: - address target: target token ZRC-20 address. - `bytes t...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~172-~172: Loose punctuation mark.
Context: ...arget token ZRC-20 address. - bytes to: recipient address on the destination ch...

(UNLIKELY_OPENING_PUNCTUATION)


[formatting] ~172-~172: If the ‘because’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...e destination chain. We're using bytes, because the recipient can be either on EVM (lik...

(COMMA_BEFORE_BECAUSE)


[misspelling] ~178-~178: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...chain. For example, on Bitcoin there is a upper limit of 80 bytes, so you might w...

(EN_A_VS_AN)


[uncategorized] ~179-~179: Possible missing comma found.
Context: ... in the most efficient way possible. On EVM don't have this limit, so it's fine to ...

(AI_HYDRA_LEO_MISSING_COMMA)


[typographical] ~217-~217: It appears that a comma is missing.
Context: ...arget Token to Connected Chain At this point the contract has the required gasFee ...

(DURING_THAT_TIME_COMMA)


[uncategorized] ~220-~220: Possible missing comma found.
Context: ...ken. To withdraw tokens to a connected chain you will be calling the withdraw meth...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~332-~332: Possible missing comma found.
Context: ...om Sepolia to BNB on BNB chain. To send USDC specify the ERC-20 token contract addre...

(AI_HYDRA_LEO_MISSING_COMMA)

src/pages/developers/tutorials/hello.mdx

[uncategorized] ~97-~97: Loose punctuation mark.
Context: ...eives the following inputs: - context: is a struct of type [zContext](http...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~102-~102: Loose punctuation mark.
Context: ... on a connected chain. - chainID: integer ID of the connected chain from ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: Loose punctuation mark.
Context: ...connected chain on ZetaChain. - amount: the amount of tokens that were sent to ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ted chain on ZetaChain. - amount: the amount of tokens that were sent to the univers...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~189-~189: Loose punctuation mark.
Context: ...' alice ``` Parameters: - --receiver: The address of the `Hello` contract on ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~190-~190: Loose punctuation mark.
Context: ...ellocontract on ZetaChain. ---types`: The ABI types of the message parameters...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~191-~191: Loose punctuation mark.
Context: ...pes of the message parameters. - alice: The message to send. The EVM gateway p...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~257-~257: Loose punctuation mark.
Context: ...2 ``` Parameters: - --call-on-revert: Informs the gateway to handle reverts. ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~258-~258: Loose punctuation mark.
Context: ... to handle reverts. - --revert-address: The address of the Revert contract on...

(UNLIKELY_OPENING_PUNCTUATION)

src/pages/developers/tutorials/swap.mdx

[uncategorized] ~188-~188: Loose punctuation mark.
Context: ... of information: - address target: The ZRC-20 address of the target token ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~189-~189: Loose punctuation mark.
Context: ...get token on ZetaChain. - bytes to: The recipient's address on the destinat...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~223-~223: Consider placing the discourse marker ‘first’ at the beginning of the sentence for more clarity.
Context: ...maintain. #### Swapping for Gas Token The contract first addresses the gas fee required for the ...

(SENT_START_FIRST_PREMIUM)

Gitleaks
src/pages/developers/tutorials/swap-tss.mdx

366-366: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Additional comments not posted (29)
src/pages/developers/tutorials/_meta.json (4)

8-8: LGTM!

The updated tutorial title provides clarity by specifying that the tutorial targets the local development environment. This change aligns well with the PR objective of updating examples to use localnet.


18-18: LGTM!

The updated tutorial title provides clarity by specifying that the tutorial targets the local development environment. This change aligns well with the PR objective of updating examples to use localnet.


23-23: LGTM!

The updated tutorial title provides clarity by specifying that the tutorial targets the local development environment and focuses on swapping any token. This change aligns well with the PR objective of updating examples to use localnet.


27-30: LGTM!

The updated tutorial description provides a more concise and clear explanation of the tutorial's focus on building and interacting with a universal app in a local development environment. This change aligns well with the PR objective of updating examples to use localnet.

src/pages/developers/frontend/bitcoin.mdx (1)

206-206: LGTM!

The change in the link target from "Staking" to "Swap" tutorial aligns with the PR objective of updating the examples to use the gateway and localnet features. The modification is appropriate and enhances the relevance of the instructions.

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

Line range hint 52-202: The updated SwapToAnyToken contract introduces valuable enhancements to support more flexible token swapping.

The addition of the withdraw flag in the Params struct and the corresponding updates to the onCrossChainCall and swapAndWithdraw functions enable users to choose whether to withdraw the swapped tokens to a connected chain or keep them on ZetaChain. This flexibility expands the contract's usability for various scenarios.

Furthermore, the introduction of the swap function allows direct interaction with the contract on ZetaChain, eliminating the need for cross-chain calls when tokens are already on ZetaChain.

These changes significantly improve the contract's versatility and cater to a wider range of use cases.


253-279: The instructions for starting localnet and deploying the SwapToAnyToken contract are clear and comprehensive.

The provided commands and expected output make it easy for users to follow the steps and ensure a successful deployment.


298-310: The instructions for swapping tokens and keeping them on ZetaChain using the swap function are well-documented.

The provided command and the explanations of the required parameters make it easy for users to understand and execute the token swap directly on ZetaChain.

src/pages/developers/tutorials/swap-tss.mdx (4)

85-164: LGTM!

The Solidity contract implementation for the cross-chain swap functionality is well-structured and follows best practices. The contract correctly inherits from the necessary contracts, defines the Params struct, and implements the onCrossChainCall function to handle cross-chain calls. The decoding of the incoming message based on the source chain is handled appropriately, and the swapAndWithdraw function is called with the correct parameters.


133-163: LGTM!

The swapAndWithdraw function implementation is well-structured and follows best practices. The function correctly retrieves the gas fee token address and amount, performs the necessary token swaps using the helper methods, approves the target token ZRC-20 contract to spend the gas fee amount, and calls the withdraw method with the appropriate parameters to send the tokens to the recipient on the connected chain.


249-266: LGTM!

The main function implementation in the interact.ts file is well-structured and follows best practices. The function correctly checks if the recipient is a valid Bitcoin address using the bech32.decode method and encodes it as bytes using utils.solidityPack if it is. If the recipient is not a valid Bitcoin address, it is assumed to be an EVM address, which is a reasonable assumption. The prepareData function call is updated appropriately to use the bytes type for the recipient.


361-367: LGTM!

The instructions for sending Bitcoin to the TSS address with a memo are clear and concise. The memo format is well-defined, including the necessary information for the cross-chain swap, such as the omnichain contract address on ZetaChain, the target token address, and the recipient address. The target token address provided in the instructions is a valid Ethereum address.

Tools
Gitleaks

366-366: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

src/pages/developers/tutorials/hello.mdx (12)

2-2: LGTM!

The updated title accurately reflects the content of the tutorial.


5-6: LGTM!

The Alert component import is valid and likely used to inform users about the availability of the gateway.


10-11: LGTM!

The updated description accurately reflects the behavior of the universal app contract.


15-19: LGTM!

The updated learning objectives are clear, concise, and align with the content of the tutorial.


21-25: LGTM!

The Alert component is used effectively to inform users about the availability of the gateway on localnet and testnet. The message is clear and helps set the right expectations for users.


34-154: LGTM!

The instructions for setting up the environment and the explanations of the Hello and Revert contracts are clear, detailed, and easy to follow. The tutorial covers the important aspects of the contracts and their usage in handling cross-chain messages and reverts.

Tools
LanguageTool

[uncategorized] ~97-~97: Loose punctuation mark.
Context: ...eives the following inputs: - context: is a struct of type [zContext](http...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~102-~102: Loose punctuation mark.
Context: ... on a connected chain. - chainID: integer ID of the connected chain from ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: Loose punctuation mark.
Context: ...connected chain on ZetaChain. - amount: the amount of tokens that were sent to ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ted chain on ZetaChain. - amount: the amount of tokens that were sent to the univers...

(AMOUNTOF_TO_NUMBEROF)


156-162: LGTM!

The instructions for starting localnet and deploying the contracts are clear and easy to follow.


164-280: LGTM!

The instructions for interacting with the Hello contract and simulating a revert scenario are clear and easy to follow. The tutorial effectively demonstrates the importance of specifying a revert address to handle reverts gracefully.

Tools
LanguageTool

[uncategorized] ~189-~189: Loose punctuation mark.
Context: ...' alice ``` Parameters: - --receiver: The address of the `Hello` contract on ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~190-~190: Loose punctuation mark.
Context: ...ellocontract on ZetaChain. ---types`: The ABI types of the message parameters...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~191-~191: Loose punctuation mark.
Context: ...pes of the message parameters. - alice: The message to send. The EVM gateway p...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~257-~257: Loose punctuation mark.
Context: ...2 ``` Parameters: - --call-on-revert: Informs the gateway to handle reverts. ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~258-~258: Loose punctuation mark.
Context: ... to handle reverts. - --revert-address: The address of the Revert contract on...

(UNLIKELY_OPENING_PUNCTUATION)


282-288: LGTM!

The instructions for handling the revert gracefully by specifying additional parameters to call the Revert contract on the source chain are clear and easy to follow. The tutorial effectively demonstrates how to use the Revert contract to handle reverts gracefully.


289-302: LGTM!

The conclusion effectively summarizes the key learnings from the tutorial and emphasizes the importance of understanding how to manage cross-chain calls and handle reverts for building robust universal applications on ZetaChain.


303-307: LGTM!

Providing a link to the source code for the tutorial in the example contracts repo is helpful for users who want to explore the code further or use it as a reference.


97-258: Skipping the static analysis hints.

The static analysis hints provided by LanguageTool are false positives in this context. The loose punctuation marks are part of the Markdown formatting and do not require any changes. The usage of "amount of" with "tokens" is acceptable, as "tokens" can be considered a mass noun in this context.

Tools
LanguageTool

[uncategorized] ~97-~97: Loose punctuation mark.
Context: ...eives the following inputs: - context: is a struct of type [zContext](http...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~102-~102: Loose punctuation mark.
Context: ... on a connected chain. - chainID: integer ID of the connected chain from ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: Loose punctuation mark.
Context: ...connected chain on ZetaChain. - amount: the amount of tokens that were sent to ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~107-~107: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...ted chain on ZetaChain. - amount: the amount of tokens that were sent to the univers...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~189-~189: Loose punctuation mark.
Context: ...' alice ``` Parameters: - --receiver: The address of the `Hello` contract on ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~190-~190: Loose punctuation mark.
Context: ...ellocontract on ZetaChain. ---types`: The ABI types of the message parameters...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~191-~191: Loose punctuation mark.
Context: ...pes of the message parameters. - alice: The message to send. The EVM gateway p...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~257-~257: Loose punctuation mark.
Context: ...2 ``` Parameters: - --call-on-revert: Informs the gateway to handle reverts. ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~258-~258: Loose punctuation mark.
Context: ... to handle reverts. - --revert-address: The address of the Revert contract on...

(UNLIKELY_OPENING_PUNCTUATION)

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

7-11: LGTM!

The introduction provides a clear and concise overview of the tutorial's objective. The example of swapping USDC from Ethereum to BTC on Bitcoin effectively illustrates the cross-chain swap functionality.


15-18: LGTM!

The learning objectives are well-structured and cover the essential aspects of the tutorial. Deploying the contract to localnet and interacting with it from a connected EVM blockchain will provide developers with a practical understanding of the swap functionality.


43-48: LGTM!

The alert message effectively communicates the tutorial's compatibility limitations and provides a helpful redirection to the "Swap on Testnet" tutorial for users seeking a testnet-compatible version. This information is crucial to set the right expectations and ensure a smooth learning experience.


Line range hint 71-181: LGTM!

The Swap contract implementation aligns with the tutorial's description and includes the necessary functionality for handling cross-chain token swaps. The onCrossChainCall function correctly decodes the incoming message based on the source chain, and the swapAndWithdraw function handles the token swaps and withdrawals effectively. The usage of the GatewayZEVM contract for withdrawing tokens to the connected chain is appropriate.

Tools
LanguageTool

[uncategorized] ~188-~188: Loose punctuation mark.
Context: ... of information: - address target: The ZRC-20 address of the target token ...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~189-~189: Loose punctuation mark.
Context: ...get token on ZetaChain. - bytes to: The recipient's address on the destinat...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~223-~223: Consider placing the discourse marker ‘first’ at the beginning of the sentence for more clarity.
Context: ...maintain. #### Swapping for Gas Token The contract first addresses the gas fee required for the ...

(SENT_START_FIRST_PREMIUM)


258-261: LGTM!

The alert message offers a valuable clarification about the ZRC-20 contract's association with connected chains. It effectively explains that specifying the withdrawal chain is not necessary, as each ZRC-20 contract knows its associated chain. The example of ZRC-20 Ethereum USDC being withdrawable only to Ethereum strengthens the understanding of this concept.

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6da7c87 and c960ba4.

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

[style] ~49-~49: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it.
Context: ...y makes the contract more versatile for a variety of use cases. ```solidity // SPDX-License...

(A_VARIETY_OF)


[uncategorized] ~230-~230: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ... fee handling and simply swaps the full amount of tokens. Once the tokens are swapped...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~292-~292: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...he receiver address (the contract), the amount of tokens to swap, the target token add...

(AMOUNTOF_TO_NUMBEROF)


[style] ~318-~318: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it.
Context: ...hain, providing greater flexibility for a variety of use cases. ## Source Code You can fin...

(A_VARIETY_OF)

Additional comments not posted (4)
src/pages/developers/tutorials/swap-any.mdx (4)

Line range hint 77-85: The Params struct is well-defined and serves its purpose effectively.

The struct provides a clear and organized way to store the necessary parameters for the contract's functionality. The field names are descriptive, and their types align with their intended usage.


133-149: The conditional handling of gas fees based on the withdraw flag is implemented correctly.

The code segment logically handles the gas fees depending on whether the tokens will be withdrawn or not. When withdraw is true, it calculates and deducts the gas fee as expected. When withdraw is false, it appropriately skips the gas fee handling and swaps the full token amount.


182-187: The direct token transfer on ZetaChain when withdraw is false is implemented correctly.

The code segment appropriately transfers the swapped tokens directly to the recipient on ZetaChain when withdraw is false. Using the IWETH9 interface ensures compatibility with wrapped tokens, and the recipient address is correctly derived from the provided recipient bytes.


Line range hint 190-200: The swap function is a valuable addition that allows direct token swaps on ZetaChain.

The introduction of the swap function provides a convenient way for users to interact with the contract directly on ZetaChain, without the need for cross-chain calls. It takes the necessary parameters, including the withdraw flag, to determine the appropriate action after the swap. The function correctly transfers the input tokens from the sender to the contract before invoking swapAndWithdraw to perform the swap and handle the withdrawal or direct transfer based on the withdraw flag.

Tools
LanguageTool

[uncategorized] ~230-~230: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ... fee handling and simply swaps the full amount of tokens. Once the tokens are swapped...

(AMOUNTOF_TO_NUMBEROF)


[uncategorized] ~292-~292: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...he receiver address (the contract), the amount of tokens to swap, the target token add...

(AMOUNTOF_TO_NUMBEROF)


[style] ~318-~318: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it.
Context: ...hain, providing greater flexibility for a variety of use cases. ## Source Code You can fin...

(A_VARIETY_OF)

src/pages/developers/tutorials/swap-any.mdx Show resolved Hide resolved
@fadeev
Copy link
Member Author

fadeev commented Sep 19, 2024

@bbbeeeee @andresaiello @zeta-chain/fullstack please, review.

@fadeev fadeev merged commit 8f747ca into main Sep 24, 2024
6 checks passed
@fadeev fadeev deleted the gateway-localnet-examples branch September 24, 2024 04:29
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