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

Feature/functions integration #11

Merged
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9b37c67
add functions-toolkit and update hardhat version
koteld Oct 16, 2023
07772c5
refactor keepersRegistry.ts
koteld Oct 16, 2023
b24217f
add skipLibCheck to tsconfig.json for compatibility
koteld Oct 16, 2023
6037253
add functionsRouter class and externally callable methods
koteld Oct 16, 2023
febef3c
add functionsUtils class and externally callable methods
koteld Oct 16, 2023
d5a69c4
add utils to create/delete Gist
koteld Oct 16, 2023
06edf12
add Function Routers to registry; remove Function Oracles
koteld Oct 19, 2023
b586305
refactor functionsUtils: add DecodedResult type
koteld Oct 19, 2023
4bb2064
update inquirers with Function Routers
koteld Oct 19, 2023
dbefc25
update types and enums with Function Routers
koteld Oct 19, 2023
dbf09ba
update subtasks wih Functions Routers
koteld Oct 19, 2023
27c8888
update plugin registry tasks with Function Routers
koteld Oct 19, 2023
1ec8973
add tasks for Function Routers and utils
koteld Oct 19, 2023
87f21ed
set consumer address optional for createSubscription method
koteld Oct 19, 2023
8a0fbe7
Function Router -> Functions Router for consistency
koteld Oct 19, 2023
0a89fcd
add initialization method for FunctionsResponseListener
koteld Oct 21, 2023
9312b7a
add FunctionsRouterSubtasks to subtasks
koteld Oct 21, 2023
1f98265
add subtasks for Functions
koteld Oct 21, 2023
7ea9af7
add Functions to Hardhat Extended class
koteld Oct 21, 2023
e3be890
add Functions task
koteld Oct 21, 2023
fd38fd3
update Functions Router actions
koteld Oct 21, 2023
8986e23
modify timeoutRequests task for convenience
koteld Oct 22, 2023
539b438
expose create/delete Gist as tasks
koteld Oct 23, 2023
7746ed8
add subtasks to creat/delete Gist to subtasks enum
koteld Oct 23, 2023
e17601b
add wrapper for Functions Secrets Manager
koteld Oct 23, 2023
b9cf9b4
update subtasks definitions
koteld Oct 23, 2023
9680ac1
add Functions Secrets Manager to Hardhat Extended class
koteld Oct 23, 2023
c36a1b9
bump @chainlink/contracts version to 0.8.0
koteld Oct 25, 2023
90d3a39
update ChainlinkDirectRequestConsumer dependencies on @chainlink/cont…
koteld Oct 25, 2023
24ff856
update fixture contracts dependencies on @chainlink/contracts
koteld Oct 25, 2023
107f010
update arbitrum goerli fixture RPC endpoint
koteld Oct 25, 2023
9a5df39
refactor keepersRegistrar module
koteld Oct 25, 2023
1e3e6b8
refactor functionsRouter.ts
koteld Oct 25, 2023
88d6d3b
bump functions-toolkit version
koteld Oct 30, 2023
9034ee2
update Functions Routers plugin registry
koteld Oct 30, 2023
b872693
update Functions Router module: add overrides, fix typings, add stati…
koteld Oct 30, 2023
cbacdf3
add Functions Consumer module to sandbox
koteld Oct 30, 2023
c7caa16
add Functions Simulations module to sandbox
koteld Oct 30, 2023
cb272fc
update shared types
koteld Oct 30, 2023
251ec7a
add necessary shared enums
koteld Oct 30, 2023
d7610c0
update constants: add default Functions simulations parameters
koteld Oct 30, 2023
4a063db
update Functions Router HRE tasks
koteld Oct 30, 2023
5ab6649
add Functions Consumer and Functions Simulations HRE tasks
koteld Oct 30, 2023
a98c5c5
add Functions Consumer contract and update hardhat max solidity version
koteld Oct 30, 2023
628e74d
add Functions Consumer and Functions Simulations to hardhat extended …
koteld Oct 30, 2023
11e0bb6
add Functions Consumer and Functions Simulations to subtasks
koteld Oct 30, 2023
10594a7
code refactoring
koteld Oct 30, 2023
aa3e463
sandbox:node - code refactoring, add get VRF keys method
koteld Oct 30, 2023
1695979
update inquirers
koteld Oct 30, 2023
e4faad6
add tests for Functions Consumer and Functions Simulations, update fi…
koteld Oct 30, 2023
29bb3cd
add scripts to run Functions Consumer and Functions Simulations tests
koteld Oct 30, 2023
43c6845
bump package version
koteld Oct 30, 2023
fca1977
update README and DOCUMENTATION
koteld Oct 30, 2023
7cd601d
code refactoring and minor fixes
koteld Oct 30, 2023
5155fb6
functions -> functionsRouter in README
koteld Oct 30, 2023
f6e0514
README: move "Available Services" section
koteld Nov 3, 2023
8267ba0
update Functions Service plugin name + refactoring
koteld Nov 3, 2023
06df0b7
add suggested description for Functions Simulations
koteld Nov 3, 2023
a7a3ed6
remove customization for Functions request simulation
koteld Nov 3, 2023
1f0fb4a
rename Functions Service in the documentation
koteld Nov 3, 2023
55f78ef
change donIdHex -> donIdBytes32 in functions routers registry
koteld Nov 3, 2023
7720424
update README + code refactoring
koteld Nov 3, 2023
363d8c9
change encryptedSecretsUploadEndpoints -> gatewayUrls in Functions Ro…
koteld Nov 3, 2023
4c14376
update DOCUMENTATION.md - fix "stop response listener" section
koteld Nov 3, 2023
aeebf9b
remove exposing functions consumer as a service
koteld Jan 10, 2024
d0e50e8
code refactoring: rename variables
koteld Jan 10, 2024
38bc11e
update documentation
koteld Jan 10, 2024
fd2e690
run functions simulations as purely a deno-runtime execution
koteld Jan 10, 2024
9f1057e
update README.md
koteld Jan 12, 2024
c545b1d
rename: drConsumer -> directRequestConsumer
koteld Jan 12, 2024
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
2,032 changes: 1,663 additions & 369 deletions DOCUMENTATION.md

