pyth-crosschain/ethereum
Ali Behjati 0df243ba9e
[eth] Add benchmark tests (#368)
* Add remappings

This helps vs code solidity LSP work

* Remove unused wormhole contract

* Format foundry config file

* Fix install foundry script

* Add benchmark tests and its utils
2022-11-02 10:59:39 +01:00
..
.openzeppelin Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
contracts [eth] Add benchmark tests (#368) 2022-11-02 10:59:39 +01:00
forge-test [eth] Add benchmark tests (#368) 2022-11-02 10:59:39 +01:00
lib Add foundry base (#362) 2022-10-25 17:49:24 +02:00
migrations Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
networks Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
scripts Add set fee to tests + add some sanity checks (#350) 2022-10-18 19:07:37 +02:00
test [eth] Some contract improvements (#356) 2022-10-19 19:47:09 +02:00
.dockerignore EVM deployment scripts and documentation (#141) 2022-05-13 10:25:35 +02:00
.env.cluster.mainnet Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
.env.cluster.testnet Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
.env.prod.arbitrum [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.aurora [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.aurora_testnet [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.avalanche [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.bnb [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.bnb_testnet [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.development [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.ethereum [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.fantom [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.fantom_testnet [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.fuji [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.goerli [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.mumbai [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.optimism [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.prod.optimism_goerli Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
.env.prod.polygon [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.env.template Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
.env.test [eth] Add set fee migration step + deployment process improvement (#346) 2022-10-13 19:09:52 -05:00
.gitignore Add foundry base (#362) 2022-10-25 17:49:24 +02:00
Deploying.md Add set fee mainnet deployment info (#349) 2022-10-17 13:46:11 +02:00
README.md [eth] Add benchmark tests (#368) 2022-11-02 10:59:39 +01:00
VERIFY.md Add mainnet networks (#274) 2022-09-10 08:35:07 +02:00
deploy.sh [eth] contract improvement (#348) 2022-10-17 16:19:55 +02:00
devnet_mnemonic.txt [WIP] Pr/drozdziak1/p2w batching/5e704f8b (#877) 2022-02-23 19:12:16 +01:00
foundry.toml [eth] Add benchmark tests (#368) 2022-11-02 10:59:39 +01:00
mine.js ethereum: mine ganache blocks in the background 2020-11-18 13:56:56 +01:00
package-lock.json Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
package.json Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
remappings.txt [eth] Add benchmark tests (#368) 2022-11-02 10:59:39 +01:00
truffle-config.js Add deployment files of optimism goerli + fix bugs (#364) 2022-10-27 20:01:14 +02:00
truffle-verify-constants.patch ethereum: Add contract verification instructions (#792) 2022-01-28 14:52:54 +01:00

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 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ .............                                                                             ┆ .....           ┆ .....  ┆ .....  ┆ .....   ┆ ..      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ parseAndVerifyVM                                                                          ┆ 90292           ┆ 91262  ┆ 90292  ┆ 138792  ┆ 50      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ updatePriceFeeds                                                                          ┆ 187385          ┆ 206005 ┆ 187385 ┆ 1118385 ┆ 50      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ .............                                                                             ┆ .....           ┆ .....  ┆ .....  ┆ .....   ┆ ...     │
╰───────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴────────┴────────┴─────────┴─────────╯

For most of the methods, the median gas usage is an indication of our desired gas usage. Because the calls that store something in the storage for the first time use significantly more 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.