Skip to content

Distribute Rewards - #29

Merged
Kaylahray merged 3 commits into
learnault:mainfrom
Birdmannn:feat-#22
Mar 8, 2026
Merged

Distribute Rewards#29
Kaylahray merged 3 commits into
learnault:mainfrom
Birdmannn:feat-#22

Conversation

@Birdmannn

Copy link
Copy Markdown
Contributor

Reward Pool Implementation Summary

What Was Done

1. Add Approved Spender Function

Implemented add_approved_spender function in the reward-pool contract to whitelist contract addresses that can distribute rewards.

Key Features:

  • Admin-only access control
  • Validates admin authentication
  • Stores spender addresses in persistent storage
  • Emits SpenderAdded event

Files Modified:

  • contracts/reward-pool/src/lib.rs - Added function implementation
  • contracts/reward-pool/src/types.rs - Added Spender(Address) to DataKey enum
  • contracts/reward-pool/src/test.rs - Added 5 comprehensive tests

2. Fixed Distribute Reward Function

Corrected the order of validation checks in distribute_reward to ensure proper error messages.

Fix Applied:

  • Moved initialization check before spender authorization check
  • Now panics with "Not initialized" when contract isn't initialized (instead of "Caller is not an authorized spender")

3. Fixed Test Issues

  • Corrected StellarAssetClient initialization to use .address() method
  • Fixed event assertion patterns for Soroban event structure
  • All 16 tests now pass

4. Project Configuration

  • Added .vscode/ to .gitignore
  • Fixed workspace configuration to exclude contracts/target directory
  • Explicitly listed workspace members to avoid rust-analyzer errors

5. CI Validation

  • ✅ Formatting check passes (cargo fmt)
  • ✅ Linting passes (cargo clippy)
  • ✅ All tests pass (cargo test)

Test Coverage

add_approved_spender tests:

  • Success case with event verification
  • Not initialized error
  • Unauthorized admin error
  • Multiple spenders
  • Duplicate spender handling

distribute_reward tests:

  • Success case with token transfer
  • Zero/negative amount validation
  • Unauthorized spender rejection
  • Not initialized error
  • Multiple distributions
  • Multiple spenders

This PR closes #22

@Kaylahray Kaylahray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arigato Sensei 🙋‍♀️🔥🔥

@Kaylahray
Kaylahray merged commit 462e365 into learnault:main Mar 8, 2026
1 check 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.

[RewardPool] Distribute Reward (Cross-Contract)

2 participants