Skip to content

Commit

Permalink
use v1.8.0 in cluster creation (#32)
Browse files Browse the repository at this point in the history
* support v1.8.0

* remove not needed function

* add tests for v1.8.0

* test to validate  v1.7.0 lock

* add tests for deposit_amounts

* deposit amounts validation

* clean the code

* fix lint errors

* use v1.7.0 for creation

* use v1.8.0 in cluster creation

* update deposit amount validation

* fix spelling mistakes

* fix checked folder in script

* use any type to fix Wallet type is not Signer type

* fix spelling

* apply lint and prettier fixes

* turn off eslint rules that contradict with prettier rules

* address review comments

* fix prettier stuff
  • Loading branch information
HananINouman authored Jul 2, 2024
1 parent ccedcbf commit 1169e42
Show file tree
Hide file tree
Showing 30 changed files with 2,626 additions and 2,250 deletions.
67 changes: 34 additions & 33 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
env: {
browser: true,
es2021: true,
},
extends: 'standard-with-typescript',
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
"extends": "standard-with-typescript",
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["**/dist/**"],
"rules": {
"@typescript-eslint/strict-boolean-expressions": 0,
"@typescript-eslint/comma-dangle": 0,
"@typescript-eslint/dot-notation": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/non-nullable-type-assertion-style": 0,
"no-useless-catch": 0,
"new-cap": 0,
}
}
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
ignorePatterns: ['**/dist/**'],
rules: {
'@typescript-eslint/strict-boolean-expressions': 0,
'@typescript-eslint/comma-dangle': 0,
'@typescript-eslint/dot-notation': 0,
'@typescript-eslint/indent': 0,
'@typescript-eslint/consistent-type-definitions': 0,
'@typescript-eslint/non-nullable-type-assertion-style': 0,
'@typescript-eslint/semi': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'no-useless-catch': 0,
'new-cap': 0,
},
};
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- name: Check eslint rules
run: yarn run lint-ci

- name: Prettier
run: npm run prettier-ci

- name: Build SDK
run: yarn run build

Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"arrowParens": "avoid"
}

5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

#### [v1.0.17](https://github.com/ObolNetwork/obol-sdk/compare/v1.0.16...v1.0.17)