Large diffs are not rendered by default.

165 changes: 82 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Hardhat Chainlink Plugin

<br>
<p align="center">
<a href="https://chain.link" target="_blank">
<img src="https://raw.githubusercontent.com/smartcontractkit/hardhat-starter-kit/main/box-img-lg.png" width="225" alt="Chainlink Hardhat logo">
</a>
</p>

# Hardhat Chainlink Plugin
<br/>

The Hardhat Chainlink plugin allows users to seamlessly interact with Chainlink services in their Hardhat-based projects.
It provides atomic methods to interact with smart contracts related to the main Chainlink services: Data Feeds, VRF, and Automation.
It provides atomic methods to interact with smart contracts related to Chainlink services: Data Feeds, VRF, Automation and Functions.
koteld marked this conversation as resolved.
Show resolved Hide resolved
This plugin offers a convenient way to integrate Chainlink functionality into your web3 development workflow.

> **Warning**
>
> **This package is currently in the BETA testing phase and is not recommended for production usage yet.**
>
> **Open issues to submit bugs and earn the Beta Tester POAP.**
> **Open issues to submit bugs.**

## Installation
> **Note**
Expand Down Expand Up @@ -46,22 +48,34 @@ require("@chainlink/hardhat-chainlink");
import "@chainlink/hardhat-chainlink";
```

This plugin also extends the Hardhat configuration and adds `chainlink` parameters group:
`hardhat.config.ts`:
## Usage

The Hardhat Chainlink plugin offers multiple ways to interact with Chainlink services,
giving you the flexibility to choose the approach that suits your workflow best.

Below is a mapping of the names of supported Chainlink services:
- `dataFeed`: Data Feeds
- `dataFeedProxy`: Data Feed Proxies
- `feedRegistry`: Feed Registries
- `l2Sequencer`: L2 Sequencers
- `ens`: ENS (Ethereum Name Service)
- `automationRegistry`: Automation Registries
- `automationRegistrar`: Automation Registrars
- `vrf`: VRF (Verifiable Random Functions)
- `functions`: Functions service

The number of confirmations to wait for transactions to Chainlink services can be set using
the corresponding parameter in the `chainlink` parameters group of `hardhat.config.ts`:
```ts
module.exports = {
...,
chainlink: {
confirmations // Number of confirmations to wait for transactions, default: 1
confirmations // Number of confirmations to wait for transactions (default: 1)
},
...
}
```

## Usage

The Hardhat Chainlink plugin offers multiple ways to interact with Chainlink services,
giving you the flexibility to choose the approach that suits your workflow best.

### 1. CLI

Interact with the Hardhat Chainlink plugin through the command line interface (CLI) using the following format:
Expand Down Expand Up @@ -132,19 +146,6 @@ async function myFunction() {
---
Choose the method that fits your project's requirements and coding style.
All three approaches provide the same set of functionalities, allowing you to interact with Chainlink services efficiently and effectively.

### Available Services
The Hardhat Chainlink plugin supports the following Chainlink services:

- `dataFeed` (Data Feeds)
- `dataFeedProxy` (Data Feed Proxies)
- `feedRegistry` (Feed Registries)
- `l2Sequencer` (L2 Sequencers)
- `ens` (ENS - Ethereum Name Service)
- `automationRegistry` (Automation Registries)
- `automationRegistrar` (Automation Registrars)
- `vrf` (Verifiable Random Functions)

For a more in-depth understanding of available services and methods, please explore their [tests](test).
koteld marked this conversation as resolved.
Show resolved Hide resolved

## Registries
Expand All @@ -155,11 +156,21 @@ which is useful for interacting with the Feed Registry.
In general, these registries help you access essential contract addresses deployed on different networks,
making it easier to integrate Chainlink services into your projects.

You can access the plugin registries using one of the following methods:
Below is a list of the registries provided by Hardhat Chainlink plugin:
koteld marked this conversation as resolved.
Show resolved Hide resolved
- `dataFeeds`: Addresses of Data Feeds-related contracts: Aggregators and Proxies, and their parameters.
- `feedRegistries`: Feed Registries' contract addresses.
- `l2Sequencers`: L2 Sequencer Uptime Feeds' contract addresses.
- `keeperRegistries`: Addresses of Automation-related contracts: Keeper Registry and Keeper Registrar.
- `linkTokens`: Link Tokens' contract addresses.
- `vrfCoordinators`: Addresses of VRF Coordinators and their parameters.
- `functionsRouters`: Addresses of Functions Routers and their parameters.
- `denominations`: Records from Denominations library to interact with Feed Registries contracts.

You can access them using one of the following methods:

### 1. CLI

To interact with the registries through the CLI, use the following command:
Access the registries through the CLI using the following command:
```
npx hardhat chainlink:registries [method]
```
Expand Down Expand Up @@ -187,7 +198,7 @@ Access the registries as methods directly in the Hardhat Environment:
const registry = hre.chainlink.registries.{registryName};
```

