Skip to content

feat: Treasury Storage, Fee Collection & Allocation Logic#325

Merged
Olowodarey merged 1 commit intoDevsol-01:mainfrom
Folex1275:feat/treasury
Mar 24, 2026
Merged

feat: Treasury Storage, Fee Collection & Allocation Logic#325
Olowodarey merged 1 commit intoDevsol-01:mainfrom
Folex1275:feat/treasury

Conversation

@Folex1275
Copy link
Copy Markdown
Contributor

feat: Treasury Storage, Fee Collection & Allocation Logic

Closes #321, Closes #322, Closes #323


Description

This PR implements the core treasury infrastructure for the Nestera savings protocol, covering three interconnected features:

  1. Treasury Storage Structure ([contract] Treasury Storage Structure #321): Defines a persistent on-chain Treasury struct to track protocol funds, including total_fees_collected, total_yield_earned, reserve_balance, treasury_balance, rewards_balance, and operations_balance. The treasury is initialized with zero values during initialize_config.

  2. Fee Collection Mechanism ([contract] Fee Collection Mechanism #322): Replaces the single protocol_fee_bps / PlatformFee configuration with three independently configurable fees:

    • deposit_fee_bps — deducted on deposits (flexi, goal)
    • withdrawal_fee_bps — deducted on withdrawals (flexi, goal)
    • performance_fee_bps — deducted on strategy yield harvest

    Each fee collection point now emits a FeeCollected event and records the fee into the Treasury struct via treasury::record_fee().

  3. Treasury Allocation Logic ([contract] Treasury Allocation Logic #323): Implements allocate_treasury() which splits the unallocated treasury_balance into three buckets:

    • reserve_balance
    • rewards_balance
    • operations_balance

    Allocation percentages are provided in basis points and must sum to exactly 10,000 (100%). Invalid configs are rejected. Operations receives the remainder to avoid rounding dust.


Files Changed

New Files

File Description
contracts/src/treasury/mod.rs Treasury module: get_treasury, initialize_treasury, record_fee, record_yield, allocate_treasury
contracts/src/treasury/types.rs Treasury struct, AllocationConfig struct

Modified Files

File Description
contracts/src/storage_types.rs Renamed DataKey::TreasuryDataKey::TreasuryAddress; added DataKey::Treasury (struct), DataKey::AllocationConfig, DataKey::DepositFeeBps, DataKey::WithdrawalFeeBps, DataKey::PerformanceFeeBps; removed DataKey::PlatformFee
contracts/src/config.rs Config struct now has deposit_fee_bps, withdrawal_fee_bps, performance_fee_bps; initialize_config accepts 3 fee params and calls initialize_treasury; set_fees replaces set_protocol_fee
contracts/src/lib.rs Exposed get_treasury, allocate_treasury, set_fees; removed set_protocol_fee, set_protocol_fee_bps, get_protocol_fee_bps
contracts/src/flexi.rs Uses DepositFeeBps / WithdrawalFeeBps; calls treasury::record_fee
contracts/src/goal.rs Uses DepositFeeBps / WithdrawalFeeBps; calls treasury::record_fee
contracts/src/strategy/routing.rs Uses performance_fee_bps from Config; calls treasury::record_fee and treasury::record_yield
contracts/src/config_tests.rs Updated for new fee signature
contracts/tests/strategy_integration_test.rs Updated for new initialize_config signature
.gitignore Added contracts/test_snapshots/

Acceptance Criteria

  • Treasury struct stored on-chain with correct fields
  • Treasury values initialized to zero during initialize_config
  • Configurable deposit_fee, withdrawal_fee, performance_fee
  • Fees deducted correctly during deposit, withdrawal, and harvest
  • Treasury balances updated accurately via record_fee
  • FeeCollected event emitted on every fee collection
  • allocate_treasury() splits funds into reserves, rewards, and operations
  • Allocation percentages must sum to exactly 100% (10,000 bps)
  • Invalid allocation configs rejected
  • Edge cases handled (small balances, zero fees, rounding)
  • All 263 tests pass
  • Contract builds successfully

Testing

cargo test
# test result: ok. 263 passed; 0 failed; 0 ignored

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nestera Error Error Mar 24, 2026 8:21am

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@Folex1275 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Olowodarey Olowodarey merged commit d883b69 into Devsol-01:main Mar 24, 2026
2 of 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.

[contract] Treasury Allocation Logic [contract] Fee Collection Mechanism [contract] Treasury Storage Structure

2 participants