@0dotxyz/p0-ts-sdk 1.2.1 → 1.2.3
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 +32 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -44780,7 +44780,9 @@ async function computeSmartCrank({
|
|
|
44780
44780
|
};
|
|
44781
44781
|
}
|
|
44782
44782
|
async function makeSmartCrankSwbFeedIx(params) {
|
|
44783
|
+
console.log("[makeSmartCrankSwbFeedIx] Called");
|
|
44783
44784
|
const crankResult = await computeSmartCrank(params);
|
|
44785
|
+
console.log("[makeSmartCrankSwbFeedIx] Crank result:", crankResult);
|
|
44784
44786
|
if (crankResult.uncrankableLiabilities.length > 0) {
|
|
44785
44787
|
console.log(
|
|
44786
44788
|
"Uncrankable liability details:",
|
|
@@ -44816,6 +44818,7 @@ async function makeSmartCrankSwbFeedIx(params) {
|
|
|
44816
44818
|
);
|
|
44817
44819
|
}
|
|
44818
44820
|
const oraclesToCrank = crankResult.requiredOracles;
|
|
44821
|
+
console.log("[makeSmartCrankSwbFeedIx] Oracles to crank:", oraclesToCrank);
|
|
44819
44822
|
const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
|
|
44820
44823
|
swbPullOracles: oraclesToCrank,
|
|
44821
44824
|
feePayer: params.marginfiAccount.authority,
|
|
@@ -44852,6 +44855,9 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
|
|
|
44852
44855
|
}
|
|
44853
44856
|
}
|
|
44854
44857
|
async function makeUpdateSwbFeedIx(props) {
|
|
44858
|
+
console.log(
|
|
44859
|
+
`[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
|
|
44860
|
+
);
|
|
44855
44861
|
const seen = /* @__PURE__ */ new Set();
|
|
44856
44862
|
const uniqueOracles = props.swbPullOracles.filter((oracle) => {
|
|
44857
44863
|
const key = oracle.key.toBase58();
|
|
@@ -44859,42 +44865,52 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
44859
44865
|
seen.add(key);
|
|
44860
44866
|
return true;
|
|
44861
44867
|
});
|
|
44862
|
-
|
|
44868
|
+
console.log(
|
|
44869
|
+
`[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
|
|
44870
|
+
);
|
|
44871
|
+
uniqueOracles.forEach(
|
|
44872
|
+
(o) => console.log(
|
|
44873
|
+
`[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
|
|
44874
|
+
)
|
|
44875
|
+
);
|
|
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);
|
|
44863
44882
|
const pullFeedInstances = uniqueOracles.map((oracle) => {
|
|
44864
44883
|
const pullFeed = new onDemand.PullFeed(swbProgram, oracle.key);
|
|
44865
44884
|
if (oracle.price?.switchboardData) {
|
|
44866
44885
|
const swbData = oracle.price?.switchboardData;
|
|
44867
|
-
pullFeed.
|
|
44886
|
+
pullFeed.configs = {
|
|
44868
44887
|
queue: new web3_js.PublicKey(swbData.queue),
|
|
44869
|
-
feedHash:
|
|
44870
|
-
maxVariance:
|
|
44871
|
-
minResponses: swbData.minResponses
|
|
44888
|
+
feedHash: Buffer.from(swbData.feedHash, "hex"),
|
|
44889
|
+
maxVariance: Number(swbData.maxVariance),
|
|
44890
|
+
minResponses: swbData.minResponses,
|
|
44891
|
+
minSampleSize: swbData.minResponses
|
|
44872
44892
|
};
|
|
44873
44893
|
}
|
|
44874
44894
|
return pullFeed;
|
|
44875
44895
|
});
|
|
44876
44896
|
if (pullFeedInstances.length === 0) {
|
|
44897
|
+
console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
|
|
44877
44898
|
return { instructions: [], luts: [] };
|
|
44878
44899
|
}
|
|
44879
44900
|
const crossbarClient = new common.CrossbarClient(
|
|
44880
44901
|
process.env.NEXT_PUBLIC_SWITCHBOARD_CROSSSBAR_API || "https://integrator-crossbar.prod.mrgn.app"
|
|
44881
44902
|
);
|
|
44882
|
-
|
|
44883
|
-
|
|
44884
|
-
|
|
44885
|
-
|
|
44886
|
-
|
|
44887
|
-
if (!gatewayUrl) {
|
|
44888
|
-
throw new Error(`Invalid gateway URL received formainnet`);
|
|
44889
|
-
}
|
|
44890
|
-
const gateway = new onDemand.Gateway(swbProgram, gatewayUrl);
|
|
44903
|
+
console.log(`[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds`);
|
|
44904
|
+
console.log(
|
|
44905
|
+
`[makeUpdateSwbFeedIx] pullFeedInstances:`,
|
|
44906
|
+
pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasConfigs: !!f.configs }))
|
|
44907
|
+
);
|
|
44891
44908
|
const [pullIx, luts] = await onDemand.PullFeed.fetchUpdateManyIx(swbProgram, {
|
|
44892
44909
|
feeds: pullFeedInstances,
|
|
44893
|
-
gateway: gateway.gatewayUrl,
|
|
44894
44910
|
numSignatures: 1,
|
|
44895
|
-
payer: props.feePayer,
|
|
44896
44911
|
crossbarClient
|
|
44897
44912
|
});
|
|
44913
|
+
console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
|
|
44898
44914
|
return { instructions: pullIx, luts };
|
|
44899
44915
|
}
|
|
44900
44916
|
|