Skip to content

Conversation

@alberto-crossmint
Copy link
Contributor

@alberto-crossmint alberto-crossmint commented Jul 13, 2025

Add smart wallet upgrade example script

Summary

This PR adds a new example script smart-wallet-upgrade.ts that demonstrates how to upgrade a deployed smart wallet contract to a new WASM version. The script follows the same patterns as the existing smart-wallet-deployment.ts example but focuses specifically on the upgrade workflow.

Key additions:

  • New smart-wallet-upgrade.ts script that takes a smart wallet contract ID as input
  • Calls the upgrade function from the SmartWalletUpgradeable trait using direct contract invocation
  • Upgrades to SW_WASM_HASH_TESTING as the target WASM version
  • Includes post-upgrade verification by testing wallet functionality
  • Added npm script npm run upgrade for convenient execution

Technical approach:

  • Uses (smartWalletClient as any).call("upgrade", ...) since the upgrade function isn't exposed in the TypeScript client interface
  • Follows the same authorization pattern as existing signer management functions
  • Requires Admin role for upgrade authorization (handled by ADMIN_SIGNER_KEYPAIR)

Review & Testing Checklist for Human

⚠️ HIGH PRIORITY - This script was not tested locally due to environment dependency issues:

  • Test end-to-end execution: Run npm run upgrade <CONTRACT_ID> with a real deployed smart wallet to verify it works
  • Verify upgrade function call: Confirm the direct contract call smartWalletClient.call("upgrade", Buffer.from(SW_WASM_HASH_TESTING, "hex")) uses the correct function signature
  • Check authorization flow: Ensure the Admin role authorization works properly for upgrade operations
  • Validate WASM hash: Confirm SW_WASM_HASH_TESTING is the appropriate target hash for upgrade testing
  • Test error scenarios: Try upgrading with invalid contract ID, non-admin signer, or invalid WASM hash to ensure proper error handling

Recommended test plan:

  1. Deploy a smart wallet using existing deployment script
  2. Run the upgrade script on that wallet
  3. Verify the wallet still functions correctly after upgrade
  4. Test with various error conditions

Diagram

%%{ init : { "theme" : "default" }}%%
graph TB
    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit  
        L3["Context/No Edit"]:::context
    end

    PackageJson["examples/package.json<br/>(add upgrade script)"]:::minor-edit
    UpgradeScript["examples/smart-wallet-upgrade.ts<br/>(new upgrade script)"]:::major-edit
    ConstsFile["examples/consts.ts<br/>(SW_WASM_HASH_TESTING)"]:::context
    UtilsFile["examples/utils.ts<br/>(printAuthEntries)"]:::context
    DeployScript["examples/smart-wallet-deployment.ts<br/>(reference patterns)"]:::context
    UpgradeableTrait["contracts/upgradeable/src/lib.rs<br/>(SmartWalletUpgradeable trait)"]:::context

    UpgradeScript -->|"imports constants"| ConstsFile
    UpgradeScript -->|"imports utilities"| UtilsFile
    UpgradeScript -->|"follows patterns from"| DeployScript
    UpgradeScript -->|"calls upgrade function from"| UpgradeableTrait
    PackageJson -->|"runs"| UpgradeScript

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB  
    classDef context fill:#FFFFFF
Loading

Notes

  • The upgrade function is implemented in the SmartWalletUpgradeable trait but not exposed in the TypeScript client, requiring direct contract invocation
  • This follows the same authorization patterns as the existing signer management examples
  • The script is designed to be run standalone with a contract ID argument, making it easy to test upgrades on existing wallets

Link to Devin run: https://app.devin.ai/sessions/e70d61b35273403d9f2b46be887d0cf1
Requested by: @alberto-crossmint

- Create focused upgrade script following smart-wallet-deployment.ts patterns
- Demonstrates wallet upgrade using SmartWalletUpgradeable trait
- Uses SW_WASM_HASH_TESTING for upgrade target
- Includes post-upgrade verification by testing wallet functionality
- Add npm script for running the upgrade example

Co-Authored-By: Alberto Garc\u00EDa <[email protected]>
@devin-ai-integration
Copy link
Contributor

Original prompt from Alberto:

In the same fashion as the existing example application, create one for upgrading the wallet

You only need to look in the following repo: Crossmint/stellar-smart-account

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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