# IWeb3Task

### AlreadyVoted

```solidity
error AlreadyVoted(address voter)
```

*Emitted when `msg.sender` already voted for a specific task.*

### InsufficientBalance

```solidity
error InsufficientBalance(uint256 balance, uint256 withdrawAmount)
```

*Emitted when authorization Id (Role) does not hold enough balance to operate.*

### InvalidEndDate

```solidity
error InvalidEndDate(uint256 endDate, uint256 blockTimestamp)
```

*Emitted when `endDate` is less than `block.timestamp`.*

### InvalidStatus

```solidity
error InvalidStatus(enum IWeb3Task.Status status)
```

*Emitted when `status` provided mismatches the one asked by the function.*

### InvalidTaskId

```solidity
error InvalidTaskId(uint256 taskId)
```

*Emitted when `taskId` is not valid when calling {Web3Task-getTask}.*

### QuorumUpdated

```solidity
event QuorumUpdated(uint256 value)
```

*Emmited when the minimum `APPROVALS` to complete a task is updated.*

### TaskCreated

```solidity
event TaskCreated(uint256 taskId, address creator, address assignee, uint256 reward, uint256 endDate)
```

*Emitted when a new `taskId` is created.*

### TaskStarted

```solidity
event TaskStarted(uint256 taskId, address assignee)
```

*Emitted when a task is started.*

### TaskUpdated

```solidity
event TaskUpdated(uint256 taskId, enum IWeb3Task.Status status)
```

*Emitted when a task is reviewed.*

### TaskReviewed

```solidity
event TaskReviewed(uint256 taskId, address reviewer, string metadata)
```

*Emitted when a review is pushed for a task.*

### Deposit

```solidity
event Deposit(uint256 authorizationId, address depositor, uint256 amount)
```

*Emitted when a deposit is made.*

### Withdraw

```solidity
event Withdraw(uint256 authorizationId, address withdrawer, uint256 amount)
```

*Emitted when a withdraw is made.*

### Status

*Enum representing the possible states of a task.*

```solidity
enum Status {
  Created,
  Progress,
  Review,
  Completed,
  Canceled
}
```

### Task

*Core struct of a task.*

```solidity
struct Task {
  enum IWeb3Task.Status status;
  string title;
  string description;
  uint256 reward;
  uint256 endDate;
  uint256[] authorizedRoles;
  uint256 creatorRole;
  address assignee;
  string metadata;
}
```

### setMinQuorum

```solidity
function setMinQuorum(uint256 value) external
```

This function sets the minimum quorum of approvals to complete a task.

Emit a {QuorumUpdated} event.

### createTask

```solidity
function createTask(struct IWeb3Task.Task task) external returns (uint256)
```

The core function to create a task.

Will increment global `_taskId`.

Emits a {TaskCreated} event.

Requirements:

* `task.endDate` must be greater than `block.timestamp`.
* `task.status` must be `Status.Created`.
* `msg.sender` must be an authorized operator (see {AccessControl}).

### startTask

```solidity
function startTask(uint256 taskId, uint256 authId) external returns (bool)
```

This function starts a task. It will set the `msg.sender` as the assignee in case none is provided. Meaning anyone with the authorization can start the task.

The task status will be set to `Status.Progress` and the next step is to execute the task and call a {reviewTask} when ready.

Emits a {TaskStarted} event.

Requirements:

* `_taskId` must be a valid task id.
* `task.status` must be `Status.Created`.
* `task.endDate` must be greater than `block.timestamp`.
* `msg.sender` must be an authorized operator (see {AccessControl}).

### reviewTask

```solidity
function reviewTask(uint256 taskId, uint256 authId, string metadata) external returns (bool)
```

This function reviews a task and let the caller push a metadata.

Metadata is a string that can be used to store any kind of information related to the task. It can be used to store a link to a file using IPFS.

IMPORTANT: This function can be called more than once by both task creator or asssignee. This is because we want to allow a ping-pong of reviews until the due date or completion. This will create a history of reviews that can be used to track the progress of the task and raise a dispute if needed.

Emits a {TaskUpdated} event.

Requirements:

* `_taskId` must be a valid task id.
* `msg.sender` must be `_task.assignee` or the `_task.creator`.
* `task.status` must be `Status.Progress` or `Status.Review`.
* `task.endDate` must be greater than `block.timestamp`.
* `msg.sender` must be an authorized operator (see {AccessControl}).

{% hint style="info" %}
**NOTE**\
If the status is `Status.Progress` it will be set to `Status.Review` once.
{% endhint %}

### completeTask

```solidity
function completeTask(uint256 taskId, uint256 authId) external returns (bool)
```

This function completes a task and transfers the rewards to the assignee.

The task status will be set to `Status.Completed` and the task will be considered done.

The `_task.assignee` will receive the `_task.reward` and also a NFT representing the completed task with the tokenId equal to the `_taskId`.

