Skip to content

scrtlabs/proxy-governance-contract

Repository files navigation

Governance Proxy Contract

A simple CosmWasm contract that enables governance-controlled contract migrations on Secret Network.

The GovernanceProxy Contract Pattern

  1. Deploy GovernanceProxy Contract: A simple contract that can execute migration messages
  2. Set Admin: Set the GovernanceProxy contract as admin of the target contract
  3. Enable Governance: Set require_governance = true on the target contract
  4. Migration Flow:
    1. Governance proposal authorizes migration
    2. Anyone can call GovernanceProxy contract to execute the migration
    3. GovernanceProxy contract calls the migration message

Execute 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
}

Quick Setup

# 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>

Governance Integration

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"
}

Key Benefits

  • 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

Building

# Compile optimized and reproducible build
make compile-optimized-reproducible

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published