Skip to content

Conversation

blockchainguyy
Copy link
Contributor

@blockchainguyy blockchainguyy commented Aug 22, 2025

Greptile Summary

This PR fixes the syncPackages function in the Sui deployment script (sui/deploy-contract.js). The sync command is responsible for synchronizing local Move package dependencies with deployed contract addresses on the Sui blockchain, ensuring that local development environments reference the correct on-chain package IDs.

The changes improve robustness by adding proper error handling for missing packages in the configuration and implementing logic to detect upgraded contracts. When contracts are upgraded on Sui, they receive new package IDs, and syncing these can create dependency conflicts in the Move.toml files. The fix addresses this by:

  1. Error handling: Adding early return when a package is not found in the chain configuration, preventing crashes
  2. Upgraded contract detection: Checking if a contract has multiple versions (indicating upgrades) and skipping sync for these contracts
  3. Selective syncing: Only syncing non-upgraded contracts to maintain clean dependency trees

This change integrates well with the existing Axelar contract deployment infrastructure, which manages complex multi-chain deployments. The sync functionality is critical for maintaining consistency between local development environments and deployed contracts across different blockchain networks.

Important Files Changed

Modified Files
Filename Score Overview
sui/deploy-contract.js 4/5 Fixed syncPackages function with error handling and upgraded contract detection

Confidence score: 4/5

  • This PR is safe to merge with low risk as it adds defensive programming practices
  • Score reflects solid error handling improvements and logical contract upgrade detection
  • No files require special attention beyond standard review practices

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as "Commander CLI"
    participant Main as "mainProcessor"
    participant Config as "Config Manager"
    participant Wallet as "Wallet Utils"
    participant Sync as "syncPackages"
    participant FS as "File System"
    participant Move as "Move Package Utils"

    User->>CLI: "node deploy-contract.js sync --env <env> --chainName <chain>"
    CLI->>Main: "mainProcessor([], options, syncPackages)"
    Main->>Config: "loadConfig(options.env)"
    Config-->>Main: "config object"
    Main->>Config: "getChainConfig(config.chains, options.chainName)"
    Config-->>Main: "chain config"
    Main->>Wallet: "getWallet(sui, options)"
    Wallet-->>Main: "[keypair, client]"
    Main->>Wallet: "printWalletInfo(keypair, client, sui, options)"
    Main->>Sync: "syncPackages(keypair, client, config, chain, options)"
    
    Sync->>FS: "fs.rmSync(moveDir, { recursive: true, force: true })"
    
    loop "for each packageDir in PACKAGE_DIRS"
        Sync->>Move: "copyMovePackage(packageDir, null, moveDir)"
        Sync->>Move: "readMovePackageName(packageDir)"
        Move-->>Sync: "packageName"
        Sync->>Sync: "check contractConfig = chain.contracts[packageName]"
        
        alt "contractConfig exists"
            alt "packageId exists and not upgraded"
                Sync->>Move: "updateMoveToml(packageDir, packageId, moveDir)"
                Sync->>Sync: "printInfo('Synced packageName with package ID', packageId)"
            else "contract is upgraded"
                Sync->>Sync: "printInfo('Skipping for upgraded contract', packageName)"
            end
        else "contractConfig not found"
            Sync->>Sync: "printError('Package not found in config')"
        end
    end
    
    Sync-->>Main: "sync complete"
    Main->>Config: "saveConfig(config, options.env)"
    Main-->>CLI: "operation complete"
    CLI-->>User: "sync operation finished"
Loading

ASANA

@blockchainguyy blockchainguyy marked this pull request as ready for review August 22, 2025 11:11
@blockchainguyy blockchainguyy requested a review from a team as a code owner August 22, 2025 11:11
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.

1 file reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

@blockchainguyy blockchainguyy marked this pull request as draft August 22, 2025 11:25
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.

1 participant