IMPORTANT: The assignee agrees to the reward distribution by completing the task and its aware that the task can be disputed by the creator. The assignee can also open a dispute if the creator does not approve the completion by reaching higher DAO authorities.

Emits a {TaskUpdated} event.

Requirements:

* `_taskId` must be a valid task id.
* `task.status` must be `Status.Review`.
* `task.endDate` must be greater than `block.timestamp`.
* `msg.sender` must be an authorized operator (see {AccessControl}).
* `msg.sender` can only cast one vote per task.
* `APPROVALS` must reach the quorum.

### cancelTask

```solidity
function cancelTask(uint256 taskId, uint256 authId) external returns (bool)
```

This function cancels a task and invalidates its continuity.

The task status will be set to `Status.Canceled`.

Emits a {TaskUpdated} event.

{% hint style="warning" %}
**IMPORTANT**

Tasks that were previously set to `Completed` can be canceled as well, but the assignee will keep the reward and the NFT.
{% endhint %}

Requirements:

* `_taskId` must be a valid task id.
* `task.status` cannot be `Status.Canceled`.
* `task.endDate` must be greater than `block.timestamp`.
* `msg.sender` must be an authorized operator (see {AccessControl}).

### getTask

```solidity
function getTask(uint256 taskId) external view returns (struct IWeb3Task.Task)
```

This function returns a task by its id.

Requirements:

* `_taskId` must exist.
* `task.endDate` must be greater than \`block.timestamp, otherwise the task is considered expired.\_

### getUserTasks

```solidity
function getUserTasks(address addr) external view returns (uint256[])
```

*This function returns all tasks created by a given address.*

### getReviews

```solidity
function getReviews(uint256 taskId) external view returns (string[])
```

*This function returns all reviews for a given task*

### getBalance

```solidity
function getBalance(uint256 roleId) external view returns (uint256)
```

This function returns the balance of a given authorization role.

{% hint style="info" %}
**NOTE**

It will return 0 if the authorization role does not exist or if the authorization role has not received any deposit.
{% endhint %}

### getTaskId

```solidity
function getTaskId() external view returns (uint256)
```

This function returns the last taskId created.

{% hint style="info" %}
**NOTE**\
taskId is an incremental number that starts at 1. If no task was created, it will return 0.
{% endhint %}

### getMinQuorum

```solidity
function getMinQuorum() external view returns (uint256)
```

This function returns the minimum approvals required to complete a task.

{% hint style="info" %}
**NOTE**

The Quorum can be updated by the contract owner. And it will emit a {QuorumUpdated} event.
{% endhint %}

### getQuorumApprovals

```solidity
function getQuorumApprovals(uint256 _taskId) external view returns (uint256)
```

*This function returns the amount of approvals cast into a task.*

### getScore

```solidity
function getScore(address addr) external view returns (uint256)
```

*This function returns the score of a given address.*

### hasVoted

```solidity
function hasVoted(uint256 taskId, address addr) external view returns (bool)
```

*This function returns a boolean if the `addr` has voted for a specific task.*

### deposit

```solidity
function deposit(uint256 authId) external payable returns (bool)
```

This function allows to deposit funds into the contract into a specific authorization role.

If the authorization role is e.g.: "Leader of Marketing" as the `authId` number 5, then sending funds to this function passing the id will increase the balance of the authorization role by `msg.value`.

Emits a {Deposit} event.

{% hint style="info" %}
**NOTE**

Any authorization role id can be used as a parameter, even those that are not yet created. For this and more related issues, there is an {emergencyWithdraw} in the contract.
{% endhint %}

### withdraw

```solidity
function withdraw(uint256 authId, uint256 amount) external returns (bool)
```

This function allows to withdrawal of funds from the contract from a specific authorization role.

Emits a {Withdraw} event.

Requirements:

* `msg.sender` must be an authorized operator (see {AccessControl}).
* `balance` of the authorization, role must be greater than `_amount`.

### emergengyWithdraw

```solidity
function emergengyWithdraw() external
```

This function allows to withdrawal of all funds from the contract.

Emits a {Withdraw} event.

Requirements:

* `msg.sender` must be the contract owner (see {AccessControl}).

***

### IWeb3Task Summarize

The `IWeb3Task` smart contract is an interface that defines the structure and behavior of a task.

* **Task Status**: The contract defines an enumeration `Status` that represents the possible states of a task. These states include `Created`, `Progress`, `Review`, `Completed`, and `Canceled`.
* **Task Structure**: The contract defines a struct `Task` that represents a task. This struct includes the status of the task, the title and description of the task, the reward for the task, the end date of the task, the roles authorized to operate the task, the role of the creator of the task, the assignee of the task, and any metadata associated with the task.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web3task.gitbook.io/web3task/contracts/iweb3task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
