Skip to content

Commit

Permalink
Merge pull request #6 from c-osmosis/frostornge/pools
Browse files Browse the repository at this point in the history
refactor: prettify proto definitions
  • Loading branch information
byeongsu-hong authored Oct 18, 2020
2 parents 0399df7 + 97e7196 commit a0c890f
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 44 deletions.
48 changes: 39 additions & 9 deletions proto/osmosis/gamm/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,49 @@ import "cosmos/base/v1beta1/coin.proto";
option go_package = "github.com/c-osmosis/osmosis/x/gamm/types";

message Record {
string denormalizedWeight = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"denormalized_weight\"", (gogoproto.nullable) = false];
string balance = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"balance\"", (gogoproto.nullable) = false];
string denormalizedWeight = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"denormalized_weight\"",
(gogoproto.nullable) = false
];
string balance = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"balance\"",
(gogoproto.nullable) = false
];
}

message LP {
string name = 1 [(gogoproto.moretags) = "yaml:\"name\""];
string totalSupply = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"total_supply\"", (gogoproto.nullable) = false];
string name = 1 [
(gogoproto.moretags) = "yaml:\"name\""
];
string totalSupply = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"total_supply\"",
(gogoproto.nullable) = false
];
}

message Pool {
uint64 id = 1 [(gogoproto.moretags) = "yaml:\"id\""];
string swapFee = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"swap_fee\"", (gogoproto.nullable) = false];
string totalWeight = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"total_weight\"", (gogoproto.nullable) = false];
LP token = 4 [(gogoproto.moretags) = "yaml:\"token\"", (gogoproto.nullable) = false];
map<string, Record> records = 5 [(gogoproto.moretags) = "yaml:\"records\"", (gogoproto.nullable) = false];
uint64 id = 1 [
(gogoproto.moretags) = "yaml:\"id\""
];
string swapFee = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.nullable) = false
];
string totalWeight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"total_weight\"",
(gogoproto.nullable) = false
];
LP token = 4 [
(gogoproto.moretags) = "yaml:\"token\"",
(gogoproto.nullable) = false
];
map<string, Record> records = 5 [
(gogoproto.moretags) = "yaml:\"records\"",
(gogoproto.nullable) = false
];
}
172 changes: 140 additions & 32 deletions proto/osmosis/gamm/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,173 @@ option go_package = "github.com/c-osmosis/osmosis/x/gamm/types";

// ===================== MsgJoinPool
message MaxAmountIn {
string denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
string maxAmount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"max_amount\"", (gogoproto.nullable) = false];
string denom = 1 [
(gogoproto.moretags) = "yaml:\"denom\""
];
string maxAmount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"max_amount\"",
(gogoproto.nullable) = false
];
}

message MsgJoinPool {
bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"sender\""];
uint64 targetPool = 2 [(gogoproto.moretags) = "yaml:\"target_pool\""];
string poolAmountOut = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"pool_amount_out\"", (gogoproto.nullable) = false];
bytes sender = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"sender\""
];
uint64 targetPool = 2 [
(gogoproto.moretags) = "yaml:\"target_pool\""
];
string poolAmountOut = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"pool_amount_out\"",
(gogoproto.nullable) = false
];

repeated MaxAmountIn maxAmountsIn = 4 [(gogoproto.moretags) = "yaml:\"max_amounts_in\"", (gogoproto.nullable) = false];
repeated MaxAmountIn maxAmountsIn = 4 [
(gogoproto.moretags) = "yaml:\"max_amounts_in\"",
(gogoproto.nullable) = false
];
}

// ===================== MsgExitPool
message MinAmountOut {
string denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
string minAmount = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"min_amount\"", (gogoproto.nullable) = false];
string denom = 1 [
(gogoproto.moretags) = "yaml:\"denom\""
];
string minAmount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_amount\"",
(gogoproto.nullable) = false
];
}

message MsgExitPool {
bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"sender\""];
uint64 targetPool = 2 [(gogoproto.moretags) = "yaml:\"target_pool\""];
string poolAmountIn = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"pool_amount_in\"", (gogoproto.nullable) = false];
bytes sender = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"sender\""
];
uint64 targetPool = 2 [
(gogoproto.moretags) = "yaml:\"target_pool\""
];
string poolAmountIn = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"pool_amount_in\"",
(gogoproto.nullable) = false
];

repeated MinAmountOut minAmountsOut = 4 [(gogoproto.moretags) = "yaml:\"min_amounts_out\"", (gogoproto.nullable) = false];
repeated MinAmountOut minAmountsOut = 4 [
(gogoproto.moretags) = "yaml:\"min_amounts_out\"",
(gogoproto.nullable) = false
];
}

// ===================== MsgCreatePool
message TokenInfo {
string denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
string ratio = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"ratio\"", (gogoproto.nullable) = false];
string amount = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"amount\"", (gogoproto.nullable) = false];
string denom = 1 [
(gogoproto.moretags) = "yaml:\"denom\""
];
string ratio = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"ratio\"",
(gogoproto.nullable) = false
];
string amount = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"amount\"",
(gogoproto.nullable) = false
];
}

