Skip to content

Latest commit

 

History

History
124 lines (99 loc) · 4.17 KB

File metadata and controls

124 lines (99 loc) · 4.17 KB

PR Summary: Implement Proposal Execution in Governance Contract

Issue

#603 Contract: Implement proposal execution in governance contract

Problem

  • ProposalExecutedEvent exists but execute_proposal function was incomplete
  • Proposals could not be executed
  • Governance system was incomplete
  • Decision implementation was missing

Impact

  • Proposals cannot be executed
  • Governance system is non-functional

Solution

Implemented complete proposal execution functionality by:

  1. Extended Proposal Structure - Added action payload fields to store what should be executed

    • target: Address - Target contract to invoke
    • function: Symbol - Function to call on target
    • args: Vec<soroban_sdk::Val> - Arguments to pass
  2. Updated create_proposal - Now accepts action parameters

    • Signature: create_proposal(env, proposer, title, description, target, function, args)
    • Stores the complete action payload with the proposal
  3. Implemented execute_proposal - Now actually executes the proposal

    • Validates proposal has passed voting
    • Invokes target contract with stored function and arguments
    • Updates proposal status to Executed
    • Emits ProposalExecutedEvent
  4. Updated Helper Functions - Adapted propose_update_* functions

    • propose_update_interest_rate
    • propose_update_collateral_ratio
    • propose_update_liquidation_bonus
  5. Updated Tests - Modified test helpers to work with new structure

    • Updated make_proposal helper to include action parameters

Branch

  • Branch Name: feat/603-proposal-execution
  • Base: master

Commits

  1. 10c93f7 - Enhanced proposal execution with comprehensive documentation and safety checks
  2. 5c705af - Implemented complete proposal execution in governance contract

Key Changes

File: contracts/governance-contract/src/lib.rs

Proposal Struct (Lines 60-73)

pub struct Proposal {
    pub id: u32,
    pub title: String,
    pub description: String,
    pub proposer: Address,
    pub yes_votes: i128,
    pub no_votes: i128,
    pub abstain_votes: i128,
    pub status: ProposalStatus,
    pub created_at: u64,
    pub expires_at: u64,
    pub target: Address,           // NEW
    pub function: Symbol,          // NEW
    pub args: Vec<soroban_sdk::Val>, // NEW
}

create_proposal Function

  • Now accepts target, function, and args parameters
  • Stores action payload with proposal
  • Enables proposals to carry their intended execution details

execute_proposal Function

  • Validates proposal has passed voting
  • Invokes target contract: env.invoke_contract(&proposal.target, &proposal.function, proposal.args)
  • Updates status to Executed
  • Emits ProposalExecutedEvent
  • Includes reentrancy protection and pause checks

File: contracts/governance-contract/src/test.rs

make_proposal Helper

  • Updated to include action parameters
  • Now passes target contract, function, and empty args

Testing

  • Existing proposal tests updated to work with new structure
  • test_execute_proposal_after_voting_period - Verifies successful execution
  • test_execute_rejected_proposal_fails - Verifies rejected proposals cannot execute

Breaking Changes

⚠️ BREAKING: The Proposal struct now includes action payload fields. Any code creating proposals must be updated to provide:

  • target: Address - The contract to execute
  • function: Symbol - The function to call
  • args: Vec<soroban_sdk::Val> - The arguments

Next Steps

  1. Review and approve PR
  2. Merge to master
  3. Update any dependent code that creates proposals
  4. Deploy updated governance contract

Verification

To verify the implementation:

# Build the contract
cd contracts/governance-contract
cargo build --target wasm32-unknown-unknown

# Run tests
cargo test

Files Modified

  • contracts/governance-contract/src/lib.rs - Core implementation
  • contracts/governance-contract/src/test.rs - Test updates

Summary

The proposal execution functionality is now complete and functional. Proposals can be created with an intended action, voted on, and then executed to perform their intended function on target contracts. This completes the governance system implementation.