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

refactor(fungible): set default liquidity cap for new ZRC20s #2802

Merged
merged 6 commits into from
Sep 10, 2024

Conversation

lumtis
Copy link
Member

@lumtis lumtis commented Aug 30, 2024

Description

Set 1000*base unit for the default liquidity cap for new ZRC20s

Close: #2521

Summary by CodeRabbit

  • New Features
    • Introduced a default liquidity cap for newly deployed ZRC20 tokens to enhance liquidity management and market stability.
  • Bug Fixes
    • Improved error handling and validation for the deployment of ZRC20 tokens.
  • Tests
    • Enhanced test coverage to verify the correct setting of liquidity caps during ZRC20 contract deployment.
  • Documentation
    • Updated changelog to reflect the new liquidity cap feature and its implications for token management.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The changes involve the implementation of a default liquidity cap for newly created ZRC20 tokens, enhancing the management of liquidity within the system. Key modifications include the introduction of a constant for the default liquidity cap, refactoring of related functions to improve clarity and error handling, and updates to testing procedures to ensure the correct application of the liquidity cap.

Changes

Files Change Summary
changelog.md Added entry for the implementation of a default liquidity cap for new ZRC20 tokens.
e2e/txserver/zeta_tx_server.go Refactored DeployZRC20s to improve fetching of contract address and modularized liquidity cap initialization. New functions added for fetching ZRC20 address and initializing liquidity cap.
x/fungible/keeper/evm.go Refactored DeployZRC20Contract to create a new coin object and introduced calculation for LiquidityCap.
x/fungible/keeper/evm_test.go Added assertion in TestKeeper_DeployZRC20Contract to verify correct setting of LiquidityCap.
x/fungible/keeper/gas_coin_and_pool_test.go Enhanced liquidity cap for foreign coins in setupGasCoin and deployZRC20 functions.
x/fungible/types/zrc20.go Introduced DefaultLiquidityCap constant set to 1000 for new ZRC20 tokens.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZetaTxServer
    participant Keeper
    participant ForeignCoin

    User->>ZetaTxServer: Deploy ZRC20 Token
    ZetaTxServer->>ZetaTxServer: fetchZRC20FromDeployResponse()
    ZetaTxServer->>Keeper: DeployZRC20Contract()
    Keeper->>ForeignCoin: Create newCoin
    Keeper->>ForeignCoin: Set LiquidityCap = DefaultLiquidityCap * 10^decimals
    ZetaTxServer->>User: Token Deployed with Liquidity Cap
Loading

Assessment against linked issues

