Skip to content

Commit

Permalink
feat: pull through max leverage to dlc connect
Browse files Browse the repository at this point in the history
  • Loading branch information
bonomat committed Jun 6, 2024
1 parent a0e11de commit 357693f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions webapp/frontend/lib/services/trade_constraints_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class TradeConstraints {
@JsonKey(name: 'channel_fee_reserve_sats')
final int channelFeeReserveSats;

/// The max leverage the trader can take
@JsonKey(name: 'max_leverage')
final int maxLeverage;

const TradeConstraints({
required this.maxLocalBalanceSats,
required this.maxCounterpartyBalanceSats,
Expand All @@ -73,6 +77,7 @@ class TradeConstraints {
required this.minMarginSats,
required this.estimatedFundingTxFeeSats,
required this.channelFeeReserveSats,
required this.maxLeverage,
});

factory TradeConstraints.fromJson(Map<String, dynamic> json) => _$TradeConstraintsFromJson(json);
Expand Down
2 changes: 2 additions & 0 deletions webapp/frontend/lib/services/trade_constraints_service.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion webapp/frontend/lib/trade/leverage_slider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get_10101/change_notifier/trade_constraint_change_notifier.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/theme.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:syncfusion_flutter_sliders/sliders.dart';
import 'package:syncfusion_flutter_core/theme.dart' as slider_theme;

Expand All @@ -11,7 +13,6 @@ const gradientColors = <Color>[Colors.green, Colors.deepOrange];
const LinearGradient gradient = LinearGradient(colors: gradientColors);

const double minLeverage = 1.0;
const double maxLeverage = 5.0;

/// Slider that allows the user to select a leverage between minLeverage and maxLeverage.
/// It uses linear scale and fractional leverage values are rounded to the nearest integer.
Expand All @@ -36,6 +37,12 @@ class _LeverageSliderState extends State<LeverageSlider> {

@override
Widget build(BuildContext context) {
TradeConstraintsChangeNotifier tradeConstraintsChangeNotifier =
context.read<TradeConstraintsChangeNotifier>();

double maxLeverage =
tradeConstraintsChangeNotifier.tradeConstraints?.maxLeverage.toDouble() ?? 5.0;

return InputDecorator(
decoration: InputDecoration(
border: const OutlineInputBorder(),
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use native::api::WalletHistoryItemType;
use native::calculations::calculate_pnl;
use native::channel_trade_constraints;
use native::dlc;
use native::state::try_get_tentenone_config;
use native::trade::order::FailureReason;
use native::trade::order::InvalidSubchannelOffer;
use rust_decimal::prelude::ToPrimitive;
Expand Down Expand Up @@ -965,6 +966,7 @@ pub struct TradeConstraints {
pub min_margin_sats: u64,
pub estimated_funding_tx_fee_sats: u64,
pub channel_fee_reserve_sats: u64,
pub max_leverage: u8,
}

#[utoipa::path(
Expand All @@ -976,6 +978,7 @@ responses(
)]
pub async fn get_trade_constraints() -> Result<Json<TradeConstraints>, AppError> {
let trade_constraints = channel_trade_constraints::channel_trade_constraints()?;
let ten_one_config = try_get_tentenone_config().context("Could not read 10101 config")?;
let fee = dlc::estimated_funding_tx_fee()?;
let channel_fee_reserve = dlc::estimated_fee_reserve()?;
Ok(Json(TradeConstraints {
Expand All @@ -987,6 +990,7 @@ pub async fn get_trade_constraints() -> Result<Json<TradeConstraints>, AppError>
min_margin_sats: trade_constraints.min_margin,
estimated_funding_tx_fee_sats: fee.to_sat(),
channel_fee_reserve_sats: channel_fee_reserve.to_sat(),
max_leverage: ten_one_config.max_leverage,
}))
}

Expand Down

0 comments on commit 357693f

Please sign in to comment.