Skip to content

Commit

Permalink
feat: rename, update dependencies and configs.
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>
  • Loading branch information
mpetrunic committed Aug 7, 2023
1 parent e09caf8 commit d29710b
Show file tree
Hide file tree
Showing 10 changed files with 676 additions and 2,323 deletions.
110 changes: 1 addition & 109 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,3 @@
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'header', 'deprecation', 'eslint-plugin-tsdoc', 'no-null'],
extends: [
'airbnb-base',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
],
rules: {
'deprecation/deprecation': 'error',
'class-methods-use-this': ['error'],
'no-unused-expressions': ['error'],
'no-continue': 'off',
'no-underscore-dangle': 'off',
'import/prefer-default-export': 'off',
'lines-between-class-members': 'off',
'no-use-before-define': ['error'],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],
'no-console': ['error', { allow: ['error', 'info', 'warn'] }],
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/prefer-for-of': ['error'],
'@typescript-eslint/consistent-type-assertions': ['error'],
'@typescript-eslint/explicit-member-accessibility': ['error'],
'@typescript-eslint/member-delimiter-style': ['error'],
'@typescript-eslint/member-ordering': [
'error',
{ default: ['public-static-field', 'public-instance-method'] },
],
'@typescript-eslint/no-extraneous-class': ['error'],
'@typescript-eslint/no-unnecessary-boolean-literal-compare': ['error'],
'@typescript-eslint/no-unnecessary-qualifier': ['error'],
'@typescript-eslint/no-unnecessary-type-arguments': ['error'],
'@typescript-eslint/prefer-function-type': ['error'],
'@typescript-eslint/prefer-includes': ['error'],
'@typescript-eslint/prefer-nullish-coalescing': ['error'],
'@typescript-eslint/prefer-optional-chain': ['error'],
'@typescript-eslint/prefer-readonly': ['error'],
'@typescript-eslint/prefer-reduce-type-parameter': ['error'],
'@typescript-eslint/prefer-string-starts-ends-with': ['error'],
'@typescript-eslint/prefer-ts-expect-error': ['error'],
'@typescript-eslint/promise-function-async': ['error'],
'@typescript-eslint/require-array-sort-compare': ['error'],
'@typescript-eslint/switch-exhaustiveness-check': ['error'],
'@typescript-eslint/type-annotation-spacing': ['error'],
// Multiple constructors are more readable
'@typescript-eslint/unified-signatures': 'off',
'@typescript-eslint/no-unused-expressions': ['error'],
'@typescript-eslint/no-useless-constructor': ['error'],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
null: "Use 'undefined' instead of 'null'",
},
},
],
'@typescript-eslint/no-unused-vars': 'warn',
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],
'no-await-in-loop': ['error'],
'no-restricted-syntax': [
'error',
{
selector: 'ForInStatement',
message:
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
},
{
selector: 'LabeledStatement',
message:
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
},
{
selector: 'WithStatement',
message:
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
},
],
'no-null/no-null': ['error'],
'tsdoc/syntax': 'warn',
},
globals: {
BigInt: true,
},
parserOptions: {
ecmaVersion: 2016,
project: './tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
extends: "@chainsafe"
};
5 changes: 0 additions & 5 deletions .lintstagedrc.json

This file was deleted.

17 changes: 0 additions & 17 deletions .npmignore

This file was deleted.

44 changes: 0 additions & 44 deletions CHANGELOG.md

This file was deleted.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ yarn add @chainsafe/web3.js-chainlink-plugin

### Installing Version `4.x` of `web3`

When adding the `web3` package to your project, make sure to use version `4.x`. You can append `@4.0.2-dev.af57eae.0` tag to install the latest version of 4 that this plugin was tested with:
When adding the `web3` package to your project, make sure to use version `4.x`:

- `npm i -S web3@4.0.2-dev.af57eae.0`
- `yarn add web3@4.0.2-dev.af57eae.0`
- `npm i -S web3@4.0.3`
- `yarn add web3@4.0.3`

> **_NOTE_**
> If 4.x was already released, you are good to just use `web3` without appending anything to it.
Expand All @@ -33,16 +33,16 @@ To verify you have the correct `web3` version installed, after adding the packag

```json
"dependencies": {
"web3": "4.0.2-dev.af57eae.0"
"web3": "4.0.3"
}
```

### Registering the Plugin with a web3.js Instance

After importing `ChainlinkPlugin` from `@chainsafe/web3.js-chainlink-plugin` and `Web3` from `web3`, register an instance of `ChainlinkPlugin` with an instance of `Web3` like so:
After importing `ChainlinkPlugin` from `@chainsafe/web3-plugin-chainlink` and `Web3` from `web3`, register an instance of `ChainlinkPlugin` with an instance of `Web3` like so:

