/** * Copyright 2017–2019, LaborX PTY * Licensed under the AGPL Version 3 license. */ pragma solidity ^0.4.25; import "../escrow/EscrowBaseInterface.sol"; import "../workflow/WorkflowBase.sol"; interface LaborContractBaseInitializable { function initLaborContract( address _owner, address _storage, bytes32 _crate ) external; function setExtensionContracts( address _signable, address _terminatable, address _disputable, address _completable, address _tasksProposable ) external; } interface LaborContractBaseGeneralizable { function getPaymentRequirements(bytes32 _contractId) external view returns (bool _lockFullBudget, uint8 _paymentTimeline); function getContractParties(bytes32 _contractId) external view returns (address _employer, address _assignee); function getContractState(bytes32 _contractId) external view returns (uint8 _state); } interface LaborContractBase { /// @notice Registers contract by an assignee that was negotiated by both parties and now is ready /// for the next step - financial relationships. Then signs registered contract. /// If job contract is taking place then `_signature` should be based on arbiter setting /// (see EscrowBaseInterface#setArbiter). /// If dispute contract is taking place then `_expireAtBlock`, `_salt`, `_signature` should skipped. /// @param _workflow workflow smart contract address that could be used for time tracking; workflow specific /// @param _escrow escrow smart contract for locking contract budget /// @param _data initialization data for a contract /// @param _expireAtBlock signature's expiration block /// @param _salt signature's unique identifier /// @param _signature signature of signed data /// @return result code of an operation function createContractAndSign( bytes32 _contractId, EscrowBaseInterface _escrow, WorkflowBase _workflow, bytes _data, uint _expireAtBlock, uint _salt, bytes _signature ) external returns (uint); } interface LaborContractBaseOperationable { /// @notice Callback function that is supposed to be called from associated workflow. /// Should be called on key operations that do not require any payment during execution. /// @param _contractId contract identifier /// @param _operationCode code of performed operation function onOperation(bytes32 _contractId, string _operationCode) external; /// @notice Callback function that is supposed to be called from associated workflow. /// Should be called on payable operations, for example, task completion confirmation. /// @param _contractId contract identifier /// @param _operationCode code of performed operation /// @param _depositValue value to deposit (if needed, should include surchange percent) /// @param _value value to be withdrawn from escrow /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _salt random bytes to identify signed data /// @param _signature signature provided by employer function onWithdrawOperation( bytes32 _contractId, string _operationCode, uint _depositValue, uint _value, uint _expireAtBlock, uint _salt, bytes _signature ) external payable; } interface LaborContractBaseSignable { /// @notice Calculates how much is needed to start a contract. /// @param _contractId contract identifier function getLockingDepositBalance(bytes32 _contractId) external view returns (uint); /// @dev Calculates how much is needed to start a contract. /// @return /// @return _values[0] tasks budget /// @return _values[1] deposit fee amount /// @return _values[2] locked termination amount /// @return _values[3] initial (upfront) payment amount /// @return _values[4] upfront withdraw fee amount function getLockingContractDetails(bytes32 _contractId) external view returns (uint[] _values); /// @notice Signs registered contract by an assignee. This operation precedes any other /// sign methods of other parties. /// If job contract is taking place then `_signature` should be based on arbiter setting /// (see EscrowBaseInterface#setArbiter). /// If dispute contract is taking place then `_expireAtBlock`, `_salt`, `_signature` should skipped. /// @param _contractId contract identifier /// @param _documentHash hash of a document on which parties have an agreement /// @param _expireAtBlock signature's expiration block /// @param _salt signature's unique identifier /// @param _signature signature of signed data /// @return result code of an operation function sign( bytes32 _contractId, bytes32 _documentHash, uint _expireAtBlock, uint _salt, bytes _signature ) external returns (uint); /// @notice Allows an assignee to revoke her sign when the contract `_contractId` has not started yet. /// @return result code of an operation function revokeSign(bytes32 _contractId) external returns (uint); /// @notice Signs contract and deposits to it, so it becomes ready for work. /// Should be done as the latest sign among all signs because it locks currency /// If job contract is taking place then `_signature` should be based on artibter setting /// (see EscrowBaseInterface#setArbiter). /// If dispute contract is taking place then `_signature` should be based on initiating escrow dispute /// (see EscrowBaseInterface#initiateDispute). /// @param _contractId contract identifier /// @param _documentHash hash of a document on which parties have an agreement /// @param _value amount of deposited currency /// @param _expireAtBlock signature's expiration block (the same as it was in assignee's sign) /// @param _salt signature's unique identifier (the same as it was in assignee's sign) /// @param _signature signature of signed data (signed data should be the same as it was in assignee's sign) /// @return result code of an operation function signAndDeposit( bytes32 _contractId, bytes32 _documentHash, uint _value, uint _expireAtBlock, uint _salt, bytes _signature ) external payable returns (uint); } interface LaborContractBaseCompletable { /// @notice Calculates how much is needed to complete a contract /// (in cases when payment is performed after all tasks and no escrow locked balance exists). /// @param _contractId contract identifier /// @return _depositValue how much should be deposited by employer to resolve contract completion /// @return _employerPaybackValue how much an employer gets back /// @return _assigneeResolveValue how much an assignee will be paid function getCompletionContractDepositBalance( bytes32 _contractId ) external view returns ( uint _depositValue, uint _employerPaybackValue, uint _assigneeResolveValue ); /// @dev Calculates how much is needed to complete a contract. /// @return /// @return _values[0] already completed and paid amount /// @return _values[1] completed but not paid (means it will be paid eventually) /// @return _values[2] unpaid (left) tasks budget amount (not completed) /// @return _values[3] escrow current balance /// @return _values[4] need to deposit amount /// @return _values[5] deposit fee value /// @return _values[6] returned amount to employer /// @return _values[7] paid amount to assignee /// @return _values[8] locked termination amount /// @return _values[9] withdraw fee amount function getCompletionContractDetails(bytes32 _contractId) external view returns (uint[] _values); /// @notice Completes the contract and resolves debts for both parties. /// No actions with contract will be available after that. /// Signature should present data for releasing termination escrow to the assignee and /// termination remainder + budget escrow to the employer. Escrow balance should be empty /// after execution - escrow will be flushed after that. /// See EscrowBaseInterface#releaseNegotiatedPayment for more details. /// @param _contractId contract identifier /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _salt random bytes to identify signed data /// @param _signatures concatenated signatures produced by employer and assignee /// @return result code of an operation function completeContract( bytes32 _contractId, uint _expireAtBlock, uint _salt, bytes _signatures ) external payable returns (uint); } interface LaborContractBaseTerminatable { /// @notice Gets details about depositing amount that is required to initiate termination process. /// @param _contractId contract identifier /// @param _terminationId termination identifier /// @return amount that is required to deposit by termination initiator function getTerminationInitiateDepositDetails(bytes32 _contractId, uint _terminationId) external view returns (uint); /// @notice Gets details about depositing amount that is required to cancel termination process. /// @param _contractId contract identifier /// @param _terminationId termination identifier /// @return amount that is required to deposit by termination confirmator function getTerminationCancelDepositDetails(bytes32 _contractId, uint _terminationId) external view returns (uint); /// @notice Gets details about depositing amount that is required to confirm termination process. /// @param _contractId contract identifier /// @param _terminationId termination identifier /// @return amount that is required to deposit by termination confirmator function getTerminationConfirmDepositDetails(bytes32 _contractId, uint _terminationId) external view returns (uint); /// @notice Calculates requested termination conditions for the contract `_contractId`. /// @param _contractId contract identifier /// @param _terminationId termination condition identifier /// @return _employerValue amount that will return back to the employer /// @return _assigneeValue amount that will go to the assignee function getTerminationPaymentAmounts( bytes32 _contractId, uint _terminationId ) external view returns (uint _employerValue, uint _assigneeValue); /// @dev Calculates requested termination conditions for the contract `_contractId`. /// @param _contractId contract identifier /// @param _terminationId termination condition identifier /// @return _values[0] termination amount /// @return _values[1] employer's amount /// @return _values[2] assignee's amount /// @return _values[3] initiator type /// @return _values[4] receiver type /// @return _values[5] unspent upfront amount that would be returned to an employer /// @return _values[6] need to deposit amount on termination initiation /// @return _values[7] need to deposit amount on termination confirmation /// @return _values[8] need to pay for tasks in case if they are competed but not paid /// @return _values[9] withdraw assignee fee amount function getTerminationContractDetails(bytes32 _contractId, uint _terminationId) external view returns (uint[] _values); /// @notice Starts termination negotiations by any party (employer or assignee) /// Is not applicable for disputes. /// @param _contractId contract identifier /// @param _terminationId termination identifier; type of termination condition should /// be assosiated with the initiator /// @param _value value to deposit, duplicated as a parameter to secure from unintended deposits /// @param _comment additional comments about termination reason or other notes /// @return result code of an operation function initiateTermination( bytes32 _contractId, uint32 _terminationId, uint _value, string _comment ) external payable returns (uint); /// @notice Cancels termination request that has not confirmed yet. /// Should be called by the termination initiator /// Is not applicable for disputes. /// @param _contractId contract identifier /// @return result code of an operation function cancelTerminationRequest(bytes32 _contractId) external returns (uint); /// @notice Cancels termination request that has not confirmed yet. /// Should be called by the termination initiator. /// Is not applicable for disputes. /// /// If a deposit was made during termination initiation stage and /// 'getTerminationCancelDepositDetails()' returns non-zero result then the opposite /// party should sign that amount for withdrawal and pass to termination's /// initiator. /// When initiator is an assignee then an employer should sign a message for /// EscrowBaseInterface#releaseBuyerPayment method. /// When initiator is an employer then an assignee should sign a message for /// EscrowBaseInterface#sendSellerPayback method. /// Otherwise expireAtBlock, salt and signature should be skipped. /// @param _contractId contract identifier /// @param _expireAtBlock contract identifier /// @param _salt contract identifier /// @param _signature contract identifier /// @return result code of an operation function cancelTerminationRequestWithApproval( bytes32 _contractId, uint _expireAtBlock, uint _salt, bytes _signature ) external returns (uint); /// @notice Performs confirmation of requested termination and terminates contract. /// Is not applicable for disputes. /// Should be signed by both parties that means they are both aware and agreed on conditions. /// Signature should present data for releasing termination escrow to the assignee and /// termination remainder + budget escrow to the employer. Escrow balance should be empty /// after execution - escrow will be flushed after that. /// See EscrowBaseInterface#releaseNegotiatedPayment for more details. /// @param _contractId contract identifier /// @param _value value to deposit, duplicated as a parameter to secure from unintended withdrawals /// @param _expireAtBlock expiry block after which transaction will be invalid. Should be the same for /// tasks payment and for negotiated payment. /// @param _tasksSalt tasks random bytes to identify signed data /// Skip when no payment is required. /// @param _tasksSignature signature of EscrowBaseInterface#releaseBuyerPayment message /// Skip when no payment is required. /// @param _salt random bytes to identify signed data /// @param _signatures concatenated signatures produced by employer and assignee /// @return result code of an operation function confirmTermination( bytes32 _contractId, uint _value, uint _expireAtBlock, uint _tasksSalt, bytes _tasksSignature, uint _salt, bytes _signatures ) external payable returns (uint); } interface LaborContractBaseDisputable { /// @notice Gets details about contract resolvement by an arbiter. /// @param _contractId contract identifier /// @param _assigneeValue value that will go to an assignee /// @return _values[0] employer's amount /// @return _values[1] withdraw fee amount (for assignee) function getResolvingContractDetails(bytes32 _contractId, uint _assigneeValue) external view returns (uint[] _values); /// @notice Resolves the dispute in contract (if such exists). /// Sends provided percent `_assigneePercent` to the underlying /// contract assignee, the remainder - to contract employer. /// No actions with contract will be available after that. /// Signature should present data for releasing full escrow balance and split /// it amont parties in a dispute. Escrow balance should be empty /// after execution - escrow will be flushed after that. /// See EscrowBaseInterface#releaseDisputedPayment for more details. /// @param _contractId contract identifier /// @param _assigneeValue part of the escrow balance that will go to the assignee /// of disputed contract /// @param _expireAtBlock expiry block after which transaction will be invalid /// @param _signature signature provided by dispute assignee (base contract's arbiter) /// @return result code of an operation function resolveContract( bytes32 _contractId, uint _assigneeValue, uint _expireAtBlock, bytes _signature ) external returns (uint); } interface LaborContractBaseTasksProposable { /// @notice Gets details about proposed tasks for contract `_contractId`. /// @param _contractId contract identifier /// @return _values[0] proposed tasks budget /// @return _values[1] amount needed to be deposited /// @return _values[2] employer's fee amount included into deposit /// @return _values[3] termination amount needed to be locked additionally /// @return _values[4] upfront amount /// @return _values[5] assignee's fee amount that will be taken fron upfront amount function getContractProposedTasksDetails(bytes32 _contractId) external view returns (uint[] _values); /// @notice Puts new tasks of a contract `_contractId` to an approval state for an employer. /// Should be called by an assignee. /// @param _contractId contract identifier /// @param _updatedDocumentHash document hash of the updated contract /// @param _data tasks and task penalty that are going to be added /// @return result code of an operation function proposeTasks( bytes32 _contractId, bytes32 _updatedDocumentHash, bytes _data ) external returns (uint); /// @notice Accepts proposed tasks for a contract `_contractId` /// and adds tasks to a contract's workflow. /// Should be called by an employer. /// @param _contractId contract identifier /// @param _updatedDocumentHash document hash of the updated contract /// @param _value value to be deposited for provided tasks /// @return result code of an operation function acceptProposedTasksAndDeposit( bytes32 _contractId, bytes32 _updatedDocumentHash, uint _value ) external payable returns (uint); }