Objective Addressed Explanation
ZRC20 Liquidity Caps should have a default value (#2521)

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 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.

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.

@lumtis lumtis changed the title Refactor/automatic liquidity cap refactor(fungible): set default liquidity cap for new ZRC20s Aug 30, 2024
Copy link

codecov bot commented Aug 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.61%. Comparing base (f617c89) to head (995a932).
Report is 17 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #2802   +/-   ##
========================================
  Coverage    66.60%   66.61%           
========================================
  Files          369      369           
  Lines        20727    20728    +1     
========================================
+ Hits         13806    13807    +1     
  Misses        6283     6283           
  Partials       638      638           
Files with missing lines Coverage Δ
x/fungible/keeper/evm.go 88.40% <100.00%> (+0.02%) ⬆️
x/fungible/types/zrc20.go 100.00% <ø> (ø)

@lumtis lumtis marked this pull request as ready for review August 30, 2024 16:57
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: 3

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b516a46 and 8a8a4a9.

Files selected for processing (6)
  • changelog.md (1 hunks)
  • e2e/txserver/zeta_tx_server.go (7 hunks)
  • x/fungible/keeper/evm.go (3 hunks)
  • x/fungible/keeper/evm_test.go (1 hunks)
  • x/fungible/keeper/gas_coin_and_pool_test.go (2 hunks)
  • x/fungible/types/zrc20.go (1 hunks)
Additional context used
Path-based instructions (5)
x/fungible/types/zrc20.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/keeper/gas_coin_and_pool_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

e2e/txserver/zeta_tx_server.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/keeper/evm_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

x/fungible/keeper/evm.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (5)
x/fungible/types/zrc20.go (1)

5-8: Well-documented constant addition.

The addition of DefaultLiquidityCap is well-documented and clearly explains its purpose and usage. This change should help standardize the deployment of new ZRC20 tokens and enhance security by providing a sensible default liquidity cap.

e2e/txserver/zeta_tx_server.go (2)

582-593: Good encapsulation of liquidity cap initialization.

The initializeLiquidityCap function encapsulates the logic for setting the liquidity cap, which enhances modularity and maintainability. The use of MustGetAccountAddressFromName within this function assumes that the operation will not fail, which is generally safe in controlled test environments but might need reconsideration for production code to handle potential errors gracefully.


595-607: Effective encapsulation of ZRC20 address fetching.

The fetchZRC20FromDeployResponse function effectively encapsulates the logic for extracting the ZRC20 address from a deployment response. This separation of concerns improves the readability and maintainability of the code. Consider adding more robust error handling or validation if the context of use expands beyond controlled test scenarios.

changelog.md (1)

25-25: Review the changelog entry for setting the default liquidity cap.

The entry "2802 - set default liquidity cap for new ZRC20s" is correctly placed under the "Refactor" section. This placement is appropriate as it reflects a change in the system's behavior rather than a new feature or a bug fix. The link to the pull request provides a direct reference for further details, which is a good practice for transparency and traceability.

x/fungible/keeper/evm_test.go (1)

319-319: Verify the Liquidity Cap Assertion

The new assertion checks if the LiquidityCap is correctly set to DefaultLiquidityCap * 8. Ensure that the DefaultLiquidityCap constant is defined with the expected value and that the multiplication by 8 is intentional. If these conditions are met, the assertion is correctly validating the new functionality.

Verification successful

Verify the Liquidity Cap Assertion

The DefaultLiquidityCap is defined as 1000 in x/fungible/types/zrc20.go. The test assertion multiplies this value by 8, resulting in a LiquidityCap of 8000. This multiplication appears intentional and aligns with the test's purpose to validate the correct setting of the liquidity cap during ZRC20 contract deployment. The assertion is correctly validating the new functionality.

  • Definition Location: x/fungible/types/zrc20.go
  • Defined Value: 1000
  • Test Assertion: Multiplies by 8 to check for 8000

No further action is required unless the multiplication factor of 8 needs additional context or justification within the test scenario.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and value of DefaultLiquidityCap.

# Test: Search for the definition and usage of DefaultLiquidityCap. Expect: Definition and correct usage.
rg --type go 'DefaultLiquidityCap' x/fungible/keeper/

Length of output: 311


Script:

#!/bin/bash
# Description: Search for the definition of DefaultLiquidityCap across the repository.

# Test: Locate the definition of DefaultLiquidityCap. Expect: Definition found in a relevant file.
rg --type go 'DefaultLiquidityCap' 

Length of output: 484

x/fungible/keeper/gas_coin_and_pool_test.go Show resolved Hide resolved
x/fungible/keeper/gas_coin_and_pool_test.go Show resolved Hide resolved
x/fungible/keeper/evm.go Show resolved Hide resolved
e2e/txserver/zeta_tx_server.go Show resolved Hide resolved
@lumtis lumtis added this pull request to the merge queue Sep 3, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 3, 2024
@lumtis lumtis added this pull request to the merge queue Sep 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Sep 3, 2024
* default liquidity cap

* fix test

* changelog

* set cap in e2e tests
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 3, 2024
@lumtis lumtis added this pull request to the merge queue Sep 3, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 3, 2024
@fbac fbac added this pull request to the merge queue Sep 10, 2024
@fbac
Copy link
Contributor

fbac commented Sep 10, 2024

Adding to merge queue, it was dropped out of it last week.

Merged via the queue into develop with commit 3c2da19 Sep 10, 2024
30 checks passed
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.

ZRC20 Liquidity Caps should have a default value
3 participants