From 5ffb9f1c0ff7bd2f39a0e02813d3a38912b897a9 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 12:29:28 -0600 Subject: [PATCH 01/28] WIP - cellarfees v2 protos --- proto/cellarfees/v1/cellarfees.proto | 2 +- proto/cellarfees/v1/genesis.proto | 2 +- proto/cellarfees/v1/params.proto | 2 +- proto/cellarfees/v1/query.proto | 2 +- proto/cellarfees/v2/cellarfees.proto | 15 + proto/cellarfees/v2/genesis.proto | 16 + proto/cellarfees/v2/params.proto | 29 + proto/cellarfees/v2/query.proto | 74 + x/cellarfees/client/cli/query.go | 37 +- x/cellarfees/keeper/abci.go | 17 - x/cellarfees/keeper/genesis.go | 7 +- x/cellarfees/keeper/keeper.go | 65 +- x/cellarfees/keeper/query_server.go | 10 +- x/cellarfees/types/cellarfees.go | 68 - x/cellarfees/types/cellarfees_test.go | 65 - x/cellarfees/types/genesis.go | 44 - x/cellarfees/types/keys.go | 6 +- x/cellarfees/types/{ => v1}/cellarfees.pb.go | 10 +- x/cellarfees/types/{ => v1}/genesis.pb.go | 42 +- x/cellarfees/types/{ => v1}/params.pb.go | 46 +- x/cellarfees/types/{ => v1}/query.pb.go | 84 +- x/cellarfees/types/{ => v1}/query.pb.gw.go | 4 +- x/cellarfees/types/v2/cellarfees.go | 1 + x/cellarfees/types/v2/cellarfees.pb.go | 374 +++ x/cellarfees/types/v2/cellarfees_test.go | 1 + x/cellarfees/types/{ => v2}/codec.go | 2 +- x/cellarfees/types/v2/genesis.go | 29 + x/cellarfees/types/v2/genesis.pb.go | 374 +++ x/cellarfees/types/{ => v2}/params.go | 41 +- x/cellarfees/types/v2/params.pb.go | 484 ++++ x/cellarfees/types/v2/query.pb.go | 2249 ++++++++++++++++++ x/cellarfees/types/v2/query.pb.gw.go | 514 ++++ 32 files changed, 4296 insertions(+), 420 deletions(-) create mode 100644 proto/cellarfees/v2/cellarfees.proto create mode 100644 proto/cellarfees/v2/genesis.proto create mode 100644 proto/cellarfees/v2/params.proto create mode 100644 proto/cellarfees/v2/query.proto delete mode 100644 x/cellarfees/types/cellarfees.go delete mode 100644 x/cellarfees/types/cellarfees_test.go delete mode 100644 x/cellarfees/types/genesis.go rename x/cellarfees/types/{ => v1}/cellarfees.pb.go (98%) rename x/cellarfees/types/{ => v1}/genesis.pb.go (84%) rename x/cellarfees/types/{ => v1}/params.pb.go (84%) rename x/cellarfees/types/{ => v1}/query.pb.go (92%) rename x/cellarfees/types/{ => v1}/query.pb.gw.go (99%) create mode 100644 x/cellarfees/types/v2/cellarfees.go create mode 100644 x/cellarfees/types/v2/cellarfees.pb.go create mode 100644 x/cellarfees/types/v2/cellarfees_test.go rename x/cellarfees/types/{ => v2}/codec.go (96%) create mode 100644 x/cellarfees/types/v2/genesis.go create mode 100644 x/cellarfees/types/v2/genesis.pb.go rename x/cellarfees/types/{ => v2}/params.go (66%) create mode 100644 x/cellarfees/types/v2/params.pb.go create mode 100644 x/cellarfees/types/v2/query.pb.go create mode 100644 x/cellarfees/types/v2/query.pb.gw.go diff --git a/proto/cellarfees/v1/cellarfees.proto b/proto/cellarfees/v1/cellarfees.proto index 2c184cf13..cacb50905 100644 --- a/proto/cellarfees/v1/cellarfees.proto +++ b/proto/cellarfees/v1/cellarfees.proto @@ -3,7 +3,7 @@ package cellarfees.v1; import "gogoproto/gogo.proto"; -option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types"; +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v1"; message FeeAccrualCounter { string denom = 1; diff --git a/proto/cellarfees/v1/genesis.proto b/proto/cellarfees/v1/genesis.proto index 6bb6a2915..bb09cbb3f 100644 --- a/proto/cellarfees/v1/genesis.proto +++ b/proto/cellarfees/v1/genesis.proto @@ -5,7 +5,7 @@ import "gogoproto/gogo.proto"; import "cellarfees/v1/params.proto"; import "cellarfees/v1/cellarfees.proto"; -option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types"; +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v1"; // GenesisState defines the cellarfees module's genesis state. message GenesisState { diff --git a/proto/cellarfees/v1/params.proto b/proto/cellarfees/v1/params.proto index ab5cc7dcd..56bb6e2ea 100644 --- a/proto/cellarfees/v1/params.proto +++ b/proto/cellarfees/v1/params.proto @@ -3,7 +3,7 @@ package cellarfees.v1; import "gogoproto/gogo.proto"; -option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types"; +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v1"; // Params defines the parameters for the module. message Params { diff --git a/proto/cellarfees/v1/query.proto b/proto/cellarfees/v1/query.proto index eecbce6f2..ead312ce9 100644 --- a/proto/cellarfees/v1/query.proto +++ b/proto/cellarfees/v1/query.proto @@ -6,7 +6,7 @@ import "google/api/annotations.proto"; import "cellarfees/v1/params.proto"; import "cellarfees/v1/cellarfees.proto"; -option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types"; +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v1"; service Query { rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) { diff --git a/proto/cellarfees/v2/cellarfees.proto b/proto/cellarfees/v2/cellarfees.proto new file mode 100644 index 000000000..9fba95543 --- /dev/null +++ b/proto/cellarfees/v2/cellarfees.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package cellarfees.v2; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; + +message FeeTokenBalance { + cosmos.base.v1beta1.Coin balance = 1 [ (gogoproto.nullable) = false ]; + string usd_value = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/cellarfees/v2/genesis.proto b/proto/cellarfees/v2/genesis.proto new file mode 100644 index 000000000..9e53c362f --- /dev/null +++ b/proto/cellarfees/v2/genesis.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package cellarfees.v2; + +import "gogoproto/gogo.proto"; +import "cellarfees/v2/params.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; + +// GenesisState defines the cellarfees module's genesis state. +message GenesisState { + reserved 2; // deleted fee accrual counters field + + Params params = 1 [(gogoproto.nullable) = false]; + string last_reward_supply_peak = 3 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; +} diff --git a/proto/cellarfees/v2/params.proto b/proto/cellarfees/v2/params.proto new file mode 100644 index 000000000..4d5f31fa9 --- /dev/null +++ b/proto/cellarfees/v2/params.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; +package cellarfees.v2; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; + +// Params defines the parameters for the module. +message Params { + reserved 1; // deleted fee accrual threshold field + + option (gogoproto.goproto_stringer) = false; + + // Emission rate factor. Specifically, the number of blocks over which to distribute + // some amount of staking rewards. + uint64 reward_emission_period = 2; + // The initial rate at which auctions should decrease their denom's price in SOMM + string initial_price_decrease_rate = 3 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; + // Number of blocks between auction price decreases + uint64 price_decrease_block_interval = 4; + // The interval between starting auctions + uint64 auction_interval = 5; + // A fee token's total USD value threshold, based on it's auction.v1.TokenPrice, above which an auction is triggered + string auction_threshold_usd_value = 6 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false]; +} + + diff --git a/proto/cellarfees/v2/query.proto b/proto/cellarfees/v2/query.proto new file mode 100644 index 000000000..05d8614fe --- /dev/null +++ b/proto/cellarfees/v2/query.proto @@ -0,0 +1,74 @@ +syntax = "proto3"; +package cellarfees.v2; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cellarfees/v2/params.proto"; +import "cellarfees/v2/cellarfees.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; + +service Query { + rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/params"; + } + + rpc QueryModuleAccounts(QueryModuleAccountsRequest) returns (QueryModuleAccountsResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/module_accounts"; + } + + rpc QueryLastRewardSupplyPeak(QueryLastRewardSupplyPeakRequest) returns (QueryLastRewardSupplyPeakResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/last_reward_supply_peak"; + } + + rpc QueryAPY(QueryAPYRequest) returns (QueryAPYResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/apy"; + } + + rpc QueryFeeTokenBalances(QueryFeeTokenBalancesRequest) returns (QueryFeeTokenBalancesResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/fee_token_balances"; + } + + rpc QueryFeeTokenBalance(QueryFeeTokenBalanceRequest) returns (QueryFeeTokenBalanceResponse) { + option (google.api.http).get = "/sommelier/cellarfees/v2/fee_token_balances/{denom}"; + } +} + +message QueryParamsRequest {} + +message QueryParamsResponse { + Params params = 1 [(gogoproto.nullable) = false]; +} + +message QueryModuleAccountsRequest {} + +message QueryModuleAccountsResponse { + string fees_address = 1; +} + +message QueryLastRewardSupplyPeakRequest {} + +message QueryLastRewardSupplyPeakResponse { + string last_reward_supply_peak = 1 + [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false]; +} + +message QueryAPYRequest {} + +message QueryAPYResponse { + string apy = 1; +} + +message QueryFeeTokenBalancesRequest {} + +message QueryFeeTokenBalancesResponse { + repeated FeeTokenBalance balances = 1; +} + +message QueryFeeTokenBalanceRequest { + string denom = 1; +} + +message QueryFeeTokenBalanceResponse { + FeeTokenBalance balance = 1; +} diff --git a/x/cellarfees/client/cli/query.go b/x/cellarfees/client/cli/query.go index 9f4eb7ead..44af37a19 100644 --- a/x/cellarfees/client/cli/query.go +++ b/x/cellarfees/client/cli/query.go @@ -5,24 +5,24 @@ import ( "fmt" // "strings" - "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" + // sdk "github.com/cosmos/cosmos-sdk/v2. - "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + types "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) // GetQueryCmd returns the cli query commands for this module func GetQueryCmd(queryRoute string) *cobra.Command { // Group cellarfees queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: cellarfeestypes.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", cellarfeestypes.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -30,7 +30,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryParams()) cmd.AddCommand(CmdQueryModuleAccounts()) - cmd.AddCommand(CmdQueryFeeAccrualCounters()) cmd.AddCommand(CmdQueryLastRewardSupplyPeak()) cmd.AddCommand(CmdQueryAPY()) @@ -113,32 +112,6 @@ func CmdQueryLastRewardSupplyPeak() *cobra.Command { return cmd } -func CmdQueryFeeAccrualCounters() *cobra.Command { - cmd := &cobra.Command{ - Use: "fee-accrual-counters", - Aliases: []string{"fac"}, - Short: "shows the number of fee accruals per denom since the last respective auction", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - - queryClient := types.NewQueryClient(clientCtx) - - res, err := queryClient.QueryFeeAccrualCounters( - context.Background(), &types.QueryFeeAccrualCountersRequest{}) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - func CmdQueryAPY() *cobra.Command { cmd := &cobra.Command{ Use: "apy", diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 1ae5e2668..e161e03ce 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -12,23 +12,6 @@ import ( func (k Keeper) BeginBlocker(ctx sdk.Context) { // Handle fee auctions - cellarfeesParams := k.GetParams(ctx) - - counters := k.GetFeeAccrualCounters(ctx) - - modulus := ctx.BlockHeader().Height % int64(cellarfeesParams.AuctionInterval) - - for _, counter := range counters.Counters { - - if counter.Count >= cellarfeesParams.FeeAccrualAuctionThreshold && modulus == 0 { - started := k.beginAuction(ctx, counter.Denom) - if started { - counters.ResetCounter(counter.Denom) - } - } - - } - k.SetFeeAccrualCounters(ctx, counters) // Handle reward emissions moduleAccount := k.GetFeesAccount(ctx) diff --git a/x/cellarfees/keeper/genesis.go b/x/cellarfees/keeper/genesis.go index bfcab0304..ea5d2c020 100644 --- a/x/cellarfees/keeper/genesis.go +++ b/x/cellarfees/keeper/genesis.go @@ -4,19 +4,19 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + types "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) // InitGenesis initializes the module's state from a provided genesis // state. func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) { k.SetParams(ctx, gs.Params) - k.SetFeeAccrualCounters(ctx, gs.FeeAccrualCounters) k.SetLastRewardSupplyPeak(ctx, gs.LastRewardSupplyPeak) feesAccount := k.GetFeesAccount(ctx) if feesAccount == nil { - panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) + panic(fmt.Sprintf("%s module account has not been set", cellarfeestypes.ModuleName)) } } @@ -24,7 +24,6 @@ func (k Keeper) InitGenesis(ctx sdk.Context, gs types.GenesisState) { func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { return types.GenesisState{ Params: k.GetParams(ctx), - FeeAccrualCounters: k.GetFeeAccrualCounters(ctx), LastRewardSupplyPeak: k.GetLastRewardSupplyPeak(ctx), } } diff --git a/x/cellarfees/keeper/keeper.go b/x/cellarfees/keeper/keeper.go index 66682e899..5b610466d 100644 --- a/x/cellarfees/keeper/keeper.go +++ b/x/cellarfees/keeper/keeper.go @@ -3,8 +3,6 @@ package keeper import ( "fmt" "math/big" - "sort" - "strings" "cosmossdk.io/math" "github.com/tendermint/tendermint/libs/log" @@ -14,31 +12,32 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/peggyjv/sommelier/v7/app/params" - "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + types "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) type Keeper struct { cdc codec.BinaryCodec storeKey storetypes.StoreKey paramSpace paramtypes.Subspace - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper - mintKeeper types.MintKeeper - corkKeeper types.CorkKeeper - gravityKeeper types.GravityKeeper - auctionKeeper types.AuctionKeeper + accountKeeper cellarfeestypes.AccountKeeper + bankKeeper cellarfeestypes.BankKeeper + mintKeeper cellarfeestypes.MintKeeper + corkKeeper cellarfeestypes.CorkKeeper + gravityKeeper cellarfeestypes.GravityKeeper + auctionKeeper cellarfeestypes.AuctionKeeper } func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, - accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, - mintKeeper types.MintKeeper, - corkKeeper types.CorkKeeper, - gravityKeeper types.GravityKeeper, - auctionKeeper types.AuctionKeeper, + accountKeeper cellarfeestypes.AccountKeeper, + bankKeeper cellarfeestypes.BankKeeper, + mintKeeper cellarfeestypes.MintKeeper, + corkKeeper cellarfeestypes.CorkKeeper, + gravityKeeper cellarfeestypes.GravityKeeper, + auctionKeeper cellarfeestypes.AuctionKeeper, ) Keeper { if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -58,7 +57,7 @@ func NewKeeper( } func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", cellarfeestypes.ModuleName)) } //////////// @@ -81,7 +80,7 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { func (k Keeper) GetLastRewardSupplyPeak(ctx sdk.Context) math.Int { store := ctx.KVStore(k.storeKey) - b := store.Get(types.GetLastRewardSupplyPeakKey()) + b := store.Get(cellarfeestypes.GetLastRewardSupplyPeakKey()) if b == nil { panic("Last highest reward supply should not have been nil") } @@ -92,37 +91,7 @@ func (k Keeper) GetLastRewardSupplyPeak(ctx sdk.Context) math.Int { func (k Keeper) SetLastRewardSupplyPeak(ctx sdk.Context, amount math.Int) { store := ctx.KVStore(k.storeKey) b := amount.BigInt().Bytes() - store.Set(types.GetLastRewardSupplyPeakKey(), b) -} - -////////////////////////// -// Fee accrual counters // -////////////////////////// - -func (k Keeper) GetFeeAccrualCounters(ctx sdk.Context) (counters types.FeeAccrualCounters) { - store := ctx.KVStore(k.storeKey) - b := store.Get(types.GetFeeAccrualCountersKey()) - if b == nil { - panic("Fee accrual counters is nil, it should have been set by InitGenesis") - } - if len(b) == 0 { - return types.DefaultFeeAccrualCounters() - } - - k.cdc.MustUnmarshal(b, &counters) - return -} - -func (k Keeper) SetFeeAccrualCounters(ctx sdk.Context, counters types.FeeAccrualCounters) { - store := ctx.KVStore(k.storeKey) - counterSlice := make([]types.FeeAccrualCounter, 0, len(counters.Counters)) - counterSlice = append(counterSlice, counters.Counters...) - sort.Slice(counterSlice, func(i, j int) bool { - return strings.Compare(counterSlice[i].Denom, counterSlice[j].Denom) == -1 - }) - counters.Counters = counterSlice - b := k.cdc.MustMarshal(&counters) - store.Set(types.GetFeeAccrualCountersKey(), b) + store.Set(cellarfeestypes.GetLastRewardSupplyPeakKey(), b) } //////////// diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index d78e3713a..856e45766 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -4,7 +4,7 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + types "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -39,14 +39,6 @@ func (k Keeper) QueryLastRewardSupplyPeak(c context.Context, req *types.QueryLas return &types.QueryLastRewardSupplyPeakResponse{LastRewardSupplyPeak: k.GetLastRewardSupplyPeak(sdk.UnwrapSDKContext(c))}, nil } -func (k Keeper) QueryFeeAccrualCounters(c context.Context, req *types.QueryFeeAccrualCountersRequest) (*types.QueryFeeAccrualCountersResponse, error) { - if req == nil { - return nil, status.Error(codes.InvalidArgument, "empty request") - } - - return &types.QueryFeeAccrualCountersResponse{FeeAccrualCounters: k.GetFeeAccrualCounters(sdk.UnwrapSDKContext(c))}, nil -} - func (k Keeper) QueryAPY(c context.Context, _ *types.QueryAPYRequest) (*types.QueryAPYResponse, error) { return &types.QueryAPYResponse{ Apy: k.GetAPY(sdk.UnwrapSDKContext(c)).String(), diff --git a/x/cellarfees/types/cellarfees.go b/x/cellarfees/types/cellarfees.go deleted file mode 100644 index 59e54f938..000000000 --- a/x/cellarfees/types/cellarfees.go +++ /dev/null @@ -1,68 +0,0 @@ -package types - -import ( - "sort" - "strings" -) - -func DefaultFeeAccrualCounters() FeeAccrualCounters { - return FeeAccrualCounters{ - Counters: []FeeAccrualCounter{}, - } -} - -// Implementing sort.Interface (see https://pkg.go.dev/sort#Interface) -func (f FeeAccrualCounters) Len() int { - return len(f.Counters) -} - -func (f FeeAccrualCounters) Less(i, j int) bool { - return strings.Compare(f.Counters[i].Denom, f.Counters[j].Denom) == -1 -} - -func (f FeeAccrualCounters) Swap(i, j int) { - f.Counters[i], f.Counters[j] = f.Counters[j], f.Counters[i] -} - -// WARNING: If editing these methods, be aware that insert() doesn't check if the denom is already -// present. Duplicate denom entries can result in fees not being auctioned. -func (f *FeeAccrualCounters) insertCounter(denom string, count uint64) { - f.Counters = append(f.Counters, FeeAccrualCounter{Denom: denom, Count: count}) - sort.Sort(f) -} - -// Increment fee accrual counter for denom. If it isn't present, append it to the counters -// slice and increment to 1. -func (f *FeeAccrualCounters) IncrementCounter(denom string) uint64 { - found := false - var count uint64 - for i, k := range f.Counters { - if k.Denom == denom { - found = true - f.Counters[i].Count++ - count = f.Counters[i].Count - break - } - } - if !found { - f.insertCounter(denom, 1) - count = 1 - } - - return count -} - -// Sets the denom's fee accrual counter to zero -func (f *FeeAccrualCounters) ResetCounter(denom string) { - found := false - for i, k := range f.Counters { - if k.Denom == denom { - found = true - f.Counters[i].Count = 0 - break - } - } - if !found { - f.insertCounter(denom, 0) - } -} diff --git a/x/cellarfees/types/cellarfees_test.go b/x/cellarfees/types/cellarfees_test.go deleted file mode 100644 index bc466e716..000000000 --- a/x/cellarfees/types/cellarfees_test.go +++ /dev/null @@ -1,65 +0,0 @@ -package types - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestFeeAccrualCounters(t *testing.T) { - expected := FeeAccrualCounters{ - Counters: []FeeAccrualCounter{ - { - Denom: "uatom", - Count: 1, - }, - { - Denom: "uist", - Count: 0, - }, - { - Denom: "uusdc", - Count: 2, - }, - }, - } - - actual := DefaultFeeAccrualCounters() - - require.Equal(t, 0, len(actual.Counters)) - - // uist: 0 - actual.ResetCounter("uist") - require.Equal(t, 1, len(actual.Counters)) - require.Equal(t, uint64(0), actual.Counters[0].Count) - - // uist: 0 - // uusdc: 1 - actual.IncrementCounter("uusdc") - require.Equal(t, len(actual.Counters), 2) - require.Equal(t, "uusdc", actual.Counters[1].Denom) - require.Equal(t, uint64(1), actual.Counters[1].Count) - - // uist: 0 - // uusdc: 2 - actual.IncrementCounter("uusdc") - - // uatom: 1 - // uist: 0 - // uusdc: 2 - actual.IncrementCounter("uatom") - require.Equal(t, len(actual.Counters), 3) - require.Equal(t, "uatom", actual.Counters[0].Denom) - require.Equal(t, uint64(1), actual.Counters[0].Count) - require.Equal(t, expected, actual) - - // uatom: 1 - // uist: 0 - // uusdc: 0 - actual.ResetCounter("uusdc") - - // uatom: 1 - // uist: 0 - // uusdc: 1 - require.Equal(t, uint64(1), actual.IncrementCounter("uusdc")) -} diff --git a/x/cellarfees/types/genesis.go b/x/cellarfees/types/genesis.go deleted file mode 100644 index 774a3274f..000000000 --- a/x/cellarfees/types/genesis.go +++ /dev/null @@ -1,44 +0,0 @@ -package types - -import ( - "sort" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -const DefaultParamspace = ModuleName - -// DefaultGenesisState get raw genesis raw message for testing -func DefaultGenesisState() GenesisState { - return GenesisState{ - Params: DefaultParams(), - FeeAccrualCounters: DefaultFeeAccrualCounters(), - LastRewardSupplyPeak: sdk.ZeroInt(), - } -} - -// Validate performs a basic stateless validation of the genesis fields. -func (gs GenesisState) Validate() error { - if err := gs.Params.ValidateBasic(); err != nil { - return err - } - - if gs.FeeAccrualCounters.Counters == nil { - return ErrInvalidFeeAccrualCounters.Wrap("counters cannot be nil!") - } - - counters := gs.FeeAccrualCounters - counters.Counters = append([]FeeAccrualCounter{}, gs.FeeAccrualCounters.Counters...) - sort.Sort(counters) - for i := range counters.Counters { - if counters.Counters[i].Denom != gs.FeeAccrualCounters.Counters[i].Denom { - return ErrInvalidFeeAccrualCounters.Wrapf("counters are unsorted! expected: %T, actual: %T", counters.Counters, gs.FeeAccrualCounters.Counters) - } - } - - if gs.LastRewardSupplyPeak.LT(sdk.ZeroInt()) { - return ErrInvalidLastRewardSupplyPeak.Wrap("last reward supply peak cannot be less than zero!") - } - - return nil -} diff --git a/x/cellarfees/types/keys.go b/x/cellarfees/types/keys.go index 3495e8bc0..db7b6329a 100644 --- a/x/cellarfees/types/keys.go +++ b/x/cellarfees/types/keys.go @@ -22,6 +22,7 @@ const ( LastRewardSupplyPeakKey // key for storing fee accrual counts + // DEPRECATED FeeAccrualCountersKey ) @@ -29,8 +30,3 @@ const ( func GetLastRewardSupplyPeakKey() []byte { return []byte{LastRewardSupplyPeakKey} } - -// GetFeeAccrualCountersKey returns the key prefix -func GetFeeAccrualCountersKey() []byte { - return []byte{FeeAccrualCountersKey} -} diff --git a/x/cellarfees/types/cellarfees.pb.go b/x/cellarfees/types/v1/cellarfees.pb.go similarity index 98% rename from x/cellarfees/types/cellarfees.pb.go rename to x/cellarfees/types/v1/cellarfees.pb.go index 96be482c3..2dd2a5f80 100644 --- a/x/cellarfees/types/cellarfees.pb.go +++ b/x/cellarfees/types/v1/cellarfees.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cellarfees/v1/cellarfees.proto -package types +package v1 import ( fmt "fmt" @@ -137,12 +137,12 @@ var fileDescriptor_34c89ca12b610c1b = []byte{ 0x90, 0x60, 0x52, 0x60, 0xd4, 0x60, 0x09, 0x82, 0x70, 0x94, 0x22, 0xb8, 0x84, 0x30, 0x0c, 0x28, 0x16, 0x72, 0xe2, 0xe2, 0x48, 0x86, 0xb2, 0x25, 0x18, 0x15, 0x98, 0x35, 0xb8, 0x8d, 0x14, 0xf4, 0x50, 0x9c, 0xa3, 0x87, 0xa1, 0xc9, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xb8, 0x3e, 0x27, - 0x9f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, - 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4a, 0xcf, 0x2c, 0xc9, + 0xff, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, + 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x2f, 0x48, 0x4d, 0x4f, 0xaf, 0xcc, 0x2a, 0xd3, 0x2f, 0xce, 0xcf, 0xcd, 0x4d, 0xcd, 0xc9, 0x4c, 0x2d, 0xd2, 0x2f, 0x33, 0xd7, 0xaf, 0x40, 0x0a, 0x0d, - 0xfd, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x7f, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x9f, 0x35, 0xe6, 0x97, 0x36, 0x01, 0x00, 0x00, + 0xfd, 0x92, 0xca, 0x02, 0x70, 0x08, 0x25, 0xb1, 0x81, 0xbd, 0x6c, 0x0c, 0x08, 0x00, 0x00, 0xff, + 0xff, 0xae, 0x5f, 0x26, 0x62, 0x39, 0x01, 0x00, 0x00, } func (m *FeeAccrualCounter) Marshal() (dAtA []byte, err error) { diff --git a/x/cellarfees/types/genesis.pb.go b/x/cellarfees/types/v1/genesis.pb.go similarity index 84% rename from x/cellarfees/types/genesis.pb.go rename to x/cellarfees/types/v1/genesis.pb.go index 79758e695..9c9c6f6f7 100644 --- a/x/cellarfees/types/genesis.pb.go +++ b/x/cellarfees/types/v1/genesis.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cellarfees/v1/genesis.proto -package types +package v1 import ( fmt "fmt" @@ -85,28 +85,28 @@ func init() { func init() { proto.RegisterFile("cellarfees/v1/genesis.proto", fileDescriptor_856aa03b4cb6eca9) } var fileDescriptor_856aa03b4cb6eca9 = []byte{ - // 326 bytes of a gzipped FileDescriptorProto + // 328 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0xd0, 0x31, 0x4f, 0x32, 0x31, 0x18, 0x07, 0xf0, 0x3b, 0xde, 0x37, 0x24, 0x9e, 0xba, 0x5c, 0x30, 0x92, 0x33, 0x29, 0xe8, 0x60, - 0x58, 0x6c, 0x03, 0x0c, 0xce, 0x62, 0xa2, 0x31, 0x71, 0x20, 0x30, 0xe9, 0x72, 0x29, 0xe5, 0xa1, - 0x22, 0x3d, 0xda, 0xb4, 0xbd, 0x53, 0x3e, 0x80, 0xbb, 0x1f, 0x8b, 0x91, 0xd1, 0x38, 0x10, 0x03, - 0x5f, 0xc4, 0xd0, 0xbb, 0x44, 0xd0, 0xa9, 0x4d, 0xfe, 0xff, 0xfe, 0x9e, 0xe6, 0x09, 0x4e, 0x18, - 0x08, 0x41, 0xf5, 0x08, 0xc0, 0x90, 0xac, 0x49, 0x38, 0x4c, 0xc1, 0x8c, 0x0d, 0x56, 0x5a, 0x5a, - 0x19, 0x1e, 0xfe, 0x84, 0x38, 0x6b, 0x46, 0x15, 0x2e, 0xb9, 0x74, 0x09, 0xd9, 0xdc, 0xf2, 0x52, - 0x14, 0xed, 0x0a, 0x8a, 0x6a, 0x9a, 0x14, 0x40, 0x84, 0x76, 0xb3, 0x2d, 0xce, 0xe5, 0x67, 0x6f, - 0xa5, 0xe0, 0xe0, 0x36, 0x1f, 0xd9, 0xb7, 0xd4, 0x42, 0xd8, 0x0e, 0xca, 0x39, 0x50, 0xf5, 0xeb, - 0x7e, 0x63, 0xbf, 0x75, 0x84, 0x77, 0xbe, 0x80, 0xbb, 0x2e, 0xec, 0xfc, 0x9f, 0x2f, 0x6b, 0x5e, - 0xaf, 0xa8, 0x86, 0x0f, 0x41, 0x65, 0x04, 0x10, 0x53, 0xc6, 0x74, 0x4a, 0x45, 0xcc, 0x64, 0x3a, - 0xb5, 0xa0, 0x4d, 0xb5, 0xe4, 0x88, 0xd3, 0x5f, 0xc4, 0x0d, 0xc0, 0x55, 0xde, 0xbc, 0x2e, 0x8a, - 0x05, 0x17, 0x8e, 0xfe, 0x24, 0x21, 0x04, 0xc7, 0x82, 0x1a, 0x1b, 0x6b, 0x78, 0xa1, 0x7a, 0x18, - 0x9b, 0x54, 0x29, 0x31, 0x8b, 0x15, 0xd0, 0x49, 0xf5, 0x5f, 0xdd, 0x6f, 0xec, 0x75, 0xf0, 0xe6, - 0xe9, 0xe7, 0xb2, 0x76, 0xce, 0xc7, 0xf6, 0x29, 0x1d, 0x60, 0x26, 0x13, 0xc2, 0xa4, 0x49, 0xa4, - 0x29, 0x8e, 0x0b, 0x33, 0x9c, 0x10, 0x3b, 0x53, 0x60, 0xf0, 0xdd, 0xd4, 0xf6, 0x2a, 0x1b, 0xae, - 0xe7, 0xb4, 0xbe, 0xc3, 0xba, 0x40, 0x27, 0x9d, 0xfb, 0xf9, 0x0a, 0xf9, 0x8b, 0x15, 0xf2, 0xbf, - 0x56, 0xc8, 0x7f, 0x5f, 0x23, 0x6f, 0xb1, 0x46, 0xde, 0xc7, 0x1a, 0x79, 0x8f, 0xad, 0x2d, 0x57, - 0x01, 0xe7, 0xb3, 0xe7, 0x8c, 0x18, 0x99, 0x24, 0x20, 0xc6, 0xa0, 0x49, 0x76, 0x49, 0x5e, 0xb7, - 0xb6, 0x9a, 0xcf, 0x19, 0x94, 0xdd, 0x72, 0xdb, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7c, 0x93, - 0x0c, 0xf6, 0xdc, 0x01, 0x00, 0x00, + 0x58, 0x6c, 0x83, 0xc4, 0x38, 0x8b, 0x89, 0xc6, 0x49, 0x02, 0x93, 0x2e, 0x97, 0x52, 0x1e, 0x2a, + 0xd2, 0xa3, 0x4d, 0xdb, 0x3b, 0xe5, 0x03, 0xb8, 0xfb, 0xb1, 0x18, 0x19, 0x8d, 0x03, 0x31, 0xf0, + 0x45, 0x0c, 0xbd, 0x4b, 0x04, 0x9d, 0xda, 0xe4, 0xff, 0xef, 0xef, 0x69, 0x9e, 0xe0, 0x88, 0x81, + 0x10, 0x54, 0x0f, 0x01, 0x0c, 0xc9, 0x9a, 0x84, 0xc3, 0x04, 0xcc, 0xc8, 0x60, 0xa5, 0xa5, 0x95, + 0xe1, 0xfe, 0x4f, 0x88, 0xb3, 0x66, 0x54, 0xe1, 0x92, 0x4b, 0x97, 0x90, 0xf5, 0x2d, 0x2f, 0x45, + 0xd1, 0xb6, 0xa0, 0xa8, 0xa6, 0x49, 0x01, 0x44, 0x68, 0x3b, 0xdb, 0xe0, 0x5c, 0x7e, 0xf2, 0x56, + 0x0a, 0xf6, 0x6e, 0xf3, 0x91, 0x3d, 0x4b, 0x2d, 0x84, 0xad, 0xa0, 0x9c, 0x03, 0x55, 0xbf, 0xee, + 0x37, 0x76, 0xcf, 0x0f, 0xf0, 0xd6, 0x17, 0x70, 0xc7, 0x85, 0xed, 0xff, 0xb3, 0x45, 0xcd, 0xeb, + 0x16, 0xd5, 0xf0, 0x21, 0xa8, 0x0c, 0x01, 0x62, 0xca, 0x98, 0x4e, 0xa9, 0x88, 0x99, 0x4c, 0x27, + 0x16, 0xb4, 0xa9, 0x96, 0x1c, 0x71, 0xfc, 0x8b, 0xb8, 0x01, 0xb8, 0xca, 0x9b, 0xd7, 0x45, 0xb1, + 0xe0, 0xc2, 0xe1, 0x9f, 0x24, 0x84, 0xe0, 0x50, 0x50, 0x63, 0x63, 0x0d, 0x2f, 0x54, 0x0f, 0x62, + 0x93, 0x2a, 0x25, 0xa6, 0xb1, 0x02, 0x3a, 0xae, 0xfe, 0xab, 0xfb, 0x8d, 0x9d, 0x36, 0x5e, 0x3f, + 0xfd, 0x5c, 0xd4, 0x4e, 0xf9, 0xc8, 0x3e, 0xa5, 0x7d, 0xcc, 0x64, 0x42, 0x98, 0x34, 0x89, 0x34, + 0xc5, 0x71, 0x66, 0x06, 0x63, 0x62, 0xa7, 0x0a, 0x0c, 0xbe, 0x9b, 0xd8, 0x6e, 0x65, 0xcd, 0x75, + 0x9d, 0xd6, 0x73, 0x58, 0x07, 0xe8, 0xb8, 0x7d, 0x3f, 0x5b, 0x22, 0x7f, 0xbe, 0x44, 0xfe, 0xd7, + 0x12, 0xf9, 0xef, 0x2b, 0xe4, 0xcd, 0x57, 0xc8, 0xfb, 0x58, 0x21, 0xef, 0xf1, 0x62, 0xc3, 0x55, + 0xc0, 0xf9, 0xf4, 0x39, 0x23, 0x46, 0x26, 0x09, 0x88, 0x11, 0x68, 0x92, 0x5d, 0x92, 0xd7, 0x8d, + 0xad, 0xe6, 0x73, 0x48, 0xd6, 0xec, 0x97, 0xdd, 0x7e, 0x5b, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x3f, 0x21, 0x00, 0x71, 0xdf, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/cellarfees/types/params.pb.go b/x/cellarfees/types/v1/params.pb.go similarity index 84% rename from x/cellarfees/types/params.pb.go rename to x/cellarfees/types/v1/params.pb.go index 546ca87eb..145770448 100644 --- a/x/cellarfees/types/params.pb.go +++ b/x/cellarfees/types/v1/params.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cellarfees/v1/params.proto -package types +package v1 import ( fmt "fmt" @@ -106,30 +106,30 @@ func init() { func init() { proto.RegisterFile("cellarfees/v1/params.proto", fileDescriptor_f3220ed6f8663c98) } var fileDescriptor_f3220ed6f8663c98 = []byte{ - // 366 bytes of a gzipped FileDescriptorProto + // 367 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x91, 0x41, 0x4b, 0xf3, 0x30, 0x18, 0xc7, 0xdb, 0xbd, 0x7b, 0x07, 0x16, 0x44, 0x29, 0x43, 0xca, 0xc4, 0x6e, 0x78, 0x90, 0x79, - 0xb0, 0x61, 0x2a, 0x08, 0xde, 0x36, 0xe6, 0x41, 0xf0, 0x30, 0x86, 0x27, 0x2f, 0x21, 0x4b, 0x9f, - 0x75, 0x71, 0xe9, 0x52, 0x92, 0xac, 0xba, 0x6f, 0xe1, 0xd1, 0xa3, 0x1f, 0x67, 0xc7, 0x1d, 0xc5, - 0xc3, 0x90, 0xcd, 0x0f, 0x22, 0x4d, 0x3b, 0x1d, 0x9e, 0x5a, 0xf2, 0xff, 0xfd, 0x9e, 0xf0, 0xcf, - 0xe3, 0xd4, 0x28, 0x70, 0x4e, 0xe4, 0x10, 0x40, 0xa1, 0xb4, 0x85, 0x12, 0x22, 0x49, 0xac, 0x82, - 0x44, 0x0a, 0x2d, 0xdc, 0xdd, 0xdf, 0x2c, 0x48, 0x5b, 0xb5, 0x6a, 0x24, 0x22, 0x61, 0x12, 0x94, - 0xfd, 0xe5, 0xd0, 0xf1, 0x57, 0xc9, 0xa9, 0xf4, 0x8c, 0xe5, 0xb6, 0x9d, 0xa3, 0x21, 0x00, 0x26, - 0x94, 0xca, 0x29, 0xe1, 0x98, 0x4c, 0xa9, 0x66, 0x62, 0x82, 0xf5, 0x48, 0x82, 0x1a, 0x09, 0x1e, - 0x7a, 0x76, 0xc3, 0x6e, 0x96, 0xfb, 0xb5, 0x21, 0x40, 0x3b, 0x67, 0xda, 0x39, 0x72, 0xbf, 0x21, - 0xdc, 0x4b, 0xe7, 0x40, 0xc2, 0x13, 0x91, 0x21, 0x86, 0x98, 0x29, 0x95, 0xe9, 0x09, 0x48, 0x26, - 0x42, 0xaf, 0x64, 0xdc, 0x6a, 0x9e, 0xde, 0x14, 0x61, 0xcf, 0x64, 0x6e, 0xec, 0x1c, 0xb2, 0x09, - 0xd3, 0x8c, 0x70, 0x9c, 0x48, 0x46, 0x01, 0x87, 0x40, 0x25, 0x10, 0x05, 0x58, 0x12, 0x0d, 0xde, - 0xbf, 0x86, 0xdd, 0xdc, 0xe9, 0x04, 0xf3, 0x65, 0xdd, 0xfa, 0x58, 0xd6, 0x4f, 0x22, 0xa6, 0x47, - 0xd3, 0x41, 0x40, 0x45, 0x8c, 0xa8, 0x50, 0xb1, 0x50, 0xc5, 0xe7, 0x4c, 0x85, 0x63, 0xa4, 0x67, - 0x09, 0xa8, 0xa0, 0x0b, 0xb4, 0xef, 0x15, 0x23, 0x7b, 0xd9, 0xc4, 0x6e, 0x31, 0xb0, 0x4f, 0x34, - 0x64, 0x3d, 0xff, 0x5c, 0x33, 0xe0, 0x82, 0x8e, 0x31, 0x9b, 0x68, 0x90, 0x29, 0xe1, 0x5e, 0x39, - 0xef, 0x99, 0x6c, 0x9b, 0x9d, 0x0c, 0xb9, 0x2d, 0x08, 0xf7, 0xd4, 0xd9, 0xdf, 0x3c, 0xcf, 0x8f, - 0xf5, 0xdf, 0x58, 0x7b, 0xc5, 0xf9, 0x06, 0xbd, 0x2e, 0xbf, 0xbe, 0xd5, 0xad, 0xce, 0xdd, 0x7c, - 0xe5, 0xdb, 0x8b, 0x95, 0x6f, 0x7f, 0xae, 0x7c, 0xfb, 0x65, 0xed, 0x5b, 0x8b, 0xb5, 0x6f, 0xbd, - 0xaf, 0x7d, 0xeb, 0xe1, 0x7c, 0xab, 0x4f, 0x02, 0x51, 0x34, 0x7b, 0x4c, 0x91, 0x12, 0x71, 0x0c, - 0x9c, 0x81, 0x44, 0xe9, 0x15, 0x7a, 0x46, 0x5b, 0x3b, 0x36, 0xfd, 0x06, 0x15, 0xb3, 0xbb, 0x8b, - 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x4d, 0xb2, 0xdd, 0xfe, 0x01, 0x00, 0x00, + 0xb0, 0x61, 0xa8, 0x08, 0xde, 0x36, 0xe6, 0xc1, 0x93, 0x63, 0x78, 0xf2, 0x12, 0xb2, 0xf4, 0x59, + 0x17, 0x97, 0x2e, 0x25, 0xc9, 0xaa, 0xfb, 0x16, 0x1e, 0x3d, 0xfa, 0x71, 0x76, 0xdc, 0x51, 0x3c, + 0x0c, 0xd9, 0xfc, 0x20, 0xd2, 0xb4, 0xd3, 0xe1, 0xa9, 0x25, 0xff, 0xdf, 0xef, 0x09, 0xff, 0x3c, + 0x4e, 0x8d, 0x02, 0xe7, 0x44, 0x0e, 0x01, 0x14, 0x4a, 0x5b, 0x28, 0x21, 0x92, 0xc4, 0x2a, 0x48, + 0xa4, 0xd0, 0xc2, 0xdd, 0xfd, 0xcd, 0x82, 0xb4, 0x55, 0xab, 0x46, 0x22, 0x12, 0x26, 0x41, 0xd9, + 0x5f, 0x0e, 0x1d, 0x7f, 0x95, 0x9c, 0x4a, 0xcf, 0x58, 0x6e, 0xdb, 0x39, 0x1a, 0x02, 0x60, 0x42, + 0xa9, 0x9c, 0x12, 0x8e, 0xc9, 0x94, 0x6a, 0x26, 0x26, 0x58, 0x8f, 0x24, 0xa8, 0x91, 0xe0, 0xa1, + 0x67, 0x37, 0xec, 0x66, 0xb9, 0x5f, 0x1b, 0x02, 0xb4, 0x73, 0xa6, 0x9d, 0x23, 0xf7, 0x1b, 0xc2, + 0xbd, 0x70, 0x0e, 0x24, 0x3c, 0x11, 0x19, 0x62, 0x88, 0x99, 0x52, 0x99, 0x9e, 0x80, 0x64, 0x22, + 0xf4, 0x4a, 0xc6, 0xad, 0xe6, 0xe9, 0x4d, 0x11, 0xf6, 0x4c, 0xe6, 0xc6, 0xce, 0x21, 0x9b, 0x30, + 0xcd, 0x08, 0xc7, 0x89, 0x64, 0x14, 0x70, 0x08, 0x54, 0x02, 0x51, 0x80, 0x25, 0xd1, 0xe0, 0xfd, + 0x6b, 0xd8, 0xcd, 0x9d, 0x4e, 0x30, 0x5f, 0xd6, 0xad, 0x8f, 0x65, 0xfd, 0x24, 0x62, 0x7a, 0x34, + 0x1d, 0x04, 0x54, 0xc4, 0x88, 0x0a, 0x15, 0x0b, 0x55, 0x7c, 0xce, 0x54, 0x38, 0x46, 0x7a, 0x96, + 0x80, 0x0a, 0xba, 0x40, 0xfb, 0x5e, 0x31, 0xb2, 0x97, 0x4d, 0xec, 0x16, 0x03, 0xfb, 0x44, 0x43, + 0xd6, 0xf3, 0xcf, 0x35, 0x03, 0x2e, 0xe8, 0x18, 0xb3, 0x89, 0x06, 0x99, 0x12, 0xee, 0x95, 0xf3, + 0x9e, 0xc9, 0xb6, 0xd9, 0xc9, 0x90, 0xdb, 0x82, 0x70, 0x4f, 0x9d, 0xfd, 0xcd, 0xf3, 0xfc, 0x58, + 0xff, 0x8d, 0xb5, 0x57, 0x9c, 0x6f, 0xd0, 0xeb, 0xf2, 0xeb, 0x5b, 0xdd, 0xea, 0xdc, 0xcd, 0x57, + 0xbe, 0xbd, 0x58, 0xf9, 0xf6, 0xe7, 0xca, 0xb7, 0x5f, 0xd6, 0xbe, 0xb5, 0x58, 0xfb, 0xd6, 0xfb, + 0xda, 0xb7, 0x1e, 0x2e, 0xb7, 0xfa, 0x24, 0x10, 0x45, 0xb3, 0xc7, 0x14, 0x29, 0x11, 0xc7, 0xc0, + 0x19, 0x48, 0x94, 0x5e, 0xa1, 0x67, 0xb4, 0xb5, 0x63, 0xd3, 0x0f, 0xa5, 0xad, 0x41, 0xc5, 0xac, + 0xef, 0xfc, 0x3b, 0x00, 0x00, 0xff, 0xff, 0xf9, 0xb0, 0x3a, 0x33, 0x01, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { diff --git a/x/cellarfees/types/query.pb.go b/x/cellarfees/types/v1/query.pb.go similarity index 92% rename from x/cellarfees/types/query.pb.go rename to x/cellarfees/types/v1/query.pb.go index bb0444a55..1f1f8a7dd 100644 --- a/x/cellarfees/types/query.pb.go +++ b/x/cellarfees/types/v1/query.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. // source: cellarfees/v1/query.proto -package types +package v1 import ( context "context" @@ -439,47 +439,47 @@ func init() { func init() { proto.RegisterFile("cellarfees/v1/query.proto", fileDescriptor_6f4742d3026cf20c) } var fileDescriptor_6f4742d3026cf20c = []byte{ - // 625 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0x41, 0x8f, 0xd2, 0x4c, - 0x1c, 0xc6, 0xe9, 0xfb, 0x2a, 0xd1, 0x41, 0xe3, 0x3a, 0x62, 0xd6, 0xad, 0xa4, 0x40, 0xb3, 0xd1, - 0x75, 0x13, 0x3a, 0x2c, 0x1b, 0xa3, 0x47, 0xc1, 0xc4, 0x44, 0xb3, 0x26, 0x88, 0xa7, 0xf5, 0xd2, - 0xcc, 0x96, 0xa1, 0x22, 0x6d, 0x67, 0xe8, 0xb4, 0x68, 0x13, 0xbd, 0x78, 0x31, 0xf1, 0x64, 0xe2, - 0xdd, 0xaf, 0xe0, 0xd5, 0x8f, 0xb0, 0xc7, 0x4d, 0xbc, 0x18, 0x0f, 0x1b, 0x03, 0x7e, 0x10, 0xd3, - 0xe9, 0xb0, 0xc0, 0xd2, 0x12, 0x4e, 0x34, 0xf3, 0x3c, 0xfd, 0x3f, 0xbf, 0x61, 0x9e, 0x0e, 0xd8, - 0xb2, 0x88, 0xe3, 0x60, 0xbf, 0x47, 0x08, 0x47, 0xa3, 0x3d, 0x34, 0x0c, 0x89, 0x1f, 0x19, 0xcc, - 0xa7, 0x01, 0x85, 0x57, 0x67, 0x92, 0x31, 0xda, 0x53, 0x8b, 0x36, 0xb5, 0xa9, 0x50, 0x50, 0xfc, - 0x94, 0x98, 0xd4, 0x92, 0x4d, 0xa9, 0xed, 0x10, 0x84, 0x59, 0x1f, 0x61, 0xcf, 0xa3, 0x01, 0x0e, - 0xfa, 0xd4, 0xe3, 0x52, 0x55, 0x17, 0xa7, 0x33, 0xec, 0x63, 0x77, 0xaa, 0x69, 0x8b, 0xda, 0x5c, - 0x98, 0xd0, 0xf5, 0x22, 0x80, 0x2f, 0x62, 0x9a, 0xb6, 0x78, 0xa9, 0x43, 0x86, 0x21, 0xe1, 0x81, - 0xfe, 0x0c, 0xdc, 0x58, 0x58, 0xe5, 0x8c, 0x7a, 0x9c, 0xc0, 0x7d, 0x90, 0x4f, 0x86, 0xdf, 0x52, - 0x2a, 0xca, 0x4e, 0xa1, 0x71, 0xd3, 0x58, 0x80, 0x37, 0x12, 0x7b, 0xeb, 0xc2, 0xf1, 0x69, 0x39, - 0xd7, 0x91, 0x56, 0xbd, 0x04, 0x54, 0x31, 0xeb, 0x39, 0xed, 0x86, 0x0e, 0x69, 0x5a, 0x16, 0x0d, - 0xbd, 0xe0, 0x2c, 0xe9, 0x11, 0xb8, 0x9d, 0xaa, 0xca, 0xc4, 0x2a, 0xb8, 0x12, 0x0f, 0x37, 0x71, - 0xb7, 0xeb, 0x13, 0x9e, 0xe4, 0x5e, 0xee, 0x14, 0xe2, 0xb5, 0x66, 0xb2, 0xa4, 0xeb, 0xa0, 0x22, - 0x26, 0x1c, 0x60, 0x1e, 0x74, 0xc8, 0x5b, 0xec, 0x77, 0x5f, 0x86, 0x8c, 0x39, 0x51, 0x9b, 0xe0, - 0xc1, 0x34, 0xe5, 0xb3, 0x02, 0xaa, 0x2b, 0x4c, 0x32, 0x8c, 0x80, 0x4d, 0x07, 0xf3, 0xc0, 0xf4, - 0x85, 0xc1, 0xe4, 0xc2, 0x61, 0x32, 0x82, 0x07, 0x49, 0x6e, 0xcb, 0x88, 0x37, 0xf6, 0xfb, 0xb4, - 0x7c, 0xc7, 0xee, 0x07, 0xaf, 0xc3, 0x23, 0xc3, 0xa2, 0x2e, 0xb2, 0x28, 0x77, 0x29, 0x97, 0x3f, - 0x35, 0xde, 0x1d, 0xa0, 0x20, 0x62, 0x84, 0x1b, 0x4f, 0xbd, 0xa0, 0x53, 0x74, 0x52, 0xe2, 0xf4, - 0x0a, 0xd0, 0x04, 0xcb, 0x13, 0x12, 0xef, 0xd7, 0x0f, 0xb1, 0xf3, 0x38, 0xde, 0x34, 0xf1, 0xcf, - 0xfe, 0x94, 0xf7, 0xa0, 0x9c, 0xe9, 0x90, 0xac, 0x87, 0xa0, 0xd8, 0x23, 0xc4, 0xc4, 0x89, 0x6c, - 0x5a, 0x52, 0x97, 0x07, 0x53, 0x3d, 0x77, 0x30, 0xcb, 0x83, 0xe4, 0x21, 0xc1, 0xde, 0x92, 0xa2, - 0x5f, 0x07, 0xd7, 0x44, 0x7a, 0xb3, 0x7d, 0x38, 0x05, 0xda, 0x06, 0x1b, 0xb3, 0x25, 0x49, 0xb0, - 0x01, 0xfe, 0xc7, 0x2c, 0x92, 0x27, 0x12, 0x3f, 0x36, 0x3e, 0xe5, 0xc1, 0x45, 0x61, 0x83, 0x1f, - 0x40, 0x61, 0xae, 0x3f, 0xf0, 0x3c, 0xce, 0x72, 0xe3, 0x54, 0x7d, 0x95, 0x25, 0x49, 0xd4, 0xef, - 0x7e, 0xfc, 0xf9, 0xf7, 0xeb, 0x7f, 0x55, 0x58, 0x46, 0x9c, 0xba, 0x2e, 0x71, 0xfa, 0xc4, 0x47, - 0x69, 0xd5, 0x87, 0xdf, 0x14, 0xd9, 0xdf, 0xc5, 0x56, 0xc1, 0x7b, 0x69, 0x21, 0xa9, 0xbd, 0x54, - 0x77, 0xd7, 0xb1, 0x4a, 0xae, 0xba, 0xe0, 0xda, 0x85, 0x3b, 0x99, 0x5c, 0xae, 0x78, 0x31, 0x3e, - 0xad, 0x04, 0xe4, 0x87, 0x02, 0xb6, 0x32, 0xfb, 0x08, 0x51, 0x5a, 0xf6, 0x8a, 0x7a, 0xab, 0xf5, - 0xf5, 0x5f, 0x90, 0xc8, 0x0f, 0x05, 0x72, 0x03, 0xd6, 0x33, 0x91, 0x33, 0xbe, 0x04, 0xf8, 0x5d, - 0x01, 0x9b, 0x19, 0xe5, 0x84, 0xb5, 0x34, 0x8e, 0xcc, 0x9a, 0xab, 0xc6, 0xba, 0x76, 0x09, 0x7d, - 0x5f, 0x40, 0x23, 0x58, 0xcb, 0x84, 0x4e, 0xfb, 0x24, 0xe0, 0x10, 0x5c, 0x9a, 0x96, 0x17, 0x6a, - 0x69, 0x91, 0xb3, 0xa2, 0xab, 0xe5, 0x4c, 0x5d, 0x32, 0x6c, 0x0b, 0x06, 0x0d, 0x96, 0x32, 0x19, - 0x30, 0x8b, 0x5a, 0x07, 0xc7, 0x63, 0x4d, 0x39, 0x19, 0x6b, 0xca, 0x9f, 0xb1, 0xa6, 0x7c, 0x99, - 0x68, 0xb9, 0x93, 0x89, 0x96, 0xfb, 0x35, 0xd1, 0x72, 0xaf, 0x1a, 0x73, 0x57, 0x07, 0x23, 0xb6, - 0x1d, 0xbd, 0x19, 0xcd, 0x4d, 0x1a, 0x3d, 0x40, 0xef, 0xe6, 0xc7, 0x89, 0xab, 0xe4, 0x28, 0x2f, - 0xae, 0xea, 0xfd, 0x7f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x6e, 0xe0, 0x3d, 0x9c, 0x46, 0x06, 0x00, - 0x00, + // 627 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x8f, 0xd2, 0x40, + 0x1c, 0xc5, 0xa9, 0x3f, 0x36, 0x3a, 0xab, 0x71, 0x1d, 0x31, 0xeb, 0x56, 0x52, 0xa0, 0xd9, 0xe8, + 0xba, 0x09, 0x1d, 0x60, 0xb3, 0xd1, 0xa3, 0x60, 0x62, 0xa2, 0xd1, 0x88, 0x78, 0x5a, 0x2f, 0xcd, + 0x6c, 0x19, 0x2a, 0xd2, 0x76, 0x86, 0x4e, 0x8b, 0x36, 0xd1, 0x8b, 0x17, 0x13, 0x4f, 0x26, 0xde, + 0xfd, 0x17, 0xbc, 0xfa, 0x27, 0xec, 0x71, 0x13, 0x2f, 0xc6, 0xc3, 0xc6, 0x80, 0x7f, 0x88, 0xe9, + 0x74, 0x58, 0x60, 0x69, 0x09, 0x27, 0x9a, 0x79, 0xaf, 0xdf, 0xf7, 0x19, 0xe6, 0x75, 0xc0, 0x96, + 0x45, 0x1c, 0x07, 0xfb, 0x5d, 0x42, 0x38, 0x1a, 0xd6, 0xd0, 0x20, 0x24, 0x7e, 0x64, 0x30, 0x9f, + 0x06, 0x14, 0x5e, 0x9d, 0x4a, 0xc6, 0xb0, 0xa6, 0xe6, 0x6d, 0x6a, 0x53, 0xa1, 0xa0, 0xf8, 0x29, + 0x31, 0xa9, 0x05, 0x9b, 0x52, 0xdb, 0x21, 0x08, 0xb3, 0x1e, 0xc2, 0x9e, 0x47, 0x03, 0x1c, 0xf4, + 0xa8, 0xc7, 0xa5, 0xaa, 0xce, 0x4f, 0x67, 0xd8, 0xc7, 0xee, 0x44, 0xd3, 0xe6, 0xb5, 0x99, 0x30, + 0xa1, 0xeb, 0x79, 0x00, 0x5f, 0xc6, 0x34, 0x2d, 0xf1, 0x52, 0x9b, 0x0c, 0x42, 0xc2, 0x03, 0xfd, + 0x29, 0xb8, 0x31, 0xb7, 0xca, 0x19, 0xf5, 0x38, 0x81, 0x7b, 0x60, 0x2d, 0x19, 0x7e, 0x4b, 0x29, + 0x29, 0x3b, 0xeb, 0xf5, 0x9b, 0xc6, 0x1c, 0xbc, 0x91, 0xd8, 0x9b, 0x17, 0x8e, 0x4e, 0x8a, 0xb9, + 0xb6, 0xb4, 0xea, 0x05, 0xa0, 0x8a, 0x59, 0xcf, 0x69, 0x27, 0x74, 0x48, 0xc3, 0xb2, 0x68, 0xe8, + 0x05, 0xa7, 0x49, 0x0f, 0xc1, 0xed, 0x54, 0x55, 0x26, 0x96, 0xc1, 0x95, 0x78, 0xb8, 0x89, 0x3b, + 0x1d, 0x9f, 0xf0, 0x24, 0xf7, 0x72, 0x7b, 0x3d, 0x5e, 0x6b, 0x24, 0x4b, 0xba, 0x0e, 0x4a, 0x62, + 0xc2, 0x33, 0xcc, 0x83, 0x36, 0x79, 0x87, 0xfd, 0xce, 0xab, 0x90, 0x31, 0x27, 0x6a, 0x11, 0xdc, + 0x9f, 0xa4, 0x7c, 0x51, 0x40, 0x79, 0x89, 0x49, 0x86, 0x11, 0xb0, 0xe9, 0x60, 0x1e, 0x98, 0xbe, + 0x30, 0x98, 0x5c, 0x38, 0x4c, 0x46, 0x70, 0x3f, 0xc9, 0x6d, 0x1a, 0xf1, 0xc6, 0xfe, 0x9c, 0x14, + 0xef, 0xd8, 0xbd, 0xe0, 0x4d, 0x78, 0x68, 0x58, 0xd4, 0x45, 0x16, 0xe5, 0x2e, 0xe5, 0xf2, 0xa7, + 0xc2, 0x3b, 0x7d, 0x14, 0x44, 0x8c, 0x70, 0xe3, 0x89, 0x17, 0xb4, 0xf3, 0x4e, 0x4a, 0x9c, 0x5e, + 0x02, 0x9a, 0x60, 0x79, 0x4c, 0xe2, 0xfd, 0xfa, 0x21, 0x76, 0x1e, 0xc5, 0x9b, 0x26, 0xfe, 0xe9, + 0x9f, 0xf2, 0x01, 0x14, 0x33, 0x1d, 0x92, 0xf5, 0x00, 0xe4, 0xbb, 0x84, 0x98, 0x38, 0x91, 0x4d, + 0x4b, 0xea, 0xf2, 0x60, 0xca, 0x67, 0x0e, 0x66, 0x71, 0x90, 0x3c, 0x24, 0xd8, 0x5d, 0x50, 0xf4, + 0xeb, 0xe0, 0x9a, 0x48, 0x6f, 0xb4, 0x0e, 0x26, 0x40, 0xdb, 0x60, 0x63, 0xba, 0x24, 0x09, 0x36, + 0xc0, 0x79, 0xcc, 0x22, 0x79, 0x22, 0xf1, 0x63, 0xfd, 0xf3, 0x1a, 0xb8, 0x28, 0x6c, 0xf0, 0x23, + 0x58, 0x9f, 0xe9, 0x0f, 0x3c, 0x8b, 0xb3, 0xd8, 0x38, 0x55, 0x5f, 0x66, 0x49, 0x12, 0xf5, 0xbb, + 0x9f, 0x7e, 0xfd, 0xfb, 0x76, 0xae, 0x0c, 0x8b, 0x88, 0x53, 0xd7, 0x25, 0x4e, 0x8f, 0xf8, 0x28, + 0xad, 0xfa, 0xf0, 0xbb, 0x22, 0xfb, 0x3b, 0xdf, 0x2a, 0x78, 0x2f, 0x2d, 0x24, 0xb5, 0x97, 0xea, + 0xee, 0x2a, 0x56, 0xc9, 0x55, 0x15, 0x5c, 0xbb, 0x70, 0x27, 0x93, 0xcb, 0x15, 0x2f, 0xc6, 0xa7, + 0x95, 0x80, 0xfc, 0x54, 0xc0, 0x56, 0x66, 0x1f, 0x21, 0x4a, 0xcb, 0x5e, 0x52, 0x6f, 0xb5, 0xba, + 0xfa, 0x0b, 0x12, 0xf9, 0x81, 0x40, 0xae, 0xc3, 0x6a, 0x26, 0x72, 0xc6, 0x97, 0x00, 0x7f, 0x28, + 0x60, 0x33, 0xa3, 0x9c, 0xb0, 0x92, 0xc6, 0x91, 0x59, 0x73, 0xd5, 0x58, 0xd5, 0x2e, 0xa1, 0xf7, + 0x05, 0x34, 0x82, 0x95, 0x4c, 0xe8, 0xb4, 0x4f, 0x02, 0x0e, 0xc0, 0xa5, 0x49, 0x79, 0xa1, 0x96, + 0x16, 0x39, 0x2d, 0xba, 0x5a, 0xcc, 0xd4, 0x25, 0xc3, 0xb6, 0x60, 0xd0, 0x60, 0x21, 0x93, 0x01, + 0xb3, 0xa8, 0xf9, 0xe2, 0x68, 0xa4, 0x29, 0xc7, 0x23, 0x4d, 0xf9, 0x3b, 0xd2, 0x94, 0xaf, 0x63, + 0x2d, 0x77, 0x3c, 0xd6, 0x72, 0xbf, 0xc7, 0x5a, 0xee, 0xf5, 0xfe, 0xcc, 0xd5, 0xc1, 0x88, 0x6d, + 0x47, 0x6f, 0x87, 0x33, 0x93, 0x86, 0xf7, 0xd1, 0xfb, 0xd9, 0x71, 0xe2, 0x2a, 0x41, 0xc3, 0xda, + 0xe1, 0x9a, 0xb8, 0xad, 0xf7, 0xfe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x44, 0x7c, 0x6e, 0x3b, 0x49, + 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/cellarfees/types/query.pb.gw.go b/x/cellarfees/types/v1/query.pb.gw.go similarity index 99% rename from x/cellarfees/types/query.pb.gw.go rename to x/cellarfees/types/v1/query.pb.gw.go index 009be4f05..216b37ab8 100644 --- a/x/cellarfees/types/query.pb.gw.go +++ b/x/cellarfees/types/v1/query.pb.gw.go @@ -2,11 +2,11 @@ // source: cellarfees/v1/query.proto /* -Package types is a reverse proxy. +Package v1 is a reverse proxy. It translates gRPC into RESTful JSON APIs. */ -package types +package v1 import ( "context" diff --git a/x/cellarfees/types/v2/cellarfees.go b/x/cellarfees/types/v2/cellarfees.go new file mode 100644 index 000000000..5ec3cc8e8 --- /dev/null +++ b/x/cellarfees/types/v2/cellarfees.go @@ -0,0 +1 @@ +package v2 diff --git a/x/cellarfees/types/v2/cellarfees.pb.go b/x/cellarfees/types/v2/cellarfees.pb.go new file mode 100644 index 000000000..ad963b099 --- /dev/null +++ b/x/cellarfees/types/v2/cellarfees.pb.go @@ -0,0 +1,374 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cellarfees/v2/cellarfees.proto + +package v2 + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type FeeTokenBalance struct { + Balance types.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance"` + UsdValue github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=usd_value,json=usdValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"usd_value"` +} + +func (m *FeeTokenBalance) Reset() { *m = FeeTokenBalance{} } +func (m *FeeTokenBalance) String() string { return proto.CompactTextString(m) } +func (*FeeTokenBalance) ProtoMessage() {} +func (*FeeTokenBalance) Descriptor() ([]byte, []int) { + return fileDescriptor_f9a743a746b9d1be, []int{0} +} +func (m *FeeTokenBalance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FeeTokenBalance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FeeTokenBalance.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *FeeTokenBalance) XXX_Merge(src proto.Message) { + xxx_messageInfo_FeeTokenBalance.Merge(m, src) +} +func (m *FeeTokenBalance) XXX_Size() int { + return m.Size() +} +func (m *FeeTokenBalance) XXX_DiscardUnknown() { + xxx_messageInfo_FeeTokenBalance.DiscardUnknown(m) +} + +var xxx_messageInfo_FeeTokenBalance proto.InternalMessageInfo + +func (m *FeeTokenBalance) GetBalance() types.Coin { + if m != nil { + return m.Balance + } + return types.Coin{} +} + +func init() { + proto.RegisterType((*FeeTokenBalance)(nil), "cellarfees.v2.FeeTokenBalance") +} + +func init() { proto.RegisterFile("cellarfees/v2/cellarfees.proto", fileDescriptor_f9a743a746b9d1be) } + +var fileDescriptor_f9a743a746b9d1be = []byte{ + // 282 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0xc3, 0x40, + 0x10, 0x86, 0xb3, 0x22, 0x6a, 0x23, 0x22, 0x14, 0x0f, 0xb5, 0x87, 0x6d, 0xf1, 0x20, 0xbd, 0xb8, + 0x43, 0x23, 0x22, 0x5e, 0xa3, 0x78, 0xf1, 0x20, 0x14, 0xf1, 0xe0, 0x45, 0x36, 0xdb, 0x31, 0xc6, + 0x26, 0x99, 0x90, 0x4d, 0x16, 0xfb, 0x16, 0x5e, 0x7d, 0xa3, 0x1e, 0x7b, 0x14, 0x0f, 0x45, 0x92, + 0x17, 0x91, 0x74, 0x2b, 0xe6, 0x34, 0xff, 0xfc, 0xfc, 0xf3, 0x31, 0x33, 0x2e, 0x57, 0x18, 0xc7, + 0x32, 0x7f, 0x41, 0xd4, 0x60, 0x3c, 0xf8, 0xef, 0x44, 0x96, 0x53, 0x41, 0xdd, 0x83, 0x96, 0x63, + 0xbc, 0x3e, 0x57, 0xa4, 0x13, 0xd2, 0x10, 0x48, 0x8d, 0x60, 0xc6, 0x01, 0x16, 0x72, 0x0c, 0x8a, + 0xa2, 0xd4, 0xc6, 0xfb, 0x47, 0x21, 0x85, 0xb4, 0x96, 0xd0, 0x28, 0xeb, 0x9e, 0x7c, 0x32, 0xf7, + 0xf0, 0x16, 0xf1, 0x81, 0x66, 0x98, 0xfa, 0x32, 0x96, 0xa9, 0xc2, 0xee, 0x95, 0xbb, 0x1b, 0x58, + 0xd9, 0x63, 0x43, 0x36, 0xda, 0xf7, 0x8e, 0x85, 0x65, 0x8b, 0x86, 0x2d, 0x36, 0x6c, 0x71, 0x4d, + 0x51, 0xea, 0x6f, 0x2f, 0x56, 0x03, 0x67, 0xf2, 0x97, 0xef, 0xde, 0xb9, 0x9d, 0x52, 0x4f, 0x9f, + 0x8d, 0x8c, 0x4b, 0xec, 0x6d, 0x0d, 0xd9, 0xa8, 0xe3, 0x8b, 0x26, 0xf1, 0xbd, 0x1a, 0x9c, 0x86, + 0x51, 0xf1, 0x5a, 0x06, 0x42, 0x51, 0x02, 0x9b, 0x55, 0x6d, 0x39, 0xd3, 0xd3, 0x19, 0x14, 0xf3, + 0x0c, 0xb5, 0xb8, 0x41, 0x35, 0xd9, 0x2b, 0xf5, 0xf4, 0xb1, 0x99, 0xf7, 0xef, 0x17, 0x15, 0x67, + 0xcb, 0x8a, 0xb3, 0x9f, 0x8a, 0xb3, 0x8f, 0x9a, 0x3b, 0xcb, 0x9a, 0x3b, 0x5f, 0x35, 0x77, 0x9e, + 0x2e, 0x5a, 0xac, 0x0c, 0xc3, 0x70, 0xfe, 0x66, 0x40, 0x53, 0x92, 0x60, 0x1c, 0x61, 0x0e, 0xe6, + 0x12, 0xde, 0x5b, 0xef, 0xb2, 0x6c, 0x30, 0x5e, 0xb0, 0xb3, 0xbe, 0xf9, 0xfc, 0x37, 0x00, 0x00, + 0xff, 0xff, 0xa8, 0x77, 0x94, 0xa9, 0x5a, 0x01, 0x00, 0x00, +} + +func (m *FeeTokenBalance) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *FeeTokenBalance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FeeTokenBalance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.UsdValue.Size() + i -= size + if _, err := m.UsdValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCellarfees(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCellarfees(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintCellarfees(dAtA []byte, offset int, v uint64) int { + offset -= sovCellarfees(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *FeeTokenBalance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Balance.Size() + n += 1 + l + sovCellarfees(uint64(l)) + l = m.UsdValue.Size() + n += 1 + l + sovCellarfees(uint64(l)) + return n +} + +func sovCellarfees(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCellarfees(x uint64) (n int) { + return sovCellarfees(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *FeeTokenBalance) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCellarfees + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: FeeTokenBalance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FeeTokenBalance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCellarfees + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCellarfees + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCellarfees + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UsdValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCellarfees + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCellarfees + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCellarfees + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.UsdValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCellarfees(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCellarfees + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCellarfees(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCellarfees + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCellarfees + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCellarfees + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCellarfees + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCellarfees + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCellarfees + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCellarfees = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCellarfees = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCellarfees = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cellarfees/types/v2/cellarfees_test.go b/x/cellarfees/types/v2/cellarfees_test.go new file mode 100644 index 000000000..5ec3cc8e8 --- /dev/null +++ b/x/cellarfees/types/v2/cellarfees_test.go @@ -0,0 +1 @@ +package v2 diff --git a/x/cellarfees/types/codec.go b/x/cellarfees/types/v2/codec.go similarity index 96% rename from x/cellarfees/types/codec.go rename to x/cellarfees/types/v2/codec.go index 5454a5be6..dca3695e2 100644 --- a/x/cellarfees/types/codec.go +++ b/x/cellarfees/types/v2/codec.go @@ -1,4 +1,4 @@ -package types +package v2 import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/cellarfees/types/v2/genesis.go b/x/cellarfees/types/v2/genesis.go new file mode 100644 index 000000000..67b93be09 --- /dev/null +++ b/x/cellarfees/types/v2/genesis.go @@ -0,0 +1,29 @@ +package v2 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/peggyjv/sommelier/v7/x/cellarfees/types" +) + +const DefaultParamspace = types.ModuleName + +// DefaultGenesisState get raw genesis raw message for testing +func DefaultGenesisState() GenesisState { + return GenesisState{ + Params: DefaultParams(), + LastRewardSupplyPeak: sdk.ZeroInt(), + } +} + +// Validate performs a basic stateless validation of the genesis fields. +func (gs GenesisState) Validate() error { + if err := gs.Params.ValidateBasic(); err != nil { + return err + } + + if gs.LastRewardSupplyPeak.LT(sdk.ZeroInt()) { + return types.ErrInvalidLastRewardSupplyPeak.Wrap("last reward supply peak cannot be less than zero!") + } + + return nil +} diff --git a/x/cellarfees/types/v2/genesis.pb.go b/x/cellarfees/types/v2/genesis.pb.go new file mode 100644 index 000000000..09f70f160 --- /dev/null +++ b/x/cellarfees/types/v2/genesis.pb.go @@ -0,0 +1,374 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cellarfees/v2/genesis.proto + +package v2 + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the cellarfees module's genesis state. +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + LastRewardSupplyPeak github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=last_reward_supply_peak,json=lastRewardSupplyPeak,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_reward_supply_peak"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_95cfe5fde263fa24, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "cellarfees.v2.GenesisState") +} + +func init() { proto.RegisterFile("cellarfees/v2/genesis.proto", fileDescriptor_95cfe5fde263fa24) } + +var fileDescriptor_95cfe5fde263fa24 = []byte{ + // 288 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x41, 0x4b, 0xc3, 0x30, + 0x18, 0x86, 0x1b, 0x37, 0x86, 0x56, 0x05, 0x19, 0x13, 0xc7, 0x84, 0x6c, 0x78, 0x90, 0x5d, 0x4c, + 0xa0, 0x43, 0xbc, 0xef, 0x22, 0x7a, 0x71, 0x6c, 0x37, 0x2f, 0x25, 0xeb, 0x3e, 0x63, 0x6d, 0xbb, + 0x84, 0x24, 0xab, 0xf6, 0x5f, 0xf8, 0x53, 0xfc, 0x19, 0x3b, 0xee, 0x28, 0x1e, 0x86, 0xb4, 0x7f, + 0x44, 0x9a, 0x16, 0xdc, 0x4e, 0xdf, 0x07, 0xef, 0xc3, 0xf3, 0xc2, 0xeb, 0x5e, 0x06, 0x10, 0xc7, + 0x4c, 0xbd, 0x00, 0x68, 0x9a, 0x7a, 0x94, 0xc3, 0x12, 0x74, 0xa8, 0x89, 0x54, 0xc2, 0x88, 0xf6, + 0xe9, 0x7f, 0x48, 0x52, 0xaf, 0xd7, 0xe1, 0x82, 0x0b, 0x9b, 0xd0, 0xf2, 0xab, 0xa0, 0x5e, 0x6f, + 0xdf, 0x20, 0x99, 0x62, 0x49, 0x2d, 0xb8, 0xfa, 0x42, 0xee, 0xc9, 0x7d, 0xa5, 0x9c, 0x19, 0x66, + 0xa0, 0x3d, 0x72, 0x5b, 0x15, 0xd0, 0x45, 0x03, 0x34, 0x3c, 0xf6, 0xce, 0xc9, 0x5e, 0x05, 0x99, + 0xd8, 0x70, 0xdc, 0x5c, 0x6f, 0xfb, 0xce, 0xb4, 0x46, 0xdb, 0xe0, 0x5e, 0xc4, 0x4c, 0x1b, 0x5f, + 0xc1, 0x3b, 0x53, 0x0b, 0x5f, 0xaf, 0xa4, 0x8c, 0x33, 0x5f, 0x02, 0x8b, 0xba, 0x8d, 0x01, 0x1a, + 0x1e, 0x8d, 0x49, 0x89, 0xff, 0x6c, 0xfb, 0xd7, 0x3c, 0x34, 0xaf, 0xab, 0x39, 0x09, 0x44, 0x42, + 0x03, 0xa1, 0x13, 0xa1, 0xeb, 0x73, 0xa3, 0x17, 0x11, 0x35, 0x99, 0x04, 0x4d, 0x1e, 0x96, 0x66, + 0xda, 0x29, 0x75, 0x53, 0x6b, 0x9b, 0x59, 0xd9, 0x04, 0x58, 0xf4, 0xd8, 0x3c, 0x3c, 0x38, 0x6b, + 0x8c, 0x9f, 0xd6, 0x39, 0x46, 0x9b, 0x1c, 0xa3, 0xdf, 0x1c, 0xa3, 0xcf, 0x02, 0x3b, 0x9b, 0x02, + 0x3b, 0xdf, 0x05, 0x76, 0x9e, 0x6f, 0x77, 0xec, 0x12, 0x38, 0xcf, 0xde, 0x52, 0xaa, 0x45, 0x92, + 0x40, 0x1c, 0x82, 0xa2, 0xe9, 0x1d, 0xfd, 0xa0, 0x3b, 0x53, 0xd8, 0x36, 0x9a, 0x7a, 0xf3, 0x96, + 0x9d, 0x62, 0xf4, 0x17, 0x00, 0x00, 0xff, 0xff, 0x01, 0x6d, 0xf0, 0xe5, 0x6a, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.LastRewardSupplyPeak.Size() + i -= size + if _, err := m.LastRewardSupplyPeak.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + l = m.LastRewardSupplyPeak.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastRewardSupplyPeak", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LastRewardSupplyPeak.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cellarfees/types/params.go b/x/cellarfees/types/v2/params.go similarity index 66% rename from x/cellarfees/types/params.go rename to x/cellarfees/types/v2/params.go index 0d81222a0..72685be62 100644 --- a/x/cellarfees/types/params.go +++ b/x/cellarfees/types/v2/params.go @@ -1,14 +1,14 @@ -package types +package v2 import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/peggyjv/sommelier/v7/x/cellarfees/types" "gopkg.in/yaml.v2" ) const ( - DefaultFeeAccrualAuctionThreshold uint64 = 2 // Rough number of blocks in 28 days, the time it takes to unbond DefaultRewardEmissionPeriod uint64 = 403200 // Initial rate at which an auction should decrease the price of the relevant coin from it's starting price. @@ -23,7 +23,6 @@ const ( // Parameter keys var ( - KeyFeeAccrualAuctionThreshold = []byte("FeeAccrualAuctionThreshold") KeyRewardEmissionPeriod = []byte("RewardEmissionPeriod") KeyInitialPriceDecreaseRate = []byte("InitialPriceDecreaseRate") KeyPriceDecreaseBlockInterval = []byte("PriceDecreaseBlockInterval") @@ -40,7 +39,6 @@ func ParamKeyTable() paramtypes.KeyTable { // DefaultParams returns default cellarfees parameters func DefaultParams() Params { return Params{ - FeeAccrualAuctionThreshold: DefaultFeeAccrualAuctionThreshold, RewardEmissionPeriod: DefaultRewardEmissionPeriod, InitialPriceDecreaseRate: sdk.MustNewDecFromStr(DefaultInitialPriceDecreaseRate), PriceDecreaseBlockInterval: DefaultPriceDecreaseBlockInterval, @@ -51,7 +49,6 @@ func DefaultParams() Params { // ParamSetPairs returns the parameter set pairs. func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyFeeAccrualAuctionThreshold, &p.FeeAccrualAuctionThreshold, validateFeeAccrualAuctionThreshold), paramtypes.NewParamSetPair(KeyRewardEmissionPeriod, &p.RewardEmissionPeriod, validateRewardEmissionPeriod), paramtypes.NewParamSetPair(KeyInitialPriceDecreaseRate, &p.InitialPriceDecreaseRate, validateInitialPriceDecreaseRate), paramtypes.NewParamSetPair(KeyPriceDecreaseBlockInterval, &p.PriceDecreaseBlockInterval, validatePriceDecreaseBlockInterval), @@ -61,9 +58,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { // ValidateBasic performs basic validation on cellarfees parameters. func (p *Params) ValidateBasic() error { - if err := validateFeeAccrualAuctionThreshold(p.FeeAccrualAuctionThreshold); err != nil { - return err - } if err := validateRewardEmissionPeriod(p.RewardEmissionPeriod); err != nil { return err } @@ -76,27 +70,14 @@ func (p *Params) ValidateBasic() error { return nil } -func validateFeeAccrualAuctionThreshold(i interface{}) error { - threshold, ok := i.(uint64) - if !ok { - return errorsmod.Wrapf(ErrInvalidFeeAccrualAuctionThreshold, "fee accrual auction threshold: %T", i) - } - - if threshold == 0 { - return errorsmod.Wrapf(ErrInvalidFeeAccrualAuctionThreshold, "fee accrual auction threshold cannot be zero") - } - - return nil -} - func validateRewardEmissionPeriod(i interface{}) error { emissionPeriod, ok := i.(uint64) if !ok { - return errorsmod.Wrapf(ErrInvalidRewardEmissionPeriod, "reward emission period: %T", i) + return errorsmod.Wrapf(types.ErrInvalidRewardEmissionPeriod, "reward emission period: %T", i) } if emissionPeriod == 0 { - return errorsmod.Wrapf(ErrInvalidRewardEmissionPeriod, "reward emission period cannot be zero") + return errorsmod.Wrapf(types.ErrInvalidRewardEmissionPeriod, "reward emission period cannot be zero") } return nil @@ -105,15 +86,15 @@ func validateRewardEmissionPeriod(i interface{}) error { func validateInitialPriceDecreaseRate(i interface{}) error { rate, ok := i.(sdk.Dec) if !ok { - return errorsmod.Wrapf(ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate: %T", i) + return errorsmod.Wrapf(types.ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate: %T", i) } if rate == sdk.ZeroDec() { - return errorsmod.Wrapf(ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate cannot be zero, must be 0 < x < 1") + return errorsmod.Wrapf(types.ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate cannot be zero, must be 0 < x < 1") } if rate == sdk.OneDec() { - return errorsmod.Wrapf(ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate cannot be one, must be 0 < x < 1") + return errorsmod.Wrapf(types.ErrInvalidInitialPriceDecreaseRate, "initial price decrease rate cannot be one, must be 0 < x < 1") } return nil @@ -122,11 +103,11 @@ func validateInitialPriceDecreaseRate(i interface{}) error { func validatePriceDecreaseBlockInterval(i interface{}) error { interval, ok := i.(uint64) if !ok { - return errorsmod.Wrapf(ErrInvalidPriceDecreaseBlockInterval, "price decrease block interval: %T", i) + return errorsmod.Wrapf(types.ErrInvalidPriceDecreaseBlockInterval, "price decrease block interval: %T", i) } if interval == 0 { - return errorsmod.Wrapf(ErrInvalidPriceDecreaseBlockInterval, "price decrease block interval cannot be zero") + return errorsmod.Wrapf(types.ErrInvalidPriceDecreaseBlockInterval, "price decrease block interval cannot be zero") } return nil @@ -135,11 +116,11 @@ func validatePriceDecreaseBlockInterval(i interface{}) error { func validateAuctionInterval(i interface{}) error { interval, ok := i.(uint64) if !ok { - return errorsmod.Wrapf(ErrInvalidAuctionInterval, "auction interval: %T", i) + return errorsmod.Wrapf(types.ErrInvalidAuctionInterval, "auction interval: %T", i) } if interval == 0 { - return errorsmod.Wrapf(ErrInvalidAuctionInterval, "auction interval cannot be zero") + return errorsmod.Wrapf(types.ErrInvalidAuctionInterval, "auction interval cannot be zero") } return nil diff --git a/x/cellarfees/types/v2/params.pb.go b/x/cellarfees/types/v2/params.pb.go new file mode 100644 index 000000000..ae6a75111 --- /dev/null +++ b/x/cellarfees/types/v2/params.pb.go @@ -0,0 +1,484 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cellarfees/v2/params.proto + +package v2 + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the module. +type Params struct { + // Emission rate factor. Specifically, the number of blocks over which to distribute + // some amount of staking rewards. + RewardEmissionPeriod uint64 `protobuf:"varint,2,opt,name=reward_emission_period,json=rewardEmissionPeriod,proto3" json:"reward_emission_period,omitempty"` + // The initial rate at which auctions should decrease their denom's price in SOMM + InitialPriceDecreaseRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=initial_price_decrease_rate,json=initialPriceDecreaseRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"initial_price_decrease_rate"` + // Number of blocks between auction price decreases + PriceDecreaseBlockInterval uint64 `protobuf:"varint,4,opt,name=price_decrease_block_interval,json=priceDecreaseBlockInterval,proto3" json:"price_decrease_block_interval,omitempty"` + // The interval between starting auctions + AuctionInterval uint64 `protobuf:"varint,5,opt,name=auction_interval,json=auctionInterval,proto3" json:"auction_interval,omitempty"` + // A fee token's total USD value threshold, based on it's auction.v1.TokenPrice, above which an auction is triggered + AuctionThresholdUsdValue github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,6,opt,name=auction_threshold_usd_value,json=auctionThresholdUsdValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"auction_threshold_usd_value"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_270f377f75209ba6, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetRewardEmissionPeriod() uint64 { + if m != nil { + return m.RewardEmissionPeriod + } + return 0 +} + +func (m *Params) GetPriceDecreaseBlockInterval() uint64 { + if m != nil { + return m.PriceDecreaseBlockInterval + } + return 0 +} + +func (m *Params) GetAuctionInterval() uint64 { + if m != nil { + return m.AuctionInterval + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "cellarfees.v2.Params") +} + +func init() { proto.RegisterFile("cellarfees/v2/params.proto", fileDescriptor_270f377f75209ba6) } + +var fileDescriptor_270f377f75209ba6 = []byte{ + // 381 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x6b, 0xdb, 0x30, + 0x1c, 0xc5, 0xed, 0xc4, 0x0b, 0x9b, 0x61, 0x2c, 0x98, 0x30, 0x4c, 0xc2, 0x9c, 0xb0, 0xc3, 0xc8, + 0x0e, 0xb3, 0x20, 0xdb, 0x18, 0xec, 0xb6, 0x90, 0x1d, 0xb6, 0x4b, 0x43, 0x68, 0x7b, 0xe8, 0x45, + 0x28, 0xf2, 0xbf, 0x8e, 0x1a, 0x29, 0x32, 0x92, 0xec, 0x36, 0xdf, 0xa2, 0xa7, 0xd2, 0x63, 0x3f, + 0x4e, 0x8e, 0x39, 0x96, 0x1e, 0x42, 0x49, 0xbe, 0x48, 0xb1, 0xe3, 0xa4, 0xa1, 0xc7, 0x9e, 0x24, + 0xf4, 0xde, 0xfb, 0x3d, 0xfd, 0x91, 0xdc, 0x26, 0x05, 0xce, 0x89, 0x3a, 0x07, 0xd0, 0x28, 0xeb, + 0xa1, 0x84, 0x28, 0x22, 0x74, 0x98, 0x28, 0x69, 0xa4, 0xf7, 0xfe, 0x59, 0x0b, 0xb3, 0x5e, 0xb3, + 0x11, 0xcb, 0x58, 0x16, 0x0a, 0xca, 0x77, 0x5b, 0xd3, 0xe7, 0x9b, 0xaa, 0x5b, 0x1b, 0x16, 0x29, + 0xef, 0x87, 0xfb, 0x51, 0xc1, 0x25, 0x51, 0x11, 0x06, 0xc1, 0xb4, 0x66, 0x72, 0x86, 0x13, 0x50, + 0x4c, 0x46, 0x7e, 0xa5, 0x63, 0x77, 0x9d, 0x51, 0x63, 0xab, 0xfe, 0x2d, 0xc5, 0x61, 0xa1, 0x79, + 0xc2, 0x6d, 0xb1, 0x19, 0x33, 0x8c, 0x70, 0x9c, 0x28, 0x46, 0x01, 0x47, 0x40, 0x15, 0x10, 0x0d, + 0x58, 0x11, 0x03, 0x7e, 0xb5, 0x63, 0x77, 0xdf, 0xf5, 0xc3, 0xc5, 0xaa, 0x6d, 0x3d, 0xac, 0xda, + 0x5f, 0x62, 0x66, 0x26, 0xe9, 0x38, 0xa4, 0x52, 0x20, 0x2a, 0xb5, 0x90, 0xba, 0x5c, 0xbe, 0xe9, + 0x68, 0x8a, 0xcc, 0x3c, 0x01, 0x1d, 0x0e, 0x80, 0x8e, 0xfc, 0x12, 0x39, 0xcc, 0x89, 0x83, 0x12, + 0x38, 0x22, 0x06, 0xbc, 0x3f, 0xee, 0xa7, 0x17, 0x35, 0x63, 0x2e, 0xe9, 0x14, 0xb3, 0x99, 0x01, + 0x95, 0x11, 0xee, 0x3b, 0xc5, 0x5d, 0x9b, 0xc9, 0x61, 0xb2, 0x9f, 0x5b, 0xfe, 0x95, 0x0e, 0xef, + 0xab, 0x5b, 0x27, 0x29, 0x35, 0xf9, 0x7c, 0xfb, 0xd4, 0x9b, 0x22, 0xf5, 0xa1, 0x3c, 0xdf, 0x5b, + 0x85, 0xdb, 0xda, 0x59, 0xcd, 0x44, 0x81, 0x9e, 0x48, 0x1e, 0xe1, 0x54, 0x47, 0x38, 0x23, 0x3c, + 0x05, 0xbf, 0xf6, 0xba, 0xe1, 0x4a, 0xe4, 0xf1, 0x8e, 0x78, 0xa2, 0xa3, 0xd3, 0x9c, 0xf7, 0xdb, + 0xb9, 0xbd, 0x6b, 0x5b, 0xff, 0x9d, 0xb7, 0x76, 0xbd, 0xd2, 0x3f, 0x5a, 0xac, 0x03, 0x7b, 0xb9, + 0x0e, 0xec, 0xc7, 0x75, 0x60, 0x5f, 0x6f, 0x02, 0x6b, 0xb9, 0x09, 0xac, 0xfb, 0x4d, 0x60, 0x9d, + 0xfd, 0x3c, 0xe8, 0x49, 0x20, 0x8e, 0xe7, 0x17, 0x19, 0xd2, 0x52, 0x08, 0xe0, 0x0c, 0x14, 0xca, + 0x7e, 0xa1, 0x2b, 0x74, 0xf0, 0x2b, 0x8a, 0x5e, 0x94, 0xf5, 0xc6, 0xb5, 0xe2, 0xc1, 0xbf, 0x3f, + 0x05, 0x00, 0x00, 0xff, 0xff, 0x87, 0x16, 0xc6, 0xed, 0x33, 0x02, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.AuctionThresholdUsdValue.Size() + i -= size + if _, err := m.AuctionThresholdUsdValue.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + if m.AuctionInterval != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.AuctionInterval)) + i-- + dAtA[i] = 0x28 + } + if m.PriceDecreaseBlockInterval != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.PriceDecreaseBlockInterval)) + i-- + dAtA[i] = 0x20 + } + { + size := m.InitialPriceDecreaseRate.Size() + i -= size + if _, err := m.InitialPriceDecreaseRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.RewardEmissionPeriod != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.RewardEmissionPeriod)) + i-- + dAtA[i] = 0x10 + } + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.RewardEmissionPeriod != 0 { + n += 1 + sovParams(uint64(m.RewardEmissionPeriod)) + } + l = m.InitialPriceDecreaseRate.Size() + n += 1 + l + sovParams(uint64(l)) + if m.PriceDecreaseBlockInterval != 0 { + n += 1 + sovParams(uint64(m.PriceDecreaseBlockInterval)) + } + if m.AuctionInterval != 0 { + n += 1 + sovParams(uint64(m.AuctionInterval)) + } + l = m.AuctionThresholdUsdValue.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardEmissionPeriod", wireType) + } + m.RewardEmissionPeriod = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RewardEmissionPeriod |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitialPriceDecreaseRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InitialPriceDecreaseRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceDecreaseBlockInterval", wireType) + } + m.PriceDecreaseBlockInterval = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PriceDecreaseBlockInterval |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionInterval", wireType) + } + m.AuctionInterval = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AuctionInterval |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AuctionThresholdUsdValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.AuctionThresholdUsdValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cellarfees/types/v2/query.pb.go b/x/cellarfees/types/v2/query.pb.go new file mode 100644 index 000000000..588c30566 --- /dev/null +++ b/x/cellarfees/types/v2/query.pb.go @@ -0,0 +1,2249 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cellarfees/v2/query.proto + +package v2 + +import ( + context "context" + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +type QueryParamsResponse struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +type QueryModuleAccountsRequest struct { +} + +func (m *QueryModuleAccountsRequest) Reset() { *m = QueryModuleAccountsRequest{} } +func (m *QueryModuleAccountsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountsRequest) ProtoMessage() {} +func (*QueryModuleAccountsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{2} +} +func (m *QueryModuleAccountsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryModuleAccountsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountsRequest.Merge(m, src) +} +func (m *QueryModuleAccountsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountsRequest proto.InternalMessageInfo + +type QueryModuleAccountsResponse struct { + FeesAddress string `protobuf:"bytes,1,opt,name=fees_address,json=feesAddress,proto3" json:"fees_address,omitempty"` +} + +func (m *QueryModuleAccountsResponse) Reset() { *m = QueryModuleAccountsResponse{} } +func (m *QueryModuleAccountsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryModuleAccountsResponse) ProtoMessage() {} +func (*QueryModuleAccountsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{3} +} +func (m *QueryModuleAccountsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryModuleAccountsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryModuleAccountsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryModuleAccountsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryModuleAccountsResponse.Merge(m, src) +} +func (m *QueryModuleAccountsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryModuleAccountsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryModuleAccountsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryModuleAccountsResponse proto.InternalMessageInfo + +func (m *QueryModuleAccountsResponse) GetFeesAddress() string { + if m != nil { + return m.FeesAddress + } + return "" +} + +type QueryLastRewardSupplyPeakRequest struct { +} + +func (m *QueryLastRewardSupplyPeakRequest) Reset() { *m = QueryLastRewardSupplyPeakRequest{} } +func (m *QueryLastRewardSupplyPeakRequest) String() string { return proto.CompactTextString(m) } +func (*QueryLastRewardSupplyPeakRequest) ProtoMessage() {} +func (*QueryLastRewardSupplyPeakRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{4} +} +func (m *QueryLastRewardSupplyPeakRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryLastRewardSupplyPeakRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryLastRewardSupplyPeakRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryLastRewardSupplyPeakRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryLastRewardSupplyPeakRequest.Merge(m, src) +} +func (m *QueryLastRewardSupplyPeakRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryLastRewardSupplyPeakRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryLastRewardSupplyPeakRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryLastRewardSupplyPeakRequest proto.InternalMessageInfo + +type QueryLastRewardSupplyPeakResponse struct { + LastRewardSupplyPeak github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=last_reward_supply_peak,json=lastRewardSupplyPeak,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_reward_supply_peak"` +} + +func (m *QueryLastRewardSupplyPeakResponse) Reset() { *m = QueryLastRewardSupplyPeakResponse{} } +func (m *QueryLastRewardSupplyPeakResponse) String() string { return proto.CompactTextString(m) } +func (*QueryLastRewardSupplyPeakResponse) ProtoMessage() {} +func (*QueryLastRewardSupplyPeakResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{5} +} +func (m *QueryLastRewardSupplyPeakResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryLastRewardSupplyPeakResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryLastRewardSupplyPeakResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryLastRewardSupplyPeakResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryLastRewardSupplyPeakResponse.Merge(m, src) +} +func (m *QueryLastRewardSupplyPeakResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryLastRewardSupplyPeakResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryLastRewardSupplyPeakResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryLastRewardSupplyPeakResponse proto.InternalMessageInfo + +type QueryAPYRequest struct { +} + +func (m *QueryAPYRequest) Reset() { *m = QueryAPYRequest{} } +func (m *QueryAPYRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAPYRequest) ProtoMessage() {} +func (*QueryAPYRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{6} +} +func (m *QueryAPYRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAPYRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAPYRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAPYRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAPYRequest.Merge(m, src) +} +func (m *QueryAPYRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAPYRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAPYRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAPYRequest proto.InternalMessageInfo + +type QueryAPYResponse struct { + Apy string `protobuf:"bytes,1,opt,name=apy,proto3" json:"apy,omitempty"` +} + +func (m *QueryAPYResponse) Reset() { *m = QueryAPYResponse{} } +func (m *QueryAPYResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAPYResponse) ProtoMessage() {} +func (*QueryAPYResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{7} +} +func (m *QueryAPYResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAPYResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAPYResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAPYResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAPYResponse.Merge(m, src) +} +func (m *QueryAPYResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAPYResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAPYResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAPYResponse proto.InternalMessageInfo + +func (m *QueryAPYResponse) GetApy() string { + if m != nil { + return m.Apy + } + return "" +} + +type QueryFeeTokenBalancesRequest struct { +} + +func (m *QueryFeeTokenBalancesRequest) Reset() { *m = QueryFeeTokenBalancesRequest{} } +func (m *QueryFeeTokenBalancesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryFeeTokenBalancesRequest) ProtoMessage() {} +func (*QueryFeeTokenBalancesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{8} +} +func (m *QueryFeeTokenBalancesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFeeTokenBalancesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFeeTokenBalancesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryFeeTokenBalancesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFeeTokenBalancesRequest.Merge(m, src) +} +func (m *QueryFeeTokenBalancesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryFeeTokenBalancesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFeeTokenBalancesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFeeTokenBalancesRequest proto.InternalMessageInfo + +type QueryFeeTokenBalancesResponse struct { + Balances []*FeeTokenBalance `protobuf:"bytes,1,rep,name=balances,proto3" json:"balances,omitempty"` +} + +func (m *QueryFeeTokenBalancesResponse) Reset() { *m = QueryFeeTokenBalancesResponse{} } +func (m *QueryFeeTokenBalancesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryFeeTokenBalancesResponse) ProtoMessage() {} +func (*QueryFeeTokenBalancesResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{9} +} +func (m *QueryFeeTokenBalancesResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFeeTokenBalancesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFeeTokenBalancesResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryFeeTokenBalancesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFeeTokenBalancesResponse.Merge(m, src) +} +func (m *QueryFeeTokenBalancesResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryFeeTokenBalancesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFeeTokenBalancesResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFeeTokenBalancesResponse proto.InternalMessageInfo + +func (m *QueryFeeTokenBalancesResponse) GetBalances() []*FeeTokenBalance { + if m != nil { + return m.Balances + } + return nil +} + +type QueryFeeTokenBalanceRequest struct { + Denom string `protobuf:"bytes,1,opt,name=denom,proto3" json:"denom,omitempty"` +} + +func (m *QueryFeeTokenBalanceRequest) Reset() { *m = QueryFeeTokenBalanceRequest{} } +func (m *QueryFeeTokenBalanceRequest) String() string { return proto.CompactTextString(m) } +func (*QueryFeeTokenBalanceRequest) ProtoMessage() {} +func (*QueryFeeTokenBalanceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{10} +} +func (m *QueryFeeTokenBalanceRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFeeTokenBalanceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFeeTokenBalanceRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryFeeTokenBalanceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFeeTokenBalanceRequest.Merge(m, src) +} +func (m *QueryFeeTokenBalanceRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryFeeTokenBalanceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFeeTokenBalanceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFeeTokenBalanceRequest proto.InternalMessageInfo + +func (m *QueryFeeTokenBalanceRequest) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +type QueryFeeTokenBalanceResponse struct { + Balance *FeeTokenBalance `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"` +} + +func (m *QueryFeeTokenBalanceResponse) Reset() { *m = QueryFeeTokenBalanceResponse{} } +func (m *QueryFeeTokenBalanceResponse) String() string { return proto.CompactTextString(m) } +func (*QueryFeeTokenBalanceResponse) ProtoMessage() {} +func (*QueryFeeTokenBalanceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_43b5cfd9b5e06b70, []int{11} +} +func (m *QueryFeeTokenBalanceResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryFeeTokenBalanceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryFeeTokenBalanceResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryFeeTokenBalanceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryFeeTokenBalanceResponse.Merge(m, src) +} +func (m *QueryFeeTokenBalanceResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryFeeTokenBalanceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryFeeTokenBalanceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryFeeTokenBalanceResponse proto.InternalMessageInfo + +func (m *QueryFeeTokenBalanceResponse) GetBalance() *FeeTokenBalance { + if m != nil { + return m.Balance + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "cellarfees.v2.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "cellarfees.v2.QueryParamsResponse") + proto.RegisterType((*QueryModuleAccountsRequest)(nil), "cellarfees.v2.QueryModuleAccountsRequest") + proto.RegisterType((*QueryModuleAccountsResponse)(nil), "cellarfees.v2.QueryModuleAccountsResponse") + proto.RegisterType((*QueryLastRewardSupplyPeakRequest)(nil), "cellarfees.v2.QueryLastRewardSupplyPeakRequest") + proto.RegisterType((*QueryLastRewardSupplyPeakResponse)(nil), "cellarfees.v2.QueryLastRewardSupplyPeakResponse") + proto.RegisterType((*QueryAPYRequest)(nil), "cellarfees.v2.QueryAPYRequest") + proto.RegisterType((*QueryAPYResponse)(nil), "cellarfees.v2.QueryAPYResponse") + proto.RegisterType((*QueryFeeTokenBalancesRequest)(nil), "cellarfees.v2.QueryFeeTokenBalancesRequest") + proto.RegisterType((*QueryFeeTokenBalancesResponse)(nil), "cellarfees.v2.QueryFeeTokenBalancesResponse") + proto.RegisterType((*QueryFeeTokenBalanceRequest)(nil), "cellarfees.v2.QueryFeeTokenBalanceRequest") + proto.RegisterType((*QueryFeeTokenBalanceResponse)(nil), "cellarfees.v2.QueryFeeTokenBalanceResponse") +} + +func init() { proto.RegisterFile("cellarfees/v2/query.proto", fileDescriptor_43b5cfd9b5e06b70) } + +var fileDescriptor_43b5cfd9b5e06b70 = []byte{ + // 700 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x95, 0xbf, 0x6f, 0xd3, 0x4e, + 0x18, 0xc6, 0xe3, 0x6f, 0xbf, 0xfd, 0xc1, 0x05, 0x44, 0x39, 0x52, 0xd1, 0x9a, 0xe0, 0x34, 0x56, + 0x05, 0xa5, 0xa5, 0xbe, 0xca, 0x51, 0x45, 0x05, 0x0b, 0xcd, 0x80, 0x04, 0x02, 0x51, 0x02, 0x03, + 0x3f, 0x06, 0xeb, 0x9a, 0xbc, 0x35, 0x21, 0xb6, 0xcf, 0xf5, 0x39, 0x81, 0x08, 0x75, 0x61, 0x64, + 0x42, 0x62, 0x67, 0x65, 0x41, 0xcc, 0xfc, 0x09, 0x1d, 0x2b, 0xb1, 0x20, 0x86, 0x0a, 0xb5, 0xfc, + 0x21, 0xc8, 0xe7, 0x73, 0x9a, 0x04, 0xbb, 0x84, 0x29, 0xce, 0xbd, 0xcf, 0xfb, 0x3e, 0x1f, 0xc7, + 0xef, 0xe3, 0xa0, 0xb9, 0x3a, 0x38, 0x0e, 0x0d, 0xb6, 0x01, 0x38, 0xe9, 0x98, 0x64, 0xa7, 0x0d, + 0x41, 0xd7, 0xf0, 0x03, 0x16, 0x32, 0x7c, 0xe6, 0xb8, 0x64, 0x74, 0x4c, 0xb5, 0x60, 0x33, 0x9b, + 0x89, 0x0a, 0x89, 0xae, 0x62, 0x91, 0x5a, 0xb4, 0x19, 0xb3, 0x1d, 0x20, 0xd4, 0x6f, 0x12, 0xea, + 0x79, 0x2c, 0xa4, 0x61, 0x93, 0x79, 0x5c, 0x56, 0xd5, 0xc1, 0xe9, 0x3e, 0x0d, 0xa8, 0x9b, 0xd4, + 0xb4, 0xc1, 0x5a, 0x9f, 0x99, 0xa8, 0xeb, 0x05, 0x84, 0x1f, 0x46, 0x34, 0x9b, 0xa2, 0xa9, 0x06, + 0x3b, 0x6d, 0xe0, 0xa1, 0x7e, 0x17, 0x9d, 0x1f, 0x38, 0xe5, 0x3e, 0xf3, 0x38, 0xe0, 0x0a, 0x9a, + 0x88, 0x87, 0xcf, 0x2a, 0xf3, 0xca, 0x62, 0xde, 0x9c, 0x31, 0x06, 0xe0, 0x8d, 0x58, 0x5e, 0xfd, + 0x7f, 0xef, 0xa0, 0x94, 0xab, 0x49, 0xa9, 0x5e, 0x44, 0xaa, 0x98, 0x75, 0x9f, 0x35, 0xda, 0x0e, + 0x6c, 0xd4, 0xeb, 0xac, 0xed, 0x85, 0x3d, 0xa7, 0x5b, 0xe8, 0x62, 0x6a, 0x55, 0x3a, 0x96, 0xd1, + 0xe9, 0x68, 0xb8, 0x45, 0x1b, 0x8d, 0x00, 0x78, 0xec, 0x7b, 0xaa, 0x96, 0x8f, 0xce, 0x36, 0xe2, + 0x23, 0x5d, 0x47, 0xf3, 0x62, 0xc2, 0x3d, 0xca, 0xc3, 0x1a, 0xbc, 0xa2, 0x41, 0xe3, 0x51, 0xdb, + 0xf7, 0x9d, 0xee, 0x26, 0xd0, 0x56, 0xe2, 0xf2, 0x4e, 0x41, 0xe5, 0x13, 0x44, 0xd2, 0x0c, 0xd0, + 0x05, 0x87, 0xf2, 0xd0, 0x0a, 0x84, 0xc0, 0xe2, 0x42, 0x61, 0xf9, 0x40, 0x5b, 0xb1, 0x6f, 0xd5, + 0x88, 0x6e, 0xec, 0xc7, 0x41, 0xe9, 0xb2, 0xdd, 0x0c, 0x5f, 0xb4, 0xb7, 0x8c, 0x3a, 0x73, 0x49, + 0x9d, 0x71, 0x97, 0x71, 0xf9, 0xb1, 0xc2, 0x1b, 0x2d, 0x12, 0x76, 0x7d, 0xe0, 0xc6, 0x1d, 0x2f, + 0xac, 0x15, 0x9c, 0x14, 0x3b, 0xfd, 0x1c, 0x3a, 0x2b, 0x58, 0x36, 0x36, 0x9f, 0x26, 0x7c, 0x0b, + 0x68, 0xfa, 0xf8, 0x48, 0xd2, 0x4c, 0xa3, 0x31, 0xea, 0x77, 0xe5, 0x1d, 0x47, 0x97, 0xba, 0x86, + 0x8a, 0x42, 0x75, 0x1b, 0xe0, 0x31, 0x6b, 0x81, 0x57, 0xa5, 0x0e, 0xf5, 0xea, 0xd0, 0xfb, 0x2d, + 0x9f, 0xa3, 0x4b, 0x19, 0x75, 0x39, 0xf2, 0x06, 0x9a, 0xda, 0x92, 0x67, 0xb3, 0xca, 0xfc, 0xd8, + 0x62, 0xde, 0xd4, 0x86, 0x9e, 0xe0, 0x50, 0x6b, 0xad, 0xa7, 0xd7, 0x2b, 0xf2, 0x41, 0x0d, 0x2b, + 0x62, 0x6f, 0x5c, 0x40, 0xe3, 0x0d, 0xf0, 0x98, 0x2b, 0x79, 0xe3, 0x2f, 0xfa, 0x93, 0x74, 0xe2, + 0x1e, 0xd0, 0x3a, 0x9a, 0x94, 0x06, 0x72, 0xa3, 0xfe, 0xc6, 0x93, 0xc8, 0xcd, 0x2f, 0x93, 0x68, + 0x5c, 0x8c, 0xc6, 0xbb, 0x28, 0xdf, 0xb7, 0xab, 0xb8, 0x3c, 0x34, 0xe1, 0xcf, 0xed, 0x56, 0xf5, + 0x93, 0x24, 0x31, 0x99, 0x7e, 0xe5, 0xed, 0xb7, 0x5f, 0x1f, 0xfe, 0x2b, 0xe3, 0x12, 0xe1, 0xcc, + 0x75, 0xc1, 0x69, 0x42, 0x40, 0xd2, 0x62, 0x86, 0x3f, 0x2a, 0x32, 0x2b, 0x83, 0x1b, 0x8c, 0xaf, + 0xa6, 0x99, 0xa4, 0x66, 0x40, 0x5d, 0x1a, 0x45, 0x2a, 0xb9, 0x56, 0x05, 0xd7, 0x12, 0x5e, 0xcc, + 0xe4, 0x72, 0x45, 0xa3, 0x45, 0x13, 0x90, 0xaf, 0x0a, 0x9a, 0xcb, 0xdc, 0x7d, 0x4c, 0xd2, 0xbc, + 0x4f, 0x88, 0x92, 0xba, 0x3a, 0x7a, 0x83, 0x44, 0x5e, 0x17, 0xc8, 0x26, 0x5e, 0xcd, 0x44, 0xce, + 0x48, 0x1d, 0xde, 0x41, 0x53, 0x49, 0x2c, 0xb0, 0x96, 0xe6, 0x7b, 0x1c, 0x21, 0xb5, 0x94, 0x59, + 0x97, 0x18, 0x0b, 0x02, 0x43, 0xc3, 0xc5, 0x4c, 0x0c, 0xea, 0x77, 0xf1, 0x27, 0x05, 0xcd, 0xa4, + 0x86, 0x08, 0x2f, 0xa7, 0x19, 0x64, 0x44, 0x51, 0xbd, 0x36, 0x9a, 0x58, 0xa2, 0x55, 0x04, 0xda, + 0x0a, 0x5e, 0xce, 0x44, 0xdb, 0x06, 0xb0, 0xc2, 0xa8, 0xd7, 0x4a, 0x02, 0x89, 0x3f, 0x2b, 0xa8, + 0x90, 0x36, 0x16, 0x2f, 0x8d, 0xe0, 0x9d, 0x70, 0x2e, 0x8f, 0xa4, 0x95, 0x98, 0x37, 0x05, 0xe6, + 0x1a, 0xae, 0xfc, 0x03, 0x26, 0x79, 0x23, 0xde, 0x04, 0xbb, 0xd5, 0x07, 0x7b, 0x87, 0x9a, 0xb2, + 0x7f, 0xa8, 0x29, 0x3f, 0x0f, 0x35, 0xe5, 0xfd, 0x91, 0x96, 0xdb, 0x3f, 0xd2, 0x72, 0xdf, 0x8f, + 0xb4, 0xdc, 0xb3, 0xb5, 0xbe, 0xb7, 0xa9, 0x0f, 0xb6, 0xdd, 0x7d, 0xd9, 0xe9, 0x33, 0xe8, 0x5c, + 0x27, 0xaf, 0xfb, 0x5d, 0xc4, 0xdb, 0x95, 0x74, 0xcc, 0xad, 0x09, 0xf1, 0x07, 0x56, 0xf9, 0x1d, + 0x00, 0x00, 0xff, 0xff, 0x21, 0x3f, 0x46, 0xc0, 0x5c, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + QueryModuleAccounts(ctx context.Context, in *QueryModuleAccountsRequest, opts ...grpc.CallOption) (*QueryModuleAccountsResponse, error) + QueryLastRewardSupplyPeak(ctx context.Context, in *QueryLastRewardSupplyPeakRequest, opts ...grpc.CallOption) (*QueryLastRewardSupplyPeakResponse, error) + QueryAPY(ctx context.Context, in *QueryAPYRequest, opts ...grpc.CallOption) (*QueryAPYResponse, error) + QueryFeeTokenBalances(ctx context.Context, in *QueryFeeTokenBalancesRequest, opts ...grpc.CallOption) (*QueryFeeTokenBalancesResponse, error) + QueryFeeTokenBalance(ctx context.Context, in *QueryFeeTokenBalanceRequest, opts ...grpc.CallOption) (*QueryFeeTokenBalanceResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryModuleAccounts(ctx context.Context, in *QueryModuleAccountsRequest, opts ...grpc.CallOption) (*QueryModuleAccountsResponse, error) { + out := new(QueryModuleAccountsResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryModuleAccounts", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryLastRewardSupplyPeak(ctx context.Context, in *QueryLastRewardSupplyPeakRequest, opts ...grpc.CallOption) (*QueryLastRewardSupplyPeakResponse, error) { + out := new(QueryLastRewardSupplyPeakResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryLastRewardSupplyPeak", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryAPY(ctx context.Context, in *QueryAPYRequest, opts ...grpc.CallOption) (*QueryAPYResponse, error) { + out := new(QueryAPYResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryAPY", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryFeeTokenBalances(ctx context.Context, in *QueryFeeTokenBalancesRequest, opts ...grpc.CallOption) (*QueryFeeTokenBalancesResponse, error) { + out := new(QueryFeeTokenBalancesResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryFeeTokenBalances", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryFeeTokenBalance(ctx context.Context, in *QueryFeeTokenBalanceRequest, opts ...grpc.CallOption) (*QueryFeeTokenBalanceResponse, error) { + out := new(QueryFeeTokenBalanceResponse) + err := c.cc.Invoke(ctx, "/cellarfees.v2.Query/QueryFeeTokenBalance", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + QueryParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + QueryModuleAccounts(context.Context, *QueryModuleAccountsRequest) (*QueryModuleAccountsResponse, error) + QueryLastRewardSupplyPeak(context.Context, *QueryLastRewardSupplyPeakRequest) (*QueryLastRewardSupplyPeakResponse, error) + QueryAPY(context.Context, *QueryAPYRequest) (*QueryAPYResponse, error) + QueryFeeTokenBalances(context.Context, *QueryFeeTokenBalancesRequest) (*QueryFeeTokenBalancesResponse, error) + QueryFeeTokenBalance(context.Context, *QueryFeeTokenBalanceRequest) (*QueryFeeTokenBalanceResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) QueryParams(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryParams not implemented") +} +func (*UnimplementedQueryServer) QueryModuleAccounts(ctx context.Context, req *QueryModuleAccountsRequest) (*QueryModuleAccountsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryModuleAccounts not implemented") +} +func (*UnimplementedQueryServer) QueryLastRewardSupplyPeak(ctx context.Context, req *QueryLastRewardSupplyPeakRequest) (*QueryLastRewardSupplyPeakResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryLastRewardSupplyPeak not implemented") +} +func (*UnimplementedQueryServer) QueryAPY(ctx context.Context, req *QueryAPYRequest) (*QueryAPYResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryAPY not implemented") +} +func (*UnimplementedQueryServer) QueryFeeTokenBalances(ctx context.Context, req *QueryFeeTokenBalancesRequest) (*QueryFeeTokenBalancesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryFeeTokenBalances not implemented") +} +func (*UnimplementedQueryServer) QueryFeeTokenBalance(ctx context.Context, req *QueryFeeTokenBalanceRequest) (*QueryFeeTokenBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryFeeTokenBalance not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_QueryParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryParams(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryModuleAccounts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryModuleAccountsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryModuleAccounts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryModuleAccounts", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryModuleAccounts(ctx, req.(*QueryModuleAccountsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryLastRewardSupplyPeak_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryLastRewardSupplyPeakRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryLastRewardSupplyPeak(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryLastRewardSupplyPeak", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryLastRewardSupplyPeak(ctx, req.(*QueryLastRewardSupplyPeakRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryAPY_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAPYRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryAPY(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryAPY", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryAPY(ctx, req.(*QueryAPYRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryFeeTokenBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryFeeTokenBalancesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryFeeTokenBalances(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryFeeTokenBalances", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryFeeTokenBalances(ctx, req.(*QueryFeeTokenBalancesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryFeeTokenBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryFeeTokenBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryFeeTokenBalance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cellarfees.v2.Query/QueryFeeTokenBalance", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryFeeTokenBalance(ctx, req.(*QueryFeeTokenBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cellarfees.v2.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "QueryParams", + Handler: _Query_QueryParams_Handler, + }, + { + MethodName: "QueryModuleAccounts", + Handler: _Query_QueryModuleAccounts_Handler, + }, + { + MethodName: "QueryLastRewardSupplyPeak", + Handler: _Query_QueryLastRewardSupplyPeak_Handler, + }, + { + MethodName: "QueryAPY", + Handler: _Query_QueryAPY_Handler, + }, + { + MethodName: "QueryFeeTokenBalances", + Handler: _Query_QueryFeeTokenBalances_Handler, + }, + { + MethodName: "QueryFeeTokenBalance", + Handler: _Query_QueryFeeTokenBalance_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cellarfees/v2/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryModuleAccountsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryModuleAccountsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryModuleAccountsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryModuleAccountsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryModuleAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.FeesAddress) > 0 { + i -= len(m.FeesAddress) + copy(dAtA[i:], m.FeesAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.FeesAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryLastRewardSupplyPeakRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryLastRewardSupplyPeakRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryLastRewardSupplyPeakRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryLastRewardSupplyPeakResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryLastRewardSupplyPeakResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryLastRewardSupplyPeakResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.LastRewardSupplyPeak.Size() + i -= size + if _, err := m.LastRewardSupplyPeak.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAPYRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAPYRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAPYRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryAPYResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAPYResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAPYResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Apy) > 0 { + i -= len(m.Apy) + copy(dAtA[i:], m.Apy) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Apy))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryFeeTokenBalancesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryFeeTokenBalancesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFeeTokenBalancesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryFeeTokenBalancesResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryFeeTokenBalancesResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFeeTokenBalancesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Balances) > 0 { + for iNdEx := len(m.Balances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Balances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryFeeTokenBalanceRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryFeeTokenBalanceRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFeeTokenBalanceRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryFeeTokenBalanceResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryFeeTokenBalanceResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryFeeTokenBalanceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Balance != nil { + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryModuleAccountsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryModuleAccountsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FeesAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryLastRewardSupplyPeakRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryLastRewardSupplyPeakResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.LastRewardSupplyPeak.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAPYRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryAPYResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Apy) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryFeeTokenBalancesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryFeeTokenBalancesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Balances) > 0 { + for _, e := range m.Balances { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryFeeTokenBalanceRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryFeeTokenBalanceResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Balance != nil { + l = m.Balance.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryModuleAccountsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryModuleAccountsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryModuleAccountsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryModuleAccountsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryModuleAccountsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FeesAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FeesAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryLastRewardSupplyPeakRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryLastRewardSupplyPeakRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryLastRewardSupplyPeakRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryLastRewardSupplyPeakResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryLastRewardSupplyPeakResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryLastRewardSupplyPeakResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LastRewardSupplyPeak", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.LastRewardSupplyPeak.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAPYRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAPYRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAPYRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAPYResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAPYResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAPYResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Apy", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Apy = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryFeeTokenBalancesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryFeeTokenBalancesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFeeTokenBalancesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryFeeTokenBalancesResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryFeeTokenBalancesResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFeeTokenBalancesResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balances", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Balances = append(m.Balances, &FeeTokenBalance{}) + if err := m.Balances[len(m.Balances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryFeeTokenBalanceRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryFeeTokenBalanceRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFeeTokenBalanceRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryFeeTokenBalanceResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryFeeTokenBalanceResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryFeeTokenBalanceResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Balance == nil { + m.Balance = &FeeTokenBalance{} + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/cellarfees/types/v2/query.pb.gw.go b/x/cellarfees/types/v2/query.pb.gw.go new file mode 100644 index 000000000..74f2f5719 --- /dev/null +++ b/x/cellarfees/types/v2/query.pb.gw.go @@ -0,0 +1,514 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: cellarfees/v2/query.proto + +/* +Package v2 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package v2 + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryParams(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryModuleAccounts_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryModuleAccounts(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryModuleAccounts_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryModuleAccountsRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryModuleAccounts(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryLastRewardSupplyPeak_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryLastRewardSupplyPeakRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryLastRewardSupplyPeak(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryLastRewardSupplyPeak_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryLastRewardSupplyPeakRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryLastRewardSupplyPeak(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryAPY_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAPYRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryAPY(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryAPY_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAPYRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryAPY(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryFeeTokenBalances_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFeeTokenBalancesRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryFeeTokenBalances(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryFeeTokenBalances_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFeeTokenBalancesRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryFeeTokenBalances(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryFeeTokenBalance_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFeeTokenBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := client.QueryFeeTokenBalance(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryFeeTokenBalance_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryFeeTokenBalanceRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["denom"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "denom") + } + + protoReq.Denom, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "denom", err) + } + + msg, err := server.QueryFeeTokenBalance(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryParams_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryModuleAccounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryModuleAccounts_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryModuleAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryLastRewardSupplyPeak_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryLastRewardSupplyPeak_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryLastRewardSupplyPeak_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAPY_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryAPY_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAPY_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryFeeTokenBalances_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryFeeTokenBalances_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryFeeTokenBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryFeeTokenBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryFeeTokenBalance_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryFeeTokenBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryParams_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryModuleAccounts_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryModuleAccounts_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryModuleAccounts_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryLastRewardSupplyPeak_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryLastRewardSupplyPeak_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryLastRewardSupplyPeak_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAPY_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryAPY_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAPY_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryFeeTokenBalances_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryFeeTokenBalances_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryFeeTokenBalances_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryFeeTokenBalance_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryFeeTokenBalance_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryFeeTokenBalance_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_QueryParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "cellarfees", "v2", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryModuleAccounts_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "cellarfees", "v2", "module_accounts"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryLastRewardSupplyPeak_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "cellarfees", "v2", "last_reward_supply_peak"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryAPY_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "cellarfees", "v2", "apy"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryFeeTokenBalances_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "cellarfees", "v2", "fee_token_balances"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryFeeTokenBalance_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sommelier", "cellarfees", "v2", "fee_token_balances", "denom"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_QueryParams_0 = runtime.ForwardResponseMessage + + forward_Query_QueryModuleAccounts_0 = runtime.ForwardResponseMessage + + forward_Query_QueryLastRewardSupplyPeak_0 = runtime.ForwardResponseMessage + + forward_Query_QueryAPY_0 = runtime.ForwardResponseMessage + + forward_Query_QueryFeeTokenBalances_0 = runtime.ForwardResponseMessage + + forward_Query_QueryFeeTokenBalance_0 = runtime.ForwardResponseMessage +) From a3611f6f1efde85d41682000b89c13e7a57a9fd8 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 14:53:40 -0600 Subject: [PATCH 02/28] FeeTokenBalance(s) queries and helper functions --- proto/cellarfees/v2/cellarfees.proto | 5 +- x/cellarfees/keeper/cellarfees.go | 13 ++++ x/cellarfees/keeper/query_server.go | 67 ++++++++++++++++ x/cellarfees/types/expected_keepers.go | 4 + x/cellarfees/types/v2/cellarfees.pb.go | 103 ++++++++++--------------- 5 files changed, 126 insertions(+), 66 deletions(-) diff --git a/proto/cellarfees/v2/cellarfees.proto b/proto/cellarfees/v2/cellarfees.proto index 9fba95543..345722d57 100644 --- a/proto/cellarfees/v2/cellarfees.proto +++ b/proto/cellarfees/v2/cellarfees.proto @@ -8,8 +8,5 @@ option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; message FeeTokenBalance { cosmos.base.v1beta1.Coin balance = 1 [ (gogoproto.nullable) = false ]; - string usd_value = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; + double usd_value = 2; } diff --git a/x/cellarfees/keeper/cellarfees.go b/x/cellarfees/keeper/cellarfees.go index fd90e763d..0d6aa52f8 100644 --- a/x/cellarfees/keeper/cellarfees.go +++ b/x/cellarfees/keeper/cellarfees.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/peggyjv/sommelier/v7/app/params" + auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" "github.com/peggyjv/sommelier/v7/x/cellarfees/types" ) @@ -38,3 +39,15 @@ func (k Keeper) GetEmission(ctx sdk.Context, remainingRewardsSupply math.Int) sd return sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, emissionAmount)) } + +func (k Keeper) GetFeeBalance(ctx sdk.Context, denom string) sdk.Coin { + feesAddr := k.GetFeesAccount(ctx).GetAddress() + + return k.bankKeeper.GetBalance(ctx, feesAddr, denom) +} + +func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice auctiontypes.TokenPrice) sdk.Dec { + unitAmount := sdk.NewDecFromInt(balance.Amount).Quo(sdk.NewDec(10).Power(tokenPrice.Exponent)) + + return tokenPrice.UsdPrice.Mul(unitAmount) +} diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index 856e45766..f5b7d0ae6 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -44,3 +44,70 @@ func (k Keeper) QueryAPY(c context.Context, _ *types.QueryAPYRequest) (*types.Qu Apy: k.GetAPY(sdk.UnwrapSDKContext(c)).String(), }, nil } + +func (k Keeper) QueryFeeTokenBalance(c context.Context, req *types.QueryFeeTokenBalanceRequest) (*types.QueryFeeTokenBalanceResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + if req.Denom == "" { + return nil, status.Error(codes.InvalidArgument, "denom cannot be empty") + } + + _, found := k.bankKeeper.GetDenomMetaData(ctx, req.Denom) + if !found { + return nil, status.Error(codes.NotFound, "denom not found") + } + + balance := k.GetFeeBalance(ctx, req.Denom) + tokenPrice, found := k.auctionKeeper.GetTokenPrice(ctx, req.Denom) + if !found { + return nil, status.Error(codes.NotFound, "token price not found") + } + + totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, tokenPrice).Float64() + if err != nil { + return nil, status.Error(codes.Internal, "failed to convert usd value to float") + } + + feeTokenBalance := types.FeeTokenBalance{ + Balance: balance, + UsdValue: totalUsdValue, + } + + return &types.QueryFeeTokenBalanceResponse{ + Balance: &feeTokenBalance, + }, nil +} + +func (k Keeper) QueryFeeTokenBalances(c context.Context, _ *types.QueryFeeTokenBalancesRequest) (*types.QueryFeeTokenBalancesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + feeBalances := make([]*types.FeeTokenBalance, 0) + + // because we can't get a USD value without a corresponding TokenPrice set in the auction module, + // this exclude fee token balances that don't have one yet. + for _, tokenPrice := range k.auctionKeeper.GetTokenPrices(ctx) { + balance := k.GetFeeBalance(ctx, tokenPrice.Denom) + + if balance.IsZero() { + continue + } + + totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, tokenPrice).Float64() + if err != nil { + return nil, status.Error(codes.Internal, "failed to convert usd value to float") + } + + feeTokenBalance := types.FeeTokenBalance{ + Balance: balance, + UsdValue: totalUsdValue, + } + + feeBalances = append(feeBalances, &feeTokenBalance) + } + + return &types.QueryFeeTokenBalancesResponse{ + Balances: feeBalances, + }, nil +} diff --git a/x/cellarfees/types/expected_keepers.go b/x/cellarfees/types/expected_keepers.go index 3a5912fdb..3925bd148 100644 --- a/x/cellarfees/types/expected_keepers.go +++ b/x/cellarfees/types/expected_keepers.go @@ -4,6 +4,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/ethereum/go-ethereum/common" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" @@ -21,6 +22,7 @@ type AccountKeeper interface { type BankKeeper interface { GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin + GetDenomMetaData(ctx sdk.Context, denom string) (banktypes.Metadata, bool) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins @@ -45,6 +47,8 @@ type GravityKeeper interface { // AuctionKeeper defines the expected auction keeper methods type AuctionKeeper interface { GetActiveAuctions(ctx sdk.Context) []*auctiontypes.Auction + GetTokenPrice(ctx sdk.Context, denom string) (auctiontypes.TokenPrice, bool) + GetTokenPrices(ctx sdk.Context) []auctiontypes.TokenPrice BeginAuction(ctx sdk.Context, startingTokensForSale sdk.Coin, initialPriceDecreaseRate sdk.Dec, diff --git a/x/cellarfees/types/v2/cellarfees.pb.go b/x/cellarfees/types/v2/cellarfees.pb.go index ad963b099..cbb6e33a9 100644 --- a/x/cellarfees/types/v2/cellarfees.pb.go +++ b/x/cellarfees/types/v2/cellarfees.pb.go @@ -4,8 +4,8 @@ package v2 import ( + encoding_binary "encoding/binary" fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" @@ -26,8 +26,8 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type FeeTokenBalance struct { - Balance types.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance"` - UsdValue github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=usd_value,json=usdValue,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"usd_value"` + Balance types.Coin `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance"` + UsdValue float64 `protobuf:"fixed64,2,opt,name=usd_value,json=usdValue,proto3" json:"usd_value,omitempty"` } func (m *FeeTokenBalance) Reset() { *m = FeeTokenBalance{} } @@ -70,6 +70,13 @@ func (m *FeeTokenBalance) GetBalance() types.Coin { return types.Coin{} } +func (m *FeeTokenBalance) GetUsdValue() float64 { + if m != nil { + return m.UsdValue + } + return 0 +} + func init() { proto.RegisterType((*FeeTokenBalance)(nil), "cellarfees.v2.FeeTokenBalance") } @@ -77,25 +84,23 @@ func init() { func init() { proto.RegisterFile("cellarfees/v2/cellarfees.proto", fileDescriptor_f9a743a746b9d1be) } var fileDescriptor_f9a743a746b9d1be = []byte{ - // 282 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xc1, 0x4a, 0xc3, 0x40, - 0x10, 0x86, 0xb3, 0x22, 0x6a, 0x23, 0x22, 0x14, 0x0f, 0xb5, 0x87, 0x6d, 0xf1, 0x20, 0xbd, 0xb8, - 0x43, 0x23, 0x22, 0x5e, 0xa3, 0x78, 0xf1, 0x20, 0x14, 0xf1, 0xe0, 0x45, 0x36, 0xdb, 0x31, 0xc6, - 0x26, 0x99, 0x90, 0x4d, 0x16, 0xfb, 0x16, 0x5e, 0x7d, 0xa3, 0x1e, 0x7b, 0x14, 0x0f, 0x45, 0x92, - 0x17, 0x91, 0x74, 0x2b, 0xe6, 0x34, 0xff, 0xfc, 0xfc, 0xf3, 0x31, 0x33, 0x2e, 0x57, 0x18, 0xc7, - 0x32, 0x7f, 0x41, 0xd4, 0x60, 0x3c, 0xf8, 0xef, 0x44, 0x96, 0x53, 0x41, 0xdd, 0x83, 0x96, 0x63, - 0xbc, 0x3e, 0x57, 0xa4, 0x13, 0xd2, 0x10, 0x48, 0x8d, 0x60, 0xc6, 0x01, 0x16, 0x72, 0x0c, 0x8a, - 0xa2, 0xd4, 0xc6, 0xfb, 0x47, 0x21, 0x85, 0xb4, 0x96, 0xd0, 0x28, 0xeb, 0x9e, 0x7c, 0x32, 0xf7, - 0xf0, 0x16, 0xf1, 0x81, 0x66, 0x98, 0xfa, 0x32, 0x96, 0xa9, 0xc2, 0xee, 0x95, 0xbb, 0x1b, 0x58, - 0xd9, 0x63, 0x43, 0x36, 0xda, 0xf7, 0x8e, 0x85, 0x65, 0x8b, 0x86, 0x2d, 0x36, 0x6c, 0x71, 0x4d, - 0x51, 0xea, 0x6f, 0x2f, 0x56, 0x03, 0x67, 0xf2, 0x97, 0xef, 0xde, 0xb9, 0x9d, 0x52, 0x4f, 0x9f, - 0x8d, 0x8c, 0x4b, 0xec, 0x6d, 0x0d, 0xd9, 0xa8, 0xe3, 0x8b, 0x26, 0xf1, 0xbd, 0x1a, 0x9c, 0x86, - 0x51, 0xf1, 0x5a, 0x06, 0x42, 0x51, 0x02, 0x9b, 0x55, 0x6d, 0x39, 0xd3, 0xd3, 0x19, 0x14, 0xf3, - 0x0c, 0xb5, 0xb8, 0x41, 0x35, 0xd9, 0x2b, 0xf5, 0xf4, 0xb1, 0x99, 0xf7, 0xef, 0x17, 0x15, 0x67, - 0xcb, 0x8a, 0xb3, 0x9f, 0x8a, 0xb3, 0x8f, 0x9a, 0x3b, 0xcb, 0x9a, 0x3b, 0x5f, 0x35, 0x77, 0x9e, - 0x2e, 0x5a, 0xac, 0x0c, 0xc3, 0x70, 0xfe, 0x66, 0x40, 0x53, 0x92, 0x60, 0x1c, 0x61, 0x0e, 0xe6, - 0x12, 0xde, 0x5b, 0xef, 0xb2, 0x6c, 0x30, 0x5e, 0xb0, 0xb3, 0xbe, 0xf9, 0xfc, 0x37, 0x00, 0x00, - 0xff, 0xff, 0xa8, 0x77, 0x94, 0xa9, 0x5a, 0x01, 0x00, 0x00, + // 255 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xbd, 0x4a, 0xc4, 0x40, + 0x14, 0x85, 0x33, 0x22, 0xfe, 0x44, 0x44, 0x08, 0x16, 0xeb, 0x0a, 0xe3, 0x62, 0xb5, 0xd5, 0x5c, + 0x36, 0x22, 0x62, 0x1b, 0xc1, 0x56, 0x58, 0xc4, 0xc2, 0x46, 0x26, 0xb3, 0xd7, 0x71, 0x74, 0x92, + 0x1b, 0x32, 0xc9, 0xe0, 0xbe, 0x85, 0x8f, 0xb5, 0xe5, 0x96, 0x56, 0x22, 0xc9, 0x8b, 0x48, 0x12, + 0xc5, 0xed, 0xbe, 0x7b, 0x38, 0x7c, 0x70, 0x6e, 0xc8, 0x15, 0x5a, 0x2b, 0xcb, 0x67, 0x44, 0x07, + 0x3e, 0x86, 0xff, 0x4b, 0x14, 0x25, 0x55, 0x14, 0x1d, 0x6e, 0x24, 0x3e, 0x1e, 0x73, 0x45, 0x2e, + 0x23, 0x07, 0xa9, 0x74, 0x08, 0x7e, 0x96, 0x62, 0x25, 0x67, 0xa0, 0xc8, 0xe4, 0x43, 0x7d, 0x7c, + 0xac, 0x49, 0x53, 0x8f, 0xd0, 0xd1, 0x90, 0x9e, 0x9b, 0xf0, 0xe8, 0x16, 0xf1, 0x9e, 0xde, 0x30, + 0x4f, 0xa4, 0x95, 0xb9, 0xc2, 0xe8, 0x3a, 0xdc, 0x4d, 0x07, 0x1c, 0xb1, 0x09, 0x9b, 0x1e, 0xc4, + 0x27, 0x62, 0x50, 0x8b, 0x4e, 0x2d, 0x7e, 0xd5, 0xe2, 0x86, 0x4c, 0x9e, 0x6c, 0xaf, 0xbe, 0xce, + 0x82, 0xf9, 0x5f, 0x3f, 0x3a, 0x0d, 0xf7, 0x6b, 0xb7, 0x78, 0xf2, 0xd2, 0xd6, 0x38, 0xda, 0x9a, + 0xb0, 0x29, 0x9b, 0xef, 0xd5, 0x6e, 0xf1, 0xd0, 0xdd, 0xc9, 0xdd, 0xaa, 0xe1, 0x6c, 0xdd, 0x70, + 0xf6, 0xdd, 0x70, 0xf6, 0xd1, 0xf2, 0x60, 0xdd, 0xf2, 0xe0, 0xb3, 0xe5, 0xc1, 0xe3, 0xa5, 0x36, + 0xd5, 0x4b, 0x9d, 0x0a, 0x45, 0x19, 0x14, 0xa8, 0xf5, 0xf2, 0xd5, 0x83, 0xa3, 0x2c, 0x43, 0x6b, + 0xb0, 0x04, 0x7f, 0x05, 0xef, 0x1b, 0xeb, 0xa1, 0x5a, 0x16, 0xfd, 0x47, 0xd2, 0x9d, 0x7e, 0xc2, + 0xc5, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x33, 0xd0, 0x4f, 0xe6, 0x29, 0x01, 0x00, 0x00, } func (m *FeeTokenBalance) Marshal() (dAtA []byte, err error) { @@ -118,16 +123,12 @@ func (m *FeeTokenBalance) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size := m.UsdValue.Size() - i -= size - if _, err := m.UsdValue.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintCellarfees(dAtA, i, uint64(size)) + if m.UsdValue != 0 { + i -= 8 + encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.UsdValue)))) + i-- + dAtA[i] = 0x11 } - i-- - dAtA[i] = 0x12 { size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -160,8 +161,9 @@ func (m *FeeTokenBalance) Size() (n int) { _ = l l = m.Balance.Size() n += 1 + l + sovCellarfees(uint64(l)) - l = m.UsdValue.Size() - n += 1 + l + sovCellarfees(uint64(l)) + if m.UsdValue != 0 { + n += 9 + } return n } @@ -234,39 +236,16 @@ func (m *FeeTokenBalance) Unmarshal(dAtA []byte) error { } iNdEx = postIndex case 2: - if wireType != 2 { + if wireType != 1 { return fmt.Errorf("proto: wrong wireType = %d for field UsdValue", wireType) } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCellarfees - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthCellarfees - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthCellarfees - } - if postIndex > l { + var v uint64 + if (iNdEx + 8) > l { return io.ErrUnexpectedEOF } - if err := m.UsdValue.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex + v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + m.UsdValue = float64(math.Float64frombits(v)) default: iNdEx = preIndex skippy, err := skipCellarfees(dAtA[iNdEx:]) From d8cb5a5ffa8b64c227de2e70dd36bb5baf283d02 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:09:48 -0600 Subject: [PATCH 03/28] Remove previous upgrade wiring --- app/app.go | 70 ++---------------------------------------------- x/cork/module.go | 2 -- 2 files changed, 2 insertions(+), 70 deletions(-) diff --git a/app/app.go b/app/app.go index b2d478e42..6f6d31f8c 100644 --- a/app/app.go +++ b/app/app.go @@ -96,10 +96,6 @@ import ( gravitykeeper "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/keeper" gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" appParams "github.com/peggyjv/sommelier/v7/app/params" - v4 "github.com/peggyjv/sommelier/v7/app/upgrades/v4" - v5 "github.com/peggyjv/sommelier/v7/app/upgrades/v5" - v6 "github.com/peggyjv/sommelier/v7/app/upgrades/v6" - v7 "github.com/peggyjv/sommelier/v7/app/upgrades/v7" "github.com/peggyjv/sommelier/v7/x/auction" auctionclient "github.com/peggyjv/sommelier/v7/x/auction/client" auctionkeeper "github.com/peggyjv/sommelier/v7/x/auction/keeper" @@ -969,30 +965,7 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() { var storeUpgrades *storetypes.StoreUpgrades = nil - if upgradeInfo.Name == v4.UpgradeName { - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{corktypes.ModuleName, cellarfeestypes.ModuleName}, - Deleted: []string{"allocation"}, - } - } - - if upgradeInfo.Name == v5.UpgradeName { - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{incentivestypes.ModuleName}, - } - } - - if upgradeInfo.Name == v6.UpgradeName { - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{icahosttypes.SubModuleName}, - } - } - - if upgradeInfo.Name == v7.UpgradeName { - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{auctiontypes.ModuleName, axelarcorktypes.ModuleName, cellarfeestypes.ModuleName, pubsubtypes.ModuleName}, - } - } + // TODO: Add v8 store loader when writing upgrade handler if storeUpgrades != nil { app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) @@ -1000,44 +973,5 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() { } func (app *SommelierApp) setupUpgradeHandlers() { - app.UpgradeKeeper.SetUpgradeHandler( - v4.UpgradeName, - v4.CreateUpgradeHandler( - app.mm, - app.configurator, - app.AccountKeeper, - app.BankKeeper, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v5.UpgradeName, - v5.CreateUpgradeHandler( - app.mm, - app.configurator, - app.IncentivesKeeper, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v6.UpgradeName, - v6.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - - app.UpgradeKeeper.SetUpgradeHandler( - v7.UpgradeName, - v7.CreateUpgradeHandler( - app.mm, - app.configurator, - app.AuctionKeeper, - app.AxelarCorkKeeper, - app.CellarFeesKeeper, - app.CorkKeeper, - app.ICAHostKeeper, - app.PubsubKeeper, - ), - ) + // TODO: Add v8 upgrade handler } diff --git a/x/cork/module.go b/x/cork/module.go index 246fbe799..bf434cc09 100644 --- a/x/cork/module.go +++ b/x/cork/module.go @@ -16,7 +16,6 @@ import ( "github.com/peggyjv/sommelier/v7/x/cork/client/cli" "github.com/peggyjv/sommelier/v7/x/cork/keeper" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types" - v1types "github.com/peggyjv/sommelier/v7/x/cork/types/v1" types "github.com/peggyjv/sommelier/v7/x/cork/types/v2" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -74,7 +73,6 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r // RegisterInterfaces implements app module basic func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { types.RegisterInterfaces(registry) - v1types.RegisterInterfaces(registry) } // AppModule implements an application module for the cork module. From 22b5272aa5c22c2b2f09bb64d050ec9466e58670 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:33:42 -0600 Subject: [PATCH 04/28] Remove gravity keeper and hooks from cellarfees --- app/app.go | 11 ++-- x/cellarfees/keeper/hooks.go | 76 --------------------------- x/cellarfees/keeper/hooks_test.go | 85 ------------------------------- x/cellarfees/keeper/keeper.go | 3 -- x/cellarfees/module.go | 4 +- 5 files changed, 6 insertions(+), 173 deletions(-) delete mode 100644 x/cellarfees/keeper/hooks.go delete mode 100644 x/cellarfees/keeper/hooks_test.go diff --git a/app/app.go b/app/app.go index 6f6d31f8c..af4f46bde 100644 --- a/app/app.go +++ b/app/app.go @@ -488,7 +488,7 @@ func NewSommelierApp( app.CellarFeesKeeper = cellarfeeskeeper.NewKeeper( appCodec, keys[cellarfeestypes.StoreKey], app.GetSubspace(cellarfeestypes.ModuleName), - app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.GravityKeeper, app.AuctionKeeper, + app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper, ) app.IncentivesKeeper = incentiveskeeper.NewKeeper( @@ -502,7 +502,6 @@ func NewSommelierApp( app.GravityKeeper = *app.GravityKeeper.SetHooks( gravitytypes.NewMultiGravityHooks( app.CorkKeeper.Hooks(), - app.CellarFeesKeeper.Hooks(), )) // register the proposal types @@ -574,7 +573,7 @@ func NewSommelierApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), cork.NewAppModule(app.CorkKeeper, appCodec), incentives.NewAppModule(app.IncentivesKeeper, app.DistrKeeper, app.BankKeeper, app.MintKeeper, appCodec), - cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.GravityKeeper, app.AuctionKeeper), + cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper), auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec), pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper), ) @@ -709,7 +708,7 @@ func NewSommelierApp( cork.NewAppModule(app.CorkKeeper, appCodec), axelarcork.NewAppModule(app.AxelarCorkKeeper, appCodec), incentives.NewAppModule(app.IncentivesKeeper, app.DistrKeeper, app.BankKeeper, app.MintKeeper, appCodec), - cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.GravityKeeper, app.AuctionKeeper), + cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper), auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec), pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper), ) @@ -965,7 +964,7 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() { var storeUpgrades *storetypes.StoreUpgrades = nil - // TODO: Add v8 store loader when writing upgrade handler + // TODO: Add v8 store loader when writing upgrade handler if storeUpgrades != nil { app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades)) @@ -973,5 +972,5 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() { } func (app *SommelierApp) setupUpgradeHandlers() { - // TODO: Add v8 upgrade handler + // TODO: Add v8 upgrade handler } diff --git a/x/cellarfees/keeper/hooks.go b/x/cellarfees/keeper/hooks.go deleted file mode 100644 index 70ecdfd8a..000000000 --- a/x/cellarfees/keeper/hooks.go +++ /dev/null @@ -1,76 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" - "github.com/peggyjv/sommelier/v7/app/params" - "github.com/peggyjv/sommelier/v7/x/cellarfees/types" -) - -type Hooks struct { - k Keeper -} - -var _ gravitytypes.GravityHooks = Hooks{} - -// Hooks Return the wrapper struct -func (k Keeper) Hooks() Hooks { - return Hooks{k} -} - -func (h Hooks) AfterContractCallExecutedEvent(ctx sdk.Context, event gravitytypes.ContractCallExecutedEvent) { -} - -func (h Hooks) AfterERC20DeployedEvent(ctx sdk.Context, event gravitytypes.ERC20DeployedEvent) {} - -func (h Hooks) AfterSignerSetExecutedEvent(ctx sdk.Context, event gravitytypes.SignerSetTxExecutedEvent) { -} - -func (h Hooks) AfterBatchExecutedEvent(ctx sdk.Context, event gravitytypes.BatchExecutedEvent) {} - -// Each time we receive a fee accrual from a cellar, we increment a counter for the respective denom. If a counter -// reaches a threshold defined in the cellarfees params, we attempt to start an auction. If the auction is started -// successfully we reset the count for that denom. -func (h Hooks) AfterSendToCosmosEvent(ctx sdk.Context, event gravitytypes.SendToCosmosEvent) { - // Check if recipient is the cellarfees module account - moduleAccountAddress := h.k.GetFeesAccount(ctx).GetAddress() - if event.CosmosReceiver != moduleAccountAddress.String() { - return - } - - if event.Amount.IsZero() { - return - } - - // Check if the sender is an approved Cellar contract. We don't want to count coins sent from any address - // as fee accruals. - if !h.k.corkKeeper.HasCellarID(ctx, common.HexToAddress(event.EthereumSender)) { - return - } - - // Denom cannot be SOMM - _, denom := h.k.gravityKeeper.ERC20ToDenomLookup(ctx, common.HexToAddress(event.TokenContract)) - if denom == params.BaseCoinUnit { - return - } - - counters := h.k.GetFeeAccrualCounters(ctx) - count := counters.IncrementCounter(denom) - h.k.SetFeeAccrualCounters(ctx, counters) - - ctx.EventManager().EmitEvents( - sdk.Events{ - sdk.NewEvent( - types.EventTypeFeeAccrual, - sdk.NewAttribute(types.AttributeKeyCellar, event.EthereumSender), - sdk.NewAttribute(types.AttributeKeyTokenContract, event.TokenContract), - sdk.NewAttribute(types.AttributeKeyDenom, denom), - sdk.NewAttribute(types.AttributeKeyAmount, event.Amount.String()), - sdk.NewAttribute(types.AttributeKeyCount, fmt.Sprint(count)), - ), - }, - ) -} diff --git a/x/cellarfees/keeper/hooks_test.go b/x/cellarfees/keeper/hooks_test.go deleted file mode 100644 index 9238af47a..000000000 --- a/x/cellarfees/keeper/hooks_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" -) - -const gravityFeeDenom = "gravity0x1111111111111111111111111111111111111111" - -func (suite *KeeperTestSuite) SetupHooksTests(ctx sdk.Context, cellarfeesKeeper Keeper) { - cellarfeesKeeper.SetParams(ctx, cellarfeesTypes.DefaultParams()) - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) - - // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, feesAccount.GetName()).Return(feesAccount).Times(1) -} - -func (suite *KeeperTestSuite) TestHooksRecipientNotFeesAccountDoesNothing() { - ctx, cellarfeesKeeper, require := suite.ctx, suite.cellarfeesKeeper, suite.Require() - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: "fakeaddress", - } - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - require.Equal(cellarfeesTypes.DefaultFeeAccrualCounters(), cellarfeesKeeper.GetFeeAccrualCounters(ctx)) -} - -func (suite *KeeperTestSuite) TestHooksEventAmountZeroDoesNothing() { - ctx, cellarfeesKeeper, require := suite.ctx, suite.cellarfeesKeeper, suite.Require() - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.ZeroInt(), - } - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - require.Equal(cellarfeesTypes.DefaultFeeAccrualCounters(), cellarfeesKeeper.GetFeeAccrualCounters(ctx)) -} - -func (suite *KeeperTestSuite) TestHooksUnapprovedCellarDoesNothing() { - ctx, cellarfeesKeeper, require := suite.ctx, suite.cellarfeesKeeper, suite.Require() - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.OneInt(), - EthereumSender: "0x0000000000000000000000000000000000000000", - } - cellarID := common.HexToAddress(event.EthereumSender) - - // mocks - suite.corkKeeper.EXPECT().HasCellarID(ctx, cellarID).Return(false).Times(1) - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - require.Equal(cellarfeesTypes.DefaultFeeAccrualCounters(), cellarfeesKeeper.GetFeeAccrualCounters(ctx)) -} - -func (suite *KeeperTestSuite) TestHooksDenomIsUsommDoesNothing() { - ctx, cellarfeesKeeper, require := suite.ctx, suite.cellarfeesKeeper, suite.Require() - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.OneInt(), - EthereumSender: "0x0000000000000000000000000000000000000000", - TokenContract: "0x1111111111111111111111111111111111111111", - } - cellarID := common.HexToAddress(event.EthereumSender) - - // mocks - suite.corkKeeper.EXPECT().HasCellarID(ctx, cellarID).Return(true) - suite.gravityKeeper.EXPECT().ERC20ToDenomLookup(ctx, common.HexToAddress(event.TokenContract)).Return(true, "usomm").Times(1) - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - require.Equal(cellarfeesTypes.DefaultFeeAccrualCounters(), cellarfeesKeeper.GetFeeAccrualCounters(ctx)) -} diff --git a/x/cellarfees/keeper/keeper.go b/x/cellarfees/keeper/keeper.go index 5b610466d..2d1c22f3a 100644 --- a/x/cellarfees/keeper/keeper.go +++ b/x/cellarfees/keeper/keeper.go @@ -24,7 +24,6 @@ type Keeper struct { bankKeeper cellarfeestypes.BankKeeper mintKeeper cellarfeestypes.MintKeeper corkKeeper cellarfeestypes.CorkKeeper - gravityKeeper cellarfeestypes.GravityKeeper auctionKeeper cellarfeestypes.AuctionKeeper } @@ -36,7 +35,6 @@ func NewKeeper( bankKeeper cellarfeestypes.BankKeeper, mintKeeper cellarfeestypes.MintKeeper, corkKeeper cellarfeestypes.CorkKeeper, - gravityKeeper cellarfeestypes.GravityKeeper, auctionKeeper cellarfeestypes.AuctionKeeper, ) Keeper { if !paramSpace.HasKeyTable() { @@ -51,7 +49,6 @@ func NewKeeper( bankKeeper: bankKeeper, mintKeeper: mintKeeper, corkKeeper: corkKeeper, - gravityKeeper: gravityKeeper, auctionKeeper: auctionKeeper, } } diff --git a/x/cellarfees/module.go b/x/cellarfees/module.go index 139029b07..03eb17992 100644 --- a/x/cellarfees/module.go +++ b/x/cellarfees/module.go @@ -81,13 +81,12 @@ type AppModule struct { bankKeeper types.BankKeeper mintKeeper types.MintKeeper corkKeeper types.CorkKeeper - gravityKeeper types.GravityKeeper auctionKeeper types.AuctionKeeper } // NewAppModule creates a new AppModule object func NewAppModule(keeper keeper.Keeper, cdc codec.Codec, accountKeeper types.AccountKeeper, bankKeeper types.BankKeeper, - mintKeeper types.MintKeeper, corkKeeper types.CorkKeeper, gravityKeeper types.GravityKeeper, auctionKeeper types.AuctionKeeper) AppModule { + mintKeeper types.MintKeeper, corkKeeper types.CorkKeeper, auctionKeeper types.AuctionKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, @@ -96,7 +95,6 @@ func NewAppModule(keeper keeper.Keeper, cdc codec.Codec, accountKeeper types.Acc bankKeeper: bankKeeper, mintKeeper: mintKeeper, corkKeeper: corkKeeper, - gravityKeeper: gravityKeeper, auctionKeeper: auctionKeeper, } } From b1b6f138f1c16fb71aad66186ab067049f8e4922 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:34:37 -0600 Subject: [PATCH 05/28] Fix imports --- x/cellarfees/module.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/x/cellarfees/module.go b/x/cellarfees/module.go index 03eb17992..01bb1bec0 100644 --- a/x/cellarfees/module.go +++ b/x/cellarfees/module.go @@ -15,6 +15,7 @@ import ( "github.com/peggyjv/sommelier/v7/x/cellarfees/client/cli" "github.com/peggyjv/sommelier/v7/x/cellarfees/keeper" "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + typesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" ) @@ -38,13 +39,13 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // DefaultGenesis returns default genesis state as raw bytes for the cellarfees // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - gs := types.DefaultGenesisState() + gs := typesv2.DefaultGenesisState() return cdc.MustMarshalJSON(&gs) } // ValidateGenesis performs genesis state validation for the cellarfees module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { - var gs types.GenesisState + var gs typesv2.GenesisState if err := cdc.UnmarshalJSON(bz, &gs); err != nil { return err } @@ -64,12 +65,12 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the cellarfees module. // also implements AppModuleBasic func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + typesv2.RegisterQueryHandlerClient(context.Background(), mux, typesv2.NewQueryClient(clientCtx)) } // RegisterInterfaces implements AppModuleBasic func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { - types.RegisterInterfaces(registry) + typesv2.RegisterInterfaces(registry) } // AppModule implements an application module for the cellarfees module. @@ -128,12 +129,12 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.We // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { //types.RegisterMsgServer(cfg.MsgServer(), am.keeper) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + typesv2.RegisterQueryServer(cfg.QueryServer(), am.keeper) } // InitGenesis performs genesis initialization for the cellarfees module. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState + var genesisState typesv2.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, genesisState) From 348c5b500a547037e5cc51b7b31d36e928b7dcd8 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:35:02 -0600 Subject: [PATCH 06/28] Fix expected keeper --- x/cellarfees/keeper/cellarfees.go | 2 +- x/cellarfees/keeper/query_server.go | 2 +- x/cellarfees/types/expected_keepers.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/cellarfees/keeper/cellarfees.go b/x/cellarfees/keeper/cellarfees.go index 0d6aa52f8..080561778 100644 --- a/x/cellarfees/keeper/cellarfees.go +++ b/x/cellarfees/keeper/cellarfees.go @@ -46,7 +46,7 @@ func (k Keeper) GetFeeBalance(ctx sdk.Context, denom string) sdk.Coin { return k.bankKeeper.GetBalance(ctx, feesAddr, denom) } -func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice auctiontypes.TokenPrice) sdk.Dec { +func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice *auctiontypes.TokenPrice) sdk.Dec { unitAmount := sdk.NewDecFromInt(balance.Amount).Quo(sdk.NewDec(10).Power(tokenPrice.Exponent)) return tokenPrice.UsdPrice.Mul(unitAmount) diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index f5b7d0ae6..cf01d1f82 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -66,7 +66,7 @@ func (k Keeper) QueryFeeTokenBalance(c context.Context, req *types.QueryFeeToken return nil, status.Error(codes.NotFound, "token price not found") } - totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, tokenPrice).Float64() + totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, &tokenPrice).Float64() if err != nil { return nil, status.Error(codes.Internal, "failed to convert usd value to float") } diff --git a/x/cellarfees/types/expected_keepers.go b/x/cellarfees/types/expected_keepers.go index 3925bd148..676c7212d 100644 --- a/x/cellarfees/types/expected_keepers.go +++ b/x/cellarfees/types/expected_keepers.go @@ -48,7 +48,7 @@ type GravityKeeper interface { type AuctionKeeper interface { GetActiveAuctions(ctx sdk.Context) []*auctiontypes.Auction GetTokenPrice(ctx sdk.Context, denom string) (auctiontypes.TokenPrice, bool) - GetTokenPrices(ctx sdk.Context) []auctiontypes.TokenPrice + GetTokenPrices(ctx sdk.Context) []*auctiontypes.TokenPrice BeginAuction(ctx sdk.Context, startingTokensForSale sdk.Coin, initialPriceDecreaseRate sdk.Dec, From 14fd4e76e20845b5c5cfb6c1f7b0d67e598abebc Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:35:35 -0600 Subject: [PATCH 07/28] remove empty file --- x/cellarfees/types/expected_keepers.go | 5 ----- x/cellarfees/types/v2/cellarfees.go | 1 - 2 files changed, 6 deletions(-) delete mode 100644 x/cellarfees/types/v2/cellarfees.go diff --git a/x/cellarfees/types/expected_keepers.go b/x/cellarfees/types/expected_keepers.go index 676c7212d..e1935a0bf 100644 --- a/x/cellarfees/types/expected_keepers.go +++ b/x/cellarfees/types/expected_keepers.go @@ -39,11 +39,6 @@ type CorkKeeper interface { HasCellarID(ctx sdk.Context, address common.Address) (found bool) } -// GravityKeeper defines the expected gravity keeper methods -type GravityKeeper interface { - ERC20ToDenomLookup(ctx sdk.Context, tokenContract common.Address) (bool, string) -} - // AuctionKeeper defines the expected auction keeper methods type AuctionKeeper interface { GetActiveAuctions(ctx sdk.Context) []*auctiontypes.Auction diff --git a/x/cellarfees/types/v2/cellarfees.go b/x/cellarfees/types/v2/cellarfees.go deleted file mode 100644 index 5ec3cc8e8..000000000 --- a/x/cellarfees/types/v2/cellarfees.go +++ /dev/null @@ -1 +0,0 @@ -package v2 From 6970c70be253b47b3e5d7bffcebc44ac3e97aaeb Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 4 Mar 2024 16:58:16 -0600 Subject: [PATCH 08/28] Initial update to auction handling --- x/cellarfees/keeper/abci.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index e161e03ce..9ea5b1ad6 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -10,9 +10,6 @@ import ( // account. Emissions are a constant value based on the last peak supply of distributable fees so that the reward supply // will decrease linearly until exhausted. func (k Keeper) BeginBlocker(ctx sdk.Context) { - - // Handle fee auctions - // Handle reward emissions moduleAccount := k.GetFeesAccount(ctx) remainingRewardsSupply := k.bankKeeper.GetBalance(ctx, moduleAccount.GetAddress(), params.BaseCoinUnit).Amount @@ -29,6 +26,28 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) { panic(err) } + // Handle fee auctions + params := k.GetParams(ctx) + + if uint64(ctx.BlockHeight())%params.AuctionInterval != 0 { + return + } + + tokenPrices := k.auctionKeeper.GetTokenPrices(ctx) + + for _, tokenPrice := range tokenPrices { + balance := k.GetFeeBalance(ctx, tokenPrice.Denom) + + if balance.IsZero() { + continue + } + + usdValue := k.GetBalanceUsdValue(ctx, balance, tokenPrice) + + if usdValue.GTE(params.AuctionThresholdUsdValue) { + k.beginAuction(ctx, tokenPrice.Denom) + } + } } // EndBlocker is called at the end of every block From 80fce3e1b2d07e0e02e91cab85e2e8e9ffaee18b Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 13:46:29 -0600 Subject: [PATCH 09/28] Wire up new param --- x/cellarfees/types/errors.go | 1 + x/cellarfees/types/v2/params.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/x/cellarfees/types/errors.go b/x/cellarfees/types/errors.go index 8e55258b6..8e587e9b1 100644 --- a/x/cellarfees/types/errors.go +++ b/x/cellarfees/types/errors.go @@ -13,4 +13,5 @@ var ( ErrInvalidFeeAccrualCounters = errorsmod.Register(ModuleName, 6, "invalid fee accrual counters") ErrInvalidLastRewardSupplyPeak = errorsmod.Register(ModuleName, 7, "invalid last reward supply peak") ErrInvalidAuctionInterval = errorsmod.Register(ModuleName, 8, "invalid interval blocks between auctions") + ErrInvalidAuctionThresholdUsdValue = errorsmod.Register(ModuleName, 9, "invalid auction threshold USD value") ) diff --git a/x/cellarfees/types/v2/params.go b/x/cellarfees/types/v2/params.go index 72685be62..cecf3300e 100644 --- a/x/cellarfees/types/v2/params.go +++ b/x/cellarfees/types/v2/params.go @@ -19,6 +19,9 @@ const ( DefaultPriceDecreaseBlockInterval uint64 = 10 // Blocks between each auction DefaultAuctionInterval uint64 = 15000 + // Minimum USD value of a token's fees balance to trigger an auction + // $10,000 + DefaultAuctionThresholdUsdValue = "10000.00" ) // Parameter keys @@ -27,6 +30,7 @@ var ( KeyInitialPriceDecreaseRate = []byte("InitialPriceDecreaseRate") KeyPriceDecreaseBlockInterval = []byte("PriceDecreaseBlockInterval") KeyAuctionInterval = []byte("AuctionInterval") + KeyAuctionThresholdUsdValue = []byte("AuctionThresholdUsdValue") ) var _ paramtypes.ParamSet = &Params{} @@ -43,6 +47,7 @@ func DefaultParams() Params { InitialPriceDecreaseRate: sdk.MustNewDecFromStr(DefaultInitialPriceDecreaseRate), PriceDecreaseBlockInterval: DefaultPriceDecreaseBlockInterval, AuctionInterval: DefaultAuctionInterval, + AuctionThresholdUsdValue: sdk.MustNewDecFromStr(DefaultAuctionThresholdUsdValue), } } @@ -53,6 +58,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeyInitialPriceDecreaseRate, &p.InitialPriceDecreaseRate, validateInitialPriceDecreaseRate), paramtypes.NewParamSetPair(KeyPriceDecreaseBlockInterval, &p.PriceDecreaseBlockInterval, validatePriceDecreaseBlockInterval), paramtypes.NewParamSetPair(KeyAuctionInterval, &p.AuctionInterval, validateAuctionInterval), + paramtypes.NewParamSetPair(KeyAuctionThresholdUsdValue, &p.AuctionThresholdUsdValue, validateAuctionThresholdUsdValue), } } @@ -126,6 +132,19 @@ func validateAuctionInterval(i interface{}) error { return nil } +func validateAuctionThresholdUsdValue(i interface{}) error { + threshold, ok := i.(sdk.Dec) + if !ok { + return errorsmod.Wrapf(types.ErrInvalidAuctionThresholdUsdValue, "auction threshold USD value: %T", i) + } + + if !threshold.IsPositive() { + return errorsmod.Wrapf(types.ErrInvalidAuctionThresholdUsdValue, "auction threshold USD value must be greater than zero") + } + + return nil +} + // String implements the String interface func (p Params) String() string { out, _ := yaml.Marshal(p) From 4ac6cc4d491b1965f9866f517c0773369ef4bfda Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 14:59:17 -0600 Subject: [PATCH 10/28] Remove old upgrade files from build --- app/upgrades/v4/upgrades.go | 2 ++ app/upgrades/v5/upgrades.go | 2 ++ app/upgrades/v6/upgrades.go | 2 ++ app/upgrades/v7/upgrades.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/upgrades/v4/upgrades.go b/app/upgrades/v4/upgrades.go index a8e358bf5..81d8cd376 100644 --- a/app/upgrades/v4/upgrades.go +++ b/app/upgrades/v4/upgrades.go @@ -1,3 +1,5 @@ +//go:build exclude + package v4 import ( diff --git a/app/upgrades/v5/upgrades.go b/app/upgrades/v5/upgrades.go index bb34bd838..06c07b64c 100644 --- a/app/upgrades/v5/upgrades.go +++ b/app/upgrades/v5/upgrades.go @@ -1,3 +1,5 @@ +//go:build exclude + package v5 import ( diff --git a/app/upgrades/v6/upgrades.go b/app/upgrades/v6/upgrades.go index 93f027776..ba0add25d 100644 --- a/app/upgrades/v6/upgrades.go +++ b/app/upgrades/v6/upgrades.go @@ -1,3 +1,5 @@ +//go:build exclude + package v6 import ( diff --git a/app/upgrades/v7/upgrades.go b/app/upgrades/v7/upgrades.go index e5dca5cf9..8e8e78a1a 100644 --- a/app/upgrades/v7/upgrades.go +++ b/app/upgrades/v7/upgrades.go @@ -1,3 +1,5 @@ +//go:build exclude + package v7 import ( From f8a6ee16275c1c020f9e9494b544f953abebac7c Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 15:00:50 -0600 Subject: [PATCH 11/28] Refactor cellarfees BeginBlocker --- x/cellarfees/keeper/abci.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 9ea5b1ad6..5f23578b5 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -10,7 +10,14 @@ import ( // account. Emissions are a constant value based on the last peak supply of distributable fees so that the reward supply // will decrease linearly until exhausted. func (k Keeper) BeginBlocker(ctx sdk.Context) { - // Handle reward emissions + k.handleRewardEmission(ctx) + k.handleFeeAuctions(ctx) +} + +// EndBlocker is called at the end of every block +func (k Keeper) EndBlocker(ctx sdk.Context) {} + +func (k Keeper) handleRewardEmission(ctx sdk.Context) { moduleAccount := k.GetFeesAccount(ctx) remainingRewardsSupply := k.bankKeeper.GetBalance(ctx, moduleAccount.GetAddress(), params.BaseCoinUnit).Amount @@ -25,17 +32,16 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) { if err != nil { panic(err) } +} - // Handle fee auctions +func (k Keeper) handleFeeAuctions(ctx sdk.Context) { params := k.GetParams(ctx) if uint64(ctx.BlockHeight())%params.AuctionInterval != 0 { return } - tokenPrices := k.auctionKeeper.GetTokenPrices(ctx) - - for _, tokenPrice := range tokenPrices { + for _, tokenPrice := range k.auctionKeeper.GetTokenPrices(ctx) { balance := k.GetFeeBalance(ctx, tokenPrice.Denom) if balance.IsZero() { @@ -49,6 +55,3 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) { } } } - -// EndBlocker is called at the end of every block -func (k Keeper) EndBlocker(ctx sdk.Context) {} From 4de900c76d21a07c3e5d3aec95b410e8f0712851 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 15:00:59 -0600 Subject: [PATCH 12/28] Update cellarfees keeper unit tests --- x/cellarfees/keeper/abci_test.go | 254 +++++------------- x/cellarfees/keeper/auction_test.go | 25 +- x/cellarfees/keeper/cellarfees_test.go | 78 ++++++ x/cellarfees/keeper/genesis_test.go | 48 +--- x/cellarfees/keeper/keeper_test.go | 32 +-- x/cellarfees/keeper/query_server.go | 3 +- x/cellarfees/keeper/query_server_test.go | 147 +++++++--- .../testutil/expected_keepers_mocks.go | 100 +++---- 8 files changed, 348 insertions(+), 339 deletions(-) create mode 100644 x/cellarfees/keeper/cellarfees_test.go diff --git a/x/cellarfees/keeper/abci_test.go b/x/cellarfees/keeper/abci_test.go index f6612a75e..1765f13fc 100644 --- a/x/cellarfees/keeper/abci_test.go +++ b/x/cellarfees/keeper/abci_test.go @@ -2,25 +2,24 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" "github.com/golang/mock/gomock" - gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" appParams "github.com/peggyjv/sommelier/v7/app/params" auctionTypes "github.com/peggyjv/sommelier/v7/x/auction/types" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) func (suite *KeeperTestSuite) TestBeginBlockerZeroRewardsBalance() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(appParams.BaseCoinUnit, sdk.ZeroInt())) suite.bankKeeper.EXPECT().SendCoinsFromModuleToModule(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Times(0) @@ -31,15 +30,14 @@ func (suite *KeeperTestSuite) TestBeginBlockerZeroRewardsBalance() { func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndPreviousPeakZero() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) rewardSupply := sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(1000000)) emissionPeriod := sdk.NewInt(int64(params.RewardEmissionPeriod)) @@ -55,14 +53,13 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndPreviousPeakZe func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndHigherPreviousPeak() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) rewardSupply := sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(1000000)) emissionPeriod := sdk.NewInt(int64(params.RewardEmissionPeriod)) @@ -80,15 +77,14 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndHigherPrevious func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndLowerPreviousPeak() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) rewardSupply := sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(1000000)) emissionPeriod := sdk.NewInt(int64(params.RewardEmissionPeriod)) @@ -107,15 +103,14 @@ func (suite *KeeperTestSuite) TestBeginBlockerWithRewardBalanceAndLowerPreviousP // If the emission calculation underflows to zero, it should be set to 1 func (suite *KeeperTestSuite) TestBeginBlockerEmissionCalculationUnderflowsToZero() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.ZeroInt()) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) rewardSupply := sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(1)) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(appParams.BaseCoinUnit, rewardSupply.Amount)) @@ -129,15 +124,14 @@ func (suite *KeeperTestSuite) TestBeginBlockerEmissionCalculationUnderflowsToZer // If the calculated emission is greater than the remaining supply, it should be set to the remaining supply func (suite *KeeperTestSuite) TestBeginBlockerEmissionGreaterThanRewardSupply() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.NewInt(1000000)) // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) rewardSupply := sdk.NewCoin(appParams.BaseCoinUnit, sdk.NewInt(1)) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(appParams.BaseCoinUnit, rewardSupply.Amount)) @@ -148,184 +142,74 @@ func (suite *KeeperTestSuite) TestBeginBlockerEmissionGreaterThanRewardSupply() require.NotPanics(func() { cellarfeesKeeper.BeginBlocker(ctx) }) } -func (suite *KeeperTestSuite) TestAuctionBeginWithSufficientFunds() { +func (suite *KeeperTestSuite) TestHandleFeeAuctionsHappyPath() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) - suite.SetupHooksTests(ctx, cellarfeesKeeper) + params := cellarfeestypesv2.DefaultParams() - require := suite.Require() - params := cellarfeesTypes.DefaultParams() params.AuctionInterval = 1 - cellarfeesKeeper.SetParams(ctx, params) - cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.NewInt(1000000)) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.NewInt(2), - EthereumSender: "0x0000000000000000000000000000000000000000", - TokenContract: "0x1111111111111111111111111111111111111111", - } - cellarID := common.HexToAddress(event.EthereumSender) - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 1, - }, - }, - }) - expectedCounters := cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 0, - }, - }, - } - - suite.corkKeeper.EXPECT().HasCellarID(ctx, cellarID).Return(true) - suite.gravityKeeper.EXPECT().ERC20ToDenomLookup(ctx, common.HexToAddress(event.TokenContract)).Return(false, gravityFeeDenom) - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - - // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(gravityFeeDenom, sdk.NewInt(0))) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - - expectedEmission := sdk.NewCoin(appParams.BaseCoinUnit, event.Amount) - suite.bankKeeper.EXPECT().SendCoinsFromModuleToModule(ctx, gomock.Any(), gomock.Any(), sdk.NewCoins(expectedEmission)).Times(1) - suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - suite.auctionKeeper.EXPECT().BeginAuction(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - - require.NotPanics(func() { cellarfeesKeeper.BeginBlocker(ctx) }) + params.AuctionThresholdUsdValue = sdk.MustNewDecFromStr("100.00") - require.Equal(expectedCounters, cellarfeesKeeper.GetFeeAccrualCounters(ctx)) - -} - -func (suite *KeeperTestSuite) TestAuctionBeginWithInSufficientFunds() { - ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - require := suite.Require() - params := cellarfeesTypes.DefaultParams() - params.AuctionInterval = 1 cellarfeesKeeper.SetParams(ctx, params) - cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.NewInt(1000000)) - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.NewInt(1), - EthereumSender: "0x0000000000000000000000000000000000000000", - TokenContract: "0x1111111111111111111111111111111111111111", - } - cellarID := common.HexToAddress(event.EthereumSender) - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 0, - }, - }, - }) - expectedCounters := cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 1, - }, + denom1 := "denom1" + denom2 := "denom2" + denom3 := "denom3" + amount1 := sdk.NewInt(1000000) + amount2 := sdk.NewInt(2000000000000) + amount3 := sdk.NewInt(3000000000000000000) + balance1 := sdk.NewCoin(denom1, amount1) + balance2 := sdk.NewCoin(denom2, amount2) + balance3 := sdk.NewCoin(denom3, amount3) + price1 := sdk.NewDec(100) + price2 := sdk.NewDec(50) + price3 := sdk.NewDec(33) + tokenPrices := []*auctiontypes.TokenPrice{ + { + Exponent: 6, + Denom: denom1, + UsdPrice: price1, }, - } - - suite.corkKeeper.EXPECT().HasCellarID(ctx, cellarID).Return(true) - suite.gravityKeeper.EXPECT().ERC20ToDenomLookup(ctx, common.HexToAddress(event.TokenContract)).Return(false, gravityFeeDenom) - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) - - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) - - // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(gravityFeeDenom, sdk.NewInt(0))) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - - expectedEmission := sdk.NewCoin(appParams.BaseCoinUnit, event.Amount) - suite.bankKeeper.EXPECT().SendCoinsFromModuleToModule(ctx, gomock.Any(), gomock.Any(), sdk.NewCoins(expectedEmission)).Times(1) - suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - suite.auctionKeeper.EXPECT().BeginAuction(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1) - - require.NotPanics(func() { cellarfeesKeeper.BeginBlocker(ctx) }) - - require.Equal(expectedCounters, cellarfeesKeeper.GetFeeAccrualCounters(ctx)) - -} - -func (suite *KeeperTestSuite) TestAuctionBeginWithSufficientFundsWrongBlockHeight() { - ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) - suite.SetupHooksTests(ctx, cellarfeesKeeper) - - require := suite.Require() - params := cellarfeesTypes.DefaultParams() - params.AuctionInterval = 1000 - cellarfeesKeeper.SetParams(ctx, params) - cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.NewInt(1000000)) - - hooks := Hooks{k: cellarfeesKeeper} - event := gravitytypes.SendToCosmosEvent{ - CosmosReceiver: feesAccount.GetAddress().String(), - Amount: sdk.NewInt(2), - EthereumSender: "0x0000000000000000000000000000000000000000", - TokenContract: "0x1111111111111111111111111111111111111111", - } - cellarID := common.HexToAddress(event.EthereumSender) - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 1, - }, + { + Exponent: 12, + Denom: denom2, + UsdPrice: price2, }, - }) - expectedCounters := cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: gravityFeeDenom, - Count: 2, - }, + { + Exponent: 18, + Denom: denom3, + UsdPrice: price3, }, } - suite.corkKeeper.EXPECT().HasCellarID(ctx, cellarID).Return(true) - suite.gravityKeeper.EXPECT().ERC20ToDenomLookup(ctx, common.HexToAddress(event.TokenContract)).Return(false, gravityFeeDenom) - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.auctionKeeper.EXPECT().GetTokenPrices(ctx).Return(tokenPrices) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(len(tokenPrices) * 2) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom1).Return(balance1).Times(2) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom2).Return(balance2).Times(2) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom3).Return(balance3).Times(2) - require.NotPanics(func() { hooks.AfterSendToCosmosEvent(ctx, event) }) + // retreiving module account + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) - // mocks - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), appParams.BaseCoinUnit).Return(sdk.NewCoin(gravityFeeDenom, sdk.NewInt(0))) - - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - - expectedEmission := sdk.NewCoin(appParams.BaseCoinUnit, event.Amount) - suite.bankKeeper.EXPECT().SendCoinsFromModuleToModule(ctx, gomock.Any(), gomock.Any(), sdk.NewCoins(expectedEmission)).Times(1) + // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), gravityFeeDenom).Return(sdk.NewCoin(gravityFeeDenom, event.Amount)) - - require.NotPanics(func() { cellarfeesKeeper.BeginBlocker(ctx) }) + suite.auctionKeeper.EXPECT().BeginAuction(ctx, balance1, params.InitialPriceDecreaseRate, params.PriceDecreaseBlockInterval, cellarfeestypes.ModuleName, cellarfeestypes.ModuleName).Return(nil) + expectedAuction1 := auctionTypes.Auction{ + Id: 1, + StartingTokensForSale: balance1, + InitialPriceDecreaseRate: params.InitialPriceDecreaseRate, + CurrentPriceDecreaseRate: params.InitialPriceDecreaseRate, + StartBlock: uint64(ctx.BlockHeight()), + EndBlock: 0, + PriceDecreaseBlockInterval: params.PriceDecreaseBlockInterval, + InitialUnitPriceInUsomm: price1, + CurrentUnitPriceInUsomm: price1, + FundingModuleAccount: cellarfeestypes.ModuleName, + ProceedsModuleAccount: cellarfeestypes.ModuleName, + } + suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{&expectedAuction1}) + suite.auctionKeeper.EXPECT().BeginAuction(ctx, balance2, params.InitialPriceDecreaseRate, params.PriceDecreaseBlockInterval, cellarfeestypes.ModuleName, cellarfeestypes.ModuleName).Return(nil) - require.Equal(expectedCounters, cellarfeesKeeper.GetFeeAccrualCounters(ctx)) + // we only set expected calls for two auctions because the third token price is $99, so no auction should be started. + cellarfeesKeeper.handleFeeAuctions(ctx) } diff --git a/x/cellarfees/keeper/auction_test.go b/x/cellarfees/keeper/auction_test.go index 075c0e732..c4fb85721 100644 --- a/x/cellarfees/keeper/auction_test.go +++ b/x/cellarfees/keeper/auction_test.go @@ -4,7 +4,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang/mock/gomock" auctionTypes "github.com/peggyjv/sommelier/v7/x/auction/types" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) const feeDenom = "testdenom" @@ -13,13 +14,13 @@ func (suite *KeeperTestSuite) TestHappyPathBeginAuction() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(1000000)) // retreiving module account - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) @@ -37,13 +38,13 @@ func (suite *KeeperTestSuite) TestAuctionFeeBalanceZeroDoesNotStartAuction() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(0)) // retreiving module account - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) @@ -58,13 +59,13 @@ func (suite *KeeperTestSuite) TestAuctionUnauthorizedFundingModule() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(1000000)) // retreiving module account - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) @@ -82,13 +83,13 @@ func (suite *KeeperTestSuite) TestAuctionUnauthorizedProceedsModule() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(1000000)) // retreiving module account - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) @@ -106,13 +107,13 @@ func (suite *KeeperTestSuite) TestAuctionNonPanicError() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(1000000)) // retreiving module account - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) @@ -130,7 +131,7 @@ func (suite *KeeperTestSuite) TestAuctionAlreadyActive() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - params := cellarfeesTypes.DefaultParams() + params := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, params) fees := sdk.NewCoin(feeDenom, sdk.NewInt(1000000)) diff --git a/x/cellarfees/keeper/cellarfees_test.go b/x/cellarfees/keeper/cellarfees_test.go new file mode 100644 index 000000000..608ef8fa8 --- /dev/null +++ b/x/cellarfees/keeper/cellarfees_test.go @@ -0,0 +1,78 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + accounttypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/peggyjv/sommelier/v7/app/params" + auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" +) + +func (suite *KeeperTestSuite) TestGetFeesAccount() { + ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper + require := suite.Require() + + expectedAddress := "somm1hqf42j6zxfnth4xpdse05wpnjjrgc864vwujxx" + account := accounttypes.ModuleAccount{ + Name: cellarfeestypes.ModuleName, + BaseAccount: accounttypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32(expectedAddress)), + } + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(&account) + + address := cellarfeesKeeper.GetFeesAccount(ctx).GetAddress().String() + + require.Equal(expectedAddress, address) +} + +func (suite *KeeperTestSuite) TestGetFeeBalance() { + ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper + require := suite.Require() + + expectedDenom := "testdenom" + expectedBalance := sdk.NewCoin(expectedDenom, sdk.NewInt(1000000)) + account := accounttypes.ModuleAccount{ + Name: cellarfeestypes.ModuleName, + BaseAccount: accounttypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32("somm1hqf42j6zxfnth4xpdse05wpnjjrgc864vwujxx")), + } + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(&account) + suite.bankKeeper.EXPECT().GetBalance(ctx, account.GetAddress(), expectedDenom).Return(expectedBalance) + + balance := cellarfeesKeeper.GetFeeBalance(ctx, expectedDenom) + + require.Equal(expectedBalance, balance) +} + +func (suite *KeeperTestSuite) TestGetBalanceUsdValue() { + ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper + require := suite.Require() + + balance := sdk.NewCoin("testdenom", sdk.NewInt(1000000)) + usdPrice := sdk.NewDec(100) + tokenPrice := &auctiontypes.TokenPrice{ + Exponent: 6, + UsdPrice: usdPrice, + } + + expectedUsdValue := usdPrice.Mul(sdk.NewDecFromInt(balance.Amount).Quo(sdk.NewDec(10).Power(tokenPrice.Exponent))) + usdValue := cellarfeesKeeper.GetBalanceUsdValue(ctx, balance, tokenPrice) + + require.Equal(expectedUsdValue, usdValue) +} + +func (suite *KeeperTestSuite) TestGetEmission() { + ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper + require := suite.Require() + + remainingRewardsSupply := sdk.NewInt(1000000) + previousSupplyPeak := sdk.NewInt(500000) + cellarfeesParams := cellarfeestypesv2.DefaultParams() + cellarfeesParams.RewardEmissionPeriod = 10 + cellarfeesKeeper.SetParams(ctx, cellarfeesParams) + cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, previousSupplyPeak) + + expectedEmissionAmount := remainingRewardsSupply.Quo(sdk.NewInt(int64(cellarfeesParams.RewardEmissionPeriod))) + emission := cellarfeesKeeper.GetEmission(ctx, remainingRewardsSupply) + + require.Equal(sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, expectedEmissionAmount)), emission) +} diff --git a/x/cellarfees/keeper/genesis_test.go b/x/cellarfees/keeper/genesis_test.go index f48e2a3e5..dffbac8f1 100644 --- a/x/cellarfees/keeper/genesis_test.go +++ b/x/cellarfees/keeper/genesis_test.go @@ -2,52 +2,37 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) func (suite *KeeperTestSuite) TestImportingEmptyGenesis() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - testGenesis := cellarfeesTypes.GenesisState{} + testGenesis := cellarfeestypesv2.GenesisState{} // Canary to make sure validate basic is being run require.Panics(func() { cellarfeesKeeper.InitGenesis(ctx, testGenesis) }) - testGenesis = cellarfeesTypes.DefaultGenesisState() + testGenesis = cellarfeestypesv2.DefaultGenesisState() require.NotPanics(func() { suite.accountKeeper.EXPECT().GetModuleAccount(ctx, feesAccount.GetName()).Return(feesAccount) cellarfeesKeeper.InitGenesis(ctx, testGenesis) }) - require.Len(cellarfeesKeeper.GetFeeAccrualCounters(ctx).Counters, 0) require.Zero(cellarfeesKeeper.GetLastRewardSupplyPeak(ctx).Int64()) - require.Equal(cellarfeesKeeper.GetParams(ctx), cellarfeesTypes.DefaultParams()) + require.Equal(cellarfeesKeeper.GetParams(ctx), cellarfeestypesv2.DefaultParams()) } func (suite *KeeperTestSuite) TestImportingPopulatedGenesis() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - testGenesis := cellarfeesTypes.GenesisState{} + testGenesis := cellarfeestypesv2.GenesisState{} // Canary to make sure validate basic is being run require.Panics(func() { cellarfeesKeeper.InitGenesis(ctx, testGenesis) }) - - testGenesis.FeeAccrualCounters = cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: "denom1", - Count: 2, - }, - { - Denom: "denom2", - Count: 0, - }, - }, - } testGenesis.LastRewardSupplyPeak = sdk.NewInt(1337) - testGenesis.Params.FeeAccrualAuctionThreshold = 2 testGenesis.Params.InitialPriceDecreaseRate = sdk.MustNewDecFromStr("0.01") testGenesis.Params.PriceDecreaseBlockInterval = 10 testGenesis.Params.RewardEmissionPeriod = 600 @@ -58,7 +43,6 @@ func (suite *KeeperTestSuite) TestImportingPopulatedGenesis() { cellarfeesKeeper.InitGenesis(ctx, testGenesis) }) - require.Equal(testGenesis.FeeAccrualCounters, cellarfeesKeeper.GetFeeAccrualCounters(ctx)) require.Equal(testGenesis.LastRewardSupplyPeak, cellarfeesKeeper.GetLastRewardSupplyPeak(ctx)) require.Equal(testGenesis.Params, cellarfeesKeeper.GetParams(ctx)) } @@ -67,42 +51,26 @@ func (suite *KeeperTestSuite) TestExportingEmptyGenesis() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - cellarfeesKeeper.SetParams(ctx, cellarfeesTypes.DefaultParams()) - cellarfeesKeeper.SetFeeAccrualCounters(ctx, cellarfeesTypes.DefaultFeeAccrualCounters()) + cellarfeesKeeper.SetParams(ctx, cellarfeestypesv2.DefaultParams()) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, sdk.ZeroInt()) - require.Equal(cellarfeesTypes.DefaultGenesisState(), cellarfeesKeeper.ExportGenesis(ctx)) + require.Equal(cellarfeestypesv2.DefaultGenesisState(), cellarfeesKeeper.ExportGenesis(ctx)) } func (suite *KeeperTestSuite) TestExportingPopulatedGenesis() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() - var params cellarfeesTypes.Params - params.FeeAccrualAuctionThreshold = 2 + var params cellarfeestypesv2.Params params.InitialPriceDecreaseRate = sdk.MustNewDecFromStr("0.01") params.PriceDecreaseBlockInterval = 10 params.RewardEmissionPeriod = 600 params.AuctionInterval = 1000 cellarfeesKeeper.SetParams(ctx, params) - counters := cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: "denom1", - Count: 2, - }, - { - Denom: "denom2", - Count: 0, - }, - }, - } - cellarfeesKeeper.SetFeeAccrualCounters(ctx, counters) peak := sdk.NewInt(1337) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, peak) export := cellarfeesKeeper.ExportGenesis(ctx) require.Equal(params, export.Params) - require.Equal(counters, export.FeeAccrualCounters) require.Equal(peak, export.LastRewardSupplyPeak) } diff --git a/x/cellarfees/keeper/keeper_test.go b/x/cellarfees/keeper/keeper_test.go index 17b90cd2c..69aa2b2f4 100644 --- a/x/cellarfees/keeper/keeper_test.go +++ b/x/cellarfees/keeper/keeper_test.go @@ -15,7 +15,8 @@ import ( cellarfeestestutil "github.com/peggyjv/sommelier/v7/x/cellarfees/testutil" moduletestutil "github.com/peggyjv/sommelier/v7/testutil" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" @@ -34,16 +35,15 @@ type KeeperTestSuite struct { bankKeeper *cellarfeestestutil.MockBankKeeper mintKeeper *cellarfeestestutil.MockMintKeeper corkKeeper *cellarfeestestutil.MockCorkKeeper - gravityKeeper *cellarfeestestutil.MockGravityKeeper auctionKeeper *cellarfeestestutil.MockAuctionKeeper - queryClient cellarfeesTypes.QueryClient + queryClient cellarfeestypesv2.QueryClient encCfg moduletestutil.TestEncodingConfig } func (suite *KeeperTestSuite) SetupTest() { - key := sdk.NewKVStoreKey(cellarfeesTypes.StoreKey) + key := sdk.NewKVStoreKey(cellarfeestypes.StoreKey) tkey := sdk.NewTransientStoreKey("transient_test") testCtx := testutil.DefaultContext(key, tkey) ctx := testCtx.WithBlockHeader(tmproto.Header{Height: 5, Time: tmtime.Now()}) @@ -57,7 +57,6 @@ func (suite *KeeperTestSuite) SetupTest() { suite.mintKeeper = cellarfeestestutil.NewMockMintKeeper(ctrl) suite.accountKeeper = cellarfeestestutil.NewMockAccountKeeper(ctrl) suite.corkKeeper = cellarfeestestutil.NewMockCorkKeeper(ctrl) - suite.gravityKeeper = cellarfeestestutil.NewMockGravityKeeper(ctrl) suite.auctionKeeper = cellarfeestestutil.NewMockAuctionKeeper(ctrl) suite.ctx = ctx @@ -68,8 +67,8 @@ func (suite *KeeperTestSuite) SetupTest() { tkey, ) - params.Subspace(cellarfeesTypes.ModuleName) - subSpace, found := params.GetSubspace(cellarfeesTypes.ModuleName) + params.Subspace(cellarfeestypes.ModuleName) + subSpace, found := params.GetSubspace(cellarfeestypes.ModuleName) suite.Assertions.True(found) suite.cellarfeesKeeper = NewKeeper( @@ -80,15 +79,14 @@ func (suite *KeeperTestSuite) SetupTest() { suite.bankKeeper, suite.mintKeeper, suite.corkKeeper, - suite.gravityKeeper, suite.auctionKeeper, ) - cellarfeesTypes.RegisterInterfaces(encCfg.InterfaceRegistry) + cellarfeestypesv2.RegisterInterfaces(encCfg.InterfaceRegistry) queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) - cellarfeesTypes.RegisterQueryServer(queryHelper, suite.cellarfeesKeeper) - queryClient := cellarfeesTypes.NewQueryClient(queryHelper) + cellarfeestypesv2.RegisterQueryServer(queryHelper, suite.cellarfeesKeeper) + queryClient := cellarfeestypesv2.NewQueryClient(queryHelper) suite.queryClient = queryClient suite.encCfg = encCfg @@ -98,16 +96,6 @@ func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } -func (suite *KeeperTestSuite) TestKeeperGettingSettingFeeAccrualCounters() { - ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper - require := suite.Require() - - expected := cellarfeesTypes.DefaultFeeAccrualCounters() - cellarfeesKeeper.SetFeeAccrualCounters(ctx, expected) - - require.Equal(expected, cellarfeesKeeper.GetFeeAccrualCounters(ctx)) -} - func (suite *KeeperTestSuite) TestKeeperGettingSettingLastRewardSupplyPeak() { ctx, cellarfeesKeeper := suite.ctx, suite.cellarfeesKeeper require := suite.Require() @@ -127,7 +115,7 @@ func (suite *KeeperTestSuite) TestGetAPY() { lastPeak := sdk.NewInt(10_000_000) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, lastPeak) - cellarfeesParams := cellarfeesTypes.DefaultParams() + cellarfeesParams := cellarfeestypesv2.DefaultParams() cellarfeesParams.RewardEmissionPeriod = 10 cellarfeesKeeper.SetParams(ctx, cellarfeesParams) suite.mintKeeper.EXPECT().GetParams(ctx).Return(minttypes.Params{ diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index cf01d1f82..d15944648 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -87,7 +87,8 @@ func (k Keeper) QueryFeeTokenBalances(c context.Context, _ *types.QueryFeeTokenB // because we can't get a USD value without a corresponding TokenPrice set in the auction module, // this exclude fee token balances that don't have one yet. - for _, tokenPrice := range k.auctionKeeper.GetTokenPrices(ctx) { + tokenPrices := k.auctionKeeper.GetTokenPrices(ctx) + for _, tokenPrice := range tokenPrices { balance := k.GetFeeBalance(ctx, tokenPrice.Denom) if balance.IsZero() { diff --git a/x/cellarfees/keeper/query_server_test.go b/x/cellarfees/keeper/query_server_test.go index f4cb0c143..b1240cecc 100644 --- a/x/cellarfees/keeper/query_server_test.go +++ b/x/cellarfees/keeper/query_server_test.go @@ -2,10 +2,15 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" "github.com/golang/mock/gomock" "github.com/peggyjv/sommelier/v7/app/params" - cellarfeesTypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) func (suite *KeeperTestSuite) TestQueriesHappyPath() { @@ -13,47 +18,27 @@ func (suite *KeeperTestSuite) TestQueriesHappyPath() { require := suite.Require() // mock - suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeesTypes.ModuleName).Return(feesAccount) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) - cellarfeesParams := cellarfeesTypes.DefaultParams() + cellarfeesParams := cellarfeestypesv2.DefaultParams() cellarfeesKeeper.SetParams(ctx, cellarfeesParams) expectedLastRewardSupplyPeakAmount := sdk.NewInt(25000) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, expectedLastRewardSupplyPeakAmount) - - expectedFeeAccrualCounters := cellarfeesTypes.FeeAccrualCounters{ - Counters: []cellarfeesTypes.FeeAccrualCounter{ - { - Denom: "denom1", - Count: 2, - }, - { - Denom: "denom2", - Count: 0, - }, - }, - } - cellarfeesKeeper.SetFeeAccrualCounters(ctx, expectedFeeAccrualCounters) - // QueryParams - paramsResponse, err := cellarfeesKeeper.QueryParams(sdk.WrapSDKContext(ctx), &cellarfeesTypes.QueryParamsRequest{}) + paramsResponse, err := cellarfeesKeeper.QueryParams(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryParamsRequest{}) require.Nil(err) - require.Equal(&cellarfeesTypes.QueryParamsResponse{Params: cellarfeesParams}, paramsResponse) + require.Equal(&cellarfeestypesv2.QueryParamsResponse{Params: cellarfeesParams}, paramsResponse) // QueryModuleAccounts - moduleAccountsResponse, err := cellarfeesKeeper.QueryModuleAccounts(sdk.WrapSDKContext(ctx), &cellarfeesTypes.QueryModuleAccountsRequest{}) + moduleAccountsResponse, err := cellarfeesKeeper.QueryModuleAccounts(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryModuleAccountsRequest{}) require.Nil(err) - require.Equal(&cellarfeesTypes.QueryModuleAccountsResponse{FeesAddress: feesAccount.GetAddress().String()}, moduleAccountsResponse) + require.Equal(&cellarfeestypesv2.QueryModuleAccountsResponse{FeesAddress: feesAccount.GetAddress().String()}, moduleAccountsResponse) // QueryLastRewardSupplyPeak - lastRewardSupplyPeakResponse, err := cellarfeesKeeper.QueryLastRewardSupplyPeak(sdk.WrapSDKContext(ctx), &cellarfeesTypes.QueryLastRewardSupplyPeakRequest{}) + lastRewardSupplyPeakResponse, err := cellarfeesKeeper.QueryLastRewardSupplyPeak(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryLastRewardSupplyPeakRequest{}) require.Nil(err) - require.Equal(&cellarfeesTypes.QueryLastRewardSupplyPeakResponse{LastRewardSupplyPeak: expectedLastRewardSupplyPeakAmount}, lastRewardSupplyPeakResponse) - - // QueryFeeAccrualCounters - feeAccrualCountersResponse, err := cellarfeesKeeper.QueryFeeAccrualCounters(sdk.WrapSDKContext(ctx), &cellarfeesTypes.QueryFeeAccrualCountersRequest{}) - require.Nil(err) - require.Equal(&cellarfeesTypes.QueryFeeAccrualCountersResponse{FeeAccrualCounters: expectedFeeAccrualCounters}, feeAccrualCountersResponse) + require.Equal(&cellarfeestypesv2.QueryLastRewardSupplyPeakResponse{LastRewardSupplyPeak: expectedLastRewardSupplyPeakAmount}, lastRewardSupplyPeakResponse) // QueryAPY blocksPerYear := 365 * 6 @@ -74,9 +59,83 @@ func (suite *KeeperTestSuite) TestQueriesHappyPath() { suite.mintKeeper.EXPECT().BondedRatio(ctx).Return(bondedRatio) suite.mintKeeper.EXPECT().StakingTokenSupply(ctx).Return(stakingTotalSupply) - APYResult, err := cellarfeesKeeper.QueryAPY(sdk.WrapSDKContext(ctx), &cellarfeesTypes.QueryAPYRequest{}) + APYResult, err := cellarfeesKeeper.QueryAPY(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryAPYRequest{}) require.Nil(err) require.Equal("0.004380000000000000", APYResult.Apy) + + // QueryFeeTokenBalance + denom := "testdenom" + amount := sdk.NewInt(1000000) + suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, true) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(1) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom).Return(auctiontypes.TokenPrice{ + Exponent: 6, + UsdPrice: sdk.NewDec(100), + }, true) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom).Return(sdk.NewCoin(denom, amount)) + + expectedFeeTokenBalance := cellarfeestypesv2.FeeTokenBalance{ + Balance: sdk.NewCoin(denom, amount), + UsdValue: 100.00, + } + feeTokenBalanceResponse, err := cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{ + Denom: denom, + }) + require.Nil(err) + require.Equal(&expectedFeeTokenBalance, feeTokenBalanceResponse.Balance) + + // QueryFeeTokenBalances + suite.SetupTest() + ctx, cellarfeesKeeper = suite.ctx, suite.cellarfeesKeeper + denom1 := "testdenom1" + denom2 := "testdenom2" + denom3 := "testdenom3" + amount1 := sdk.NewInt(1000000) + amount2 := sdk.NewInt(2000000) + amount3 := sdk.NewInt(3000000) + balance1 := sdk.NewCoin(denom1, amount1) + balance2 := sdk.NewCoin(denom2, amount2) + balance3 := sdk.NewCoin(denom3, amount3) + tokenPrice1 := auctiontypes.TokenPrice{ + Exponent: 6, + UsdPrice: sdk.NewDec(100), + Denom: denom1, + } + tokenPrice2 := auctiontypes.TokenPrice{ + Exponent: 12, + UsdPrice: sdk.NewDec(50), + Denom: denom2, + } + tokenPrice3 := auctiontypes.TokenPrice{ + Exponent: 18, + UsdPrice: sdk.NewDec(25), + Denom: denom3, + } + tokenPrices := []*auctiontypes.TokenPrice{&tokenPrice1, &tokenPrice2, &tokenPrice3} + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(3) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom1).Return(balance1) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom2).Return(balance2) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom3).Return(balance3) + suite.auctionKeeper.EXPECT().GetTokenPrices(ctx).Return(tokenPrices) + + expectedFeeTokenBalances := []*cellarfeestypesv2.FeeTokenBalance{ + { + Balance: balance1, + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance1, &tokenPrice1).MustFloat64(), + }, + { + Balance: balance2, + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance2, &tokenPrice2).MustFloat64(), + }, + { + Balance: balance3, + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance3, &tokenPrice3).MustFloat64(), + }, + } + + feeTokenBalancesResponse, err := cellarfeesKeeper.QueryFeeTokenBalances(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalancesRequest{}) + require.Nil(err) + require.Equal(expectedFeeTokenBalances, feeTokenBalancesResponse.Balances) } func (suite *KeeperTestSuite) TestQueriesUnhappyPath() { @@ -98,8 +157,30 @@ func (suite *KeeperTestSuite) TestQueriesUnhappyPath() { require.Nil(lastRewardSupplyPeakResponse) require.NotNil(err) - // QueryFeeAccrualCounters - feeAccrualCountersResponse, err := cellarfeesKeeper.QueryFeeAccrualCounters(sdk.WrapSDKContext(ctx), nil) - require.Nil(feeAccrualCountersResponse) + // QueryFeeTokenBalance + feeTokenBalanceResponse, err := cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), nil) + require.Nil(feeTokenBalanceResponse) + require.NotNil(err) + require.Equal(status.Code(err), codes.InvalidArgument) + + feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{}) + require.Nil(feeTokenBalanceResponse) + require.NotNil(err) + require.Equal(status.Code(err), codes.InvalidArgument) + + denom := "testdenom" + suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, false) + feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: "testdenom"}) + require.Nil(feeTokenBalanceResponse) + require.NotNil(err) + require.Equal(status.Code(err), codes.NotFound) + + suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, true) + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, gomock.Any()).Return(feesAccount) + suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom).Return(sdk.NewCoin(denom, sdk.NewInt(1000000))) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom).Return(auctiontypes.TokenPrice{}, false) + feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: denom}) + require.Nil(feeTokenBalanceResponse) require.NotNil(err) + require.Equal(status.Code(err), codes.NotFound) } diff --git a/x/cellarfees/testutil/expected_keepers_mocks.go b/x/cellarfees/testutil/expected_keepers_mocks.go index e38696d5b..3ea8d6a1f 100644 --- a/x/cellarfees/testutil/expected_keepers_mocks.go +++ b/x/cellarfees/testutil/expected_keepers_mocks.go @@ -7,12 +7,14 @@ package mock_types import ( reflect "reflect" + math "cosmossdk.io/math" types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/auth/types" - types1 "github.com/cosmos/cosmos-sdk/x/mint/types" + types1 "github.com/cosmos/cosmos-sdk/x/bank/types" + types2 "github.com/cosmos/cosmos-sdk/x/mint/types" common "github.com/ethereum/go-ethereum/common" gomock "github.com/golang/mock/gomock" - types2 "github.com/peggyjv/sommelier/v7/x/auction/types" + types3 "github.com/peggyjv/sommelier/v7/x/auction/types" ) // MockAccountKeeper is a mock of AccountKeeper interface. @@ -145,6 +147,21 @@ func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBalance", reflect.TypeOf((*MockBankKeeper)(nil).GetBalance), ctx, addr, denom) } +// GetDenomMetaData mocks base method. +func (m *MockBankKeeper) GetDenomMetaData(ctx types.Context, denom string) (types1.Metadata, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDenomMetaData", ctx, denom) + ret0, _ := ret[0].(types1.Metadata) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetDenomMetaData indicates an expected call of GetDenomMetaData. +func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDenomMetaData", reflect.TypeOf((*MockBankKeeper)(nil).GetDenomMetaData), ctx, denom) +} + // LockedCoins mocks base method. func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins { m.ctrl.T.Helper() @@ -266,44 +283,6 @@ func (mr *MockCorkKeeperMockRecorder) HasCellarID(ctx, address interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasCellarID", reflect.TypeOf((*MockCorkKeeper)(nil).HasCellarID), ctx, address) } -// MockGravityKeeper is a mock of GravityKeeper interface. -type MockGravityKeeper struct { - ctrl *gomock.Controller - recorder *MockGravityKeeperMockRecorder -} - -// MockGravityKeeperMockRecorder is the mock recorder for MockGravityKeeper. -type MockGravityKeeperMockRecorder struct { - mock *MockGravityKeeper -} - -// NewMockGravityKeeper creates a new mock instance. -func NewMockGravityKeeper(ctrl *gomock.Controller) *MockGravityKeeper { - mock := &MockGravityKeeper{ctrl: ctrl} - mock.recorder = &MockGravityKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGravityKeeper) EXPECT() *MockGravityKeeperMockRecorder { - return m.recorder -} - -// ERC20ToDenomLookup mocks base method. -func (m *MockGravityKeeper) ERC20ToDenomLookup(ctx types.Context, tokenContract common.Address) (bool, string) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ERC20ToDenomLookup", ctx, tokenContract) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(string) - return ret0, ret1 -} - -// ERC20ToDenomLookup indicates an expected call of ERC20ToDenomLookup. -func (mr *MockGravityKeeperMockRecorder) ERC20ToDenomLookup(ctx, tokenContract interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ERC20ToDenomLookup", reflect.TypeOf((*MockGravityKeeper)(nil).ERC20ToDenomLookup), ctx, tokenContract) -} - // MockAuctionKeeper is a mock of AuctionKeeper interface. type MockAuctionKeeper struct { ctrl *gomock.Controller @@ -342,10 +321,10 @@ func (mr *MockAuctionKeeperMockRecorder) BeginAuction(ctx, startingTokensForSale } // GetActiveAuctions mocks base method. -func (m *MockAuctionKeeper) GetActiveAuctions(ctx types.Context) []*types2.Auction { +func (m *MockAuctionKeeper) GetActiveAuctions(ctx types.Context) []*types3.Auction { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetActiveAuctions", ctx) - ret0, _ := ret[0].([]*types2.Auction) + ret0, _ := ret[0].([]*types3.Auction) return ret0 } @@ -355,6 +334,35 @@ func (mr *MockAuctionKeeperMockRecorder) GetActiveAuctions(ctx interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetActiveAuctions", reflect.TypeOf((*MockAuctionKeeper)(nil).GetActiveAuctions), ctx) } +// GetTokenPrice mocks base method. +func (m *MockAuctionKeeper) GetTokenPrice(ctx types.Context, denom string) (types3.TokenPrice, bool) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTokenPrice", ctx, denom) + ret0, _ := ret[0].(types3.TokenPrice) + ret1, _ := ret[1].(bool) + return ret0, ret1 +} + +// GetTokenPrice indicates an expected call of GetTokenPrice. +func (mr *MockAuctionKeeperMockRecorder) GetTokenPrice(ctx, denom interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenPrice", reflect.TypeOf((*MockAuctionKeeper)(nil).GetTokenPrice), ctx, denom) +} + +// GetTokenPrices mocks base method. +func (m *MockAuctionKeeper) GetTokenPrices(ctx types.Context) []*types3.TokenPrice { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTokenPrices", ctx) + ret0, _ := ret[0].([]*types3.TokenPrice) + return ret0 +} + +// GetTokenPrices indicates an expected call of GetTokenPrices. +func (mr *MockAuctionKeeperMockRecorder) GetTokenPrices(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTokenPrices", reflect.TypeOf((*MockAuctionKeeper)(nil).GetTokenPrices), ctx) +} + // MockMintKeeper is a mock of MintKeeper interface. type MockMintKeeper struct { ctrl *gomock.Controller @@ -393,10 +401,10 @@ func (mr *MockMintKeeperMockRecorder) BondedRatio(ctx interface{}) *gomock.Call } // GetParams mocks base method. -func (m *MockMintKeeper) GetParams(ctx types.Context) types1.Params { +func (m *MockMintKeeper) GetParams(ctx types.Context) types2.Params { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetParams", ctx) - ret0, _ := ret[0].(types1.Params) + ret0, _ := ret[0].(types2.Params) return ret0 } @@ -407,10 +415,10 @@ func (mr *MockMintKeeperMockRecorder) GetParams(ctx interface{}) *gomock.Call { } // StakingTokenSupply mocks base method. -func (m *MockMintKeeper) StakingTokenSupply(ctx types.Context) types.Int { +func (m *MockMintKeeper) StakingTokenSupply(ctx types.Context) math.Int { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StakingTokenSupply", ctx) - ret0, _ := ret[0].(types.Int) + ret0, _ := ret[0].(math.Int) return ret0 } From a62b45a3e5d77f2085ce2f4b024df61448cfd1bd Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 15:01:25 -0600 Subject: [PATCH 13/28] Remove empty file --- x/cellarfees/types/v2/cellarfees_test.go | 1 - 1 file changed, 1 deletion(-) delete mode 100644 x/cellarfees/types/v2/cellarfees_test.go diff --git a/x/cellarfees/types/v2/cellarfees_test.go b/x/cellarfees/types/v2/cellarfees_test.go deleted file mode 100644 index 5ec3cc8e8..000000000 --- a/x/cellarfees/types/v2/cellarfees_test.go +++ /dev/null @@ -1 +0,0 @@ -package v2 From a42def9197793281740252e15381a37d88cdc835 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 15:07:01 -0600 Subject: [PATCH 14/28] Fix broken unit tests and compiler errors --- x/cellarfees/keeper/genesis_test.go | 2 ++ x/cellarfees/types/v1/params.go | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 x/cellarfees/types/v1/params.go diff --git a/x/cellarfees/keeper/genesis_test.go b/x/cellarfees/keeper/genesis_test.go index dffbac8f1..c49f29140 100644 --- a/x/cellarfees/keeper/genesis_test.go +++ b/x/cellarfees/keeper/genesis_test.go @@ -37,6 +37,7 @@ func (suite *KeeperTestSuite) TestImportingPopulatedGenesis() { testGenesis.Params.PriceDecreaseBlockInterval = 10 testGenesis.Params.RewardEmissionPeriod = 600 testGenesis.Params.AuctionInterval = 1000 + testGenesis.Params.AuctionThresholdUsdValue = sdk.NewDec(1000000) require.NotPanics(func() { suite.accountKeeper.EXPECT().GetModuleAccount(ctx, feesAccount.GetName()).Return(feesAccount) @@ -66,6 +67,7 @@ func (suite *KeeperTestSuite) TestExportingPopulatedGenesis() { params.PriceDecreaseBlockInterval = 10 params.RewardEmissionPeriod = 600 params.AuctionInterval = 1000 + params.AuctionThresholdUsdValue = sdk.NewDec(1000000) cellarfeesKeeper.SetParams(ctx, params) peak := sdk.NewInt(1337) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, peak) diff --git a/x/cellarfees/types/v1/params.go b/x/cellarfees/types/v1/params.go new file mode 100644 index 000000000..1d9ee1bc3 --- /dev/null +++ b/x/cellarfees/types/v1/params.go @@ -0,0 +1,10 @@ +package v1 + +import "gopkg.in/yaml.v2" + +// String implements the String interface +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + From 2abf19fa057f7c73bfc2e8735b137e2db1dc484c Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 15:09:28 -0600 Subject: [PATCH 15/28] gofmt --- x/cellarfees/keeper/genesis_test.go | 4 ++-- x/cellarfees/types/v1/params.go | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/x/cellarfees/keeper/genesis_test.go b/x/cellarfees/keeper/genesis_test.go index c49f29140..dfce65b31 100644 --- a/x/cellarfees/keeper/genesis_test.go +++ b/x/cellarfees/keeper/genesis_test.go @@ -37,7 +37,7 @@ func (suite *KeeperTestSuite) TestImportingPopulatedGenesis() { testGenesis.Params.PriceDecreaseBlockInterval = 10 testGenesis.Params.RewardEmissionPeriod = 600 testGenesis.Params.AuctionInterval = 1000 - testGenesis.Params.AuctionThresholdUsdValue = sdk.NewDec(1000000) + testGenesis.Params.AuctionThresholdUsdValue = sdk.NewDec(1000000) require.NotPanics(func() { suite.accountKeeper.EXPECT().GetModuleAccount(ctx, feesAccount.GetName()).Return(feesAccount) @@ -67,7 +67,7 @@ func (suite *KeeperTestSuite) TestExportingPopulatedGenesis() { params.PriceDecreaseBlockInterval = 10 params.RewardEmissionPeriod = 600 params.AuctionInterval = 1000 - params.AuctionThresholdUsdValue = sdk.NewDec(1000000) + params.AuctionThresholdUsdValue = sdk.NewDec(1000000) cellarfeesKeeper.SetParams(ctx, params) peak := sdk.NewInt(1337) cellarfeesKeeper.SetLastRewardSupplyPeak(ctx, peak) diff --git a/x/cellarfees/types/v1/params.go b/x/cellarfees/types/v1/params.go index 1d9ee1bc3..7f383094a 100644 --- a/x/cellarfees/types/v1/params.go +++ b/x/cellarfees/types/v1/params.go @@ -7,4 +7,3 @@ func (p Params) String() string { out, _ := yaml.Marshal(p) return string(out) } - From d49043abfd2853a6a6ade6dfa077c2dc7050223d Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 5 Mar 2024 17:23:43 -0600 Subject: [PATCH 16/28] WIP - fix integration tests --- integration_tests/cellarfees_test.go | 118 +-------------------------- integration_tests/setup_test.go | 17 ++-- 2 files changed, 9 insertions(+), 126 deletions(-) diff --git a/integration_tests/cellarfees_test.go b/integration_tests/cellarfees_test.go index 308d921cd..508378dcf 100644 --- a/integration_tests/cellarfees_test.go +++ b/integration_tests/cellarfees_test.go @@ -8,11 +8,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" - cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" ) @@ -31,7 +29,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { auctionQueryClient := auctiontypes.NewQueryClient(clientCtx) bankQueryClient := banktypes.NewQueryClient(clientCtx) - cellarfeesQueryClient := cellarfeestypes.NewQueryClient(clientCtx) + cellarfeesQueryClient := cellarfeestypesv2.NewQueryClient(clientCtx) corkQueryClient := corktypes.NewQueryClient(clientCtx) distQueryClient := disttypes.NewQueryClient(clientCtx) @@ -52,7 +50,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() - acctsRes, err := cellarfeesQueryClient.QueryModuleAccounts(ctx, &cellarfeestypes.QueryModuleAccountsRequest{}) + acctsRes, err := cellarfeesQueryClient.QueryModuleAccounts(ctx, &cellarfeestypesv2.QueryModuleAccountsRequest{}) s.Require().NoError(err, "Failed to query module accounts") feesAddress := acctsRes.FeesAddress @@ -63,116 +61,6 @@ func (s *IntegrationTestSuite) TestCellarFees() { }) s.Require().NoError(err, "Failed to query fee balance of denom %s", alphaERC20Contract.Hex()) s.Require().Zero(balanceRes.Balance.Amount.Uint64()) - balanceRes, err = bankQueryClient.Balance(ctx, &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: fmt.Sprintf("gravity%s", betaERC20Contract.Hex()), - }) - s.Require().NoError(err, "Failed to query fee balance of denom %s", betaERC20Contract.Hex()) - s.Require().Zero(balanceRes.Balance.Amount.Uint64()) - - s.T().Logf("Approving Gravity to spend Alpha ERC20") - approveData := PackApproveERC20(gravityContract) - err = SendEthTransaction(ethClient, &val.ethereumKey, alphaERC20Contract, approveData) - s.Require().NoError(err, "Error approving spending ALPHA balance for the gravity contract on behalf of the first validator") - - s.T().Logf("Approving Gravity to spend Beta ERC20") - approveData = PackApproveERC20(gravityContract) - err = SendEthTransaction(ethClient, &val.ethereumKey, betaERC20Contract, approveData) - s.Require().NoError(err, "Error approving spending BETA balance for the gravity contract on behalf of the first validator") - - s.T().Logf("Waiting for allowance confirmations..") - data := PackAllowance(common.HexToAddress(ethereumSender), gravityContract) - s.Require().Eventually(func() bool { - res, _ := ethClient.CallContract(context.Background(), ethereum.CallMsg{ - From: common.HexToAddress(ethereumSender), - To: &alphaERC20Contract, - Gas: 0, - Data: data, - }, nil) - - allowance := UnpackEthUInt(res).BigInt() - s.T().Logf("Allowance: %v", allowance) - - return sdk.NewIntFromBigInt(allowance).GT(sdk.ZeroInt()) - }, time.Second*10, time.Second, "AlphaERC20 allowance not found") - - data = PackAllowance(common.HexToAddress(ethereumSender), gravityContract) - s.Require().Eventually(func() bool { - res, _ := ethClient.CallContract(context.Background(), ethereum.CallMsg{ - From: common.HexToAddress(ethereumSender), - To: &betaERC20Contract, - Gas: 0, - Data: data, - }, nil) - - allowance := UnpackEthUInt(res).BigInt() - s.T().Logf("Allowance: %v", allowance) - - return sdk.NewIntFromBigInt(allowance).GT(sdk.ZeroInt()) - }, time.Second*10, time.Second, "BetaERC20 allowance not found") - - s.T().Log("Sending ALPHA fees to cellarfees module account") - acc, err := sdk.AccAddressFromBech32(feesAddress) - s.Require().NoError(err, "Failed to derive fees account address from bech32 string: %s", feesAddress) - sendData := PackSendToCosmos(alphaERC20Contract, acc, sdk.NewInt(50000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - s.T().Log("Sending BETA fees to cellarfees module account") - acc, err = sdk.AccAddressFromBech32(feesAddress) - s.Require().NoError(err, "Failed to derive fees account address from bech32 string: %s", feesAddress) - sendData = PackSendToCosmos(betaERC20Contract, acc, sdk.NewInt(20000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - s.T().Log("Waiting for fees to be received...") - s.Require().Eventually(func() bool { - res, err := bankQueryClient.Balance(context.Background(), - &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: alphaFeeDenom, - }) - s.Require().NoError(err) - s.T().Logf("fee balance: %s", res.Balance) - - return res.Balance.Amount.GT(sdk.ZeroInt()) - }, time.Second*60, time.Second*6, "ALPHA Fees never received by cellarfees account") - - s.Require().Eventually(func() bool { - res, err := bankQueryClient.Balance(context.Background(), - &banktypes.QueryBalanceRequest{ - Address: feesAddress, - Denom: betaFeeDenom, - }) - s.Require().NoError(err) - s.T().Logf("fee balance: %s", res.Balance) - - return res.Balance.Amount.GT(sdk.ZeroInt()) - }, time.Second*60, time.Second*6, "BETA Fees never received by cellarfees account") - - s.T().Log("Fees received! Confirming no auction gets started yet...") - for i := 0; i < 10; i++ { - res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) - if res == nil { - continue - } - - for _, auction := range res.Auctions { - s.Require().NotEqual(auction.StartingTokensForSale.Denom, alphaFeeDenom) - s.Require().NotEqual(auction.StartingTokensForSale.Denom, betaFeeDenom) - } - - time.Sleep(time.Second) - } - - s.T().Log("Sending ERC20 fees a second time") - sendData = PackSendToCosmos(alphaERC20Contract, acc, sdk.NewInt(100000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - - sendData = PackSendToCosmos(betaERC20Contract, acc, sdk.NewInt(120000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") s.T().Log("Waiting for auctions to start") alphaAuctionID, betaAuctionID := uint32(0), uint32(0) diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index 47dac1a0d..3f771bda8 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -22,6 +22,7 @@ import ( auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" axelarcorktypes "github.com/peggyjv/sommelier/v7/x/axelarcork/types" cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" corktypesunversioned "github.com/peggyjv/sommelier/v7/x/cork/types" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" pubsubtypes "github.com/peggyjv/sommelier/v7/x/pubsub/types" @@ -69,6 +70,7 @@ pohf4PJrfacqpi7PoXBk -----END CERTIFICATE----- ` axelarSweepDenom = "sweep" + ibcDenom = "ibc/1" ) var ( @@ -79,7 +81,7 @@ var ( gravityContract = common.HexToAddress("0x04C89607413713Ec9775E14b954286519d836FEf") counterContract = common.HexToAddress("0x0000000000000000000000000000000000000000") alphaERC20Contract = common.HexToAddress("0x0000000000000000000000000000000000000000") - betaERC20Contract = common.HexToAddress("0x0000000000000000000000000000000000000000") + alphaERC20Denom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) unusedGenesisContract = common.HexToAddress("0x0000000000000000000000000000000000000001") alphaFeeDenom = "" @@ -408,7 +410,6 @@ func (s *IntegrationTestSuite) initGenesis() { // Add an auction for integration testing of the auction module alphaFeeDenom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) - betaFeeDenom = fmt.Sprintf("gravity%s", betaERC20Contract.Hex()) var auctionGenState auctiontypes.GenesisState s.Require().NoError(cdc.UnmarshalJSON(appGenState[auctiontypes.ModuleName], &auctionGenState)) auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ @@ -417,12 +418,6 @@ func (s *IntegrationTestSuite) initGenesis() { UsdPrice: sdk.MustNewDecFromStr("1.0"), LastUpdatedBlock: 0, }) - auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ - Denom: betaFeeDenom, - Exponent: 6, - UsdPrice: sdk.MustNewDecFromStr("5.0"), - LastUpdatedBlock: 0, - }) auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ Denom: testDenom, Exponent: 6, @@ -463,14 +458,14 @@ func (s *IntegrationTestSuite) initGenesis() { appGenState[axelarcorktypes.ModuleName] = bz // set cellarfees gen state - cellarfeesGenState := cellarfeestypes.DefaultGenesisState() + cellarfeesGenState := cellarfeestypesv2.DefaultGenesisState() s.Require().NoError(cdc.UnmarshalJSON(appGenState[cellarfeestypes.ModuleName], &cellarfeesGenState)) - cellarfeesGenState.Params = cellarfeestypes.Params{ - FeeAccrualAuctionThreshold: 2, + cellarfeesGenState.Params = cellarfeestypesv2.Params{ RewardEmissionPeriod: 100, InitialPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), PriceDecreaseBlockInterval: uint64(1000), AuctionInterval: 50, + AuctionThresholdUsdValue: sdk.MustNewDecFromStr("100.00"), } bz, err = cdc.MarshalJSON(&cellarfeesGenState) s.Require().NoError(err) From 2c5aade19a4339f050fb38f37d12ad4dd942b501 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Wed, 6 Mar 2024 12:18:47 -0600 Subject: [PATCH 17/28] WIP - Integration test updates --- integration_tests/cellarfees_test.go | 35 +++------------------------- integration_tests/setup_test.go | 8 ------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/integration_tests/cellarfees_test.go b/integration_tests/cellarfees_test.go index 508378dcf..61bda8fc3 100644 --- a/integration_tests/cellarfees_test.go +++ b/integration_tests/cellarfees_test.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - "github.com/ethereum/go-ethereum/ethclient" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" @@ -21,9 +20,6 @@ func (s *IntegrationTestSuite) TestCellarFees() { kb, err := val.keyring() s.Require().NoError(err) - ethClient, err := ethclient.Dial(fmt.Sprintf("http://%s", s.ethResource.GetHostPort("8545/tcp"))) - s.Require().NoError(err) - clientCtx, err := s.chain.clientContext("tcp://localhost:26657", &kb, "val", val.address()) s.Require().NoError(err) @@ -63,28 +59,19 @@ func (s *IntegrationTestSuite) TestCellarFees() { s.Require().Zero(balanceRes.Balance.Amount.Uint64()) s.T().Log("Waiting for auctions to start") - alphaAuctionID, betaAuctionID := uint32(0), uint32(0) + alphaAuctionID := uint32(0) s.Require().Eventually(func() bool { res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) - alpha, beta := false, false if res != nil { for _, auction := range res.Auctions { if auction.StartingTokensForSale.Denom == alphaFeeDenom { - alphaAuctionID = auction.Id - alpha = true - } else if auction.StartingTokensForSale.Denom == betaFeeDenom { - betaAuctionID = auction.Id - beta = true - } - - if alpha && beta { - break + return true } } } - return alpha && beta + return false }, time.Second*30, time.Second*5, "Auctions never started for test fees") s.T().Log("Bidding to buy all of the ALPHA fees available") @@ -152,17 +139,6 @@ func (s *IntegrationTestSuite) TestCellarFees() { return false }, time.Second*30, time.Millisecond*400, "Distribution rate was invalid or could not be determined") - s.T().Log("Distribution rate is linear. Increasing the reward supply by bidding on the BETA auction") - bidRequest2 := auctiontypes.MsgSubmitBidRequest{ - AuctionId: betaAuctionID, - Signer: orch.address().String(), - MaxBidInUsomm: sdk.NewCoin(testDenom, sdk.NewIntFromUint64(1400000)), - SaleTokenMinimumAmount: sdk.NewCoin(betaFeeDenom, sdk.NewIntFromUint64(140000)), - } - - _, err = s.chain.sendMsgs(*orchClientCtx, &bidRequest2) - s.Require().NoError(err, "Failed to submit bid") - s.T().Log("Waiting to see distribution rate increase") lastBalanceSeen = sdk.ZeroInt() s.Require().Eventually(func() bool { @@ -223,11 +199,6 @@ func (s *IntegrationTestSuite) TestCellarFees() { return res == nil || res.Balance.Amount.Equal(sdk.ZeroInt()) }, time.Second*300, time.Second*10, "Reward supply did not exhaust in the provided amount of time") - s.T().Log("Verify that the accrual counter reset by sending more ALPHA") - sendData = PackSendToCosmos(alphaERC20Contract, acc, sdk.NewInt(25000)) - err = SendEthTransaction(ethClient, &val.ethereumKey, gravityContract, sendData) - s.Require().NoError(err, "Failed to send fees transaction to Cosmos") - s.T().Log("Confirming no auction is started...") for i := 0; i < 20; i++ { res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index 3f771bda8..f2758d173 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -85,7 +85,6 @@ var ( unusedGenesisContract = common.HexToAddress("0x0000000000000000000000000000000000000001") alphaFeeDenom = "" - betaFeeDenom = "" // 67% corkVoteThreshold = sdk.NewDecWithPrec(67, 2) @@ -676,12 +675,6 @@ func (s *IntegrationTestSuite) runEthContainer() { // this is not the last contract deployed continue } - if strings.HasPrefix(s, "betaERC20 contract deployed at") { - strSpl := strings.Split(s, "-") - betaERC20Contract = common.HexToAddress(strings.ReplaceAll(strSpl[1], " ", "")) - // this is not the last contract deployed - continue - } if strings.HasPrefix(s, "counter contract deployed at") { strSpl := strings.Split(s, "-") counterContract = common.HexToAddress(strings.ReplaceAll(strSpl[1], " ", "")) @@ -692,7 +685,6 @@ func (s *IntegrationTestSuite) runEthContainer() { }, time.Minute*5, time.Second*10, "unable to retrieve gravity address from logs") s.T().Logf("gravity contract deployed at %s", gravityContract.String()) s.T().Logf("alphaERC20 contract deployed at %s", alphaERC20Contract.String()) - s.T().Logf("betaERC20 contract deployed at %s", betaERC20Contract.String()) s.T().Logf("counter contract deployed at %s", counterContract.String()) s.T().Logf("started Ethereum container: %s", s.ethResource.Container.ID) } From dc341be15b3575ca8a8285763e7525495a5993c9 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Thu, 7 Mar 2024 10:57:12 -0600 Subject: [PATCH 18/28] Remove auction requirement that denom be prefixed with gravity --- x/auction/keeper/proposal_handler_test.go | 18 +---- x/auction/types/auction.go | 15 ---- x/auction/types/auction_test.go | 91 ++++++++++++++--------- x/auction/types/errors.go | 4 +- x/auction/types/genesis_test.go | 23 +++++- x/auction/types/msgs.go | 6 -- x/auction/types/msgs_test.go | 11 --- 7 files changed, 80 insertions(+), 88 deletions(-) diff --git a/x/auction/keeper/proposal_handler_test.go b/x/auction/keeper/proposal_handler_test.go index 60e72ca6e..82a0580ef 100644 --- a/x/auction/keeper/proposal_handler_test.go +++ b/x/auction/keeper/proposal_handler_test.go @@ -12,7 +12,7 @@ import ( ) // Happy path test for proposal handler -func (suite *KeeperTestSuite) TestHappPathForProposalHandler() { +func (suite *KeeperTestSuite) TestHappyPathForProposalHandler() { ctx, auctionKeeper := suite.ctx, suite.auctionKeeper require := suite.Require() @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestHappPathForProposalHandler() { } // Unhappy path test for proposal handler -func (suite *KeeperTestSuite) TestUnhappPathForProposalHandler() { +func (suite *KeeperTestSuite) TestUnhappyPathForProposalHandler() { ctx, auctionKeeper := suite.ctx, suite.auctionKeeper require := suite.Require() @@ -73,20 +73,6 @@ func (suite *KeeperTestSuite) TestUnhappPathForProposalHandler() { }, expectedError: errorsmod.Wrap(govTypes.ErrInvalidProposalContent, "proposal title cannot be blank"), }, - { - name: "Validate basic canary 2 -- cannot have non usomm & non gravity denom", - proposal: auctionTypes.SetTokenPricesProposal{ - Title: "Title", - Description: "Description", - TokenPrices: []*auctionTypes.ProposedTokenPrice{ - { - Denom: "weth", - UsdPrice: sdk.MustNewDecFromStr("17.0"), - }, - }, - }, - expectedError: errorsmod.Wrapf(auctionTypes.ErrInvalidTokenPriceDenom, "denom: weth"), - }, { name: "Cannot attempt to update prices twice for a denom in one proposal", proposal: auctionTypes.SetTokenPricesProposal{ diff --git a/x/auction/types/auction.go b/x/auction/types/auction.go index dac5c87f6..cd18017a2 100644 --- a/x/auction/types/auction.go +++ b/x/auction/types/auction.go @@ -1,12 +1,9 @@ package types import ( - "strings" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" "github.com/peggyjv/sommelier/v7/app/params" ) @@ -83,10 +80,6 @@ func (b *Bid) ValidateBasic() error { return errorsmod.Wrapf(ErrBidMustBeInUsomm, "bid: %s", b.MaxBidInUsomm.String()) } - if !strings.HasPrefix(b.SaleTokenMinimumAmount.Denom, gravitytypes.GravityDenomPrefix) { - return errorsmod.Wrapf(ErrInvalidTokenBeingBidOn, "sale token: %s", b.SaleTokenMinimumAmount.String()) - } - if !b.SaleTokenMinimumAmount.IsValid() || !b.SaleTokenMinimumAmount.IsPositive() { return errorsmod.Wrapf(ErrMinimumAmountMustBePositive, "sale token amount: %s", b.SaleTokenMinimumAmount.String()) } @@ -123,10 +116,6 @@ func (t *TokenPrice) ValidateBasic() error { return errorsmod.Wrapf(ErrInvalidLastUpdatedBlock, "block: %d", t.LastUpdatedBlock) } - if !strings.HasPrefix(t.Denom, gravitytypes.GravityDenomPrefix) && t.Denom != params.BaseCoinUnit { - return errorsmod.Wrapf(ErrInvalidTokenPriceDenom, "denom: %s", t.Denom) - } - if t.Exponent > 18 { return errorsmod.Wrapf(ErrTokenPriceExponentTooHigh, "exponent: %d", t.Exponent) } @@ -143,10 +132,6 @@ func (t *ProposedTokenPrice) ValidateBasic() error { return errorsmod.Wrapf(ErrPriceMustBePositive, "usd price: %s", t.UsdPrice.String()) } - if !strings.HasPrefix(t.Denom, gravitytypes.GravityDenomPrefix) && t.Denom != params.BaseCoinUnit { - return errorsmod.Wrapf(ErrInvalidTokenPriceDenom, "denom: %s", t.Denom) - } - if t.Exponent > 18 { return errorsmod.Wrapf(ErrTokenPriceExponentTooHigh, "exponent: %d", t.Exponent) } diff --git a/x/auction/types/auction_test.go b/x/auction/types/auction_test.go index 20bdf242c..220c86f1e 100644 --- a/x/auction/types/auction_test.go +++ b/x/auction/types/auction_test.go @@ -23,7 +23,7 @@ func TestAuctionValidate(t *testing.T) { err error }{ { - name: "Happy path", + name: "Happy path 1", auction: Auction{ Id: uint32(1), StartingTokensForSale: sdk.NewCoin("gravity0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", sdk.NewIntFromUint64(1000)), @@ -41,6 +41,25 @@ func TestAuctionValidate(t *testing.T) { expPass: true, err: nil, }, + { + name: "Happy path 2", + auction: Auction{ + Id: uint32(1), + StartingTokensForSale: sdk.NewCoin("ibc/1", sdk.NewIntFromUint64(1000)), + StartBlock: uint64(200), + EndBlock: uint64(0), + InitialPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), + CurrentPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), + PriceDecreaseBlockInterval: uint64(10), + InitialUnitPriceInUsomm: sdk.MustNewDecFromStr("20.0"), + CurrentUnitPriceInUsomm: sdk.MustNewDecFromStr("20.0"), + RemainingTokensForSale: sdk.NewCoin("ibc/1", sdk.NewIntFromUint64(900)), + FundingModuleAccount: "someModule", + ProceedsModuleAccount: "someModule", + }, + expPass: true, + err: nil, + }, { name: "Auction ID cannot be 0", auction: Auction{ @@ -311,7 +330,7 @@ func TestBidValidate(t *testing.T) { err error }{ { - name: "Happy path", + name: "Happy path 1", bid: Bid{ Id: uint64(1), AuctionId: uint32(1), @@ -325,6 +344,21 @@ func TestBidValidate(t *testing.T) { expPass: true, err: nil, }, + { + name: "Happy path 2", + bid: Bid{ + Id: uint64(1), + AuctionId: uint32(1), + Bidder: cosmosAddress2, + MaxBidInUsomm: sdk.NewCoin("usomm", sdk.NewInt(100)), + SaleTokenMinimumAmount: sdk.NewCoin("ibc/1", sdk.NewInt(50)), + TotalFulfilledSaleTokens: sdk.NewCoin("ibc/1", sdk.NewInt(50)), + SaleTokenUnitPriceInUsomm: sdk.MustNewDecFromStr("2.0"), + TotalUsommPaid: sdk.NewCoin("usomm", sdk.NewInt(100)), + }, + expPass: true, + err: nil, + }, { name: "Bid ID cannot be 0", bid: Bid{ @@ -415,21 +449,6 @@ func TestBidValidate(t *testing.T) { expPass: false, err: errorsmod.Wrapf(ErrBidMustBeInUsomm, "bid: %s", sdk.NewCoin("usdc", sdk.NewInt(100)).String()), }, - { - name: "Sale token must be gravity prefixed", - bid: Bid{ - Id: uint64(1), - AuctionId: uint32(1), - Bidder: cosmosAddress2, - MaxBidInUsomm: sdk.NewCoin("usomm", sdk.NewInt(100)), - SaleTokenMinimumAmount: sdk.NewCoin("usdc", sdk.NewInt(50)), - TotalFulfilledSaleTokens: sdk.NewCoin("gravity0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", sdk.NewInt(50)), - SaleTokenUnitPriceInUsomm: sdk.MustNewDecFromStr("2.0"), - TotalUsommPaid: sdk.NewCoin("usomm", sdk.NewInt(100)), - }, - expPass: false, - err: errorsmod.Wrapf(ErrInvalidTokenBeingBidOn, "sale token: %s", sdk.NewCoin("usdc", sdk.NewInt(50)).String()), - }, { name: "Sale token amount must be positive", bid: Bid{ @@ -516,6 +535,16 @@ func TestTokenPriceValidate(t *testing.T) { expPass: true, err: nil, }, + { + name: "Happy path -- ibc denom", + tokenPrice: TokenPrice{ + Denom: "ibc/1", + UsdPrice: sdk.MustNewDecFromStr("0.001"), + LastUpdatedBlock: uint64(321), + }, + expPass: true, + err: nil, + }, { name: "Denom cannot be empty", tokenPrice: TokenPrice{ @@ -546,16 +575,6 @@ func TestTokenPriceValidate(t *testing.T) { expPass: false, err: errorsmod.Wrapf(ErrInvalidLastUpdatedBlock, "block: 0"), }, - { - name: "Token price must be usomm or gravity prefixed", - tokenPrice: TokenPrice{ - Denom: "usdc", - UsdPrice: sdk.MustNewDecFromStr("1.0"), - LastUpdatedBlock: uint64(321), - }, - expPass: false, - err: errorsmod.Wrapf(ErrInvalidTokenPriceDenom, "denom: usdc"), - }, } for _, tc := range testCases { @@ -595,6 +614,15 @@ func TestProposedTokenPriceValidate(t *testing.T) { expPass: true, err: nil, }, + { + name: "Happy path -- ibc denom", + proposedTokenPrice: ProposedTokenPrice{ + Denom: "ibc/1", + UsdPrice: sdk.MustNewDecFromStr("0.001"), + }, + expPass: true, + err: nil, + }, { name: "Denom cannot be empty", proposedTokenPrice: ProposedTokenPrice{ @@ -613,15 +641,6 @@ func TestProposedTokenPriceValidate(t *testing.T) { expPass: false, err: errorsmod.Wrapf(ErrPriceMustBePositive, "usd price: %s", sdk.MustNewDecFromStr("0.0").String()), }, - { - name: "Token price must be usomm or gravity prefixed", - proposedTokenPrice: ProposedTokenPrice{ - Denom: "usdc", - UsdPrice: sdk.MustNewDecFromStr("1.0"), - }, - expPass: false, - err: errorsmod.Wrapf(ErrInvalidTokenPriceDenom, "denom: usdc"), - }, } for _, tc := range testCases { diff --git a/x/auction/types/errors.go b/x/auction/types/errors.go index 7fc6155bc..199138883 100644 --- a/x/auction/types/errors.go +++ b/x/auction/types/errors.go @@ -32,11 +32,11 @@ var ( ErrBidIDMustBeNonZero = errorsmod.Register(ModuleName, 25, "bid ID must be non-zero") ErrBidAmountMustBePositive = errorsmod.Register(ModuleName, 26, "bid amount must be positive") ErrBidMustBeInUsomm = errorsmod.Register(ModuleName, 27, "bid must be in usomm") - ErrInvalidTokenBeingBidOn = errorsmod.Register(ModuleName, 28, "tokens being bid on must have the gravity prefix") + ErrInvalidTokenBeingBidOn = errorsmod.Register(ModuleName, 28, "bid token denom is invalid") ErrMinimumAmountMustBePositive = errorsmod.Register(ModuleName, 29, "minimum amount to purchase with bid must be positive") ErrAddressExpected = errorsmod.Register(ModuleName, 30, "address cannot be empty") ErrBidUnitPriceInUsommMustBePositive = errorsmod.Register(ModuleName, 31, "unit price of sale tokens in usomm must be positive") - ErrInvalidTokenPriceDenom = errorsmod.Register(ModuleName, 32, "token price denoms must be either usomm or addresses prefixed with 'gravity'") + ErrInvalidTokenPriceDenom = errorsmod.Register(ModuleName, 32, "invalid token price denom") ErrTokenPriceProposalAttemptsToUpdateTokenPriceMoreThanOnce = errorsmod.Register(ModuleName, 33, "token price proposals should not attempt to update the same denom's price more than once per proposal") ErrTokenPriceMaxBlockAgeMustBePositive = errorsmod.Register(ModuleName, 34, "price max block age must be positive") ErrInvalidPriceMaxBlockAgeParameterType = errorsmod.Register(ModuleName, 35, "price max block age type must be uint64") diff --git a/x/auction/types/genesis_test.go b/x/auction/types/genesis_test.go index cd390fd58..a0144fd75 100644 --- a/x/auction/types/genesis_test.go +++ b/x/auction/types/genesis_test.go @@ -51,6 +51,20 @@ func TestGenesisValidate(t *testing.T) { FundingModuleAccount: "someModule", ProceedsModuleAccount: "someModule", }, + { + Id: uint32(2), + StartingTokensForSale: sdk.NewCoin("ibc/1", sdk.NewIntFromUint64(1000)), + StartBlock: uint64(200), + EndBlock: uint64(0), + InitialPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), + CurrentPriceDecreaseRate: sdk.MustNewDecFromStr("0.05"), + PriceDecreaseBlockInterval: uint64(10), + InitialUnitPriceInUsomm: sdk.MustNewDecFromStr("20.0"), + CurrentUnitPriceInUsomm: sdk.MustNewDecFromStr("20.0"), + RemainingTokensForSale: sdk.NewCoin("ibc/1", sdk.NewIntFromUint64(900)), + FundingModuleAccount: "someModule", + ProceedsModuleAccount: "someModule", + }, }, Bids: []*Bid{ { @@ -125,6 +139,11 @@ func TestGenesisValidate(t *testing.T) { UsdPrice: sdk.MustNewDecFromStr("0.032"), LastUpdatedBlock: uint64(321), }, + { + Denom: "ibc/1", + UsdPrice: sdk.MustNewDecFromStr("0.032"), + LastUpdatedBlock: uint64(321), + }, }, LastAuctionId: uint32(1), LastBidId: uint64(1), @@ -218,7 +237,7 @@ func TestGenesisValidate(t *testing.T) { { Denom: "usdc", UsdPrice: sdk.MustNewDecFromStr("0.0008"), - LastUpdatedBlock: uint64(123), + LastUpdatedBlock: uint64(0), }, { Denom: "gravity0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", @@ -230,7 +249,7 @@ func TestGenesisValidate(t *testing.T) { LastBidId: uint64(1), }, expPass: false, - err: errorsmod.Wrapf(ErrInvalidTokenPriceDenom, "denom: usdc"), + err: errorsmod.Wrapf(ErrInvalidLastUpdatedBlock, "block: 0"), }, } diff --git a/x/auction/types/msgs.go b/x/auction/types/msgs.go index c9a8abfa0..0f5827a62 100644 --- a/x/auction/types/msgs.go +++ b/x/auction/types/msgs.go @@ -1,8 +1,6 @@ package types import ( - "strings" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -55,10 +53,6 @@ func (m *MsgSubmitBidRequest) ValidateBasic() error { return errorsmod.Wrapf(ErrMinimumAmountMustBePositive, "sale token amount: %s", m.SaleTokenMinimumAmount.String()) } - if !strings.HasPrefix(m.SaleTokenMinimumAmount.Denom, "gravity0x") { - return errorsmod.Wrapf(ErrInvalidTokenBeingBidOn, "sale token: %s", m.SaleTokenMinimumAmount.String()) - } - if _, err := sdk.AccAddressFromBech32(m.Signer); err != nil { return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } diff --git a/x/auction/types/msgs_test.go b/x/auction/types/msgs_test.go index d141cf0bc..642863e16 100644 --- a/x/auction/types/msgs_test.go +++ b/x/auction/types/msgs_test.go @@ -75,17 +75,6 @@ func TestMsgValidate(t *testing.T) { expPass: false, err: errorsmod.Wrapf(ErrBidAmountMustBePositive, "bid amount in usomm: %s", sdk.NewCoin("usomm", sdk.NewInt(0))), }, - { - name: "Sale token must be prefixed with gravity0x", - msgSubmitBidRequest: MsgSubmitBidRequest{ - AuctionId: uint32(1), - MaxBidInUsomm: sdk.NewCoin("usomm", sdk.NewInt(200)), - SaleTokenMinimumAmount: sdk.NewCoin("usdc", sdk.NewInt(1)), - Signer: cosmosAddress1, - }, - expPass: false, - err: errorsmod.Wrapf(ErrInvalidTokenBeingBidOn, "sale token: %s", sdk.NewCoin("usdc", sdk.NewInt(1))), - }, { name: "Sale token minimum amount must be positive", msgSubmitBidRequest: MsgSubmitBidRequest{ From 53dc56c79740b9ac8ce91da50bf9ca392a83519a Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Thu, 7 Mar 2024 15:24:10 -0600 Subject: [PATCH 19/28] WIP - Integration test passing, fee acct usomm balance not going to 0 bug --- app/app.go | 1 + integration_tests/cellarfees_test.go | 176 +++++++++++++++++++++------ integration_tests/setup_test.go | 28 ++--- x/cellarfees/keeper/abci.go | 2 + 4 files changed, 154 insertions(+), 53 deletions(-) diff --git a/app/app.go b/app/app.go index af4f46bde..22a4e373f 100644 --- a/app/app.go +++ b/app/app.go @@ -219,6 +219,7 @@ var ( // incidentally this permission is also required to be able to send tokens from module accounts allowedReceivingModAcc = map[string]bool{ axelarcorktypes.ModuleName: true, + cellarfeestypes.ModuleName: true, } _ simapp.App = (*SommelierApp)(nil) diff --git a/integration_tests/cellarfees_test.go b/integration_tests/cellarfees_test.go index 61bda8fc3..2707b5155 100644 --- a/integration_tests/cellarfees_test.go +++ b/integration_tests/cellarfees_test.go @@ -2,21 +2,23 @@ package integration_tests import ( "context" - "fmt" + "math/big" "time" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" + cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" - corktypes "github.com/peggyjv/sommelier/v7/x/cork/types/v2" ) func (s *IntegrationTestSuite) TestCellarFees() { - s.Run("Bring up chain, send fees from ethereum, observe auction and fee distribution", func() { + s.Run("Bring up chain, submit TokenPrices, observe auction and fee distribution", func() { val := s.chain.validators[0] - ethereumSender := val.ethereumKey.address kb, err := val.keyring() s.Require().NoError(err) @@ -26,23 +28,9 @@ func (s *IntegrationTestSuite) TestCellarFees() { auctionQueryClient := auctiontypes.NewQueryClient(clientCtx) bankQueryClient := banktypes.NewQueryClient(clientCtx) cellarfeesQueryClient := cellarfeestypesv2.NewQueryClient(clientCtx) - corkQueryClient := corktypes.NewQueryClient(clientCtx) distQueryClient := disttypes.NewQueryClient(clientCtx) - s.T().Log("Verify that the first validator address is an approved cellar ID") - idsRes, err := corkQueryClient.QueryCellarIDs(context.Background(), &corktypes.QueryCellarIDsRequest{}) - s.Require().NoError(err) - - var found bool - for _, id := range idsRes.CellarIds { - if id == ethereumSender { - found = true - break - } - } - s.Require().True(found, "validator ethereum address %s is not an approved cellar ID", ethereumSender) - - s.T().Logf("Verify that the module account's fee balances are zero") + s.T().Logf("Verify that the module account's fee balances are not zero") ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() @@ -51,54 +39,143 @@ func (s *IntegrationTestSuite) TestCellarFees() { feesAddress := acctsRes.FeesAddress s.T().Logf("Fees address: %s", feesAddress) - balanceRes, err := bankQueryClient.Balance(ctx, &banktypes.QueryBalanceRequest{ + balanceRes, err := bankQueryClient.AllBalances(ctx, &banktypes.QueryAllBalancesRequest{ Address: feesAddress, - Denom: fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()), }) s.Require().NoError(err, "Failed to query fee balance of denom %s", alphaERC20Contract.Hex()) - s.Require().Zero(balanceRes.Balance.Amount.Uint64()) - s.T().Log("Waiting for auctions to start") - alphaAuctionID := uint32(0) + foundGravityDenom, foundIbcDenom := false, false + for _, balance := range balanceRes.Balances { + if balance.Denom == gravityDenom { + s.Require().NotZero(balance.Amount.Uint64()) + foundGravityDenom = true + } else if balance.Denom == ibcDenom { + s.Require().NotZero(balance.Amount.Uint64()) + foundIbcDenom = true + } + } + + s.Require().True(foundGravityDenom, "fees account is missing initial gravity denom balance") + s.Require().True(foundIbcDenom, "fees account is missing initial ibc denom balance") + + // Submit TokenPrices proposal + orch0 := s.chain.orchestrators[0] + orch0ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch0.keyring, "orch", orch0.address()) + s.Require().NoError(err) + proposer := s.chain.proposer + proposerCtx, err := s.chain.clientContext("tcp://localhost:26657", proposer.keyring, "proposer", proposer.address()) + s.Require().NoError(err) + propID := uint64(1) + + s.T().Log("Submitting TokenPrices proposal") + tokenPrices := []*auctiontypes.ProposedTokenPrice{ + { + Denom: gravityDenom, + Exponent: 12, + UsdPrice: sdk.MustNewDecFromStr("10.00"), + }, + { + Denom: ibcDenom, + Exponent: 6, + UsdPrice: sdk.MustNewDecFromStr("1.00"), + }, + } + addTokenPricesProp := auctiontypes.SetTokenPricesProposal{ + Title: "add token prices", + Description: "add token prices", + TokenPrices: tokenPrices, + } + + addTokenPricesPropMsg, err := govtypesv1beta1.NewMsgSubmitProposal( + &addTokenPricesProp, + sdk.Coins{ + { + Denom: testDenom, + Amount: math.NewInt(2), + }, + }, + proposer.address(), + ) + s.Require().NoError(err, "Unable to create governance proposal") + + s.submitAndVoteForProposal(proposerCtx, orch0ClientCtx, propID, addTokenPricesPropMsg) + + s.T().Log("Waiting for gravity denom auction to start") + var gravityAuctionID uint32 + var ibcAuctionID uint32 s.Require().Eventually(func() bool { res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) if res != nil { for _, auction := range res.Auctions { - if auction.StartingTokensForSale.Denom == alphaFeeDenom { + if auction.StartingTokensForSale.Denom == gravityDenom { + gravityAuctionID = auction.Id return true } } } return false - }, time.Second*30, time.Second*5, "Auctions never started for test fees") + }, time.Second*60, time.Second*5, "Auctions never started for gravity fees") - s.T().Log("Bidding to buy all of the ALPHA fees available") + // Send ibcDenom tokens from the orch to the fee account to trigger another auction orch := s.chain.orchestrators[0] + orchClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch.keyring, "orch", orch.address()) + s.Require().NoError(err, "Failed to create client for orchestrator") + + s.T().Log("sending 1 ibc/1 to fees account to trigger auction") + feesAcct := authtypes.NewModuleAddress(cellarfeestypes.ModuleName) + sendRequest := banktypes.NewMsgSend( + orch.address(), + feesAcct, + sdk.NewCoins( + sdk.Coin{ + Denom: ibcDenom, + Amount: sdk.NewInt(1), + }, + ), + ) + + _, err = s.chain.sendMsgs(*orchClientCtx, sendRequest) + s.Require().NoError(err, "Failed to submit send request") + + s.T().Log("Waiting for ibc denom auction to start") + s.Require().Eventually(func() bool { + res, _ := auctionQueryClient.QueryActiveAuctions(ctx, &auctiontypes.QueryActiveAuctionsRequest{}) + + if res != nil { + for _, auction := range res.Auctions { + if auction.StartingTokensForSale.Denom == ibcDenom { + ibcAuctionID = auction.Id + return true + } + } + } + + return false + }, time.Second*120, time.Second*5, "Auctions never started for ibc fees") + + s.T().Log("Bidding to buy all of the gravity fees available") bidRequest1 := auctiontypes.MsgSubmitBidRequest{ - AuctionId: alphaAuctionID, + AuctionId: gravityAuctionID, Signer: orch.address().String(), - MaxBidInUsomm: sdk.NewCoin(testDenom, sdk.NewIntFromUint64(300000)), - SaleTokenMinimumAmount: sdk.NewCoin(alphaFeeDenom, sdk.NewIntFromUint64(150000)), + MaxBidInUsomm: sdk.NewCoin(testDenom, sdk.NewIntFromUint64(1000000000000000)), + SaleTokenMinimumAmount: sdk.NewCoin(gravityDenom, sdk.NewIntFromBigInt(big.NewInt(100000000000000))), } - - orchClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch.keyring, "orch", orch.address()) - s.Require().NoError(err, "Failed to create client for orchestrator") _, err = s.chain.sendMsgs(*orchClientCtx, &bidRequest1) - s.Require().NoError(err, "Failed to submit bid") + s.Require().NoError(err, "Failed to submit gravity bid") - s.T().Log("Bid submitted. Waiting to confirm auction ended") + s.T().Log("Bids submitted. Waiting to confirm gravity auction ended") s.Require().Eventually(func() bool { _, err := auctionQueryClient.QueryEndedAuction(ctx, &auctiontypes.QueryEndedAuctionRequest{ - AuctionId: alphaAuctionID, + AuctionId: gravityAuctionID, }) // a nil error indicates the item was found return err == nil }, time.Second*10, time.Second, "Auction did not end.") - s.T().Log("Auction ended. Waiting to receive usomm in fees account") + s.T().Log("Gravity auction ended. Waiting to receive usomm in fees account") s.Require().Eventually(func() bool { res, err := bankQueryClient.Balance(ctx, &banktypes.QueryBalanceRequest{ Address: feesAddress, @@ -139,7 +216,28 @@ func (s *IntegrationTestSuite) TestCellarFees() { return false }, time.Second*30, time.Millisecond*400, "Distribution rate was invalid or could not be determined") - s.T().Log("Waiting to see distribution rate increase") + s.T().Log("Distribution rate is nonzero. Submitting bid for all of the ibc fees available") + bidRequest2 := auctiontypes.MsgSubmitBidRequest{ + AuctionId: ibcAuctionID, + Signer: orch.address().String(), + MaxBidInUsomm: sdk.NewCoin(testDenom, sdk.NewIntFromUint64(100000000)), + SaleTokenMinimumAmount: sdk.NewCoin(ibcDenom, sdk.NewIntFromBigInt(big.NewInt(100000000))), + } + + _, err = s.chain.sendMsgs(*orchClientCtx, &bidRequest2) + s.Require().NoError(err, "Failed to submit ibc bid") + + s.T().Log("Waiting to confirm ibc auction ended") + s.Require().Eventually(func() bool { + _, err := auctionQueryClient.QueryEndedAuction(ctx, &auctiontypes.QueryEndedAuctionRequest{ + AuctionId: ibcAuctionID, + }) + + // a nil error indicates the item was found + return err == nil + }, time.Second*10, time.Second, "Auction did not end.") + + s.T().Log("IBC auction ended. Waiting to see distribution rate increase") lastBalanceSeen = sdk.ZeroInt() s.Require().Eventually(func() bool { res, err := bankQueryClient.Balance(ctx, &banktypes.QueryBalanceRequest{ @@ -207,7 +305,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { } for _, auction := range res.Auctions { - s.Require().NotEqual(auction.StartingTokensForSale.Denom, alphaFeeDenom) + s.Require().NotEqual(auction.StartingTokensForSale.Denom, gravityDenom) } time.Sleep(time.Second) diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index f2758d173..073b9af9c 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -51,7 +51,7 @@ import ( const ( testDenom = "usomm" - initBalanceStr = "210000000000usomm" + initBalanceStr = "210000000000usomm,1ibc/1" minGasPrice = "2" ethChainID uint = 15 exampleCA = `-----BEGIN CERTIFICATE----- @@ -70,6 +70,7 @@ pohf4PJrfacqpi7PoXBk -----END CERTIFICATE----- ` axelarSweepDenom = "sweep" + gravityDenom = "gravity0x0000000000000000000000000000000000000000" ibcDenom = "ibc/1" ) @@ -81,11 +82,8 @@ var ( gravityContract = common.HexToAddress("0x04C89607413713Ec9775E14b954286519d836FEf") counterContract = common.HexToAddress("0x0000000000000000000000000000000000000000") alphaERC20Contract = common.HexToAddress("0x0000000000000000000000000000000000000000") - alphaERC20Denom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) unusedGenesisContract = common.HexToAddress("0x0000000000000000000000000000000000000001") - alphaFeeDenom = "" - // 67% corkVoteThreshold = sdk.NewDecWithPrec(67, 2) @@ -336,7 +334,7 @@ func (s *IntegrationTestSuite) initGenesis() { }) // Set up auction module with some coins to auction off - balance := banktypes.Balance{ + auctionBalance := banktypes.Balance{ Address: authtypes.NewModuleAddress(auctiontypes.ModuleName).String(), Coins: sdk.NewCoins(sdk.NewCoin("gravity0x3506424f91fd33084466f402d5d97f05f8e3b4af", sdk.NewInt(5000000000))), } @@ -348,9 +346,17 @@ func (s *IntegrationTestSuite) initGenesis() { Address: s.chain.orchestrators[0].address().String(), Coins: sdk.NewCoins(sdk.NewCoin(axelarSweepDenom, sdk.NewInt(2000000000))), } - bankGenState.Balances = append(bankGenState.Balances, balance) + feesBalance := banktypes.Balance{ + Address: authtypes.NewModuleAddress(cellarfeestypes.ModuleName).String(), + Coins: sdk.NewCoins( + sdk.NewCoin(gravityDenom, sdk.NewInt(100000000000000)), + sdk.NewCoin(ibcDenom, sdk.NewInt(99999999)), + ), + } + bankGenState.Balances = append(bankGenState.Balances, auctionBalance) bankGenState.Balances = append(bankGenState.Balances, distBalance) bankGenState.Balances = append(bankGenState.Balances, orchSweepBalance) + bankGenState.Balances = append(bankGenState.Balances, feesBalance) bz, err := cdc.MarshalJSON(&bankGenState) s.Require().NoError(err) @@ -408,19 +414,12 @@ func (s *IntegrationTestSuite) initGenesis() { s.Require().NoError(cdc.UnmarshalJSON(appGenState[genutiltypes.ModuleName], &genUtilGenState)) // Add an auction for integration testing of the auction module - alphaFeeDenom = fmt.Sprintf("gravity%s", alphaERC20Contract.Hex()) var auctionGenState auctiontypes.GenesisState s.Require().NoError(cdc.UnmarshalJSON(appGenState[auctiontypes.ModuleName], &auctionGenState)) - auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ - Denom: alphaFeeDenom, - Exponent: 6, - UsdPrice: sdk.MustNewDecFromStr("1.0"), - LastUpdatedBlock: 0, - }) auctionGenState.TokenPrices = append(auctionGenState.TokenPrices, &auctiontypes.TokenPrice{ Denom: testDenom, Exponent: 6, - UsdPrice: sdk.MustNewDecFromStr("0.5"), + UsdPrice: sdk.MustNewDecFromStr("1.0"), LastUpdatedBlock: 0, }) auctionGenState.Auctions = append(auctionGenState.Auctions, &auctiontypes.Auction{ @@ -437,6 +436,7 @@ func (s *IntegrationTestSuite) initGenesis() { FundingModuleAccount: cellarfeestypes.ModuleName, ProceedsModuleAccount: cellarfeestypes.ModuleName, }) + auctionGenState.LastAuctionId = 1 bz, err = cdc.MarshalJSON(&auctionGenState) s.Require().NoError(err) appGenState[auctiontypes.ModuleName] = bz diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 5f23578b5..1ed328ec1 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/peggyjv/sommelier/v7/app/params" + "github.com/peggyjv/sommelier/v7/x/cellarfees/types" ) // BeginBlocker emits rewards each block they are available by sending them to the distribution module's fee collector @@ -28,6 +29,7 @@ func (k Keeper) handleRewardEmission(ctx sdk.Context) { emission := k.GetEmission(ctx, remainingRewardsSupply) // Send to fee collector for distribution + ctx.Logger().Info("Sending rewards to fee collector", "module", types.ModuleName) err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, moduleAccount.GetName(), authtypes.FeeCollectorName, emission) if err != nil { panic(err) From 8f8aeb30cfae3639d40ffcb36d48cc08eb5fd2d6 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 12:02:55 -0500 Subject: [PATCH 20/28] Fix test and skip usomm in auction start logic --- integration_tests/cellarfees_test.go | 2 +- x/cellarfees/keeper/abci.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/integration_tests/cellarfees_test.go b/integration_tests/cellarfees_test.go index 2707b5155..042e7c47d 100644 --- a/integration_tests/cellarfees_test.go +++ b/integration_tests/cellarfees_test.go @@ -294,7 +294,7 @@ func (s *IntegrationTestSuite) TestCellarFees() { bankQueryClient = banktypes.NewQueryClient(clientCtx) } - return res == nil || res.Balance.Amount.Equal(sdk.ZeroInt()) + return res != nil && res.Balance.Amount.IsZero() }, time.Second*300, time.Second*10, "Reward supply did not exhaust in the provided amount of time") s.T().Log("Confirming no auction is started...") diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 1ed328ec1..232eaee01 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/peggyjv/sommelier/v7/app/params" + paramstypes "github.com/peggyjv/sommelier/v7/app/params" "github.com/peggyjv/sommelier/v7/x/cellarfees/types" ) @@ -20,7 +20,7 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {} func (k Keeper) handleRewardEmission(ctx sdk.Context) { moduleAccount := k.GetFeesAccount(ctx) - remainingRewardsSupply := k.bankKeeper.GetBalance(ctx, moduleAccount.GetAddress(), params.BaseCoinUnit).Amount + remainingRewardsSupply := k.bankKeeper.GetBalance(ctx, moduleAccount.GetAddress(), paramstypes.BaseCoinUnit).Amount if remainingRewardsSupply.IsZero() { return @@ -44,6 +44,11 @@ func (k Keeper) handleFeeAuctions(ctx sdk.Context) { } for _, tokenPrice := range k.auctionKeeper.GetTokenPrices(ctx) { + // skip usomm + if tokenPrice.Denom == paramstypes.BaseCoinUnit { + continue + } + balance := k.GetFeeBalance(ctx, tokenPrice.Denom) if balance.IsZero() { From e92366c5be661067375d20b0055c91379c07b93b Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 12:12:42 -0500 Subject: [PATCH 21/28] Linting --- app/upgrades/v7/constants.go | 2 ++ app/upgrades/v7/upgrades.go | 2 +- x/cellarfees/keeper/abci_test.go | 7 +++---- x/cellarfees/keeper/query_server_test.go | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/upgrades/v7/constants.go b/app/upgrades/v7/constants.go index 43b8ba413..9bb0182e2 100644 --- a/app/upgrades/v7/constants.go +++ b/app/upgrades/v7/constants.go @@ -1,3 +1,5 @@ +//go:build exclude + package v7 // UpgradeName defines the on-chain upgrade name for the Sommelier v7 upgrade diff --git a/app/upgrades/v7/upgrades.go b/app/upgrades/v7/upgrades.go index 8e8e78a1a..e1a09aef9 100644 --- a/app/upgrades/v7/upgrades.go +++ b/app/upgrades/v7/upgrades.go @@ -1,4 +1,4 @@ -//go:build exclude +// +build exclude package v7 diff --git a/x/cellarfees/keeper/abci_test.go b/x/cellarfees/keeper/abci_test.go index 1765f13fc..7e9431e7a 100644 --- a/x/cellarfees/keeper/abci_test.go +++ b/x/cellarfees/keeper/abci_test.go @@ -4,7 +4,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/golang/mock/gomock" appParams "github.com/peggyjv/sommelier/v7/app/params" - auctionTypes "github.com/peggyjv/sommelier/v7/x/auction/types" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" @@ -191,9 +190,9 @@ func (suite *KeeperTestSuite) TestHandleFeeAuctionsHappyPath() { suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) // no active auctions - suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) + suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctiontypes.Auction{}) suite.auctionKeeper.EXPECT().BeginAuction(ctx, balance1, params.InitialPriceDecreaseRate, params.PriceDecreaseBlockInterval, cellarfeestypes.ModuleName, cellarfeestypes.ModuleName).Return(nil) - expectedAuction1 := auctionTypes.Auction{ + expectedAuction1 := auctiontypes.Auction{ Id: 1, StartingTokensForSale: balance1, InitialPriceDecreaseRate: params.InitialPriceDecreaseRate, @@ -206,7 +205,7 @@ func (suite *KeeperTestSuite) TestHandleFeeAuctionsHappyPath() { FundingModuleAccount: cellarfeestypes.ModuleName, ProceedsModuleAccount: cellarfeestypes.ModuleName, } - suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{&expectedAuction1}) + suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctiontypes.Auction{&expectedAuction1}) suite.auctionKeeper.EXPECT().BeginAuction(ctx, balance2, params.InitialPriceDecreaseRate, params.PriceDecreaseBlockInterval, cellarfeestypes.ModuleName, cellarfeestypes.ModuleName).Return(nil) // we only set expected calls for two auctions because the third token price is $99, so no auction should be started. diff --git a/x/cellarfees/keeper/query_server_test.go b/x/cellarfees/keeper/query_server_test.go index b1240cecc..ca79e01e1 100644 --- a/x/cellarfees/keeper/query_server_test.go +++ b/x/cellarfees/keeper/query_server_test.go @@ -64,7 +64,7 @@ func (suite *KeeperTestSuite) TestQueriesHappyPath() { require.Equal("0.004380000000000000", APYResult.Apy) // QueryFeeTokenBalance - denom := "testdenom" + denom := feeDenom amount := sdk.NewInt(1000000) suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, true) suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(1) @@ -168,9 +168,9 @@ func (suite *KeeperTestSuite) TestQueriesUnhappyPath() { require.NotNil(err) require.Equal(status.Code(err), codes.InvalidArgument) - denom := "testdenom" + denom := feeDenom suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, false) - feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: "testdenom"}) + feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: denom}) require.Nil(feeTokenBalanceResponse) require.NotNil(err) require.Equal(status.Code(err), codes.NotFound) From f60fb3212b5343a2679421d4ef718308b4d2b3c7 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 15:56:37 -0500 Subject: [PATCH 22/28] Remove old upgrades from linting rules --- app/upgrades/v7/upgrades.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/upgrades/v7/upgrades.go b/app/upgrades/v7/upgrades.go index e1a09aef9..1d13ce00a 100644 --- a/app/upgrades/v7/upgrades.go +++ b/app/upgrades/v7/upgrades.go @@ -1,3 +1,4 @@ +//go:build exclude // +build exclude package v7 From 8ea06d393d73e8840f6d1fc7dc65ed53bd77d9dd Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 15:57:04 -0500 Subject: [PATCH 23/28] Add CLI commands for new queries --- x/cellarfees/client/cli/query.go | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/x/cellarfees/client/cli/query.go b/x/cellarfees/client/cli/query.go index 44af37a19..761199390 100644 --- a/x/cellarfees/client/cli/query.go +++ b/x/cellarfees/client/cli/query.go @@ -32,6 +32,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryModuleAccounts()) cmd.AddCommand(CmdQueryLastRewardSupplyPeak()) cmd.AddCommand(CmdQueryAPY()) + cmd.AddCommand(CmdQueryFeeTokenBalance()) + cmd.AddCommand(CmdQueryFeeTokenBalances()) return cmd } @@ -139,3 +141,65 @@ func CmdQueryAPY() *cobra.Command { return cmd } + +func CmdQueryFeeTokenBalance() *cobra.Command { + cmd := &cobra.Command{ + Use: "fee-token-balance", + Aliases: []string{"ftb"}, + Args: cobra.ExactArgs(1), + Short: "query a fee tokens balance and its USD value in the cellarfees module", + RunE: func(cmd *cobra.Command, _ []string) error { + ctx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + args := cmd.Flags().Args() + + queryClient := types.NewQueryClient(ctx) + req := &types.QueryFeeTokenBalanceRequest{ + Denom: args[0], + } + + res, err := queryClient.QueryFeeTokenBalance(cmd.Context(), req) + if err != nil { + return err + } + + return ctx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryFeeTokenBalances() *cobra.Command { + cmd := &cobra.Command{ + Use: "fee-token-balances", + Aliases: []string{"ftbs"}, + Args: cobra.NoArgs, + Short: "query all fee token balances and their USD values in the cellarfees module", + RunE: func(cmd *cobra.Command, _ []string) error { + ctx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(ctx) + req := &types.QueryFeeTokenBalancesRequest{} + + res, err := queryClient.QueryFeeTokenBalances(cmd.Context(), req) + if err != nil { + return err + } + + return ctx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} From f9111c8454eb12940c1676136f5d09046040d79c Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 15:57:17 -0500 Subject: [PATCH 24/28] Fix bugs found in testing --- x/cellarfees/keeper/abci.go | 6 +++++- x/cellarfees/keeper/cellarfees.go | 10 ++++++++-- x/cellarfees/keeper/cellarfees_test.go | 3 ++- x/cellarfees/keeper/query_server.go | 11 ++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 232eaee01..85b377ce5 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -49,7 +49,11 @@ func (k Keeper) handleFeeAuctions(ctx sdk.Context) { continue } - balance := k.GetFeeBalance(ctx, tokenPrice.Denom) + balance, found := k.GetFeeBalance(ctx, tokenPrice.Denom) + + if !found { + continue + } if balance.IsZero() { continue diff --git a/x/cellarfees/keeper/cellarfees.go b/x/cellarfees/keeper/cellarfees.go index 080561778..8c18a9c28 100644 --- a/x/cellarfees/keeper/cellarfees.go +++ b/x/cellarfees/keeper/cellarfees.go @@ -40,10 +40,16 @@ func (k Keeper) GetEmission(ctx sdk.Context, remainingRewardsSupply math.Int) sd return sdk.NewCoins(sdk.NewCoin(params.BaseCoinUnit, emissionAmount)) } -func (k Keeper) GetFeeBalance(ctx sdk.Context, denom string) sdk.Coin { +func (k Keeper) GetFeeBalance(ctx sdk.Context, denom string) (sdk.Coin, bool) { feesAddr := k.GetFeesAccount(ctx).GetAddress() - return k.bankKeeper.GetBalance(ctx, feesAddr, denom) + for _, balance := range k.bankKeeper.GetAllBalances(ctx, feesAddr) { + if balance.Denom == denom { + return balance, true + } + } + + return sdk.Coin{}, false } func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice *auctiontypes.TokenPrice) sdk.Dec { diff --git a/x/cellarfees/keeper/cellarfees_test.go b/x/cellarfees/keeper/cellarfees_test.go index 608ef8fa8..1c9f78b49 100644 --- a/x/cellarfees/keeper/cellarfees_test.go +++ b/x/cellarfees/keeper/cellarfees_test.go @@ -38,8 +38,9 @@ func (suite *KeeperTestSuite) TestGetFeeBalance() { suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(&account) suite.bankKeeper.EXPECT().GetBalance(ctx, account.GetAddress(), expectedDenom).Return(expectedBalance) - balance := cellarfeesKeeper.GetFeeBalance(ctx, expectedDenom) + balance, found := cellarfeesKeeper.GetFeeBalance(ctx, expectedDenom) + require.True(found) require.Equal(expectedBalance, balance) } diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index d15944648..91e60a054 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -25,7 +25,6 @@ func (k Keeper) QueryModuleAccounts(c context.Context, req *types.QueryModuleAcc if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") } - return &types.QueryModuleAccountsResponse{ FeesAddress: k.GetFeesAccount(sdk.UnwrapSDKContext(c)).GetAddress().String(), }, nil @@ -55,12 +54,11 @@ func (k Keeper) QueryFeeTokenBalance(c context.Context, req *types.QueryFeeToken return nil, status.Error(codes.InvalidArgument, "denom cannot be empty") } - _, found := k.bankKeeper.GetDenomMetaData(ctx, req.Denom) + balance, found := k.GetFeeBalance(ctx, req.Denom) if !found { - return nil, status.Error(codes.NotFound, "denom not found") + return nil, status.Error(codes.NotFound, "fee token balance not found") } - balance := k.GetFeeBalance(ctx, req.Denom) tokenPrice, found := k.auctionKeeper.GetTokenPrice(ctx, req.Denom) if !found { return nil, status.Error(codes.NotFound, "token price not found") @@ -89,7 +87,10 @@ func (k Keeper) QueryFeeTokenBalances(c context.Context, _ *types.QueryFeeTokenB // this exclude fee token balances that don't have one yet. tokenPrices := k.auctionKeeper.GetTokenPrices(ctx) for _, tokenPrice := range tokenPrices { - balance := k.GetFeeBalance(ctx, tokenPrice.Denom) + balance, found := k.GetFeeBalance(ctx, tokenPrice.Denom) + if !found { + continue + } if balance.IsZero() { continue From f157ed051b6b72998687818f1cb6dda06b536540 Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Mon, 11 Mar 2024 17:14:40 -0500 Subject: [PATCH 25/28] Refactor FeeBalance methods/handler to iterate balances instead of token prices --- x/cellarfees/keeper/abci.go | 11 +++++------ x/cellarfees/keeper/abci_test.go | 7 +++++-- x/cellarfees/keeper/cellarfees.go | 2 +- x/cellarfees/keeper/cellarfees_test.go | 8 ++++---- x/cellarfees/keeper/query_server.go | 14 ++++++-------- x/cellarfees/keeper/query_server_test.go | 23 +++++++++++++---------- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 85b377ce5..13d50298f 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -43,19 +43,18 @@ func (k Keeper) handleFeeAuctions(ctx sdk.Context) { return } - for _, tokenPrice := range k.auctionKeeper.GetTokenPrices(ctx) { + for _, balance := range k.bankKeeper.GetAllBalances(ctx, k.GetFeesAccount(ctx).GetAddress()) { // skip usomm - if tokenPrice.Denom == paramstypes.BaseCoinUnit { + if balance.Denom == paramstypes.BaseCoinUnit { continue } - balance, found := k.GetFeeBalance(ctx, tokenPrice.Denom) - - if !found { + if balance.IsZero() { continue } - if balance.IsZero() { + tokenPrice, found := k.auctionKeeper.GetTokenPrice(ctx, balance.Denom) + if !found { continue } diff --git a/x/cellarfees/keeper/abci_test.go b/x/cellarfees/keeper/abci_test.go index 7e9431e7a..d10cd0951 100644 --- a/x/cellarfees/keeper/abci_test.go +++ b/x/cellarfees/keeper/abci_test.go @@ -155,7 +155,7 @@ func (suite *KeeperTestSuite) TestHandleFeeAuctionsHappyPath() { denom3 := "denom3" amount1 := sdk.NewInt(1000000) amount2 := sdk.NewInt(2000000000000) - amount3 := sdk.NewInt(3000000000000000000) + amount3 := sdk.NewInt(3000000000000000) balance1 := sdk.NewCoin(denom1, amount1) balance2 := sdk.NewCoin(denom2, amount2) balance3 := sdk.NewCoin(denom3, amount3) @@ -180,8 +180,11 @@ func (suite *KeeperTestSuite) TestHandleFeeAuctionsHappyPath() { }, } - suite.auctionKeeper.EXPECT().GetTokenPrices(ctx).Return(tokenPrices) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom1).Return(*tokenPrices[0], true) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom2).Return(*tokenPrices[1], true) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom3).Return(*tokenPrices[2], true) suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(len(tokenPrices) * 2) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, feesAccount.GetAddress()).Return(sdk.NewCoins(balance1)).Times(2) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom1).Return(balance1).Times(2) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom2).Return(balance2).Times(2) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom3).Return(balance3).Times(2) diff --git a/x/cellarfees/keeper/cellarfees.go b/x/cellarfees/keeper/cellarfees.go index 8c18a9c28..399d039f9 100644 --- a/x/cellarfees/keeper/cellarfees.go +++ b/x/cellarfees/keeper/cellarfees.go @@ -52,7 +52,7 @@ func (k Keeper) GetFeeBalance(ctx sdk.Context, denom string) (sdk.Coin, bool) { return sdk.Coin{}, false } -func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice *auctiontypes.TokenPrice) sdk.Dec { +func (k Keeper) GetBalanceUsdValue(ctx sdk.Context, balance sdk.Coin, tokenPrice auctiontypes.TokenPrice) sdk.Dec { unitAmount := sdk.NewDecFromInt(balance.Amount).Quo(sdk.NewDec(10).Power(tokenPrice.Exponent)) return tokenPrice.UsdPrice.Mul(unitAmount) diff --git a/x/cellarfees/keeper/cellarfees_test.go b/x/cellarfees/keeper/cellarfees_test.go index 1c9f78b49..a65d4fc2d 100644 --- a/x/cellarfees/keeper/cellarfees_test.go +++ b/x/cellarfees/keeper/cellarfees_test.go @@ -30,18 +30,18 @@ func (suite *KeeperTestSuite) TestGetFeeBalance() { require := suite.Require() expectedDenom := "testdenom" - expectedBalance := sdk.NewCoin(expectedDenom, sdk.NewInt(1000000)) + expectedBalances := sdk.Coins{sdk.NewCoin(expectedDenom, sdk.NewInt(1000000))} account := accounttypes.ModuleAccount{ Name: cellarfeestypes.ModuleName, BaseAccount: accounttypes.NewBaseAccountWithAddress(sdk.MustAccAddressFromBech32("somm1hqf42j6zxfnth4xpdse05wpnjjrgc864vwujxx")), } suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(&account) - suite.bankKeeper.EXPECT().GetBalance(ctx, account.GetAddress(), expectedDenom).Return(expectedBalance) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, account.GetAddress()).Return(expectedBalances) balance, found := cellarfeesKeeper.GetFeeBalance(ctx, expectedDenom) require.True(found) - require.Equal(expectedBalance, balance) + require.Equal(expectedBalances[0], balance) } func (suite *KeeperTestSuite) TestGetBalanceUsdValue() { @@ -50,7 +50,7 @@ func (suite *KeeperTestSuite) TestGetBalanceUsdValue() { balance := sdk.NewCoin("testdenom", sdk.NewInt(1000000)) usdPrice := sdk.NewDec(100) - tokenPrice := &auctiontypes.TokenPrice{ + tokenPrice := auctiontypes.TokenPrice{ Exponent: 6, UsdPrice: usdPrice, } diff --git a/x/cellarfees/keeper/query_server.go b/x/cellarfees/keeper/query_server.go index 91e60a054..18a3e701e 100644 --- a/x/cellarfees/keeper/query_server.go +++ b/x/cellarfees/keeper/query_server.go @@ -64,7 +64,7 @@ func (k Keeper) QueryFeeTokenBalance(c context.Context, req *types.QueryFeeToken return nil, status.Error(codes.NotFound, "token price not found") } - totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, &tokenPrice).Float64() + totalUsdValue, err := k.GetBalanceUsdValue(ctx, balance, tokenPrice).Float64() if err != nil { return nil, status.Error(codes.Internal, "failed to convert usd value to float") } @@ -83,16 +83,14 @@ func (k Keeper) QueryFeeTokenBalances(c context.Context, _ *types.QueryFeeTokenB ctx := sdk.UnwrapSDKContext(c) feeBalances := make([]*types.FeeTokenBalance, 0) - // because we can't get a USD value without a corresponding TokenPrice set in the auction module, - // this exclude fee token balances that don't have one yet. - tokenPrices := k.auctionKeeper.GetTokenPrices(ctx) - for _, tokenPrice := range tokenPrices { - balance, found := k.GetFeeBalance(ctx, tokenPrice.Denom) - if !found { + balances := k.bankKeeper.GetAllBalances(ctx, k.GetFeesAccount(ctx).GetAddress()) + for _, balance := range balances { + if balance.IsZero() { continue } - if balance.IsZero() { + tokenPrice, found := k.auctionKeeper.GetTokenPrice(ctx, balance.Denom) + if !found { continue } diff --git a/x/cellarfees/keeper/query_server_test.go b/x/cellarfees/keeper/query_server_test.go index ca79e01e1..277f0b68f 100644 --- a/x/cellarfees/keeper/query_server_test.go +++ b/x/cellarfees/keeper/query_server_test.go @@ -72,7 +72,7 @@ func (suite *KeeperTestSuite) TestQueriesHappyPath() { Exponent: 6, UsdPrice: sdk.NewDec(100), }, true) - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom).Return(sdk.NewCoin(denom, amount)) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, feesAccount.GetAddress()).Return(sdk.Coins{sdk.NewCoin(denom, amount)}) expectedFeeTokenBalance := cellarfeestypesv2.FeeTokenBalance{ Balance: sdk.NewCoin(denom, amount), @@ -113,23 +113,26 @@ func (suite *KeeperTestSuite) TestQueriesHappyPath() { } tokenPrices := []*auctiontypes.TokenPrice{&tokenPrice1, &tokenPrice2, &tokenPrice3} suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount).Times(3) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, feesAccount.GetAddress()).Return(sdk.Coins{balance1, balance2, balance3}).Times(3) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom1).Return(balance1) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom2).Return(balance2) suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom3).Return(balance3) - suite.auctionKeeper.EXPECT().GetTokenPrices(ctx).Return(tokenPrices) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom1).Return(*tokenPrices[0], true) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom2).Return(*tokenPrices[1], true) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom3).Return(*tokenPrices[2], true) expectedFeeTokenBalances := []*cellarfeestypesv2.FeeTokenBalance{ { Balance: balance1, - UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance1, &tokenPrice1).MustFloat64(), + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance1, tokenPrice1).MustFloat64(), }, { Balance: balance2, - UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance2, &tokenPrice2).MustFloat64(), + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance2, tokenPrice2).MustFloat64(), }, { Balance: balance3, - UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance3, &tokenPrice3).MustFloat64(), + UsdValue: cellarfeesKeeper.GetBalanceUsdValue(ctx, balance3, tokenPrice3).MustFloat64(), }, } @@ -158,6 +161,10 @@ func (suite *KeeperTestSuite) TestQueriesUnhappyPath() { require.NotNil(err) // QueryFeeTokenBalance + denom := feeDenom + suite.accountKeeper.EXPECT().GetModuleAccount(ctx, cellarfeestypes.ModuleName).Return(feesAccount) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, feesAccount.GetAddress()).Return(sdk.Coins{sdk.NewCoin(denom, sdk.NewInt(1000000))}) + suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom).Return(auctiontypes.TokenPrice{}, false).Times(2) feeTokenBalanceResponse, err := cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), nil) require.Nil(feeTokenBalanceResponse) require.NotNil(err) @@ -168,17 +175,13 @@ func (suite *KeeperTestSuite) TestQueriesUnhappyPath() { require.NotNil(err) require.Equal(status.Code(err), codes.InvalidArgument) - denom := feeDenom - suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, false) feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: denom}) require.Nil(feeTokenBalanceResponse) require.NotNil(err) require.Equal(status.Code(err), codes.NotFound) - suite.bankKeeper.EXPECT().GetDenomMetaData(ctx, denom).Return(banktypes.Metadata{}, true) suite.accountKeeper.EXPECT().GetModuleAccount(ctx, gomock.Any()).Return(feesAccount) - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), denom).Return(sdk.NewCoin(denom, sdk.NewInt(1000000))) - suite.auctionKeeper.EXPECT().GetTokenPrice(ctx, denom).Return(auctiontypes.TokenPrice{}, false) + suite.bankKeeper.EXPECT().GetAllBalances(ctx, feesAccount.GetAddress()).Return(sdk.Coins{sdk.NewCoin(denom, sdk.NewInt(1000000))}) feeTokenBalanceResponse, err = cellarfeesKeeper.QueryFeeTokenBalance(sdk.WrapSDKContext(ctx), &cellarfeestypesv2.QueryFeeTokenBalanceRequest{Denom: denom}) require.Nil(feeTokenBalanceResponse) require.NotNil(err) From 9f5ab51ae9fe579901084ac4a65687800fd987be Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 12 Mar 2024 10:27:09 -0500 Subject: [PATCH 26/28] Tweak comments and imports --- x/cellarfees/client/cli/query.go | 32 ++++++++++++++------------------ x/cellarfees/keeper/abci.go | 5 +++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/x/cellarfees/client/cli/query.go b/x/cellarfees/client/cli/query.go index 761199390..7d025c7a9 100644 --- a/x/cellarfees/client/cli/query.go +++ b/x/cellarfees/client/cli/query.go @@ -4,17 +4,13 @@ import ( "context" "fmt" - // "strings" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/v2. - cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" - types "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" + cellarfeestypesv2 "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2" ) // GetQueryCmd returns the cli query commands for this module @@ -46,9 +42,9 @@ func CmdQueryParams() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) + queryClient := cellarfeestypesv2.NewQueryClient(clientCtx) - res, err := queryClient.QueryParams(context.Background(), &types.QueryParamsRequest{}) + res, err := queryClient.QueryParams(context.Background(), &cellarfeestypesv2.QueryParamsRequest{}) if err != nil { return err } @@ -71,10 +67,10 @@ func CmdQueryModuleAccounts() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) + queryClient := cellarfeestypesv2.NewQueryClient(clientCtx) res, err := queryClient.QueryModuleAccounts( - context.Background(), &types.QueryModuleAccountsRequest{}) + context.Background(), &cellarfeestypesv2.QueryModuleAccountsRequest{}) if err != nil { return err } @@ -97,10 +93,10 @@ func CmdQueryLastRewardSupplyPeak() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { clientCtx := client.GetClientContextFromCmd(cmd) - queryClient := types.NewQueryClient(clientCtx) + queryClient := cellarfeestypesv2.NewQueryClient(clientCtx) res, err := queryClient.QueryLastRewardSupplyPeak( - context.Background(), &types.QueryLastRewardSupplyPeakRequest{}) + context.Background(), &cellarfeestypesv2.QueryLastRewardSupplyPeakRequest{}) if err != nil { return err } @@ -125,8 +121,8 @@ func CmdQueryAPY() *cobra.Command { return err } - queryClient := types.NewQueryClient(ctx) - req := &types.QueryAPYRequest{} + queryClient := cellarfeestypesv2.NewQueryClient(ctx) + req := &cellarfeestypesv2.QueryAPYRequest{} res, err := queryClient.QueryAPY(cmd.Context(), req) if err != nil { @@ -147,7 +143,7 @@ func CmdQueryFeeTokenBalance() *cobra.Command { Use: "fee-token-balance", Aliases: []string{"ftb"}, Args: cobra.ExactArgs(1), - Short: "query a fee tokens balance and its USD value in the cellarfees module", + Short: "query a fee token's balance and it's USD value in the cellarfees module", RunE: func(cmd *cobra.Command, _ []string) error { ctx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -156,8 +152,8 @@ func CmdQueryFeeTokenBalance() *cobra.Command { args := cmd.Flags().Args() - queryClient := types.NewQueryClient(ctx) - req := &types.QueryFeeTokenBalanceRequest{ + queryClient := cellarfeestypesv2.NewQueryClient(ctx) + req := &cellarfeestypesv2.QueryFeeTokenBalanceRequest{ Denom: args[0], } @@ -187,8 +183,8 @@ func CmdQueryFeeTokenBalances() *cobra.Command { return err } - queryClient := types.NewQueryClient(ctx) - req := &types.QueryFeeTokenBalancesRequest{} + queryClient := cellarfeestypesv2.NewQueryClient(ctx) + req := &cellarfeestypesv2.QueryFeeTokenBalancesRequest{} res, err := queryClient.QueryFeeTokenBalances(cmd.Context(), req) if err != nil { diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 13d50298f..37382f89a 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -28,6 +28,11 @@ func (k Keeper) handleRewardEmission(ctx sdk.Context) { emission := k.GetEmission(ctx, remainingRewardsSupply) + // sanity check. the upcoming bank keeper call will error causing a panic if this is zero + if emission.IsZero() { + return + } + // Send to fee collector for distribution ctx.Logger().Info("Sending rewards to fee collector", "module", types.ModuleName) err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, moduleAccount.GetName(), authtypes.FeeCollectorName, emission) From a723644e8884f9ecb9b17344c1fae21f0719e6bb Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 12 Mar 2024 10:28:07 -0500 Subject: [PATCH 27/28] Refactor beginAuction method --- x/cellarfees/keeper/abci.go | 2 +- x/cellarfees/keeper/auction.go | 8 +++----- x/cellarfees/keeper/auction_test.go | 27 ++++++--------------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/x/cellarfees/keeper/abci.go b/x/cellarfees/keeper/abci.go index 37382f89a..fa55c20bf 100644 --- a/x/cellarfees/keeper/abci.go +++ b/x/cellarfees/keeper/abci.go @@ -66,7 +66,7 @@ func (k Keeper) handleFeeAuctions(ctx sdk.Context) { usdValue := k.GetBalanceUsdValue(ctx, balance, tokenPrice) if usdValue.GTE(params.AuctionThresholdUsdValue) { - k.beginAuction(ctx, tokenPrice.Denom) + k.beginAuction(ctx, balance) } } } diff --git a/x/cellarfees/keeper/auction.go b/x/cellarfees/keeper/auction.go index ea4e4ab90..111b0cd4c 100644 --- a/x/cellarfees/keeper/auction.go +++ b/x/cellarfees/keeper/auction.go @@ -7,21 +7,19 @@ import ( ) // Attempts to start an auction for the provided denom -func (k Keeper) beginAuction(ctx sdk.Context, denom string) (started bool) { +func (k Keeper) beginAuction(ctx sdk.Context, balance sdk.Coin) bool { activeAuctions := k.auctionKeeper.GetActiveAuctions(ctx) // Don't start an auction if the denom has an active one for _, auction := range activeAuctions { - if denom == auction.StartingTokensForSale.Denom { + if balance.Denom == auction.StartingTokensForSale.Denom { return false } } - // We auction the entire balance in the cellarfees module account cellarfeesParams := k.GetParams(ctx) - balance := k.bankKeeper.GetBalance(ctx, k.GetFeesAccount(ctx).GetAddress(), denom) if balance.IsZero() { - k.Logger(ctx).Error("Attempted to begin auction for denom %s with a zero balance.", denom) + k.Logger(ctx).Error("Attempted to begin auction for denom %s with a zero balance.", balance.Denom) return false } diff --git a/x/cellarfees/keeper/auction_test.go b/x/cellarfees/keeper/auction_test.go index c4fb85721..6c52cb4ff 100644 --- a/x/cellarfees/keeper/auction_test.go +++ b/x/cellarfees/keeper/auction_test.go @@ -25,13 +25,10 @@ func (suite *KeeperTestSuite) TestHappyPathBeginAuction() { // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - // nonzero fee balance - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), feeDenom).Return(fees) - // begin auction doesn't error suite.auctionKeeper.EXPECT().BeginAuction(ctx, fees, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil) - require.True(cellarfeesKeeper.beginAuction(ctx, feeDenom)) + require.True(cellarfeesKeeper.beginAuction(ctx, fees)) } func (suite *KeeperTestSuite) TestAuctionFeeBalanceZeroDoesNotStartAuction() { @@ -49,10 +46,7 @@ func (suite *KeeperTestSuite) TestAuctionFeeBalanceZeroDoesNotStartAuction() { // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - // zero fee balance - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), feeDenom).Return(fees) - - require.False(cellarfeesKeeper.beginAuction(ctx, feeDenom)) + require.False(cellarfeesKeeper.beginAuction(ctx, fees)) } func (suite *KeeperTestSuite) TestAuctionUnauthorizedFundingModule() { @@ -70,13 +64,10 @@ func (suite *KeeperTestSuite) TestAuctionUnauthorizedFundingModule() { // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - // nonzero fee balance - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), feeDenom).Return(fees) - // begin auction errors suite.auctionKeeper.EXPECT().BeginAuction(ctx, fees, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(auctionTypes.ErrUnauthorizedFundingModule) - require.Panics(func() { cellarfeesKeeper.beginAuction(ctx, feeDenom) }) + require.Panics(func() { cellarfeesKeeper.beginAuction(ctx, fees) }) } func (suite *KeeperTestSuite) TestAuctionUnauthorizedProceedsModule() { @@ -94,13 +85,10 @@ func (suite *KeeperTestSuite) TestAuctionUnauthorizedProceedsModule() { // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - // nonzero fee balance - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), feeDenom).Return(fees) - // begin auction errors suite.auctionKeeper.EXPECT().BeginAuction(ctx, fees, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(auctionTypes.ErrUnauthorizedProceedsModule) - require.Panics(func() { cellarfeesKeeper.beginAuction(ctx, feeDenom) }) + require.Panics(func() { cellarfeesKeeper.beginAuction(ctx, fees) }) } func (suite *KeeperTestSuite) TestAuctionNonPanicError() { @@ -118,13 +106,10 @@ func (suite *KeeperTestSuite) TestAuctionNonPanicError() { // no active auctions suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{}) - // nonzero fee balance - suite.bankKeeper.EXPECT().GetBalance(ctx, feesAccount.GetAddress(), feeDenom).Return(fees) - // begin auction errors suite.auctionKeeper.EXPECT().BeginAuction(ctx, fees, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(auctionTypes.ErrDenomCannotBeEmpty) - require.False(cellarfeesKeeper.beginAuction(ctx, feeDenom)) + require.False(cellarfeesKeeper.beginAuction(ctx, fees)) } func (suite *KeeperTestSuite) TestAuctionAlreadyActive() { @@ -142,5 +127,5 @@ func (suite *KeeperTestSuite) TestAuctionAlreadyActive() { } suite.auctionKeeper.EXPECT().GetActiveAuctions(ctx).Return([]*auctionTypes.Auction{&testAuction}) - require.False(cellarfeesKeeper.beginAuction(ctx, feeDenom)) + require.False(cellarfeesKeeper.beginAuction(ctx, fees)) } From bff3e201bfceb9bdfbabc718d56fdb96e06c4c2c Mon Sep 17 00:00:00 2001 From: Collin Brittain Date: Tue, 12 Mar 2024 10:34:22 -0500 Subject: [PATCH 28/28] Comment in proto --- proto/cellarfees/v2/cellarfees.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/cellarfees/v2/cellarfees.proto b/proto/cellarfees/v2/cellarfees.proto index 345722d57..7f56b8702 100644 --- a/proto/cellarfees/v2/cellarfees.proto +++ b/proto/cellarfees/v2/cellarfees.proto @@ -6,6 +6,8 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/peggyjv/sommelier/v7/x/cellarfees/types/v2"; +// Collin: This type should never be saved to state in case of indeterminism around how +// Go interprets floating point numbers. This is only meant to be used for query results. message FeeTokenBalance { cosmos.base.v1beta1.Coin balance = 1 [ (gogoproto.nullable) = false ]; double usd_value = 2;