pyth-crosschain/target_chains/ethereum/contracts
Ali Behjati ef922220ee
chore(contract_manager): Rename package to @pythnetwork/contract-manager (#1507)
This change renames the contract manager package name to @pythnetwork/contract-manager to be consistent with our package names.
2024-04-29 15:25:05 +02:00
..
contracts refactor(target_chains/ethereum): clean up unused batch update code 2024-03-28 14:50:01 +00:00
deploy chore(eth): deploy stable contracts on testnets (#1146) 2023-11-24 11:59:04 +01:00
forge-test feat(target_chains/ethereum/sdk/solidity): add convertToUint method to the sdk (#1390) 2024-03-28 17:23:41 -04:00
lib [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
migrations/test fix(target_chains/ethereum): update some configs to make js tests work (#1399) 2024-03-27 14:56:27 +01:00
scripts chore(contract_manager): Rename package to @pythnetwork/contract-manager (#1507) 2024-04-29 15:25:05 +02:00
test refactor(target_chains/ethereum): remove truffle tests for batch updates 2024-03-28 14:50:01 +00:00
.dockerignore [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.template [evm] [cosmwasm] Minor cleanup (#1027) 2023-08-24 11:41:59 +02:00
.env.test fix(target_chains/ethereum): update some configs to make js tests work (#1399) 2024-03-27 14:56:27 +01:00
.gitignore chore: add coverage/ to gitignore 2023-08-09 20:58:54 +03:30
README.md fix(target_chains/ethereum): update some configs to make js tests work (#1399) 2024-03-27 14:56:27 +01:00
VERIFY.md fix: typos (#1347) 2024-03-11 15:50:28 +00:00
blast-gas-claim-patch.diff chore(target_chains/ethereum): add Blast and Mode gas claim patches (#1440) 2024-04-10 19:32:11 +02:00
canto-deployment-patch.diff [eth] Add Canto mainnet (#751) 2023-04-07 17:49:01 +02:00
coverage.sh fix: make coverage work on newer versions 2023-08-09 20:58:54 +03:30
deploy.sh feat(contract_manager): script for EVM feeds contract deployment (#1254) 2024-01-30 12:11:19 +01:00
foundry.toml chore(target_chains/eth): revert solidity version 2023-12-06 17:42:42 +03:30
hardhat.config.ts [evm] Evm runs (#1099) 2023-10-13 15:45:35 +02:00
mine.js [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
mode-gas-claim-patch.diff chore(target_chains/ethereum): add Blast and Mode gas claim patches (#1440) 2024-04-10 19:32:11 +02:00
package.json chore(contract_manager): Rename package to @pythnetwork/contract-manager (#1507) 2024-04-29 15:25:05 +02:00
remappings.txt [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
truffle-config.js chore(target_chains/eth): revert solidity version 2023-12-06 17:42:42 +03:30

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:

npm ci
npx lerna run build --scope="@pythnetwork/pyth-evm-contract" --include-dependencies

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):
npx ganache-cli -e 10000 --deterministic --time="1970-01-02T00:00:00+00:00" --host=0.0.0.0
  1. deploy the contracts:
cp .env.test .env && npx truffle compile --all && npx truffle migrate --network development
  1. 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.