Skip to content

Commit

Permalink
refactor: remove ethers and web3 from the project (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDiscotech authored Oct 19, 2023
1 parent 507e13e commit 1863726
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 164 deletions.
90 changes: 10 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

# Interface Exporter Action

Interface Exporter Action automates the process of extracting TypeScript interfaces from Solidity contracts and provides compatibility with TypeChain. The action allows users to generate an NPM package compatible with web3-v1 or ethers-v6 typings. Developers can seamlessly generate typings with only a few lines of yaml code.
Interface Exporter Action automates the process of extracting TypeScript interfaces from Solidity contracts and provides compatibility with TypeChain. Developers can seamlessly generate typings with only a few lines of yaml code.

## Action Inputs

| Input | Description | Default | Options |
| --------------- | --------------------------------------------------------------------- | -------------- | ----------------------- |
| out_dir | The path to the directory where contracts are built | **Required** | |
| interfaces_dir | The path to the directory where the interfaces are located | src/interfaces | |
| typing_type | Typing option which NPM package will be compatible | **Required** | abi, ethers-v6, web3-v1, contracts |
| package_name | Chosen name for the exported NPM package | **Required** | |
| destination_dir | The path to the destination directory where the NPM will be exported | **Required** | |
| contracts_dir | The path to the directory where the contracts are located | **Optional** | |
| Input | Description | Default | Options |
| --------------- | -------------------------------------------------------------------- | -------------- | -------------- |
| out_dir | The path to the directory where contracts are built | **Required** | |
| interfaces_dir | The path to the directory where the interfaces are located | src/interfaces | |
| typing_type | Typing option which NPM package will be compatible | **Required** | abi, contracts |
| package_name | Chosen name for the exported NPM package | **Required** | |
| destination_dir | The path to the destination directory where the NPM will be exported | **Required** | |
| contracts_dir | The path to the directory where the contracts are located | **Optional** | |

## Action Outputs

Expand Down Expand Up @@ -57,71 +57,7 @@ Interface Exporter Action generates an NPM package with your interfaces ABIs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Interface Exporter Action generates an NPM package with typechain which has compatibility with ethers-v6. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: yarn --frozen-lockfile

- name: Build project and generate out directory
run: yarn build

- name: Add typechain to install dependencies
run: yarn add typechain @typechain/ethers-v6

- name: Export interfaces for ethers compatibility
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: out
interfaces_dir: src/interfaces
typing_type: ethers-v6
package_name: @my-cool-protocol/core-interfaces-ethers
destination_dir: ethers-project

- name: Publish
run: cd ethers-project && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Interface Exporter Action generates an NPM package with typechain which has compatibility with web3. Also, the Action provides ABIs interfaces.
```yaml
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
run: yarn --frozen-lockfile

- name: Build project and generate out directory
run: yarn build

- name: Add typechain to install dependencies
run: yarn add typechain @typechain/web3-v1

- name: Export interfaces for web3 compatibility
uses: defi-wonderland/interface-exporter-action@v1
with:
out_dir: ./out
interfaces_dir: src/interfaces
typing_type: web3-v1
package_name: @my-cool-protocol/core-interfaces-web3
destination_dir: web3-project

- name: Publish
run: cd web3-project && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```
Interface Exporter Action generates an NPM package with your contracts:
```yaml
- name: Use Node.js
Expand Down Expand Up @@ -160,12 +96,6 @@ Install the dependencies
npm install
```

Build the typescript and package it for distribution

```bash
npm run build && npm run package
```

Run the tests

```bash
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
default: 'src/interfaces'
required: false
typing_type:
description: 'interface compatibility: abi, ethers-v6, web3-v1, contracts'
description: 'interface compatibility: abi, contracts'
required: true
package_name:
description: 'name of the package to be publish'
Expand Down
31 changes: 2 additions & 29 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/* eslint-disable prettier/prettier */
export const ethersDependencies = {
'@ethersproject/abi': '5.7.0',
'@ethersproject/providers': '5.7.2',
'bn.js': '5.2.1',
ethers: '6.0.3',
};

export const web3Dependencies = {
'bn.js': '5.2.1',
'web3-core': '1.9.0',
};

export enum TypingType {
ABI = 'abi',
ETHERS_V6 = 'ethers-v6',
WEB3_V1 = 'web3-v1',
CONTRACTS = 'contracts',
}
6 changes: 0 additions & 6 deletions src/createPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,5 @@ export const createPackage = (
// install package dependencies
console.log(`Installing abi dependencies`);
execSync(`cd ${exportDir} && yarn`);

// use typechain if needed
if (typingType === TypingType.ETHERS_V6 || typingType === TypingType.WEB3_V1) {
console.log(`Generating types for ${typingType}`);
execSync(`yarn typechain --target ${typingType} --out-dir ${exportDir}/${typingType} '${exportDir}/abi/*.json'`);
}
});
};
8 changes: 1 addition & 7 deletions src/createPackages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fse from 'fs-extra';
import { createPackage } from './createPackage';
import { TypingType, ethersDependencies, web3Dependencies } from './constants';
import { TypingType } from './constants';
import { execSync } from 'child_process';

export const createPackages = (
Expand All @@ -23,17 +23,11 @@ export const createPackages = (
// Checks if exist
if (!wholePackage) return;

// Add additional dependencies if needed
let additionalDependencies: Record<string, string> = {};
if (typingType === TypingType.ETHERS_V6) additionalDependencies = ethersDependencies;
if (typingType === TypingType.WEB3_V1) additionalDependencies = web3Dependencies;

const packageJson = {
name: packageName,
version: wholePackage.version,
dependencies: {
...wholePackage.dependencies,
...additionalDependencies,
},
};

Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ export interface PackageJson {

export const publicTypeLabels: Record<TypingType, string> = {
[TypingType.ABI]: 'ABIs',
[TypingType.ETHERS_V6]: 'ethers.js types',
[TypingType.WEB3_V1]: 'web3 types',
[TypingType.CONTRACTS]: 'ABIs and contracts',
};
24 changes: 1 addition & 23 deletions test/unit/createReadmeAndLicense.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,9 @@ describe('createReadmeAndLicense', () => {
expect(readmeContent).to.include(`# ${packageName}`);
});

it('should create ethers v6 README.MD file with correct package name', () => {
const packageName = 'test-package';
createReadmeAndLicense(packageName, TypingType.ETHERS_V6, exportDir);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;

const readmeContent = fse.readFileSync(readmePath, 'utf8');
expect(readmeContent).to.include(`# ${packageName}`);
});

it('should create web3 README.MD file with correct package name', () => {
const packageName = 'test-package';
createReadmeAndLicense(packageName, TypingType.WEB3_V1, exportDir);

const readmePath = `${exportDir}/README.MD`;
expect(fse.existsSync(readmePath)).to.be.true;

const readmeContent = fse.readFileSync(readmePath, 'utf8');
expect(readmeContent).to.include(`# ${packageName}`);
});

it('should create LICENSE file if it exists', () => {
const packageName = 'test-package';
createReadmeAndLicense(packageName, TypingType.WEB3_V1, exportDir);
createReadmeAndLicense(packageName, TypingType.CONTRACTS, exportDir);

const licenseFilePath = `${exportDir}/LICENSE`;
expect(fse.existsSync(licenseFilePath)).to.be.true;
Expand Down

0 comments on commit 1863726

Please sign in to comment.