mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Allow asb to set a bitcoin address that is controlled by the asb itself to redeem/punish Bitcoin to
This commit is contained in:
parent
b1fe7b0d2f
commit
b6201192c2
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Changed ASB to quote on Monero unlocked balance instead of total balance
|
- 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
|
### Added
|
||||||
|
|
||||||
|
@ -216,6 +216,7 @@ pub struct Maker {
|
|||||||
pub max_buy_btc: bitcoin::Amount,
|
pub max_buy_btc: bitcoin::Amount,
|
||||||
pub ask_spread: Decimal,
|
pub ask_spread: Decimal,
|
||||||
pub price_ticker_ws_url: Url,
|
pub price_ticker_ws_url: Url,
|
||||||
|
pub external_bitcoin_redeem_address: Option<bitcoin::Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TorConf {
|
impl Default for TorConf {
|
||||||
@ -384,6 +385,7 @@ pub fn query_user_for_initial_config(testnet: bool) -> Result<Config> {
|
|||||||
max_buy_btc: max_buy,
|
max_buy_btc: max_buy,
|
||||||
ask_spread,
|
ask_spread,
|
||||||
price_ticker_ws_url: defaults.price_ticker_ws_url,
|
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(),
|
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
|
||||||
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
||||||
price_ticker_ws_url: defaults.price_ticker_ws_url,
|
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(),
|
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
|
||||||
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
||||||
price_ticker_ws_url: defaults.price_ticker_ws_url,
|
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(),
|
max_buy_btc: bitcoin::Amount::from_btc(DEFAULT_MAX_BUY_AMOUNT).unwrap(),
|
||||||
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
ask_spread: Decimal::from_f64(DEFAULT_SPREAD).unwrap(),
|
||||||
price_ticker_ws_url: defaults.price_ticker_ws_url,
|
price_ticker_ws_url: defaults.price_ticker_ws_url,
|
||||||
|
external_bitcoin_redeem_address: None,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ where
|
|||||||
latest_rate: LR,
|
latest_rate: LR,
|
||||||
min_buy: bitcoin::Amount,
|
min_buy: bitcoin::Amount,
|
||||||
max_buy: bitcoin::Amount,
|
max_buy: bitcoin::Amount,
|
||||||
|
external_redeem_address: Option<bitcoin::Address>,
|
||||||
|
|
||||||
swap_sender: mpsc::Sender<Swap>,
|
swap_sender: mpsc::Sender<Swap>,
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ where
|
|||||||
latest_rate: LR,
|
latest_rate: LR,
|
||||||
min_buy: bitcoin::Amount,
|
min_buy: bitcoin::Amount,
|
||||||
max_buy: bitcoin::Amount,
|
max_buy: bitcoin::Amount,
|
||||||
|
external_redeem_address: Option<bitcoin::Address>,
|
||||||
) -> Result<(Self, mpsc::Receiver<Swap>)> {
|
) -> Result<(Self, mpsc::Receiver<Swap>)> {
|
||||||
let swap_channel = MpscChannels::default();
|
let swap_channel = MpscChannels::default();
|
||||||
|
|
||||||
@ -89,6 +91,7 @@ where
|
|||||||
swap_sender: swap_channel.sender,
|
swap_sender: swap_channel.sender,
|
||||||
min_buy,
|
min_buy,
|
||||||
max_buy,
|
max_buy,
|
||||||
|
external_redeem_address,
|
||||||
recv_encrypted_signature: Default::default(),
|
recv_encrypted_signature: Default::default(),
|
||||||
inflight_encrypted_signatures: Default::default(),
|
inflight_encrypted_signatures: Default::default(),
|
||||||
send_transfer_proof: 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,
|
Ok(wallet_snapshot) => wallet_snapshot,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
tracing::error!("Swap request will be ignored because we were unable to create wallet snapshot for swap: {:#}", error);
|
tracing::error!("Swap request will be ignored because we were unable to create wallet snapshot for swap: {:#}", error);
|
||||||
|
@ -188,6 +188,7 @@ async fn main() -> Result<()> {
|
|||||||
kraken_rate.clone(),
|
kraken_rate.clone(),
|
||||||
config.maker.min_buy_btc,
|
config.maker.min_buy_btc,
|
||||||
config.maker.max_buy_btc,
|
config.maker.max_buy_btc,
|
||||||
|
config.maker.external_bitcoin_redeem_address,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -59,11 +59,17 @@ impl WalletSnapshot {
|
|||||||
pub async fn capture(
|
pub async fn capture(
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
bitcoin_wallet: &bitcoin::Wallet,
|
||||||
monero_wallet: &monero::Wallet,
|
monero_wallet: &monero::Wallet,
|
||||||
|
external_redeem_address: &Option<bitcoin::Address>,
|
||||||
transfer_amount: bitcoin::Amount,
|
transfer_amount: bitcoin::Amount,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let balance = monero_wallet.get_balance().await?;
|
let balance = monero_wallet.get_balance().await?;
|
||||||
let redeem_address = bitcoin_wallet.new_address().await?;
|
let redeem_address = external_redeem_address
|
||||||
let punish_address = bitcoin_wallet.new_address().await?;
|
.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
|
let redeem_fee = bitcoin_wallet
|
||||||
.estimate_fee(bitcoin::TxRedeem::weight(), transfer_amount)
|
.estimate_fee(bitcoin::TxRedeem::weight(), transfer_amount)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -259,6 +259,7 @@ async fn start_alice(
|
|||||||
FixedRate::default(),
|
FixedRate::default(),
|
||||||
min_buy,
|
min_buy,
|
||||||
max_buy,
|
max_buy,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user