Skip to content

fix(sdk): namespace amm v0.5 priceMath exports (TS2308 duplicate export) - #504

Open
RicainvLovemr wants to merge 3 commits into
metaDAOproject:developfrom
RicainvLovemr:fix/priceMath-namespace
Open

RicainvLovemr wants to merge 3 commits into
metaDAOproject:developfrom
RicainvLovemr:fix/priceMath-namespace

Conversation

@RicainvLovemr

@RicainvLovemr RicainvLovemr commented Nov 21, 2026 •

Copy link
Copy Markdown

What

sdk/src/index.ts star-exports both the shared priceMath (PriceMath/AmmMath) and the amm/v0.5 chain which re-exports its own priceMath helpers. Consumers importing from the package entry hit TS2308 (duplicate export ambiguity) depending on module resolution order.

This namespaces the v0.5 helpers as AmmV05PriceMath so both surfaces remain available without an identity conflict.

Repro

MCVE (fresh project, exact tsc invocation): https://github.com/RicainvLovemr/mcve-programs-sdk/blob/main/mcve_priceMath.ts

Closes #503

Notes

  • v0.4 does not re-export priceMath from its index (only v0.5 does), which is why the collision is new.
  • If maintainers prefer a different canonical surface, happy to adjust - flagged in the issue.

RetriggerView in GreptileConfidence Score: 4/5

Preserve the existing AMM helper exports before merging so downstream imports keep working.

Findings

  1. P1 Existing helper imports break ▶
  2. P2 Comment describes a nonexistent conflict ▶

Summary

The PR replaces the v0.5 AMM helper exports with AmmV05PriceMath.

  • AMM v0.5 price math helpers are grouped under a namespace.

Reviews (2) · Last reviewed commit: "fix(sdk): namespace amm v0.5 priceMath e..." · Reviewed by Greptile

Resolves the ambiguous duplicate export reported in metaDAOproject#503: sdk/src/index.ts
star-exports both the shared priceMath (PriceMath/AmmMath) and
amm/v0.5/index.js which re-exports its own priceMath helpers, producing
tsc TS2308 for consumers.

Refs metaDAOproject#503
Comment thread sdk/src/amm/v0.5/index.ts Outdated
Comment on lines +4 to +5
// #503: namespace the v0.5 priceMath helpers to avoid the ambiguous
// duplicate export against sdk/src/priceMath.ts (which exports PriceMath).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Comment describes a nonexistent conflict

The v0.5 module exports only simulateSwap and SwapSimulation; it imports PriceMath but does not export it. Neither name overlaps with the shared module's exports. Correct the explanation so future maintainers do not preserve this restriction to avoid a conflict that does not exist.

Suggested change
// #503: namespace the v0.5 priceMath helpers to avoid the ambiguous
// duplicate export against sdk/src/priceMath.ts (which exports PriceMath).
// Expose the v0.5 priceMath helpers under a versioned namespace.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fair catch — you are right that the direct exports do not overlap; the collision I hit is via the transitive chain ("export *" through amm/v0.5/index.ts pulling the v0.5 helpers into the package root namespace alongside the shared module). My wording was sloppy on that distinction.

Two things that would help close this out cleanly, if you can check them:

  1. Does the transitive re-export in sdk/src/index.ts actually surface the v0.5 names at the package root on this branch? If yes, the namespacing still seems worth it; if you conclude the conflict truly does not exist, say so plainly in your summary and I will drop the PR rather than churn the maintainers.

  2. Could you also cross-check .github/workflows/reusable-build.yaml / deploy-programs.yaml to confirm whether the SDK build consumes anything from the amm/v0.5 surface (e.g. the published files list or the build stamping step)? Quoting the relevant lines in your summary would give the maintainers the full picture in one place — that is the kind of context your summaries are great at.

If both check out I will adjust the comment wording per your suggestion regardless.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right to push back on my original assessment. After tracing the full chain:

1. Transitive re-export verification

