mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add the fixAMMOfferRounding amendment: (#4983)
* Fix AMM offer rounding and low quality LOB offer blocking AMM: A single-path AMM offer with account offer on DEX, is always generated starting with the takerPays first, which is rounded up, and then the takerGets, which is rounded down. This rounding ensures that the pool's product invariant is maintained. However, when one of the offer's side is XRP, this rounding can result in the AMM offer having a lower quality, potentially causing offer generation to fail if the quality is lower than the account's offer quality. To address this issue, the proposed fix adjusts the offer generation process to start with the XRP side first and always rounds it down. This results in a smaller offer size, improving the offer's quality. Regardless if the offer has XRP or not, the rounding is done so that the offer size is minimized. This change still ensures the product invariant, as the other generated side is the exact result of the swap-in or swap-out equations. If a liquidity can be provided by both AMM and LOB offer on offer crossing then AMM offer is generated so that it matches LOB offer quality. If LOB offer quality is less than limit quality then generated AMM offer quality is also less than limit quality and the offer doesn't cross. To address this issue, if LOB quality is better than limit quality then use LOB quality to generate AMM offer. Otherwise, don't use the quality to generate AMM offer. In this case, limitOut() function in StrandFlow limits the out amount to match strand's quality to limit quality and consume maximum AMM liquidity.
This commit is contained in:
committed by
GitHub
parent
244ac5e024
commit
2705109592
@@ -359,7 +359,7 @@ extern uint256 const featurePriceOracle;
|
||||
extern uint256 const fixEmptyDID;
|
||||
extern uint256 const fixXChainRewardRounding;
|
||||
extern uint256 const fixPreviousTxnID;
|
||||
extern uint256 const fixAMMRounding;
|
||||
extern uint256 const fixAMMv1_1;
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
|
||||
@@ -466,7 +466,7 @@ REGISTER_FEATURE(PriceOracle, Supported::yes, VoteBehavior::De
|
||||
REGISTER_FIX (fixEmptyDID, Supported::yes, VoteBehavior::DefaultNo);
|
||||
REGISTER_FIX (fixXChainRewardRounding, Supported::yes, VoteBehavior::DefaultNo);
|
||||
REGISTER_FIX (fixPreviousTxnID, Supported::yes, VoteBehavior::DefaultNo);
|
||||
REGISTER_FIX (fixAMMRounding, Supported::yes, VoteBehavior::DefaultNo);
|
||||
REGISTER_FIX (fixAMMv1_1, Supported::yes, VoteBehavior::DefaultNo);
|
||||
|
||||
// The following amendments are obsolete, but must remain supported
|
||||
// because they could potentially get enabled.
|
||||
|
||||
@@ -1367,26 +1367,6 @@ canonicalizeRoundStrict(
|
||||
|
||||
namespace {
|
||||
|
||||
// saveNumberRoundMode doesn't do quite enough for us. What we want is a
|
||||
// Number::RoundModeGuard that sets the new mode and restores the old mode
|
||||
// when it leaves scope. Since Number doesn't have that facility, we'll
|
||||
// build it here.
|
||||
class NumberRoundModeGuard
|
||||
{
|
||||
saveNumberRoundMode saved_;
|
||||
|
||||
public:
|
||||
explicit NumberRoundModeGuard(Number::rounding_mode mode) noexcept
|
||||
: saved_{Number::setround(mode)}
|
||||
{
|
||||
}
|
||||
|
||||
NumberRoundModeGuard(NumberRoundModeGuard const&) = delete;
|
||||
|
||||
NumberRoundModeGuard&
|
||||
operator=(NumberRoundModeGuard const&) = delete;
|
||||
};
|
||||
|
||||
// We need a class that has an interface similar to NumberRoundModeGuard
|
||||
// but does nothing.
|
||||
class DontAffectNumberRoundMode
|
||||
|
||||
Reference in New Issue
Block a user