Skip to content

Commit

Permalink
program: update high level mode fees (#1317)
Browse files Browse the repository at this point in the history
* program: update high lev mode fee to be lower

* add sdk
  • Loading branch information
crispheaney authored Nov 11, 2024
1 parent aaa86c8 commit 546f63f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
21 changes: 9 additions & 12 deletions programs/drift/src/math/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions programs/drift/src/math/fees/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 546f63f

Please sign in to comment.