A smart contract to help incentivize open source software development through ongoing competitions.
Ryan Christoffersen ee3b38aa6c updated implementation 7 months ago
contracts updated implementation 7 months ago
migrations hackathon submission 7 months ago
test updated implementation 7 months ago
.gitignore initial commit 7 months ago
LICENSE.md initial commit 7 months ago
README.md updated implementation 7 months ago
package.json updated implementation 7 months ago
truffle.js hackathon submission 7 months ago
yarn.lock hackathon submission 7 months ago

README.md

StandardCompetitions

A smart contract for competitions to help incentivize open source

About

This project was originally created for the Hack.Summit(“Blockchain”) Virtual Hackathon in response to the challenge set forth by Gitcoin, which was to "create an incentivization mechanism to grow the open source ecosystem".

The StandardCompetitions smart contract is inspired by Bounty Network's StandardBounties contract. The goal of the smart contract is to establish a standard for open source software competitions to help incentivize open source.

Overview

  • (1) create competition
  • (2) receive contributions
  • (3) activate competition
  • (4) receive submissions
  • (5) score submissions
  • (6) complete competition
  • (7) winners claim prizes

Implementation

The implementation of StandardCompetitions is similar to that of StandardBounties with added features to accommodate for the submission scoring process and the distribution of multiple prizes.

A competition is used to distribute amounts of ETH or a given token to one or several contestants based on the outcome of the scoring process. The contract aims to reduce the necessary trust in the competition host by forcing them to transfer sufficient amounts of ETH or a given token to pay out the winning contestants.

The following public functions are listed in the same order as they are in the contract. The order of the sender functions is designed to represent a general flow of a competition from start to finish.

Sender Functions

createCompetition(host, deadline, specification, judges, prizes, token)

  • createCompetition() creates a competition draft.

    • host - the address of the host managing the competition (valid address required)
    • deadline - a unix timestamp representing the competition deadline (valid 10-digit integer required)
    • specification - a string representing the specification of the competition (valid non-empty string required)
    • judges - an array of addresses representing the judges of the competition (the number of judges is represented by the length of the array and the judges are represented by the value of each item in the array) (either an empty array or an array of valid addresses required)
    • prizes - an array of numbers representing the prizes for the competition (the number of prizes is represented by the length of the array, the order of the prizes is represented by the order of the array, and the amount to be distributed to each winning contestant is represented by the value of each item in the array) (either an empty array or an array of valid integers required)
    • token - the address of the token that the competition will use to receive and send payments (the competition will use ETH if the competition token is not set) (either an empty address or valid address required)
  • Additional Notes

    • The deadline must be a future date at the time which the competition is created and activated.
    • The host, deadline, specification, judges and prizes are required to activate the competition.
    • The host, deadline, specification, judges and token cannot be updated once the competition has been activated and the prizes can only be increased once the competition has been activated.

updateHost(competitionId, host) * only competition host

  • updateHost() updates the host for the given competition.

    • competitionId - the index of the competition (valid index required)
    • host - the address of the host managing the competition (valid address required)
  • Additional Notes

    • The host cannot be changed once the competition has been activated.

updateDeadline(competitionId, deadline) * only competition host

  • updateDeadline() updates the deadline for the given competition.

    • competitionId - the index of the competition (valid index required)
    • deadline - a unix timestamp representing the competition deadline (valid 10-digit integer required)
  • Additional Notes

    • The deadline cannot be changed once the competition has been activated.

updateSpecification(competitionId, specification) * only competition host

  • updateSpecification() updates the specification for the given competition.

    • competitionId - the index of the competition (valid index required)
    • specification - a string representing the specification of the competition (valid non-empty string required)
  • Additional Notes

    • The specification cannot be changed once the competition has been activated.

updateJudges(competitionId, judges) * only competition host

  • updateJudges() updates the judges for the given competition.

    • competitionId - the index of the competition (valid index required)
    • judges - an array of addresses representing the judges of the competition (the number of judges is represented by the length of the array and the judges are represented by the value of each item in the array) (an array of valid addresses required)
  • Additional Notes

    • The judges must be set before the competition can be activated.
    • The judges cannot be changed once the competition has been activated.

updatePrizes(competitionId, prizes) * only competition host

  • updatePrizes() updates the prizes for the given competition.

    • competitionId - the index of the competition (valid index required)
    • prizes - an array of numbers representing the prizes for the competition (the number of prizes is represented by the length of the array, the order of the prizes is represented by the order of the array, and the amount to be distributed to each winning contestant is represented by the value of each item in the array) (an array of valid integers required)
  • Additional Notes

    • The prizes must be set before the competition can be activated.
    • The prizes can only be increased once the competition has been activated.

updateToken(competitionId, token) * only competition host

  • updateToken() updates the token for the given competition.

    • competitionId - the index of the competition (valid index required)
    • token - the address of the token that the competition will use to receive and send payments (the competition will use ETH if the competition token is not set) (valid address required)
  • Additional Notes

    • If the host wishes to distribute the prizes in a given token, the token must be set and the competition must receive the sum total of the prizes before the competition can be activated.
    • If the competition has previously received payments in a given token or ETH, the amount of previously received payments will be returned to the host before the token is updated.

makeContribution(competitionId, amount)

  • makeContribution() transfers the provided amount to the given competition.

    • competitionId - the index of the competition (valid index required)
    • amount - the amount of tokens or ETH that the sender wishes to transfer to the competition (if the competition token is not set and the sender wishes to transfer ETH, the amount must match the value sent with the request) (valid non-zero integer required)
  • Additional Notes

    • Transfers to the competition can be received at any stage, giving the host the opportunity to increase prizes after the competition has been activated.
    • Transfers to the competition can be received from any address, giving the competition the opportunity to receive payments from contributors who wish to help fund the competition.

