Problem
None of the 5 contracts (creditline, liquidity-pool, reputation, vendor-registry, token-mock) currently expose an upgrade() entry point. Once deployed to testnet, any bug fix requires a full redeploy and address change — breaking every client that references the old address.
Context
Soroban supports in-place WASM upgrades preserving contract address and storage. Without this, every contract bugfix invalidates the API's contract IDs and the mobile app's hardcoded references. Upgradeability is the difference between a one-shot deploy and a maintainable protocol.
Before Starting
Read these context files first:
- context/architecture-context.md
- context/code-standards.md
- context/progress-tracker.md
- contracts/*/src/lib.rs
What To Build
- Define a shared snippet (in each contract's
lib.rs):
pub fn upgrade(env: Env, new_wasm_hash: BytesN<32>) -> Result<(), ContractError> {
let admin: Address = env.storage().instance().get(&StorageKey::Admin).ok_or(ContractError::NotInitialized)?;
admin.require_auth();
env.deployer().update_current_contract_wasm(new_wasm_hash);
Ok(())
}
- Add to all 5 contracts: creditline, liquidity-pool, reputation, vendor-registry, token-mock.
- Emit a
CONTRACTUPGRADED event with (old_version, new_version, ts) — add a get_version() -> u32 function returning current version, bumped by upgrade.
- Persist
StorageKey::Version in each contract's instance storage, default 1.
- Write one unit test per contract: non-admin call rejected, admin call succeeds (mock the wasm hash).
- Document the upgrade flow in
contracts/README.md.
Files To Touch
contracts/creditline-contract/src/lib.rs
contracts/liquidity-pool-contract/src/lib.rs
contracts/reputation-contract/src/lib.rs
contracts/vendor-registry-contract/src/lib.rs
contracts/token-mock-contract/src/lib.rs
- Each contract's
events.rs, storage.rs, errors.rs
contracts/README.md
Acceptance Criteria
Mandatory Checks Before PR
Problem
None of the 5 contracts (creditline, liquidity-pool, reputation, vendor-registry, token-mock) currently expose an
upgrade()entry point. Once deployed to testnet, any bug fix requires a full redeploy and address change — breaking every client that references the old address.Context
Soroban supports in-place WASM upgrades preserving contract address and storage. Without this, every contract bugfix invalidates the API's contract IDs and the mobile app's hardcoded references. Upgradeability is the difference between a one-shot deploy and a maintainable protocol.
Before Starting
Read these context files first:
What To Build
lib.rs):CONTRACTUPGRADEDevent with(old_version, new_version, ts)— add aget_version() -> u32function returning current version, bumped by upgrade.StorageKey::Versionin each contract's instance storage, default 1.contracts/README.md.Files To Touch
contracts/creditline-contract/src/lib.rscontracts/liquidity-pool-contract/src/lib.rscontracts/reputation-contract/src/lib.rscontracts/vendor-registry-contract/src/lib.rscontracts/token-mock-contract/src/lib.rsevents.rs,storage.rs,errors.rscontracts/README.mdAcceptance Criteria
upgrade(env, new_wasm_hash)get_version()returning au32upgrade()CONTRACTUPGRADEDevent emitted on successful upgradeMandatory Checks Before PR