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

Gamm Spec Out V3 - Modulize File Structure #541

Merged
merged 31 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46620fb
Change proto Pool -> BalancerPool
mattverse Oct 4, 2021
a720994
Proto changes implementation
mattverse Oct 4, 2021
0a4b0f5
Change proto
mattverse Oct 7, 2021
d804fc6
Revert Pool Query from BalancerPool
mattverse Oct 7, 2021
ec54a65
Change method names accordingly
mattverse Oct 7, 2021
3e876f1
Adjust marshal.go to struct change
mattverse Oct 7, 2021
c7620c0
Fix test
mattverse Oct 8, 2021
ce85d2f
Revert Pool Params, remove Exitfee, Swapfee query
mattverse Oct 12, 2021
81f6b74
Merge branch 'mattverse/gamm-spec-out' into mattverse/gamm-spec-out-v2
mattverse Oct 12, 2021
6531615
Remove unused Yaml from gamm query import
mattverse Oct 13, 2021
c2759a6
Add Pool Params Query
mattverse Oct 13, 2021
389e8ca
Merge branch 'mattverse/gamm-spec-out' into mattverse/gamm-spec-out-v2
mattverse Oct 13, 2021
b188e17
Revert yaml import
mattverse Oct 13, 2021
0c51405
Revert marshal back to poolParams
mattverse Oct 13, 2021
9efed1a
WIP: move balancerPool.proto into pool-models folder
mattverse Oct 13, 2021
bfa6735
WIP: moving balancer_pool.go logic from types -> pool-models
mattverse Oct 13, 2021
a62b2e3
WIP: Change in file structure
mattverse Oct 14, 2021
58f4870
WIP: Changing packages
mattverse Oct 18, 2021
e6bcb00
Use types from balancer package
mattverse Oct 18, 2021
9a29cd6
Revert go mod back to original state
mattverse Oct 19, 2021
229bd59
Register Codec
mattverse Oct 20, 2021
35e5a06
WIP: Fixing CLI test
mattverse Oct 24, 2021
747813a
Fix proto Any field to Balancer specific
mattverse Oct 25, 2021
3d04a93
Remove BalancerPoolParamsI
mattverse Oct 25, 2021
8ec9a8d
Add switch cases to poolParams Query, clean up code
mattverse Oct 26, 2021
8ffe3e8
WIP Merging main
mattverse Dec 16, 2021
efdb376
Merge branch 'main' into mattverse/gamm-spec-out-v3
mattverse Dec 20, 2021
26981f9
Merge branch 'main' into mattverse/gamm-spec-out-v3.1
mattverse Dec 20, 2021
209ddd6
Fix type from proto
mattverse Dec 20, 2021
60b84e2
Cleanup code for test codes
mattverse Dec 21, 2021
eccdfee
Cleanup code for merge
mattverse Dec 21, 2021
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
59 changes: 59 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package osmosis.gamm.v1beta1;
package osmosis.gamm.poolmodels;
Copy link
Member

Choose a reason for hiding this comment

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

should this still be behind a v1beta1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you referring to the entire file itself? If my understanding is right upon your question, pool-models is declared as a whole new package in gamm, thats where this is coming from.

Copy link
Member

Choose a reason for hiding this comment

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

I see, tbh I don't really understand the v1beta1 stuff. Lets make an issue for this question, and then ask regen folks post-holidays

Copy link
Member Author

Choose a reason for hiding this comment

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

haha. I'm supposing its just a legacy in structuring the proto files from the cosmos-sdk and that it does not have any additional functionallities. I didn't have any issues when I wasn't using v1beta1 as a package file structure, they should be good to be removed as well


import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
Expand All @@ -10,29 +10,9 @@ import "google/protobuf/timestamp.proto";
import "cosmos/auth/v1beta1/auth.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/osmosis-labs/osmosis/x/gamm/types";
import "osmosis/gamm/v1beta1/pool.proto";

