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 <86064887+binarybaron@users.noreply.github.com>
This commit is contained in:
bors[bot] 2022-12-31 00:56:48 +00:00 committed by GitHub
commit 4950167b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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 {
@ -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,
},
})
}
@ -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,
},
};
@ -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,
},
};
@ -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,
},
};

View File

@ -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>,
@ -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();
@ -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(),
@ -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);

View File

@ -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();

View File

@ -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?;

View File

@ -259,6 +259,7 @@ async fn start_alice(
FixedRate::default(),
min_buy,
max_buy,
None,
)
.unwrap();