Replace {registryName} with the name of the registry (e.g., dataFeeds, feedRegistries, keeperRegistries).
Replace the `{registryName}` placeholder with the name of the registry (e.g., dataFeeds, feedRegistries, keeperRegistries).

Example of getting data from registry in the Hardhat Environment:
```js
Expand All @@ -197,49 +208,48 @@ async function myFunction() {
// 0xE62B71cf983019BFf55bC83B48601ce8419650CC
}
```
---
For a more in-depth understanding of the structure of these records, please explore their [interfaces](src%2Fregistries%2Finterfaces).

### Available registries
## Sandbox

The Hardhat Chainlink plugin provides the following registries:
- `dataFeeds`: Addresses of Data Feeds-related contracts: Aggregators and Proxies, and their parameters.
- `feedRegistries`: Feed Registries' contract addresses.
- `l2Sequencers`: L2 Sequencer Uptime Feeds' contract addresses.
- `keeperRegistries`: Addresses of Automation-related contracts: Keeper Registry and Keeper Registrar.
- `linkTokens`: Link Tokens' contract addresses.
- `vrfCoordinators`: Addresses of VRF Coordinators and their parameters.
- `denominations`: Records from Denominations library to interact with Feed Registries contracts.
The `sandbox` module of Hardhat Chainlink plugin provides the ability to test dApps against Chainlink services locally and run simulations.

