Skip to content

Commit

Permalink
feat(IRO): IRO module implementation (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Sep 24, 2024
1 parent 05e445c commit 5601240
Show file tree
Hide file tree
Showing 90 changed files with 15,103 additions and 417 deletions.
9 changes: 3 additions & 6 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

delayedack "github.com/dymensionxyz/dymension/v3/x/delayedack"
lightclientante "github.com/dymensionxyz/dymension/v3/x/lightclient/ante"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis"
)

func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
Expand Down Expand Up @@ -74,9 +75,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
delayedack.NewIBCProofHeightDecorator(),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
)
}

Expand Down Expand Up @@ -112,8 +111,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
lightclientante.NewIBCMessagesDecorator(*options.LightClientKeeper, options.IBCKeeper.ClientKeeper, options.IBCKeeper.ChannelKeeper, options.RollappKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
transfergenesis.NewTransferEnabledDecorator(options.RollappKeeper.GetRollapp, options.IBCKeeper.ChannelKeeper),
)
}
22 changes: 13 additions & 9 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
app "github.com/dymensionxyz/dymension/v3/app"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

Expand Down Expand Up @@ -80,17 +81,20 @@ func SetupTestingApp() (*app.App, app.GenesisState) {
params.SetAddressPrefixes()

newApp := app.New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, app.DefaultNodeHome, 5, encCdc, EmptyAppOptions{}, bam.SetChainID(TestChainID))

defaultGenesisState := app.NewDefaultGenesisState(encCdc.Codec)

// set EnableCreate to false
if evmGenesisStateJson, found := defaultGenesisState[evmtypes.ModuleName]; found {
// force disable Enable Create of x/evm
var evmGenesisState evmtypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(evmGenesisStateJson, &evmGenesisState)
evmGenesisState.Params.EnableCreate = false
defaultGenesisState[evmtypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&evmGenesisState)
}
incentivesGenesisStateJson := defaultGenesisState[incentivestypes.ModuleName]
var incentivesGenesisState incentivestypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(incentivesGenesisStateJson, &incentivesGenesisState)
incentivesGenesisState.LockableDurations = append(incentivesGenesisState.LockableDurations, time.Second*60)
defaultGenesisState[incentivestypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&incentivesGenesisState)

// force disable EnableCreate of x/evm
evmGenesisStateJson := defaultGenesisState[evmtypes.ModuleName]
var evmGenesisState evmtypes.GenesisState
encCdc.Codec.MustUnmarshalJSON(evmGenesisStateJson, &evmGenesisState)
evmGenesisState.Params.EnableCreate = false
defaultGenesisState[evmtypes.ModuleName] = encCdc.Codec.MustMarshalJSON(&evmGenesisState)

