Skip to content

feat(lazer): create js solana sdk package #2899

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Riateche
Copy link
Contributor

@Riateche Riateche commented Jul 25, 2025

Summary

Create a JS package for interacting with Lazer Solana on-chain contract. The package includes:

  • Anchor IDL of the contract
  • TypeScript definition of the IDL
  • Helper function to work with native Solana signatures

I will also add an example for working with it to the pyth-examples repo.

Rationale

We removed signature helper from our main JS SDK because we don't want it to depend on Solana packages.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Locally built the package and used it as a dependency in examples.

Copy link

vercel bot commented Jul 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 0:27am

@@ -0,0 +1,6 @@
import type { PythLazerSolanaContract } from "./idl/pyth-lazer-solana-contract.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was the .js in the end necessary :?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed when using nodenext module resolution, in which typescript does not transform import paths at all. See https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution for reference.

In general, nodenext is the preferred module resolution for anything that supports node (and IMO, any published lib should be using it as it's the most future-proof option). The short explanation is that nodenext leaves imports alone when transpiling, meaning the import path gets passed directly to node. Since node requires extensions when using esm, so then does the nodenext module resolution strategy (this also explains why the extension is .js and not .ts).

For more context, eventually node will change so that type annotations are just ignored at runtime, and at that point typescript will no longer be a transpiler and just a type checker, similar to mypy in python.

Copy link
Collaborator

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I wait for Connor to approve it though.

Copy link
Collaborator

@cprussin cprussin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most important change is the change to pnpm-workspace.yaml since that will cause swc to be broken in some environments.

@@ -6,6 +6,7 @@
"fix:format": "prettier --write **/*.*",
"test:format": "prettier --check **/*.*",
"test:anchor": "CARGO_TARGET_DIR=\"$PWD/target\" RUSTUP_TOOLCHAIN=nightly-2025-04-15 anchor test",
"update-idl": "RUSTUP_TOOLCHAIN=nightly-2025-04-15 anchor build && cp target/types/pyth_lazer_solana_contract.ts ../../sdk/js-solana/src/idl/pyth-lazer-solana-contract.ts && cp target/idl/pyth_lazer_solana_contract.json ../../sdk/js-solana/src/idl/pyth-lazer-solana-contract.json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't personally like having a task in one package which reaches into and updates another package. Personally, I'd put this as a build:idl sub-task on the @pythnetwork/pyth-lazer-solana-sdk package instead, given it's a task that builds files for that package.

If you really want to be pedantic, you leave something like RUSTUP_TOOLCHAIN=nightly-2025-04-15 anchor build here, and then add the cp commands in @pythnetwork/pyth-lazer-solana-sdk, and set up turbo so the latter depends on the former.

"test:types": "tsc",
"test:format": "prettier --check .",
"fix:format": "prettier --write .",
"doc": "typedoc --out docs/typedoc src"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit but I usually name this as build:docs

"@types/node": "^18.19.54",
"eslint": "catalog:",
"prettier": "catalog:",
"typedoc": "^0.26.8",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving these dependencies up to pnpm-workspace.yaml and marking them as catalog: dependencies; in general I think we should only be using numbered dependencies for places where some package needs to be held back from the rest of the monorepo for some reason.

@@ -0,0 +1,464 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these files are generated, I suggest not checking them in. Instead, ensure the build tasks are correctly ordered so the files get generated as part of building this package. I personally really prefer not to check these files in, since it is effectively a cache and checking them in means you are now susceptible to cache sync issues.

@@ -0,0 +1,6 @@
import type { PythLazerSolanaContract } from "./idl/pyth-lazer-solana-contract.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed when using nodenext module resolution, in which typescript does not transform import paths at all. See https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution for reference.

In general, nodenext is the preferred module resolution for anything that supports node (and IMO, any published lib should be using it as it's the most future-proof option). The short explanation is that nodenext leaves imports alone when transpiling, meaning the import path gets passed directly to node. Since node requires extensions when using esm, so then does the nodenext module resolution strategy (this also explains why the extension is .js and not .ts).

For more context, eventually node will change so that type annotations are just ignored at runtime, and at that point typescript will no longer be a transpiler and just a type checker, similar to mypy in python.

@@ -0,0 +1,9 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you moved to swc, you no longer need this file.

@@ -185,3 +186,5 @@ onlyBuiltDependencies:
- web3
- web3-bzz
- web3-shh
ignoredBuiltDependencies:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add this to onlyBuiltDependencies, not ignoredBuiltDependencies. Adding it here will cause it to break in any environment where the binaries aren't already present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants