Skip to content

Commit

Permalink
Merge pull request #109 from Reecepbcups/reece/tf-addition
Browse files Browse the repository at this point in the history
[v6] x/tokenfactory from Juno
  • Loading branch information
woof-chihuahua authored Dec 12, 2023
2 parents 8084b6d + 95d452e commit c49c608
Show file tree
Hide file tree
Showing 63 changed files with 11,286 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
ifeq (,$(findstring nostrip,$(chihuahua_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

#$(info $$BUILD_FLAGS is [$(BUILD_FLAGS)])


Expand All @@ -107,7 +107,7 @@ build-reproducible-amd64:

build-reproducible-arm64:
ARCH=aarch64 PLATFORM=linux/arm64 $(MAKE) build-reproducible-generic

build-reproducible-generic: go.sum
$(DOCKER) rm $(subst /,-,latest-build-$(PLATFORM)) || true
DOCKER_BUILDKIT=1 $(DOCKER) build -t latest-build-$(PLATFORM) \
Expand Down Expand Up @@ -138,7 +138,7 @@ containerProtoImage=ghcr.io/cosmos/proto-builder:$(containerProtoVer)
proto-gen:
@echo "Generating Protobuf files"
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh;
sh ./scripts/protocgen.sh;

docs:
@echo
Expand Down
52 changes: 47 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,17 @@ import (
ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7"
ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/keeper"
ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v7/types"

tokenfactory "github.com/ChihuahuaChain/chihuahua/x/tokenfactory"
tokenbindings "github.com/ChihuahuaChain/chihuahua/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/ChihuahuaChain/chihuahua/x/tokenfactory/keeper"
tokenfactorytypes "github.com/ChihuahuaChain/chihuahua/x/tokenfactory/types"
)

const (
Bech32Prefix = "chihuahua"
Name = "chihuahua"
UpgradeName = "v503"
UpgradeName = "v6"
NodeDir = ".chihuahuad"
)

Expand Down Expand Up @@ -180,6 +185,12 @@ var (
Bech32PrefixConsAddr = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
Bech32PrefixConsPub = Bech32Prefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic

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

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
Expand Down Expand Up @@ -265,6 +276,7 @@ var (
feeburnmodule.AppModuleBasic{},
alliancemodule.AppModuleBasic{},
ibchooks.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
)

// module account permissions
Expand All @@ -282,6 +294,7 @@ var (
wasmtypes.ModuleName: {authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)

Expand Down Expand Up @@ -335,9 +348,10 @@ type App struct {
TransferKeeper ibctransferkeeper.Keeper
wasmKeeper wasmkeeper.Keeper

FeeburnKeeper feeburnmodulekeeper.Keeper
AllianceKeeper alliancemodulekeeper.Keeper
IBCHooksKeeper ibchookskeeper.Keeper
FeeburnKeeper feeburnmodulekeeper.Keeper
AllianceKeeper alliancemodulekeeper.Keeper
IBCHooksKeeper ibchookskeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -392,6 +406,7 @@ func New(
feeburnmoduletypes.StoreKey,
alliancemoduletypes.StoreKey,
ibchookstypes.StoreKey,
tokenfactorytypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -578,6 +593,19 @@ func New(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
appCodec,
app.keys[tokenfactorytypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.DistrKeeper,
tokenFactoryCapabilities,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

tfOpts := tokenbindings.RegisterCustomPlugins(&app.BankKeeper, &app.TokenFactoryKeeper)
wasmOpts = append(wasmOpts, tfOpts...)

wasmDir := filepath.Join(homePath, "data")

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
Expand Down Expand Up @@ -699,6 +727,7 @@ func New(
transfer.NewAppModule(app.TransferKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancemoduletypes.ModuleName)),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(tokenfactorytypes.ModuleName)),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -721,6 +750,7 @@ func New(
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
alliancemoduletypes.ModuleName,
tokenfactorytypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -739,6 +769,7 @@ func New(
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
alliancemoduletypes.ModuleName,
tokenfactorytypes.ModuleName,
)
// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand All @@ -764,6 +795,7 @@ func New(
// wasm after ibc transfer
wasmtypes.ModuleName,
alliancemoduletypes.ModuleName,
tokenfactorytypes.ModuleName,
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
app.mm.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -833,6 +865,7 @@ func New(
Added: []string{
//alliancemoduletypes.StoreKey,
//ibchookstypes.StoreKey,
tokenfactorytypes.ModuleName,
},
}

Expand Down Expand Up @@ -1068,7 +1101,16 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// RegisterUpgradeHandlers returns upgrade handlers
func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(UpgradeName, func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, cfg, vm)
vm, err := app.mm.RunMigrations(ctx, cfg, vm)

if err := app.TokenFactoryKeeper.SetParams(ctx, tokenfactorytypes.Params{
DenomCreationFee: nil,
DenomCreationGasConsume: 50_000, // 50k gas consume for creating a token. Ref: Juno is 2m and Osmosis 2m.
}); err != nil {
return nil, err
}

return vm, err
})
}

Expand Down
8 changes: 8 additions & 0 deletions app/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/tx"
)

const (
BondDenom = "uhuahua"
DisplayDenom = "HUAHUA"
// DefaultGasLimit - set to the same value as cosmos-sdk flags.DefaultGasLimit
// this value is currently only used in tests.
DefaultGasLimit = 200000
)

// MakeEncodingConfig creates an EncodingConfig for an amino based test configuration.
func MakeEncodingConfig() EncodingConfig {
amino := codec.NewLegacyAmino()
Expand Down
14 changes: 14 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package params

// Simulation parameter constants
const (
StakePerAccount = "stake_per_account"
InitiallyBondedValidators = "initially_bonded_validators"

DefaultWeightMsgCreateDenom int = 100
DefaultWeightMsgMint int = 100
DefaultWeightMsgBurn int = 100
DefaultWeightMsgChangeAdmin int = 100
DefaultWeightMsgSetDenomMetadata int = 100
DefaultWeightMsgForceTransfer int = 100
)
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/ChihuahuaChain/chihuahua/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/ChihuahuaChain/chihuahua/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/ChihuahuaChain/chihuahua/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/ChihuahuaChain/chihuahua/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

0 comments on commit c49c608

Please sign in to comment.