Price Feed
Price feed example
The price feed updates a specified price on an adjustable interval. This price is available on chain for any contracts to use.
The price feed example uses either LiquidScheduler
and LiquidHarmony
or just LiquidHarmony
oracles to fetch a price every X seconds. If the price does not deviate by more or less than 1% (default) then an assertion will be thrown preventing the DSP from using CPU on the oracle request or the cron rescheduling action.
Code located here
Open source implementation by maltablock here
Download and test with zeus
To download and run the unit test the price feed with zeus simply run:
The unit test will run several requests, none of which will increment the CPU used past the first action unless the price deviates by 1% from the first price logged during the test.
Price feed settings
The following are the settings that can be customized with the settings
action.
uint32_t threshold = 1;
- this represents the minimum amount of DSPs that must respond to deem a price fetch valid, defaults to 1float lower_bound_filter = 1;
// lower bound check to see if a price has dropped by more than x%, if so, update the price and spend CPU to do so, if not assert reschedule the cron and spend no CPU, defaults 1%float upper_bound_filter = 1;
// upper bound check to see if a price has increased by more than x%, if so, update the price and spend CPU to do so, if not assert reschedule the cron and spend no CPU, defaults 1%float lower_bound_dsp = 1;
// lower bound check to compare all DSP results against, if any DSP result is less than the first reported price by x%, assert, defaults to 1%float upper_bound_dsp = 1;
// upper bound check to compare all DSP results against, if any DSP result is more than the first reported price by x%, assert, defaults to 1%
The example also allows an average or median consensus mechanism for calculating the most recent price.
Price feed actions
testfeed (std::vector<char> uri, uint32_t interval)
- takes a LiquidHarmony URI and an interval to reschedule the price feed requestsettings (uint32_t new_threshold_val, float lower_bound_filter, float upper_bound_filter, float lower_bound_dsp, float upper_bound_dsp)
- update settings for price feedstopstart (bool stopstart_bool)
- toggles price feed cron on or offtestfetch (std::vector<char> uri)
- fetches price feed oracle request without cron
cleos examples:
Last updated