-
Notifications
You must be signed in to change notification settings - Fork 52
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
Set initial LP token price to be one & add unit test for create pool #131
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
"github.com/elys-network/elys/x/amm/keeper" | ||
"github.com/elys-network/elys/x/amm/types" | ||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestMsgServerCreatePool() { | ||
for _, tc := range []struct { | ||
desc string | ||
senderInitBalance sdk.Coins | ||
poolParams types.PoolParams | ||
poolAssets []types.PoolAsset | ||
expSenderBalance sdk.Coins | ||
expTotalLiquidity sdk.Coins | ||
expLpCommitment sdk.Coin | ||
expPass bool | ||
}{ | ||
{ | ||
desc: "zero tvl pool creation", | ||
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("ueden", 1000000), sdk.NewInt64Coin("uelys", 1000000)}, | ||
poolParams: types.PoolParams{ | ||
SwapFee: sdk.ZeroDec(), | ||
ExitFee: sdk.ZeroDec(), | ||
UseOracle: false, | ||
WeightBreakingFeeMultiplier: sdk.ZeroDec(), | ||
SlippageReduction: sdk.ZeroDec(), | ||
LpFeePortion: sdk.ZeroDec(), | ||
StakingFeePortion: sdk.ZeroDec(), | ||
WeightRecoveryFeePortion: sdk.ZeroDec(), | ||
ThresholdWeightDifference: sdk.ZeroDec(), | ||
FeeDenom: "", | ||
}, | ||
poolAssets: []types.PoolAsset{ | ||
{ | ||
Token: sdk.NewInt64Coin("ueden", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
{ | ||
Token: sdk.NewInt64Coin("uelys", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
}, | ||
expSenderBalance: sdk.Coins{}, | ||
expLpCommitment: sdk.NewCoin("amm/pool/0", sdk.NewInt(100).Mul(types.OneShare)), | ||
expPass: true, | ||
}, | ||
{ | ||
desc: "positive tvl pool creation", | ||
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("ueden", 1000000), sdk.NewInt64Coin("uusdc", 1000000)}, | ||
poolParams: types.PoolParams{ | ||
SwapFee: sdk.ZeroDec(), | ||
ExitFee: sdk.ZeroDec(), | ||
UseOracle: false, | ||
WeightBreakingFeeMultiplier: sdk.ZeroDec(), | ||
SlippageReduction: sdk.ZeroDec(), | ||
LpFeePortion: sdk.ZeroDec(), | ||
StakingFeePortion: sdk.ZeroDec(), | ||
WeightRecoveryFeePortion: sdk.ZeroDec(), | ||
ThresholdWeightDifference: sdk.ZeroDec(), | ||
FeeDenom: "", | ||
}, | ||
poolAssets: []types.PoolAsset{ | ||
{ | ||
Token: sdk.NewInt64Coin("ueden", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
{ | ||
Token: sdk.NewInt64Coin("uusdc", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
}, | ||
expSenderBalance: sdk.Coins{}, | ||
expLpCommitment: sdk.NewCoin("amm/pool/0", sdk.NewInt(2).Mul(types.OneShare)), | ||
expPass: true, | ||
}, | ||
{ | ||
desc: "not enough balance to create pool", | ||
senderInitBalance: sdk.Coins{sdk.NewInt64Coin("ueden", 1000000)}, | ||
poolParams: types.PoolParams{ | ||
SwapFee: sdk.ZeroDec(), | ||
ExitFee: sdk.ZeroDec(), | ||
UseOracle: false, | ||
WeightBreakingFeeMultiplier: sdk.ZeroDec(), | ||
SlippageReduction: sdk.ZeroDec(), | ||
LpFeePortion: sdk.ZeroDec(), | ||
StakingFeePortion: sdk.ZeroDec(), | ||
WeightRecoveryFeePortion: sdk.ZeroDec(), | ||
ThresholdWeightDifference: sdk.ZeroDec(), | ||
FeeDenom: "", | ||
}, | ||
poolAssets: []types.PoolAsset{ | ||
{ | ||
Token: sdk.NewInt64Coin("ueden", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
{ | ||
Token: sdk.NewInt64Coin("uusdc", 1000000), | ||
Weight: sdk.OneInt(), | ||
}, | ||
}, | ||
expSenderBalance: sdk.Coins{}, | ||
expLpCommitment: sdk.Coin{}, | ||
expPass: false, | ||
}, | ||
} { | ||
suite.Run(tc.desc, func() { | ||
suite.SetupTest() | ||
suite.SetupStableCoinPrices() | ||
|
||
// bootstrap accounts | ||
sender := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) | ||
|
||
// bootstrap balances | ||
err := suite.app.BankKeeper.MintCoins(suite.ctx, minttypes.ModuleName, tc.senderInitBalance) | ||
suite.Require().NoError(err) | ||
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, minttypes.ModuleName, sender, tc.senderInitBalance) | ||
suite.Require().NoError(err) | ||
|
||
// execute function | ||
msgServer := keeper.NewMsgServerImpl(suite.app.AmmKeeper) | ||
resp, err := msgServer.CreatePool( | ||
sdk.WrapSDKContext(suite.ctx), | ||
&types.MsgCreatePool{ | ||
Sender: sender.String(), | ||
PoolParams: &tc.poolParams, | ||
PoolAssets: tc.poolAssets, | ||
}) | ||
if !tc.expPass { | ||
suite.Require().Error(err) | ||
} else { | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(resp.PoolID, uint64(0)) | ||
|
||
pools := suite.app.AmmKeeper.GetAllPool(suite.ctx) | ||
suite.Require().Len(pools, 1) | ||
suite.Require().Equal(pools[0].PoolId, uint64(0)) | ||
suite.Require().Equal(pools[0].PoolParams, tc.poolParams) | ||
suite.Require().Equal(pools[0].TotalShares.Amount.String(), tc.expLpCommitment.Amount.String()) | ||
|
||
totalWeight := sdk.ZeroInt() | ||
for _, poolAsset := range tc.poolAssets { | ||
totalWeight = totalWeight.Add(poolAsset.Weight) | ||
} | ||
suite.Require().Equal(pools[0].TotalWeight.String(), totalWeight.MulRaw(types.GuaranteedWeightPrecision).String()) | ||
|
||
// check balance change on sender | ||
balances := suite.app.BankKeeper.GetAllBalances(suite.ctx, sender) | ||
suite.Require().Equal(balances.String(), tc.expSenderBalance.String()) | ||
|
||
// check lp token commitment | ||
commitments, found := suite.app.CommitmentKeeper.GetCommitments(suite.ctx, sender.String()) | ||
suite.Require().True(found) | ||
suite.Require().Len(commitments.CommittedTokens, 1) | ||
suite.Require().Equal(commitments.CommittedTokens[0].Denom, tc.expLpCommitment.Denom) | ||
suite.Require().Equal(commitments.CommittedTokens[0].Amount.String(), tc.expLpCommitment.Amount.String()) | ||
} | ||
}) | ||
} | ||
} |
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
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.
This one solved the issue that the lp tokens were not balanced?