Skip to content

fix(stake): remove silent mainnet default in getStakeProgramId for browser bundles - #340

Open
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/stake-mainnet-default-upstream
Open

fix(stake): remove silent mainnet default in getStakeProgramId for browser bundles#340
Morenikeoa wants to merge 1 commit into
dcccrypto:mainfrom
Morenikeoa:fix/stake-mainnet-default-upstream

Conversation

@Morenikeoa

Copy link
Copy Markdown

Summary

getStakeProgramId()'s network-resolution IIFE defaulted to 'mainnet' whenever it ran in a browser bundle with no explicit network argument and no NETWORK/NEXT_PUBLIC_DEFAULT_NETWORK env var set (process.env is empty in browser bundles since env vars aren't inlined into third-party SDK code). This is the exact opposite of the sibling getCurrentNetwork() in program-ids.ts, which was hardened under PERC-697 specifically to remove this same class of silent-mainnet-default bug and now fails open to devnet.

Any frontend/wallet-integration code built on this SDK (the natural consumption pattern for a trading SDK) that calls getStakeProgramId() or the PDA helpers that default to it (deriveStakePool, deriveStakeVaultAuth, deriveDepositPda) without an explicit network or programId, in an environment where the bundler didn't inline a NETWORK env var, silently derives mainnet PDAs and targets the mainnet stake program — risking a devnet-testing flow executing against mainnet, or a real deposit/withdraw/stake transaction going to the wrong program.

Fix

The browser-context branch now returns 'devnet', matching getCurrentNetwork()'s fail-open-to-devnet policy exactly. Mainnet still requires an explicit network argument or env var — this only removes the silent default, it does not change explicit-network behavior.

Test plan

  • Added a regression test that simulates a browser context (temporary global window) with no env vars set and asserts getStakeProgramId() returns the devnet address, not mainnet.
  • Confirmed the test fails against the prior code (returns the mainnet address) and passes against this fix.
  • Full suite green: 852 passed, 31 skipped (883 total, +1 new test).

…owser bundles

getStakeProgramId()'s network-resolution IIFE defaulted to 'mainnet'
whenever it ran in a browser bundle with no explicit network argument
and no NETWORK/NEXT_PUBLIC_DEFAULT_NETWORK env var set (process.env is
empty in browser bundles since env vars aren't inlined into
third-party SDK code). This is the exact opposite of the sibling
getCurrentNetwork() in program-ids.ts, which was hardened under
PERC-697 specifically to remove this same class of silent-mainnet-
default bug and now fails open to devnet.

Any frontend/wallet-integration code built on this SDK (the natural
consumption pattern for a trading SDK) that calls getStakeProgramId()
or the PDA helpers that default to it (deriveStakePool,
deriveStakeVaultAuth, deriveDepositPda) without an explicit network or
programId, in an environment where the bundler didn't inline a
NETWORK env var, silently derives mainnet PDAs and targets the
mainnet stake program — risking a devnet-testing flow executing
against mainnet, or a real deposit/withdraw/stake transaction going
to the wrong program.

Fix: the browser-context branch now returns 'devnet', matching
getCurrentNetwork()'s fail-open-to-devnet policy exactly. Mainnet
still requires an explicit `network` argument or env var — this only
removes the silent default, it does not change explicit-network
behavior.

Added a regression test that simulates a browser context (temporary
global `window`) with no env vars set and asserts getStakeProgramId()
returns the devnet address, not mainnet. Confirmed it fails against
the prior code (returns the mainnet address) and passes against this
fix.

Full suite: 852 passed | 31 skipped (883 total, +1 new test).
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Morenikeoa, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 30 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24887661-f1ba-418a-bf2f-c13380dceb98

📥 Commits

Reviewing files that changed from the base of the PR and between 673bc47 and f1b3550.

📒 Files selected for processing (2)
  • src/solana/stake.ts
  • test/drift-check.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant