Skip to content

Commit

Permalink
wip: tokens factory
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Aug 23, 2023
1 parent 3aed359 commit 5d7df2e
Show file tree
Hide file tree
Showing 24 changed files with 443 additions and 14,748 deletions.
39 changes: 20 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,7 @@ build-release-arm64: go.sum $(BUILDDIR)/
install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./cmd/terrad

gen-swagger-docs:
bash scripts/protoc-swagger-gen.sh

update-swagger-docs: statik
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "Swagger docs are out of sync!";\
exit 1;\
else \
echo "Swagger docs are in sync!";\
fi

apply-swagger: gen-swagger-docs update-swagger-docs

.PHONY: build build-linux install update-swagger-docs apply-swagger
.PHONY: build build-linux install


###############################################################################
Expand Down Expand Up @@ -265,14 +251,29 @@ clean-testing-data:
###############################################################################
### Protobuf ###
###############################################################################

proto-all: proto-gen
protoVer=0.13.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

proto-gen:
@echo "Generating Protobuf files"
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /worwkspace tendermintdev/sdk-proto-gen:v0.3 sh ./scripts/protocgen.sh
@$(protoImage) sh ./scripts/protocgen.sh

gen-swagger-docs:
bash scripts/protoc-swagger-gen.sh

update-swagger-docs: statik
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "Swagger docs are out of sync!";\
exit 1;\
else \
echo "Swagger docs are in sync!";\
fi

apply-swagger: gen-swagger-docs update-swagger-docs

.PHONY: proto-all proto-gen
.PHONY: proto-all proto-gen gen-swagger-docs update-swagger-docs apply-swagger

########################################
### Tools & dependencies
Expand Down
50 changes: 25 additions & 25 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -133,6 +132,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/prometheus/client_golang/prometheus"

"github.com/terra-money/core/v2/x/tokenfactory"
Expand Down Expand Up @@ -175,24 +175,24 @@ var (

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
func GetEnabledProposals() []wasmtypes.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
return wasmtypes.EnableAllProposals
}
return wasm.DisableAllProposals
return wasmtypes.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
proposals, err := wasmtypes.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}

// GetWasmOpts build wasm options
func GetWasmOpts(app *TerraApp, appOpts servertypes.AppOptions) []wasm.Option {
var wasmOpts []wasm.Option
func GetWasmOpts(app *TerraApp, appOpts servertypes.AppOptions) []wasmkeeper.Option {
var wasmOpts []wasmkeeper.Option
if cast.ToBool(appOpts.Get("telemetry.enabled")) {
wasmOpts = append(wasmOpts, wasmkeeper.WithVMCacheMetrics(prometheus.DefaultRegisterer))
}
Expand Down Expand Up @@ -267,7 +267,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
wasm.ModuleName: {authtypes.Burner},
wasmtypes.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Burner, authtypes.Minter},
alliancetypes.ModuleName: {authtypes.Burner, authtypes.Minter},
alliancetypes.RewardsPoolName: nil,
Expand Down Expand Up @@ -341,7 +341,7 @@ type TerraApp struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

wasmKeeper wasm.Keeper
WasmKeeper wasmkeeper.Keeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper

// the module manager
Expand Down Expand Up @@ -381,7 +381,7 @@ func NewTerraApp(
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, routertypes.StoreKey, consensusparamtypes.StoreKey, tokenfactorytypes.StoreKey,
wasm.StoreKey, ibcfeetypes.StoreKey, ibchookstypes.StoreKey, alliancetypes.StoreKey,
wasmtypes.StoreKey, ibcfeetypes.StoreKey, ibchookstypes.StoreKey, alliancetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -412,7 +412,7 @@ func NewTerraApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -619,10 +619,10 @@ func NewTerraApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,token_factory"
app.wasmKeeper = wasm.NewKeeper(
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,token_factory"
app.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -641,25 +641,25 @@ func NewTerraApp(
GetWasmOpts(app, appOpts)...,
)

app.Ics20WasmHooks.ContractKeeper = &app.wasmKeeper
app.Ics20WasmHooks.ContractKeeper = &app.WasmKeeper

// register wasm gov proposal types
enabledProposals := GetEnabledProposals()
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.wasmKeeper, enabledProposals))
govRouter.AddRoute(wasmtypes.RouterKey, wasmkeeper.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(app.wasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, hooksTransferStack).
AddRoute(wasm.ModuleName, wasmStack)
AddRoute(wasmtypes.ModuleName, wasmStack)

app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -712,7 +712,7 @@ func NewTerraApp(
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
router.NewAppModule(&app.RouterKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibchooks.NewAppModule(app.AccountKeeper),
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -746,7 +746,7 @@ func NewTerraApp(
ibcfeetypes.ModuleName,
routertypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -776,7 +776,7 @@ func NewTerraApp(
ibcfeetypes.ModuleName,
routertypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
Expand Down Expand Up @@ -811,7 +811,7 @@ func NewTerraApp(
routertypes.ModuleName,
tokenfactorytypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
)
Expand All @@ -837,7 +837,7 @@ func NewTerraApp(
SigGasConsumer: cosmosante.DefaultSigVerificationGasConsumer,
},
IBCkeeper: app.IBCKeeper,
TxCounterStoreKey: keys[wasm.StoreKey],
TxCounterStoreKey: keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig.ToWasmConfig(),
},
)
Expand Down Expand Up @@ -1096,7 +1096,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(alliancetypes.ModuleName)

paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)

return paramsKeeper
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
router.NewAppModule(&app.RouterKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasm.ModuleName)),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

Expand Down
20 changes: 11 additions & 9 deletions app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -235,10 +236,11 @@ func TestNewGenesis(t *testing.T) {
"params": {
"denom_creation_fee": [
{
"denom": "stake",
"denom": "uluna",
"amount": "10000000"
}
]
],
"denom_creation_gas_consume": "1000000"
},
"factory_denoms": []
},
Expand All @@ -257,7 +259,6 @@ func TestNewGenesis(t *testing.T) {
"params": {
"code_upload_access": {
"permission": "Everybody",
"address": "",
"addresses": []
},
"instantiate_default_permission": "Everybody"
Expand All @@ -267,7 +268,6 @@ func TestNewGenesis(t *testing.T) {
"sequences": []
}
}`

require.JSONEq(t, string(jsonGenState), expectedState)
}

Expand Down Expand Up @@ -502,7 +502,8 @@ func TestNewGenesisWithBondDenom(t *testing.T) {
"denom": "uluna",
"amount": "10000000"
}
]
],
"denom_creation_gas_consume": "1000000"
},
"factory_denoms": []
},
Expand All @@ -521,7 +522,6 @@ func TestNewGenesisWithBondDenom(t *testing.T) {
"params": {
"code_upload_access": {
"permission": "Everybody",
"address": "",
"addresses": []
},
"instantiate_default_permission": "Everybody"
Expand Down Expand Up @@ -787,10 +787,11 @@ func TestNewGenesisConfigureICA(t *testing.T) {
"params": {
"denom_creation_fee": [
{
"denom": "stake",
"denom": "uluna",
"amount": "10000000"
}
]
],
"denom_creation_gas_consume": "1000000"
},
"factory_denoms": []
},
Expand All @@ -809,7 +810,6 @@ func TestNewGenesisConfigureICA(t *testing.T) {
"params": {
"code_upload_access": {
"permission": "Everybody",
"address": "",
"addresses": []
},
"instantiate_default_permission": "Everybody"
Expand All @@ -819,5 +819,7 @@ func TestNewGenesisConfigureICA(t *testing.T) {
"sequences": []
}
}`
fmt.Print(string(jsonGenState))

require.JSONEq(t, string(jsonGenState), expectedState)
}
20 changes: 10 additions & 10 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
simcli.GetSimulatorFlags()
}

