Skip to content

Implement-Decentralized-Payout-Trigger - #33

Merged
Queenode merged 3 commits into
Kolo-Org:mainfrom
Securify001:Implement-Decentralized-Payout-Trigger
Aug 22, 2026
Merged

Implement-Decentralized-Payout-Trigger#33
Queenode merged 3 commits into
Kolo-Org:mainfrom
Securify001:Implement-Decentralized-Payout-Trigger

Conversation

@Securify001

Copy link
Copy Markdown
Contributor

Summary

Changes Made

  1. Added CurrentCycleContributions Storage Key
    Added new DataKey::CurrentCycleContributions variant to track contributions per cycle efficiently without iterating over all members.
  2. State Management Optimization
    contribute(): Now initializes CurrentCycleContributions to 0 when a new cycle starts, and increments it by 1 on each contribution.
    reset_cycle(): Now resets CurrentCycleContributions to 0 when a cycle is reset.
  3. Implemented trigger_payout() Function
    Signature: pub fn trigger_payout(env: Env, caller: Address, recipient: Address)
    Access Control: Caller must be a member (requires authentication)
    Pool Fullness Check: Pool is considered full when CurrentCycleContributions == CycleMemberCount
    Recipient Validation: Recipient must be a member and must not have received a payout this cycle
    Payout Execution: Same logic as admin payout() function
    Event: Emits trg_pay event on successful payout
  4. Unit Tests Added
    test_trigger_payout_success: Member triggers payout when pool is full (succeeds)
    test_trigger_payout_pool_not_full: Member triggers payout when pool is NOT full (panics with "Pool is not full")
    test_trigger_payout_non_member: Non-member attempts to trigger payout (panics with "Caller is not a member")

Test Results

running 8 tests
test test::test_add_member ... ok
test test::test_events ... ok
test test::test_initialize ... ok
test test::test_double_initialize - should panic ... ok
test test::test_contribute_not_member - should panic ... ok
test test::test_trigger_payout_pool_not_full - should panic ... ok
test test::test_trigger_payout_non_member - should panic ... ok
test test::test_trigger_payout_success ... ok

test result: ok. 8 passed; 0 failed

Files Modified

lib.rs - Added CurrentCycleContributions storage key, modified contribute() and reset_cycle(), added trigger_payout() function
test.rs - Added 3 unit tests for trigger_payout

All acceptance criteria have been met:

✅ Reduce Admin Reliance - Members can now trigger payouts
✅ Pool Fullness Check - Efficient check using CurrentCycleContributions counter
✅ Member-Triggered Payout - trigger_payout() function implemented with proper validations
✅ State Management Optimization - Counter tracks contributions efficiently
✅ Testing - All 3 required unit tests passing

Closes #21

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8f6c9ef-bdc4-4b5e-8f63-4881e441387b


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Queenode

Copy link
Copy Markdown
Contributor

Thank you for your contribution @Securify001 .
All checks passed, please don't forget to give Kolo-org a star
Merging now

@Queenode
Queenode merged commit 6519710 into Kolo-Org:main Aug 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Implement Decentralized Payout Trigger (Member-Initiated)

2 participants