Mohammad Amin Khashkhashi Moghaddam 741f763375 Fix mainnet values on fuji and chiado and remove oasis network (#979) 2 سال پیش
..
contracts dcec1e9328 [eth] Finalize accumulator contract (#960) 2 سال پیش
deploy c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
forge-test ac97b4d35d [eth] - Aave FallbackOracle Integration (#924) 2 سال پیش
lib bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
migrations c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
networks e63490be48 [eth] Add EOS network (#963) 2 سال پیش
scripts c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
test c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
.dockerignore bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.cluster.mainnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.cluster.testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.arbitrum bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.arbitrum_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.aurora bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.aurora_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.avalanche bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.base_goerli 70c006176b Add base goerli config (#668) 2 سال پیش
.env.prod.bnb bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.bnb_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.canto 85b9c80e2a [eth] Add Canto mainnet (#751) 2 سال پیش
.env.prod.canto_testnet 38a8c2831a [evm] Deploy on Canto Testnet (#725) 2 سال پیش
.env.prod.celo bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.celo_alfajores_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.chiado 1771a8a98a [eth] Add new testnets (#669) 2 سال پیش
.env.prod.conflux_espace 71da520647 [eth] Deploy to Conflux eSpace (#748) 2 سال پیش
.env.prod.conflux_espace_testnet 71da520647 [eth] Deploy to Conflux eSpace (#748) 2 سال پیش
.env.prod.cronos bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.cronos_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.development bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.eos e63490be48 [eth] Add EOS network (#963) 2 سال پیش
.env.prod.eos_testnet e63490be48 [eth] Add EOS network (#963) 2 سال پیش
.env.prod.ethereum bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.evmos de0096efd4 [eth] add evmos mainnet (#686) 2 سال پیش
.env.prod.evmos_testnet 533181cc80 [eth] add evmos testnet (#683) 2 سال پیش
.env.prod.fantom bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.fantom_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.fuji bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.gnosis 11a0ba17d0 [eth] Deploy to gnosis mainnet (#892) 2 سال پیش
.env.prod.goerli bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.kava bdc3fede24 [eth] Deploy to Kava (#859) 2 سال پیش
.env.prod.kava_testnet bdc3fede24 [eth] Deploy to Kava (#859) 2 سال پیش
.env.prod.kcc bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.kcc_testnet bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.linea c86e4f2610 [eth] Add linea (#956) 2 سال پیش
.env.prod.linea_goerli 2a4045504d [eth] Add Linea goerli network (#947) 2 سال پیش
.env.prod.mantle a77ee78d13 [eth] Deploy to mantle (#948) 2 سال پیش
.env.prod.mantle_testnet 2db5a26752 [eth] Deploy to testnet Mantle (#742) 2 سال پیش
.env.prod.meter 111b0fa09f [eth] Deploy to meter (#731) 2 سال پیش
.env.prod.meter_testnet 111b0fa09f [eth] Deploy to meter (#731) 2 سال پیش
.env.prod.mumbai bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.neon 11cb14ca76 Deploy neon (#854) 2 سال پیش
.env.prod.neon_devnet 156fb23f24 [evm] deploy neon devnet (#693) 2 سال پیش
.env.prod.optimism bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.optimism_goerli bdc3fede24 [eth] Deploy to Kava (#859) 2 سال پیش
.env.prod.polygon bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.polygon_zkevm 7dad38ea89 [evm] Deploy on Polygon ZkEVM mainnet (#723) 2 سال پیش
.env.prod.polygon_zkevm_testnet c45664c951 [evm] Polygon ZKEVM deployment (#711) 2 سال پیش
.env.prod.wemix aa0e6fdf22 [eth] Add WEMIX network (#940) 2 سال پیش
.env.prod.wemix_testnet aa0e6fdf22 [eth] Add WEMIX network (#940) 2 سال پیش
.env.prod.zksync bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.prod.zksync_goerli bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.env.template c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
.env.test bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
.gitignore 085f08055a [eth] Add zksync mainnet (#682) 2 سال پیش
Deploying.md c732fcf586 Abolish xc governance sdk (#957) 2 سال پیش
README.md 6f8fa11b20 Fix README.md for prettier (#959) 2 سال پیش
VERIFY.md d06c10502d [evm] Verifying shimmer_testnet and neon_devnet with hardhat (#703) 2 سال پیش
canto-deployment-patch.diff 85b9c80e2a [eth] Add Canto mainnet (#751) 2 سال پیش
deploy.sh c86e4f2610 [eth] Add linea (#956) 2 سال پیش
foundry.toml 19b77e2c84 [ethereum] - charge updateFee per number of updates (#878) 2 سال پیش
hardhat.config.ts e39277dd9c [eth] Add setWormholeAddress governance message (#917) 2 سال پیش
mine.js bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
package.json dcec1e9328 [eth] Finalize accumulator contract (#960) 2 سال پیش
remappings.txt bbe10ba553 [sdk] Move JS sdks into this repo (#611) 2 سال پیش
truffle-config.js 741f763375 Fix mainnet values on fuji and chiado and remove oasis network (#979) 2 سال پیش

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 on the repo root to install required dependencies for the contract:

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

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/target_chains/ethereum/contracts $ bash ../../../scripts/install-foundry.sh

You need to install npm dependencies as described in Installation. Also, you need to run the following command in the contracts directory 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.

Governance tests

There is a separate test suite executed by truffle for testing governance messages and contract upgrades. You can either use tilt to test automatically or 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
    
  2. deploy the contracts:

    cp .env.test .env && npx truffle compile --all && npx truffle migrate
    
  3. Run the test suite:

    npm run test-contract
    

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.