Skip to content

feat(pyth-sui-js): migrate to @mysten/sui v2 API#3502

Open
0xCryptoZen wants to merge 1 commit intopyth-network:mainfrom
0xCryptoZen:feat/pyth-sui-js-v2-migration
Open

feat(pyth-sui-js): migrate to @mysten/sui v2 API#3502
0xCryptoZen wants to merge 1 commit intopyth-network:mainfrom
0xCryptoZen:feat/pyth-sui-js-v2-migration

Conversation

@0xCryptoZen
Copy link

@0xCryptoZen 0xCryptoZen commented Feb 24, 2026

Summary

  • Migrate @pythnetwork/pyth-sui-js from @mysten/sui v1 to v2, replacing SuiClient with the transport-agnostic ClientWithCoreApi interface and updating all API calls to the new provider.core.* namespace
  • Move @mysten/sui from direct dependency to peerDependencies: "^2.0.0" so consumers can choose their preferred transport (JSON-RPC, gRPC, or GraphQL)
  • Update the Sui CLI tooling (pyth_deploy.ts, upgrade_pyth.ts) to use SuiJsonRpcClient and the renamed fromBase64 utility
  • Bump @pythnetwork/pyth-sui-js version from 3.0.0 to 4.0.0 (breaking change)

Key migration details

  • SuiClientClientWithCoreApi (from @mysten/sui/client)
  • provider.getObject()provider.core.getObject() with { include: { json: true } } instead of { options: { showContent: true } }
  • provider.getDynamicFieldObject()provider.core.getDynamicObjectField() with BCS-encoded field names
  • Object response: result.data.content.fields.xresult.object.json.x
  • Example updated to use SuiGrpcClient with the new transaction result format

Closes #3454

Test plan

  • TypeScript strict type-checking passes for client.ts against @mysten/sui@2.5.0
  • Integration test with a live Sui RPC endpoint to verify getBaseUpdateFee(), getPackageId(), getPriceFeedObjectId()
  • Verify SuiRelay.ts example works with SuiGrpcClient
  • Verify CLI deploy/upgrade workflows with SuiJsonRpcClient

@0xCryptoZen 0xCryptoZen requested a review from a team as a code owner February 24, 2026 15:12
@vercel
Copy link

vercel bot commented Feb 24, 2026

@0xCryptoZen is attempting to deploy a commit to the Pyth Network Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bba8900b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


throw new Error(`Cannot fetch package id for object ${objectId}`);
});
const result = await this.provider.core.getObject({

Choose a reason for hiding this comment

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

P1 Badge Preserve compatibility with existing Sui providers

This change unconditionally dereferences provider.core, but internal consumers in this repo still instantiate SuiPythClient via SuiChain.getProvider() in contract_manager/src/core/chains.ts while contract_manager/package.json is pinned to @mysten/sui ^1.3.0; that provider shape does not expose core. In that existing path (contract_manager/src/core/contracts/sui.ts), calls like getPackageId() now fail immediately with a runtime undefined property error instead of performing an RPC call.

Useful? React with 👍 / 👎.

Comment on lines 318 to 320
} catch {
// Dynamic field not found
return undefined;

Choose a reason for hiding this comment

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

P2 Badge Propagate non-not-found dynamic field errors

The broad catch here converts every getDynamicObjectField failure into undefined, so network timeouts, auth issues, and malformed responses are all misreported as “feed not found.” That masks real outages and can push callers into incorrect create/update behavior instead of surfacing the underlying RPC failure; only the explicit not-found case should be mapped to undefined.

Useful? React with 👍 / 👎.

@0xCryptoZen 0xCryptoZen force-pushed the feat/pyth-sui-js-v2-migration branch from 3bba890 to 552e7b4 Compare February 24, 2026 16:54
Migrate @pythnetwork/pyth-sui-js, the Sui CLI tooling, and
contract_manager from @mysten/sui v1 to v2.

Key changes:
- Replace SuiClient with ClientWithCoreApi (transport-agnostic) in pyth-sui-js
- Use provider.core.* namespace for all data access methods
- BCS-encode dynamic field names as required by v2
- Update response handling for new object/json format
- Move @mysten/sui to peerDependencies (^2.0.0) in pyth-sui-js
- Update CLI to use SuiJsonRpcClient and fromBase64
- Migrate contract_manager to SuiJsonRpcClient for compatibility
- Update contract_manager tsconfig moduleResolution to bundler
- Narrow catch in getPriceFeedObjectId to only swallow not-found errors
- Bump pyth-sui-js version from 3.0.0 to 4.0.0

Closes pyth-network#3454
@0xCryptoZen 0xCryptoZen force-pushed the feat/pyth-sui-js-v2-migration branch from 552e7b4 to fbbc56d Compare February 24, 2026 17:49
@0xCryptoZen
Copy link
Author

Re: P1 — Preserve compatibility with existing Sui providers

Addressed. contract_manager has been migrated to @mysten/sui@^2.5.0 in this PR:

  • contract_manager/package.json: @mysten/sui bumped from ^1.3.0 to ^2.5.0
  • contract_manager/src/core/chains.ts: SuiClientSuiJsonRpcClient (from @mysten/sui/jsonRpc), which implements ClientWithCoreApi and preserves all v1-compatible JSON-RPC method signatures (getObject, getDynamicFieldObject, signAndExecuteTransaction, etc.)
  • contract_manager/tsconfig.json: moduleResolution updated from "node" to "bundler" to resolve v2's ESM-only exports

Type-checking passes for both chains.ts and contracts/sui.ts with zero errors.


Re: P2 — Propagate non-not-found dynamic field errors

Addressed. The broad catch has been narrowed to only swallow "not found" errors. All other failures (network timeouts, auth issues, malformed responses) are now re-thrown:

} catch (e: unknown) {
  const msg = e instanceof Error ? e.message : String(e);
  if (
    msg.includes("Could not find the referenced object") ||
    msg.includes("dynamicFieldNotFound") ||
    msg.includes("not found")
  ) {
    return undefined;
  }
  throw e;
}

@0xCryptoZen
Copy link
Author

@https://github.com/codex review

@0xCryptoZen
Copy link
Author

@devin-ai-integration please review this 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.

pyth-sui-js still targets Sui v1 API and cannot be used cleanly with Sui v2 toolchain

1 participant