rippled icon indicating copy to clipboard operation
rippled copied to clipboard

Add MPT support to DEX

Open gregtatcam opened this issue 11 months ago • 12 comments

High Level Overview of Change

Add MPT support to DEX

Context of Change

Implements XLS-82d

Adds MPT support for the following transactions:

  • Payment
  • OfferCreate
  • CheckCash
  • All AMM transactions
  • Pathfinding

Retires FlowCross feature.

Type of Change

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Refactor (non-breaking change that only restructures code)
  • [ ] Performance (increase or change in throughput and/or latency)
  • [x] Tests (you added tests for code that already exists, or your new feature included in this PR)
  • [ ] Documentation update
  • [ ] Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • [ ] Release

API Impact

  • [ ] Public API: New feature (new methods and/or new fields)
  • [x] Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • [ ] libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • [ ] Peer protocol change (must be backward compatible or bump the peer protocol version)

Test Plan

Extended MPToken unit-test to test for basic MPT interactions with DEX.

gregtatcam avatar Feb 12 '25 10:02 gregtatcam

Codecov Report

:x: Patch coverage is 90.49128% with 120 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 78.8%. Comparing base (b33b506) to head (f4750bf). :warning: Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
src/xrpld/app/paths/PathRequest.cpp 75.0% 24 Missing :warning:
src/xrpld/app/paths/Pathfinder.cpp 92.9% 12 Missing :warning:
src/libxrpl/protocol/STParsedJSON.cpp 78.4% 11 Missing :warning:
include/xrpl/protocol/AmountConversions.h 73.7% 10 Missing :warning:
src/libxrpl/ledger/View.cpp 91.9% 10 Missing :warning:
src/xrpld/app/ledger/OrderBookDB.cpp 74.1% 7 Missing :warning:
include/xrpl/protocol/Book.h 62.5% 6 Missing :warning:
src/xrpld/app/misc/detail/AMMUtils.cpp 94.0% 5 Missing :warning:
src/libxrpl/protocol/Indexes.cpp 90.2% 4 Missing :warning:
src/xrpld/app/misc/AMMHelpers.h 71.4% 4 Missing :warning:
... and 15 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #5285     +/-   ##
=========================================
+ Coverage     78.6%   78.8%   +0.2%     
=========================================
  Files          818     825      +7     
  Lines        68938   70615   +1677     
  Branches      8242    8332     +90     
=========================================
+ Hits         54171   55616   +1445     
- Misses       14767   14999    +232     
Files with missing lines Coverage Δ
include/xrpl/ledger/PaymentSandbox.h 100.0% <100.0%> (ø)
include/xrpl/protocol/AMMCore.h 100.0% <ø> (ø)
include/xrpl/protocol/Concepts.h 100.0% <100.0%> (ø)
include/xrpl/protocol/MPTAmount.h 90.9% <100.0%> (-9.1%) :arrow_down:
include/xrpl/protocol/MPTIssue.h 100.0% <100.0%> (ø)
include/xrpl/protocol/STObject.h 93.1% <ø> (ø)
include/xrpl/protocol/TER.h 100.0% <ø> (ø)
include/xrpl/protocol/detail/ledger_entries.macro 100.0% <ø> (ø)
include/xrpl/protocol/detail/transactions.macro 100.0% <ø> (ø)
src/libxrpl/protocol/Asset.cpp 100.0% <100.0%> (ø)
... and 102 more

... and 8 files with indirect coverage changes

Impacted file tree graph

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Feb 12 '25 15:02 codecov[bot]

haven't reviewed the changes but one invariant would be good to have is to ensure that the amount changed for OutstandingBalance in MPTokenIssuance should equal the net change of all the MPTokens modified in the transaction

shawnxie999 avatar Feb 18 '25 23:02 shawnxie999

Most recent changes are breaking the unit-tests @gregtatcam

vlntb avatar Jun 12 '25 14:06 vlntb

There there are several Transactors that check have checks for featureMPTokensV1. Should those Transactors also check for featureMPTokensV2?

vlntb avatar Jun 12 '25 15:06 vlntb

Most recent changes are breaking the unit-tests @gregtatcam

It runs with no errors on my local MAC. I'm not too worried for now about CI failures.

gregtatcam avatar Jun 12 '25 15:06 gregtatcam

There there are several Transactors that check have checks for featureMPTokensV1. Should those Transactors also check for featureMPTokensV2?

There are cases where only V1 support is required like Clawback, Escrow, and SAV.

gregtatcam avatar Jun 12 '25 15:06 gregtatcam

add a comment here because I can not add on an unchanged line:

in AMMWithdraw::equalWithdrawLimit, amount2Withdraw is calculated twice, but the first calculation is not necessary.

yinyiqian1 avatar Jun 20 '25 18:06 yinyiqian1

add a comment here because I can not add on an unchanged line:

in AMMWithdraw::equalWithdrawLimit, amount2Withdraw is calculated twice, but the first calculation is not necessary.

frac is recalculated. Therefore, amount2Withdraw has to be adjusted.

gregtatcam avatar Jul 09 '25 14:07 gregtatcam

In AssetCache.cpp three XRPL_ASSERTs need to be updated from

  82,30:                     "ripple::RippleLineCache::getRippleLines : maximum lines");
  104,22:             "ripple::RippleLineCache::getRippleLines : null lines");
  117,18:         "ripple::RippleLineCache::getRippleLines : null or nonempty lines");

to

82,30:                     "ripple::AssetCache::getRippleLines : maximum lines");
  104,22:             "ripple::AssetCache::getRippleLines : null lines");
  117,18:         "ripple::AssetCache::getRippleLines : null or nonempty lines");

vlntb avatar Jul 10 '25 10:07 vlntb

add a comment here because I can not add on an unchanged line: in AMMWithdraw::equalWithdrawLimit, amount2Withdraw is calculated twice, but the first calculation is not necessary.

frac is recalculated. Therefore, amount2Withdraw has to be adjusted.

It seems the first amount2Withdraw is not used, although the frac is recalculated and used by the second amount2Withdraw

yinyiqian1 avatar Jul 29 '25 15:07 yinyiqian1

[nit]: Once the unit-testing is sorted this comment in the PR description need to updated:

Significant number of unit-tests must be added to test all aspects of MPT interactions with DEX. Essentially all current unit-tests designed to test IOU interactions with DEX must be replicated for MPT. This is work in progress.

vlntb avatar Aug 21 '25 18:08 vlntb

Can we add two basic tests for PermissionedDEX with MPTs:

  1. A domain payment should only consume a USD/MPT offer with a domain. It must not consume a regular USD/MPT offer.
  2. A hybrid USD/MPT domain offer should still be consumable by a regular payment.

We don’t need extensive test coverage for this right now (though that would be a good improvement for the future).

shawnxie999 avatar Sep 02 '25 17:09 shawnxie999