Skip to content

Commit

Permalink
add total units
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdavinchee committed Dec 11, 2023
1 parent 886c0f1 commit a3a5a61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ type InstantDistributionUpdatedEvent implements Event @entity(immutable: true) {
operator: Bytes!
requestedAmount: BigInt!
actualAmount: BigInt!
totalUnits: BigInt!
userData: Bytes!

pool: Pool!
Expand Down Expand Up @@ -755,6 +756,7 @@ type FlowDistributionUpdatedEvent implements Event @entity(immutable: true) {
newTotalDistributionFlowRate: BigInt!
adjustmentFlowRecipient: Bytes!
adjustmentFlowRate: BigInt!
totalUnits: BigInt!
userData: Bytes!

pool: Pool!
Expand Down Expand Up @@ -811,6 +813,7 @@ type MemberUnitsUpdatedEvent implements Event @entity(immutable: true) {
token: Bytes!
oldUnits: BigInt!
units: BigInt!
totalUnits: BigInt!

pool: Pool!
poolMember: PoolMember!
Expand Down
12 changes: 8 additions & 4 deletions packages/subgraph/src/mappings/gdav1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export function handleFlowDistributionUpdated(
);

// Create Event Entity
_createFlowDistributionUpdatedEntity(event, poolDistributor.id);
_createFlowDistributionUpdatedEntity(event, poolDistributor.id, pool.totalUnits);
}

export function handleInstantDistributionUpdated(
Expand Down Expand Up @@ -344,7 +344,7 @@ export function handleInstantDistributionUpdated(
);

// Create Event Entity
_createInstantDistributionUpdatedEntity(event, poolDistributor.id);
_createInstantDistributionUpdatedEntity(event, poolDistributor.id, pool.totalUnits);
}

// Event Entity Creation Functions
Expand Down Expand Up @@ -417,7 +417,8 @@ function _createBufferAdjustedEntity(

function _createInstantDistributionUpdatedEntity(
event: InstantDistributionUpdated,
poolDistributorId: string
poolDistributorId: string,
totalUnits: BigInt
): InstantDistributionUpdatedEvent {
const ev = new InstantDistributionUpdatedEvent(
createEventID("InstantDistributionUpdated", event)
Expand All @@ -435,6 +436,7 @@ function _createInstantDistributionUpdatedEntity(
ev.actualAmount = event.params.actualAmount;
ev.pool = event.params.pool.toHex();
ev.poolDistributor = poolDistributorId;
ev.totalUnits = totalUnits;
ev.userData = event.params.userData;

ev.save();
Expand All @@ -444,7 +446,8 @@ function _createInstantDistributionUpdatedEntity(

function _createFlowDistributionUpdatedEntity(
event: FlowDistributionUpdated,
poolDistributorId: string
poolDistributorId: string,
totalUnits: BigInt
): FlowDistributionUpdatedEvent {
const ev = new FlowDistributionUpdatedEvent(
createEventID("FlowDistributionUpdated", event)
Expand All @@ -465,6 +468,7 @@ function _createFlowDistributionUpdatedEntity(
ev.adjustmentFlowRate = event.params.adjustmentFlowRate;
ev.pool = event.params.pool.toHex();
ev.poolDistributor = poolDistributorId;
ev.totalUnits = totalUnits;
ev.userData = event.params.userData;

ev.save();
Expand Down
9 changes: 7 additions & 2 deletions packages/subgraph/src/mappings/superfluidPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void {
}

// Create Event Entity
_createMemberUnitsUpdatedEntity(event, poolMember.id);
_createMemberUnitsUpdatedEntity(event, poolMember.id, pool.totalUnits);
}

function _createDistributionClaimedEntity(event: DistributionClaimed, poolMemberId: string): DistributionClaimedEvent {
Expand All @@ -141,13 +141,18 @@ function _createDistributionClaimedEntity(event: DistributionClaimed, poolMember
return ev;
}

function _createMemberUnitsUpdatedEntity(event: MemberUnitsUpdated, poolMemberId: string): MemberUnitsUpdatedEvent {
function _createMemberUnitsUpdatedEntity(
event: MemberUnitsUpdated,
poolMemberId: string,
totalUnits: BigInt
): MemberUnitsUpdatedEvent {
const ev = new MemberUnitsUpdatedEvent(createEventID("MemberUnitsUpdated", event));
initializeEventEntity(ev, event, [event.params.token, event.address, event.params.member]);

ev.token = event.params.token;
ev.oldUnits = event.params.oldUnits;
ev.units = event.params.newUnits;
ev.totalUnits = totalUnits;
ev.pool = event.address.toHex();
ev.poolMember = poolMemberId;
ev.save();
Expand Down

0 comments on commit a3a5a61

Please sign in to comment.