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

Initial version of js sdk for express relay #1281

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Initial version of js sdk for express relay
  • Loading branch information
m30m committed Feb 7, 2024
commit 20812cce3dd419eaa22d0a81e18b23dc6607cd50
6 changes: 6 additions & 0 deletions express_relay/sdk/js/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
};
1 change: 1 addition & 0 deletions express_relay/sdk/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/
66 changes: 66 additions & 0 deletions express_relay/sdk/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Pyth Express Relay JS SDK

Utility library for interacting with the Pyth Express Relay API.

## Installation

### npm

```
$ npm install --save @pythnetwork/express-relay-evm-js
```

### Yarn

```
$ yarn add @pythnetwork/express-relay-evm-js
```

## Quickstart

```typescript
import {
Client,
OpportunityParams,
BidInfo,
} from "@pythnetwork/express-relay-evm-js";

const client = new Client({ baseUrl: "https://per-staging.dourolabs.app/" });

function calculateOpportunityBid(
opportunity: OpportunityParams
): BidInfo | null {
// searcher implementation here
// if the opportunity is not suitable for the searcher, return null
}
const opportunities = await client.getOpportunities();

for (const opportunity of opportunities) {
const bidInfo = calculateOpportunityBid(order);
if (bidInfo === null) continue;
const opportunityBid = await client.signOpporunityBid(
opportunity,
bidInfo,
privateKey // searcher private key with appropriate permissions and assets
);
await client.submitOpportunityBid(opportunityBid);
}
```

### Example

There is an example searcher in [examples](./src/examples/) directory.

#### SimpleSearcher

[This example](./src/examples/SimpleSearcher.ts) fetches `OpportunityParams` from the specified endpoint,
creates a fixed bid on each opportunity and signs them with the provided private key, and finally submits them back to the server. You can run it with
`npm run simple-searcher`. A full command looks like this:

```bash
npm run simple-searcher -- \
--endpoint https://per-staging.dourolabs.app/ \
--bid 100000 \
--chain-id op_sepolia \
--private-key <YOUR-PRIVATE-KEY>
```
Loading
Loading