message MsgCreatePool {
bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"sender\""];
bytes sender = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"sender\""
];

string swapFee = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.moretags) = "yaml:\"swap_fee\"", (gogoproto.nullable) = false];
string swapFee = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"swap_fee\"",
(gogoproto.nullable) = false
];

repeated TokenInfo tokenInfo = 3 [(gogoproto.moretags) = "yaml:\"token_info\"", (gogoproto.nullable) = false];
repeated TokenInfo tokenInfo = 3 [
(gogoproto.moretags) = "yaml:\"token_info\"",
(gogoproto.nullable) = false
];
}

// ===================== MsgSwapExactAmountIn
message MsgSwapExactAmountIn {
bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"sender\""];
bytes targetPool = 2 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"target_pool\""];
cosmos.base.v1beta1.Coin tokenIn = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.moretags) = "yaml:\"token_in\"", (gogoproto.nullable) = false];
string tokenAmountIn = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"token_amount_in\"", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin tokenOut = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.moretags) = "yaml:\"token_out\"", (gogoproto.nullable) = false];
string minAmountOut = 6 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"min_amount_out\"", (gogoproto.nullable) = false];
string maxPrice = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"max_price\"", (gogoproto.nullable) = false];
bytes sender = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"sender\""
];
bytes targetPool = 2 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"target_pool\""
];
cosmos.base.v1beta1.Coin tokenIn = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.moretags) = "yaml:\"token_in\"",
(gogoproto.nullable) = false
];
string tokenAmountIn = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_amount_in\"",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin tokenOut = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.moretags) = "yaml:\"token_out\"",
(gogoproto.nullable) = false
];
string minAmountOut = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_amount_out\"",
(gogoproto.nullable) = false
];
string maxPrice = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"max_price\"",
(gogoproto.nullable) = false
];
}

// ===================== MsgSwapExactAmountOut
message MsgSwapExactAmountOut {
bytes sender = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"sender\""];
bytes targetPool = 2 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress", (gogoproto.moretags) = "yaml:\"target_pool\""];
cosmos.base.v1beta1.Coin tokenIn = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.moretags) = "yaml:\"token_in\"", (gogoproto.nullable) = false];
string maxAmountIn = 4 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"max_amount_in\"", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin tokenOut = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.moretags) = "yaml:\"token_out\"", (gogoproto.nullable) = false];
string tokenAmountOut = 6 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"token_amount_out\"", (gogoproto.nullable) = false];
string maxPrice = 7 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.moretags) = "yaml:\"max_price\"", (gogoproto.nullable) = false];
bytes sender = 1 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"sender\""
];
bytes targetPool = 2 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(gogoproto.moretags) = "yaml:\"target_pool\""
];
cosmos.base.v1beta1.Coin tokenIn = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.moretags) = "yaml:\"token_in\"",
(gogoproto.nullable) = false
];
string maxAmountIn = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"max_amount_in\"",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin tokenOut = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.moretags) = "yaml:\"token_out\"",
(gogoproto.nullable) = false
];
string tokenAmountOut = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"token_amount_out\"",
(gogoproto.nullable) = false
];
string maxPrice = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"max_price\"",
(gogoproto.nullable) = false
];
}
11 changes: 11 additions & 0 deletions x/gamm/keeper/pool/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ func (p poolService) CreatePool(
swapFee sdk.Dec,
tokenInfo []types.TokenInfo,
) error {
if len(tokenInfo) < 2 {
return sdkerrors.Wrapf(
types.ErrInvalidRequest,
"token info length should be at least 2",
)
}

records := make(map[string]types.Record, len(tokenInfo))
for _, info := range tokenInfo {
records[info.Denom] = types.Record{
Expand All @@ -61,6 +68,10 @@ func (p poolService) CreatePool(
Amount: record.Balance,
})
}
if coins == nil {
panic("oh my god")
}
coins = coins.Sort()

return p.bankKeeper.SendCoinsFromAccountToModule(
ctx,
Expand Down
7 changes: 4 additions & 3 deletions x/gamm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

// x/gamm module sentinel errors
var (
ErrPoolNotFound = sdkerrors.Register(ModuleName, 2, "pool not found")
ErrMathApprox = sdkerrors.Register(ModuleName, 3, "math approx error")
ErrLimitExceed = sdkerrors.Register(ModuleName, 4, "limit exceeded")
ErrPoolNotFound = sdkerrors.Register(ModuleName, 2, "pool not found")
ErrMathApprox = sdkerrors.Register(ModuleName, 3, "math approx error")
ErrLimitExceed = sdkerrors.Register(ModuleName, 4, "limit exceeded")
ErrInvalidRequest = sdkerrors.Register(ModuleName, 5, "bad request")
)

0 comments on commit a0c890f

Please sign in to comment.