@0dotxyz/p0-ts-sdk 1.2.4-alpha.0 → 1.2.4-alpha.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.
package/dist/index.cjs CHANGED
@@ -44854,6 +44854,54 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
44854
44854
  return { instructions: [], luts: [] };
44855
44855
  }
44856
44856
  }
44857
+ function patchSwbFeedHashMismatch(pullIx, expectedFeedPubkeys) {
44858
+ const DEFAULT_KEY = web3_js.PublicKey.default.toBase58();
44859
+ const expectedSet = new Set(expectedFeedPubkeys.map((pk) => pk.toBase58()));
44860
+ const numExpectedFeeds = expectedFeedPubkeys.length;
44861
+ for (const ix of pullIx) {
44862
+ let feedSectionStart = -1;
44863
+ for (let i = 0; i < ix.keys.length; i++) {
44864
+ if (expectedSet.has(ix.keys[i].pubkey.toBase58())) {
44865
+ feedSectionStart = i;
44866
+ break;
44867
+ }
44868
+ }
44869
+ if (feedSectionStart === -1) {
44870
+ for (let i = 0; i < ix.keys.length; i++) {
44871
+ if (ix.keys[i].pubkey.toBase58() === DEFAULT_KEY && ix.keys[i].isWritable) {
44872
+ feedSectionStart = i;
44873
+ break;
44874
+ }
44875
+ }
44876
+ }
44877
+ if (feedSectionStart === -1) continue;
44878
+ const feedSectionEnd = Math.min(feedSectionStart + numExpectedFeeds, ix.keys.length);
44879
+ const presentFeeds = /* @__PURE__ */ new Set();
44880
+ for (let i = feedSectionStart; i < feedSectionEnd; i++) {
44881
+ const key = ix.keys[i].pubkey.toBase58();
44882
+ if (expectedSet.has(key)) {
44883
+ presentFeeds.add(key);
44884
+ }
44885
+ }
44886
+ const missingFeeds = expectedFeedPubkeys.filter((pk) => !presentFeeds.has(pk.toBase58()));
44887
+ if (missingFeeds.length === 0) continue;
44888
+ let missingIdx = 0;
44889
+ for (let i = feedSectionStart; i < feedSectionEnd; i++) {
44890
+ if (ix.keys[i].pubkey.toBase58() === DEFAULT_KEY && missingIdx < missingFeeds.length) {
44891
+ console.log(
44892
+ `[patchSwbFeedHashMismatch] ix.keys[${i}]: replacing PublicKey.default \u2192 ${missingFeeds[missingIdx].toBase58()}`
44893
+ );
44894
+ ix.keys[i].pubkey = missingFeeds[missingIdx];
44895
+ missingIdx++;
44896
+ }
44897
+ }
44898
+ if (missingIdx > 0) {
44899
+ console.log(
44900
+ `[patchSwbFeedHashMismatch] Patched ${missingIdx}/${numExpectedFeeds} feed key(s)`
44901
+ );
44902
+ }
44903
+ }
44904
+ }
44857
44905
  async function makeUpdateSwbFeedIx(props) {
44858
44906
  console.log(
44859
44907
  `[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
@@ -44868,11 +44916,6 @@ async function makeUpdateSwbFeedIx(props) {
44868
44916
  console.log(
44869
44917
  `[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
44870
44918
  );
44871
- uniqueOracles.forEach(
44872
- (o) => console.log(
44873
- `[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
44874
- )
44875
- );
44876
44919
  const dummyWallet = {
44877
44920
  publicKey: props.feePayer,
44878
44921
  signTransaction: async (tx) => tx,
@@ -44894,27 +44937,11 @@ async function makeUpdateSwbFeedIx(props) {
44894
44937
  return pullFeed;
44895
44938
  });
44896
44939
  if (pullFeedInstances.length === 0) {
44897
- console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
44898
44940
  return { instructions: [], luts: [] };
44899
44941
  }
44900
44942
  const crossbarClient = new common.CrossbarClient(
44901
44943
  process.env.NEXT_PUBLIC_SWITCHBOARD_CROSSSBAR_API || "https://integrator-crossbar.prod.mrgn.app"
44902
44944
  );
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
- );
44912
- }
44913
- console.log(`[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds`);
44914
- console.log(
44915
- `[makeUpdateSwbFeedIx] pullFeedInstances:`,
44916
- pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasConfigs: !!f.configs }))
44917
- );
44918
44945
  const [pullIx, luts] = await onDemand.PullFeed.fetchUpdateManyIx(swbProgram, {
44919
44946
  feeds: pullFeedInstances,
44920
44947
  numSignatures: 1,
@@ -44922,25 +44949,8 @@ async function makeUpdateSwbFeedIx(props) {
44922
44949
  payer: props.feePayer
44923
44950
  });
44924
44951
  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
- }
44952
+ const expectedFeedPubkeys = pullFeedInstances.map((f) => f.pubkey);
44953
+ patchSwbFeedHashMismatch(pullIx, expectedFeedPubkeys);
44944
44954
  return { instructions: pullIx, luts };
44945
44955
  }
44946
44956