Skip to content

Commit

Permalink
Add fixAMMv1_3 amendment
Browse files Browse the repository at this point in the history
* Add AMM deposit and withdraw rounding to ensure AMM invariant
* Add AMM swap/deposit/withdraw/create invariants
* Add Offer invariant to verify consumed amounts
* Fix Bid validation
  • Loading branch information
gregtatcam committed Nov 22, 2024
1 parent 838978b commit 5fe2012
Show file tree
Hide file tree
Showing 22 changed files with 2,302 additions and 566 deletions.
6 changes: 6 additions & 0 deletions include/xrpl/basics/IOUAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class IOUAmount : private boost::totally_ordered<IOUAmount>,

static IOUAmount
minPositiveAmount();

friend std::ostream&
operator<<(std::ostream& os, IOUAmount const& x)
{
return os << to_string(x);
}
};

inline IOUAmount::IOUAmount(beast::Zero)
Expand Down
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 83;
static constexpr std::size_t numFeatures = 84;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/Rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@ class CurrentTransactionRulesGuard
std::optional<Rules> saved_;
};

bool
isFeatureEnabled(uint256 const& feature);

} // namespace ripple
#endif
3 changes: 2 additions & 1 deletion include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
// If you add an amendment here, then do not forget to increment `numFeatures`
// in include/xrpl/protocol/Feature.h.

XRPL_FIX (AMMv1_3, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(Credentials, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(AMMClawback, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (AMMv1_2, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
// InvariantsV1_1 will be changes to Supported::yes when all the
// invariants expected to be included under it are complete.
XRPL_FEATURE(MPTokensV1, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(InvariantsV1_1, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (NFTokenPageLinks, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (InnerObjTemplate2, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
8 changes: 8 additions & 0 deletions src/libxrpl/protocol/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,12 @@ Rules::operator!=(Rules const& other) const
{
return !(*this == other);
}

bool
isFeatureEnabled(uint256 const& feature)
{
auto const rules = getCurrentTransactionRules();
return rules && rules->enabled(feature);
}

} // namespace ripple
553 changes: 409 additions & 144 deletions src/test/app/AMMClawback_test.cpp

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/test/app/AMMExtended_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ struct AMMExtended_test : public jtx::AMMTest
using namespace jtx;
FeatureBitset const all{supported_amendments()};
testRmFundedOffer(all);
testRmFundedOffer(all - fixAMMv1_1);
testRmFundedOffer(all - fixAMMv1_1 - fixAMMv1_3);
testEnforceNoRipple(all);
testFillModes(all);
testOfferCrossWithXRP(all);
Expand All @@ -1458,15 +1458,15 @@ struct AMMExtended_test : public jtx::AMMTest
testOfferCreateThenCross(all);
testSellFlagExceedLimit(all);
testGatewayCrossCurrency(all);
testGatewayCrossCurrency(all - fixAMMv1_1);
testGatewayCrossCurrency(all - fixAMMv1_1 - fixAMMv1_3);
testBridgedCross(all);
testSellWithFillOrKill(all);
testTransferRateOffer(all);
testSelfIssueOffer(all);
testBadPathAssert(all);
testSellFlagBasic(all);
testDirectToDirectPath(all);
testDirectToDirectPath(all - fixAMMv1_1);
testDirectToDirectPath(all - fixAMMv1_1 - fixAMMv1_3);
testRequireAuth(all);
testMissingAuth(all);
}
Expand Down Expand Up @@ -4090,9 +4090,9 @@ struct AMMExtended_test : public jtx::AMMTest
testBookStep(all);
testBookStep(all | ownerPaysFee);
testTransferRate(all | ownerPaysFee);
testTransferRate((all - fixAMMv1_1) | ownerPaysFee);
testTransferRate((all - fixAMMv1_1 - fixAMMv1_3) | ownerPaysFee);
testTransferRateNoOwnerFee(all);
testTransferRateNoOwnerFee(all - fixAMMv1_1);
testTransferRateNoOwnerFee(all - fixAMMv1_1 - fixAMMv1_3);
testLimitQuality();
testXRPPathLoop();
}
Expand All @@ -4103,7 +4103,7 @@ struct AMMExtended_test : public jtx::AMMTest
using namespace jtx;
FeatureBitset const all{supported_amendments()};
testStepLimit(all);
testStepLimit(all - fixAMMv1_1);
testStepLimit(all - fixAMMv1_1 - fixAMMv1_3);
}

void
Expand All @@ -4112,7 +4112,7 @@ struct AMMExtended_test : public jtx::AMMTest
using namespace jtx;
FeatureBitset const all{supported_amendments()};
test_convert_all_of_an_asset(all);
test_convert_all_of_an_asset(all - fixAMMv1_1);
test_convert_all_of_an_asset(all - fixAMMv1_1 - fixAMMv1_3);
}

void
Expand Down
Loading

0 comments on commit 5fe2012

Please sign in to comment.