@0block.io/sdk 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ export interface FetchBlockhashOptions {
2
+ /** Injectable fetch (tests / non-standard runtimes). Defaults to global fetch. */
3
+ fetchImpl?: typeof fetch;
4
+ }
5
+ export interface RecentBlockhash {
6
+ /** The finalized blockhash to use as a transaction's recentBlockhash. */
7
+ blockhash: string;
8
+ /** Last block height at which this blockhash is still valid (0 if absent). */
9
+ lastValidBlockHeight: number;
10
+ }
11
+ /**
12
+ * Fetch the recent finalized blockhash from 0Block's cached public endpoint.
13
+ * `apiBaseUrl` is the 0Block API base (e.g. "https://<0block-host>"); the
14
+ * "/api/v1/blockhash" path is appended.
15
+ */
16
+ export declare function fetchRecentBlockhash(apiBaseUrl: string, opts?: FetchBlockhashOptions): Promise<RecentBlockhash>;
@@ -0,0 +1,24 @@
1
+ // 0Block public API: recent blockhash. Lets clients build transactions without
2
+ // their own Solana read RPC — 0Block polls and caches getLatestBlockhash on the
3
+ // server and serves it at GET {apiBaseUrl}/api/v1/blockhash (public, no key).
4
+ /**
5
+ * Fetch the recent finalized blockhash from 0Block's cached public endpoint.
6
+ * `apiBaseUrl` is the 0Block API base (e.g. "https://<0block-host>"); the
7
+ * "/api/v1/blockhash" path is appended.
8
+ */
9
+ export async function fetchRecentBlockhash(apiBaseUrl, opts) {
10
+ const fetchImpl = opts?.fetchImpl ?? fetch;
11
+ const base = apiBaseUrl.replace(/\/+$/, "");
12
+ const res = await fetchImpl(`${base}/api/v1/blockhash`);
13
+ if (!res.ok) {
14
+ throw new Error(`0Block blockhash unavailable (HTTP ${res.status})`);
15
+ }
16
+ const body = (await res.json());
17
+ if (!body.blockhash) {
18
+ throw new Error("0Block blockhash response missing blockhash");
19
+ }
20
+ return {
21
+ blockhash: body.blockhash,
22
+ lastValidBlockHeight: body.lastValidBlockHeight ?? 0,
23
+ };
24
+ }
package/dist/events.js CHANGED
@@ -1,7 +1,14 @@
1
1
  import * as web3 from "@solana/web3.js";
2
- // Anchor ships CJS-only; a default import + destructure works everywhere
3
- // (bundlers and raw Node ESM), named imports do not.
4
- import anchor from "@coral-xyz/anchor";
2
+ // Anchor ships BOTH a CJS build (Node resolves it via `require`, exposing
3
+ // everything as the interop `default`; its named exports are NOT statically
4
+ // detectable through Anchor's deep `export *` chain, so named imports fail in
5
+ // Node ESM) AND ESM/browser builds (bundlers like Turbopack/webpack resolve
6
+ // these — they have named exports and NO `default`). Import the namespace and
7
+ // prefer the CJS `default` when present, else fall back to the ESM namespace,
8
+ // so this resolves in Node ESM, webpack, and Turbopack alike.
9
+ import * as anchorNamespace from "@coral-xyz/anchor";
10
+ const anchor = (anchorNamespace
11
+ .default ?? anchorNamespace);
5
12
  const { BN, BorshEventCoder } = anchor;
6
13
  import { ROUTER_IDL } from "./idl/router.js";
7
14
  // Event layouts derive from the vendored (trimmed) router IDL.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./constants.js";
2
2
  export * from "./types.js";
3
3
  export { createContext, type CreateContextParams, type TenantInit, type ZeroBlockContext, } from "./context.js";
4
4
  export { buildSendTransactionRequest, createLandingClient, withLandingTip, type LandingClient, type LandingServiceConfig, type SendTransactionOptions, } from "./landing.js";
