Skip to content

Commit

Permalink
40 add support to interact with 010 rankify interfaces (#52)
Browse files Browse the repository at this point in the history
* added 0.10 rankify contracts basic support

* updated index file

* moved rank token methods to separate class

* refactored sdk to use viem  (#48)

* build suceeds

* added prebuild step to copy and use abi's within srcs

* fix wrong imports

* update prebuild script

* update multipass class to use chain ID as a number

---------

Co-authored-by: theKosmoss <[email protected]>

* Peersky/40 add support 010 rankify/with viem (#49)

* build suceeds

* added prebuild step to copy and use abi's within srcs

* fix wrong imports

* generate chain id mapping to supported chains path during sdk build

* Refactored sdk to accept chainId instead of chain

* made linter to highlight more issues and fixed those

* added jest for TDD

* multipass unit test

* updated ci cd

* upd ci

* added tests to player, fixed bug

* validate address in distributor constructor

* multipass constructor tweaks

* added abi files to index & generator

* export abis as object

* reexport abis

* fix dist import require paths

* Revert "fix dist import require paths"

This reverts commit cf816da.

* modified build scipt instead

* up ci

* upd MAO distributor class getter namings

* updated generation scripts and decoupled multipass in base and registrar classes

* added block range for getEvents

* tests mock deployments, removed console logs

* remove console logs

* happy linter - happy life

* added types node

* lockfile

* add readme and setup local dev script

* env sertup process

* fix bug

* docstrings & readme upd

* changeset

* upodate docs generation

* wip

* wip

* TDD game master

* updates for monitor

---------

Co-authored-by: theKosmoss <[email protected]>
  • Loading branch information
peersky and theKosmoss authored Dec 19, 2024
1 parent 96c4b5c commit 25ba1db
Show file tree
Hide file tree
Showing 47 changed files with 6,973 additions and 3,006 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-poems-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rankify-js": minor
---

added script to locally bring up development enviroment
5 changes: 5 additions & 0 deletions .changeset/serious-suns-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rankify-js": major
---

adapted client library for rankify v0.10.0 release
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Environment
NODE_ENV="TEST"

# RPC URLs
FORK_RPC_URL="https://arb1.arbitrum.io/rpc"

# Repository paths - update these to your local paths
RANKIFY_CONTRACTS_PATH="/path/to/rankify/contracts"
EDS_PATH="/path/to/eds"
MULTIPASS_PATH="/path/to/multipass"
9 changes: 5 additions & 4 deletions .github/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: setup
description: 'Setup the environment for the CI'
runs:
using: 'composite'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install pnpm
Expand All @@ -11,15 +12,15 @@ runs:
version: 9
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18.17.1
node-version: lts/*
cache: 'pnpm'
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
pull_request:
branches: [main,staging]
types: [opened, reopened, labeled, synchronize]
env:
NODE_ENV: 'TEST'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: './.github/setup'
- name: Building
run: pnpm build
- name: Linting
run: pnpm lint:ci

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: './.github/setup'

- name: Running tests
run: pnpm test:ci
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: "./.github/setup"
with:
node-version: 18.x
node-version: lts/*
- name: install dependencies
run: pnpm install
- name: build package
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_modules
.secrets
/.idea/*
.DS_Store
src/abis
.env
docs/
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
.changeset
pnpm-lock.yaml
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"arrowParens": "always"
}
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,92 @@
# SDK

This is SDK for use with Rankify game. You can use this to ease interaction with smart contracts
This is SDK for use with Rankify game. You can ease interaction with smart contracts.

## Prerequisites

Before setting up the local development environment, ensure you have the following installed:

1. **Node.js and pnpm**
```bash
# Using homebrew
brew install node
npm install -g pnpm
```

2. **Foundry (for Anvil)**
```bash
curl -L https://foundry.paradigm.xyz | bash
foundryup
```

3. **tmux**
```bash
# Using homebrew
brew install tmux
```

## Local Development Setup

To set up your local development environment:

1. Create your environment file:
```bash
cp .env.example .env
```
Then edit `.env` to set your local repository paths.

2. Set the required environment variables:
```bash
export RANKIFY_CONTRACTS_PATH="/path/to/rankify/contracts"
export EDS_PATH="/path/to/eds"
export MULTIPASS_PATH="/path/to/multipass"
```

3. Make the setup script executable:
```bash
chmod +x scripts/setup-local-dev.sh
```

4. Run the setup script:
```bash
source .env && ./scripts/setup-local-dev.sh
```

This will:
- Start a local Anvil development network in a tmux session (or use existing one if running)
- Install dependencies for all repositories
- Run local deployment scripts (`playbook/utils/deploy-to-local-anvil.sh`) in each repository
- Set up local pnpm links between packages

The script uses a fixed mnemonic for consistent addresses across runs.

### Managing Anvil

- View Anvil logs: `tmux attach -t anvil`
- Detach from logs: Press `Ctrl+B` then `D`
- Stop Anvil: `tmux kill-session -t anvil`

## Documentation

The SDK comes with comprehensive API documentation generated using TypeDoc. The documentation is automatically generated during the package build process and is included in the npm package.

### Generating Documentation

To generate the documentation locally:

```bash
pnpm run docs
```

This will create a `docs` directory with the generated documentation.

For development, you can use the watch mode:

```bash
pnpm run docs:watch
```

### Accessing Documentation

- **Local Development**: Open `docs/index.html` in your browser after generating the documentation
- **Published Package**: Documentation is available through the npm package page
66 changes: 33 additions & 33 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import promise from "eslint-plugin-promise";
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";
import prettier from "eslint-plugin-prettier";
import tseslint from "typescript-eslint";
import prettierConfig from "eslint-config-prettier";

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 [
export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
prettierConfig,
{
ignores: ["deployments/", "coverage/**", "docs/templates/", "**/node_modules/"],
// Base configuration for all files
ignores: ["**/node_modules/**", "**/dist/**", "src/abis/*.ts", "scripts", "copyPackageFile.js"],
},
...compat.extends("eslint:recommended", "plugin:promise/recommended", "prettier"),
{
plugins: {
promise,
prettier, // Add Prettier plugin
"@typescript-eslint": tseslint.plugin,
},
// TypeScript files configuration
files: ["**/*.ts"],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.mocha,
artifacts: "readonly",
contract: "readonly",
assert: "readonly",
web3: "readonly",
parserOptions: {
project: ["./tsconfig.json", "./tsconfig.test.json"],
tsconfigRootDir: ".",
},
parser: tsParser,
},
rules: {
"no-unused-vars": "warn",
"prettier/prettier": "error", // Add Prettier as an ESLint rule
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/await-thenable": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-require-imports": "off",
},
files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"],
},
];
{
// JavaScript files configuration
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
ignores: ["src/**/*.ts", "**/node_modules/**", "**/dist/**"],
extends: [tseslint.configs.disableTypeChecked],
languageOptions: {
sourceType: "module",
},
rules: {
// Add JavaScript-specific rules here if needed
},
}
);
18 changes: 18 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('jest').Config} */
export default {
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
useESM: true,
},
],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
59 changes: 35 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@peeramid-labs/sdk",
"name": "rankify-js",
"description": "Peeramid Labs js client library",
"version": "1.1.0",
"private": "true",
Expand All @@ -22,45 +22,56 @@
}
},
"scripts": {
"lint:fix": "prettier --write '**/*.ts' && eslint --fix --no-ignore",
"lint": "eslint",
"prebuild": "jq '.type = \"commonjs\"' package.json > temp.json && mv temp.json package.json",
"lint:fix": "prettier --write 'src/**/*.{ts,js}' && eslint --fix .",
"lint": "eslint .",
"generate-chain-mapping": "node ./scripts/generateChainMapping.mjs",
"prebuild": "pnpm generate-chain-mapping && node scripts/copyAbi.cjs && jq '.type = \"commonjs\"' package.json > temp.json && mv temp.json package.json",
"build-esm": "tsc --project tsconfig.esm.json",
"build-all": "pnpm run build-commonjs && pnpm run build-esm",
"build-commonjs": "tsc --project tsconfig.commonjs.json",
"build": "pnpm build-all && node ./copyPackageFile.js prod",
"build": "pnpm build-all && node ./scripts/copyPackageFile.cjs prod",
"postbuild": "jq '.type = \"module\"' package.json > temp.json && mv temp.json package.json && cp README.md dist && cp -r .changeset ./dist/.changeset && prettier --write \"dist/**/*.{ts,js,json}\" && cd ./dist && pnpm install",
"dist": "changeset && changeset version && pnpm build && cp -r .changeset ./dist && cd dist && pnpm changeset publish",
"version": "changeset version",
"release": "pnpm build && cd ./dist && changeset publish"
"release": "pnpm build && cd ./dist && changeset publish",
"test": "jest",
"test:ci": "pnpm generate-chain-mapping && node scripts/copyAbi.cjs && pnpm jest",
"test:watch": "jest --watch",
"lint:ci": "pnpm generate-chain-mapping && node scripts/copyAbi.cjs && pnpm lint",
"docs": "typedoc",
"docs:watch": "typedoc --watch",
"prepublishOnly": "pnpm run build && pnpm run docs"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@peeramid-labs/multipass": "^0.3.1",
"@peersky/eth-auth": "^2.0.0",
"@peeramid-labs/eds": "^2.2.0",
"@peeramid-labs/multipass": "^0.3.2",
"crypto-js": "^4.1.1",
"ethers": "^5.0.0",
"lodash": "^4.17.21",
"rankify-contracts": "^0.9.3",
"typescript": "^5.0.4"
"rankify-contracts": "^0.10.1",
"viem": "^2.21.55"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@peersky/eth-auth": "^2.0.0",
"@eslint/js": "^8.56.0",
"@jest/globals": "^29.7.0",
"@types/crypto-js": "^4.1.3",
"globals": "^15.9.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^8.4.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"eslint": "^9.9.1",
"eslint-plugin-prettier": "^5.2.1",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-plugin-jest": "^28.9.0",
"globals": "^15.9.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"typescript": "^5.0.4"
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0",
"typedoc": "^0.25.7",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-theme-hierarchy": "^4.1.2"
}
}
Loading

0 comments on commit 25ba1db

Please sign in to comment.