Skip to content

Conversation

@elrakabawi
Copy link
Collaborator

Swap and Flashloan Fees Not Accumulated

  • Severity: Medium
  • Target: Smart Contract
  • Category: Logic Error
  • Status: Pending

Description

During swaps, the total_fee and the futarchy_fee are calculated as follows:

    let total_fee = (amount_in as u128)
        .checked_mul(pair.swap_fee_bps as u128)
        .ok_or(ErrorCode::FeeMathOverflow)?
        .checked_div(BPS_DENOMINATOR as u128)
        .ok_or(ErrorCode::FeeMathOverflow)? as u64;

    // Calculate futarchy fee portion of the total fee
    let futarchy_fee = (total_fee as u128)
        .checked_mul(futarchy_authority.revenue_share.swap_bps as u128)
        .ok_or(ErrorCode::FeeMathOverflow)?
        .checked_div(BPS_DENOMINATOR as u128)
        .ok_or(ErrorCode::FeeMathOverflow)? as u64;

However, the remaining portion of the fee (total_fee - futarchy_fee) is ignored, it is neither transferred out nor recorded in internal accounting.

A similar issue exists in the flashloan logic:

      let fee0 = (amount0 as u128)
          .checked_mul(FLASHLOAN_FEE_BPS as u128)
          .unwrap()
          .checked_div(BPS_DENOMINATOR as u128)
          .unwrap() as u64;
      
      let fee1 = (amount1 as u128)
          .checked_mul(FLASHLOAN_FEE_BPS as u128)
          .unwrap()
          .checked_div(BPS_DENOMINATOR as u128)
          .unwrap() as u64;

These fees are not accumulated into the pool reserves or protocol revenue.

Impact

The protocol and liquidity providers may earn less revenue than expected because a portion of the fees is never credited.

Recommendation

Add the logic to accumulate the fees.

Fix

  • Added swap LP fee to reserves
  • Added flashloan LP fee to reserves

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.

3 participants