Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elys-network/elys into transfer_mid…
Browse files Browse the repository at this point in the history
…dleware
  • Loading branch information
jelysn committed Sep 27, 2023
2 parents c94e50a + be505a9 commit b54029f
Show file tree
Hide file tree
Showing 70 changed files with 5,144 additions and 165 deletions.
103 changes: 75 additions & 28 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/log"
Expand Down Expand Up @@ -95,6 +92,9 @@ 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"
ibc_hooks "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"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
Expand Down Expand Up @@ -167,6 +167,14 @@ import (
transferhookkeeper "github.com/elys-network/elys/x/transferhook/keeper"
transferhooktypes "github.com/elys-network/elys/x/transferhook/types"

clockmodule "github.com/elys-network/elys/x/clock"
clockmodulekeeper "github.com/elys-network/elys/x/clock/keeper"
clockmoduletypes "github.com/elys-network/elys/x/clock/types"

wasmmodule "github.com/CosmWasm/wasmd/x/wasm"
wasmmodulekeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmmoduletypes "github.com/CosmWasm/wasmd/x/wasm/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

"github.com/elys-network/elys/docs"
Expand Down Expand Up @@ -208,15 +216,15 @@ func getGovProposalHandlers() []govclient.ProposalHandler {

// GetEnabledProposals parses the ProposalsEnabled / EnableSpecificProposals values to
// produce a list of enabled proposals to pass into wasmd app.
func GetEnabledProposals() []wasm.ProposalType {
func GetEnabledProposals() []wasmmodule.ProposalType {
if EnableSpecificProposals == "" {
if ProposalsEnabled == "true" {
return wasm.EnableAllProposals
return wasmmodule.EnableAllProposals
}
return wasm.DisableAllProposals
return wasmmodule.DisableAllProposals
}
chunks := strings.Split(EnableSpecificProposals, ",")
proposals, err := wasm.ConvertToProposals(chunks)
proposals, err := wasmmodule.ConvertToProposals(chunks)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -254,7 +262,7 @@ var (
ibcfee.AppModuleBasic{},
vesting.AppModuleBasic{},
consensus.AppModuleBasic{},
wasm.AppModuleBasic{},
wasmmodule.AppModuleBasic{},
epochsmodule.AppModuleBasic{},
assetprofilemodule.AppModuleBasic{},
liquidityprovidermodule.AppModuleBasic{},
Expand All @@ -268,6 +276,7 @@ var (
marginmodule.AppModuleBasic{},
accountedpoolmodule.AppModuleBasic{},
transferhook.AppModuleBasic{},
clockmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -286,7 +295,7 @@ var (
burnermoduletypes.ModuleName: {authtypes.Burner},
incentivemoduletypes.ModuleName: nil,
ammmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
wasm.ModuleName: {authtypes.Burner},
wasmmoduletypes.ModuleName: {authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -335,13 +344,14 @@ type ElysApp struct {
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
GroupKeeper groupkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
WasmKeeper wasm.Keeper
WasmKeeper wasmmodulekeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -362,7 +372,9 @@ type ElysApp struct {
AmmKeeper ammmodulekeeper.Keeper
ParameterKeeper parametermodulekeeper.Keeper
MarginKeeper marginmodulekeeper.Keeper
TransferhookKeeper transferhookkeeper.Keeper
TransferhookKeeper transferhookkeeper.Keeper
ContractKeeper *wasmmodulekeeper.PermissionedKeeper
ClockKeeper clockmodulekeeper.Keeper

AccountedPoolKeeper accountedpoolmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
Expand All @@ -373,6 +385,10 @@ type ElysApp struct {
// sm is the simulation manager
sm *module.SimulationManager
configurator module.Configurator

// Middleware wrapper
Ics20WasmHooks *ibc_hooks.WasmHooks
HooksICS4Wrapper ibc_hooks.ICS4Middleware
}

// New returns a reference to an initialized blockchain app
Expand All @@ -381,9 +397,9 @@ func NewElysApp(
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
enabledProposals []wasm.ProposalType,
enabledProposals []wasmmodule.ProposalType,
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
wasmOpts []wasmmodule.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *ElysApp {
encodingConfig := MakeEncodingConfig()
Expand Down Expand Up @@ -419,7 +435,7 @@ func NewElysApp(
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey, group.StoreKey,
ibcfeetypes.StoreKey,
icacontrollertypes.StoreKey,
wasm.StoreKey,
wasmmodule.StoreKey,
consensusparamtypes.StoreKey,
epochsmoduletypes.StoreKey,
assetprofilemoduletypes.StoreKey,
Expand All @@ -434,6 +450,7 @@ func NewElysApp(
parametermoduletypes.StoreKey,
marginmoduletypes.StoreKey,
transferhooktypes.StoreKey,
clockmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, ammmoduletypes.TStoreKey)
Expand Down Expand Up @@ -482,7 +499,7 @@ func NewElysApp(
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasmmodule.ModuleName)
// this line is used by starport scaffolding # stargate/app/scopedKeeper

// add keepers
Expand Down Expand Up @@ -772,7 +789,7 @@ func NewElysApp(
parameterModule := parametermodule.NewAppModule(appCodec, app.ParameterKeeper, app.AccountKeeper, app.BankKeeper)

wasmDir := filepath.Join(homePath, "wasm")
wasmConfig, err := wasm.ReadWasmConfig(appOpts)
wasmConfig, err := wasmmodule.ReadWasmConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error while reading wasm config: %s", err))
}
Expand All @@ -783,9 +800,9 @@ func NewElysApp(

wasmOpts = append(RegisterCustomPlugins(&app.OracleKeeper), wasmOpts...)

app.WasmKeeper = wasm.NewKeeper(
app.WasmKeeper = wasmmodule.NewKeeper(
appCodec,
keys[wasm.StoreKey],
keys[wasmmodule.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand All @@ -810,6 +827,22 @@ func NewElysApp(
app.GetSubspace(transferhooktypes.ModuleName),
app.AmmKeeper)
transferhookModule := transferhook.NewAppModule(appCodec, app.TransferhookKeeper)
// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
keys[ibchookstypes.StoreKey],
)
app.IBCHooksKeeper = &hooksKeeper

wasmHooks := ibc_hooks.NewWasmHooks(app.IBCHooksKeeper, &app.WasmKeeper, AccountAddressPrefix) // The contract keeper needs to be set later
app.Ics20WasmHooks = &wasmHooks
app.HooksICS4Wrapper = ibc_hooks.NewICS4Middleware(
app.IBCKeeper.ChannelKeeper,
app.Ics20WasmHooks,
)

// set the contract keeper for the Ics20WasmHooks
app.ContractKeeper = wasmmodulekeeper.NewDefaultPermissionKeeper(app.WasmKeeper)
app.Ics20WasmHooks.ContractKeeper = &app.WasmKeeper

govConfig := govtypes.DefaultConfig()
govKeeper := govkeeper.NewKeeper(
Expand All @@ -834,7 +867,7 @@ func NewElysApp(
AddRoute(parametermoduletypes.RouterKey, parametermodule.NewParameterChangeProposalHandler(&app.ParameterKeeper))
// The gov proposal types can be individually enabled
if len(enabledProposals) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
govRouter.AddRoute(wasmmodule.RouterKey, wasmmodule.NewWasmProposalHandler(app.WasmKeeper, enabledProposals))
}
govKeeper.SetLegacyRouter(govRouter)

Expand All @@ -849,6 +882,15 @@ func NewElysApp(
)
marginModule := marginmodule.NewAppModule(appCodec, app.MarginKeeper, app.AccountKeeper, app.BankKeeper)

app.ClockKeeper = *clockmodulekeeper.NewKeeper(
keys[clockmoduletypes.StoreKey],
appCodec,
app.GetSubspace(clockmoduletypes.ModuleName),
*app.ContractKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
clockModule := clockmodule.NewAppModule(appCodec, app.ClockKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition

/**** IBC Routing ****/
Expand All @@ -858,7 +900,7 @@ func NewElysApp(

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

var transferStack porttypes.IBCModule = transferIBCModule
Expand All @@ -868,7 +910,7 @@ func NewElysApp(
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(wasm.ModuleName, wasmStack).
AddRoute(wasmmodule.ModuleName, wasmStack).
AddRoute(oracletypes.ModuleName, oracleIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -947,7 +989,7 @@ func NewElysApp(
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasmmodule.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmmoduletypes.ModuleName)),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
Expand All @@ -965,6 +1007,7 @@ func NewElysApp(
marginModule,
accountedPoolModule,
transferhookModule,
clockModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -1006,9 +1049,10 @@ func NewElysApp(
ammmoduletypes.ModuleName,
parametermoduletypes.ModuleName,
marginmoduletypes.ModuleName,
wasm.ModuleName,
wasmmodule.ModuleName,
accountedpoolmoduletypes.ModuleName,
transferhooktypes.ModuleName,
clockmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -1045,9 +1089,10 @@ func NewElysApp(
ammmoduletypes.ModuleName,
parametermoduletypes.ModuleName,
marginmoduletypes.ModuleName,
wasm.ModuleName,
wasmmodule.ModuleName,
accountedpoolmoduletypes.ModuleName,
transferhooktypes.ModuleName,
clockmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -1088,9 +1133,10 @@ func NewElysApp(
ammmoduletypes.ModuleName,
parametermoduletypes.ModuleName,
marginmoduletypes.ModuleName,
wasm.ModuleName,
wasmmodule.ModuleName,
accountedpoolmoduletypes.ModuleName,
transferhooktypes.ModuleName,
clockmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
}
app.mm.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -1127,14 +1173,14 @@ func NewElysApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
SetupHandlers(app)
app.setAnteHandler(encodingConfig.TxConfig, wasmConfig, keys[wasm.StoreKey])
app.setAnteHandler(encodingConfig.TxConfig, wasmConfig, keys[wasmmodule.StoreKey])

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
wasmmodulekeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
Expand Down Expand Up @@ -1181,7 +1227,7 @@ func NewElysApp(
return app
}

func (app *ElysApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.WasmConfig, txCounterStoreKey storetypes.StoreKey) {
func (app *ElysApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmmoduletypes.WasmConfig, txCounterStoreKey storetypes.StoreKey) {
anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand Down Expand Up @@ -1388,6 +1434,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(marginmoduletypes.ModuleName)
paramsKeeper.Subspace(accountedpoolmoduletypes.ModuleName)
paramsKeeper.Subspace(transferhooktypes.ModuleName)
paramsKeeper.Subspace(clockmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
5 changes: 4 additions & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
ammtypes "github.com/elys-network/elys/x/amm/types"
assetprofiletypes "github.com/elys-network/elys/x/assetprofile/types"
burnertypes "github.com/elys-network/elys/x/burner/types"
clocktypes "github.com/elys-network/elys/x/clock/types"
commitmenttypes "github.com/elys-network/elys/x/commitment/types"
incentivetypes "github.com/elys-network/elys/x/incentive/types"
liquidityprovidertypes "github.com/elys-network/elys/x/liquidityprovider/types"
Expand Down Expand Up @@ -80,6 +81,8 @@ func setUpgradeHandler(app *ElysApp) {
keyTable = tokenomicstypes.ParamKeyTable() //nolint:staticcheck
case accountedpooltypes.ModuleName:
keyTable = accountedpooltypes.ParamKeyTable() //nolint:staticcheck
case clocktypes.ModuleName:
keyTable = clocktypes.ParamKeyTable() //nolint:staticcheck
}

if !subspace.HasKeyTable() {
Expand Down Expand Up @@ -112,7 +115,7 @@ func loadUpgradeStore(app *ElysApp) {
if shouldLoadUpgradeStore(app, upgradeInfo) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
accountedpooltypes.ModuleName,
clocktypes.ModuleName,
},
}
// Use upgrade store loader for the initial loading of all stores when app starts,
Expand Down
6 changes: 4 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ version: 1
accounts:
- name: treasury
coins:
- 100000000uatom
- 100000000uusdt
- 1000000000000uatom
- 1000000000000uusdc
- 1000000000000uusdt
- 9000000000000000uelys
- 100000000ueden
mnemonic: olympic slide park figure frost benefit deer reform fly pull price airport submit monitor silk insect uphold convince pupil project ignore roof warfare slight
Expand Down Expand Up @@ -238,6 +239,7 @@ genesis:
withdraw_addr_enabled: true
reward_portion_for_lps: "0.65"
pool_infos: []
elys_stake_tracking_rate: "10"
fee_pool:
community_pool:
- amount: "0"
Expand Down
Loading

0 comments on commit b54029f

Please sign in to comment.