Skip to content

feat(zetaclient): PTB building for Sui withdrawAndCall transaction#3793

Merged
ws4charlie merged 59 commits intodevelopfrom
sui-ptb
Apr 25, 2025
Merged

feat(zetaclient): PTB building for Sui withdrawAndCall transaction#3793
ws4charlie merged 59 commits intodevelopfrom
sui-ptb

Conversation

@lumtis
Copy link
Contributor

@lumtis lumtis commented Apr 9, 2025

Description

Done

Closes #3740 #3741

Summary by CodeRabbit

  • New Features

    • Added support for Sui "withdraw and call" transactions using programmable transaction builder (PTB), enabling advanced cross-chain operations.
    • Introduced new Sui example contracts and Move modules for testing and demonstration purposes.
    • Expanded Sui configuration options with additional contract fields.
    • Enhanced Sui signer with new RPC methods for batch object retrieval and coin queries.
  • Bug Fixes

    • Improved test coverage and validation for Sui withdraw-and-call logic.
  • Documentation

    • Updated changelog with new feature entries.
    • Added Move package manifest and .gitignore for Sui contract examples.
  • Tests

    • Added comprehensive unit and integration tests for new Sui transaction types and argument parsing.
  • Chores

    • Added new dependencies related to Sui blockchain support.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

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

This change set introduces comprehensive support for Sui programmable transaction blocks (PTB) in the ZetaClient, specifically targeting the "withdrawAndCall" pattern. It adds new Move modules for Sui contract testing, expands configuration and deployment logic to handle example contracts, and implements robust Go-side utilities to build, parse, and test PTB transactions. The ZetaClient's signer logic is refactored to construct and broadcast PTB transactions, with appropriate logging and object reference management. Supporting utilities for Sui coin types and PTB arguments are added, and extensive unit tests ensure correctness of the new parsing and transaction-building logic. Mock interfaces and dependencies are updated to accommodate new RPC requirements.

Changes

File(s) Change Summary
e2e/contracts/sui/example/Move.toml, e2e/contracts/sui/example/sources/example.move, e2e/contracts/sui/example/sources/token.move Added new Move package and modules for Sui example contracts, defining custom coin and shared object logic for E2E testing.
e2e/contracts/sui/bin.go Embedded new Move bytecode binaries and accessor functions for the example contracts.
e2e/contracts/sui/example/.gitignore Added .gitignore to exclude build artifacts.
e2e/config/config.go Extended Sui config struct with fields for example contract object IDs and types.
e2e/runner/runner.go, e2e/runner/sui.go, e2e/runner/setup_sui.go Added logic and struct for deploying, tracking, and storing Sui example contract object IDs; refactored Sui deployment and setup for modularity.
cmd/zetae2e/config/config.go, cmd/zetae2e/config/contracts.go Updated contract export/import logic to include new Sui example contract fields.
e2e/e2etests/test_sui_withdraw_and_call.go Refactored Sui withdraw-and-call E2E test to use dynamic inputs and example contracts, verifying balance changes.
cmd/zetae2e/local/local.go Re-enabled the Sui withdraw-and-call E2E test.
pkg/contracts/sui/coin.go, pkg/contracts/sui/coin_test.go Introduced Sui coin type utility and corresponding tests.
pkg/contracts/sui/ptb_argument.go, pkg/contracts/sui/ptb_argument_test.go Added PTB argument parsing/construction utilities and tests.
pkg/contracts/sui/withdraw_and_call_ptb.go, pkg/contracts/sui/withdraw_and_call_ptb_test.go Implemented parsing logic for Sui withdraw-and-call PTB transactions and comprehensive unit tests.
pkg/contracts/sui/gateway.go Removed redundant coin type definitions, added PTB event type, and integrated PTB parsing into outbound event logic.
go.mod Added dependencies for Sui/Move development and blockchain utilities.
testutil/sample/crypto.go Added utility for generating sample Sui addresses for tests.
zetaclient/chains/sui/observer/observer.go Removed unused SuiGetObject RPC method from observer interface.
zetaclient/chains/sui/observer/outbound.go Improved logging for outbound vote posting.
zetaclient/chains/sui/signer/signer.go, zetaclient/chains/sui/signer/withdraw_and_call.go, zetaclient/chains/sui/signer/signer_tx.go Implemented PTB transaction construction for withdraw-and-call, added new RPCs for batch object and coin retrieval, refactored logging and internal parameter naming.
zetaclient/chains/sui/signer/signer_tracker.go Updated logging context for outbound tracker reporting.
zetaclient/testutils/mocks/sui_client.go, zetaclient/testutils/mocks/sui_gen.go Updated and extended Sui client mock interfaces to support new RPC methods and batch operations.