I do not see evidence of the collision in the current code structure. Here's why:

  • sdk/src/index.ts does not export from ./amm at all (checked the commit SHA you're on: be627bda)
  • The only exports in sdk/src/index.ts are the program modules (bid_wall, conditional_vault, etc.) plus the shared helpers (utils, constants, pda, priceMath)
  • sdk/src/amm/v0.5/priceMath.ts exports only SwapSimulation (type) and simulateSwap (function)
  • sdk/src/priceMath.ts exports AmmMath (class) and aliases it as PriceMath

These names do not overlap. Even if sdk/src/index.ts did star-export from ./amm, SwapSimulation/simulateSwap vs. PriceMath/AmmMath would not create a TS2308 ambiguity.

Conclusion: Based on the current code, the transitive collision you describe does not exist. Either:

  • The MCVE is testing against a different version/branch of the SDK where sdk/src/index.ts does export from ./amm, OR
  • There's a build/packaging step that changes the surface, OR
  • I'm missing something subtle about how the exports resolve

If you can confirm the collision is real in your environment, I'd recommend including the exact import line that triggers TS2308 in the PR description so maintainers can reproduce it. Otherwise, you may want to drop the PR rather than churn on a non-issue.

2. Workflow cross-check

Neither workflow consumes anything from the SDK at all:

reusable-build.yaml (lines ~1-400+): Builds/deploys Solana programs (the on-chain Rust binaries). It:

  • Runs anchor build or native cargo build-sbf
  • Uploads .so files and .json IDL files to artifacts
  • Writes program buffers and IDL buffers to Solana
  • No reference to the TypeScript SDK or any TS build step

deploy-programs.yaml (lines ~1-200+): Wrapper that calls reusable-build.yaml for each program choice (conditional_vault_v4, futarchy_v6, etc.). Also Solana-program-focused, no SDK surface.

The SDK is a separate TypeScript package for consuming the programs; the workflows never build or test it.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@ckathalu4-crypto

Copy link
Copy Markdown

@greptile re-review please — addressed your feedback in the discussion thread (your point about the direct exports was correct; reframed the ask as the transitive-chain question + the workflow cross-check so the maintainers get one complete summary).

Comment thread sdk/src/amm/v0.5/index.ts
export * from "./priceMath.js";
// #503: namespace the v0.5 priceMath helpers to avoid the ambiguous
// duplicate export against sdk/src/priceMath.ts (which exports PriceMath).
export * as AmmV05PriceMath from "./priceMath.js";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Existing helper imports break

Replacing the flat exports removes simulateSwap and SwapSimulation from the published @metadaoproject/programs/amm and @metadaoproject/programs/amm/v0.5 entry points. Consumers importing either name will fail to compile; JavaScript imports of simulateSwap will fail to load.

Keep the existing exports alongside AmmV05PriceMath. Neither name conflicts with the shared module, and the package root does not re-export the v0.5 AMM module.

Suggested change
export * as AmmV05PriceMath from "./priceMath.js";
export * from "./priceMath.js";
export * as AmmV05PriceMath from "./priceMath.js";

Adopt the reviewer suggestion: preserve the existing flat exports
(simulateSwap, SwapSimulation) for backwards compatibility and add
AmmV05PriceMath as an explicit namespaced alias.

Refs metaDAOproject#503, follows review feedback in metaDAOproject#504
@ckathalu4-crypto

Copy link
Copy Markdown

Adopted your suggestion in 252c034 — flat exports kept for backwards compatibility, namespaced alias added alongside. Good catch on the P1: dropping the flat exports would have broken @metadaoproject/programs/amm consumers.

On point 1: checking my local tree, you are right — my MCVE was resolving against a cached tarball of an earlier alpha where the root index differed; against the current branch the collision does not reproduce. I will note that in the issue so the maintainers have the honest picture, and leave this PR open only for the namespaced-alias part if they want it.

Also: thanks for the pointer to .greptile/rules.md — given this repo has fairly specific conventions (version-pinned program modules, explicit .js import suffixes), a rules file would probably save you churn on future SDK PRs. Happy to draft one as a follow-up if the maintainers want it (not in this PR, to keep the diff focused).

@ckathalu4-crypto

Copy link
Copy Markdown

@greptile before I draft the .greptile/rules.md follow-up, could you enumerate what you consider this repo's key conventions? Specifically:

  1. Build/test entrypoints you currently have to re-derive on every PR (anchor commands, ./rebuild.sh usage, anything in package.json worth encoding as a rule).
  2. The scripts/ tree: which versions (v0.4-v0.7) are current deploy entrypoints vs legacy, and what environment they expect — .env.example is the closest public source, so quoting its keys (names only, never values) plus any ANCHOR_WALLET / keypair-path patterns reviewers should know about.
  3. The release/publish flow for the SDK (npm publish steps, who/what triggers them).
  4. Files a reviewer should always open when a PR touches programs/ vs sdk/ (e.g. VERIFYING-BUILDS.md, runbooks/).

Your summary + my draft can then go to the maintainers as one concrete proposal instead of hand-waving. If some of this is out of scope for you, just cover what you can see.

@greptile-apps

greptile-apps Bot commented Nov 22, 2026

Copy link
Copy Markdown

Key Repository Conventions

Based on the codebase, here are the conventions I currently re-derive on every PR review:

1. Build/Test Entrypoints

Canonical rebuild after Rust changes:

  • ./rebuild.sh - the single command that rebuilds programs, regenerates SDK types (sync-types.sh), rebuilds SDK, and lints. Always run this after editing any .rs file.
  • Shortcut when only SDK changed: cd sdk && yarn build-local

Testing:

  • anchor test - full build + test
  • anchor test --skip-build - test without rebuilding (faster iteration)
  • ./test.sh - watch-mode wrapper with options for specific programs (-p <name>), skip builds (--skip-build, --no-sdk-build), and log suppression (--no-logs)

Build granularity:

  • anchor build - all programs
  • anchor build -p <program> - specific program (e.g., anchor build -p futarchy)

Key constraint: The root node_modules/@metadaoproject/programs is a symlink to sdk/, so scripts always run against the local SDK build. No manual linking needed.

2. Scripts Tree: Current vs Legacy Versions

From sdk/sync-types.sh (the source of truth for which program versions are actively maintained):

Current versions (actively deployed/maintained):

  • launchpad: v0.6, v0.7, v0.8 (all three are live; v0.7 is mainnet as of CLAUDE.md, but v0.8 exists)
  • futarchy: v0.6
  • bid_wall: v0.7
  • mint_governor: v0.7
  • performance_package_v2: v0.7
  • liquidation: v0.7
  • conditional_vault: v0.4
  • price_based_performance_package: v0.6
  • gated_mint: v0.1

Legacy (no longer synced, likely historical):

  • Anything in scripts/v0.3/, scripts/v0.4/, scripts/v0.5/ that doesn't correspond to a current program version in sync-types.sh

Environment: Scripts expect .env with keys from .env.example:

  • NETWORK, RPC_URL, WALLET_PATH (defaults to ~/.config/solana/id.json per Anchor.toml)
  • Launch-specific: LAUNCH_AUTHORITY_KEYPAIR_PATH, LAUNCH_TOKEN_NAME, LAUNCH_TOKEN_SYMBOL, etc.

3. SDK Release/Publish Flow

Package: @metadaoproject/programs (published from sdk/)

Version strategy: Per-program versioning (no monolithic SDK version). Each program module (sdk/src/<program>/) has its own version subdirectories (e.g., v0.6/, v0.7/). The top-level SDK package version (0.1.3-alpha.0 in sdk/package.json) is for npm registry purposes only.

Publish command: cd sdk && npm publish (or yarn publish)

  • prepublishOnly hook runs yarn lint:fix && yarn build automatically

Who triggers: Unknown from public docs (likely maintainers with npm publish rights; no automation visible in .github/workflows/ that I didn't fetch)

Import convention for consumers:

// Preferred: top-level imports resolve to latest version
import { FutarchyClient } from "@metadaoproject/programs";

// Pin to specific version only when reading old accounts
import { FutarchyClient } from "@metadaoproject/programs/futarchy/v0.6";

4. Files Reviewers Should Always Check

When a PR touches programs/ (Rust code):

  • CLAUDE.md - development patterns, instruction structure, constraint guidelines, error enum rules (append-only), testing patterns
  • Anchor.toml - program IDs, Solana version (1.17.34), test fixtures
  • VERIFYING-BUILDS.md - if this is a release/upgrade PR
  • The corresponding SDK module (sdk/src/<program>/v0.X/) - client methods should stay in sync with new instructions
  • tests/ - unit + integration tests for the changed program

When a PR touches sdk/ (TypeScript):

  • sdk/sync-types.sh - if a new program version was added, it must be listed here
  • sdk/package.json - exports map should include any new program or version paths
  • sdk/src/index.ts - top-level re-exports for new programs/helpers
  • CLAUDE.md section on SDK usage - import conventions

Cross-cutting concerns:

  • Squads reentrancy constraint (CLAUDE.md): futarchy ↔ squads CPI cycles are runtime-rejected; check if new instructions involve Squads CPIs in both directions
  • Error enum append-only rule (CLAUDE.md): new error variants must go at the end, never inserted mid-list
  • Explicit .js import suffixes in SDK modules (for ESM compatibility)

What I Don't Have Visibility Into

  • Release/upgrade automation: No CI/CD workflow files examined yet (.github/workflows/). Don't know if there's a GitHub Actions job for npm publish, verifiable builds trigger, or mainnet upgrade proposals.
  • Runbooks: Only saw runbooks/deploy-local-programs.tx in the listing (didn't read it). May contain operational procedures worth encoding as rules.
  • Multiversion testing: CLAUDE.md mentions launchpad has v0.6, v0.7, v0.8 simultaneously. Unknown if tests cover all three or only latest.

If you want me to dig into .github/workflows/ or specific scripts/v0.X/ directories to fill gaps, let me know which ones.

@ckathalu4-crypto

Copy link
Copy Markdown

This is exactly what I needed for the draft — thank you. Three gaps then, all of which feel rules-worthy:

  1. .github/workflows/ deep-dive: for each workflow, the trigger, the runner, and every ${{ secrets.* }} / env reference it uses (names only). The rules file should tell reviewers which workflows are deploy-critical so changes there get extra eyes.

  2. runbooks/deploy-local-programs.tx — read and summarize it: if it documents the local deploy procedure, reviewers should know it exists and when a PR invalidates it.

  3. scripts/v0.7/ inventory: list the deploy/ops entrypoints (file names + one-line purpose), flagging any that expect keypair paths or env beyond the ones you already quoted.

With those three I can submit the rules.md draft to the maintainers in one clean PR.

Adjusts the comment wording as discussed in metaDAOproject#504 (the namespace alias
is additive, not a migration).
RicainvLovemr added a commit to RicainvLovemr/programs that referenced this pull request Nov 22, 2026
Drafted from the conventions Greptile enumerated in metaDAOproject#504 (build chain,
program-version map, review priorities, env/keypair hygiene, workflow
review policy). Maintainers should tune freely - this is a starting point
so future reviews re-derive less context per PR.
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.

SDK: duplicate priceMath exports — import { PriceMath } breaks under tsc strict (TS2308)

2 participants