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

JoinPoolNoSwap simulation #3242

Merged
merged 18 commits into from
Nov 14, 2022
Merged

JoinPoolNoSwap simulation #3242

merged 18 commits into from
Nov 14, 2022

Conversation

pysel
Copy link
Member

@pysel pysel commented Nov 4, 2022

Closes: #2956 (actually this)

What is the purpose of the change

Adds a simulating query of JoinPoolNoSwap

Testing and Verifying

tests added

Documentation and Release Note

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

@github-actions github-actions bot added the C:x/gamm Changes, features and bugs related to the gamm module. label Nov 4, 2022
@georgemc98
Copy link
Contributor

@apollo-sturdy

This looks good to me. Can we change the name SimJoinPoolNoSwap to CalcJoinPoolNoSwap?

@pysel pysel changed the title Issue2956 cont JoinPoolNoSwap simulation Nov 5, 2022
@pysel pysel marked this pull request as ready for review November 5, 2022 05:01
@pysel pysel requested a review from a team November 5, 2022 05:01
@pysel
Copy link
Member Author

pysel commented Nov 5, 2022

fixed minor mistakes, now ready for review @apollo-sturdy

@apollo-sturdy
Copy link

apollo-sturdy commented Nov 9, 2022

fixed minor mistakes, now ready for review @apollo-sturdy

Hi. Thanks very much. I now had a chance to look at this. After more thought, this approach doesn't solve for our use case. The reason is that we currently have no way to know what to input to MsgJoinPool argument ShareOutAmount, which is what we want this query to address. So the query should be able to answer the question:

Given some amount of assets that we want to provide liquidity with via MsgJoinPool, what should we pass in as ShareOutAmount?

I should have noticed that @p0mvn's description of the requirements written here doesn't match what we need, since we don't know how to get the shareOutAmount in the first place.

@p0mvn Do you have any suggestions how to solve this? One option would of course be to change the API of MsgJoinPool to the more common one of just taking in the assets the user wants to provide liquidity with. Is this something you would be willing to consider?

@georgemc98
Copy link
Contributor

Hi @rusakh, did something change recently with the make proto-all command? I've been running make proto-all with no issues, but today the command is not generating the pg.go files. I implemented CalcJoinPoolNoSwapShares to @apollo-sturdy specifications and added table driven tests for it, but I cannot produce the pb.go file, even after restarting Docker. The CalcJoinPoolNoSwapShares query should pass the tests once the pb.go files are generated.

@pysel pysel marked this pull request as draft November 10, 2022 05:14
@pysel
Copy link
Member Author

pysel commented Nov 10, 2022

Hi @georgemc98. That is odd, make proto-all works on my machine well, however, after I generate files, in gamm/types/query.pb.go I get a few errors, for example in:

size := m.TokensIn.Size()

the error is:

m.TokensIn.Size undefined (type "github.com/cosmos/cosmos-sdk/types".Coins has no field or method Size)

@georgemc98
Copy link
Contributor

Hi @georgemc98. That is odd, make proto-all works on my machine well, however, after I generate files, in gamm/types/query.pb.go I get a few errors, for example in:

size := m.TokensIn.Size()

the error is:

m.TokensIn.Size undefined (type "github.com/cosmos/cosmos-sdk/types".Coins has no field or method Size)

I changed the tokens_in type. I think that should fix the issue. @rusakh

@pysel
Copy link
Member Author

pysel commented Nov 10, 2022

Hi @georgemc98. That is odd, make proto-all works on my machine well, however, after I generate files, in gamm/types/query.pb.go I get a few errors, for example in:

size := m.TokensIn.Size()

the error is:

m.TokensIn.Size undefined (type "github.com/cosmos/cosmos-sdk/types".Coins has no field or method Size)

I changed the tokens_in type. I think that should fix the issue. @rusakh

oh, yes it did, thank you very much! I will continue working on it as soon as possible

@georgemc98
Copy link
Contributor

Hi @georgemc98. That is odd, make proto-all works on my machine well, however, after I generate files, in gamm/types/query.pb.go I get a few errors, for example in:

size := m.TokensIn.Size()

the error is:

m.TokensIn.Size undefined (type "github.com/cosmos/cosmos-sdk/types".Coins has no field or method Size)

I changed the tokens_in type. I think that should fix the issue. @rusakh

oh, yes it did, thank you very much! I will continue working on it as soon as possible

