Skip to content

Commit

Permalink
feat: Ics721 nft transfer module (#109)
Browse files Browse the repository at this point in the history
* add nft-transfer module

* add ics721nft middleware nft-transfer module

* bump up ibc-apps

* bump up packages

* add ibc tendermint client in app module basics

* update streampay version

* clean code

* update ics721 nft builder

* update denom metadata builder for for ics721 nfts

* fix lint
  • Loading branch information
harish551 authored Nov 20, 2023
1 parent 34dae59 commit 9d2dacc
Show file tree
Hide file tree
Showing 20 changed files with 444 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:

before:
hooks:
- go mod tidy -compat=1.20
- go mod tidy -compat=1.21

builds:
- main: ./cmd/omniflixhubd
Expand Down
47 changes: 36 additions & 11 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keepers

import (
"github.com/OmniFlix/omniflixhub/v2/x/ics721nft"
nfttransfer "github.com/bianjieai/nft-transfer"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -84,9 +86,9 @@ import (
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"

packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"

allockeeper "github.com/OmniFlix/omniflixhub/v2/x/alloc/keeper"
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
Expand All @@ -102,6 +104,9 @@ import (

streampaykeeper "github.com/OmniFlix/streampay/v2/x/streampay/keeper"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"

ibcnfttransferkeeper "github.com/bianjieai/nft-transfer/keeper"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
)

var tokenFactoryCapabilities = []string{
Expand Down Expand Up @@ -140,12 +145,14 @@ type AppKeepers struct {
GlobalFeeKeeper globalfeekeeper.Keeper
GroupKeeper groupkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
IBCNFTTransferKeeper ibcnfttransferkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
ScopedNFTTransferKeeper capabilitykeeper.ScopedKeeper

AllocKeeper allockeeper.Keeper
ONFTKeeper onftkeeper.Keeper
Expand Down Expand Up @@ -205,6 +212,7 @@ func NewAppKeeper(
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedICQKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icqtypes.ModuleName)
appKeepers.ScopedNFTTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibcnfttransfertypes.ModuleName)

appKeepers.CapabilityKeeper.Seal()

Expand Down Expand Up @@ -356,13 +364,14 @@ func NewAppKeeper(

// initialize ibc packet forwarding middleware router
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec, appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.GetSubspace(packetforwardtypes.ModuleName),
appCodec,
appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.TransferKeeper, // Will be zero-value here. Reference is set later on with SetTransferKeeper.
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
govModAddress,
)

// Create Transfer Keepers
Expand Down Expand Up @@ -397,12 +406,12 @@ func NewAppKeeper(
appKeepers.ICQKeeper = icqkeeper.NewKeeper(
appCodec,
appKeepers.keys[icqtypes.StoreKey],
appKeepers.GetSubspace(icqtypes.ModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICQKeeper,
bApp.GRPCQueryRouter(),
govModAddress,
)
icqModule := icq.NewIBCModule(appKeepers.ICQKeeper)

Expand Down Expand Up @@ -443,6 +452,21 @@ func NewAppKeeper(
appKeepers.DistrKeeper,
govModAddress,
)

appKeepers.IBCNFTTransferKeeper = ibcnfttransferkeeper.NewKeeper(
appCodec,
keys[ibcnfttransfertypes.StoreKey],
govModAddress,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
ics721nft.NewKeeper(appCodec, appKeepers.ONFTKeeper, appKeepers.AccountKeeper),
appKeepers.ScopedNFTTransferKeeper,
)

nfttransferIBCModule := nfttransfer.NewIBCModule(appKeepers.IBCNFTTransferKeeper)

appKeepers.MarketplaceKeeper = marketplacekeeper.NewKeeper(
appCodec,
appKeepers.keys[marketplacetypes.StoreKey],
Expand Down Expand Up @@ -490,7 +514,8 @@ func NewAppKeeper(
ibcRouter.
AddRoute(ibctransfertypes.ModuleName, ibcStack).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(icqtypes.ModuleName, icqModule)
AddRoute(icqtypes.ModuleName, icqModule).
AddRoute(ibcnfttransfertypes.ModuleName, nfttransferIBCModule)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down
4 changes: 3 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
onfttypes "github.com/OmniFlix/omniflixhub/v2/x/onft/types"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -26,7 +27,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand All @@ -51,6 +52,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
icahosttypes.StoreKey,
icqtypes.StoreKey,
packetforwardtypes.StoreKey,
ibcnfttransfertypes.StoreKey,
capabilitytypes.StoreKey,
crisistypes.StoreKey,
feegrant.StoreKey,
Expand Down
18 changes: 14 additions & 4 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package app
import (
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/x/globalfee"
nfttransfer "github.com/bianjieai/nft-transfer"
ibcnfttransfertypes "github.com/bianjieai/nft-transfer/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
Expand Down Expand Up @@ -65,6 +67,7 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
Expand All @@ -73,8 +76,8 @@ import (
icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"

packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"

"github.com/OmniFlix/omniflixhub/v2/x/alloc"
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
Expand Down Expand Up @@ -111,6 +114,7 @@ var (
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ica.AppModuleBasic{},
icq.AppModuleBasic{},
packetforward.AppModuleBasic{},
Expand All @@ -122,6 +126,7 @@ var (
vesting.AppModuleBasic{},
globalfee.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
nfttransfer.AppModuleBasic{},

alloc.AppModuleBasic{},
onft.AppModuleBasic{},
Expand All @@ -140,6 +145,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcnfttransfertypes.ModuleName: nil,
icatypes.ModuleName: nil,
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
globalfee.ModuleName: nil,
Expand Down Expand Up @@ -221,8 +227,9 @@ func appModules(
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
transfer.NewAppModule(app.TransferKeeper),
ica.NewAppModule(nil, &app.ICAHostKeeper),
icq.NewAppModule(app.ICQKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper),
icq.NewAppModule(app.ICQKeeper, app.GetSubspace(icqtypes.ModuleName)),
nfttransfer.NewAppModule(app.IBCNFTTransferKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
globalfee.NewAppModule(appCodec, app.GlobalFeeKeeper, bondDenom),
alloc.NewAppModule(appCodec, app.AllocKeeper, app.GetSubspace(alloctypes.ModuleName)),
onft.NewAppModule(
Expand Down Expand Up @@ -301,6 +308,7 @@ func orderBeginBlockers() []string {
icatypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
ibcnfttransfertypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
authtypes.ModuleName,
Expand Down Expand Up @@ -334,6 +342,7 @@ func orderEndBlockers() []string {
icatypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
ibcnfttransfertypes.ModuleName,
minttypes.ModuleName,
slashingtypes.ModuleName,
distrtypes.ModuleName,
Expand Down Expand Up @@ -387,6 +396,7 @@ func orderInitGenesis() []string {
icatypes.ModuleName,
icqtypes.ModuleName,
packetforwardtypes.ModuleName,
ibcnfttransfertypes.ModuleName,
alloctypes.ModuleName,
onfttypes.ModuleName,
marketplacetypes.ModuleName,
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v012/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v012
import (
"github.com/OmniFlix/omniflixhub/v2/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
)

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v012/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router/types"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
)

Expand Down
17 changes: 9 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
module github.com/OmniFlix/omniflixhub/v2

go 1.20
go 1.21

require (
github.com/OmniFlix/streampay/v2 v2.1.1-0.20230922163133-93e80c4663ef
github.com/OmniFlix/streampay/v2 v2.2.0-alpha.1
github.com/bianjieai/nft-transfer v1.1.3-ibc-v7.3.0
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.0.0
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.0.0
github.com/cosmos/ibc-go/v7 v7.2.0
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.1
github.com/cosmos/ibc-apps/modules/async-icq/v7 v7.1.1
github.com/cosmos/ibc-go/v7 v7.3.1
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/google/uuid v1.4.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
Expand Down
Loading

0 comments on commit 9d2dacc

Please sign in to comment.