Skip to content

Commit

Permalink
[scheduler] Default to early updates (#1140)
Browse files Browse the repository at this point in the history
* make early updates the default

* make early updates the default
  • Loading branch information
jayantk authored Nov 16, 2023
1 parent ef02cfe commit cc7054b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions price_pusher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The parameters above are configured per price feed in a price configuration YAML
time_difference: 60 # Time difference threshold (in seconds) to push a newer price feed.
price_deviation: 0.5 # The price deviation (%) threshold to push a newer price feed.
confidence_ratio: 1 # The confidence/price (%) threshold to push a newer price feed.

# Optional block to configure whether this feed can be early updated. If at least one feed meets the
# triggering conditions above, all other feeds who meet the early update conditions will be included in
# the submitted batch of prices. This logic takes advantage of the fact that adding a feed to a larger
Expand All @@ -49,6 +50,24 @@ The parameters above are configured per price feed in a price configuration YAML
- ...
```
By default, the price pusher will automatically update the price of all listed price feeds whenever the
triggering condition for a single feed is met. This behavior takes advantage of the reduced cost of batch price updates
provided by the [Perseus upgrade](https://medium.com/@antonia.vanna.delgado/pyth-network-perseus-first-party-data-matters-e3379bf0d019),
and is typically the lowest cost way to schedule price updates for multiple feeds.
However, if you would like to customize this behavior, you can add an `early_update` section to the YAML configuration file for
the feed.

```yaml
- alias: A/USD # Arbitrary alias for the price feed. It is used in enhance logging.
...
# If provided, only early update this price feed if at least one of the listed triggering conditions is met.
early_update:
time_difference: 30
price_deviation: 0.1
confidence_ratio: 0.5
```

Two sample YAML configuration files are available in the root of this repo.

You can get the list of available price feeds from
Expand Down
2 changes: 1 addition & 1 deletion price_pusher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/price-pusher",
"version": "5.7.1",
"version": "6.0.0",
"description": "Pyth Price Pusher",
"homepage": "https://pyth.network",
"main": "lib/index.js",
Expand Down
10 changes: 10 additions & 0 deletions price_pusher/src/price-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export type PriceConfig = {

// An early update happens when another price has met the conditions to be pushed, so this
// price can be included in a batch update for minimal gas cost.
// By default, every price feed will be early updated in a batch if any other price update triggers
// the conditions. This configuration will typically minimize gas usage.
//
// However, if you would like to customize this behavior, set `customEarlyUpdate: true` in your config
// for the price feed, then set the specific conditions (time / price / confidence) under which you would
// like the early update to trigger.
customEarlyUpdate: boolean | undefined;
earlyUpdateTimeDifference: DurationInSeconds | undefined;
earlyUpdatePriceDeviation: PctNumber | undefined;
earlyUpdateConfidenceRatio: PctNumber | undefined;
Expand All @@ -56,6 +63,7 @@ export function readPriceConfigFile(path: string): PriceConfig[] {
priceDeviation: priceConfigRaw.price_deviation,
confidenceRatio: priceConfigRaw.confidence_ratio,

customEarlyUpdate: priceConfigRaw.early_update !== undefined,
earlyUpdateTimeDifference: priceConfigRaw.early_update?.time_difference,
earlyUpdatePriceDeviation: priceConfigRaw.early_update?.price_deviation,
earlyUpdateConfidenceRatio: priceConfigRaw.early_update?.confidence_ratio,
Expand Down Expand Up @@ -139,6 +147,8 @@ export function shouldUpdate(
) {
return UpdateCondition.YES;
} else if (
priceConfig.customEarlyUpdate === undefined ||
!priceConfig.customEarlyUpdate ||
(priceConfig.earlyUpdateTimeDifference !== undefined &&
timeDifference >= priceConfig.earlyUpdateTimeDifference) ||
(priceConfig.earlyUpdatePriceDeviation !== undefined &&
Expand Down

0 comments on commit cc7054b

Please sign in to comment.