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

@@ -23,9 +23,11 @@
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/jss.h>
#include <test/jtx.h>
#include <test/jtx/TestHelpers.h>
#include <algorithm>
#include <iterator>
#include <test/jtx.h>
namespace ripple {
namespace test {
@@ -61,134 +63,6 @@ struct Escrow_test : public beast::unit_test::suite
0x26, 0x4A, 0x2D, 0x85, 0x7B, 0xE8, 0xA0, 0x9C, 0x1D, 0xFD,
0x57, 0x0D, 0x15, 0x85, 0x8B, 0xD4, 0x81, 0x01, 0x04}};
/** Set the "FinishAfter" time tag on a JTx */
struct finish_time
{
private:
NetClock::time_point value_;
public:
explicit finish_time(NetClock::time_point const& value) : value_(value)
{
}
void
operator()(jtx::Env&, jtx::JTx& jt) const
{
jt.jv[sfFinishAfter.jsonName] = value_.time_since_epoch().count();
}
};
/** Set the "CancelAfter" time tag on a JTx */
struct cancel_time
{
private:
NetClock::time_point value_;
public:
explicit cancel_time(NetClock::time_point const& value) : value_(value)
{
}
void
operator()(jtx::Env&, jtx::JTx& jt) const
{
jt.jv[sfCancelAfter.jsonName] = value_.time_since_epoch().count();
}
};
struct condition
{
private:
std::string value_;
public:
explicit condition(Slice cond) : value_(strHex(cond))
{
}
template <size_t N>
explicit condition(std::array<std::uint8_t, N> c)
: condition(makeSlice(c))
{
}
void
operator()(jtx::Env&, jtx::JTx& jt) const
{
jt.jv[sfCondition.jsonName] = value_;
}
};
struct fulfillment
{
private:
std::string value_;
public:
explicit fulfillment(Slice condition) : value_(strHex(condition))
{
}
template <size_t N>
explicit fulfillment(std::array<std::uint8_t, N> f)
: fulfillment(makeSlice(f))
{
}
void
operator()(jtx::Env&, jtx::JTx& jt) const
{
jt.jv[sfFulfillment.jsonName] = value_;
}
};
static Json::Value
escrow(
jtx::Account const& account,
jtx::Account const& to,
STAmount const& amount)
{
using namespace jtx;
Json::Value jv;
jv[jss::TransactionType] = jss::EscrowCreate;
jv[jss::Flags] = tfUniversal;
jv[jss::Account] = account.human();
jv[jss::Destination] = to.human();
jv[jss::Amount] = amount.getJson(JsonOptions::none);
return jv;
}
static Json::Value
finish(
jtx::Account const& account,
jtx::Account const& from,
std::uint32_t seq)
{
Json::Value jv;
jv[jss::TransactionType] = jss::EscrowFinish;
jv[jss::Flags] = tfUniversal;
jv[jss::Account] = account.human();
jv[sfOwner.jsonName] = from.human();
jv[sfOfferSequence.jsonName] = seq;
return jv;
}
static Json::Value
cancel(
jtx::Account const& account,
jtx::Account const& from,
std::uint32_t seq)
{
Json::Value jv;
jv[jss::TransactionType] = jss::EscrowCancel;
jv[jss::Flags] = tfUniversal;
jv[jss::Account] = account.human();
jv[sfOwner.jsonName] = from.human();
jv[sfOfferSequence.jsonName] = seq;
return jv;
}
void
testEnablement()
{