Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit-tests to verify CLOB/AMM offer and strand selection logic with the transfer fee #4642

Closed

Conversation

gregtatcam
Copy link
Collaborator

High Level Overview of Change

This PR includes only the unit-tests to verify the payment engine logic to select AMM/CLOB offer and to select the best quality strand when the transfer fee is set.

Context of Change

The transfer fee changes the offer quality and therefore has to be considered when selecting CLOB/AMM offer or the best quality strand. The transfer in rate can be optimized out since it is applied to both CLOB and AMM offer. The transfer out rate is set to one in case of the cross currency payment. The quality adjustment for the transfer fee in case of the offer crossing is disabled. Therefore the transfer fee adjustment cancels itself out.

Type of Change

  • Tests

Test Plan

The unit-tests consider two cases:

  • If AMM has the same spot price quality as CLOB offer, then AMM can't generate an offer with a better quality than CLOB offer. Therefore, CLOB offer has to be selected over AMM offer and consequently a strand with CLOB offer has to be selected over a strand with AMM offer regardless of the transfer fee.
  • If AMM has a slightly better spot price quality than CLOB offer, then AMM can generate an offer with a better quality than CLOB offer. Therefore, AMM offer has to be selected over CLOB offer and consequently a strand with AMM offer has to be selected over a strand with CLOB offer regardless of the transfer fee.

Both cases are considered for the cross-currency payment and the offer crossing.

Future Tasks

If ownerPaysFee amendment is enabled that the transfer fee adjustment has to be reconsidered.

Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@intelliot intelliot requested a review from ximinez August 9, 2023 00:26
// as CLOB's offer and can't generate a better quality offer.
// The transfer fee in this case doesn't change the CLOB quality
// because trIn is ignored on adjustment and trOut on payment is
// also ignored because ownerPaysTransferFee is false in this case.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason that ownerPaysTransferFee is false is because the OwnerPaysFee feature is unsupported. If that ever changes to Supported::yes, some of these tests will fail. If that's intentional, great! If not, you should explicitly create the Env objects with a FeatureBitset that explicitly removes featureOwnerPaysFee.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional!

Copy link
Collaborator

@ximinez ximinez Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add that to the explanation? Something like, "These tests are expected to fail if the OwnerPaysFee feature is ever supported. Updates will need to be made to AMM handling in the payment engine, and these tests will need to be updated."

src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
src/test/app/AMM_test.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ximinez ximinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I left another comment asking to update the test description, but I figure I don't need to re-review after you add that.

Could you add that to the explanation? Something like, "These tests are expected to fail if the OwnerPaysFee feature is ever supported. Updates will need to be made to AMM handling in the payment engine, and these tests will need to be updated."

@intelliot intelliot assigned gregtatcam and unassigned seelabs and ximinez Aug 15, 2023
@intelliot
Copy link
Collaborator

@gregtatcam to confirm whether this is ready to merge. If it's waiting for something, please comment to note that here.

@intelliot intelliot added this to the 1.12 milestone Aug 15, 2023
@gregtatcam
Copy link
Collaborator Author

@gregtatcam to confirm whether this is ready to merge. If it's waiting for something, please comment to note that here.

This PR is ready to merge.

@intelliot intelliot added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Aug 15, 2023
@intelliot intelliot assigned manojsdoshi and unassigned gregtatcam Aug 15, 2023
@intelliot
Copy link
Collaborator

Suggested commit message:

test: verify transfer fee for LOB/AMM offer, strand selection (#4642)

Add unit tests to verify the payment engine logic to select AMM/LOB
offer and to select the best quality strand when the transfer fee is
set. LOB is Limit Order Book, a list of buy and sell offers for a pair
of assets, organized by price level (quality).

The transfer fee changes the offer quality and therefore has to be
considered when selecting LOB/AMM offer or the best quality strand. The
`transfer in` rate can be optimized out since it is applied to both LOB
and AMM offer. The `transfer out` rate is set to one in case of the
cross currency payment. The quality adjustment for the transfer fee in
case of the offer crossing is disabled. Therefore the transfer fee
adjustment cancels itself out.

The unit-tests consider two cases: 

- If AMM has the same spot price quality as LOB offer, then AMM can't
  generate an offer with a better quality than LOB offer. Therefore, LOB
  offer has to be selected over AMM offer and consequently a strand with
  LOB offer has to be selected over a strand with AMM offer regardless
  of the transfer fee.
- If AMM has a slightly better spot price quality than LOB offer, then
  AMM can generate an offer with a better quality than LOB offer.
  Therefore, AMM offer has to be selected over LOB offer and
  consequently a strand with AMM offer has to be selected over a strand
  with LOB offer regardless of the transfer fee.

Both cases are considered for the cross-currency payment and the offer
crossing.

The selection tests would have to be updated if `OwnerPaysFeature`
amendment is enabled.

@intelliot
Copy link
Collaborator

This PR was merged as part of #4626.

#4626 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. XLS-30
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants