working on wrong input amount calculation

This commit is contained in:
fbock
2024-08-27 17:11:53 +02:00
parent 183eaf07f5
commit 48ad59c1a9
3 changed files with 29 additions and 3 deletions

View File

@ -15,8 +15,28 @@ pub async fn process_order(
let wallet = &coordinator.coordinator_wallet;
let database = &coordinator.coordinator_db;
let locking_amount_sat = offer.amount_satoshi * u64::from(offer.bond_ratio) / 100;
// the client also uses this amount to select inputs for the escrow psbt, this could be separated
// to make the required bond amount lower without causing the client to return too small inputs
// 5000 is the abs tx fee used in the escrow psbt per trader
panic!("This is borked");
let coordinator_feerate = (coordinator.coordinator_wallet.coordinator_feerate
* offer.amount_satoshi as f64) as u64
/ 100;
let locking_amount_sat = match offer.is_buy_order {
true => {
5000 + coordinator_feerate + offer.amount_satoshi * u64::from(offer.bond_ratio) / 100
}
false => {
(offer.amount_satoshi * u64::from(offer.bond_ratio) / 100)
+ offer.amount_satoshi
+ 5000 + coordinator_feerate
}
};
trace!(
"Offer amount: {}, Locking amount: {}",
offer.amount_satoshi,
locking_amount_sat
);
let bond_requirements = BondRequirementResponse {
bond_address: wallet.get_new_address().await?,
locking_amount_sat,

View File

@ -159,6 +159,12 @@ impl<D: bdk::database::BatchDatabase> CoordinatorWallet<D> {
// upfront and substract the fee from the change outputs (10k == ~30/sat vbyte)
let tx_fee_abs = 10000;
debug!(
"Escrow amounts: maker: {}, fee: {}, input sum: {}",
escrow_amount_maker_sat,
escrow_fee_sat_per_participant,
maker_psbt_input_data.input_sum()?
);
let change_amount_maker = maker_psbt_input_data.input_sum()?
- (escrow_amount_maker_sat + escrow_fee_sat_per_participant + tx_fee_abs / 2);
let change_amount_taker = taker_psbt_input_data.input_sum()?

View File

@ -55,7 +55,7 @@ impl ActiveOffer {
// returns the PSBT of the escrow trade transaction we have to validate, sign and return
pub fn wait_until_taken(&self, trader_config: &TraderSettings) -> Result<OfferTakenResponse> {
loop {
thread::sleep(Duration::from_secs(10));
thread::sleep(Duration::from_secs(2));
if let Some(offer_taken_response) = OfferTakenResponse::check(self, trader_config)? {
return Ok(offer_taken_response);
}