Skip to content

Commit

Permalink
Move pool_asset from types to balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Mar 23, 2022
1 parent b7d8bb7 commit e4bc4ed
Show file tree
Hide file tree
Showing 34 changed files with 622 additions and 1,315 deletions.
6 changes: 3 additions & 3 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ func (keeperTestHelper *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(
defaultFutureGovernor = ""

// pool assets
defaultFooAsset gammtypes.PoolAsset = gammtypes.PoolAsset{
defaultFooAsset balancer.PoolAsset = balancer.PoolAsset{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(bondDenom, uosmoAmount),
}
defaultBarAsset gammtypes.PoolAsset = gammtypes.PoolAsset{
defaultBarAsset balancer.PoolAsset = balancer.PoolAsset{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(token, sdk.NewInt(10000)),
}
poolAssets []gammtypes.PoolAsset = []gammtypes.PoolAsset{defaultFooAsset, defaultBarAsset}
poolAssets []balancer.PoolAsset = []balancer.PoolAsset{defaultFooAsset, defaultBarAsset}
)

poolId, err := keeperTestHelper.App.GAMMKeeper.CreateBalancerPool(keeperTestHelper.Ctx, acc1, balancer.PoolParams{
Expand Down
52 changes: 52 additions & 0 deletions go.sum

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions proto/osmosis/gamm/pool-models/balancer/balancerPool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import "google/protobuf/timestamp.proto";
import "cosmos/auth/v1beta1/auth.proto";
import "cosmos/base/v1beta1/coin.proto";

import "osmosis/gamm/v1beta1/pool.proto";

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

// Parameters for changing the weights in a balancer pool smoothly from
Expand Down Expand Up @@ -89,6 +87,32 @@ message PoolParams {
];
}

// Pool asset is an internal struct that combines the amount of the
// token in the pool, and its balancer weight.
// This is an awkward packaging of data,
// and should be revisited in a future state migration.
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
// ];
}

message Pool {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
Expand Down
1 change: 0 additions & 1 deletion proto/osmosis/gamm/pool-models/balancer/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package osmosis.gamm.v1beta1;

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/v7/x/gamm/pool-models/balancer";

Expand Down
30 changes: 0 additions & 30 deletions proto/osmosis/gamm/v1beta1/pool.proto

This file was deleted.

14 changes: 1 addition & 13 deletions proto/osmosis/gamm/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package osmosis.gamm.v1beta1;

import "gogoproto/gogo.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";
Expand Down Expand Up @@ -38,10 +37,7 @@ service Query {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/total_shares";
}
rpc PoolAssets(QueryPoolAssetsRequest) returns (QueryPoolAssetsResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/tokens";
}

rpc SpotPrice(QuerySpotPriceRequest) returns (QuerySpotPriceResponse) {
option (google.api.http).get =
"/osmosis/gamm/v1beta1/pools/{poolId}/prices";
Expand Down Expand Up @@ -104,14 +100,6 @@ message QueryTotalSharesResponse {
];
}

//=============================== PoolAssets
message QueryPoolAssetsRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
}
message QueryPoolAssetsResponse {
repeated PoolAsset poolAssets = 1 [ (gogoproto.nullable) = false ];
}

//=============================== SpotPrice
message QuerySpotPriceRequest {
uint64 poolId = 1 [ (gogoproto.moretags) = "yaml:\"pool_id\"" ];
Expand Down
43 changes: 0 additions & 43 deletions x/gamm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func GetQueryCmd() *cobra.Command {
GetCmdNumPools(),
GetCmdPoolParams(),
GetCmdTotalShares(),
GetCmdPoolAssets(),
GetCmdSpotPrice(),
GetCmdQueryTotalLiquidity(),
GetCmdEstimateSwapExactAmountIn(),
Expand Down Expand Up @@ -315,48 +314,6 @@ $ %s query gamm total-liquidity
return cmd
}

// GetCmdPoolAssets return pool-assets for a pool
func GetCmdPoolAssets() *cobra.Command {
cmd := &cobra.Command{
Use: "pool-assets <poolID>",
Short: "Query pool-assets",
Long: strings.TrimSpace(
fmt.Sprintf(`Query pool assets.
Example:
$ %s query gamm pool-assets 1
`,
version.AppName,
),
),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

poolID, err := strconv.Atoi(args[0])
if err != nil {
return err
}

res, err := queryClient.PoolAssets(cmd.Context(), &types.QueryPoolAssetsRequest{
PoolId: uint64(poolID),
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdSpotPrice returns spot price
func GetCmdSpotPrice() *cobra.Command {
cmd := &cobra.Command{
Expand Down
8 changes: 4 additions & 4 deletions x/gamm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,14 @@ func NewBuildCreateBalancerPoolMsg(clientCtx client.Context, txf tx.Factory, fs
return txf, nil, err
}

var poolAssets []types.PoolAsset
var poolAssets []balancer.PoolAsset
for i := 0; i < len(poolAssetCoins); i++ {

if poolAssetCoins[i].Denom != deposit[i].Denom {
return txf, nil, errors.New("deposit tokens and token weights should have same denom order")
}

poolAssets = append(poolAssets, types.PoolAsset{
poolAssets = append(poolAssets, balancer.PoolAsset{
Weight: poolAssetCoins[i].Amount.RoundInt(),
Token: deposit[i],
})
Expand Down Expand Up @@ -399,14 +399,14 @@ func NewBuildCreateBalancerPoolMsg(clientCtx client.Context, txf tx.Factory, fs
return txf, nil, err
}

var targetPoolAssets []types.PoolAsset
var targetPoolAssets []balancer.PoolAsset
for i := 0; i < len(targetPoolAssetCoins); i++ {

if targetPoolAssetCoins[i].Denom != poolAssetCoins[i].Denom {
return txf, nil, errors.New("initial pool weights and target pool weights should have same denom order")
}

targetPoolAssets = append(targetPoolAssets, types.PoolAsset{
targetPoolAssets = append(targetPoolAssets, balancer.PoolAsset{
Weight: targetPoolAssetCoins[i].Amount.RoundInt(),
Token: deposit[i],
// TODO: This doesn't make sense. Should only use denom, not an sdk.Coin
Expand Down
9 changes: 4 additions & 5 deletions x/gamm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
osmoapp "github.com/osmosis-labs/osmosis/v7/app"
"github.com/osmosis-labs/osmosis/v7/x/gamm"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
Expand All @@ -22,7 +21,7 @@ import (
// balancerPool, err := balancer.NewBalancerPool(1, balancer.PoolParams{
// SwapFee: sdk.NewDecWithPrec(1, 2),
// ExitFee: sdk.NewDecWithPrec(1, 2),
// }, []types.PoolAsset{
// }, []balancerbalancer.PoolAsset{
// {
// Weight: sdk.NewInt(1),
// Token: sdk.NewInt64Coin(sdk.DefaultBondDenom, 10),
Expand Down Expand Up @@ -79,7 +78,7 @@ func TestGammExportGenesis(t *testing.T) {
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.PoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
}, []balancer.PoolAsset{{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin("foo", sdk.NewInt(10000)),
}, {
Expand All @@ -91,7 +90,7 @@ func TestGammExportGenesis(t *testing.T) {
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.PoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
}, []balancer.PoolAsset{{
Weight: sdk.NewInt(70),
Token: sdk.NewCoin("foo", sdk.NewInt(10000)),
}, {
Expand Down Expand Up @@ -123,7 +122,7 @@ func TestMarshalUnmarshalGenesis(t *testing.T) {
_, err = app.GAMMKeeper.CreateBalancerPool(ctx, acc1, balancer.PoolParams{
SwapFee: sdk.NewDecWithPrec(1, 2),
ExitFee: sdk.NewDecWithPrec(1, 2),
}, []types.PoolAsset{{
}, []balancer.PoolAsset{{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin("foo", sdk.NewInt(10000)),
}, {
Expand Down
6 changes: 3 additions & 3 deletions x/gamm/keeper/gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

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

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

defaultPoolParams := balanacertypes.PoolParams{
defaultPoolParams := balancertypes.PoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
}
Expand All @@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestRepeatedJoinPoolDistinctDenom() {
err = simapp.FundAccount(suite.app.BankKeeper, suite.ctx, defaultAddr, coins)
suite.Require().NoError(err)

poolAssets := []types.PoolAsset{
poolAssets := []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin(prevRandToken, sdk.NewInt(10)),
Expand Down
19 changes: 0 additions & 19 deletions x/gamm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,6 @@ func (k Keeper) TotalShares(ctx context.Context, req *types.QueryTotalSharesRequ
}, nil
}

// TODO: Fix
func (k Keeper) PoolAssets(ctx context.Context, req *types.QueryPoolAssetsRequest) (*types.QueryPoolAssetsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

return nil, status.Error(codes.Unimplemented, "unimplemented")

// sdkCtx := sdk.UnwrapSDKContext(ctx)

// pool, err := k.GetPool(sdkCtx, req.PoolId)
// if err != nil {
// return nil, status.Error(codes.Internal, err.Error())
// }
// return &types.QueryPoolAssetsResponse{
// PoolAssets: pool.GetAllPoolAssets(),
// }, nil
}

func (k Keeper) SpotPrice(ctx context.Context, req *types.QuerySpotPriceRequest) (*types.QuerySpotPriceResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
Expand Down
3 changes: 2 additions & 1 deletion x/gamm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/osmosis-labs/osmosis/v7/app"

"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
balancertypes "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func (suite *KeeperTestSuite) prepareBalancerPoolWithPoolParams(PoolParams balan
}
}

poolId, err := suite.app.GAMMKeeper.CreateBalancerPool(suite.ctx, acc1, PoolParams, []types.PoolAsset{
poolId, err := suite.app.GAMMKeeper.CreateBalancerPool(suite.ctx, acc1, PoolParams, []balancertypes.PoolAsset{
{
Weight: sdk.NewInt(100),
Token: sdk.NewCoin("foo", sdk.NewInt(5000000)),
Expand Down
7 changes: 4 additions & 3 deletions x/gamm/keeper/marshal_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/osmosis-labs/osmosis/v7/app"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
balancertypes "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
gammtypes "github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

func genPoolAssets(r *rand.Rand) []gammtypes.PoolAsset {
func genPoolAssets(r *rand.Rand) []balancertypes.PoolAsset {
denoms := []string{"IBC/0123456789ABCDEF012346789ABCDEF", "IBC/denom56789ABCDEF012346789ABCDEF"}
assets := []gammtypes.PoolAsset{}
assets := []balancertypes.PoolAsset{}
for _, denom := range denoms {
amt, _ := simtypes.RandPositiveInt(r, sdk.NewIntWithDecimal(1, 40))
reserveAmt := sdk.NewCoin(denom, amt)
weight := sdk.NewInt(r.Int63n(9) + 1)
assets = append(assets, gammtypes.PoolAsset{Token: reserveAmt, Weight: weight})
assets = append(assets, balancertypes.PoolAsset{Token: reserveAmt, Weight: weight})
}

return assets
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (k Keeper) DeletePool(ctx sdk.Context, poolId uint64) error {

// newBalancerPool is an internal function that creates a new Balancer Pool object with the provided
// parameters, initial assets, and future governor.
func (k Keeper) newBalancerPool(ctx sdk.Context, balancerPoolParams balancer.PoolParams, assets []types.PoolAsset, futureGovernor string) (types.PoolI, error) {
func (k Keeper) newBalancerPool(ctx sdk.Context, balancerPoolParams balancer.PoolParams, assets []balancer.PoolAsset, futureGovernor string) (types.PoolI, error) {
poolId := k.GetNextPoolNumberAndIncrement(ctx)

pool, err := balancer.NewBalancerPool(poolId, balancerPoolParams, assets, futureGovernor, ctx.BlockTime())
Expand Down
2 changes: 1 addition & 1 deletion x/gamm/keeper/pool_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (k Keeper) CreateBalancerPool(
ctx sdk.Context,
sender sdk.AccAddress,
BalancerPoolParams balancer.PoolParams,
poolAssets []types.PoolAsset,
poolAssets []balancer.PoolAsset,
futurePoolGovernor string,
) (uint64, error) {
if len(poolAssets) < types.MinPoolAssets {
Expand Down
Loading

0 comments on commit e4bc4ed

Please sign in to comment.