-
Notifications
You must be signed in to change notification settings - Fork 29
fix: give unlinked coin #1076
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
fix: give unlinked coin #1076
Conversation
There was a problem hiding this 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)
togiveUnlinkedCoin(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"
1 file reviewed, no comments
target: `${STD_PACKAGE_ID}::option::destroy_none`, | ||
arguments: [channelOption], | ||
typeArguments: [channelType], | ||
}); |
There was a problem hiding this comment.
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.
why?
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.
symbol
andtokenId
instead of deploying/registering a coin; loads coin fromcontracts
.tokenId
; uses existingMetadata
,TreasuryCap
,typeArgument
.moveCall
now returns[TreasuryCapReclaimer, Channel]
; extracts/transfers both when requested and destroys options.give-unlinked-coin <symbol> <tokenId>
, removes--salt
, updates description.publish-coin <symbol> <name> <decimals>
to deploy a coin and save it.legacy-coins --createCoin
.Written by Cursor Bugbot for commit 76ba90c. This will update automatically on new commits. Configure here.