-
Notifications
You must be signed in to change notification settings - Fork 608
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
Changes from 3 commits
16ef254
a65020a
c788e3d
0d8b036
c8a9dc3
5213b40
5e12273
3508497
fd0424f
92e2979
f8b018d
8f3113b
b2c792e
476d82d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,17 @@ func (s *KeeperTestSuite) TestBuildRoutes() { | |
description: "Route exists for swap in Bitcoin and swap out Atom", | ||
inputDenom: "bitcoin", | ||
outputDenom: "Atom", | ||
poolID: 4, | ||
poolID: 55, | ||
expectedRoutes: [][]TestRoute{ | ||
{ | ||
{PoolId: 25, InputDenom: types.OsmosisDenomination, OutputDenom: "Atom"}, | ||
{PoolId: 4, InputDenom: "Atom", OutputDenom: "bitcoin"}, | ||
{PoolId: 55, InputDenom: "Atom", OutputDenom: "bitcoin"}, | ||
{PoolId: 10, InputDenom: "bitcoin", OutputDenom: types.OsmosisDenomination}, | ||
}, | ||
{ | ||
{PoolId: 4, InputDenom: "Atom", OutputDenom: "bitcoin"}, | ||
{PoolId: 55, InputDenom: "bitcoin", OutputDenom: "Atom"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
|
@@ -91,6 +95,18 @@ func (s *KeeperTestSuite) TestBuildRoutes() { | |
}, | ||
}, | ||
}, | ||
{ | ||
description: "Two Pool Route exists for (osmo, atom)", | ||
inputDenom: "Atom", | ||
outputDenom: types.OsmosisDenomination, | ||
poolID: 51, | ||
expectedRoutes: [][]TestRoute{ | ||
{ | ||
{PoolId: 25, InputDenom: types.OsmosisDenomination, OutputDenom: "Atom"}, | ||
{PoolId: 51, InputDenom: "Atom", OutputDenom: types.OsmosisDenomination}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
|
@@ -225,6 +241,77 @@ func (s *KeeperTestSuite) TestBuildHighestLiquidityRoute() { | |
} | ||
} | ||
|
||
// TestBuildTwoPoolRoute tests the BuildTwoPoolRoute function | ||
func (s *KeeperTestSuite) TestBuildTwoPoolRoute() { | ||
cases := []struct { | ||
description string | ||
swapDenom types.BaseDenom | ||
tokenIn string | ||
tokenOut string | ||
poolId uint64 | ||
expectedRoute []TestRoute | ||
hasRoute bool | ||
}{ | ||
{ | ||
description: "two pool route can be created", | ||
swapDenom: types.BaseDenom{ | ||
Denom: types.OsmosisDenomination, | ||
StepSize: sdk.NewInt(1_000_000), | ||
}, | ||
tokenIn: "stake", | ||
tokenOut: types.OsmosisDenomination, | ||
poolId: 53, | ||
expectedRoute: []TestRoute{ | ||
{PoolId: 54, InputDenom: types.OsmosisDenomination, OutputDenom: "stake"}, | ||
{PoolId: 53, InputDenom: "stake", OutputDenom: types.OsmosisDenomination}, | ||
}, | ||
hasRoute: true, | ||
}, | ||
{ | ||
description: "two pool route where swap is on the highest liquidity pool", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to make sure i understand the scenario: if |
||
swapDenom: types.BaseDenom{ | ||
Denom: types.OsmosisDenomination, | ||
StepSize: sdk.NewInt(1_000_000), | ||
}, | ||
tokenIn: "stake", | ||
tokenOut: types.OsmosisDenomination, | ||
poolId: 54, | ||
expectedRoute: []TestRoute{}, | ||
hasRoute: false, | ||
}, | ||
{ | ||
description: "two pool route where swap in is the base denom", | ||
swapDenom: types.BaseDenom{ | ||
Denom: types.OsmosisDenomination, | ||
StepSize: sdk.NewInt(1_000_000), | ||
}, | ||
tokenIn: types.OsmosisDenomination, | ||
tokenOut: "stake", | ||
poolId: 53, | ||
expectedRoute: []TestRoute{}, | ||
hasRoute: false, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
s.Run(tc.description, func() { | ||
routeMetaData, err := s.App.ProtoRevKeeper.BuildTwoPoolRoute(s.Ctx, tc.swapDenom, tc.tokenIn, tc.tokenOut, tc.poolId) | ||
|
||
if tc.hasRoute { | ||
s.Require().NoError(err) | ||
s.Require().Equal(len(tc.expectedRoute), len(routeMetaData.Route.PoolIds())) | ||
|
||
for index, trade := range tc.expectedRoute { | ||
s.Require().Equal(trade.PoolId, routeMetaData.Route.PoolIds()[index]) | ||
} | ||
} else { | ||
s.Require().Equal(len(tc.expectedRoute), len(routeMetaData.Route.PoolIds())) | ||
s.Require().Error(err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// TestBuildHotRoutes tests the BuildHotRoutes function | ||
func (s *KeeperTestSuite) TestBuildHotRoutes() { | ||
cases := []struct { | ||
|
There was a problem hiding this comment.
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