Skip to content

Commit

Permalink
feat: one listener for amms/prices/twaps/orders
Browse files Browse the repository at this point in the history
  • Loading branch information
calmdentist committed Nov 19, 2024
1 parent 9f6f833 commit 9df1048
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
24 changes: 22 additions & 2 deletions packages/indexer/src/v3_indexer/builders/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ export class SwapBuilder {
// }

return Ok(new SwapPersistable(swapOrder, swapTake, transactionRecord)); // priceRecord
} else {
// handle non-swap transactions (add/remove liquidity, crank, etc)
// find market account from instructions
console.log("builder::buildOrderFromSwapIx::looking for market account in non swap txn");
let marketAcct: PublicKey | undefined;
for (const ix of tx.instructions) {
const candidate = ix.accountsWithData.find((a) => a.name === "amm");
if (candidate) {
marketAcct = new PublicKey(candidate.pubkey);
break;
}
}
if (marketAcct) {
console.log("builder::buildOrderFromSwapIx::market found for non swap txn, indexing price and twap", marketAcct);
this.indexPriceAndTWAPForAccount(marketAcct);
}
}
return Err({ type: SwapPersistableError.NonSwapTransaction });
} catch (e: any) {
Expand Down Expand Up @@ -283,8 +299,12 @@ export class SwapBuilder {

const marketAcct = swapIx.accountsWithData.find((a) => a.name === "amm");
if (!marketAcct) return Err({ type: "missing data" });
// const marketAcctPubKey = new PublicKey(marketAcct.pubkey);
// this.indexPriceAndTWAPForAccount(marketAcctPubKey);

//get market account and index price and twap async
console.log("builder::buildOrderFromSwapIx::indexing price and twap for market", marketAcct.pubkey);
const marketAcctPubKey = new PublicKey(marketAcct.pubkey);
this.indexPriceAndTWAPForAccount(marketAcctPubKey);

const userAcct = swapIx.accountsWithData.find((a) => a.name === "user");
if (!userAcct) return Err({ type: "missing data" });
const userAcctPubKey = new PublicKey(userAcct.pubkey);
Expand Down
13 changes: 7 additions & 6 deletions packages/indexer/src/v3_indexer/cli/txw/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ async function populateAmmMarketIndexerAccountDependencies() {
)) ?? [];

for (const ammMarket of ammMarkets) {
const newAmmIndexerDep: IndexerAccountDependency = {
acct: ammMarket.marketAcct.toString(),
name: "amm-market-accounts",
latestTxSigProcessed: null,
};
// TODO: we no longer need an account info indexer market accounts.. leaving this here for now
// const newAmmIndexerDep: IndexerAccountDependency = {
// acct: ammMarket.marketAcct.toString(),
// name: "amm-market-accounts",
// latestTxSigProcessed: null,
// };
const newAmmIntervalIndexerDep: IndexerAccountDependency = {
acct: ammMarket.marketAcct.toString(),
name: "amm-market-accounts-fetch",
Expand All @@ -111,7 +112,7 @@ async function populateAmmMarketIndexerAccountDependencies() {
db
.insert(schema.indexerAccountDependencies)
.values([
newAmmIndexerDep,
// newAmmIndexerDep, //TODO: leaving this here for now
newAmmIntervalIndexerDep,
newAmmLogsSubscribeIndexerDep,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ export async function startAccountInfoIndexer(
}
}

connection.onAccountChange(accountPubKey, async (accountInfo, context) => {
const res = await implementation.index(
accountInfo,
accountPubKey,
context
);
if (!res.success) {
logger.error("error indexing account update", accountPubKey.toString());
}
});
// // TODO: re-enable this or delete this whole thing if not needed
// connection.onAccountChange(accountPubKey, async (accountInfo, context) => {
// const res = await implementation.index(
// accountInfo,
// accountPubKey,
// context
// );
// if (!res.success) {
// logger.error("error indexing account update", accountPubKey.toString());
// }
// });
}
}
function getAccountInfoIndexerImplementation(
Expand Down

0 comments on commit 9df1048

Please sign in to comment.