Skip to content

Commit 9698281

Browse files
authored
Merge pull request #43 from jtriley2p/main
Add Generic Deployer Script & Log of Deployments
2 parents 464a82e + a1d8eb3 commit 9698281

5 files changed

Lines changed: 123 additions & 13 deletions

File tree

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
WORMHOLE_CORE=
2+
WORMHOLE_CHAIN_ID=

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ If you are deploying the receiver to a new chain, you will also need to supply a
3232

3333
If you are redeploying the receiver to an existing chain, you will want to deploy the latest copy of the receiver contract for that chain with any changes desired. Similarly, the construction addresses for the Wormhole Core Contracts and sender will need to be supplied. Additionally, you will need to use the current receiver implementation to send a governance message to the Uniswap V3 deployment on that chain to update it's trusted receiver to point to the new implementation.
3434

35+
The receiver contract can be deployed via a Foundry script. The `RPC_URL` environment variable must be set to a valid RPC url and a wallet must be made accessible to the forge script. More on how this can be done [here](https://www.getfoundry.sh/forge/scripting#providing-a-private-key).
36+
37+
```bash
38+
forge script script/DeployReceiver.s.sol --rpc-url $RPC_URL
39+
```
40+
3541
## Unit Tests
3642

3743
Unit tests are written using [forge](https://github.com/foundry-rs/foundry). To run the tests, [install forge](https://getfoundry.sh/) and then:
@@ -40,4 +46,25 @@ Unit tests are written using [forge](https://github.com/foundry-rs/foundry). To
4046

4147
To check the test coverage:
4248

43-
```forge coverage```
49+
```forge coverage```
50+
51+
## Existing Deployments
52+
53+
Sender:
54+
55+
| Network | Address |
56+
| -------- | ----------------------------------------------------------------------------------------------------------------------- |
57+
| Ethereum | [`0xf5F4496219F31CDCBa6130B5402873624585615a`](https://etherscan.io/address/0xf5F4496219F31CDCBa6130B5402873624585615a) |
58+
59+
Receiver:
60+
61+
| Network | Address |
62+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- |
63+
| Celo | [`0x0Eb863541278308c3A64F8E908BC646e27BFD071`](https://celoscan.io/address/0x0Eb863541278308c3A64F8E908BC646e27BFD071) |
64+
| BNB Chain* | [`0x341c1511141022cf8eE20824Ae0fFA3491F1302b`](https://bscscan.com/address/0x341c1511141022cf8eE20824Ae0fFA3491F1302b) |
65+
| MegaETH | [`0xa107580F73BD797Bd8b87Ff24e98346D99F93DdB`](https://mega.etherscan.io/address/0xa107580F73BD797Bd8b87Ff24e98346D99F93DdB) |
66+
| Avalanche | [`0x47eB0Cf11a1626462Da3C830bCDe64c3F582B5a6`](https://snowscan.xyz/address/0x47eB0Cf11a1626462Da3C830bCDe64c3F582B5a6) |
67+
68+
Notices:
69+
70+
**BNBChain**: BNBChain's `UniswapWormholeReceiver` does not match this repository 1:1. Notably, it uses a hard coded, public `BSC_CHAIN_ID` value rather than the public immutable `chainId` used in this repository. Otherwise it is functionally identical.

foundry.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"lib/forge-std": {
3+
"branch": {
4+
"name": "v1.5.0",
5+
"rev": "c2236853aadb8e2d9909bbecdc490099519b70a4"
6+
}
7+
},
8+
"lib/openzeppelin-contracts": {
9+
"branch": {
10+
"name": "v4.8.2",
11+
"rev": "eedca5d873a559140d79cc7ec674d0e28b2b6ebd"
12+
}
13+
},
14+
"lib/wormhole": {
15+
"rev": "36c34bec1cb87e87c9e6264d3d70796f2ace11f7"
16+
}
17+
}

script/DeployReceiver.s.sol

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity 0.8.12;
3+
4+
import {Script, console} from "../lib/forge-std/src/Script.sol";
5+
6+
import {UniswapWormholeMessageReceiver} from "../src/UniswapWormholeMessageReceiver.sol";
7+
8+
/// @title Deployer of UniswapWormholeMessageReceiver
9+
/// @dev `WORMHOLE_CORE` is required; it is the wormhole bridge address on the remote chain.
10+
/// @dev `WORMHOLE_CHAIN_ID` is required; it is the wormhole-defined chain id for the remote chain.
11+
/// @dev `MESSAGE_SENDER` is optional, as we use one unified sender on Ethereum.
12+
contract DeployReceiver is Script {
13+
uint16 internal constant WORMHOLE_ETHEREUM_CHAIN_ID = 2;
14+
15+
function run() external {
16+
// -----------------------------------------------------------------------------------------
17+
// Load environment variables
18+
//
19+
address messageSender = vm.envOr("MESSAGE_SENDER", 0xf5F4496219F31CDCBa6130B5402873624585615a);
20+
address wormholeCore = vm.envAddress("WORMHOLE_CORE");
21+
uint16 wormholeChainId = uint16(vm.envUint("WORMHOLE_CHAIN_ID"));
22+
23+
bytes32 wormholeMessageSender = bytes32(uint256(uint160(messageSender)));
24+
25+
// -----------------------------------------------------------------------------------------
26+
// Deploy the receiver contract.
27+
//
28+
vm.startBroadcast();
29+
UniswapWormholeMessageReceiver receiver = new UniswapWormholeMessageReceiver({
30+
wormholeAddress: wormholeCore, _messageSender: wormholeMessageSender, _chainId: wormholeChainId
31+
});
32+
vm.stopBroadcast();
33+
34+
// -----------------------------------------------------------------------------------------
35+
// Smoke check the deployment.
36+
//
37+
require(receiver.messageSender() == wormholeMessageSender, "mismatch: messageSender");
38+
require(receiver.chainId() == wormholeChainId, "mismatch: chainId");
39+
require(receiver.ETHEREUM_CHAIN_ID() == WORMHOLE_ETHEREUM_CHAIN_ID, "mismatch: ETHEREUM_CHAIN_ID");
40+
require(receiver.nextMinimumSequence() == 0, "mismatch: nextMinimumSequence");
41+
require(receiver.MESSAGE_TIME_OUT_SECONDS() == 2 days, "mismatch: MESSAGE_TIME_OUT_SECONDS");
42+
43+
// -----------------------------------------------------------------------------------------
44+
// Log the output.
45+
//
46+
console.logString(
47+
string.concat(
48+
"Deployed UniswapWormholeMessageReceiver",
49+
"\naddress (target chain): ",
50+
vm.toString(address(receiver)),
51+
"\neip-155 chain id (target chain): ",
52+
vm.toString(block.chainid),
53+
"\nwormhole chain id (target chain): ",
54+
vm.toString(wormholeChainId),
55+
"\nmessage sender (ethereum): ",
56+
vm.toString(messageSender),
57+
"\nwormhole core (target chain): ",
58+
vm.toString(wormholeCore)
59+
)
60+
);
61+
}
62+
}

test/UniswapWormholeMessageSenderReceiver.t.sol

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ contract UniswapWormholeMessageSenderReceiverTest is Test {
4848
wormhole = IWormhole(setupWormhole());
4949

5050
// set up uniswap wormhole message receiver contract
51-
address uniReceiverAddress = address(new UniswapWormholeMessageReceiver(address(wormhole), msgSender, bsc_chain_id));
51+
address uniReceiverAddress =
52+
address(new UniswapWormholeMessageReceiver(address(wormhole), msgSender, bsc_chain_id));
5253
uniReceiver = IUniswapWormholeMessageReceiver(uniReceiverAddress);
5354

5455
// deploy the mock governance contract
@@ -82,14 +83,15 @@ contract UniswapWormholeMessageSenderReceiverTest is Test {
8283

8384
// These values are the default values used in our tilt test environment
8485
// and are not important.
85-
Setup(address(wormholeAddress)).setup(
86-
address(wormholeImpl),
87-
initSigners,
88-
bsc_chain_id, // BSC chain ID
89-
1, // Governance source chain ID (1 = solana)
90-
0x0000000000000000000000000000000000000000000000000000000000000004, // Governance source address
91-
block.chainid // evm chain Id
92-
);
86+
Setup(address(wormholeAddress))
87+
.setup(
88+
address(wormholeImpl),
89+
initSigners,
90+
bsc_chain_id, // BSC chain ID
91+
1, // Governance source chain ID (1 = solana)
92+
0x0000000000000000000000000000000000000000000000000000000000000004, // Governance source address
93+
block.chainid // evm chain Id
94+
);
9395
return address(wormholeAddress);
9496
}
9597

@@ -193,7 +195,7 @@ contract UniswapWormholeMessageSenderReceiverTest is Test {
193195
wormhole = IWormhole(setupWormhole());
194196

195197
// set up uniswap wormhole message receiver contract, with Ethereum as the destination chain ID
196-
vm.expectRevert('Invalid chainId Ethereum');
198+
vm.expectRevert("Invalid chainId Ethereum");
197199
address(new UniswapWormholeMessageReceiver(address(wormhole), msgSender, ethereum_chain_id));
198200
}
199201

@@ -226,7 +228,7 @@ contract UniswapWormholeMessageSenderReceiverTest is Test {
226228
// update the wormhole message fee
227229
updateWormholeMessageFee(newFee);
228230

229-
vm.expectRevert('invalid receiverChainID Ethereum');
231+
vm.expectRevert("invalid receiverChainID Ethereum");
230232
uniSender.sendMessage{value: newFee}(targets, values, datas, address(uniReceiver), ethereum_chain_id);
231233
}
232234

@@ -237,7 +239,7 @@ contract UniswapWormholeMessageSenderReceiverTest is Test {
237239
// update the wormhole message fee
238240
updateWormholeMessageFee(newFee);
239241

240-
vm.expectRevert('invalid receiverChainID Unset');
242+
vm.expectRevert("invalid receiverChainID Unset");
241243
uniSender.sendMessage{value: newFee}(targets, values, datas, address(uniReceiver), unset_chain_id);
242244
}
243245

0 commit comments

Comments
 (0)