@cypher-zk/sdk 0.7.3 → 0.7.4

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.
package/dist/index.js CHANGED
@@ -2440,6 +2440,31 @@ var lpPositionFilters = {
2440
2440
  };
2441
2441
 
2442
2442
  // src/accounts/market.ts
2443
+ var MIN_DECODE_BYTES = 8 + 580;
2444
+ function decodeMarketAccount(client, data) {
2445
+ const coder = client.program.coder.accounts;
2446
+ let buf = Buffer.from(data);
2447
+ if (buf.length < MIN_DECODE_BYTES) {
2448
+ const padded = Buffer.alloc(MIN_DECODE_BYTES);
2449
+ buf.copy(padded);
2450
+ buf = padded;
2451
+ }
2452
+ return coder.decode("market", buf);
2453
+ }
2454
+ async function gpaFetchMarkets(client, extraFilters = []) {
2455
+ const rawAccounts = await client.connection.getProgramAccounts(client.programId, {
2456
+ filters: [marketFilters.discriminator(), ...extraFilters]
2457
+ });
2458
+ const results = [];
2459
+ for (const { pubkey, account } of rawAccounts) {
2460
+ try {
2461
+ const raw = decodeMarketAccount(client, account.data);
2462
+ results.push({ publicKey: pubkey, account: decode2(raw) });
2463
+ } catch {
2464
+ }
2465
+ }
2466
+ return results;
2467
+ }
2443
2468
  function decode2(raw) {
2444
2469
  const questionLen = raw.questionLen;
2445
2470
  const question = Buffer.from(raw.question.slice(0, questionLen)).toString("utf8");
@@ -2486,25 +2511,24 @@ function decode2(raw) {
2486
2511
  vaultBump: raw.vaultBump
2487
2512
  };
2488
2513
  }
2489
- function marketAccountFacade(client) {
2490
- return client.program.account.market;
2491
- }
2492
2514
  async function fetchMarket(client, idOrPda) {
2493
2515
  const pda = idOrPda instanceof PublicKey ? idOrPda : marketPda(idOrPda, client.programId)[0];
2494
- const raw = await marketAccountFacade(client).fetchNullable(pda);
2495
- return raw ? decode2(raw) : null;
2516
+ const accountInfo = await client.connection.getAccountInfo(pda);
2517
+ if (!accountInfo) return null;
2518
+ try {
2519
+ return decode2(decodeMarketAccount(client, accountInfo.data));
2520
+ } catch {
2521
+ return null;
2522
+ }
2496
2523
  }
2497
2524
  async function fetchAllMarkets(client) {
2498
- const raw = await marketAccountFacade(client).all();
2499
- return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
2525
+ return gpaFetchMarkets(client);
2500
2526
  }
2501
2527
  async function fetchMarketsByCreator(client, creator) {
2502
- const raw = await marketAccountFacade(client).all([marketFilters.byCreator(creator)]);
2503
- return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
2528
+ return gpaFetchMarkets(client, [marketFilters.byCreator(creator)]);
2504
2529
  }
2505
2530
  async function fetchMarketsByState(client, state) {
2506
- const raw = await marketAccountFacade(client).all([marketFilters.byState(state)]);
2507
- return raw.map(({ publicKey, account }) => ({ publicKey, account: decode2(account) }));
2531
+ return gpaFetchMarkets(client, [marketFilters.byState(state)]);
2508
2532
  }
2509
2533
  function decode3(raw) {
2510
2534
  return {