Skip to content

Commit

Permalink
Merge #1259
Browse files Browse the repository at this point in the history
1259: Allow asb to set a bitcoin address that is controlled by the asb itself to redeem/punish Bitcoin to r=binarybaron a=binarybaron



Co-authored-by: binarybaron <[email protected]>
  • Loading branch information
bors[bot] and binarybaron authored Dec 31, 2022
2 parents e5f52b1 + b620119 commit a1a910a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Update `bdk` library to latest version. This introduces an incompatability with previous versions due to different formats being used to exchange Bitcoin transactions
- Changed ASB to quote on Monero unlocked balance instead of total balance
- Allow `asb` to set a bitcoin address that is controlled by the asb itself to redeem/punish bitcoin to

### Added

Expand Down
5 changes: 5 additions & 0 deletions swap/src/asb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub struct Maker {
pub max_buy_btc: bitcoin::Amount,
pub ask_spread: Decimal,
pub price_ticker_ws_url: Url,
pub external_bitcoin_redeem_address: Option<bitcoin::Address>,
}

impl Default for TorConf {
Expand Down Expand Up @@ -384,6 +385,7 @@ pub fn query_user_for_initial_config(testnet: bool) -> Result<Config> {
max_buy_btc: max_buy,
ask_spread,
price_ticker_ws_url: defaults.price_ticker_ws_url,
external_bitcoin_redeem_address: None,
},
})
}
Expand Down Expand Up @@ -429,6 +431,7 @@ mod tests {
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
price_ticker_ws_url: defaults.price_ticker_ws_url,
external_bitcoin_redeem_address: None,
},
};

Expand Down Expand Up @@ -472,6 +475,7 @@ mod tests {
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
price_ticker_ws_url: defaults.price_ticker_ws_url,
external_bitcoin_redeem_address: None,
},
};

Expand Down Expand Up @@ -525,6 +529,7 @@ mod tests {
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
price_ticker_ws_url: defaults.price_ticker_ws_url,
external_bitcoin_redeem_address: None,
},
};

Expand Down
5 changes: 4 additions & 1 deletion swap/src/asb/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where
latest_rate: LR,
min_buy: bitcoin::Amount,
max_buy: bitcoin::Amount,
external_redeem_address: Option<bitcoin::Address>,

swap_sender: mpsc::Sender<Swap>,

Expand Down Expand Up @@ -76,6 +77,7 @@ where
latest_rate: LR,
min_buy: bitcoin::Amount,
max_buy: bitcoin::Amount,
external_redeem_address: Option<bitcoin::Address>,
) -> Result<(Self, mpsc::Receiver<Swap>)> {
let swap_channel = MpscChannels::default();

Expand All @@ -89,6 +91,7 @@ where
swap_sender: swap_channel.sender,
min_buy,
max_buy,
external_redeem_address,
recv_encrypted_signature: Default::default(),
inflight_encrypted_signatures: Default::default(),
send_transfer_proof: Default::default(),
Expand Down Expand Up @@ -165,7 +168,7 @@ where
}
};

let wallet_snapshot = match WalletSnapshot::capture(&self.bitcoin_wallet, &self.monero_wallet, btc).await {
let wallet_snapshot = match WalletSnapshot::capture(&self.bitcoin_wallet, &self.monero_wallet, &self.external_redeem_address, btc).await {
Ok(wallet_snapshot) => wallet_snapshot,
Err(error) => {
tracing::error!("Swap request will be ignored because we were unable to create wallet snapshot for swap: {:#}", error);
Expand Down
1 change: 1 addition & 0 deletions swap/src/bin/asb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ async fn main() -> Result<()> {
kraken_rate.clone(),
config.maker.min_buy_btc,
config.maker.max_buy_btc,
config.maker.external_bitcoin_redeem_address,
)
.unwrap();

Expand Down
10 changes: 8 additions & 2 deletions swap/src/network/swap_setup/alice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@ impl WalletSnapshot {
pub async fn capture(
bitcoin_wallet: &bitcoin::Wallet,
monero_wallet: &monero::Wallet,
external_redeem_address: &Option<bitcoin::Address>,
transfer_amount: bitcoin::Amount,
) -> Result<Self> {
let balance = monero_wallet.get_balance().await?;
let redeem_address = bitcoin_wallet.new_address().await?;
let punish_address = bitcoin_wallet.new_address().await?;
let redeem_address = external_redeem_address
.clone()
.unwrap_or(bitcoin_wallet.new_address().await?);
let punish_address = external_redeem_address
.clone()
.unwrap_or(bitcoin_wallet.new_address().await?);

let redeem_fee = bitcoin_wallet
.estimate_fee(bitcoin::TxRedeem::weight(), transfer_amount)
.await?;
Expand Down
1 change: 1 addition & 0 deletions swap/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ async fn start_alice(
FixedRate::default(),
min_buy,
max_buy,
None,
)
.unwrap();

Expand Down

0 comments on commit a1a910a

Please sign in to comment.