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

feat: add message definitions #2

Merged
merged 5 commits into from
Oct 18, 2020
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

.PHONY: message

proto:
message:
./scripts/protocgen.sh
10 changes: 0 additions & 10 deletions proto/osmosis/gamm/v1beta1/query.proto

This file was deleted.

120 changes: 107 additions & 13 deletions proto/osmosis/gamm/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,110 @@ import "cosmos/base/v1beta1/coin.proto";

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

// TODO: 해당 컨트랙트 메소드 로직 이해하고 메세지 정의 작업하기
//* JoinPool
//* ExitPool
//* SwapExactAmountIn
//* SwapExactAmountOut
//* JoinSwapExternAmountIn
//* JoinSwapPoolAmountOut
//* ExitSwapPoolAmountIn
//* ExitSwapExternAmountOut
message MsgSwap {}
message MsgJoinPool {}
message MsgExitPool {}
message MsgCreatePool {}

// ===================== MsgJoinPool
message MaxAmountIn {
cosmos.base.v1beta1.Coin token = 1 [
(gogoproto.moretags) = "yaml:\"token\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
];
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\""
];
bytes targetPool = 2 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(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
];
}

// ===================== MsgExitPool
message MinAmountOut {
cosmos.base.v1beta1.Coin token = 1 [
(gogoproto.moretags) = "yaml:\"token\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
];
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\""
];
bytes targetPool = 2 [
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
(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
];
}

// ===================== MsgCreatePool
message TokenInfo {
cosmos.base.v1beta1.Coin token = 1 [
(gogoproto.moretags) = "yaml:\"token\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
];
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:\"ratio\"",
(gogoproto.nullable) = false
];
}

message MsgCreatePool {
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
];

repeated TokenInfo tokenInfo = 3 [
(gogoproto.moretags) = "yaml:\"token_info\"",
(gogoproto.nullable) = false
];
}
6 changes: 3 additions & 3 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xarg
for dir in $proto_dirs; do
protoc \
-I "proto" \
-I "third_party/proto" \
-I "$cosmos_sdk_dir" \
-I "$cosmos_sdk_dir/third_party/proto" \
-I "$cosmos_sdk_dir/proto" \
--gocosmos_out=plugins=interfacetype+grpc,\
Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
$(find "${dir}" -name '*.proto')
done

cp -r github.com/c-osmosis/osmosis/* ./
#rm -rf github.com
rm -rf github.com
2 changes: 1 addition & 1 deletion x/gamm/keeper/pool/math.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package keeper
package pool

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
9 changes: 8 additions & 1 deletion x/gamm/keeper/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package pool

import sdk "github.com/cosmos/cosmos-sdk/types"

type Record struct {
DenormalizedWeight sdk.Dec
Balance sdk.Int
}

type Pool struct {
Address sdk.AccAddress
Address sdk.AccAddress
Records map[string]Record
TotalWeight sdk.Int
}
61 changes: 7 additions & 54 deletions x/gamm/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,7 @@ const (
TypeMsgExitPool = "exit_pool"
)

// TODO: 일단 이 메세지 타입들을 사용하되, proto 정의가 완성되면 그것을 사용한다.
var (
_ sdk.Msg = &MsgCreatePool{}
_ sdk.Msg = &MsgSwapExactAmountIn{}
_ sdk.Msg = &MsgSwapExactAmountOut{}
_ sdk.Msg = &MsgJoinPool{}
_ sdk.Msg = &MsgExitPool{}
)

type TokenInfo struct {
Token sdk.Coin `json:"token"`
Ratio sdk.Dec `json:"ratio"`
Amount sdk.Int `json:"amount"`
}

type MsgCreatePool struct {
Sender sdk.AccAddress `json:"sender"`
SwapFee sdk.Dec `json:"swap_fee"`
TokenInfo []TokenInfo `json:"token_info"`
}

func (m MsgCreatePool) Reset() { panic("implement me") }
func (m MsgCreatePool) String() string { panic("implement me") }
func (m MsgCreatePool) ProtoMessage() { panic("implement me") }
var _ sdk.Msg = &MsgCreatePool{}

func (m MsgCreatePool) Route() string { return RouterKey }
func (m MsgCreatePool) Type() string { return TypeMsgCreatePool }
Expand All @@ -47,6 +24,8 @@ func (m MsgCreatePool) GetSignBytes() []byte {
}
func (m MsgCreatePool) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Sender} }

var _ sdk.Msg = &MsgSwapExactAmountIn{}

type MsgSwapExactAmountIn struct {
Sender sdk.AccAddress `json:"sender"`
TargetPool sdk.AccAddress `json:"target_pool"`
Expand All @@ -71,6 +50,8 @@ func (m MsgSwapExactAmountIn) GetSignBytes() []byte {
}
func (m MsgSwapExactAmountIn) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Sender} }

var _ sdk.Msg = &MsgSwapExactAmountOut{}

type MsgSwapExactAmountOut struct {
Sender sdk.AccAddress `json:"sender"`
TargetPool sdk.AccAddress `json:"target_pool"`
Expand All @@ -95,21 +76,7 @@ func (m MsgSwapExactAmountOut) GetSignBytes() []byte {
}
func (m MsgSwapExactAmountOut) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Sender} }

type MaxAmountIn struct {
Token string `json:"token"`
MaxAmount sdk.Int `json:"max_amount"`
}

type MsgJoinPool struct {
Sender sdk.AccAddress `json:"sender"`
TargetPool sdk.AccAddress `json:"target_pool"`
PoolAmountOut sdk.Int `json:"pool_amount_out"`
MaxAmountsIn []MaxAmountIn `json:"max_amounts_in"`
}

func (m MsgJoinPool) Reset() { panic("implement me") }
func (m MsgJoinPool) String() string { panic("implement me") }
func (m MsgJoinPool) ProtoMessage() { panic("implement me") }
var _ sdk.Msg = &MsgJoinPool{}

func (m MsgJoinPool) Route() string { return RouterKey }
func (m MsgJoinPool) Type() string { return TypeMsgJoinPool }
Expand All @@ -121,21 +88,7 @@ func (m MsgJoinPool) GetSignBytes() []byte {
}
func (m MsgJoinPool) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{m.Sender} }

type MinAmountOut struct {
Token string `json:"token"`
MinAmount sdk.Int `json:"min_amount"`
}

type MsgExitPool struct {
Sender sdk.AccAddress `json:"sender"`
TargetPool sdk.AccAddress `json:"target_pool"`
PoolAmountIn sdk.Int `json:"pool_amount_out"`
MinAmountsOut []MinAmountOut `json:"min_amounts_out"`
}

func (m MsgExitPool) Reset() { panic("implement me") }
func (m MsgExitPool) String() string { panic("implement me") }
func (m MsgExitPool) ProtoMessage() { panic("implement me") }
var _ sdk.Msg = &MsgExitPool{}

func (m MsgExitPool) Route() string { return RouterKey }
func (m MsgExitPool) Type() string { return TypeMsgExitPool }
Expand Down
Loading