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: no tests, but logic #5

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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
github.com/cosmos/cosmos-sdk v0.34.4-0.20200921130040-27db2cf89772
github.com/gogo/protobuf v1.3.1
github.com/gorilla/mux v1.8.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.3.1
Expand Down
48 changes: 9 additions & 39 deletions proto/osmosis/gamm/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,19 @@ 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];
}
173 changes: 32 additions & 141 deletions proto/osmosis/gamm/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,176 +6,67 @@ import "cosmos/base/v1beta1/coin.proto";

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];
}
10 changes: 5 additions & 5 deletions x/gamm/keeper/pool/lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
)

type lp struct {
type lpService struct {
denom string
bankKeeper bankkeeper.Keeper
}

func (p lp) pushPoolShare(ctx sdk.Context, to sdk.AccAddress, amount sdk.Int) error {
func (p lpService) pushPoolShare(ctx sdk.Context, to sdk.AccAddress, amount sdk.Int) error {
lp := sdk.Coin{Denom: p.denom, Amount: amount}
return p.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, to, sdk.Coins{lp})
}

func (p lp) pullPoolShare(ctx sdk.Context, from sdk.AccAddress, amount sdk.Int) error {
func (p lpService) pullPoolShare(ctx sdk.Context, from sdk.AccAddress, amount sdk.Int) error {
lp := sdk.Coin{Denom: p.denom, Amount: amount}
return p.bankKeeper.SendCoinsFromAccountToModule(ctx, from, types.ModuleName, sdk.Coins{lp})
}

func (p lp) mintPoolShare(ctx sdk.Context, amount sdk.Int) error {
func (p lpService) mintPoolShare(ctx sdk.Context, amount sdk.Int) error {
lp := sdk.Coin{Denom: p.denom, Amount: amount}
return p.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.Coins{lp})
}

func (p lp) burnPoolShare(ctx sdk.Context, amount sdk.Int) error {
func (p lpService) burnPoolShare(ctx sdk.Context, amount sdk.Int) error {
lp := sdk.Coin{Denom: p.denom, Amount: amount}
return p.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.Coins{lp})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package math
package pool

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package math
package pool

import (
"testing"
Expand Down
Loading