Skip to content

Commit

Permalink
Export types (minswap#4)
Browse files Browse the repository at this point in the history
* Export types

* CI check format

Signed-off-by: Nguyen Le Vu Long <[email protected]>

Co-authored-by: Nguyen Le Vu Long <[email protected]>
  • Loading branch information
hieupnh and longngn authored May 17, 2022
1 parent 5877e9f commit 56b0cda
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 87 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
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: ${{ secrets.BLOCKFROST_PROJECT_ID }}
- name: Run lint
run: npm run lint
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"scripts": {
"build": "rimraf build && rollup -c rollup.config.js",
"test": "jest",
"lint": "eslint src --ext .ts"
"format": "prettier --write **/*.{ts,tsx} && eslint --fix --ext .ts,.tsx .",
"check-format": "prettier --check **/*.{ts,tsx} && eslint --ext .ts,.tsx ."
},
"keywords": [
"minswap",
Expand Down Expand Up @@ -46,6 +47,7 @@
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^28.0.1",
"prettier": "^2.6.2",
"rollup": "^2.70.2",
"rollup-plugin-dts": "^4.2.1",
"rollup-plugin-esbuild": "^4.9.1",
Expand Down
29 changes: 29 additions & 0 deletions scripts/pump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

set -euo pipefail

version=$1

echo "update version field"
jq ".version = \"$version\"" <package.json >package.json.tmp
mv package.json.tmp package.json

jq ".version = \"$version\"" <package-lock.json >package-lock.json.tmp
mv package-lock.json.tmp package-lock.json

echo "build"
npm run build

echo "publish"
npm publish

echo "commit new version"
git add package.json package-lock.json
git commit -m "publish version v$version"

echo "tag version"
git tag v"$version"

echo "push to remote"
git push origin main
git push origin v"$version"
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import minFetcher from "./tokens/min";
import mintFetcher from "./tokens/mint";
import ntxFetcher from "./tokens/ntx";
import sundaeFetcher from "./tokens/sundae";
import { SupplyFetcher } from "./utils";
import { SupplyFetcher } from "./types";

export * from "./types";

export const supplyFetchers: Record<string, SupplyFetcher> = {
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e": minFetcher,
Expand All @@ -27,5 +29,6 @@ export const supplyFetchers: Record<string, SupplyFetcher> = {
db30c7905f598ed0154de14f970de0f61f0cb3943ed82c891968480a434c4150: clapFetcher,
b34b3ea80060ace9427bda98690a73d33840e27aaa8d6edb7f0c757a634e455441:
cnetaFetcher,
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74": mintFetcher,
"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74":
mintFetcher,
};
8 changes: 2 additions & 6 deletions src/tokens/aada.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const AADA = "8fef2d34078659493ce161a6c7fba4b56afefa8535296a5743f6958741414441";

Expand Down
7 changes: 2 additions & 5 deletions src/tokens/agix.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
defaultFetcherOptions,
getAxiosInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAxiosInstance } from "../utils";

const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => {
const axios = getAxiosInstance(options);
Expand Down
8 changes: 2 additions & 6 deletions src/tokens/clap.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const CLAP = "db30c7905f598ed0154de14f970de0f61f0cb3943ed82c891968480a434c4150";

Expand Down
8 changes: 2 additions & 6 deletions src/tokens/cneta.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const CNETA =
"b34b3ea80060ace9427bda98690a73d33840e27aaa8d6edb7f0c757a634e455441";
Expand Down
8 changes: 2 additions & 6 deletions src/tokens/lq.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const LQ = "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d244c51";

Expand Down
7 changes: 2 additions & 5 deletions src/tokens/meld.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
defaultFetcherOptions,
getAxiosInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAxiosInstance } from "../utils";

const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => {
const axios = getAxiosInstance(options);
Expand Down
8 changes: 2 additions & 6 deletions src/tokens/milk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const MILK = "8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa4d494c4b";

Expand Down
8 changes: 2 additions & 6 deletions src/tokens/min.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const MIN = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e";
const TREASURY_ADDRESSES = [
Expand Down
11 changes: 3 additions & 8 deletions src/tokens/mint.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
SupplyFetcherResponse,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const MINT = "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e74";
const TREASURY_ADDRESSES = [
"addr1v9urht2tqg7ncs7r545qdj2wn5tpam5l04t7eyermpmyvmg5xf2mt", // FISO
"addr1w9p9akyhpqsy0xq79g8hspy90xl9htxfrd3mama6py42jjgtvfgn8", // DripDropz
];

const fetcher: SupplyFetcher = async (options = defaultFetcherOptions): Promise<SupplyFetcherResponse> => {
const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => {
const blockFrost = getBlockFrostInstance(options);
const total = 100_000_000;
const treasury =
Expand Down
7 changes: 2 additions & 5 deletions src/tokens/ntx.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
defaultFetcherOptions,
getAxiosInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAxiosInstance } from "../utils";

const fetcher: SupplyFetcher = async (options = defaultFetcherOptions) => {
const axios = getAxiosInstance(options);
Expand Down
8 changes: 2 additions & 6 deletions src/tokens/sundae.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
defaultFetcherOptions,
getAmountInAddresses,
getBlockFrostInstance,
SupplyFetcher,
} from "../utils";
import { defaultFetcherOptions, SupplyFetcher } from "../types";
import { getAmountInAddresses, getBlockFrostInstance } from "../utils";

const SUNDAE =
"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145";
Expand Down
19 changes: 19 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type FetcherOptions = {
/**
* Fetch timeout in milliseconds. Default to 20s
*/
timeout?: number;
};

export const defaultFetcherOptions: FetcherOptions = {
timeout: 20_000,
};

export type SupplyFetcherResponse = {
circulating: string;
total: string;
};

export type SupplyFetcher = (
options?: FetcherOptions
) => Promise<SupplyFetcherResponse>;
18 changes: 1 addition & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { BlockFrostAPI } from "@blockfrost/blockfrost-js";
import axios, { AxiosInstance } from "axios";

export type FetcherOptions = {
/**
* Fetch timeout in milliseconds. Default to 20s
*/
timeout?: number;
};

export const defaultFetcherOptions: FetcherOptions = {
timeout: 20_000,
};

export type SupplyFetcherResponse = {
circulating: string;
total: string;
}

export type SupplyFetcher = (options?: FetcherOptions) => Promise<SupplyFetcherResponse>;
import { FetcherOptions } from "./types";

export function getBlockFrostInstance(options: FetcherOptions): BlockFrostAPI {
return new BlockFrostAPI({
Expand Down

0 comments on commit 56b0cda

Please sign in to comment.