@@ -3,7 +3,6 @@ pragma solidity ^0.8.0;
3
3
4
4
import {Vm} from "forge-std/Vm.sol " ;
5
5
import {console} from "forge-std/console.sol " ;
6
- import {strings} from "solidity-stringutils/src/strings.sol " ;
7
6
8
7
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol " ;
9
8
@@ -18,8 +17,6 @@ import {ProposeUpgradeResponse, ApprovalProcessResponse} from "../Defender.sol";
18
17
* WARNING: DO NOT USE DIRECTLY. Use Defender.sol instead.
19
18
*/
20
19
library DefenderDeploy {
21
- using strings for * ;
22
-
23
20
function deploy (
24
21
string memory contractName ,
25
22
bytes memory constructorData ,
@@ -54,7 +51,7 @@ library DefenderDeploy {
54
51
) internal view returns (string [] memory ) {
55
52
Vm vm = Vm (Utils.CHEATCODE_ADDRESS);
56
53
57
- if (! (defenderOpts.licenseType).toSlice (). empty () ) {
54
+ if (bytes (defenderOpts.licenseType).length != 0 ) {
58
55
if (defenderOpts.skipVerifySourceCode) {
59
56
revert ("The `licenseType` option cannot be used when the `skipVerifySourceCode` option is `true` " );
60
57
} else if (defenderOpts.skipLicenseType) {
@@ -86,14 +83,14 @@ library DefenderDeploy {
86
83
if (defenderOpts.skipVerifySourceCode) {
87
84
inputBuilder[i++ ] = "--verifySourceCode " ;
88
85
inputBuilder[i++ ] = "false " ;
89
- } else if (! (defenderOpts.licenseType).toSlice (). empty () ) {
86
+ } else if (bytes (defenderOpts.licenseType).length != 0 ) {
90
87
inputBuilder[i++ ] = "--licenseType " ;
91
88
inputBuilder[i++ ] = string (abi.encodePacked ('" ' , defenderOpts.licenseType, '" ' ));
92
- } else if (! defenderOpts.skipLicenseType && ! (contractInfo.license).toSlice (). empty () ) {
89
+ } else if (! defenderOpts.skipLicenseType && bytes (contractInfo.license).length != 0 ) {
93
90
inputBuilder[i++ ] = "--licenseType " ;
94
91
inputBuilder[i++ ] = string (abi.encodePacked ('" ' , _toLicenseType (contractInfo), '" ' ));
95
92
}
96
- if (! (defenderOpts.relayerId).toSlice (). empty () ) {
93
+ if (bytes (defenderOpts.relayerId).length != 0 ) {
97
94
inputBuilder[i++ ] = "--relayerId " ;
98
95
inputBuilder[i++ ] = defenderOpts.relayerId;
99
96
}
@@ -117,7 +114,7 @@ library DefenderDeploy {
117
114
inputBuilder[i++ ] = "--maxPriorityFeePerGas " ;
118
115
inputBuilder[i++ ] = Strings.toString (defenderOpts.txOverrides.maxPriorityFeePerGas);
119
116
}
120
- if (! (defenderOpts.metadata).toSlice (). empty () ) {
117
+ if (bytes (defenderOpts.metadata).length != 0 ) {
121
118
inputBuilder[i++ ] = "--metadata " ;
122
119
inputBuilder[i++ ] = string (abi.encodePacked ('" ' , vm.replace (defenderOpts.metadata, '" ' , '\ \" ' ), '" ' ));
123
120
}
@@ -133,35 +130,37 @@ library DefenderDeploy {
133
130
return inputs;
134
131
}
135
132
133
+ using Strings for string ;
134
+
136
135
function _toLicenseType (ContractInfo memory contractInfo ) private pure returns (string memory ) {
137
- strings.slice memory id = contractInfo.license. toSlice () ;
138
- if (id.equals ("UNLICENSED " . toSlice () )) {
136
+ string memory id = contractInfo.license;
137
+ if (id.equal ("UNLICENSED " )) {
139
138
return "None " ;
140
- } else if (id.equals ("Unlicense " . toSlice () )) {
139
+ } else if (id.equal ("Unlicense " )) {
141
140
return "Unlicense " ;
142
- } else if (id.equals ("MIT " . toSlice () )) {
141
+ } else if (id.equal ("MIT " )) {
143
142
return "MIT " ;
144
- } else if (id.equals ("GPL-2.0-only " . toSlice ()) || id.equals ("GPL-2.0-or-later " . toSlice () )) {
143
+ } else if (id.equal ("GPL-2.0-only " ) || id.equal ("GPL-2.0-or-later " )) {
145
144
return "GNU GPLv2 " ;
146
- } else if (id.equals ("GPL-3.0-only " . toSlice ()) || id.equals ("GPL-3.0-or-later " . toSlice () )) {
145
+ } else if (id.equal ("GPL-3.0-only " ) || id.equal ("GPL-3.0-or-later " )) {
147
146
return "GNU GPLv3 " ;
148
- } else if (id.equals ("LGPL-2.1-only " . toSlice ()) || id.equals ("LGPL-2.1-or-later " . toSlice () )) {
147
+ } else if (id.equal ("LGPL-2.1-only " ) || id.equal ("LGPL-2.1-or-later " )) {
149
148
return "GNU LGPLv2.1 " ;
150
- } else if (id.equals ("LGPL-3.0-only " . toSlice ()) || id.equals ("LGPL-3.0-or-later " . toSlice () )) {
149
+ } else if (id.equal ("LGPL-3.0-only " ) || id.equal ("LGPL-3.0-or-later " )) {
151
150
return "GNU LGPLv3 " ;
152
- } else if (id.equals ("BSD-2-Clause " . toSlice () )) {
151
+ } else if (id.equal ("BSD-2-Clause " )) {
153
152
return "BSD-2-Clause " ;
154
- } else if (id.equals ("BSD-3-Clause " . toSlice () )) {
153
+ } else if (id.equal ("BSD-3-Clause " )) {
155
154
return "BSD-3-Clause " ;
156
- } else if (id.equals ("MPL-2.0 " . toSlice () )) {
155
+ } else if (id.equal ("MPL-2.0 " )) {
157
156
return "MPL-2.0 " ;
158
- } else if (id.equals ("OSL-3.0 " . toSlice () )) {
157
+ } else if (id.equal ("OSL-3.0 " )) {
159
158
return "OSL-3.0 " ;
160
- } else if (id.equals ("Apache-2.0 " . toSlice () )) {
159
+ } else if (id.equal ("Apache-2.0 " )) {
161
160
return "Apache-2.0 " ;
162
- } else if (id.equals ("AGPL-3.0-only " . toSlice ()) || id.equals ("AGPL-3.0-or-later " . toSlice () )) {
161
+ } else if (id.equal ("AGPL-3.0-only " ) || id.equal ("AGPL-3.0-or-later " )) {
163
162
return "GNU AGPLv3 " ;
164
- } else if (id.equals ("BUSL-1.1 " . toSlice () )) {
163
+ } else if (id.equal ("BUSL-1.1 " )) {
165
164
return "BSL 1.1 " ;
166
165
} else {
167
166
revert (
@@ -217,7 +216,7 @@ library DefenderDeploy {
217
216
return parseProposeUpgradeResponse (stdout);
218
217
}
219
218
220
- function parseProposeUpgradeResponse (string memory stdout ) internal pure returns (ProposeUpgradeResponse memory ) {
219
+ function parseProposeUpgradeResponse (string memory stdout ) internal returns (ProposeUpgradeResponse memory ) {
221
220
ProposeUpgradeResponse memory response;
222
221
response.proposalId = _parseLine ("Proposal ID: " , stdout, true );
223
222
response.url = _parseLine ("Proposal URL: " , stdout, false );
@@ -228,15 +227,26 @@ library DefenderDeploy {
228
227
string memory expectedPrefix ,
229
228
string memory stdout ,
230
229
bool required
231
- ) private pure returns (string memory ) {
232
- strings.slice memory delim = expectedPrefix.toSlice ();
233
- if (stdout.toSlice ().contains (delim)) {
234
- strings.slice memory slice = stdout.toSlice ().copy ().find (delim).beyond (delim);
235
- // Remove any following lines
236
- if (slice.contains ("\n " .toSlice ())) {
237
- slice = slice.split ("\n " .toSlice ());
230
+ ) private returns (string memory ) {
231
+ Vm vm = Vm (Utils.CHEATCODE_ADDRESS);
232
+ if (vm.contains (stdout, expectedPrefix)) {
233
+ // Get the substring after the prefix
234
+ string [] memory segments = vm.split (stdout, expectedPrefix);
235
+ if (segments.length > 2 ) {
236
+ revert (
237
+ string (
238
+ abi.encodePacked (
239
+ "Found multiple occurrences of prefix ' " ,
240
+ expectedPrefix,
241
+ "' in output: " ,
242
+ stdout
243
+ )
244
+ )
245
+ );
238
246
}
239
- return slice.toString ();
247
+ string memory suffix = segments[1 ];
248
+ // Keep only the first line
249
+ return vm.split (suffix, "\n " )[0 ];
240
250
} else if (required) {
241
251
revert (
242
252
string (abi.encodePacked ("Failed to find line with prefix ' " , expectedPrefix, "' in output: " , stdout))
@@ -276,7 +286,7 @@ library DefenderDeploy {
276
286
inputBuilder[i++ ] = "--proxyAdminAddress " ;
277
287
inputBuilder[i++ ] = vm.toString (proxyAdminAddress);
278
288
}
279
- if (! (opts.defender.upgradeApprovalProcessId).toSlice (). empty () ) {
289
+ if (bytes (opts.defender.upgradeApprovalProcessId).length != 0 ) {
280
290
inputBuilder[i++ ] = "--approvalProcessId " ;
281
291
inputBuilder[i++ ] = opts.defender.upgradeApprovalProcessId;
282
292
}
@@ -303,15 +313,15 @@ library DefenderDeploy {
303
313
return parseApprovalProcessResponse (stdout);
304
314
}
305
315
306
- function parseApprovalProcessResponse (string memory stdout ) internal pure returns (ApprovalProcessResponse memory ) {
316
+ function parseApprovalProcessResponse (string memory stdout ) internal returns (ApprovalProcessResponse memory ) {
307
317
Vm vm = Vm (Utils.CHEATCODE_ADDRESS);
308
318
309
319
ApprovalProcessResponse memory response;
310
320
311
321
response.approvalProcessId = _parseLine ("Approval process ID: " , stdout, true );
312
322
313
323
string memory viaString = _parseLine ("Via: " , stdout, false );
314
- if (viaString. toSlice (). len () != 0 ) {
324
+ if (bytes (viaString). length != 0 ) {
315
325
response.via = vm.parseAddress (viaString);
316
326
}
317
327
0 commit comments