-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from morpho-labs/feat/create-fallback-provider
Feat/create fallback provider
- Loading branch information
Showing
10 changed files
with
3,144 additions
and
42 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,2 +1,2 @@ | ||
# Set the repository to show as TypeScript rather than JS in GitHub | ||
*.js linguist-detectable=false | ||
*.js linguist-detectable=false |
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,39 @@ | ||
<!-- | ||
😀 Wonderful! Thank you for opening a pull request. | ||
Please fill in the information below to expedite the review | ||
and (hopefully) merge of your change. | ||
--> | ||
|
||
### Description of change | ||
|
||
<!-- | ||
Please be clear and concise what the change is intended to do, | ||
why this change is needed, and how you've verified that it | ||
corrects what you intended. | ||
In some cases it may be helpful to include the current behavior | ||
and the new behavior. | ||
If the change is related to an open issue, you can link it here. | ||
If you include `Fixes #0000` (replacing `0000` with the issue number) | ||
when this is merged it will automatically mark the issue as fixed and | ||
close it. | ||
--> | ||
|
||
### Pull-Request Checklist | ||
|
||
<!-- | ||
Please make sure to review and check all of the following. | ||
If an item is not applicable, you can add "N/A" to the end. | ||
--> | ||
|
||
- [ ] This pull request links relevant issues as `Fixes #0000` | ||
- [ ] There are new or updated unit tests validating the change | ||
- [ ] Documentation has been updated to reflect this change | ||
- [ ] The new commits follow conventions outlined in the [conventional commit spec](https://www.conventionalcommits.org/en/v1.0.0/) | ||
|
||
<!-- | ||
🎉 Thank you for contributing! | ||
--> |
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,83 @@ | ||
name: Continuous integration | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x, 18.x] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: yarn | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Build package | ||
run: yarn build | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x, 18.x] | ||
needs: build | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: yarn | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Test package | ||
run: yarn test | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
needs: [build, test] | ||
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: yarn | ||
|
||
- name: Install dependencies | ||
run: yarn --frozen-lockfile | ||
|
||
- name: Build package | ||
run: yarn build | ||
|
||
- name: Publish package | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
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 +1,4 @@ | ||
node_modules | ||
lib | ||
|
||
*.tsbuildinfo |
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,27 @@ | ||
--- | ||
name: "🐛 Bug Report" | ||
about: Report a reproducible bug or regression. | ||
title: '' | ||
labels: bug | ||
assignees: '' | ||
|
||
--- | ||
|
||
## Current Behavior | ||
|
||
<!-- Describe how the issue manifests. --> | ||
|
||
## Expected Behavior | ||
|
||
<!-- Describe what the desired behavior would be. --> | ||
|
||
## Steps to Reproduce the Problem | ||
|
||
1. | ||
1. | ||
1. | ||
|
||
## Environment | ||
|
||
- Version: <!-- Version set on npm --> | ||
- Node.js Version: <!-- Output of running `node -v` --> |
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,34 @@ | ||
--- | ||
name: 🌈 Feature request | ||
about: Suggest an amazing new idea for this project | ||
title: '' | ||
labels: enhancement | ||
assignees: '' | ||
|
||
--- | ||
|
||
## Feature Request | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
<!-- A clear and concise description of what the problem is. Ex. I have an issue when [...] --> | ||
|
||
**Describe the solution you'd like** | ||
<!-- A clear and concise description of what you want to happen. Add any considered drawbacks. --> | ||
|
||
**Describe alternatives you've considered** | ||
<!-- A clear and concise description of any alternative solutions or features you've considered. --> | ||
|
||
## Are you willing to resolve this issue by submitting a Pull Request? | ||
|
||
<!-- | ||
Remember that first-time contributors are welcome! 🙌 | ||
--> | ||
|
||
- [ ] Yes, I have the time, and I know how to start. | ||
- [ ] Yes, I have the time, but I don't know how to start. I would need guidance. | ||
- [ ] No, I don't have the time, although I believe I could do it if I had the time... | ||
- [ ] No, I don't have the time and I wouldn't even know how to start. | ||
|
||
<!-- | ||
👋 Have a great day and thank you for the feature request! | ||
--> |
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,3 +1,68 @@ | ||
# ethers-fallback-provider | ||
[![npm package][npm-img]][npm-url] | ||
[![Build Status][build-img]][build-url] | ||
[![Downloads][downloads-img]][downloads-url] | ||
[![Issues][issues-img]][issues-url] | ||
[![Commitizen Friendly][commitizen-img]][commitizen-url] | ||
[![Semantic Release][semantic-release-img]][semantic-release-url] | ||
|
||
> Package providing a fallback provider based on `ethers` package, adding more resilience. | ||
The provider fallbacks on multiple providers in case of failure, and returns the first successful result. | ||
|
||
It throws an error if all providers failed. | ||
|
||
The providers are called in the order they are passed to the constructor. | ||
|
||
Contrary to the `FallbackProvider` provided by `ethers`, this one does not use all providers at the same time, but only one at a time. | ||
The purpose is more to have resilience if one provider fails, rather than having a resilience on the result. | ||
|
||
## Installation | ||
```bash | ||
npm install @morpho-labs/ethers-fallback-provider | ||
``` | ||
or | ||
```bash | ||
yarn add @morpho-labs/ethers-fallback-provider | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import FallbackProvider from '@morpho-labs/ethers-fallback-provider'; | ||
|
||
import { | ||
InfuraProvider, | ||
AlchemyProvider, | ||
getDefaultProvider | ||
} from "@ethersproject/providers"; | ||
|
||
|
||
const timeout = 1000; // 1 second, optionnal, default is 3000ms | ||
|
||
const provider = new FallbackProvider([ | ||
new InfuraProvider('mainnet', 'your-api-key'), | ||
new AlchemyProvider('mainnet', 'your-api-key'), | ||
getDefaultProvider('mainnet') | ||
]); | ||
|
||
// You can now use the fallback provider as a classic provider | ||
const blockNumber = await provider.getBlockNumber(); | ||
|
||
``` | ||
|
||
|
||
[build-img]: https://github.com/morpho-labs/ethers-fallback-provider/actions/workflows/ci.yml/badge.svg?branch=main | ||
[build-url]: https://github.com/morpho-labs/ethers-fallback-provider/actions/workflows/ci.yml | ||
[downloads-img]: https://img.shields.io/npm/dt/ethers-multicall-provider | ||
[downloads-url]: https://www.npmtrends.com/ethers-multicall-provider | ||
[npm-img]: https://img.shields.io/npm/v/ethers-multicall-provider | ||
[npm-url]: https://www.npmjs.com/package/ethers-multicall-provider | ||
[issues-img]: https://img.shields.io/github/issues/morpho-labs/ethers-fallback-provider | ||
[issues-url]: https://github.com/morpho-labs/ethers-fallback-provider/issues | ||
[codecov-img]: https://codecov.io/gh/morpho-labs/ethers-fallback-provider/branch/main/graph/badge.svg | ||
[codecov-url]: https://codecov.io/gh/morpho-labs/ethers-fallback-provider | ||
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg | ||
[semantic-release-url]: https://github.com/semantic-release/semantic-release | ||
[commitizen-img]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg | ||
[commitizen-url]: http://commitizen.github.io/cz-cli/ |
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 +1,5 @@ | ||
import { FallbackProvider } from "./FallbackProvider"; | ||
|
||
export * from "./FallbackProvider"; | ||
|
||
export default FallbackProvider; |
Oops, something went wrong.