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

Add stableswap to pooltype, and pooltype query to stargate whitelist #3356

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

* [#2788](https://github.com/osmosis-labs/osmosis/pull/2788) Add logarithm base 2 implementation.
* [#2739](https://github.com/osmosis-labs/osmosis/pull/2739) Add pool type query
* [#2739](https://github.com/osmosis-labs/osmosis/pull/2739),[#3356](https://github.com/osmosis-labs/osmosis/pull/3356) Add pool type query, and add it to stargate whitelist
* [#2956](https://github.com/osmosis-labs/osmosis/issues/2956) Add queries for calculating amount of shares/tokens you get by providing X tokens/shares when entering/exiting a pool
* [#3313](https://github.com/osmosis-labs/osmosis/pull/3313) Upgrade to IBC v3.4.0, allowing for IBC transfers with metadata.
* [#3335](https://github.com/osmosis-labs/osmosis/pull/3335) Add v2 spot price queries
Expand Down
21 changes: 21 additions & 0 deletions app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

gammkeeper "github.com/osmosis-labs/osmosis/v12/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/stableswap"
gammtypes "github.com/osmosis-labs/osmosis/v12/x/gamm/types"
)

Expand Down Expand Up @@ -32,6 +33,11 @@ var DefaultPoolAssets = []balancer.PoolAsset{
Token: sdk.NewCoin("uosmo", sdk.NewInt(5000000)),
},
}
var DefaultStableswapLiquidity = sdk.NewCoins(
sdk.NewCoin("foo", sdk.NewInt(10000000)),
sdk.NewCoin("bar", sdk.NewInt(10000000)),
sdk.NewCoin("baz", sdk.NewInt(10000000)),
)

// PrepareBalancerPoolWithCoins returns a balancer pool
// consisted of given coins with equal weight.
Expand Down Expand Up @@ -81,6 +87,21 @@ func (s *KeeperTestHelper) PrepareBalancerPool() uint64 {
return poolId
}

func (s *KeeperTestHelper) PrepareBasicStableswapPool() uint64 {
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

params := stableswap.PoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
}

msg := stableswap.NewMsgCreateStableswapPool(s.TestAccs[0], params, DefaultStableswapLiquidity, []uint64{}, "")
poolId, err := s.App.GAMMKeeper.CreatePool(s.Ctx, msg)
s.NoError(err)
return poolId
}

// PrepareBalancerPoolWithPoolParams sets up a Balancer pool with poolParams.
func (s *KeeperTestHelper) PrepareBalancerPoolWithPoolParams(poolParams balancer.PoolParams) uint64 {
// Mint some assets to the account.
Expand Down
1 change: 1 addition & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func init() {
setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/TotalPoolLiquidity", &gammtypes.QueryTotalPoolLiquidityResponse{})
setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/TotalShares", &gammtypes.QueryTotalSharesResponse{})
setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/SpotPrice", &gammtypes.QuerySpotPriceResponse{})
setWhitelistedQuery("/osmosis.gamm.v1beta1.Query/PoolType", &gammtypes.QueryPoolTypeResponse{})
setWhitelistedQuery("/osmosis.gamm.v2.Query/SpotPrice", &gammv2types.QuerySpotPriceResponse{})

// incentives
Expand Down
15 changes: 11 additions & 4 deletions x/gamm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer"
balancertypes "github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v12/x/gamm/pool-models/stableswap"
"github.com/osmosis-labs/osmosis/v12/x/gamm/types"
"github.com/osmosis-labs/osmosis/v12/x/gamm/v2types"
)
Expand Down Expand Up @@ -416,15 +417,21 @@ func (suite *KeeperTestSuite) TestQueryPools() {
}

func (suite *KeeperTestSuite) TestPoolType() {
poolId := suite.PrepareBalancerPool()
poolIdBalancer := suite.PrepareBalancerPool()
poolIdStableswap := suite.PrepareBasicStableswapPool()

// error when querying invalid pool ID
_, err := suite.queryClient.PoolType(gocontext.Background(), &types.QueryPoolTypeRequest{PoolId: poolId + 1})
_, err := suite.queryClient.PoolType(gocontext.Background(), &types.QueryPoolTypeRequest{PoolId: poolIdStableswap + 1})
suite.Require().Error(err)

res, err := suite.queryClient.PoolType(gocontext.Background(), &types.QueryPoolTypeRequest{PoolId: poolId})
res, err := suite.queryClient.PoolType(gocontext.Background(), &types.QueryPoolTypeRequest{PoolId: poolIdBalancer})
suite.Require().NoError(err)
suite.Require().Equal(balancer.PoolTypeName, res.PoolType)

res, err = suite.queryClient.PoolType(gocontext.Background(),
&types.QueryPoolTypeRequest{PoolId: poolIdStableswap})
suite.Require().NoError(err)
suite.Require().Equal("Balancer", res.PoolType)
suite.Require().Equal(stableswap.PoolTypeName, res.PoolType)
}

func (suite *KeeperTestSuite) TestQueryNumPools1() {
Expand Down
4 changes: 3 additions & 1 deletion x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func (k Keeper) GetPoolType(ctx sdk.Context, poolId uint64) (string, error) {

switch pool := pool.(type) {
case *balancer.Pool:
return "Balancer", nil
return balancer.PoolTypeName, nil
case *stableswap.Pool:
return stableswap.PoolTypeName, nil
default:
errMsg := fmt.Sprintf("unrecognized %s pool type: %T", types.ModuleName, pool)
return "", sdkerrors.Wrap(sdkerrors.ErrUnpackAny, errMsg)
Expand Down
2 changes: 2 additions & 0 deletions x/gamm/pool-models/balancer/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ var (
//
// This is done so that smooth weight changes have enough precision to actually be smooth.
GuaranteedWeightPrecision int64 = 1 << 30

PoolTypeName string = "Balancer"
)
2 changes: 2 additions & 0 deletions x/gamm/pool-models/stableswap/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ func init() {
RegisterLegacyAminoCodec(authzcodec.Amino)
amino.Seal()
}

const PoolTypeName string = "Stableswap"
11 changes: 8 additions & 3 deletions x/gamm/pool-models/stableswap/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ func (msg MsgCreateStableswapPool) ValidateBasic() error {
}

// validation for scaling factors
scalingFactors := msg.ScalingFactors
// The message's scaling factors must be empty or a valid set of scaling factors
if len(msg.ScalingFactors) != 0 {
if err = validateScalingFactors(msg.ScalingFactors, len(msg.InitialPoolLiquidity)); err != nil {
if len(scalingFactors) != 0 {
if err = validateScalingFactors(scalingFactors, len(msg.InitialPoolLiquidity)); err != nil {
return err
}
} else {
for i := 0; i < len(msg.InitialPoolLiquidity); i += 1 {
scalingFactors = append(scalingFactors, 1)
}
}

// validation for pool initial liquidity
// The message's pool liquidity must have between 2 and 8 assets with at most 10B post-scaled units in each
if err = validatePoolLiquidity(msg.InitialPoolLiquidity, msg.ScalingFactors); err != nil {
if err = validatePoolLiquidity(msg.InitialPoolLiquidity, scalingFactors); err != nil {
return err
}

Expand Down
8 changes: 8 additions & 0 deletions x/gamm/pool-models/stableswap/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func TestMsgCreateStableswapPoolValidateBasic(t *testing.T) {
}),
expectPass: true,
},
{
name: "no scaling factors",
msg: updateMsg(func(msg stableswap.MsgCreateStableswapPool) stableswap.MsgCreateStableswapPool {
msg.ScalingFactors = []uint64{}
return msg
}),
expectPass: true,
},
{
name: "invalid sender",
msg: updateMsg(func(msg stableswap.MsgCreateStableswapPool) stableswap.MsgCreateStableswapPool {
Expand Down