Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hardhat compatibility (Part 1 - Provider interface) #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5246d7e
feat: initial analysis on the hardhat interface for vechain sdk
pierobassa Oct 30, 2023
4c2547b
chore: abstract provider file
pierobassa Oct 30, 2023
ca7ba48
chore: json rpc provider file
pierobassa Oct 30, 2023
90e099c
chore: eslint
pierobassa Oct 30, 2023
6b78412
chore: minor temp comments
pierobassa Oct 30, 2023
1198f4f
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
rodolfopietro97 Dec 12, 2023
4473637
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
rodolfopietro97 Dec 12, 2023
9fc561a
Merge branch '132-alignment-with-hardhat-initial-public-functions' of…
rodolfopietro97 Dec 12, 2023
90c4479
fix: remove provider to separate package 'ethers-adapter'
rodolfopietro97 Dec 12, 2023
57c5181
feat: 'ethers-adapter'
rodolfopietro97 Dec 12, 2023
8e1cdc0
fix: change thor solo node strategy
rodolfopietro97 Dec 12, 2023
5ec5189
fix: remove container dependency
rodolfopietro97 Dec 12, 2023
876f015
fix: remove change directory
rodolfopietro97 Dec 12, 2023
35696fd
fix: missing healthcheck
rodolfopietro97 Dec 12, 2023
6d0a315
feat: not implemented errors
rodolfopietro97 Dec 13, 2023
f93103e
feat: removed axios and use ethers
rodolfopietro97 Dec 13, 2023
9f8bb77
feat: utils functions for abstract provider
rodolfopietro97 Dec 13, 2023
a1bd5c2
fix: substitute todo with to_modify
rodolfopietro97 Dec 13, 2023
3e069a5
fix: add tests
rodolfopietro97 Dec 18, 2023
a309c07
fix: fix tests
rodolfopietro97 Dec 18, 2023
646e1be
fix: code smells
rodolfopietro97 Dec 18, 2023
996b062
fix: simplify event emitter
rodolfopietro97 Dec 18, 2023
8248614
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
rodolfopietro97 Dec 18, 2023
f598a36
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
rodolfopietro97 Dec 19, 2023
f739830
test: added isPromise test cases
pierobassa Dec 19, 2023
2d9abc9
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
rodolfopietro97 Dec 20, 2023
1b62939
fix: remove ethers from ethers-adapter and using ether of core
rodolfopietro97 Dec 20, 2023
5a42ad8
fix: remove redundant check
rodolfopietro97 Dec 20, 2023
0fd12f2
chore: typo
rodolfopietro97 Dec 20, 2023
c9548b0
fix: typo
rodolfopietro97 Dec 21, 2023
67b7ce0
fix: typo in doc
rodolfopietro97 Dec 21, 2023
d8a3f7d
fix: stop thor solo in any case after tests
rodolfopietro97 Dec 21, 2023
381b9e6
Merge branch 'main' into 132-alignment-with-hardhat-initial-public-fu…
fabiorigam Dec 21, 2023
83b0aa4
fix: other typo
rodolfopietro97 Dec 21, 2023
493e444
Merge branch '132-alignment-with-hardhat-initial-public-functions' of…
rodolfopietro97 Dec 21, 2023
e707663
fix: merge with main
rodolfopietro97 Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
yarn build
- name: Test docs examples
run: |
cd docs
yarn test:examples

install-build:
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"postinstall": "husky install",
"build": "turbo build",
"lint": "turbo lint",
"test": "turbo test --force && yarn merge-coverage",
"start-thor-solo": "echo 'Starting thor solo node ...\n' && docker compose up -d --wait && echo '\nThor solo node started'",
"stop-thor-solo": "docker compose down && echo '\nThor solo node stopped'",
"test": "(yarn start-thor-solo && turbo test --force && yarn merge-coverage) && (yarn stop-thor-solo) || (yarn stop-thor-solo)",
"test:unit": "turbo test:unit",
"test:integration": "turbo test:integration",
"test:integration": "(yarn start-thor-solo && turbo test:integration) && (yarn stop-thor-solo) || (yarn stop-thor-solo)",
"format": "turbo format",
"test:examples": "turbo test:examples",
"test:examples": "(yarn start-thor-solo && turbo test:examples) && (yarn stop-thor-solo) || (yarn stop-thor-solo)",
"merge-coverage": "ts-node scripts/merge-coverage.ts",
"generate:apidocs": "typedoc --options typedoc.json --logLevel Error",
"generate:apidocs-debug": "typedoc --options typedoc.json --logLevel Verbose --plugin typedoc-plugin-missing-exports --validation.notDocumented"
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ethers } from 'ethers';

