Skip to content

Commit

Permalink
feat(library): Make emprops-clients a library (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrordzl authored Jul 24, 2024
1 parent 84bc8f5 commit f1dc149
Show file tree
Hide file tree
Showing 21 changed files with 1,112 additions and 447 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,jsx,ts,tsx,json}]
indent_size = 2
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"node": true
},
"extends": [
"plugin:prettier/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["prettier", "@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"no-prototype-builtins": "warn",
"no-async-promise-executor": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "warn"
}
}
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: build
on: [pull_request]
jobs:
build:
name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['18.x']
os: [ubuntu-latest, macOS-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn lint

- name: Build
run: yarn build
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish NPM

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install npm toolchain
uses: actions/setup-node@v2
with:
node-version: 18

- run: npm install
- run: npm run build
- run: npm version ${{github.ref_name}} --git-tag-version false
- run: npm pkg set version=${{github.ref_name}}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "release: ${{github.ref_name}}"
branch: master
file_pattern: package.json
- run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
- run: npm publish --access public
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
node_modules
.DS_Store
node_modules
dist
.env
types
*-error.log
output
50 changes: 50 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import prettier from "eslint-plugin-prettier";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import globals from "globals";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: ["**/node_modules/", "**/dist/", "**/types/"],
},
...compat.extends(
"plugin:prettier/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
),
{
plugins: {
prettier,
"@typescript-eslint": typescriptEslint,
},

languageOptions: {
globals: {
...globals.node,
},

parser: tsParser,
},
ignores: ["node_modules/*", "dist/*", "types/*"],
files: ["**/*.ts"],
rules: {
"@typescript-eslint/no-unused-vars": "error",
"no-prototype-builtins": "warn",
"no-async-promise-executor": "warn",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "warn",
},
},
];
4 changes: 0 additions & 4 deletions index.ts

This file was deleted.

35 changes: 22 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
{
"name": "contract-client",
"name": "@emprops/clients",
"version": "0.0.1",
"description": "Library to interact with EmProps smart contracts in different blockchains",
"main": "index.js",
"description": "Core clients EmProps library",
"main": "dist/index.js",
"types": "types/index.d.ts",
"files": [
"dist",
"types"
],
"author": "David Rodriguez <[email protected]>",
"license": "MIT",
"private": true,
"license": "UNLICENSED",
"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"build": "rm -rf dist && tsc",
"lint": "eslint --fix ." },
"dependencies": {
"@dynamic-labs/utils": "^2.2.7",
"discord.js": "^14.15.3",
"typescript": "^5.4.5",
"viem": "^2.16.5",
"viem": "^2.17.10",
"web3": "^4.10.0"
},
"devDependencies": {
"@types/node": "^20.12.13",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0"
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"eslint": "^9.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"typescript": "^5.5.4"
},
"engines": {
"node": ">=18.0.0"
}
}
12 changes: 12 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

cd packages/core
rm -rf node_modules
yarn install -f
npm version $1
npm publish
cd ../..
git add .
git commit -m "release: publish $1"
git tag $1
git push origin master --tags
2 changes: 1 addition & 1 deletion src/blockchains/base/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CollectionStatus,
QueryResponse,
TransactionResponse,
} from "../../types";
} from "../types";
import { handleTransactionResponse } from "../utils";
import { WalletClient, encodeFunctionData } from "viem";
import { getChain } from "@dynamic-labs/utils";
Expand Down
2 changes: 1 addition & 1 deletion src/blockchains/ethereum/v0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CollectionStatus,
QueryResponse,
TransactionResponse,
} from "../../types";
} from "../types";
import { WalletClient, encodeFunctionData } from "viem";
import { getChain } from "@dynamic-labs/utils";
export interface CollectionTransactionEthereumParams
Expand Down
2 changes: 1 addition & 1 deletion src/blockchains/ethereum/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
CollectionStatus,
QueryResponse,
TransactionResponse,
} from "../../types";
} from "../types";
import { WalletClient, encodeFunctionData } from "viem";
import { getChain } from "@dynamic-labs/utils";
export interface CollectionTransactionEthereumParams
Expand Down
34 changes: 26 additions & 8 deletions src/factory.ts → src/blockchains/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCollectionV1 } from "./blockchains/base/v1";
import { EthereumCollectionV0 } from "./blockchains/ethereum/v0";
import { EthereumCollectionV1 } from "./blockchains/ethereum/v1";
import { BaseCollectionV1 } from "./base/v1";
import { EthereumCollectionV0 } from "./ethereum/v0";
import { EthereumCollectionV1 } from "./ethereum/v1";
import { BlockchainType, CollectionContract, VersionType } from "./types";
import { WalletClient } from "viem";

Expand All @@ -13,7 +13,13 @@ export class BaseFactoryContract {
rpcUrl: string,
): CollectionContract {
if (version === "v1") {
return new BaseCollectionV1(walletProvider, abi, address, rpcUrl, version);
return new BaseCollectionV1(
walletProvider,
abi,
address,
rpcUrl,
version,
);
}
throw new Error("Invalid BASE contract version");
}
Expand All @@ -28,10 +34,22 @@ export class EthereumFactoryContract {
rpcUrl: string,
): CollectionContract {
if (version === "v0") {
return new EthereumCollectionV0(walletProvider, abi, address, rpcUrl, version);
return new EthereumCollectionV0(
walletProvider,
abi,
address,
rpcUrl,
version,
);
}
if (version === "v1") {
return new EthereumCollectionV1(walletProvider, abi, address, rpcUrl, version);
return new EthereumCollectionV1(
walletProvider,
abi,
address,
rpcUrl,
version,
);
}
throw new Error("Invalid ETHEREUM contract version");
}
Expand All @@ -55,14 +73,14 @@ export class ContractFactoryFacade {
rpcUrl,
);
}
if(blockchain === "ETHEREUM") {
if (blockchain === "ETHEREUM") {
return new EthereumFactoryContract().createCollectionContract(
walletProvider as WalletClient,
version,
address,
abi,
rpcUrl,
)
);
}
return undefined;
}
Expand Down
4 changes: 4 additions & 0 deletions src/blockchains/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./types";
export * from "./factory";
export * from "./base/v1";
export * from "./utils";
18 changes: 10 additions & 8 deletions src/types.ts → src/blockchains/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ export interface CollectionContract {
}>
>;
getTokensMinted<T>(params: T): Promise<
QueryResponse<{
QueryResponse<{
tokensMinted: {
allowlistCount: number;
freelistCount: number;
}
}>>;
getCollectionConfig<T>(params:T): Promise<
freelistCount: number;
};
}>
>;
getCollectionConfig<T>(params: T): Promise<
QueryResponse<{
maxBatchMintAllowed: number;
startDate: number;
endDate: number;
enableBatchMint: boolean;
}>>
}>
>;
getPlatformConfig(): Promise<
QueryResponse<{
maxCollectionSize: string;
Expand All @@ -42,15 +44,15 @@ export interface CollectionContract {
>;
}

export type TransactionResponse = SendTransactionReturnType
export type TransactionResponse = SendTransactionReturnType;

export interface QueryResponse<T> {
data: T | null;
error: Error | null;
}
export type ContractType = "collection" | "token";
export type BlockchainType = "BASE" | "ETHEREUM";
export type VersionType = "v0" | "v1" ;
export type VersionType = "v0" | "v1";
export enum CollectionStatus {
OFF = 0,
ON = 1,
Expand Down
Loading

0 comments on commit f1dc149

Please sign in to comment.