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

feat(ProtoRev): Supporting Two Pool Routes #5953

Merged
merged 14 commits into from
Aug 16, 2023
Merged

Conversation

davidterpay
Copy link
Contributor

What is the purpose of the change

This PR updates the route building logic of ProtoRev to be able to construct two pool arbitrage routes. This is particularly useful when there are multiple pools of that consist of the same assets and are imbalanced. As before, routes will only be constructed using the base denoms.

Testing and Verifying

  • Added unit test that test the construction of two pool routes under various conditions
  • Updated existing test cases that should also now create two pool routes

Documentation and Release Note

This PR is a part of the open issue for ProtoRev updates for V17 (#5858)

@davidterpay davidterpay mentioned this pull request Aug 3, 2023
10 tasks
@davidterpay davidterpay added protorev All things related to x/protorev V:state/breaking State machine breaking PR labels Aug 3, 2023
@@ -902,6 +903,91 @@ func (s *KeeperTestSuite) setUpPools() {
// Pool 50
s.PrepareCosmWasmPool()

// Create a duplicate pool for testing
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add in the comment what test these pools are for

Copy link
Contributor

@NotJeremyLiu NotJeremyLiu left a comment

Choose a reason for hiding this comment

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

lgtm after supporting both directions

Copy link
Contributor

@NotJeremyLiu NotJeremyLiu left a comment

Choose a reason for hiding this comment

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

lgtm

@davidterpay davidterpay marked this pull request as ready for review August 4, 2023 19:23
@davidterpay davidterpay requested a review from p0mvn as a code owner August 4, 2023 19:23
Copy link
Contributor

@stackman27 stackman27 left a comment

Choose a reason for hiding this comment

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

just have a question to understand this logic more before approving

func (k Keeper) BuildTwoPoolRoute(
ctx sdk.Context,
baseDenom types.BaseDenom,
swapIn, swapOut string,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: or SwapInDenom, SwapOutDenom

Suggested change
swapIn, swapOut string,
tokenInDenom, tokenOutDenom string,

hasRoute: true,
},
{
description: "two pool route where swap is on the highest liquidity pool",
Copy link
Contributor

@stackman27 stackman27 Aug 4, 2023

Choose a reason for hiding this comment

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

i'm trying to understand this: if SwapDenom == tokenOutDenom & huge swap occours in highest liquidity pool, isn't base denom being cheaper so you would create a route to balance it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to make sure i understand the scenario:

if BaseDenom == tokenOutDenom, base denom becomes more expensive as the token supply of baseDenom in that pool decreases. i.e. if x == tokenInDenom and y == tokenOutDenom, then x + deltaX / y - deltaY > x / y. in this case, tokenOut is y which means it is more expensive and hence we can get more of X on the current pool than the other pool. We should then find the highest liquidity pool with the same assets and route through that. if the swap occurred on the highest liquidity pool, then we cannot make a route.

@czarcas7ic
Copy link
Member

@NotJeremyLiu @davidterpay getting the same protorev e2e failure after two runs. Any way you can take a look into this?

@davidterpay
Copy link
Contributor Author

@NotJeremyLiu @davidterpay getting the same protorev e2e failure after two runs. Any way you can take a look into this?

It looks like its failing a CL test swap. I'll see if I can replicate the same issue and resolve it locally. Will ping once I find the issue (likely tmw morning EST).

@ValarDragon
Copy link
Member

devbot merge base

@davidterpay
Copy link
Contributor Author

We think the issue may be arising because of the two pool routing as the swap in the CL test does create some arbitrage that the module is confirmed to capture. This might be messing with the calculations done in the test case.

There are a few approaches for this:

  1. We can disable protorev for the test case (but im unsure if this will affect the other protorev test since it is executed in parallel).
  2. We can determine if the calculations for sqrt amount can be updated in accordance with any liquidity changes that protorev introduces.
  3. We can switch out the denoms used in the test case for other denoms so that we do not have to disable protorev.

@davidterpay
Copy link
Contributor Author

davidterpay commented Aug 8, 2023

// Change the parameter to disable protorev
err = chainABNode.ParamChangeProposal("protorev", string(protorevtypes.ParamStoreKeyEnableModule), []byte("false"), chainAB)
s.Require().NoError(err)

Added this for the time being.

@czarcas7ic
Copy link
Member

Do you think we can instead remove the route from protorev in the protorev test itself? It doesn't seem scalable if we have another test that relies on calculating the output of the pools to check if protorev is disabled. Also, since everything is concurrent, there could be a scenario in which

  1. Protorev test starts
  2. CL test starts as well
  3. CL test diables protorev
  4. Protorev test fails due to being disabled via the CL test

@davidterpay
Copy link
Contributor Author

@czarcas7ic set the max pool points such that it will always pass on the ProtoRev test and will never execute a backrun in the CL test. Should always pass now even if the tests execute in parallel.

tests/e2e/configurer/chain/commands.go Outdated Show resolved Hide resolved
@czarcas7ic czarcas7ic merged commit 12fca5b into main Aug 16, 2023
1 check passed
@czarcas7ic czarcas7ic deleted the terpay/two-pool-routes branch August 16, 2023 17:22
p0mvn pushed a commit that referenced this pull request Aug 29, 2023
* testing

* changelog

* trading both ways

* updating test

* nit

* test fix

* protorev test update

* Update tests/e2e/configurer/chain/commands.go

---------

Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com>
Co-authored-by: Adam Tucker <adam@osmosis.team>
nicolaslara pushed a commit that referenced this pull request Aug 31, 2023
* testing

* changelog

* trading both ways

* updating test

* nit

* test fix

* protorev test update

* Update tests/e2e/configurer/chain/commands.go

---------

Co-authored-by: devbot-wizard <141283918+devbot-wizard@users.noreply.github.com>
Co-authored-by: Adam Tucker <adam@osmosis.team>
@github-actions github-actions bot mentioned this pull request May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
protorev All things related to x/protorev V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants