pyth-crosschain/express_relay/sdk/js
Anirudh Suresh 92566736da
Express relay python searcher (#1319)
* move js searcher sdk

* add the python searcher sdk

* remove pycache

* create class for simple searcher

* add websocket to python searcher sdk

* finish ws, avoid storing liquidation opportunities within client

* python scripts now working w auto type generation

* minor precommit changes

* address comments 1

* add openapi type generations

* fixed precommit issues on generated type files

* reorg

* fixed openapi_client generated precommit

* fix js filepath issue

* added close ws

* renamings and add send_ws_message method

* get rid of duplicate error parsing

* cleanup

* set up pypi workflow

* address comments

* add python precommit

* changes + precommit changes

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* test precommit change

* correct directory for poetry in pypi wf

* remove isort

* rename package

* add UUID and some cleanup

* new openapi typings

* add pydantic to pyproj

* more changes

* precommit

* remove extraneous files, stick w actual_instance

* added back http as nondefault

* correction

* some cleanup and reorg

* minor changes

* add back api response typing file

* minorer changes

* exclude openapi_client from end of file fixer

* build internal models via pydantic

* chgs

* start to reorg classes

* configure precommit to work

* some cleanup

* reorg a bit

* address comments

* chgs

* fgt

* morechgs

* some more chgs

---------

Co-authored-by: ani <ani@Anirudhs-MacBook-Pro.local>
Co-authored-by: ani <ani@Anirudhs-MBP.cable.rcn.com>
2024-03-15 15:08:48 -04:00
..
src Express relay python searcher (#1319) 2024-03-15 15:08:48 -04:00
.eslintrc.js Initial version of js sdk for express relay (#1281) 2024-02-08 10:56:17 +01:00
.gitignore Initial version of js sdk for express relay (#1281) 2024-02-08 10:56:17 +01:00
README.md feat(per-js-sdk): Add support for bid state and raw bid submission + renames (#1329) 2024-03-14 20:15:14 +01:00
package-lock.json Express relay python searcher (#1319) 2024-03-15 15:08:48 -04:00
package.json Express relay python searcher (#1319) 2024-03-15 15:08:48 -04:00
tsconfig.json Express relay python searcher (#1319) 2024-03-15 15:08:48 -04:00

README.md

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

Development

To generate the latest type declarations from the server openapi schema, run:

npm run generate-api-types

Quickstart

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

function calculateOpportunityBid(opportunity: Opportunity): BidParams | null {
  // searcher implementation here
  // if the opportunity is not suitable for the searcher, return null
}

async function bidStatusCallback(bidStatus: BidStatusUpdate) {
  console.log(`Bid status for bid ${bidStatus.id}: ${bidStatus.status.status}`);
}

async function opportunityCallback(opportunity: Opportunity) {
  const bidParams = calculateOpportunityBid(opportunity);
  if (bidParams === null) return;
  const opportunityBid = await client.signOpportunityBid(
    opportunity,
    bidParams,
    privateKey // searcher private key with appropriate permissions and assets
  );
  await client.submitOpportunityBid(opportunityBid);
}

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

await client.subscribeChains([chain_id]); // chain id you want to subscribe to

Example

There is an example searcher in examples directory.

SimpleSearcher

This example 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:

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