Skip to content

Commit

Permalink
Merge pull request #237 from metaDAOproject/fix/attempts
Browse files Browse the repository at this point in the history
fix: working on something
  • Loading branch information
LukasDeco authored Aug 17, 2024
2 parents 5fc5657 + 2c095a4 commit 931e0b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { startIndexerAccountDependencyPopulation } from "./cli/txw/populate";
import { startTransactionWatchers } from "./transaction/watcher";
import { startServer } from "./server";

// startServer();
// startIndexerAccountDependencyPopulation();
startServer();
startIndexerAccountDependencyPopulation();

// await startTransactionWatchers();
await startTransactionWatchers();
await startIndexers();
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ async function calculateUserPerformance(
.from(schema.prices)
.where(
and(
eq(schema.prices.marketAcct, base_tokens.mintAcct),
lte(schema.prices.createdAt, proposalFinalizedAt),
gt(schema.prices.createdAt, proposalFinalizedAtMinus2Minutes)
)
Expand All @@ -704,9 +705,10 @@ async function calculateUserPerformance(
};
}

const baseTokenDecimals = base_tokens?.decimals ?? -1;
const baseTokenDecimals = base_tokens?.decimals;
const quoteTokenDecimals = quote_tokens?.decimals ?? 6; // NOTE: Safe for now
if (!baseTokenDecimals && !quoteTokenDecimals) {

if (!baseTokenDecimals || !quoteTokenDecimals) {
return current;
}

Expand All @@ -717,7 +719,7 @@ async function calculateUserPerformance(
);

// Amount or notional
const amount = Number(next.quotePrice).valueOf() * size
const amount = Number(next.quotePrice).valueOf() * size;

if (next.side === "BID") {
totals.tokensBought = totals.tokensBought + size;
Expand Down Expand Up @@ -746,7 +748,9 @@ async function calculateUserPerformance(
// We need to complete the round trip / final leg
if (tradeSizeDelta !== 0) {
// TODO: This needs to be revised given the spot price can't be null or 0 if we want to really do this
const lastLegNotional = tradeSizeDelta * Number(spotPrice[0].price ?? "0");
const lastLegNotional =
tradeSizeDelta * Number(spotPrice[0]?.price ?? "0");

if (needsSellToExit) {
// We've bought more than we've sold, therefore when we exit the position calulcation
// we need to count the remaining volume as a sell at spot price when conditional
Expand Down

0 comments on commit 931e0b6

Please sign in to comment.