Skip to content

Commit

Permalink
feat: update reserves in market table
Browse files Browse the repository at this point in the history
  • Loading branch information
calmdentist committed Dec 4, 2024
1 parent 2685275 commit 840d1e9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/indexer/src/v3_indexer/indexers/amm/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,25 @@ export async function indexAmmMarketAccountWithContext(
return Err({ type: AmmMarketAccountIndexingErrors.AmmTwapPriceError });
}

try {
const marketReservesUpdateResult = await usingDb((db) =>
db
.update(schema.markets)
.set({
baseAmount: ammMarketAccount.baseAmount.toString(),
quoteAmount: ammMarketAccount.quoteAmount.toString(),
})
.where(eq(schema.markets.marketAcct, account.toBase58()))
.returning({ marketAcct: schema.markets.marketAcct })
);
if (marketReservesUpdateResult === undefined || marketReservesUpdateResult.length === 0) {
logger.error("failed to update market reserves", account.toBase58());
return Err({ type: AmmMarketAccountIndexingErrors.AmmTwapPriceError });
}
} catch (e) {
logger.error("error updating market reserves", e);
return Err({ type: AmmMarketAccountIndexingErrors.AmmTwapPriceError });
}

return Ok(`successfully indexed amm: ${account.toBase58()}`);
}

0 comments on commit 840d1e9

Please sign in to comment.