Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnya97 committed Nov 21, 2021
1 parent 0bdeda2 commit b25991f
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 141 deletions.
10 changes: 9 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ import (
poolincentivesclient "github.com/osmosis-labs/osmosis/x/pool-incentives/client"
poolincentiveskeeper "github.com/osmosis-labs/osmosis/x/pool-incentives/keeper"
poolincentivestypes "github.com/osmosis-labs/osmosis/x/pool-incentives/types"
"github.com/osmosis-labs/osmosis/x/tokenfactory"
tokenfactorykeeper "github.com/osmosis-labs/osmosis/x/tokenfactory/keeper"
tokenfactorytypes "github.com/osmosis-labs/osmosis/x/tokenfactory/types"
"github.com/osmosis-labs/osmosis/x/txfees"
txfeeskeeper "github.com/osmosis-labs/osmosis/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/x/txfees/types"
Expand Down Expand Up @@ -151,6 +154,7 @@ var (
poolincentives.AppModuleBasic{},
epochs.AppModuleBasic{},
claim.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
)

// module account permissions
Expand All @@ -169,6 +173,7 @@ var (
lockuptypes.ModuleName: {authtypes.Minter, authtypes.Burner},
poolincentivestypes.ModuleName: nil,
txfeestypes.ModuleName: nil,
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -217,6 +222,7 @@ type OsmosisApp struct {
EpochsKeeper epochskeeper.Keeper
PoolIncentivesKeeper poolincentiveskeeper.Keeper
TxFeesKeeper txfeeskeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -259,7 +265,7 @@ func NewOsmosisApp(
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
gammtypes.StoreKey, lockuptypes.StoreKey, claimtypes.StoreKey, incentivestypes.StoreKey,
epochstypes.StoreKey, poolincentivestypes.StoreKey, txfeestypes.StoreKey,
epochstypes.StoreKey, poolincentivestypes.StoreKey, txfeestypes.StoreKey, tokenfactorytypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -411,6 +417,8 @@ func NewOsmosisApp(
)
poolIncentivesHooks := app.PoolIncentivesKeeper.Hooks()

app.TokenFactoryKeeper = *tokenfactorykeeper.NewKeeper(appCodec, keys[tokenfactorytypes.StoreKey], app.BankKeeper)

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
Expand Down
4 changes: 4 additions & 0 deletions proto/osmosis/tokenfactory/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ option go_package = "github.com/osmosis-labs/osmosis/x/tokenfactory/types";

// GenesisState defines the tokenfactory module's genesis state.
message GenesisState {
option (gogoproto.equal) = true;

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

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

string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
DenomAuthorityMetadata authority_metadata = 2 [
(gogoproto.moretags) = "yaml:\"authority_metadata\"",
Expand Down
5 changes: 4 additions & 1 deletion proto/osmosis/tokenfactory/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ message MsgCreateDenom {
string nonce = 2 [ (gogoproto.moretags) = "yaml:\"nonce\"" ];
}

message MsgCreateDenomResponse {}
message MsgCreateDenomResponse {
string new_token_denom = 1
[ (gogoproto.moretags) = "yaml:\"new_token_denom\"" ];
}

// ===================== MsgMint
message MsgMint {
Expand Down
39 changes: 0 additions & 39 deletions testutil/keeper/tokenfactory.go

This file was deleted.

66 changes: 65 additions & 1 deletion x/tokenfactory/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package cli

import (
"fmt"

// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -24,7 +27,68 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
RunE: client.ValidateCmd,
}

// this line is used by starport scaffolding # 1
cmd.AddCommand(
GetCmdDenomAuthorityMetadata(),
GetCmdDenomsFromCreator(),
)

return cmd
}

// GetCmdDenomAuthorityMetadata returns the authority metadata for a queried denom
func GetCmdDenomAuthorityMetadata() *cobra.Command {
cmd := &cobra.Command{
Use: "denom-authority-metadata [denom] [flags]",
Short: "Get the authority metadata for a specific denom",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.DenomAuthorityMetadata(cmd.Context(), &types.QueryDenomAuthorityMetadataRequest{
Denom: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdDenomAuthorityMetadata returns the authority metadata for a queried denom
func GetCmdDenomsFromCreator() *cobra.Command {
cmd := &cobra.Command{
Use: "denoms-from-creator [creator address] [flags]",
Short: "Returns a list of all tokens created by a specific creator address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.DenomsFromCreator(cmd.Context(), &types.QueryDenomsFromCreatorRequest{
Creator: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
36 changes: 26 additions & 10 deletions x/tokenfactory/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ package tokenfactory_test
import (
"testing"

keepertest "github.com/osmosis-labs/osmosis/testutil/keeper"
"github.com/osmosis-labs/osmosis/x/tokenfactory"
simapp "github.com/osmosis-labs/osmosis/app"
appparams "github.com/osmosis-labs/osmosis/app/params"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/osmosis-labs/osmosis/x/tokenfactory/types"
"github.com/stretchr/testify/require"
)

func TestGenesis(t *testing.T) {
appparams.SetAddressPrefixes()

genesisState := types.GenesisState{
// this line is used by starport scaffolding # genesis/test/state
FactoryDenoms: []types.GenesisDenom{
{
Denom: "factory/osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44/bitcoin",
AuthorityMetadata: types.DenomAuthorityMetadata{
Admin: "osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44",
},
},
{
Denom: "factory/osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44/litecoin",
AuthorityMetadata: types.DenomAuthorityMetadata{
Admin: "osmo1t7egva48prqmzl59x5ngv4zx0dtrwewc9m7z44",
},
},
},
}
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

k, ctx := keepertest.TokenfactoryKeeper(t)
tokenfactory.InitGenesis(ctx, *k, genesisState)
got := tokenfactory.ExportGenesis(ctx, *k)
require.NotNil(t, got)

// this line is used by starport scaffolding # genesis/test/assert
// tokenfactory.InitGenesis(ctx, *k, genesisState)
// got := tokenfactory.ExportGenesis(ctx, *k)
// require.NotNil(t, got)
// require.Equal(t, genesisState, got)
}
10 changes: 5 additions & 5 deletions x/tokenfactory/keeper/createdenom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

// ConvertToBaseToken converts a fee amount in a whitelisted fee token to the base fee token amount
func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, denomnonce string) error {
func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, denomnonce string) (newTokenDenom string, err error) {
denom, err := types.GetTokenDenom(creatorAddr, denomnonce)
if err != nil {
return err
return "", err
}

_, found := k.bankKeeper.GetDenomMetaData(ctx, denom)
if found {
return types.ErrDenomExists
return "", types.ErrDenomExists
}

baseDenomUnit := banktypes.DenomUnit{
Expand All @@ -35,9 +35,9 @@ func (k Keeper) CreateDenom(ctx sdk.Context, creatorAddr string, denomnonce stri
}
err = k.SetAuthorityMetadata(ctx, denom, authorityMetadata)
if err != nil {
return err
return "", err
}

k.addDenomFromCreator(ctx, creatorAddr, denom)
return nil
return denom, nil
}
6 changes: 1 addition & 5 deletions x/tokenfactory/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ type (
Keeper struct {
cdc codec.Marshaler
storeKey sdk.StoreKey
memKey sdk.StoreKey

bankKeeper types.BankKeeper
}
)

func NewKeeper(
cdc codec.Marshaler,
storeKey,
memKey sdk.StoreKey,

storeKey sdk.StoreKey,
bankKeeper types.BankKeeper,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,

bankKeeper: bankKeeper,
}
Expand Down
Loading

0 comments on commit b25991f

Please sign in to comment.