// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract CrewVault { address[] public owners; mapping(address => bool) public isOwner; uint256 public immutable threshold; struct Proposal { address payable recipient; uint256 amount; bytes32 memoHash; address proposer; uint256 approvals; bool executed; bool cancelled; } Proposal[] public proposals; mapping(uint256 => mapping(address => bool)) public approved; bool private entered; event Deposited(address indexed sender,uint256 amount); event Proposed(uint256 indexed id,address indexed proposer,address indexed recipient,uint256 amount,bytes32 memoHash); event Approval(uint256 indexed id,address indexed owner,bool enabled); event Executed(uint256 indexed id,address indexed recipient,uint256 amount); event Cancelled(uint256 indexed id); modifier onlyOwner(){require(isOwner[msg.sender],"Owner only");_;} constructor(address[] memory members,uint256 required) payable { require(members.length>0&&members.length<=10&&required>0&&required<=members.length,"Invalid owners or threshold"); for(uint256 i;i0)emit Deposited(msg.sender,msg.value); } receive() external payable {require(msg.value>0,"Zero deposit");emit Deposited(msg.sender,msg.value);} function ownerCount() external view returns(uint256){return owners.length;} function proposalCount() external view returns(uint256){return proposals.length;} function propose(address payable recipient,uint256 amount,bytes32 memoHash) external onlyOwner returns(uint256 id){ require(recipient!=address(0)&&recipient!=address(this)&&amount>0,"Invalid payment");id=proposals.length; proposals.push(Proposal(recipient,amount,memoHash,msg.sender,1,false,false));approved[id][msg.sender]=true; emit Proposed(id,msg.sender,recipient,amount,memoHash);emit Approval(id,msg.sender,true); } function approve(uint256 id) external onlyOwner {Proposal storage p=proposals[id];require(!p.executed&&!p.cancelled&&!approved[id][msg.sender],"Cannot approve");approved[id][msg.sender]=true;p.approvals++;emit Approval(id,msg.sender,true);} function revoke(uint256 id) external onlyOwner {Proposal storage p=proposals[id];require(!p.executed&&!p.cancelled&&approved[id][msg.sender],"Cannot revoke");approved[id][msg.sender]=false;p.approvals--;emit Approval(id,msg.sender,false);} function cancel(uint256 id) external {Proposal storage p=proposals[id];require(msg.sender==p.proposer&&!p.executed&&!p.cancelled,"Cannot cancel");p.cancelled=true;emit Cancelled(id);} function execute(uint256 id) external {require(!entered,"Reentrant");entered=true;Proposal storage p=proposals[id];require(!p.executed&&!p.cancelled&&p.approvals>=threshold&&address(this).balance>=p.amount,"Payment not ready");p.executed=true;(bool ok,)=p.recipient.call{value:p.amount}("");require(ok,"Transfer failed");emit Executed(id,p.recipient,p.amount);entered=false;} } contract CrewFactory { address[] public vaults; event VaultCreated(address indexed creator,address indexed vault,uint256 threshold); function vaultCount() external view returns(uint256){return vaults.length;} function createVault(address[] calldata owners,uint256 threshold) external payable returns(address vault){bool included;for(uint256 i;i