pyth-crosschain/target_chains/ethereum/contracts
Mohammad Amin Khashkhashi Moghaddam 175dfef5bd
Deploy to the latest shimmer testnet (#1001)
2023-08-02 16:59:39 +01:00
..
contracts [eth] Finalize accumulator contract (#960) 2023-07-18 12:57:29 +03:30
deploy Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
forge-test [eth] - Aave FallbackOracle Integration (#924) 2023-07-06 08:29:08 -04:00
lib [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
migrations Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
networks Deploy to the latest shimmer testnet (#1001) 2023-08-02 16:59:39 +01:00
scripts Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
test Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
.dockerignore [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.cluster.mainnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.cluster.testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.arbitrum [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.arbitrum_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.aurora [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.aurora_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.avalanche [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.base chore(ethereum): deploy to base and syndr_testnet (#988) 2023-07-27 16:16:45 +03:30
.env.prod.base_goerli Add base goerli config (#668) 2023-03-08 09:48:24 +01:00
.env.prod.bnb [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.bnb_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.canto [eth] Add Canto mainnet (#751) 2023-04-07 17:49:01 +02:00
.env.prod.canto_testnet [evm] Deploy on Canto Testnet (#725) 2023-03-29 19:15:08 +02:00
.env.prod.celo [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.celo_alfajores_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.chiado [eth] Add new testnets (#669) 2023-03-08 10:01:05 +01:00
.env.prod.conflux_espace [eth] Deploy to Conflux eSpace (#748) 2023-04-07 16:23:20 +02:00
.env.prod.conflux_espace_testnet [eth] Deploy to Conflux eSpace (#748) 2023-04-07 16:23:20 +02:00
.env.prod.cronos [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.cronos_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.development [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.eos [eth] Add EOS network (#963) 2023-07-18 23:00:47 +03:30
.env.prod.eos_testnet [eth] Add EOS network (#963) 2023-07-18 23:00:47 +03:30
.env.prod.ethereum [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.evmos [eth] add evmos mainnet (#686) 2023-03-14 18:12:49 +09:00
.env.prod.evmos_testnet [eth] add evmos testnet (#683) 2023-03-14 14:11:23 +09:00
.env.prod.fantom [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.fantom_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.fuji [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.gnosis [eth] Deploy to gnosis mainnet (#892) 2023-06-15 20:58:39 +02:00
.env.prod.goerli [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.kava [eth] Deploy to Kava (#859) 2023-06-07 15:29:03 +02:00
.env.prod.kava_testnet [eth] Deploy to Kava (#859) 2023-06-07 15:29:03 +02:00
.env.prod.kcc [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.kcc_testnet [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.linea [eth] Add linea (#956) 2023-07-17 17:51:22 +03:30
.env.prod.linea_goerli [eth] Add Linea goerli network (#947) 2023-07-11 11:15:22 +01:00
.env.prod.mantle [eth] Deploy to mantle (#948) 2023-07-12 14:18:56 +01:00
.env.prod.mantle_testnet [eth] Deploy to testnet Mantle (#742) 2023-04-04 13:34:32 +02:00
.env.prod.meter [eth] Deploy to meter (#731) 2023-03-31 18:51:18 +02:00
.env.prod.meter_testnet [eth] Deploy to meter (#731) 2023-03-31 18:51:18 +02:00
.env.prod.mumbai [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.neon Deploy neon (#854) 2023-06-02 11:29:35 +01:00
.env.prod.neon_devnet [evm] deploy neon devnet (#693) 2023-03-14 22:48:46 -05:00
.env.prod.optimism [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.optimism_goerli [eth] Deploy to Kava (#859) 2023-06-07 15:29:03 +02:00
.env.prod.polygon [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.polygon_zkevm [evm] Deploy on Polygon ZkEVM mainnet (#723) 2023-03-27 08:18:09 -07:00
.env.prod.polygon_zkevm_testnet [evm] Polygon ZKEVM deployment (#711) 2023-03-22 13:04:47 -07:00
.env.prod.shimmer_testnet Deploy to the latest shimmer testnet (#1001) 2023-08-02 16:59:39 +01:00
.env.prod.syndr_nitro_testnet chore(ethereum): deploy to base and syndr_testnet (#988) 2023-07-27 16:16:45 +03:30
.env.prod.wemix [eth] Add WEMIX network (#940) 2023-07-05 18:15:43 +01:00
.env.prod.wemix_testnet [eth] Add WEMIX network (#940) 2023-07-05 18:15:43 +01:00
.env.prod.zksync [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.prod.zksync_goerli [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.env.template Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
.env.test [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.gitignore [eth] Add zksync mainnet (#682) 2023-03-13 09:12:46 +01:00
Deploying.md Abolish xc governance sdk (#957) 2023-07-17 15:24:54 +02:00
README.md Fix README.md for prettier (#959) 2023-07-17 16:42:03 +02:00
VERIFY.md [evm] Verifying shimmer_testnet and neon_devnet with hardhat (#703) 2023-03-17 09:47:59 -05:00
canto-deployment-patch.diff [eth] Add Canto mainnet (#751) 2023-04-07 17:49:01 +02:00
deploy.sh [eth] Add linea (#956) 2023-07-17 17:51:22 +03:30
foundry.toml [ethereum] - charge updateFee per number of updates (#878) 2023-06-13 07:25:46 -07:00
hardhat.config.ts [eth] Add setWormholeAddress governance message (#917) 2023-06-26 11:31:19 +02:00
mine.js [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
package.json chore(ethereum): deploy to base and syndr_testnet (#988) 2023-07-27 16:16:45 +03:30
remappings.txt [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
truffle-config.js Deploy to the latest shimmer testnet (#1001) 2023-08-02 16:59:39 +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 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
  1. deploy the contracts:
cp .env.test .env && npx truffle compile --all && npx truffle migrate
  1. 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.