Skip to content

Commit fe7c621

Browse files
committed
remove truffle and replace with foundry
1 parent e62f2eb commit fe7c621

File tree

16 files changed

+395
-1106
lines changed

16 files changed

+395
-1106
lines changed

target_chains/ethereum/contracts/README.md

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,71 @@ npm run coverage
3434

3535
Open `coverage/index.html` in your web browser to see the results.
3636

37-
### Governance tests
37+
## Deployment
3838

39-
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:
39+
To deploy the contracts, you'll need to set up your environment variables and use the Foundry deployment script.
4040

41-
1. Spawn a new network on a seperate terminal (do not close it while running tests):
41+
1. Copy the environment template and fill in your values:
4242

4343
```bash
44-
pnpm dlx ganache-cli -e 10000 --deterministic --time="1970-01-02T00:00:00+00:00" --host=0.0.0.0
44+
cp deploy.env.example .env
45+
# Edit .env with your configuration
4546
```
4647

47-
2. deploy the contracts:
48+
2. Deploy to a local network (for testing):
4849

4950
```bash
50-
cp .env.test .env && pnpm exec truffle compile --all && pnpm exec truffle migrate --network development
51+
# Start a local node
52+
anvil
53+
54+
# In another terminal, deploy the contracts
55+
npm run deploy-local
56+
```
57+
58+
3. Deploy to a live network:
59+
60+
```bash
61+
# Make sure your .env file has the correct RPC_URL and PRIVATE_KEY
62+
npm run deploy
5163
```
5264

53-
3. Run the test suite:
65+
The deployment script will:
66+
- Deploy the Wormhole contracts (Setup, Implementation, and Wormhole proxy)
67+
- Deploy the Pyth contracts (PythUpgradable with ERC1967 proxy)
68+
- Configure all necessary parameters from environment variables
69+
70+
### Guardian Set Sync
71+
72+
After deploying Wormhole contracts on mainnet, you need to sync the guardian sets to match the current mainnet state:
5473

5574
```bash
56-
npm run test-contract
75+
# Set WORMHOLE_ADDRESS in your .env file to the deployed Wormhole contract address
76+
npm run sync-guardian-sets
5777
```
5878

79+
This script submits the pre-configured mainnet guardian set upgrade VAAs to bring your contract up to date with the current mainnet guardian set.
80+
81+
### Utility Scripts
82+
83+
Additional utility scripts are available for testing and development:
84+
85+
#### Create Governance VAA (for testing)
86+
87+
```bash
88+
# Create a governance VAA for localnet testing
89+
GOVERNANCE_DATA=0x... npm run create-governance-vaa
90+
```
91+
92+
This script creates a properly signed governance VAA for local testing. You can customize it with environment variables:
93+
- `TIMESTAMP` - VAA timestamp (defaults to current block timestamp)
94+
- `NONCE` - VAA nonce (defaults to 0)
95+
- `EMITTER_CHAIN_ID` - Chain ID of the emitter (defaults to 1)
96+
- `EMITTER_ADDRESS` - Address of the emitter (defaults to test address)
97+
- `SEQUENCE` - VAA sequence number (defaults to 0)
98+
- `GOVERNANCE_DATA` - The governance payload data (required)
99+
- `GUARDIAN_SET_INDEX` - Guardian set index (defaults to 0)
100+
- `CONSISTENCY_LEVEL` - Consistency level (defaults to 32)
101+
59102
### Gas Benchmarks
60103

61104
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

target_chains/ethereum/contracts/VERIFY.md

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ Most of the explorers accept the standard json-input format, while some only acc
1717
Pyth contract address refers to the proxy contract. After verifying the proxy contract, the implementation contract needs to be verified as well.
1818

1919
Use the verification files in the release to verify the contracts on the explorer sites.
20-
You can find the compiler configurations in [`truffle-config.js`](./truffle-config.js) by searching for `compilers`.
20+
You can find the compiler configurations in [`foundry.toml`](./foundry.toml).
2121
The required configurations are the _solc version_ and the _optimizer runs_.
2222

