pyth-crosschain/target-chains/ethereum
Stanisław Drozd 01c4661985
Repo structure refactor (#449)
* Repo structure refactor

This change introduces major codebase layout changes in three areas:
* Tilt devnet lives in tilt-devnet/ - all k8s and docker files,
scripts, local testing private keys are moved to this directory.
* pyth2wormhole becomes pyth-wormhole-attester and is relocated to
wormhole-attester/ - This long-needed rename will hopefully eradicate
most of the confusing naming around the attester. The Rust client binary
becomes pyth-wormhole-attester-client.
* Target-chain code lives in target-chain/ - This leaves just the
attester, third_party and pythnet-specific things at top-level.

Other opportunistic changes:
* Fixed rebuild trigger for Dockerfile.wasm

These items are a fraction of the necessary structure changes in the repo.

* cosmwasm: fix contract after faulty merge

* .github: remove unused dependabot config

* Fix path references in .github and .pre-commit-config.yml

* .github: Rename attester references to pyth-wormhole-attester

* .pre-commit-config.yaml: fix paths and run all commit hooks

* p2w-relay: Fix faulty merge resolution in favor of origin/main

* Dockerfile.pyth_relay: Fix Ethereum path reference

* Dockerfile.solana: Trip early cache with arbitrary change

* Dockerfile.pyth_relay: typo

* p2w-relay: fix evm build in npm script

* Dockerfile.solana: Retry invalidating cache again

* near -> target-chains/near

* wormhole-attester: bump on/off-chain major versions due to rename

Attester packages were renamed. This possibly breaks most dependees.

* Dockerfile.solana: Improve decoy-crate to have a real lib target

* .github/[...]/pyth-cosmwasm-contract.yml: typo

* rust-toolchain: Bump rust to stable 1.63

* rust-toolchain: use christmas nightly

* empty commit to trigger build

* attester-image-push.yaml: keep xc-attest image name intact

* multisig-wh-message-builder: remove accidental revert
2023-01-04 14:46:42 +01:00
..
contracts Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
deploy Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
forge-test Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
lib Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
migrations Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
networks Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
scripts Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
test Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.dockerignore Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.cluster.mainnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.cluster.testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.arbitrum Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.arbitrum_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.aurora Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.aurora_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.avalanche Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.bnb Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.bnb_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.celo Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.celo_alfajores_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.cronos Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.cronos_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.development Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.ethereum Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.fantom Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.fantom_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.fuji Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.goerli Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.kcc Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.kcc_testnet Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.mumbai Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.optimism Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.optimism_goerli Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.polygon Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.zksync Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.prod.zksync_goerli Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.template Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.env.test Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
.gitignore Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
Deploying.md Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
README.md Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
VERIFY.md Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
deploy.sh Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
foundry.toml Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
hardhat.config.ts Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
mine.js Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
package-lock.json Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
package.json Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
remappings.txt Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
truffle-config.js Repo structure refactor (#449) 2023-01-04 14:46:42 +01:00
truffle-verify-constants.patch Repo structure refactor (#449) 2023-01-04 14:46:42 +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 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ .............                                                                             ┆ .....           ┆ .....  ┆ .....  ┆ .....   ┆ ..      │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 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.