Skip to content

Commit

Permalink
feat: adds in new order for proposal grabbing
Browse files Browse the repository at this point in the history
  • Loading branch information
R-K-H committed Dec 15, 2024
1 parent 6902c3e commit 20d95e6
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
twapMaxObservationChangePerUpdate:
dbDao.twapMaxObservationChangePerUpdate ?? null,
};
// NOTE: We insert the markets first so that we can update the proposal with the market accounts
await insertAssociatedAccountsDataForProposal(proposal, currentTime);

await usingDb((db) =>
db
Expand All @@ -217,7 +219,10 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
.onConflictDoNothing()
.execute()
);
await insertAssociatedAccountsDataForProposal(proposal, currentTime);

// NOTE: We update the markets with the proposal after the proposal is inserted
await updateMarketsWithProposal(proposal);

});

logger.log("inserted proposals");
Expand Down Expand Up @@ -391,7 +396,6 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {
await calculateUserPerformance(onChainProposal);
}

// check if markets are there, if they aren't insert them
// Check if markets are there, if they aren't, insert them
const passAmm = onChainProposal.account.passAmm;
const failAmm = onChainProposal.account.failAmm;
Expand Down Expand Up @@ -445,6 +449,27 @@ export const AutocratProposalIndexer: IntervalFetchIndexer = {

};

async function updateMarketsWithProposal(
proposal: ProposalAccountWithKey,
) {
if(!proposal.account.passAmm || !proposal.account.failAmm) return Err({ type: AutocratDaoIndexerError.MissingParamError });

await usingDb((db) =>
db
.update(schema.markets)
.set({
proposalAcct: proposal.publicKey.toString(),
})
.where(
or(
eq(schema.markets.marketAcct, passMarket.marketAcct),
eq(schema.markets.marketAcct, failMarket.marketAcct)
)
)
.execute()
);
}


async function insertAssociatedAccountsDataForProposal(
proposal: ProposalAccountWithKey,
Expand Down

0 comments on commit 20d95e6

Please sign in to comment.