-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of js sdk for express relay (#1281)
- Loading branch information
Showing
9 changed files
with
3,018 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
root: true, | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint"], | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
}; |
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 @@ | ||
lib/ |
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,74 @@ | ||
# 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: | ||
|
||
```bash | ||
npm run generate-api-types | ||
``` | ||
|
||
## 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.signOpportunityBid( | ||
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> | ||
``` |
Oops, something went wrong.