From 25c7272424b1c55b2132dd22e4a921d617498993 Mon Sep 17 00:00:00 2001 From: Mykhailo Kremniov Date: Tue, 11 Aug 2026 18:46:05 +0300 Subject: [PATCH] Fix fee calculation for ConcludeOrder; update sdk version --- Cargo.lock | 8 ++--- Cargo.toml | 4 +-- .../src/handlers/sign_tx/summary_collector.rs | 35 ++++++++++++++----- tests/test_sign_tx.py | 7 ++-- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d302656..7a0e108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -348,9 +348,9 @@ checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "ledger_device_sdk" -version = "1.36.0" +version = "1.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b18ab2ba8ba9a6fb622f3eb0694f9759e062b026b6d60e2c4e1f0255b427fbb" +checksum = "d36088f33e948d2e544a043632ba76b76d663f67cf8090b7162d8945d132ed83" dependencies = [ "const-zero", "include_gif", @@ -364,9 +364,9 @@ dependencies = [ [[package]] name = "ledger_secure_sdk_sys" -version = "1.16.2" +version = "1.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7424fb1da714f47453c65a58ca4144fa576e91563c860522b31db4c6868408" +checksum = "027f543582d3de5cb05db8f4b9cba5e89480ad03f63d133ca3757687475d8a06" dependencies = [ "bindgen", "cc", diff --git a/Cargo.toml b/Cargo.toml index 958c7bc..3985ce6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ chrono = { version = "0.4", default-features = false } const-hex = { version = "1.19", default-features = false } derive_more = { version = "2.1", default-features = false } itertools = { version = "0.15", default-features = false } -ledger_device_sdk = "1.35" -ledger_secure_sdk_sys = "1.16" +ledger_device_sdk = "1.36.1" +ledger_secure_sdk_sys = "1.16.3" num_enum = { version = "0.7", default-features = false } num-traits = { version = "0.2", default-features = false } strum = { version = "0.27", default-features = false } diff --git a/crates/app-core/src/handlers/sign_tx/summary_collector.rs b/crates/app-core/src/handlers/sign_tx/summary_collector.rs index 69938d3..3971899 100644 --- a/crates/app-core/src/handlers/sign_tx/summary_collector.rs +++ b/crates/app-core/src/handlers/sign_tx/summary_collector.rs @@ -183,6 +183,7 @@ impl TxSummaryCollector { self.tx_type = merge_tx_type(self.tx_type, TxType::CreateOrder); let (coin_or_token_id, amount) = into_coin_or_token_id_and_amount(&order_data.give)?; + // Add the give amount as a "pseudo-output" (it goes into the order account). self.increase_output_totals(coin_or_token_id, amount)?; } } @@ -293,13 +294,26 @@ impl TxSummaryCollector { self.tx_type = merge_tx_type(self.tx_type, TxType::FillOrder); } OrderAccountCommand::ConcludeOrder(_) => { - let (coin_or_token_id, _) = + let (asked_coin_or_token_id, initially_asked) = into_coin_or_token_id_and_amount(&additional_info.initially_asked)?; - self.increase_input_totals(coin_or_token_id, additional_info.ask_balance)?; - - let (coin_or_token_id, _) = + let (given_coin_or_token_id, _) = into_coin_or_token_id_and_amount(&additional_info.initially_given)?; - self.increase_input_totals(coin_or_token_id, additional_info.give_balance)?; + + let filled_atoms = initially_asked + .into_atoms() + .checked_sub(additional_info.ask_balance.into_atoms()) + .ok_or(StatusWord::TxNumericOperationFail)?; + let filled_amount = Amount::from_atoms(filled_atoms); + // Add the filled amount as a "pseudo-input", so that actual transfer outputs + // can consume it. + self.increase_input_totals(asked_coin_or_token_id, filled_amount)?; + + // Add the unspent given amount as a "pseudo-input", so that actual transfer outputs + // can consume it. + self.increase_input_totals( + given_coin_or_token_id, + additional_info.give_balance, + )?; self.tx_type = merge_tx_type(self.tx_type, TxType::ConcludeOrder); } @@ -938,8 +952,9 @@ mod tests { let ask_balance = mlcp::Amount::from_atoms(30); let give_balance = mlcp::Amount::from_atoms(60); let token_id = mlcp::Id::new(mlcp::H256::zero()); + let initially_asked_amount = mlcp::Amount::from_atoms(100); let additional_info = AdditionalOrderInfo { - initially_asked: mlcp::OutputValue::Coin(mlcp::Amount::from_atoms(100)), + initially_asked: mlcp::OutputValue::Coin(initially_asked_amount), initially_given: mlcp::OutputValue::TokenV1(token_id, mlcp::Amount::from_atoms(200)), ask_balance, give_balance, @@ -950,10 +965,14 @@ mod tests { ); collector.process_input(&inp).unwrap(); assert_eq!(collector.tx_type(), Some(TxType::ConcludeOrder)); - // Conclude order increases inputs by ask_balance and give_balance + + let filled_amount = mlcp::Amount::from_atoms( + initially_asked_amount.into_atoms() - ask_balance.into_atoms(), + ); + // Conclude order increases inputs by filled_amount and give_balance assert_eq!( collector.total_inputs().get(&CoinOrTokenId::Coin), - Some(&ask_balance) + Some(&filled_amount) ); assert_eq!( collector diff --git a/tests/test_sign_tx.py b/tests/test_sign_tx.py index 7bfbf4c..55dcdc9 100644 --- a/tests/test_sign_tx.py +++ b/tests/test_sign_tx.py @@ -1299,7 +1299,8 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator): Test signing a transaction with two inputs: 1. A standard UTXO input to pay for tx fees. 2. An OrderAccountCommand input to conclude an order. - And one output to transfer the change coins + ask balance and another output for the give balance. + And one output to transfer the change coins plus the filled amount (where the latter + is initial_ask minus ask_balance) and another output for the give balance. """ client = MintlayerCommandSender(backend) bip44_path = make_path(0, KeyPurpose.Receive, 0) @@ -1332,7 +1333,7 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator): initial_ask = 100 initial_give = 1000 - ask_balance = 10 + ask_balance = 90 give_balance = 900 token_id = bytes([1] * 32) @@ -1367,7 +1368,7 @@ def test_sign_tx_order_conclude(backend, scenario_navigator, device, navigator): } change_output = _make_transfer_output( - 100 - 1 + ask_balance, + 100 - 1 + initial_ask - ask_balance, fetch_public_key_as_pk_destination(client, MAINNET, bip44_change_path), bip44_change_path, )