Skip to content

Commit

Permalink
Merge branch 'main' into faddat/linters2
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Mar 23, 2022
2 parents 39642c7 + d143d83 commit 1642c86
Show file tree
Hide file tree
Showing 46 changed files with 745 additions and 1,922 deletions.
6 changes: 3 additions & 3 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/tendermint/tm-db v0.6.7
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
10 changes: 10 additions & 0 deletions osmomath/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ var (
two sdk.Dec = sdk.MustNewDecFromStr("2")
)

// Returns the internal "power precision".
// All fractional exponentiation in osmosis is expected to be accurate up to
// powPrecision.
// *technically* the error term can be greater than this powPrecision,
// but for small bases this bound applies. See comments in the PowApprox function
// for more detail.
func GetPowPrecision() sdk.Dec {
return powPrecision.Clone()
}

/*********************************************************/

// AbsDifferenceWithSign returns | a - b |, (a - b).sign()
Expand Down
19 changes: 17 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,23 @@ 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
];
}

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
55 changes: 29 additions & 26 deletions x/epochs/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,42 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) {
shouldInitialEpochStart := !epochInfo.EpochCountingStarted && !epochInfo.StartTime.After(ctx.BlockTime())

epochEndTime := epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
shouldEpochStart := ctx.BlockTime().After(epochEndTime) && !shouldInitialEpochStart && !epochInfo.StartTime.After(ctx.BlockTime())

if shouldInitialEpochStart || shouldEpochStart {
epochInfo.CurrentEpochStartHeight = ctx.BlockHeight()

if shouldInitialEpochStart {
epochInfo.EpochCountingStarted = true
epochInfo.CurrentEpoch = 1
epochInfo.CurrentEpochStartTime = epochInfo.StartTime
logger.Info(fmt.Sprintf("Starting new epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
} else {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeEpochEnd,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)),
),
)
k.AfterEpochEnd(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch)
epochInfo.CurrentEpoch += 1
epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
logger.Info(fmt.Sprintf("Starting epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
}
k.SetEpochInfo(ctx, epochInfo)
shouldEpochStart := (ctx.BlockTime().After(epochEndTime) && !epochInfo.StartTime.After(ctx.BlockTime())) || shouldInitialEpochStart

if !shouldEpochStart {
return false
}
epochInfo.CurrentEpochStartHeight = ctx.BlockHeight()

if shouldInitialEpochStart {
epochInfo.EpochCountingStarted = true
epochInfo.CurrentEpoch = 1
epochInfo.CurrentEpochStartTime = epochInfo.StartTime
logger.Info(fmt.Sprintf("Starting new epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
} else {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeEpochStart,
types.EventTypeEpochEnd,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)),
sdk.NewAttribute(types.AttributeEpochStartTime, fmt.Sprintf("%d", epochInfo.CurrentEpochStartTime.Unix())),
),
)
k.BeforeEpochStart(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch)
k.AfterEpochEnd(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch)
epochInfo.CurrentEpoch += 1
epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
logger.Info(fmt.Sprintf("Starting epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
}

// emit new epoch start event, set epoch info, and run BeforeEpochStart hook
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeEpochStart,
sdk.NewAttribute(types.AttributeEpochNumber, fmt.Sprintf("%d", epochInfo.CurrentEpoch)),
sdk.NewAttribute(types.AttributeEpochStartTime, fmt.Sprintf("%d", epochInfo.CurrentEpochStartTime.Unix())),
),
)
k.SetEpochInfo(ctx, epochInfo)
k.BeforeEpochStart(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch)

return false
})
}
45 changes: 1 addition & 44 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 @@ -313,49 +312,7 @@ $ %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.
// GetCmdSpotPrice returns spot price
func GetCmdSpotPrice() *cobra.Command {
cmd := &cobra.Command{
Use: "spot-price <poolID> <tokenInDenom> <tokenOutDenom>",
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 @@ -362,13 +362,13 @@ 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 @@ -397,13 +397,13 @@ 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
Loading

0 comments on commit 1642c86

Please sign in to comment.