diff --git a/packages/subgraph/package.json b/packages/subgraph/package.json index b61a4dd2f6..9dc34a4401 100644 --- a/packages/subgraph/package.json +++ b/packages/subgraph/package.json @@ -59,6 +59,7 @@ "generate-sf-meta": "./tasks/getSFMeta.sh", "generate-sf-meta-local": "COMMIT_HASH=local CONFIGURATION=local BRANCH=local TAG=local ./tasks/getSFMeta.sh", "check-updates": "ncu --target minor --dep prod,dev", - "cloc": "cloc src" + "cloc": "cloc src", + "example:deploy-to-goldsky": "GOLDSKY_API_KEY=${YOUR_API_KEY} bash ./tasks/deploy.sh -o goldsky -n ${NETWORK} -r ${TAG} -v ${VERSION}" } } diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index a13d7739cb..e8e4d40c3d 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -498,7 +498,7 @@ export function getOrInitPool(event: ethereum.Event, poolId: string): Pool { return pool; } -export function updatePoolTotalAmountFlowedAndDistributed( +export function updatePoolParticleAndTotalAmountFlowedAndDistributed( event: ethereum.Event, pool: Pool ): Pool { @@ -513,6 +513,8 @@ export function updatePoolTotalAmountFlowedAndDistributed( pool.totalAmountDistributedUntilUpdatedAt.plus( amountFlowedSinceLastUpdate ); + + settlePoolParticle(pool, event.block); pool.save(); @@ -1535,7 +1537,6 @@ export function syncPoolMemberParticle(pool: Pool, poolMember: PoolMember): Pool } export function settlePDPoolMemberMU(pool: Pool, poolMember: PoolMember, block: ethereum.Block): void { - pool = settlePoolParticle(pool, block); poolMember.totalAmountReceivedUntilUpdatedAt = monetaryUnitPoolMemberRTB(pool, poolMember, block.timestamp); poolMember = syncPoolMemberParticle(pool, poolMember); } diff --git a/packages/subgraph/src/mappings/gdav1.ts b/packages/subgraph/src/mappings/gdav1.ts index 19762416f7..846bd58af2 100644 --- a/packages/subgraph/src/mappings/gdav1.ts +++ b/packages/subgraph/src/mappings/gdav1.ts @@ -22,11 +22,10 @@ import { getOrInitOrUpdatePoolMember, getOrInitTokenStatistic, settlePDPoolMemberMU, - settlePoolParticle, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, updatePoolDistributorTotalAmountFlowedAndDistributed, - updatePoolTotalAmountFlowedAndDistributed, + updatePoolParticleAndTotalAmountFlowedAndDistributed, updateSenderATSStreamData, updateTokenStatisticStreamData, updateTokenStatsStreamedUntilUpdatedAt, @@ -101,7 +100,7 @@ export function handlePoolConnectionUpdated( // Update Pool Entity let pool = getOrInitPool(event, event.params.pool.toHex()); // @note we modify pool and poolMember here in memory, but do not save - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); settlePDPoolMemberMU(pool, poolMember, event.block); if (poolMember.units.gt(BIG_INT_ZERO)) { if (memberConnectedStatusUpdated) { @@ -194,7 +193,7 @@ export function handleBufferAdjusted(event: BufferAdjusted): void { // Update Pool let pool = getOrInitPool(event, event.params.pool.toHex()); - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); pool.totalBuffer = pool.totalBuffer.plus(event.params.bufferDelta); pool.save(); @@ -233,8 +232,7 @@ export function handleFlowDistributionUpdated( // @note that we are duplicating update of updatedAtTimestamp/BlockNumber here // in the two functions - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); - pool = settlePoolParticle(pool, event.block); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); pool.perUnitFlowRate = divideOrZero(event.params.newDistributorToPoolFlowRate, pool.totalUnits); pool.flowRate = event.params.newTotalDistributionFlowRate; pool.adjustmentFlowRate = event.params.adjustmentFlowRate; @@ -321,8 +319,7 @@ export function handleInstantDistributionUpdated( // @note that we are duplicating update of updatedAtTimestamp/BlockNumber here // in the two functions - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); - pool = settlePoolParticle(pool, event.block); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); // @note a speculations on what needs to be done pool.perUnitSettledValue = pool.perUnitSettledValue.plus(divideOrZero(event.params.actualAmount, pool.totalUnits)); const previousTotalAmountDistributed = diff --git a/packages/subgraph/src/mappings/superfluidPool.ts b/packages/subgraph/src/mappings/superfluidPool.ts index f4740745c2..bdbfb46ce1 100644 --- a/packages/subgraph/src/mappings/superfluidPool.ts +++ b/packages/subgraph/src/mappings/superfluidPool.ts @@ -12,7 +12,7 @@ import { settlePDPoolMemberMU, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, - updatePoolTotalAmountFlowedAndDistributed, + updatePoolParticleAndTotalAmountFlowedAndDistributed, updateTokenStatsStreamedUntilUpdatedAt, } from "../mappingHelpers"; import { BIG_INT_ZERO, createEventID, initializeEventEntity, membershipWithUnitsExists } from "../utils"; @@ -28,7 +28,7 @@ export function handleDistributionClaimed(event: DistributionClaimed): void { poolMember.totalAmountClaimed = event.params.totalClaimed; // settle pool and pool member - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); settlePDPoolMemberMU(pool, poolMember, event.block); // Update PoolMember @@ -58,7 +58,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { const unitsDelta = event.params.newUnits.minus(previousUnits); const newTotalUnits = pool.totalUnits.plus(unitsDelta); - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = updatePoolParticleAndTotalAmountFlowedAndDistributed(event, pool); settlePDPoolMemberMU(pool, poolMember, event.block); const existingPoolFlowRate = pool.perUnitFlowRate.times(pool.totalUnits); diff --git a/packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts b/packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts index fdd04955af..b6171ca8a1 100644 --- a/packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts +++ b/packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts @@ -242,10 +242,6 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", const pool = Pool.load(poolAddress.toHexString()); - if (pool) { - pool.updatedAtTimestamp = poolCreatedEvent.block.timestamp; - } - // ## Arrange PoolMember 1 const aliceAddress = Address.fromString(alice_); const aliceId = getPoolMemberID(poolAddress, aliceAddress); @@ -262,10 +258,6 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", handleMemberUnitsUpdated(aliceCreatedEvent); // # First flow rate - if (pool) { - pool.updatedAtTimestamp = aliceCreatedEvent.block.timestamp; - } - const firstFlowRateEvent = createFlowDistributionUpdatedEvent( superTokenAddress, poolAddress.toHexString(), @@ -337,10 +329,6 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, bobAddress.toHexString(), createBobEvent.block.timestamp); handleMemberUnitsUpdated(createBobEvent); - - if (pool) { - pool.updatedAtTimestamp = createBobEvent.block.timestamp; - } assert.fieldEquals( "Pool", @@ -374,10 +362,6 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, poolAdminAndDistributorAddress.toHexString(), secondFlowRateEvent.block.timestamp); handleFlowDistributionUpdated(secondFlowRateEvent); - if (pool) { - pool.updatedAtTimestamp = secondFlowRateEvent.block.timestamp; - } - assert.fieldEquals( "Pool", poolAddress.toHexString(),