Skip to content

Commit ae88640

Browse files
author
Dev Kalra
authored
move changes from pyth-js (#624)
1 parent a549d53 commit ae88640

14 files changed

+470
-475
lines changed

price_pusher/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ docker-compose -f docker-compose.testnet.sample.yaml up
122122

123123
It will take a few minutes until all the services are up and running.
124124

125-
[pyth price service]: https://github.com/pyth-network/pyth-crosschain/tree/main/third_party/pyth/price-service
125+
[pyth price service]: https://github.com/pyth-network/pyth-crosschain/tree/main/price_service/server

price_pusher/docker-compose.mainnet.sample.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
spy:
33
# Find latest Guardian images in https://github.com/wormhole-foundation/wormhole/pkgs/container/guardiand
4-
image: ghcr.io/wormhole-foundation/guardiand:v.2.14.5
4+
image: ghcr.io/wormhole-foundation/guardiand:v.2.14.8.1
55
command:
66
- "spy"
77
- "--nodeKey"
@@ -16,7 +16,7 @@ services:
1616
- "warn"
1717
price-service:
1818
# Find latest price service images https://gallery.ecr.aws/pyth-network/xc-server
19-
image: public.ecr.aws/pyth-network/xc-server:v2.2.3
19+
image: public.ecr.aws/pyth-network/xc-server:v3.0.0
2020
environment:
2121
SPY_SERVICE_HOST: "spy:7072"
2222
SPY_SERVICE_FILTERS: |

price_pusher/docker-compose.testnet.sample.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
spy:
33
# Find latest Guardian images in https://github.com/wormhole-foundation/wormhole/pkgs/container/guardiand
4-
image: ghcr.io/wormhole-foundation/guardiand:v.2.14.5
4+
image: ghcr.io/wormhole-foundation/guardiand:v.2.14.8.1
55
command:
66
- "spy"
77
- "--nodeKey"
@@ -16,7 +16,7 @@ services:
1616
- "warn"
1717
price-service:
1818
# Find latest price service images https://gallery.ecr.aws/pyth-network/xc-server
19-
image: public.ecr.aws/pyth-network/xc-server:v2.2.3
19+
image: public.ecr.aws/pyth-network/xc-server:v3.0.0
2020
environment:
2121
SPY_SERVICE_HOST: "spy:7072"
2222
SPY_SERVICE_FILTERS: |

price_pusher/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_pusher/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-price-pusher",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Pyth EVM Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -43,6 +43,7 @@
4343
"typescript": "^4.6.3"
4444
},
4545
"dependencies": {
46+
"@pythnetwork/pyth-common-js": "^1.2.0",
4647
"@pythnetwork/pyth-evm-js": "^1.1.0",
4748
"@pythnetwork/pyth-sdk-solidity": "^2.2.0",
4849
"@truffle/hdwallet-provider": "^2.1.3",

price_pusher/src/controller.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { UnixTimestamp } from "@pythnetwork/pyth-evm-js";
2+
import { DurationInSeconds, sleep } from "./utils";
3+
import { ChainPricePusher, PriceListener } from "./interface";
4+
import { PriceConfig, shouldUpdate } from "./price-config";
5+
6+
export class Controller {
7+
private cooldownDuration: DurationInSeconds;
8+
constructor(
9+
private priceConfigs: PriceConfig[],
10+
private sourcePriceListener: PriceListener,
11+
private targetPriceListener: PriceListener,
12+
private targetChainPricePusher: ChainPricePusher,
13+
config: {
14+
cooldownDuration: DurationInSeconds;
15+
}
16+
) {
17+
this.cooldownDuration = config.cooldownDuration;
18+
}
19+
20+
async start() {
21+
for (;;) {
22+
const pricesToPush: PriceConfig[] = [];
23+
const pubTimesToPush: UnixTimestamp[] = [];
24+
25+
for (const priceConfig of this.priceConfigs) {
26+
const priceId = priceConfig.id;
27+
28+
const targetLatestPrice =
29+
this.targetPriceListener.getLatestPriceInfo(priceId);
30+
const sourceLatestPrice =
31+
this.sourcePriceListener.getLatestPriceInfo(priceId);
32+
33+
if (shouldUpdate(priceConfig, sourceLatestPrice, targetLatestPrice)) {
34+
pricesToPush.push(priceConfig);
35+
pubTimesToPush.push((targetLatestPrice?.publishTime || 0) + 1);
36+
}
37+
}
38+
// note that the priceIds are without leading "0x"
39+
const priceIds = pricesToPush.map((priceConfig) => priceConfig.id);
40+
this.targetChainPricePusher.updatePriceFeed(priceIds, pubTimesToPush);
41+
await sleep(this.cooldownDuration * 1000);
42+
}
43+
}
44+
}

price_pusher/src/evm-price-listener.ts

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)