all files / contracts/ EscrowFactory.sol

100% Statements 10/10
70% Branches 7/10
100% Functions 6/6
100% Lines 14/14
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                                                        63× 63×           63× 63×               41×     41×         39×             39× 39× 39× 39× 39×                                
// SPDX-License-Identifier: MIT
 
pragma solidity >=0.6.2;
 
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
 
import './interfaces/IStaking.sol';
import './Escrow.sol';
 
contract EscrowFactory is OwnableUpgradeable, UUPSUpgradeable {
    // all Escrows will have this duration.
    uint256 constant STANDARD_DURATION = 8640000;
    string constant ERROR_ZERO_ADDRESS = 'EscrowFactory: Zero Address';
 
    uint256 public counter;
    mapping(address => uint256) public escrowCounters;
    address public lastEscrow;
    address public staking;
 
    event Launched(address token, address escrow);
    event LaunchedV2(address token, address escrow, string jobRequesterId);
 
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
 
    function initialize(address _staking) external payable virtual Einitializer {
        __Ownable_init_unchained();
        __EscrowFactory_init_unchained(_staking);
    }
 
    function __EscrowFactory_init_unchained(
        address _staking
    ) internal EonlyInitializing {
        Erequire(_staking != address(0), ERROR_ZERO_ADDRESS);
        staking = _staking;
    }
 
    function createEscrow(
        address token,
        address[] memory trustedHandlers,
        string memory jobRequesterId
    ) public returns (address) {
        bool hasAvailableStake = IStaking(staking).hasAvailableStake(
            msg.sender
        );
        require(
            hasAvailableStake == true,
            'Needs to stake THXC tokens to create an escrow.'
        );
 
        Escrow escrow = new Escrow(
            token,
            msg.sender,
            payable(msg.sender),
            STANDARD_DURATION,
            trustedHandlers
        );
        counter++;
        escrowCounters[address(escrow)] = counter;
        lastEscrow = address(escrow);
        emit LaunchedV2(token, lastEscrow, jobRequesterId);
        return lastEscrow;
    }
 
    function hasEscrow(address _address) public view returns (bool) {
        return escrowCounters[_address] != 0;
    }
 
    // solhint-disable-next-line no-empty-blocks
    function _authorizeUpgrade(address) internal override onlyOwner {}
 
    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[46] private __gap;
}