-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(lazer): add js example * chore: set up CI
- Loading branch information
Showing
6 changed files
with
326 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,22 @@ | ||
name: "Lazer JS Test Suite" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
lazer-js-test-suite: | ||
name: Lazer JS Test Suite | ||
runs-on: ubuntu-22.04 | ||
defaults: | ||
run: | ||
working-directory: lazer/js | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
- run: npm install --global [email protected] | ||
- run: pnpm install --frozen-lockfile | ||
- run: pnpm run test |
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,2 @@ | ||
tsconfig.tsbuildinfo | ||
dist |
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": "pyth-lazer-js-example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node --loader ts-node/esm src/index.js", | ||
"test": "pnpm run test:format && pnpm run build:cjs && pnpm run build:esm", | ||
"build:cjs": "tsc --project tsconfig.json --verbatimModuleSyntax false --module commonjs --outDir ./dist/cjs && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json", | ||
"build:esm": "tsc --project tsconfig.json --outDir ./dist/esm && echo '{\"type\":\"module\"}' > dist/esm/package.json", | ||
"fix:format": "prettier --write **/*.*", | ||
"test:format": "prettier --check **/*.*" | ||
}, | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@pythnetwork/pyth-lazer-sdk": "^0.1.1" | ||
}, | ||
"devDependencies": { | ||
"@cprussin/tsconfig": "^3.0.1", | ||
"@types/node": "^22.10.0", | ||
"prettier": "^3.4.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk"; | ||
|
||
/* eslint-disable no-console */ | ||
const client = new PythLazerClient( | ||
"wss://pyth-lazer-staging.dourolabs.app/v1/stream", | ||
"my_token", | ||
); | ||
client.addMessageListener((message) => { | ||
console.log("got message:", message); | ||
switch (message.type) { | ||
case "json": { | ||
if (message.value.type == "streamUpdated") { | ||
console.log( | ||
"stream updated for subscription", | ||
message.value.subscriptionId, | ||
":", | ||
message.value.parsed?.priceFeeds, | ||
); | ||
} | ||
break; | ||
} | ||
case "binary": { | ||
if ("solana" in message.value) { | ||
console.log("solana message:", message.value.solana?.toString("hex")); | ||
} | ||
if ("evm" in message.value) { | ||
console.log("evm message:", message.value.evm?.toString("hex")); | ||
} | ||
break; | ||
} | ||
} | ||
}); | ||
client.ws.addEventListener("open", () => { | ||
client.send({ | ||
type: "subscribe", | ||
subscriptionId: 1, | ||
priceFeedIds: [1, 2], | ||
properties: ["price"], | ||
chains: ["solana"], | ||
deliveryFormat: "json", | ||
channel: "fixed_rate@200ms", | ||
jsonBinaryEncoding: "hex", | ||
}); | ||
}); |
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,7 @@ | ||
{ | ||
"extends": "@cprussin/tsconfig/base.json", | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |