Skip to content

Commit

Permalink
feat: use balance deltas over rpc calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparkallas committed May 30, 2024
1 parent e1b1b33 commit 41f6e67
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/subgraph/src/mappingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ export function updateAggregateDistributionAgreementData(
totalApprovedSubscriptionsDelta;
}

// TODO: Also consider adjustment flow rate here
accountTokenSnapshot.isLiquidationEstimateOptimistic =
accountTokenSnapshot.totalSubscriptionsWithUnits > 0 ||
accountTokenSnapshot.totalMembershipsWithUnits > 0;
Expand Down Expand Up @@ -980,7 +981,7 @@ function updateATSBalanceAndUpdatedAt(
Address.fromString(accountTokenSnapshot.token)
);

if (balanceDelta && accountTokenSnapshot.totalSubscriptionsWithUnits == 0) {
if (balanceDelta && !accountTokenSnapshot.isLiquidationEstimateOptimistic) {
accountTokenSnapshot.balanceUntilUpdatedAt =
accountTokenSnapshot.balanceUntilUpdatedAt.plus(
balanceDelta as BigInt
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/src/mappings/cfav1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function handleFlowUpdated(event: FlowUpdated): void {
receiverAddress,
tokenAddress,
event.block,
null
BigInt.fromI32(0)
);

// update stream counter data for sender and receiver ATS
Expand Down
11 changes: 6 additions & 5 deletions packages/subgraph/src/mappings/gdav1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function handlePoolCreated(event: PoolCreated): void {
event.params.admin,
event.params.token,
event.block,
null
BigInt.fromI32(0)
);

_createAccountTokenSnapshotLogEntity(
Expand Down Expand Up @@ -131,19 +131,19 @@ export function handlePoolConnectionUpdated(
}
}

pool.save();
poolMember.save();

// Update Token Stats Streamed Until Updated At
updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block);
// Update ATS Balance and Streamed Until Updated At
updateATSStreamedAndBalanceUntilUpdatedAt(
event.params.account,
event.params.token,
event.block,
null
BigInt.fromI32(0)
);

pool.save();
poolMember.save();

const isConnecting = event.params.connected;

// there is no concept of revoking in GDA, but in the subgraph
Expand Down Expand Up @@ -500,6 +500,7 @@ function _createFlowDistributionUpdatedEntity(
ev.poolDistributor = poolDistributorId;
ev.totalUnits = totalUnits;
ev.userData = event.params.userData;
// TODO: Why not have data about buffer here?

ev.save();

Expand Down
16 changes: 8 additions & 8 deletions packages/subgraph/src/mappings/idav1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function handleIndexCreated(event: IndexCreated): void {
event.params.publisher,
event.params.token,
event.block,
null // will do RPC if any units exist anyways (balance isn't impacted by index creation)
BigInt.fromI32(0) // will do RPC if any units exist anyways (balance isn't impacted by index creation)
);

_createAccountTokenSnapshotLogEntity(
Expand Down Expand Up @@ -280,7 +280,7 @@ export function handleSubscriptionApproved(event: SubscriptionApproved): void {
event.params.publisher,
event.params.token,
event.block,
null // will do RPC if any units exist anyways
BigInt.fromI32(0)
);
_createAccountTokenSnapshotLogEntity(
event,
Expand Down Expand Up @@ -365,13 +365,13 @@ export function handleSubscriptionDistributionClaimed(
event.params.publisher,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
BigInt.fromI32(0)
);
updateATSStreamedAndBalanceUntilUpdatedAt(
event.params.subscriber,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
event.params.amount
);
_createAccountTokenSnapshotLogEntity(
event,
Expand Down Expand Up @@ -445,7 +445,7 @@ export function handleSubscriptionRevoked(event: SubscriptionRevoked): void {
event.params.subscriber,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
balanceDelta
);

updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block);
Expand All @@ -467,7 +467,7 @@ export function handleSubscriptionRevoked(event: SubscriptionRevoked): void {
event.params.publisher,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
BigInt.fromI32(0)
);

// occurs on revoke or delete
Expand Down Expand Up @@ -563,13 +563,13 @@ export function handleSubscriptionUnitsUpdated(
event.params.publisher,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
BigInt.fromI32(0)
);
updateATSStreamedAndBalanceUntilUpdatedAt(
event.params.subscriber,
event.params.token,
event.block,
null // will do RPC call if they have sub w/ units
balanceDelta
);

updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block);
Expand Down
8 changes: 4 additions & 4 deletions packages/subgraph/src/mappings/superToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function handleTokenUpgraded(event: TokenUpgraded): void {
event.params.account,
event.address,
event.block,
null // will always do final RPC - override accounting done in handleTransfer
event.params.amount
);
updateTokenStatsStreamedUntilUpdatedAt(event.address, event.block);
_createAccountTokenSnapshotLogEntity(
Expand Down Expand Up @@ -132,7 +132,7 @@ export function handleTokenDowngraded(event: TokenDowngraded): void {
event.params.account,
event.address,
event.block,
null // will always do final RPC - override accounting done in handleTransfer
event.params.amount.times(BigInt.fromI32(-1))
);
updateTokenStatsStreamedUntilUpdatedAt(event.address, event.block);
_createAccountTokenSnapshotLogEntity(
Expand Down Expand Up @@ -161,13 +161,13 @@ export function handleTransfer(event: Transfer): void {
event.params.to,
event.address,
event.block,
null // manual accounting (overridden in upgrade/downgrade)
event.params.value
);
updateATSStreamedAndBalanceUntilUpdatedAt(
event.params.from,
event.address,
event.block,
null // manual accounting (overridden in upgrade/downgrade)
event.params.value.times(BigInt.fromI32(-1))
);
updateTokenStatsStreamedUntilUpdatedAt(tokenId, event.block);

Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/src/mappings/superfluidPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function handleDistributionClaimed(event: DistributionClaimed): void {
_createTokenStatisticLogEntity(event, token, eventName);

// Update ATS
updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, token, event.block, null);
updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, token, event.block, event.params.claimedAmount);
_createAccountTokenSnapshotLogEntity(event, event.params.member, token, eventName);

// Create Event Entity
Expand Down Expand Up @@ -147,7 +147,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void {
updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block);
_createTokenStatisticLogEntity(event, event.params.token, eventName);

updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, event.params.token, event.block, null);
updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, event.params.token, event.block, BigInt.fromI32(0));
_createAccountTokenSnapshotLogEntity(event, event.params.member, event.params.token, eventName);
}

Expand Down

0 comments on commit 41f6e67

Please sign in to comment.