Skip to content

feat(dex-fee): update fee rate, migrate fee addresses and default netid#2710

Open
shamardy wants to merge 16 commits intodevfrom
feat/update-dex-fee-addresses-and-rate
Open

feat(dex-fee): update fee rate, migrate fee addresses and default netid#2710
shamardy wants to merge 16 commits intodevfrom
feat/update-dex-fee-addresses-and-rate

Conversation

@shamardy
Copy link
Collaborator

@shamardy shamardy commented Jan 27, 2026

Summary

Updates the global DEX fee configuration:

  • Change fee rate from ~0.129% (1/777) to 2% for standard trades
  • GLEEC fee discount: 1% fee rate (50% off) when either base or rel is GLEEC
  • Update DEX fee pubkey to 0348685437335ec43ba6211caf848576ca3d34abbe9e089f861471b4ed9ee9bbd1
  • Update Z-address for ZCash/ARRR shielded fee collection
  • Disable burn feature (preserve code for future re-enablement)
  • Remove KMD fee discount/exemption, replace with GLEEC discount

Netid Migration

  • Change default netid from 8762 to 6133 ("GLEE" in leet-speak)
  • Add 8762 to deprecated netid list (same pattern as 77778762 migration)
  • Update adex_cli default and help messages

Breaking Changes

⚠️ This release is incompatible with older client versions.

  • Swaps between clients running different versions will fail validation (fee address mismatch)
  • Clients on netid 8762 will not connect to clients on netid 6133
  • All GUIs and clients must be updated together when this is deployed

Addresses Derived from New Pubkey

Chain Address
GLEEC RR1RS8UFiufoLe9hwZgSBTjutiZvKV62v5
BTC 1GjEMcay85sEGdnWUPhK5wQi8T7KkBvQG2
EVM 0x2CA50934E704624e3e035056d066C887abc123bd

Z-Address: zs18egqw99pw5846jfrqntu4neup4hjjchx874j6krmeq88yh4adws9djmuplg5hfx9f0wdsscgr5j

TODOs

  • Netid change: Deploying the new fee pubkey requires a netid change so old and new clients don't mix on the same network
  • SIA DEX fee address: Add SIA dex fee address once SIA is released (in GUI SIA PR / test wallet)

Fee Discount

The dex_fee_rate(base, rel) function applies a ticker-based discount:

  • Standard rate: 2% for all trades
  • GLEEC discount: 1% when either base or rel is GLEEC (50% off)
  • In test mode, MYCOIN_FEE_DISCOUNT env var adds MYCOIN to the discount list

The MaxTakerVolRequest.trade_with field is restored to active use for pair-aware fee calculation.


Test Updates

All tests have been updated to work with the new configuration:

Fee Rate Changes (2% standard, 1% GLEEC discount)

  • test_dex_fee_amount - Updated expected values for 2% rate, added GLEEC discount cases
  • test_max_taker_vol_from_available - Updated max volume calculations with GLEEC boundary values
  • test_with_burn_fee_calculation - Verifies 2% rate and 75/25 burn split for non-discount coins
  • test_gleec_taker_dex_fee_calculation - Verifies 1% GLEEC discount with burn split
  • test_dex_fee_from_taker_coin_discount - Verifies MYCOIN_FEE_DISCOUNT env var behavior
  • Docker tests (utxo_swaps_v1_tests, swap_proto_v2_tests) - Updated fee expectations

V2 Swap NoFee

  • NoFee branches for GLEEC in V2 maker/taker swaps are commented out with NOTE comments for future reference, replaced by the discount-based fee calculation

Address Validation Tests

Tests that validate historical transaction fixtures now mock the DEX fee address to return the legacy pubkey:

  • qrc20_tests::test_validate_fee
  • tendermint_coin::validate_taker_fee_test / validate_taker_fee_with_burn_test
  • utxo_tests::test_validate_old_fee_tx / test_validate_fee_bch_70_bytes_signature
  • z_unit_tests::test_validate_zcoin_dex_fee

