Skip to content

Commit

Permalink
Reduce fees on mm deals (#66)
Browse files Browse the repository at this point in the history
* Reduce fees on mm deals

* lint

* update fees

* lint
  • Loading branch information
brittcyr authored Apr 16, 2024
1 parent 4d7bb89 commit 57bb472
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
36 changes: 27 additions & 9 deletions programs/staking-options/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anchor_lang::prelude::*;
use std::cmp;

pub const SO_CONFIG_SEED: &[u8] = b"so-config";
pub const SO_VAULT_SEED: &[u8] = b"so-vault";
Expand Down Expand Up @@ -89,7 +90,7 @@ pub fn is_fee_exempt(user_quote_account_owner: Pubkey) -> bool {
return false;
}

pub fn get_fee_bps(base_mint: Pubkey, quote_mint: Pubkey) -> u64 {
pub fn get_fee_bps(base_mint: Pubkey, quote_mint: Pubkey, name: String) -> u64 {
let is_base_stable = [
USDC.to_string(),
USDT.to_string(),
Expand All @@ -107,10 +108,11 @@ pub fn get_fee_bps(base_mint: Pubkey, quote_mint: Pubkey) -> u64 {
]
.contains(&quote_mint.to_string());

// Reduced fee on stables
if is_base_stable && is_quote_stable {
return 5;
}
// Hack for MM deals. Name is a user generated field, but if another user
// were to abuse that, we will address later in future versions.
let is_mm_deal = name.to_lowercase().contains("mm") || name.to_lowercase().contains("loan");

let is_otc = name.to_lowercase().contains("otc");

let is_base_major = [
WBTCPO.to_string(),
Expand Down Expand Up @@ -138,18 +140,34 @@ pub fn get_fee_bps(base_mint: Pubkey, quote_mint: Pubkey) -> u64 {
let is_quote_partner =
[MNGO.to_string(), RAY.to_string(), NOS.to_string()].contains(&quote_mint.to_string());

let mut fee_bps = 350;

// Reduced fee on stables
if is_base_stable && is_quote_stable {
fee_bps = cmp::min(fee_bps, 5);
}

// Reduced fee on mm tokens
if is_mm_deal {
fee_bps = cmp::min(fee_bps, 25);
}

if is_otc {
fee_bps = cmp::min(fee_bps, 10);
}

// Charge reduced fees on pairs of majors.
if (is_base_major && is_quote_stable) || (is_quote_major && is_base_stable) {
return 25;
fee_bps = cmp::min(fee_bps, 10);
}
// Charge reduced fees to partners.
if (is_base_partner && is_quote_stable) || (is_quote_partner && is_base_stable) {
return 50;
fee_bps = cmp::min(fee_bps, 25);
}
// Charge lower fee on major/major pairs
if is_base_major && is_quote_major {
return 5;
fee_bps = cmp::min(fee_bps, 5);
}

return 350;
return fee_bps;
}
6 changes: 5 additions & 1 deletion programs/staking-options/src/instructions/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ pub fn withdraw_all(ctx: Context<WithdrawAll>) -> Result<()> {
let fee: u64 = if is_fee_exempt(ctx.accounts.quote_account.owner.key()) {
0
} else {
let fee_bps = get_fee_bps(ctx.accounts.state.base_mint, ctx.accounts.state.quote_mint);
let fee_bps = get_fee_bps(
ctx.accounts.state.base_mint,
ctx.accounts.state.quote_mint,
ctx.accounts.state.so_name.clone(),
);

total_quote_tokens
.checked_mul(fee_bps)
Expand Down

0 comments on commit 57bb472

Please sign in to comment.