pyth-crosschain/target_chains/ethereum/contracts
Amin Moghaddam f2ca88176a
Add shimmer mainnet (#1053)
2023-09-15 18:23:12 +02:00
..
contracts fix(eth): update legacy updateFee method pricing 2023-08-31 11:51:27 +02:00
deploy [evm] Wormhole receiver deploy all (#1009) 2023-08-09 18:22:47 +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 [evm] [cosmwasm] Minor cleanup (#1027) 2023-08-24 11:41:59 +02:00
networks Add shimmer mainnet (#1053) 2023-09-15 18:23:12 +02:00
scripts [contract-manager] General improvements (#1024) 2023-08-23 16:29:43 +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.prod.development [evm] [cosmwasm] Minor cleanup (#1027) 2023-08-24 11:41:59 +02:00
.env.template [evm] [cosmwasm] Minor cleanup (#1027) 2023-08-24 11:41:59 +02:00
.env.test [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
.gitignore chore: add coverage/ to gitignore 2023-08-09 20:58:54 +03:30
Deploying.md [evm] [cosmwasm] Minor cleanup (#1027) 2023-08-24 11:41:59 +02:00
README.md chore(ethereum): add html coverage bits 2023-08-09 20:58:54 +03:30
VERIFY.md [contract-manager] Contract manager improvements (#1000) 2023-08-07 14:13:29 +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
create-env.js [contract-manager] Contract manager improvements (#1000) 2023-08-07 14:13:29 +02:00
deploy.sh [contract-manager] Contract manager improvements (#1000) 2023-08-07 14:13:29 +02:00
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 fix(eth): update legacy updateFee method pricing 2023-08-31 11:51:27 +02:00
remappings.txt [sdk] Move JS sdks into this repo (#611) 2023-02-22 13:44:42 -08:00
truffle-config.js [contract-manager] Contract manager improvements (#1000) 2023-08-07 14:13:29 +02: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. 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 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.