Ali Behjati 04d8a468ac [eth] Improve docs and repo (#438) 2 лет назад
..
contracts 4821b877e3 [eth] Improve and automate deployment process (#412) 3 лет назад
forge-test 33f5b8a5bf [eth] Remove ownership entirely in favor of governance (#405) 3 лет назад
lib 1c17499d03 Add foundry base (#362) 3 лет назад
migrations b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
networks 2efd512d36 [eth] Deploy to arbitrum-testnet (#436) 2 лет назад
scripts 09f8af74ed [eth] Complete syncPythState.js (#425) 2 лет назад
test 33f5b8a5bf [eth] Remove ownership entirely in favor of governance (#405) 3 лет назад
.dockerignore d6e25d9209 Add pre-commit globally (#393) 3 лет назад
.env.cluster.mainnet 09f8af74ed [eth] Complete syncPythState.js (#425) 2 лет назад
.env.cluster.testnet 09f8af74ed [eth] Complete syncPythState.js (#425) 2 лет назад
.env.prod.arbitrum f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.arbitrum_testnet 2efd512d36 [eth] Deploy to arbitrum-testnet (#436) 2 лет назад
.env.prod.aurora f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.aurora_testnet f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.avalanche f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.bnb f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.bnb_testnet f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.celo b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.celo_alfajores_testnet b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.cronos b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.cronos_testnet b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.development f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.ethereum d6e25d9209 Add pre-commit globally (#393) 3 лет назад
.env.prod.fantom f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.fantom_testnet f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.fuji f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.goerli f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.kcc b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.kcc_testnet b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.mumbai f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.optimism f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.optimism_goerli a9a1fb7b5a Add deployment files of optimism goerli + fix bugs (#364) 3 лет назад
.env.prod.polygon f7958e387f [eth] Add set fee migration step + deployment process improvement (#346) 3 лет назад
.env.prod.zksync b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.prod.zksync_testnet b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.template b1aea626e9 [eth] Add new networks and their configurations (#418) 2 лет назад
.env.test 45ce07725f Update contract initializer (#397) 3 лет назад
.gitignore 04d8a468ac [eth] Improve docs and repo (#438) 2 лет назад
Deploying.md 04d8a468ac [eth] Improve docs and repo (#438) 2 лет назад
README.md 2efd512d36 [eth] Deploy to arbitrum-testnet (#436) 2 лет назад
VERIFY.md d6e25d9209 Add pre-commit globally (#393) 3 лет назад
deploy.sh 4821b877e3 [eth] Improve and automate deployment process (#412) 3 лет назад
devnet_mnemonic.txt 2ea41b8176 [WIP] Pr/drozdziak1/p2w batching/5e704f8b (#877) 3 лет назад
foundry.toml f8447f871e [eth]: Improve optimization runs to 10000 (#406) 3 лет назад
mine.js d6e25d9209 Add pre-commit globally (#393) 3 лет назад
package-lock.json 09f8af74ed [eth] Complete syncPythState.js (#425) 2 лет назад
package.json 09f8af74ed [eth] Complete syncPythState.js (#425) 2 лет назад
remappings.txt 0df243ba9e [eth] Add benchmark tests (#368) 3 лет назад
truffle-config.js 2efd512d36 [eth] Deploy to arbitrum-testnet (#436) 2 лет назад
truffle-verify-constants.patch d6e25d9209 Add pre-commit globally (#393) 3 лет назад

README.md

Pyth Ethereum Contract

This directory contains The Pyth contract on Ethereum and utilities to deploy it in EVM chains.

Installation

Run the following command to install required dependencies for the contract:

# xc-governance-sdk-js is a local dependency that should be built
# it is used in deployment (truffle migrations) to generate/sanity check
# the governance VAAs
pushd ../third_party/pyth/xc-governance-sdk-js && npm ci && popd
npm ci

Deployment

Please refer to Deploying.md for more information.

Foundry

Foundry can be installed by the official installer, or by running our helper script which will automatically pull the correct installation script individually for Foundry and the Solidity compiler for your current OS. This may work better if you are running into networking/firewall issues using Foundry's Solidity installer. To use helper script, run the command below from this directory:

pyth-crosschain/ethereum $ bash ../scripts/install-foundry.sh

You need to install npm dependencies as described in Installation. Also, you need to run the following command to install forge dependencies:

npm run install-forge-deps

After installing the dependencies. Run forge build to build the contracts and forge test to test the contracts using tests in forge-test directory.

Gas Benchmark

You can use foundry to run benchmark tests written in forge-test/GasBenchmark.t.sol. To run the tests with gas report you can run forge test --gas-report --match-contract GasBenchmark. However, as there are multiple benchmarks, this might not be useful. You can run a specific benchmark test by passing the test name using --match-test. A full command to run testBenchmarkUpdatePriceFeedsFresh benchmark test is like this:

forge test --gas-report --match-contract GasBenchmark --match-test testBenchmarkUpdatePriceFeedsFresh

A gas report should have a couple of tables like this:

╭───────────────────────────────────────────────────────────────────────────────────────────┬─────────────────┬────────┬────────┬─────────┬─────────╮
│ node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy contract ┆                 ┆        ┆        ┆         ┆         │
╞═══════════════════════════════════════════════════════════════════════════════════════════╪═════════════════╪════════╪════════╪═════════╪═════════╡
│ Deployment Cost                                                                           ┆ Deployment Size ┆        ┆        ┆         ┆         │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 164236                                                                                    ┆ 2050            ┆        ┆        ┆         ┆         │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ Function Name                                                                             ┆ min             ┆ avg    ┆ median ┆ max     ┆ # calls │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ .............                                                                             ┆ .....           ┆ .....  ┆ .....  ┆ .....   ┆ ..      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ updatePriceFeeds                                                                          ┆ 383169          ┆ 724277 ┆ 187385 ┆ 1065385 ┆ 2       │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ .............                                                                             ┆ .....           ┆ .....  ┆ .....  ┆ .....   ┆ ...     │
╰───────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴────────┴────────┴─────────┴─────────╯

For most of the methods, the minimum gas usage is an indication of our desired gas usage. Because the calls that store something in the storage for the first time in setUp use significantly more gas. For example, in the above table, there are two calls to updatePriceFeeds. The first call has happend in the setUp method and costed over a million gas and is not intended for our Benchmark. So our desired value is the minimum value which is around 380k gas.

If you like to optimize the contract and measure the gas optimization you can get gas snapshots using forge snapshot and evaluate your optimization with it. For more information, please refer to Gas Snapshots documentation. Once you optimized the code, please share the snapshot difference (generated using forge snapshot --diff <old-snapshot>) in the PR too. This snapshot gas value also includes an initial transaction cost as well as reading from the contract storage itself. You can get the most accurate result by looking at the gas report or the gas shown in the call trace with -vvvv argument to forge test.