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

Create Catnip.ts #355

Closed
wants to merge 6 commits into from
Closed
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 .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build
build
56 changes: 28 additions & 28 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json"],
},
plugins: ["@typescript-eslint", "simple-import-sort", "unused-imports"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
eqeqeq: "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-floating-promises": "error",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
"no-console": "warn",
},
};
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["./tsconfig.json"],
},
plugins: ["@typescript-eslint", "simple-import-sort", "unused-imports"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
eqeqeq: "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-floating-promises": "error",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
"no-console": "warn",
},
};
56 changes: 28 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: Node.js CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
- name: Install dependencies
run: npm ci
- name: Check format
run: npm run check-format
- name: Run build
run: npm run build
- name: Run test
run: npm test
env:
BLOCKFROST_PROJECT_ID: mainnetTV9qV3mfZXbE6e44TVGMe1UoRlLrpSQt
name: Node.js CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
- name: Install dependencies
run: npm ci
- name: Check format
run: npm run check-format
- name: Run build
run: npm run build
- name: Run test
run: npm test
env:
BLOCKFROST_PROJECT_ID: mainnetTV9qV3mfZXbE6e44TVGMe1UoRlLrpSQt
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
build
coverage
node_modules
build
coverage
8 changes: 4 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build
build
8 changes: 4 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": false,
"trailingComma": "es5"
}
{
"singleQuote": false,
"trailingComma": "es5"
}
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2022 Minswap

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.
MIT License
Copyright (c) 2022 Minswap
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.
130 changes: 65 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
# Market Cap

Transparent, accurate and open-sourced circulating supply and market cap calculation for Cardano's native tokens.

## Overview

This package doesn't expose market cap by itself, but only circulating supply and total supply.

Market cap = Circulating supply \* Market price

Fully-diluted market cap = Total supply \* Market price

You can use [Blockfrost Adapter](https://github.com/minswap/blockfrost-adapter) to query market price from Minswap.

## Install

- NPM: `npm install @minswap/market-cap`
- Yarn: `yarn add @minswap/market-cap`

## Usage

```ts
import { supplyFetchers } from "@minswap/market-cap";

const minInfo = await supplyFetchers[
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
]();
console.log(minInfo);
// { circulating: '240813714.66121483', total: '5000000000' }
```

## How to add my token

1. Create a file in `src/tokens` with your token's name and export default a function of type `SupplyFetcher`.
2. Import the function into `src/index.ts` and add the corresponding entry in `supplyFetchers` map with the key being the concatenation of your token's policyID and assetName
3. Test your function:

```bash
# only if you use Blockfrost
export BLOCKFROST_PROJECT_ID=<your_blockfrost_key>
ONLY_TEST=<your_policy_id_concat_with_asset_name> npm test
```

4. Run format: `npm run format`

### Example

1. MIN token fetcher: [src/tokens/min.ts](src/tokens/min.ts)
2. Add entry to `index.ts`:

```ts
import minFetcher from "./tokens/min";

export const supplyFetchers: Record<string, SupplyFetcher> = {
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e": minFetcher,
...
};
```

3. Run test:

```bash
export BLOCKFROST_PROJECT_ID=<your_blockfrost_key>
ONLY_TEST=29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e npm test
```
# Market Cap
Transparent, accurate and open-sourced circulating supply and market cap calculation for Cardano's native tokens.
## Overview
This package doesn't expose market cap by itself, but only circulating supply and total supply.
Market cap = Circulating supply \* Market price
Fully-diluted market cap = Total supply \* Market price
You can use [Blockfrost Adapter](https://github.com/minswap/blockfrost-adapter) to query market price from Minswap.
## Install
- NPM: `npm install @minswap/market-cap`
- Yarn: `yarn add @minswap/market-cap`
## Usage
```ts
import { supplyFetchers } from "@minswap/market-cap";
const minInfo = await supplyFetchers[
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e"
]();
console.log(minInfo);
// { circulating: '240813714.66121483', total: '5000000000' }
```
## How to add my token
1. Create a file in `src/tokens` with your token's name and export default a function of type `SupplyFetcher`.
2. Import the function into `src/index.ts` and add the corresponding entry in `supplyFetchers` map with the key being the concatenation of your token's policyID and assetName
3. Test your function:
```bash
# only if you use Blockfrost
export BLOCKFROST_PROJECT_ID=<your_blockfrost_key>
ONLY_TEST=<your_policy_id_concat_with_asset_name> npm test
```
4. Run format: `npm run format`
### Example
1. MIN token fetcher: [src/tokens/min.ts](src/tokens/min.ts)
2. Add entry to `index.ts`:
```ts
import minFetcher from "./tokens/min";
export const supplyFetchers: Record<string, SupplyFetcher> = {
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e": minFetcher,
...
};
```
3. Run test:
```bash
export BLOCKFROST_PROJECT_ID=<your_blockfrost_key>
ONLY_TEST=29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e npm test
```
12 changes: 6 additions & 6 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
module.exports = {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
Loading