Skip to content

Commit

Permalink
fix: get simulations working
Browse files Browse the repository at this point in the history
  • Loading branch information
johnletey committed Oct 12, 2023
1 parent f8d7233 commit 148d7d0
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 48 deletions.
73 changes: 31 additions & 42 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ import (
cctp "github.com/circlefin/noble-cctp/x/cctp"
cctpkeeper "github.com/circlefin/noble-cctp/x/cctp/keeper"
cctptypes "github.com/circlefin/noble-cctp/x/cctp/types"
router "github.com/strangelove-ventures/noble-router/x/router"
routerkeeper "github.com/strangelove-ventures/noble-router/x/router/keeper"
routertypes "github.com/strangelove-ventures/noble-router/x/router/types"
)

const (
Expand Down Expand Up @@ -156,7 +153,7 @@ var (
globalfee.AppModuleBasic{},
tariff.AppModuleBasic{},
cctp.AppModuleBasic{},
router.AppModuleBasic{},
//router.AppModuleBasic{},
paramauthorityibc.AppModuleBasic{},
)

Expand Down Expand Up @@ -234,7 +231,7 @@ type App struct {
FiatTokenFactoryKeeper *fiattokenfactorymodulekeeper.Keeper
TariffKeeper tariffkeeper.Keeper
CCTPKeeper *cctpkeeper.Keeper
RouterKeeper *routerkeeper.Keeper
//RouterKeeper *routerkeeper.Keeper

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

Expand Down Expand Up @@ -273,7 +270,7 @@ func New(
paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey,
ibctransfertypes.StoreKey, icahosttypes.StoreKey, capabilitytypes.StoreKey,
tokenfactorymoduletypes.StoreKey, fiattokenfactorymoduletypes.StoreKey, packetforwardtypes.StoreKey, stakingtypes.StoreKey,
cctptypes.StoreKey, routertypes.StoreKey,
cctptypes.StoreKey, // routertypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -385,7 +382,9 @@ func New(

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *app.StakingKeeper.SetHooks(app.SlashingKeeper.Hooks())
app.StakingKeeper = *app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

// ... other modules keepers

Expand Down Expand Up @@ -474,24 +473,24 @@ func New(
)
fiattokenfactorymodule := fiattokenfactorymodule.NewAppModule(appCodec, app.FiatTokenFactoryKeeper, app.AccountKeeper, app.BankKeeper)

app.RouterKeeper = routerkeeper.NewKeeper(
appCodec,
keys[routertypes.StoreKey],
app.GetSubspace(routertypes.ModuleName),
app.CCTPKeeper,
app.TransferKeeper,
)
//app.RouterKeeper = routerkeeper.NewKeeper(
// appCodec,
// keys[routertypes.StoreKey],
// app.GetSubspace(routertypes.ModuleName),
// app.CCTPKeeper,
// app.TransferKeeper,
//)

app.CCTPKeeper = cctpkeeper.NewKeeper(
appCodec,
keys[cctptypes.StoreKey],
app.GetSubspace(cctptypes.ModuleName),
app.BankKeeper,
app.FiatTokenFactoryKeeper,
app.RouterKeeper,
nil,
)

app.RouterKeeper.SetCctpKeeper(app.CCTPKeeper)
//app.RouterKeeper.SetCctpKeeper(app.CCTPKeeper)

var transferStack ibcporttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
Expand All @@ -502,8 +501,8 @@ func New(
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
transferStack = router.NewIBCMiddleware(transferStack, app.RouterKeeper)
transferStack = blockibc.NewIBCMiddleware(transferStack, app.TokenFactoryKeeper, app.FiatTokenFactoryKeeper)
//transferStack = router.NewIBCMiddleware(transferStack, app.RouterKeeper)
transferStack = blockibc.NewIBCMiddleware(transferStack, nil, app.FiatTokenFactoryKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
Expand Down Expand Up @@ -534,7 +533,7 @@ func New(
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, &app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
paramauthorityupgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
Expand All @@ -548,8 +547,8 @@ func New(
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)),
tariff.NewAppModule(appCodec, app.TariffKeeper, app.AccountKeeper, app.BankKeeper),
cctp.NewAppModule(appCodec, app.CCTPKeeper),
router.NewAppModule(appCodec, app.RouterKeeper),
cctp.NewAppModule(appCodec, app.AccountKeeper, app.CCTPKeeper),
//router.NewAppModule(appCodec, app.RouterKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -581,7 +580,7 @@ func New(
fiattokenfactorymoduletypes.ModuleName,
globalfee.ModuleName,
cctptypes.ModuleName,
routertypes.ModuleName,
//routertypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -608,7 +607,7 @@ func New(
globalfee.ModuleName,
tarifftypes.ModuleName,
cctptypes.ModuleName,
routertypes.ModuleName,
//routertypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -617,11 +616,11 @@ func New(
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.mm.SetOrderInitGenesis(
stakingtypes.ModuleName,
capabilitytypes.ModuleName,
ibctransfertypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
stakingtypes.ModuleName,
tarifftypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
Expand All @@ -640,7 +639,7 @@ func New(
fiattokenfactorymoduletypes.ModuleName,
globalfee.ModuleName,
cctptypes.ModuleName,
routertypes.ModuleName,
//routertypes.ModuleName,

// this line is used by starport scaffolding # stargate/app/initGenesis
)
Expand All @@ -661,21 +660,11 @@ func New(
)

// create the simulation manager and define the order of the modules for deterministic simulations
app.sm = module.NewSimulationManager(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, &app.StakingKeeper),
paramauthority.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
transferModule,
tokenfactoryModule,
fiattokenfactorymodule,
)
overrideModules := map[string]module.AppModuleSimulation{
authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
}
app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules)

app.sm.RegisterStoreDecoders()

// initialize stores
Expand Down Expand Up @@ -881,7 +870,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(upgradetypes.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(cctptypes.ModuleName)
paramsKeeper.Subspace(routertypes.ModuleName)
//paramsKeeper.Subspace(routertypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down Expand Up @@ -925,7 +914,7 @@ func (app *App) setupUpgradeHandlers() {
app.FiatTokenFactoryKeeper,
app.ParamsKeeper,
app.CCTPKeeper,
app.RouterKeeper,
nil,
),
)

Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,16 @@ require (
)

replace (
github.com/circlefin/noble-cctp => github.com/noble-assets/cctp v0.0.0-20231011123114-2d9a649f0036

// huckleberry patch for ibc-go v3
github.com/cosmos/ibc-go/v3 => github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry

// use cosmos-flavored protocol buffers
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

github.com/strangelove-ventures/paramauthority => github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0

// cometbft
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/circlefin/noble-cctp v0.0.0-20230925203250-4d2482bd0d7c h1:RwSIc6O1bcBkfpOMrBF08xpctcwkVDxAQCIRlOHyg0U=
github.com/circlefin/noble-cctp v0.0.0-20230925203250-4d2482bd0d7c/go.mod h1:kTaX51dOT10LBoERZYT1ahuove3dL/+q5IagWQUABd0=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
Expand Down Expand Up @@ -765,8 +763,12 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi
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/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/noble-assets/cctp v0.0.0-20231011123114-2d9a649f0036 h1:Ang5ySxQFPVr89NPGcTAWKKU9jk6Q053/lhkiuBks+4=
github.com/noble-assets/cctp v0.0.0-20231011123114-2d9a649f0036/go.mod h1:kTaX51dOT10LBoERZYT1ahuove3dL/+q5IagWQUABd0=
github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry h1:02oo/GHLGITexbPNUO/jmYa67xE+B5BvNv/i+wufdHI=
github.com/noble-assets/ibc-go/v3 v3.4.0-huckleberry/go.mod h1:VwB/vWu4ysT5DN2aF78d17LYmx3omSAdq6gpKvM7XRA=
github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0 h1:+D+62FTPcn63gaFuI8FDeOl5lAUw2b5NvrMfMxOMGiA=
github.com/noble-assets/paramauthority v0.0.0-20231012123800-75b3a76f31c0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
Expand Down Expand Up @@ -954,8 +956,6 @@ github.com/strangelove-ventures/noble-router v1.0.0 h1:YvBivqz/qpXLom8MpghbjYoRC
github.com/strangelove-ventures/noble-router v1.0.0/go.mod h1:zYp/EROBOZh//YJiAVTeiWEmjwsSWdp0iGvksSI93YY=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.5 h1:iXXjziCSAebzuRUPFSnqD7epSDB8LEPgkh9zhbj7ha4=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.5/go.mod h1:ncgsf5rykh36HkM16BNcKKx1XzVRdWXt+4pph1syDHE=
github.com/strangelove-ventures/paramauthority v1.0.0 h1:kgWsSfkiBh25ZZyt/ZQUwXEVdFknX9YIdEWDm1X7AWg=
github.com/strangelove-ventures/paramauthority v1.0.0/go.mod h1:31HVpoItQMa4Wj2BimVhQWbIYeb+kdUDJ8MzBEbGj28=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
30 changes: 29 additions & 1 deletion x/fiattokenfactory/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/strangelove-ventures/noble/testutil/sample"
tokenfactorysimulation "github.com/strangelove-ventures/noble/x/fiattokenfactory/simulation"
Expand Down Expand Up @@ -90,10 +91,37 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs[i] = acc.Address.String()
}
tokenfactoryGenesis := types.GenesisState{
Params: types.DefaultParams(),
Params: types.DefaultParams(),
MintingDenom: &types.MintingDenom{Denom: "uusdc"},
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis)

bankGenesisBz := simState.GenState[bankTypes.ModuleName]
var bankGenesis bankTypes.GenesisState
simState.Cdc.MustUnmarshalJSON(bankGenesisBz, &bankGenesis)

bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, bankTypes.Metadata{
Description: "USD Coin",
DenomUnits: []*bankTypes.DenomUnit{
{
Denom: "uusdc",
Exponent: 0,
Aliases: []string{"microusdc"},
},
{
Denom: "usdc",
Exponent: 6,
Aliases: []string{},
},
},
Base: "uusdc",
Display: "usdc",
Name: "usdc",
Symbol: "USDC",
})

simState.GenState[bankTypes.ModuleName] = simState.Cdc.MustMarshalJSON(&bankGenesis)
}

// ProposalContents doesn't return any content functions for governance proposals
Expand Down
30 changes: 30 additions & 0 deletions x/tariff/module_simulation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tariff

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/strangelove-ventures/noble/x/tariff/types"
"math/rand"
)

