Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdavinchee committed Jan 8, 2024
1 parent c28853d commit 75c8c55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,8 @@ type PoolMember @entity {
units: BigInt!
isConnected: Boolean!
totalAmountClaimed: BigInt!
poolTotalAmountDistributedUntilUpdatedAt: BigInt!
totalAmountReceivedUntilUpdatedAt: BigInt!

account: Account!
pool: Pool!
Expand Down
7 changes: 7 additions & 0 deletions packages/subgraph/src/mappings/superfluidPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void {
pool.totalUnits = pool.totalUnits.plus(unitsDelta);
pool.save();

const newReceivedAmount = pool.totalAmountDistributedUntilUpdatedAt
.minus(poolMember.totalAmountDistributedUntilUpdatedAt)
.div(pool.totalUnits)
.mul(poolMember.units);
poolMember.totalAmountReceivedUntilUpdatedAt = poolMember.totalAmountReceivedUntilUpdatedAt.plus(newReceivedAmount);
poolMember.totalAmountDistributedUntilUpdatedAt = pool.totalAmountDistributedUntilUpdatedAt;

// 0 units to > 0 units
if (previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO)) {
pool.totalMembers = pool.totalMembers + 1;
Expand Down

0 comments on commit 75c8c55

Please sign in to comment.