Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance. This was fixed for `AMMWithdraw` in `fixAMMv1_1` by adjusting the LPTokenBalance to be the same as the trustline balance. Since `AMMClawback` is also performing a withdrawal, we need to adjust LPTokenBalance as well in `AMMClawback.`
This change includes:
1. Refactored `verifyAndAdjustLPTokenBalance` function in `AMMUtils`, which both`AMMWithdraw` and `AMMClawback` call to adjust LPTokenBalance.
2. Added the unit test `testLastHolderLPTokenBalance` to test the scenario.
3. Modify the existing unit tests for `fixAMMClawbackRounding`.
* Add AMM bid/create/deposit/swap/withdraw/vote invariants:
- Deposit, Withdrawal invariants: `sqrt(asset1Balance * asset2Balance) >= LPTokens`.
- Bid: `sqrt(asset1Balance * asset2Balance) > LPTokens` and the pool balances don't change.
- Create: `sqrt(asset1Balance * assetBalance2) == LPTokens`.
- Swap: `asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore`
and `LPTokens` don't change.
- Vote: `LPTokens` and pool balances don't change.
- All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens
are withdrawn.
* Add AMM deposit and withdraw rounding to ensure AMM invariant:
- On deposit, tokens out are rounded downward and deposit amount is rounded upward.
- On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
* Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
* Fix Bid validation. `AuthAccount` can't have duplicate accounts or the submitter account.
This commit makes several changes to the base_uint class, which was
originally taken from Bitcoin and has already been heavily modified
by Ripple engineers.
It introduces conditional widening of the internal limb type, going
from 32 to 64 bits if the requested number of bits is a multiple of
64. This change alone halves iteration counts for common operations
and, combined with use of add-with-carry compiler intrinsics, helps
leverage modern processor resources more effectively.
Other changes include:
- Extracting the arithmetic operations into free helper functions
which operate on the limb array directly.
- Replacing the SFINAE-based is_contiguous_container trait with a
byte_copy_source concept.
- Rewriting the hex parsing around a consteval lookup table and a
simple left-to-right loop, replacing the old shift-based nibble
accumulator.
- Using memmove instead of memcpy when copying to avoid UB in the
unlikely case where the source and destination buffers overlap.
- Eliminating a workaround in operator<=> to handle MacOS quirks.
- Removing redundant parseHex overloads and introducing from_hex
as a factory function.
- Introducing a tagless_compare() for cross-tag comparison.
- Adding noexcept, [[nodiscard]], and constexpr throughout.
- Fix unlikely edge case in setCurrentThreadName
setCurrentThreadName accepts a std::string_view parameter, which is
not guaranteed to include a null terminator, which it then forwards
to OS-specific APIs that expect null-terminated C strings.
- Fix several compilation warnings
- Fix header includes
- Fix unnecessarily verbose logging
- Simplify code using inline lambdas instead of std::bind
- Modernize the Beast "lexical cast" framework
- Use boost::asio types instead of legacy Beast type wrappers
- Clean up LogicError, custom exception throwing and termination handling
- Clean up and modernize PublicKey, SecretKey and Seed
Simplify construction, buffer iteration and comparisons by leveraging
modern C++ features.
- Clean up and modernize RFC1751 code
Turn static-member-only class into namespace, thin out the public API
and make code noexcept and constexpr. Verify internal data at compile
time.
- Clean up CSPRNG engine
- Clean up rngfill function, eliminating GCC false-positive warning.
- Improve Slice comparison using C++ operator<=> and operator synthesis.
Due to rounding, the LPTokenBalance of the last LP might not match the LP's trustline balance. This was fixed for `AMMWithdraw` in `fixAMMv1_1` by adjusting the LPTokenBalance to be the same as the trustline balance. Since `AMMClawback` is also performing a withdrawal, we need to adjust LPTokenBalance as well in `AMMClawback.`
This change includes:
1. Refactored `verifyAndAdjustLPTokenBalance` function in `AMMUtils`, which both`AMMWithdraw` and `AMMClawback` call to adjust LPTokenBalance.
2. Added the unit test `testLastHolderLPTokenBalance` to test the scenario.
3. Modify the existing unit tests for `fixAMMClawbackRounding`.
* Add AMM bid/create/deposit/swap/withdraw/vote invariants:
- Deposit, Withdrawal invariants: `sqrt(asset1Balance * asset2Balance) >= LPTokens`.
- Bid: `sqrt(asset1Balance * asset2Balance) > LPTokens` and the pool balances don't change.
- Create: `sqrt(asset1Balance * assetBalance2) == LPTokens`.
- Swap: `asset1BalanceAfter * asset2BalanceAfter >= asset1BalanceBefore * asset2BalanceBefore`
and `LPTokens` don't change.
- Vote: `LPTokens` and pool balances don't change.
- All AMM and swap transactions: amounts and tokens are greater than zero, except on withdrawal if all tokens
are withdrawn.
* Add AMM deposit and withdraw rounding to ensure AMM invariant:
- On deposit, tokens out are rounded downward and deposit amount is rounded upward.
- On withdrawal, tokens in are rounded upward and withdrawal amount is rounded downward.
* Add Order Book Offer invariant to verify consumed amounts. Consumed amounts are less than the offer.
* Fix Bid validation. `AuthAccount` can't have duplicate accounts or the submitter account.
- Also get the branch name.
- Use rev-parse instead of describe to get a clean hash.
- Return the git hash and branch name in server_info for admin
connections.
- Include git hash and branch name on separate lines in --version.
The LEDGER_ENTRY macro now takes an additional parameter, which makes it easier to avoid missing including the new field in jss.h and to the list of account_objects/ledger_data filters.