return newApp, defaultGenesisState
}
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *KeeperTestHelper) CreateRollappByName(name string) {
Bech32Prefix: strings.ToLower(rand.Str(3)),
GenesisChecksum: "1234567890abcdefg",
InitialSupply: sdk.NewInt(1000),
NativeDenom: &rollapptypes.DenomMetadata{
NativeDenom: rollapptypes.DenomMetadata{
Display: "DEN",
Base: "aden",
Exponent: 18,
Expand Down
20 changes: 17 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ import (
eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"
incentiveskeeper "github.com/dymensionxyz/dymension/v3/x/incentives/keeper"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
irokeeper "github.com/dymensionxyz/dymension/v3/x/iro/keeper"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
lightclientmodulekeeper "github.com/dymensionxyz/dymension/v3/x/lightclient/keeper"
lightclientmoduletypes "github.com/dymensionxyz/dymension/v3/x/lightclient/types"
lockupkeeper "github.com/dymensionxyz/dymension/v3/x/lockup/keeper"
lockuptypes "github.com/dymensionxyz/dymension/v3/x/lockup/types"
rollappmodule "github.com/dymensionxyz/dymension/v3/x/rollapp"
rollappmodulekeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/rollapp/transfergenesis"
rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
sequencermodulekeeper "github.com/dymensionxyz/dymension/v3/x/sequencer/keeper"
sequencermoduletypes "github.com/dymensionxyz/dymension/v3/x/sequencer/types"
Expand Down Expand Up @@ -121,6 +124,7 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
PacketForwardMiddlewareKeeper *packetforwardkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
IROKeeper *irokeeper.Keeper

// Ethermint keepers
EvmKeeper *evmkeeper.Keeper
Expand Down Expand Up @@ -383,6 +387,17 @@ func (a *AppKeepers) InitKeepers(
a.RollappKeeper,
)

a.IROKeeper = irokeeper.NewKeeper(
appCodec,
a.keys[irotypes.StoreKey],
&a.AccountKeeper,
a.BankKeeper,
a.RollappKeeper,
a.GAMMKeeper,
a.IncentivesKeeper,
a.PoolManagerKeeper,
)

a.SponsorshipKeeper = sponsorshipkeeper.NewKeeper(
appCodec,
a.keys[sponsorshiptypes.StoreKey],
Expand Down Expand Up @@ -511,9 +526,7 @@ func (a *AppKeepers) InitTransferStack() {
delayedackmodule.WithRollappKeeper(a.RollappKeeper),
)
a.TransferStack = a.delayedAckMiddleware

// disabled until #1208 handled (https://github.com/dymensionxyz/dymension/issues/1208)
// a.TransferStack = transfergenesis.NewIBCModule(a.TransferStack, a.DelayedAckKeeper, *a.RollappKeeper, a.TransferKeeper, a.DenomMetadataKeeper)
a.TransferStack = transfergenesis.NewIBCModule(a.TransferStack, a.RollappKeeper, a.TransferKeeper, a.DenomMetadataKeeper, a.IROKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
Expand Down Expand Up @@ -589,6 +602,7 @@ func (a *AppKeepers) SetupHooks() {
a.StreamerKeeper.Hooks(),
a.DymNSKeeper.GetRollAppHooks(),
a.LightClientKeeper.RollappHooks(),
a.IROKeeper,
))
}

Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types"
Expand Down Expand Up @@ -114,6 +115,7 @@ var KVStoreKeys = sdk.NewKVStoreKeys(
capabilitytypes.StoreKey,
crisistypes.StoreKey,
consensusparamtypes.StoreKey,
irotypes.StoreKey,
rollappmoduletypes.StoreKey,
sequencermoduletypes.StoreKey,
sponsorshiptypes.StoreKey,
Expand Down
12 changes: 10 additions & 2 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ import (
"github.com/dymensionxyz/dymension/v3/x/eibc"
eibcmoduletypes "github.com/dymensionxyz/dymension/v3/x/eibc/types"
incentivestypes "github.com/dymensionxyz/dymension/v3/x/incentives/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp"

"github.com/dymensionxyz/dymension/v3/x/iro"
irotypes "github.com/dymensionxyz/dymension/v3/x/iro/types"
lightclientmodule "github.com/dymensionxyz/dymension/v3/x/lightclient"
lightclientmoduletypes "github.com/dymensionxyz/dymension/v3/x/lightclient/types"
"github.com/dymensionxyz/dymension/v3/x/rollapp"
rollappmoduleclient "github.com/dymensionxyz/dymension/v3/x/rollapp/client"
rollappmoduletypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/dymensionxyz/dymension/v3/x/sequencer"
Expand Down Expand Up @@ -150,6 +151,7 @@ var ModuleBasics = module.NewBasicManager(
streamer.AppModuleBasic{},
denommetadata.AppModuleBasic{},
packetforward.AppModuleBasic{},
iro.AppModuleBasic{},
delayedack.AppModuleBasic{},
eibc.AppModuleBasic{},
dymnsmodule.AppModuleBasic{},
Expand Down Expand Up @@ -199,6 +201,7 @@ func (a *AppKeepers) SetupModules(
packetforwardmiddleware.NewAppModule(a.PacketForwardMiddlewareKeeper, a.GetSubspace(packetforwardtypes.ModuleName)),
ibctransfer.NewAppModule(a.TransferKeeper),
rollappmodule.NewAppModule(appCodec, a.RollappKeeper, a.AccountKeeper, a.BankKeeper),
iro.NewAppModule(appCodec, *a.IROKeeper),
sequencermodule.NewAppModule(appCodec, a.SequencerKeeper, a.AccountKeeper, a.BankKeeper, a.GetSubspace(sequencertypes.ModuleName)),
sponsorship.NewAppModule(a.SponsorshipKeeper),
streamermodule.NewAppModule(a.StreamerKeeper, a.AccountKeeper, a.BankKeeper, a.EpochsKeeper),
Expand Down Expand Up @@ -232,6 +235,7 @@ func (*AppKeepers) ModuleAccountAddrs() map[string]bool {
// exclude the streamer as we want him to be able to get external incentives
modAccAddrs[authtypes.NewModuleAddress(streamermoduletypes.ModuleName).String()] = false
modAccAddrs[authtypes.NewModuleAddress(txfeestypes.ModuleName).String()] = false
modAccAddrs[authtypes.NewModuleAddress(irotypes.ModuleName).String()] = false
return modAccAddrs
}

Expand All @@ -255,6 +259,7 @@ var maccPerms = map[string][]string{
incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner},
txfeestypes.ModuleName: {authtypes.Burner},
dymnstypes.ModuleName: {authtypes.Minter, authtypes.Burner},
irotypes.ModuleName: {authtypes.Minter, authtypes.Burner},
}

var BeginBlockers = []string{
Expand Down Expand Up @@ -294,6 +299,7 @@ var BeginBlockers = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
}

Expand Down Expand Up @@ -333,6 +339,7 @@ var EndBlockers = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
}
Expand Down Expand Up @@ -373,6 +380,7 @@ var InitGenesis = []string{
incentivestypes.ModuleName,
txfeestypes.ModuleName,
consensusparamtypes.ModuleName,
irotypes.ModuleName,
lightclientmoduletypes.ModuleName,
crisistypes.ModuleName,
}
4 changes: 2 additions & 2 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollap
GenesisInfo: rollapptypes.GenesisInfo{
Bech32Prefix: oldRollapp.RollappId[:5], // placeholder data
GenesisChecksum: string(crypto.Sha256([]byte(oldRollapp.RollappId))), // placeholder data
NativeDenom: &rollapptypes.DenomMetadata{
NativeDenom: rollapptypes.DenomMetadata{
Display: "DEN", // placeholder data
Base: "aden", // placeholder data
Exponent: 6, // placeholder data
Exponent: 18, // placeholder data
},
InitialSupply: sdk.NewInt(100000), // placeholder data
Sealed: true,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/osmosis-labs/osmosis/osmomath v0.0.4
github.com/osmosis-labs/osmosis/v15 v15.2.0
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.6.0
Expand Down Expand Up @@ -169,7 +170,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/osmosis-labs/osmosis/osmomath v0.0.4 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
Loading

0 comments on commit 5601240

Please sign in to comment.