Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit c0b9bd9

Browse files
committed
remove utxo chain fee reserves
1 parent a572f75 commit c0b9bd9

4 files changed

Lines changed: 62 additions & 11 deletions

File tree

crates/swapper/src/chainflip/provider.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ where
349349
#[cfg(test)]
350350
mod tests {
351351
use super::*;
352-
use crate::SwapperQuoteAsset;
352+
use crate::{Options, SwapperQuoteAsset};
353353
use primitives::AssetId;
354354

355355
#[test]
@@ -378,13 +378,18 @@ mod tests {
378378
let request = QuoteRequest {
379379
from_asset: SwapperQuoteAsset::from(AssetId::from_chain(Chain::Bitcoin)),
380380
to_asset: SwapperQuoteAsset::from(AssetId::from_chain(Chain::Ethereum)),
381+
value: "89100".to_string(),
382+
options: Options {
383+
use_max_amount: true,
384+
..Default::default()
385+
},
381386
..QuoteRequest::mock(Chain::Bitcoin, None)
382387
};
383388

384389
let quote_request = build_quote_request(&request).unwrap();
385390

386-
assert_eq!(quote_request.from_value, "1000000");
387-
assert_eq!(quote_request.quote_request.amount, "1000000");
391+
assert_eq!(quote_request.from_value, "89100");
392+
assert_eq!(quote_request.quote_request.amount, "89100");
388393
assert_eq!(quote_request.quote_request.src_chain, "Bitcoin");
389394
assert_eq!(quote_request.quote_request.src_asset, "BTC");
390395
assert_eq!(quote_request.quote_request.dest_chain, "Ethereum");

crates/swapper/src/fees/reserve.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ pub static RESERVED_NATIVE_FEES: LazyLock<HashMap<Chain, &'static str>> = LazyLo
2020
(Chain::Solana, "20000"), // 0.00002 SOL
2121
(Chain::Ton, "20000000"), // 0.02 TON
2222
(Chain::Tron, "20000000"), // 20 TRX
23-
(Chain::Bitcoin, "40000"), // 0.0004 BTC
24-
(Chain::Zcash, "1000000"), // 0.01 ZEC
25-
(Chain::Doge, "500000000"), // 5 DOGE
2623
(Chain::Xrp, "2000000"), // 2 XRP
2724
(Chain::Cardano, "2000000"), // 2 ADA
2825
(Chain::Aptos, "20000000"), // 0.2 APT
2926
(Chain::Stellar, "100000"), // 0.01 XLM
30-
(Chain::Litecoin, "100000"), // 0.001 LTC
31-
(Chain::BitcoinCash, "100000"), // 0.001 BCH
3227
(Chain::Monad, "5000000000000000"), // 0.005 MON
3328
(Chain::XLayer, "5000000000000000"), // 0.005 OKB
3429
(Chain::Plasma, "5000000000000000"), // 0.005 XPL
@@ -65,3 +60,36 @@ pub fn quote_value_after_reserve_by_chain(request: &QuoteRequest) -> Result<Stri
6560
};
6661
quote_value_after_reserve(request, reserved)
6762
}
63+
64+
#[cfg(test)]
65+
mod tests {
66+
use primitives::AssetId;
67+
68+
use super::*;
69+
use crate::{Options, SwapperQuoteAsset};
70+
71+
#[test]
72+
fn btc_family_chains_have_no_reserve() {
73+
// UTXO chains do not need swapper-side reserves; the signer subtracts fees from selected inputs.
74+
for chain in [Chain::Bitcoin, Chain::Litecoin, Chain::BitcoinCash, Chain::Doge, Chain::Zcash] {
75+
assert_eq!(reserved_tx_fees(chain), None, "{chain:?} should not be in the reserve table");
76+
}
77+
}
78+
79+
#[test]
80+
fn btc_max_quote_passes_value_through() {
81+
let request = QuoteRequest {
82+
from_asset: SwapperQuoteAsset::from(AssetId::from_chain(Chain::Bitcoin)),
83+
to_asset: SwapperQuoteAsset::from(AssetId::from_chain(Chain::Solana)),
84+
wallet_address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4".into(),
85+
destination_address: "11111111111111111111111111111111".into(),
86+
value: "89100".to_string(),
87+
options: Options {
88+
use_max_amount: true,
89+
..Default::default()
90+
},
91+
};
92+
93+
assert_eq!(quote_value_after_reserve_by_chain(&request).unwrap(), "89100");
94+
}
95+
}

crates/swapper/src/near_intents/provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ mod tests {
395395

396396
#[test]
397397
fn max_quote_keeps_transfer_amount() {
398-
let mut request = QuoteRequest::mock(Chain::Tron, None);
398+
let mut request = QuoteRequest::mock(Chain::Bitcoin, None);
399399
request.to_asset = SwapperQuoteAsset::from(AssetId::from_chain(Chain::Near));
400-
request.value = "37000000".to_string();
400+
request.value = "89100".to_string();
401401
request.options.use_max_amount = true;
402402

403403
let quote_request = NearIntents::<RpcClient>::build_quote_request(&request, SwapType::FlexInput, true).unwrap();
404404

405-
assert_eq!(quote_request.amount, "37000000");
405+
assert_eq!(quote_request.amount, "89100");
406406
}
407407

408408
#[test]

crates/swapper/src/thorchain/provider.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ mod tests {
243243
assert!(has_zcash);
244244
}
245245

246+
#[test]
247+
fn test_quote_input_value_bitcoin_max_passes_value_through() {
248+
let from_asset = THORChainAsset::from_asset_id(Chain::Bitcoin.as_ref()).unwrap();
249+
let request = QuoteRequest {
250+
from_asset: SwapperQuoteAsset::from(Chain::Bitcoin.as_asset_id()),
251+
to_asset: SwapperQuoteAsset::from(Chain::Solana.as_asset_id()),
252+
wallet_address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4".to_string(),
253+
destination_address: "11111111111111111111111111111111".to_string(),
254+
value: "89100".to_string(),
255+
options: Options {
256+
use_max_amount: true,
257+
..Default::default()
258+
},
259+
};
260+
261+
assert_eq!(quote_input_value(&from_asset, &request).unwrap(), "89100");
262+
}
263+
246264
#[tokio::test]
247265
async fn test_get_quote_data_uses_quote_from_value() {
248266
let provider = Arc::new(ProviderMock::new(String::new()));

0 commit comments

Comments
 (0)