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

[CL][Swap Router Module]: implement store index to map pool id to swap module #3238

Closed
p0mvn opened this issue Nov 4, 2022 · 2 comments
Closed
Assignees
Labels
C:x/swap-router F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board T:task ⚙️ A task belongs to a story

Comments

@p0mvn
Copy link
Member

p0mvn commented Nov 4, 2022

Background

We need to store a mapping from pool id to swap module (gamm or concentrated-liquidity).

This is necessary for swaps. Given the pool id, we should be able to know which module to route the swap to.

Currently, swaprouter hardcodes all swaps to be routed to gamm.

Suggested Design

See for details: #3233

  1. Implement:
// x/swaprouter/types/keys.go
var	SwapModuleRouterPrefix     = []byte{0x01}
type ModuleRoute struct {
    PoolId uint64
    PoolType PoolType
}
// ModuleRouteToBytes serializes moduleRoute to bytes.
func ModuleRouteToBytes(moduleRoute ModuleRoute) []byte {
    ...
}
// ModuleRouteFromBytes deserializes an encoded module route. It returns
// an error if decoding fails.
func ModuleRouteFromBytes(bz []byte) (ModuleRoute, error) {
    ...
}
  1. Use the above to store the mapping in CreatePool
  • update tests to check that the store is updated
  1. Implement pseudocode.
// x/swaprouter/router.go RouteExactAmountIn(...)
moduleRouteBytes := osmoutils.MustGet(swaproutertypes.FormatModuleRouteIndex(poolId))
moduleRoute, _ := swaproutertypes.ModuleRouteFromBytes(moduleRouteBytes)
swapModule := k.routes[moduleRoute.PoolType]
_ := swapModule.SwapExactAmountIn(...)
  1. Optionally in the same PR, complete: [CL][Swap Router Module]: test CreatePool #3236

  2. Optionally in the same PR: [CL][Swap Router Module]: improve TestMultihopSwapExactAmountIn and TestMultihopSwapExactAmountOut #3131

Acceptance Criteria

  • suggested design implemented
  • proper abstractions added, not just pseudocode
  • requested tests added
@p0mvn p0mvn added C:x/swap-router F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board labels Nov 4, 2022
@osmo-bot osmo-bot moved this to Needs Review 🔍 in Osmosis Chain Development Nov 4, 2022
@p0mvn p0mvn added the T:task ⚙️ A task belongs to a story label Nov 4, 2022
@p0mvn
Copy link
Member Author

p0mvn commented Nov 4, 2022

Before proceeding, consider alternatives from: #3097

@p0mvn p0mvn self-assigned this Nov 7, 2022
@p0mvn
Copy link
Member Author

p0mvn commented Nov 7, 2022

fixed by #3097

@p0mvn p0mvn closed this as completed Nov 7, 2022
Repository owner moved this from Needs Review 🔍 to Done ✅ in Osmosis Chain Development Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/swap-router F: concentrated-liquidity Tracking the development of concentrated liquidity feature to improve filtering on the project board T:task ⚙️ A task belongs to a story
Projects
Archived in project
Development

No branches or pull requests

1 participant