LPToken adjustment to factor in the LPTokenBalance rounding
Possible conflict between Liquidity Provider trustline LPToken balance
and LPTokenBalance when last Liquidity Provider withdraws all tokens
Type of Change
[ ] Bug fix (non-breaking change which fixes an issue)
[ ] New feature (non-breaking change which adds functionality)
[x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[ ] Refactor (non-breaking change that only restructures code)
[ ] Performance (increase or change in throughput and/or latency)
[x] Tests (you added tests for code that already exists, or your new feature included in this PR)
[ ] Documentation update
[ ] Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
[ ] Release
Before / After
qualityUpperBound() and QualityFunction calculation doesn't factor in the transfer fee on offer crossing.
This is correct behavior when crossing an account offer. Single-path with AMM limits the out value based
on the limitQuality. If the transfer fee is not factored in then the out value is going to be such that
the generated AMM offer quality matches the limitQuality. But the effective quality is smaller because
takerPays amount factors in the transfer fee when the strand's quality is calculated. The fix factors in
the transfer fee when the quality is adjusted for the fees on offer crossing.
adjustAmountsByLPTokens() function is not returning adjusted tokens and amounts in some cases.
The fix returns the adjusted LPToken and adjusted amounts.
Liquidity Provider's (LP) LPToken trustline balances might not add up to the total LPTokenBalance due to the rounding.
This results in a dust amount left in the balances on the last LP withdrawal or the withdrawal transaction failing. The fix
sets the LPTokenBalance to the trustline balance if LP is the only remaining LP on withdrawal transaction.
High Level Overview of Change
This PR addresses three issues:
Type of Change
.gitignore
, formatting, dropping support for older tooling)Before / After
qualityUpperBound()
andQualityFunction
calculation doesn't factor in the transfer fee on offer crossing. This is correct behavior when crossing an account offer. Single-path with AMM limits theout
value based on the limitQuality. If the transfer fee is not factored in then the out value is going to be such that the generated AMM offer quality matches the limitQuality. But the effective quality is smaller becausetakerPays
amount factors in the transfer fee when the strand's quality is calculated. The fix factors in the transfer fee when the quality is adjusted for the fees on offer crossing.adjustAmountsByLPTokens()
function is not returning adjusted tokens and amounts in some cases. The fix returns the adjusted LPToken and adjusted amounts.Test Plan
Updated AMM_test and AMMExtended unit-tests.