type AppTest interface {
type terraApp interface {
app.TerraApp
GetBaseApp() *baseapp.BaseApp
AppCodec() codec.Codec
Expand Down Expand Up @@ -60,7 +60,7 @@ func BenchmarkSimulation(b *testing.B) {

encoding := app.MakeEncodingConfig()

appTest := app.NewTerraApp(
terraApp := app.NewTerraApp(
logger,
db,
nil,
Expand All @@ -77,17 +77,17 @@ func BenchmarkSimulation(b *testing.B) {
_, simParams, simErr := simulation.SimulateFromSeed(
b,
os.Stdout,
appTest.BaseApp,
simtestutil.AppStateFn(appTest.AppCodec(), appTest.SimulationManager(), appTest.DefaultGenesis()),
terraApp.BaseApp,
simtestutil.AppStateFn(terraApp.AppCodec(), terraApp.SimulationManager(), terraApp.DefaultGenesis()),
simulationtypes.RandomAccounts,
simtestutil.SimulationOperations(appTest, appTest.AppCodec(), config),
appTest.ModuleAccountAddrs(),
simtestutil.SimulationOperations(terraApp, terraApp.AppCodec(), config),
terraApp.ModuleAccountAddrs(),
config,
appTest.AppCodec(),
terraApp.AppCodec(),
)

// export state and simParams before the simulation error is checked
err = simtestutil.CheckExportSimulation(appTest, config, simParams)
err = simtestutil.CheckExportSimulation(terraApp, config, simParams)
require.NoError(b, err)
require.NoError(b, simErr)

Expand All @@ -100,7 +100,7 @@ func TestSimulationManager(t *testing.T) {
db := dbm.NewMemDB()
encoding := app.MakeEncodingConfig()

AppTest := app.NewTerraApp(
terraApp := app.NewTerraApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
db,
nil,
Expand All @@ -112,6 +112,6 @@ func TestSimulationManager(t *testing.T) {
simtestutil.EmptyAppOptions{},
wasmconfig.DefaultConfig(),
)
sm := AppTest.SimulationManager()
sm := terraApp.SimulationManager()
require.NotNil(t, sm)
}
Loading

0 comments on commit 5d7df2e

Please sign in to comment.