Skip to content

Commit

Permalink
merge: listings with split shares, marketplace commission, royalty tr…
Browse files Browse the repository at this point in the history
…ansfer to nft creator (#7)

- marketplace commission for nft sale 
- sale splits option for listing
- royalty share transfer
  • Loading branch information
harish551 authored Feb 14, 2022
2 parents 66cf1d0 + 345baa2 commit f54ef33
Show file tree
Hide file tree
Showing 38 changed files with 2,407 additions and 279 deletions.
22 changes: 19 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -350,13 +351,15 @@ func New(
&stakingKeeper, govRouter,
)
app.ONFTKeeper = onftkeeper.NewKeeper(appCodec, keys[onfttypes.StoreKey])
onftModule := onft.NewAppModule(appCodec, app.ONFTKeeper)
onftModule := onft.NewAppModule(appCodec, app.ONFTKeeper, app.AccountKeeper, app.BankKeeper)
app.MarketplaceKeeper = marketplacemodulekeeper.NewKeeper(
appCodec,
keys[marketplacemoduletypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.ONFTKeeper,
app.DistrKeeper,
app.GetSubspace(marketplacemoduletypes.ModuleName),
)
marketplaceModule := marketplacemodule.NewAppModule(appCodec, app.MarketplaceKeeper)

Expand Down Expand Up @@ -410,10 +413,19 @@ func New(
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
feegrant.ModuleName,
feegrant.ModuleName, marketplacemoduletypes.ModuleName, onfttypes.ModuleName, ibctransfertypes.ModuleName, authtypes.ModuleName,
vestingtypes.ModuleName, govtypes.ModuleName, genutiltypes.ModuleName, crisistypes.ModuleName,
paramstypes.ModuleName, banktypes.ModuleName,
)

app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName,
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
feegrant.ModuleName, marketplacemoduletypes.ModuleName, onfttypes.ModuleName, ibctransfertypes.ModuleName, authtypes.ModuleName,
vestingtypes.ModuleName, genutiltypes.ModuleName,
paramstypes.ModuleName, banktypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand All @@ -434,6 +446,10 @@ func New(
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
upgradetypes.ModuleName,
onfttypes.ModuleName,
marketplacemoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
Expand Down
21 changes: 7 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ module github.com/OmniFlix/marketplace
go 1.16

require (
github.com/OmniFlix/onft v0.2.0
github.com/cosmos/cosmos-sdk v0.44.3
github.com/OmniFlix/onft v0.3.0-alpha.1
github.com/cosmos/cosmos-sdk v0.45.1
github.com/cosmos/ibc-go v1.2.2
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.3 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/tendermint/spm v0.1.8
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83
google.golang.org/grpc v1.40.0
gopkg.in/ini.v1 v1.63.2 // indirect
github.com/tendermint/spm v0.1.9
github.com/tendermint/tendermint v0.34.15
github.com/tendermint/tm-db v0.6.6
google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4
google.golang.org/grpc v1.42.0
)

replace (
Expand Down
229 changes: 195 additions & 34 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/marketplace/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package OmniFlix.marketplace.v1beta1;

import "gogoproto/gogo.proto";
import "marketplace/v1beta1/listing.proto";
import "marketplace/v1beta1/params.proto";

option go_package = "github.com/OmniFlix/marketplace/x/marketplace/types";

message GenesisState {
// NFTs that are listed in marketplace
repeated Listing listings = 1 [(gogoproto.nullable) = false];
uint64 ListingCount = 2;
Params params = 3 [(gogoproto.nullable) = false];
}
15 changes: 15 additions & 0 deletions proto/marketplace/v1beta1/listing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@ message Listing {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
string owner = 5 [(gogoproto.moretags) = "yaml:\"owner\""];
repeated WeightedAddress split_shares = 6 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"split_shares\""
];
}

message WeightedAddress {
option (gogoproto.equal) = true;

string address = 1 [(gogoproto.moretags) = "yaml:\"address\""];
string weight = 2 [
(gogoproto.moretags) = "yaml:\"weight\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
31 changes: 31 additions & 0 deletions proto/marketplace/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
syntax = "proto3";
package OmniFlix.marketplace.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/OmniFlix/marketplace/x/marketplace/types";
option (gogoproto.goproto_getters_all) = false;



message Params {
string sale_commission = 1 [
(gogoproto.moretags) = "yaml:\"sale_commission\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
Distribution distribution = 2 [(gogoproto.nullable) = false];
}

message Distribution {
string staking = 1 [
(gogoproto.moretags) = "yaml:\"staking\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string community_pool = 2 [
(gogoproto.moretags) = "yaml:\"community_pool\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
16 changes: 16 additions & 0 deletions proto/marketplace/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ package OmniFlix.marketplace.v1beta1;
import "cosmos/base/query/v1beta1/pagination.proto";
import "google/api/annotations.proto";
import "marketplace/v1beta1/listing.proto";
import "marketplace/v1beta1/params.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/OmniFlix/marketplace/x/marketplace/types";

service Query {
// Params queries params of the marketplace module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/omniflix/marketplace/v1beta1/params";
}

rpc Listings(QueryListingsRequest) returns (QueryListingsResponse) {
option (google.api.http).get = "/omniflix/marketplace/v1beta1/listings";
}
Expand All @@ -30,6 +36,16 @@ service Query {
}
}


// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}

message QueryListingsRequest {
string owner = 1;
string price_denom = 2 [(gogoproto.moretags) = "yaml:\"price_denom\""];
Expand Down
15 changes: 10 additions & 5 deletions proto/marketplace/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package OmniFlix.marketplace.v1beta1;

import "cosmos/base/v1beta1/coin.proto";
import "marketplace/v1beta1/listing.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/OmniFlix/marketplace/x/marketplace/types";
Expand All @@ -20,14 +21,18 @@ service Msg {
}

message MsgListNFT {
string id = 1;
string nft_id = 2;
string denom_id = 3;
cosmos.base.v1beta1.Coin price = 4 [
string id = 1;
string nft_id = 2;
string denom_id = 3;
cosmos.base.v1beta1.Coin price = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
string owner = 5;
string owner = 5;
repeated WeightedAddress split_shares = 6 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"split_shares\""
];
}
message MsgListNFTResponse {}

Expand Down
12 changes: 7 additions & 5 deletions x/marketplace/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
)

const (
FlagDenomId = "denom-id"
FlagNftId = "nft-id"
FlagPrice = "price"
FlagOwner = "owner"
FlagPriceDenom = "price-denom"
FlagDenomId = "denom-id"
FlagNftId = "nft-id"
FlagPrice = "price"
FlagOwner = "owner"
FlagPriceDenom = "price-denom"
FlagSplitShares = "split-shares"
)

var (
Expand All @@ -22,6 +23,7 @@ func init() {
FsListNft.String(FlagDenomId, "", "nft denom id")
FsListNft.String(FlagNftId, "", "nft id")
FsListNft.String(FlagPrice, "", "listing price of nft")
FsListNft.String(FlagSplitShares, "", "split shares for listing")

FsEditListing.String(FlagPrice, "", "listing price of nft")

Expand Down
27 changes: 27 additions & 0 deletions x/marketplace/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetQueryCmd() *cobra.Command {
RunE: client.ValidateCmd,
}
cmd.AddCommand(
GetCmdQueryParams(),
GetCmdQueryListing(),
GetCmdQueryAllListings(),
GetCmdQueryListingsByOwner(),
Expand All @@ -32,6 +33,32 @@ func GetQueryCmd() *cobra.Command {
return cmd
}

// GetCmdQueryParams implements the query params command.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Args: cobra.NoArgs,
Short: "Query Marketplace params",
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdQueryListing implements the query listing command.
func GetCmdQueryListing() *cobra.Command {
cmd := &cobra.Command{
Expand Down
35 changes: 34 additions & 1 deletion x/marketplace/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,19 @@ func GetCmdListNft() *cobra.Command {
if err != nil {
return fmt.Errorf("failed to parse price: %s", price)
}
splitSharesStr, err := cmd.Flags().GetString(FlagSplitShares)
if err != nil {
return err
}
var splitShares []types.WeightedAddress
if len(splitSharesStr) > 0 {
splitShares, err = parseSplitShares(splitSharesStr)
if err != nil {
return err
}
}

msg := types.NewMsgListNFT(denomId, nftId, price, owner)
msg := types.NewMsgListNFT(denomId, nftId, price, owner, splitShares)

if err := msg.ValidateBasic(); err != nil {
return err
Expand Down Expand Up @@ -222,3 +233,25 @@ func GetCmdBuyNft() *cobra.Command {

return cmd
}

func parseSplitShares(splitsharesStr string) ([]types.WeightedAddress, error) {
splitsharesStr = strings.TrimSpace(splitsharesStr)
splitsStrList := strings.Split(splitsharesStr, ",")
var weightedAddrsList []types.WeightedAddress
for _, splitStr := range splitsStrList {
var share types.WeightedAddress
split := strings.Split(strings.TrimSpace(splitStr), ":")
address, err := sdk.AccAddressFromBech32(strings.TrimSpace(split[0]))
if err != nil {
return nil, err
}
weight, err := sdk.NewDecFromStr(strings.TrimSpace(split[1]))
if err != nil {
return nil, err
}
share.Address = address.String()
share.Weight = weight
weightedAddrsList = append(weightedAddrsList, share)
}
return weightedAddrsList, nil
}
25 changes: 25 additions & 0 deletions x/marketplace/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (

func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {

r.HandleFunc(fmt.Sprintf("/%s/parameters", types.ModuleName),
queryParams(cliCtx),
).Methods("GET")

r.HandleFunc(fmt.Sprintf("/%s/listing/{%s}",
types.ModuleName, RestParamListingId),
queryListing(cliCtx),
Expand All @@ -32,6 +36,27 @@ func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {
).Methods("GET")
}

// queryParams
func queryParams(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

res, height, err := cliCtx.QueryWithData(
fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams), nil,
)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}

// queryListing
func queryListing(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
Expand Down
Loading

0 comments on commit f54ef33

Please sign in to comment.