Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor market and rewards module #277

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/wasm/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (m *CustomMessenger) RemoveWhitelistAppIDVaultInterest(ctx sdk.Context, con

func MsgRemoveWhitelistAppIDVaultInterest(rewardsKeeper rewardskeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress,
a *bindings.MsgRemoveWhitelistAppIdVaultInterest) error {
err := rewardsKeeper.WasmRemoveWhitelistAppIdVaultInterest(ctx, a.AppMappingId)
err := rewardsKeeper.WasmRemoveWhitelistAppIDVaultInterest(ctx, a.AppMappingId)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions app/wasm/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func (qp QueryPlugin) GetTokenMint(ctx sdk.Context, appMappingID, assetID uint64
}

func (qp QueryPlugin) GetRemoveWhitelistAppIdLockerRewardsCheck(ctx sdk.Context, appMappingId uint64, assetId []uint64) (found bool, err string) {
found, err = qp.rewardsKeeper.GetRemoveWhitelistAppIdLockerRewardsCheck(ctx, appMappingId, assetId)
found, err = qp.rewardsKeeper.GetRemoveWhitelistAppIDLockerRewardsCheck(ctx, appMappingId, assetId)
return found, err
}

func (qp QueryPlugin) GetWhitelistAppIdVaultInterestCheck(ctx sdk.Context, appMappingId uint64) (found bool, err string) {
found, err = qp.rewardsKeeper.GetWhitelistAppIdVaultInterestCheck(ctx, appMappingId)
found, err = qp.rewardsKeeper.GetWhitelistAppIDVaultInterestCheck(ctx, appMappingId)
return found, err
}
func (qp QueryPlugin) GetWhitelistAppIdLockerRewardsCheck(ctx sdk.Context, appMappingId uint64, assetId []uint64) (found bool, err string) {
found, err = qp.rewardsKeeper.GetWhitelistAppIdLockerRewardsCheck(ctx, appMappingId, assetId)
found, err = qp.rewardsKeeper.GetWhitelistAppIDLockerRewardsCheck(ctx, appMappingId, assetId)

return found, err
}
Expand Down Expand Up @@ -116,7 +116,7 @@ func (qp QueryPlugin) UpdateCollectorLookupTableQueryCheck(ctx sdk.Context, appM
}

func (qp QueryPlugin) WasmRemoveWhitelistAppIdVaultInterestQueryCheck(ctx sdk.Context, AppMappingId uint64) (found bool, err string) {
found, err = qp.rewardsKeeper.WasmRemoveWhitelistAppIdVaultInterestQuery(ctx, AppMappingId)
found, err = qp.rewardsKeeper.WasmRemoveWhitelistAppIDVaultInterestQuery(ctx, AppMappingId)
return found, err
}

Expand Down
40 changes: 0 additions & 40 deletions x/market/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,41 +1 @@
package cli

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
"github.com/spf13/cobra"
)

const (
flagLiquidationRatio = "liquidation-ratio"
flagScriptID = "script-id"
flagPacketTimeoutHeight = "packet-timeout-height"
flagFeeLimit = "fee-limit"
)

func GetLiquidationRatio(cmd *cobra.Command) (sdk.Dec, error) {
s, err := cmd.Flags().GetString(flagLiquidationRatio)
if err != nil {
return sdk.Dec{}, err
}

return sdk.NewDecFromStr(s)
}

func GetPacketTimeoutHeight(cmd *cobra.Command) (ibcclienttypes.Height, error) {
s, err := cmd.Flags().GetString(flagPacketTimeoutHeight)
if err != nil {
return ibcclienttypes.Height{}, err
}

return ibcclienttypes.ParseHeight(s)
}

func GetFeeLimit(cmd *cobra.Command) (sdk.Coins, error) {
s, err := cmd.Flags().GetString(flagFeeLimit)
if err != nil {
return sdk.Coins{}, err
}

return sdk.ParseCoinsNormalized(s)
}
161 changes: 0 additions & 161 deletions x/market/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,162 +1 @@
package cli

import (
"strconv"

"github.com/comdex-official/comdex/x/market/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
)

func txAddMarket() *cobra.Command {
cmd := &cobra.Command{
Use: "add-market [symbol] [script-id] [asset]",
Short: "Add a market",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

scriptID, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

asset, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}

var rates uint64
rates = 0

msg := types.NewMsgAddMarketRequest(
ctx.FromAddress,
args[0],
scriptID,
asset,
rates,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func txUpdateMarket() *cobra.Command {
cmd := &cobra.Command{
Use: "update-market [symbol]",
Short: "Update a market",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

scriptID, err := cmd.Flags().GetUint64(flagScriptID)
if err != nil {
return err
}

//rates, _ := keeper.Keeper.GetPriceForMarket(keeper.Keeper{}, sdk.Context{},args[0])
var rates uint64
rates = 40
msg := types.NewMsgUpdateMarketRequest(
ctx.FromAddress,
args[0],
scriptID,
rates,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)
cmd.Flags().Uint64(flagScriptID, 0, "script identity")

return cmd
}

/*func txAddMarketForAsset() *cobra.Command {
cmd := &cobra.Command{
Use: "add-market-for-asset [asset] [symbol]",
Short: "Add a market for asset",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

asset, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgAddMarketForAssetRequest(
ctx.FromAddress,
asset,
args[1],
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}*/

func txRemoveMarketForAsset() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-market-for-asset [asset] [symbol]",
Short: "Remove a market for asset",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

asset, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgRemoveMarketForAssetRequest(
ctx.FromAddress,
asset,
args[1],
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
1 change: 0 additions & 1 deletion x/market/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) {

for _, item := range state.Markets {
k.SetMarket(ctx, item)
}
Expand Down
1 change: 0 additions & 1 deletion x/market/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Keeper struct {
}

func NewKeeper(cdc codec.BinaryCodec, key sdk.StoreKey, params paramstypes.Subspace, scoped expected.ScopedKeeper, assetKeeper assetkeeper.Keeper, bandoraclekeeper expected.BandOracleKeeper) *Keeper {

return &Keeper{
cdc: cdc,
key: key,
Expand Down
12 changes: 6 additions & 6 deletions x/market/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ func (k *Keeper) GetMarkets(ctx sdk.Context) (markets []types.Market) {
iter = sdk.KVStorePrefixIterator(store, types.MarketKeyPrefix)
)

defer iter.Close()
defer func(iter sdk.Iterator) {
err := iter.Close()
if err != nil {
return
}
}(iter)

for ; iter.Valid(); iter.Next() {
var market types.Market
Expand All @@ -58,7 +63,6 @@ func (k *Keeper) GetMarkets(ctx sdk.Context) (markets []types.Market) {
}

func (k *Keeper) GetPriceForMarket(ctx sdk.Context, symbol string) (uint64, bool) {

var (
store = k.Store(ctx)
key = types.PriceForMarketKey(symbol)
Expand All @@ -76,7 +80,6 @@ func (k *Keeper) GetPriceForMarket(ctx sdk.Context, symbol string) (uint64, bool
}

func (k *Keeper) GetRates(ctx sdk.Context, symbol string) (uint64, bool) {

var (
store = k.Store(ctx)
key = types.PriceForMarketKey(symbol)
Expand All @@ -94,7 +97,6 @@ func (k *Keeper) GetRates(ctx sdk.Context, symbol string) (uint64, bool) {
}

func (k *Keeper) SetRates(ctx sdk.Context, _ string) {

id := k.bandoraclekeeper.GetLastFetchPriceID(ctx)
data, _ := k.bandoraclekeeper.GetFetchPriceResult(ctx, bandoraclemoduletypes.OracleRequestID(id))

Expand All @@ -115,7 +117,6 @@ func (k *Keeper) SetRates(ctx sdk.Context, _ string) {
}
}
}

}

func (k *Keeper) SetMarketForAsset(ctx sdk.Context, id uint64, symbol string) {
Expand Down Expand Up @@ -168,7 +169,6 @@ func (k *Keeper) DeleteMarketForAsset(ctx sdk.Context, id uint64) {
}

func (k *Keeper) GetPriceForAsset(ctx sdk.Context, id uint64) (uint64, bool) {

if id == 1 {
return 220000, true
}
Expand Down
2 changes: 1 addition & 1 deletion x/market/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (q *queryServer) QueryMarket(c context.Context, req *types.QueryMarketReque

item, found := q.GetMarket(ctx, req.Symbol)
if !found {
return nil, status.Errorf(codes.NotFound, "market does not exist for symbol %d", req.Symbol)
return nil, status.Errorf(codes.NotFound, "market does not exist for symbol %s", req.Symbol)
}

return &types.QueryMarketResponse{
Expand Down
25 changes: 4 additions & 21 deletions x/market/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,17 @@ import (
)

var (
ErrorInvalidDecimals = errors.Register(ModuleName, 101, "invalid decimals")
ErrorInvalidDenom = errors.Register(ModuleName, 102, "invalid denom")
ErrorInvalidFrom = errors.Register(ModuleName, 103, "invalid from")
ErrorInvalidID = errors.Register(ModuleName, 104, "invalid id")
ErrorInvalidLiquidationRatio = errors.Register(ModuleName, 105, "invalid liquidation ratio")
ErrorInvalidName = errors.Register(ModuleName, 106, "invalid name")
ErrorInvalidScriptID = errors.Register(ModuleName, 107, "invalid script id")
ErrorInvalidSourceChannel = errors.Register(ModuleName, 108, "invalid source channel")
ErrorInvalidSourcePort = errors.Register(ModuleName, 109, "invalid source port")
ErrorInvalidSymbol = errors.Register(ModuleName, 110, "invalid symbol")
ErrorInvalidSymbols = errors.Register(ModuleName, 111, "invalid symbols")
ErrorInvalidFrom = errors.Register(ModuleName, 103, "invalid from")
ErrorInvalidID = errors.Register(ModuleName, 104, "invalid id")
ErrorInvalidScriptID = errors.Register(ModuleName, 107, "invalid script id")
ErrorInvalidSymbol = errors.Register(ModuleName, 110, "invalid symbol")
)

var (
ErrorAssetDoesNotExist = errors.Register(ModuleName, 201, "asset does not exist")
ErrorDuplicateAsset = errors.Register(ModuleName, 202, "duplicate asset")
ErrorDuplicateMarket = errors.Register(ModuleName, 203, "duplicate market")
ErrorDuplicateMarketForAsset = errors.Register(ModuleName, 204, "duplicate market for asset")
ErrorMarketDoesNotExist = errors.Register(ModuleName, 205, "market does not exist")
ErrorMarketForAssetDoesNotExist = errors.Register(ModuleName, 206, "market for asset does not exist")
ErrorPairDoesNotExist = errors.Register(ModuleName, 207, "pair does not exist")
ErrorScriptIDMismatch = errors.Register(ModuleName, 208, "script id mismatch")
ErrorUnauthorized = errors.Register(ModuleName, 209, "unauthorized")
)

var (
Expand All @@ -37,8 +25,3 @@ var (
var (
ErrorUnknownProposalType = errors.Register(ModuleName, 401, "unknown proposal type")
)

var (
ErrorInvalidVersion = errors.Register(ModuleName, 501, "invalid version")
ErrorMaxAssetChannels = errors.Register(ModuleName, 502, "max asset channels")
)
9 changes: 1 addition & 8 deletions x/market/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@ const (
)

var (
CalldataIDKey = []byte{0x02}

CalldataKeyPrefix = []byte{0x12}
MarketKeyPrefix = []byte{0x13}
MarketKeyPrefix = []byte{0x13}

MarketForAssetKeyPrefix = []byte{0x22}
PriceForMarketKeyPrefix = []byte{0x23}
)

func CalldataKey(id uint64) []byte {
return append(CalldataKeyPrefix, sdk.Uint64ToBigEndian(id)...)
}

func MarketKey(symbol string) []byte {
return append(MarketKeyPrefix, []byte(symbol)...)
}
Expand Down
Loading