-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathDeployWormholeNttBase.sol
134 lines (110 loc) · 4.81 KB
/
DeployWormholeNttBase.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: Apache 2
pragma solidity >=0.8.8 <0.9.0;
import {console2} from "forge-std/Script.sol";
import {ParseNttConfig} from "./ParseNttConfig.sol";
import "../../src/interfaces/IManagerBase.sol";
import "../../src/interfaces/INttManager.sol";
import "../../src/interfaces/IWormholeTransceiver.sol";
import {NttManager} from "../../src/NttManager/NttManager.sol";
import {WormholeTransceiver} from
"../../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
contract DeployWormholeNttBase is ParseNttConfig {
struct DeploymentParams {
address token;
IManagerBase.Mode mode;
uint16 wormholeChainId;
uint64 rateLimitDuration;
bool shouldSkipRatelimiter;
address wormholeCoreBridge;
address wormholeRelayerAddr;
address specialRelayerAddr;
uint8 consistencyLevel;
uint256 gasLimit;
uint256 outboundLimit;
}
// The minimum gas limit to verify a message on mainnet. If you're worried about saving
// gas on testnet, pick up the phone and start dialing!
uint256 constant MIN_WORMHOLE_GAS_LIMIT = 150000;
function deployNttManager(
DeploymentParams memory params
) internal returns (address) {
// Deploy the Manager Implementation.
NttManager implementation = new NttManager(
params.token,
params.mode,
params.wormholeChainId,
params.rateLimitDuration,
params.shouldSkipRatelimiter
);
// NttManager Proxy
NttManager nttManagerProxy =
NttManager(address(new ERC1967Proxy(address(implementation), "")));
nttManagerProxy.initialize();
console2.log("NttManager:", address(nttManagerProxy));
return address(nttManagerProxy);
}
function deployWormholeTransceiver(
DeploymentParams memory params,
address nttManager
) public returns (address) {
// Deploy the Wormhole Transceiver.
WormholeTransceiver implementation = new WormholeTransceiver(
nttManager,
params.wormholeCoreBridge,
params.wormholeRelayerAddr,
params.specialRelayerAddr,
params.consistencyLevel,
params.gasLimit
);
WormholeTransceiver transceiverProxy =
WormholeTransceiver(address(new ERC1967Proxy(address(implementation), "")));
transceiverProxy.initialize();
console2.log("WormholeTransceiver:", address(transceiverProxy));
return address(transceiverProxy);
}
function configureNttManager(
address nttManager,
address transceiver,
uint256 outboundLimit,
bool shouldSkipRateLimiter
) public {
IManagerBase(nttManager).setTransceiver(transceiver);
console2.log("Transceiver address set on NttManager: ", transceiver);
if (!shouldSkipRateLimiter) {
INttManager(nttManager).setOutboundLimit(outboundLimit);
console2.log("Outbound rate limit set on NttManager: ", outboundLimit);
}
}
function _readEnvVariables() internal view returns (DeploymentParams memory params) {
// Token address.
params.token = vm.envAddress("RELEASE_TOKEN_ADDRESS");
require(params.token != address(0), "Invalid token address");
// Mode.
uint8 mode = uint8(vm.envUint("RELEASE_MODE"));
if (mode == 0) {
params.mode = IManagerBase.Mode.LOCKING;
} else if (mode == 1) {
params.mode = IManagerBase.Mode.BURNING;
} else {
revert("Invalid mode");
}
// Chain ID.
params.wormholeChainId = uint16(vm.envUint("RELEASE_WORMHOLE_CHAIN_ID"));
require(params.wormholeChainId != 0, "Invalid chain ID");
// Rate limit duration.
params.rateLimitDuration = uint64(vm.envUint("RELEASE_RATE_LIMIT_DURATION"));
params.shouldSkipRatelimiter = vm.envBool("RELEASE_SKIP_RATE_LIMIT");
// Wormhole Core Bridge address.
params.wormholeCoreBridge = vm.envAddress("RELEASE_CORE_BRIDGE_ADDRESS");
require(params.wormholeCoreBridge != address(0), "Invalid wormhole core bridge address");
// Wormhole relayer, special relayer, consistency level.
params.wormholeRelayerAddr = vm.envAddress("RELEASE_WORMHOLE_RELAYER_ADDRESS");
params.specialRelayerAddr = vm.envAddress("RELEASE_SPECIAL_RELAYER_ADDRESS");
params.consistencyLevel = uint8(vm.envUint("RELEASE_CONSISTENCY_LEVEL"));
params.gasLimit = vm.envUint("RELEASE_GAS_LIMIT");
require(params.gasLimit >= MIN_WORMHOLE_GAS_LIMIT, "Invalid gas limit");
// Outbound rate limiter limit.
params.outboundLimit = vm.envUint("RELEASE_OUTBOUND_LIMIT");
}
}