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

feat: tokenfactory module #104

Merged
merged 3 commits into from
Oct 16, 2023
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
5 changes: 5 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
"github.com/stretchr/testify/suite"
)

var (
SecondaryDenom = "uxflx"
SecondaryAmount = sdk.NewInt(100000000)
)

type KeeperTestHelper struct {
suite.Suite

Expand Down
26 changes: 25 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package keepers

import (
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"

icq "github.com/cosmos/ibc-apps/modules/async-icq/v7"
icqkeeper "github.com/cosmos/ibc-apps/modules/async-icq/v7/keeper"
icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types"

ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"

authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -46,6 +47,7 @@ import (

"github.com/OmniFlix/omniflixhub/v2/x/globalfee"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"

"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
Expand All @@ -63,6 +65,9 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

tokenfactorykeeper "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/keeper"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"

"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand Down Expand Up @@ -99,6 +104,12 @@ import (
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
)

var tokenFactoryCapabilities = []string{
tokenfactorytypes.EnableBurnFrom,
tokenfactorytypes.EnableForceTransfer,
tokenfactorytypes.EnableSetMetadata,
}

type AppKeepers struct {
// keys to access the substores
keys map[string]*storetypes.KVStoreKey
Expand Down Expand Up @@ -128,6 +139,7 @@ type AppKeepers struct {
ConsensusParamsKeeper consensusparamkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper
GroupKeeper groupkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -401,6 +413,17 @@ func NewAppKeeper(
govModAddress,
)

// Create the TokenFactory Keeper
appKeepers.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
appCodec,
appKeepers.keys[tokenfactorytypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.DistrKeeper,
tokenFactoryCapabilities,
govModAddress,
)

appKeepers.AllocKeeper = *allockeeper.NewKeeper(
appCodec,
appKeepers.keys[alloctypes.StoreKey],
Expand Down Expand Up @@ -497,6 +520,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icqtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(tokenfactorytypes.ModuleName)
paramsKeeper.Subspace(alloctypes.ModuleName)
paramsKeeper.Subspace(onfttypes.ModuleName)
paramsKeeper.Subspace(marketplacetypes.ModuleName)
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types"
marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
onfttypes "github.com/OmniFlix/onft/types"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -55,6 +56,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
feegrant.StoreKey,
globalfeetypes.StoreKey,
group.StoreKey,
tokenfactorytypes.StoreKey,
authzkeeper.StoreKey,
alloctypes.StoreKey,
onfttypes.StoreKey,
Expand Down
16 changes: 14 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/x/globalfee"

"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 @@ -41,8 +42,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

// "github.com/cosmos/cosmos-sdk/x/group"
// groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"

"github.com/cosmos/cosmos-sdk/x/mint"
Expand All @@ -57,6 +56,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/OmniFlix/omniflixhub/v2/x/tokenfactory"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"

"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

Expand Down Expand Up @@ -119,6 +121,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
globalfee.AppModuleBasic{},
tokenfactory.AppModuleBasic{},

alloc.AppModuleBasic{},
onft.AppModuleBasic{},
Expand All @@ -138,6 +141,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
globalfee.ModuleName: nil,
alloctypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
onfttypes.ModuleName: nil,
Expand Down Expand Up @@ -178,6 +182,11 @@ func appModules(
app.BankKeeper,
app.interfaceRegistry,
),
tokenfactory.NewAppModule(
app.AppKeepers.TokenFactoryKeeper,
app.AppKeepers.AccountKeeper,
app.AppKeepers.BankKeeper,
),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
slashing.NewAppModule(
appCodec,
Expand Down Expand Up @@ -297,6 +306,7 @@ func orderBeginBlockers() []string {
crisistypes.ModuleName,
feegrant.ModuleName,
globalfee.ModuleName,
tokenfactorytypes.ModuleName,
group.ModuleName,
onfttypes.ModuleName,
marketplacetypes.ModuleName,
Expand Down Expand Up @@ -330,6 +340,7 @@ func orderEndBlockers() []string {
feegrant.ModuleName,
globalfee.ModuleName,
group.ModuleName,
tokenfactorytypes.ModuleName,
authz.ModuleName,
alloctypes.ModuleName,
onfttypes.ModuleName,
Expand Down Expand Up @@ -369,6 +380,7 @@ func orderInitGenesis() []string {
feegrant.ModuleName,
globalfee.ModuleName,
group.ModuleName,
tokenfactorytypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
Expand Down
11 changes: 11 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package params

// Simulation parameter constants
const (
DefaultWeightMsgCreateDenom int = 100
DefaultWeightMsgMint int = 100
DefaultWeightMsgBurn int = 100
DefaultWeightMsgChangeAdmin int = 100
DefaultWeightMsgSetDenomMetadata int = 100
DefaultWeightMsgForceTransfer int = 100
)
7 changes: 7 additions & 0 deletions app/upgrades/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types"
marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types"
tokenfactorytypes "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types"
onfttypes "github.com/OmniFlix/onft/types"
streampaytypes "github.com/OmniFlix/streampay/v2/x/streampay/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -118,6 +119,12 @@ func CreateV2UpgradeHandler(
return nil, err
}

// set token-factory denom creation fee
err = keepers.TokenFactoryKeeper.SetParams(ctx, tokenfactorytypes.DefaultParams())
if err != nil {
return nil, err
}

ctx.Logger().Info("Upgrade complete")
return versionMap, nil
}
Expand Down
17 changes: 17 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/authorityMetadata.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";
package osmosis.tokenfactory.v1beta1;

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

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types";

// DenomAuthorityMetadata specifies metadata for addresses that have specific
// capabilities over a token factory denom. Right now there is only one Admin
// permission, but is planned to be extended to the future.
message DenomAuthorityMetadata {
option (gogoproto.equal) = true;

// Can be empty for no admin, or a valid osmosis address
string admin = 1 [ (gogoproto.moretags) = "yaml:\"admin\"" ];
}
32 changes: 32 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
syntax = "proto3";
package osmosis.tokenfactory.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/tokenfactory/v1beta1/authorityMetadata.proto";
import "osmosis/tokenfactory/v1beta1/params.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types";

// GenesisState defines the tokenfactory module's genesis state.
message GenesisState {
// params defines the paramaters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];

repeated GenesisDenom factory_denoms = 2 [
(gogoproto.moretags) = "yaml:\"factory_denoms\"",
(gogoproto.nullable) = false
];
}

// GenesisDenom defines a tokenfactory denom that is defined within genesis
// state. The structure contains DenomAuthorityMetadata which defines the
// denom's admin.
message GenesisDenom {
option (gogoproto.equal) = true;

string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
DenomAuthorityMetadata authority_metadata = 2 [
(gogoproto.moretags) = "yaml:\"authority_metadata\"",
(gogoproto.nullable) = false
];
}
26 changes: 26 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";
package osmosis.tokenfactory.v1beta1;

import "gogoproto/gogo.proto";
import "osmosis/tokenfactory/v1beta1/authorityMetadata.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types";

// Params defines the parameters for the tokenfactory module.
message Params {
repeated cosmos.base.v1beta1.Coin denom_creation_fee = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"denom_creation_fee\"",
(gogoproto.nullable) = false
];

// if denom_creation_fee is an empty array, then this field is used to add more gas consumption
// to the base cost.
// https://github.com/CosmWasm/token-factory/issues/11
uint64 denom_creation_gas_consume = 2 [
(gogoproto.moretags) = "yaml:\"denom_creation_gas_consume\"",
(gogoproto.nullable) = true
];
}
71 changes: 71 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
syntax = "proto3";
package osmosis.tokenfactory.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "osmosis/tokenfactory/v1beta1/authorityMetadata.proto";
import "osmosis/tokenfactory/v1beta1/params.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/tokenfactory/types";

// Query defines the gRPC querier service.
service Query {
// Params defines a gRPC query method that returns the tokenfactory module's
// parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/osmosis/tokenfactory/v1beta1/params";
}

// DenomAuthorityMetadata defines a gRPC query method for fetching
// DenomAuthorityMetadata for a particular denom.
rpc DenomAuthorityMetadata(QueryDenomAuthorityMetadataRequest)
returns (QueryDenomAuthorityMetadataResponse) {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/denoms/{denom}/authority_metadata";
}

// DenomsFromCreator defines a gRPC query method for fetching all
// denominations created by a specific admin/creator.
rpc DenomsFromCreator(QueryDenomsFromCreatorRequest)
returns (QueryDenomsFromCreatorResponse) {
option (google.api.http).get =
"/osmosis/tokenfactory/v1beta1/denoms_from_creator/{creator}";
}
}

// 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 ];
}

// QueryDenomAuthorityMetadataRequest defines the request structure for the
// DenomAuthorityMetadata gRPC query.
message QueryDenomAuthorityMetadataRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
}

// QueryDenomAuthorityMetadataResponse defines the response structure for the
// DenomAuthorityMetadata gRPC query.
message QueryDenomAuthorityMetadataResponse {
DenomAuthorityMetadata authority_metadata = 1 [
(gogoproto.moretags) = "yaml:\"authority_metadata\"",
(gogoproto.nullable) = false
];
}

// QueryDenomsFromCreatorRequest defines the request structure for the
// DenomsFromCreator gRPC query.
message QueryDenomsFromCreatorRequest {
string creator = 1 [ (gogoproto.moretags) = "yaml:\"creator\"" ];
}

// QueryDenomsFromCreatorRequest defines the response structure for the
// DenomsFromCreator gRPC query.
message QueryDenomsFromCreatorResponse {
repeated string denoms = 1 [ (gogoproto.moretags) = "yaml:\"denoms\"" ];
}
Loading
Loading