From 71f8ff18ecd967b7689bf398b8d508ff1bb34056 Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Mon, 29 Jan 2024 16:37:54 +0200 Subject: [PATCH] removed unused fields (mostly related to GDA inflows), fix possible overflow in updatePoolMemberTotalAmountUntilUpdatedAtFields --- packages/subgraph/schema.graphql | 117 ++---------------- packages/subgraph/src/mappingHelpers.ts | 157 +++--------------------- packages/subgraph/src/mappings/cfav1.ts | 1 - packages/subgraph/src/utils.ts | 2 +- 4 files changed, 29 insertions(+), 248 deletions(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index f8e8c990c6..2ea2e086a4 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -2281,20 +2281,11 @@ type AccountTokenSnapshot @entity { """ activeGDAOutgoingStreamCount: Int! - """ - The count of active incoming streams to this account for all agreements. - """ - activeIncomingStreamCount: Int! - """ The count of active incoming streams to this account for the CFA. + GDA incoming streams are *NOT* counted here. """ - activeCFAIncomingStreamCount: Int! - - """ - The count of active incoming streams to this account for the GDA. - """ - activeGDAIncomingStreamCount: Int! + activeIncomingStreamCount: Int! """ The count of closed streams by `account`, both incoming and outgoing for all agreements. @@ -2326,20 +2317,11 @@ type AccountTokenSnapshot @entity { """ inactiveGDAOutgoingStreamCount: Int! - """ - The count of closed incoming streams by `account` for all agreements. - """ - inactiveIncomingStreamCount: Int! - """ The count of closed incoming streams by `account` for the CFA. + Close incoming GDA streams are *NOT* counted here. """ - inactiveCFAIncomingStreamCount: Int! - - """ - The count of closed incoming streams by `account` for the GDA. - """ - inactiveGDAIncomingStreamCount: Int! + inactiveIncomingStreamCount: Int! """ The current (as of updatedAt) number of subscriptions with units allocated to them tied to this `account`. @@ -2384,6 +2366,7 @@ type AccountTokenSnapshot @entity { """ The total net flow rate of the `account` as of `updatedAtTimestamp`/`updatedAtBlock` for all flow agreements. This can be obtained by: `totalInflowRate - totalOutflowRate`. + NOTE: this property will NOT be 100% accurate all the time for receivers of GDA flows. """ totalNetFlowRate: BigInt! @@ -2392,25 +2375,11 @@ type AccountTokenSnapshot @entity { """ totalCFANetFlowRate: BigInt! - """ - The total net flow rate of the `account` as of `updatedAtTimestamp`/`updatedAtBlock` for the GDA. - """ - totalGDANetFlowRate: BigInt! - - """ - The total inflow rate (receive flowRate per second) of the `account` for all flow agreements. - """ - totalInflowRate: BigInt! - """ The total inflow rate (receive flowRate per second) of the `account` for the CFA. + GDA inflow rate is *NOT* included here. """ - totalCFAInflowRate: BigInt! - - """ - The total inflow rate (receive flowRate per second) of the `account` for the GDA. - """ - totalGDAInflowRate: BigInt! + totalInflowRate: BigInt! """ The total outflow rate (send flowrate per second) of the `account` for all flow agreements. @@ -2427,20 +2396,10 @@ type AccountTokenSnapshot @entity { """ totalGDAOutflowRate: BigInt! - """ - The total amount of `token` streamed into this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for all flow agreements. - """ - totalAmountStreamedInUntilUpdatedAt: BigInt! - """ The total amount of `token` streamed into this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for the CFA. """ - totalCFAAmountStreamedInUntilUpdatedAt: BigInt! - - """ - The total amount of `token` streamed into this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for the GDA. - """ - totalGDAAmountStreamedInUntilUpdatedAt: BigInt! + totalAmountStreamedInUntilUpdatedAt: BigInt! """ The total amount of `token` streamed from this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for all flow agreements. @@ -2467,11 +2426,6 @@ type AccountTokenSnapshot @entity { """ totalCFAAmountStreamedUntilUpdatedAt: BigInt! - """ - The total amount of `token` streamed through this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for the GDA. - """ - totalGDAAmountStreamedUntilUpdatedAt: BigInt! - """ The total amount of `token` this `account` has transferred. """ @@ -2538,16 +2492,6 @@ type AccountTokenSnapshotLog @entity { """ activeIncomingStreamCount: Int! - """ - The count of active incoming streams to this account for the CFA. - """ - activeCFAIncomingStreamCount: Int! - - """ - The count of active incoming streams to this account for the GDA. - """ - activeGDAIncomingStreamCount: Int! - """ The current (as of timestamp) count of closed streams for all agreements. """ @@ -2578,20 +2522,11 @@ type AccountTokenSnapshotLog @entity { """ inactiveGDAOutgoingStreamCount: Int! - """ - The count of closed incoming streams by `account` for all agreements. - """ - inactiveIncomingStreamCount: Int! - """ The count of closed incoming streams by `account` for the CFA. + Close incoming GDA streams are *NOT* counted here. """ - inactiveCFAIncomingStreamCount: Int! - - """ - The count of closed incoming streams by `account` for the GDA. - """ - inactiveGDAIncomingStreamCount: Int! + inactiveIncomingStreamCount: Int! """ The current (as of timestamp) number of subscriptions with units allocated to them tied to this `account`. @@ -2641,31 +2576,14 @@ type AccountTokenSnapshotLog @entity { """ The total (as of timestamp) net flow rate of the `account` as of `timestamp`/`block` for the CFA. - This can be obtained by: `totalCFAInflowRate - totalCFAOutflowRate` """ totalCFANetFlowRate: BigInt! - """ - The total (as of timestamp) net flow rate of the `account` as of `timestamp`/`block` for the GDA. - This can be obtained by: `totalGDAInflowRate - totalGDAOutflowRate` - """ - totalGDANetFlowRate: BigInt! - """ The total (as of timestamp) inflow rate (receive flowRate per second) of the `account`. """ totalInflowRate: BigInt! - """ - The total (as of timestamp) inflow rate (receive flowRate per second) of the `account` for the CFA. - """ - totalCFAInflowRate: BigInt! - - """ - The total (as of timestamp) inflow rate (receive flowRate per second) of the `account` for the GDA. - """ - totalGDAInflowRate: BigInt! - """ The total (as of timestamp) outflow rate (send flowrate per second) of the `account`. """ @@ -2686,16 +2604,6 @@ type AccountTokenSnapshotLog @entity { """ totalAmountStreamedIn: BigInt! - """ - The total (as of timestamp) amount of `token` streamed into this `account` until the `timestamp`/`block` for the CFA. - """ - totalCFAAmountStreamedIn: BigInt! - - """ - The total (as of timestamp) amount of `token` streamed into this `account` until the `timestamp`/`block` for the GDA. - """ - totalGDAAmountStreamedIn: BigInt! - """ The total (as of timestamp) amount of `token` streamed from this `account` until the `timestamp`/`block`. """ @@ -2857,11 +2765,6 @@ type TokenStatistic @entity { """ totalCFAAmountStreamedUntilUpdatedAt: BigInt! - """ - The all-time total amount streamed (outflows) until the `updatedAtTimestamp`/`updatedAtBlock` for the GDA. - """ - totalGDAAmountStreamedUntilUpdatedAt: BigInt! - """ The all-time total amount transferred until the `updatedAtTimestamp`/`updatedAtBlock`. """ diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index e0183b4908..4cc6fe07aa 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -37,6 +37,7 @@ import { getPoolDistributorID, getActiveStreamsDelta, getClosedStreamsDelta, + MAX_UINT256, } from "./utils"; import { SuperToken as SuperTokenTemplate } from "../generated/templates"; import { ISuperToken as SuperToken } from "../generated/templates/SuperToken/ISuperToken"; @@ -646,14 +647,10 @@ if (accountTokenSnapshot == null) { accountTokenSnapshot.totalCFANumberOfActiveStreams = 0; accountTokenSnapshot.totalGDANumberOfActiveStreams = 0; accountTokenSnapshot.activeIncomingStreamCount = 0; - accountTokenSnapshot.activeCFAIncomingStreamCount = 0; - accountTokenSnapshot.activeGDAIncomingStreamCount = 0; accountTokenSnapshot.activeOutgoingStreamCount = 0; accountTokenSnapshot.activeCFAOutgoingStreamCount = 0; accountTokenSnapshot.activeGDAOutgoingStreamCount = 0; accountTokenSnapshot.inactiveIncomingStreamCount = 0; - accountTokenSnapshot.inactiveCFAIncomingStreamCount = 0; - accountTokenSnapshot.inactiveGDAIncomingStreamCount = 0; accountTokenSnapshot.inactiveOutgoingStreamCount = 0; accountTokenSnapshot.inactiveCFAOutgoingStreamCount = 0; accountTokenSnapshot.inactiveGDAOutgoingStreamCount = 0; @@ -668,18 +665,11 @@ if (accountTokenSnapshot == null) { accountTokenSnapshot.balanceUntilUpdatedAt = BIG_INT_ZERO; accountTokenSnapshot.totalNetFlowRate = BIG_INT_ZERO; accountTokenSnapshot.totalCFANetFlowRate = BIG_INT_ZERO; - accountTokenSnapshot.totalGDANetFlowRate = BIG_INT_ZERO; accountTokenSnapshot.totalInflowRate = BIG_INT_ZERO; - accountTokenSnapshot.totalCFAInflowRate = BIG_INT_ZERO; - accountTokenSnapshot.totalGDAInflowRate = BIG_INT_ZERO; accountTokenSnapshot.totalOutflowRate = BIG_INT_ZERO; accountTokenSnapshot.totalCFAOutflowRate = BIG_INT_ZERO; accountTokenSnapshot.totalGDAOutflowRate = BIG_INT_ZERO; accountTokenSnapshot.totalAmountStreamedInUntilUpdatedAt = BIG_INT_ZERO; - accountTokenSnapshot.totalCFAAmountStreamedInUntilUpdatedAt = - BIG_INT_ZERO; - accountTokenSnapshot.totalGDAAmountStreamedInUntilUpdatedAt = - BIG_INT_ZERO; accountTokenSnapshot.totalAmountStreamedOutUntilUpdatedAt = BIG_INT_ZERO; accountTokenSnapshot.totalCFAAmountStreamedOutUntilUpdatedAt = @@ -689,8 +679,6 @@ if (accountTokenSnapshot == null) { accountTokenSnapshot.totalAmountStreamedUntilUpdatedAt = BIG_INT_ZERO; accountTokenSnapshot.totalCFAAmountStreamedUntilUpdatedAt = BIG_INT_ZERO; - accountTokenSnapshot.totalGDAAmountStreamedUntilUpdatedAt = - BIG_INT_ZERO; accountTokenSnapshot.totalAmountTransferredUntilUpdatedAt = BIG_INT_ZERO; accountTokenSnapshot.totalDeposit = BIG_INT_ZERO; @@ -739,8 +727,6 @@ export function _createAccountTokenSnapshotLogEntity( atsLog.totalCFANumberOfActiveStreams = ats.totalCFANumberOfActiveStreams; atsLog.totalGDANumberOfActiveStreams = ats.totalGDANumberOfActiveStreams; atsLog.activeIncomingStreamCount = ats.activeIncomingStreamCount; - atsLog.activeCFAIncomingStreamCount = ats.activeCFAIncomingStreamCount; - atsLog.activeGDAIncomingStreamCount = ats.activeGDAIncomingStreamCount; atsLog.activeOutgoingStreamCount = ats.activeOutgoingStreamCount; atsLog.activeCFAOutgoingStreamCount = ats.activeCFAOutgoingStreamCount; atsLog.activeGDAOutgoingStreamCount = ats.activeGDAOutgoingStreamCount; @@ -748,8 +734,6 @@ export function _createAccountTokenSnapshotLogEntity( atsLog.totalCFANumberOfClosedStreams = ats.totalCFANumberOfClosedStreams; atsLog.totalGDANumberOfClosedStreams = ats.totalGDANumberOfClosedStreams; atsLog.inactiveIncomingStreamCount = ats.inactiveIncomingStreamCount; - atsLog.inactiveCFAIncomingStreamCount = ats.inactiveCFAIncomingStreamCount; - atsLog.inactiveGDAIncomingStreamCount = ats.inactiveGDAIncomingStreamCount; atsLog.inactiveOutgoingStreamCount = ats.inactiveOutgoingStreamCount; atsLog.inactiveCFAOutgoingStreamCount = ats.inactiveCFAOutgoingStreamCount; atsLog.inactiveGDAOutgoingStreamCount = ats.inactiveGDAOutgoingStreamCount; @@ -760,22 +744,14 @@ export function _createAccountTokenSnapshotLogEntity( atsLog.balance = ats.balanceUntilUpdatedAt; atsLog.totalNetFlowRate = ats.totalNetFlowRate; atsLog.totalCFANetFlowRate = ats.totalCFANetFlowRate; - atsLog.totalGDANetFlowRate = ats.totalGDANetFlowRate; atsLog.totalInflowRate = ats.totalInflowRate; - atsLog.totalCFAInflowRate = ats.totalCFAInflowRate; - atsLog.totalGDAInflowRate = ats.totalGDAInflowRate; atsLog.totalOutflowRate = ats.totalOutflowRate; atsLog.totalCFAOutflowRate = ats.totalCFAOutflowRate; atsLog.totalGDAOutflowRate = ats.totalGDAOutflowRate; atsLog.totalAmountStreamed = ats.totalAmountStreamedUntilUpdatedAt; atsLog.totalCFAAmountStreamed = ats.totalCFAAmountStreamedUntilUpdatedAt; - atsLog.totalGDAAmountStreamed = ats.totalGDAAmountStreamedUntilUpdatedAt; atsLog.totalAmountStreamedIn = ats.totalAmountStreamedInUntilUpdatedAt; - atsLog.totalCFAAmountStreamedIn = - ats.totalCFAAmountStreamedInUntilUpdatedAt; atsLog.totalAmountStreamedOut = ats.totalAmountStreamedOutUntilUpdatedAt; - atsLog.totalGDAAmountStreamedIn = - ats.totalGDAAmountStreamedInUntilUpdatedAt; atsLog.totalCFAAmountStreamedOut = ats.totalCFAAmountStreamedOutUntilUpdatedAt; atsLog.totalGDAAmountStreamedOut = @@ -821,7 +797,6 @@ export function getOrInitTokenStatistic( tokenStatistic.totalNumberOfAccounts = 0; tokenStatistic.totalAmountStreamedUntilUpdatedAt = BIG_INT_ZERO; tokenStatistic.totalCFAAmountStreamedUntilUpdatedAt = BIG_INT_ZERO; - tokenStatistic.totalGDAAmountStreamedUntilUpdatedAt = BIG_INT_ZERO; tokenStatistic.totalAmountTransferredUntilUpdatedAt = BIG_INT_ZERO; tokenStatistic.totalAmountDistributedUntilUpdatedAt = BIG_INT_ZERO; tokenStatistic.totalSupply = BIG_INT_ZERO; @@ -891,8 +866,6 @@ export function _createTokenStatisticLogEntity( tokenStatistic.totalAmountStreamedUntilUpdatedAt; tokenStatisticLog.totalCFAAmountStreamed = tokenStatistic.totalCFAAmountStreamedUntilUpdatedAt; - tokenStatisticLog.totalGDAAmountStreamed = - tokenStatistic.totalGDAAmountStreamedUntilUpdatedAt; tokenStatisticLog.totalAmountTransferred = tokenStatistic.totalAmountTransferredUntilUpdatedAt; tokenStatisticLog.totalAmountDistributed = @@ -1139,12 +1112,6 @@ export function updateATSStreamedAndBalanceUntilUpdatedAt( accountTokenSnapshot.updatedAtTimestamp, accountTokenSnapshot.totalCFANetFlowRate ); - const totalCFAAmountStreamedInSinceLastUpdatedAt = - getAmountStreamedSinceLastUpdatedAt( - block.timestamp, - accountTokenSnapshot.updatedAtTimestamp, - accountTokenSnapshot.totalCFAInflowRate - ); const totalCFAAmountStreamedOutSinceLastUpdatedAt = getAmountStreamedSinceLastUpdatedAt( block.timestamp, @@ -1158,12 +1125,6 @@ export function updateATSStreamedAndBalanceUntilUpdatedAt( totalCFAAmountStreamedSinceLastUpdatedAt ); - // update the totalCFAStreamedUntilUpdatedAt (in) - accountTokenSnapshot.totalCFAAmountStreamedInUntilUpdatedAt = - accountTokenSnapshot.totalCFAAmountStreamedInUntilUpdatedAt.plus( - totalCFAAmountStreamedInSinceLastUpdatedAt - ); - // update the totalCFAStreamedUntilUpdatedAt (out) accountTokenSnapshot.totalCFAAmountStreamedOutUntilUpdatedAt = accountTokenSnapshot.totalCFAAmountStreamedOutUntilUpdatedAt.plus( @@ -1171,18 +1132,6 @@ export function updateATSStreamedAndBalanceUntilUpdatedAt( ); //////////////// GDA streamed amounts //////////////// - const totalGDAAmountStreamedSinceLastUpdatedAt = - getAmountStreamedSinceLastUpdatedAt( - block.timestamp, - accountTokenSnapshot.updatedAtTimestamp, - accountTokenSnapshot.totalGDANetFlowRate - ); - const totalGDAAmountStreamedInSinceLastUpdatedAt = - getAmountStreamedSinceLastUpdatedAt( - block.timestamp, - accountTokenSnapshot.updatedAtTimestamp, - accountTokenSnapshot.totalGDAInflowRate - ); const totalGDAAmountStreamedOutSinceLastUpdatedAt = getAmountStreamedSinceLastUpdatedAt( block.timestamp, @@ -1190,18 +1139,6 @@ export function updateATSStreamedAndBalanceUntilUpdatedAt( accountTokenSnapshot.totalGDAOutflowRate ); - // update the totalGDAStreamedUntilUpdatedAt (net) - accountTokenSnapshot.totalGDAAmountStreamedUntilUpdatedAt = - accountTokenSnapshot.totalGDAAmountStreamedUntilUpdatedAt.plus( - totalGDAAmountStreamedSinceLastUpdatedAt - ); - - // update the totalGDAStreamedUntilUpdatedAt (in) - accountTokenSnapshot.totalGDAAmountStreamedInUntilUpdatedAt = - accountTokenSnapshot.totalGDAAmountStreamedInUntilUpdatedAt.plus( - totalGDAAmountStreamedInSinceLastUpdatedAt - ); - // update the totalGDAStreamedUntilUpdatedAt (out) accountTokenSnapshot.totalGDAAmountStreamedOutUntilUpdatedAt = accountTokenSnapshot.totalGDAAmountStreamedOutUntilUpdatedAt.plus( @@ -1276,18 +1213,6 @@ export function updateTokenStatsStreamedUntilUpdatedAt( cfaAmountStreamedSinceLastUpdatedAt ); - //// GDA streamed amounts //// - const gdaAmountStreamedSinceLastUpdatedAt = - getAmountStreamedSinceLastUpdatedAt( - block.timestamp, - tokenStats.updatedAtTimestamp, - tokenStats.totalGDAOutflowRate - ); - tokenStats.totalGDAAmountStreamedUntilUpdatedAt = - tokenStats.totalGDAAmountStreamedUntilUpdatedAt.plus( - gdaAmountStreamedSinceLastUpdatedAt - ); - tokenStats.updatedAtTimestamp = block.timestamp; tokenStats.updatedAtBlockNumber = block.number; tokenStats.save(); @@ -1446,9 +1371,6 @@ export function updateSenderATSStreamData( senderATS.totalCFADeposit = senderATS.totalCFADeposit.plus(depositDelta); } else { - senderATS.totalGDANetFlowRate = - senderATS.totalGDANetFlowRate.minus(flowRateDelta); - // the outflow rate should never go below 0. senderATS.totalGDAOutflowRate = senderATS.totalGDAOutflowRate .plus(flowRateDelta) @@ -1488,7 +1410,6 @@ export function updateReceiverATSStreamData( flowRateDelta: BigInt, isCreate: boolean, isDelete: boolean, - isCFA: boolean, block: ethereum.Block ): void { const totalNumberOfActiveStreamsDelta = getActiveStreamsDelta( @@ -1531,55 +1452,17 @@ export function updateReceiverATSStreamData( receiverATS.maybeCriticalAtTimestamp ); - if (isCFA) { - receiverATS.totalCFANetFlowRate = - receiverATS.totalCFANetFlowRate.plus(flowRateDelta); - - // the inflow rate should never go below 0. - receiverATS.totalCFAInflowRate = receiverATS.totalCFAInflowRate - .plus(flowRateDelta) - .lt(BIG_INT_ZERO) - ? newFlowRate - : receiverATS.totalCFAInflowRate.plus(flowRateDelta); - - receiverATS.totalCFANumberOfActiveStreams = - receiverATS.totalCFANumberOfActiveStreams + - totalNumberOfActiveStreamsDelta; - receiverATS.activeCFAIncomingStreamCount = - receiverATS.activeCFAIncomingStreamCount + - totalNumberOfActiveStreamsDelta; - receiverATS.inactiveCFAIncomingStreamCount = - receiverATS.inactiveCFAIncomingStreamCount + - totalNumberOfClosedStreamsDelta; + receiverATS.totalCFANetFlowRate = + receiverATS.totalCFANetFlowRate.plus(flowRateDelta); - receiverATS.totalCFANumberOfClosedStreams = - receiverATS.totalCFANumberOfClosedStreams + - totalNumberOfClosedStreamsDelta; - } else { - receiverATS.totalGDANetFlowRate = - receiverATS.totalGDANetFlowRate.plus(flowRateDelta); - - // the inflow rate should never go below 0. - receiverATS.totalGDAInflowRate = receiverATS.totalGDAInflowRate - .plus(flowRateDelta) - .lt(BIG_INT_ZERO) - ? newFlowRate - : receiverATS.totalGDAInflowRate.plus(flowRateDelta); - - receiverATS.totalGDANumberOfActiveStreams = - receiverATS.totalGDANumberOfActiveStreams + - totalNumberOfActiveStreamsDelta; - receiverATS.activeGDAIncomingStreamCount = - receiverATS.activeGDAIncomingStreamCount + - totalNumberOfActiveStreamsDelta; - receiverATS.inactiveGDAIncomingStreamCount = - receiverATS.inactiveGDAIncomingStreamCount + - totalNumberOfClosedStreamsDelta; + receiverATS.totalCFANumberOfActiveStreams = + receiverATS.totalCFANumberOfActiveStreams + + totalNumberOfActiveStreamsDelta; + totalNumberOfClosedStreamsDelta; - receiverATS.totalGDANumberOfClosedStreams = - receiverATS.totalGDANumberOfClosedStreams + - totalNumberOfClosedStreamsDelta; - } + receiverATS.totalCFANumberOfClosedStreams = + receiverATS.totalCFANumberOfClosedStreams + + totalNumberOfClosedStreamsDelta; receiverATS.save(); } @@ -1625,18 +1508,14 @@ export function updatePoolMemberTotalAmountUntilUpdatedAtFields(pool: Pool, pool // if the pool has any units, we calculate the delta // otherwise the delta is going to be 0 if (!pool.totalUnits.equals(BIG_INT_ZERO)) { - try { - amountReceivedDelta = pool.totalAmountDistributedUntilUpdatedAt - .minus(poolMember.poolTotalAmountDistributedUntilUpdatedAt) - .times(poolMember.units) - .div(pool.totalUnits); - } catch (err) { - // we divide here first before multiplying in case the try block fails - // due to an overflow - amountReceivedDelta = pool.totalAmountDistributedUntilUpdatedAt - .minus(poolMember.poolTotalAmountDistributedUntilUpdatedAt) - .div(pool.totalUnits) - .times(poolMember.units); + const distributedAmountDelta = pool.totalAmountDistributedUntilUpdatedAt + .minus(poolMember.poolTotalAmountDistributedUntilUpdatedAt); + + const isSafeToMultiplyWithoutOverflow = MAX_UINT256.div(poolMember.units).gt(distributedAmountDelta); + if (isSafeToMultiplyWithoutOverflow) { + amountReceivedDelta = distributedAmountDelta.times(poolMember.units).div(pool.totalUnits); + } else { + amountReceivedDelta = distributedAmountDelta.div(pool.totalUnits).times(poolMember.units); } } poolMember.totalAmountReceivedUntilUpdatedAt = diff --git a/packages/subgraph/src/mappings/cfav1.ts b/packages/subgraph/src/mappings/cfav1.ts index fa548d6091..6fd69406bd 100644 --- a/packages/subgraph/src/mappings/cfav1.ts +++ b/packages/subgraph/src/mappings/cfav1.ts @@ -163,7 +163,6 @@ export function handleFlowUpdated(event: FlowUpdated): void { flowRateDelta, isCreate, isDelete, - true, event.block ); diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts index 1d11509bc2..859f213a1a 100644 --- a/packages/subgraph/src/utils.ts +++ b/packages/subgraph/src/utils.ts @@ -25,7 +25,7 @@ export const ZERO_ADDRESS = Address.zero(); export const MAX_FLOW_RATE = BigInt.fromI32(2).pow(95).minus(BigInt.fromI32(1)); export const ORDER_MULTIPLIER = BigInt.fromI32(10000); export const MAX_SAFE_SECONDS = BigInt.fromI64(8640000000000); //In seconds, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_ecmascript_epoch_and_timestamps - +export const MAX_UINT256 = BigInt.fromString("115792089237316195423570985008687907853269984665640564039457584007913129639935"); /************************************************************************** * Convenience Conversions *************************************************************************/