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

Commit c311f36

Browse files
authored
[pyth-evm-price-pusher] Add price configuration file (#33)
* Update dependencies * Add price configuration file * Address review comments * Fix lint errors and warnings
1 parent a10dbd2 commit c311f36

File tree

10 files changed

+285
-120
lines changed

10 files changed

+285
-120
lines changed

pyth-evm-price-pusher/README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,23 @@ This approach is useful for protocols that already depend on regular push update
2222
The price pusher service monitors both the off-chain and on-chain Pyth price for a configured set of price feeds.
2323
It then pushes a price update to an on-chain Pyth contract if any of the following conditions are met:
2424

25-
- Time difference: The on-chain price is older than `time-difference` seconds
25+
- Time difference: The on-chain price is older than `time_difference` seconds
2626
from the latest Pyth price.
27-
- Price deviation: The latest Pyth price feed has changed more than `price-deviation` percent
27+
- Price deviation: The latest Pyth price feed has changed more than `price_deviation` percent
2828
from the on-chain price feed price.
2929
- Confidence ratio: The latest Pyth price feed has confidence to price ratio of more than
30-
`confidence-ratio`.
30+
`confidence_ratio`.
31+
32+
The parameters above are configured per price feed in a price configuration YAML file. The structure looks like this:
33+
34+
```yaml
35+
- alias: A/USD # Arbitrary alias for the price feed. It is used in enhance logging.
36+
id: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef # id of a price feed, a 32-byte hex string.
37+
time_difference: 60 # Time difference threshold (in seconds) to push a newer price feed.
38+
price_deviation: 0.5 # The price deviation (%) threshold to push a newer price feed.
39+
confidence_ratio: 1 # The confidence/price (%) threshold to push a newer price feed.
40+
- ...
41+
```
3142
3243
To run the price pusher, please run the following commands, replacing the command line arguments as necessary:
3344
@@ -36,8 +47,7 @@ npm install # Only run it the first time
3647

3748
npm run start -- --evm-endpoint wss://example-rpc.com --mnemonic-file "path/to/mnemonic.txt" \
3849
--pyth-contract example_network --price-endpoint https://example-pyth-price.com \
39-
--time-difference 60 --price-deviation 0.5 --confidence-ratio 5 \
40-
--price-ids "abcd..." "efgh..." "..." \
50+
--price-config-file "path/to/price-config-file.yaml" \
4151
[--cooldown-duration 10] \
4252
[--evm-polling-frequency 5]
4353
```
@@ -50,7 +60,7 @@ The program accepts the following command line arguments:
5060
the price pusher will use event subscriptions to read the current EVM price. If you provide a normal
5161
HTTP endpoint, the pusher will periodically poll for updates. The polling interval is configurable via
5262
the `evm-polling-frequency` command-line argument (described below).
53-
- `mnemonic-file`: Payer mnemonic (private key) file.
63+
- `mnemonic-file`: Path to payer mnemonic (private key) file.
5464
- `pyth-contract`: The Pyth contract address. Provide the network name on which Pyth is deployed
5565
or the Pyth contract address if you use a local network.
5666
You can find the networks on which pyth is live and their corresponding names
@@ -59,11 +69,7 @@ The program accepts the following command line arguments:
5969
`https://prices.testnet.pyth.network` for testnet and
6070
`https://prices.mainnet.pyth.network` for mainnet. It is recommended
6171
to run a standalone price service for more resiliency.
62-
- `price-ids`: Space separated price feed ids (in hex) to push. List of available
63-
price feeds is available in the [price feed ids page][].
64-
- `time-difference`: Time difference threshold (in seconds) to push a newer price feed.
65-
- `price-deviation`: The price deviation (%) threshold to push a newer price feed.
66-
- `confidence-ratio`: The confidence/price (%) threshold to push a newer price feed.
72+
- `price-config-file`: Path to price configuration YAML file.
6773
- `cooldown-duration` (Optional): The amount of time (in seconds) to wait between pushing
6874
price updates. It should be greater than the block time of the network, so this
6975
program confirms the price is updated and does not push it twice. Default: 10 seconds.
@@ -80,6 +86,8 @@ For example, to push `BTC/USD` and `BNB/USD` prices on BNB testnet, run the foll
8086
```sh
8187
npm run start -- --evm-endpoint "https://data-seed-prebsc-1-s1.binance.org:8545" --mnemonic-file "path/to/mnemonic.txt" \
8288
--pyth-contract bnb_testnet --price-endpoint https://prices.testnet.pyth.network \
83-
--price-ids "f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b" "ecf553770d9b10965f8fb64771e93f5690a182edc32be4a3236e0caaa6e0581a" \
84-
--time-difference 60 --price-deviation 0.5 --confidence-ratio 1
89+
--price-config-file "price-config.testnet.sample.yaml"
8590
```
91+
92+
[`price-config.testnet.sample.yaml`](./price-config.testnet.sample.yaml) contains configuration for `BTC/USD`
93+
and `BNB/USD` price feeds on Pyth testnet.

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

Lines changed: 124 additions & 23 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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@
4545
"typescript": "^4.6.3"
4646
},
4747
"dependencies": {
48-
"@pythnetwork/pyth-evm-js": "^0.4.0",
48+
"@pythnetwork/pyth-evm-js": "^0.5.0",
4949
"@pythnetwork/pyth-sdk-solidity": "^0.4.0",
5050
"@truffle/hdwallet-provider": "^2.0.8",
51+
"joi": "^17.6.0",
5152
"web3": "^1.5.3",
5253
"web3-eth-contract": "^1.7.5",
54+
"yaml": "^2.1.1",
5355
"yargs": "^17.5.1"
5456
}
5557
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- alias: BTC/USD
2+
id: f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b
3+
time_difference: 60
4+
price_deviation: 0.5
5+
confidence_ratio: 1
6+
- alias: BNB/USD
7+
id: ecf553770d9b10965f8fb64771e93f5690a182edc32be4a3236e0caaa6e0581a
8+
time_difference: 60
9+
price_deviation: 1
10+
confidence_ratio: 1

0 commit comments

Comments
 (0)