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

feat: erc20 custody legacy deposit #328

Merged
merged 5 commits into from
Aug 15, 2024
Merged

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Aug 15, 2024

Focused to make minimal changes and difference between future version of contract. We need 2 new fields (zeta and zetaFee) which now can only be updated by admin (should this be changed to be called by tss address? or introduce new role for it?), and not added in constructor. I also didn't add maxZetaFee field to keep it minimal, but can be added if needed.

closes: #326

Summary by CodeRabbit

  • New Features

    • Introduced new public variables tssAddress and supportsLegacy for enhanced contract management.
    • Added functions for managing legacy support and deprecated setters for backward compatibility.
  • Bug Fixes

    • Enhanced the deposit function to enforce checks on legacy method support.
  • Tests

    • Expanded the test suite to include validations for legacy deposit methods and error handling scenarios.

Copy link
Contributor

coderabbitai bot commented Aug 15, 2024

Walkthrough

Walkthrough

The recent updates to the ERC20Custody contract enhance its functionality by introducing support for legacy deposit methods, improving error handling, and facilitating integration with external systems. Key additions include new public state variables for managing legacy functionality, modifications to the constructor, and additional external functions. These changes ensure backward compatibility while allowing for more flexible contract operations.

Changes

Files Change Summary
v2/src/evm/ERC20Custody.sol Added tssAddress and supportsLegacy state variables, modified the constructor to initialize tssAddress, updated deposit function to check legacy support, and retained deprecated setter functions for compatibility.
v2/test/ERC20Custody.t.sol Introduced new tests for legacy deposit methods, including checks for successful deposits when legacy support is enabled and reverts when it is disabled or tokens are unwhitelisted.

Possibly related issues


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.

@@ -22,20 +22,32 @@
IGatewayEVM public immutable gateway;
/// @notice Mapping of whitelisted tokens => true/false.
mapping(address => bool) public whitelisted;
/// @notice The address of the TSS (Threshold Signature Scheme) contract.
address public tssAddress;

Check warning

Code scanning / Slither

State variables that could be declared immutable Warning

ERC20Custody.tssAddress should be immutable
@@ -53,6 +65,23 @@
_unpause();
}

