Skip to content

Commit

Permalink
Add error type
Browse files Browse the repository at this point in the history
  • Loading branch information
ozankaymak committed Sep 9, 2024
1 parent 115f8a6 commit bf0757b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ pub enum BridgeError {
/// OperatorFundingUtxoAmountNotEnough is returned when the operator funding utxo amount is not enough
#[error("OperatorFundingUtxoAmountNotEnough: Operator funding utxo amount is not enough, pls send some amount here: {0}, then call the set_operator_funding_utxo RPC")]
OperatorFundingUtxoAmountNotEnough(bitcoin::Address),
/// OperatorWithdrawalFeeNotSet is returned when the operator withdrawal fee is not set
#[error("OperatorWithdrawalFeeNotSet")]
OperatorWithdrawalFeeNotSet,
/// InvalidKickoffUtxo is returned when the kickoff utxo is invalid
#[error("InvalidKickoffUtxo")]
InvalidKickoffUtxo,
Expand Down
15 changes: 13 additions & 2 deletions core/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,19 @@ where
}

async fn is_profitable(&self, withdrawal_amount: u64) -> Result<bool, BridgeError> {
let net_profit = self.config.bridge_amount_sats - withdrawal_amount;
Ok(self.config.operator_withdrawal_fee_sats.unwrap() < net_profit)
// Check if the withdrawal amount is within the acceptable range
if withdrawal_amount > self.config.bridge_amount_sats {
Ok(false)
} else {
// Calculate net profit after the withdrawal
let net_profit = self.config.bridge_amount_sats - withdrawal_amount;

// Check if the operator withdrawal fee is set and calculate profitability
match self.config.operator_withdrawal_fee_sats {
Some(fee) => Ok(fee < net_profit),
None => Err(BridgeError::OperatorWithdrawalFeeNotSet),
}
}
}

async fn new_withdrawal_sig(
Expand Down

0 comments on commit bf0757b

Please sign in to comment.