Skip to content
Draft
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
97 changes: 84 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -78,7 +80,7 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
Expand All @@ -89,11 +91,10 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

tmjson "github.com/tendermint/tendermint/libs/json"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"

tmjson "github.com/tendermint/tendermint/libs/json"

"github.com/gravity-devs/liquidity/x/liquidity"
liquiditykeeper "github.com/gravity-devs/liquidity/x/liquidity/keeper"
liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types"
Expand All @@ -108,10 +109,29 @@ import (
"github.com/AutonomyNetwork/nft"
nftKeeper "github.com/AutonomyNetwork/nft/keeper"
nftTypes "github.com/AutonomyNetwork/nft/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmKeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

const Name = "autonomy"

func GetWasmEnabledProposals() []wasm.ProposalType {
if EnableSpecificWasmProposals == "" {
if WasmProposalsEnabled == "true" {
return wasm.EnableAllProposals
}
return wasm.DisableAllProposals
}
chunks := strings.Split(EnableSpecificWasmProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
return proposals
}
func getGovProposalHandlers() []govclient.ProposalHandler {
var govProposalHandlers []govclient.ProposalHandler

Expand All @@ -124,13 +144,15 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
ibcclientclient.UpgradeProposalHandler,
)

govProposalHandlers = append(govProposalHandlers, wasmclient.ProposalHandlers...)
return govProposalHandlers
}

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

DefaultNodeHome string
WasmProposalsEnabled = "true"
EnableSpecificWasmProposals = ""
// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
Expand Down Expand Up @@ -158,6 +180,7 @@ var (

issuance.AppModuleBasic{},
nft.AppModuleBasic{},
wasm.AppModuleBasic{},
)

// module account permissions
Expand All @@ -172,6 +195,7 @@ var (
issuanceTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
nftTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasmTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}
)

Expand Down Expand Up @@ -227,10 +251,11 @@ type App struct {

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

IssuanceKeeper issuanceKeeper.Keeper
NFTKeeper nftKeeper.Keeper

WasmKeeper wasmKeeper.Keeper
// the module manager
mm *module.Manager

Expand All @@ -242,7 +267,7 @@ type App struct {
func New(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
appOpts servertypes.AppOptions, eanbledProposal []wasm.ProposalType, wasmOpts []wasm.Option, baseAppOptions ...func(*baseapp.BaseApp),
) *App {

appCodec := encodingConfig.Marshaler
Expand All @@ -259,7 +284,7 @@ func New(
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
issuanceTypes.StoreKey, authzkeeper.StoreKey, liquiditytypes.StoreKey, nftTypes.StoreKey,
issuanceTypes.StoreKey, authzkeeper.StoreKey, liquiditytypes.StoreKey, nftTypes.StoreKey, wasmTypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand All @@ -285,6 +310,7 @@ func New(
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -328,6 +354,32 @@ func New(

app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.BaseApp.MsgServiceRouter())

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}
supportedFeatures := "iterator,staking,stargate,comdex"

app.WasmKeeper = wasm.NewKeeper(
app.appCodec,
keys[wasmTypes.StoreKey],
app.GetSubspace(wasmTypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.DistrKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedWasmKeeper,
app.TransferKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
wasmOpts...,
)
// register the proposal types
govRouter := govtypes.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
Expand All @@ -336,6 +388,10 @@ func New(
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

if len(eanbledProposal) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, eanbledProposal))
}

app.GovKeeper = govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, govRouter,
Expand Down Expand Up @@ -374,7 +430,7 @@ func New(
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)

app.IBCKeeper.SetRouter(ibcRouter)

/**** Module Options ****/
Expand Down Expand Up @@ -412,6 +468,7 @@ func New(

issuance.NewAppModule(appCodec, app.IssuanceKeeper, app.BankKeeper),
nft.NewAppModule(appCodec, app.NFTKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
Expand Down Expand Up @@ -439,7 +496,8 @@ func New(
vestingtypes.ModuleName,
nftTypes.ModuleName,
issuanceTypes.ModuleName,
)
wasmTypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -463,7 +521,8 @@ func New(
vestingtypes.ModuleName,
nftTypes.ModuleName,
issuanceTypes.ModuleName,
)
wasmTypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
Expand Down Expand Up @@ -492,6 +551,7 @@ func New(
feegrant.ModuleName,
liquiditytypes.ModuleName,
nftTypes.ModuleName,
wasmTypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -552,6 +612,16 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}

encCfg := MakeEncodingConfig()
wasmGen := wasm.GenesisState{
Params: wasmTypes.Params{
CodeUploadAccess: wasmTypes.AllowNobody,
InstantiateDefaultPermission: wasmTypes.AccessTypeNobody,
},
}
genesisState[wasm.ModuleName] = encCfg.Marshaler.MustMarshalJSON(&wasmGen)

return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down Expand Up @@ -676,6 +746,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(liquiditytypes.ModuleName)
paramsKeeper.Subspace(nftTypes.ModuleName)
paramsKeeper.Subspace(wasmTypes.ModuleName)

return paramsKeeper
}
Binary file added cmd/autonomy/autonomy
Binary file not shown.
Loading