Skip to content
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

feat(utxo-swap): add utxo burn output for non-kmd taker fee #2112

Open
wants to merge 86 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
f3625e5
make mockable optional
dimxy Apr 27, 2024
d3f843d
add support for utxo coin burn account to dex fee
dimxy Apr 29, 2024
bc5c005
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Apr 29, 2024
7894f7d
remove left over dup dex_fee_rate()
dimxy Apr 29, 2024
2984c67
fix coins crate mocktopus dependency for mm2_main crate tests
dimxy Apr 29, 2024
128c4b4
fix dex fee changed due to new burn output in couple of lp_swap tests
dimxy Apr 29, 2024
23f2a08
fix swap v2 test non-kmd burn output
dimxy May 1, 2024
2c810b0
fix fmt
dimxy May 6, 2024
af45b71
remove comment
dimxy May 6, 2024
0e2869e
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy May 14, 2024
0f34d2e
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy May 22, 2024
d53dc37
fix zombie chain scan block num
dimxy Jun 14, 2024
81263e0
add burn output for privacy coin,
dimxy Jun 14, 2024
7719b80
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Jun 16, 2024
9331e40
use custom log! instead debug! (as env_logger disabled) in qrc20 dock…
dimxy Jun 17, 2024
b343275
fix to make should_burn_dex_fee explicitly in each coin (to fix qrc20…
dimxy Jun 17, 2024
587b1ae
restore original test log message
dimxy Jun 17, 2024
58d84cf
add test for std dex fee for zcoin
dimxy Jun 17, 2024
1243935
remove unused cache dir var in z_coin init block
dimxy Jun 17, 2024
bc00ee8
fix clippy
dimxy Jun 18, 2024
4d59545
fix burn addr in ZOutput
dimxy Jun 19, 2024
dc9e710
refactor dex fee code;
dimxy Jun 19, 2024
7a2399c
refactor dex fee code to eliminate extra if-else
dimxy Jun 19, 2024
4625554
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Jul 3, 2024
b84b3a9
fix comments (by review notes)
dimxy Jul 3, 2024
35b04a2
refactor var names on review notes
dimxy Aug 7, 2024
8b1033e
refactor fee_amount var names to dex_fee (as those are structs)
dimxy Aug 7, 2024
1a48a04
add test for qtum dex fee with burn output validation
dimxy Aug 7, 2024
06e36b5
remove todo for qrc20 with burn test (as we decided not to add evm bu…
dimxy Aug 7, 2024
1e79216
fix fn should_burn_dex_fee uninmlemented for solana
dimxy Aug 8, 2024
9fd47a4
fix restore cach_db_path (deleted by mistake)
dimxy Aug 9, 2024
217a313
fix review notes: delete unused fn, add cfg for test code
dimxy Aug 9, 2024
f35be00
fix review: add test from todo
dimxy Aug 9, 2024
26552c3
add NegotiationDataMsg V4 with version field, add swap features activ…
dimxy Aug 11, 2024
c02253a
add non-kmd burn activation with negotiation msg V4
dimxy Aug 11, 2024
fd5b4fe
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Aug 12, 2024
22b5c42
added NegotiationDataMsgVersion, removed NegotiationDataV4 (bcz V2 is…
dimxy Aug 12, 2024
9951626
fix activation ver
dimxy Aug 12, 2024
d72a313
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Aug 12, 2024
a63c3e0
fix after merge
dimxy Aug 12, 2024
983d8ef
remove relaxed dex fee validation (in favour versioned check)
dimxy Aug 13, 2024
849b190
add mocktopus to mm2_main
dimxy Aug 13, 2024
8e2fdaf
fix version in recreate swap
dimxy Aug 13, 2024
b844318
fix node version determination: try versioned then old negotiation me…
dimxy Aug 13, 2024
ddb4863
add test feature to emulate old non-versioned negotiation msgs (also …
dimxy Aug 14, 2024
9a34268
fix fmt
dimxy Aug 14, 2024
f8b543b
fix swap tx spend size
dimxy Aug 15, 2024
44a2586
move version activation swap_feature mod to coins (to allow using it …
dimxy Aug 17, 2024
e6fe67f
add delay between broadcasts of new and old messages
dimxy Aug 17, 2024
b20e679
fix old (non-versioned) taker and maker emulation (for tests)
dimxy Aug 17, 2024
e930f58
fix swap proto version: use new topic for versioned negotiation (Swap…
dimxy Aug 19, 2024
80d34f6
fix comment
dimxy Aug 19, 2024
5cc210e
add DexFee::NoFee option support for utxo if taker is dex pubkey (dex…
dimxy Aug 24, 2024
69cbfa4
add tests for swap v1 mycoin to mycoin with dex pubkey as Alice (to t…
dimxy Aug 24, 2024
248536a
fix tests to validate fee and recreate swaps
dimxy Aug 25, 2024
b0fabcf
fix DexFee::NoFee taker payment spending outputs for swaps V2
dimxy Aug 26, 2024
f6cc684
fix tests for no dex fee for swaps v1, add tests for no dex fee for s…
dimxy Aug 26, 2024
7053e2e
fix TODO for delay in broadcast msgs
dimxy Aug 26, 2024
1def60d
fixes for review notes
dimxy Aug 26, 2024
74d8ea3
fixes for review notes
dimxy Aug 26, 2024
bc560b8
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Sep 13, 2024
c4b494a
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Oct 4, 2024
347093d
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Oct 21, 2024
f95b91e
add dex fee burning for tendermint coins
dimxy Oct 31, 2024
e19b738
fix should_burn_dex_fee to true and burn_pubkey for validate dex fee …
dimxy Oct 31, 2024
446b3db
add mockable support for TendermintCoin (note: some TendermintCoin co…
dimxy Nov 1, 2024
8aa7a06
refactor validate_taker_fee_test with mocked txns
dimxy Nov 1, 2024
53a553f
add test to validate taker fee tx with burn for tendermint
dimxy Nov 1, 2024
2f47bdc
add test to calc DexFee with burn for nucleus ticker
dimxy Nov 1, 2024
a61d4a0
Refactor dex fee code:
dimxy Nov 2, 2024
63ecd0b
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Nov 2, 2024
29ad460
fix await in zhtlc tests
dimxy Nov 2, 2024
2ea8b9f
add TODO zhtlc feature
dimxy Nov 2, 2024
ab4f2a5
fix fmt
dimxy Nov 2, 2024
8711131
add comments how to run zcoin native tests
dimxy Nov 4, 2024
bf65293
add print into tests with hint how to sync wallet db
dimxy Nov 4, 2024
5f0d3d6
add debug logging for updating zcoin wallet db
dimxy Nov 4, 2024
b3eccf8
add scan interval in zcoin tests to prevent 'Can't assign requested a…
dimxy Nov 5, 2024
d5b9bbd
Merge branch 'dev' into burn-dex-fee-for-non-kmd
dimxy Nov 5, 2024
b92d065
fix review notes
dimxy Nov 7, 2024
601519d
fix build err
dimxy Nov 7, 2024
05feb72
add swap feature deactivation by version
dimxy Nov 7, 2024
ce1a5e0
improve comments for protocol version
dimxy Nov 7, 2024
dcfdbbd
fix burn_pubkey as taker in DexFee::NoFee;
dimxy Nov 8, 2024
dfb9673
fix fmt
dimxy Nov 8, 2024
2559e0e
fix tests with burn key as taker
dimxy Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mm2_number = { path = "../mm2_number"}
mm2_p2p = { path = "../mm2_p2p" }
mm2_rpc = { path = "../mm2_rpc" }
mm2_state_machine = { path = "../mm2_state_machine" }
mocktopus = "0.8.0"
mocktopus = { version = "0.8.0", optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could add it as a for-test feature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way like it is now is convenient as we may use mocktopus both from tests inside the crate and from other crates, without extra features, and at the same time avoiding building it into releases

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from tests inside the crate -> dev-deps section
from tests from outside/integration -> for-test flag to activate it, this has the downside though as u said will enable all and every extra test features we have, but it's a for-test build anyway so i wouldn't worry much about that and instead prioritize having less complex cfgs around the code base.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from tests from outside/integration -> for-test flag to activate it

I think, in this case mocktopus would be built into release what is not recommended for performance reasons.
The optional flag is a way to avoid this.

num-traits = "0.2"
parking_lot = { version = "0.12.0", features = ["nightly"] }
primitives = { path = "../mm2_bitcoin/primitives" }
Expand Down Expand Up @@ -160,6 +160,7 @@ winapi = "0.3"

[dev-dependencies]
mm2_test_helpers = { path = "../mm2_test_helpers" }
mocktopus = { version = "0.8.0" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wagyu-zcash-parameters = { version = "0.2" }
Expand Down
20 changes: 6 additions & 14 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ use mm2_core::mm_ctx::{MmArc, MmWeak};
use mm2_event_stream::behaviour::{EventBehaviour, EventInitStatus};
use mm2_number::bigdecimal_custom::CheckedDivision;
use mm2_number::{BigDecimal, BigUint, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
use rand::seq::SliceRandom;
use rlp::{DecoderError, Encodable, RlpStream};
use rpc::v1::types::Bytes as BytesJson;
Expand Down Expand Up @@ -1105,14 +1104,8 @@ impl Deref for EthCoin {

#[async_trait]
impl SwapOps for EthCoin {
async fn send_taker_fee(
&self,
fee_addr: &[u8],
dex_fee: DexFee,
_uuid: &[u8],
_expire_at: u64,
) -> TransactionResult {
let address = try_tx_s!(addr_from_raw_pubkey(fee_addr));
async fn send_taker_fee(&self, dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionResult {
let address = try_tx_s!(addr_from_raw_pubkey(self.dex_pubkey()));
self.send_to_address(
address,
try_tx_s!(wei_from_big_decimal(&dex_fee.fee_amount().into(), self.decimals)),
Expand Down Expand Up @@ -1179,7 +1172,6 @@ impl SwapOps for EthCoin {
validate_fee_impl(self.clone(), EthValidateFeeArgs {
fee_tx_hash: &tx.tx_hash(),
expected_sender: validate_fee_args.expected_sender,
fee_addr: validate_fee_args.fee_addr,
amount: &validate_fee_args.dex_fee.fee_amount().into(),
min_block_number: validate_fee_args.min_block_number,
uuid: validate_fee_args.uuid,
Expand Down Expand Up @@ -1517,7 +1509,6 @@ impl WatcherOps for EthCoin {
validate_fee_impl(self.clone(), EthValidateFeeArgs {
fee_tx_hash: &H256::from_slice(validate_fee_args.taker_fee_hash.as_slice()),
expected_sender: &validate_fee_args.sender_pubkey,
fee_addr: &validate_fee_args.fee_addr,
amount: &BigDecimal::from(0),
min_block_number: validate_fee_args.min_block_number,
uuid: &[],
Expand Down Expand Up @@ -2119,7 +2110,6 @@ impl WatcherOps for EthCoin {

#[async_trait]
#[cfg_attr(test, mockable)]
#[async_trait]
impl MarketCoinOps for EthCoin {
fn ticker(&self) -> &str { &self.ticker[..] }

Expand Down Expand Up @@ -2490,6 +2480,9 @@ impl MarketCoinOps for EthCoin {
MmNumber::from(1) / MmNumber::from(10u64.pow(pow))
}

#[inline]
fn should_burn_dex_fee(&self) -> bool { false }

fn is_trezor(&self) -> bool { self.priv_key_policy.is_trezor() }
}

Expand Down Expand Up @@ -5804,8 +5797,7 @@ fn validate_fee_impl(coin: EthCoin, validate_fee_args: EthValidateFeeArgs<'_>) -
let sender_addr = try_f!(
addr_from_raw_pubkey(validate_fee_args.expected_sender).map_to_mm(ValidatePaymentError::InvalidParameter)
);
let fee_addr =
try_f!(addr_from_raw_pubkey(validate_fee_args.fee_addr).map_to_mm(ValidatePaymentError::InvalidParameter));
let fee_addr = try_f!(addr_from_raw_pubkey(coin.dex_pubkey()).map_to_mm(ValidatePaymentError::InvalidParameter));
let amount = validate_fee_args.amount.clone();
let min_block_number = validate_fee_args.min_block_number;

Expand Down
4 changes: 0 additions & 4 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ fn validate_dex_fee_invalid_sender_eth() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 0,
uuid: &[],
Expand Down Expand Up @@ -622,7 +621,6 @@ fn validate_dex_fee_invalid_sender_erc() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &DEX_FEE_ADDR_RAW_PUBKEY,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 0,
uuid: &[],
Expand Down Expand Up @@ -662,7 +660,6 @@ fn validate_dex_fee_eth_confirmed_before_min_block() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &compressed_public,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 11784793,
uuid: &[],
Expand Down Expand Up @@ -701,7 +698,6 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
let validate_fee_args = ValidateFeeArgs {
fee_tx: &tx,
expected_sender: &compressed_public,
fee_addr: &DEX_FEE_ADDR_RAW_PUBKEY,
dex_fee: &DexFee::Standard(amount.into()),
min_block_number: 11823975,
uuid: &[],
Expand Down
10 changes: 3 additions & 7 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,7 @@ impl LightningCoin {
#[async_trait]
impl SwapOps for LightningCoin {
// Todo: This uses dummy data for now for the sake of swap P.O.C., this should be implemented probably after agreeing on how fees will work for lightning
async fn send_taker_fee(
&self,
_fee_addr: &[u8],
_dex_fee: DexFee,
_uuid: &[u8],
_expire_at: u64,
) -> TransactionResult {
async fn send_taker_fee(&self, _dex_fee: DexFee, _uuid: &[u8], _expire_at: u64) -> TransactionResult {
Ok(TransactionEnum::LightningPayment(PaymentHash([1; 32])))
}

Expand Down Expand Up @@ -1253,6 +1247,8 @@ impl MarketCoinOps for LightningCoin {
// Todo: doesn't take routing fees into account too, There is no way to know the route to the other side of the swap when placing the order, need to find a workaround for this
fn min_trading_vol(&self) -> MmNumber { self.min_tx_amount().into() }

fn should_burn_dex_fee(&self) -> bool { false }

fn is_trezor(&self) -> bool { self.platform.coin.is_trezor() }
}

Expand Down
Loading
Loading