Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
193 commits
Select commit Hold shift + click to select a range
a0ee987
Add MPT support to DEX:
gregtatcam Feb 11, 2025
7a42ba9
Extend AMM/MPT test framework to facilitate MPT/DEX unit-tests
gregtatcam Feb 27, 2025
be413c8
Address reviewer's feedback
gregtatcam May 20, 2025
069a787
Merge with the latest develop
gregtatcam May 20, 2025
4a41f89
Fix clang format
gregtatcam May 20, 2025
452b4cd
Fix clang format
gregtatcam May 20, 2025
2c02241
Fix missing initializer warning
gregtatcam May 20, 2025
f4b871f
Don't create MPToken for issuer account on AMM Withdraw and Cash Check.
gregtatcam May 29, 2025
b0b731d
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jun 9, 2025
84d46b5
Resolve merge conflicts.
gregtatcam Jun 9, 2025
480e0e8
Fix clang-format and compile error.
gregtatcam Jun 9, 2025
f2613c5
Extend/add unit-tests.
gregtatcam Jun 10, 2025
3f6c50d
Fix clang format
gregtatcam Jun 10, 2025
8407f42
Fix ambiguous call resolution on some platforms.
gregtatcam Jun 10, 2025
eea4420
Implement MPT PaymentSandbox credit/debit logic. Split balanceHook() …
gregtatcam Jun 23, 2025
966d166
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jun 24, 2025
958aa46
Fix temBAD_MPT error definition.
gregtatcam Jun 24, 2025
3ceb9d4
Add MPT/IOU mix to the tests.
gregtatcam Jul 3, 2025
13b8209
Remove unsupported OwnerPaysFee from FlowMPT_test.
gregtatcam Jul 5, 2025
f7b50be
Fix clang-format and compile error
gregtatcam Jul 5, 2025
0b14cd2
Add MPT/IOU mix to MPTOffer_test.
gregtatcam Jul 7, 2025
3409c9f
Fix clang format
gregtatcam Jul 7, 2025
d0bae41
Add MPT/IOU mix to CrossingLimitsMPT_test.
gregtatcam Jul 7, 2025
bdf3256
Fix linux compile error
gregtatcam Jul 7, 2025
0c3eb0b
Add MPT/IOU mix to PayStrandMPT_test.
gregtatcam Jul 8, 2025
6b2682f
Fix unit tests for different reference fee (DUNIT_TEST_REFERENCE_FEE)
gregtatcam Jul 8, 2025
d551e11
Remove fset DefaultRipple from issueHelperIOU().
gregtatcam Jul 9, 2025
229909f
Return actual amm balance in ammAccountHolds() (no balance hook).
gregtatcam Jul 11, 2025
70b0001
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jul 11, 2025
aa5756c
Add LockedAmount to MPT invariant.
gregtatcam Jul 11, 2025
609f4cb
Address reviewers feedback
gregtatcam Jul 12, 2025
77ea432
Add domain to PathMPT_test
gregtatcam Jul 12, 2025
4374314
Add IOU/MPT mix to FlowMPT_test
gregtatcam Jul 12, 2025
d4749d7
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jul 15, 2025
d8251f9
Resolve merge conflicts
gregtatcam Jul 15, 2025
d31918a
Change isMPTAllowed() return to tecLOCKED if locked.
gregtatcam Jul 15, 2025
90cdd84
Change isMPTAllowed() return to tecLOCKED if locked locally.
gregtatcam Jul 15, 2025
44ea9af
Fix check for locked MPT in MPTEndpoint.
gregtatcam Jul 16, 2025
3877f2b
Fix check for locked MPT in BookStep.
gregtatcam Jul 17, 2025
cfabef9
Fix single AMMWithdraw when another asset is locked.
gregtatcam Jul 17, 2025
5d27adb
AMMMPT, AMMExtendedMPT and AMMClawbackMPT (#54)
yinyiqian1 Jul 18, 2025
73642e9
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jul 25, 2025
00c787d
Resolve merge conflicts
gregtatcam Jul 25, 2025
3eeb83d
Fix compile error.
gregtatcam Jul 25, 2025
2b05e1f
Fix declaration order compile errors.
gregtatcam Jul 26, 2025
2a068f4
Fix unit-tests with high reference fee
gregtatcam Jul 26, 2025
efb1dd5
Address audit/reviewer's feedback.
gregtatcam Jul 31, 2025
21ab036
Add helper functions to return jv for MPT transactions.
gregtatcam Aug 5, 2025
523268f
Remove not needed functions.
gregtatcam Aug 5, 2025
0af3897
Fix added but not-implemented function.
gregtatcam Aug 5, 2025
525b58a
Add functions returning Json::Value for AMM transactions.
gregtatcam Aug 12, 2025
979dbb3
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Aug 12, 2025
29cb622
Resolve merge conflict.
gregtatcam Aug 12, 2025
92d035a
Retire featureCheckCashMakesTrustLine.
gregtatcam Aug 13, 2025
47c55fe
Minor refactoring
gregtatcam Aug 13, 2025
e820332
Fix ahIGNORE_AUTH/ahZERO_IF_UNAUTHORIZED and minor refactoring.
gregtatcam Aug 14, 2025
891e17a
Simplify EitherAmount, remove AmountSpec. Plus minor refactoring/typo…
gregtatcam Aug 15, 2025
4cb964d
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 1, 2025
2f74ce5
Replace STAmount::setIssuer(...) with type safer STAmount::get<Issue>…
gregtatcam Sep 2, 2025
187dbfc
Address reviewer's feedback - extend the unit-tests.
gregtatcam Sep 5, 2025
770efc1
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 8, 2025
65e44e4
Fix format
gregtatcam Sep 8, 2025
637234b
Remove setIssuer() from STAmount
gregtatcam Sep 8, 2025
9a38024
Handle OutstandingAmount overflow threshold.
gregtatcam Sep 11, 2025
192cff5
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 15, 2025
1c3e925
Fix merge conflicts
gregtatcam Sep 15, 2025
1a9a679
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 16, 2025
2929dc5
Fix merge conflicts. Extend mutable MPT unit-test.
gregtatcam Sep 16, 2025
fae6b35
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 17, 2025
f6f4ceb
Fix MPTSet initialization order
gregtatcam Sep 17, 2025
6386ccc
Rename isMPTTxAllowed() and isMPTDEXAllowed() to checkMPTTxAllowed() …
gregtatcam Sep 18, 2025
ac3342a
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 19, 2025
461416b
Fix merge conflicts. Remove OutstandingAmount negation in Env::balanc…
gregtatcam Sep 19, 2025
2e07609
Make Env.balance() for an MPT issuer negative. This is consistent wit…
gregtatcam Sep 30, 2025
2bd8a25
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Sep 30, 2025
8e646db
Fix merge conflicts.
gregtatcam Sep 30, 2025
dc13b03
Delete AMM's MPToken on auto AMM delete if succeed in deleting all tr…
gregtatcam Oct 1, 2025
46076a8
Replace checkMPTTxAllowed() with checkMPTDEXAllowed() in CreateOffer.
gregtatcam Oct 2, 2025
6f01d5b
Address reviewer's feedback.
gregtatcam Oct 8, 2025
a743acd
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Oct 14, 2025
6c929df
Resolve merge-conflicts.
gregtatcam Oct 14, 2025
56e154a
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Oct 23, 2025
632f947
Fix merge conflicts.
gregtatcam Oct 23, 2025
878d22d
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Oct 28, 2025
a514736
Fix merge conflicts.
gregtatcam Oct 28, 2025
1ab6ee4
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Oct 31, 2025
b96273f
Fix merge conflicts.
gregtatcam Oct 31, 2025
921f850
Feature/mpt v2e visit refactor (#56)
gregtatcam Nov 3, 2025
a4bfa5d
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 5, 2025
a72c343
Fix merge conflicts
gregtatcam Nov 5, 2025
8dfbe8a
Fix mulRoundImpl() for MPT and roundUp true.
gregtatcam Nov 10, 2025
107a675
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 12, 2025
4bfd211
Fix merge conflicts.
gregtatcam Nov 12, 2025
4335216
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 17, 2025
05f21f1
Fix merge conflicts.
gregtatcam Nov 17, 2025
a4a69cb
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 21, 2025
31b6deb
Fix clang format
gregtatcam Nov 21, 2025
4aa3603
Update levelization
gregtatcam Nov 21, 2025
7faa6e7
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 25, 2025
7884749
Fix merge conflicts
gregtatcam Nov 25, 2025
4775f9d
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Nov 29, 2025
d470f26
Remove copyright and other XRPL refactoring
gregtatcam Nov 30, 2025
f4750bf
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Dec 2, 2025
0f046bb
Merge branch 'develop' into feature/mpt-v2e (Lending Protocol)
gregtatcam Dec 3, 2025
8c948e0
Fix merge conflicts
gregtatcam Dec 4, 2025
094945a
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Dec 12, 2025
870c085
Fix merge conflicts and xrpl refactoring
gregtatcam Dec 12, 2025
628dbec
Fix accountHolds() (0) and accountFunds() (available to issue) balanc…
gregtatcam Dec 12, 2025
dfe824a
Fix xrpl refactoring
gregtatcam Dec 12, 2025
891692f
Use integral() instead of xrp|mpt check in arithmetics.
gregtatcam Dec 15, 2025
ebdfd35
Use integral() in mulRoundImpl() for xrp|mpt. Update unit-tests.
gregtatcam Dec 16, 2025
d4eaafc
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Dec 16, 2025
3f541cd
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 2, 2026
73b4ac9
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 7, 2026
753d134
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 9, 2026
1436a7c
Fix merge conflicts.
gregtatcam Jan 9, 2026
6e47bc0
Fix cspell errors.
gregtatcam Jan 9, 2026
b2bc829
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 12, 2026
8e82ce8
Replace some std::visit with Asset::visit.
gregtatcam Jan 12, 2026
f7b7d30
Fix cspell errors
gregtatcam Jan 12, 2026
faffb1e
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 13, 2026
c2322af
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 13, 2026
db90332
Fix merge conflicts (Lending Protocol - #6102)
gregtatcam Jan 13, 2026
5125802
Update accountHolds() and accountFunds().
gregtatcam Jan 14, 2026
6acbe14
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 14, 2026
9fce575
Update unit-tests due to extended Number precision. Add AMMWithdraw v…
gregtatcam Jan 16, 2026
f2fe579
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Jan 21, 2026
728cc37
Address reviewer's feedback
gregtatcam Jan 29, 2026
b0045ff
Update TickSize logic for MPT (#57)
gregtatcam Feb 2, 2026
9df5cbc
Fix ledger_entry for AMM with MPT (#58)
gregtatcam Feb 3, 2026
8a862c7
Simplify checkMPTDEX() and checkMPTTx(). (#59)
gregtatcam Feb 9, 2026
c41ab0c
Merge commit '92046785d1fea5f9efe5a770d636792ea6cab78b' into feature/…
gregtatcam Feb 10, 2026
d3cd4d3
Merge branch 'develop' into feature/mpt-v2e (100 width)
gregtatcam Feb 22, 2026
9492d34
Fix merge conflicts, format, spelling,
gregtatcam Feb 22, 2026
6bdc702
Fix non-unity build
gregtatcam Mar 7, 2026
91bbbe4
Merge branch 'feature/mpt-v2e-merge-line-width-100' into feature/mpt-v2e
gregtatcam Mar 7, 2026
9144970
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 7, 2026
673e817
Fix merge conflicts.
gregtatcam Mar 8, 2026
c16df34
Fix Copilot warnings.
gregtatcam Mar 8, 2026
b838206
Fix MPTUtils.h include path.
gregtatcam Mar 9, 2026
3448ebc
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 10, 2026
9b5db68
Move ValidPayment to ValidMPTPayment.
gregtatcam Mar 10, 2026
85f72c7
Address MPTLock for takerBuys in BookStep.
gregtatcam Mar 13, 2026
9af3792
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 14, 2026
c208a40
Fix merge conflicts
gregtatcam Mar 14, 2026
5c7da0e
Update MPT invariants comments.
gregtatcam Mar 21, 2026
228aec4
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 27, 2026
188ea4b
Fix merge conflicts
gregtatcam Mar 29, 2026
bd9e852
Move MPTUtils to MPTokenHelpers
gregtatcam Mar 29, 2026
3329d3c
Fix clang-tidy errors.
gregtatcam Mar 29, 2026
c08ed57
Fix clang-tidy errors.
gregtatcam Mar 29, 2026
3ddceca
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 30, 2026
bea6fc4
Fix format.
gregtatcam Mar 30, 2026
adbd06f
Address reviewer's feedback
gregtatcam Mar 30, 2026
62cb782
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 30, 2026
adabcac
Fix clang-tidy errors
gregtatcam Mar 30, 2026
06b6c5c
Address AI feedback
gregtatcam Mar 31, 2026
4485977
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 31, 2026
4e3d3ef
Fix clang-format
gregtatcam Mar 31, 2026
36dec12
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 31, 2026
97189fb
Fix clang-format
gregtatcam Mar 31, 2026
07b915f
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Mar 31, 2026
4ab4d7a
Fix clang-tidy const errors.
gregtatcam Mar 31, 2026
1ef173b
Minor refactorings
gregtatcam Apr 1, 2026
583cbdf
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Apr 1, 2026
50c6914
Fix clang-tidy errors
gregtatcam Apr 1, 2026
fea848b
Enforce ValidTaker type restriction on both TakerPays and TakerGets.
gregtatcam Apr 1, 2026
8baf529
Fix clang-tidy const
gregtatcam Apr 1, 2026
281a7f9
Fix comment
gregtatcam Apr 1, 2026
b1bd936
Handle overflow in MPTInvariant and other fixes.
gregtatcam Apr 2, 2026
b6d9424
Remove mptV2 amendment check in requireAuth().
gregtatcam Apr 2, 2026
a277cd1
Fix clang-tidy error
gregtatcam Apr 2, 2026
e98265c
Accumulate holder's debit on DeferredCredits::apply().
gregtatcam Apr 3, 2026
05d7500
Make an offer with locked takerBuys MPT unfunded.
gregtatcam Apr 3, 2026
0906939
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Apr 3, 2026
2588518
Replace tecFROZEN with tecLOCKED in CheckCreate/Cash.
gregtatcam Apr 6, 2026
e4f3a57
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Apr 6, 2026
454a289
Add ValidMPTTransfer invariant.
gregtatcam Apr 6, 2026
0fee8ba
Replace canTrade with canTransfer in CheckCreate/Cash (Check is not D…
gregtatcam Apr 6, 2026
5b5f74a
Update src/libxrpl/tx/invariants/MPTInvariant.cpp
gregtatcam Apr 7, 2026
4657b2a
Address reviewer's feedback.
gregtatcam Apr 7, 2026
7c0bed1
Merge branch 'develop' into feature/mpt-v2e
gregtatcam Apr 7, 2026
ec1032c
Fix merge conflicts.
gregtatcam Apr 7, 2026
a5a8cf0
Add a unit-test to address MPT/MPT + tecINCOMPLETE invariant combination
gregtatcam Apr 7, 2026
8e12934
Change tecFROZEN to tecLOCKED for locked MPT.
gregtatcam Apr 7, 2026
294c821
Merge branch 'feature/mpt-v2e' into feature/mpt-v2e-assorted-fixes
gregtatcam Apr 7, 2026
0156cfd
Fix double adjustOwnerCount() in AMMWithdraw.
gregtatcam Apr 7, 2026
dfcad69
feat: Add MPT support to DEX (#5285)
gregtatcam Apr 8, 2026
dc95c1a
Uncomment the tests
gregtatcam Apr 8, 2026
7793b5f
refactor: Combine `AMMHelpers` and `AMMUtils` (#6733)
mvadari Apr 8, 2026
d52dd29
fix: Address AI reviewer comments for Permission Delegation (#6675)
yinyiqian1 Apr 8, 2026
56c9d1d
fix: Add description for `terLOCKED` error (#6811)
gregtatcam Apr 8, 2026
3925f97
Merge branch 'develop' into feature/mpt-v2e-assorted-fixes
gregtatcam Apr 9, 2026
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
96 changes: 96 additions & 0 deletions include/xrpl/ledger/helpers/AMMHelpers.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#pragma once

#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/Number.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/Sandbox.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
#include <xrpl/ledger/helpers/TokenHelpers.h>
#include <xrpl/protocol/AMMCore.h>
#include <xrpl/protocol/AmountConversions.h>
#include <xrpl/protocol/Feature.h>
Expand All @@ -11,6 +16,7 @@
#include <xrpl/protocol/Quality.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>

namespace xrpl {

Expand Down Expand Up @@ -713,4 +719,94 @@ adjustFracByTokens(
STAmount const& tokens,
Number const& frac);

/** Get AMM pool balances.
*/
std::pair<STAmount, STAmount>
ammPoolHolds(
ReadView const& view,
AccountID const& ammAccountID,
Asset const& asset1,
Asset const& asset2,
FreezeHandling freezeHandling,
AuthHandling authHandling,
beast::Journal const j);

/** Get AMM pool and LP token balances. If both optIssue are
* provided then they are used as the AMM token pair issues.
* Otherwise the missing issues are fetched from ammSle.
*/
Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
ammHolds(
ReadView const& view,
SLE const& ammSle,
std::optional<Asset> const& optAsset1,
std::optional<Asset> const& optAsset2,
FreezeHandling freezeHandling,
AuthHandling authHandling,
beast::Journal const j);

/** Get the balance of LP tokens.
*/
STAmount
ammLPHolds(
ReadView const& view,
Asset const& asset1,
Asset const& asset2,
AccountID const& ammAccount,
AccountID const& lpAccount,
beast::Journal const j);

STAmount
ammLPHolds(
ReadView const& view,
SLE const& ammSle,
AccountID const& lpAccount,
beast::Journal const j);

/** Get AMM trading fee for the given account. The fee is discounted
* if the account is the auction slot owner or one of the slot's authorized
* accounts.
*/
std::uint16_t
getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account);

/** Returns total amount held by AMM for the given token.
*/
STAmount
ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset);

/** Delete trustlines to AMM. If all trustlines are deleted then
* AMM object and account are deleted. Otherwise tecINCOMPLETE is returned.
*/
TER
deleteAMMAccount(Sandbox& view, Asset const& asset, Asset const& asset2, beast::Journal j);

/** Initialize Auction and Voting slots and set the trading/discounted fee.
*/
void
initializeFeeAuctionVote(
ApplyView& view,
std::shared_ptr<SLE>& ammSle,
AccountID const& account,
Asset const& lptAsset,
std::uint16_t tfee);

/** Return true if the Liquidity Provider is the only AMM provider, false
* otherwise. Return tecINTERNAL if encountered an unexpected condition,
* for instance Liquidity Provider has more than one LPToken trustline.
*/
Expected<bool, TER>
isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount);

/** Due to rounding, the LPTokenBalance of the last LP might
* not match the LP's trustline balance. If it's within the tolerance,
* update LPTokenBalance to match the LP's trustline balance.
*/
Expected<bool, TER>
verifyAndAdjustLPTokenBalance(
Sandbox& sb,
STAmount const& lpTokens,
std::shared_ptr<SLE>& ammSle,
AccountID const& account);

} // namespace xrpl
108 changes: 0 additions & 108 deletions include/xrpl/ledger/helpers/AMMUtils.h
Original file line number Diff line number Diff line change
@@ -1,108 +0,0 @@
#pragma once

#include <xrpl/basics/Expected.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/TER.h>

namespace xrpl {

class ReadView;
class ApplyView;
class Sandbox;
class NetClock;

/** Get AMM pool balances.
*/
std::pair<STAmount, STAmount>
ammPoolHolds(
ReadView const& view,
AccountID const& ammAccountID,
Asset const& asset1,
Asset const& asset2,
FreezeHandling freezeHandling,
AuthHandling authHandling,
beast::Journal const j);

/** Get AMM pool and LP token balances. If both optIssue are
* provided then they are used as the AMM token pair issues.
* Otherwise the missing issues are fetched from ammSle.
*/
Expected<std::tuple<STAmount, STAmount, STAmount>, TER>
ammHolds(
ReadView const& view,
SLE const& ammSle,
std::optional<Asset> const& optAsset1,
std::optional<Asset> const& optAsset2,
FreezeHandling freezeHandling,
AuthHandling authHandling,
beast::Journal const j);

/** Get the balance of LP tokens.
*/
STAmount
ammLPHolds(
ReadView const& view,
Asset const& asset1,
Asset const& asset2,
AccountID const& ammAccount,
AccountID const& lpAccount,
beast::Journal const j);

STAmount
ammLPHolds(
ReadView const& view,
SLE const& ammSle,
AccountID const& lpAccount,
beast::Journal const j);

/** Get AMM trading fee for the given account. The fee is discounted
* if the account is the auction slot owner or one of the slot's authorized
* accounts.
*/
std::uint16_t
getTradingFee(ReadView const& view, SLE const& ammSle, AccountID const& account);

/** Returns total amount held by AMM for the given token.
*/
STAmount
ammAccountHolds(ReadView const& view, AccountID const& ammAccountID, Asset const& asset);

/** Delete trustlines to AMM. If all trustlines are deleted then
* AMM object and account are deleted. Otherwise tecIMPCOMPLETE is returned.
*/
TER
deleteAMMAccount(Sandbox& view, Asset const& asset, Asset const& asset2, beast::Journal j);

/** Initialize Auction and Voting slots and set the trading/discounted fee.
*/
void
initializeFeeAuctionVote(
ApplyView& view,
std::shared_ptr<SLE>& ammSle,
AccountID const& account,
Asset const& lptAsset,
std::uint16_t tfee);

/** Return true if the Liquidity Provider is the only AMM provider, false
* otherwise. Return tecINTERNAL if encountered an unexpected condition,
* for instance Liquidity Provider has more than one LPToken trustline.
*/
Expected<bool, TER>
isOnlyLiquidityProvider(ReadView const& view, Issue const& ammIssue, AccountID const& lpAccount);

/** Due to rounding, the LPTokenBalance of the last LP might
* not match the LP's trustline balance. If it's within the tolerance,
* update LPTokenBalance to match the LP's trustline balance.
*/
Expected<bool, TER>
verifyAndAdjustLPTokenBalance(
Sandbox& sb,
STAmount const& lpTokens,
std::shared_ptr<SLE>& ammSle,
AccountID const& account);

} // namespace xrpl
28 changes: 15 additions & 13 deletions include/xrpl/ledger/helpers/MPTokenHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ canTransfer(
[[nodiscard]] TER
canTrade(ReadView const& view, Asset const& asset);

/** Convenience to combine canTrade/Transfer. Returns tesSUCCESS if Asset is Issue.
*/
[[nodiscard]] TER
canMPTTradeAndTransfer(
ReadView const& v,
Asset const& asset,
AccountID const& from,
AccountID const& to);

/** Check if Asset can be traded on DEX. return tecNO_PERMISSION
* if it doesn't and tesSUCCESS otherwise.
*/
[[nodiscard]] TER
canTrade(ReadView const& view, Asset const& asset);

//------------------------------------------------------------------------------
//
// Empty holding operations (MPT-specific)
Expand Down Expand Up @@ -227,17 +242,4 @@ issuerFundsToSelfIssue(ReadView const& view, MPTIssue const& issue);
void
issuerSelfDebitHookMPT(ApplyView& view, MPTIssue const& issue, std::uint64_t amount);

//------------------------------------------------------------------------------
//
// MPT DEX
//
//------------------------------------------------------------------------------

/* Return true if a transaction is allowed for the specified MPT/account. The
* function checks MPTokenIssuance and MPToken objects flags to determine if the
* transaction is allowed.
*/
TER
checkMPTTxAllowed(ReadView const& v, TxType tx, Asset const& asset, AccountID const& accountID);

} // namespace xrpl
6 changes: 6 additions & 0 deletions include/xrpl/ledger/helpers/TokenHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ enum class AuthType { StrongAuth, WeakAuth, Legacy };
[[nodiscard]] bool
isGlobalFrozen(ReadView const& view, Asset const& asset);

[[nodiscard]] TER
checkGlobalFrozen(ReadView const& view, Asset const& asset);

[[nodiscard]] bool
isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);

[[nodiscard]] TER
checkIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset);

/**
* isFrozen check is recursive for MPT shares in a vault, descending to
* assets in the vault, up to maxAssetCheckDepth recursion depth. This is
Expand Down
4 changes: 0 additions & 4 deletions include/xrpl/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ enum TECcodes : TERUnderlyingType {
tecLIMIT_EXCEEDED = 195,
tecPSEUDO_ACCOUNT = 196,
tecPRECISION_LOSS = 197,
// DEPRECATED: This error code tecNO_DELEGATE_PERMISSION is reserved for
// backward compatibility with historical data on non-prod networks, can be
// reclaimed after those networks reset.
tecNO_DELEGATE_PERMISSION = 198,
};

//------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/tx/invariants/InvariantCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ using InvariantChecks = std::tuple<
ValidLoanBroker,
ValidLoan,
ValidVault,
ValidMPTPayment>;
ValidMPTPayment,
ValidMPTTransfer>;

/**
* @brief get a tuple of all invariant checks
Expand Down
18 changes: 18 additions & 0 deletions include/xrpl/tx/invariants/MPTInvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@ class ValidMPTPayment
finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
};

class ValidMPTTransfer
{
struct Value
{
std::optional<std::uint64_t> amtBefore;
std::optional<std::uint64_t> amtAfter;
};
// MPTID: {holder: Value}
hash_map<uint192, hash_map<AccountID, Value>> amount_;

public:
void
visitEntry(bool, std::shared_ptr<SLE const> const&, std::shared_ptr<SLE const> const&);

bool
finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&);
};

} // namespace xrpl
1 change: 0 additions & 1 deletion include/xrpl/tx/paths/AMMLiquidity.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AMMHelpers.h>
#include <xrpl/ledger/helpers/AMMUtils.h>
#include <xrpl/protocol/Concepts.h>
#include <xrpl/protocol/Quality.h>
#include <xrpl/tx/transactors/dex/AMMContext.h>
Expand Down
Loading
Loading