diff --git a/proto/dex/params.proto b/proto/dex/params.proto index 546d828b76..7fb90c9a86 100644 --- a/proto/dex/params.proto +++ b/proto/dex/params.proto @@ -7,6 +7,8 @@ option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; // Params defines the parameters for the module. message Params { + option (gogoproto.equal) = true; option (gogoproto.goproto_stringer) = false; - + + uint64 price_snapshot_retention = 1 [(gogoproto.moretags) = "yaml:\"price_snapshot_retention\""]; } \ No newline at end of file diff --git a/proto/dex/price.proto b/proto/dex/price.proto new file mode 100644 index 0000000000..33fd4df25d --- /dev/null +++ b/proto/dex/price.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package seiprotocol.seichain.dex; + +import "gogoproto/gogo.proto"; +import "dex/pair.proto"; + +option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; + +message Price { + + uint64 snapshotTimestampInSeconds = 1; + string price = 2 [ + (gogoproto.moretags) = "yaml:\"price\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + Pair pair = 3; +} diff --git a/proto/dex/query.proto b/proto/dex/query.proto index fae51f9448..8dd319ea0e 100644 --- a/proto/dex/query.proto +++ b/proto/dex/query.proto @@ -8,8 +8,9 @@ import "dex/params.proto"; import "dex/long_book.proto"; import "dex/short_book.proto"; import "dex/settlement.proto"; -import "dex/twap.proto"; import "dex/enums.proto"; +import "dex/price.proto"; +import "dex/twap.proto"; // this line is used by starport scaffolding # 1 option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; @@ -44,9 +45,12 @@ service Query { option (google.api.http).get = "/sei-protocol/seichain/dex/settlement"; } -// Queries a list of GetTwap items. - rpc GetTwap(QueryGetTwapRequest) returns (QueryGetTwapResponse) { - option (google.api.http).get = "/sei-protocol/seichain/dex/get_twap/{priceDenom}/{assetDenom}"; + rpc GetPrices(QueryGetPricesRequest) returns (QueryGetPricesResponse) { + option (google.api.http).get = "/sei-protocol/seichain/dex/get_prices/{contractAddr}/{priceDenom}/{assetDenom}"; + } + + rpc GetTwaps(QueryGetTwapsRequest) returns (QueryGetTwapsResponse) { + option (google.api.http).get = "/sei-protocol/seichain/dex/get_twaps/{contractAddr}/{lookbackSeconds}"; } // this line is used by starport scaffolding # 2 @@ -127,14 +131,23 @@ message QueryAllSettlementsResponse { cosmos.base.query.v1beta1.PageResponse pagination = 2; } -message QueryGetTwapRequest { - Denom priceDenom = 1; - Denom assetDenom = 2; +message QueryGetPricesRequest { + Denom priceDenom = 1; + Denom assetDenom = 2; string contractAddr = 3; } -message QueryGetTwapResponse { - Twap twaps = 1; +message QueryGetPricesResponse { + repeated Price prices = 1; } +message QueryGetTwapsRequest { + string contractAddr = 1; + uint64 lookbackSeconds = 2; + } + + message QueryGetTwapsResponse { + repeated Twap twaps = 1; + } + // this line is used by starport scaffolding # 3 diff --git a/proto/dex/twap.proto b/proto/dex/twap.proto index d59a3b3729..fbbf65fc9f 100644 --- a/proto/dex/twap.proto +++ b/proto/dex/twap.proto @@ -1,13 +1,19 @@ syntax = "proto3"; package seiprotocol.seichain.dex; +import "gogoproto/gogo.proto"; +import "dex/pair.proto"; + option go_package = "github.com/sei-protocol/sei-chain/x/dex/types"; + message Twap { - - uint64 lastEpoch = 1; - repeated uint64 prices = 2; - uint64 twapPrice = 3; - string priceDenom = 4; - string assetDenom = 5; + + Pair pair = 1; + string twap = 2 [ + (gogoproto.moretags) = "yaml:\"twap\"", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + uint64 lookbackSeconds = 3; } diff --git a/x/dex/client/cli/query.go b/x/dex/client/cli/query.go index d942f7c175..350e969b7e 100644 --- a/x/dex/client/cli/query.go +++ b/x/dex/client/cli/query.go @@ -29,7 +29,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdShowLongBook()) cmd.AddCommand(CmdListShortBook()) cmd.AddCommand(CmdShowShortBook()) - cmd.AddCommand(CmdGetTwap()) + cmd.AddCommand(CmdGetPrice()) + cmd.AddCommand(CmdGetTwaps()) // this line is used by starport scaffolding # 1 diff --git a/x/dex/client/cli/query_get_prices.go b/x/dex/client/cli/query_get_prices.go new file mode 100644 index 0000000000..ca87cedbe9 --- /dev/null +++ b/x/dex/client/cli/query_get_prices.go @@ -0,0 +1,55 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdGetPrice() *cobra.Command { + cmd := &cobra.Command{ + Use: "get-prices [contract-address] [price-denom] [asset-denom]", + Short: "Query getPrices", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) (err error) { + reqContractAddr := args[0] + reqPriceDenom, _, err := types.GetDenomFromStr(args[1]) + if err != nil { + return err + } + reqAssetDenom, _, err := types.GetDenomFromStr(args[2]) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetPricesRequest{ + ContractAddr: reqContractAddr, + PriceDenom: reqPriceDenom, + AssetDenom: reqAssetDenom, + } + + res, err := queryClient.GetPrices(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dex/client/cli/query_get_twap.go b/x/dex/client/cli/query_get_twap.go deleted file mode 100644 index 42426e01c8..0000000000 --- a/x/dex/client/cli/query_get_twap.go +++ /dev/null @@ -1,61 +0,0 @@ -package cli - -import ( - "errors" - "strconv" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/sei-protocol/sei-chain/x/dex/types" - "github.com/spf13/cobra" -) - -var _ = strconv.Itoa(0) - -func CmdGetTwap() *cobra.Command { - cmd := &cobra.Command{ - Use: "get-twap [price-denom] [asset-denom]", - Short: "Query getTwap", - Args: cobra.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) (err error) { - reqPriceDenom, unit, err := types.GetDenomFromStr(args[0]) - if err != nil { - return err - } - if unit != types.Unit_STANDARD { - return errors.New("Denom must be in standard/whole unit (e.g. sei instead of usei)") - } - - reqAssetDenom, unit, err := types.GetDenomFromStr(args[1]) - if err != nil { - return err - } - if unit != types.Unit_STANDARD { - return errors.New("Denom must be in standard/whole unit (e.g. sei instead of usei)") - } - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryGetTwapRequest{ - PriceDenom: reqPriceDenom, - AssetDenom: reqAssetDenom, - } - - res, err := queryClient.GetTwap(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/dex/client/cli/query_get_twaps.go b/x/dex/client/cli/query_get_twaps.go new file mode 100644 index 0000000000..f251d020e5 --- /dev/null +++ b/x/dex/client/cli/query_get_twaps.go @@ -0,0 +1,49 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdGetTwaps() *cobra.Command { + cmd := &cobra.Command{ + Use: "get-twaps [contract-address] [lookback]", + Short: "Query getPrice", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + reqContractAddr := args[0] + reqLookback, err := strconv.ParseUint(args[1], 10, 64) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryGetTwapsRequest{ + ContractAddr: reqContractAddr, + LookbackSeconds: reqLookback, + } + + res, err := queryClient.GetTwaps(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/dex/genesis.go b/x/dex/genesis.go index ac47abe982..87a974b899 100644 --- a/x/dex/genesis.go +++ b/x/dex/genesis.go @@ -22,12 +22,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) // this line is used by starport scaffolding # genesis/module/init k.SetParams(ctx, genState.Params) - for _, twap := range genState.TwapList { - twap.LastEpoch = 0 - twap.TwapPrice = twap.Prices[0] - k.SetTwap(ctx, *twap, "genesis") - } - k.SetEpoch(ctx, genState.LastEpoch) } diff --git a/x/dex/keeper/grpc_query_get_twap.go b/x/dex/keeper/grpc_query_get_prices.go similarity index 52% rename from x/dex/keeper/grpc_query_get_twap.go rename to x/dex/keeper/grpc_query_get_prices.go index d413007b4b..01a77b34b6 100644 --- a/x/dex/keeper/grpc_query_get_twap.go +++ b/x/dex/keeper/grpc_query_get_prices.go @@ -9,16 +9,16 @@ import ( "google.golang.org/grpc/status" ) -func (k Keeper) GetTwap(goCtx context.Context, req *types.QueryGetTwapRequest) (*types.QueryGetTwapResponse, error) { +func (k Keeper) GetPrices(goCtx context.Context, req *types.QueryGetPricesRequest) (*types.QueryGetPricesResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } ctx := sdk.UnwrapSDKContext(goCtx) - twap := k.GetTwapState(ctx, req.ContractAddr, req.PriceDenom, req.AssetDenom) + prices := k.GetAllPrices(ctx, req.ContractAddr, types.Pair{PriceDenom: req.PriceDenom, AssetDenom: req.AssetDenom}) - return &types.QueryGetTwapResponse{ - Twaps: &twap, + return &types.QueryGetPricesResponse{ + Prices: prices, }, nil } diff --git a/x/dex/keeper/grpc_query_get_twaps.go b/x/dex/keeper/grpc_query_get_twaps.go new file mode 100644 index 0000000000..509391e65a --- /dev/null +++ b/x/dex/keeper/grpc_query_get_twaps.go @@ -0,0 +1,61 @@ +package keeper + +import ( + "context" + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) GetTwaps(goCtx context.Context, req *types.QueryGetTwapsRequest) (*types.QueryGetTwapsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + allRegisteredPairs := k.GetAllRegisteredPairs(ctx, req.ContractAddr) + twaps := []*types.Twap{} + for _, pair := range allRegisteredPairs { + prices := k.GetAllPrices(ctx, req.ContractAddr, pair) + twaps = append(twaps, &types.Twap{ + Pair: &pair, + Twap: calculateTwap(ctx, prices, req.LookbackSeconds), + LookbackSeconds: req.LookbackSeconds, + }) + } + + return &types.QueryGetTwapsResponse{ + Twaps: twaps, + }, nil +} + +func calculateTwap(ctx sdk.Context, prices []*types.Price, lookback uint64) sdk.Dec { + // sort prices in descending order to start iteration from the latest + sort.Slice(prices, func(p1, p2 int) bool { + return prices[p1].SnapshotTimestampInSeconds > prices[p2].SnapshotTimestampInSeconds + }) + var timeTraversed uint64 = 0 + var weightedPriceSum sdk.Dec = sdk.ZeroDec() + for _, price := range prices { + newTimeTraversed := uint64(ctx.BlockTime().Unix()) - price.SnapshotTimestampInSeconds + if newTimeTraversed > lookback { + weightedPriceSum = weightedPriceSum.Add( + price.Price.MulInt64(int64(lookback - timeTraversed)), + ) + timeTraversed = lookback + break + } + weightedPriceSum = weightedPriceSum.Add( + price.Price.MulInt64(int64(newTimeTraversed - timeTraversed)), + ) + timeTraversed = newTimeTraversed + } + if timeTraversed == 0 { + return sdk.ZeroDec() + } else { + return weightedPriceSum.QuoInt64(int64(timeTraversed)) + } +} diff --git a/x/dex/keeper/grpc_query_get_twaps_test.go b/x/dex/keeper/grpc_query_get_twaps_test.go new file mode 100644 index 0000000000..24f0e385b7 --- /dev/null +++ b/x/dex/keeper/grpc_query_get_twaps_test.go @@ -0,0 +1,144 @@ +package keeper_test + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" + "github.com/sei-protocol/sei-chain/x/dex/types" + "github.com/stretchr/testify/require" +) + +const GENESIS_TIME uint64 = 3600 + +var TEST_PAIR = types.Pair{ + PriceDenom: TEST_PRICE_DENOM, + AssetDenom: TEST_ASSET_DENOM, +} + +func TestGetTwapsNoPriceSnapshot(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + wctx := sdk.WrapSDKContext(ctx) + var lookback uint64 = 10 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: sdk.ZeroDec(), + LookbackSeconds: lookback, + }, + }, + } + t.Run("No snapshot", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} + +func TestGetTwapsOnePriceSnapshot(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + ctx = ctx.WithBlockTime(time.Unix(int64(GENESIS_TIME)+5, 0)) + wctx := sdk.WrapSDKContext(ctx) + + snapshotPrice := sdk.MustNewDecFromStr("100.00") + keeper.SetPriceState(ctx, types.Price{ + SnapshotTimestampInSeconds: GENESIS_TIME, + Price: snapshotPrice, + Pair: &TEST_PAIR, + }, TEST_CONTRACT, 0) + + var lookback uint64 = 10 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: snapshotPrice, + LookbackSeconds: lookback, + }, + }, + } + t.Run("One snapshot", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) + + lookback = 4 + request = types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedResponse = types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: snapshotPrice, + LookbackSeconds: lookback, + }, + }, + } + t.Run("One old snapshot", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} + +func TestGetTwapsMultipleSnapshots(t *testing.T) { + keeper, ctx := keepertest.DexKeeper(t) + keeper.AddRegisteredPair(ctx, TEST_CONTRACT, TEST_PAIR) + ctx = ctx.WithBlockTime(time.Unix(int64(GENESIS_TIME)+20, 0)) + wctx := sdk.WrapSDKContext(ctx) + + snapshotPrices := []sdk.Dec{ + sdk.MustNewDecFromStr("100.00"), + sdk.MustNewDecFromStr("98.50"), + sdk.MustNewDecFromStr("101.00"), + } + timestampDeltas := []uint64{0, 10, 15} + for i := range snapshotPrices { + keeper.SetPriceState(ctx, types.Price{ + SnapshotTimestampInSeconds: GENESIS_TIME + timestampDeltas[i], + Price: snapshotPrices[i], + Pair: &TEST_PAIR, + }, TEST_CONTRACT, uint64(i)) + } + + var lookback uint64 = 20 + request := types.QueryGetTwapsRequest{ + ContractAddr: TEST_CONTRACT, + LookbackSeconds: lookback, + } + expectedTwap := snapshotPrices[0].MulInt64(10).Add( + snapshotPrices[1].MulInt64(15 - 10), + ).Add( + snapshotPrices[2].MulInt64(20 - 15), + ).QuoInt64(20) + require.Equal(t, sdk.MustNewDecFromStr("99.875"), expectedTwap) + expectedResponse := types.QueryGetTwapsResponse{ + Twaps: []*types.Twap{ + { + Pair: &TEST_PAIR, + Twap: expectedTwap, + LookbackSeconds: lookback, + }, + }, + } + t.Run("Multiple snapshots", func(t *testing.T) { + response, err := keeper.GetTwaps(wctx, &request) + require.NoError(t, err) + require.Equal(t, expectedResponse, *response) + }) +} diff --git a/x/dex/keeper/params.go b/x/dex/keeper/params.go index 92ce38d221..30087a9987 100644 --- a/x/dex/keeper/params.go +++ b/x/dex/keeper/params.go @@ -7,7 +7,9 @@ import ( // GetParams get all parameters as types.Params func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams() + params := types.Params{} + k.paramstore.GetParamSet(ctx, ¶ms) + return params } // SetParams set the params diff --git a/x/dex/keeper/price.go b/x/dex/keeper/price.go new file mode 100644 index 0000000000..661b8e0d37 --- /dev/null +++ b/x/dex/keeper/price.go @@ -0,0 +1,61 @@ +package keeper + +import ( + "encoding/binary" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/dex/types" +) + +func (k Keeper) SetPriceState(ctx sdk.Context, price types.Price, contractAddr string, epoch uint64) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + b := k.Cdc.MustMarshal(&price) + store.Set(GetKeyForPriceState(epoch, *price.Pair), b) +} + +func (k Keeper) DeletePriceState(ctx sdk.Context, contractAddr string, epoch uint64, pair types.Pair) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + store.Delete(GetKeyForPriceState(epoch, pair)) +} + +func (k Keeper) GetPriceState(ctx sdk.Context, contractAddr string, epoch uint64, pair types.Pair) (types.Price, bool) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + res := types.Price{} + key := GetKeyForPriceState(epoch, pair) + if !store.Has(key) { + res.Pair = &pair + return res, false + } + b := store.Get(key) + k.Cdc.MustUnmarshal(b, &res) + return res, true +} + +func (k Keeper) GetAllPrices(ctx sdk.Context, contractAddr string, pair types.Pair) (list []*types.Price) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.PricePrefix(contractAddr)) + iterator := sdk.KVStorePrefixIterator(store, types.PairPrefix(pair.PriceDenom, pair.AssetDenom)) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.Price + k.Cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, &val) + } + + return +} + +func GetKeyForEpoch(epoch uint64) []byte { + epochKey := make([]byte, 8) + binary.BigEndian.PutUint64(epochKey, epoch) + return epochKey +} + +func GetKeyForPriceState(epoch uint64, pair types.Pair) []byte { + return append( + types.PairPrefix(pair.PriceDenom, pair.AssetDenom), + GetKeyForEpoch(epoch)..., + ) +} diff --git a/x/dex/keeper/twap.go b/x/dex/keeper/twap.go deleted file mode 100644 index 8a67022fc0..0000000000 --- a/x/dex/keeper/twap.go +++ /dev/null @@ -1,44 +0,0 @@ -package keeper - -import ( - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/x/dex/types" -) - -func (k Keeper) SetTwap(ctx sdk.Context, twap types.Twap, contractAddr string) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - b := k.Cdc.MustMarshal(&twap) - priceDenom, _, err := types.GetDenomFromStr(twap.PriceDenom) - if err != nil { - panic(err) - } - assetDenom, _, err := types.GetDenomFromStr(twap.AssetDenom) - if err != nil { - panic(err) - } - store.Set(types.PairPrefix(priceDenom, assetDenom), b) -} - -func (k Keeper) GetTwapState(ctx sdk.Context, contractAddr string, priceDenom types.Denom, assetDenom types.Denom) types.Twap { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - b := store.Get(types.PairPrefix(priceDenom, assetDenom)) - res := types.Twap{} - k.Cdc.MustUnmarshal(b, &res) - return res -} - -func (k Keeper) GetAllTwaps(ctx sdk.Context, contractAddr string) (list []types.Twap) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.TwapPrefix(contractAddr)) - iterator := sdk.KVStorePrefixIterator(store, []byte{}) - - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - var val types.Twap - k.Cdc.MustUnmarshal(iterator.Value(), &val) - list = append(list, val) - } - - return -} diff --git a/x/dex/module.go b/x/dex/module.go index c8538a0fe4..bfd4793877 100644 --- a/x/dex/module.go +++ b/x/dex/module.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "strconv" "github.com/CosmWasm/wasmd/x/wasm" "github.com/gorilla/mux" @@ -207,6 +206,9 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { for _, contractAddr := range am.getAllContractAddresses(ctx) { am.beginBlockForContract(ctx, contractAddr) } + if isNewEpoch, currentEpoch := am.keeper.IsNewEpoch(ctx); isNewEpoch { + am.keeper.SetEpoch(ctx, currentEpoch) + } } func (am AppModule) beginBlockForContract(ctx sdk.Context, contractAddr string) { @@ -228,51 +230,25 @@ func (am AppModule) beginBlockForContract(ctx sdk.Context, contractAddr string) ctx.Logger().Info(fmt.Sprintf("Orders %s, %s", am.keeper.Orders, contractAddr)) if isNewEpoch, currentEpoch := am.keeper.IsNewEpoch(ctx); isNewEpoch { - ctx.Logger().Info(fmt.Sprintf("Updating funding payment rate for epoch %d", currentEpoch)) - for _, twap := range am.keeper.GetAllTwaps(ctx, contractAddr) { - dexPrice := twap.TwapPrice - ctx.Logger().Info(fmt.Sprintf("%s/%s: %d", twap.PriceDenom, twap.AssetDenom, dexPrice)) - oraclePrice := uint64(100) // TODO: replace with oracle call - var diff uint64 - var negative bool - if dexPrice < oraclePrice { - diff = oraclePrice - dexPrice - negative = true - } else { - diff = dexPrice - oraclePrice - negative = false - } - nativeSetFPRMsg := types.SudoSetFundingPaymentRateMsg{ - SetFundingPaymentRate: types.SetFundingPaymentRate{ - Epoch: currentEpoch, - AssetDenom: twap.AssetDenom, - PriceDiff: strconv.FormatUint(diff, 10), - Negative: negative, - }, - } - wasmMsg, err := json.Marshal(nativeSetFPRMsg) - if err != nil { - ctx.Logger().Info(err.Error()) + ctx.Logger().Info(fmt.Sprintf("Updating price for epoch %d", currentEpoch)) + priceRetention := am.keeper.GetParams(ctx).PriceSnapshotRetention + for _, pair := range am.keeper.GetAllRegisteredPairs(ctx, contractAddr) { + lastEpochPrice, exists := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch-1, pair) + if exists { + newEpochPrice := types.Price{ + SnapshotTimestampInSeconds: uint64(ctx.BlockTime().Unix()), + Pair: &pair, + Price: lastEpochPrice.Price, + } + am.keeper.SetPriceState(ctx, newEpochPrice, contractAddr, currentEpoch) } - ctx.Logger().Info("Setting funding payment rate") - am.callClearingHouseContractSudo(ctx, wasmMsg, contractAddr) - - var newPrices []uint64 - if len(twap.Prices) == 24 { // replace with config - newPrices = append(twap.Prices[1:], twap.Prices[len(twap.Prices)-1]) - } else { - newPrices = append(twap.Prices, twap.Prices[len(twap.Prices)-1]) + // condition to prevent unsigned integer overflow + if currentEpoch >= priceRetention { + // this will no-op if price snapshot for the target epoch doesn't exist + am.keeper.DeletePriceState(ctx, contractAddr, currentEpoch-priceRetention, pair) } - am.keeper.SetTwap(ctx, types.Twap{ - LastEpoch: currentEpoch, - Prices: newPrices, - TwapPrice: getTwapPrice(newPrices), - PriceDenom: twap.PriceDenom, - AssetDenom: twap.AssetDenom, - }, contractAddr) } - am.keeper.SetEpoch(ctx, currentEpoch) } } @@ -292,6 +268,8 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { defer span.End() registeredPairs := am.keeper.GetAllRegisteredPairs(ctx, contractAddr) + _, currentEpoch := am.keeper.IsNewEpoch(ctx) + am.keeper.HandleEBLiquidation(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) am.keeper.HandleEBPlaceOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) @@ -348,20 +326,10 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { avgPrice = sdk.ZeroDec() } else { avgPrice = (marketBuyTotalPrice.Add(marketSellTotalPrice).Add(limitTotalPrice)).Quo(marketBuyTotalQuantity.Add(marketSellTotalQuantity).Add(limitTotalQuantity)) - twap := am.keeper.GetTwapState(ctx, contractAddr, pair.PriceDenom, pair.AssetDenom) - newPrices := twap.Prices - if len(newPrices) == 0 { - newPrices = []uint64{avgPrice.BigInt().Uint64()} - } else { - newPrices[len(newPrices)-1] = avgPrice.BigInt().Uint64() - } - am.keeper.SetTwap(ctx, types.Twap{ - LastEpoch: am.keeper.EpochKeeper.GetEpoch(ctx).CurrentEpoch, - Prices: newPrices, - TwapPrice: getTwapPrice(newPrices), - PriceDenom: pair.PriceDenom.String(), - AssetDenom: pair.AssetDenom.String(), - }, contractAddr) + priceState, _ := am.keeper.GetPriceState(ctx, contractAddr, currentEpoch, pair) + priceState.SnapshotTimestampInSeconds = uint64(ctx.BlockTime().Unix()) + priceState.Price = avgPrice + am.keeper.SetPriceState(ctx, priceState, contractAddr, currentEpoch) } ctx.Logger().Info(fmt.Sprintf("Average price for %s/%s: %d", pair.PriceDenom, pair.AssetDenom, avgPrice)) for _, buy := range allExistingBuys { @@ -455,11 +423,3 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contractAddr string) { // Cancel unfilled market orders am.keeper.HandleEBCancelOrders(spanCtx, ctx, am.tracingInfo.Tracer, contractAddr, registeredPairs) } - -func getTwapPrice(prices []uint64) uint64 { - var total uint64 = 0 - for _, price := range prices { - total += price - } - return total / uint64(len(prices)) -} diff --git a/x/dex/types/funding_payment_rate.go b/x/dex/types/funding_payment_rate.go deleted file mode 100644 index 3ee18ebc38..0000000000 --- a/x/dex/types/funding_payment_rate.go +++ /dev/null @@ -1,12 +0,0 @@ -package types - -type SudoSetFundingPaymentRateMsg struct { - SetFundingPaymentRate SetFundingPaymentRate `json:"set_funding_payment_rate"` -} - -type SetFundingPaymentRate struct { - Epoch uint64 `json:"epoch"` - AssetDenom string `json:"asset_denom"` - PriceDiff string `json:"price_diff"` - Negative bool `json:"negative"` -} diff --git a/x/dex/types/genesis.go b/x/dex/types/genesis.go index f9378c3a5e..6cb58ee95d 100644 --- a/x/dex/types/genesis.go +++ b/x/dex/types/genesis.go @@ -15,22 +15,6 @@ func DefaultGenesis() *GenesisState { // this line is used by starport scaffolding # genesis/types/default Params: DefaultParams(), LastEpoch: 0, - TwapList: []*Twap{ - { - LastEpoch: 0, - Prices: []uint64{105}, - TwapPrice: 105, - PriceDenom: "usdc", - AssetDenom: "sei", - }, - { - LastEpoch: 0, - Prices: []uint64{105}, - TwapPrice: 105, - PriceDenom: "usdc", - AssetDenom: "atom", - }, - }, } } diff --git a/x/dex/types/keys.go b/x/dex/types/keys.go index 1a51e497c0..8ad25db6da 100644 --- a/x/dex/types/keys.go +++ b/x/dex/types/keys.go @@ -52,6 +52,10 @@ func TwapPrefix(contractAddr string) []byte { return append(KeyPrefix(TwapKey), KeyPrefix(contractAddr)...) } +func PricePrefix(contractAddr string) []byte { + return append(KeyPrefix(PriceKey), KeyPrefix(contractAddr)...) +} + func SettlementEntryPrefix(contractAddr string, blockHeight uint64) []byte { return append( append(KeyPrefix(SettlementEntryKey), KeyPrefix(contractAddr)...), @@ -89,6 +93,7 @@ const ( ) const TwapKey = "TWAP-" +const PriceKey = "Price-" const SettlementEntryKey = "SettlementEntry-" diff --git a/x/dex/types/params.go b/x/dex/types/params.go index 357196ad6a..62b33f074b 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -1,10 +1,20 @@ package types import ( + fmt "fmt" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "gopkg.in/yaml.v2" ) +var ( + KeyPriceSnapshotRetention = []byte("PriceSnapshotRetention") // number of epochs to retain price snapshots for +) + +const ( + DefaultPriceSnapshotRetention = 1440 // default epoch interval is one minute so this results in a one-day retention +) + var _ paramtypes.ParamSet = (*Params)(nil) // ParamKeyTable the param key table for launch module @@ -19,12 +29,16 @@ func NewParams() Params { // DefaultParams returns a default set of parameters func DefaultParams() Params { - return NewParams() + return Params{ + PriceSnapshotRetention: DefaultPriceSnapshotRetention, + } } // ParamSetPairs get the params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{} + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyPriceSnapshotRetention, &p.PriceSnapshotRetention, validatePriceSnapshotRetention), + } } // Validate validates the set of params @@ -37,3 +51,16 @@ func (p Params) String() string { out, _ := yaml.Marshal(p) return string(out) } + +func validatePriceSnapshotRetention(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("price snapshot retention must be a positive integer: %d", v) + } + + return nil +} diff --git a/x/dex/types/params.pb.go b/x/dex/types/params.pb.go index f3c816fcca..4b898d9c9a 100644 --- a/x/dex/types/params.pb.go +++ b/x/dex/types/params.pb.go @@ -25,6 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { + PriceSnapshotRetention uint64 `protobuf:"varint,1,opt,name=price_snapshot_retention,json=priceSnapshotRetention,proto3" json:"price_snapshot_retention,omitempty" yaml:"price_snapshot_retention"` } func (m *Params) Reset() { *m = Params{} } @@ -59,6 +60,13 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +func (m *Params) GetPriceSnapshotRetention() uint64 { + if m != nil { + return m.PriceSnapshotRetention + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "seiprotocol.seichain.dex.Params") } @@ -66,19 +74,47 @@ func init() { func init() { proto.RegisterFile("dex/params.proto", fileDescriptor_e49286500ccff43e) } var fileDescriptor_e49286500ccff43e = []byte{ - // 156 bytes of a gzipped FileDescriptorProto + // 220 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x48, 0x49, 0xad, 0xd0, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, 0x2b, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0xbd, - 0x12, 0x1f, 0x17, 0x5b, 0x00, 0x58, 0xbf, 0x15, 0xcb, 0x8c, 0x05, 0xf2, 0x0c, 0x4e, 0xee, 0x27, - 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, - 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9b, 0x9e, 0x59, 0x92, 0x51, 0x9a, - 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x5f, 0x9c, 0x9a, 0xa9, 0x0b, 0xb3, 0x05, 0xcc, 0x01, 0x5b, 0xa3, - 0x5f, 0xa1, 0x0f, 0x72, 0x4f, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0xde, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0x6a, 0x11, 0x75, 0x70, 0xa3, 0x00, 0x00, 0x00, + 0x52, 0x21, 0x17, 0x5b, 0x00, 0x58, 0xbf, 0x50, 0x2c, 0x97, 0x44, 0x41, 0x51, 0x66, 0x72, 0x6a, + 0x7c, 0x71, 0x5e, 0x62, 0x41, 0x71, 0x46, 0x7e, 0x49, 0x7c, 0x51, 0x6a, 0x49, 0x6a, 0x5e, 0x49, + 0x66, 0x7e, 0x9e, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x8b, 0x93, 0xf2, 0xa7, 0x7b, 0xf2, 0xf2, 0x95, + 0x89, 0xb9, 0x39, 0x56, 0x4a, 0xb8, 0x54, 0x2a, 0x05, 0x89, 0x81, 0xa5, 0x82, 0xa1, 0x32, 0x41, + 0x30, 0x09, 0x2b, 0x8e, 0x19, 0x0b, 0xe4, 0x19, 0x5e, 0x2c, 0x90, 0x67, 0x74, 0x72, 0x3f, 0xf1, + 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, + 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xdd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, + 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xd4, 0x4c, 0x5d, 0x98, 0x47, 0xc0, 0x1c, 0xb0, 0x4f, 0xf4, + 0x2b, 0xf4, 0x41, 0x5e, 0x2e, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xcb, 0x1b, 0x03, 0x02, + 0x00, 0x00, 0xff, 0xff, 0xb9, 0xf5, 0xe8, 0x21, 0x06, 0x01, 0x00, 0x00, } +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.PriceSnapshotRetention != that1.PriceSnapshotRetention { + return false + } + return true +} func (m *Params) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -99,6 +135,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.PriceSnapshotRetention != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.PriceSnapshotRetention)) + i-- + dAtA[i] = 0x8 + } return len(dAtA) - i, nil } @@ -119,6 +160,9 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.PriceSnapshotRetention != 0 { + n += 1 + sovParams(uint64(m.PriceSnapshotRetention)) + } return n } @@ -157,6 +201,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PriceSnapshotRetention", wireType) + } + m.PriceSnapshotRetention = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PriceSnapshotRetention |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/dex/types/price.go b/x/dex/types/price.go new file mode 100644 index 0000000000..e95760d42a --- /dev/null +++ b/x/dex/types/price.go @@ -0,0 +1,17 @@ +package types + +type SudoSetPricesMsg struct { + SetPrices SetPrices `json:"set_prices"` +} + +type SetPrices struct { + Prices []SetPrice `json:"prices"` +} + +type SetPrice struct { + Epoch uint64 `json:"epoch"` + PriceDenom string `json:"price_denom"` + AssetDenom string `json:"asset_denom"` + ExchangePrice string `json:"exchange_price"` + OraclePrice string `json:"oracle_price"` +} diff --git a/x/dex/types/price.pb.go b/x/dex/types/price.pb.go new file mode 100644 index 0000000000..39bf38bf1f --- /dev/null +++ b/x/dex/types/price.pb.go @@ -0,0 +1,415 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: dex/price.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/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 Price struct { + SnapshotTimestampInSeconds uint64 `protobuf:"varint,1,opt,name=snapshotTimestampInSeconds,proto3" json:"snapshotTimestampInSeconds,omitempty"` + Price github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=price,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"price" yaml:"price"` + Pair *Pair `protobuf:"bytes,3,opt,name=pair,proto3" json:"pair,omitempty"` +} + +func (m *Price) Reset() { *m = Price{} } +func (m *Price) String() string { return proto.CompactTextString(m) } +func (*Price) ProtoMessage() {} +func (*Price) Descriptor() ([]byte, []int) { + return fileDescriptor_bd5d1c9d490efb8c, []int{0} +} +func (m *Price) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Price) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Price.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 *Price) XXX_Merge(src proto.Message) { + xxx_messageInfo_Price.Merge(m, src) +} +func (m *Price) XXX_Size() int { + return m.Size() +} +func (m *Price) XXX_DiscardUnknown() { + xxx_messageInfo_Price.DiscardUnknown(m) +} + +var xxx_messageInfo_Price proto.InternalMessageInfo + +func (m *Price) GetSnapshotTimestampInSeconds() uint64 { + if m != nil { + return m.SnapshotTimestampInSeconds + } + return 0 +} + +func (m *Price) GetPair() *Pair { + if m != nil { + return m.Pair + } + return nil +} + +func init() { + proto.RegisterType((*Price)(nil), "seiprotocol.seichain.dex.Price") +} + +func init() { proto.RegisterFile("dex/price.proto", fileDescriptor_bd5d1c9d490efb8c) } + +var fileDescriptor_bd5d1c9d490efb8c = []byte{ + // 285 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4f, 0x49, 0xad, 0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, 0x4a, 0x30, 0x2b, 0x30, 0x6a, 0x70, 0x1b, 0xc9, 0xe9, 0xe1, 0xf2, + 0xae, 0x5e, 0x40, 0x62, 0x66, 0x51, 0x10, 0x58, 0xad, 0x93, 0xfb, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0x22, 0x39, 0xa6, 0x38, 0x35, 0x53, 0x17, 0x66, 0x14, 0x98, + 0x03, 0x36, 0x4b, 0xbf, 0x42, 0x1f, 0x14, 0x42, 0x60, 0x77, 0x25, 0xb1, 0x81, 0xe5, 0x8d, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x55, 0x90, 0xf5, 0xec, 0x76, 0x01, 0x00, 0x00, +} + +func (m *Price) 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 *Price) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Price) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pair != nil { + { + size, err := m.Pair.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPrice(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + { + size := m.Price.Size() + i -= size + if _, err := m.Price.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintPrice(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if m.SnapshotTimestampInSeconds != 0 { + i = encodeVarintPrice(dAtA, i, uint64(m.SnapshotTimestampInSeconds)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintPrice(dAtA []byte, offset int, v uint64) int { + offset -= sovPrice(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Price) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SnapshotTimestampInSeconds != 0 { + n += 1 + sovPrice(uint64(m.SnapshotTimestampInSeconds)) + } + l = m.Price.Size() + n += 1 + l + sovPrice(uint64(l)) + if m.Pair != nil { + l = m.Pair.Size() + n += 1 + l + sovPrice(uint64(l)) + } + return n +} + +func sovPrice(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPrice(x uint64) (n int) { + return sovPrice(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Price) 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 ErrIntOverflowPrice + } + 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: Price: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Price: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SnapshotTimestampInSeconds", wireType) + } + m.SnapshotTimestampInSeconds = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SnapshotTimestampInSeconds |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Price", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + 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 ErrInvalidLengthPrice + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPrice + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Price.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pair", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPrice + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPrice + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPrice + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pair == nil { + m.Pair = &Pair{} + } + if err := m.Pair.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPrice(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPrice + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPrice(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, ErrIntOverflowPrice + } + 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, ErrIntOverflowPrice + } + 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, ErrIntOverflowPrice + } + 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, ErrInvalidLengthPrice + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPrice + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPrice + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPrice = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPrice = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPrice = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/dex/types/query.pb.go b/x/dex/types/query.pb.go index bd6fc10e5c..e11b0effb0 100644 --- a/x/dex/types/query.pb.go +++ b/x/dex/types/query.pb.go @@ -785,24 +785,24 @@ func (m *QueryAllSettlementsResponse) GetPagination() *query.PageResponse { return nil } -type QueryGetTwapRequest struct { +type QueryGetPricesRequest struct { PriceDenom Denom `protobuf:"varint,1,opt,name=priceDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"priceDenom,omitempty"` AssetDenom Denom `protobuf:"varint,2,opt,name=assetDenom,proto3,enum=seiprotocol.seichain.dex.Denom" json:"assetDenom,omitempty"` ContractAddr string `protobuf:"bytes,3,opt,name=contractAddr,proto3" json:"contractAddr,omitempty"` } -func (m *QueryGetTwapRequest) Reset() { *m = QueryGetTwapRequest{} } -func (m *QueryGetTwapRequest) String() string { return proto.CompactTextString(m) } -func (*QueryGetTwapRequest) ProtoMessage() {} -func (*QueryGetTwapRequest) Descriptor() ([]byte, []int) { +func (m *QueryGetPricesRequest) Reset() { *m = QueryGetPricesRequest{} } +func (m *QueryGetPricesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetPricesRequest) ProtoMessage() {} +func (*QueryGetPricesRequest) Descriptor() ([]byte, []int) { return fileDescriptor_d8e98105e6e08a59, []int{14} } -func (m *QueryGetTwapRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryGetPricesRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetPricesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetTwapRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetPricesRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -812,55 +812,55 @@ func (m *QueryGetTwapRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *QueryGetTwapRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetTwapRequest.Merge(m, src) +func (m *QueryGetPricesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPricesRequest.Merge(m, src) } -func (m *QueryGetTwapRequest) XXX_Size() int { +func (m *QueryGetPricesRequest) XXX_Size() int { return m.Size() } -func (m *QueryGetTwapRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetTwapRequest.DiscardUnknown(m) +func (m *QueryGetPricesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPricesRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetTwapRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryGetPricesRequest proto.InternalMessageInfo -func (m *QueryGetTwapRequest) GetPriceDenom() Denom { +func (m *QueryGetPricesRequest) GetPriceDenom() Denom { if m != nil { return m.PriceDenom } return Denom_SEI } -func (m *QueryGetTwapRequest) GetAssetDenom() Denom { +func (m *QueryGetPricesRequest) GetAssetDenom() Denom { if m != nil { return m.AssetDenom } return Denom_SEI } -func (m *QueryGetTwapRequest) GetContractAddr() string { +func (m *QueryGetPricesRequest) GetContractAddr() string { if m != nil { return m.ContractAddr } return "" } -type QueryGetTwapResponse struct { - Twaps *Twap `protobuf:"bytes,1,opt,name=twaps,proto3" json:"twaps,omitempty"` +type QueryGetPricesResponse struct { + Prices []*Price `protobuf:"bytes,1,rep,name=prices,proto3" json:"prices,omitempty"` } -func (m *QueryGetTwapResponse) Reset() { *m = QueryGetTwapResponse{} } -func (m *QueryGetTwapResponse) String() string { return proto.CompactTextString(m) } -func (*QueryGetTwapResponse) ProtoMessage() {} -func (*QueryGetTwapResponse) Descriptor() ([]byte, []int) { +func (m *QueryGetPricesResponse) Reset() { *m = QueryGetPricesResponse{} } +func (m *QueryGetPricesResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetPricesResponse) ProtoMessage() {} +func (*QueryGetPricesResponse) Descriptor() ([]byte, []int) { return fileDescriptor_d8e98105e6e08a59, []int{15} } -func (m *QueryGetTwapResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryGetPricesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryGetTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryGetPricesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryGetTwapResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryGetPricesResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -870,19 +870,115 @@ func (m *QueryGetTwapResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte return b[:n], nil } } -func (m *QueryGetTwapResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryGetTwapResponse.Merge(m, src) +func (m *QueryGetPricesResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetPricesResponse.Merge(m, src) } -func (m *QueryGetTwapResponse) XXX_Size() int { +func (m *QueryGetPricesResponse) XXX_Size() int { return m.Size() } -func (m *QueryGetTwapResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryGetTwapResponse.DiscardUnknown(m) +func (m *QueryGetPricesResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetPricesResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryGetTwapResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryGetPricesResponse proto.InternalMessageInfo -func (m *QueryGetTwapResponse) GetTwaps() *Twap { +func (m *QueryGetPricesResponse) GetPrices() []*Price { + if m != nil { + return m.Prices + } + return nil +} + +type QueryGetTwapsRequest struct { + ContractAddr string `protobuf:"bytes,1,opt,name=contractAddr,proto3" json:"contractAddr,omitempty"` + LookbackSeconds uint64 `protobuf:"varint,2,opt,name=lookbackSeconds,proto3" json:"lookbackSeconds,omitempty"` +} + +func (m *QueryGetTwapsRequest) Reset() { *m = QueryGetTwapsRequest{} } +func (m *QueryGetTwapsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryGetTwapsRequest) ProtoMessage() {} +func (*QueryGetTwapsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d8e98105e6e08a59, []int{16} +} +func (m *QueryGetTwapsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetTwapsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetTwapsRequest.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 *QueryGetTwapsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetTwapsRequest.Merge(m, src) +} +func (m *QueryGetTwapsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryGetTwapsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetTwapsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetTwapsRequest proto.InternalMessageInfo + +func (m *QueryGetTwapsRequest) GetContractAddr() string { + if m != nil { + return m.ContractAddr + } + return "" +} + +func (m *QueryGetTwapsRequest) GetLookbackSeconds() uint64 { + if m != nil { + return m.LookbackSeconds + } + return 0 +} + +type QueryGetTwapsResponse struct { + Twaps []*Twap `protobuf:"bytes,1,rep,name=twaps,proto3" json:"twaps,omitempty"` +} + +func (m *QueryGetTwapsResponse) Reset() { *m = QueryGetTwapsResponse{} } +func (m *QueryGetTwapsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryGetTwapsResponse) ProtoMessage() {} +func (*QueryGetTwapsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d8e98105e6e08a59, []int{17} +} +func (m *QueryGetTwapsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryGetTwapsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryGetTwapsResponse.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 *QueryGetTwapsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryGetTwapsResponse.Merge(m, src) +} +func (m *QueryGetTwapsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryGetTwapsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryGetTwapsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryGetTwapsResponse proto.InternalMessageInfo + +func (m *QueryGetTwapsResponse) GetTwaps() []*Twap { if m != nil { return m.Twaps } @@ -904,74 +1000,81 @@ func init() { proto.RegisterType((*QueryGetSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryGetSettlementsResponse") proto.RegisterType((*QueryAllSettlementsRequest)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsRequest") proto.RegisterType((*QueryAllSettlementsResponse)(nil), "seiprotocol.seichain.dex.QueryAllSettlementsResponse") - proto.RegisterType((*QueryGetTwapRequest)(nil), "seiprotocol.seichain.dex.QueryGetTwapRequest") - proto.RegisterType((*QueryGetTwapResponse)(nil), "seiprotocol.seichain.dex.QueryGetTwapResponse") + proto.RegisterType((*QueryGetPricesRequest)(nil), "seiprotocol.seichain.dex.QueryGetPricesRequest") + proto.RegisterType((*QueryGetPricesResponse)(nil), "seiprotocol.seichain.dex.QueryGetPricesResponse") + proto.RegisterType((*QueryGetTwapsRequest)(nil), "seiprotocol.seichain.dex.QueryGetTwapsRequest") + proto.RegisterType((*QueryGetTwapsResponse)(nil), "seiprotocol.seichain.dex.QueryGetTwapsResponse") } func init() { proto.RegisterFile("dex/query.proto", fileDescriptor_d8e98105e6e08a59) } var fileDescriptor_d8e98105e6e08a59 = []byte{ - // 950 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcd, 0x4f, 0x1b, 0x47, - 0x14, 0xf7, 0xd8, 0x40, 0xcb, 0x18, 0xd1, 0x6a, 0xb0, 0x54, 0x77, 0x5b, 0x19, 0x77, 0x11, 0x85, - 0x56, 0xf5, 0xae, 0x30, 0xf4, 0xd8, 0x22, 0x10, 0xad, 0x7b, 0x80, 0x96, 0xba, 0x85, 0x56, 0x95, - 0x1a, 0xb2, 0x5e, 0x8f, 0xd6, 0x2b, 0xd6, 0x3b, 0x8b, 0x77, 0x1c, 0x40, 0x88, 0x4b, 0x2e, 0xc9, - 0x11, 0x29, 0x7f, 0x45, 0xa4, 0x44, 0x39,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0x57, 0x75, 0xa6, 0xd4, 0x83, 0xe4, 0x7d, 0x33, 0x6b, 0x77, 0x3f, 0x8b, 0x9b, 0x8c, 0xd9, - 0x3a, 0xfa, 0x7d, 0xb0, 0xcc, 0xd0, 0x3d, 0x00, 0xc7, 0x43, 0xef, 0x52, 0x87, 0xd3, 0x42, 0x0f, - 0xfd, 0x45, 0xee, 0x0e, 0xe1, 0xc7, 0x3e, 0x51, 0x9c, 0x57, 0x81, 0xf1, 0x9a, 0x41, 0xd3, 0x9d, - 0x78, 0xf9, 0x38, 0xf4, 0x00, 0xc0, 0x4f, 0xf8, 0xfb, 0x0d, 0x15, 0xba, 0x3b, 0x24, 0xf4, 0x12, - 0x17, 0xa4, 0x5e, 0xd3, 0x79, 0x67, 0xbf, 0xb0, 0xce, 0x16, 0xd1, 0x4f, 0x1d, 0x3a, 0xd3, 0x30, - 0xdd, 0x72, 0x5e, 0x97, 0xf1, 0x02, 0x2f, 0x97, 0x8e, 0x4f, 0x73, 0xe0, 0xe4, 0x34, 0x07, 0xde, - 0x9c, 0xe6, 0xc0, 0xd1, 0x59, 0x2e, 0x71, 0x72, 0x96, 0x4b, 0xbc, 0x3a, 0xcb, 0x25, 0xfe, 0x2b, - 0x68, 0x3a, 0xad, 0x35, 0x2b, 0x92, 0x4a, 0xea, 0x91, 0x12, 0x05, 0xb7, 0xc6, 0x1e, 0xab, 0x42, - 0xf7, 0x2d, 0x6c, 0x57, 0x46, 0xd8, 0xf3, 0xf9, 0xb7, 0x01, 0x00, 0x00, 0xff, 0xff, 0x53, 0x51, - 0x3f, 0x93, 0x6e, 0x10, 0x00, 0x00, + // 1033 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x57, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xce, 0xd8, 0x49, 0xd4, 0xbc, 0x44, 0x29, 0x9a, 0x1a, 0x30, 0x0b, 0x72, 0xc3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c5, 0x6f, 0x6a, 0xaa, 0x8f, 0x6f, + 0x2b, 0x7b, 0x70, 0x68, 0xc6, 0xc4, 0xf9, 0xc8, 0x62, 0x47, 0xb1, 0xa8, 0xd1, 0x37, 0xc7, 0xb0, + 0x50, 0xaf, 0xfe, 0x1c, 0x89, 0xbe, 0x93, 0xa6, 0xbb, 0x5d, 0x7b, 0x70, 0x52, 0x21, 0xc7, 0x27, + 0x15, 0xf2, 0xf7, 0x49, 0x85, 0xdc, 0x3f, 0xad, 0xcc, 0x1d, 0x9f, 0x56, 0xe6, 0xfe, 0x3c, 0xad, + 0xcc, 0x7d, 0x54, 0xb5, 0x1d, 0xb9, 0x7f, 0xd0, 0xd0, 0x2d, 0xd1, 0xce, 0x95, 0xaa, 0x46, 0xb5, + 0x0e, 0x55, 0x35, 0x79, 0xcf, 0xe7, 0x41, 0x63, 0x51, 0xad, 0x5f, 0xfd, 0x27, 0x00, 0x00, 0xff, + 0xff, 0x49, 0xf8, 0x5a, 0x39, 0x0f, 0x12, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -997,8 +1100,8 @@ type QueryClient interface { // Queries a list of ShortBook items. ShortBookAll(ctx context.Context, in *QueryAllShortBookRequest, opts ...grpc.CallOption) (*QueryAllShortBookResponse, error) SettlementsAll(ctx context.Context, in *QueryAllSettlementsRequest, opts ...grpc.CallOption) (*QueryAllSettlementsResponse, error) - // Queries a list of GetTwap items. - GetTwap(ctx context.Context, in *QueryGetTwapRequest, opts ...grpc.CallOption) (*QueryGetTwapResponse, error) + GetPrices(ctx context.Context, in *QueryGetPricesRequest, opts ...grpc.CallOption) (*QueryGetPricesResponse, error) + GetTwaps(ctx context.Context, in *QueryGetTwapsRequest, opts ...grpc.CallOption) (*QueryGetTwapsResponse, error) } type queryClient struct { @@ -1063,9 +1166,18 @@ func (c *queryClient) SettlementsAll(ctx context.Context, in *QueryAllSettlement return out, nil } -func (c *queryClient) GetTwap(ctx context.Context, in *QueryGetTwapRequest, opts ...grpc.CallOption) (*QueryGetTwapResponse, error) { - out := new(QueryGetTwapResponse) - err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetTwap", in, out, opts...) +func (c *queryClient) GetPrices(ctx context.Context, in *QueryGetPricesRequest, opts ...grpc.CallOption) (*QueryGetPricesResponse, error) { + out := new(QueryGetPricesResponse) + err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetPrices", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) GetTwaps(ctx context.Context, in *QueryGetTwapsRequest, opts ...grpc.CallOption) (*QueryGetTwapsResponse, error) { + out := new(QueryGetTwapsResponse) + err := c.cc.Invoke(ctx, "/seiprotocol.seichain.dex.Query/GetTwaps", in, out, opts...) if err != nil { return nil, err } @@ -1085,8 +1197,8 @@ type QueryServer interface { // Queries a list of ShortBook items. ShortBookAll(context.Context, *QueryAllShortBookRequest) (*QueryAllShortBookResponse, error) SettlementsAll(context.Context, *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) - // Queries a list of GetTwap items. - GetTwap(context.Context, *QueryGetTwapRequest) (*QueryGetTwapResponse, error) + GetPrices(context.Context, *QueryGetPricesRequest) (*QueryGetPricesResponse, error) + GetTwaps(context.Context, *QueryGetTwapsRequest) (*QueryGetTwapsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1111,8 +1223,11 @@ func (*UnimplementedQueryServer) ShortBookAll(ctx context.Context, req *QueryAll func (*UnimplementedQueryServer) SettlementsAll(ctx context.Context, req *QueryAllSettlementsRequest) (*QueryAllSettlementsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SettlementsAll not implemented") } -func (*UnimplementedQueryServer) GetTwap(ctx context.Context, req *QueryGetTwapRequest) (*QueryGetTwapResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetTwap not implemented") +func (*UnimplementedQueryServer) GetPrices(ctx context.Context, req *QueryGetPricesRequest) (*QueryGetPricesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetPrices not implemented") +} +func (*UnimplementedQueryServer) GetTwaps(ctx context.Context, req *QueryGetTwapsRequest) (*QueryGetTwapsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetTwaps not implemented") } func RegisterQueryServer(s grpc1.Server, srv QueryServer) { @@ -1227,20 +1342,38 @@ func _Query_SettlementsAll_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } -func _Query_GetTwap_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryGetTwapRequest) +func _Query_GetPrices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetPricesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).GetPrices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/seiprotocol.seichain.dex.Query/GetPrices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).GetPrices(ctx, req.(*QueryGetPricesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_GetTwaps_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryGetTwapsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).GetTwap(ctx, in) + return srv.(QueryServer).GetTwaps(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/seiprotocol.seichain.dex.Query/GetTwap", + FullMethod: "/seiprotocol.seichain.dex.Query/GetTwaps", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).GetTwap(ctx, req.(*QueryGetTwapRequest)) + return srv.(QueryServer).GetTwaps(ctx, req.(*QueryGetTwapsRequest)) } return interceptor(ctx, in, info, handler) } @@ -1274,8 +1407,12 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_SettlementsAll_Handler, }, { - MethodName: "GetTwap", - Handler: _Query_GetTwap_Handler, + MethodName: "GetPrices", + Handler: _Query_GetPrices_Handler, + }, + { + MethodName: "GetTwaps", + Handler: _Query_GetTwaps_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -1862,7 +1999,7 @@ func (m *QueryAllSettlementsResponse) MarshalToSizedBuffer(dAtA []byte) (int, er return len(dAtA) - i, nil } -func (m *QueryGetTwapRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPricesRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1872,12 +2009,12 @@ func (m *QueryGetTwapRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetTwapRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPricesRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPricesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1902,7 +2039,7 @@ func (m *QueryGetTwapRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryGetTwapResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryGetPricesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1912,31 +2049,105 @@ func (m *QueryGetTwapResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryGetTwapResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryGetPricesResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryGetTwapResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryGetPricesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.Twaps != nil { - { - size, err := m.Twaps.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if len(m.Prices) > 0 { + for iNdEx := len(m.Prices) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Prices[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0xa } + } + return len(dAtA) - i, nil +} + +func (m *QueryGetTwapsRequest) 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 *QueryGetTwapsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetTwapsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.LookbackSeconds != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.LookbackSeconds)) + i-- + dAtA[i] = 0x10 + } + if len(m.ContractAddr) > 0 { + i -= len(m.ContractAddr) + copy(dAtA[i:], m.ContractAddr) + i = encodeVarintQuery(dAtA, i, uint64(len(m.ContractAddr))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } +func (m *QueryGetTwapsResponse) 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 *QueryGetTwapsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryGetTwapsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Twaps) > 0 { + for iNdEx := len(m.Twaps) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Twaps[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 encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -2185,7 +2396,7 @@ func (m *QueryAllSettlementsResponse) Size() (n int) { return n } -func (m *QueryGetTwapRequest) Size() (n int) { +func (m *QueryGetPricesRequest) Size() (n int) { if m == nil { return 0 } @@ -2204,16 +2415,49 @@ func (m *QueryGetTwapRequest) Size() (n int) { return n } -func (m *QueryGetTwapResponse) Size() (n int) { +func (m *QueryGetPricesResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Prices) > 0 { + for _, e := range m.Prices { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func (m *QueryGetTwapsRequest) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Twaps != nil { - l = m.Twaps.Size() + l = len(m.ContractAddr) + if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.LookbackSeconds != 0 { + n += 1 + sovQuery(uint64(m.LookbackSeconds)) + } + return n +} + +func (m *QueryGetTwapsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Twaps) > 0 { + for _, e := range m.Twaps { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } return n } @@ -3806,7 +4050,7 @@ func (m *QueryAllSettlementsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { +func (m *QueryGetPricesRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3829,10 +4073,10 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetTwapRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetPricesRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetTwapRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetPricesRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -3926,7 +4170,7 @@ func (m *QueryGetTwapRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { +func (m *QueryGetPricesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -3949,15 +4193,15 @@ func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryGetTwapResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryGetPricesResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryGetTwapResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryGetPricesResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Twaps", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -3984,10 +4228,193 @@ func (m *QueryGetTwapResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Twaps == nil { - m.Twaps = &Twap{} + m.Prices = append(m.Prices, &Price{}) + if err := m.Prices[len(m.Prices)-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 *QueryGetTwapsRequest) 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: QueryGetTwapsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetTwapsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractAddr", 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.ContractAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LookbackSeconds", wireType) + } + m.LookbackSeconds = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LookbackSeconds |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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 *QueryGetTwapsResponse) 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: QueryGetTwapsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryGetTwapsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Twaps", 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.Twaps.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Twaps = append(m.Twaps, &Twap{}) + if err := m.Twaps[len(m.Twaps)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/dex/types/query.pb.gw.go b/x/dex/types/query.pb.gw.go index 72a078cbd9..93360c07a4 100644 --- a/x/dex/types/query.pb.gw.go +++ b/x/dex/types/query.pb.gw.go @@ -599,12 +599,8 @@ func local_request_Query_SettlementsAll_0(ctx context.Context, marshaler runtime } -var ( - filter_Query_GetTwap_0 = &utilities.DoubleArray{Encoding: map[string]int{"priceDenom": 0, "assetDenom": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} -) - -func request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetTwapRequest +func request_Query_GetPrices_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPricesRequest var metadata runtime.ServerMetadata var ( @@ -615,6 +611,17 @@ func request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, c _ = err ) + val, ok = pathParams["contractAddr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") + } + + protoReq.ContractAddr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) + } + val, ok = pathParams["priceDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") @@ -641,20 +648,13 @@ func request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, c protoReq.AssetDenom = Denom(e) - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetTwap_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.GetTwap(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.GetPrices(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryGetTwapRequest +func local_request_Query_GetPrices_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetPricesRequest var metadata runtime.ServerMetadata var ( @@ -665,6 +665,17 @@ func local_request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marsha _ = err ) + val, ok = pathParams["contractAddr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") + } + + protoReq.ContractAddr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) + } + val, ok = pathParams["priceDenom"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "priceDenom") @@ -691,14 +702,83 @@ func local_request_Query_GetTwap_0(ctx context.Context, marshaler runtime.Marsha protoReq.AssetDenom = Denom(e) - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + msg, err := server.GetPrices(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_GetTwaps_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetTwapsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["contractAddr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_GetTwap_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + + protoReq.ContractAddr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) + } + + val, ok = pathParams["lookbackSeconds"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookbackSeconds") + } + + protoReq.LookbackSeconds, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookbackSeconds", err) + } + + msg, err := client.GetTwaps(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_GetTwaps_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryGetTwapsRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["contractAddr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "contractAddr") } - msg, err := server.GetTwap(ctx, &protoReq) + protoReq.ContractAddr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "contractAddr", err) + } + + val, ok = pathParams["lookbackSeconds"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "lookbackSeconds") + } + + protoReq.LookbackSeconds, err = runtime.Uint64(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "lookbackSeconds", err) + } + + msg, err := server.GetTwaps(ctx, &protoReq) return msg, metadata, err } @@ -847,7 +927,30 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_GetTwap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrices_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_GetPrices_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_GetPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetTwaps_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -858,7 +961,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_GetTwap_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_GetTwaps_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 { @@ -866,7 +969,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_GetTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetTwaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1031,7 +1134,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_GetTwap_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_GetPrices_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) @@ -1040,14 +1143,34 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_GetTwap_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_GetPrices_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_GetTwap_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_GetPrices_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_GetTwaps_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_GetTwaps_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_GetTwaps_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1067,7 +1190,9 @@ var ( pattern_Query_SettlementsAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sei-protocol", "seichain", "dex", "settlement"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_GetTwap_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sei-protocol", "seichain", "dex", "get_twap", "priceDenom", "assetDenom"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_GetPrices_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"sei-protocol", "seichain", "dex", "get_prices", "contractAddr", "priceDenom", "assetDenom"}, "", runtime.AssumeColonVerbOpt(true))) + + pattern_Query_GetTwaps_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sei-protocol", "seichain", "dex", "get_twaps", "contractAddr", "lookbackSeconds"}, "", runtime.AssumeColonVerbOpt(true))) ) var ( @@ -1083,5 +1208,7 @@ var ( forward_Query_SettlementsAll_0 = runtime.ForwardResponseMessage - forward_Query_GetTwap_0 = runtime.ForwardResponseMessage + forward_Query_GetPrices_0 = runtime.ForwardResponseMessage + + forward_Query_GetTwaps_0 = runtime.ForwardResponseMessage ) diff --git a/x/dex/types/twap.pb.go b/x/dex/types/twap.pb.go index 3e795a0aef..8307ea0114 100644 --- a/x/dex/types/twap.pb.go +++ b/x/dex/types/twap.pb.go @@ -5,6 +5,8 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -23,11 +25,9 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Twap struct { - LastEpoch uint64 `protobuf:"varint,1,opt,name=lastEpoch,proto3" json:"lastEpoch,omitempty"` - Prices []uint64 `protobuf:"varint,2,rep,packed,name=prices,proto3" json:"prices,omitempty"` - TwapPrice uint64 `protobuf:"varint,3,opt,name=twapPrice,proto3" json:"twapPrice,omitempty"` - PriceDenom string `protobuf:"bytes,4,opt,name=priceDenom,proto3" json:"priceDenom,omitempty"` - AssetDenom string `protobuf:"bytes,5,opt,name=assetDenom,proto3" json:"assetDenom,omitempty"` + Pair *Pair `protobuf:"bytes,1,opt,name=pair,proto3" json:"pair,omitempty"` + Twap github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=twap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"twap" yaml:"twap"` + LookbackSeconds uint64 `protobuf:"varint,3,opt,name=lookbackSeconds,proto3" json:"lookbackSeconds,omitempty"` } func (m *Twap) Reset() { *m = Twap{} } @@ -63,41 +63,20 @@ func (m *Twap) XXX_DiscardUnknown() { var xxx_messageInfo_Twap proto.InternalMessageInfo -func (m *Twap) GetLastEpoch() uint64 { +func (m *Twap) GetPair() *Pair { if m != nil { - return m.LastEpoch - } - return 0 -} - -func (m *Twap) GetPrices() []uint64 { - if m != nil { - return m.Prices + return m.Pair } return nil } -func (m *Twap) GetTwapPrice() uint64 { +func (m *Twap) GetLookbackSeconds() uint64 { if m != nil { - return m.TwapPrice + return m.LookbackSeconds } return 0 } -func (m *Twap) GetPriceDenom() string { - if m != nil { - return m.PriceDenom - } - return "" -} - -func (m *Twap) GetAssetDenom() string { - if m != nil { - return m.AssetDenom - } - return "" -} - func init() { proto.RegisterType((*Twap)(nil), "seiprotocol.seichain.dex.Twap") } @@ -105,21 +84,25 @@ func init() { func init() { proto.RegisterFile("dex/twap.proto", fileDescriptor_10aa4b136085207a) } var fileDescriptor_10aa4b136085207a = []byte{ - // 224 bytes of a gzipped FileDescriptorProto + // 273 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4b, 0x49, 0xad, 0xd0, 0x2f, 0x29, 0x4f, 0x2c, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x28, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0x52, 0x52, - 0x2b, 0x94, 0x66, 0x31, 0x72, 0xb1, 0x84, 0x94, 0x27, 0x16, 0x08, 0xc9, 0x70, 0x71, 0xe6, 0x24, - 0x16, 0x97, 0xb8, 0x16, 0xe4, 0x27, 0x67, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0x21, 0x04, - 0x84, 0xc4, 0xb8, 0xd8, 0x0a, 0x8a, 0x32, 0x93, 0x53, 0x8b, 0x25, 0x98, 0x14, 0x98, 0x35, 0x58, - 0x82, 0xa0, 0x3c, 0x90, 0x2e, 0x90, 0x35, 0x01, 0x20, 0x9e, 0x04, 0x33, 0x44, 0x17, 0x5c, 0x40, - 0x48, 0x8e, 0x8b, 0x0b, 0xac, 0xce, 0x25, 0x35, 0x2f, 0x3f, 0x57, 0x82, 0x45, 0x81, 0x51, 0x83, - 0x33, 0x08, 0x49, 0x04, 0x24, 0x9f, 0x58, 0x5c, 0x9c, 0x5a, 0x02, 0x91, 0x67, 0x85, 0xc8, 0x23, - 0x44, 0x9c, 0xdc, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, - 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x37, 0x3d, - 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, 0x17, 0xe6, 0x39, - 0x30, 0x07, 0xec, 0x3b, 0xfd, 0x0a, 0x7d, 0x70, 0x20, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, - 0xe5, 0x8d, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x98, 0x40, 0x0f, 0xa7, 0x18, 0x01, 0x00, 0x00, + 0x2b, 0xa4, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x52, 0xfa, 0x20, 0x16, 0x44, 0xbd, 0x14, 0x58, + 0x7f, 0x41, 0x62, 0x66, 0x11, 0x84, 0xaf, 0xb4, 0x9d, 0x91, 0x8b, 0x25, 0xa4, 0x3c, 0xb1, 0x40, + 0xc8, 0x88, 0x8b, 0x05, 0x24, 0x2c, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa7, 0x87, 0xcb, + 0x5c, 0xbd, 0x80, 0xc4, 0xcc, 0xa2, 0x20, 0xb0, 0x5a, 0xa1, 0x40, 0x2e, 0x16, 0x90, 0x53, 0x24, + 0x98, 0x14, 0x18, 0x35, 0x38, 0x9d, 0x6c, 0x4f, 0xdc, 0x93, 0x67, 0xb8, 0x75, 0x4f, 0x5e, 0x2d, + 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x3f, 0x39, 0xbf, 0x38, 0x37, 0xbf, + 0x18, 0x4a, 0xe9, 0x16, 0xa7, 0x64, 0xeb, 0x97, 0x54, 0x16, 0xa4, 0x16, 0xeb, 0xb9, 0xa4, 0x26, + 0x7f, 0xba, 0x27, 0xcf, 0x5d, 0x99, 0x98, 0x9b, 0x63, 0xa5, 0x04, 0x32, 0x43, 0x29, 0x08, 0x6c, + 0x94, 0x90, 0x06, 0x17, 0x7f, 0x4e, 0x7e, 0x7e, 0x76, 0x52, 0x62, 0x72, 0x76, 0x70, 0x6a, 0x72, + 0x7e, 0x5e, 0x4a, 0xb1, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4b, 0x10, 0xba, 0xb0, 0x93, 0xfb, 0x89, + 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, + 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0x22, 0x39, 0xa0, 0x38, 0x35, 0x53, + 0x17, 0xe6, 0x0f, 0x30, 0x07, 0xec, 0x11, 0xfd, 0x0a, 0x7d, 0x70, 0x38, 0x82, 0xdc, 0x92, 0xc4, + 0x06, 0x96, 0x37, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x99, 0x67, 0x7b, 0xff, 0x5b, 0x01, 0x00, + 0x00, } func (m *Twap) Marshal() (dAtA []byte, err error) { @@ -142,47 +125,32 @@ func (m *Twap) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.AssetDenom) > 0 { - i -= len(m.AssetDenom) - copy(dAtA[i:], m.AssetDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.AssetDenom))) - i-- - dAtA[i] = 0x2a - } - if len(m.PriceDenom) > 0 { - i -= len(m.PriceDenom) - copy(dAtA[i:], m.PriceDenom) - i = encodeVarintTwap(dAtA, i, uint64(len(m.PriceDenom))) - i-- - dAtA[i] = 0x22 - } - if m.TwapPrice != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.TwapPrice)) + if m.LookbackSeconds != 0 { + i = encodeVarintTwap(dAtA, i, uint64(m.LookbackSeconds)) i-- dAtA[i] = 0x18 } - if len(m.Prices) > 0 { - dAtA2 := make([]byte, len(m.Prices)*10) - var j1 int - for _, num := range m.Prices { - for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA2[j1] = uint8(num) - j1++ + { + size := m.Twap.Size() + i -= size + if _, err := m.Twap.MarshalTo(dAtA[i:]); err != nil { + return 0, err } - i -= j1 - copy(dAtA[i:], dAtA2[:j1]) - i = encodeVarintTwap(dAtA, i, uint64(j1)) - i-- - dAtA[i] = 0x12 + i = encodeVarintTwap(dAtA, i, uint64(size)) } - if m.LastEpoch != 0 { - i = encodeVarintTwap(dAtA, i, uint64(m.LastEpoch)) + i-- + dAtA[i] = 0x12 + if m.Pair != nil { + { + size, err := m.Pair.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTwap(dAtA, i, uint64(size)) + } i-- - dAtA[i] = 0x8 + dAtA[i] = 0xa } return len(dAtA) - i, nil } @@ -204,26 +172,14 @@ func (m *Twap) Size() (n int) { } var l int _ = l - if m.LastEpoch != 0 { - n += 1 + sovTwap(uint64(m.LastEpoch)) - } - if len(m.Prices) > 0 { - l = 0 - for _, e := range m.Prices { - l += sovTwap(uint64(e)) - } - n += 1 + sovTwap(uint64(l)) + l - } - if m.TwapPrice != 0 { - n += 1 + sovTwap(uint64(m.TwapPrice)) - } - l = len(m.PriceDenom) - if l > 0 { + if m.Pair != nil { + l = m.Pair.Size() n += 1 + l + sovTwap(uint64(l)) } - l = len(m.AssetDenom) - if l > 0 { - n += 1 + l + sovTwap(uint64(l)) + l = m.Twap.Size() + n += 1 + l + sovTwap(uint64(l)) + if m.LookbackSeconds != 0 { + n += 1 + sovTwap(uint64(m.LookbackSeconds)) } return n } @@ -264,10 +220,10 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LastEpoch", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pair", wireType) } - m.LastEpoch = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTwap @@ -277,109 +233,31 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.LastEpoch |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - case 2: - if wireType == 0 { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthTwap - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Prices) == 0 { - m.Prices = make([]uint64, 0, elementCount) - } - for iNdEx < postIndex { - var v uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Prices = append(m.Prices, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Prices", wireType) + if msglen < 0 { + return ErrInvalidLengthTwap } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TwapPrice", wireType) + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTwap } - m.TwapPrice = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTwap - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TwapPrice |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } + if postIndex > l { + return io.ErrUnexpectedEOF } - case 4: + if m.Pair == nil { + m.Pair = &Pair{} + } + if err := m.Pair.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field PriceDenom", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Twap", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -407,13 +285,15 @@ func (m *Twap) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.PriceDenom = string(dAtA[iNdEx:postIndex]) + if err := m.Twap.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AssetDenom", wireType) + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LookbackSeconds", wireType) } - var stringLen uint64 + m.LookbackSeconds = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTwap @@ -423,24 +303,11 @@ func (m *Twap) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + m.LookbackSeconds |= uint64(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTwap - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTwap - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AssetDenom = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTwap(dAtA[iNdEx:])