Repository navigation
fix(sdk): namespace amm v0.5 priceMath exports (TS2308 duplicate export) - #504
RicainvLovemr wants to merge 3 commits into
Conversation
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
| // #503: namespace the v0.5 priceMath helpers to avoid the ambiguous | ||
| // duplicate export against sdk/src/priceMath.ts (which exports PriceMath). |
There was a problem hiding this comment.
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.
| // #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!
There was a problem hiding this comment.
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:
-
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.
-
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.
There was a problem hiding this comment.
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.tsdoes not export from./ammat 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.tsexports onlySwapSimulation(type) andsimulateSwap(function)sdk/src/priceMath.tsexportsAmmMath(class) and aliases it asPriceMath
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 buildor nativecargo build-sbf - Uploads
.sofiles and.jsonIDL 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.
|
@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). |
| 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"; |
There was a problem hiding this comment.
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.
| 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
|
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 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). |
|
@greptile before I draft the .greptile/rules.md follow-up, could you enumerate what you consider this repo's key conventions? Specifically:
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. |
Key Repository ConventionsBased on the codebase, here are the conventions I currently re-derive on every PR review: 1. Build/Test EntrypointsCanonical rebuild after Rust changes:
Testing:
Build granularity:
Key constraint: The root 2. Scripts Tree: Current vs Legacy VersionsFrom Current versions (actively deployed/maintained):
Legacy (no longer synced, likely historical):
Environment: Scripts expect
3. SDK Release/Publish FlowPackage: Version strategy: Per-program versioning (no monolithic SDK version). Each program module ( Publish command:
Who triggers: Unknown from public docs (likely maintainers with npm publish rights; no automation visible in 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 CheckWhen a PR touches
When a PR touches
Cross-cutting concerns:
What I Don't Have Visibility Into
If you want me to dig into |
|
This is exactly what I needed for the draft — thank you. Three gaps then, all of which feel rules-worthy:
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).
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.
What
sdk/src/index.tsstar-exports both the sharedpriceMath(PriceMath/AmmMath) and theamm/v0.5chain which re-exports its ownpriceMathhelpers. Consumers importing from the package entry hitTS2308(duplicate export ambiguity) depending on module resolution order.This namespaces the v0.5 helpers as
AmmV05PriceMathso 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
priceMathfrom its index (only v0.5 does), which is why the collision is new.Preserve the existing AMM helper exports before merging so downstream imports keep working.
Findings
Summary
The PR replaces the v0.5 AMM helper exports with
AmmV05PriceMath.Reviews (2) · Last reviewed commit: "fix(sdk): namespace amm v0.5 priceMath e..." · Reviewed by Greptile