A simple CosmWasm contract that enables governance-controlled contract migrations on Secret Network.
- Deploy GovernanceProxy Contract: A simple contract that can execute migration messages
- Set Admin: Set the GovernanceProxy contract as admin of the target contract
- Enable Governance: Set
require_governance = true
on the target contract - Migration Flow:
- Governance proposal authorizes migration
- Anyone can call GovernanceProxy contract to execute the migration
- GovernanceProxy contract calls the migration message
MigrateContract {
contract_addr: String, // Address of contract to migrate
new_code_id: u64, // New code ID to migrate to
migrate_msg: Binary, // Migration message for target contract
code_hash: String, // Code hash of new contract code
}
# 1. Deploy proxy
secretcli tx compute instantiate <code-id> '{}' --from <key> --label "governance-proxy"
# 2. Set proxy as admin of target contract
secretcli tx compute set-admin <target-contract> <proxy-contract> --from <current-admin>
# 3. Execute migration via proxy
secretcli tx compute execute <proxy-contract> '{
"migrate_contract": {
"contract_addr": "<target-contract>",
"new_code_id": 123,
"migrate_msg": "eyJ1cGdyYWRlIjp7fX0=",
"code_hash": "<hash>"
}
}' --from <key>
Create a governance proposal that calls the proxy contract:
{
"messages": [{
"@type": "/secret.compute.v1beta1.MsgExecuteContract",
"sender": "<governance-module-address>",
"contract": "<proxy-contract-address>",
"msg": {
"migrate_contract": {
"contract_addr": "<target-contract>",
"new_code_id": 456,
"migrate_msg": "eyJ1cGdyYWRlIjp7fX0=",
"code_hash": "<hash>"
}
}
}],
"title": "Migrate Contract to v2.0",
"summary": "Upgrade contract to latest version"
}
- Decentralized Control: Migrations controlled by governance
- Trustless Execution: Anyone can execute approved migrations
- Audit Trail: All migrations recorded on-chain
- Simple Pattern: Minimal contract with clear responsibility
# Compile optimized and reproducible build
make compile-optimized-reproducible