Skip to content

Commit

Permalink
fix: use neutron fork
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Dec 22, 2023
1 parent 02d2e2a commit 85d1a19
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import (
v05 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v05"
"github.com/Nolus-Protocol/nolus-core/docs"

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

const (
Expand Down Expand Up @@ -213,7 +213,7 @@ func New(
},
BankKeeper: app.BankKeeper,
TaxKeeper: *app.TaxKeeper,
TxCounterStoreKey: app.GetKVStoreKey()[wasm.StoreKey],
TxCounterStoreKey: app.GetKVStoreKey()[wasmtypes.StoreKey],
WasmConfig: &app.WasmConfig,
IBCKeeper: app.IBCKeeper,
},
Expand Down
71 changes: 11 additions & 60 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keepers

import (
"path/filepath"
"strings"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -64,6 +63,7 @@ import (
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

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

"github.com/neutron-org/neutron/x/contractmanager"
Expand All @@ -82,55 +82,6 @@ import (
wrapkeeper "github.com/neutron-org/neutron/x/transfer/keeper"
)

var (
// WasmProposalsEnabled enables all x/wasm proposals when it's value is "true"
// and EnableSpecificWasmProposals is empty. Otherwise, all x/wasm proposals
// are disabled.
WasmProposalsEnabled = "true"

// EnableSpecificWasmProposals, if set, must be comma-separated list of values
// that are all a subset of "EnableAllProposals", which takes precedence over
// WasmProposalsEnabled.
//
// See: https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificWasmProposals = ""

// EmptyWasmOpts defines a type alias for a list of wasm options.
EmptyWasmOpts []wasm.Option
)

var (
// If EnabledSpecificProposals is "", and this is "true", then enable all x/wasm proposals.
// If EnabledSpecificProposals is "", and this is not "true", then disable all x/wasm proposals.
ProposalsEnabled = "true"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://github.com/CosmWasm/wasmd/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

// GetWasmEnabledProposals parses the WasmProposalsEnabled and
// EnableSpecificWasmProposals values to produce a list of enabled proposals to
// pass into the application.
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
}

type AppKeepers struct {
// keys to access the substores
keys map[string]*storetypes.KVStoreKey
Expand Down Expand Up @@ -171,7 +122,7 @@ type AppKeepers struct {
InterchainQueriesKeeper *interchainquerieskeeper.Keeper
ContractManagerKeeper *contractmanagermodulekeeper.Keeper

WasmKeeper wasm.Keeper
WasmKeeper wasmkeeper.Keeper
WasmConfig wasmtypes.WasmConfig

// Modules
Expand Down Expand Up @@ -227,7 +178,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedInterchainTxsKeeper = appKeepers.CapabilityKeeper.ScopeToModule(interchaintxstypes.ModuleName)
appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
appKeepers.ScopedWasmKeeper = appKeepers.CapabilityKeeper.ScopeToModule(wasmtypes.ModuleName)

// seal capabilities after scoping modules
appKeepers.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -419,14 +370,14 @@ func (appKeepers *AppKeepers) NewAppKeepers(
}
appKeepers.WasmConfig = wasmConfig

var wasmOpts []wasm.Option
var wasmOpts []wasmkeeper.Option
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate,migrate,upgrade,neutron,cosmwasm_1_1,cosmwasm_1_2"
wasmOpts = append(wasmbinding.RegisterCustomPlugins(appKeepers.InterchainTxsKeeper, appKeepers.InterchainQueriesKeeper, *appKeepers.TransferKeeper, appKeepers.FeeRefunderKeeper, appKeepers.ContractManagerKeeper), wasmOpts...)
appKeepers.WasmKeeper = wasm.NewKeeper(
appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
appCodec,
appKeepers.keys[wasm.StoreKey],
appKeepers.keys[wasmtypes.StoreKey],
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
Expand Down Expand Up @@ -458,9 +409,9 @@ func (appKeepers *AppKeepers) NewAppKeepers(
AddRoute(ibcexported.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))

// The gov proposal types can be individually enabled
if len(GetWasmEnabledProposals()) != 0 {
govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(appKeepers.WasmKeeper, GetWasmEnabledProposals()))
}
// if len(GetWasmEnabledProposals()) != 0 {
// govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(appKeepers.WasmKeeper, GetWasmEnabledProposals()))
// }

govConfig := govtypes.DefaultConfig()
// MaxMetadataLen defines the maximum proposal metadata length.
Expand Down Expand Up @@ -514,7 +465,7 @@ func (appKeepers *AppKeepers) NewAppKeepers(
ibcRouter.AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(interchaintxstypes.ModuleName, icaControllerStack).
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper))
AddRoute(wasmtypes.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper))
appKeepers.IBCKeeper.SetRouter(ibcRouter)

authzKeepper := authzkeeper.NewKeeper(
Expand Down Expand Up @@ -548,7 +499,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(wasm.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(feetypes.ModuleName)
Expand Down
5 changes: 3 additions & 2 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
taxmoduletypes "github.com/Nolus-Protocol/nolus-core/x/tax/types"
vestingstypes "github.com/Nolus-Protocol/nolus-core/x/vestings/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

contractmanagermoduletypes "github.com/neutron-org/neutron/x/contractmanager/types"
feerefundertypes "github.com/neutron-org/neutron/x/feerefunder/types"
Expand Down Expand Up @@ -58,7 +58,8 @@ func (appKeepers *AppKeepers) GenerateKeys() {
interchainqueriestypes.StoreKey,
contractmanagermoduletypes.StoreKey,
interchaintxstypes.StoreKey,
wasm.StoreKey, feerefundertypes.StoreKey,
wasmtypes.StoreKey,
feerefundertypes.StoreKey,
consensusparamtypes.StoreKey,
)

Expand Down
8 changes: 4 additions & 4 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var maccPerms = map[string][]string{
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
wasm.ModuleName: {authtypes.Burner},
wasmtypes.ModuleName: {authtypes.Burner},
vestingstypes.ModuleName: nil,
icatypes.ModuleName: nil,
interchainqueriestypes.ModuleName: nil,
Expand Down Expand Up @@ -232,7 +232,7 @@ func orderBeginBlockers() []string {
interchaintxstypes.ModuleName,
interchainqueriestypes.ModuleName,
contractmanagermoduletypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
feetypes.ModuleName,
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func orderEndBlockers() []string {
interchaintxstypes.ModuleName,
interchainqueriestypes.ModuleName,
contractmanagermoduletypes.ModuleName,
wasm.ModuleName,
wasmtypes.ModuleName,
feetypes.ModuleName,
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func orderInitBlockers() []string {
interchaintxstypes.ModuleName,
contractmanagermoduletypes.ModuleName,
// wasm after ibc transfer
wasm.ModuleName,
wasmtypes.ModuleName,
feetypes.ModuleName,
consensusparamtypes.ModuleName,
}
Expand Down
3 changes: 1 addition & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"

"github.com/CosmWasm/wasmd/x/wasm"
wasmsim "github.com/CosmWasm/wasmd/x/wasm/simulation"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

Expand Down Expand Up @@ -302,7 +301,7 @@ func TestAppImportExport(t *testing.T) {
{keys[contractmanagermoduletypes.StoreKey], newKeys[contractmanagermoduletypes.StoreKey], [][]byte{}},
{keys[interchainqueriestypes.StoreKey], newKeys[interchainqueriestypes.StoreKey], [][]byte{}},
{keys[icacontrollertypes.StoreKey], newKeys[icacontrollertypes.StoreKey], [][]byte{}},
{keys[wasm.StoreKey], newKeys[wasm.StoreKey], [][]byte{wasmtypes.TXCounterPrefix}},
{keys[wasmtypes.StoreKey], newKeys[wasmtypes.StoreKey], [][]byte{wasmtypes.TXCounterPrefix}},
}

// diff both stores
Expand Down
4 changes: 1 addition & 3 deletions app/upgrades/v05/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"github.com/Nolus-Protocol/nolus-core/app/upgrades"

store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/x/authz"
consensusparamstypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v1.0.0"
UpgradeName = "v0.5.0"
)

var Upgrade = upgrades.Upgrade{
Expand All @@ -21,7 +20,6 @@ var Upgrade = upgrades.Upgrade{
Added: []string{
consensusparamstypes.ModuleName,
crisistypes.ModuleName,
authz.ModuleName,
},
},
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ replace (
// fixes build problem: "cometbft/cometbft/crypto/sr25519/pubkey.go:58:9: too many return values"
github.com/ChainSafe/go-schnorrkel => github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d

github.com/CosmWasm/wasmd => github.com/neutron-org/wasmd v0.40.0-rc.0.0.20230705143547-22c391d461d5
github.com/CosmWasm/wasmd => github.com/neutron-org/wasmd v0.45.0

// TODO: Simapp dependency, review removing when updating to SDK with backported update https://github.com/cosmos/cosmos-sdk/issues/13423
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 // indirect
github.com/cosmos/admin-module => github.com/neutron-org/admin-module v0.0.0-20230705134325-b23404470a1d
github.com/cosmos/admin-module => github.com/neutron-org/admin-module v1.0.0

// neutron dependency
github.com/cosmos/gaia/v11 => github.com/cosmos/gaia/v11 v11.0.0-20230724152830-861ba391c3b4
Expand All @@ -217,7 +217,7 @@ replace (

// For more info https://github.com/CosmWasm/wasmd/blob/d63bea442bedf5b3055f3821472c7e6cafc3d813/go.mod#L131
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

github.com/neutron-org/neutron => github.com/nolus-protocol/neutron v1.0.5-0.20231205124747-52e7b36b5527
// TODO: REMOVE THIS, its used for testing
// github.com/neutron-org/neutron => /home/denislavivanov/go/github/neutron

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,13 @@ github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/neilotoole/errgroup v0.1.6/go.mod h1:Q2nLGf+594h0CLBs/Mbg6qOr7GtqDK7C2S41udRnToE=
github.com/neutron-org/admin-module v0.0.0-20230705134325-b23404470a1d h1:oexw79znoA0TEo7CGdWHrolbvZqCDD3aI+031CbOq9Y=
github.com/neutron-org/admin-module v0.0.0-20230705134325-b23404470a1d/go.mod h1:QuxQ7FJlEAFMRssyEYOrR9ORnYQvBFMTlO8BXny6ntw=
github.com/neutron-org/neutron v1.0.5-0.20231128122544-e605ed3db438 h1:/wGpk7i/+42JsoTQTbGBD058VXV56fI/BIrGDzCEFEs=
github.com/neutron-org/neutron v1.0.5-0.20231128122544-e605ed3db438/go.mod h1:/7wnWxAbDz0XPPnYcQGiq09qeVk8VfbOPLxa1SZH254=
github.com/neutron-org/wasmd v0.40.0-rc.0.0.20230705143547-22c391d461d5 h1:2YQaqP5W3F+5VH0IAA7m8OHjkwONxQDqXUwo5tzKdDU=
github.com/neutron-org/wasmd v0.40.0-rc.0.0.20230705143547-22c391d461d5/go.mod h1:l699csQZeRKYqF8R9JoYoQ6E0j4PfDM3Ln7EawtUwJE=
github.com/neutron-org/admin-module v1.0.0 h1:mmX5U6jz4rX+lk8SB5Bx0Lsugu9bh4PCREMnVkLQoIs=
github.com/neutron-org/admin-module v1.0.0/go.mod h1:INknneN2W3Fr9Eld7SpfLRdjyHR1muzFbbqXln1ixic=
github.com/neutron-org/wasmd v0.45.0 h1:K3WpYYTP9Msd7cLtdIau8VBUW1n1CC1qC/yaKPCYJsQ=
github.com/neutron-org/wasmd v0.45.0/go.mod h1:k2/B7hBKbCEHhhOSaiv7UBHUR2fLVb003pnswasgG/w=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nolus-protocol/neutron v1.0.5-0.20231205124747-52e7b36b5527 h1:z/8MyZJQ8ttuCBsA2QQPxC+7kNbV06z5kw4dm09LEEY=
github.com/nolus-protocol/neutron v1.0.5-0.20231205124747-52e7b36b5527/go.mod h1:/7wnWxAbDz0XPPnYcQGiq09qeVk8VfbOPLxa1SZH254=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
8 changes: 8 additions & 0 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func (m *CustomMessenger) performRegisterInterchainAccount(ctx sdk.Context, cont
FromAddress: contractAddr.String(),
ConnectionId: reg.ConnectionId,
InterchainAccountId: reg.InterchainAccountId,
RegisterFee: getRegisterFee(reg.RegisterFee),
}
if err := msg.ValidateBasic(); err != nil {
return nil, errors.Wrap(err, "failed to validate incoming RegisterInterchainAccount message")
Expand Down Expand Up @@ -414,3 +415,10 @@ func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccA

return nil, [][]byte{data}, nil
}

func getRegisterFee(fee sdk.Coins) sdk.Coins {
if fee == nil {
return make(sdk.Coins, 0)
}
return fee
}
5 changes: 5 additions & 0 deletions wasmbinding/test/custom_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (suite *CustomMessengerTestSuite) TestRegisterInterchainAccount() {
})
suite.NoError(err)

bankKeeper := suite.neutron.BankKeeper
senderAddress := suite.ChainA.SenderAccounts[0].SenderAccount.GetAddress()
err = bankKeeper.SendCoins(suite.ctx, senderAddress, suite.contractAddress, sdk.NewCoins(sdk.NewCoin(params.DefaultDenom, sdk.NewInt(1_000_000))))
suite.NoError(err)

// Dispatch RegisterInterchainAccount message
events, data, err := suite.messenger.DispatchMsg(suite.ctx, suite.contractAddress, suite.Path.EndpointA.ChannelConfig.PortID, types.CosmosMsg{
Custom: msg,
Expand Down
3 changes: 1 addition & 2 deletions wasmbinding/wasm.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wasmbinding

import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

contractmanagerkeeper "github.com/neutron-org/neutron/x/contractmanager/keeper"
Expand All @@ -28,7 +27,7 @@ func RegisterCustomPlugins(
CustomMessageDecorator(ictxKeeper, icqKeeper, transfer, contractmanagerKeeper),
)

return []wasm.Option{
return []wasmkeeper.Option{
queryPluginOpt,
messageHandlerDecoratorOpt,
}
Expand Down

0 comments on commit 85d1a19

Please sign in to comment.