For a more in-depth understanding of the structure of these records, please explore their [interfaces](src%2Fregistries%2Finterfaces).
### Functions request simulation

## Sandbox
This plugin enables you to run local Functions request simulations.
A simulation is an execution of your custom JavaScript code in a locally spun up Deno sandbox environment.
It is useful for debugging and for checking whether the source code you supply to Chainlink Functions can reasonably be expected to work when passed on-chain.

In addition to the primary feature of interacting with Chainlink services, this plugin provides the ability to manage a local Chainlink node.
The corresponding functionality is implemented in a special tasks module `sandbox`.
This module implements methods for starting, restarting and stopping a Chainlink node, getting Chainlink node information,
deploying and interacting with such contracts as [LinkToken](contracts%2FLinkToken.sol), [Operator](contracts%2FOperator.sol) and [ChainlinkDirectRequestConsumer](contracts%2FChainlinkDirectRequestConsumer.sol).
> **Note**
Install [Deno](https://deno.com/) and add it to PATH, run ```deno --version``` to verify installation. Instructions: [https://deno.com/#installation](https://deno.com/#installation).

### Configure, run and manage local Chainlink node
Functions' requests simulations could be performed following the [sandbox documentation](SANDBOX.md#service-alias-functionssimulation).

This plugin allows you to run a local Chainlink node and then manage it using Docker.
### Local testing
> **Note**
Install and run Docker Daemon, and Docker Desktop for convenience. Instructions: [docs.docker.com/get-docker](https://docs.docker.com/get-docker/).
> Install and run Docker Daemon, and Docker Desktop for convenience. Instructions: [docs.docker.com/get-docker](https://docs.docker.com/get-docker/).

Before you start a Chainlink node, it's important to configure it. To achieve this, parameters have been included in the Hardhat configuration `chainlink` group:
`hardhat.config.ts`:
This plugin enables you to spin up a local Chainlink node, set up Chainlink services, and then conduct local tests.

#### Configure local Chainlink node

Before you start a Chainlink node, it's important to configure it.
To achieve this, additional parameters have been included in the `chainlink` group of `hardhat.config.ts`:
```ts
module.exports = {
chainlink: {
node: {
chain_id, // Chain ID, default: "1337"
chain_name, // Chain name, default: "local"
http_url, // JSON RPC HTTP endpoint, default: "http://host.docker.internal:8545"
ws_url, // JSON RPC WebSocket endpoint, default: "ws://host.docker.internal:8545"
cl_keystore_password, // Password to encode Chainlink keys in database, default: "password1234567890"
cl_api_user, // Email of Chainlink API user/admin, default: "user@chain.link"
cl_api_password, // Password of Chainlink API user/admin, default: "password1234567890"
pg_user, // Postgres DB user name, default: "chainlink"
pg_password, // Postgres DB user password, default: "password1234567890"
pg_db, // Postgres DB name, default: "chainlink"
chain_id, // Chain ID (default: "1337")
chain_name, // Chain name (default: "local")
http_url, // JSON RPC HTTP endpoint (default: "http://host.docker.internal:8545")
ws_url, // JSON RPC WebSocket endpoint (default: "ws://host.docker.internal:8545")
cl_keystore_password, // Password to encode Chainlink keys in database (default: "password1234567890")
cl_api_user, // Email of Chainlink API user/admin (default: "user@chain.link")
cl_api_password, // Password of Chainlink API user/admin (default: "password1234567890")
pg_user, // Postgres DB user name (default: "chainlink")
pg_password, // Postgres DB user password (default: "password1234567890")
pg_db, // Postgres DB name (default: "chainlink")
}
},
...
Expand All @@ -248,11 +258,15 @@ module.exports = {
> **Note**
> Passwords must contain both letters and numbers and be at least 16 characters long.

Once these parameters are specified, Chainlink node could be started/restarted/stopped and managed with plugin following the [documentation](DOCUMENTATION.md#service-alias-node).
### Manage local Chainlink node

You can also manage a Chainlink node either with Chainlink CLI or Chainlink node GUI.
Once local Chainlink node parameters are specified, Chainlink node could be started/restarted/stopped and managed with the plugin following the [sandbox documentation](SANDBOX.md#service-alias-node).
In order to login use credentials provided with `cl_api_user` and `cl_api_password`.

Alternatively, you can manage a Chainlink node either with Chainlink CLI or Chainlink node GUI.

#### Chainlink CLI

Chainlink node CLI is available directly on a machine running Chainlink node, so first you have to connect with `bash` to a Docker container to be able to run commands.

Here are some of the things you can do with the CLI:
Expand All @@ -262,47 +276,32 @@ Here are some of the things you can do with the CLI:
* See/Create Chainlink node's keys: ETH, OCR, P2P
* and more...

Here is example command to get list of ETH keys that are used by the Chainlink node:
Here is example command to get list of ETH keys that are used by a Chainlink node:
```bash
chainlink keys eth list
```
The most useful commands to manage Chainlink node with UI you can find here: https://docs.chain.link/chainlink-nodes/resources/miscellaneous.
The most useful commands to manage Chainlink node with CLI you can find here: https://docs.chain.link/chainlink-nodes/resources/miscellaneous.

#### Chainlink GUI

Chainlink node GUI is by default available on the port `6688`, this port is exposed with a docker-compose file to a host machine.

Here are some of the things you can do with the GUI:
* Create/Delete Chainlink Jobs
* Create Chainlink Bridge
* See Chainlink Jobs runs
* See Chainlink node's keys: ETH, OCR, P2P
* See Chainlink node's keys: ETH, OCR, P2P, VRF
* See Chainlink node's current configuration
* and more...

In order to login use credentials provided with `cl_api_user` and `cl_api_password`.

### Set up a Direct Request job with plugin

Once Chainlink node is started, Direct Request job could be set up. It can be used for testing, learning and other purposes.
The process of setting up a Direct Request job is as follows:
1. [Deploy Link Token contract](DOCUMENTATION.md#deploy-contract)
2. [Deploy Operator contract](DOCUMENTATION.md#deploy-contract-1)
3. [Deploy Direct Request Consumer contract](DOCUMENTATION.md#deploy-contract-1)
4. [Get Chainlink node ETH accounts](DOCUMENTATION.md#get-eth-keys) and choose one of them
5. [Fund chosen Chainlink ETH account](DOCUMENTATION.md#transfer-eth) with reasonable amount of ETH
6. [Fund Direct Request Consumer contract with Link tokens](DOCUMENTATION.md#transfer) (at least 1 token)
7. [Set chosen Chainlink ETH account to Operator contract as Authorized Sender](DOCUMENTATION.md#set-authorized-sender)
8. [Create Direct Request job](DOCUMENTATION.md#create-direct-request-job)
9. [Request data with Direct Request job](DOCUMENTATION.md#request-data)
10. [Check if answer in Direct Request consumer was updated](DOCUMENTATION.md#get-latest-answer)

More on Direct Request job: https://docs.chain.link/chainlink-nodes/oracle-jobs/all-jobs#direct-request-jobs.

## Documentation

For detailed usage instructions and more information on each service and method, refer to the [DOCUMENTATION.md](DOCUMENTATION.md).
For detailed usage instructions and more information, refer to:
* [DOCUMENTATION.md](DOCUMENTATION.md) for interaction with Chainlink services;
* [SANDBOX.md](SANDBOX.md) for local testing in Sandbox.

## Contribution

We welcome contributions from the community.

If you find any issues, have suggestions for improvements, or want to add new features to the plugin,
Expand Down
Loading