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 18, 2024
1 parent 838978b commit f47a0f5
Show file tree
Hide file tree
Showing 19 changed files with 1,765 additions and 340 deletions.
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
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// 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)
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
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 f47a0f5

Please sign in to comment.