```typescript
import { ChainlinkPlugin } from '@chainsafe/web3.js-chainlink-plugin';
import { ChainlinkPlugin } from '@chainsafe/web3-plugin-chainlink';
import { Web3 } from 'web3';

const web3 = new Web3('YOUR_PROVIDER_URL');
Expand Down Expand Up @@ -81,7 +81,7 @@ The `getPrice` method, accepts `MainnetPriceFeeds | GoerliPriceFeeds | Address`
Under the hood, this method is calling the `latestRoundData` for the specified price feed, more information about it can be found [here](https://docs.chain.link/data-feeds/price-feeds/api-reference#latestrounddata).

```typescript
import { ChainlinkPlugin, MainnetPriceFeeds } from '@chainsafe/web3.js-chainlink-plugin';
import { ChainlinkPlugin, MainnetPriceFeeds } from '@chainsafe/web3-plugin-chainlink';
import { Web3 } from 'web3';

const web3 = new Web3('YOUR_PROVIDER_URL');
Expand Down
12 changes: 0 additions & 12 deletions cypress/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,7 @@ module.exports = {
},
],
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
net: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('readable-stream'),
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
Expand Down
43 changes: 10 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chainsafe/web3.js-chainlink-plugin",
"version": "9.9.9",
"name": "@chainsafe/web3-plugin-chainlink",
"version": "0.1.0-alpha.0",
"description": "A Web3.js 4.x Plugin for Interacting With Chainlink Smart Contracts",
"main": "lib/index.js",
"repository": {
Expand All @@ -16,65 +16,42 @@
],
"scripts": {
"build": "tsc --build",
"build:web": "npx webpack",
"build:web": "webpack",
"clean": "rimraf lib && rimraf dist",
"format": "prettier --write '**/*'",
"lint": "eslint --ext .js,.ts .",
"lint:fix": "eslint --fix --ext .js,.ts .",
"post-black-box": "./scripts/black_box_test_helpers.sh stop",
"pre-black-box": "./scripts/black_box_test_helpers.sh startBackgroundAndPublish",
"prebuild": "yarn clean",
"prepare": "husky install",
"test": "jest --config=./test/unit/jest.config.js",
"test:black-box": "yarn pre-black-box && ./scripts/black_box_test_helpers.sh runTests",
"test:coverage": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text",
"test:e2e:chrome": "npx cypress run --headless --browser chrome",
"test:e2e:firefox": "npx cypress run --headless --browser firefox",
"test:e2e:electron": "npx cypress run --headless --browser electron",
"test:e2e:chrome": "cypress run --headless --browser chrome",
"test:e2e:firefox": "cypress run --headless --browser firefox",
"test:e2e:electron": "cypress run --headless --browser electron",
"test:unit": "jest --config=./test/unit/jest.config.js",
"test:all": "yarn && yarn build && yarn test && yarn run test:e2e:firefox && yarn run test:black-box"
},
"devDependencies": {
"@babel/core": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@chainsafe/eslint-config": "^2.0.0",
"@cypress/webpack-preprocessor": "^5.15.5",
"@types/jest": "^28.1.6",
"@types/node": "^18.7.23",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"assert": "^2.0.0",
"babel-loader": "^8.0.2",
"crypto-browserify": "^3.12.0",
"cypress": "^12.3.0",
"cypress-jest-adapter": "^0.1.1",
"declaration-bundler-webpack-plugin": "^1.0.3",
"eslint": "^8.20.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-deprecation": "^1.3.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-tsdoc": "^0.2.17",
"husky": "^8.0.1",
"eslint": "^8",
"jest": "^28.1.3",
"jest-extended": "^3.0.1",
"lint-staged": "^13.0.3",
"npm-auth-to-token": "^1.0.0",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.24",
"process": "^0.11.10",
"ts-jest": "^28.0.7",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"web3": "^4.0.2-dev.af57eae.0",
"web3": "^4.0.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"peerDependencies": {
"web3": ">= 4.0.2-dev.af57eae.0 < 5"
"web3": ">= 4.0.3"
}
}
6 changes: 3 additions & 3 deletions src/chainlink_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, Contract, ContractAbi, Web3PluginBase, validator } from 'web3';
import { AggregatorV3InterfaceABI } from './aggregator_v3_interface_abi';
import { GoerliPriceFeeds, MainnetPriceFeeds } from './types';
import { GoerliPriceFeeds, MainnetPriceFeeds, Price } from './types';

export class ChainlinkPlugin extends Web3PluginBase {
public pluginNamespace: string;
Expand All @@ -25,14 +25,14 @@ export class ChainlinkPlugin extends Web3PluginBase {
public async getPrice(
priceFeedAddress: MainnetPriceFeeds | GoerliPriceFeeds | Address,
aggregatorInterfaceAbi: ContractAbi = this.defaultAggregatorInterfaceAbi,
) {
): Promise<Price> {
if (!validator.isAddress(priceFeedAddress)) {
throw new Error(
`Provided priceFeedAddress is not a valid address: ${priceFeedAddress}`,
);
}

const _contract: Contract<typeof aggregatorInterfaceAbi> = new Contract(
const _contract: Contract<typeof AggregatorV3InterfaceABI> = new Contract(
aggregatorInterfaceAbi,
priceFeedAddress,
);
Expand Down
17 changes: 0 additions & 17 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,4 @@ module.exports = {
},
],
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
fs: false,
net: false,
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('readable-stream'),
},
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
};
Loading

0 comments on commit d29710b

Please sign in to comment.