Skip to content

Conversation

blockchainguyy
Copy link
Contributor

@blockchainguyy blockchainguyy commented Oct 1, 2025

why?

  • ...
  • Task: ?

how?

  • ...

testing

  • ...

Note

Splits linking flow by adding link-coin-with-channel (uses existing channel, pays gas, sends link message) and trimming link-coin to deploy/register only; updates docs and CLI.

  • ITS CLI (sui/its.js)
    • New command: link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId> --tokenManagerMode <lock_unlock|mint_burn> --gasValue <amount_in_SUI> [--saltAddress <addr>].
      • Constructs salt, selects token manager type, pays gas via GasService::pay_gas, sends link message via AxelarGateway::gateway::send_message, and saves [linkedToken] to config.
    • Refactor link-coin: Remove in-command linking and message send; now only deploys/registers coin and saves deployment with empty linkedTokens.
      • Logs resolved channelId.
  • Docs (sui/README.md)
    • Add usage example for link-coin-with-channel alongside link-coin.

Written by Cursor Bugbot for commit 40c2870. This will update automatically on new commits. Configure here.

Greptile Overview

Updated On: 2025-10-01 13:16:51 UTC

Summary

This PR refactors the `link-coin` command in the Sui ITS (Interchain Token Service) implementation by breaking it into two separate, more focused commands. The original `link-coin` command was performing both token deployment/registration AND cross-chain linking in a single operation, which has been split for better separation of concerns.

The refactored link-coin command now only handles:

  • Token deployment and registration with the ITS
  • Generation of a channelId for the token
  • Saving token deployment information (but with an empty linked tokens array)

The new link-coin-with-channel command handles the actual cross-chain linking functionality:

  • Requires an existing channelId (from a previous link-coin operation)
  • Handles token manager type configuration
  • Manages gas payments for cross-chain transactions
  • Performs the actual linking via gateway message sending

This change aligns with the principle of single responsibility, allowing developers to deploy tokens first and then link them to destination chains in separate steps. The documentation in sui/README.md has been updated to reflect both command options, providing users with examples of the simpler link-coin command and the more advanced link-coin-with-channel command with its additional parameters.

Important Files Changed

Changed Files
Filename Score Overview
sui/its.js 4/5 Breaks link-coin command into two separate commands, removing 49 lines of linking logic from the original command and adding new linkCoinWithChannel function
sui/README.md 5/5 Documentation update adding example usage for the new link-coin-with-channel command alongside existing link-coin command

Confidence score: 4/5

  • This PR appears safe to merge with the separation of concerns improving code maintainability and user experience
  • Score reflects solid architectural improvement with clear separation between deployment and linking phases
  • The documentation file requires no special attention, but the main logic changes in sui/its.js should be tested to ensure both commands work independently

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as "CLI (sui/its.js)"
    participant TxBuilder as "Transaction Builder"
    participant ITS as "InterchainTokenService"
    participant Gateway as "AxelarGateway"
    participant GasService as "Gas Service"
    participant Blockchain as "Sui Network"

    User->>CLI: "link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId>"
    CLI->>CLI: "Validate parameters and options"
    CLI->>TxBuilder: "Create new TxBuilder instance"
    
    TxBuilder->>ITS: "Call token_manager_type with tokenManagerMode"
    ITS-->>TxBuilder: "Return tokenManagerType object"
    
    TxBuilder->>Gateway: "Create bytes32 salt from saltAddress"
    Gateway-->>TxBuilder: "Return salt object"
    
    TxBuilder->>ITS: "Call link_coin with parameters"
    Note over TxBuilder,ITS: "Parameters: InterchainTokenService, channel, salt, destinationChain, destinationAddress, tokenManagerType, linkParams"
    ITS-->>TxBuilder: "Return messageTicket"
    
    TxBuilder->>TxBuilder: "Split gas coins for payment"
    
    TxBuilder->>GasService: "Call pay_gas with messageTicket and gas"
    GasService-->>TxBuilder: "Gas payment processed"
    
    TxBuilder->>Gateway: "Call send_message with messageTicket"
    Gateway-->>TxBuilder: "Message queued for sending"
    
    CLI->>Blockchain: "Broadcast transaction"
    Blockchain-->>CLI: "Transaction result"
    
    CLI->>CLI: "Save linked token info to config"
    CLI-->>User: "Link Coin operation completed"
Loading

@blockchainguyy blockchainguyy marked this pull request as ready for review October 1, 2025 13:15
@blockchainguyy blockchainguyy requested a review from a team as a code owner October 1, 2025 13:15
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

sui/README.md Outdated
```bash
ts-node sui/its link-coin <symbol> <name> <decimals> <destinationChain> <destinationAddress>

node sui/its.js link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId> --tokenManagerMode <lock_unlock|mint_burn> --gasValue <amount_in_SUI> --saltAddress <addr>
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Inconsistent command invocation - uses 'node' instead of 'ts-node' like other commands in the documentation

Suggested change
node sui/its.js link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId> --tokenManagerMode <lock_unlock|mint_burn> --gasValue <amount_in_SUI> --saltAddress <addr>
ts-node sui/its.js link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId> --tokenManagerMode <lock_unlock|mint_burn> --gasValue <amount_in_SUI> --saltAddress <addr>
Prompt To Fix With AI
This is a comment left during a code review.
Path: sui/README.md
Line: 522:522

Comment:
style: Inconsistent command invocation - uses 'node' instead of 'ts-node' like other commands in the documentation

```suggestion
ts-node sui/its.js link-coin-with-channel <symbol> <destinationChain> <destinationAddress> --channel <channelId> --tokenManagerMode <lock_unlock|mint_burn> --gasValue <amount_in_SUI> --saltAddress <addr>
```

How can I resolve this? If you propose a fix, please make it concise.

new Option('--tokenManagerMode <mode>', 'Token Manager Mode').choices(['lock_unlock', 'mint_burn']).makeOptionMandatory(true),
)
.addOption(new Option('--destinationOperator <address>', 'Operator that can control flow limits on the destination chain'))
.requiredOption('--gasValue <amount>', 'Amount to pay gas (SUI full units)', parseSuiUnitAmount)
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: Missing import for parseSuiUnitAmount function used in gasValue validation

Prompt To Fix With AI
This is a comment left during a code review.
Path: sui/its.js
Line: 1069:1069

Comment:
syntax: Missing import for `parseSuiUnitAmount` function used in gasValue validation

How can I resolve this? If you propose a fix, please make it concise.

cursor[bot]

This comment was marked as outdated.

coin.objects.Metadata,
[linkedToken],
saltAddress,
);
Copy link

Choose a reason for hiding this comment

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

Bug: Token Linking Overwrites Data, Gas Wasted

The linkCoinWithChannel function overwrites existing linked token data when saving, causing previously linked chains to be lost if a token is linked multiple times. Separately, the token existence check occurs after the transaction is broadcast, potentially wasting gas if the token isn't in the config.

Fix in Cursor Fix in Web

@drewstaylor
Copy link
Member

This work was done in #1059

@drewstaylor drewstaylor closed this Oct 1, 2025
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