-
Notifications
You must be signed in to change notification settings - Fork 117
feat(tpu): implement 0 dexfee for kmd trading pairs #2323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
9059f93
450ced6
0cc613a
49f08ac
1a8539a
dc45a35
f62a0de
2d6ae32
a6cb780
06ccb20
76cd46e
4358025
c05963e
634c5f5
29a8460
a50238f
d2e766e
da5fc4e
8ba9aab
dd33004
84e5b7f
0d3be66
c714e4e
1afe061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1244,39 +1244,50 @@ async fn gen_taker_payment_spend_preimage<T: UtxoCommonOps>( | |
| args: &GenTakerPaymentSpendArgs<'_, T>, | ||
| n_time: NTimeSetting, | ||
| ) -> GenPreimageResInner { | ||
| let dex_fee_address = address_from_raw_pubkey( | ||
| args.dex_fee_pub, | ||
| coin.as_ref().conf.address_prefixes.clone(), | ||
| coin.as_ref().conf.checksum_type, | ||
| coin.as_ref().conf.bech32_hrp.clone(), | ||
| coin.addr_format().clone(), | ||
| ) | ||
| .map_to_mm(|e| TxGenError::AddressDerivation(format!("Failed to derive dex_fee_address: {}", e)))?; | ||
|
|
||
| let mut outputs = generate_taker_fee_tx_outputs(coin.as_ref().decimals, dex_fee_address.hash(), args.dex_fee)?; | ||
| if let DexFee::WithBurn { .. } = args.dex_fee { | ||
| let script = output_script(args.maker_address).map_to_mm(|e| { | ||
| TxGenError::Other(format!( | ||
| "Couldn't generate output script for maker address {}, error {}", | ||
| args.maker_address, e | ||
| )) | ||
| })?; | ||
| let tx_fee = coin | ||
| .get_htlc_spend_fee(DEFAULT_SWAP_TX_SPEND_SIZE, &FeeApproxStage::WithoutApprox) | ||
| .await?; | ||
| let maker_value = args | ||
| .taker_tx | ||
| .first_output() | ||
| .map_to_mm(|e| TxGenError::PrevTxIsNotValid(e.to_string()))? | ||
| .value | ||
| - outputs[0].value | ||
| - outputs[1].value | ||
| - tx_fee; | ||
| outputs.push(TransactionOutput { | ||
| value: maker_value, | ||
| script_pubkey: script.to_bytes(), | ||
| }) | ||
| } | ||
| let outputs = match args.dex_fee { | ||
| DexFee::Zero => vec![], | ||
| dex_fee => { | ||
| let dex_fee_address = address_from_raw_pubkey( | ||
| args.dex_fee_pub, | ||
| coin.as_ref().conf.address_prefixes.clone(), | ||
| coin.as_ref().conf.checksum_type, | ||
| coin.as_ref().conf.bech32_hrp.clone(), | ||
| coin.addr_format().clone(), | ||
| ) | ||
| .map_to_mm(|e| TxGenError::AddressDerivation(format!("Failed to derive dex_fee_address: {}", e)))?; | ||
|
|
||
| let mut fee_outputs = | ||
| generate_taker_fee_tx_outputs(coin.as_ref().decimals, dex_fee_address.hash(), dex_fee)?; | ||
|
|
||
| if let DexFee::WithBurn { .. } = dex_fee { | ||
| let script = output_script(args.maker_address).map_to_mm(|e| { | ||
| TxGenError::Other(format!( | ||
| "Couldn't generate output script for maker address {}, error {}", | ||
| args.maker_address, e | ||
| )) | ||
| })?; | ||
|
|
||
| let tx_fee = coin | ||
| .get_htlc_spend_fee(DEFAULT_SWAP_TX_SPEND_SIZE, &FeeApproxStage::WithoutApprox) | ||
| .await?; | ||
|
|
||
| let total_fee_value: u64 = fee_outputs.iter().map(|out| out.value).sum(); | ||
| let first_output_value = args | ||
| .taker_tx | ||
| .first_output() | ||
| .map_to_mm(|e| TxGenError::PrevTxIsNotValid(e.to_string()))? | ||
| .value; | ||
|
|
||
| let maker_value = first_output_value - total_fee_value - tx_fee; | ||
| fee_outputs.push(TransactionOutput { | ||
| value: maker_value, | ||
| script_pubkey: script.to_bytes(), | ||
| }); | ||
| } | ||
|
|
||
| fee_outputs | ||
| }, | ||
| }; | ||
|
|
||
| p2sh_spending_tx_preimage( | ||
| coin, | ||
|
|
@@ -1307,7 +1318,7 @@ pub async fn gen_and_sign_taker_payment_spend_preimage<T: UtxoCommonOps>( | |
|
|
||
| let sig_hash_type = match args.dex_fee { | ||
| DexFee::Standard(_) => SIGHASH_SINGLE, | ||
| DexFee::WithBurn { .. } => SIGHASH_ALL, | ||
| DexFee::WithBurn { .. } | DexFee::Zero => SIGHASH_ALL, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify why we should use SIGHASH_ALL for zero fee?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I guess using either for zero fees won't make a significant diff. cc @dimxy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok I was just curious will it be the difference for zero fee, as for
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should use SIGHASH_ALL wherever possible. |
||
| }; | ||
|
|
||
| let signature = calc_and_sign_sighash( | ||
|
|
@@ -1350,7 +1361,7 @@ pub async fn validate_taker_payment_spend_preimage<T: UtxoCommonOps + SwapOps>( | |
|
|
||
| let sig_hash_type = match gen_args.dex_fee { | ||
| DexFee::Standard(_) => SIGHASH_SINGLE, | ||
| DexFee::WithBurn { .. } => SIGHASH_ALL, | ||
| DexFee::WithBurn { .. } | DexFee::Zero => SIGHASH_ALL, | ||
| }; | ||
|
|
||
| let sig_hash = signature_hash_to_sign( | ||
|
|
@@ -1434,7 +1445,7 @@ pub async fn sign_and_broadcast_taker_payment_spend<T: UtxoCommonOps>( | |
| let mut taker_signature_with_sighash = preimage.signature.to_vec(); | ||
| let taker_sig_hash = match gen_args.dex_fee { | ||
| DexFee::Standard(_) => (SIGHASH_SINGLE | coin.as_ref().conf.fork_id) as u8, | ||
| DexFee::WithBurn { .. } => (SIGHASH_ALL | coin.as_ref().conf.fork_id) as u8, | ||
| DexFee::WithBurn { .. } | DexFee::Zero => (SIGHASH_ALL | coin.as_ref().conf.fork_id) as u8, | ||
| }; | ||
|
|
||
| taker_signature_with_sighash.push(taker_sig_hash); | ||
|
|
@@ -3999,13 +4010,12 @@ where | |
| T: MarketCoinOps + UtxoCommonOps, | ||
| { | ||
| let decimals = coin.as_ref().decimals; | ||
|
|
||
| let outputs = generate_taker_fee_tx_outputs(decimals, &AddressHashEnum::default_address_hash(), &dex_fee)?; | ||
|
|
||
| let gas_fee = None; | ||
| let fee_amount = coin | ||
| .preimage_trade_fee_required_to_send_outputs(outputs, FeePolicy::SendExact, gas_fee, &stage) | ||
| .await?; | ||
|
|
||
| Ok(TradeFee { | ||
| coin: coin.ticker().to_owned(), | ||
| amount: fee_amount.into(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.