#603 Contract: Implement proposal execution in governance contract
- Problem: ProposalExecutedEvent exists but execute_proposal function was incomplete
- Impact: Proposals cannot be executed, governance system is incomplete
- Decision: Implementation missing
The execute_proposal function existed but was non-functional:
- It only updated the proposal status to
Executed - It did NOT actually execute the proposal's intended action
- The
Proposalstruct had no fields to store what action should be executed - No contract invocation was happening
Added three new fields to store the action payload:
pub struct Proposal {
// ... existing fields ...
pub target: Address, // Target contract to invoke
pub function: Symbol, // Function to call
pub args: Vec<soroban_sdk::Val>, // Arguments to pass
}Now accepts and stores the action parameters:
pub fn create_proposal(
env: Env,
proposer: Address,
title: String,
description: String,
target: Address, // NEW
function: Symbol, // NEW
args: Vec<soroban_sdk::Val>, // NEW
) -> Result<u32, GovernanceError>The execute_proposal function now:
- ✅ Validates executor authorization
- ✅ Checks for reentrancy attacks
- ✅ Verifies contract is not paused
- ✅ Evaluates proposal status (must be Passed)
- ✅ Retrieves proposal from storage
- ✅ Prevents double execution
- ✅ INVOKES TARGET CONTRACT with stored function and arguments
- ✅ Updates proposal status to Executed
- ✅ Emits ProposalExecutedEvent
- ✅ Properly exits reentrancy guard
Key execution line:
env.invoke_contract::<soroban_sdk::Val>(
&proposal.target,
&proposal.function,
proposal.args.clone(),
);Modified proposal creation helpers to use new structure:
propose_update_interest_ratepropose_update_collateral_ratiopropose_update_liquidation_bonus
Modified test helpers to work with new proposal structure:
make_proposalhelper now includes action parameters
- Branch:
feat/603-proposal-execution - Base:
master - Status: Ready for PR
-
10c93f7 - Enhanced proposal execution with comprehensive documentation and safety checks
- Added detailed documentation
- Added explicit double-execution prevention
- Ensured reentrancy guard released on all error paths
-
5c705af - Implemented complete proposal execution in governance contract
- Extended Proposal struct with action payload fields
- Updated create_proposal to accept action parameters
- Implemented actual contract invocation in execute_proposal
- Updated helper functions and tests
contracts/governance-contract/src/lib.rs(37 insertions)contracts/governance-contract/src/test.rs(3 insertions)
Proposal struct now requires action payload fields when creating proposals.
Migration Required:
// OLD (no longer works)
create_proposal(env, proposer, title, description)
// NEW (required)
create_proposal(env, proposer, title, description, target, function, args)- ✅ Proposal struct extended with action fields
- ✅ create_proposal accepts action parameters
- ✅ execute_proposal invokes target contract
- ✅ Reentrancy protection in place
- ✅ Double-execution prevention implemented
- ✅ ProposalExecutedEvent emitted correctly
- ✅ Tests updated for new structure
- ✅ Helper functions updated
- ✅ Commits created with descriptive messages
- ✅ Branch pushed to remote
let proposal_id = client.create_proposal(
&proposer,
&String::from_str(env, "Update Interest Rate"),
&String::from_str(env, "Proposal to update interest rate"),
&contract_address, // Target contract
&Symbol::new(env, "update_interest_rate"), // Function to call
&args, // Arguments
)?;client.vote(&voter, &proposal_id, &VoteChoice::Yes)?;// After voting period ends and proposal passes
client.execute_proposal(&executor, &proposal_id)?;
// This now:
// 1. Validates proposal passed
// 2. Invokes the target contract with stored function and args
// 3. Updates status to Executed
// 4. Emits ProposalExecutedEventThe governance contract now has a fully functional proposal execution system:
- ✅ Create proposals with intended actions
- ✅ Vote on proposals
- ✅ Evaluate voting results
- ✅ Execute passed proposals on target contracts
- ✅ Track execution status and events
- Create pull request on GitHub
- Request code review
- Merge to master after approval
- Update dependent code that creates proposals
- Deploy updated governance contract
- See
PROPOSAL_EXECUTION_PR_SUMMARY.mdfor detailed PR information - See commit messages for implementation details
- See contract code for complete implementation
Issue Resolution: #603 ✅ RESOLVED Implementation Status: COMPLETE Ready for Review: YES