Introduce AMM support (XLS-30d): (#4294)

Add AMM functionality:
- InstanceCreate
- Deposit
- Withdraw
- Governance
- Auctioning
- payment engine integration

To support this functionality, add:
- New RPC method, `amm_info`, to fetch pool and LPT balances
- AMM Root Account
- trust line for each IOU AMM token
- trust line to track Liquidity Provider Tokens (LPT)
- `ltAMM` object

The `ltAMM` object tracks:
- fee votes
- auction slot bids
- AMM tokens pair
- total outstanding tokens balance
- `AMMID` to AMM `RootAccountID` mapping

Add new classes to facilitate AMM integration into the payment engine.
`BookStep` uses these classes to infer if AMM liquidity can be consumed.

The AMM formula implementation uses the new Number class added in #4192.
IOUAmount and STAmount use Number arithmetic.

Add AMM unit tests for all features.

AMM requires the following amendments:
- featureAMM
- fixUniversalNumber
- featureFlowCross

Notes:
- Current trading fee threshold is 1%
- AMM currency is generated by: 0x03 + 152 bits of sha256{cur1, cur2}
- Current max AMM Offers is 30

---------

Co-authored-by: Howard Hinnant <howard.hinnant@gmail.com>
This commit is contained in:
Gregory Tsipenyuk
2023-07-12 13:52:50 -04:00
committed by GitHub
parent eeb8b41889
commit 3c9db4b69e
100 changed files with 18092 additions and 649 deletions

View File

@@ -26,8 +26,10 @@
#include <ripple/ledger/Sandbox.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include "ripple/app/paths/AMMContext.h"
#include <test/jtx.h>
#include <test/jtx/PathSet.h>
#include <test/jtx/TestHelpers.h>
namespace ripple {
namespace test {
@@ -162,26 +164,6 @@ iape(AccountID const& account)
STPathElement::typeIssuer, xrpAccount(), xrpCurrency(), account);
};
// Currency path element
STPathElement
cpe(Currency const& c)
{
return STPathElement(
STPathElement::typeCurrency, xrpAccount(), c, xrpAccount());
};
// All path element
STPathElement
allpe(AccountID const& a, Issue const& iss)
{
return STPathElement(
STPathElement::typeAccount | STPathElement::typeCurrency |
STPathElement::typeIssuer,
a,
iss.currency,
iss.account);
};
class ElementComboIter
{
enum class SB /*state bit*/
@@ -657,6 +639,8 @@ struct PayStrand_test : public beast::unit_test::suite
using B = ripple::Book;
using XRPS = XRPEndpointStepInfo;
AMMContext ammContext(alice, false);
auto test = [&, this](
jtx::Env& env,
Issue const& deliver,
@@ -674,6 +658,7 @@ struct PayStrand_test : public beast::unit_test::suite
path,
true,
false,
ammContext,
env.app().logs().journal("Flow"));
BEAST_EXPECT(ter == expTer);
if (sizeof...(expSteps) != 0)
@@ -701,6 +686,7 @@ struct PayStrand_test : public beast::unit_test::suite
path,
true,
false,
ammContext,
env.app().logs().journal("Flow"));
(void)_;
BEAST_EXPECT(ter == tesSUCCESS);
@@ -717,6 +703,7 @@ struct PayStrand_test : public beast::unit_test::suite
path,
true,
false,
ammContext,
env.app().logs().journal("Flow"));
(void)_;
BEAST_EXPECT(ter == tesSUCCESS);
@@ -836,6 +823,7 @@ struct PayStrand_test : public beast::unit_test::suite
STPath(),
true,
false,
ammContext,
flowJournal);
BEAST_EXPECT(r.first == temBAD_PATH);
}
@@ -851,6 +839,7 @@ struct PayStrand_test : public beast::unit_test::suite
STPath(),
true,
false,
ammContext,
flowJournal);
BEAST_EXPECT(r.first == temBAD_PATH);
}
@@ -866,6 +855,7 @@ struct PayStrand_test : public beast::unit_test::suite
STPath(),
true,
false,
ammContext,
flowJournal);
BEAST_EXPECT(r.first == temBAD_PATH);
}
@@ -1002,6 +992,7 @@ struct PayStrand_test : public beast::unit_test::suite
STPath(),
true,
false,
ammContext,
env.app().logs().journal("Flow"));
BEAST_EXPECT(ter == tesSUCCESS);
BEAST_EXPECT(equal(strand, D{alice, gw, usdC}));
@@ -1028,6 +1019,7 @@ struct PayStrand_test : public beast::unit_test::suite
path,
false,
false,
ammContext,
env.app().logs().journal("Flow"));
BEAST_EXPECT(ter == tesSUCCESS);
BEAST_EXPECT(equal(