Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 72a8dec

Browse files
authored
Use new sdk + a bit cleanup + release (#54)
* Use new sdk + a bit cleanup + release * Address reviews + add more comments
1 parent d7aacb3 commit 72a8dec

File tree

7 files changed

+102
-79
lines changed

7 files changed

+102
-79
lines changed

pyth-evm-price-pusher/docker-compose.mainnet.sample.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- "--logLevel"
1515
- "debug"
1616
price-service:
17-
image: public.ecr.aws/pyth-network/xc-server:v1.0.0
17+
image: public.ecr.aws/pyth-network/xc-server:v2.0.0
1818
environment:
1919
SPY_SERVICE_HOST: "spy:7072"
2020
SPY_SERVICE_FILTERS: |
@@ -26,12 +26,12 @@ services:
2626
{
2727
"chain_id": 26,
2828
"emitter_address": "f8cd23c2ab91237730770bbea08d61005cdda0984348f3f6eecb559638c0bba0"
29-
},
29+
}
3030
]
3131
REST_PORT: "4200"
3232
PROM_PORT: "8081"
33-
READINESS_SPY_SYNC_TIME_SECONDS: "60"
34-
READINESS_NUM_LOADED_SYMBOLS: "8"
33+
READINESS_SPY_SYNC_TIME_SECONDS: "20"
34+
READINESS_NUM_LOADED_SYMBOLS: "50"
3535
LOG_LEVEL: debug
3636
healthcheck:
3737
test:
@@ -43,7 +43,7 @@ services:
4343
"--spider",
4444
"http://localhost:4200/ready",
4545
]
46-
start_period: 60s
46+
start_period: 20s
4747
depends_on:
4848
- spy
4949
price-pusher:

pyth-evm-price-pusher/docker-compose.testnet.sample.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- "--logLevel"
1515
- "debug"
1616
price-service:
17-
image: public.ecr.aws/pyth-network/xc-server:v1.0.0
17+
image: public.ecr.aws/pyth-network/xc-server:v2.0.0
1818
environment:
1919
SPY_SERVICE_HOST: "spy:7072"
2020
SPY_SERVICE_FILTERS: |
@@ -26,12 +26,12 @@ services:
2626
{
2727
"chain_id": 26,
2828
"emitter_address": "a27839d641b07743c0cb5f68c51f8cd31d2c0762bec00dc6fcd25433ef1ab5b6"
29-
},
29+
}
3030
]
3131
REST_PORT: "4200"
3232
PROM_PORT: "8081"
33-
READINESS_SPY_SYNC_TIME_SECONDS: "60"
34-
READINESS_NUM_LOADED_SYMBOLS: "8"
33+
READINESS_SPY_SYNC_TIME_SECONDS: "20"
34+
READINESS_NUM_LOADED_SYMBOLS: "50"
3535
LOG_LEVEL: debug
3636
healthcheck:
3737
test:
@@ -43,7 +43,7 @@ services:
4343
"--spider",
4444
"http://localhost:4200/ready",
4545
]
46-
start_period: 60s
46+
start_period: 20s
4747
depends_on:
4848
- spy
4949
price-pusher:

pyth-evm-price-pusher/package-lock.json

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

pyth-evm-price-pusher/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-evm-price-pusher",
3-
"version": "0.3.0",
3+
"version": "1.0.0",
44
"description": "Pyth EVM Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",
@@ -45,7 +45,7 @@
4545
"typescript": "^4.6.3"
4646
},
4747
"dependencies": {
48-
"@pythnetwork/pyth-evm-js": "^0.5.0",
48+
"@pythnetwork/pyth-evm-js": "^1.0.0",
4949
"@pythnetwork/pyth-sdk-solidity": "^1.0.1",
5050
"@truffle/hdwallet-provider": "^2.0.8",
5151
"joi": "^17.6.0",

pyth-evm-price-pusher/src/evm-price-listener.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HexString, PriceFeed } from "@pythnetwork/pyth-evm-js";
1+
import { HexString } from "@pythnetwork/pyth-evm-js";
22

33
import AbstractPythAbi from "@pythnetwork/pyth-sdk-solidity/abis/AbstractPyth.json";
44
import Web3 from "web3";
@@ -10,7 +10,6 @@ import {
1010
DurationInSeconds,
1111
isWsEndpoint,
1212
removeLeading0x,
13-
statusNumberToEnum,
1413
} from "./utils";
1514

1615
export class EvmPriceListener implements PriceListener {

pyth-evm-price-pusher/src/pyth-price-listener.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ export class PythPriceListener implements PriceListener {
3434

3535
const priceFeeds = await this.connection.getLatestPriceFeeds(this.priceIds);
3636
priceFeeds?.forEach((priceFeed) => {
37-
const latestAvailablePrice = priceFeed.getLatestAvailablePriceUnchecked();
37+
// Getting unchecked because although it might be old
38+
// but might not be there on the target chain.
39+
const latestAvailablePrice = priceFeed.getPriceUnchecked();
3840
this.latestPriceInfo.set(priceFeed.id, {
39-
price: latestAvailablePrice[0].price,
40-
conf: latestAvailablePrice[0].conf,
41-
publishTime: latestAvailablePrice[1],
41+
price: latestAvailablePrice.price,
42+
conf: latestAvailablePrice.conf,
43+
publishTime: latestAvailablePrice.publishTime,
4244
});
4345
});
4446
}
@@ -50,15 +52,16 @@ export class PythPriceListener implements PriceListener {
5052
)} ${priceFeed.id}`
5153
);
5254

53-
const currentPrice = priceFeed.getCurrentPrice();
55+
// Consider price to be currently available if it is not older than 60s
56+
const currentPrice = priceFeed.getPriceNoOlderThan(60);
5457
if (currentPrice === undefined) {
5558
return;
5659
}
5760

5861
const priceInfo: PriceInfo = {
5962
conf: currentPrice.conf,
6063
price: currentPrice.price,
61-
publishTime: priceFeed.publishTime,
64+
publishTime: currentPrice.publishTime,
6265
};
6366

6467
this.latestPriceInfo.set(priceFeed.id, priceInfo);

pyth-evm-price-pusher/src/utils.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HexString, PriceStatus } from "@pythnetwork/pyth-evm-js";
1+
import { HexString } from "@pythnetwork/pyth-evm-js";
22

33
export type PctNumber = number;
44
export type DurationInSeconds = number;
@@ -21,21 +21,6 @@ export function addLeading0x(id: HexString): HexString {
2121
return "0x" + id;
2222
}
2323

24-
export function statusNumberToEnum(status: number): PriceStatus {
25-
switch (status) {
26-
case 0:
27-
return PriceStatus.Unknown;
28-
case 1:
29-
return PriceStatus.Trading;
30-
case 2:
31-
return PriceStatus.Halted;
32-
case 3:
33-
return PriceStatus.Auction;
34-
default:
35-
throw new Error("Invalid status");
36-
}
37-
}
38-
3924
export function isWsEndpoint(endpoint: string): boolean {
4025
const url = new URL(endpoint);
4126
const protocol = url.protocol;

0 commit comments

Comments
 (0)