Skip to content

Commit

Permalink
monorepo and added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed May 23, 2024
1 parent 5dee51f commit d54d0d7
Show file tree
Hide file tree
Showing 26 changed files with 6,759 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [antfu]
opencollective: antfu
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Lint
run: nr lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Typecheck
run: nr typecheck

test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: [lts/*]
os: [ubuntu-latest, windows-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v3

- name: Set node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Setup
run: npm i -g @antfu/ni

- name: Install
run: nci

- name: Build
run: nr build

- name: Test
run: nr test
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v3

- name: Set node
uses: actions/setup-node@v4
with:
node-version: lts/*

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
41 changes: 41 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml"
]
}
74 changes: 26 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,54 @@
<h1 align="center">Nimiq Nuxt Template</h1>
<h1 align="center">Nimiq Validators</h1>

<p align="center">
<a href="https://github.com/onmax/nimiq-vue-template">
<img src="https://github.com/onmax/nimiq-vue-template/raw/main/public/brave_screenshot_localhost.png" alt="Nimiq Nuxt Template" width="644" />
</a>

<p align="center">
This template should help you get started developing with Nimiq in Nuxt. Highly opinionated!
Details of validators in the Nimiq Blockchain and their scores, calculated using Nimiq's VTS algorithm.
<p>

<p align="center">
<a href="https://codesandbox.io/p/github/onmax/nimiq-vue-template/main?import=true&layout=%257B%2522sidebarPanel%2522%253A%2522GIT%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clulnm8fp0006356gxslexhfi%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clulnm8fp0002356gcn2x5ofe%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clulnm8fp0004356geryynd9c%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clulnm8fp0005356ge16lgdas%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B100%252C0%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clulnm8fp0002356gcn2x5ofe%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clulnm8fp0001356gweihipgr%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252FREADME.md%2522%257D%255D%252C%2522id%2522%253A%2522clulnm8fp0002356gcn2x5ofe%2522%252C%2522activeTabId%2522%253A%2522clulnm8fp0001356gweihipgr%2522%257D%252C%2522clulnm8fp0005356ge16lgdas%2522%253A%257B%2522id%2522%253A%2522clulnm8fp0005356ge16lgdas%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clulnm8fp0004356geryynd9c%2522%253A%257B%2522id%2522%253A%2522clulnm8fp0004356geryynd9c%2522%252C%2522activeTabId%2522%253A%2522clulnmy9o00ai356g6226i4gx%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clulnm8fp0003356g6uqy7ae5%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clulnma2f0012def69szq4ong%2522%257D%252C%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522CSB_RUN_OUTSIDE_CONTAINER%253D1%2520devcontainer%2520templates%2520apply%2520--template-id%2520%255C%2522ghcr.io%252Fdevcontainers%252Ftemplates%252Ftypescript-node%255C%2522%2520--template-args%2520%27%257B%257D%27%2520--features%2520%27%255B%255D%27%2522%252C%2522id%2522%253A%2522clulnmx0w004y356g3iz9t0o4%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%252C%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522clulnmy9o00ai356g6226i4gx%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Afalse%252C%2522showShells%2522%253Afalse%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D"><img src="https://img.shields.io/badge/Open%20with-Codesandbox-blue?style=flat&colorA=1F2348&colorB=ffffff" alt="Template on Codesandbox"></a>
</p>

## Try it now!

This template requires Node >=18

### GitHub Template
## Validators Dashboard

Create a repo from this template on GitHub. You can use the button "Use this template" in the top right.
https://nimiq-validators.nuxt.dev

### Clone to local
The dashboard is a simple Nuxt application that displays all validators and their scores.

If you prefer to do it manually with the cleaner git history
## Validators API

```bash
npx degit onmax/nimiq-nuxt-template my-awesome-nimiq-app
cd my-awesome-nimiq-app
pnpm i
```
https://nimiq-validators.nuxt.dev/api/validators

> [!NOTE]
> If you don't have pnpm installed, run: `npm install -g pnpm`.
> Alternatively, you can delete `pnpm-lock.yaml` and use npm or yarn
An endpoint that returns the list of validators and their scores.

Now make sure to update the following files:
## Validator Trust Score

- `package.json`: Update the `name`, `version`, `description`, `author`, `repository`, `bugs`, and `homepage` fields.
- `vite.config.ts`: Update the `base` field to match your repository name or custom domain.
[Source code](./packages/nimiq-vts/)

> the whole is not SSR since Nimiq Web Client is suppose to run in the client. You can modify this behaviour as you want and create islands
This is a npm package that calculates the Trust Score of a validator. You can read more about the Trust Score [here](https://nimiq-validators.nuxt.dev/vts).

## Features
## Validator Details

- Includes `@nimiq/core@next` and connects to the Nimiq Albatross Testnet.
- Uses `nimiq-css` and `Nimiq Icons` for the UI. Supports dark mode!
- Some nuxt modules already installed
- Added `unocss` with `attributify` mode.
The validator details are hardcoded into the [server/database/seed.ts](./server/database/seed.ts) file. If you are responsible for a validator and want to update the information, please open a PR with your information. This process may change in the future.

## Other templates
### Development

- [Vue 3 Nimiq Template](https://github.com/onmax/nimiq-vue-template)

## Recommended IDE Setup
```bash
pnpm install
pnpm dev
```

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar).
> [!Note]
> We use [Nuxt Hub](https://hub.nuxt.dev) which uses Cloudfare Pages + Cloudfare D1 databases. The database is a sqlite instance and currently the database is remote for both development and production. You can change this behaviour in nuxt.config.ts.
## Project Setup
We use Drizzle to access the database.

```sh
pnpm install
```
### Calculating the score using Nitro Tasks

### Compile and Hot-Reload for Development
To calculate the score, we need to run two processes: the fetcher and the score calculator. We do this using a Nitro Task, which is currently an experimental feature of Nitro. Nitro Task is a feature that allows you to trigger an action in the server programatically or manually from the Nuxt Dev Center(go to tasks page).

```sh
pnpm dev
```
Read more about the process of computing the score in the [nimiq-vts](./packages/nimiq-vts/README.md) package.

### Type-Check, Compile and Minify for Production
#### Database

```sh
pnpm build
```
As well as storing the [Validator Details](#validator-details), we also store the data produced by the fetcher in a sqlite database. This data is then used in the score calculator to compute the score. You can see the file [schema.ts](./server/database/schema.ts).
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "nuxt-app",
"name": "nimiq-validators",
"type": "module",
"private": true,
"scripts": {
Expand All @@ -20,6 +20,7 @@
"defu": "^6.1.4",
"drizzle-orm": "^0.30.10",
"nimiq-rpc-client-ts": "^0.3.0",
"nimiq-vts": "workspace:*",
"nuxt": "^3.11.2",
"pinia": "^2.1.7",
"vue": "^3.4.27",
Expand Down
2 changes: 2 additions & 0 deletions packages/nimiq-vts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore-workspace-root-check=true
shell-emulator=true
19 changes: 19 additions & 0 deletions packages/nimiq-vts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Nimiq Validator Trust Score

The algorithm to compute the Nimiq's Validator Trust Score. The VTS is a metric that helps to evaluate the trustworthiness of a validator. You can read more about the Algorithm of the Score [here](https://nimiq-validators.nuxt.dev/vts).

This package is the implementation of such algorithm. Anyone with access to a node should be able to run the same algorithm and get the same result.

The package is implemented with versatility in mind meaning, that it is straightforward to use it in any environment and with different configurations.

The implementation has mainly two parts:

## Fetcher

Retrieves all the necessary data from previous blocks and returns it in a format that is easy to use. It will return an object of type [ActivityEpoch`](./src/types.ts).

## Score Calculator

The score calculator will take the `ActivityEpoch` object and calculate the score of the validator. The score is a number between 0 and 1, where 1 is the best score possible. The score object will be of type [`ScoreValues`](./src/types.ts).

You can change the parameters that the algorithm uses to calculate the score. See [`ScoreParams`](./src/types.ts) for more information.
12 changes: 12 additions & 0 deletions packages/nimiq-vts/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
})
60 changes: 60 additions & 0 deletions packages/nimiq-vts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "nimiq-vts",
"type": "module",
"version": "0.0.0",
"description": "The algorithm to compute the Nimiq's Validator Trust Score",
"license": "MIT",
"homepage": "https://github.com/onmax/nimiq-validators#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/onmax/nimiq-validators.git"
},
"bugs": "https://github.com/onmax/nimiq-validators/issues",
"keywords": [],
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"./dist/*",
"./dist/index.d.ts"
]
}
},
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"prepublishOnly": "nr build",
"release": "bumpp && npm publish",
"start": "esno src/index.ts",
"typecheck": "tsc --noEmit",
"prepare": "simple-git-hooks"
},
"dependencies": {
"defu": "^6.1.4",
"nimiq-rpc-client-ts": "^0.3.0"
},
"devDependencies": {
"@antfu/ni": "^0.21.12",
"@antfu/utils": "^0.7.8",
"@types/node": "^20.12.12",
"bumpp": "^9.4.1",
"esno": "^4.7.0",
"pnpm": "^9.1.1",
"typescript": "^5.4.5",
"unbuild": "^2.0.0",
"vite": "^5.2.11"
}
}
Loading

0 comments on commit d54d0d7

Please sign in to comment.