Thanks! I fixed the unit tests and I am going to write one additional test. I'll have it done in a few hours.

@georgemc98
Copy link
Contributor

Hi @georgemc98. That is odd, make proto-all works on my machine well, however, after I generate files, in gamm/types/query.pb.go I get a few errors, for example in:

size := m.TokensIn.Size()

the error is:

m.TokensIn.Size undefined (type "github.com/cosmos/cosmos-sdk/types".Coins has no field or method Size)

I changed the tokens_in type. I think that should fix the issue. @rusakh

oh, yes it did, thank you very much! I will continue working on it as soon as possible

@rusakh The test pass on my end and we are ready to merge. Should we change this from a Draft so it can start being reviewed?

@pysel
Copy link
Member Author

pysel commented Nov 11, 2022

thank you @georgemc98, opened!

@p0mvn
Copy link
Member

p0mvn commented Nov 11, 2022

Can we fix CI here?

x/gamm/keeper/export_test.go Outdated Show resolved Hide resolved
x/gamm/keeper/grpc_query.go Outdated Show resolved Hide resolved
@p0mvn p0mvn added V:state/compatible/backport State machine compatible PR, should be backported A:backport/v13.x backport patches to v13.x branch labels Nov 11, 2022
@@ -288,6 +288,29 @@ func (q Querier) CalcExitPoolCoinsFromShares(ctx context.Context, req *types.Que
return &types.QueryCalcExitPoolCoinsFromSharesResponse{TokensOut: exitCoins}, nil
}

// CalcJoinPoolNoSwapShares returns the amount of shares you'd get if joined a pool without a swap and tokens which need to be provided
func (q Querier) CalcJoinPoolNoSwapShares(ctx context.Context, req *types.QueryCalcJoinPoolNoSwapSharesRequest) (*types.QueryCalcJoinPoolNoSwapSharesResponse, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we please add this and your previous query to this test:

func (s *QueryTestSuite) TestQueriesNeverAlterState() {

It ensures that queries don't alter state. This would be very useful for a stargate query

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, I'll change this ASAP

}

sdkCtx := sdk.UnwrapSDKContext(ctx)
pool, err := q.GetPoolAndPoke(sdkCtx, req.PoolId)
Copy link
Member

Choose a reason for hiding this comment

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

This method calls PokePool() which may update pool weights for a balancer pool. Is this acceptable for a stargate query?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link

@apollo-sturdy apollo-sturdy Nov 14, 2022

Choose a reason for hiding this comment

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

Seems like it's fine: #2972 (comment)

So then this PR should be able to be merged?

@p0mvn

@p0mvn p0mvn merged commit fa2f483 into osmosis-labs:main Nov 14, 2022
mergify bot pushed a commit that referenced this pull request Nov 14, 2022
* autocli copy from cosmos

* reset

* save

* SimJoinPoolNoSwap

* docs

* JoinPoolNoSwap simulation

* more fixes

* fix docs and name

* fix: change tokens_in type

* test: fix TestCalcJoinPoolNoSwapShares test

* chore: remove whitespace

Co-authored-by: Roman <[email protected]>

* chore: change query name in comment

Co-authored-by: Roman <[email protected]>

* feat: build query.pb.go

Co-authored-by: Ruslan Akhtariev <[email protected]>
Co-authored-by: George McAskill <[email protected]>
Co-authored-by: Roman <[email protected]>
(cherry picked from commit fa2f483)
p0mvn pushed a commit that referenced this pull request Nov 14, 2022
* autocli copy from cosmos

* reset

* save

* SimJoinPoolNoSwap

* docs

* JoinPoolNoSwap simulation

* more fixes

* fix docs and name

* fix: change tokens_in type

* test: fix TestCalcJoinPoolNoSwapShares test

* chore: remove whitespace

Co-authored-by: Roman <[email protected]>

* chore: change query name in comment

Co-authored-by: Roman <[email protected]>

* feat: build query.pb.go

Co-authored-by: Ruslan Akhtariev <[email protected]>
Co-authored-by: George McAskill <[email protected]>
Co-authored-by: Roman <[email protected]>
(cherry picked from commit fa2f483)

Co-authored-by: Ruslan Akhtariev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v13.x backport patches to v13.x branch C:x/gamm Changes, features and bugs related to the gamm module. V:state/compatible/backport State machine compatible PR, should be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[x/gamm]: Add RPC query endpoints for joining and exiting pools
4 participants