activateCompetition(competitionId) * only competition host

  • activateCompetition() activates the given competition.

    • competitionId - the index of the competition (valid index required)
  • Additional Notes

    • The deadline must be a future date at the time which the competition is activated.
    • The host, deadline, specification, judges and prizes are required to activate the competition.
    • The competition must receive the sum total of the prizes before the competition can be activated.

cancelCompetition(competitionId) * only competition host

  • cancelCompetition() cancels the given competition.

    • competitionId - the index of the competition (valid index required)
  • Additional Notes

    • The competition cannot be cancelled once the competition has received a submission.

createSubmission(competitionId, specification)

  • createSubmission() creates a submission for the given competition.

    • competitionId - the index of the competition (valid index required)
    • specification - a string representing the specification of the submission
  • Additional Notes

    • A submission can only be created when the competition is active.
    • A submission cannot be created once the competition deadline has passed.
    • A submission cannot be created by the host or any judges of the competition.
    • The specification cannot be changed once the competition deadline has passed.

updateSubmission(competitionId, submissionId, specification) * only submission sender

  • updateSubmission() updates the specification for the given competition submission.

    • competitionId - the index of the competition (valid index required)
    • submissionId - the index of the submission (valid index required)
    • specification - a string representing the specification of the submission
  • Additional Notes

    • The specification can only be updated when the competition is active.
    • The specification cannot be changed once the competition deadline has passed.

scoreSubmission(competitionId, submissionId, score) * only competition judge

  • scoreSubmission() scores the given competition submission.

    • competitionId - the index of the competition (valid index required)
    • submissionId - the index of the submission (valid index required)
    • score - the amount of points the submission will receive (valid index required)
  • Additional Notes

    • A submission can only be scored when the competition is active.
    • A submission can only be scored once the deadline has passed.
    • A submission can only be scored if the judge has not already scored the submission.

completeCompetition(competitionId) * only competition host

  • completeCompetition() completes the given competition.

    • competitionId - the index of the competition (valid index required)
  • Additional Notes

    • A competition can only be completed when the competition is active.
    • A competition can only be completed when all judges have scored all submissions.

claimPrize(competitionId, winnerId) * only competition winner

  • claimPrize() claims the prize for the given competition.

    • competitionId - the index of the competition (valid index required)
    • winnerId - the index of the winner (valid index required)
  • Additional Notes

    • A competition prize can only be claimed by the winner of the competition.

Caller Functions

getCompetition(competitionId)

  • getCompetition() returns properties of the given competition.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • host - the address of the host managing the competition
    • deadline - a unix timestamp representing the competition deadline
    • specification - a string representing the specification of the competition
    • stage - the numeric identifier for the stage of the competition
    • prizesPot - the balance of the competition in the given token or ETH
    • prizesTotal - the sum total of the prizes for the competition
    • hasToken - a boolean representing whether or not the competition has a given token

getCompetitionsCount()

  • getCompetitionsCount() returns the total number of competitions.

  • Return Values

    • count - the total number of competitions

getContribution(competitionId, contributionId)

  • getContribution() returns properties of the given contribution.

    • competitionId - the index of the competition (valid index required)
    • contributionId - the index of the contribution (valid index required)
  • Return Values

    • contributor - the address of the contributor of the contribution
    • contribution - the amount the contributor contributed to the competition

getContributionsCount(_competitionId)

  • getContributionsCount() returns the total number of contributions.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • count - the total number of contributions

getJudges(competitionId)

  • getJudges() returns the judges of the given competition.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • judges - an array of addresses representing the judges of the competition (the number of judges is represented by the length of the array and the judges are represented by the value of each item in the array)

getPrizes(competitionId)

  • getPrizes() returns the prizes of the given competition.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • prizes - an array of numbers representing the prizes for the competition (the number of prizes is represented by the length of the array, the order of the prizes is represented by the order of the array, and the amount to be distributed to each winning contestant is represented by the value of each item in the array)

getToken(competitionId)

  • getToken() returns the token contract of the given competition.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • token - the token contract that the competition use to receive and send payments

getSubmission(competitionId, submissionId)

  • getSubmission() returns properties of the given submission.

    • competitionId - the index of the competition (valid index required)
    • submissionId - the index of the submission (valid index required)
  • Return Values

    • submitter - the address of the submitter of the submission
    • specification - a string representing the specification of the submission
    • totalScore - a number representing the total points the submission has received

getSubmissionsCount(_competitionId)

  • getSubmissionsCount() returns the total number of submissions.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • count - the total number of submissions

getWinner(competitionId, winnerId)

  • getWinner() returns properties of the given winner.

    • competitionId - the index of the competition (valid index required)
    • winnerId - the index of the winner (valid index required)
  • Return Values

    • winner - the address of the winner
    • prizePot - a number representing the prize pot of the winner
    • prizeTotal - a number representing the prize total of the winner
    • totalScore - a number representing the total points the winner received

getWinnersCount(_competitionId)

  • getWinnersCount() returns the total number of winners.

    • competitionId - the index of the competition (valid index required)
  • Return Values

    • count - the total number of winners

Development

Prerequisites

  • Yarn 1.7.0

Install

yarn

Test

yarn test

Compile

yarn build