Skip to content

Commit

Permalink
[SUBGRAPH] approval mapping (#1878)
Browse files Browse the repository at this point in the history
* approval mapping

* missing addresses

* missing addresses cont.

* no-op, trigger build

* fix tests

---------

Co-authored-by: Kaspar Kallas <[email protected]>
  • Loading branch information
0xdavinchee and kasparkallas authored Mar 12, 2024
1 parent b48fcca commit a58cf6b
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 42 deletions.
98 changes: 78 additions & 20 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,8 @@ type AgreementClassRegisteredEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `code`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -849,7 +850,8 @@ type AgreementClassUpdatedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `code`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -868,7 +870,8 @@ type AppRegisteredEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `app`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -889,7 +892,9 @@ type GovernanceReplacedEvent implements Event @entity(immutable: true) {
order: BigInt!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `oldGovernance`
addresses[1] = `newGovernance`
"""
addresses: [Bytes!]!
oldGovernance: Bytes!
Expand All @@ -905,7 +910,8 @@ type JailEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `app`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -924,7 +930,8 @@ type SuperTokenFactoryUpdatedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `newFactory`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -942,7 +949,9 @@ type SuperTokenLogicUpdatedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `token`
addresses[1] = `code`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -963,7 +972,9 @@ type RoleAdminChangedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `previousAdminRole`
addresses[1] = `newAdminRole`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -983,7 +994,9 @@ type RoleGrantedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `account`
addresses[1] = `sender`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -1003,7 +1016,9 @@ type RoleRevokedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `account`
addresses[1] = `sender`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand Down Expand Up @@ -1057,7 +1072,10 @@ type CFAv1LiquidationPeriodChangedEvent implements Event
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -1083,7 +1101,10 @@ type ConfigChangedEvent implements Event @entity(immutable: true) {
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -1110,7 +1131,11 @@ type RewardAddressChangedEvent implements Event @entity(immutable: true) {
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
addresses[3] = `rewardAddress`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -1136,7 +1161,10 @@ type PPPConfigurationChangedEvent implements Event @entity(immutable: true) {
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand Down Expand Up @@ -1164,7 +1192,10 @@ type SuperTokenMinimumDepositChangedEvent implements Event
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand All @@ -1190,7 +1221,11 @@ type TrustedForwarderChangedEvent implements Event @entity(immutable: true) {
governanceAddress: Bytes!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `governanceAddress`
addresses[1] = `host`
addresses[2] = `superToken`
addresses[3] = `forwarder`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand Down Expand Up @@ -1468,20 +1503,39 @@ type ApprovalEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `isNFTApproval` ? `nft address` : `token` (superToken)
addresses[1] = `owner`
addresses[2] = `to`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
logIndex: BigInt!
order: BigInt!

"""
The address that will be granting allowance to transfer ERC20/NFT.
"""
owner: Account!

"""
The address that will be granted allowance to transfer the NFT.
The address that will be granted allowance to transfer ERC20/NFT.
"""
to: Account!

"""
Indicates whether the event was emitted for the approval of an NFT.
"""
isNFTApproval: Boolean!

"""
If `amount` is non-zero, this event was emitted for the approval of an ERC20.
Tne amount of ERC20 tokens that will be granted allowance to transfer.
"""
amount: BigInt!

"""
If `tokenId` is non-zero, this event was emitted for the approval of an NFT.
The id of the NFT that will be granted allowance to transfer.
The id is: uint256(keccak256(abi.encode(block.chainid, superToken, sender, receiver)))
"""
Expand All @@ -1497,7 +1551,10 @@ type ApprovalForAllEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = NFT address
addresses[1] = `owner`
addresses[2] = `operator`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand Down Expand Up @@ -1590,7 +1647,8 @@ type SuperTokenLogicCreatedEvent implements Event @entity(immutable: true) {
name: String!

"""
Empty addresses array.
Contains the addresses that were impacted by this event:
addresses[0] = `tokenLogic`
"""
addresses: [Bytes!]!
blockNumber: BigInt!
Expand Down
8 changes: 5 additions & 3 deletions packages/subgraph/src/mappings/flowNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ import {
MetadataUpdateEvent,
TransferEvent,
} from "../../generated/schema";
import { createEventID, initializeEventEntity } from "../utils";
import { BIG_INT_ONE, createEventID, initializeEventEntity } from "../utils";

export function handleApproval(event: Approval): void {
const eventId = createEventID("Approval", event);
const ev = new ApprovalEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.approved]);
ev.owner = event.params.owner.toHex();
ev.to = event.params.approved.toHex();
ev.tokenId = event.params.tokenId;
ev.amount = BIG_INT_ONE.neg();
ev.isNFTApproval = true;

ev.save();
}

export function handleApprovalForAll(event: ApprovalForAll): void {
const eventId = createEventID("ApprovalForAll", event);
const ev = new ApprovalForAllEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.operator]);
ev.owner = event.params.owner.toHex();
ev.operator = event.params.operator.toHex();
ev.approved = event.params.approved;
Expand Down
14 changes: 7 additions & 7 deletions packages/subgraph/src/mappings/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { SuperfluidGovernance } from "../../generated/templates";
export function handleGovernanceReplaced(event: GovernanceReplaced): void {
const eventId = createEventID("GovernanceReplaced", event);
const ev = new GovernanceReplacedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.oldGov, event.params.newGov]);
ev.oldGovernance = event.params.oldGov;
ev.newGovernance = event.params.newGov;
ev.save();
Expand All @@ -42,7 +42,7 @@ export function handleAgreementClassRegistered(
): void {
const eventId = createEventID("AgreementClassRegistered", event);
const ev = new AgreementClassRegisteredEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.code]);
ev.agreementType = event.params.agreementType;
ev.code = event.params.code;
ev.save();
Expand All @@ -55,7 +55,7 @@ export function handleAgreementClassUpdated(
): void {
const eventId = createEventID("AgreementClassUpdated", event);
const ev = new AgreementClassUpdatedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.code]);

ev.agreementType = event.params.agreementType;
ev.code = event.params.code;
Expand All @@ -70,7 +70,7 @@ export function handleSuperTokenFactoryUpdated(
): void {
const eventId = createEventID("SuperTokenFactoryUpdated", event);
const ev = new SuperTokenFactoryUpdatedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.newFactory]);

ev.newFactory = event.params.newFactory;
ev.save();
Expand All @@ -81,7 +81,7 @@ export function handleSuperTokenLogicUpdated(
): void {
const eventId = createEventID("SuperTokenLogicUpdated", event);
const ev = new SuperTokenLogicUpdatedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.token, event.params.code]);

ev.token = event.params.token;
ev.code = event.params.code;
Expand All @@ -90,15 +90,15 @@ export function handleSuperTokenLogicUpdated(

export function handleAppRegistered(event: AppRegistered): void {
const ev = new AppRegisteredEvent(createEventID("AppRegistered", event));
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.app]);

ev.app = event.params.app;
ev.save();
}

export function handleJail(event: Jail): void {
const ev = new JailEvent(createEventID("Jail", event));
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.app]);

ev.app = event.params.app;
ev.reason = event.params.reason;
Expand Down
6 changes: 3 additions & 3 deletions packages/subgraph/src/mappings/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createEventID, initializeEventEntity, ZERO_ADDRESS } from "../utils";
export function handleRoleAdminChanged(event: RoleAdminChanged): void {
const eventId = createEventID("RoleAdminChanged", event);
const ev = new RoleAdminChangedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.previousAdminRole, event.params.newAdminRole]);

ev.role = event.params.role;
ev.previousAdminRole = event.params.previousAdminRole;
Expand All @@ -29,7 +29,7 @@ export function handleRoleAdminChanged(event: RoleAdminChanged): void {
export function handleRoleGranted(event: RoleGranted): void {
const eventId = createEventID("RoleGranted", event);
const ev = new RoleGrantedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.account, event.params.sender]);

ev.role = event.params.role;
ev.account = event.params.account;
Expand All @@ -39,7 +39,7 @@ export function handleRoleGranted(event: RoleGranted): void {
export function handleRoleRevoked(event: RoleRevoked): void {
const eventId = createEventID("RoleRevoked", event);
const ev = new RoleRevokedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.account, event.params.sender]);

ev.role = event.params.role;
ev.account = event.params.account;
Expand Down
12 changes: 12 additions & 0 deletions packages/subgraph/src/mappings/superToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
AgreementLiquidatedByEvent,
AgreementLiquidatedV2Event,
ApprovalEvent,
BurnedEvent,
MintedEvent,
SentEvent,
Expand Down Expand Up @@ -452,6 +453,17 @@ function _createTransferEventEntity(event: Transfer): void {
}

export function handleApproval(event: Approval): void {
const eventId = createEventID("Approval", event);
const ev = new ApprovalEvent(eventId);
initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.spender]);
ev.owner = event.params.owner.toHex();
ev.to = event.params.spender.toHex();
ev.tokenId = BIG_INT_ZERO;
ev.amount = event.params.value;
ev.isNFTApproval = false;

ev.save();

// The entity named `FlowOperators` which currently holds all the user access and approval settings will be renamed to `AccessSettings`.
const flowOperator = getOrInitFlowOperator(
event.block,
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/src/mappings/superTokenFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function handleSuperTokenLogicCreated(
}
const eventId = createEventID("SuperTokenLogicCreated", event);
const ev = new SuperTokenLogicCreatedEvent(eventId);
initializeEventEntity(ev, event, []);
initializeEventEntity(ev, event, [event.params.tokenLogic]);

ev.tokenLogic = event.params.tokenLogic;
ev.save();
Expand Down
Loading

0 comments on commit a58cf6b

Please sign in to comment.