Skip to content

Commit

Permalink
reinstate pyth pull logic
Browse files Browse the repository at this point in the history
  • Loading branch information
0xodia committed Aug 11, 2024
1 parent 4621d1b commit a1cb3d9
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions solend-sdk/src/core/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,11 +1159,6 @@ export class SolendActionCore {
(oracleKey) => new PullFeed(sbod as any, oracleKey)
);

const updateFeeds = await Promise.all(
feedAccounts.map((feedAccount) => feedAccount.loadData())
);

if (updateFeeds.length) {
const crossbar = new CrossbarClient(
"https://crossbar.switchboard.xyz/"
);
Expand Down Expand Up @@ -1204,7 +1199,6 @@ export class SolendActionCore {
const vtx = new VersionedTransaction(message);

this.pullPriceTxns.push(vtx);
}

const pythPulledOracles = oracleAccounts.filter(
(o) =>
Expand All @@ -1214,20 +1208,27 @@ export class SolendActionCore {
const shuffledPriceIds = (
pythPulledOracles
.map((pythOracleData, index) => {
if (!pythOracleData) {
throw new Error(`Could not find oracle data at index ${index}`);
}
const priceUpdate =
pythSolanaReceiver.receiver.account.priceUpdateV2.coder.accounts.decode(
"priceUpdateV2",
pythOracleData.data
);

return {
key: Math.random(),
priceFeedId: toHexString(priceUpdate.priceMessage.feedId),
};
})
if (!pythOracleData) {
throw new Error(`Could not find oracle data at index ${index}`);
}
const priceUpdate =
pythSolanaReceiver.receiver.account.priceUpdateV2.coder.accounts.decode(
"priceUpdateV2",
pythOracleData.data
);

const needUpdate =
Date.now() / 1000 -
Number(priceUpdate.priceMessage.publishTime.toString()) >
30;

return needUpdate
? {
key: Math.random(),
priceFeedId: toHexString(priceUpdate.priceMessage.feedId),
}
: undefined;
})
.filter(Boolean) as Array<{
key: number;
priceFeedId: string;
Expand Down

0 comments on commit a1cb3d9

Please sign in to comment.