-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDeployBase.s.sol
More file actions
252 lines (211 loc) · 9.86 KB
/
DeployBase.s.sol
File metadata and controls
252 lines (211 loc) · 9.86 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;
import { DeployHelpers } from "../../lib/common/script/deploy/DeployHelpers.sol";
import { Options } from "../../lib/openzeppelin-foundry-upgrades/src/Options.sol";
import { Upgrades } from "../../lib/openzeppelin-foundry-upgrades/src/Upgrades.sol";
import { ScriptBase } from "../ScriptBase.s.sol";
import { MEarnerManager } from "../../src/projects/earnerManager/MEarnerManager.sol";
import { MYieldToOne } from "../../src/projects/yieldToOne/MYieldToOne.sol";
import { MYieldToOneForcedTransfer } from "../../src/projects/yieldToOne/MYieldToOneForcedTransfer.sol";
import { MYieldFee } from "../../src/projects/yieldToAllWithFee/MYieldFee.sol";
import { JMIExtension } from "../../src/projects/jmi/JMIExtension.sol";
import { SwapFacility } from "../../src/swap/SwapFacility.sol";
import { UniswapV3SwapAdapter } from "../../src/swap/UniswapV3SwapAdapter.sol";
import { console } from "forge-std/console.sol";
contract DeployBase is DeployHelpers, ScriptBase {
Options public deployOptions;
/**
* @notice Checks if PREDICTED_ADDRESS env var is set
* @return True if PREDICTED_ADDRESS is set, false otherwise
*/
function _shouldVerifyPredictedAddress() internal view returns (bool) {
return vm.envOr("PREDICTED_ADDRESS", address(0)) != address(0);
}
/**
* @notice Verifies predicted address against computed CREATE3 address
* @dev Computes expected address and compares with PREDICTED_ADDRESS env var
* @param deployer The deployer address
* @param contractName Contract Name used for salt computation
*/
function _verifyPredictedAddress(address deployer, string memory contractName) internal view {
address predictedAddress = vm.envAddress("PREDICTED_ADDRESS");
address computedAddress = _getCreate3Address(deployer, _computeSalt(deployer, contractName));
console.log("================================================================================");
console.log(string.concat("PREDICTED_ADDRESS verification for ", contractName));
console.log("================================================================================");
console.log("Predicted address: ", predictedAddress);
console.log("Computed address: ", computedAddress);
require(
computedAddress == predictedAddress,
string.concat(
contractName,
" address mismatch! Predicted: ",
vm.toString(predictedAddress),
", but computed: ",
vm.toString(computedAddress)
)
);
console.log("--------------------------------------------------------------------------------");
console.log(string.concat("SUCCESS: Address verification passed for ", contractName, "!"));
console.log("================================================================================");
}
function _deploySwapFacility(
address deployer,
address pauser
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new SwapFacility(config.mToken, config.registrar));
proxy = _deployCreate3TransparentProxy(
implementation,
config.admin,
abi.encodeWithSelector(SwapFacility.initialize.selector, config.admin, pauser),
_computeSalt(deployer, "SwapFacility")
);
proxyAdmin = Upgrades.getAdminAddress(proxy);
}
function _deploySwapAdapter(address deployer) internal returns (address swapAdapter) {
DeployConfig memory config = _getDeployConfig(block.chainid);
swapAdapter = _deployCreate3(
abi.encodePacked(
type(UniswapV3SwapAdapter).creationCode,
abi.encode(
config.wrappedMToken,
_getSwapFacility(),
config.uniswapV3Router,
config.admin,
_getWhitelistedTokens(block.chainid)
)
),
_computeSalt(deployer, "SwapAdapter")
);
}
function _deployMEarnerManager(
address deployer,
MEarnerManagerConfig memory extensionConfig
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new MEarnerManager(config.mToken, _getSwapFacility()));
proxy = _deployCreate3TransparentProxy(
implementation,
extensionConfig.admin,
abi.encodeWithSelector(
MEarnerManager.initialize.selector,
extensionConfig.extensionName,
extensionConfig.symbol,
extensionConfig.admin,
extensionConfig.earnerManager,
extensionConfig.feeRecipient,
extensionConfig.pauser
),
_computeSalt(deployer, extensionConfig.contractName)
);
proxyAdmin = Upgrades.getAdminAddress(proxy);
return (implementation, proxy, proxyAdmin);
}
function _deployYieldToOne(
address deployer,
YieldToOneConfig memory extensionConfig
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new MYieldToOne(config.mToken, _getSwapFacility()));
proxy = _deployCreate3TransparentProxy(
implementation,
extensionConfig.admin,
abi.encodeWithSelector(
MYieldToOne.initialize.selector,
extensionConfig.extensionName,
extensionConfig.symbol,
extensionConfig.yieldRecipient,
extensionConfig.admin,
extensionConfig.freezeManager,
extensionConfig.yieldRecipientManager,
extensionConfig.pauser
),
_computeSalt(deployer, extensionConfig.contractName)
);
proxyAdmin = Upgrades.getAdminAddress(proxy);
}
function _deployYieldToOneForcedTransfer(
address deployer,
YieldToOneForcedTransferConfig memory extensionConfig
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new MYieldToOneForcedTransfer(config.mToken, _getSwapFacility()));
proxy = _deployCreate3TransparentProxy(
implementation,
0x8Cfac65f5621D699f9efAa84DDaff2A88eeEa405, // Moonpay Proxy Admin
abi.encodeWithSelector(
MYieldToOneForcedTransfer.initialize.selector,
extensionConfig.extensionName,
extensionConfig.symbol,
extensionConfig.yieldRecipient,
extensionConfig.admin,
extensionConfig.freezeManager,
extensionConfig.yieldRecipientManager,
extensionConfig.pauser,
extensionConfig.forcedTransferManager
),
_computeSalt(deployer, extensionConfig.contractName)
);
proxyAdmin = Upgrades.getAdminAddress(proxy);
}
function _deployJMIExtension(
address deployer,
JMIExtensionConfig memory extensionConfig
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new JMIExtension(config.mToken, _getSwapFacility()));
proxy = _deployCreate3TransparentProxy(
implementation,
extensionConfig.admin,
abi.encodeWithSelector(
JMIExtension.initialize.selector,
extensionConfig.extensionName,
extensionConfig.symbol,
extensionConfig.yieldRecipient,
extensionConfig.admin,
extensionConfig.assetCapManager,
extensionConfig.freezeManager,
extensionConfig.pauser,
extensionConfig.yieldRecipientManager
),
_computeSalt(deployer, extensionConfig.contractName)
);
proxyAdmin = Upgrades.getAdminAddress(proxy);
}
function _deployYieldToAllWithFee(
address deployer,
YieldToAllWithFeeConfig memory extensionConfig
) internal returns (address implementation, address proxy, address proxyAdmin) {
DeployConfig memory config = _getDeployConfig(block.chainid);
implementation = address(new MYieldFee(config.mToken, _getSwapFacility()));
// delegate to helper function to avoid stack too deep
proxy = _deployYieldToAllWithFeeProxy(deployer, implementation, extensionConfig);
proxyAdmin = Upgrades.getAdminAddress(proxy);
return (implementation, proxy, proxyAdmin);
}
// helper function to avoid stack too deep
function _deployYieldToAllWithFeeProxy(
address deployer,
address implementation,
YieldToAllWithFeeConfig memory extensionConfig
) private returns (address proxy) {
proxy = _deployCreate3TransparentProxy(
implementation,
extensionConfig.admin,
abi.encodeWithSelector(
MYieldFee.initialize.selector,
extensionConfig.extensionName,
extensionConfig.symbol,
extensionConfig.feeRate,
extensionConfig.feeRecipient,
extensionConfig.admin,
extensionConfig.feeManager,
extensionConfig.claimRecipientManager,
extensionConfig.freezeManager,
extensionConfig.pauser
),
_computeSalt(deployer, extensionConfig.contractName)
);
}
}