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: scaling factors validation in create stableswap pool, small refactor and unit tests #1459

Closed
wants to merge 15 commits into from

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented May 10, 2022

Closes: #1392

What is the purpose of the change

Implemented scaling factors for CreateStableswapPool, NewStableswapPool, along with ValidateBasic validation.

Refactored to make it more testable and align the design closer to balancer.

All changed logic is covered by unit tests.

Brief Changelog

Testing and Verifying

This change introduces a scaling factors to CreateSta

includes a minor refactor to introduce PoolAssets in stableswap pool to make the design more aligned with the balancer and more testable.

This change added tests and can be verified as follows:

go test github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/stableswap

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? yes - proto files were changed
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? no
  • How is the feature or change documented? not applicable

@github-actions github-actions bot added the C:x/gamm Changes, features and bugs related to the gamm module. label May 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 10, 2022

Codecov Report

Merging #1459 (c6f7ba2) into main (f56fbe5) will decrease coverage by 0.18%.
The diff coverage is 23.74%.

@@            Coverage Diff             @@
##             main    #1459      +/-   ##
==========================================
- Coverage   19.82%   19.64%   -0.19%     
==========================================
  Files         202      230      +28     
  Lines       27685    31617    +3932     
==========================================
+ Hits         5489     6211     +722     
- Misses      21175    24281    +3106     
- Partials     1021     1125     +104     
Impacted Files Coverage Δ
x/epochs/client/cli/query.go 0.00% <ø> (ø)
x/gamm/client/cli/query.go 36.74% <0.00%> (-0.36%) ⬇️
x/gamm/pool-models/balancer/balancer_pool.go 64.37% <0.00%> (ø)
x/gamm/pool-models/stableswap/tx.pb.go 0.77% <0.00%> (ø)
x/gamm/types/pool.go 0.00% <ø> (ø)
x/incentives/client/cli/query.go 0.00% <ø> (ø)
x/incentives/keeper/distribute.go 61.00% <0.00%> (ø)
x/incentives/keeper/hooks.go 50.00% <0.00%> (ø)
x/incentives/module.go 51.11% <0.00%> (+1.11%) ⬆️
x/lockup/client/cli/query.go 51.99% <0.00%> (-3.00%) ⬇️
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a8685a...c6f7ba2. Read the comment docs.


func ValidatePoolAssets(poolAssets []PoolAsset) error {
// validation for pool initial liquidity
// TODO: expand this check to accommodate multi-asset pools for stableswap
Copy link
Member Author

Choose a reason for hiding this comment

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

this was copied over, what are the plans for this?

@@ -154,7 +139,9 @@ func (pa *Pool) SwapOutAmtGivenIn(ctx sdk.Context, tokenIn sdk.Coins, tokenOutDe
return sdk.Coin{}, err
}

pa.updatePoolLiquidityForSwap(tokenIn, sdk.NewCoins(tokenOut))
if err := pa.updatePoolLiquidityForSwap(tokenIn, sdk.NewCoins(tokenOut)); err != nil {
panic(err)
Copy link
Member Author

Choose a reason for hiding this comment

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

this was changed to make it more testable in unit tests

// Returns a pool asset, and its index. If err != nil, then the index will be valid.
// CONTRACT: pool must be created with NewStableSwapPool so that the pool assets are sorted
// by denom. Otherwise, the behavior is undefined.
func (pa Pool) getPoolAssetAndIndex(denom string) (int, PoolAsset, error) {
Copy link
Member Author

@p0mvn p0mvn May 10, 2022

Choose a reason for hiding this comment

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

this can be later generalized with balancer

@p0mvn p0mvn marked this pull request as ready for review May 10, 2022 08:05
@p0mvn p0mvn requested a review from a team May 10, 2022 08:05
@ValarDragon
Copy link
Member

I think the non-pool asset design was better tbh, and Balancer is what needs changing in the future

@p0mvn
Copy link
Member Author

p0mvn commented May 10, 2022

I think the non-pool asset design was better tbh, and Balancer is what needs changing in the future

Why do you think so?

I find it more brittle to rely on the order of 2 separate slices to be in sync. If 2 slices need to maintain the same order, they should be grouped and merged into one. Otherwise, a small update to the ordering of one of the slices in the future can bring them out of sync and might cause problems when debugging.

Additionally, while setting up unit tests, I found this abstraction to be easier to configure and assert on its results.

These were the 2 primary motivators for this change

Please let me know what you think

[ (gogoproto.moretags) = "yaml:\"token\"", (gogoproto.nullable) = false ];
// used for normalizing values for calculation amognst assets with different
// precisions
string scalingFactor = 2 [
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
string scalingFactor = 2 [
string scaling_factor = 2 [

(gogoproto.moretags) = "yaml:\"stableswap_scaling_factor\"",
(gogoproto.nullable) = false
];
repeated osmosis.gamm.stableswap.v1beta1.PoolAsset poolAssets = 6
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
repeated osmosis.gamm.stableswap.v1beta1.PoolAsset poolAssets = 6
repeated osmosis.gamm.stableswap.v1beta1.PoolAsset pool_assets = 6

@p0mvn
Copy link
Member Author

p0mvn commented May 19, 2022

@ValarDragon any updates on this?

@mattverse
Copy link
Member

Since this PR is starting to have blockers on it, we should decide direction for this on call

@mattverse mattverse mentioned this pull request Jun 2, 2022
55 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2022

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Jul 8, 2022
@mattverse
Copy link
Member

Stale bot is indeed doing its work! Nice :)

@github-actions github-actions bot removed the Stale label Jul 9, 2022
@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

@github-actions github-actions bot added the Stale label Jul 24, 2022
@github-actions github-actions bot closed this Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/gamm Changes, features and bugs related to the gamm module. Stale
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[x/gamm][StableSwap] Implement Scaling Factors to CreateStableswapPool
5 participants