Skip to content

feat: support dynamic fee tiers based on volume (#317)#376

Open
milah-247 wants to merge 1 commit intoWeb3Novalabs:mainfrom
milah-247:feat/dynamic-fee-tiers-317
Open

feat: support dynamic fee tiers based on volume (#317)#376
milah-247 wants to merge 1 commit intoWeb3Novalabs:mainfrom
milah-247:feat/dynamic-fee-tiers-317

Conversation

@milah-247
Copy link

Description

Implements a dynamic fee tier system where the protocol fee percentage decreases as the total pool stake increases. This encourages participation in larger markets by rewarding high-volume pools with lower fees.

Related Issue

Fixes #317
Depends on #304

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Changes Made

  • Added new contract function(s)
  • Modified existing function(s)
  • Added/updated tests
  • Updated documentation

Testing

  • All existing tests pass
  • Added tests for new functionality
  • Tested on local environment
  • Manual testing completed

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Screenshots (if applicable)

N/A

Additional Notes

Files Modified:

File Change
contracts/predifi-contract/src/lib.rs Added FeeTier struct, DataKey::FeeTiers, set_fee_tiers(), get_fee_tiers(), calculate_dynamic_fee_bps(), updated claim_winnings()
contracts/predifi-contract/src/integration_test.rs Fixed pre-existing test failure by whitelisting token in setup_integration()
contracts/predifi-contract/src/test.rs Fixed pre-existing test: added missing category argument to create_pool() call

New Data Structures:

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct FeeTier {
    pub min_stake: i128, // Minimum total stake to qualify for this tier
    pub fee_bps: u32,    // Fee in basis points (e.g. 50 = 0.5%)
}

New Admin Functions:

Function Description
set_fee_tiers(env, admin, tiers) Sets the fee tier schedule. Admin only. Tiers must be sorted by min_stake ascending
get_fee_tiers(env) Returns the current fee tier schedule

Example Fee Tier Configuration:

// Tier 1: Default fee for small pools
FeeTier { min_stake: 0,         fee_bps: 200 } // 2.0%
// Tier 2: Reduced fee for mid-size pools
FeeTier { min_stake: 500_000,   fee_bps: 100 } // 1.0%
// Tier 3: Lowest fee for large pools
FeeTier { min_stake: 1_000_000, fee_bps: 50  } // 0.5%

New Events:

Event Trigger
FeeTierUpdateEvent Emitted when admin updates fee tiers
FeeTierAppliedEvent Emitted on each claim, records which fee tier was applied

Fee Calculation Logic (claim_winnings):

  • calculate_dynamic_fee_bps() iterates tiers in ascending order and returns the fee for the highest qualifying tier
  • Falls back to config.fee_bps if no tiers are configured, maintaining full backward compatibility
  • Fee deducted from gross winnings; net amount transferred to user; fee amount transferred to treasury

Test Results:

test result: ok. 60 passed; 0 failed
test result: ok. 11 passed; 0 failed
Total: 71 tests passed, 0 failed

@vercel
Copy link

vercel bot commented Feb 24, 2026

@milah-247 is attempting to deploy a commit to the shola's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Yunusabdul38
Copy link
Collaborator

@milah-247 relove conflict and ci

@Yunusabdul38
Copy link
Collaborator

@milah-247 any update on this

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.

Support Dynamic Fee Tiers Based on Volume

2 participants