- revert back to using git changelog [`#46`](https://github.com/ObolNetwork/obol-sdk/pull/46)
- Hanan/ta nd c [`#44`](https://github.com/ObolNetwork/obol-sdk/pull/44)

#### [v1.0.16](https://github.com/ObolNetwork/obol-sdk/compare/v1.0.15...v1.0.16)

> 24 May 2024
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
![Obol Logo](https://obol.tech/obolnetwork.png)
![Obol Logo](https://obol.org/obolnetwork.png)

<h1 align="center">Obol SDK</h1>

This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.tech/api).
This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.org/api).

## Getting Started

Checkout our [docs](https://docs.obol.tech/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-sdk). Further guides and walkthroughs coming soon.
Checkout our [docs](https://docs.obol.org/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-sdk). Further guides and walkthroughs coming soon.

## Terms and Conditions
To use obol-sdk and in order to be able to create a cluster definition or accept an invite to join a cluster, you must accept the [latest Obol terms and conditions](https://obol.tech/terms.pdf) by calling acceptObolLatestTermsAndConditions.
To use obol-sdk and in order to be able to create a cluster definition or accept an invite to join a cluster, you must accept the [latest Obol terms and conditions](https://obol.org/terms.pdf) by calling acceptObolLatestTermsAndConditions.

## Contributing

Expand Down
7 changes: 7 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
// This will lint and format TypeScript
'**/*.(ts|tsx)': filenames => [
`npx eslint --fix ${filenames.join(' ')}`,
`npx prettier --write ${filenames.join(' ')}`,
],
}
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@obolnetwork/obol-sdk",
"version": "1.0.17",
"version": "1.0.16",
"description": "A package for creating Distributed Validators using the Obol API.",
"bugs": {
"url": "https://github.com/obolnetwork/obol-sdk/issues"
},
"homepage": "https://docs.obol.tech/",
"homepage": "https://docs.obol.org/",
"keywords": [
"Obol",
"Distributed Validators",
Expand All @@ -20,13 +20,15 @@
"npm:publish": "npm publish --tag latest",
"release": "release-it",
"release:dry": "release-it --dry-run --no-npm",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint-ci": "eslint \"{src,apps,libs,test}/**/*.ts\""
"lint": "eslint \"{src,test}/**/*.{js,ts}\" --fix",
"lint-ci": "eslint \"{src,test}/**/*.{js,ts}\"",
"prettier-ci": "prettier --check \"{src,test}/**/*.{js,ts}\"",
"prettier": "prettier --write \"{src,test}/**/*.{js,ts}\""
},
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/src/index.js",
"typings": "./dist/types/src/index.d.ts",
"author": "Obol Labs (https://obol.tech)",
"author": "Obol Labs (https://obol.org)",
"repository": {
"type": "git",
"url": "git+https://github.com/obolnetwork/obol-sdk.git"
Expand Down Expand Up @@ -65,15 +67,18 @@
"@types/semver": "^7.5.8",
"@types/uuid": "^9.0.1",
"eslint": "^8.57.0",
"husky": "^9.0.11",
"jest": "^28.1.3",
"lint-staged": "^15.2.2",
"msw": "^2.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"release-it": "^17.2.1",
"ts-jest": "^28.0.8",
"tsup": "^6.7.0",
"typedoc": "^0.25.7",
"typedoc-plugin-markdown": "^4.0.0-next.50",
"typescript": "^5.3.3"
"typescript": "~5.3.3"
},
"engines": {
"node": ">= 16"
Expand Down
45 changes: 38 additions & 7 deletions src/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
import Ajv, { type ErrorObject } from 'ajv'
import Ajv, { type ErrorObject } from 'ajv';
import { parseUnits } from 'ethers';

export function validatePayload (
function validDepositAmounts(data: boolean, deposits: string[]): boolean {
let sum = 0;
// from ether togwei is same as from gwei to wei
const maxDeposit = Number(parseUnits('32', 'gwei'));
const minDeposit = Number(parseUnits('1', 'gwei'));

for (const element of deposits) {
const amountInGWei = Number(element);

if (
!Number.isInteger(amountInGWei) ||
amountInGWei > maxDeposit ||
amountInGWei < minDeposit
) {
return false;
}
sum += amountInGWei;
}
if (sum / minDeposit !== 32) {
return false;
} else {
return true;
}
}

export function validatePayload(
data: any,
schema: any,
): ErrorObject[] | undefined | null | boolean {
const ajv = new Ajv()
const validate = ajv.compile(schema)
const isValid = validate(data)
const ajv = new Ajv();
ajv.addKeyword({
keyword: 'validDepositAmounts',
validate: validDepositAmounts,
errors: true,
});
const validate = ajv.compile(schema);
const isValid = validate(data);
if (!isValid) {
throw new Error(
`Schema compilation errors', ${validate.errors?.[0].message}`,
)
);
}
return isValid
return isValid;
}
40 changes: 22 additions & 18 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
// src/resources/base.ts
import { DEFAULT_BASE_URL, DEFAULT_CHAIN_ID, SDK_VERSION } from './constants.js'
import { FORK_MAPPING } from './types.js'
import {
DEFAULT_BASE_URL,
DEFAULT_CHAIN_ID,
SDK_VERSION,
} from './constants.js';
import { FORK_MAPPING } from './types.js';

interface Config {
baseUrl?: string
chainId?: FORK_MAPPING
baseUrl?: string;
chainId?: FORK_MAPPING;
}

export abstract class Base {
baseUrl: string
chainId: number
fork_version: string
baseUrl: string;
chainId: number;
fork_version: string;

constructor ({
constructor({
baseUrl = DEFAULT_BASE_URL,
chainId = DEFAULT_CHAIN_ID,
}: Config) {
this.baseUrl = baseUrl
this.chainId = chainId
this.fork_version = FORK_MAPPING[this.chainId]
this.baseUrl = baseUrl;
this.chainId = chainId;
this.fork_version = FORK_MAPPING[this.chainId];
}

protected async request<T>(
endpoint: string,
options?: RequestInit,
): Promise<T> {
const url = `${this.baseUrl}${endpoint}`
const url = `${this.baseUrl}${endpoint}`;
const config = {
...options,
headers: {
'Content-Type': 'application/json',
'User-Agent': `Obol-SDK/${SDK_VERSION}`,
...options?.headers,
},
}
};

try {
const response = await fetch(url, config)
const response = await fetch(url, config);
if (response.ok) {
return await response.json()
return await response.json();
} else {
const errorResponse = await response.json()
throw errorResponse
const errorResponse = await response.json();
throw errorResponse;
}
} catch (e: any) {
throw e
throw e;
}
}
}
Loading

0 comments on commit 1169e42

Please sign in to comment.