IWeb3Task

AlreadyVoted

error AlreadyVoted(address voter)

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

InsufficientBalance

error InsufficientBalance(uint256 balance, uint256 withdrawAmount)

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

InvalidEndDate

error InvalidEndDate(uint256 endDate, uint256 blockTimestamp)

Emitted when endDate is less than block.timestamp.

InvalidStatus

error InvalidStatus(enum IWeb3Task.Status status)

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

InvalidTaskId

error InvalidTaskId(uint256 taskId)

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

QuorumUpdated

event QuorumUpdated(uint256 value)

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

TaskCreated

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

Emitted when a new taskId is created.

TaskStarted

event TaskStarted(uint256 taskId, address assignee)

Emitted when a task is started.

TaskUpdated

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

Emitted when a task is reviewed.

TaskReviewed

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

Emitted when a review is pushed for a task.

Deposit

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

Emitted when a deposit is made.

Withdraw

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

Emitted when a withdraw is made.

Status

Enum representing the possible states of a task.

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

Task

Core struct of a task.

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

setMinQuorum

function setMinQuorum(uint256 value) external

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

Emit a {QuorumUpdated} event.

createTask

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

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

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}).

NOTE If the status is Status.Progress it will be set to Status.Review once.

completeTask

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

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.

IMPORTANT

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

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

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

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

This function returns all tasks created by a given address.

getReviews

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

This function returns all reviews for a given task

getBalance

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

This function returns the balance of a given authorization role.

NOTE

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

getTaskId

function getTaskId() external view returns (uint256)

This function returns the last taskId created.

NOTE taskId is an incremental number that starts at 1. If no task was created, it will return 0.

getMinQuorum

function getMinQuorum() external view returns (uint256)

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

NOTE

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

getQuorumApprovals

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

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

getScore

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

This function returns the score of a given address.

hasVoted

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

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.

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.

withdraw

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

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.

Last updated