Skip to content

Commit

Permalink
Merge pull request #147 from lidofinance/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
DiRaiks authored Jul 23, 2024
2 parents 87ec66c + 1a7ac9d commit 255e3a2
Show file tree
Hide file tree
Showing 44 changed files with 2,265 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/publish-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ permissions:
id-token: write # to enable use of OIDC for npm provenance

jobs:
pre-publish:
if: github.ref == 'refs/heads/develop'
uses: ./.github/workflows/publish-dry-run.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
publish:
needs: pre-publish
runs-on: ubuntu-latest
environment: development
# restricts job to develop branch
Expand Down Expand Up @@ -44,7 +50,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish Alpha
run: yarn multi-semantic-release --deps.bump=override --deps.release=patch --sequential-init
run: yarn multi-semantic-release
env:
NPM_CONFIG_PROVENANCE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/publish-dry-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Publish Dry Run
on:
workflow_dispatch:
workflow_call:
secrets:
NPM_TOKEN:
description: 'NPM token'
required: true

jobs:
publish-dry-run:
runs-on: ubuntu-latest
environment: development
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'

- name: Install dependencies
run: yarn --immutable

- name: Build
run: yarn build:packages

- name: Dry run Publish
run: yarn multi-semantic-release --dry-run --silent | grep -E '#|###|\*' > dry_run_output.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Write results to summary
run: |
if [ -s dry_run_output.txt ]; then
echo "# Packages to be published:" >> $GITHUB_STEP_SUMMARY
cat dry_run_output.txt >> $GITHUB_STEP_SUMMARY
else
echo "Nothing will be published" >> $GITHUB_STEP_SUMMARY
fi
7 changes: 6 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ permissions:
id-token: write # to enable use of OIDC for npm provenance

