Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nimiq supply and rewards calculators libraries #16

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const networkName = useRuntimeConfig().public.nimiqNetwork
<span font-semibold>Error</span>
</NuxtLink>
</div>
<NuxtLink to="https://github.com/onmax/nimiq-validators" i-nimiq:logos-github-mono target="_blank" />
<NuxtLink to="https://github.com/nimiq/validators-api" i-nimiq:logos-github-mono target="_blank" />
<button i-nimiq:moon @click="() => toggleDark()" />
</header>
<main flex-1>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@nuxt/image": "^1.8.1",
"@nuxtjs/color-mode": "^3.5.2",
"@pinia/nuxt": "^0.5.5",
"@types/node": "^22.9.0",
"@unocss/eslint-config": "^0.63.6",
"@unocss/nuxt": "^0.63.6",
"@unocss/preset-rem-to-px": "^0.63.6",
Expand Down
49 changes: 49 additions & 0 deletions packages/nimiq-rewards-calculator/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// 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", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
23 changes: 23 additions & 0 deletions packages/nimiq-rewards-calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Nimiq Rewards Calculator

A function that calculates the rewards for Nimiq's validators based on factors such as the total staked amount, staking period, and current stake ratio. It helps determine the share of rewards earned by each validator.

## Installation

```bash
npm install nimiq-rewards-calculator
```

## Usage

```ts
import { calculateStakingRewards } from 'nimiq-rewards-calculator'

const amount = 1_000_000 // In NIM
const durationInDays = 365
const stakedSupplyRatio = 0.5 // [0-1]
const autoRestake = true

const rewards = calculateStakingRewards({ amount, durationInDays, stakedSupplyRatio, autoRestake })
console.log('Rewards:', rewards)
```
12 changes: 12 additions & 0 deletions packages/nimiq-rewards-calculator/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,
},
})
5 changes: 5 additions & 0 deletions packages/nimiq-rewards-calculator/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import antfu from '@antfu/eslint-config'

export default antfu({

})
68 changes: 68 additions & 0 deletions packages/nimiq-rewards-calculator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"name": "nimiq-rewards-calculator",
"type": "module",
"version": "0.0.1",
"packageManager": "[email protected]",
"description": "Calculates the rewards for Nimiq's validators",
"license": "MIT",
"homepage": "https://github.com/nimiq/validators-api#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/nimiq/validators-api.git"
},
"bugs": "https://github.com/nimiq/validators-api/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",
"prepare": "pnpm run build",
"prepublishOnly": "nr build",
"release": "bumpp && npm publish",
"start": "esno src/index.ts",
"typecheck": "tsc --noEmit",
"test": "vitest",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"nimiq-supply-calculator": "workspace:*"
},
"devDependencies": {
"@antfu/eslint-config": "catalog:",
"eslint": "catalog:",
"esno": "catalog:",
"lint-staged": "catalog:",
"simple-git-hooks": "catalog:",
"typescript": "catalog:",
"unbuild": "catalog:",
"vite": "catalog:"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading
Loading