Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add predictionV3 AI subgraph #264

Open
wants to merge 5 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions subgraphs/prediction/v3-ai-generic/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function handleStartRound(event: StartRound): void {
if (round === null) {
round = new Round(event.params.epoch.toString());
round.epoch = event.params.epoch;
round.AIPrice = event.params.AIPrice.divDecimal(EIGHT_BD);
round.previous = event.params.epoch.equals(ZERO_BI) ? null : event.params.epoch.minus(ONE_BI).toString();
round.startAt = event.block.timestamp;
round.startBlock = event.block.number;
Expand Down Expand Up @@ -202,9 +203,12 @@ export function handleEndRound(event: EndRound): void {
}
// round.closeRoundId = event.params.roundId; // Not evicted in the new version of event

// Get round result based on lock/close price.
// Get round result based on lock, close and AI price.
if (round.closePrice) {
if (round.closePrice.equals(round.lockPrice as BigDecimal)) {
if (
round.closePrice.equals(round.lockPrice as BigDecimal) &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we do not have house win, only have two result, AI win or AI lose.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, understood. What would normally be a House win is now an AI Lose for us. Makes sense.

round.AIPrice?.notEqual(round.lockPrice as BigDecimal)
) {
round.position = "House";

let market = Market.load("1");
Expand All @@ -217,12 +221,16 @@ export function handleEndRound(event: EndRound): void {
market.netAmount = market.netAmount.plus(round.totalAmount);
market.save();
}
} else if (round.closePrice.gt(round.lockPrice as BigDecimal)) {
} else if (
(round.closePrice.gt(round.lockPrice as BigDecimal) && round.AIPrice?.gt(round.lockPrice as BigDecimal)) ||
(round.closePrice.lt(round.lockPrice as BigDecimal) && round.AIPrice?.lt(round.lockPrice as BigDecimal)) ||
(round.closePrice.equals(round.lockPrice as BigDecimal) && round.AIPrice?.equals(round.lockPrice as BigDecimal))
) {
// AI win => Follow AI pool wins
round.position = "Bull";
} else if (round.closePrice.lt(round.lockPrice as BigDecimal)) {
round.position = "Bear";
} else {
round.position = null;
// AI lose => Against AI pool wins
round.position = "Bear";
}

round.failed = false;
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/prediction/v3-ai-generic/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Round @entity {
bearBets: BigInt!
bearAmount: BigDecimal!
bets: [Bet!]! @derivedFrom(field: "round")

# AI Predictions
AIPrice: BigDecimal
}

type User @entity {
Expand Down
Loading