jobs:
pre-publish:
uses: ./.github/workflows/publish-dry-run.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
publish:
needs: pre-publish
runs-on: ubuntu-latest
environment: production
steps:
Expand Down Expand Up @@ -44,7 +49,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish
run: yarn multi-semantic-release --deps.bump=override --deps.release=patch --sequential-init
run: yarn multi-semantic-release
env:
NPM_CONFIG_PROVENANCE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
10 changes: 10 additions & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ const config: Config = {
sidebarPath: './sidebarsExamples.ts',
},
],
[
'@docusaurus/plugin-content-docs',
{
id: 'lidoPulse',
path: 'lidoPulse',
routeBasePath: 'lidoPulse',
sidebarPath: './sidebarsLidoPulse.ts',
},
],
],
presets: [
[
Expand Down Expand Up @@ -74,6 +83,7 @@ const config: Config = {
label: 'Docs',
},
{ to: '/examples/intro', label: 'Examples', position: 'left' },
{ to: '/lidoPulse/intro', label: 'LidoPulse', position: 'left' },
{
href: '/playground',
label: 'Playground',
Expand Down
7 changes: 7 additions & 0 deletions docs/examples/erlang-bridge/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "Erlang Bridge",
"position": 3,
"link": {
"type": "generated-index"
}
}
21 changes: 21 additions & 0 deletions docs/examples/erlang-bridge/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
sidebar_position: 2
---

# Installation

## Installing Erlang

Download and install Erlang/OTP from the [official website](https://www.erlang.org/downloads).

## Installing Node.js (version >= 20)

Download and install Node.js and NPM from the [official website](https://nodejs.org/).

## Installing Node.js Dependencies

Navigate to the project directory and install the necessary dependencies:

```bash
yarn install
```
17 changes: 17 additions & 0 deletions docs/examples/erlang-bridge/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
sidebar_position: 1
title: Introduction
---

# Erlang and Lido Ethereum SDK Interaction

## Introduction

This example demonstrate the interaction between Erlang and Lido Ethereum SDK processes. The Erlang process launches a Node.js process and sends commands to retrieve a result from the Lido SDK methods.

- `main.erl`: Erlang module that manages launching and interacting with the Node.js process.
- `sdk.js`: Lido SDK script that processes commands received from the Erlang process and returns results.

## Use Case

The primary use case for this project is to integrate blockchain reward retrieval functionalities into an Erlang-based application. By leveraging the Lido SDK in a Node.js process, this project provides a way to access blockchain data and utilities that may not be easily accessible within the Erlang ecosystem.
66 changes: 66 additions & 0 deletions docs/examples/erlang-bridge/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
sidebar_position: 3
---

# Usage

## Starting the Erlang Process

1. Navigate to the project directory and install deps :

```bash
cd examples/erlang-bridge/src

yarn install
```

2. Replace RPC_URL in `sdk.js` with the actual RPC URL and set the `chain` parameter to which chain you want to connect:

```ts
const rpcProvider = createPublicClient({
chain: mainnet,
transport: http('RPC_URL'),
});
```

3. Start the Erlang shell:

```bash
rebar3 get-deps && rebar3 compile
```

```bash
erlc main.erl
```

```bash
erl -pa _build/default/lib/*/ebin
```

4. In the Erlang shell, compile the `main` module:

```erlang
c(main).
```

5. Start the Node.js process from Erlang and get the port:

```erlang
{ok, Port} = main:start().
```

6. Define the parameters and call the `get_rewards_from_chain` function:

```erlang
Params = [
{<<"address">>, <<"0x">>},
{<<"stepBlock">>, 10000},
{<<"back">>, {<<"days">>, 1}}
].
Result = main:get_rewards_from_chain(Port, Params).
```

- address: Ethereum address for which to retrieve rewards.
- stepBlock: Max blocks in 1 query - depend on the RPC capabilities and pricing plans
- back.days: Number of days to step back.
7 changes: 7 additions & 0 deletions docs/lidoPulse/get-started/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "Get Started",
"position": 2,
"link": {
"type": "generated-index"
}
}
89 changes: 89 additions & 0 deletions docs/lidoPulse/get-started/batch-requests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
sidebar_position: 4
---

# Batch Requests

The server also supports batch requests, allowing multiple JSON-RPC calls to be sent in a single HTTP request. Each request in the batch will be processed independently, and a single response containing the results of all requests will be returned. Note that the order of responses in the batch response may not match the order of the requests. You should match responses to requests using the `id` field.

## Example Batch JSON-RPC Request

```json
[
{
"jsonrpc": "2.0",
"method": "shares.balance",
"params": ["0x2f0EA53F92252167d658963f334a91de0824e322"],
"id": 1
},
{
"jsonrpc": "2.0",
"method": "unsteth.getNFTsByAccount",
"params": ["0x2f0EA53F92252167d658963f334a91de0824e322"],
"id": 2
},
{
"jsonrpc": "2.0",
"method": "events.stethEvents.getLastRebaseEvent",
"params": [],
"id": 3
}
]
```

## Example Batch Response

```json
[
{
"jsonrpc": "2.0",
"result": [
{
"amountOfStETH": "10000000000000000",
"amountOfShares": "9995810557743733",
"owner": "0x",
"timestamp": "16973450812",
"isFinalized": true,
"isClaimed": false,
"id": "777"
}
],
"id": 2
},
{
"jsonrpc": "2.0",
"result": "14066156191713469572",
"id": 1
},
{
"jsonrpc": "2.0",
"result": {
"eventName": "TokenRebased",
"args": {
"reportTimestamp": "1721072820",
"timeElapsed": "4608",
"preTotalShares": "1079179109989045486885777",
"preTotalEther": "1093196098970760843229455",
"postTotalShares": "1079179369664131812438396",
"postTotalEther": "1093198738453702928397482",
"sharesMintedAsFees": "260563376065765428"
},
"address": "0x3f1c547b21f65e10480de3ad8e19faac46c95034",
"topics": [
"0xff08c3ef606d198e316ef5b822193c489965899eb4e3c248cea1a4626c3eda50",
"0x0000000000000000000000000000000000000000000000000000000066957cb4"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000e4866ab1ef0fa0ba1b9100000000000000000000000000000000000000000000e77e477e6cbd9ce5f90f00000000000000000000000000000000000000000000e4866e4c7c2d1e2e317c00000000000000000000000000000000000000000000e77e6c1fc07dee9674aa000000000000000000000000000000000000000000000000039db5028fe06034",
"blockNumber": "1934791",
"transactionHash": "0x826b3e20a499dfb655828829ba08cab037b81873237397502159ea41f9186246",
"transactionIndex": 16,
"blockHash": "0x61ea6638b24ef3b0215556e67bb847e44f52c97e9f24b898452b3b6c426ee82e",
"logIndex": 43,
"removed": false
},
"id": 3
}
]
```

Batch requests are useful for optimizing network usage and reducing latency by sending multiple requests at once.
31 changes: 31 additions & 0 deletions docs/lidoPulse/get-started/errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
sidebar_position: 5
---

# Handling Errors

The server includes comprehensive error handling. Errors are returned in the standard JSON-RPC format, including an error code and message.

## Example Error Response

```json
{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "Invalid Request"
},
"id": null
}
```

## Error Codes

The following error codes are used by the server:

- `-32600`: Invalid Request
- `-32700`: Parse error
- `-32601`: Method not found
- `-32602`: Invalid params
- `-32603`: Internal error
- `-32000`: Server error
32 changes: 32 additions & 0 deletions docs/lidoPulse/get-started/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
sidebar_position: 2
---

# Installation

To get started, clone the repository and install the dependencies:

```bash
git clone https://github.com/lidofinance/lido-ethereum-sdk.git
cd packages/lido-pulse
cp .env.example .env
yarn install
```

Fill in the `.env` file with the required environment variables.

## Running the Server

To start the Fastify server, run:

```bash
yarn start
```

You can also run the server in development mode with hot reloading:

```bash
yarn dev
```

The server will start on port 3000 by default.
Loading

0 comments on commit 255e3a2

Please sign in to comment.