23-
## Verifying the contract via truffle or hardhat
23+
## Verifying the contract via Foundry or Hardhat
2424

25-
Although, verification via explorers is the recommended way, you can also verify the contracts using truffle or hardhat.
25+
Although, verification via explorers is the recommended way, you can also verify the contracts using Foundry or Hardhat.
2626
In general, you will need an API key for the relevant explorer (this can be obtained by creating an account),
2727
and also know which address the contract code lives. The API key is expected to
2828
be set in the `ETHERSCAN_KEY` environment variable for all APIs (not just etherscan, bit of a misnomer).
@@ -31,44 +31,21 @@ be set in the `ETHERSCAN_KEY` environment variable for all APIs (not just ethers
3131
ETHERSCAN_KEY=... npm run verify --module=PythUpgradable --contract_address=0x0e082F06FF657D94310cB8cE8B0D9a04541d8052 --network=avalanche
3232
```
3333

34-
(Note: the network name comes from the `truffle-config.json`).
3534
(Note: In this case, the `ETHERSCAN_KEY` is your snowtrace API key).
3635

37-
**You might need to add the explorer api keys in [the truffle config](./truffle-config.js) `api_keys`.** Please look at
38-
`truffle-plugin-verify/utils.js` to find the key names. Here is an example:
36+
For Foundry verification, you can use the built-in verification feature by adding `--verify` to your deployment command:
3937

40-
```js
41-
{
42-
compilers: [...],
43-
44-
api_keys: {
45-
etherscan: process.env.ETHERSCAN_KEY,
46-
bscscan: process.env.BSCSCAN_KEY,
47-
snowtrace: process.env.SNOWTRACE_KEY,
48-
},
49-
50-
plugins: [...]
51-
}
38+
```bash
39+
forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY
5240
```
5341

54-
# Note
55-
56-
The `npm run verify` script uses the `truffle-plugin-verify` plugin under the
57-
hood. The version of `truffle-plugin-verify` pinned in the repo (`^0.5.11` at
58-
the time of writing) doesn't support the avalanche RPC. In later versions of the
59-
plugin, support was added, but other stuff has changed as well in the transitive
60-
dependencies, so it fails to parse the `HDWallet` arguments in our
61-
`truffle-config.json`. As a quick workaround, we backport the patch to `0.5.11`
62-
by applying the `truffle-verify-constants.patch` file, which the `npm run verify` script does transparently. Once the toolchain has been upgraded and the
63-
errors fixed, this patch can be removed.
64-
65-
### Verifying with hardhat
42+
### Verifying with Hardhat
6643

67-
Some chains might require users to verify with hardhat. Here are the additional steps :
44+
Some chains might require users to verify with Hardhat. Here are the additional steps:
6845

69-
- Add the chain to `networks` in `hardhat.config.ts` (equivalent of `truffle-config.js`)
46+
- Add the chain to `networks` in `hardhat.config.ts`
7047
- Add the explorer parameters to `etherscan` in `hardhat.config.ts`
71-
- Run :
48+
- Run:
7249

7350
```
7451
MNEMONIC=... pnpm exec hardhat verify 0x354bF866A4B006C9AF9d9e06d9364217A8616E12 --network shimmer_testnet

target_chains/ethereum/contracts/contracts/Migrations.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Deployment Configuration
2+
PRIVATE_KEY=your_private_key_here
3+
4+
# Wormhole Configuration
5+
INIT_SIGNERS=["0x...","0x..."] # JSON array of initial guardian public keys
6+
INIT_CHAIN_ID=1 # Chain ID for this deployment
7+
INIT_GOV_CHAIN_ID=1 # Governance chain ID
8+
INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
9+
10+
# Pyth Configuration
11+
SOLANA_CHAIN_ID=1 # Solana chain ID for Pyth data source
12+
SOLANA_EMITTER=0x... # Pyth emitter address on Solana
13+
GOVERNANCE_CHAIN_ID=1 # Governance chain ID
14+
GOVERNANCE_EMITTER=0x... # Governance emitter address
15+
GOVERNANCE_INITIAL_SEQUENCE=0 # Initial governance sequence number
16+
VALID_TIME_PERIOD_SECONDS=60 # Valid time period for price updates in seconds
17+
SINGLE_UPDATE_FEE_IN_WEI=1000000000000000 # Fee for single price update in wei
18+
19+
# RPC Configuration
20+
RPC_URL=https://rpc.ankr.com/eth
21+
ETHERSCAN_API_KEY=your_etherscan_api_key_here
22+
23+
# Guardian Set Sync Configuration
24+
WORMHOLE_ADDRESS=0x... # Address of the deployed Wormhole contract

target_chains/ethereum/contracts/foundry.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ evm_version = "paris"
44
optimizer = true
55
optimizer_runs = 200
66
src = 'contracts'
7-
# We put the tests into the forge-test directory (instead of test) so that
8-
# truffle doesn't try to build them
7+
# Tests are in the forge-test directory
98
test = 'forge-test'
109

1110
libs = ['lib', 'node_modules']

target_chains/ethereum/contracts/migrations/test/1_initial_migration.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

target_chains/ethereum/contracts/migrations/test/2_deploy_wormhole.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

target_chains/ethereum/contracts/migrations/test/3_deploy_pyth.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

target_chains/ethereum/contracts/package.json

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@
44
"description": "",
55
"private": "true",
66
"devDependencies": {
7-
"@openzeppelin/test-helpers": "^0.5.15",
8-
"@openzeppelin/truffle-upgrades": "^1.14.0",
9-
"@truffle/hdwallet-provider": "^2.1.5",
107
"@types/chai": "^4.3.4",
118
"chai": "^4.2.0",
129
"mocha": "^8.2.1",
1310
"prettier": "catalog:",
14-
"prettier-plugin-solidity": "catalog:",
15-
"truffle": "^5.7.4",
16-
"truffle-deploy-registry": "^0.5.1",
17-
"truffle-plugin-stdjsonin": "github:mhrsalehi/truffle-plugin-stdjsonin",
18-
"truffle-plugin-verify": "^0.6.1"
11+
"prettier-plugin-solidity": "catalog:"
1912
},
2013
"scripts": {
21-
"build": "rm -rf build && truffle compile --all",
22-
"test-contract": "truffle test",
23-
"migrate": "truffle migrate",
24-
"receiver-submit-guardian-sets": "truffle exec scripts/receiverSubmitGuardianSetUpgrades.js",
25-
"verify": "truffle run verify $npm_config_module@$npm_config_contract_address --network $npm_config_network",
14+
"build": "forge build",
15+
"test": "forge test",
16+
"test-contract": "forge test",
17+
"deploy": "forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify",
18+
"deploy-local": "forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast",
19+
"sync-guardian-sets": "forge script script/SyncGuardianSets.s.sol --rpc-url $RPC_URL --broadcast",
20+
"create-governance-vaa": "forge script script/CreateLocalnetGovernanceVaa.s.sol",
2621
"install-forge-deps": "forge install foundry-rs/[email protected] --no-git",
2722
"coverage": "./coverage.sh",
2823
"test:format": "prettier --check .",
@@ -53,7 +48,6 @@
5348
"jsonfile": "^4.0.0",
5449
"lodash": "^4.17.21",
5550
"solc": "0.8.4",
56-
"truffle-contract-size": "^2.0.1",
5751
"ts-node": "catalog:",
5852
"typescript": "catalog:",
5953
"web3": "^1.2.2",

target_chains/ethereum/contracts/remappings.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
ds-test/=lib/forge-std/lib/ds-test/src/
55
forge-std/=lib/forge-std/src/
66
@nomad-xyz=./node_modules/@nomad-xyz/
7-
truffle/=./node_modules/truffle/

0 commit comments

Comments
 (0)