ZCoin Changes

  • Added mockable dex_fee_addr() and dex_burn_addr() methods for test mocking
  • Docker tests now use Standard fees (burn disabled)
  • Unit tests use mocking to test WithBurn validation with legacy addresses

Swap Watcher Tests

  • Updated balance assertions to account for non-refundable 2% DEX fee

Legacy Constants

  • Moved DEX_FEE_ADDR_PUBKEY_LEGACY and DEX_FEE_ADDR_RAW_PUBKEY_LEGACY to mm2_test_helpers crate

🤖 Generated with Claude Code

shamardy and others added 7 commits January 27, 2026 04:04
- Update DEX_FEE_ADDR_PUBKEY to new value
- Set DEX_BURN_ADDR_PUBKEY to same as fee address (burn disabled)
- Add TODO comment for ED25519 pubkey (Sia)
- Update abbreviated pubkeys in AGENTS.md documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update DEX fee and burn Z-addresses to new value. Burn is disabled
by setting burn address to same value as fee address.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Disable all burn mechanisms - fees now go entirely to DEX fee address:
- should_burn_directly() returns false (was KMD-specific OP_RETURN burn)
- should_burn_dex_fee() returns false with updated doc comment

Code preserved for potential future re-enablement.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- dex_fee_rate() now returns 2% flat for all trades (was ~0.129% with
  KMD discount at ~0.116%). Original discount logic preserved as
  comments for reference, with instructions for adapting to 2% base.
- Simplified dex_fee_rate() signature (no parameters needed for flat rate)
- Removed KMD NoFee exemption from swap v2 state machines. Old logic
  preserved as comments with instructions for re-enabling (e.g., GLEEC).
- Cleaned up TODO in should_burn_dex_fee()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add #[ignore] to tests that verify KMD discount behavior which has been
removed. The fee is now 2% flat for all trades.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update "wrong pubkey" test values in qrc20_tests.rs to use the new
DEX fee pubkey base with intentionally wrong ending (bbd0 instead of
bbd1) to maintain test validation logic.

Note: z_coin_tests.rs not updated as it validates historical transaction
data that actually went to the old z-address.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Now that the DEX fee is a flat 2% for all trades, the base/rel ticker
parameters used for KMD discount calculation are no longer needed.

Removed parameters:
- DexFee::new_from_taker_coin: maker_ticker
- DexFee::new_with_taker_pubkey: maker_ticker
- max_taker_vol_from_available: base, rel
- calc_max_taker_vol: other_coin

MaxTakerVolRequest.trade_with kept with deprecation comment for
backward compatibility with existing API clients.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes clippy::test_attr_in_doctest warning introduced in newer Rust.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@shamardy shamardy requested a review from mariocynicys January 27, 2026 03:26
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good overall, some question inline.

shamardy and others added 4 commits January 29, 2026 14:04
- Update test_dex_fee_amount and test_max_taker_vol_from_available
  for 2% flat fee rate (removed KMD discount)
- Fix address validation tests by mocking dex_fee_addr/dex_pubkey
  to return legacy addresses for historical transaction fixtures
- Add mockable dex_fee_addr() and dex_burn_addr() methods to ZCoin
  for proper WithBurn validation testing with different addresses
- Update docker tests for 2% fee rate and Standard fees (burn disabled)
- Move legacy DEX fee constants to mm2_test_helpers crate
- Update swap watcher tests to account for non-refundable DEX fee

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename test_kmd_taker_dex_fee_calculation to test_with_burn_fee_calculation
- Rename test_dex_fee_from_taker_coin_discount to test_uniform_fee_rate_no_discounts
- Remove #[ignore] - tests now verify current behavior
- Update assertions to test uniform 2% fee rate (no KMD discount)
- Add TODO comments for adding discount tests when implemented for GLEEC

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Restore the TODO comment reminding that if burn is re-enabled,
negotiation version checking needs to be implemented to prevent
breaking swaps between different client versions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- z_coin: use correct legacy burn z-address (was invalid checksum)
- tendermint: add legacy burn pubkey constant and mock burn_pubkey()
- qrc20: increase dust tolerance from 0.001 to 0.002 for 2% fee rate

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@shamardy shamardy requested a review from mariocynicys January 29, 2026 13:05
mariocynicys
mariocynicys previously approved these changes Jan 30, 2026
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes. LGTM!

