Skip to content

Commit

Permalink
Revert "clear bounty entity"
Browse files Browse the repository at this point in the history
This reverts commit 4281354.
  • Loading branch information
rouzwelt committed Oct 11, 2024
1 parent 4281354 commit 89ff699
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 99 deletions.
20 changes: 0 additions & 20 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
106 changes: 27 additions & 79 deletions subgraph/src/clear.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -144,90 +143,39 @@ 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)
);
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 {}", [
Expand Down

0 comments on commit 89ff699

Please sign in to comment.