Skip to content

Commit

Permalink
Merge pull request #2441 from get10101/fix/fee-rebate-calculation
Browse files Browse the repository at this point in the history
fix(ui): Calculate fee rebate from full order matching fee
  • Loading branch information
holzeis authored Apr 18, 2024
2 parents 1f88581 + 34db224 commit 2fe6fde
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ class TradeBottomSheetConfirmation extends StatelessWidget {

final orderMatchingFee = tradeValues.fee ?? Amount.zero();
final feeRebate = referralStatus != null
? Amount((referralStatus.referralFeeBonus * orderMatchingFee.sats).ceil())
? Amount((referralStatus.referralFeeBonus * orderMatchingFee.sats).floor())
: Amount.zero();
final feeBeforeRebate = orderMatchingFee + feeRebate;

return Container(
padding: EdgeInsets.only(left: 20, right: 20, top: (isClose ? 20 : 10), bottom: 10),
Expand Down Expand Up @@ -224,7 +223,7 @@ class TradeBottomSheetConfirmation extends StatelessWidget {
),
ValueDataRow(
type: ValueType.amount,
value: feeBeforeRebate,
value: orderMatchingFee,
label: "Order-matching fee",
),
if (referralStatus != null && referralStatus.referralFeeBonus > 0)
Expand Down
9 changes: 2 additions & 7 deletions mobile/lib/features/trade/trade_bottom_sheet_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,8 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
selector: (_, provider) =>
provider.orderMatchingFee(direction) ?? Amount.zero(),
builder: (context, fee, child) {
final feeRebate = referralStatus != null
? Amount((referralStatus.referralFeeBonus * fee.sats).ceil())
: Amount.zero();
final feeBeforeRebate = fee + feeRebate;
return Flexible(
child: ValueDataRow(
type: ValueType.amount, value: feeBeforeRebate, label: "Fee:"));
child: ValueDataRow(type: ValueType.amount, value: fee, label: "Fee:"));
}),
],
),
Expand All @@ -344,7 +339,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
provider.orderMatchingFee(direction) ?? Amount.zero(),
builder: (context, fee, child) {
return Text(
"-${Amount((referralStatus.referralFeeBonus * fee.sats).ceil())}",
"-${Amount((referralStatus.referralFeeBonus * fee.sats).floor())}",
style: const TextStyle(color: Colors.green),
);
}),
Expand Down
2 changes: 1 addition & 1 deletion mobile/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub fn calculate_pnl(
pub fn order_matching_fee(quantity: f32, price: f32) -> SyncReturn<u64> {
let price = Decimal::from_f32(price).expect("price to fit in Decimal");

let fee_rate = ln_dlc::get_order_matching_fee_rate();
let fee_rate = ln_dlc::get_order_matching_fee_rate(false);
let order_matching_fee = commons::order_matching_fee(quantity, price, fee_rate).to_sat();

SyncReturn(order_matching_fee)
Expand Down
10 changes: 7 additions & 3 deletions mobile/native/src/ln_dlc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,17 @@ pub fn get_maintenance_margin_rate() -> Decimal {
}
}

pub fn get_order_matching_fee_rate() -> Decimal {
pub fn get_order_matching_fee_rate(deduct_rebate: bool) -> Decimal {
match state::try_get_tentenone_config() {
Some(config) => {
let fee_percent =
Decimal::try_from(config.order_matching_fee_rate).expect("to fit into decimal");
let fee_discount = config.referral_status.referral_fee_bonus;
fee_percent - (fee_percent * fee_discount)
if deduct_rebate {
let fee_discount = config.referral_status.referral_fee_bonus;
fee_percent - (fee_percent * fee_discount)
} else {
fee_percent
}
}
None => dec!(0.003),
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl From<(native::trade::position::Position, Option<Price>)> for Position {
};

// FIXME: A from implementation should not contain this kind of logic.
let fee_rate = ln_dlc::get_order_matching_fee_rate();
let fee_rate = ln_dlc::get_order_matching_fee_rate(true);

(
calculate_pnl(
Expand Down Expand Up @@ -682,7 +682,7 @@ pub async fn get_best_quote(
bid: bid_price,
ask: ask_price,
},
fee: ln_dlc::get_order_matching_fee_rate(),
fee: ln_dlc::get_order_matching_fee_rate(true),
};

Ok(Json(Some(quotes)))
Expand Down

0 comments on commit 2fe6fde

Please sign in to comment.