diff --git a/README.md b/README.md index d28f856e..255e6fa7 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ $ make install Example command structure for running a node with a price feeder config file located at `./price-feeder.example.config` (See [price-feeder](https://github.com/ojo-network/price-feeder) repo for more information on configuring an Ojo price feeder) ```shell -$ ojod start --pricefeeder.config_path=./price-feeder.example.config --pricefeeder.log_level="INFO" --pricefeeder.chain_config=TRUE --pricefeeder.oracle_tick_time=5s +$ ojod start --pricefeeder.config_path=./price-feeder.example.config --pricefeeder.log_level="INFO" ``` ## Networks diff --git a/app/app.go b/app/app.go index 3c874d10..a8935ed0 100644 --- a/app/app.go +++ b/app/app.go @@ -121,7 +121,6 @@ import ( airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper" airdroptypes "github.com/ojo-network/ojo/x/airdrop/types" - "github.com/ojo-network/ojo/pricefeeder" oracleabci "github.com/ojo-network/ojo/x/oracle/abci" customante "github.com/ojo-network/ojo/ante" @@ -221,8 +220,6 @@ type App struct { // module configurator configurator module.Configurator - - PriceFeeder *pricefeeder.PriceFeeder } // New returns a reference to an initialized blockchain app @@ -738,12 +735,9 @@ func New( app.SetPrepareProposal(proposalHandler.PrepareProposalHandler()) app.SetProcessProposal(proposalHandler.ProcessProposalHandler()) - // initialize empty price feeder object to pass reference into vote extension handler - app.PriceFeeder = &pricefeeder.PriceFeeder{} voteExtensionsHandler := oracleabci.NewVoteExtensionHandler( app.Logger(), app.OracleKeeper, - app.PriceFeeder, ) app.SetExtendVoteHandler(voteExtensionsHandler.ExtendVoteHandler()) app.SetVerifyVoteExtensionHandler(voteExtensionsHandler.VerifyVoteExtensionHandler()) diff --git a/app/upgrades.go b/app/upgrades.go index 0d8a2f2a..22c431e6 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -46,6 +46,7 @@ func (app App) RegisterUpgradeHandlers() { app.registerUpgrade0_3_1(upgradeInfo) app.registerUpgrade0_3_2(upgradeInfo) app.registerUpgrade0_4_0(upgradeInfo) + app.registerUpgrade0_4_1(upgradeInfo) } // performs upgrade from v0.1.3 to v0.1.4 @@ -284,6 +285,18 @@ func (app *App) registerUpgrade0_4_0(upgradeInfo upgradetypes.Plan) { }) } +func (app *App) registerUpgrade0_4_1(_ upgradetypes.Plan) { + const planName = "v0.4.1" + + app.UpgradeKeeper.SetUpgradeHandler(planName, + func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + sdkCtx.Logger().Info("Upgrade handler execution", "name", planName) + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) +} + // helper function to check if the store loader should be upgraded func (app *App) storeUpgrade(planName string, ui upgradetypes.Plan, stores storetypes.StoreUpgrades) { if ui.Name == planName && !app.UpgradeKeeper.IsSkipHeight(ui.Height) { diff --git a/cmd/ojod/cmd/commands.go b/cmd/ojod/cmd/commands.go index 2478b3c5..1688d6ed 100644 --- a/cmd/ojod/cmd/commands.go +++ b/cmd/ojod/cmd/commands.go @@ -4,7 +4,6 @@ import ( "errors" "io" "os" - "time" "cosmossdk.io/log" "cosmossdk.io/tools/confix/cmd" @@ -32,7 +31,6 @@ import ( app "github.com/ojo-network/ojo/app" "github.com/ojo-network/ojo/pricefeeder" - oracletypes "github.com/ojo-network/ojo/x/oracle/types" ) // initCometBFTConfig helps to override default CometBFT Config values. @@ -71,10 +69,8 @@ func initAppConfig() (string, interface{}) { QueryGasLimit: 300000, }, PriceFeeder: pricefeeder.AppConfig{ - ConfigPath: "", - ChainConfig: true, - LogLevel: "info", - OracleTickTime: time.Second * 5, + ConfigPath: "", + LogLevel: "info", }, } @@ -131,17 +127,7 @@ func initRootCmd( // add price feeder flags rootCmd.PersistentFlags().String(pricefeeder.FlagConfigPath, "", "Path to price feeder config file") - rootCmd.PersistentFlags().Bool( - pricefeeder.FlagChainConfig, - true, - "Specifies whether the currency pair providers and currency deviation threshold values should", - ) rootCmd.PersistentFlags().String(pricefeeder.FlagLogLevel, "", "Log level of price feeder process") - rootCmd.PersistentFlags().Duration( - pricefeeder.FlagOracleTickTime, - time.Second*5, - "Time interval that the price feeder's oracle process waits before fetching for new prices", - ) } // genesisCommand builds genesis-related `simd genesis` command. Users may @@ -226,20 +212,12 @@ func newApp( baseappOptions..., ) - // start price feeder + // load app config into oracle keeper price feeder appConfig, err := pricefeeder.ReadConfigFromAppOpts(appOpts) if err != nil { panic(err) } - - var oracleGenState oracletypes.GenesisState - app.AppCodec().MustUnmarshalJSON(app.DefaultGenesis()[oracletypes.ModuleName], &oracleGenState) - go func() { - err := app.PriceFeeder.Start(oracleGenState.Params, appConfig) - if err != nil { - panic(err) - } - }() + app.OracleKeeper.PriceFeeder.AppConfig = appConfig return app } diff --git a/go.mod b/go.mod index 78636c3b..d41dd9bf 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 github.com/mgechev/revive v1.3.9 github.com/mitchellh/mapstructure v1.5.0 - github.com/ojo-network/price-feeder v0.2.0 + github.com/ojo-network/price-feeder v0.2.1-rc1 github.com/ory/dockertest/v3 v3.10.0 github.com/rs/zerolog v1.32.0 github.com/spf13/cast v1.6.0 diff --git a/go.sum b/go.sum index 958ca19b..572337a0 100644 --- a/go.sum +++ b/go.sum @@ -1122,8 +1122,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= -github.com/ojo-network/price-feeder v0.2.0 h1:1D+0K19xUlmEPUxAeyG0W+CWjBvSOSdwoMYcQ2+u9dM= -github.com/ojo-network/price-feeder v0.2.0/go.mod h1:2xHrCcUMPoozsvst9785vToD7/U05OOAAl0NvnMYaTg= +github.com/ojo-network/price-feeder v0.2.1-rc1 h1:m9vgR9DYuXhM5f2DQX/wewihzkPVAVdVjZgtr/gB6bs= +github.com/ojo-network/price-feeder v0.2.1-rc1/go.mod h1:CSdgh7XiOMLGQwRW8OqbL5FlkE5Mc3+fDZEMRN8JkYY= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= diff --git a/pricefeeder/config.go b/pricefeeder/config.go index e9b0ac72..f549f0b0 100644 --- a/pricefeeder/config.go +++ b/pricefeeder/config.go @@ -2,7 +2,6 @@ package pricefeeder import ( "fmt" - "time" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/spf13/cast" @@ -14,30 +13,20 @@ const ( # Path to price feeder config file. config_path = "" -# Specifies whether to use the on chain price feeder provider pair and deviation threshold values or the config file. -chain_config = true - # Log level of price feeder process. log_level = "info" - -# Time interval that the price feeder's oracle process waits before fetching for new prices. -oracle_tick_time = "5s" ` ) const ( - FlagConfigPath = "pricefeeder.config_path" - FlagChainConfig = "pricefeeder.chain_config" - FlagLogLevel = "pricefeeder.log_level" - FlagOracleTickTime = "pricefeeder.oracle_tick_time" + FlagConfigPath = "pricefeeder.config_path" + FlagLogLevel = "pricefeeder.log_level" ) // AppConfig defines the app configuration for the price feeder that must be set in the app.toml file. type AppConfig struct { - ConfigPath string `mapstructure:"config_path"` - ChainConfig bool `mapstructure:"chain_config"` - LogLevel string `mapstructure:"log_level"` - OracleTickTime time.Duration `mapstructure:"oracle_tick_time"` + ConfigPath string `mapstructure:"config_path"` + LogLevel string `mapstructure:"log_level"` } // ValidateBasic performs basic validation of the price feeder app config. @@ -46,10 +35,6 @@ func (c *AppConfig) ValidateBasic() error { return fmt.Errorf("path to price feeder config must be set") } - if c.OracleTickTime <= 0 { - return fmt.Errorf("oracle tick time must be greater than 0") - } - return nil } @@ -66,24 +51,12 @@ func ReadConfigFromAppOpts(opts servertypes.AppOptions) (AppConfig, error) { } } - if v := opts.Get(FlagChainConfig); v != nil { - if cfg.ChainConfig, err = cast.ToBoolE(v); err != nil { - return cfg, err - } - } - if v := opts.Get(FlagLogLevel); v != nil { if cfg.LogLevel, err = cast.ToStringE(v); err != nil { return cfg, err } } - if v := opts.Get(FlagOracleTickTime); v != nil { - if cfg.OracleTickTime, err = cast.ToDurationE(v); err != nil { - return cfg, err - } - } - if err := cfg.ValidateBasic(); err != nil { return cfg, err } diff --git a/pricefeeder/price-feeder.example.toml b/pricefeeder/price-feeder.example.toml index 6b2607a3..df086fe9 100644 --- a/pricefeeder/price-feeder.example.toml +++ b/pricefeeder/price-feeder.example.toml @@ -1,311 +1,6 @@ gas_adjustment = 1 provider_timeout = "1000000s" -[[deviation_thresholds]] -base = "USDT" -threshold = "1.5" - -[[deviation_thresholds]] -base = "USDC" -threshold = "1.5" - -[[deviation_thresholds]] -base = "ATOM" -threshold = "1.5" - -[[deviation_thresholds]] -base = "USDC" -threshold = "1.5" - -[[deviation_thresholds]] -base = "ETH" -threshold = "2" - -[[deviation_thresholds]] -base = "BTC" -threshold = "2" - -[[deviation_thresholds]] -base = "OSMO" -threshold = "2" - -[[deviation_thresholds]] -base = "DAI" -threshold = "2" - -[[deviation_thresholds]] -base = "stOSMO" -threshold = "2" - -[[deviation_thresholds]] -base = "stATOM" -threshold = "2" - -[[deviation_thresholds]] -base = "stJUNO" -threshold = "2" - -[[deviation_thresholds]] -base = "JUNO" -threshold = "2" - -[[deviation_thresholds]] -base = "SCRT" -threshold = "2" - -[[deviation_thresholds]] -base = "WETH" -threshold = "2" - -[[deviation_thresholds]] -base = "WBTC" -threshold = "2" - -[[deviation_thresholds]] -base = "CBETH" -threshold = "2" - -[[deviation_thresholds]] -base = "LINK" -threshold = "2" - -[[deviation_thresholds]] -base = "RETH" -threshold = "2" - -[[currency_pairs]] -base = "USDT" -providers = [ - "kraken", - "coinbase", - "crypto", -] -quote = "USD" - -[[currency_pairs]] -base = "USDC" -providers = [ - "okx", - "bitget", - "kraken", -] -quote = "USDT" - - -[[currency_pairs]] -base = "USDC" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "USDC" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "ATOM" -providers = [ - "okx", - "bitget", - "gate", -] -quote = "USDT" - -[[currency_pairs]] -base = "ATOM" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "ETH" -providers = [ - "okx", - "bitget", -] -quote = "USDT" - -[[currency_pairs]] -base = "ETH" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "BTC" -providers = [ - "okx", - "gate", - "bitget", -] -quote = "USDT" - -[[currency_pairs]] -base = "BTC" -providers = [ - "coinbase", -] -quote = "USD" - -[[currency_pairs]] -base = "OSMO" -providers = [ - "bitget", - "gate", - "huobi", -] -quote = "USDT" - -[[currency_pairs]] -base = "OSMO" -providers = [ - "osmosis", -] -quote = "ATOM" - -[[currency_pairs]] -base = "WETH" -providers = [ - "eth-uniswap" -] -quote = "USDC" - -[[currency_pairs]] -base = "WBTC" -providers = [ - "eth-uniswap" -] -quote = "WETH" - -[[currency_pairs]] -base = "CBETH" -providers = [ - "eth-uniswap" -] -quote = "WETH" - -[[currency_pairs]] -base = "LINK" -providers = [ - "eth-uniswap" -] -quote = "WETH" - -[[currency_pairs]] -base = "RETH" -providers = [ - "eth-uniswap", -] -quote = "WETH" - -[[currency_pairs]] -base = "SFRXETH" -providers = [ - "eth-uniswap", -] -quote = "WETH" - -[[currency_pairs]] -base = "WSTETH" -providers = [ - "eth-uniswap", -] -quote = "WETH" - -[[currency_pairs]] -base = "stATOM" -providers = [ - "osmosis", -] -quote = "ATOM" - -[[currency_pairs]] -base = "stOSMO" -providers = [ - "osmosis", -] -quote = "OSMO" - -[[currency_pairs]] -base = "DAI" -providers = [ - "okx", - "bitget", - "huobi", -] -quote = "USDT" - -[[currency_pairs]] -base = "DAI" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "JUNO" -providers = [ - "mexc", -] -quote = "USDT" - -[[currency_pairs]] -base = "JUNO" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "JUNO" -providers = [ - "osmosis", -] -quote = "ATOM" - -[[currency_pairs]] -base = "stJUNO" -providers = [ - "osmosis", -] -quote = "JUNO" - -[[currency_pairs]] -base = "SCRT" -providers = [ - "kraken", -] -quote = "USD" - -[[currency_pairs]] -base = "SCRT" -providers = [ - "mexc", - "gate" -] -quote = "USDT" - -[[currency_pairs]] -base = "INJ" -providers = [ - "gate", - "mexc", -] -quote = "USDT" - -[[currency_pairs]] -base = "INJ" -providers = [ - "kraken", -] -quote = "USD" - [server] listen_addr = "0.0.0.0:7171" read_timeout = "20s" diff --git a/pricefeeder/pricefeeder.go b/pricefeeder/pricefeeder.go index f87b9d5e..517af572 100644 --- a/pricefeeder/pricefeeder.go +++ b/pricefeeder/pricefeeder.go @@ -26,18 +26,19 @@ import ( ) type PriceFeeder struct { - Oracle *oracle.Oracle + Oracle *oracle.Oracle + AppConfig AppConfig } -func (pf *PriceFeeder) Start(oracleParams types.Params, appConfig AppConfig) error { +func (pf *PriceFeeder) Start(currentBlockHeight int64, oracleParams types.Params) error { logWriter := zerolog.ConsoleWriter{Out: os.Stderr} - logLevel, err := zerolog.ParseLevel(appConfig.LogLevel) + logLevel, err := zerolog.ParseLevel(pf.AppConfig.LogLevel) if err != nil { return err } logger := zerolog.New(logWriter).Level(logLevel).With().Timestamp().Logger() - cfg, err := config.LoadConfigFromFlags(appConfig.ConfigPath, "") + cfg, err := config.LoadConfigFromFlags(pf.AppConfig.ConfigPath, "") if err != nil { return err } @@ -53,21 +54,12 @@ func (pf *PriceFeeder) Start(oracleParams types.Params, appConfig AppConfig) err return fmt.Errorf("failed to parse provider timeout: %w", err) } - providers := cfg.ProviderPairs() - deviations, err := cfg.DeviationsMap() + providers := oracle.CreatePairProvidersFromCurrencyPairProvidersList(oracleParams.CurrencyPairProviders) + deviations, err := oracle.CreateDeviationsFromCurrencyDeviationThresholdList(oracleParams.CurrencyDeviationThresholds) if err != nil { return err } - // overwite providers and deviations with on chain values if specified - if appConfig.ChainConfig { - providers = oracle.CreatePairProvidersFromCurrencyPairProvidersList(oracleParams.CurrencyPairProviders) - deviations, err = oracle.CreateDeviationsFromCurrencyDeviationThresholdList(oracleParams.CurrencyDeviationThresholds) - if err != nil { - return err - } - } - pf.Oracle = oracle.New( logger, client.OracleClient{}, @@ -75,7 +67,7 @@ func (pf *PriceFeeder) Start(oracleParams types.Params, appConfig AppConfig) err providerTimeout, deviations, cfg.ProviderEndpointsMap(), - appConfig.ChainConfig, + true, ) telemetryCfg := telemetry.Config{} @@ -92,10 +84,6 @@ func (pf *PriceFeeder) Start(oracleParams types.Params, appConfig AppConfig) err // start the process that observes and publishes exchange prices return startPriceFeeder(ctx, logger, cfg, pf.Oracle, metrics) }) - g.Go(func() error { - // start the process that calculates oracle prices - return startPriceOracle(ctx, logger, pf.Oracle, oracleParams, appConfig.OracleTickTime) - }) // Block main process until all spawned goroutines have gracefully exited and // signal has been captured in the main process or if an error occurs. @@ -173,32 +161,3 @@ func startPriceFeeder( } } } - -// startPriceOracle sets oracle prices fetched from price providers every tick sleep. -func startPriceOracle( - ctx context.Context, - logger zerolog.Logger, - oracle *oracle.Oracle, - oracleParams types.Params, - tickSleep time.Duration, -) error { - srvErrCh := make(chan error, 1) - - go func() { - logger.Info().Msg("starting price-feeder oracle...") - srvErrCh <- oracle.StartClientless(ctx, oracleParams, tickSleep) - }() - - for { - select { - case <-ctx.Done(): - logger.Info().Msg("shutting down price-feeder oracle...") - return nil - - case err := <-srvErrCh: - logger.Err(err).Msg("error starting the price-feeder oracle") - oracle.Stop() - return err - } - } -} diff --git a/scripts/init-local.sh b/scripts/init-local.sh index fd25fb33..1915065c 100755 --- a/scripts/init-local.sh +++ b/scripts/init-local.sh @@ -3,7 +3,6 @@ CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" PRICE_FEEDER_CONFIG_PATH="${CWD}/../pricefeeder/price-feeder.example.toml" export PRICE_FEEDER_CONFIG=$(realpath "$PRICE_FEEDER_CONFIG_PATH") -export PRICE_FEEDER_CHAIN_CONFIG="TRUE" export PRICE_FEEDER_LOG_LEVEL="DEBUG" NODE_BIN="${1:-$CWD/../build/ojod}" diff --git a/tests/e2e/orchestrator/oracle_gen_state.go b/tests/e2e/orchestrator/oracle_gen_state.go index 110baeb7..9dd3dc3f 100644 --- a/tests/e2e/orchestrator/oracle_gen_state.go +++ b/tests/e2e/orchestrator/oracle_gen_state.go @@ -18,7 +18,7 @@ var ( {BaseDenom: "ibc/6", SymbolDenom: "BNB", Exponent: 18}, {BaseDenom: "ibc/7", SymbolDenom: "stATOM", Exponent: 6}, {BaseDenom: "ibc/8", SymbolDenom: "stOSMO", Exponent: 6}, - {BaseDenom: "ibc/9", SymbolDenom: "OSMO", Exponent: 6}, + {BaseDenom: "ibc/9", SymbolDenom: "USDT", Exponent: 6}, {BaseDenom: "ibc/10", SymbolDenom: "IST", Exponent: 6}, } @@ -26,7 +26,7 @@ var ( {BaseDenom: "ibc/1", SymbolDenom: "ATOM", Exponent: 6}, {BaseDenom: "ibc/4", SymbolDenom: "ETH", Exponent: 18}, {BaseDenom: "ibc/5", SymbolDenom: "BTC", Exponent: 8}, - {BaseDenom: "ibc/9", SymbolDenom: "OSMO", Exponent: 6}, + {BaseDenom: "ibc/9", SymbolDenom: "USDT", Exponent: 6}, } oracleRewardBands = []oracletypes.RewardBand{ @@ -39,7 +39,7 @@ var ( {SymbolDenom: "BNB", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, {SymbolDenom: "stATOM", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, {SymbolDenom: "stOSMO", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, - {SymbolDenom: "OSMO", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, + {SymbolDenom: "USDT", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, {SymbolDenom: "IST", RewardBand: math.LegacyMustNewDecFromStr("1.0")}, } ) diff --git a/tests/e2e/orchestrator/orchestrator.go b/tests/e2e/orchestrator/orchestrator.go index b2668077..ae91e62f 100644 --- a/tests/e2e/orchestrator/orchestrator.go +++ b/tests/e2e/orchestrator/orchestrator.go @@ -334,9 +334,7 @@ func (o *Orchestrator) runValidators(t *testing.T) { priceFeederConfigArgs := []string{ "start", "--pricefeeder.config_path=/root/pricefeeder/price-feeder.example.toml", - "--pricefeeder.chain_config=false", "--pricefeeder.log_level=info", - "--pricefeeder.oracle_tick_time=5s", } runOpts := &dockertest.RunOptions{ diff --git a/tests/grpc/price_listener.go b/tests/grpc/price_listener.go index 63912112..016bc013 100644 --- a/tests/grpc/price_listener.go +++ b/tests/grpc/price_listener.go @@ -44,7 +44,6 @@ func listenForPrices( if err != nil { return nil, err } - exchangeRates, err := ojoClient.QueryClient.QueryExchangeRates() if err != nil { return nil, err diff --git a/x/oracle/abci/endblocker.go b/x/oracle/abci/endblocker.go index 063d4c0d..88ce64d9 100644 --- a/x/oracle/abci/endblocker.go +++ b/x/oracle/abci/endblocker.go @@ -32,6 +32,16 @@ func EndBlocker(ctx context.Context, k keeper.Keeper) error { params := k.GetParams(sdkCtx) + // Start price feeder if it hasn't been started. + if k.PriceFeeder.Oracle == nil { + go func() { + err := k.PriceFeeder.Start(sdkCtx.BlockHeight(), params) + if err != nil { + sdkCtx.Logger().Error("Error starting Oracle Keeper price feeder", "err", err) + } + }() + } + // Set all current active validators into the ValidatorRewardSet at // the beginning of a new Slash Window. if k.IsPeriodLastBlock(sdkCtx, params.SlashWindow+1) { @@ -41,6 +51,17 @@ func EndBlocker(ctx context.Context, k keeper.Keeper) error { } if k.IsPeriodLastBlock(sdkCtx, params.VotePeriod) { + if k.PriceFeeder.Oracle != nil { + // Update price feeder oracle with latest params. + k.PriceFeeder.Oracle.ParamCache.UpdateParamCache(sdkCtx.BlockHeight(), k.GetParams(sdkCtx), nil) + + // Execute price feeder oracle tick. + if err := k.PriceFeeder.Oracle.TickClientless(ctx); err != nil { + return err + } + } + + // Update oracle module with prices. if err := CalcPrices(sdkCtx, params, k); err != nil { return err } diff --git a/x/oracle/abci/voteextension.go b/x/oracle/abci/voteextension.go index 406f2a63..57f5e92b 100644 --- a/x/oracle/abci/voteextension.go +++ b/x/oracle/abci/voteextension.go @@ -8,7 +8,6 @@ import ( cometabci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ojo-network/ojo/pricefeeder" "github.com/ojo-network/ojo/x/oracle/keeper" "github.com/ojo-network/ojo/x/oracle/types" "github.com/ojo-network/price-feeder/oracle" @@ -23,19 +22,16 @@ type OracleVoteExtension struct { type VoteExtensionHandler struct { logger log.Logger oracleKeeper keeper.Keeper - priceFeeder *pricefeeder.PriceFeeder } // NewVoteExtensionHandler returns a new VoteExtensionHandler. func NewVoteExtensionHandler( logger log.Logger, oracleKeeper keeper.Keeper, - priceFeeder *pricefeeder.PriceFeeder, ) *VoteExtensionHandler { return &VoteExtensionHandler{ logger: logger, oracleKeeper: oracleKeeper, - priceFeeder: priceFeeder, } } @@ -63,12 +59,12 @@ func (h *VoteExtensionHandler) ExtendVoteHandler() sdk.ExtendVoteHandler { } // Get prices from Oracle Keeper's pricefeeder and generate vote msg - if h.priceFeeder.Oracle == nil { + if h.oracleKeeper.PriceFeeder.Oracle == nil { err := fmt.Errorf("price feeder oracle not set") h.logger.Error(err.Error()) return nil, err } - prices := h.priceFeeder.Oracle.GetPrices() + prices := h.oracleKeeper.PriceFeeder.Oracle.GetPrices() exchangeRatesStr := oracle.GenerateExchangeRatesString(prices) // Parse as DecCoins diff --git a/x/oracle/abci/voteextension_test.go b/x/oracle/abci/voteextension_test.go index 5271b55f..3ec16bbd 100644 --- a/x/oracle/abci/voteextension_test.go +++ b/x/oracle/abci/voteextension_test.go @@ -37,7 +37,7 @@ func (s *IntegrationTestSuite) TestExtendVoteHandler() { name: "price feeder oracle not set", logger: log.NewNopLogger(), oracleKeeper: app.OracleKeeper, - priceFeeder: app.PriceFeeder, + priceFeeder: &pricefeeder.PriceFeeder{}, extendVoteRequest: &cometabci.RequestExtendVote{ Height: ctx.BlockHeight(), }, @@ -58,10 +58,10 @@ func (s *IntegrationTestSuite) TestExtendVoteHandler() { for _, tc := range testCases { s.Run(tc.name, func() { + tc.oracleKeeper.PriceFeeder = tc.priceFeeder h := abci.NewVoteExtensionHandler( tc.logger, tc.oracleKeeper, - tc.priceFeeder, ) resp, err := h.ExtendVoteHandler()(ctx, tc.extendVoteRequest) @@ -139,10 +139,10 @@ func (s *IntegrationTestSuite) TestVerifyVoteExtensionHandler() { for _, tc := range testCases { s.Run(tc.name, func() { + tc.oracleKeeper.PriceFeeder = tc.priceFeeder h := abci.NewVoteExtensionHandler( tc.logger, tc.oracleKeeper, - tc.priceFeeder, ) resp, err := h.VerifyVoteExtensionHandler()(ctx, tc.verifyVoteRequest) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index fdac62df..f9ef8f5f 100644 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -12,9 +12,9 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ojo-network/ojo/pricefeeder" "github.com/ojo-network/ojo/util/metrics" "github.com/ojo-network/ojo/x/oracle/types" - "github.com/ojo-network/price-feeder/oracle" ) var ten = math.LegacyMustNewDecFromStr("10") @@ -30,7 +30,7 @@ type Keeper struct { distrKeeper types.DistributionKeeper StakingKeeper types.StakingKeeper - PriceFeederOracle *oracle.Oracle + PriceFeeder *pricefeeder.PriceFeeder distrName string telemetryEnabled bool @@ -70,6 +70,7 @@ func NewKeeper( bankKeeper: bankKeeper, distrKeeper: distrKeeper, StakingKeeper: stakingKeeper, + PriceFeeder: &pricefeeder.PriceFeeder{}, distrName: distrName, telemetryEnabled: telemetryEnabled, authority: authority,