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

feat: add ConditionalCommitAuthorizedEventLog #593

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"deploy:staging:goerli": "npm run manifest:staging:goerli && graph deploy --node https://api.thegraph.com/deploy/ --product hosted-service --ipfs https://api.thegraph.com/ipfs/ bosonprotocol/goerli-staging",
"deploy:production": "npm run manifest:production && graph deploy --node https://api.thegraph.com/deploy/ --product hosted-service --ipfs https://api.thegraph.com/ipfs/ bosonprotocol/polygon",
"deploy:production:ethereum": "npm run manifest:production:ethereum && graph deploy --node https://api.thegraph.com/deploy/ --product hosted-service --ipfs https://api.thegraph.com/ipfs/ bosonprotocol/ethereum",
"test": "npm run manifest:local && graph test"
"test": "npm run manifest:local && graph test -v 0.5.4"
}
}
15 changes: 15 additions & 0 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,21 @@ type ExchangeEventLog implements EventLog @entity {
exchange: Exchange!
}

type ConditionalCommitAuthorizedEventLog @entity {
id: ID!
hash: String!
type: EventType!
timestamp: BigInt!
executedBy: Bytes!

offerId: String!
groupId: String!
tokenId: BigInt!
gating: Int!
commitCount: BigInt!
maxCommits: BigInt!
}

type FundsEventLog implements EventLog @entity {
id: ID!
hash: String!
Expand Down
42 changes: 40 additions & 2 deletions packages/subgraph/src/entities/event-log.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { BigInt, Bytes } from "@graphprotocol/graph-ts";
/* eslint-disable @typescript-eslint/ban-types */
import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts";
import {
AccountEventLog,
OfferEventLog,
ExchangeEventLog,
FundsEventLog,
DisputeEventLog,
Exchange
Exchange,
ConditionalCommitAuthorizedEventLog,
Buyer
} from "../../generated/schema";

export function getEventLogId(
Expand Down Expand Up @@ -226,3 +229,38 @@ function saveDisputeEventLog(

return eventLogId;
}

export function saveConditionalCommitAuthorizedEventLog(
txHash: string,
logIndex: BigInt,
type: string,
timestamp: BigInt,
buyerAddress: Address,
offerId: BigInt,
commitCount: BigInt,
maxCommits: BigInt,
gating: i32,
tokenId: BigInt,
groupId: string
): string {
const eventLogId = getEventLogId(txHash, logIndex, offerId.toString());

let eventLog = ConditionalCommitAuthorizedEventLog.load(eventLogId);

if (!eventLog) {
eventLog = new ConditionalCommitAuthorizedEventLog(eventLogId);
}

eventLog.hash = txHash;
eventLog.type = type;
eventLog.timestamp = timestamp;
eventLog.executedBy = changetype<Bytes>(buyerAddress.toString());
eventLog.commitCount = commitCount;
eventLog.maxCommits = maxCommits;
eventLog.gating = gating;
eventLog.tokenId = tokenId;
eventLog.groupId = groupId;
eventLog.save();

return eventLogId;
}
35 changes: 32 additions & 3 deletions packages/subgraph/src/mappings/exchange-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import {
VoucherExtended,
VoucherTransferred,
ExchangeCompleted,
VoucherExpired
VoucherExpired,
ConditionalCommitAuthorized
} from "../../generated/BosonExchangeHandler/IBosonExchangeHandler";
import { Exchange, Offer } from "../../generated/schema";
import { ConditionEntity, Exchange, Offer } from "../../generated/schema";

import { saveMetadata } from "../entities/metadata/handler";
import { saveExchangeEventLogs } from "../entities/event-log";
import {
saveConditionalCommitAuthorizedEventLog,
saveExchangeEventLogs
} from "../entities/event-log";

export function handleBuyerCommittedEvent(event: BuyerCommitted): void {
const exchangeFromEvent = event.params.exchange;
Expand Down Expand Up @@ -223,3 +227,28 @@ export function handleExchangeCompletedEvent(event: ExchangeCompleted): void {
);
}
}

export function handleConditionalCommitAuthorizedEvent(
event: ConditionalCommitAuthorized
): void {
const offer = Offer.load(event.params.offerId.toString());

if (offer && offer.condition) {
const offerCondition = ConditionEntity.load(offer.condition as string);
if (offerCondition) {
saveConditionalCommitAuthorizedEventLog(
event.transaction.hash.toHexString(),
event.logIndex,
"CONDITIONAL_COMMIT",
event.block.timestamp,
event.params.buyerAddress,
event.params.offerId,
event.params.commitCount,
event.params.maxCommits,
event.params.gating,
event.params.tokenId,
offerCondition.id
);
}
}
}
2 changes: 2 additions & 0 deletions packages/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ dataSources:
handler: handleVoucherTransferredEvent
- event: ExchangeCompleted(indexed uint256,indexed uint256,indexed uint256,address)
handler: handleExchangeCompletedEvent
- event: ConditionalCommitAuthorized(indexed uint256,uint8,indexed address,indexed uint256,uint256,uint256)
handler: handleConditionalCommitAuthorizedEvent
file: ./src/mappings/exchange-handler.ts
- kind: ethereum/contract
name: BosonFundsHandler
Expand Down
Loading