@0dotxyz/p0-ts-sdk 1.2.2 → 1.2.4-alpha.0

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.cjs CHANGED
@@ -44873,16 +44873,22 @@ async function makeUpdateSwbFeedIx(props) {
44873
44873
  `[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
44874
44874
  )
44875
44875
  );
44876
- const swbProgram = await onDemand.AnchorUtils.loadProgramFromConnection(props.connection);
44876
+ const dummyWallet = {
44877
+ publicKey: props.feePayer,
44878
+ signTransaction: async (tx) => tx,
44879
+ signAllTransactions: async (txs) => txs
44880
+ };
44881
+ const swbProgram = await onDemand.AnchorUtils.loadProgramFromConnection(props.connection, dummyWallet);
44877
44882
  const pullFeedInstances = uniqueOracles.map((oracle) => {
44878
44883
  const pullFeed = new onDemand.PullFeed(swbProgram, oracle.key);
44879
44884
  if (oracle.price?.switchboardData) {
44880
44885
  const swbData = oracle.price?.switchboardData;
44881
- pullFeed.data = {
44886
+ pullFeed.configs = {
44882
44887
  queue: new web3_js.PublicKey(swbData.queue),
44883
- feedHash: new Uint8Array(Buffer.from(swbData.feedHash, "hex")),
44884
- maxVariance: new BN11.BN(swbData.maxVariance),
44885
- minResponses: swbData.minResponses
44888
+ feedHash: Buffer.from(swbData.feedHash, "hex"),
44889
+ maxVariance: Number(swbData.maxVariance),
44890
+ minResponses: swbData.minResponses,
44891
+ minSampleSize: swbData.minResponses
44886
44892
  };
44887
44893
  }
44888
44894
  return pullFeed;
@@ -44894,31 +44900,47 @@ async function makeUpdateSwbFeedIx(props) {
44894
44900
  const crossbarClient = new common.CrossbarClient(
44895
44901
  process.env.NEXT_PUBLIC_SWITCHBOARD_CROSSSBAR_API || "https://integrator-crossbar.prod.mrgn.app"
44896
44902
  );
44897
- const gatewayUrls = await crossbarClient.fetchGateways("mainnet");
44898
- if (!gatewayUrls || gatewayUrls.length === 0) {
44899
- throw new Error(`No gateways available for mainnet`);
44900
- }
44901
- console.log(`[makeUpdateSwbFeedIx] Fetched ${gatewayUrls.length} gateways`);
44902
- const gatewayUrl = gatewayUrls[0];
44903
- if (!gatewayUrl) {
44904
- throw new Error(`Invalid gateway URL received formainnet`);
44903
+ const onChainDatas = await onDemand.PullFeed.loadMany(swbProgram, pullFeedInstances);
44904
+ for (let i = 0; i < pullFeedInstances.length; i++) {
44905
+ const feed = pullFeedInstances[i];
44906
+ const onChainData = onChainDatas[i];
44907
+ const configHash = feed.configs?.feedHash ? Buffer.from(feed.configs.feedHash).toString("hex") : "none";
44908
+ const onChainHash = onChainData?.feedHash ? Buffer.from(onChainData.feedHash).toString("hex") : "none";
44909
+ console.log(
44910
+ `[makeUpdateSwbFeedIx] Feed ${feed.pubkey.toBase58()} | configs.feedHash: ${configHash} | onChain.feedHash: ${onChainHash} | loaded: ${!!onChainData}`
44911
+ );
44905
44912
  }
44906
- const gateway = new onDemand.Gateway(swbProgram, gatewayUrl);
44907
- console.log(
44908
- `[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds via gateway: ${gateway.gatewayUrl}`
44909
- );
44913
+ console.log(`[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds`);
44910
44914
  console.log(
44911
44915
  `[makeUpdateSwbFeedIx] pullFeedInstances:`,
44912
- pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasData: !!f.data }))
44916
+ pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasConfigs: !!f.configs }))
44913
44917
  );
44914
44918
  const [pullIx, luts] = await onDemand.PullFeed.fetchUpdateManyIx(swbProgram, {
44915
44919
  feeds: pullFeedInstances,
44916
- gateway: gateway.gatewayUrl,
44917
44920
  numSignatures: 1,
44918
- payer: props.feePayer,
44919
- crossbarClient
44921
+ crossbarClient,
44922
+ payer: props.feePayer
44920
44923
  });
44921
44924
  console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
44925
+ const feedPubkeySet = new Set(pullFeedInstances.map((f) => f.pubkey.toBase58()));
44926
+ if (pullIx.length >= 2) {
44927
+ const submitIx = pullIx[1];
44928
+ const defaultKey = web3_js.PublicKey.default.toBase58();
44929
+ const presentFeedKeys = new Set(
44930
+ submitIx.keys.filter((k) => feedPubkeySet.has(k.pubkey.toBase58())).map((k) => k.pubkey.toBase58())
44931
+ );
44932
+ const missingFeedKeys = pullFeedInstances.map((f) => f.pubkey).filter((pk) => !presentFeedKeys.has(pk.toBase58()));
44933
+ let missingIdx = 0;
44934
+ for (const key of submitIx.keys) {
44935
+ if (key.pubkey.toBase58() === defaultKey && missingIdx < missingFeedKeys.length) {
44936
+ console.log(
44937
+ `[makeUpdateSwbFeedIx] Replacing PublicKey.default with ${missingFeedKeys[missingIdx].toBase58()}`
44938
+ );
44939
+ key.pubkey = missingFeedKeys[missingIdx];
44940
+ missingIdx++;
44941
+ }
44942
+ }
44943
+ }
44922
44944
  return { instructions: pullIx, luts };
44923
44945
  }
44924
44946