diff --git a/crates/subgraph/schema/orderbook.graphql b/crates/subgraph/schema/orderbook.graphql index 4f8338925..0d3335354 100644 --- a/crates/subgraph/schema/orderbook.graphql +++ b/crates/subgraph/schema/orderbook.graphql @@ -149,6 +149,370 @@ input Block_height { scalar Bytes +type ClearBounty implements VaultBalanceChange { + 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! +} + +input ClearBounty_filter { + id: Bytes + id_not: Bytes + id_gt: Bytes + id_lt: Bytes + id_gte: Bytes + id_lte: Bytes + id_in: [Bytes!] + id_not_in: [Bytes!] + id_contains: Bytes + id_not_contains: Bytes + orderbook: String + orderbook_not: String + orderbook_gt: String + orderbook_lt: String + orderbook_gte: String + orderbook_lte: String + orderbook_in: [String!] + orderbook_not_in: [String!] + orderbook_contains: String + orderbook_contains_nocase: String + orderbook_not_contains: String + orderbook_not_contains_nocase: String + orderbook_starts_with: String + orderbook_starts_with_nocase: String + orderbook_not_starts_with: String + orderbook_not_starts_with_nocase: String + orderbook_ends_with: String + orderbook_ends_with_nocase: String + orderbook_not_ends_with: String + orderbook_not_ends_with_nocase: String + orderbook_: Orderbook_filter + sender: Bytes + sender_not: Bytes + sender_gt: Bytes + sender_lt: Bytes + sender_gte: Bytes + sender_lte: Bytes + sender_in: [Bytes!] + sender_not_in: [Bytes!] + sender_contains: Bytes + sender_not_contains: Bytes + vault: String + vault_not: String + vault_gt: String + vault_lt: String + vault_gte: String + vault_lte: String + vault_in: [String!] + vault_not_in: [String!] + vault_contains: String + vault_contains_nocase: String + vault_not_contains: String + vault_not_contains_nocase: String + vault_starts_with: String + vault_starts_with_nocase: String + vault_not_starts_with: String + vault_not_starts_with_nocase: String + vault_ends_with: String + vault_ends_with_nocase: String + vault_not_ends_with: String + vault_not_ends_with_nocase: String + vault_: Vault_filter + amount: BigInt + amount_not: BigInt + amount_gt: BigInt + amount_lt: BigInt + amount_gte: BigInt + amount_lte: BigInt + amount_in: [BigInt!] + amount_not_in: [BigInt!] + oldVaultBalance: BigInt + oldVaultBalance_not: BigInt + oldVaultBalance_gt: BigInt + oldVaultBalance_lt: BigInt + oldVaultBalance_gte: BigInt + oldVaultBalance_lte: BigInt + oldVaultBalance_in: [BigInt!] + oldVaultBalance_not_in: [BigInt!] + newVaultBalance: BigInt + newVaultBalance_not: BigInt + newVaultBalance_gt: BigInt + newVaultBalance_lt: BigInt + newVaultBalance_gte: BigInt + newVaultBalance_lte: BigInt + newVaultBalance_in: [BigInt!] + newVaultBalance_not_in: [BigInt!] + timestamp: BigInt + timestamp_not: BigInt + timestamp_gt: BigInt + timestamp_lt: BigInt + timestamp_gte: BigInt + timestamp_lte: BigInt + timestamp_in: [BigInt!] + timestamp_not_in: [BigInt!] + transaction: String + transaction_not: String + transaction_gt: String + transaction_lt: String + transaction_gte: String + transaction_lte: String + transaction_in: [String!] + transaction_not_in: [String!] + transaction_contains: String + transaction_contains_nocase: String + transaction_not_contains: String + transaction_not_contains_nocase: String + transaction_starts_with: String + transaction_starts_with_nocase: String + transaction_not_starts_with: String + transaction_not_starts_with_nocase: String + transaction_ends_with: String + transaction_ends_with_nocase: String + transaction_not_ends_with: String + transaction_not_ends_with_nocase: String + transaction_: Transaction_filter + """ + Filter for the block changed event. + """ + _change_block: BlockChangedFilter + and: [ClearBounty_filter] + or: [ClearBounty_filter] +} + +enum ClearBounty_orderBy { + id + orderbook + orderbook__id + sender + vault + vault__id + vault__owner + vault__vaultId + vault__balance + amount + oldVaultBalance + newVaultBalance + timestamp + transaction + transaction__id + transaction__timestamp + transaction__blockNumber + transaction__from +} + +type ClearTemporaryData { + id: Bytes! + aliceOrderHash: Bytes! + aliceAddress: Bytes! + aliceInputVaultId: BigInt! + aliceInputToken: Bytes! + aliceOutputVaultId: BigInt! + aliceOutputToken: Bytes! + aliceBounty: BigInt! + bobOrderHash: Bytes! + bobAddress: Bytes! + bobInputVaultId: BigInt! + bobInputToken: Bytes! + bobOutputVaultId: BigInt! + bobOutputToken: Bytes! + bobBounty: BigInt! +} + +input ClearTemporaryData_filter { + id: Bytes + id_not: Bytes + id_gt: Bytes + id_lt: Bytes + id_gte: Bytes + id_lte: Bytes + id_in: [Bytes!] + id_not_in: [Bytes!] + id_contains: Bytes + id_not_contains: Bytes + aliceOrderHash: Bytes + aliceOrderHash_not: Bytes + aliceOrderHash_gt: Bytes + aliceOrderHash_lt: Bytes + aliceOrderHash_gte: Bytes + aliceOrderHash_lte: Bytes + aliceOrderHash_in: [Bytes!] + aliceOrderHash_not_in: [Bytes!] + aliceOrderHash_contains: Bytes + aliceOrderHash_not_contains: Bytes + aliceAddress: Bytes + aliceAddress_not: Bytes + aliceAddress_gt: Bytes + aliceAddress_lt: Bytes + aliceAddress_gte: Bytes + aliceAddress_lte: Bytes + aliceAddress_in: [Bytes!] + aliceAddress_not_in: [Bytes!] + aliceAddress_contains: Bytes + aliceAddress_not_contains: Bytes + aliceInputVaultId: BigInt + aliceInputVaultId_not: BigInt + aliceInputVaultId_gt: BigInt + aliceInputVaultId_lt: BigInt + aliceInputVaultId_gte: BigInt + aliceInputVaultId_lte: BigInt + aliceInputVaultId_in: [BigInt!] + aliceInputVaultId_not_in: [BigInt!] + aliceInputToken: Bytes + aliceInputToken_not: Bytes + aliceInputToken_gt: Bytes + aliceInputToken_lt: Bytes + aliceInputToken_gte: Bytes + aliceInputToken_lte: Bytes + aliceInputToken_in: [Bytes!] + aliceInputToken_not_in: [Bytes!] + aliceInputToken_contains: Bytes + aliceInputToken_not_contains: Bytes + aliceOutputVaultId: BigInt + aliceOutputVaultId_not: BigInt + aliceOutputVaultId_gt: BigInt + aliceOutputVaultId_lt: BigInt + aliceOutputVaultId_gte: BigInt + aliceOutputVaultId_lte: BigInt + aliceOutputVaultId_in: [BigInt!] + aliceOutputVaultId_not_in: [BigInt!] + aliceOutputToken: Bytes + aliceOutputToken_not: Bytes + aliceOutputToken_gt: Bytes + aliceOutputToken_lt: Bytes + aliceOutputToken_gte: Bytes + aliceOutputToken_lte: Bytes + aliceOutputToken_in: [Bytes!] + aliceOutputToken_not_in: [Bytes!] + aliceOutputToken_contains: Bytes + aliceOutputToken_not_contains: Bytes + aliceBounty: BigInt + aliceBounty_not: BigInt + aliceBounty_gt: BigInt + aliceBounty_lt: BigInt + aliceBounty_gte: BigInt + aliceBounty_lte: BigInt + aliceBounty_in: [BigInt!] + aliceBounty_not_in: [BigInt!] + bobOrderHash: Bytes + bobOrderHash_not: Bytes + bobOrderHash_gt: Bytes + bobOrderHash_lt: Bytes + bobOrderHash_gte: Bytes + bobOrderHash_lte: Bytes + bobOrderHash_in: [Bytes!] + bobOrderHash_not_in: [Bytes!] + bobOrderHash_contains: Bytes + bobOrderHash_not_contains: Bytes + bobAddress: Bytes + bobAddress_not: Bytes + bobAddress_gt: Bytes + bobAddress_lt: Bytes + bobAddress_gte: Bytes + bobAddress_lte: Bytes + bobAddress_in: [Bytes!] + bobAddress_not_in: [Bytes!] + bobAddress_contains: Bytes + bobAddress_not_contains: Bytes + bobInputVaultId: BigInt + bobInputVaultId_not: BigInt + bobInputVaultId_gt: BigInt + bobInputVaultId_lt: BigInt + bobInputVaultId_gte: BigInt + bobInputVaultId_lte: BigInt + bobInputVaultId_in: [BigInt!] + bobInputVaultId_not_in: [BigInt!] + bobInputToken: Bytes + bobInputToken_not: Bytes + bobInputToken_gt: Bytes + bobInputToken_lt: Bytes + bobInputToken_gte: Bytes + bobInputToken_lte: Bytes + bobInputToken_in: [Bytes!] + bobInputToken_not_in: [Bytes!] + bobInputToken_contains: Bytes + bobInputToken_not_contains: Bytes + bobOutputVaultId: BigInt + bobOutputVaultId_not: BigInt + bobOutputVaultId_gt: BigInt + bobOutputVaultId_lt: BigInt + bobOutputVaultId_gte: BigInt + bobOutputVaultId_lte: BigInt + bobOutputVaultId_in: [BigInt!] + bobOutputVaultId_not_in: [BigInt!] + bobOutputToken: Bytes + bobOutputToken_not: Bytes + bobOutputToken_gt: Bytes + bobOutputToken_lt: Bytes + bobOutputToken_gte: Bytes + bobOutputToken_lte: Bytes + bobOutputToken_in: [Bytes!] + bobOutputToken_not_in: [Bytes!] + bobOutputToken_contains: Bytes + bobOutputToken_not_contains: Bytes + bobBounty: BigInt + bobBounty_not: BigInt + bobBounty_gt: BigInt + bobBounty_lt: BigInt + bobBounty_gte: BigInt + bobBounty_lte: BigInt + bobBounty_in: [BigInt!] + bobBounty_not_in: [BigInt!] + """ + Filter for the block changed event. + """ + _change_block: BlockChangedFilter + and: [ClearTemporaryData_filter] + or: [ClearTemporaryData_filter] +} + +enum ClearTemporaryData_orderBy { + id + aliceOrderHash + aliceAddress + aliceInputVaultId + aliceInputToken + aliceOutputVaultId + aliceOutputToken + aliceBounty + bobOrderHash + bobAddress + bobInputVaultId + bobInputToken + bobOutputVaultId + bobOutputToken + bobBounty +} + type Deposit implements Event & VaultBalanceChange { id: Bytes! """ @@ -1001,6 +1365,32 @@ type Query { """ subgraphError: _SubgraphErrorPolicy_! = deny ): [TradeVaultBalanceChange!]! + clearBounty( + id: ID! + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): ClearBounty + clearBounties( + skip: Int = 0 + first: Int = 100 + orderBy: ClearBounty_orderBy + orderDirection: OrderDirection + where: ClearBounty_filter + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): [ClearBounty!]! order( id: ID! """ @@ -1183,6 +1573,32 @@ type Query { """ subgraphError: _SubgraphErrorPolicy_! = deny ): [ERC20!]! + clearTemporaryData( + id: ID! + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): ClearTemporaryData + clearTemporaryDatas( + skip: Int = 0 + first: Int = 100 + orderBy: ClearTemporaryData_orderBy + orderDirection: OrderDirection + where: ClearTemporaryData_filter + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): [ClearTemporaryData!]! vaultBalanceChange( id: ID! """ @@ -1528,6 +1944,32 @@ type Subscription { """ subgraphError: _SubgraphErrorPolicy_! = deny ): [TradeVaultBalanceChange!]! + clearBounty( + id: ID! + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): ClearBounty + clearBounties( + skip: Int = 0 + first: Int = 100 + orderBy: ClearBounty_orderBy + orderDirection: OrderDirection + where: ClearBounty_filter + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): [ClearBounty!]! order( id: ID! """ @@ -1710,6 +2152,32 @@ type Subscription { """ subgraphError: _SubgraphErrorPolicy_! = deny ): [ERC20!]! + clearTemporaryData( + id: ID! + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): ClearTemporaryData + clearTemporaryDatas( + skip: Int = 0 + first: Int = 100 + orderBy: ClearTemporaryData_orderBy + orderDirection: OrderDirection + where: ClearTemporaryData_filter + """ + The block at which the query should be executed. Can either be a `{ hash: Bytes }` value containing a block hash, a `{ number: Int }` containing the block number, or a `{ number_gte: Int }` containing the minimum block number. In the case of `number_gte`, the query will be executed on the latest block only if the subgraph has progressed to or past the minimum block number. Defaults to the latest block when omitted. + """ + block: Block_height + """ + Set to `allow` to receive data even if the subgraph has skipped over errors while syncing. + """ + subgraphError: _SubgraphErrorPolicy_! = deny + ): [ClearTemporaryData!]! vaultBalanceChange( id: ID! """ diff --git a/crates/subgraph/src/types/common.rs b/crates/subgraph/src/types/common.rs index 0a0d7d973..bef02ad12 100644 --- a/crates/subgraph/src/types/common.rs +++ b/crates/subgraph/src/types/common.rs @@ -185,6 +185,7 @@ pub enum VaultBalanceChange { Withdrawal(Withdrawal), TradeVaultBalanceChange(TradeVaultBalanceChange), Deposit(Deposit), + ClearBounty(ClearBounty), #[cynic(fallback)] Unknown, } @@ -234,6 +235,22 @@ pub struct TradeVaultBalanceChange { pub orderbook: Orderbook, } +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[typeshare] +#[serde(rename_all = "camelCase")] +pub struct ClearBounty { + pub id: Bytes, + pub __typename: String, + pub amount: BigInt, + pub new_vault_balance: BigInt, + pub old_vault_balance: BigInt, + pub vault: VaultBalanceChangeVault, + pub timestamp: BigInt, + pub transaction: Transaction, + pub orderbook: Orderbook, + pub sender: Bytes, +} + #[derive(cynic::QueryFragment, Debug, Clone, Serialize)] #[typeshare] pub struct TradeEvent { diff --git a/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap b/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap index 5df263de3..b02666f22 100644 --- a/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap @@ -119,6 +119,35 @@ query BatchOrderDetailQuery($id_list: Order_filter!) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } inputs { @@ -232,6 +261,35 @@ query BatchOrderDetailQuery($id_list: Order_filter!) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } orderbook { diff --git a/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap b/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap index 69f41804e..754ed1164 100644 --- a/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap @@ -119,6 +119,35 @@ query OrderDetailQuery($id: ID!) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } inputs { @@ -232,6 +261,35 @@ query OrderDetailQuery($id: ID!) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } orderbook { diff --git a/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap b/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap index 85fa9396a..7e6dd6dcb 100644 --- a/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap @@ -119,6 +119,35 @@ query OrdersListQuery($first: Int, $skip: Int, $filters: Order_filter) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } inputs { @@ -232,6 +261,35 @@ query OrdersListQuery($first: Int, $skip: Int, $filters: Order_filter) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } orderbook { diff --git a/crates/subgraph/tests/snapshots/vault_test__vaults_query_gql_output.snap b/crates/subgraph/tests/snapshots/vault_test__vaults_query_gql_output.snap index d357056ab..e3beb593c 100644 --- a/crates/subgraph/tests/snapshots/vault_test__vaults_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/vault_test__vaults_query_gql_output.snap @@ -114,6 +114,35 @@ query VaultDetailQuery($id: ID!) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } } diff --git a/crates/subgraph/tests/snapshots/vaults_test__vaults_query_gql_output.snap b/crates/subgraph/tests/snapshots/vaults_test__vaults_query_gql_output.snap index 32b77a4de..c0cd662ca 100644 --- a/crates/subgraph/tests/snapshots/vaults_test__vaults_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/vaults_test__vaults_query_gql_output.snap @@ -114,6 +114,35 @@ query VaultsListQuery($first: Int, $skip: Int, $filters: Vault_filter) { id } } + ... on ClearBounty { + id + __typename + amount + newVaultBalance + oldVaultBalance + vault { + id + vaultId + token { + id + address + name + symbol + decimals + } + } + timestamp + transaction { + id + from + blockNumber + timestamp + } + orderbook { + id + } + sender + } } } } diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 25f14f7f0..36e96fb43 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -123,6 +123,26 @@ 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 5dd156114..8b3881c9c 100644 --- a/subgraph/src/clear.ts +++ b/subgraph/src/clear.ts @@ -1,7 +1,9 @@ import { AfterClear, ClearV2 } from "../generated/OrderBook/OrderBook"; -import { ClearTemporaryData } from "../generated/schema"; +import { ClearBounty, ClearTemporaryData } from "../generated/schema"; +import { eventId } from "./interfaces/event"; import { createTradeEntity } from "./trade"; import { createTradeVaultBalanceChangeEntity } from "./tradevaultbalancechange"; +import { createTransactionEntity } from "./transaction"; import { handleVaultBalanceChange, vaultEntityId } from "./vault"; import { log } from "@graphprotocol/graph-ts"; import { @@ -29,6 +31,7 @@ export function clearTemporaryDataEntityId(event: ethereum.Event): Bytes { } export function handleClear(event: ClearV2): void { + createTransactionEntity(event); let clearTemporaryData = new ClearTemporaryData( clearTemporaryDataEntityId(event) ); @@ -143,6 +146,82 @@ 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) @@ -150,32 +229,7 @@ export function handleAfterClear(event: AfterClear): void { if (clearTemporaryData) { createTrade(event, clearTemporaryData, true); createTrade(event, clearTemporaryData, false); - - // 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 - ); - } + handleClearBounty(event, clearTemporaryData); store.remove("ClearTemporaryData", clearTemporaryData.id.toHexString()); } else { log.error("ClearTemporaryData not found for event {}", [