// Our core library
export * from './abi';
export * from './address';
export * from './bloom';
Expand All @@ -13,3 +16,6 @@ export * from './transaction';
export * from './utils';
export * from './bloom';
export * from './certificate';

// Other libraries
export { ethers as vechain_sdk_core_ethers };
4 changes: 2 additions & 2 deletions packages/core/src/utils/units/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const formatUnits = (
/**
* Parses a string number to a string with 18 decimals.
*
* VET is the native token of the VeChainThor blockchain.
* VET is the native token of the VechainThor blockchain.
* It has 18 decimals.
*
* This method can parse any numeric string with 18 decimals (e.g., VTHO balance too).
Expand All @@ -69,7 +69,7 @@ const parseVET = (value: string): bigint => {
/**
* Converts a value into a decimal string assuming 18 decimals.
*
* VET is the native token of the VeChainThor blockchain.
* VET is the native token of the VechainThor blockchain.
* It has 18 decimals.
*
* This method can format any numeric value with 18 decimals (e.g., VTHO balance too).
Expand Down
19 changes: 19 additions & 0 deletions packages/errors/src/model/generic/function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type DefaultErrorData } from '../../types';
import { ErrorBase } from '../base';

/**
* Not implemented function
*/
class NotImplementedError extends ErrorBase<
FUNCTION.NOT_IMPLEMENTED,
DefaultErrorData
> {}

/**
* Errors enum.
*/
enum FUNCTION {
rodolfopietro97 marked this conversation as resolved.
Show resolved Hide resolved
NOT_IMPLEMENTED = 'NOT_IMPLEMENTED'
}

export { NotImplementedError, FUNCTION };
1 change: 1 addition & 0 deletions packages/errors/src/model/generic/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './function';
1 change: 1 addition & 0 deletions packages/errors/src/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './base';
export * from './core';
export * from './network';
export * from './generic';
17 changes: 12 additions & 5 deletions packages/errors/src/types/errorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import {
TransactionAlreadySignedError,
TransactionBodyError,
TransactionDelegationError,
TransactionNotSignedError
TransactionNotSignedError,
FUNCTION,
NotImplementedError
} from '../model';

/**
Expand Down Expand Up @@ -75,7 +77,8 @@ type ErrorCode =
| DATA
| TRANSACTION
| HTTP_CLIENT
| POLL_ERROR;
| POLL_ERROR
| FUNCTION;

/**
* Conditional type to get the error data type from the error code.
Expand Down Expand Up @@ -106,7 +109,8 @@ const ERROR_CODES = {
DATA,
TRANSACTION,
HTTP_CLIENT,
POLL_ERROR
POLL_ERROR,
FUNCTION
};

/**
Expand Down Expand Up @@ -182,7 +186,9 @@ type ErrorType<ErrorCodeT> =
? HTTPClientError
: ErrorCodeT extends POLL_ERROR.POLL_EXECUTION_ERROR
? PollExecutionError
: never;
: ErrorCodeT extends FUNCTION.NOT_IMPLEMENTED
? NotImplementedError
: never;

/**
* Map to get the error class from the error code.
Expand Down Expand Up @@ -236,7 +242,8 @@ const ErrorClassMap = new Map<
[TRANSACTION.INVALID_TRANSACTION_BODY, TransactionBodyError],
[TRANSACTION.INVALID_DELEGATION, TransactionDelegationError],
[HTTP_CLIENT.INVALID_HTTP_REQUEST, HTTPClientError],
[POLL_ERROR.POLL_EXECUTION_ERROR, PollExecutionError]
[POLL_ERROR.POLL_EXECUTION_ERROR, PollExecutionError],
[FUNCTION.NOT_IMPLEMENTED, NotImplementedError]
]);

export {
Expand Down
3 changes: 3 additions & 0 deletions packages/ethers-adapter/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../.eslintrc.json"]
}
40 changes: 40 additions & 0 deletions packages/ethers-adapter/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @vechainfoundation/vechain-sdk-network

Welcome to the **ethers-adapter package** of the vechain SDK!

## Introduction
The vechain SDK Ethers-Adapter: Enabling Ethers.js Integration

The vechain SDK Ethers-Adapter is a sophisticated tool designed to facilitate developers' interactions with the VechainThor blockchain through the utilization of standard ethers.js constructs. This package serves as an advanced wrapper built atop the vechain SDK Network package. It is meticulously crafted to extend and complement the already comprehensive features set provided for decentralized application (dApp) development on the VechainThor blockchain.

At its core, the vechain SDK Ethers-Adapter primarily focuses on offering seamless integration of the signer and provider constructs, which are fundamental components of the ethers.js library. This integration is carefully adapted to align with the unique architecture and functionalities of the vechain SDK, thereby ensuring a fluid and intuitive development experience.

## Key Features

Explore the rich feature set of the vechain SDK Network package, tailored for VechainThor blockchain and dApp development:

- **Blocks and Node Status**: Interact with and retrieve information about blocks on the VechainThor blockchain. Vechain SDK Network allows developers to access block data and query the status of connected veChain nodes.
- **Accounts**: Facilitate interactions with Externally Owned Accounts (EOAs), empowering developers to manage and transact with individual user accounts on the VechainThor blockchain. This includes sending VET tokens and interacting with VTHO (VeThor) tokens.
- **Smart Contracts**: With vechain SDK Network, seamlessly interact with and manage smart contracts deployed on the VechainThor blockchain. Deploy contracts, invoke functions, and retrieve contract data effortlessly.
- **Transactions**: Initiate various transactions on the VechainThor blockchain using vechain SDK Network. Developers can create and broadcast transactions, including token transfers, contract interactions, and asset management.
- **Certificates**: Manage certificates and certificate-related operations on the blockchain with vechain SDK Network. Certificates play a crucial role in identity verification and access control within dApps.
- **Queries**: Efficiently retrieve specific data from the blockchain using vechain SDK Network's querying system. This includes querying transaction details, contract state, and other relevant blockchain information for streamlined dApp development.

Vechain SDK Network is your all-in-one solution for seamlessly integrating with the VechainThor blockchain, providing a reliable and feature-rich experience for dApp developers. Dive into the world of vechain SDK Network and elevate your decentralized applications with ease.

## Commands

- **Build**: Execute `yarn build` to build the package.
- **Lint**: Execute `yarn lint` to lint the package.
- **Format**: Execute `yarn format` to format the package.
- **Test:unit**: Execute `yarn test:unit` to run unit tests.
- **Test:integration**: Execute `yarn test:integration` to run integration tests.
- **Test**: Execute `yarn test` to run all tests on the package.

## Usage

Explore examples of how to use this package in real-world scenarios at [vechain SDK examples](https://github.com/vechainfoundation/vechain-sdk/tree/main/docs/examples).

Feel free to leverage these resources and don't hesitate to reach out if you have any questions or need further assistance.

Happy coding with the vechain SDK!
8 changes: 8 additions & 0 deletions packages/ethers-adapter/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
coverageReporters: ['html', 'lcov', 'json'],
runner: 'groups',
reporters: ['default', 'jest-junit']
};
21 changes: 21 additions & 0 deletions packages/ethers-adapter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@vechainfoundation/vechain-sdk-ethers-adapter",
"version": "1.0.0",
"private": false,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
"scripts": {
"build": "rm -rf ./dist && tsup src/index.ts --format cjs,esm --dts",
"lint": "eslint --ext .ts src --ext .ts tests",
"test:unit": "rm -rf ./coverageUnit && jest --coverage --coverageDirectory=coverageUnit --group=unit",
"test:integration": "export JEST_INTEGRATION=true; rm -rf ./coverageIntegration && jest --coverage --coverageDirectory=coverageIntegration --group=integration",
"test": "export JEST_INTEGRATION=true; rm -rf ./coverage && jest --coverage --coverageDirectory=coverage --group=integration --group=unit",
"format": "prettier --write src/**/*.ts tests/**/*.ts"
},
"dependencies": {
"@vechainfoundation/vechain-sdk-errors": "*",
"@vechainfoundation/vechain-sdk-core": "*",
"@vechainfoundation/vechain-sdk-network": "*"
}
}
1 change: 1 addition & 0 deletions packages/ethers-adapter/src/ethers-adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './providers';
5 changes: 5 additions & 0 deletions packages/ethers-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as ethersAdapter from './ethers-adapter';

export { ethersAdapter };

export * from './ethers-adapter';
10 changes: 10 additions & 0 deletions packages/ethers-adapter/src/providers/asbtract-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Abstract provider will implement Provider interface
*
* The abstract provider provides a base class for sub-classes to implement the Provider API.
*
* ------ TEMPORARY COMMENT ------
* The structure will generally abide to the the ethers abstract-provider.ts structure
* We need to understand if we want the plugins feature too
* ------------------------------
*/
3 changes: 3 additions & 0 deletions packages/ethers-adapter/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// export * from './asbtract-provider'
// export * from './jsonrpc-provider'
export * from './types.d';
7 changes: 7 additions & 0 deletions packages/ethers-adapter/src/providers/jsonrpc-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* ------- TEMPORARY COMMENT -------
* We can then decide to extend our abstract provider to allow json rpc calls
*
* This way also a json rpc wrapper (https://github.com/vechain/thorify) can be included in the sdk
rodolfopietro97 marked this conversation as resolved.
Show resolved Hide resolved
* ------------------------------
*/
Loading