/// @notice Unpause contract.
function setSupportsLegacy(bool _supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {

Check warning

Code scanning / Slither

Conformance to Solidity naming conventions Warning

v2/src/evm/ERC20Custody.sol Fixed Show fixed Hide fixed
v2/src/evm/ERC20Custody.sol Fixed Show fixed Hide fixed
@codecov-commenter
Copy link

codecov-commenter commented Aug 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.23%. Comparing base (7b37b69) to head (fb2a8e2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #328      +/-   ##
==========================================
+ Coverage   81.81%   82.23%   +0.41%     
==========================================
  Files           7        7              
  Lines         297      304       +7     
  Branches       97       99       +2     
==========================================
+ Hits          243      250       +7     
  Misses         54       54              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 15f0e2b and b980254.

Files ignored due to path filters (27)
  • v2/pkg/erc20custody.sol/erc20custody.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custody.t.sol/erc20custodytest.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custodyechidnatest.sol/erc20custodyechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.sol/gatewayevm.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevminboundtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmechidnatest.sol/gatewayevmechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmupgrade.t.sol/gatewayevmuupsupgradetest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmupgradetest.sol/gatewayevmupgradetest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/ierc20custody.sol/ierc20custody.go is excluded by !v2/pkg/**
  • v2/pkg/ierc20custody.sol/ierc20custodyerrors.go is excluded by !v2/pkg/**
  • v2/pkg/ierc20custody.sol/ierc20custodyevents.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornative.t.sol/zetaconnectornativetest.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornonnative.t.sol/zetaconnectornonnativetest.go is excluded by !v2/pkg/**
  • v2/types/ERC20Custody.ts is excluded by !v2/types/**
  • v2/types/ERC20CustodyEchidnaTest.ts is excluded by !v2/types/**
  • v2/types/IERC20Custody.sol/IERC20Custody.ts is excluded by !v2/types/**
  • v2/types/IERC20Custody.sol/IERC20CustodyEvents.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20CustodyEchidnaTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20Custody__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVMEchidnaTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVMUpgradeTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVM__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IERC20Custody.sol/IERC20CustodyErrors__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IERC20Custody.sol/IERC20CustodyEvents__factory.ts is excluded by !v2/types/**
  • v2/types/factories/IERC20Custody.sol/IERC20Custody__factory.ts is excluded by !v2/types/**
Files selected for processing (3)
  • v2/src/evm/ERC20Custody.sol (3 hunks)
  • v2/src/evm/interfaces/IERC20Custody.sol (3 hunks)
  • v2/test/ERC20Custody.t.sol (3 hunks)
Additional context used
GitHub Check: Slither
v2/src/evm/ERC20Custody.sol

[warning] 26-26: State variables that could be declared immutable
ERC20Custody.tssAddress (src/evm/ERC20Custody.sol#26) should be immutable


[warning] 69-69: Conformance to Solidity naming conventions
Parameter ERC20Custody.setSupportsLegacy(bool)._supportsLegacy (src/evm/ERC20Custody.sol#69) is not in mixedCase


[warning] 75-75: Conformance to Solidity naming conventions
Parameter ERC20Custody.setZeta(IERC20)._zeta (src/evm/ERC20Custody.sol#75) is not in mixedCase


[warning] 81-81: Conformance to Solidity naming conventions
Parameter ERC20Custody.setZetaFee(uint256)._zetaFee (src/evm/ERC20Custody.sol#81) is not in mixedCase

Additional comments not posted (10)
v2/src/evm/interfaces/IERC20Custody.sol (2)

41-42: Event Deposited is well-defined.

The event captures necessary details for legacy deposit tracking. Ensure its usage is consistent across the contract.


52-53: Error LegacyMethodsNotSupported is appropriately defined.

This error enhances clarity in error handling for unsupported legacy methods.

v2/src/evm/ERC20Custody.sol (2)

28-28: State variable supportsLegacy is well-defined.

This flag effectively controls the support for legacy methods.


182-204: Function deposit is well-implemented with legacy support check.

The function appropriately handles legacy support and fee management.

v2/test/ERC20Custody.t.sol (6)

41-41: Error LegacyMethodsNotSupported is appropriately defined for testing.

This error facilitates testing of unsupported legacy methods.


477-497: Test testDepositLegacy effectively validates legacy deposit functionality.

The test ensures correct balance updates and event emission.


499-519: Test testDepositLegacyIfZetaFeeIs0 correctly handles zero fee scenarios.

The test ensures the TSS Zeta balance remains unchanged when the fee is zero.


521-540: Test testDepositLegacyIfZetaIsZeroAddress ensures deposits function without a Zeta address.

The test confirms deposits proceed correctly when the Zeta address is not set.


542-553: Test testDepositLegacyFailsIfNotSupported correctly verifies failure without legacy support.

The test ensures the deposit reverts when legacy support is disabled.


555-567: Test testDepositLegacyFailsIfTokenNotWhitelisted ensures deposits fail for unwhitelisted tokens.

The test correctly verifies access control by rejecting deposits for unwhitelisted tokens.

Comment on lines 81 to 83
function setZetaFee(uint256 _zetaFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
zetaFee = _zetaFee;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename parameter _zetaFee to follow naming conventions.

The parameter should be in mixedCase to conform with Solidity naming conventions.

- function setZetaFee(uint256 _zetaFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
+ function setZetaFee(uint256 zetaFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function setZetaFee(uint256 _zetaFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
zetaFee = _zetaFee;
}
function setZetaFee(uint256 zetaFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
zetaFee = _zetaFee;
}
Tools
GitHub Check: Slither

[warning] 81-81: Conformance to Solidity naming conventions
Parameter ERC20Custody.setZetaFee(uint256)._zetaFee (src/evm/ERC20Custody.sol#81) is not in mixedCase

Comment on lines 75 to 77
function setZeta(IERC20 _zeta) external onlyRole(DEFAULT_ADMIN_ROLE) {
zeta = _zeta;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename parameter _zeta to follow naming conventions.

The parameter should be in mixedCase to conform with Solidity naming conventions.

- function setZeta(IERC20 _zeta) external onlyRole(DEFAULT_ADMIN_ROLE) {
+ function setZeta(IERC20 zeta) external onlyRole(DEFAULT_ADMIN_ROLE) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function setZeta(IERC20 _zeta) external onlyRole(DEFAULT_ADMIN_ROLE) {
zeta = _zeta;
}
function setZeta(IERC20 zeta) external onlyRole(DEFAULT_ADMIN_ROLE) {
zeta = _zeta;
}
Tools
GitHub Check: Slither

[warning] 75-75: Conformance to Solidity naming conventions
Parameter ERC20Custody.setZeta(IERC20)._zeta (src/evm/ERC20Custody.sol#75) is not in mixedCase

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove zeta related logic

v2/src/evm/ERC20Custody.sol Outdated Show resolved Hide resolved
@skosito skosito requested a review from lumtis August 15, 2024 14:14
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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b980254 and fb2a8e2.

Files ignored due to path filters (15)
  • v2/pkg/erc20custody.sol/erc20custody.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custody.t.sol/erc20custodytest.go is excluded by !v2/pkg/**
  • v2/pkg/erc20custodyechidnatest.sol/erc20custodyechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevminboundtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevm.t.sol/gatewayevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmechidnatest.sol/gatewayevmechidnatest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmupgrade.t.sol/gatewayevmuupsupgradetest.go is excluded by !v2/pkg/**
  • v2/pkg/gatewayevmzevm.t.sol/gatewayevmzevmtest.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornative.t.sol/zetaconnectornativetest.go is excluded by !v2/pkg/**
  • v2/pkg/zetaconnectornonnative.t.sol/zetaconnectornonnativetest.go is excluded by !v2/pkg/**
  • v2/types/ERC20Custody.ts is excluded by !v2/types/**
  • v2/types/ERC20CustodyEchidnaTest.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20CustodyEchidnaTest__factory.ts is excluded by !v2/types/**
  • v2/types/factories/ERC20Custody__factory.ts is excluded by !v2/types/**
  • v2/types/factories/GatewayEVMEchidnaTest__factory.ts is excluded by !v2/types/**
Files selected for processing (2)
  • v2/src/evm/ERC20Custody.sol (4 hunks)
  • v2/test/ERC20Custody.t.sol (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • v2/test/ERC20Custody.t.sol
Additional context used
GitHub Check: Slither
v2/src/evm/ERC20Custody.sol

[warning] 26-26: State variables that could be declared immutable
ERC20Custody.tssAddress (src/evm/ERC20Custody.sol#26) should be immutable


[warning] 62-62: Conformance to Solidity naming conventions
Parameter ERC20Custody.setSupportsLegacy(bool)._supportsLegacy (src/evm/ERC20Custody.sol#62) is not in mixedCase

Additional comments not posted (3)
v2/src/evm/ERC20Custody.sol (3)

27-28: LGTM: Addition of supportsLegacy.

The supportsLegacy state variable is a useful addition for managing legacy functionality.


42-43: LGTM: Constructor changes.

The constructor is well-structured and correctly initializes the necessary state variables and roles.


163-182: LGTM: deposit function changes.

The deposit function correctly handles legacy method support and token transfer logic.

@@ -22,6 +22,10 @@
IGatewayEVM public immutable gateway;
/// @notice Mapping of whitelisted tokens => true/false.
mapping(address => bool) public whitelisted;
/// @notice The address of the TSS (Threshold Signature Scheme) contract.
address public tssAddress;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making tssAddress immutable.

The tssAddress variable is set only once in the constructor and can be declared immutable for gas optimization.

- address public tssAddress;
+ address public immutable tssAddress;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
address public tssAddress;
address public immutable tssAddress;
Tools
GitHub Check: Slither

[warning] 26-26: State variables that could be declared immutable
ERC20Custody.tssAddress (src/evm/ERC20Custody.sol#26) should be immutable

Comment on lines +62 to +64
function setSupportsLegacy(bool _supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {
supportsLegacy = _supportsLegacy;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename parameter _supportsLegacy to follow naming conventions.

The parameter should be in mixedCase to conform with Solidity naming conventions.

- function setSupportsLegacy(bool _supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {
+ function setSupportsLegacy(bool supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function setSupportsLegacy(bool _supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {
supportsLegacy = _supportsLegacy;
}
function setSupportsLegacy(bool supportsLegacy) external onlyRole(DEFAULT_ADMIN_ROLE) {
supportsLegacy = _supportsLegacy;
}
Tools
GitHub Check: Slither

[warning] 62-62: Conformance to Solidity naming conventions
Parameter ERC20Custody.setSupportsLegacy(bool)._supportsLegacy (src/evm/ERC20Custody.sol#62) is not in mixedCase

@skosito skosito merged commit f172f56 into main Aug 15, 2024
9 checks passed
@skosito skosito deleted the erc20-custody-legacy-deposit branch August 15, 2024 15:15
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.

Add support for legacy deposit in ERC20Custody
4 participants