message PoolAsset {
// Coins we are talking about,
// the denomination must be unique amongst all PoolAssets for this pool.
cosmos.base.v1beta1.Coin token = 1
[ (gogoproto.moretags) = "yaml:\"token\"", (gogoproto.nullable) = false ];
// Weight that is not normalized. This weight must be less than 2^50
string weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"weight\"",
(gogoproto.nullable) = false
];

// Weight that is normalized s.t. the sum of all pool assets' weights
// equals 1. If the user provides this value, it is ignored. This should only
// ever be set by the state machine. This is left as a TODO for a future PR.
// string normalizedWeight = 3 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
// (gogoproto.moretags) = "yaml:\"normalized_weight\"",
// (gogoproto.nullable) = true
// ];
}
option go_package = "github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer";

// Parameters for changing the weights in a balancer pool smoothly from
// a start weight and end weight over a period of time.
Expand Down Expand Up @@ -66,15 +46,15 @@ message SmoothWeightChangeParams {
// The amount PoolAsset.token.amount field is ignored if present,
// future type refactorings should just have a type with the denom & weight
// here.
repeated PoolAsset initialPoolWeights = 3 [
repeated osmosis.gamm.v1beta1.PoolAsset initialPoolWeights = 3 [
(gogoproto.moretags) = "yaml:\"initial_pool_weights\"",
(gogoproto.nullable) = false
];
// The target pool weights. The pool weights will change linearly with respect
// to time between start_time, and start_time + duration. The amount
// PoolAsset.token.amount field is ignored if present, future type
// refactorings should just have a type with the denom & weight here.
repeated PoolAsset targetPoolWeights = 4 [
repeated osmosis.gamm.v1beta1.PoolAsset targetPoolWeights = 4 [
(gogoproto.moretags) = "yaml:\"target_pool_weights\"",
(gogoproto.nullable) = false
];
Expand Down Expand Up @@ -139,7 +119,7 @@ message BalancerPool {
];
// These are assumed to be sorted by denomiation.
// They contain the pool asset and the information about the weight
repeated PoolAsset poolAssets = 6 [
repeated osmosis.gamm.v1beta1.PoolAsset poolAssets = 6 [
(gogoproto.moretags) = "yaml:\"pool_assets\"",
(gogoproto.nullable) = false
];
Expand Down
29 changes: 29 additions & 0 deletions proto/osmosis/gamm/pool-models/balancer/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package osmosis.gamm.poolmodels;

import "gogoproto/gogo.proto";
import "osmosis/gamm/pool-models/balancer/balancerPool.proto";
import "osmosis/gamm/v1beta1/pool.proto";

option go_package = "github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer";

service Msg {
rpc CreateBalancerPool(MsgCreateBalancerPool)
returns (MsgCreateBalancerPoolResponse);
}

// ===================== MsgCreatePool
message MsgCreateBalancerPool {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];

BalancerPoolParams poolParams = 2
[ (gogoproto.moretags) = "yaml:\"pool_params\"" ];

repeated osmosis.gamm.v1beta1.PoolAsset poolAssets = 3
[ (gogoproto.nullable) = false ];

string future_pool_governor = 4
[ (gogoproto.moretags) = "yaml:\"future_pool_governor\"" ];
}

message MsgCreateBalancerPoolResponse {}
30 changes: 30 additions & 0 deletions proto/osmosis/gamm/v1beta1/pool.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package osmosis.gamm.v1beta1;

import "gogoproto/gogo.proto";

import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/osmosis-labs/osmosis/x/gamm/types";

message PoolAsset {
// Coins we are talking about,
// the denomination must be unique amongst all PoolAssets for this pool.
cosmos.base.v1beta1.Coin token = 1
[ (gogoproto.moretags) = "yaml:\"token\"", (gogoproto.nullable) = false ];
// Weight that is not normalized. This weight must be less than 2^50
string weight = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"weight\"",
(gogoproto.nullable) = false
];
mattverse marked this conversation as resolved.
Show resolved Hide resolved

// Weight that is normalized s.t. the sum of all pool assets' weights
// equals 1. If the user provides this value, it is ignored. This should only
// ever be set by the state machine. This is left as a TODO for a future PR.
// string normalizedWeight = 3 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
// (gogoproto.moretags) = "yaml:\"normalized_weight\"",
// (gogoproto.nullable) = true
// ];
}
7 changes: 3 additions & 4 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ syntax = "proto3";
package osmosis.gamm.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/gamm/v1beta1/balancerPool.proto";
import "osmosis/gamm/v1beta1/tx.proto";
import "osmosis/gamm/v1beta1/pool.proto";

import "cosmos/base/v1beta1/coin.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
Expand Down Expand Up @@ -90,9 +91,7 @@ message QueryNumPoolsResponse {
message QueryPoolParamsRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
message QueryPoolParamsResponse {
oneof params { BalancerPoolParams balancerPoolParams = 1; }
}
message QueryPoolParamsResponse { google.protobuf.Any params = 1; }
ValarDragon marked this conversation as resolved.
Show resolved Hide resolved

//=============================== TotalShares
message QueryTotalSharesRequest {
Expand Down
20 changes: 0 additions & 20 deletions proto/osmosis/gamm/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ syntax = "proto3";
package osmosis.gamm.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/gamm/v1beta1/balancerPool.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/osmosis-labs/osmosis/x/gamm/types";

service Msg {
rpc CreateBalancerPool(MsgCreateBalancerPool)
returns (MsgCreateBalancerPoolResponse);
rpc JoinPool(MsgJoinPool) returns (MsgJoinPoolResponse);
rpc ExitPool(MsgExitPool) returns (MsgExitPoolResponse);
rpc SwapExactAmountIn(MsgSwapExactAmountIn)
Expand All @@ -26,23 +23,6 @@ service Msg {
returns (MsgExitSwapShareAmountInResponse);
}

// ===================== MsgCreatePool
message MsgCreateBalancerPool {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];

BalancerPoolParams poolParams = 2 [
(gogoproto.moretags) = "yaml:\"pool_params\"",
(gogoproto.nullable) = false
];

repeated PoolAsset poolAssets = 3 [ (gogoproto.nullable) = false ];

string future_pool_governor = 4
[ (gogoproto.moretags) = "yaml:\"future_pool_governor\"" ];
}

message MsgCreateBalancerPoolResponse {}

// ===================== MsgJoinPool
message MsgJoinPool {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
Expand Down
17 changes: 10 additions & 7 deletions x/gamm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/x/gamm/types"
)

Expand Down Expand Up @@ -375,12 +376,14 @@ func NewBuildCreateBalancerPoolMsg(clientCtx client.Context, txf tx.Factory, fs
})
}

msg := &types.MsgCreateBalancerPool{
Sender: clientCtx.GetFromAddress().String(),
PoolParams: types.BalancerPoolParams{
SwapFee: swapFee,
ExitFee: exitFee,
},
poolParams := &balancer.BalancerPoolParams{
SwapFee: swapFee,
ExitFee: exitFee,
}

msg := &balancer.MsgCreateBalancerPool{
Sender: clientCtx.GetFromAddress().String(),
PoolParams: poolParams,
PoolAssets: poolAssets,
FuturePoolGovernor: pool.FutureGovernor,
}
Expand Down Expand Up @@ -410,7 +413,7 @@ func NewBuildCreateBalancerPoolMsg(clientCtx client.Context, txf tx.Factory, fs
})
}

smoothWeightParams := types.SmoothWeightChangeParams{
smoothWeightParams := balancer.SmoothWeightChangeParams{
Duration: duration,
InitialPoolWeights: poolAssets,
TargetPoolWeights: targetPoolAssets,
Expand Down
14 changes: 6 additions & 8 deletions x/gamm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
osmoapp "github.com/osmosis-labs/osmosis/app"
appparams "github.com/osmosis-labs/osmosis/app/params"
"github.com/osmosis-labs/osmosis/x/gamm"
"github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/x/gamm/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -20,7 +21,7 @@ func TestGammInitGenesis(t *testing.T) {
app := osmoapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

poolI, err := types.NewBalancerPool(1, types.BalancerPoolParams{
balancerPool, err := balancer.NewBalancerPool(1, balancer.BalancerPoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{
Expand All @@ -35,10 +36,7 @@ func TestGammInitGenesis(t *testing.T) {
}, "", ctx.BlockTime())
require.NoError(t, err)

balancerPool, ok := poolI.(*types.BalancerPool)
require.True(t, ok)

any, err := codectypes.NewAnyWithValue(poolI)
any, err := codectypes.NewAnyWithValue(&balancerPool)
require.NoError(t, err)

gamm.InitGenesis(ctx, app.GAMMKeeper, types.GenesisState{
Expand Down Expand Up @@ -80,7 +78,7 @@ func TestGammExportGenesis(t *testing.T) {
))
require.NoError(t, err)

_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, types.BalancerPoolParams{
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.BalancerPoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
Expand All @@ -92,7 +90,7 @@ func TestGammExportGenesis(t *testing.T) {
}}, "")
require.NoError(t, err)

_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, types.BalancerPoolParams{
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.BalancerPoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
Expand Down Expand Up @@ -124,7 +122,7 @@ func TestMarshalUnmarshalGenesis(t *testing.T) {
))
require.NoError(t, err)

_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, types.BalancerPoolParams{
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.BalancerPoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
Expand Down
6 changes: 4 additions & 2 deletions x/gamm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/osmosis-labs/osmosis/x/gamm/keeper"
"github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/x/gamm/types"
)

// NewHandler returns a handler for "gamm" type messages.
func NewHandler(k keeper.Keeper) sdk.Handler {
msgServer := keeper.NewMsgServerImpl(k)
msgBalancerServer := keeper.NewBalancerMsgServerImpl(k)

return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
Expand All @@ -23,8 +25,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
res, err := msgServer.ExitPool(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgCreateBalancerPool:
res, err := msgServer.CreateBalancerPool(sdk.WrapSDKContext(ctx), msg)
case *balancer.MsgCreateBalancerPool:
res, err := msgBalancerServer.CreateBalancerPool(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

case *types.MsgSwapExactAmountIn:
Expand Down
9 changes: 5 additions & 4 deletions x/gamm/keeper/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
balanacertypes "github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/x/gamm/types"
)

Expand Down Expand Up @@ -70,7 +71,7 @@ func (suite *KeeperTestSuite) TestJoinPoolGas() {
suite.Require().NoError(err)

firstJoinGas := suite.measureJoinPoolGas(defaultAddr, poolId, minShareOutAmount, defaultCoins)
suite.Assert().Equal(65580, int(firstJoinGas))
suite.Assert().Equal(65679, int(firstJoinGas))

for i := 1; i < startAveragingAt; i++ {
err := suite.app.GAMMKeeper.JoinPool(suite.ctx, defaultAddr, poolId, minShareOutAmount, sdk.Coins{})
Expand All @@ -79,8 +80,8 @@ func (suite *KeeperTestSuite) TestJoinPoolGas() {

avgGas, maxGas := suite.measureAvgAndMaxJoinPoolGas(totalNumJoins, defaultAddr, poolIDFn, minShareOutAmountFn, maxCoinsFn)
fmt.Printf("test deets: total %d of pools joined, begin average at %d\n", totalNumJoins, startAveragingAt)
suite.Assert().Equal(67095, int(avgGas), "average gas / join pool")
suite.Assert().Equal(67194, int(maxGas), "max gas / join pool")
suite.Assert().Equal(67194, int(avgGas), "average gas / join pool")
suite.Assert().Equal(67293, int(maxGas), "max gas / join pool")
}

func (suite *KeeperTestSuite) TestRepeatedJoinPoolDistinctDenom() {
Expand All @@ -102,7 +103,7 @@ func (suite *KeeperTestSuite) TestRepeatedJoinPoolDistinctDenom() {
err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, defaultAddr, coins)
suite.Require().NoError(err)

defaultBalancerPoolParams := types.BalancerPoolParams{
defaultBalancerPoolParams := balanacertypes.BalancerPoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
}
Expand Down
Loading