Skip to content

feat(contracts): add contract upgradeability - #106

Merged
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
Itodo-S:feat/contract-upgradeability
Mar 24, 2026
Merged

feat(contracts): add contract upgradeability#106
Smartdevs17 merged 1 commit into
Smartdevs17:mainfrom
Itodo-S:feat/contract-upgradeability

Conversation

@Itodo-S

@Itodo-S Itodo-S commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implement contract upgradeability using Soroban's built-in update_current_contract_wasm mechanism
  • Admin-only upgrade(admin, new_wasm_hash) function replaces bytecode while preserving all persistent and instance storage
  • Add version() query (returns 1) for tracking contract versions across upgrades

Changes

contracts/src/lib.rs:

  • Import BytesN for WASM hash parameter
  • Add upgrade() — validates admin auth, calls env.deployer().update_current_contract_wasm()
  • Add version() — returns current contract version constant
  • Add tests: test_version_returns_current and test_upgrade_rejects_non_admin

Upgrade flow

# 1. Build new contract version
cargo build --target wasm32-unknown-unknown --release

# 2. Install the new WASM on-chain
soroban contract install --wasm target/wasm32-unknown-unknown/release/agenticpay.wasm --network testnet

# 3. Call upgrade with the returned hash
soroban contract invoke --id $CONTRACT_ID --network testnet -- upgrade --admin $ADMIN_ADDRESS --new_wasm_hash $WASM_HASH

Test plan

  • test_version_returns_current — version() returns 1
  • test_upgrade_rejects_non_admin — non-admin upgrade panics with "Only admin can upgrade"

Closes #42

@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown

@Itodo-S is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Mar 24, 2026

Copy link
Copy Markdown

@Itodo-S Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17

Copy link
Copy Markdown
Owner

fix merge confllicts

Implement Soroban's built-in upgrade mechanism that replaces contract
bytecode while preserving all storage (persistent + instance).

Changes:
- Add `upgrade(admin, new_wasm_hash)` function, admin-only, uses
  `env.deployer().update_current_contract_wasm()`
- Add `version()` query returning current contract version (1) for
  tracking upgrades across deployments
- Add tests: version query and non-admin upgrade rejection

Closes Smartdevs17#42
@Itodo-S
Itodo-S force-pushed the feat/contract-upgradeability branch from 2dfc690 to 123f3b2 Compare March 24, 2026 13:43
@Smartdevs17
Smartdevs17 merged commit 77695bb into Smartdevs17:main Mar 24, 2026
3 of 7 checks passed
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.

Smart Contract: Add contract upgradeability

2 participants