5
+ export { fetchRecentBlockhash, type FetchBlockhashOptions, type RecentBlockhash, } from "./blockhash.js";
5
6
  export { toPk, deriveAta, deriveOrderMarker, deriveWrapperConfig, deriveRouterGlobalConfig, deriveRouterTenantConfig, derivePumpfunGlobal, derivePumpfunBondingCurve, derivePumpfunBondingCurveV2, derivePumpfunEventAuthority, derivePumpfunCreatorVault, derivePumpfunGlobalVolumeAccumulator, derivePumpfunUserVolumeAccumulator, derivePumpfunFeeConfig, } from "./pda.js";
6
7
  export { type AccountFetcher, connectionFetcher, resolveTokenProgram, resolvePumpfunMarketContext, fetchPumpfunGlobalFeeRecipient, fetchPumpfunBondingCurveCreator, fetchPumpfunBuybackFeeRecipients, } from "./fetch.js";
7
8
  export { buildPumpfunRemainingAccounts, type PumpfunRemainingAccountsParams, } from "./venues/pumpfun.js";
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export * from "./constants.js";
15
15
  export * from "./types.js";
16
16
  export { createContext, } from "./context.js";
17
17
  export { buildSendTransactionRequest, createLandingClient, withLandingTip, } from "./landing.js";
18
+ export { fetchRecentBlockhash, } from "./blockhash.js";
18
19
  export { toPk, deriveAta, deriveOrderMarker, deriveWrapperConfig, deriveRouterGlobalConfig, deriveRouterTenantConfig, derivePumpfunGlobal, derivePumpfunBondingCurve, derivePumpfunBondingCurveV2, derivePumpfunEventAuthority, derivePumpfunCreatorVault, derivePumpfunGlobalVolumeAccumulator, derivePumpfunUserVolumeAccumulator, derivePumpfunFeeConfig, } from "./pda.js";
19
20
  export { connectionFetcher, resolveTokenProgram, resolvePumpfunMarketContext, fetchPumpfunGlobalFeeRecipient, fetchPumpfunBondingCurveCreator, fetchPumpfunBuybackFeeRecipients, } from "./fetch.js";
20
21
  export { buildPumpfunRemainingAccounts, } from "./venues/pumpfun.js";
package/dist/swap.js CHANGED
@@ -1,7 +1,14 @@
1
1
  import * as web3 from "@solana/web3.js";
2
- // Anchor ships CJS-only; a default import + destructure works everywhere
3
- // (bundlers and raw Node ESM), named imports do not.
4
- import anchor from "@coral-xyz/anchor";
2
+ // Anchor ships BOTH a CJS build (Node resolves it via `require`, exposing
3
+ // everything as the interop `default`; its named exports are NOT statically
4
+ // detectable through Anchor's deep `export *` chain, so named imports fail in
5
+ // Node ESM) AND ESM/browser builds (bundlers like Turbopack/webpack resolve
6
+ // these — they have named exports and NO `default`). Import the namespace and
7
+ // prefer the CJS `default` when present, else fall back to the ESM namespace,
8
+ // so this resolves in Node ESM, webpack, and Turbopack alike.
9
+ import * as anchorNamespace from "@coral-xyz/anchor";
10
+ const anchor = (anchorNamespace
11
+ .default ?? anchorNamespace);
5
12
  const { BN, BorshInstructionCoder } = anchor;
6
13
  import { ASSOCIATED_TOKEN_PROGRAM_ID, FEE_MINT_ALLOWLIST, INSTRUCTIONS_SYSVAR_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, WSOL_MINT, } from "./constants.js";
7
14
  import { TENANT_WRAPPER_IDL } from "./idl/tenantWrapper.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0block.io/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Client-side transaction builder for the 0Block DEX router. Builds unsigned v0 swap transactions entirely offline \u2014 tenant-wrapped or direct \u2014 with shared address lookup tables, gateway tips, and on-chain fee-event decoding for accounting.",
5
5
  "keywords": [
6
6
  "solana",