Skip to content

Conversation

blockchainguyy
Copy link
Contributor

@blockchainguyy blockchainguyy commented Oct 7, 2025

why?

  • ...
  • Task: ?

how?

  • ...

testing

  • ...

Note

Refactors give-unlinked-coin to use an existing coin with a provided tokenId (and handle Channel), and adds a new publish-coin CLI to deploy coins.

  • ITS / give_unlinked_coin:
    • Accepts symbol and tokenId instead of deploying/registering a coin; loads coin from contracts.
    • Validates tokenId; uses existing Metadata, TreasuryCap, typeArgument.
    • moveCall now returns [TreasuryCapReclaimer, Channel]; extracts/transfers both when requested and destroys options.
    • Saves deployment with empty salt string.
    • CLI: changes command to give-unlinked-coin <symbol> <tokenId>, removes --salt, updates description.
  • Tokens CLI:
    • Adds publish-coin <symbol> <name> <decimals> to deploy a coin and save it.
    • Minor validation consolidation in legacy-coins --createCoin.

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

@blockchainguyy blockchainguyy requested a review from a team as a code owner October 7, 2025 13:10
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.

Greptile Overview

Summary

This PR refactors the `giveUnlinkedCoin` function in `sui/its.js` to focus solely on giving treasury capabilities of existing coins to the Interchain Token Service (ITS), rather than deploying new tokens. The change represents a separation of concerns where the function now assumes coins are already deployed and registered in the configuration.

The key changes include:

  • Function signature update: Changed from giveUnlinkedCoin(symbol, name, decimals) to giveUnlinkedCoin(symbol, tokenId)
  • Removed token deployment logic: Eliminated the code that was creating new tokens via copyMovePackage and custom coin registration
  • Configuration-based approach: The function now loads existing coin details from the configuration using the provided tokenId
  • CLI command update: Updated the command signature and removed the salt option

This refactoring aligns the function name with its actual purpose - giving treasury capabilities of an already deployed coin to ITS rather than creating and then giving capabilities. The change makes the codebase more modular by separating token deployment from treasury capability management.

PR Description Notes:

  • The PR description is incomplete with placeholder text ("...", "?") and lacks specific details about the changes made
  • Missing testing information and rationale for the change

Important Files Changed

Changed Files
Filename Score Overview
sui/its.js 4/5 Refactored giveUnlinkedCoin function to work with existing coins instead of deploying new ones, updated CLI command signature

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it's a focused refactoring that improves code organization
  • Score reflects clean separation of concerns and straightforward logic changes without complex interdependencies
  • Pay attention to ensuring existing coins are properly configured before calling this function

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as "CLI Program"
    participant GUC as "giveUnlinkedCoin"
    participant TxBuilder as "TxBuilder"
    participant ITS as "InterchainTokenService"
    participant Wallet as "User Wallet"

    User->>CLI: "give-unlinked-coin <symbol> <tokenId> [--treasuryCapReclaimer]"
    CLI->>GUC: "mainProcessor(giveUnlinkedCoin, options, [symbol, tokenId])"
    GUC->>GUC: "validateParameters({isHexString: {tokenId}})"
    GUC->>GUC: "Find coin config by symbol"
    alt Coin not found
        GUC-->>User: "Error: Cannot find coin with symbol"
    end
    GUC->>TxBuilder: "Create new TxBuilder(client)"
    GUC->>TxBuilder: "moveCall token_id::from_address"
    TxBuilder->>ITS: "Convert tokenId to TokenId object"
    ITS-->>TxBuilder: "tokenIdObject"
    alt treasuryCapReclaimer option enabled
        GUC->>TxBuilder: "moveCall option::some with TreasuryCap"
        TxBuilder-->>GUC: "treasuryCapOption"
    else treasuryCapReclaimer option disabled
        GUC->>TxBuilder: "moveCall option::none"
        TxBuilder-->>GUC: "treasuryCapOption"
    end
    GUC->>TxBuilder: "moveCall give_unlinked_coin"
    TxBuilder->>ITS: "give_unlinked_coin(InterchainTokenService, tokenIdObject, metadata, treasuryCapOption)"
    ITS-->>TxBuilder: "treasuryCapReclaimerOption"
    alt treasuryCapReclaimer option enabled
        GUC->>TxBuilder: "moveCall option::extract"
        TxBuilder-->>GUC: "treasuryCapReclaimer"
        GUC->>TxBuilder: "transferObjects([treasuryCapReclaimer], walletAddress)"
        TxBuilder->>Wallet: "Transfer TreasuryCapReclaimer"
    end
    GUC->>TxBuilder: "moveCall option::destroy_none"
    GUC->>GUC: "broadcastFromTxBuilder(txBuilder, keypair)"
    GUC->>ITS: "Broadcast transaction"
    ITS-->>GUC: "Transaction result"
    GUC->>GUC: "saveTokenDeployment(...)"
    alt treasuryCapReclaimer created
        GUC->>GUC: "Save TreasuryCapReclaimer to coin config"
    end
    GUC-->>User: "Give Unlinked Coin completed"
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@drewstaylor drewstaylor merged commit c4db003 into fix/sui-link-coin-encoding Oct 7, 2025
7 checks passed
@drewstaylor drewstaylor deleted the fix/give-unlinked-coin branch October 7, 2025 16:47
target: `${STD_PACKAGE_ID}::option::destroy_none`,
arguments: [channelOption],
typeArguments: [channelType],
});
Copy link

Choose a reason for hiding this comment

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

Bug: Unconditional Destruction of Optional Values

The giveUnlinkedCoin function unconditionally calls destroy_none on treasuryCapReclaimerOption and channelOption. This fails because when options.treasuryCapReclaimer is true, their values are extracted, consuming them. When options.treasuryCapReclaimer is false, channelOption is never extracted, remaining a Some variant.

Fix in Cursor Fix in Web

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