Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script for deterministic deployment, remove ffi, support stdJson, fix comment #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
auto_detect_solc = false
bytecode_hash = "none"
evm_version = "paris"
fs_permissions = [{access = "read", path = "package.json"}]
gas_reports = ["*"]
optimizer = true
optimizer_runs = 1000
Expand Down
17 changes: 6 additions & 11 deletions script/Base.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import { console2 } from "forge-std/src/console2.sol";
import { Script } from "forge-std/src/Script.sol";
import { stdJson } from "forge-std/src/StdJson.sol";

abstract contract BaseScript is Script {
using Strings for uint256;
using stdJson for string;

/// @dev Included to enable compilation of the script without a $MNEMONIC environment variable.
string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
Expand Down Expand Up @@ -49,18 +51,11 @@ abstract contract BaseScript is Script {
///
/// Notes:
/// - The salt format is "ChainID <chainid>, Version <version>".
/// - The version is obtained from `package.json` using the `ffi` cheatcode:
/// https://book.getfoundry.sh/cheatcodes/ffi
/// - Requires the `jq` CLI installed: https://jqlang.github.io/jq/
function constructCreate2Salt() public returns (bytes32) {
/// - The version is obtained from `package.json`.
function constructCreate2Salt() public view returns (bytes32) {
string memory chainId = block.chainid.toString();
string[] memory inputs = new string[](4);
inputs[0] = "jq";
inputs[1] = "-r";
inputs[2] = ".version";
inputs[3] = "./package.json";
bytes memory result = vm.ffi(inputs);
string memory version = string(result);
string memory json = vm.readFile("package.json");
string memory version = json.readString(".version");
string memory create2Salt = string.concat("ChainID ", chainId, ", Version ", version);
console2.log("The CREATE2 salt is \"%s\"", create2Salt);
return bytes32(abi.encodePacked(create2Salt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BaseScript } from "./Base.s.sol";

/// @notice Deploys {SablierV2OpenEnded} at a deterministic address across chains.
/// @dev Reverts if the contract has already been deployed.
contract DeployOpenEnded is BaseScript {
contract DeployDeterministicOpenEnded is BaseScript {
function run() public broadcast returns (SablierV2OpenEnded openEnded) {
openEnded = new SablierV2OpenEnded{ salt: constructCreate2Salt() }();
}
Expand Down
1 change: 1 addition & 0 deletions script/DeployOpenEnded.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SablierV2OpenEnded } from "src/SablierV2OpenEnded.sol";

import { BaseScript } from "./Base.s.sol";

/// @notice Deploys {SablierV2OpenEnded}.
contract DeployOpenEnded is BaseScript {
function run() public broadcast returns (SablierV2OpenEnded openEnded) {
openEnded = new SablierV2OpenEnded();
Expand Down
4 changes: 2 additions & 2 deletions src/SablierV2OpenEnded.sol
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ contract SablierV2OpenEnded is ISablierV2OpenEnded, NoDelegateCall, SablierV2Ope
// Retrieve the recipient from storage.
address recipient = _streams[streamId].recipient;

// Check: if `msg.sender` is neither the stream's recipient, the withdrawal address must be the recipient.
if (to != recipient && !(msg.sender == recipient)) {
// Check: if `msg.sender` is not the stream's recipient, the withdrawal address must be the recipient.
if (to != recipient && msg.sender != recipient) {
revert Errors.SablierV2OpenEnded_WithdrawalAddressNotRecipient(streamId, msg.sender, to);
}

Expand Down
Loading