3.0.5 • Published 3 months ago

@human-protocol/core v3.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Contracts

Escrow

Escrow contract represents the entire life cycle of the job on Human Protocol. Escrow status is usually changed as follows.

Launched -> Pending -> Partial -> Paid -> Completed

On the other hand, it can be cancelled anytime.

  • constructor(token, launcher, canceler, duration, trustedHandlers)

    Create a new escrow with ERC20 token for payments, launcher who initiated the call to escrow factory, canceler who receives the money back when the job is cancelled, job duration before expiry, and extra trusted handlers that act like super admin of the escrow. Initial escrow status is Launched.

  • setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFeePercentage, recordingOracleFeePercentage, exchangeOracleFeePercentage, url, hash)

    Assigns the reputation, recording, and exchange oracle to the job, with relevant fee percentages. Job manifest url, and hash is also configured at this point. This function should be called after the escrow is funded from the job launcher. The escrow is now in Pending status.

    Only trusted handlers can call this function.

  • storeResults(url, hash)

    Stores intermediate results. Can be called when the escrow is in Pending, or Partial status.

    Trusted handlers, and recording oracle can call this function.

  • bulkPayOut(recipients, amounts, url, hash, txId)

    Pay out the workers. Final result URL is recorded. If the escrow is fully paid out, escrow status is changed to Paid, otherwise it's changed to Partial.

    Trusted handlers, and reputation oracle can call this funciton.

  • complete()

    Finishes the job. Escrow is now in Completed status. Can be called only if the escrow is in Paid status.

    Only trusted handlers can call this function.

  • abort()

    Cancels the escrow, and self destruct the contract instance.

    Only trusted handlers can call this function.

  • cancel()

    Cancels the escrow, and sends the remaining funds to the canceler. Escrow status is changed to Cancelled.

    Only trusted handlers can call this function.

  • addTrustedHandlers(trustedHandlers)

    Adds more trusted handlers.

    Only trusted handlers can call this function.

  • getBalance()

    Get remaining balance of the escrow.

EscrowFactory

EscrowFactory allows job launchers to create new Escrow contracts.

  • createEscrow(token, trustedHandlers, jobRequesterId)

    Create a new escrow, which uses ERC20 token for payment, as well as extra trusted handlers. Job launcher is canceler itself, and the job duration is 100 days. Job Requester Id is passed to keep track of job creators. Here, jobRequesterId is an internal id of the Job Launcher, and it can be used to identify the jobs requested by each Job Requester without crossing data between Subgraph and database.

  • hasEscrow(escrow)

    Check if the escrow is created by EscrowFactory

HMToken

ERC20 token for Human Protocol, used for escrow payments by default. It has same interface as ERC20, but some other functions are added for bulk payments.

  • transferBulk(recipients, amounts, txId)

    Transfer to all of the recipients with the amount specified for each of them.

  • increaseApprovalBulk(spenders, amounts, txId)

    Increase allowance of all spenders with the amount given for each of them.

Staking

To be considered valid operator on Human Protocol, user needs to stake HMT.

  • stake(amount)

    Stakes given amount of HMT.

  • unstake(amount)

    Unstakes given amount of HMT. Unstaked tokens are locked for a lock period, and can't be withdrawn.

  • withdraw()

    Withdraw unstaked HMT after lock period.

  • slash(slasher, staker, escrow, token)

    Slash the staker stake allocated to the escrow for abuse contents.

  • allocate(escrow, amount)

    Allocates staker's stake to the escrow. It's essential to launch the escrow.

  • closeAllocation(escrow)

    Close an allocation and free the staked tokens.

Reward Pool

RewardPool is the reward system of Human Protocol. It keeps track of slashes, and distribute reward to the slashers.

  • distributeReward(escrow)

    Distributes token slashes of the escrow after fee.

  • withdraw(to)

    Withdraw collected fees to a specific account.

    Only owner can call this.

KVStore

KVStore is the simple key-value store.

  • set(key, value)

    Save key -> value pair for the user.

  • setBulk(keys, values)

    Save multiple key -> value pairs as bulk for the user.

    • get(account, key)

    Read the value of the given key for the account.

Deployment

Deploy contracts with proxy to a live network

  1. Create a .env file in the root folder of core package, with the following variables(this is an example for Polygon Mumbai, for other networks check hardhat.config.ts):
ETH_POLYGON_MUMBAI_URL=
PRIVATE_KEY=
HMT_ADDRESS=
POLYGONSCAN_API_KEY=
  1. Open ./scripts/deploy-proxies.ts and check if you actually need to deploy all the contracts this script deploys.

  2. Deploy the contracts runing this (NETWORK_NAME = network name from hardhat.config.ts):

yarn deploy:proxy --network [NETWORK_NAME]
  1. Verify every contract runing the following line for each contract address(for those that use a proxy just verifyin the proxy will verify the implementation too):
npx hardhat verify --network [NETWORK_NAME] [CONTRACT_ADDRESS]
  1. Request the Human Protocol team to include the new contract address in the document at https://tech-docs.humanprotocol.org/contracts/contract-addresses.

Upgrade contracts with proxy

  1. Create a .env file in the root folder of core package, with the following variables(this is an example to update EscrowFactory on Polygon Mumbai, if you want to upgrade more proxies you need to add the corresponding addresses. Also, for other networks check hardhat.config.ts):
ETH_POLYGON_MUMBAI_URL=
PRIVATE_KEY=
POLYGONSCAN_API_KEY=
ESCROW_FACTORY_ADDRESS=
  1. Open ./scripts/upgrade-proxies.ts and add all the proxies you actually need to upgrade.

  2. Compile the contract runing this:

yarn compile
  1. Deploy the upgraded contract runing this (NETWORK_NAME = network name from hardhat.config.ts):
yarn upgrade:proxy --network [NETWORK_NAME]
  1. Verify the contract runing the following line:
npx hardhat verify --network [NETWORK_NAME] [CONTRACT_ADDRESS]

Documentation

For detailed information about core, please refer to the Human Protocol Tech Docs.

License

This project is licensed under the MIT License. See the LICENSE file for details.

3.0.5

3 months ago

3.0.4

4 months ago

3.0.3

4 months ago

3.0.2

4 months ago

3.0.1

5 months ago

3.0.0

7 months ago

2.1.4

8 months ago

2.1.3

8 months ago

2.1.2

8 months ago

2.1.1

9 months ago

2.1.0

10 months ago

2.0.0

10 months ago

1.1.19

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

1.0.40

2 years ago

1.0.41

2 years ago

1.1.0-1

2 years ago

1.1.0

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

0.0.10

2 years ago

1.0.33

2 years ago

1.0.11

2 years ago

1.0.32

2 years ago

1.0.10

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.12

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago