-
Notifications
You must be signed in to change notification settings - Fork 606
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
Feature/add details to join exit pool reponse #1886
Merged
ValarDragon
merged 9 commits into
osmosis-labs:main
from
quasar-finance:feature/add_details_to_join_exit_pool_reponse
Jul 7, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1e9f69
Add ShareOutAmount and TokenIn fields to MsgJoinPoolResponse
Ehsan-saradar a3045b0
Fix yaml tags
Ehsan-saradar 8f9b40c
Fix yaml tags of MsgExitPoolResponse
Ehsan-saradar 35a342a
Set TokenOut as exitCoins
Ehsan-saradar bb0bb73
Fix tests
Ehsan-saradar 33dc056
Merge branch 'main' into dev/takeover_1886
ValarDragon 920b74e
Add Changelog
ValarDragon 63e976b
Add requested test updates
ValarDragon b2411d1
Merge pull request #2 from osmosis-labs/dev/takeover_1886
Ehsan-saradar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,21 +255,24 @@ func (suite *KeeperTestSuite) TestCreateBalancerPool() { | |
|
||
// TODO: Add more edge cases around TokenInMaxs not containing every token in pool. | ||
func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | ||
fiveKFooAndBar := sdk.NewCoins(sdk.NewCoin("bar", sdk.NewInt(5000)), sdk.NewCoin("foo", sdk.NewInt(5000))) | ||
tests := []struct { | ||
fn func(poolId uint64) | ||
}{ | ||
{ | ||
fn: func(poolId uint64) { | ||
keeper := suite.App.GAMMKeeper | ||
balancesBefore := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[1]) | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{}) | ||
neededLp, sharesOut, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{}) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(types.OneShare.MulRaw(50).String(), sharesOut.String()) | ||
suite.Require().Equal(types.OneShare.MulRaw(50).String(), suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], "gamm/pool/1").Amount.String()) | ||
balancesAfter := suite.App.BankKeeper.GetAllBalances(suite.Ctx, suite.TestAccs[1]) | ||
|
||
deltaBalances, _ := balancesBefore.SafeSub(balancesAfter) | ||
// The pool was created with the 10000foo, 10000bar, and the pool share was minted as 100000000gamm/pool/1. | ||
// Thus, to get the 50*OneShare gamm/pool/1, (10000foo, 10000bar) * (1 / 2) balances should be provided. | ||
suite.Require().Equal(deltaBalances.FilterDenoms([]string{"foo", "bar"}).Sort().String(), neededLp.Sort().String()) | ||
suite.Require().Equal("5000", deltaBalances.AmountOf("foo").String()) | ||
suite.Require().Equal("5000", deltaBalances.AmountOf("bar").String()) | ||
|
||
|
@@ -280,14 +283,14 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | |
{ | ||
fn: func(poolId uint64) { | ||
keeper := suite.App.GAMMKeeper | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, sdk.NewInt(0), sdk.Coins{}) | ||
_, _, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, sdk.NewInt(0), sdk.Coins{}) | ||
suite.Require().Error(err, "can't join the pool with requesting 0 share amount") | ||
}, | ||
}, | ||
{ | ||
fn: func(poolId uint64) { | ||
keeper := suite.App.GAMMKeeper | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, sdk.NewInt(-1), sdk.Coins{}) | ||
_, _, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, sdk.NewInt(-1), sdk.Coins{}) | ||
suite.Require().Error(err, "can't join the pool with requesting negative share amount") | ||
}, | ||
}, | ||
|
@@ -296,7 +299,7 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | |
keeper := suite.App.GAMMKeeper | ||
// Test the "tokenInMaxs" | ||
// In this case, to get the 50 * OneShare amount of share token, the foo, bar token are expected to be provided as 5000 amounts. | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
_, _, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
sdk.NewCoin("bar", sdk.NewInt(4999)), sdk.NewCoin("foo", sdk.NewInt(4999)), | ||
}) | ||
suite.Require().Error(err) | ||
|
@@ -307,13 +310,17 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | |
keeper := suite.App.GAMMKeeper | ||
// Test the "tokenInMaxs" | ||
// In this case, to get the 50 * OneShare amount of share token, the foo, bar token are expected to be provided as 5000 amounts. | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
sdk.NewCoin("bar", sdk.NewInt(5000)), sdk.NewCoin("foo", sdk.NewInt(5000)), | ||
}) | ||
actualTokenIn, actualSharesOut, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
fiveKFooAndBar[0], fiveKFooAndBar[1]}) | ||
suite.Require().NoError(err) | ||
|
||
liquidity := suite.App.GAMMKeeper.GetTotalLiquidity(suite.Ctx) | ||
suite.Require().Equal("15000bar,15000foo", liquidity.String()) | ||
// TODO: Add these tests to more cases, as part of improving this test structure. | ||
// 100% add, so actualTokenIn = max provided | ||
suite.Require().Equal(fiveKFooAndBar, actualTokenIn) | ||
// shares out was estimated perfectly | ||
suite.Require().Equal(types.OneShare.MulRaw(50), actualSharesOut) | ||
}, | ||
}, | ||
{ | ||
|
@@ -322,7 +329,7 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | |
// Test the "tokenInMaxs" with an additional invalid denom | ||
// In this case, to get the 50 * OneShare amount of share token, the foo, bar token are expected to be provided as 5000 amounts. | ||
// The test input has the correct amount for each, but also includes an incorrect denom that should cause an error | ||
err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
_, _, err := keeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[1], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
sdk.NewCoin("bar", sdk.NewInt(5000)), sdk.NewCoin("foo", sdk.NewInt(5000)), sdk.NewCoin("baz", sdk.NewInt(5000)), | ||
}) | ||
suite.Require().Error(err) | ||
|
@@ -351,6 +358,7 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() { | |
} | ||
|
||
func (suite *KeeperTestSuite) TestExitPool() { | ||
fiveKFooAndBar := sdk.NewCoins(sdk.NewCoin("bar", sdk.NewInt(5000)), sdk.NewCoin("foo", sdk.NewInt(5000))) | ||
tests := []struct { | ||
fn func(poolId uint64) | ||
}{ | ||
|
@@ -414,10 +422,11 @@ func (suite *KeeperTestSuite) TestExitPool() { | |
|
||
// Test the "tokenOutMins" | ||
// In this case, to refund the 50000000 amount of share token, the foo, bar token are expected to be refunded as 5000 amounts. | ||
_, err := keeper.ExitPool(suite.Ctx, suite.TestAccs[0], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
exitedCoins, err := keeper.ExitPool(suite.Ctx, suite.TestAccs[0], poolId, types.OneShare.MulRaw(50), sdk.Coins{ | ||
sdk.NewCoin("foo", sdk.NewInt(5000)), | ||
}) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(fiveKFooAndBar, exitedCoins) | ||
}, | ||
}, | ||
} | ||
|
@@ -505,7 +514,7 @@ func (suite *KeeperTestSuite) TestJoinPoolExitPool_InverseRelationship() { | |
balanceBeforeJoin := suite.App.BankKeeper.GetAllBalances(suite.Ctx, joinPoolAcc) | ||
fmt.Println(balanceBeforeJoin.String()) | ||
|
||
err = suite.App.GAMMKeeper.JoinPoolNoSwap(suite.Ctx, joinPoolAcc, poolId, tc.joinPoolShareAmt, sdk.Coins{}) | ||
_, _, err = suite.App.GAMMKeeper.JoinPoolNoSwap(suite.Ctx, joinPoolAcc, poolId, tc.joinPoolShareAmt, sdk.Coins{}) | ||
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. ditto:Can we add check and test ShareOutAmount and TokenIn returned here is as expected? |
||
suite.Require().NoError(err) | ||
|
||
_, err = suite.App.GAMMKeeper.ExitPool(suite.Ctx, joinPoolAcc, poolId, tc.joinPoolShareAmt, sdk.Coins{}) | ||
|
@@ -547,7 +556,7 @@ func (suite *KeeperTestSuite) TestActiveBalancerPool() { | |
suite.Ctx = suite.Ctx.WithBlockTime(tc.blockTime) | ||
|
||
// uneffected by start time | ||
err := suite.App.GAMMKeeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[0], poolId, types.OneShare.MulRaw(50), sdk.Coins{}) | ||
_, _, err := suite.App.GAMMKeeper.JoinPoolNoSwap(suite.Ctx, suite.TestAccs[0], poolId, types.OneShare.MulRaw(50), sdk.Coins{}) | ||
suite.Require().NoError(err) | ||
_, err = suite.App.GAMMKeeper.ExitPool(suite.Ctx, suite.TestAccs[0], poolId, types.InitPoolSharesSupply.QuoRaw(2), sdk.Coins{}) | ||
suite.Require().NoError(err) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 check and test ShareOutAmount and TokenIn returned here is as expected?