Browse Source

Add API for calculating payout curve

fix-olivia-event-id
Thomas Eizinger 3 years ago
parent
commit
43b1d08898
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 1
      daemon/src/maker.rs
  2. 13
      daemon/src/payout_curve.rs
  3. 11
      daemon/src/setup_contract.rs
  4. 1
      daemon/src/taker.rs

1
daemon/src/maker.rs

@ -30,6 +30,7 @@ mod maker_inc_connections;
mod model;
mod monitor;
mod oracle;
mod payout_curve;
mod routes;
mod routes_maker;
mod seed;

13
daemon/src/payout_curve.rs

@ -0,0 +1,13 @@
use crate::model::{Leverage, Usd};
use anyhow::Result;
use bdk::bitcoin;
use cfd_protocol::Payout;
pub fn calculate(
_price: Usd,
_quantity: Usd,
_maker_payin: bitcoin::Amount,
(_taker_payin, _leverage): (bitcoin::Amount, Leverage),
) -> Result<Vec<Payout>> {
Ok(vec![])
}

11
daemon/src/setup_contract.rs

@ -1,7 +1,7 @@
use crate::model;
use crate::model::cfd::{Cfd, Dlc};
use crate::wallet::Wallet;
use crate::wire::{Msg0, Msg1, Msg2, SetupMsg};
use crate::{model, payout_curve};
use anyhow::{Context, Result};
use bdk::bitcoin::secp256k1::{schnorrsig, Signature, SECP256K1};
use bdk::bitcoin::{Amount, PublicKey, Transaction};
@ -61,6 +61,13 @@ pub async fn new(
)
}
let payouts = payout_curve::calculate(
cfd.order.price,
cfd.quantity_usd,
params.maker().lock_amount,
(params.taker().lock_amount, cfd.order.leverage),
)?;
let own_cfd_txs = create_cfd_transactions(
(params.maker().clone(), *params.maker_punish()),
(params.taker().clone(), *params.taker_punish()),
@ -69,7 +76,7 @@ pub async fn new(
model::cfd::Cfd::CET_TIMELOCK,
cfd.refund_timelock_in_blocks(),
),
vec![],
payouts,
sk,
)
.context("Failed to create CFD transactions")?;

1
daemon/src/taker.rs

@ -30,6 +30,7 @@ mod logger;
mod model;
mod monitor;
mod oracle;
mod payout_curve;
mod routes;
mod routes_taker;
mod seed;

Loading…
Cancel
Save