For the tests that still use the old dex address. Maybe we better invest in moving them to docker instead of replaying the fixtures needed for those tests with the new dex address.

@github-actions github-actions bot added the [] label Feb 3, 2026
@shamardy shamardy removed the [] label Mar 4, 2026
Restore the ticker-based fee discount mechanism that was removed when
switching to a 2% flat rate. GLEEC trades now get a 50% discount (1%
fee rate) while all other pairs use the standard 2% rate. The discount
applies when either base or rel is GLEEC.

Key changes:
- Restore dex_fee_rate(base, rel) signature with GLEEC discount logic
- Thread maker_ticker parameter through all DexFee call sites
- Comment out (not remove) NoFee branches in V2 swaps for future reference
- Add GLEEC-specific test coverage alongside existing burn fee tests
- Restore MaxTakerVolRequest.trade_with field from deprecated to active

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
shamardy and others added 2 commits March 5, 2026 17:55
…iscount rate

The test sets MYCOIN_FEE_DISCOUNT env var and uses trade_with: "MYCOIN",
which triggers the 1% discount rate. The expected denominator should be
101000000 (1.01) not 102000000 (1.02).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Migrate the default P2P network ID to 6133 ("GLEE" in leet-speak) as
part of the GLEEC rebranding. Add 8762 to the deprecated netid list,
following the same pattern used for the 7777 → 8762 migration.
@shamardy shamardy changed the title feat(dex-fee): update fee rate to 2% and migrate to new fee addresses feat(dex-fee): update fee rate, migrate fee addresses and default netid Mar 5, 2026
@shamardy shamardy requested a review from mariocynicys March 5, 2026 16:18
Copy link
Collaborator

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

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

was really smart not to wipe out the discount logic xD
few queries, looks good otherwise.

Comment on lines +4192 to +4193
// 1% fee (50% discount)
BigRational::new(1.into(), 100.into()).into()
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think discounting more than 50% (e.g. 70%) would incentives more ppl to perform the trades with GLEEC as an intermediate coin.

currently there is no incentive to do such a thing since that requires two swaps each costing 1% fee, so still 2% total (+ more chain fees).

Comment on lines +2384 to +2387
/// Tests that GLEEC trades get a 50% fee discount (1% vs 2% standard rate)
/// and that the 75/25 fee/burn split is applied on the discounted amount.
#[test]
fn test_gleec_taker_dex_fee_calculation() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this test mainly checks the burn interaction with the discount/non-discount coin variations. i think this should be made clearer in the test name.

Comment on lines +2437 to 2439
/// Tests that MYCOIN gets GLEEC-like discount when MYCOIN_FEE_DISCOUNT env is set.
#[test]
fn test_dex_fee_from_taker_coin_discount() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

and what's the point of such a test? what's the point of testing if an env variable (that's used in tests) work as expected.

edit: i mean, if it doesn't work as expected, the relevant tests will just fail.

Comment on lines +2338 to 2345
/// Tests WithBurn fee calculation when burn is enabled via mocking.
/// Verifies that non-discount coins use the same 2% fee rate and correct 75/25 fee/burn split.
/// Uses KMD and RICK (neither is a discount ticker) to avoid env var race with other tests.
#[test]
fn test_kmd_taker_dex_fee_calculation() {
std::env::set_var("MYCOIN_FEE_DISCOUNT", "");

fn test_with_burn_fee_calculation() {
let kmd = coins::TestCoin::new("KMD");
TestCoin::should_burn_dex_fee.mock_safe(|_| MockResult::Return(true));
let (kmd_fee_amount, kmd_burn_amount) = match DexFee::new_from_taker_coin(&kmd, "ETH", &MmNumber::from(6150)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: i think these tests mainly tests DexFee::new_from_taker_coin, why are they in lp_swap.rs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants