Skip to content

feat(price-pusher): allow mnemonic from MNEMONIC env var#3689

Open
0xghost42 wants to merge 2 commits into
pyth-network:mainfrom
0xghost42:feat/1015-mnemonic-env
Open

feat(price-pusher): allow mnemonic from MNEMONIC env var#3689
0xghost42 wants to merge 2 commits into
pyth-network:mainfrom
0xghost42:feat/1015-mnemonic-env

Conversation

@0xghost42
Copy link
Copy Markdown

@0xghost42 0xghost42 commented May 13, 2026

Summary

Closes #1015.

Make --mnemonic-file optional in the price pusher and fall back to a MNEMONIC environment variable when the flag is not supplied. This makes deployments on platforms that inject secrets as encrypted env vars (DigitalOcean, Fly.io, etc.) much simpler, since operators no longer need to write the mnemonic to disk before launching the process.

Maintainer pre-approval: @jayantk on the original issue — "happily accept a PR".

Change

  • apps/price_pusher/src/options.ts: --mnemonic-file is now required: false, with an updated description noting the env var fallback.
  • apps/price_pusher/src/utils.ts: new readMnemonic(mnemonicFile) helper. Resolution order: file (if supplied) → MNEMONIC env var → clear error naming both sources.
  • apps/price_pusher/src/{evm,sui,aptos,injective}/command.ts: replace per-command fs.readFileSync(mnemonicFile, "utf8").trim() with the shared helper; drop now-unused fs import.
  • apps/price_pusher/README.md: short note on the two supported sources and the precedence rule.

Verification

  • pnpm exec tsc --noEmit from apps/price_pusher passes.
  • pnpm turbo fix --filter @pythnetwork/price-pusher is clean (formatting + biome).
  • Behaviour matrix:
    • --mnemonic-file <path> only → reads file (unchanged from today).
    • MNEMONIC=… env var only → reads env.
    • Both supplied → file wins (explicit beats implicit).
    • Neither → clear error: No mnemonic provided. Pass --mnemonic-file or set the MNEMONIC environment variable.

Out of scope

I did not touch the solana, fuel, near, or ton commands — they use different key-loading paths (keypair files / explicit private keys) and don't accept --mnemonic-file today. Happy to extend to those in a follow-up if useful.


Open in Devin Review

@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

7 Skipped Deployments
Project Deployment Actions Updated (UTC)
api-reference Skipped Skipped May 21, 2026 8:36am
component-library Skipped Skipped May 21, 2026 8:36am
developer-hub Skipped Skipped May 21, 2026 8:36am
entropy-explorer Skipped Skipped May 21, 2026 8:36am
insights Skipped Skipped May 21, 2026 8:36am
proposals Skipped Skipped May 21, 2026 8:36am
staking Skipped Skipped May 21, 2026 8:36am

Request Review

@vercel vercel Bot temporarily deployed to Preview – component-library May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – entropy-explorer May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – proposals May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – api-reference May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – insights May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – developer-hub May 13, 2026 10:25 Inactive
@vercel vercel Bot temporarily deployed to Preview – staking May 13, 2026 10:25 Inactive
devin-ai-integration[bot]

This comment was marked as resolved.

@0xghost42 0xghost42 force-pushed the feat/1015-mnemonic-env branch from ea1abb5 to f1a68c4 Compare May 14, 2026 10:24
@0xghost42 0xghost42 requested a review from a team as a code owner May 14, 2026 10:24
@vercel vercel Bot temporarily deployed to Preview – insights May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – entropy-explorer May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – component-library May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – developer-hub May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – api-reference May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – proposals May 14, 2026 10:24 Inactive
@vercel vercel Bot temporarily deployed to Preview – staking May 14, 2026 10:24 Inactive
@0xghost42
Copy link
Copy Markdown
Author

Pushed f1a68c4 — rebased on main (resolves the conflict the hermes-access-token merge created in injective/command.ts) and addressed both Devin review findings:

  • Version bump@pythnetwork/price-pusher from 10.4.0 -> 10.5.0 (minor, backward-compatible feature addition). 10.4.0 was consumed by feat: add hermes access token to price pusher #3687 (hermes access token) after this PR was opened.
  • Test coverage — added apps/price_pusher/tests/utils.test.ts (six cases): file path, env-var fallback, empty-string path treated as not-supplied, file-source precedence over env, missing-both error, empty-env error. Wired test:unit into package.json scripts. pnpm --filter @pythnetwork/price-pusher exec test-unit runs green locally.

Type check (tsc --noEmit) also clean on the rebased branch.

@0xghost42
Copy link
Copy Markdown
Author

Hi @keyvankhademi — gentle bump on this one. Open since 13/05, all checks green, Devin findings (version bump to 10.5.0, readMnemonic test coverage) both marked Resolved. Small additive change: env-var fallback for mnemonic with existing CLI/file paths untouched. Happy to rebase if a different version cadence is preferred.

0xghost42 added a commit to 0xghost42/pyth-crosschain that referenced this pull request May 21, 2026
The sample Grafana dashboard (`grafana-dashboard.sample.json`) filters
every Prometheus query by `namespace=$chain`:

  pyth_price_feeds_total{namespace="$chain"}
  pyth_price_last_published_time{namespace="$chain"}
  pyth_price_update_attempts_total{namespace="$chain", ...}
  ...

But `src/metrics.ts` only set `app="price_pusher"` as the default label
and never emitted a `namespace` label on any counter/gauge, and
`prometheus.sample.yml` did not add one via relabeling. With the
dashboard out of the box that filter matched zero series, so every
panel for a fresh deployment came up empty — flagged by Devin during
review of pyth-network#3692 and acknowledged there as pre-existing dashboard
behavior worth fixing in a separate PR. This is that PR.

Wiring:

  - new CLI option `--metrics-namespace <name>` in `src/options.ts`,
    defaulted per chain command (`evm`, `sui`, `aptos`, `solana`) so
    that single-chain deployments work without configuration
  - `PricePusherMetrics` constructor now takes a `namespace: string`
    parameter and sets it via `registry.setDefaultLabels`, so every
    existing metric series gains a `namespace` label without per-metric
    `labelNames` plumbing
  - each chain command (`evm/sui/aptos/solana/command.ts`) reads the
    new arg and passes through to the constructor

Operators running multiple deployments of the same chain (e.g. several
EVM networks against one Grafana instance) can now set
`--metrics-namespace bsc-mainnet` / `--metrics-namespace polygon-mainnet`
to disambiguate. Single-deployment setups keep working unchanged.

Bumps `@pythnetwork/price-pusher` to `10.5.0` (additive, no breaking
changes — old CLIs still work). Note: pyth-network#3689 and pyth-network#3703 also bump to
`10.5.0`, so whichever of the three lands second/third will need a
trivial rebase to `10.6.0` / `10.7.0`.

Refs pyth-network#3692.
0xghost42 added 2 commits May 21, 2026 14:06
…-network#1015)

Previously the price pusher required `--mnemonic-file` pointing at a file on
disk containing the signing mnemonic. On platforms that provide encrypted env
vars (DigitalOcean, Fly.io, etc.) this forces operators to first write the
secret to disk before launching the process.

Make `--mnemonic-file` optional and fall back to the `MNEMONIC` environment
variable when the flag is not supplied. If both are supplied, the file takes
precedence (explicit beats implicit). If neither is supplied, the existing
required-arg error is replaced with a clearer message naming both sources.

The helper lives in `utils.ts` so all four chain commands (evm, sui, aptos,
injective) share identical resolution behaviour.
Per review feedback:

- Bump @pythnetwork/price-pusher to 10.5.0 (minor) — backward-compatible
  feature addition (MNEMONIC env var fallback). 10.4.0 was consumed by
  pyth-network#3687 hermes-access-token.
- Add tests/utils.test.ts covering all three readMnemonic paths plus
  the file-precedence-over-env behaviour: file source, env fallback,
  empty-string path (treated as not supplied), file > env precedence,
  missing-both error, empty-env error.
- Wire `test:unit` script into apps/price_pusher/package.json so the
  workspace runner picks it up.

`pnpm --filter @pythnetwork/price-pusher exec test-unit` — 6 passing.
@0xghost42 0xghost42 force-pushed the feat/1015-mnemonic-env branch from f1a68c4 to 8c59265 Compare May 21, 2026 08:36
@vercel vercel Bot temporarily deployed to Preview – proposals May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – component-library May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – insights May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – entropy-explorer May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – developer-hub May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – api-reference May 21, 2026 08:36 Inactive
@vercel vercel Bot temporarily deployed to Preview – staking May 21, 2026 08:36 Inactive
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

return fs.readFileSync(mnemonicFile, "utf8").trim();
}

const envMnemonic = process.env.MNEMONIC;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Missing biome-ignore for noProcessEnv lint rule in utils.ts

The new readMnemonic function uses process.env.MNEMONIC at line 70, which violates the repository's Biome noProcessEnv: "error" lint rule (biome.json:151). The test file correctly includes // biome-ignore-all lint/style/noProcessEnv (tests/utils.test.ts:1), but the source file has no such suppression comment. Every other file in the repo that accesses process.env includes a biome-ignore comment (e.g., apps/mcp/src/config.ts:1, apps/developer-hub/src/cookies/initialAccessTokenCookie.ts:12). CI runs biome ci --changed which will report this as an error and fail the lint check.

Suggested change
const envMnemonic = process.env.MNEMONIC;
// biome-ignore lint/style/noProcessEnv: readMnemonic is the designated env var fallback point
const envMnemonic = process.env.MNEMONIC;
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

[Feature Request] price-pusher should look for MNEMONIC env var when mnemonic-file is not present

1 participant