Skip to content

Commit

Permalink
Fortune v2 (#487)
Browse files Browse the repository at this point in the history
* Added Exchange Oracle basic template

* Added basic templates for all services with migrations and typeorm entities

* Change the provider of the fiat section

* Clean logs

* use minio for python sdk doctest (#281)

* fix duplicated dependency

* Added oracles, added new packages, updated orm config

* Job launcher/fiat payments (#333)

* Added payment service logic. Added job services base template

* Finalized payment module implementation. Added fortune and cvat job types

* Fixed payment module dto. Fixed jwt public guard

* Updated required node version to 18.x

* Job launcher/job types (#336)

* Added logic to process both types of job, Fortune and CVAT

* Implemented support for both types of jobs Fortune and CVAT

* Updated job migrations. Updated dto types. Tested job creation logic

* Job launcher/job types (#337)

* Added logic to process both types of job, Fortune and CVAT

* Implemented support for both types of jobs Fortune and CVAT

* Updated job migrations. Updated dto types. Tested job creation logic

* Added untracked files

* Implemented encryption module (#339)

* Change enums to specific folder and add currency service

* Job launcher/encrypt manifest (#341)

* Updated storage service. Updated create job and manifest encryption logic

* Updated readme

* Removed .github and assets folder

* Job launcher/encrypt manifest (#341)

* Updated storage service. Updated create job and manifest encryption logic

* Updated readme

* Removed .github and assets folder

* Delete contracts folder and create currency controller

* Change function name

* Add docker compose with minio and postgres services

* Update fortune v2 project name

* Added webhook incomming logic processing (#355)

* Added webhook incomming logic processing. Updated payment scheme

* Added pending incoming webhook processing with cron

* Added user balance logic (#357)

* Recording oracle/webhook (#358)

* Added basic notification service for oracle

* Fixed typos

* Added base webhook module (#359)

* Added oracle client (#360)

* Refactored job launcher

* Removed oracles services

* Updated dto

* Refactored service

* Moved mogrations

* Added cockie parser

* Resolved PRs comments

---------

Co-authored-by: Francisco López <[email protected]>
Co-authored-by: CryptoRush <[email protected]>
Co-authored-by: Eric Lee <[email protected]>
Co-authored-by: Francisco López <[email protected]>
  • Loading branch information
5 people authored May 22, 2023
1 parent de9fa16 commit a7a7ac0
Show file tree
Hide file tree
Showing 76 changed files with 3,575 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ dist

#cache
cache

#Postgres Data
db
47 changes: 47 additions & 0 deletions packages/examples/fortune-v2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.7'

services:
postgres:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=fortune
- POSTGRES_PASSWORD=fortune
- POSTGRES_DB=hmt-job-launcher
logging:
options:
max-size: 10m
max-file: "3"
ports:
- '5432:5432'
volumes:
- ./db:/var/lib/postgresql/data
minio:
container_name: minio
image: minio/minio:RELEASE.2022-05-26T05-48-41Z
ports:
- 9001:9001
- 9000:9000
environment:
MINIO_ROOT_USER: dev
MINIO_ROOT_PASSWORD: devdevdev
entrypoint: 'sh'
command:
-c "minio server /data --console-address ':9001'"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 5s
timeout: 5s
retries: 3
minio-mc:
container_name: minio-mc
image: minio/mc
depends_on:
minio:
condition: service_healthy
entrypoint: >
/bin/sh -c "
/usr/bin/mc config host add myminio http://minio:9000 dev devdevdev;
/usr/bin/mc mb myminio/launcher;
/usr/bin/mc anonymous set public myminio/launcher;
"
21 changes: 21 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# General
NODE_ENV=
HOST=
PORT=
FE_URL=
SESSION_SECRET=
PASSWORD_SECRET='$2b$10$EICgM2wYixoJisgqckU9gu'

# Database
DB_TYPE=
POSTGRES_HOST=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=
POSTGRES_SYNC=
POSTGRES_PORT=

# Auth
JWT_SECRET=
JWT_ACCESS_TOKEN_EXPIRES_IN=
JWT_REFRESH_TOKEN_EXPIRES_IN=
11 changes: 11 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**/node_modules/*
**/dist/*
**/README.md
**/ganache/*
**/build/*
**/cache/*
**/coverage/*
**/node_modules/*
**/truffle.js
**/cache/*
**/typechain-types/*
9 changes: 9 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parserOptions": {
"project": "./tsconfig.test.json"
},
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off"
},
"root": true
}
45 changes: 45 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# compiled output
dist
pgdata
/node_modules
.lintstagedrc

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea

# IDE - VSCode
.vscode/*

# OS
.DS_Store

# env
.env.*
.env

# VisualStudioCode
../.vscode/
.vscode
.vscode/*

# yarn
.yarn/build-state.yml
.yarn/cache
yarn-debug.log*
yarn-error.log*
.yarn/install-state.gz
.yarn-integrity
# Yarn Integrity file
.yarn/unplugged

5 changes: 5 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
7 changes: 7 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 120,
"trailingComma": "all",
"singleQuote": false
}
21 changes: 21 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Human Protocol

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Job Launcher Server
Pre-reading: https://github.com/humanprotocol/.github/wiki

## Overview
HUMAN is a multi-chain protocol with hundreds of thousands of decentralized workers operating across multiple chains. Anyone can assume the role of a worker and be paid for performing tasks.
Job requesters (people who want work performed) can launch jobs into the network and the jobs will be completed by workers. At a high level the HUMAN Protocol consists of two layers, the Routing Layer and the Execution Layer. The routing layer is responsible for routing jobs to the Layer 1 chains that offer the best execution terms (e.g tx cost, speed, liquidity). The execution layer is responsible for distributing individual tasks within a job to workers, verifying the results of those tasks, maintaining a reputation system for workers and remunerating workers for completed tasks. The two layers work together to facilitate the creation and completion of Jobs in the HUMAN Network.

## Job Launcher
This repository contains the HUMAN Job Launcher Server, an open source and multi-chain application that can be used to launch jobs into the HUMAN network. Job Launchers may be operated by organizations, institutions and individuals who earn rewards and commission for the services they provide. There are many Job Launchers within the HUMAN network and each one can provide specialized services (i.e different job types). You can view all existing Job Launchers operating on the HUMAN network by checking out the Leaderboard page: ADD LINK This particular version of the job launcher is focused on data labeling services. A job launcher operator will provide this service to the community. Job requesters can then use this service to upload raw images, which will ultimately be annotated by real HUMANS. We expect this repository to be modified and extended to other use cases.

## Tokenomics Model (Incentivization Mechanisms)
The open nature of the HUMAN Protocol means that any person or organization may operate core infrastructure and earn rewards for doing so. To prevent participants from acting maliciously, we have created a staking contract which requires all operators within the ecosystem to stake a security collateral. This is called Proof Of Balance. Any operator who is found to be breaching these rules will have their stake reduced by a predetermined amount, this is known as slashing.

## Software Requirements
The Job Launcher Server requires of a number key components, before installing the Server you should ensure you have completed the pre-install steps below.

1. Node.js and NPM
To see if you have installed Node.js and npm, execute the following commands in your terminal:

`node -v`

`npm -v`

If you do not have these installed you can follow the guide here:
https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

2. Postgres Database
The server uses postgres as a database to store user emails and passwords. Ensure that you have installed postgres and created a database before installing the actual server itself. For postgres install instructions see here:
https://www.postgresql.org/download/

Make a note of the postgres username, password and database name.

3. Hardhat
Hardhat is an Ethereum development environment. Compile your contracts and run them on a development network. To install Hardhat see here:
https://hardhat.org/hardhat-runner/docs/getting-started

4. S3 credentials
The server uses S3 to store job details. To setup an S3 bucket and generate the API Key & Secret follow this guide: https://medium.com/@shamnad.p.s/how-to-create-an-s3-bucket-and-aws-access-key-id-and-secret-access-key-for-accessing-it-5653b6e54337

Take a note of the AWS region for the S3 bucket you just created, your API Key and Secret.

## Installation
5. When installing for the first time it will be necessary to run a database migration. To do so you should execute the following command in your terminal:


6. Clone this repo to your local machine and change directory into the cloned repo:

`git clone [email protected]:humanprotocol/human-protocol.git`

7. Install using yarn

`yarn install`

8. Set the variable <NODE_ENV> to development, testing or production. Populate the .env.<NODE_ENV> file with the values you noted down in steps 2, 3 and 4. Use .env.example file to start.

9. Run migrations using yarn

`yarn migration:run`

`yarn migration:create <MIGRATION_NAME>` - Create new migration

`yarn migration:revert` - Revert latest migration

10. Run application using yarn
`yarn start`

10 changes: 10 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"coverageDirectory": "../coverage",
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": "src",
"testEnvironment": "node",
"testRegex": ".spec.ts$",
"transform": {
".+\\.(t|j)s$": "ts-jest"
}
}
16 changes: 16 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/ormconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "default",
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "fortune",
"password": "fortune",
"database": "hmt-job-launcher",
"entities": ["dist/**/*.entity{ .ts,.js}"],
"synchronize": false,
"migrations": ["dist/migrations/*{.ts,.js}"],
"migrationsTableName": "migrations_typeorm",
"migrationsRun": true
}
]
97 changes: 97 additions & 0 deletions packages/examples/fortune-v2/job-launcher/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"private": "true",
"name": "@human-protocol/job-launcher-server",
"version": "1.0.0",
"description": "Human Protocol | Job Launcher Server",
"license": "MIT",
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"bugs": {
"url": "https://github.com/humanprotocol/human-protocol/issues"
},
"title": "Human Protocol Foundation",
"engines": {
"node": "18.x"
},
"main": "./dist/main.js",
"scripts": {
"build": "tsc",
"db:restart": "docker-compose down && docker-compose up -d",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"kill": "sudo pkill -9 node",
"lint": "eslint . --fix",
"migration:create": "typeorm migration:create -d src/migrations -n",
"migration:generate": "typeorm migration:generate -d src/migrations -n",
"migration:revert": "typeorm migration:revert -- -d src/migrations",
"migration:run": "typeorm migration:run -- -d src/ormconfig.ts",
"migration:show": "typeorm migration:show -d src/migrations",
"prebuild": "rimraf dist/",
"prepublish": "npm run build",
"start": "NODE_ENV=${NODE_ENV:=development} tsc-watch --onSuccess \"node .\" --onFailure \"echo Compilation Failed\"",
"start:dev": "NODE_ENV=${NODE_ENV:=development} tsc",
"start:production": "NODE_ENV=${NODE_ENV:=production} tsc-watch --onSuccess \"node .\" --onFailure \"echo Compilation Failed\"",
"start:staging": "NODE_ENV=${NODE_ENV:=staging} node .",
"test": "NODE_ENV=${NODE_ENV:=test} jest --config jest.config.json --detectOpenHandles"
},
"dependencies": {
"@nestjs/axios": "^2.0.0",
"@nestjs/common": "^9.3.9",
"@nestjs/config": "^2.3.1",
"@nestjs/core": "^9.3.9",
"@nestjs/jwt": "^10.0.2",
"@nestjs/passport": "^9.0.3",
"@nestjs/platform-express": "^9.3.9",
"@nestjs/schedule": "^2.2.0",
"@nestjs/swagger": "^6.2.1",
"@nestjs/terminus": "^9.2.1",
"@nestjs/testing": "^9.3.9",
"@nestjs/typeorm": "^9.0.1",
"@types/chai": "^4.3.4",
"axios": "^1.3.4",
"bcrypt": "^5.0.0",
"body-parser": "^1.20.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.6",
"express": "^4.18.2",
"express-session": "^1.17.3",
"helmet": "^6.0.1",
"nestjs-ethers": "^2.0.3",
"nestjs-minio-client": "^2.0.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"pg": "^8.10.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"typeorm": "0.2.43",
"typeorm-naming-strategies": "^4.1.0",
"uuid": "^9.0.0",
"zxcvbn": "^4.4.2",
"bip39": "^3.1.0"
},
"devDependencies": {
"@nestjs/testing": "^9.3.9",
"@types/chai": "^4.3.4",
"@types/express": "^4.17.17",
"@types/express-session": "^1.17.6",
"@types/passport": "^1.0.12",
"@types/passport-jwt": "^3.0.8",
"@types/passport-twitter": "^1.0.37",
"@types/uuid": "^9.0.1",
"@types/zxcvbn": "^4.4.1",
"@types/bcrypt": "^5.0.0",
"@types/cookie-parser": "^1.4.3",
"chai": "^4.3.7",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-ts": "^0.4.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-standard": "^5.0.0",
"ethereum-types": "^3.7.1",
"passport-facebook": "^3.0.0",
"passport-google-oauth": "^2.0.0",
"rimraf": "^4.3.1",
"tsc-watch": "^6.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get, Redirect } from "@nestjs/common";

import { Public } from "./common/decorators";
import { ApiTags } from "@nestjs/swagger";

@Controller("/")
@ApiTags("Main")
export class AppController {
@Public()
@Get("/")
@Redirect("/swagger", 301)
public redirect(): void {}
}
Loading

1 comment on commit a7a7ac0

@vercel
Copy link

@vercel vercel bot commented on a7a7ac0 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

fortune-exchange-oracle-server – ./packages/examples/fortune/exchange-oracle/server

fortune-exchange-oracle-server-humanprotocol.vercel.app
exchange-server.humanprotocol.org
fortune-exchange-oracle-server.vercel.app
fortune-exchange-oracle-server-git-develop-humanprotocol.vercel.app

Please sign in to comment.