Skip to content

Commit

Permalink
Merge pull request #52 from Hats-Protocol/new-fmt
Browse files Browse the repository at this point in the history
use new forge fmt config
  • Loading branch information
spengrah authored Sep 23, 2024
2 parents 7130bae + db0769c commit f602ecd
Show file tree
Hide file tree
Showing 14 changed files with 2,844 additions and 2,832 deletions.
6 changes: 3 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ bracket_spacing = true
int_types = "long"
line_length = 120
multiline_func_header = "attributes_first"
number_underscore = "preserve"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4
wrap_comments = false
tab_width = 2
wrap_comments = true

[rpc_endpoints]
arbitrum = "https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}"
Expand Down
266 changes: 133 additions & 133 deletions script/HatsSignerGate.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,148 +7,148 @@ import { HatsSignerGate } from "../src/HatsSignerGate.sol";
import { ModuleProxyFactory } from "../lib/zodiac/contracts/factory/ModuleProxyFactory.sol";

contract BaseScript is Script {
bool public verbose = true;
bool public verbose = true;

function getChainKey() internal view returns (string memory) {
return string.concat(".", vm.toString(block.chainid));
}
function getChainKey() internal view returns (string memory) {
return string.concat(".", vm.toString(block.chainid));
}
}

contract DeployImplementation is BaseScript {
using stdJson for string;

address public hats;
address public safeFallbackLibrary;
address public safeMultisendLibrary;
address public safeProxyFactory;
address public safeSingleton;
address public zodiacModuleFactory;

HatsSignerGate public implementation;

/// ===========================================
/// @dev deployment params to be set manually
string public version = "v2.0.0-test";
bytes32 public SALT = bytes32(abi.encode(0x4a75)); // ~ H(4) A(a) T(7) S(6)
/// ===========================================

function setDeployParams() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script/DeployParams.json");
string memory json = vm.readFile(path);
string memory chain = getChainKey();

bytes memory params = json.parseRaw(chain);

// the json is parsed in alphabetical order, so we decode it that way too
(hats, safeFallbackLibrary, safeMultisendLibrary, safeProxyFactory, safeSingleton, zodiacModuleFactory) =
abi.decode(params, (address, address, address, address, address, address));
}

function prepare(bool _verbose, string memory _version) public {
verbose = _verbose;
version = _version;
using stdJson for string;

address public hats;
address public safeFallbackLibrary;
address public safeMultisendLibrary;
address public safeProxyFactory;
address public safeSingleton;
address public zodiacModuleFactory;

HatsSignerGate public implementation;

/// ===========================================
/// @dev deployment params to be set manually
string public version = "v2.0.0-test";
bytes32 public SALT = bytes32(abi.encode(0x4a75)); // ~ H(4) A(a) T(7) S(6)
/// ===========================================

function setDeployParams() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script/DeployParams.json");
string memory json = vm.readFile(path);
string memory chain = getChainKey();

bytes memory params = json.parseRaw(chain);

// the json is parsed in alphabetical order, so we decode it that way too
(hats, safeFallbackLibrary, safeMultisendLibrary, safeProxyFactory, safeSingleton, zodiacModuleFactory) =
abi.decode(params, (address, address, address, address, address, address));
}

function prepare(bool _verbose, string memory _version) public {
verbose = _verbose;
version = _version;
}

function run() external returns (HatsSignerGate) {
setDeployParams();
uint256 privKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(privKey);
vm.startBroadcast(deployer);

implementation = new HatsSignerGate(safeSingleton, safeFallbackLibrary, safeMultisendLibrary, safeProxyFactory);

vm.stopBroadcast();

if (verbose) {
console2.log("HSG implementation", address(implementation));
console2.log("Safe singleton", safeSingleton);
console2.log("Safe fallback library", safeFallbackLibrary);
console2.log("Safe multisend library", safeMultisendLibrary);
console2.log("Safe proxy factory", safeProxyFactory);
}

function run() external returns (HatsSignerGate) {
setDeployParams();
uint256 privKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(privKey);
vm.startBroadcast(deployer);

implementation = new HatsSignerGate(safeSingleton, safeFallbackLibrary, safeMultisendLibrary, safeProxyFactory);

vm.stopBroadcast();

if (verbose) {
console2.log("HSG implementation", address(implementation));
console2.log("Safe singleton", safeSingleton);
console2.log("Safe fallback library", safeFallbackLibrary);
console2.log("Safe multisend library", safeMultisendLibrary);
console2.log("Safe proxy factory", safeProxyFactory);
}

return implementation;
}
return implementation;
}
}

contract DeployInstance is BaseScript {
using stdJson for string;

address public zodiacModuleFactory;
address public hats;
address public implementation;
address public instance;

uint256 public saltNonce;

uint256 public ownerHat;
uint256[] public signersHats;
uint256 public minThreshold;
uint256 public targetThreshold;
uint256 public maxSigners;
address public safe;
string public version;

function prepare(
bool _verbose,
address _implementation,
uint256 _ownerHat,
uint256[] memory _signersHats,
uint256 _minThreshold,
uint256 _targetThreshold,
uint256 _maxSigners,
address _safe,
string memory _version,
uint256 _saltNonce
) public {
verbose = _verbose;
implementation = _implementation;
ownerHat = _ownerHat;
signersHats = _signersHats;
minThreshold = _minThreshold;
targetThreshold = _targetThreshold;
maxSigners = _maxSigners;
safe = _safe;
version = _version;
saltNonce = _saltNonce;
}

function setModuleFactory() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script/DeployParams.json");
string memory json = vm.readFile(path);
string memory chain = getChainKey();

bytes memory params = json.parseRaw(chain);

// the json is parsed in alphabetical order, so we decode it that way too
(hats,,,,, zodiacModuleFactory) = abi.decode(params, (address, address, address, address, address, address));
using stdJson for string;

address public zodiacModuleFactory;
address public hats;
address public implementation;
address public instance;

uint256 public saltNonce;

uint256 public ownerHat;
uint256[] public signersHats;
uint256 public minThreshold;
uint256 public targetThreshold;
uint256 public maxSigners;
address public safe;
string public version;

function prepare(
bool _verbose,
address _implementation,
uint256 _ownerHat,
uint256[] memory _signersHats,
uint256 _minThreshold,
uint256 _targetThreshold,
uint256 _maxSigners,
address _safe,
string memory _version,
uint256 _saltNonce
) public {
verbose = _verbose;
implementation = _implementation;
ownerHat = _ownerHat;
signersHats = _signersHats;
minThreshold = _minThreshold;
targetThreshold = _targetThreshold;
maxSigners = _maxSigners;
safe = _safe;
version = _version;
saltNonce = _saltNonce;
}

function setModuleFactory() public {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script/DeployParams.json");
string memory json = vm.readFile(path);
string memory chain = getChainKey();

bytes memory params = json.parseRaw(chain);

// the json is parsed in alphabetical order, so we decode it that way too
(hats,,,,, zodiacModuleFactory) = abi.decode(params, (address, address, address, address, address, address));
}

function createDeployParams() public view returns (bytes memory) {
return abi.encode(ownerHat, signersHats, safe, hats, minThreshold, targetThreshold, maxSigners, version);
}

function run() external returns (HatsSignerGate) {
setModuleFactory();

uint256 privKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(privKey);
vm.startBroadcast(deployer);

instance = ModuleProxyFactory(zodiacModuleFactory).deployModule(
address(implementation), abi.encodeWithSignature("setUp(bytes)", createDeployParams()), saltNonce
);

vm.stopBroadcast();

if (verbose) {
if (safe == address(0)) {
console2.log("new Safe deployed", address(HatsSignerGate(instance).safe()));
}
}

function createDeployParams() public view returns (bytes memory) {
return abi.encode(ownerHat, signersHats, safe, hats, minThreshold, targetThreshold, maxSigners, version);
}

function run() external returns (HatsSignerGate) {
setModuleFactory();

uint256 privKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.rememberKey(privKey);
vm.startBroadcast(deployer);

instance = ModuleProxyFactory(zodiacModuleFactory).deployModule(
address(implementation), abi.encodeWithSignature("setUp(bytes)", createDeployParams()), saltNonce
);

vm.stopBroadcast();

if (verbose) {
if (safe == address(0)) {
console2.log("new Safe deployed", address(HatsSignerGate(instance).safe()));
}
}

return HatsSignerGate(instance);
}
return HatsSignerGate(instance);
}
}
15 changes: 8 additions & 7 deletions src/HSGLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
pragma solidity >=0.8.13;

library HSGLib {
/// @notice Emitted when a new target signature threshold for the `safe` is set
event TargetThresholdSet(uint256 threshold);
/// @notice Emitted when a new target signature threshold for the `safe` is set
event TargetThresholdSet(uint256 threshold);

/// @notice Emitted when a new minimum signature threshold for the `safe` is set
event MinThresholdSet(uint256 threshold);
/// @notice Emitted when a new minimum signature threshold for the `safe` is set
event MinThresholdSet(uint256 threshold);

/// @notice Emitted when new approved signer hats are added
event SignerHatsAdded(uint256[] newSignerHats);
/// @notice Emitted when new approved signer hats are added
event SignerHatsAdded(uint256[] newSignerHats);
}

/// @notice Signers are not allowed to disable the HatsSignerGate guard
Expand All @@ -34,7 +34,8 @@ error StillWearsSignerHat(address signer);
error MaxSignersReached();

/// @notice Emitted when a valid signer attempts `claimSigner` but there are already `maxSigners` signers
/// @dev This will only occur if `signerCount` is out of sync with the current number of valid signers, which can be resolved by calling `reconcileSignerCount`
/// @dev This will only occur if `signerCount` is out of sync with the current number of valid signers, which can be
/// resolved by calling `reconcileSignerCount`
error NoInvalidSignersToReplace();

/// @notice Target threshold must be lower than `maxSigners`
Expand Down
Loading

0 comments on commit f602ecd

Please sign in to comment.