var _ module.AppModuleSimulation = AppModule{}

func (am AppModule) GenerateGenesisState(simState *module.SimulationState) {
genesis := types.DefaultGenesis()
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(genesis)
}

func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

func (am AppModule) RandomizedParams(_ *rand.Rand) []simtypes.ParamChange {
return nil
}

func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {}

func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
return nil
}
35 changes: 34 additions & 1 deletion x/tokenfactory/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/strangelove-ventures/noble/testutil/sample"
tokenfactorysimulation "github.com/strangelove-ventures/noble/x/tokenfactory/simulation"
Expand Down Expand Up @@ -90,10 +91,42 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs[i] = acc.Address.String()
}
tokenfactoryGenesis := types.GenesisState{
Params: types.DefaultParams(),
Params: types.DefaultParams(),
MintingDenom: &types.MintingDenom{Denom: "ufrienzies"},
// this line is used by starport scaffolding # simapp/module/genesisState
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis)

bankGenesisBz := simState.GenState[bankTypes.ModuleName]
var bankGenesis bankTypes.GenesisState
simState.Cdc.MustUnmarshalJSON(bankGenesisBz, &bankGenesis)

bankGenesis.DenomMetadata = append(bankGenesis.DenomMetadata, bankTypes.Metadata{
Description: "Frienzies are an IBC token redeemable exclusively for a physical asset issued by the Noble entity.",
DenomUnits: []*bankTypes.DenomUnit{
{
Denom: "ufrienzies",
Exponent: 0,
Aliases: []string{"microfrienzies"},
},
{
Denom: "mfrienzies",
Exponent: 3,
Aliases: []string{"millifrienzies"},
},
{
Denom: "frienzies",
Exponent: 6,
Aliases: []string{},
},
},
Base: "ufrienzies",
Display: "frienzies",
Name: "frienzies",
Symbol: "FRNZ",
})

simState.GenState[bankTypes.ModuleName] = simState.Cdc.MustMarshalJSON(&bankGenesis)
}

// ProposalContents doesn't return any content functions for governance proposals
Expand Down

0 comments on commit 148d7d0

Please sign in to comment.