Sequence Diagram(s)

sequenceDiagram
    participant Test as E2E Test
    participant Runner as E2ERunner
    participant SuiChain as Sui Blockchain
    participant Signer as ZetaClient Signer

    Test->>Runner: Deploy Sui Example Contracts
    Runner->>SuiChain: Publish Move modules (token, connected)
    SuiChain-->>Runner: Return package and object IDs

    Test->>Runner: Prepare WithdrawAndCall Test
    Runner->>Signer: Build PTB withdrawAndCall transaction
    Signer->>SuiChain: Fetch object refs, build PTB
    Signer->>SuiChain: Broadcast PTB transaction
    SuiChain-->>Signer: Transaction result

    Test->>SuiChain: Query recipient balance
    SuiChain-->>Test: Return balance
Loading

Assessment against linked issues

Objective Addressed Explanation
Add support for Sui PTB in ZetaClient, including building blocks for withdrawAndCall PTB transactions that invoke withdraw_impl and on_call (Issue #3740)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 linked an issue Apr 9, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Apr 9, 2025

Codecov Report

Attention: Patch coverage is 63.94366% with 128 lines in your changes missing coverage. Please review.

Project coverage is 64.40%. Comparing base (29f26d4) to head (85449be).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
zetaclient/chains/sui/signer/withdraw_and_call.go 80.15% 34 Missing and 17 partials ⚠️
zetaclient/chains/sui/client/client.go 12.50% 42 Missing ⚠️
zetaclient/chains/sui/signer/signer_tx.go 24.44% 34 Missing ⚠️
zetaclient/chains/sui/observer/outbound.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3793      +/-   ##
===========================================
+ Coverage    64.38%   64.40%   +0.02%     
===========================================
  Files          463      464       +1     
  Lines        33356    33667     +311     
===========================================
+ Hits         21476    21684     +208     
- Misses       10889    10976      +87     
- Partials       991     1007      +16     
Files with missing lines Coverage Δ
zetaclient/chains/sui/observer/observer.go 53.62% <ø> (ø)
zetaclient/chains/sui/signer/signer.go 52.99% <100.00%> (+1.23%) ⬆️
zetaclient/chains/sui/signer/signer_tracker.go 65.07% <100.00%> (-1.08%) ⬇️
zetaclient/chains/sui/observer/outbound.go 57.35% <0.00%> (-0.90%) ⬇️
zetaclient/chains/sui/signer/signer_tx.go 50.22% <24.44%> (-1.48%) ⬇️
zetaclient/chains/sui/client/client.go 13.30% <12.50%> (-2.64%) ⬇️
zetaclient/chains/sui/signer/withdraw_and_call.go 80.15% <80.15%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Apr 18, 2025

!!!WARNING!!!
nosec detected in the following files: zetaclient/chains/sui/signer/withdraw_and_call.go, e2e/e2etests/e2etests.go, e2e/runner/sui.go, pkg/contracts/sui/gateway.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label Apr 18, 2025
@lumtis
Copy link
Contributor Author

lumtis commented Apr 24, 2025

@ws4charlie ready for new review?

@ws4charlie
Copy link
Contributor

ws4charlie commented Apr 24, 2025

@ws4charlie ready for new review?

Yeah. The withdrawAndCall revert E2E test is added: bd2f5da @lumtis

Copy link
Contributor Author

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

Solid ✅

Can't approve since I orignally created the PR but it looks good to me

@swift1337 swift1337 added the SOLANA_TESTS Run make start-solana-test label Apr 25, 2025
Copy link
Contributor

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all comments! Looks solid 📈

The only part that is left IMO is to add a unit test for TestSigner.ProcessCCTX that checks that all RPC calls are valid (similarly to ts.MockMoveCall(...)).

Let's tackle this in a separate issue: #3829

@ws4charlie ws4charlie added this pull request to the merge queue Apr 25, 2025
Merged via the queue into develop with commit 835341d Apr 25, 2025
46 of 47 checks passed
@ws4charlie ws4charlie deleted the sui-ptb branch April 25, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking:cli chain:sui nosec SOLANA_TESTS Run make start-solana-test zetaclient Issues related to ZetaClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add implementation for withdrawAndCall PTB in ZetaClient Add support for Sui PTB in ZetaClient

4 participants