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

Merged
merged 2 commits into from
Jul 30, 2025

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 29, 2025 0:18am
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 0:18am

@Riateche Riateche force-pushed the publish-lazer-solana-js-package2 branch from 8437764 to a0cb877 Compare July 28, 2025 12:20
@Riateche Riateche marked this pull request as ready for review July 28, 2025 12:28
@Riateche Riateche requested review from ali-behjati and a team as code owners July 28, 2025 12:28
@@ -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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the update-idl task to the @pythnetwork/pyth-lazer-solana-sdk package. I agree that generating IDL as part of the build process would be a cleaner way to do this, but I don't want to introduce anchor as a build dependency to JS packages. We tried to do that before with the Lazer Solana contract tests, and it was constantly causing problems for people.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah that makes sense

@@ -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.

@Riateche Riateche merged commit cd2b055 into main Jul 30, 2025
13 checks passed
@Riateche Riateche deleted the publish-lazer-solana-js-package2 branch July 30, 2025 10:26
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