|
| 1 | +import { BigInt, Bytes } from "@graphprotocol/graph-ts"; |
| 2 | +import { Arbitrable, Court, Dispute, DisputeKit, Round } from "../../generated/schema"; |
| 3 | +import { ONE, ZERO } from "../utils"; |
| 4 | +import { updateCases, updateCasesRuled, updateCourtCumulativeMetric } from "../datapoint"; |
| 5 | + |
| 6 | +const ARCHIVE_STUB_DISPUTE_KIT_ID = "archive-stub-dispute-kit"; |
| 7 | +const ARCHIVE_STUB_ARBITRABLE_ID = "0x0000000000000000000000000000000000000000"; |
| 8 | + |
| 9 | +function ensureArchiveStubDisputeKit(): void { |
| 10 | + if (DisputeKit.load(ARCHIVE_STUB_DISPUTE_KIT_ID) != null) { |
| 11 | + return; |
| 12 | + } |
| 13 | + const disputeKit = new DisputeKit(ARCHIVE_STUB_DISPUTE_KIT_ID); |
| 14 | + disputeKit.address = null; |
| 15 | + disputeKit.needsFreezing = false; |
| 16 | + disputeKit.save(); |
| 17 | +} |
| 18 | + |
| 19 | +function ensureArchiveStubArbitrable(): void { |
| 20 | + if (Arbitrable.load(ARCHIVE_STUB_ARBITRABLE_ID) != null) { |
| 21 | + return; |
| 22 | + } |
| 23 | + const arbitrable = new Arbitrable(ARCHIVE_STUB_ARBITRABLE_ID); |
| 24 | + arbitrable.totalDisputes = ZERO; |
| 25 | + arbitrable.save(); |
| 26 | +} |
| 27 | + |
| 28 | +// creates placeholder entities |
| 29 | +export function ensureArchiveStubEntities(): void { |
| 30 | + ensureArchiveStubDisputeKit(); |
| 31 | + ensureArchiveStubArbitrable(); |
| 32 | +} |
| 33 | + |
| 34 | +export function createArchiveOnlyDispute( |
| 35 | + disputeId: BigInt, |
| 36 | + courtId: BigInt, |
| 37 | + cid: string, |
| 38 | + reason: string | null, |
| 39 | + blockTimestamp: BigInt, |
| 40 | + blockNumber: BigInt, |
| 41 | + transactionHash: Bytes |
| 42 | +): void { |
| 43 | + ensureArchiveStubEntities(); |
| 44 | + updateCases(ONE, blockTimestamp); |
| 45 | + updateCasesRuled(ONE, blockTimestamp); |
| 46 | + |
| 47 | + // placeholder for currentRound, actual data is fetched from ipfs |
| 48 | + const currentRoundId = disputeId.toString() + "-0"; |
| 49 | + const currentRound = Round.load(currentRoundId); |
| 50 | + |
| 51 | + if (!currentRound) { |
| 52 | + const round = new Round(currentRoundId); |
| 53 | + round.dispute = disputeId.toString(); |
| 54 | + round.court = courtId.toString(); |
| 55 | + round.disputeKit = ARCHIVE_STUB_DISPUTE_KIT_ID; |
| 56 | + round.tokensAtStakePerJuror = ZERO; |
| 57 | + round.totalFeesForJurors = ZERO; |
| 58 | + round.nbVotes = ZERO; |
| 59 | + round.isCurrentRound = true; |
| 60 | + round.repartitions = ZERO; |
| 61 | + round.penalties = ZERO; |
| 62 | + round.timeline = [ZERO, ZERO, ZERO, ZERO]; |
| 63 | + round.jurorsDrawn = false; |
| 64 | + round.jurorRewardsDispersed = false; |
| 65 | + round.timesPerPeriod = [ZERO, ZERO, ZERO, ZERO]; |
| 66 | + round.hiddenVotes = false; |
| 67 | + round.jurorsForCourtJump = ZERO; |
| 68 | + round.feeToken = null; |
| 69 | + round.save(); |
| 70 | + } |
| 71 | + |
| 72 | + const dispute = new Dispute(disputeId.toString()); |
| 73 | + dispute.disputeID = disputeId; |
| 74 | + dispute.court = courtId.toString(); |
| 75 | + dispute.createdAt = blockTimestamp; |
| 76 | + dispute.transactionHash = transactionHash.toHexString(); |
| 77 | + dispute.arbitrated = ARCHIVE_STUB_ARBITRABLE_ID; |
| 78 | + dispute.period = "execution"; |
| 79 | + dispute.ruled = true; |
| 80 | + dispute.executed = true; |
| 81 | + dispute.currentRuling = ZERO; |
| 82 | + dispute.tied = false; |
| 83 | + dispute.overridden = false; |
| 84 | + dispute.periodDeadline = blockTimestamp; |
| 85 | + dispute.periodNotificationIndex = ZERO; |
| 86 | + dispute.lastPeriodChange = blockTimestamp; |
| 87 | + dispute.lastPeriodChangeBlockNumber = blockNumber; |
| 88 | + dispute.currentRound = currentRoundId; |
| 89 | + dispute.currentRoundIndex = ZERO; |
| 90 | + dispute.evidenceCount = ZERO; |
| 91 | + dispute.isArchived = true; |
| 92 | + dispute.archiveCid = cid; |
| 93 | + dispute.save(); |
| 94 | + |
| 95 | + const court = Court.load(courtId.toString()); |
| 96 | + if (!court) return; |
| 97 | + court.numberDisputes = court.numberDisputes.plus(ONE); |
| 98 | + // archived dispute is closed already |
| 99 | + court.numberClosedDisputes = court.numberClosedDisputes.plus(ONE); |
| 100 | + updateCourtCumulativeMetric(courtId.toString(), ONE, blockTimestamp, "numberDisputes"); |
| 101 | +} |
0 commit comments