|
1 |
| -# Pyth price pusher on EVM networks |
| 1 | +# Pyth EVM price pusher |
| 2 | + |
| 3 | +Pyth EVM price pusher is a service that regularly pushes updates to the on-chain Pyth price based on configurable conditions. |
| 4 | + |
| 5 | +## Background |
| 6 | + |
| 7 | +Pyth is a cross-chain oracle that streams price updates over the peer-to-peer [Wormhole Network](https://wormholenetwork.com/). |
| 8 | +These price updates can be consumed on any chain that has a deployment of the Pyth contract. |
| 9 | +By default, Pyth does not automatically update the on-chain price every time the off-chain price changes; |
| 10 | +instead, anyone can permissionlessly update the on-chain price prior to using it. |
| 11 | +For more information please refer to [this document](../pyth-evm-js/README.md#how-pyth-works-on-evm-chains). |
| 12 | + |
| 13 | +Protocols integrating with can update the on-chain Pyth prices in two different ways. |
| 14 | +The first approach is on-demand updates: package a Pyth price update together with each transaction that depends on it. |
| 15 | +On-demand updates minimize latency and are more gas efficient, as prices are only updated on-chain when they are needed. |
| 16 | + |
| 17 | +The second approach is to run this service to regularly push updates to the on-chain price. |
| 18 | +This approach is useful for protocols that already depend on regular push updates. |
| 19 | + |
| 20 | +## Running Price Pusher |
| 21 | + |
| 22 | +The price pusher service monitors both the off-chain and on-chain Pyth price for a configured set of price feeds. |
| 23 | +It then pushes a price update to an on-chain Pyth contract if any of the following conditions are met: |
| 24 | + |
| 25 | +- Time difference: The on-chain price is older than `time-difference` seconds |
| 26 | + from the latest Pyth price. |
| 27 | +- Price deviation: The latest Pyth price feed has changed more than `price-deviation` percent |
| 28 | + from the on-chain price feed price. |
| 29 | +- Confidence ratio: The latest Pyth price feed has confidence to price ratio of more than |
| 30 | + `confidence-ratio`. |
| 31 | + |
| 32 | +To run the price pusher, please run the following commands, replacing the command line arguments as necessary: |
| 33 | + |
| 34 | +```sh |
| 35 | +npm install # Only run it the first time |
| 36 | + |
| 37 | +npm run start -- --evm-endpoint wss://example-rpc.com --mnemonic-file "path/to/mnemonic.txt" \ |
| 38 | + --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..." "..." \ |
| 41 | + [--cooldown-duration 10] \ |
| 42 | + [--evm-polling-frequency 5] |
| 43 | +``` |
| 44 | + |
| 45 | +### Command Line Arguments |
| 46 | + |
| 47 | +The program accepts the following command line arguments: |
| 48 | + |
| 49 | +- `evm-endpoint`: RPC endpoint URL for the EVM network. If you provide a websocket RPC endpoint (`ws[s]://...`), |
| 50 | + the price pusher will use event subscriptions to read the current EVM price. If you provide a normal |
| 51 | + HTTP endpoint, the pusher will periodically poll for updates. The polling interval is configurable via |
| 52 | + the `evm-polling-frequency` command-line argument (described below). |
| 53 | +- `mnemonic-file`: Payer mnemonic (private key) file. |
| 54 | +- `pyth-contract`: The Pyth contract address. Provide the network name on which Pyth is deployed |
| 55 | + or the Pyth contract address if you use a local network. |
| 56 | + You can find the networks on which pyth is live and their corresponding names |
| 57 | + [here](../pyth-evm-js/src/index.ts#L13). An example is `bnb_testnet`. |
| 58 | +- `price-endpoint`: Endpoint URL for the price service. You can use |
| 59 | + `https://prices.testnet.pyth.network` for testnet and |
| 60 | + `https://prices.mainnet.pyth.network` for mainnet. It is recommended |
| 61 | + 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. |
| 67 | +- `cooldown-duration` (Optional): The amount of time (in seconds) to wait between pushing |
| 68 | + price updates. It should be greater than the block time of the network, so this |
| 69 | + program confirms the price is updated and does not push it twice. Default: 10 seconds. |
| 70 | +- `evm-polling-frequency` (Optional): The frequency to poll price info data from the EVM network |
| 71 | + if the RPC is not a Websocket. It has no effect if the RPC is a Websocket. |
| 72 | + Default: 5 seconds. |
| 73 | + |
| 74 | +[price feed ids page]: https://pyth.network/developers/price-feed-ids/#pyth-cross-chain-testnet |
| 75 | + |
| 76 | +### Example |
| 77 | + |
| 78 | +For example, to push `BTC/USD` and `BNB/USD` prices on BNB testnet, run the following command: |
| 79 | + |
| 80 | +```sh |
| 81 | +npm run start -- --evm-endpoint "https://data-seed-prebsc-1-s1.binance.org:8545" --mnemonic-file "path/to/mnemonic.txt" \ |
| 82 | + --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 |
| 85 | +``` |
0 commit comments