feat: Add MPT support to DEX (#5285)

This commit is contained in:
Gregory Tsipenyuk
2026-04-08 12:17:37 -04:00
committed by GitHub
parent 6d1a5be8d2
commit dfcad69155
223 changed files with 34897 additions and 4228 deletions

View File

@@ -420,7 +420,7 @@ public:
auto tinyAmount = [&](IOU const& iou) -> PrettyAmount {
STAmount const amt(
iou.issue(),
iou,
/*mantissa*/ 1,
/*exponent*/ -81);
return PrettyAmount(amt, iou.account.name());
@@ -709,7 +709,7 @@ public:
// Helper function that returns the Offers on an account.
static std::vector<std::shared_ptr<SLE const>>
offersOnAccount(jtx::Env& env, jtx::Account account)
offersOnAccount(jtx::Env& env, jtx::Account const& account)
{
std::vector<std::shared_ptr<SLE const>> result;
forEachItem(*env.current(), account, [&result](std::shared_ptr<SLE const> const& sle) {
@@ -1203,7 +1203,6 @@ public:
BEAST_EXPECT(jrr[jss::offers].isArray());
BEAST_EXPECT(jrr[jss::offers].size() == 0);
// NOTE :
// At this point, all offers are expected to be consumed.
{
auto acctOffers = offersOnAccount(env, account_to_test);
@@ -1279,7 +1278,7 @@ public:
auto const gw_initial_balance = drops(1149999730);
auto const alice_initial_balance = drops(499946999680);
auto const bob_initial_balance = drops(10199999920);
auto const small_amount = STAmount{bob["USD"].issue(), UINT64_C(2710505431213761), -33};
auto const small_amount = STAmount{bob["USD"], UINT64_C(2710505431213761), -33};
env.fund(gw_initial_balance, gw);
env.fund(alice_initial_balance, alice);
@@ -2136,18 +2135,18 @@ public:
jtx::Account const& account,
jtx::PrettyAmount const& expectBalance)
{
auto const sleTrust = env.le(keylet::line(account.id(), expectBalance.value().issue()));
Issue const& issue = expectBalance.value().get<Issue>();
auto const sleTrust = env.le(keylet::line(account.id(), issue));
BEAST_EXPECT(sleTrust);
if (sleTrust)
{
Issue const issue = expectBalance.value().issue();
bool const accountLow = account.id() < issue.account;
STAmount low{issue};
STAmount high{issue};
low.setIssuer(accountLow ? account.id() : issue.account);
high.setIssuer(accountLow ? issue.account : account.id());
low.get<Issue>().account = (accountLow ? account.id() : issue.account);
high.get<Issue>().account = (accountLow ? issue.account : account.id());
BEAST_EXPECT(sleTrust->getFieldAmount(sfLowLimit) == low);
BEAST_EXPECT(sleTrust->getFieldAmount(sfHighLimit) == high);
@@ -2278,7 +2277,7 @@ public:
}
std::uint32_t const acctOfferSeq = env.seq(acct) - 1;
BEAST_EXPECT(env.balance(acct, USD.issue()) == t.balanceUsd);
BEAST_EXPECT(env.balance(acct, USD) == t.balanceUsd);
BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp);
env.require(offers(acct, t.offers));
env.require(owners(acct, t.owners));
@@ -2304,7 +2303,7 @@ public:
else
{
// Verify that no trustline was created.
auto const sleTrust = env.le(keylet::line(acct, USD.issue()));
auto const sleTrust = env.le(keylet::line(acct, USD));
BEAST_EXPECT(!sleTrust);
}
}
@@ -2489,8 +2488,8 @@ public:
env.require(offers(bob, 0));
// The two trustlines that were generated by offers should be gone.
BEAST_EXPECT(!env.le(keylet::line(alice.id(), EUR.issue())));
BEAST_EXPECT(!env.le(keylet::line(bob.id(), USD.issue())));
BEAST_EXPECT(!env.le(keylet::line(alice.id(), EUR)));
BEAST_EXPECT(!env.le(keylet::line(bob.id(), USD)));
// Make two more offers that leave one of the offers non-dry. We
// need to properly sequence the transactions:
@@ -2768,7 +2767,7 @@ public:
std::uint32_t const acctOfferSeq = env.seq(acct) - 1;
// Check results
BEAST_EXPECT(env.balance(acct, USD.issue()) == t.finalUsd);
BEAST_EXPECT(env.balance(acct, USD) == t.finalUsd);
BEAST_EXPECT(env.balance(acct, xrpIssue()) == t.fundXrp - t.spentXrp);
env.require(offers(acct, t.offers));
env.require(owners(acct, t.owners));
@@ -3675,7 +3674,7 @@ public:
BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER);
BEAST_EXPECT(
offer[sfTakerGets] ==
STAmount(JPY.issue(), std::uint64_t(2230682446713524ul), -12));
STAmount(JPY, std::uint64_t(2230682446713524ul), -12));
BEAST_EXPECT(offer[sfTakerPays] == BTC(0.035378));
}
}
@@ -3712,24 +3711,24 @@ public:
env(
pay(gw1,
alice,
STAmount{USD.issue(), std::uint64_t(2185410179555600), -14}));
STAmount{USD, std::uint64_t(2185410179555600), -14}));
env(
pay(gw2,
bob,
STAmount{JPY.issue(), std::uint64_t(6351823459548956), -12}));
STAmount{JPY, std::uint64_t(6351823459548956), -12}));
env.close();
env(offer(
bob,
STAmount{USD.issue(), std::uint64_t(4371257532306000), -17},
STAmount{JPY.issue(), std::uint64_t(4573216636606000), -15}));
STAmount{USD, std::uint64_t(4371257532306000), -17},
STAmount{JPY, std::uint64_t(4573216636606000), -15}));
env.close();
// This offer did not partially cross correctly.
env(offer(
alice,
STAmount{JPY.issue(), std::uint64_t(2291181510070762), -12},
STAmount{USD.issue(), std::uint64_t(2190218999914694), -14}));
STAmount{JPY, std::uint64_t(2291181510070762), -12},
STAmount{USD, std::uint64_t(2190218999914694), -14}));
env.close();
auto const aliceOffers = offersOnAccount(env, alice);
@@ -3740,10 +3739,10 @@ public:
BEAST_EXPECT(offer[sfLedgerEntryType] == ltOFFER);
BEAST_EXPECT(
offer[sfTakerGets] ==
STAmount(USD.issue(), std::uint64_t(2185847305256635), -14));
STAmount(USD, std::uint64_t(2185847305256635), -14));
BEAST_EXPECT(
offer[sfTakerPays] ==
STAmount(JPY.issue(), std::uint64_t(2286608293434156), -12));
STAmount(JPY, std::uint64_t(2286608293434156), -12));
}
}
@@ -3772,21 +3771,21 @@ public:
// Place alice's tiny offer in the book first. Let's see what happens
// when a reasonable offer crosses it.
STAmount const aliceCnyOffer{
CNY.issue(), std::uint64_t(4926000000000000), -23};
CNY, std::uint64_t(4926000000000000), -23};
env(offer(alice, aliceCnyOffer, drops(1), tfPassive));
env.close();
// bob places an ordinary offer
STAmount const bobCnyStartBalance{
CNY.issue(), std::uint64_t(3767479960090235), -15};
CNY, std::uint64_t(3767479960090235), -15};
env(pay(gw, bob, bobCnyStartBalance));
env.close();
env(offer(
bob,
drops(203),
STAmount{CNY.issue(), std::uint64_t(1000000000000000), -20}));
STAmount{CNY, std::uint64_t(1000000000000000), -20}));
env.close();
env.require(balance(alice, aliceCnyOffer));