Jayant Krishnamurthy 9805bbd6ec hardhat config for abstract (#2853) 4 luni în urmă
..
chain_patches 8578eb2837 chore(target_chains/ethereum) Organize chain patches (#1816) 1 an în urmă
contracts 02fe8404f7 updating version, reverting preincrement, renaming slots strict to with config in test functions 5 luni în urmă
deploy b29522f562 chore(entropy): deployment script for entropy upgrades (#2697) 6 luni în urmă
forge-test cfa52f58d5 fix: run turbo fix (#2803) 5 luni în urmă
lib bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 ani în urmă
migrations 1b5195aa0a fix: run turbo fix 8 luni în urmă
scripts 1b5195aa0a fix: run turbo fix 8 luni în urmă
test 1b5195aa0a fix: run turbo fix 8 luni în urmă
.dockerignore bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 ani în urmă
.env.template ed31243d1f Chore(entropy) deploy on abstract (#2056) 1 an în urmă
.env.test f18f1c8e7c fix(target_chains/ethereum): update some configs to make js tests work (#1399) 1 an în urmă
.gitignore ec63330cf0 chore: add coverage/ to gitignore 2 ani în urmă
README.md e08052c2c4 feat: set up turborepo 1 an în urmă
VERIFY.md 29d6b9f586 Migrate to pnpm 1 an în urmă
coverage.sh 439a0f0337 fix: make coverage work on newer versions 2 ani în urmă
deploy.sh 2f1becdf17 chore(target_chains/ethereum): use versioned artifacts for deployment (#2714) 6 luni în urmă
foundry.toml 3292f62357 chore(target_chains/ethereum): add new networks (#2707) 6 luni în urmă
hardhat.config.ts 9805bbd6ec hardhat config for abstract (#2853) 4 luni în urmă
mine.js 1b5195aa0a fix: run turbo fix 8 luni în urmă
package.json 9a1b059750 feat(pulse-sdk-solidity): Create Pulse solidity SDK (#2667) 5 luni în urmă
prettier.config.mjs b1dc4c27f5 chore: move prettier to individual packages & upgrade prettier 8 luni în urmă
remappings.txt f841dfc14e feat(entropy): Add callback failure states to the contract (#2546) 7 luni în urmă
truffle-config.js 3292f62357 chore(target_chains/ethereum): add new networks (#2707) 6 luni în urmă

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.