Skip to content

Commit

Permalink
enable oracle module in app, and set default params to a future block
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Apr 25, 2024
1 parent 8cc8f75 commit ecf9145
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
15 changes: 14 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
avsTaskKeeper "github.com/ExocoreNetwork/exocore/x/avstask/keeper"
avsTaskTypes "github.com/ExocoreNetwork/exocore/x/avstask/types"

"github.com/ExocoreNetwork/exocore/x/oracle"
oracleKeeper "github.com/ExocoreNetwork/exocore/x/oracle/keeper"
oracleTypes "github.com/ExocoreNetwork/exocore/x/oracle/types"

"github.com/ExocoreNetwork/exocore/x/avs"
"github.com/ExocoreNetwork/exocore/x/operator"
operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper"
Expand Down Expand Up @@ -279,6 +283,7 @@ var (
exoslash.AppModuleBasic{},
avs.AppModuleBasic{},
avstask.AppModuleBasic{},
oracle.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -364,6 +369,7 @@ type ExocoreApp struct {
ExoSlashKeeper slashKeeper.Keeper
AVSManagerKeeper avsManagerKeeper.Keeper
TaskKeeper avsTaskKeeper.Keeper
OracleKeeper oracleKeeper.Keeper

// the module manager
mm *module.Manager
Expand Down Expand Up @@ -449,10 +455,11 @@ func NewExocoreApp(
operatorTypes.StoreKey,
avsManagerTypes.StoreKey,
avsTaskTypes.StoreKey,
oracleTypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, oracleTypes.MemStoreKey)

// load state streaming if enabled
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil {
Expand Down Expand Up @@ -662,6 +669,7 @@ func NewExocoreApp(
app.ExoSlashKeeper = slashKeeper.NewKeeper(appCodec, keys[exoslashTypes.StoreKey], app.AssetsKeeper)
app.AVSManagerKeeper = *avsManagerKeeper.NewKeeper(appCodec, keys[avsManagerTypes.StoreKey], &app.OperatorKeeper, app.AssetsKeeper)
app.TaskKeeper = avsTaskKeeper.NewKeeper(appCodec, keys[avsTaskTypes.StoreKey], app.AVSManagerKeeper)
app.OracleKeeper = oracleKeeper.NewKeeper(appCodec, keys[oracleTypes.StoreKey], memKeys[oracleTypes.MemStoreKey], app.GetSubspace(oracleTypes.ModuleName), app.StakingKeeper)
// We call this after setting the hooks to ensure that the hooks are set on the keeper
evmKeeper.WithPrecompiles(
evmkeeper.AvailablePrecompiles(
Expand Down Expand Up @@ -851,6 +859,7 @@ func NewExocoreApp(
exoslash.NewAppModule(appCodec, app.ExoSlashKeeper),
avs.NewAppModule(appCodec, app.AVSManagerKeeper),
avstask.NewAppModule(appCodec, app.TaskKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after reward.BeginBlocker so that
Expand Down Expand Up @@ -896,6 +905,7 @@ func NewExocoreApp(
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
avsTaskTypes.ModuleName,
oracleTypes.ModuleName,
)

// NOTE: fee market module must go last in order to retrieve the block gas used.
Expand Down Expand Up @@ -936,6 +946,7 @@ func NewExocoreApp(
exoslashTypes.ModuleName,
avsManagerTypes.ModuleName,
avsTaskTypes.ModuleName,
oracleTypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -974,6 +985,7 @@ func NewExocoreApp(
rewardTypes.ModuleName,
exoslashTypes.ModuleName,
// no particular order required
oracleTypes.ModuleName,
// Evmos modules
erc20types.ModuleName,
epochstypes.ModuleName,
Expand Down Expand Up @@ -1336,6 +1348,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(icahosttypes.SubModuleName)
// ethermint subspaces
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(oracleTypes.ModuleName).WithKeyTable(oracleTypes.ParamKeyTable())
return paramsKeeper
}

Expand Down
5 changes: 4 additions & 1 deletion testutil/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func OracleKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())

// Initialize params
k.SetParams(ctx, types.DefaultParams())
p4Test := types.DefaultParams()
p4Test.TokenFeeders[1].StartBaseBlock = 1
//k.SetParams(ctx, types.DefaultParams())

Check failure on line 53 in testutil/keeper/oracle.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
k.SetParams(ctx, p4Test)

return &k, ctx
}
7 changes: 7 additions & 0 deletions testutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"golang.org/x/exp/rand"

testutiltx "github.com/ExocoreNetwork/exocore/testutil/tx"
oracletypes "github.com/ExocoreNetwork/exocore/x/oracle/types"

exocoreapp "github.com/ExocoreNetwork/exocore/app"
"github.com/ExocoreNetwork/exocore/utils"
Expand Down Expand Up @@ -84,6 +85,12 @@ func (suite *BaseTestSuite) SetupWithGenesisValSet(valSet *tmtypes.ValidatorSet,
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

oracleDefaultParams := oracletypes.DefaultParams()
oracleDefaultParams.TokenFeeders[1].StartBaseBlock = 1
oracleGenesis := oracletypes.NewGenesisState(oracleDefaultParams)

genesisState[oracletypes.ModuleName] = app.AppCodec().MustMarshalJSON(oracleGenesis)

// set genesis staking assets
ethClientChain := assetstypes.ClientChainInfo{
Name: "ethereum",
Expand Down
4 changes: 3 additions & 1 deletion x/oracle/keeper/msg_server_create_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ var _ = Describe("MsgCreatePrice", func() {
c = keeper.GetCaches()
pRes := &common.Params{}
c.GetCache(cache.ItemP(pRes))
Expect(*pRes).Should(BeEquivalentTo(types.DefaultParams()))
p4Test := types.DefaultParams()
p4Test.TokenFeeders[1].StartBaseBlock = 1
Expect(*pRes).Should(BeEquivalentTo(p4Test))
})

It("success on 3rd message", func() {
Expand Down
12 changes: 12 additions & 0 deletions x/oracle/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ func DefaultGenesis() *GenesisState {
}
}

func NewGenesisState(p Params) *GenesisState {
return &GenesisState{
PricesList: []Prices{},
ValidatorUpdateBlock: nil,
IndexRecentParams: nil,
IndexRecentMsg: nil,
RecentMsgList: []RecentMsg{},
RecentParamsList: []RecentParams{},
Params: p,
}
}

// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
Expand Down
16 changes: 1 addition & 15 deletions x/oracle/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func DefaultParams() Params {
Decimal: 18,
Active: true,
},
{
Name: "SHIBA INU",
ChainID: 1,
ContractAddress: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
Decimal: 18,
Active: true,
},
},
Sources: []*Source{
{
Expand Down Expand Up @@ -76,14 +69,7 @@ func DefaultParams() Params {
TokenID: 1,
RuleID: 1,
StartRoundID: 1,
StartBaseBlock: 1,
Interval: 10,
},
{
TokenID: 2,
RuleID: 1,
StartRoundID: 1,
StartBaseBlock: 5,
StartBaseBlock: 100000000,
Interval: 10,
},
},
Expand Down

0 comments on commit ecf9145

Please sign in to comment.