From 89ff699e59993639746ac3a673627472850b2323 Mon Sep 17 00:00:00 2001 From: rouzwelt Date: Fri, 11 Oct 2024 22:09:02 +0000 Subject: [PATCH] Revert "clear bounty entity" This reverts commit 4281354a7205280c29d571a948659759223c28a6. --- subgraph/schema.graphql | 20 -------- subgraph/src/clear.ts | 106 ++++++++++------------------------------ 2 files changed, 27 insertions(+), 99 deletions(-) diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 77327e115..25f14f7f0 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -123,26 +123,6 @@ type TradeVaultBalanceChange implements VaultBalanceChange @entity(immutable: tr transaction: Transaction! } -type ClearBounty implements VaultBalanceChange @entity(immutable: true) { - id: Bytes! - "The orderbook this balance change is for" - orderbook: Orderbook! - "The msg.sender of this clear call and owner of the vault" - sender: Bytes! - "The vault that was affected" - vault: Vault! - "The amount that was changed - this is signed" - amount: BigInt! - "The balance of the vault before the change" - oldVaultBalance: BigInt! - "The balance of the vault after the change" - newVaultBalance: BigInt! - "The timestamp this balance change was executed" - timestamp: BigInt! - "The transaction in which this balance change was executed" - transaction: Transaction! -} - type Order @entity { id: Bytes! "The orderbook this order is in" diff --git a/subgraph/src/clear.ts b/subgraph/src/clear.ts index e9e55681f..5dd156114 100644 --- a/subgraph/src/clear.ts +++ b/subgraph/src/clear.ts @@ -1,6 +1,5 @@ import { AfterClear, ClearV2 } from "../generated/OrderBook/OrderBook"; -import { ClearBounty, ClearTemporaryData } from "../generated/schema"; -import { eventId } from "./interfaces/event"; +import { ClearTemporaryData } from "../generated/schema"; import { createTradeEntity } from "./trade"; import { createTradeVaultBalanceChangeEntity } from "./tradevaultbalancechange"; import { handleVaultBalanceChange, vaultEntityId } from "./vault"; @@ -144,82 +143,6 @@ function createTrade( ); } -export function clearBountyId(event: AfterClear, vaultEntityId: Bytes): Bytes { - let bytes = eventId(event).concat(vaultEntityId); - return Bytes.fromByteArray(crypto.keccak256(bytes)); -} - -export function createClearBountyEntity( - event: AfterClear, - vaultEntityId: Bytes, - oldVaultBalance: BigInt, - amount: BigInt -): ClearBounty { - let clearBounty = new ClearBounty(clearBountyId(event, vaultEntityId)); - clearBounty.orderbook = event.address; - clearBounty.amount = amount; - clearBounty.oldVaultBalance = oldVaultBalance; - clearBounty.newVaultBalance = oldVaultBalance.plus(amount); - clearBounty.vault = vaultEntityId; - clearBounty.timestamp = event.block.timestamp; - clearBounty.transaction = event.transaction.hash; - clearBounty.sender = event.params.sender; - clearBounty.save(); - return clearBounty; -} - -export function handleClearBounty( - event: AfterClear, - clearTemporaryData: ClearTemporaryData -): void { - const aliceBountyAmount = event.params.clearStateChange.aliceOutput.minus( - event.params.clearStateChange.bobInput - ); - const bobBountyAmount = event.params.clearStateChange.bobOutput.minus( - event.params.clearStateChange.aliceInput - ); - if (aliceBountyAmount.gt(BigInt.fromU32(0))) { - const oldBalance = handleVaultBalanceChange( - event.address, - clearTemporaryData.aliceBounty, - clearTemporaryData.aliceOutputToken, - aliceBountyAmount, - event.params.sender - ); - createClearBountyEntity( - event, - vaultEntityId( - event.address, - event.params.sender, - clearTemporaryData.aliceBounty, - clearTemporaryData.aliceOutputToken - ), - oldBalance, - aliceBountyAmount - ); - } - if (bobBountyAmount.gt(BigInt.fromU32(0))) { - const oldBalance = handleVaultBalanceChange( - event.address, - clearTemporaryData.bobBounty, - clearTemporaryData.bobOutputToken, - bobBountyAmount, - event.params.sender - ); - createClearBountyEntity( - event, - vaultEntityId( - event.address, - event.params.sender, - clearTemporaryData.bobBounty, - clearTemporaryData.bobOutputToken - ), - oldBalance, - bobBountyAmount - ); - } -} - export function handleAfterClear(event: AfterClear): void { let clearTemporaryData = ClearTemporaryData.load( clearTemporaryDataEntityId(event) @@ -227,7 +150,32 @@ export function handleAfterClear(event: AfterClear): void { if (clearTemporaryData) { createTrade(event, clearTemporaryData, true); createTrade(event, clearTemporaryData, false); - handleClearBounty(event, clearTemporaryData); + + // handle bounty vault changes + const aliceBountyAmount = event.params.clearStateChange.aliceOutput.minus( + event.params.clearStateChange.bobInput + ); + const bobBountyAmount = event.params.clearStateChange.bobOutput.minus( + event.params.clearStateChange.aliceInput + ); + if (aliceBountyAmount.gt(BigInt.fromU32(0))) { + handleVaultBalanceChange( + event.address, + clearTemporaryData.aliceBounty, + clearTemporaryData.aliceOutputToken, + aliceBountyAmount, + event.params.sender + ); + } + if (bobBountyAmount.gt(BigInt.fromU32(0))) { + handleVaultBalanceChange( + event.address, + clearTemporaryData.bobBounty, + clearTemporaryData.bobOutputToken, + bobBountyAmount, + event.params.sender + ); + } store.remove("ClearTemporaryData", clearTemporaryData.id.toHexString()); } else { log.error("ClearTemporaryData not found for event {}", [