@0dotxyz/p0-ts-sdk 1.2.3 → 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 +52 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -12
- package/dist/index.js.map +1 -1
- package/package.json +24 -26
package/dist/index.js
CHANGED
|
@@ -44829,6 +44829,54 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
|
|
|
44829
44829
|
return { instructions: [], luts: [] };
|
|
44830
44830
|
}
|
|
44831
44831
|
}
|
|
44832
|
+
function patchSwbFeedHashMismatch(pullIx, expectedFeedPubkeys) {
|
|
44833
|
+
const DEFAULT_KEY = PublicKey.default.toBase58();
|
|
44834
|
+
const expectedSet = new Set(expectedFeedPubkeys.map((pk) => pk.toBase58()));
|
|
44835
|
+
const numExpectedFeeds = expectedFeedPubkeys.length;
|
|
44836
|
+
for (const ix of pullIx) {
|
|
44837
|
+
let feedSectionStart = -1;
|
|
44838
|
+
for (let i = 0; i < ix.keys.length; i++) {
|
|
44839
|
+
if (expectedSet.has(ix.keys[i].pubkey.toBase58())) {
|
|
44840
|
+
feedSectionStart = i;
|
|
44841
|
+
break;
|
|
44842
|
+
}
|
|
44843
|
+
}
|
|
44844
|
+
if (feedSectionStart === -1) {
|
|
44845
|
+
for (let i = 0; i < ix.keys.length; i++) {
|
|
44846
|
+
if (ix.keys[i].pubkey.toBase58() === DEFAULT_KEY && ix.keys[i].isWritable) {
|
|
44847
|
+
feedSectionStart = i;
|
|
44848
|
+
break;
|
|
44849
|
+
}
|
|
44850
|
+
}
|
|
44851
|
+
}
|
|
44852
|
+
if (feedSectionStart === -1) continue;
|
|
44853
|
+
const feedSectionEnd = Math.min(feedSectionStart + numExpectedFeeds, ix.keys.length);
|
|
44854
|
+
const presentFeeds = /* @__PURE__ */ new Set();
|
|
44855
|
+
for (let i = feedSectionStart; i < feedSectionEnd; i++) {
|
|
44856
|
+
const key = ix.keys[i].pubkey.toBase58();
|
|
44857
|
+
if (expectedSet.has(key)) {
|
|
44858
|
+
presentFeeds.add(key);
|
|
44859
|
+
}
|
|
44860
|
+
}
|
|
44861
|
+
const missingFeeds = expectedFeedPubkeys.filter((pk) => !presentFeeds.has(pk.toBase58()));
|
|
44862
|
+
if (missingFeeds.length === 0) continue;
|
|
44863
|
+
let missingIdx = 0;
|
|
44864
|
+
for (let i = feedSectionStart; i < feedSectionEnd; i++) {
|
|
44865
|
+
if (ix.keys[i].pubkey.toBase58() === DEFAULT_KEY && missingIdx < missingFeeds.length) {
|
|
44866
|
+
console.log(
|
|
44867
|
+
`[patchSwbFeedHashMismatch] ix.keys[${i}]: replacing PublicKey.default \u2192 ${missingFeeds[missingIdx].toBase58()}`
|
|
44868
|
+
);
|
|
44869
|
+
ix.keys[i].pubkey = missingFeeds[missingIdx];
|
|
44870
|
+
missingIdx++;
|
|
44871
|
+
}
|
|
44872
|
+
}
|
|
44873
|
+
if (missingIdx > 0) {
|
|
44874
|
+
console.log(
|
|
44875
|
+
`[patchSwbFeedHashMismatch] Patched ${missingIdx}/${numExpectedFeeds} feed key(s)`
|
|
44876
|
+
);
|
|
44877
|
+
}
|
|
44878
|
+
}
|
|
44879
|
+
}
|
|
44832
44880
|
async function makeUpdateSwbFeedIx(props) {
|
|
44833
44881
|
console.log(
|
|
44834
44882
|
`[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
|
|
@@ -44843,11 +44891,6 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
44843
44891
|
console.log(
|
|
44844
44892
|
`[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
|
|
44845
44893
|
);
|
|
44846
|
-
uniqueOracles.forEach(
|
|
44847
|
-
(o) => console.log(
|
|
44848
|
-
`[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
|
|
44849
|
-
)
|
|
44850
|
-
);
|
|
44851
44894
|
const dummyWallet = {
|
|
44852
44895
|
publicKey: props.feePayer,
|
|
44853
44896
|
signTransaction: async (tx) => tx,
|
|
@@ -44869,23 +44912,20 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
44869
44912
|
return pullFeed;
|
|
44870
44913
|
});
|
|
44871
44914
|
if (pullFeedInstances.length === 0) {
|
|
44872
|
-
console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
|
|
44873
44915
|
return { instructions: [], luts: [] };
|
|
44874
44916
|
}
|
|
44875
44917
|
const crossbarClient = new CrossbarClient(
|
|
44876
44918
|
process.env.NEXT_PUBLIC_SWITCHBOARD_CROSSSBAR_API || "https://integrator-crossbar.prod.mrgn.app"
|
|
44877
44919
|
);
|
|
44878
|
-
console.log(`[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds`);
|
|
44879
|
-
console.log(
|
|
44880
|
-
`[makeUpdateSwbFeedIx] pullFeedInstances:`,
|
|
44881
|
-
pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasConfigs: !!f.configs }))
|
|
44882
|
-
);
|
|
44883
44920
|
const [pullIx, luts] = await PullFeed.fetchUpdateManyIx(swbProgram, {
|
|
44884
44921
|
feeds: pullFeedInstances,
|
|
44885
44922
|
numSignatures: 1,
|
|
44886
|
-
crossbarClient
|
|
44923
|
+
crossbarClient,
|
|
44924
|
+
payer: props.feePayer
|
|
44887
44925
|
});
|
|
44888
44926
|
console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
|
|
44927
|
+
const expectedFeedPubkeys = pullFeedInstances.map((f) => f.pubkey);
|
|
44928
|
+
patchSwbFeedHashMismatch(pullIx, expectedFeedPubkeys);
|
|
44889
44929
|
return { instructions: pullIx, luts };
|
|
44890
44930
|
}
|
|
44891
44931
|
|