mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-04 01:06:37 +00:00
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>
114 lines
2.8 KiB
C++
114 lines
2.8 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2023 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <ripple/protocol/STIssue.h>
|
|
|
|
#include <ripple/basics/contract.h>
|
|
|
|
namespace ripple {
|
|
|
|
STIssue::STIssue(SField const& name) : STBase{name}
|
|
{
|
|
}
|
|
|
|
STIssue::STIssue(SerialIter& sit, SField const& name) : STBase{name}
|
|
{
|
|
issue_.currency = sit.get160();
|
|
if (!isXRP(issue_.currency))
|
|
issue_.account = sit.get160();
|
|
else
|
|
issue_.account = xrpAccount();
|
|
|
|
if (isXRP(issue_.currency) != isXRP(issue_.account))
|
|
Throw<std::runtime_error>(
|
|
"invalid issue: currency and account native mismatch");
|
|
}
|
|
|
|
STIssue::STIssue(SField const& name, Issue const& issue)
|
|
: STBase{name}, issue_{issue}
|
|
{
|
|
if (isXRP(issue_.currency) != isXRP(issue_.account))
|
|
Throw<std::runtime_error>(
|
|
"invalid issue: currency and account native mismatch");
|
|
}
|
|
|
|
SerializedTypeID
|
|
STIssue::getSType() const
|
|
{
|
|
return STI_ISSUE;
|
|
}
|
|
|
|
std::string
|
|
STIssue::getText() const
|
|
{
|
|
return issue_.getText();
|
|
}
|
|
|
|
Json::Value STIssue::getJson(JsonOptions) const
|
|
{
|
|
return to_json(issue_);
|
|
}
|
|
|
|
void
|
|
STIssue::add(Serializer& s) const
|
|
{
|
|
s.addBitString(issue_.currency);
|
|
if (!isXRP(issue_.currency))
|
|
s.addBitString(issue_.account);
|
|
}
|
|
|
|
bool
|
|
STIssue::isEquivalent(const STBase& t) const
|
|
{
|
|
const STIssue* v = dynamic_cast<const STIssue*>(&t);
|
|
return v && (*v == *this);
|
|
}
|
|
|
|
bool
|
|
STIssue::isDefault() const
|
|
{
|
|
return issue_ == xrpIssue();
|
|
}
|
|
|
|
std::unique_ptr<STIssue>
|
|
STIssue::construct(SerialIter& sit, SField const& name)
|
|
{
|
|
return std::make_unique<STIssue>(sit, name);
|
|
}
|
|
|
|
STBase*
|
|
STIssue::copy(std::size_t n, void* buf) const
|
|
{
|
|
return emplace(n, buf, *this);
|
|
}
|
|
|
|
STBase*
|
|
STIssue::move(std::size_t n, void* buf)
|
|
{
|
|
return emplace(n, buf, std::move(*this));
|
|
}
|
|
|
|
STIssue
|
|
issueFromJson(SField const& name, Json::Value const& v)
|
|
{
|
|
return STIssue{name, issueFromJson(v)};
|
|
}
|
|
|
|
} // namespace ripple
|