Ali Behjati 2f1becdf17 chore(target_chains/ethereum): use versioned artifacts for deployment (#2714) 6 月之前
..
chain_patches 8578eb2837 chore(target_chains/ethereum) Organize chain patches (#1816) 1 年之前
contracts 0295874676 chore(target_chains/ethereum): cut another release for pyth (#2705) 6 月之前
deploy b29522f562 chore(entropy): deployment script for entropy upgrades (#2697) 6 月之前
forge-test f01d4bd4bc feat(target_chains/ethereum/pyth): strict minimal updateData parsing (#2637) 6 月之前
lib bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 年之前
migrations 1b5195aa0a fix: run turbo fix 8 月之前
scripts 1b5195aa0a fix: run turbo fix 8 月之前
test 1b5195aa0a fix: run turbo fix 8 月之前
.dockerignore bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 年之前
.env.template ed31243d1f Chore(entropy) deploy on abstract (#2056) 1 年之前
.env.test f18f1c8e7c fix(target_chains/ethereum): update some configs to make js tests work (#1399) 1 年之前
.gitignore ec63330cf0 chore: add coverage/ to gitignore 2 年之前
README.md e08052c2c4 feat: set up turborepo 1 年之前
VERIFY.md 29d6b9f586 Migrate to pnpm 1 年之前
coverage.sh 439a0f0337 fix: make coverage work on newer versions 2 年之前
deploy.sh 2f1becdf17 chore(target_chains/ethereum): use versioned artifacts for deployment (#2714) 6 月之前
foundry.toml 3292f62357 chore(target_chains/ethereum): add new networks (#2707) 6 月之前
hardhat.config.ts 3292f62357 chore(target_chains/ethereum): add new networks (#2707) 6 月之前
mine.js 1b5195aa0a fix: run turbo fix 8 月之前
package.json 0295874676 chore(target_chains/ethereum): cut another release for pyth (#2705) 6 月之前
prettier.config.mjs b1dc4c27f5 chore: move prettier to individual packages & upgrade prettier 8 月之前
remappings.txt f841dfc14e feat(entropy): Add callback failure states to the contract (#2546) 7 月之前
truffle-config.js 3292f62357 chore(target_chains/ethereum): add new networks (#2707) 6 月之前

README.md

Pyth Ethereum Contract

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

Installation

The contracts are built and tested using Foundry. Follow the Foundry installation instructions to install it if you do not already have it.

Next, run the following command from the repo root to install required dependencies for the contract:

pnpm i
pnpm turbo build --filter @pythnetwork/pyth-evm-contract

Next, from the contracts directory, run the following command to install forge dependencies:

npm run install-forge-deps

Testing

Run forge build to build the contracts and forge test to run the contract unit tests. The unit tests live in the forge-test directory.

Code Coverage

To see line-by-line test coverage:

npm run coverage

Open coverage/index.html in your web browser to see the results.

Governance tests

There is a separate test suite executed by truffle for testing governance messages and contract upgrades. You can run ganache-cli as a blockchain instance and test it manually. To do the latter, run the following commands in the contracts folder:

  1. Spawn a new network on a seperate terminal (do not close it while running tests):

    pnpm dlx ganache-cli -e 10000 --deterministic --time="1970-01-02T00:00:00+00:00" --host=0.0.0.0
    
  2. deploy the contracts:

    cp .env.test .env && pnpm exec truffle compile --all && pnpm exec truffle migrate --network development
    
  3. Run the test suite:

    npm run test-contract
    

Gas Benchmarks

You can use foundry to run gas benchmark tests (which can be found in the forge-test directory). 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 happened 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.