@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 +43 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -23
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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
|
|
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.
|
|
44886
|
+
pullFeed.configs = {
|
|
44882
44887
|
queue: new web3_js.PublicKey(swbData.queue),
|
|
44883
|
-
feedHash:
|
|
44884
|
-
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
|
|
44898
|
-
|
|
44899
|
-
|
|
44900
|
-
|
|
44901
|
-
|
|
44902
|
-
|
|
44903
|
-
|
|
44904
|
-
|
|
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
|
-
|
|
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(),
|
|
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
|
-
|
|
44919
|
-
|
|
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
|
|