diff --git a/programs/drift/src/math/fees.rs b/programs/drift/src/math/fees.rs index d71724097..be955a9c1 100644 --- a/programs/drift/src/math/fees.rs +++ b/programs/drift/src/math/fees.rs @@ -95,13 +95,12 @@ pub fn calculate_fee_for_fulfillment_with_amm( referee_discount: 0, }) } else { - let taker_fee_adjustment = if user_high_leverage_mode { - FEE_ADJUSTMENT_MAX_I16 // high lev mode gets 2x fees - } else { - fee_adjustment - }; + let mut fee = calculate_taker_fee(quote_asset_amount, fee_tier, fee_adjustment)?; + + if user_high_leverage_mode { + fee = fee.safe_mul(2)?; + } - let fee = calculate_taker_fee(quote_asset_amount, fee_tier, taker_fee_adjustment)?; let (fee, referee_discount, referrer_reward) = if reward_referrer { calculate_referee_fee_and_referrer_reward( @@ -302,13 +301,11 @@ pub fn calculate_fee_for_fulfillment_with_match( determine_user_fee_tier(taker_stats, fee_structure, market_type, false)? }; - let taker_fee_adjustment = if user_high_leverage_mode { - FEE_ADJUSTMENT_MAX_I16 // high lev mode gets 2x fees - } else { - fee_adjustment - }; + let mut taker_fee = calculate_taker_fee(quote_asset_amount, taker_fee_tier, fee_adjustment)?; - let taker_fee = calculate_taker_fee(quote_asset_amount, taker_fee_tier, taker_fee_adjustment)?; + if user_high_leverage_mode { + taker_fee = taker_fee.safe_mul(2)?; + } let (taker_fee, referee_discount, referrer_reward) = if reward_referrer { calculate_referee_fee_and_referrer_reward( diff --git a/programs/drift/src/math/fees/tests.rs b/programs/drift/src/math/fees/tests.rs index 1fa565f8a..e07184575 100644 --- a/programs/drift/src/math/fees/tests.rs +++ b/programs/drift/src/math/fees/tests.rs @@ -376,9 +376,9 @@ mod calculate_fee_for_taker_and_maker { ) .unwrap(); - assert_eq!(taker_fee, 200000); + assert_eq!(taker_fee, 100000); assert_eq!(maker_rebate, 30000); - assert_eq!(fee_to_market, 160000); + assert_eq!(fee_to_market, 60000); assert_eq!(filler_reward, 10000); assert_eq!(referrer_reward, 0); assert_eq!(referee_discount, 0); @@ -584,8 +584,8 @@ mod calculate_fee_for_order_fulfill_against_amm { ) .unwrap(); - assert_eq!(user_fee, 200000); - assert_eq!(fee_to_market, 200000); + assert_eq!(user_fee, 100000); + assert_eq!(fee_to_market, 100000); assert_eq!(filler_reward, 0); assert_eq!(referrer_reward, 0); assert_eq!(referee_discount, 0); diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 348285410..8b4ce35cd 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -8053,14 +8053,10 @@ export class DriftClient { marketAccount = this.getSpotMarketAccount(marketIndex); } - let takeFeeAdjustment; + takerFee += (takerFee * marketAccount.feeAdjustment) / 100; if (user && user.isHighLeverageMode()) { - takeFeeAdjustment = 100; - } else { - takeFeeAdjustment = marketAccount.feeAdjustment; + takerFee *= 2; } - - takerFee += (takerFee * takeFeeAdjustment) / 100; makerFee += (makerFee * marketAccount.feeAdjustment) / 100; }