Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(denommetadata): wire the denommetadata ibc middleware #283

Merged
merged 8 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func NewHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}
anteHandler = cosmosHandler(
options,
//nolint:staticcheck
cosmosante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), // Use old signature verification: uses EIP instead of the cosmos signature validator
)
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx": // TODO: can delete?
Expand Down
93 changes: 51 additions & 42 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"path/filepath"
"sort"

"github.com/dymensionxyz/dymension-rdk/x/denommetadata"
hubkeeper "github.com/dymensionxyz/dymension-rdk/x/hub/keeper"
hubtypes "github.com/dymensionxyz/dymension-rdk/x/hub/types"

"github.com/dymensionxyz/rollapp-evm/app/ante"

"github.com/gorilla/mux"
Expand All @@ -28,7 +32,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
simapp "github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand Down Expand Up @@ -95,13 +99,14 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types"

rollappparams "github.com/dymensionxyz/rollapp-evm/app/params"
srvflags "github.com/evmos/evmos/v12/server/flags"

rollappparams "github.com/dymensionxyz/rollapp-evm/app/params"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"

staking "github.com/dymensionxyz/dymension-rdk/x/staking"
"github.com/dymensionxyz/dymension-rdk/x/staking"
stakingkeeper "github.com/dymensionxyz/dymension-rdk/x/staking/keeper"

"github.com/dymensionxyz/dymension-rdk/x/sequencers"
Expand All @@ -111,9 +116,6 @@ import (
distr "github.com/dymensionxyz/dymension-rdk/x/dist"
distrkeeper "github.com/dymensionxyz/dymension-rdk/x/dist/keeper"

"github.com/dymensionxyz/dymension-rdk/x/denommetadata"
denommetadatamodulekeeper "github.com/dymensionxyz/dymension-rdk/x/denommetadata/keeper"
denommetadatamoduletypes "github.com/dymensionxyz/dymension-rdk/x/denommetadata/types"
"github.com/evmos/evmos/v12/ethereum/eip712"
ethermint "github.com/evmos/evmos/v12/types"
"github.com/evmos/evmos/v12/x/claims"
Expand All @@ -132,6 +134,8 @@ import (
"github.com/evmos/evmos/v12/x/ibc/transfer"
transferkeeper "github.com/evmos/evmos/v12/x/ibc/transfer/keeper"

denommetadatamoduletypes "github.com/dymensionxyz/dymension-rdk/x/denommetadata/types"

// Upgrade handlers
v2_2_0_upgrade "github.com/dymensionxyz/rollapp-evm/app/upgrades/v2.2.0"

Expand All @@ -152,14 +156,13 @@ var (
minttypes.StoreKey, distrtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey,
ibchost.StoreKey, upgradetypes.StoreKey,
epochstypes.StoreKey, hubgentypes.StoreKey,
epochstypes.StoreKey, hubtypes.StoreKey, hubgentypes.StoreKey,
ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
// ethermint keys
evmtypes.StoreKey, feemarkettypes.StoreKey,
// evmos keys
erc20types.StoreKey,
claimstypes.StoreKey,
denommetadatamoduletypes.StoreKey,
}
)

Expand Down Expand Up @@ -212,23 +215,21 @@ var (
erc20.AppModuleBasic{},
transfer.AppModuleBasic{AppModuleBasic: &ibctransfer.AppModuleBasic{}},
claims.AppModuleBasic{},
denommetadata.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},
claimstypes.ModuleName: nil,
hubgentypes.ModuleName: {authtypes.Burner},
denommetadatamoduletypes.ModuleName: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},
claimstypes.ModuleName: nil,
hubgentypes.ModuleName: {authtypes.Burner},
}

