Skip to content

Commit cc7054b

Browse files
authored
[scheduler] Default to early updates (#1140)
* make early updates the default * make early updates the default
1 parent ef02cfe commit cc7054b

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

price_pusher/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The parameters above are configured per price feed in a price configuration YAML
3737
time_difference: 60 # Time difference threshold (in seconds) to push a newer price feed.
3838
price_deviation: 0.5 # The price deviation (%) threshold to push a newer price feed.
3939
confidence_ratio: 1 # The confidence/price (%) threshold to push a newer price feed.
40+
4041
# Optional block to configure whether this feed can be early updated. If at least one feed meets the
4142
# triggering conditions above, all other feeds who meet the early update conditions will be included in
4243
# the submitted batch of prices. This logic takes advantage of the fact that adding a feed to a larger
@@ -49,6 +50,24 @@ The parameters above are configured per price feed in a price configuration YAML
4950
- ...
5051
```
5152
53+
By default, the price pusher will automatically update the price of all listed price feeds whenever the
54+
triggering condition for a single feed is met. This behavior takes advantage of the reduced cost of batch price updates
55+
provided by the [Perseus upgrade](https://medium.com/@antonia.vanna.delgado/pyth-network-perseus-first-party-data-matters-e3379bf0d019),
56+
and is typically the lowest cost way to schedule price updates for multiple feeds.
57+
58+
However, if you would like to customize this behavior, you can add an `early_update` section to the YAML configuration file for
59+
the feed.
60+
61+
```yaml
62+
- alias: A/USD # Arbitrary alias for the price feed. It is used in enhance logging.
63+
...
64+
# If provided, only early update this price feed if at least one of the listed triggering conditions is met.
65+
early_update:
66+
time_difference: 30
67+
price_deviation: 0.1
68+
confidence_ratio: 0.5
69+
```
70+
5271
Two sample YAML configuration files are available in the root of this repo.
5372

5473
You can get the list of available price feeds from

price_pusher/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "5.7.1",
3+
"version": "6.0.0",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

price_pusher/src/price-config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export type PriceConfig = {
3535

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

66+
customEarlyUpdate: priceConfigRaw.early_update !== undefined,
5967
earlyUpdateTimeDifference: priceConfigRaw.early_update?.time_difference,
6068
earlyUpdatePriceDeviation: priceConfigRaw.early_update?.price_deviation,
6169
earlyUpdateConfidenceRatio: priceConfigRaw.early_update?.confidence_ratio,
@@ -139,6 +147,8 @@ export function shouldUpdate(
139147
) {
140148
return UpdateCondition.YES;
141149
} else if (
150+
priceConfig.customEarlyUpdate === undefined ||
151+
!priceConfig.customEarlyUpdate ||
142152
(priceConfig.earlyUpdateTimeDifference !== undefined &&
143153
timeDifference >= priceConfig.earlyUpdateTimeDifference) ||
144154
(priceConfig.earlyUpdatePriceDeviation !== undefined &&

0 commit comments

Comments
 (0)