-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use v1.8.0 in cluster creation (#32)
* 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
1 parent
ccedcbf
commit 1169e42
Showing
30 changed files
with
2,626 additions
and
2,250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(' ')}`, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.