// module accounts that are allowed to receive tokens
Expand Down Expand Up @@ -284,6 +285,7 @@ type App struct {
EpochsKeeper epochskeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
HubKeeper hubkeeper.Keeper
HubGenesisKeeper hubgenkeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
Expand All @@ -302,8 +304,6 @@ type App struct {
Erc20Keeper erc20keeper.Keeper
ClaimsKeeper *claimskeeper.Keeper

DenomMetadataKeeper denommetadatamodulekeeper.Keeper

// mm is the module manager
mm *module.Manager

Expand Down Expand Up @@ -520,25 +520,29 @@ func NewRollapp(
),
)

denomMetadataHooks := denommetadatamoduletypes.NewMultiDenommetadataHooks(
erc20keeper.NewERC20ContractRegistrationHook(app.Erc20Keeper),
app.HubKeeper = hubkeeper.NewKeeper(
appCodec,
keys[hubtypes.StoreKey],
app.IBCKeeper.ChannelKeeper,
)

app.TransferKeeper = transferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.ClaimsKeeper, // ICS4 Wrapper: claims IBC middleware
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
denomMetadataMiddleware := denommetadata.NewIBCSendMiddleware(
app.ClaimsKeeper,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zale144 why we need the claims keeper?
it's unused and planned to be removed asap

app.HubKeeper,
app.BankKeeper,
)

app.DenomMetadataKeeper = denommetadatamodulekeeper.NewKeeper(
app.TransferKeeper = transferkeeper.NewKeeper(
appCodec,
keys[denommetadatamoduletypes.StoreKey],
keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
denomMetadataMiddleware, // ICS4 Wrapper: claims IBC middleware
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
app.TransferKeeper,
denomMetadataHooks,
app.GetSubspace(denommetadatamoduletypes.ModuleName),
scopedTransferKeeper,
app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers
)

app.HubGenesisKeeper = hubgenkeeper.NewKeeper(
Expand All @@ -548,6 +552,7 @@ func NewRollapp(
app.IBCKeeper.ChannelKeeper,
app.BankKeeper,
app.AccountKeeper,
app.HubKeeper,
)

// NOTE: app.Erc20Keeper is already initialized elsewhere
Expand All @@ -562,6 +567,15 @@ func NewRollapp(

transferStack = transfer.NewIBCModule(app.TransferKeeper)
transferStack = claims.NewIBCMiddleware(*app.ClaimsKeeper, transferStack)
transferStack = denommetadata.NewIBCRecvMiddleware(
transferStack,
app.BankKeeper,
app.TransferKeeper,
app.HubKeeper,
denommetadatamoduletypes.NewMultiDenommetadataHooks(
erc20keeper.NewERC20ContractRegistrationHook(app.Erc20Keeper),
),
)
transferStack = erc20.NewIBCMiddleware(app.Erc20Keeper, transferStack)

// Create static IBC router, add transfer route, then set and seal it
Expand Down Expand Up @@ -601,7 +615,6 @@ func NewRollapp(
transferModule,
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)),
claims.NewAppModule(appCodec, *app.ClaimsKeeper, app.GetSubspace(claimstypes.ModuleName)),
denommetadata.NewAppModule(app.DenomMetadataKeeper, app.BankKeeper),
}

app.mm = module.NewManager(modules...)
Expand Down Expand Up @@ -632,7 +645,6 @@ func NewRollapp(
epochstypes.ModuleName,
paramstypes.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderBeginBlockers(beginBlockersList...)

Expand All @@ -657,7 +669,6 @@ func NewRollapp(
ibchost.ModuleName,
ibctransfertypes.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderEndBlockers(endBlockersList...)

Expand Down Expand Up @@ -689,7 +700,6 @@ func NewRollapp(
upgradetypes.ModuleName,
ibctransfertypes.ModuleName,
hubgentypes.ModuleName,
denommetadatamoduletypes.ModuleName,
}
app.mm.SetOrderInitGenesis(initGenesisList...)

Expand Down Expand Up @@ -738,7 +748,7 @@ func NewRollapp(
For now, we just assume the only account with permission is the denom one
We will eventually replace with something more substantial
*/
return app.DenomMetadataKeeper.IsAddressPermissioned(ctx, accAddr.String())
return app.HubGenesisKeeper.IsAddressInGenesisTriggererAllowList(ctx, accAddr.String())
},
app.AccountKeeper,
app.StakingKeeper,
Expand Down Expand Up @@ -1026,7 +1036,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
// evmos subspaces
paramsKeeper.Subspace(erc20types.ModuleName)
paramsKeeper.Subspace(claimstypes.ModuleName)
paramsKeeper.Subspace(denommetadatamoduletypes.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bcdevtools/evm-block-explorer-rpc-cosmos v1.1.4
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cosmos/ibc-go/v6 v6.2.1
github.com/dymensionxyz/dymension-rdk v1.6.1-rc01
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240619093329-089c0278814c
github.com/dymensionxyz/dymint v1.1.3-rc04
github.com/ethereum/go-ethereum v1.12.0
github.com/evmos/evmos/v12 v12.1.6
Expand Down Expand Up @@ -317,6 +317,7 @@ require (
)

replace (
github.com/CosmWasm/wasmd => github.com/decentrio/wasmd v0.33.0-sdk46.2
github.com/centrifuge/go-substrate-rpc-client/v4 => github.com/availproject/go-substrate-rpc-client/v4 v4.0.12-avail-1.4.0-rc1-5e286e3
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
// use Evmos geth fork
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/CosmWasm/wasmvm v1.2.3 h1:OKYlobwmVGbl0eSn0mXoAAjE5hIuXnQCLPjbNd91sVY=
github.com/CosmWasm/wasmvm v1.2.3/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
Expand Down Expand Up @@ -491,6 +493,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c h1:pFUpOrbxDR6AkioZ1ySsx5yxlDQZ8stG2b88gTPxgJU=
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c/go.mod h1:6UhI8N9EjYm1c2odKpFpAYeR8dsBeM7PtzQhRgxRr9U=
github.com/decentrio/wasmd v0.33.0-sdk46.2 h1:cUgYN8crDXiQiKLBYfGR5IXg77Z/QrvZBoU9Fg/1ACo=
github.com/decentrio/wasmd v0.33.0-sdk46.2/go.mod h1:mPBiB+54La70eS2HHzvK2Vn7Frgf7rjnxDo70oopw+w=
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/decred/base58 v1.0.4 h1:QJC6B0E0rXOPA8U/kw2rP+qiRJsUaE2Er+pYb3siUeA=
Expand Down Expand Up @@ -529,6 +533,8 @@ github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/docker/cli v24.0.2+incompatible h1:QdqR7znue1mtkXIJ+ruQMGQhpw2JzMJLRXp6zpzF6tM=
github.com/docker/cli v24.0.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.6.2/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v24.0.2+incompatible h1:eATx+oLz9WdNVkQrr0qjQ8HvRJ4bOOxfzEo8R+dA3cg=
github.com/docker/docker v24.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand All @@ -551,8 +557,8 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx
github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/cosmosclient v0.4.2-beta h1:sokBefcN1tIOlUKmB8Q2E9XMJ93LueqtFThiM/kA4DI=
github.com/dymensionxyz/cosmosclient v0.4.2-beta/go.mod h1:GQQu3ITEjWfi5ULR2B6X2i2YZNennY1yzcT5qdL4MGI=
github.com/dymensionxyz/dymension-rdk v1.6.1-rc01 h1:qkkW3FhGyWNAh8hy04b1JuT85rAVTx13HthR7przxjo=
github.com/dymensionxyz/dymension-rdk v1.6.1-rc01/go.mod h1:WxJQLPL8HXg00qNY4P1XVZDbIHoNVQT2eQTrIPZYWtg=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240619093329-089c0278814c h1:niw+muXRUVxzdCL++HRA3AMqwhUuYubG6klEuL3QNNI=
github.com/dymensionxyz/dymension-rdk v1.6.1-0.20240619093329-089c0278814c/go.mod h1:TAHvT9y1D9gEgq4j4OPghlmxn9Z7T2dSAbxjhOa25q8=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56 h1:cmpJYdRviuUfmlJdHrcAND8Jd6JIY4rp63bWAQzPr54=
github.com/dymensionxyz/dymension/v3 v3.1.0-rc03.0.20240411195658-f7cd96f53b56/go.mod h1:3Pfrr8j/BR9ztNKztGfC5PqDiO6CcrzMLCJtFtPEVW4=
github.com/dymensionxyz/dymint v1.1.3-rc04 h1:RqDF8bxB73mYmxHKnVNGeTnTsZihAwV6AElIgIDL5Xw=
Expand Down
Loading