From a1cb3d95c4e5aa4bebb09d6f4d32a5c655fee7d2 Mon Sep 17 00:00:00 2001 From: 0xodia <0xodia@solend.fi> Date: Sun, 11 Aug 2024 18:23:40 -0400 Subject: [PATCH] reinstate pyth pull logic --- solend-sdk/src/core/actions.ts | 41 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/solend-sdk/src/core/actions.ts b/solend-sdk/src/core/actions.ts index f12269fd..38603561 100644 --- a/solend-sdk/src/core/actions.ts +++ b/solend-sdk/src/core/actions.ts @@ -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/" ); @@ -1204,7 +1199,6 @@ export class SolendActionCore { const vtx = new VersionedTransaction(message); this.pullPriceTxns.push(vtx); - } const pythPulledOracles = oracleAccounts.filter( (o) => @@ -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;