Skip to content

Commit

Permalink
Merge pull request #12 from superfluid-finance/add-gas-used-to-events
Browse files Browse the repository at this point in the history
Add `gasUsed` to execution events
  • Loading branch information
kasparkallas authored May 21, 2024
2 parents a37f80c + 13343fb commit a066c41
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion subgraphs/flow-scheduler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flow-scheduler-subgraph",
"version": "1.0.0",
"version": "1.0.1",
"description": "A subgraph for the flow scheduler contracts",
"keywords": [
"subgraph"
Expand Down
2 changes: 2 additions & 0 deletions subgraphs/flow-scheduler/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type CreateFlowExecutedEvent implements Event @entity(immutable: true) {
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# CreateFlowExecutedEvent Specific Properties #
superToken: Bytes!
Expand Down Expand Up @@ -116,6 +117,7 @@ type DeleteFlowExecutedEvent implements Event @entity(immutable: true) {
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# DeleteFlowExecutedEvent Specific Properties #
superToken: Bytes!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { CreateFlowExecuted } from "../types/FlowScheduler/FlowScheduler";
import { CreateFlowExecutedEvent } from "../types/schema";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -24,5 +25,12 @@ export function createCreateFlowExecutedEventEntity(
ev.startAmount = event.params.startAmount;
ev.userData = event.params.userData;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { DeleteFlowExecuted } from "../types/FlowScheduler/FlowScheduler";
import { DeleteFlowExecutedEvent } from "../types/schema";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -21,5 +22,12 @@ export function createDeleteFlowExecutedEventEntity(
ev.endDate = event.params.endDate;
ev.userData = event.params.userData;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}
2 changes: 1 addition & 1 deletion subgraphs/flow-scheduler/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function setBaseProperties(
entity.set("addresses", Value.fromBytesArray(addresses));
entity.set("timestamp", Value.fromBigInt(event.block.timestamp));
entity.set("transactionHash", Value.fromBytes(event.transaction.hash));
entity.set("gasPrice", Value.fromBigInt(event.block.number));
entity.set("gasPrice", Value.fromBigInt(event.transaction.gasPrice));
return entity;
}

Expand Down
6 changes: 4 additions & 2 deletions subgraphs/flow-scheduler/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ dataSources:
- event: FlowScheduleCreated(indexed address,indexed address,indexed address,uint32,uint32,int96,uint32,uint256,bytes)
handler: handleFlowScheduleCreated
- event: FlowScheduleDeleted(indexed address,indexed address,indexed address)
handler: handleFlowScheduleDeleted
handler: handleFlowScheduleDeleted
- event: CreateFlowExecuted(indexed address,indexed address,indexed address,uint32,uint32,int96,uint256,bytes)
handler: handleCreateFlowExecuted
receipt: true
- event: DeleteFlowExecuted(indexed address,indexed address,indexed address,uint32,bytes)
handler: handleDeleteFlowExecuted
handler: handleDeleteFlowExecuted
receipt: true
2 changes: 1 addition & 1 deletion subgraphs/vesting-scheduler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vesting-scheduler-subgraph",
"version": "1.0.0",
"version": "1.0.1",
"description": "A subgraph for the vesting scheduler contracts",
"keywords": [
"subgraph"
Expand Down
3 changes: 3 additions & 0 deletions subgraphs/vesting-scheduler/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type VestingCliffAndFlowExecutedEvent implements Event
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# CreateVestingScheduleEvent Specific Properties #
superToken: Bytes!
Expand All @@ -64,6 +65,7 @@ type VestingEndExecutedEvent implements Event @entity(immutable: true) {
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# VestingEndExecutedEvent Specific Properties #
superToken: Bytes!
Expand All @@ -89,6 +91,7 @@ type VestingEndFailedEvent implements Event @entity(immutable: true) {
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# VestingEndExecutedEvent Specific Properties #
superToken: Bytes!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { VestingCliffAndFlowExecutedEvent } from "../types/schema";
import { VestingCliffAndFlowExecuted } from "../types/VestingScheduler/VestingScheduler";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -22,5 +23,12 @@ export function createVestingCliffAndFlowExecutedEntity(
ev.cliffAmount = event.params.cliffAmount;
ev.flowDelayCompensation = event.params.flowDelayCompensation;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { VestingEndExecutedEvent } from "../types/schema";
import { VestingEndExecuted } from "../types/VestingScheduler/VestingScheduler";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -21,5 +22,12 @@ export function createVestingEndExecutedEventEntity(
ev.earlyEndCompensation = event.params.earlyEndCompensation;
ev.didCompensationFail = event.params.didCompensationFail;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { VestingEndFailedEvent } from "../types/schema";
import { VestingEndFailed } from "../types/VestingScheduler/VestingScheduler";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -17,5 +18,12 @@ export function createVestingEndFailedEventEntity(
ev.receiver = event.params.receiver;
ev.endDate = event.params.endDate;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}
2 changes: 1 addition & 1 deletion subgraphs/vesting-scheduler/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function setBaseProperties(
entity.set("addresses", Value.fromBytesArray(addresses));
entity.set("timestamp", Value.fromBigInt(event.block.timestamp));
entity.set("transactionHash", Value.fromBytes(event.transaction.hash));
entity.set("gasPrice", Value.fromBigInt(event.block.number));
entity.set("gasPrice", Value.fromBigInt(event.transaction.gasPrice));
return entity;
}

Expand Down
3 changes: 3 additions & 0 deletions subgraphs/vesting-scheduler/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ dataSources:
eventHandlers:
- event: VestingCliffAndFlowExecuted(indexed address,indexed address,indexed address,uint32,int96,uint256,uint256)
handler: handleVestingCliffAndFlowExecuted
receipt: true
- event: VestingEndExecuted(indexed address,indexed address,indexed address,uint32,uint256,bool)
handler: handleVestingEndExecuted
receipt: true
- event: VestingScheduleCreated(indexed address,indexed address,indexed address,uint32,uint32,int96,uint32,uint256)
handler: handleVestingScheduleCreated
- event: VestingScheduleDeleted(indexed address,indexed address,indexed address)
Expand All @@ -39,3 +41,4 @@ dataSources:
handler: handleVestingScheduleUpdated
- event: VestingEndFailed(indexed address,indexed address,indexed address,uint32)
handler: handleVestingEndFailed
receipt: true
2 changes: 1 addition & 1 deletion subgraphs/wrap-scheduler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wrap-scheduler-subgraph",
"version": "1.0.0",
"version": "1.0.1",
"description": "A subgraph for the auto-wrap scheduler contracts",
"keywords": [
"subgraph"
Expand Down
1 change: 1 addition & 0 deletions subgraphs/wrap-scheduler/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type WrapExecutedEvent implements Event @entity(immutable: true) {
timestamp: BigInt!
transactionHash: Bytes!
gasPrice: BigInt!
gasUsed: BigInt!

# WrapExecutedEvent Specific Properties #
amount: BigInt!
Expand Down
8 changes: 8 additions & 0 deletions subgraphs/wrap-scheduler/src/utils/createWrapExecuted.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from "@graphprotocol/graph-ts";
import { WrapExecutedEvent } from "../types/schema";
import { WrapExecuted } from "../types/WrapScheduler/WrapManager";
import { createEventID, setBaseProperties } from "./general";
Expand All @@ -16,6 +17,13 @@ export function createWrapExecutedEventEntity(
ev.wrapScheduleId = event.params.id;
ev.amount = event.params.wrapAmount;

const receipt = event.receipt;
if (receipt) {
ev.gasUsed = receipt.gasUsed;
} else {
log.critical("receipt MUST NOT be null, set `receipt: true` under `eventHandlers` in the manifest file", []);
}

return ev;
}

2 changes: 1 addition & 1 deletion subgraphs/wrap-scheduler/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function setBaseProperties(
entity.set("addresses", Value.fromBytesArray(addresses));
entity.set("timestamp", Value.fromBigInt(event.block.timestamp));
entity.set("transactionHash", Value.fromBytes(event.transaction.hash));
entity.set("gasPrice", Value.fromBigInt(event.block.number));
entity.set("gasPrice", Value.fromBigInt(event.transaction.gasPrice));
return entity;
}

Expand Down
1 change: 1 addition & 0 deletions subgraphs/wrap-scheduler/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dataSources:
handler: handleWrapScheduleDeleted
- event: WrapExecuted(indexed bytes32,uint256)
handler: handleWrapExecuted
receipt: true
# - event: AddedApprovedStrategy(indexed address)
# handler: handleAddedApprovedStrategy
# - event: RemovedApprovedStrategy(indexed address)
Expand Down

0 comments on commit a066c41

Please sign in to comment.