From 58a4407a9fbe6a562ad9552e1668f1fa37b75443 Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Fri, 23 Feb 2024 16:12:14 +0200 Subject: [PATCH 01/15] add gda pool subgraph entity queries --- packages/sdk-core/src/index.ts | 5 +- .../{flowOperators.ts => flowOperator.ts} | 0 .../src/subgraph/entities/pool/pool.ts | 118 ++++++++++++++++++ .../src/subgraph/entities/pool/pools.graphql | 51 ++++++++ .../poolDistributor/poolDistributor.ts | 81 ++++++++++++ .../poolDistributor/poolDistributors.graphql | 37 ++++++ .../entities/poolMember/poolMember.ts | 76 +++++++++++ .../entities/poolMember/poolMembers.graphql | 37 ++++++ .../subgraphApiSlice/endpoints/entityArgs.ts | 27 ++++ .../endpoints/entityEndpoints.ts | 18 +++ 10 files changed, 449 insertions(+), 1 deletion(-) rename packages/sdk-core/src/subgraph/entities/flowOperator/{flowOperators.ts => flowOperator.ts} (100%) create mode 100644 packages/sdk-core/src/subgraph/entities/pool/pool.ts create mode 100644 packages/sdk-core/src/subgraph/entities/pool/pools.graphql create mode 100644 packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributor.ts create mode 100644 packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributors.graphql create mode 100644 packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts create mode 100644 packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql diff --git a/packages/sdk-core/src/index.ts b/packages/sdk-core/src/index.ts index 6834a8bc16..4e12a39c19 100644 --- a/packages/sdk-core/src/index.ts +++ b/packages/sdk-core/src/index.ts @@ -52,7 +52,10 @@ export * from "./subgraph/entities/streamPeriod/streamPeriod"; export * from "./subgraph/entities/token/token"; export * from "./subgraph/entities/tokenStatistic/tokenStatistic"; export * from "./subgraph/entities/tokenStatisticLog/tokenStatisticLog"; -export * from "./subgraph/entities/flowOperator/flowOperators"; +export * from "./subgraph/entities/flowOperator/flowOperator"; +export * from "./subgraph/entities/pool/pool"; +export * from "./subgraph/entities/poolMember/poolMember"; +export * from "./subgraph/entities/poolDistributor/poolDistributor"; export * from "./subgraph/events/events"; export * from "./subgraph/events/flowUpdatedEvent"; diff --git a/packages/sdk-core/src/subgraph/entities/flowOperator/flowOperators.ts b/packages/sdk-core/src/subgraph/entities/flowOperator/flowOperator.ts similarity index 100% rename from packages/sdk-core/src/subgraph/entities/flowOperator/flowOperators.ts rename to packages/sdk-core/src/subgraph/entities/flowOperator/flowOperator.ts diff --git a/packages/sdk-core/src/subgraph/entities/pool/pool.ts b/packages/sdk-core/src/subgraph/entities/pool/pool.ts new file mode 100644 index 0000000000..6ad1fc7746 --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/pool/pool.ts @@ -0,0 +1,118 @@ +import { + Address, + BigNumber, + BlockNumber, + Timestamp, +} from "../../mappedSubgraphTypes"; +import { Pool_Filter, Pool_OrderBy } from "../../schema.generated"; +import { + RelevantAddressesIntermediate, + SubgraphListQuery, + SubgraphQueryHandler, +} from "../../subgraphQueryHandler"; + +import { + GetPoolQuery, + PoolsDocument, + PoolsQuery, + PoolsQueryVariables, +} from "./pools.generated"; + +export type PoolListQuery = SubgraphListQuery; + +export interface Pool { + id: Address; + createdAtTimestamp: Timestamp; + createdAtBlockNumber: BlockNumber; + updatedAtTimestamp: Timestamp; + updatedAtBlockNumber: BlockNumber; + totalAmountInstantlyDistributedUntilUpdatedAt: BigNumber; + totalAmountFlowedDistributedUntilUpdatedAt: BigNumber; + totalAmountDistributedUntilUpdatedAt: BigNumber; + totalUnits: BigNumber; + totalConnectedUnits: BigNumber; + totalDisconnectedUnits: BigNumber; + /** + * A member is any account which has more than 0 units in the pool. + * + */ + totalMembers: number; + /** + * A connected member is any account which has more than 0 units in the pool and is connected. + * + */ + totalConnectedMembers: number; + /** + * A disconnected member is any account which has more than 0 units in the pool and is not connected. + * + */ + totalDisconnectedMembers: number; + adjustmentFlowRate: BigNumber; + flowRate: BigNumber; + totalBuffer: BigNumber; + token: Address; + admin: Address; +} + +export type SubgraphPool = NonNullable["pool"]>; + +export const mapSubgraphGDAPool = (x: SubgraphPool): Pool => { + const mappedPool = { + ...x, + createdAtTimestamp: Number(x.createdAtTimestamp), + createdAtBlockNumber: Number(x.createdAtBlockNumber), + updatedAtTimestamp: Number(x.updatedAtTimestamp), + updatedAtBlockNumber: Number(x.updatedAtBlockNumber), + totalAmountInstantlyDistributedUntilUpdatedAt: + x.totalAmountInstantlyDistributedUntilUpdatedAt, + totalAmountFlowedDistributedUntilUpdatedAt: + x.totalAmountFlowedDistributedUntilUpdatedAt, + totalAmountDistributedUntilUpdatedAt: + x.totalAmountDistributedUntilUpdatedAt, + admin: x.admin.id, + token: x.token.id, + }; + + return mappedPool; +}; + +export class PoolQueryHandler extends SubgraphQueryHandler< + Pool, + PoolListQuery, + PoolsQuery, + PoolsQueryVariables +> { + getAddressFieldKeysFromFilter = (): { + accountKeys: (keyof Pool_Filter)[]; + tokenKeys: (keyof Pool_Filter)[]; + } => ({ + accountKeys: ["admin", "id"], + tokenKeys: ["token"], + }); + + getRelevantAddressesFromResultCore = ( + result: Pool + ): RelevantAddressesIntermediate => ({ + tokens: [result.token], + accounts: [result.admin, result.id], + }); + + mapFromSubgraphResponse = (response: PoolsQuery): Pool[] => + response.pools.map((x) => ({ + ...x, + createdAtTimestamp: Number(x.createdAtTimestamp), + createdAtBlockNumber: Number(x.createdAtBlockNumber), + updatedAtTimestamp: Number(x.updatedAtTimestamp), + updatedAtBlockNumber: Number(x.updatedAtBlockNumber), + totalAmountInstantlyDistributedUntilUpdatedAt: + x.totalAmountInstantlyDistributedUntilUpdatedAt, + totalAmountFlowedDistributedUntilUpdatedAt: + x.totalAmountFlowedDistributedUntilUpdatedAt, + totalAmountDistributedUntilUpdatedAt: + x.totalAmountDistributedUntilUpdatedAt, + admin: x.admin.id, + token: x.token.id, + })); + + requestDocument = PoolsDocument; +} diff --git a/packages/sdk-core/src/subgraph/entities/pool/pools.graphql b/packages/sdk-core/src/subgraph/entities/pool/pools.graphql new file mode 100644 index 0000000000..f40661b6d4 --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/pool/pools.graphql @@ -0,0 +1,51 @@ +query getPool($id: ID!) { + pool(id: $id) { + ...PoolPart + } +} + +query pools( + $first: Int = 10 + $orderBy: Pool_orderBy = id + $orderDirection: OrderDirection = asc + $skip: Int = 0 + $where: Pool_filter = {} + $block: Block_height +) { + pools( + first: $first + orderBy: $orderBy + orderDirection: $orderDirection + skip: $skip + where: $where + block: $block + ) { + ...PoolPart + } +} + +fragment PoolPart on Pool { + id + createdAtTimestamp + createdAtBlockNumber + updatedAtTimestamp + updatedAtBlockNumber + flowRate + totalMembers + totalUnits + totalAmountDistributedUntilUpdatedAt + adjustmentFlowRate + totalAmountFlowedDistributedUntilUpdatedAt + totalAmountInstantlyDistributedUntilUpdatedAt + totalBuffer + totalConnectedMembers + totalConnectedUnits + totalDisconnectedMembers + totalDisconnectedUnits + admin { + id + } + token { + id + } +} diff --git a/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributor.ts b/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributor.ts new file mode 100644 index 0000000000..2f8894ccd2 --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributor.ts @@ -0,0 +1,81 @@ +import { + Address, + BigNumber, + BlockNumber, + SubgraphId, + Timestamp, +} from "../../mappedSubgraphTypes"; +import { + PoolDistributor_Filter, + PoolDistributor_OrderBy, +} from "../../schema.generated"; +import { + RelevantAddressesIntermediate, + SubgraphListQuery, + SubgraphQueryHandler, +} from "../../subgraphQueryHandler"; + +import { + PoolDistributorsDocument, + PoolDistributorsQuery, + PoolDistributorsQueryVariables, +} from "./poolDistributors.generated"; + +export interface PoolDistributor { + id: SubgraphId; + createdAtTimestamp: Timestamp; + createdAtBlockNumber: BlockNumber; + updatedAtTimestamp: Timestamp; + updatedAtBlockNumber: BlockNumber; + totalBuffer: BigNumber; + totalAmountInstantlyDistributedUntilUpdatedAt: BigNumber; + totalAmountFlowedDistributedUntilUpdatedAt: BigNumber; + totalAmountDistributedUntilUpdatedAt: BigNumber; + flowRate: BigNumber; + account: Address; + pool: Address; + token: Address; +} + +export type PoolDistributorsListQuery = SubgraphListQuery< + PoolDistributor_Filter, + PoolDistributor_OrderBy +>; + +export class PoolDistributorQueryHandler extends SubgraphQueryHandler< + PoolDistributor, + PoolDistributorsListQuery, + PoolDistributorsQuery, + PoolDistributorsQueryVariables +> { + getAddressFieldKeysFromFilter = (): { + accountKeys: (keyof PoolDistributor_Filter)[]; + tokenKeys: (keyof PoolDistributor_Filter)[]; + } => ({ + accountKeys: ["account", "pool"], + tokenKeys: [], + }); + + getRelevantAddressesFromResultCore = ( + result: PoolDistributor + ): RelevantAddressesIntermediate => ({ + tokens: [result.token], + accounts: [result.account, result.pool], + }); + + mapFromSubgraphResponse = ( + response: PoolDistributorsQuery + ): PoolDistributor[] => + response.poolDistributors.map((x) => ({ + ...x, + createdAtTimestamp: Number(x.createdAtTimestamp), + createdAtBlockNumber: Number(x.createdAtBlockNumber), + updatedAtTimestamp: Number(x.updatedAtTimestamp), + updatedAtBlockNumber: Number(x.updatedAtBlockNumber), + pool: x.pool.id, + token: x.pool.token.id, + account: x.account.id, + })); + + requestDocument = PoolDistributorsDocument; +} diff --git a/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributors.graphql b/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributors.graphql new file mode 100644 index 0000000000..beed5a215b --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributors.graphql @@ -0,0 +1,37 @@ +query poolDistributors( + $first: Int = 10 + $skip: Int = 0 + $orderBy: PoolDistributor_orderBy = id + $orderDirection: OrderDirection = asc + $where: PoolDistributor_filter = {} + $block: Block_height +) { + poolDistributors( + first: $first + orderBy: $orderBy + orderDirection: $orderDirection + skip: $skip + where: $where + block: $block + ) { + createdAtTimestamp + createdAtBlockNumber + updatedAtTimestamp + updatedAtBlockNumber + totalBuffer + totalAmountInstantlyDistributedUntilUpdatedAt + totalAmountFlowedDistributedUntilUpdatedAt + totalAmountDistributedUntilUpdatedAt + id + flowRate + account { + id + } + pool { + id + token { + id + } + } + } +} diff --git a/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts b/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts new file mode 100644 index 0000000000..3b679e58e7 --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts @@ -0,0 +1,76 @@ +import { + Address, + BigNumber, + BlockNumber, + SubgraphId, + Timestamp, +} from "../../mappedSubgraphTypes"; +import { PoolMember_Filter, PoolMember_OrderBy } from "../../schema.generated"; +import { + RelevantAddressesIntermediate, + SubgraphListQuery, + SubgraphQueryHandler, +} from "../../subgraphQueryHandler"; + +import { + PoolMembersDocument, + PoolMembersQuery, + PoolMembersQueryVariables, +} from "./poolMembers.generated"; + +export interface PoolMember { + id: SubgraphId; + createdAtBlockNumber: BlockNumber; + createdAtTimestamp: Timestamp; + updatedAtTimestamp: Timestamp; + updatedAtBlockNumber: BlockNumber; + units: BigNumber; + account: Address; + isConnected: boolean; + totalAmountClaimed: BigNumber; + token: Address; + totalAmountReceivedUntilUpdatedAt: BigNumber; + poolTotalAmountDistributedUntilUpdatedAt: BigNumber; + pool: Address; +} + +export type PoolMembersListQuery = SubgraphListQuery< + PoolMember_Filter, + PoolMember_OrderBy +>; + +export class PoolMemberQueryHandler extends SubgraphQueryHandler< + PoolMember, + PoolMembersListQuery, + PoolMembersQuery, + PoolMembersQueryVariables +> { + getAddressFieldKeysFromFilter = (): { + accountKeys: (keyof PoolMember_Filter)[]; + tokenKeys: (keyof PoolMember_Filter)[]; + } => ({ + accountKeys: ["account", "pool"], + tokenKeys: [], + }); + + getRelevantAddressesFromResultCore = ( + result: PoolMember + ): RelevantAddressesIntermediate => ({ + tokens: [result.token], + accounts: [result.account, result.pool], + }); + + mapFromSubgraphResponse = (response: PoolMembersQuery): PoolMember[] => + response.poolMembers.map((x) => ({ + ...x, + account: x.account.id, + createdAtTimestamp: Number(x.createdAtTimestamp), + createdAtBlockNumber: Number(x.createdAtBlockNumber), + updatedAtTimestamp: Number(x.updatedAtTimestamp), + updatedAtBlockNumber: Number(x.updatedAtBlockNumber), + pool: x.pool.id, + token: x.pool.token.id, + })); + + requestDocument = PoolMembersDocument; +} diff --git a/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql b/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql new file mode 100644 index 0000000000..035d12f85c --- /dev/null +++ b/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql @@ -0,0 +1,37 @@ +query poolMembers( + $first: Int = 10 + $skip: Int = 0 + $orderBy: PoolMember_orderBy = id + $orderDirection: OrderDirection = asc + $where: PoolMember_filter = {} + $block: Block_height +) { + poolMembers( + first: $first + orderBy: $orderBy + orderDirection: $orderDirection + skip: $skip + where: $where + block: $block + ) { + id + createdAtTimestamp + createdAtBlockNumber + updatedAtTimestamp + updatedAtBlockNumber + units + pool { + id + token { + id + } + } + account { + id + } + isConnected + totalAmountClaimed + totalAmountReceivedUntilUpdatedAt + poolTotalAmountDistributedUntilUpdatedAt + } +} diff --git a/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityArgs.ts b/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityArgs.ts index 3aeddb1ce3..b351e97114 100644 --- a/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityArgs.ts +++ b/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityArgs.ts @@ -5,6 +5,9 @@ import { FlowOperatorListQuery, IndexListQuery, IndexSubscriptionsListQuery, + PoolDistributorsListQuery, + PoolListQuery, + PoolMembersListQuery, StreamListQuery, StreamPeriodListQuery, SubgraphGetQuery, @@ -100,3 +103,27 @@ export interface FlowOperatorQuery extends SubgraphGetQuery { export interface FlowOperatorsQuery extends FlowOperatorListQuery { chainId: number; } + +export interface PoolQuery extends SubgraphGetQuery { + chainId: number; +} + +export interface PoolsQuery extends PoolListQuery { + chainId: number; +} + +export interface PoolMemberQuery extends SubgraphGetQuery { + chainId: number; +} + +export interface PoolMembersQuery extends PoolMembersListQuery { + chainId: number; +} + +export interface PoolDistributorQuery extends SubgraphGetQuery { + chainId: number; +} + +export interface PoolDistributorsQuery extends PoolDistributorsListQuery { + chainId: number; +} diff --git a/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityEndpoints.ts b/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityEndpoints.ts index d5785d2452..666a254e84 100644 --- a/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityEndpoints.ts +++ b/packages/sdk-redux/src/reduxSlices/rtkQuery/subgraphApiSlice/endpoints/entityEndpoints.ts @@ -13,6 +13,12 @@ import { IndexSubscription, IndexSubscriptionQueryHandler, PagedResult, + Pool, + PoolDistributor, + PoolDistributorQueryHandler, + PoolMember, + PoolMemberQueryHandler, + PoolQueryHandler, RelevantAddressProviderFromFilter, RelevantAddressProviderFromResult, Stream, @@ -50,6 +56,12 @@ import { IndexQuery, IndexSubscriptionQuery, IndexSubscriptionsQuery, + PoolDistributorQuery, + PoolDistributorsQuery, + PoolMemberQuery, + PoolMembersQuery, + PoolQuery, + PoolsQuery, StreamPeriodQuery, StreamPeriodsQuery, StreamQuery, @@ -88,6 +100,12 @@ export const createEntityEndpoints = (builder: SubgraphEndpointBuilder) => { tokenStatisticLogs: list(builder, new TokenStatisticLogQueryHandler()), flowOperator: get(builder, new FlowOperatorQueryHandler()), flowOperators: list(builder, new FlowOperatorQueryHandler()), + pool: get(builder, new PoolQueryHandler()), + pools: list(builder, new PoolQueryHandler()), + poolMember: get(builder, new PoolMemberQueryHandler()), + poolMembers: list(builder, new PoolMemberQueryHandler()), + poolDistributor: get(builder, new PoolDistributorQueryHandler()), + poolDistributors: list(builder, new PoolDistributorQueryHandler()), }; }; From 63468d1e10f105208f3d4e7f69643300c8ce772d Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Fri, 23 Feb 2024 17:58:13 +0200 Subject: [PATCH 02/15] improve infinity paging api --- packages/sdk-core/src/pagination.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-core/src/pagination.ts b/packages/sdk-core/src/pagination.ts index 1e6bef1ed8..a4b8c1df21 100644 --- a/packages/sdk-core/src/pagination.ts +++ b/packages/sdk-core/src/pagination.ts @@ -121,7 +121,7 @@ export function isLastIdPaging(paging?: Paging): paging is LastIdPaging { export function isAllPaging(paging?: Paging): paging is AllPaging { return ( paging !== undefined && - paging.skip === undefined && + !paging.skip && paging.lastId === undefined && paging.take === Infinity ); From 091bf3ee631271fd013c8ab85fd0f1b9597def2c Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 27 Feb 2024 11:39:12 +0200 Subject: [PATCH 03/15] add some robustness to transaction serialization --- .../trySerializeTransaction.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/trySerializeTransaction.ts b/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/trySerializeTransaction.ts index 283e736a50..a4d9905d80 100644 --- a/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/trySerializeTransaction.ts +++ b/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/trySerializeTransaction.ts @@ -1,17 +1,34 @@ import {SignatureLike} from '@ethersproject/bytes'; -import {ethers, UnsignedTransaction} from 'ethers'; +import {ethers, Transaction} from 'ethers'; /** * The use-case arose from Gnosis Safe transaction serialization failing. */ export const trySerializeTransaction = ( - transaction: UnsignedTransaction, + transaction: Partial, signature?: SignatureLike ): string | undefined => { try { return ethers.utils.serializeTransaction(transaction, signature); } catch (error) { // This tends to happen with Gnosis Safe which changes the transaction response structure. + + if (transaction.hash) { + // Check if the transaction hash contains a prefix (e.g. chainId) followed by colon + const parts = transaction.hash.split(':'); + if (parts.length === 2) { + // Remove the prefix and set the plain transaction hash + transaction.hash = parts[1]; + // Second attempt to serialize the transaction with the correct (?) hash + try { + return ethers.utils.serializeTransaction(transaction, signature); + } catch { + // Log the first error instead + console.warn(error); + } + } + } + console.warn(error); } return undefined; From 7514a4d42efc84479e58f43dd72bf8c5b23330cb Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 27 Feb 2024 11:41:19 +0200 Subject: [PATCH 04/15] reduce tx tracking timeout from 10 mins to 3 mins --- .../thunks/trackPendingTransactionThunk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/thunks/trackPendingTransactionThunk.ts b/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/thunks/trackPendingTransactionThunk.ts index e931659aac..e30d8b4c2a 100644 --- a/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/thunks/trackPendingTransactionThunk.ts +++ b/packages/sdk-redux/src/reduxSlices/transactionTrackerSlice/thunks/trackPendingTransactionThunk.ts @@ -40,7 +40,7 @@ export const trackPendingTransactionThunk = createAsyncThunk< const framework = await getFramework(chainId); const waitForOneConfirmation = wait ? () => wait(1) - : () => framework.settings.provider.waitForTransaction(transactionHash, 1, MillisecondTimes.TenMinutes); + : () => framework.settings.provider.waitForTransaction(transactionHash, 1, MillisecondTimes.ThreeMinutes); await waitForOneConfirmation() .then(async (transactionReceipt: ethers.providers.TransactionReceipt) => { From 098ba3d70132c24672752d3dab074dcfeb0f5cb6 Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 27 Feb 2024 12:29:59 +0200 Subject: [PATCH 05/15] remove unnecessary toLowerCase --- packages/sdk-core/src/subgraph/subgraphQueryHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk-core/src/subgraph/subgraphQueryHandler.ts b/packages/sdk-core/src/subgraph/subgraphQueryHandler.ts index 34a201198b..452b264cb1 100644 --- a/packages/sdk-core/src/subgraph/subgraphQueryHandler.ts +++ b/packages/sdk-core/src/subgraph/subgraphQueryHandler.ts @@ -224,7 +224,7 @@ export abstract class SubgraphQueryHandler< const response = await this.querySubgraph(subgraphClient, { where: { - id: query.id.toLowerCase(), + id: query.id, }, skip: 0, take: 1, From 3ae38da05f9bf7e08559c4d1461d99caeae14cfd Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Mon, 11 Mar 2024 10:18:23 +0200 Subject: [PATCH 06/15] changeset --- packages/sdk-core/CHANGELOG.md | 3 +++ packages/sdk-redux/CHANGELOG.md | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/sdk-core/CHANGELOG.md b/packages/sdk-core/CHANGELOG.md index 0191f309fe..60197e4337 100644 --- a/packages/sdk-core/CHANGELOG.md +++ b/packages/sdk-core/CHANGELOG.md @@ -7,8 +7,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] ### Changed + - Map the name from subgraph to an unknown event, instead of "\_Unknown". - Don't lock metadata version to a specific version, use semver (^). +- Allow infinite pagination with 'skip: 0' value (previously had to be undefined) +- Add subgraphs queries for Pools, PoolMembers and PoolDistributors ## [0.6.12] - 2023-10-23 diff --git a/packages/sdk-redux/CHANGELOG.md b/packages/sdk-redux/CHANGELOG.md index 6ef753e3fb..0a6f797b78 100644 --- a/packages/sdk-redux/CHANGELOG.md +++ b/packages/sdk-redux/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to the SDK-redux will be documented in this file. ### Changed -- Node dependency updates. +- Node dependency updates +- Reduce transaction tracking expiration from 10 minutes to 3 minutes + +### Added +- Support for `Pool`, `PoolMember` and `PoolDistributor` queries ## [0.5.1] - 2023-05-17 From b48fccaf727109c64a43154e676bc9d9c66210bd Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 12 Mar 2024 14:23:13 +0200 Subject: [PATCH 07/15] [SUBGRAPH] [BUG] PoolMember not getting updated when the member units change (#1877) * add a test starter * add the test * fixes * improve test * update dev container for matchstick compatibility * implement the fix * clean-up * add elaborate test for pool total amount received * fix test issue * add even more comments * fix test name * ignore test --------- Co-authored-by: 0xdavinchee <0xdavinchee@gmail.com> --- .devcontainer/devcontainer.json | 7 +- packages/subgraph/src/mappingHelpers.ts | 12 +- packages/subgraph/src/mappings/gdav1.ts | 10 +- .../subgraph/src/mappings/superfluidPool.ts | 44 ++- .../2024-02-29-aleph-total-supply.test.ts | 2 +- ...24-03-06-pool-member-units-changed.test.ts | 89 ++++++ ...-pool-member-total-amount-received.test.ts | 258 ++++++++++++++++++ .../tests/gdav1/hol/gdav1.hol.test.ts | 10 +- 8 files changed, 390 insertions(+), 42 deletions(-) create mode 100644 packages/subgraph/tests/bugs/2024-03-06-pool-member-units-changed.test.ts create mode 100644 packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a6cff952a4..dcfd2038eb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ { "name": "Node.js & TypeScript", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", // Features to add to the dev container. More info: https://containers.dev/features. "features": { // If having issues with Nix then consult: @@ -19,7 +19,9 @@ "ghcr.io/lukewiwa/features/shellcheck:0": {}, "ghcr.io/devcontainers-contrib/features/curl-apt-get:1": {}, "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/devcontainers-contrib/features/act:1": {} + "ghcr.io/devcontainers-contrib/features/act:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], @@ -32,6 +34,7 @@ "source /home/node/.bashrc && foundryup", "yarn global add npm-run-all", "yarn install && yarn build", + "sudo apt-get install libpq5", // for subgraph's matchstick "./tasks/fix-devcontainer.sh && nix develop . -c bash <(echo \"yarn install && yarn build\")" ] // Configure tool-specific properties. diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index a272e5d05b..82cf7a0cb5 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -536,7 +536,7 @@ export function updatePoolTotalAmountFlowedAndDistributed( return pool; } -export function getOrInitPoolMember( +export function getOrInitOrUpdatePoolMember( event: ethereum.Event, poolAddress: Address, poolMemberAddress: Address @@ -548,19 +548,19 @@ export function getOrInitPoolMember( poolMember = new PoolMember(poolMemberID); poolMember.createdAtTimestamp = event.block.timestamp; poolMember.createdAtBlockNumber = event.block.number; - poolMember.updatedAtTimestamp = event.block.timestamp; - poolMember.updatedAtBlockNumber = event.block.number; - + poolMember.units = BIG_INT_ZERO; poolMember.isConnected = false; poolMember.totalAmountClaimed = BIG_INT_ZERO; poolMember.poolTotalAmountDistributedUntilUpdatedAt = BIG_INT_ZERO; poolMember.totalAmountReceivedUntilUpdatedAt = BIG_INT_ZERO; - + poolMember.account = poolMemberAddress.toHex(); poolMember.pool = poolAddress.toHex(); } - + poolMember.updatedAtTimestamp = event.block.timestamp; + poolMember.updatedAtBlockNumber = event.block.number; + return poolMember; } diff --git a/packages/subgraph/src/mappings/gdav1.ts b/packages/subgraph/src/mappings/gdav1.ts index 81381e7464..e5a74baf36 100644 --- a/packages/subgraph/src/mappings/gdav1.ts +++ b/packages/subgraph/src/mappings/gdav1.ts @@ -19,7 +19,7 @@ import { _createTokenStatisticLogEntity, getOrInitPool, getOrInitPoolDistributor, - getOrInitPoolMember, + getOrInitOrUpdatePoolMember, getOrInitTokenStatistic, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, @@ -84,7 +84,7 @@ export function handlePoolConnectionUpdated( event: PoolConnectionUpdated ): void { // Update Pool Member Entity - let poolMember = getOrInitPoolMember( + let poolMember = getOrInitOrUpdatePoolMember( event, event.params.pool, event.params.account @@ -162,6 +162,9 @@ export function handlePoolConnectionUpdated( false // isIDA ); + // Create Event Entity + _createPoolConnectionUpdatedEntity(event, poolMember.id); + // Create ATS and Token Statistic Log Entities const eventName = "PoolConnectionUpdated"; _createAccountTokenSnapshotLogEntity( @@ -172,9 +175,6 @@ export function handlePoolConnectionUpdated( ); _createTokenStatisticLogEntity(event, event.params.token, eventName); - - // Create Event Entity - _createPoolConnectionUpdatedEntity(event, poolMember.id); } export function handleBufferAdjusted(event: BufferAdjusted): void { diff --git a/packages/subgraph/src/mappings/superfluidPool.ts b/packages/subgraph/src/mappings/superfluidPool.ts index b018d2377a..15a22f6b8c 100644 --- a/packages/subgraph/src/mappings/superfluidPool.ts +++ b/packages/subgraph/src/mappings/superfluidPool.ts @@ -8,7 +8,7 @@ import { _createAccountTokenSnapshotLogEntity, _createTokenStatisticLogEntity, getOrInitPool, - getOrInitPoolMember, + getOrInitOrUpdatePoolMember, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, updatePoolMemberTotalAmountUntilUpdatedAtFields, @@ -28,7 +28,7 @@ export function handleDistributionClaimed(event: DistributionClaimed): void { pool.save(); // Update PoolMember - let poolMember = getOrInitPoolMember(event, event.address, event.params.member); + let poolMember = getOrInitOrUpdatePoolMember(event, event.address, event.params.member); poolMember.totalAmountClaimed = event.params.totalClaimed; poolMember = updatePoolMemberTotalAmountUntilUpdatedAtFields(pool, poolMember); @@ -48,29 +48,16 @@ export function handleDistributionClaimed(event: DistributionClaimed): void { } export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { - // - PoolMember - // - units - let poolMember = getOrInitPoolMember(event, event.address, event.params.member); - const hasMembershipWithUnits = membershipWithUnitsExists(poolMember.id); - let pool = getOrInitPool(event, event.address.toHex()); - - const previousUnits = poolMember.units; - const unitsDelta = event.params.newUnits.minus(previousUnits); + let poolMember = getOrInitOrUpdatePoolMember(event, event.address, event.params.member); pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); - poolMember = updatePoolMemberTotalAmountUntilUpdatedAtFields(pool, poolMember); - + + const previousUnits = poolMember.units; + const unitsDelta = event.params.newUnits.minus(previousUnits); poolMember.units = event.params.newUnits; - const eventName = "MemberUnitsUpdated"; - updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block); - _createTokenStatisticLogEntity(event, event.params.token, eventName); - - updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, event.params.token, event.block, null); - _createAccountTokenSnapshotLogEntity(event, event.params.member, event.params.token, eventName); - if (poolMember.isConnected) { pool.totalConnectedUnits = pool.totalConnectedUnits.plus(unitsDelta); } else { @@ -79,7 +66,8 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { pool.totalUnits = pool.totalUnits.plus(unitsDelta); // 0 units to > 0 units - if (previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO)) { + const didPoolMemberBecomeActive = previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO) + if (didPoolMemberBecomeActive) { pool.totalMembers = pool.totalMembers + 1; // if the member is connected with units now, we add one to connected if (poolMember.isConnected) { @@ -92,7 +80,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { updateAggregateDistributionAgreementData( event.params.member, event.params.token, - hasMembershipWithUnits, + true, // has units poolMember.isConnected, true, // only place we increment subWithUnits false, // not deleting @@ -102,8 +90,10 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { false // isIDA ); } + // > 0 units to 0 units - if (previousUnits.gt(BIG_INT_ZERO) && poolMember.units.equals(BIG_INT_ZERO)) { + const didPoolMemberBecomeInactive = previousUnits.gt(BIG_INT_ZERO) && poolMember.units.equals(BIG_INT_ZERO) + if (didPoolMemberBecomeInactive) { pool.totalMembers = pool.totalMembers - 1; // if the member is connected with no units now, we subtract one from connected if (poolMember.isConnected) { @@ -116,7 +106,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { updateAggregateDistributionAgreementData( event.params.member, event.params.token, - hasMembershipWithUnits, + false, // has units poolMember.isConnected, false, // don't increment memberWithUnits false, // not disconnecting membership @@ -132,6 +122,14 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { // Create Event Entity _createMemberUnitsUpdatedEntity(event, poolMember.id, pool.totalUnits); + + // Other entity updates + const eventName = "MemberUnitsUpdated"; + updateTokenStatsStreamedUntilUpdatedAt(event.params.token, event.block); + _createTokenStatisticLogEntity(event, event.params.token, eventName); + + updateATSStreamedAndBalanceUntilUpdatedAt(event.params.member, event.params.token, event.block, null); + _createAccountTokenSnapshotLogEntity(event, event.params.member, event.params.token, eventName); } function _createDistributionClaimedEntity(event: DistributionClaimed, poolMemberId: string): DistributionClaimedEvent { diff --git a/packages/subgraph/tests/bugs/2024-02-29-aleph-total-supply.test.ts b/packages/subgraph/tests/bugs/2024-02-29-aleph-total-supply.test.ts index bfb7412813..45d7a15c97 100644 --- a/packages/subgraph/tests/bugs/2024-02-29-aleph-total-supply.test.ts +++ b/packages/subgraph/tests/bugs/2024-02-29-aleph-total-supply.test.ts @@ -30,7 +30,7 @@ describe("ALEPH Total Supply Bug", () => { mockedTokenName(superToken, "tokenName"); mockedTokenSymbol(superToken, "tokenSymbol"); mockedTokenDecimals(superToken, 18); - + // unused mocked function call after change in this commit (removing total supply RPC call in getOrInitSuperToken) mockedTokenTotalSupply(superToken, totalSupply); diff --git a/packages/subgraph/tests/bugs/2024-03-06-pool-member-units-changed.test.ts b/packages/subgraph/tests/bugs/2024-03-06-pool-member-units-changed.test.ts new file mode 100644 index 0000000000..f4053da76a --- /dev/null +++ b/packages/subgraph/tests/bugs/2024-03-06-pool-member-units-changed.test.ts @@ -0,0 +1,89 @@ +import { handleMemberUnitsUpdated } from "../../src/mappings/superfluidPool"; +import { createMemberUnitsUpdatedEvent } from "../gdav1/gdav1.helper"; +import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { FAKE_INITIAL_BALANCE, alice, bob, charlie } from "../constants"; +import { BIG_INT_ZERO, getPoolMemberID } from "../../src/utils"; +import { assert, describe, test } from "matchstick-as"; +import { mockedGetAppManifest, mockedRealtimeBalanceOf } from "../mockedFunctions"; + +describe("PoolMember not updating when units changed", () => { + test("emit MemberUnitsUpdated event", () => { + const superTokenAddress = alice; + + const poolAddress = Address.fromString(bob); + const poolMemberAccountAddress = Address.fromString(charlie); + const poolMemberId = getPoolMemberID(poolAddress, poolMemberAccountAddress); + + mockedGetAppManifest(poolMemberAccountAddress.toHexString(), false, false, BIG_INT_ZERO); + + // Initialize pool member for the first time + const firstEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + poolMemberAccountAddress.toHexString(), + BigInt.fromI32(0), // old units + BigInt.fromI32(0) // new units + ); + firstEvent.address = poolAddress; + + mockedRealtimeBalanceOf( + superTokenAddress, + poolMemberAccountAddress.toHexString(), + firstEvent.block.timestamp, + FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), + BIG_INT_ZERO + ); + + handleMemberUnitsUpdated(firstEvent); + // --- + + + const newUnits = BigInt.fromI32(100); + const blockNumber = BigInt.fromI32(200) + const timestamp = BigInt.fromI32(300) + + const secondEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + poolMemberAccountAddress.toHexString(), + BigInt.fromI32(0), // old units + newUnits + ); + secondEvent.block.timestamp = timestamp + secondEvent.address = poolAddress; + secondEvent.block.number = blockNumber; + + mockedRealtimeBalanceOf( + superTokenAddress, + poolMemberAccountAddress.toHexString(), + secondEvent.block.timestamp, + FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), + BIG_INT_ZERO + ); + + // Act + handleMemberUnitsUpdated(secondEvent); + + // Assert + assert.fieldEquals( + "PoolMember", + poolMemberId, + "units", + newUnits.toString() + ); + + assert.fieldEquals( + "PoolMember", + poolMemberId, + "updatedAtTimestamp", + timestamp.toString() + ); + + assert.fieldEquals( + "PoolMember", + poolMemberId, + "updatedAtBlockNumber", + blockNumber.toString() + ); + }); +}); 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 new file mode 100644 index 0000000000..c214de0a25 --- /dev/null +++ b/packages/subgraph/tests/bugs/2024-03-07-pool-member-total-amount-received.test.ts @@ -0,0 +1,258 @@ +import { assert, describe, test } from "matchstick-as"; +import { Pool, PoolDistributor, PoolMember } from "../../generated/schema" +import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { FAKE_INITIAL_BALANCE, alice as alice_, bob as bob_, charlie, delta, echo, maticXAddress, superfluidPool } from "../constants"; +import { BIG_INT_ZERO, getPoolMemberID } from "../../src/utils"; +import { handleInstantDistributionUpdated } from "../../src/mappings/gdav1"; +import { createInstantDistributionUpdatedEvent, createMemberUnitsUpdatedEvent } from "../gdav1/gdav1.helper"; +import { mockedGetAppManifest, mockedRealtimeBalanceOf } from "../mockedFunctions"; +import { handleMemberUnitsUpdated } from "../../src/mappings/superfluidPool"; + +/** + * Problem description + 1. Create pool + 2. Add member A and update A units to 100 + 3. Distribute 100 tokens + 4. Add member B and update B units to 100 + 4. Distribute 100 tokens + + Expected result: + member A 150 tokens + member B 50 tokens + + Actual result: + member A 100 tokens + member B 50 tokens + */ +describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", () => { + test("create elaborate scenario with 2 distributions and 2 pool members", () => { + return; // ignore test for CI (as the test is failing for now) + + const superTokenAddress = maticXAddress; + + // # Arrange State 1 + // ## Arrange Pool + const poolAddress = Address.fromString(superfluidPool); + const poolAdminAndDistributorAddress = Address.fromString(delta); + let pool = new Pool(poolAddress.toHexString()); + pool.createdAtTimestamp = BigInt.fromI32(1); + pool.createdAtBlockNumber = BigInt.fromI32(1); + pool.updatedAtTimestamp = BigInt.fromI32(1); + pool.updatedAtBlockNumber = BigInt.fromI32(1); + + pool.totalMembers = 1; + pool.totalConnectedMembers = 1; + pool.totalDisconnectedMembers = 0; + pool.adjustmentFlowRate = BigInt.fromI32(0); + pool.flowRate = BigInt.fromI32(0); + pool.admin = poolAdminAndDistributorAddress.toHexString(); + pool.totalBuffer = BigInt.fromI32(0); + pool.token = superTokenAddress; + pool.totalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); + pool.totalAmountFlowedDistributedUntilUpdatedAt = BigInt.fromI32(0); + pool.totalAmountInstantlyDistributedUntilUpdatedAt = BigInt.fromI32(0); + pool.totalConnectedUnits = BigInt.fromI32(100); + pool.totalDisconnectedUnits = BigInt.fromI32(0); + pool.totalUnits = BigInt.fromI32(100); + pool.save(); + // --- + + // ## Arrange PoolMember 1 + const aliceAddress = Address.fromString(alice_); + const aliceId = getPoolMemberID(poolAddress, aliceAddress); + const alice = new PoolMember(aliceId) + alice.createdAtTimestamp = BigInt.fromI32(1); + alice.createdAtBlockNumber = BigInt.fromI32(1); + alice.updatedAtTimestamp = BigInt.fromI32(1); + alice.updatedAtBlockNumber = BigInt.fromI32(1); + + alice.account = aliceAddress.toHexString(); + alice.units = BigInt.fromI32(100); + alice.totalAmountReceivedUntilUpdatedAt = BigInt.fromI32(0); + alice.poolTotalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); + alice.isConnected = true; + alice.totalAmountClaimed = BigInt.fromI32(0); + alice.pool = poolAddress.toHexString(); + alice.save(); + // # --- + + // ## Arrange Distributor + const poolDistributor = new PoolDistributor(poolAdminAndDistributorAddress.toHexString()); + poolDistributor.createdAtTimestamp = BigInt.fromI32(1); + poolDistributor.createdAtBlockNumber = BigInt.fromI32(1); + poolDistributor.updatedAtTimestamp = BigInt.fromI32(1); + poolDistributor.updatedAtBlockNumber = BigInt.fromI32(1); + poolDistributor.account = charlie; + poolDistributor.totalBuffer = BigInt.fromI32(0); + poolDistributor.flowRate = BigInt.fromI32(0); + poolDistributor.pool = poolAddress.toHexString(); + poolDistributor.totalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); + poolDistributor.totalAmountFlowedDistributedUntilUpdatedAt = BigInt.fromI32(0); + poolDistributor.totalAmountInstantlyDistributedUntilUpdatedAt = BigInt.fromI32(0); + poolDistributor.save(); + // --- + + // # First distribution (State 2) + const instantDistributionEvent = createInstantDistributionUpdatedEvent( + superTokenAddress, + poolAddress.toHexString(), + poolAdminAndDistributorAddress.toHexString(), + echo, + BigInt.fromI32(100), // requested amount + BigInt.fromI32(100), // actual amount + Bytes.fromHexString("0x") + ); + instantDistributionEvent.block.timestamp = BigInt.fromI32(1); + instantDistributionEvent.address = poolAddress; + + mockedGetAppManifest(poolAdminAndDistributorAddress.toHexString(), false, false, BIG_INT_ZERO); + mockedRealtimeBalanceOf( + superTokenAddress, + poolAdminAndDistributorAddress.toHexString(), + BigInt.fromI32(1), + FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), + BIG_INT_ZERO + ); + + handleInstantDistributionUpdated(instantDistributionEvent); + + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "100" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "totalAmountReceivedUntilUpdatedAt", + "0" + ); + // # --- + + // # Arrange State 3 + // ## Arrange PoolMember 2 (new member) + const bobAddress = Address.fromString(bob_); + const bobId = getPoolMemberID(poolAddress, bobAddress); + const bob = new PoolMember(bobId) + bob.createdAtTimestamp = BigInt.fromI32(1); + bob.createdAtBlockNumber = BigInt.fromI32(1); + bob.updatedAtTimestamp = BigInt.fromI32(1); + bob.updatedAtBlockNumber = BigInt.fromI32(1); + + bob.account = bobAddress.toHexString(); + bob.units = BigInt.fromI32(100); + bob.totalAmountReceivedUntilUpdatedAt = BigInt.fromI32(0); + bob.poolTotalAmountDistributedUntilUpdatedAt = BigInt.fromI32(100); + bob.isConnected = true; + bob.totalAmountClaimed = BigInt.fromI32(0); + bob.pool = poolAddress.toHexString(); + bob.save(); + // # --- + + // ## Update Pool for member 2 + pool = Pool.load(poolAddress.toHexString())!; + pool.updatedAtTimestamp = BigInt.fromI32(2); + pool.updatedAtBlockNumber = BigInt.fromI32(2); + pool.totalMembers = 2; + pool.totalConnectedMembers = 2; + pool.totalDisconnectedMembers = 0; + pool.totalConnectedUnits = BigInt.fromI32(2000); + pool.totalUnits = BigInt.fromI32(200); + pool.save(); + // --- + + // # Second distribution (we can use the first event again) (State 4) + handleInstantDistributionUpdated(instantDistributionEvent); + + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "200" + ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalUnits", + "200" + ); + // # --- + + // # Update PoolMember 2's units to get the `totalAmountReceivedUntilUpdatedAt` + const updateBobUnitsEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + bobAddress.toHexString(), + BigInt.fromI32(100), // old units + BigInt.fromI32(100) // new units + ); + // Note, the units can stay the same, we just want to trigger an update. + updateBobUnitsEvent.address = poolAddress; + updateBobUnitsEvent.block.timestamp = BigInt.fromI32(2); + + mockedGetAppManifest(bobAddress.toHexString(), false, false, BIG_INT_ZERO); + mockedRealtimeBalanceOf( + superTokenAddress, + bobAddress.toHexString(), + BigInt.fromI32(2), + FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), + BIG_INT_ZERO + ); + + // Act 1 + handleMemberUnitsUpdated(updateBobUnitsEvent); + + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "200" + ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalUnits", + "200" + ); + assert.fieldEquals( + "PoolMember", + bobId, + "totalAmountReceivedUntilUpdatedAt", + "50" + ); + + // # Update PoolMember 1's units to get the `totalAmountReceivedUntilUpdatedAt` + const updateAliceUnitsEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + aliceAddress.toHexString(), + BigInt.fromI32(10), // old units + BigInt.fromI32(10) // new units + ); + // Note, the units can stay the same, we just want to trigger an update. + updateAliceUnitsEvent.address = poolAddress; + updateAliceUnitsEvent.block.timestamp = BigInt.fromI32(3); + + mockedGetAppManifest(aliceAddress.toHexString(), false, false, BIG_INT_ZERO); + mockedRealtimeBalanceOf( + superTokenAddress, + aliceAddress.toHexString(), + BigInt.fromI32(3), + FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), + BIG_INT_ZERO + ); + + // Act 2 + handleMemberUnitsUpdated(updateAliceUnitsEvent); + + assert.fieldEquals( + "PoolMember", + aliceId, + "totalAmountReceivedUntilUpdatedAt", + "150" // 100 from first + 50 from second + ); + }) +}); + \ No newline at end of file diff --git a/packages/subgraph/tests/gdav1/hol/gdav1.hol.test.ts b/packages/subgraph/tests/gdav1/hol/gdav1.hol.test.ts index c0e2cfc3f7..9873aef7f1 100644 --- a/packages/subgraph/tests/gdav1/hol/gdav1.hol.test.ts +++ b/packages/subgraph/tests/gdav1/hol/gdav1.hol.test.ts @@ -19,7 +19,7 @@ import { } from "../../../src/mappings/gdav1"; import { updateMemberUnitsAndReturnMemberUnitsUpdatedEvent } from "../gdav1.helper"; import { handleDistributionClaimed, handleMemberUnitsUpdated } from "../../../src/mappings/superfluidPool"; -import { getOrInitPoolMember } from "../../../src/mappingHelpers"; +import { getOrInitOrUpdatePoolMember } from "../../../src/mappingHelpers"; import { stringToBytes } from "../../converters"; const initialFlowRate = BigInt.fromI32(100); @@ -285,7 +285,7 @@ describe("GeneralDistributionAgreementV1 Higher Order Level Entity Unit Tests", const oldUnits = BigInt.fromI32(0); const newUnits = BigInt.fromI32(100000000); const memberUnitsUpdatedEvent = createMemberUnitsUpdatedEvent(superToken, poolMember, oldUnits, newUnits); - const poolMemberEntity = getOrInitPoolMember( + const poolMemberEntity = getOrInitOrUpdatePoolMember( memberUnitsUpdatedEvent, memberUnitsUpdatedEvent.address, Address.fromString(poolMember) @@ -319,7 +319,7 @@ describe("GeneralDistributionAgreementV1 Higher Order Level Entity Unit Tests", const oldUnits = BigInt.fromI32(0); const newUnits = BigInt.fromI32(100000000); const memberUnitsUpdatedEvent = createMemberUnitsUpdatedEvent(superToken, poolMember, oldUnits, newUnits); - const poolMemberEntity = getOrInitPoolMember( + const poolMemberEntity = getOrInitOrUpdatePoolMember( memberUnitsUpdatedEvent, memberUnitsUpdatedEvent.address, Address.fromString(poolMember) @@ -362,7 +362,7 @@ describe("GeneralDistributionAgreementV1 Higher Order Level Entity Unit Tests", const oldUnits = BigInt.fromI32(0); const newUnits = BigInt.fromI32(100000000); const memberUnitsUpdatedEvent = createMemberUnitsUpdatedEvent(superToken, poolMember, oldUnits, newUnits); - const poolMemberEntity = getOrInitPoolMember( + const poolMemberEntity = getOrInitOrUpdatePoolMember( memberUnitsUpdatedEvent, memberUnitsUpdatedEvent.address, Address.fromString(poolMember) @@ -395,7 +395,7 @@ describe("GeneralDistributionAgreementV1 Higher Order Level Entity Unit Tests", const oldUnits = BigInt.fromI32(0); const newUnits = BigInt.fromI32(100000000); const memberUnitsUpdatedEvent = createMemberUnitsUpdatedEvent(superToken, poolMember, oldUnits, newUnits); - const poolMemberEntity = getOrInitPoolMember( + const poolMemberEntity = getOrInitOrUpdatePoolMember( memberUnitsUpdatedEvent, memberUnitsUpdatedEvent.address, Address.fromString(poolMember) From a58cf6be2b4f940e4e3f0af830db1d54f88df11c Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Tue, 12 Mar 2024 15:31:56 +0200 Subject: [PATCH 08/15] [SUBGRAPH] approval mapping (#1878) * approval mapping * missing addresses * missing addresses cont. * no-op, trigger build * fix tests --------- Co-authored-by: Kaspar Kallas --- packages/subgraph/schema.graphql | 98 +++++++++++++++---- packages/subgraph/src/mappings/flowNFT.ts | 8 +- packages/subgraph/src/mappings/host.ts | 14 +-- packages/subgraph/src/mappings/resolver.ts | 6 +- packages/subgraph/src/mappings/superToken.ts | 12 +++ .../src/mappings/superTokenFactory.ts | 2 +- .../src/mappings/superfluidGovernance.ts | 17 ++-- .../superToken/event/superToken.event.test.ts | 30 +++++- .../tests/superToken/superToken.helper.ts | 14 +++ 9 files changed, 159 insertions(+), 42 deletions(-) diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 1627c06aa4..5820aba5fb 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -830,7 +830,8 @@ type AgreementClassRegisteredEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `code` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -849,7 +850,8 @@ type AgreementClassUpdatedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `code` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -868,7 +870,8 @@ type AppRegisteredEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `app` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -889,7 +892,9 @@ type GovernanceReplacedEvent implements Event @entity(immutable: true) { order: BigInt! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `oldGovernance` + addresses[1] = `newGovernance` """ addresses: [Bytes!]! oldGovernance: Bytes! @@ -905,7 +910,8 @@ type JailEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `app` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -924,7 +930,8 @@ type SuperTokenFactoryUpdatedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `newFactory` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -942,7 +949,9 @@ type SuperTokenLogicUpdatedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `token` + addresses[1] = `code` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -963,7 +972,9 @@ type RoleAdminChangedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `previousAdminRole` + addresses[1] = `newAdminRole` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -983,7 +994,9 @@ type RoleGrantedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `account` + addresses[1] = `sender` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1003,7 +1016,9 @@ type RoleRevokedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `account` + addresses[1] = `sender` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1057,7 +1072,10 @@ type CFAv1LiquidationPeriodChangedEvent implements Event governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1083,7 +1101,10 @@ type ConfigChangedEvent implements Event @entity(immutable: true) { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1110,7 +1131,11 @@ type RewardAddressChangedEvent implements Event @entity(immutable: true) { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` + addresses[3] = `rewardAddress` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1136,7 +1161,10 @@ type PPPConfigurationChangedEvent implements Event @entity(immutable: true) { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1164,7 +1192,10 @@ type SuperTokenMinimumDepositChangedEvent implements Event governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1190,7 +1221,11 @@ type TrustedForwarderChangedEvent implements Event @entity(immutable: true) { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` + addresses[3] = `forwarder` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1468,20 +1503,39 @@ type ApprovalEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `isNFTApproval` ? `nft address` : `token` (superToken) + addresses[1] = `owner` + addresses[2] = `to` """ addresses: [Bytes!]! blockNumber: BigInt! logIndex: BigInt! order: BigInt! + """ + The address that will be granting allowance to transfer ERC20/NFT. + """ owner: Account! """ - The address that will be granted allowance to transfer the NFT. + The address that will be granted allowance to transfer ERC20/NFT. """ to: Account! + + """ + Indicates whether the event was emitted for the approval of an NFT. + """ + isNFTApproval: Boolean! + + """ + If `amount` is non-zero, this event was emitted for the approval of an ERC20. + Tne amount of ERC20 tokens that will be granted allowance to transfer. """ + amount: BigInt! + + """ + If `tokenId` is non-zero, this event was emitted for the approval of an NFT. The id of the NFT that will be granted allowance to transfer. The id is: uint256(keccak256(abi.encode(block.chainid, superToken, sender, receiver))) """ @@ -1497,7 +1551,10 @@ type ApprovalForAllEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = NFT address + addresses[1] = `owner` + addresses[2] = `operator` """ addresses: [Bytes!]! blockNumber: BigInt! @@ -1590,7 +1647,8 @@ type SuperTokenLogicCreatedEvent implements Event @entity(immutable: true) { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `tokenLogic` """ addresses: [Bytes!]! blockNumber: BigInt! diff --git a/packages/subgraph/src/mappings/flowNFT.ts b/packages/subgraph/src/mappings/flowNFT.ts index a070abf8dd..2124988e1e 100644 --- a/packages/subgraph/src/mappings/flowNFT.ts +++ b/packages/subgraph/src/mappings/flowNFT.ts @@ -10,15 +10,17 @@ import { MetadataUpdateEvent, TransferEvent, } from "../../generated/schema"; -import { createEventID, initializeEventEntity } from "../utils"; +import { BIG_INT_ONE, createEventID, initializeEventEntity } from "../utils"; export function handleApproval(event: Approval): void { const eventId = createEventID("Approval", event); const ev = new ApprovalEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.approved]); ev.owner = event.params.owner.toHex(); ev.to = event.params.approved.toHex(); ev.tokenId = event.params.tokenId; + ev.amount = BIG_INT_ONE.neg(); + ev.isNFTApproval = true; ev.save(); } @@ -26,7 +28,7 @@ export function handleApproval(event: Approval): void { export function handleApprovalForAll(event: ApprovalForAll): void { const eventId = createEventID("ApprovalForAll", event); const ev = new ApprovalForAllEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.operator]); ev.owner = event.params.owner.toHex(); ev.operator = event.params.operator.toHex(); ev.approved = event.params.approved; diff --git a/packages/subgraph/src/mappings/host.ts b/packages/subgraph/src/mappings/host.ts index 7b877d3ff4..738afd49d0 100644 --- a/packages/subgraph/src/mappings/host.ts +++ b/packages/subgraph/src/mappings/host.ts @@ -25,7 +25,7 @@ import { SuperfluidGovernance } from "../../generated/templates"; export function handleGovernanceReplaced(event: GovernanceReplaced): void { const eventId = createEventID("GovernanceReplaced", event); const ev = new GovernanceReplacedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.oldGov, event.params.newGov]); ev.oldGovernance = event.params.oldGov; ev.newGovernance = event.params.newGov; ev.save(); @@ -42,7 +42,7 @@ export function handleAgreementClassRegistered( ): void { const eventId = createEventID("AgreementClassRegistered", event); const ev = new AgreementClassRegisteredEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.code]); ev.agreementType = event.params.agreementType; ev.code = event.params.code; ev.save(); @@ -55,7 +55,7 @@ export function handleAgreementClassUpdated( ): void { const eventId = createEventID("AgreementClassUpdated", event); const ev = new AgreementClassUpdatedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.code]); ev.agreementType = event.params.agreementType; ev.code = event.params.code; @@ -70,7 +70,7 @@ export function handleSuperTokenFactoryUpdated( ): void { const eventId = createEventID("SuperTokenFactoryUpdated", event); const ev = new SuperTokenFactoryUpdatedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.newFactory]); ev.newFactory = event.params.newFactory; ev.save(); @@ -81,7 +81,7 @@ export function handleSuperTokenLogicUpdated( ): void { const eventId = createEventID("SuperTokenLogicUpdated", event); const ev = new SuperTokenLogicUpdatedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.token, event.params.code]); ev.token = event.params.token; ev.code = event.params.code; @@ -90,7 +90,7 @@ export function handleSuperTokenLogicUpdated( export function handleAppRegistered(event: AppRegistered): void { const ev = new AppRegisteredEvent(createEventID("AppRegistered", event)); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.app]); ev.app = event.params.app; ev.save(); @@ -98,7 +98,7 @@ export function handleAppRegistered(event: AppRegistered): void { export function handleJail(event: Jail): void { const ev = new JailEvent(createEventID("Jail", event)); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.app]); ev.app = event.params.app; ev.reason = event.params.reason; diff --git a/packages/subgraph/src/mappings/resolver.ts b/packages/subgraph/src/mappings/resolver.ts index 69a0d3dc26..706647abc4 100644 --- a/packages/subgraph/src/mappings/resolver.ts +++ b/packages/subgraph/src/mappings/resolver.ts @@ -18,7 +18,7 @@ import { createEventID, initializeEventEntity, ZERO_ADDRESS } from "../utils"; export function handleRoleAdminChanged(event: RoleAdminChanged): void { const eventId = createEventID("RoleAdminChanged", event); const ev = new RoleAdminChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.previousAdminRole, event.params.newAdminRole]); ev.role = event.params.role; ev.previousAdminRole = event.params.previousAdminRole; @@ -29,7 +29,7 @@ export function handleRoleAdminChanged(event: RoleAdminChanged): void { export function handleRoleGranted(event: RoleGranted): void { const eventId = createEventID("RoleGranted", event); const ev = new RoleGrantedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.account, event.params.sender]); ev.role = event.params.role; ev.account = event.params.account; @@ -39,7 +39,7 @@ export function handleRoleGranted(event: RoleGranted): void { export function handleRoleRevoked(event: RoleRevoked): void { const eventId = createEventID("RoleRevoked", event); const ev = new RoleRevokedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.account, event.params.sender]); ev.role = event.params.role; ev.account = event.params.account; diff --git a/packages/subgraph/src/mappings/superToken.ts b/packages/subgraph/src/mappings/superToken.ts index a6e10d496d..18be4b2050 100644 --- a/packages/subgraph/src/mappings/superToken.ts +++ b/packages/subgraph/src/mappings/superToken.ts @@ -12,6 +12,7 @@ import { import { AgreementLiquidatedByEvent, AgreementLiquidatedV2Event, + ApprovalEvent, BurnedEvent, MintedEvent, SentEvent, @@ -452,6 +453,17 @@ function _createTransferEventEntity(event: Transfer): void { } export function handleApproval(event: Approval): void { + const eventId = createEventID("Approval", event); + const ev = new ApprovalEvent(eventId); + initializeEventEntity(ev, event, [event.address, event.params.owner, event.params.spender]); + ev.owner = event.params.owner.toHex(); + ev.to = event.params.spender.toHex(); + ev.tokenId = BIG_INT_ZERO; + ev.amount = event.params.value; + ev.isNFTApproval = false; + + ev.save(); + // The entity named `FlowOperators` which currently holds all the user access and approval settings will be renamed to `AccessSettings`. const flowOperator = getOrInitFlowOperator( event.block, diff --git a/packages/subgraph/src/mappings/superTokenFactory.ts b/packages/subgraph/src/mappings/superTokenFactory.ts index d8d3bdf701..e65b939daa 100644 --- a/packages/subgraph/src/mappings/superTokenFactory.ts +++ b/packages/subgraph/src/mappings/superTokenFactory.ts @@ -59,7 +59,7 @@ export function handleSuperTokenLogicCreated( } const eventId = createEventID("SuperTokenLogicCreated", event); const ev = new SuperTokenLogicCreatedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.params.tokenLogic]); ev.tokenLogic = event.params.tokenLogic; ev.save(); diff --git a/packages/subgraph/src/mappings/superfluidGovernance.ts b/packages/subgraph/src/mappings/superfluidGovernance.ts index bbee404b60..a8432dc228 100644 --- a/packages/subgraph/src/mappings/superfluidGovernance.ts +++ b/packages/subgraph/src/mappings/superfluidGovernance.ts @@ -21,7 +21,7 @@ import { getOrInitTokenGovernanceConfig } from "../mappingHelpers"; export function handleConfigChanged(event: ConfigChanged): void { const eventId = createEventID("ConfigChanged", event); const ev = new ConfigChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.host, event.params.superToken]) ev.governanceAddress = event.address; ev.host = event.params.host; @@ -35,7 +35,7 @@ export function handleConfigChanged(event: ConfigChanged): void { export function handleRewardAddressChanged(event: RewardAddressChanged): void { const eventId = createEventID("RewardAddressChanged", event); const ev = new RewardAddressChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.host, event.params.superToken, event.params.rewardAddress]); ev.governanceAddress = event.address; ev.host = event.params.host; @@ -66,7 +66,7 @@ export function handleCFAv1LiquidationPeriodChanged( ): void { const eventId = createEventID("CFAv1LiquidationPeriodChanged", event); const ev = new CFAv1LiquidationPeriodChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.host, event.params.superToken]); ev.governanceAddress = event.address; ev.host = event.params.host; @@ -91,7 +91,7 @@ export function handlePPPConfigurationChanged( ): void { const eventId = createEventID("PPPConfigurationChanged", event); const ev = new PPPConfigurationChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.host, event.params.superToken]); ev.governanceAddress = event.address; ev.host = event.params.host; @@ -118,7 +118,12 @@ export function handleTrustedForwarderChanged( ): void { const eventId = createEventID("TrustedForwarderChanged", event); const ev = new TrustedForwarderChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [ + event.address, + event.params.host, + event.params.superToken, + event.params.forwarder, + ]); ev.governanceAddress = event.address; ev.host = event.params.host; @@ -134,7 +139,7 @@ export function handleSuperTokenMinimumDepositChanged( ): void { const eventId = createEventID("SuperTokenMinimumDepositChanged", event); const ev = new SuperTokenMinimumDepositChangedEvent(eventId); - initializeEventEntity(ev, event, []); + initializeEventEntity(ev, event, [event.address, event.params.host, event.params.superToken]); ev.governanceAddress = event.address; ev.host = event.params.host; diff --git a/packages/subgraph/tests/superToken/event/superToken.event.test.ts b/packages/subgraph/tests/superToken/event/superToken.event.test.ts index f515b4165a..b04f280ba2 100644 --- a/packages/subgraph/tests/superToken/event/superToken.event.test.ts +++ b/packages/subgraph/tests/superToken/event/superToken.event.test.ts @@ -9,6 +9,7 @@ import { import { handleAgreementLiquidatedBy, handleAgreementLiquidatedV2, + handleApproval, handleBurned, handleMinted, handleSent, @@ -18,7 +19,7 @@ import { } from "../../../src/mappings/superToken"; import { BIG_INT_ONE, BIG_INT_ZERO, encode, ZERO_ADDRESS } from "../../../src/utils"; import { assertEmptyTokenStatisticProperties, assertEventBaseProperties, assertTokenStatisticProperties } from "../../assertionHelpers"; -import { alice, bob, cfaV1Address, charlie, DEFAULT_DECIMALS, delta, FAKE_INITIAL_BALANCE, maticXName, maticXSymbol } from "../../constants"; +import { alice, bob, cfaV1Address, charlie, DEFAULT_DECIMALS, delta, FAKE_INITIAL_BALANCE, FALSE, maticXName, maticXSymbol, TRUE } from "../../constants"; import { getETHAddress, getETHUnsignedBigInt, stringToBytes } from "../../converters"; import { createStream, createStreamRevision } from "../../mockedEntities"; import { mockedGetAppManifest, mockedGetHost, mockedHandleSuperTokenInitRPCCalls, mockedRealtimeBalanceOf } from "../../mockedFunctions"; @@ -28,6 +29,7 @@ import { createBurnedEvent, createMintedEvent, createSentEvent, + createSuperTokenApprovalEvent, createTokenDowngradedEvent, createTokenUpgradedEvent, createTransferEvent, @@ -337,6 +339,30 @@ describe("SuperToken Mapper Unit Tests", () => { assert.fieldEquals("TokenDowngradedEvent", id, "amount", amount.toString()); }); + test("handleApproval() - Should create a new ApprovalEvent entity", () => { + const owner = alice; + const spender = bob; + const value = BigInt.fromI32(100); + + const superTokenApprovalEvent = createSuperTokenApprovalEvent( + owner, + spender, + value + ); + + handleApproval(superTokenApprovalEvent); + + const id = assertEventBaseProperties( + superTokenApprovalEvent, + "Approval" + ); + assert.fieldEquals("ApprovalEvent", id, "owner", owner); + assert.fieldEquals("ApprovalEvent", id, "to", spender); + assert.fieldEquals("ApprovalEvent", id, "amount", value.toString()); + assert.fieldEquals("ApprovalEvent", id, "isNFTApproval", FALSE); + assert.fieldEquals("ApprovalEvent", id, "tokenId", "0"); + }); + test("handleTransfer() - Should create a new TransferEvent entity", () => { const from = alice; const to = bob; @@ -480,7 +506,7 @@ describe("SuperToken Mapper Unit Tests", () => { "operatorData", operatorData.toHexString() ); - }); + }); test("TokenStatistic::totalNumberOfHolders should decrease its count when a user transfers tokens and the balance reaches 0.", () => { const from = alice; diff --git a/packages/subgraph/tests/superToken/superToken.helper.ts b/packages/subgraph/tests/superToken/superToken.helper.ts index a8f9d82ae3..4ac930cdf8 100644 --- a/packages/subgraph/tests/superToken/superToken.helper.ts +++ b/packages/subgraph/tests/superToken/superToken.helper.ts @@ -77,6 +77,20 @@ export function createTokenUpgradedEvent( return newTokenUpgradedEvent; } +export function createSuperTokenApprovalEvent( + owner: string, + spender: string, + value: BigInt +): Approval { + const newApprovalEvent = changetype(newMockEvent()); + newApprovalEvent.parameters = new Array(); + newApprovalEvent.parameters.push(getAddressEventParam("owner", owner)); + newApprovalEvent.parameters.push(getAddressEventParam("spender", spender)); + newApprovalEvent.parameters.push(getBigIntEventParam("value", value)); + + return newApprovalEvent; +} + export function createTokenDowngradedEvent( account: string, amount: BigInt From 4bf79c82298d0bf520333c7436ec475cc65c877d Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 19 Mar 2024 14:49:51 +0200 Subject: [PATCH 09/15] [subgraph] Fix Correctness of GDA Entities (#1890) --------- Co-authored-by: 0xdavinchee <0xdavinchee@gmail.com> --- packages/subgraph/config/hardhat.json | 1 + packages/subgraph/config/polygon-mainnet.json | 1 + packages/subgraph/schema.graphql | 8 + packages/subgraph/src/mappingHelpers.ts | 114 +++- packages/subgraph/src/mappings/gdav1.ts | 20 +- .../subgraph/src/mappings/superfluidPool.ts | 41 +- packages/subgraph/src/utils.ts | 9 + ...-pool-member-total-amount-received.test.ts | 543 ++++++++++++------ packages/subgraph/tests/mockedFunctions.ts | 16 + 9 files changed, 549 insertions(+), 204 deletions(-) create mode 100644 packages/subgraph/config/hardhat.json create mode 100644 packages/subgraph/config/polygon-mainnet.json diff --git a/packages/subgraph/config/hardhat.json b/packages/subgraph/config/hardhat.json new file mode 100644 index 0000000000..d9f3424abb --- /dev/null +++ b/packages/subgraph/config/hardhat.json @@ -0,0 +1 @@ +{"network":"mainnet","testNetwork":"hardhat","hostStartBlock":0,"hostAddress":"0x4374EEcaAD0Dcaa149CfFc160d5a0552B1D092b0","cfaAddress":"0x44BF2a9217A2970A1bCC7529Bf1d40828C594320","idaAddress":"0x0826223156fF61F9abf620D2f58A06177DA664Cc","gdaAddress":"0x1Ad83f2789e013a41eA18819F0e24a4d41477b4c","superTokenFactoryAddress":"0x9b9389FacF9d345676b178EfEe328334cA711A38","resolverV1Address":"0x0e528E13E32cfB153818F1e10c7aff11ec5B46A3","nativeAssetSuperTokenAddress":"0x68bFD28e2AB62C450C563E1687f5f4F6b008149f","constantOutflowNFTAddress":"0x765FEFc8D7b2A6ec1D83626c50781e8cdd7e8284","constantInflowNFTAddress":"0x0983210c9f6f968ACC2010ac4dc56124dcDe2EC2"} \ No newline at end of file diff --git a/packages/subgraph/config/polygon-mainnet.json b/packages/subgraph/config/polygon-mainnet.json new file mode 100644 index 0000000000..8637fdd0b2 --- /dev/null +++ b/packages/subgraph/config/polygon-mainnet.json @@ -0,0 +1 @@ +{"network":"matic","hostStartBlock":11650500,"hostAddress":"0x3E14dC1b13c488a8d5D310918780c983bD5982E7","cfaAddress":"0x6EeE6060f715257b970700bc2656De21dEdF074C","idaAddress":"0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1","gdaAddress":"0x961dd5A052741B49B6CBf6759591f9D8576fCFb0","superTokenFactoryAddress":"0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34","resolverV1Address":"0x8bDCb5613153f41B2856F71Bd7A7e0432F6dbe58","nativeAssetSuperTokenAddress":"0x3aD736904E9e65189c3000c7DD2c8AC8bB7cD4e3","constantOutflowNFTAddress":"0x554e2bbaCF43FD87417b7201A9F1649a3ED89d68","constantInflowNFTAddress":"0x55909bB8cd8276887Aae35118d60b19755201c68"} \ No newline at end of file diff --git a/packages/subgraph/schema.graphql b/packages/subgraph/schema.graphql index 5820aba5fb..ca3c7ffa44 100644 --- a/packages/subgraph/schema.graphql +++ b/packages/subgraph/schema.graphql @@ -1815,6 +1815,11 @@ type Pool @entity { totalAmountInstantlyDistributedUntilUpdatedAt: BigInt! totalAmountFlowedDistributedUntilUpdatedAt: BigInt! totalAmountDistributedUntilUpdatedAt: BigInt! + totalFlowAdjustmentAmountDistributedUntilUpdatedAt: BigInt! + + perUnitSettledValue: BigInt! + perUnitFlowRate: BigInt! + """ A member is any account which has more than 0 units in the pool. """ @@ -1870,6 +1875,9 @@ type PoolMember @entity { poolTotalAmountDistributedUntilUpdatedAt: BigInt! totalAmountReceivedUntilUpdatedAt: BigInt! + syncedPerUnitSettledValue: BigInt! + syncedPerUnitFlowRate: BigInt! + account: Account! pool: Pool! diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index 82cf7a0cb5..2f206ffed6 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -36,7 +36,6 @@ import { getPoolDistributorID, getActiveStreamsDelta, getClosedStreamsDelta, - MAX_UINT256, } from "./utils"; import { SuperToken as SuperTokenTemplate } from "../generated/templates"; import { ISuperToken as SuperToken } from "../generated/templates/SuperToken/ISuperToken"; @@ -499,6 +498,11 @@ export function getOrInitPool(event: ethereum.Event, poolId: string): Pool { pool.totalAmountInstantlyDistributedUntilUpdatedAt = BIG_INT_ZERO; pool.totalAmountFlowedDistributedUntilUpdatedAt = BIG_INT_ZERO; pool.totalAmountDistributedUntilUpdatedAt = BIG_INT_ZERO; + pool.totalFlowAdjustmentAmountDistributedUntilUpdatedAt = BIG_INT_ZERO; + + pool.perUnitSettledValue = BIG_INT_ZERO; + pool.perUnitFlowRate = BIG_INT_ZERO; + pool.totalMembers = 0; pool.totalConnectedMembers = 0; pool.totalDisconnectedMembers = 0; @@ -519,9 +523,6 @@ export function updatePoolTotalAmountFlowedAndDistributed( const timeDelta = event.block.timestamp.minus(pool.updatedAtTimestamp); const amountFlowedSinceLastUpdate = pool.flowRate.times(timeDelta); - pool.updatedAtBlockNumber = event.block.number; - pool.updatedAtTimestamp = event.block.timestamp; - pool.totalAmountFlowedDistributedUntilUpdatedAt = pool.totalAmountFlowedDistributedUntilUpdatedAt.plus( amountFlowedSinceLastUpdate @@ -554,13 +555,19 @@ export function getOrInitOrUpdatePoolMember( poolMember.totalAmountClaimed = BIG_INT_ZERO; poolMember.poolTotalAmountDistributedUntilUpdatedAt = BIG_INT_ZERO; poolMember.totalAmountReceivedUntilUpdatedAt = BIG_INT_ZERO; - + + poolMember.syncedPerUnitSettledValue = BIG_INT_ZERO; + poolMember.syncedPerUnitFlowRate = BIG_INT_ZERO; + poolMember.account = poolMemberAddress.toHex(); poolMember.pool = poolAddress.toHex(); } poolMember.updatedAtTimestamp = event.block.timestamp; poolMember.updatedAtBlockNumber = event.block.number; + poolMember.updatedAtTimestamp = event.block.timestamp; + poolMember.updatedAtBlockNumber = event.block.number; + return poolMember; } @@ -1471,33 +1478,80 @@ export function updateAggregateEntitiesTransferData( tokenStatistic.save(); } + +export function particleRTB( + perUnitSettledValue: BigInt, + perUnitFlowRate: BigInt, + currentTimestamp: BigInt, + lastUpdatedTimestamp: BigInt +): BigInt { + const amountFlowedPerUnit = perUnitFlowRate.times(currentTimestamp.minus(lastUpdatedTimestamp)); + return perUnitSettledValue.plus(amountFlowedPerUnit); +} + +export function monetaryUnitPoolMemberRTB(pool: Pool, poolMember: PoolMember, currentTimestamp: BigInt): BigInt { + const poolPerUnitRTB = particleRTB( + pool.perUnitSettledValue, + pool.perUnitFlowRate, + currentTimestamp, + pool.updatedAtTimestamp + ); + const poolMemberPerUnitRTB = particleRTB( + poolMember.syncedPerUnitSettledValue, + poolMember.syncedPerUnitFlowRate, + currentTimestamp, + poolMember.updatedAtTimestamp + ); + + return poolMember.totalAmountReceivedUntilUpdatedAt.plus( + poolPerUnitRTB.minus(poolMemberPerUnitRTB).times(poolMember.units) + ); +} + /** - * Updates `totalAmountReceivedUntilUpdatedAt` and `poolTotalAmountDistributedUntilUpdatedAt` fields - * Requires an explicit save on the PoolMember entity. - * Requires `pool.totalAmountDistributedUntilUpdatedAt` is updated *BEFORE* this function is called. - * Requires that pool.totalUnits and poolMember.units are updated *AFTER* this function is called. - * @param pool the pool entity - * @param poolMember the pool member entity - * @returns the updated pool member entity to be saved + * Updates the pool.perUnitSettledValue to the up to date value based on the current block, + * and updates the updatedAtTimestamp and updatedAtBlockNumber. + * @param pool pool entity + * @param block current block + * @returns updated pool entity */ -export function updatePoolMemberTotalAmountUntilUpdatedAtFields(pool: Pool, poolMember: PoolMember): PoolMember { - let amountReceivedDelta = BIG_INT_ZERO; - // if the pool member has any units, we calculate the delta - // otherwise the delta is going to be 0 - if (!poolMember.units.equals(BIG_INT_ZERO)) { - 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 = - poolMember.totalAmountReceivedUntilUpdatedAt.plus(amountReceivedDelta); - poolMember.poolTotalAmountDistributedUntilUpdatedAt = pool.totalAmountDistributedUntilUpdatedAt; +export function settlePoolParticle(pool: Pool, block: ethereum.Block): Pool { + pool.perUnitSettledValue = particleRTB( + pool.perUnitSettledValue, + pool.perUnitFlowRate, + block.timestamp, + pool.updatedAtTimestamp + ); + pool.updatedAtTimestamp = block.timestamp; + pool.updatedAtBlockNumber = block.number; + + return pool; +} + +export function settlePoolMemberParticle(poolMember: PoolMember, block: ethereum.Block): PoolMember { + poolMember.syncedPerUnitSettledValue = particleRTB( + poolMember.syncedPerUnitSettledValue, + poolMember.syncedPerUnitFlowRate, + block.timestamp, + poolMember.updatedAtTimestamp + ); + poolMember.updatedAtTimestamp = block.timestamp; + poolMember.updatedAtBlockNumber = block.number; + + return poolMember; +} + +export function syncPoolMemberParticle(pool: Pool, poolMember: PoolMember): PoolMember { + poolMember.syncedPerUnitSettledValue = pool.perUnitSettledValue; + poolMember.syncedPerUnitFlowRate = pool.perUnitFlowRate; + poolMember.updatedAtTimestamp = pool.updatedAtTimestamp; + poolMember.updatedAtBlockNumber = pool.updatedAtBlockNumber; return poolMember; } + +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 e5a74baf36..19762416f7 100644 --- a/packages/subgraph/src/mappings/gdav1.ts +++ b/packages/subgraph/src/mappings/gdav1.ts @@ -21,10 +21,11 @@ import { getOrInitPoolDistributor, getOrInitOrUpdatePoolMember, getOrInitTokenStatistic, + settlePDPoolMemberMU, + settlePoolParticle, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, updatePoolDistributorTotalAmountFlowedAndDistributed, - updatePoolMemberTotalAmountUntilUpdatedAtFields, updatePoolTotalAmountFlowedAndDistributed, updateSenderATSStreamData, updateTokenStatisticStreamData, @@ -33,6 +34,7 @@ import { import { BIG_INT_ZERO, createEventID, + divideOrZero, initializeEventEntity, membershipWithUnitsExists, } from "../utils"; @@ -98,7 +100,9 @@ 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); + settlePDPoolMemberMU(pool, poolMember, event.block); if (poolMember.units.gt(BIG_INT_ZERO)) { if (memberConnectedStatusUpdated) { // disconnected -> connected case @@ -126,9 +130,6 @@ export function handlePoolConnectionUpdated( } } } - - // Update totalAmountDistributedUntilUpdatedAt - poolMember = updatePoolMemberTotalAmountUntilUpdatedAtFields(pool, poolMember); pool.save(); poolMember.save(); @@ -229,7 +230,12 @@ export function handleFlowDistributionUpdated( // Update Pool let pool = getOrInitPool(event, event.params.pool.toHex()); + + // @note that we are duplicating update of updatedAtTimestamp/BlockNumber here + // in the two functions pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = settlePoolParticle(pool, event.block); + pool.perUnitFlowRate = divideOrZero(event.params.newDistributorToPoolFlowRate, pool.totalUnits); pool.flowRate = event.params.newTotalDistributionFlowRate; pool.adjustmentFlowRate = event.params.adjustmentFlowRate; pool.save(); @@ -312,7 +318,13 @@ export function handleInstantDistributionUpdated( // Update Pool let pool = getOrInitPool(event, event.params.pool.toHex()); + + // @note that we are duplicating update of updatedAtTimestamp/BlockNumber here + // in the two functions pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + pool = settlePoolParticle(pool, event.block); + // @note a speculations on what needs to be done + pool.perUnitSettledValue = pool.perUnitSettledValue.plus(divideOrZero(event.params.actualAmount, pool.totalUnits)); const previousTotalAmountDistributed = pool.totalAmountDistributedUntilUpdatedAt; pool.totalAmountInstantlyDistributedUntilUpdatedAt = diff --git a/packages/subgraph/src/mappings/superfluidPool.ts b/packages/subgraph/src/mappings/superfluidPool.ts index 15a22f6b8c..12afde5e09 100644 --- a/packages/subgraph/src/mappings/superfluidPool.ts +++ b/packages/subgraph/src/mappings/superfluidPool.ts @@ -9,9 +9,9 @@ import { _createTokenStatisticLogEntity, getOrInitPool, getOrInitOrUpdatePoolMember, + settlePDPoolMemberMU, updateATSStreamedAndBalanceUntilUpdatedAt, updateAggregateDistributionAgreementData, - updatePoolMemberTotalAmountUntilUpdatedAtFields, updatePoolTotalAmountFlowedAndDistributed, updateTokenStatsStreamedUntilUpdatedAt, } from "../mappingHelpers"; @@ -24,14 +24,17 @@ export function handleDistributionClaimed(event: DistributionClaimed): void { // Update Pool let pool = getOrInitPool(event, event.address.toHex()); - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); - pool.save(); - - // Update PoolMember let poolMember = getOrInitOrUpdatePoolMember(event, event.address, event.params.member); poolMember.totalAmountClaimed = event.params.totalClaimed; - poolMember = updatePoolMemberTotalAmountUntilUpdatedAtFields(pool, poolMember); + // settle pool and pool member + pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + settlePDPoolMemberMU(pool, poolMember, event.block); + + // Update PoolMember + poolMember.totalAmountClaimed = event.params.totalClaimed; + + pool.save(); poolMember.save(); // Update Token Statistics @@ -51,11 +54,30 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { let pool = getOrInitPool(event, event.address.toHex()); let poolMember = getOrInitOrUpdatePoolMember(event, event.address, event.params.member); - pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); - poolMember = updatePoolMemberTotalAmountUntilUpdatedAtFields(pool, poolMember); - const previousUnits = poolMember.units; const unitsDelta = event.params.newUnits.minus(previousUnits); + const newTotalUnits = pool.totalUnits.plus(unitsDelta); + + pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); + settlePDPoolMemberMU(pool, poolMember, event.block); + + // @note TODO update the pool.perUnitFlowRate + // @note TODO update the poolMember.perUnitFlowRate + const existingPoolFlowRate = pool.perUnitFlowRate.times(pool.totalUnits); + let newPerUnitFlowRate: BigInt; + let remainderRate: BigInt; + + if (!newTotalUnits.equals(BIG_INT_ZERO)) { + newPerUnitFlowRate = existingPoolFlowRate.div(newTotalUnits); + remainderRate = existingPoolFlowRate.minus(newPerUnitFlowRate.times(newTotalUnits)); + } else { + remainderRate = existingPoolFlowRate; + newPerUnitFlowRate = BIG_INT_ZERO; + } + pool.perUnitFlowRate = newPerUnitFlowRate; + pool.totalUnits = newTotalUnits; + + poolMember.syncedPerUnitFlowRate = poolMember.syncedPerUnitFlowRate.plus(remainderRate); poolMember.units = event.params.newUnits; if (poolMember.isConnected) { @@ -63,7 +85,6 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { } else { pool.totalDisconnectedUnits = pool.totalDisconnectedUnits.plus(unitsDelta); } - pool.totalUnits = pool.totalUnits.plus(unitsDelta); // 0 units to > 0 units const didPoolMemberBecomeActive = previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO) diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts index a182123f3c..ce7d5c1ed6 100644 --- a/packages/subgraph/src/utils.ts +++ b/packages/subgraph/src/utils.ts @@ -387,3 +387,12 @@ export function createLogID( event.logIndex.toString() ); } + +export function divideOrZero( + numerator: BigInt, + denominator: BigInt +): BigInt { + return denominator.equals(BIG_INT_ZERO) + ? BIG_INT_ZERO + : numerator.div(denominator); +} \ No newline at end of file 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 c214de0a25..fdd04955af 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 @@ -1,176 +1,139 @@ -import { assert, describe, test } from "matchstick-as"; -import { Pool, PoolDistributor, PoolMember } from "../../generated/schema" +import { assert, beforeEach, clearStore, describe, test } from "matchstick-as"; import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; -import { FAKE_INITIAL_BALANCE, alice as alice_, bob as bob_, charlie, delta, echo, maticXAddress, superfluidPool } from "../constants"; -import { BIG_INT_ZERO, getPoolMemberID } from "../../src/utils"; -import { handleInstantDistributionUpdated } from "../../src/mappings/gdav1"; -import { createInstantDistributionUpdatedEvent, createMemberUnitsUpdatedEvent } from "../gdav1/gdav1.helper"; -import { mockedGetAppManifest, mockedRealtimeBalanceOf } from "../mockedFunctions"; +import { alice as alice_, bob as bob_, delta, echo, maticXAddress, superfluidPool } from "../constants"; +import { getPoolMemberID } from "../../src/utils"; +import { handleFlowDistributionUpdated, handleInstantDistributionUpdated, handlePoolCreated } from "../../src/mappings/gdav1"; +import { createFlowDistributionUpdatedEvent, createInstantDistributionUpdatedEvent, createMemberUnitsUpdatedEvent, createPoolAndReturnPoolCreatedEvent } from "../gdav1/gdav1.helper"; +import { mockedAppManifestAndRealtimeBalanceOf } from "../mockedFunctions"; import { handleMemberUnitsUpdated } from "../../src/mappings/superfluidPool"; +import { Pool } from "../../generated/schema"; -/** - * Problem description - 1. Create pool - 2. Add member A and update A units to 100 - 3. Distribute 100 tokens - 4. Add member B and update B units to 100 - 4. Distribute 100 tokens - - Expected result: - member A 150 tokens - member B 50 tokens - - Actual result: - member A 100 tokens - member B 50 tokens - */ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", () => { - test("create elaborate scenario with 2 distributions and 2 pool members", () => { - return; // ignore test for CI (as the test is failing for now) + beforeEach(() => { + clearStore(); + }); + /** + * Problem description + 1. Create pool + 2. Add member A and update A units to 100 + 3. Distribute 1000 tokens + 4. Add member B and update B units to 100 + 5. Distribute 1000 tokens + + Expected result: + member A 1500 tokens + member B 500 tokens + */ + test("create elaborate scenario with 2 instant distributions and 2 pool members", () => { const superTokenAddress = maticXAddress; - + const poolAdminAndDistributorAddress = Address.fromString(delta); + const poolAddress = Address.fromString(superfluidPool); + // # Arrange State 1 // ## Arrange Pool - const poolAddress = Address.fromString(superfluidPool); - const poolAdminAndDistributorAddress = Address.fromString(delta); - let pool = new Pool(poolAddress.toHexString()); - pool.createdAtTimestamp = BigInt.fromI32(1); - pool.createdAtBlockNumber = BigInt.fromI32(1); - pool.updatedAtTimestamp = BigInt.fromI32(1); - pool.updatedAtBlockNumber = BigInt.fromI32(1); + const poolCreatedEvent = createPoolAndReturnPoolCreatedEvent(poolAdminAndDistributorAddress.toHexString(), superTokenAddress, poolAddress.toHexString()); - pool.totalMembers = 1; - pool.totalConnectedMembers = 1; - pool.totalDisconnectedMembers = 0; - pool.adjustmentFlowRate = BigInt.fromI32(0); - pool.flowRate = BigInt.fromI32(0); - pool.admin = poolAdminAndDistributorAddress.toHexString(); - pool.totalBuffer = BigInt.fromI32(0); - pool.token = superTokenAddress; - pool.totalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); - pool.totalAmountFlowedDistributedUntilUpdatedAt = BigInt.fromI32(0); - pool.totalAmountInstantlyDistributedUntilUpdatedAt = BigInt.fromI32(0); - pool.totalConnectedUnits = BigInt.fromI32(100); - pool.totalDisconnectedUnits = BigInt.fromI32(0); - pool.totalUnits = BigInt.fromI32(100); - pool.save(); - // --- - // ## Arrange PoolMember 1 const aliceAddress = Address.fromString(alice_); const aliceId = getPoolMemberID(poolAddress, aliceAddress); - const alice = new PoolMember(aliceId) - alice.createdAtTimestamp = BigInt.fromI32(1); - alice.createdAtBlockNumber = BigInt.fromI32(1); - alice.updatedAtTimestamp = BigInt.fromI32(1); - alice.updatedAtBlockNumber = BigInt.fromI32(1); - - alice.account = aliceAddress.toHexString(); - alice.units = BigInt.fromI32(100); - alice.totalAmountReceivedUntilUpdatedAt = BigInt.fromI32(0); - alice.poolTotalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); - alice.isConnected = true; - alice.totalAmountClaimed = BigInt.fromI32(0); - alice.pool = poolAddress.toHexString(); - alice.save(); - // # --- - - // ## Arrange Distributor - const poolDistributor = new PoolDistributor(poolAdminAndDistributorAddress.toHexString()); - poolDistributor.createdAtTimestamp = BigInt.fromI32(1); - poolDistributor.createdAtBlockNumber = BigInt.fromI32(1); - poolDistributor.updatedAtTimestamp = BigInt.fromI32(1); - poolDistributor.updatedAtBlockNumber = BigInt.fromI32(1); - poolDistributor.account = charlie; - poolDistributor.totalBuffer = BigInt.fromI32(0); - poolDistributor.flowRate = BigInt.fromI32(0); - poolDistributor.pool = poolAddress.toHexString(); - poolDistributor.totalAmountDistributedUntilUpdatedAt = BigInt.fromI32(0); - poolDistributor.totalAmountFlowedDistributedUntilUpdatedAt = BigInt.fromI32(0); - poolDistributor.totalAmountInstantlyDistributedUntilUpdatedAt = BigInt.fromI32(0); - poolDistributor.save(); - // --- + const aliceCreatedEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + aliceAddress.toHexString(), + BigInt.fromI32(0), // old units + BigInt.fromI32(100) // new units + ); + aliceCreatedEvent.address = poolAddress; + aliceCreatedEvent.block.timestamp = poolCreatedEvent.block.timestamp; - // # First distribution (State 2) - const instantDistributionEvent = createInstantDistributionUpdatedEvent( + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, aliceAddress.toHexString(), aliceCreatedEvent.block.timestamp); + handleMemberUnitsUpdated(aliceCreatedEvent); + + // # First distribution + const firstDistributionEvent = createInstantDistributionUpdatedEvent( superTokenAddress, poolAddress.toHexString(), poolAdminAndDistributorAddress.toHexString(), echo, - BigInt.fromI32(100), // requested amount - BigInt.fromI32(100), // actual amount + BigInt.fromI32(1000), // requested amount + BigInt.fromI32(1000), // actual amount Bytes.fromHexString("0x") ); - instantDistributionEvent.block.timestamp = BigInt.fromI32(1); - instantDistributionEvent.address = poolAddress; + firstDistributionEvent.block.timestamp = poolCreatedEvent.block.timestamp; + firstDistributionEvent.address = poolAddress; - mockedGetAppManifest(poolAdminAndDistributorAddress.toHexString(), false, false, BIG_INT_ZERO); - mockedRealtimeBalanceOf( - superTokenAddress, - poolAdminAndDistributorAddress.toHexString(), - BigInt.fromI32(1), - FAKE_INITIAL_BALANCE, - BigInt.fromI32(0), - BIG_INT_ZERO - ); - - handleInstantDistributionUpdated(instantDistributionEvent); + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, poolAdminAndDistributorAddress.toHexString(), firstDistributionEvent.block.timestamp); + handleInstantDistributionUpdated(firstDistributionEvent); assert.fieldEquals( "Pool", poolAddress.toHexString(), "totalAmountDistributedUntilUpdatedAt", + "1000" + ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalUnits", "100" ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalMembers", + "1" + ); assert.fieldEquals( "PoolMember", aliceId, "totalAmountReceivedUntilUpdatedAt", "0" ); - // # --- + assert.fieldEquals( + "PoolMember", + aliceId, + "units", + "100" + ); + // --- - // # Arrange State 3 + // # Arrange State 2 // ## Arrange PoolMember 2 (new member) const bobAddress = Address.fromString(bob_); const bobId = getPoolMemberID(poolAddress, bobAddress); - const bob = new PoolMember(bobId) - bob.createdAtTimestamp = BigInt.fromI32(1); - bob.createdAtBlockNumber = BigInt.fromI32(1); - bob.updatedAtTimestamp = BigInt.fromI32(1); - bob.updatedAtBlockNumber = BigInt.fromI32(1); - - bob.account = bobAddress.toHexString(); - bob.units = BigInt.fromI32(100); - bob.totalAmountReceivedUntilUpdatedAt = BigInt.fromI32(0); - bob.poolTotalAmountDistributedUntilUpdatedAt = BigInt.fromI32(100); - bob.isConnected = true; - bob.totalAmountClaimed = BigInt.fromI32(0); - bob.pool = poolAddress.toHexString(); - bob.save(); - // # --- - - // ## Update Pool for member 2 - pool = Pool.load(poolAddress.toHexString())!; - pool.updatedAtTimestamp = BigInt.fromI32(2); - pool.updatedAtBlockNumber = BigInt.fromI32(2); - pool.totalMembers = 2; - pool.totalConnectedMembers = 2; - pool.totalDisconnectedMembers = 0; - pool.totalConnectedUnits = BigInt.fromI32(2000); - pool.totalUnits = BigInt.fromI32(200); - pool.save(); - // --- + let createBobEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + bobAddress.toHexString(), + BigInt.fromI32(0), // old units + BigInt.fromI32(100) // new units + ); + createBobEvent.address = poolAddress; + createBobEvent.block.timestamp = BigInt.fromI32(2); + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, bobAddress.toHexString(), createBobEvent.block.timestamp); + handleMemberUnitsUpdated(createBobEvent); + + // # Second distribution + const secondDistributionEvent = createInstantDistributionUpdatedEvent( + superTokenAddress, + poolAddress.toHexString(), + poolAdminAndDistributorAddress.toHexString(), + echo, + BigInt.fromI32(1000), // requested amount + BigInt.fromI32(1000), // actual amount + Bytes.fromHexString("0x") + ); + secondDistributionEvent.block.timestamp = poolCreatedEvent.block.timestamp; + secondDistributionEvent.address = poolAddress; + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, poolAdminAndDistributorAddress.toHexString(), secondDistributionEvent.block.timestamp); + handleInstantDistributionUpdated(secondDistributionEvent); - // # Second distribution (we can use the first event again) (State 4) - handleInstantDistributionUpdated(instantDistributionEvent); - assert.fieldEquals( "Pool", poolAddress.toHexString(), "totalAmountDistributedUntilUpdatedAt", - "200" + "2000" ); assert.fieldEquals( "Pool", @@ -178,37 +141,248 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", "totalUnits", "200" ); - // # --- + assert.fieldEquals( + "PoolMember", + bobId, + "totalAmountReceivedUntilUpdatedAt", + "0" + ); + assert.fieldEquals( + "PoolMember", + bobId, + "units", + "100" + ); + // --- + // Arrange State 3 // # Update PoolMember 2's units to get the `totalAmountReceivedUntilUpdatedAt` - const updateBobUnitsEvent = createMemberUnitsUpdatedEvent( + const updateBobEvent = createMemberUnitsUpdatedEvent( superTokenAddress, bobAddress.toHexString(), BigInt.fromI32(100), // old units BigInt.fromI32(100) // new units ); // Note, the units can stay the same, we just want to trigger an update. - updateBobUnitsEvent.address = poolAddress; - updateBobUnitsEvent.block.timestamp = BigInt.fromI32(2); + updateBobEvent.address = poolAddress; + updateBobEvent.block.timestamp = BigInt.fromI32(3); + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, bobAddress.toHexString(), updateBobEvent.block.timestamp); + handleMemberUnitsUpdated(createBobEvent); + + assert.fieldEquals( + "PoolMember", + bobId, + "totalAmountReceivedUntilUpdatedAt", + "500" + ); + assert.fieldEquals( + "PoolMember", + bobId, + "units", + "100" + ); + + // # Update PoolMember 1's units to get the `totalAmountReceivedUntilUpdatedAt` + const updateAliceEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + aliceAddress.toHexString(), + BigInt.fromI32(100), // old units + BigInt.fromI32(100) // new units + ); + // Note, the units can stay the same, we just want to trigger an update. + updateAliceEvent.address = poolAddress; + updateAliceEvent.block.timestamp = BigInt.fromI32(3); + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, aliceAddress.toHexString(), updateAliceEvent.block.timestamp); + handleMemberUnitsUpdated(updateAliceEvent); + + assert.fieldEquals( + "PoolMember", + aliceId, + "totalAmountReceivedUntilUpdatedAt", + "1500" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "units", + "100" + ); + }); + /** + * Problem description + 1. Create pool + 2. Add member A and update A units to 100 + 3. Flow 1000 tokens (elapse 1 second) + 4. Add member B and update B units to 100 + 5. Flow 1000 tokens (elapse 1 second) + 6. Update flow rate to 2000 tokens + 7. Flow 2000 tokens (elapse 1 second) + + Expected result: + member A 2500 tokens + member B 1500 tokens + + Actual result: + member A 100 tokens + member B 50 tokens + */ + test("create elaborate scenario with 2 flowing distributions and 2 pool members", () => { + const superTokenAddress = maticXAddress; + const poolAdminAndDistributorAddress = Address.fromString(delta); + const poolAddress = Address.fromString(superfluidPool); + + // # Arrange State 1 + // ## Arrange Pool + const poolCreatedEvent = createPoolAndReturnPoolCreatedEvent(poolAdminAndDistributorAddress.toHexString(), superTokenAddress, poolAddress.toHexString()); + assert.stringEquals(poolCreatedEvent.block.timestamp.toString(), BigInt.fromI32(1).toString()); + + handlePoolCreated(poolCreatedEvent); + + 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); + const aliceCreatedEvent = createMemberUnitsUpdatedEvent( + superTokenAddress, + aliceAddress.toHexString(), + BigInt.fromI32(0), // old units + BigInt.fromI32(100) // new units + ); + aliceCreatedEvent.address = poolAddress; + aliceCreatedEvent.block.timestamp = poolCreatedEvent.block.timestamp; // 1 + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, aliceAddress.toHexString(), aliceCreatedEvent.block.timestamp); + handleMemberUnitsUpdated(aliceCreatedEvent); + + // # First flow rate + if (pool) { + pool.updatedAtTimestamp = aliceCreatedEvent.block.timestamp; + } + + const firstFlowRateEvent = createFlowDistributionUpdatedEvent( + superTokenAddress, + poolAddress.toHexString(), + poolAdminAndDistributorAddress.toHexString(), + echo, + BigInt.fromI32(0), // oldFlowRate + BigInt.fromI32(1000), // newDistributorToPoolFlowRate + BigInt.fromI32(1000), // newTotalDistributionFlowRate + poolAdminAndDistributorAddress.toHexString(), // adjustmentFlowRecipient + BigInt.fromI32(0), + Bytes.fromHexString("0x") + ); + firstFlowRateEvent.block.timestamp = poolCreatedEvent.block.timestamp; // 1 + firstFlowRateEvent.address = poolAddress; + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, poolAdminAndDistributorAddress.toHexString(), firstFlowRateEvent.block.timestamp); + handleFlowDistributionUpdated(firstFlowRateEvent); + + // # First flow rate + if (pool) { + pool.updatedAtTimestamp = firstFlowRateEvent.block.timestamp; + } + + // TODO: This fails, how has this already flown??? + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "0" // nothing is flowed yet + ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalUnits", + "100" + ); + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalMembers", + "1" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "totalAmountReceivedUntilUpdatedAt", + "0" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "units", + "100" + ); + // --- - mockedGetAppManifest(bobAddress.toHexString(), false, false, BIG_INT_ZERO); - mockedRealtimeBalanceOf( + // # Arrange State 2 + // ## Arrange PoolMember 2 (new member) + const bobAddress = Address.fromString(bob_); + const bobId = getPoolMemberID(poolAddress, bobAddress); + let createBobEvent = createMemberUnitsUpdatedEvent( superTokenAddress, bobAddress.toHexString(), - BigInt.fromI32(2), - FAKE_INITIAL_BALANCE, + BigInt.fromI32(0), // old units + BigInt.fromI32(100) // new units + ); + createBobEvent.address = poolAddress; + createBobEvent.block.timestamp = BigInt.fromI32(2); // Skip 1 second to let it flow to Alice + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, bobAddress.toHexString(), createBobEvent.block.timestamp); + handleMemberUnitsUpdated(createBobEvent); + + if (pool) { + pool.updatedAtTimestamp = createBobEvent.block.timestamp; + } + + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "1000" + ); + assert.fieldEquals( + "PoolMember", + bobId, + "totalAmountReceivedUntilUpdatedAt", + "0" // Bob just joined, shouldn't have any received + ); + + // # Second flow rate + const secondFlowRateEvent = createFlowDistributionUpdatedEvent( + superTokenAddress, + poolAddress.toHexString(), + poolAdminAndDistributorAddress.toHexString(), + echo, + BigInt.fromI32(1000), // oldFlowRate + BigInt.fromI32(2000), // newDistributorToPoolFlowRate + BigInt.fromI32(2000), // newTotalDistributionFlowRate + poolAdminAndDistributorAddress.toHexString(), // adjustmentFlowRecipient BigInt.fromI32(0), - BIG_INT_ZERO + Bytes.fromHexString("0x") ); + secondFlowRateEvent.block.timestamp = BigInt.fromI32(3); // One second skipped, 2 seconds flown to Alice, 1 second to Bob + secondFlowRateEvent.address = poolAddress; + + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, poolAdminAndDistributorAddress.toHexString(), secondFlowRateEvent.block.timestamp); + handleFlowDistributionUpdated(secondFlowRateEvent); - // Act 1 - handleMemberUnitsUpdated(updateBobUnitsEvent); + if (pool) { + pool.updatedAtTimestamp = secondFlowRateEvent.block.timestamp; + } assert.fieldEquals( "Pool", poolAddress.toHexString(), "totalAmountDistributedUntilUpdatedAt", - "200" + "2000" // Only for first flow rate ); assert.fieldEquals( "Pool", @@ -220,38 +394,87 @@ describe("PoolMember ending up with wrong `totalAmountReceivedUntilUpdatedAt`", "PoolMember", bobId, "totalAmountReceivedUntilUpdatedAt", - "50" + "0" // it's 500 if we query on-chain, but 0 here because update member units hasn't been called again since + ); + assert.fieldEquals( + "PoolMember", + bobId, + "units", + "100" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "totalAmountReceivedUntilUpdatedAt", + "0" // it's 1500 if we query on-chain, but 0 here because update member units hasn't been called again since ); + // --- - // # Update PoolMember 1's units to get the `totalAmountReceivedUntilUpdatedAt` - const updateAliceUnitsEvent = createMemberUnitsUpdatedEvent( + // Arrange State 3 + // # Update PoolMember 2's units to get the `totalAmountReceivedUntilUpdatedAt` + const updateBobEvent = createMemberUnitsUpdatedEvent( superTokenAddress, - aliceAddress.toHexString(), - BigInt.fromI32(10), // old units - BigInt.fromI32(10) // new units + bobAddress.toHexString(), + BigInt.fromI32(100), // old units + BigInt.fromI32(100) // new units ); // Note, the units can stay the same, we just want to trigger an update. - updateAliceUnitsEvent.address = poolAddress; - updateAliceUnitsEvent.block.timestamp = BigInt.fromI32(3); + updateBobEvent.address = poolAddress; + updateBobEvent.block.timestamp = BigInt.fromI32(4); // 4 - 1 = 3 seconds of flow - mockedGetAppManifest(aliceAddress.toHexString(), false, false, BIG_INT_ZERO); - mockedRealtimeBalanceOf( + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, bobAddress.toHexString(), updateBobEvent.block.timestamp); + handleMemberUnitsUpdated(updateBobEvent); + + if (pool) { + pool.updatedAtTimestamp = updateBobEvent.block.timestamp; + } + assert.fieldEquals( + "Pool", + poolAddress.toHexString(), + "totalAmountDistributedUntilUpdatedAt", + "4000" + ); + assert.fieldEquals( + "PoolMember", + bobId, + "totalAmountReceivedUntilUpdatedAt", + "1500" // 50% of 2000 + ); + assert.fieldEquals( + "PoolMember", + bobId, + "units", + "100" + ); + + // # Update PoolMember 1's units to get the `totalAmountReceivedUntilUpdatedAt` + const updateAliceEvent = createMemberUnitsUpdatedEvent( superTokenAddress, aliceAddress.toHexString(), - BigInt.fromI32(3), - FAKE_INITIAL_BALANCE, - BigInt.fromI32(0), - BIG_INT_ZERO + BigInt.fromI32(100), // old units + BigInt.fromI32(100) // new units ); + // Note, the units can stay the same, we just want to trigger an update. + updateAliceEvent.address = poolAddress; + updateAliceEvent.block.timestamp = updateBobEvent.block.timestamp; // 4 - // Act 2 - handleMemberUnitsUpdated(updateAliceUnitsEvent); + mockedAppManifestAndRealtimeBalanceOf(superTokenAddress, aliceAddress.toHexString(), updateAliceEvent.block.timestamp); + handleMemberUnitsUpdated(updateAliceEvent); + if (pool) { + pool.updatedAtTimestamp = updateAliceEvent.block.timestamp; + } assert.fieldEquals( "PoolMember", aliceId, "totalAmountReceivedUntilUpdatedAt", - "150" // 100 from first + 50 from second + "2500" + ); + assert.fieldEquals( + "PoolMember", + aliceId, + "units", + "100" ); }) }); diff --git a/packages/subgraph/tests/mockedFunctions.ts b/packages/subgraph/tests/mockedFunctions.ts index 88629bdc57..7ef88761b5 100644 --- a/packages/subgraph/tests/mockedFunctions.ts +++ b/packages/subgraph/tests/mockedFunctions.ts @@ -379,3 +379,19 @@ export function mockedApprove( ]) .returns([getETHUnsignedBigInt(expectedValue)]); } + +export function mockedAppManifestAndRealtimeBalanceOf( + tokenAddress: string, + accountAddress: string, + timestamp: BigInt +): void { + mockedGetAppManifest(accountAddress, false, false, BIG_INT_ZERO); + mockedRealtimeBalanceOf( + tokenAddress, + accountAddress, + timestamp, + FAKE_INITIAL_BALANCE, + BIG_INT_ZERO, + BIG_INT_ZERO + ); +} From cc9cb4312d5bbae2084497e12e572604d1b828a0 Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Wed, 20 Mar 2024 16:22:47 +0200 Subject: [PATCH 10/15] add getTotalAmountReceivedByPoolMember to sdk-core (#1902) --- packages/sdk-core/CHANGELOG.md | 3 + packages/sdk-core/src/SuperfluidPool.ts | 26 + packages/sdk-core/src/interfaces.ts | 5 + packages/sdk-core/src/subgraph/schema.graphql | 635 ++++++------------ 4 files changed, 257 insertions(+), 412 deletions(-) diff --git a/packages/sdk-core/CHANGELOG.md b/packages/sdk-core/CHANGELOG.md index 60197e4337..1206cfa0d7 100644 --- a/packages/sdk-core/CHANGELOG.md +++ b/packages/sdk-core/CHANGELOG.md @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Added +- Added `getTotalAmountReceivedByMember` + ### Changed - Map the name from subgraph to an unknown event, instead of "\_Unknown". diff --git a/packages/sdk-core/src/SuperfluidPool.ts b/packages/sdk-core/src/SuperfluidPool.ts index 62312f1cfe..dbe642aac9 100644 --- a/packages/sdk-core/src/SuperfluidPool.ts +++ b/packages/sdk-core/src/SuperfluidPool.ts @@ -13,6 +13,7 @@ import { GetClaimableParams, GetDisconnectedBalanceParams, GetMemberFlowRateParams, + GetTotalAmountReceivedByMemberParams, GetUnitsParams, SuperfluidPoolDecreaseAllowanceParams, SuperfluidPoolIncreaseAllowanceParams, @@ -236,6 +237,31 @@ export default class SuperfluidPoolClass { } }; + /** + * Retrieves the flow rate for a specific member. + * @param member The member's address. + * @param providerOrSigner A provider or signer object + * @returns The total amount received by the member. + */ + getTotalAmountReceivedByMember = async ( + params: GetTotalAmountReceivedByMemberParams + ): Promise => { + try { + return ( + await this.contract + .connect(params.providerOrSigner) + .getTotalAmountReceivedByMember(params.member) + ).toString(); + } catch (err) { + throw new SFError({ + type: "SUPERFLUID_POOL_READ", + message: + "There was an error getting the total amount received by member.", + cause: err, + }); + } + }; + /** * Retrieves the claimable amount for a specific member and time. * @param member The member's address. diff --git a/packages/sdk-core/src/interfaces.ts b/packages/sdk-core/src/interfaces.ts index 5207ecc4f2..9093b9ed39 100644 --- a/packages/sdk-core/src/interfaces.ts +++ b/packages/sdk-core/src/interfaces.ts @@ -778,6 +778,11 @@ export interface GetMemberFlowRateParams { readonly providerOrSigner: ethers.providers.Provider | ethers.Signer; } +export interface GetTotalAmountReceivedByMemberParams { + readonly member: string; + readonly providerOrSigner: ethers.providers.Provider | ethers.Signer; +} + export interface ClaimAllForMemberParams { readonly member: string; readonly signer: ethers.Signer; diff --git a/packages/sdk-core/src/subgraph/schema.graphql b/packages/sdk-core/src/subgraph/schema.graphql index 7d73de9331..7c93eab6f2 100644 --- a/packages/sdk-core/src/subgraph/schema.graphql +++ b/packages/sdk-core/src/subgraph/schema.graphql @@ -21,6 +21,9 @@ type _Block_ { """Integer representation of the timestamp stored in blocks for the chain""" timestamp: Int + + """The hash of the parent block""" + parentHash: Bytes } """The type for the top-level _meta field""" @@ -227,23 +230,12 @@ type AccountTokenSnapshot { """ 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. @@ -281,23 +273,12 @@ type AccountTokenSnapshot { """ 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`. @@ -350,6 +331,7 @@ type AccountTokenSnapshot { """ 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! @@ -360,29 +342,12 @@ type AccountTokenSnapshot { """ 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. @@ -402,24 +367,11 @@ type AccountTokenSnapshot { """ 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 @@ -434,12 +386,6 @@ type AccountTokenSnapshot { """ totalCFAAmountStreamedOutUntilUpdatedAt: BigInt! - """ - The total amount of `token` streamed from this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for the GDA. - - """ - totalGDAAmountStreamedOutUntilUpdatedAt: BigInt! - """ The total amount of `token` streamed through this `account` until the `updatedAtTimestamp`/`updatedAtBlock` for all flow agreements. @@ -453,12 +399,6 @@ type AccountTokenSnapshot { """ 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. @@ -563,22 +503,6 @@ input AccountTokenSnapshot_filter { activeIncomingStreamCount_lte: Int activeIncomingStreamCount_in: [Int!] activeIncomingStreamCount_not_in: [Int!] - activeCFAIncomingStreamCount: Int - activeCFAIncomingStreamCount_not: Int - activeCFAIncomingStreamCount_gt: Int - activeCFAIncomingStreamCount_lt: Int - activeCFAIncomingStreamCount_gte: Int - activeCFAIncomingStreamCount_lte: Int - activeCFAIncomingStreamCount_in: [Int!] - activeCFAIncomingStreamCount_not_in: [Int!] - activeGDAIncomingStreamCount: Int - activeGDAIncomingStreamCount_not: Int - activeGDAIncomingStreamCount_gt: Int - activeGDAIncomingStreamCount_lt: Int - activeGDAIncomingStreamCount_gte: Int - activeGDAIncomingStreamCount_lte: Int - activeGDAIncomingStreamCount_in: [Int!] - activeGDAIncomingStreamCount_not_in: [Int!] totalNumberOfClosedStreams: Int totalNumberOfClosedStreams_not: Int totalNumberOfClosedStreams_gt: Int @@ -635,22 +559,6 @@ input AccountTokenSnapshot_filter { inactiveIncomingStreamCount_lte: Int inactiveIncomingStreamCount_in: [Int!] inactiveIncomingStreamCount_not_in: [Int!] - inactiveCFAIncomingStreamCount: Int - inactiveCFAIncomingStreamCount_not: Int - inactiveCFAIncomingStreamCount_gt: Int - inactiveCFAIncomingStreamCount_lt: Int - inactiveCFAIncomingStreamCount_gte: Int - inactiveCFAIncomingStreamCount_lte: Int - inactiveCFAIncomingStreamCount_in: [Int!] - inactiveCFAIncomingStreamCount_not_in: [Int!] - inactiveGDAIncomingStreamCount: Int - inactiveGDAIncomingStreamCount_not: Int - inactiveGDAIncomingStreamCount_gt: Int - inactiveGDAIncomingStreamCount_lt: Int - inactiveGDAIncomingStreamCount_gte: Int - inactiveGDAIncomingStreamCount_lte: Int - inactiveGDAIncomingStreamCount_in: [Int!] - inactiveGDAIncomingStreamCount_not_in: [Int!] totalSubscriptionsWithUnits: Int totalSubscriptionsWithUnits_not: Int totalSubscriptionsWithUnits_gt: Int @@ -731,14 +639,6 @@ input AccountTokenSnapshot_filter { totalCFANetFlowRate_lte: BigInt totalCFANetFlowRate_in: [BigInt!] totalCFANetFlowRate_not_in: [BigInt!] - totalGDANetFlowRate: BigInt - totalGDANetFlowRate_not: BigInt - totalGDANetFlowRate_gt: BigInt - totalGDANetFlowRate_lt: BigInt - totalGDANetFlowRate_gte: BigInt - totalGDANetFlowRate_lte: BigInt - totalGDANetFlowRate_in: [BigInt!] - totalGDANetFlowRate_not_in: [BigInt!] totalInflowRate: BigInt totalInflowRate_not: BigInt totalInflowRate_gt: BigInt @@ -747,22 +647,6 @@ input AccountTokenSnapshot_filter { totalInflowRate_lte: BigInt totalInflowRate_in: [BigInt!] totalInflowRate_not_in: [BigInt!] - totalCFAInflowRate: BigInt - totalCFAInflowRate_not: BigInt - totalCFAInflowRate_gt: BigInt - totalCFAInflowRate_lt: BigInt - totalCFAInflowRate_gte: BigInt - totalCFAInflowRate_lte: BigInt - totalCFAInflowRate_in: [BigInt!] - totalCFAInflowRate_not_in: [BigInt!] - totalGDAInflowRate: BigInt - totalGDAInflowRate_not: BigInt - totalGDAInflowRate_gt: BigInt - totalGDAInflowRate_lt: BigInt - totalGDAInflowRate_gte: BigInt - totalGDAInflowRate_lte: BigInt - totalGDAInflowRate_in: [BigInt!] - totalGDAInflowRate_not_in: [BigInt!] totalOutflowRate: BigInt totalOutflowRate_not: BigInt totalOutflowRate_gt: BigInt @@ -795,22 +679,6 @@ input AccountTokenSnapshot_filter { totalAmountStreamedInUntilUpdatedAt_lte: BigInt totalAmountStreamedInUntilUpdatedAt_in: [BigInt!] totalAmountStreamedInUntilUpdatedAt_not_in: [BigInt!] - totalCFAAmountStreamedInUntilUpdatedAt: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_not: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_gt: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_lt: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_gte: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_lte: BigInt - totalCFAAmountStreamedInUntilUpdatedAt_in: [BigInt!] - totalCFAAmountStreamedInUntilUpdatedAt_not_in: [BigInt!] - totalGDAAmountStreamedInUntilUpdatedAt: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_not: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_gt: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_lt: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_gte: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_lte: BigInt - totalGDAAmountStreamedInUntilUpdatedAt_in: [BigInt!] - totalGDAAmountStreamedInUntilUpdatedAt_not_in: [BigInt!] totalAmountStreamedOutUntilUpdatedAt: BigInt totalAmountStreamedOutUntilUpdatedAt_not: BigInt totalAmountStreamedOutUntilUpdatedAt_gt: BigInt @@ -827,14 +695,6 @@ input AccountTokenSnapshot_filter { totalCFAAmountStreamedOutUntilUpdatedAt_lte: BigInt totalCFAAmountStreamedOutUntilUpdatedAt_in: [BigInt!] totalCFAAmountStreamedOutUntilUpdatedAt_not_in: [BigInt!] - totalGDAAmountStreamedOutUntilUpdatedAt: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_not: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_gt: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_lt: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_gte: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_lte: BigInt - totalGDAAmountStreamedOutUntilUpdatedAt_in: [BigInt!] - totalGDAAmountStreamedOutUntilUpdatedAt_not_in: [BigInt!] totalAmountStreamedUntilUpdatedAt: BigInt totalAmountStreamedUntilUpdatedAt_not: BigInt totalAmountStreamedUntilUpdatedAt_gt: BigInt @@ -851,14 +711,6 @@ input AccountTokenSnapshot_filter { totalCFAAmountStreamedUntilUpdatedAt_lte: BigInt totalCFAAmountStreamedUntilUpdatedAt_in: [BigInt!] totalCFAAmountStreamedUntilUpdatedAt_not_in: [BigInt!] - totalGDAAmountStreamedUntilUpdatedAt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_not: BigInt - totalGDAAmountStreamedUntilUpdatedAt_gt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_lt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_gte: BigInt - totalGDAAmountStreamedUntilUpdatedAt_lte: BigInt - totalGDAAmountStreamedUntilUpdatedAt_in: [BigInt!] - totalGDAAmountStreamedUntilUpdatedAt_not_in: [BigInt!] totalAmountTransferredUntilUpdatedAt: BigInt totalAmountTransferredUntilUpdatedAt_not: BigInt totalAmountTransferredUntilUpdatedAt_gt: BigInt @@ -931,8 +783,6 @@ enum AccountTokenSnapshot_orderBy { activeCFAOutgoingStreamCount activeGDAOutgoingStreamCount activeIncomingStreamCount - activeCFAIncomingStreamCount - activeGDAIncomingStreamCount totalNumberOfClosedStreams totalCFANumberOfClosedStreams totalGDANumberOfClosedStreams @@ -940,8 +790,6 @@ enum AccountTokenSnapshot_orderBy { inactiveCFAOutgoingStreamCount inactiveGDAOutgoingStreamCount inactiveIncomingStreamCount - inactiveCFAIncomingStreamCount - inactiveGDAIncomingStreamCount totalSubscriptionsWithUnits totalApprovedSubscriptions totalMembershipsWithUnits @@ -952,22 +800,15 @@ enum AccountTokenSnapshot_orderBy { totalGDADeposit totalNetFlowRate totalCFANetFlowRate - totalGDANetFlowRate totalInflowRate - totalCFAInflowRate - totalGDAInflowRate totalOutflowRate totalCFAOutflowRate totalGDAOutflowRate totalAmountStreamedInUntilUpdatedAt - totalCFAAmountStreamedInUntilUpdatedAt - totalGDAAmountStreamedInUntilUpdatedAt totalAmountStreamedOutUntilUpdatedAt totalCFAAmountStreamedOutUntilUpdatedAt - totalGDAAmountStreamedOutUntilUpdatedAt totalAmountStreamedUntilUpdatedAt totalCFAAmountStreamedUntilUpdatedAt - totalGDAAmountStreamedUntilUpdatedAt totalAmountTransferredUntilUpdatedAt account account__id @@ -1052,18 +893,6 @@ type AccountTokenSnapshotLog { """ 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. @@ -1100,23 +929,12 @@ type AccountTokenSnapshotLog { """ 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`. @@ -1175,36 +993,16 @@ type AccountTokenSnapshotLog { """ 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`. @@ -1229,18 +1027,6 @@ type AccountTokenSnapshotLog { """ 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`. @@ -1253,12 +1039,6 @@ type AccountTokenSnapshotLog { """ totalCFAAmountStreamedOut: BigInt! - """ - The total (as of timestamp) amount of `token` streamed from this `account` until the `timestamp`/`block` for the GDA. - - """ - totalGDAAmountStreamedOut: BigInt! - """ The total (as of timestamp) net amount of `token` streamed through this `account` until the `timestamp`/`block`. @@ -1272,13 +1052,6 @@ type AccountTokenSnapshotLog { """ totalCFAAmountStreamed: BigInt! - """ - The total (as of timestamp) net amount of `token` streamed through this - `account` until the `timestamp`/`block` for the GDA. - - """ - totalGDAAmountStreamed: BigInt! - """ The total (as of timestamp) amount of `token` this `account` has transferred out until the `timestamp`/`block`. @@ -1424,22 +1197,6 @@ input AccountTokenSnapshotLog_filter { activeIncomingStreamCount_lte: Int activeIncomingStreamCount_in: [Int!] activeIncomingStreamCount_not_in: [Int!] - activeCFAIncomingStreamCount: Int - activeCFAIncomingStreamCount_not: Int - activeCFAIncomingStreamCount_gt: Int - activeCFAIncomingStreamCount_lt: Int - activeCFAIncomingStreamCount_gte: Int - activeCFAIncomingStreamCount_lte: Int - activeCFAIncomingStreamCount_in: [Int!] - activeCFAIncomingStreamCount_not_in: [Int!] - activeGDAIncomingStreamCount: Int - activeGDAIncomingStreamCount_not: Int - activeGDAIncomingStreamCount_gt: Int - activeGDAIncomingStreamCount_lt: Int - activeGDAIncomingStreamCount_gte: Int - activeGDAIncomingStreamCount_lte: Int - activeGDAIncomingStreamCount_in: [Int!] - activeGDAIncomingStreamCount_not_in: [Int!] totalNumberOfClosedStreams: Int totalNumberOfClosedStreams_not: Int totalNumberOfClosedStreams_gt: Int @@ -1496,22 +1253,6 @@ input AccountTokenSnapshotLog_filter { inactiveIncomingStreamCount_lte: Int inactiveIncomingStreamCount_in: [Int!] inactiveIncomingStreamCount_not_in: [Int!] - inactiveCFAIncomingStreamCount: Int - inactiveCFAIncomingStreamCount_not: Int - inactiveCFAIncomingStreamCount_gt: Int - inactiveCFAIncomingStreamCount_lt: Int - inactiveCFAIncomingStreamCount_gte: Int - inactiveCFAIncomingStreamCount_lte: Int - inactiveCFAIncomingStreamCount_in: [Int!] - inactiveCFAIncomingStreamCount_not_in: [Int!] - inactiveGDAIncomingStreamCount: Int - inactiveGDAIncomingStreamCount_not: Int - inactiveGDAIncomingStreamCount_gt: Int - inactiveGDAIncomingStreamCount_lt: Int - inactiveGDAIncomingStreamCount_gte: Int - inactiveGDAIncomingStreamCount_lte: Int - inactiveGDAIncomingStreamCount_in: [Int!] - inactiveGDAIncomingStreamCount_not_in: [Int!] totalSubscriptionsWithUnits: Int totalSubscriptionsWithUnits_not: Int totalSubscriptionsWithUnits_gt: Int @@ -1592,14 +1333,6 @@ input AccountTokenSnapshotLog_filter { totalCFANetFlowRate_lte: BigInt totalCFANetFlowRate_in: [BigInt!] totalCFANetFlowRate_not_in: [BigInt!] - totalGDANetFlowRate: BigInt - totalGDANetFlowRate_not: BigInt - totalGDANetFlowRate_gt: BigInt - totalGDANetFlowRate_lt: BigInt - totalGDANetFlowRate_gte: BigInt - totalGDANetFlowRate_lte: BigInt - totalGDANetFlowRate_in: [BigInt!] - totalGDANetFlowRate_not_in: [BigInt!] totalInflowRate: BigInt totalInflowRate_not: BigInt totalInflowRate_gt: BigInt @@ -1608,22 +1341,6 @@ input AccountTokenSnapshotLog_filter { totalInflowRate_lte: BigInt totalInflowRate_in: [BigInt!] totalInflowRate_not_in: [BigInt!] - totalCFAInflowRate: BigInt - totalCFAInflowRate_not: BigInt - totalCFAInflowRate_gt: BigInt - totalCFAInflowRate_lt: BigInt - totalCFAInflowRate_gte: BigInt - totalCFAInflowRate_lte: BigInt - totalCFAInflowRate_in: [BigInt!] - totalCFAInflowRate_not_in: [BigInt!] - totalGDAInflowRate: BigInt - totalGDAInflowRate_not: BigInt - totalGDAInflowRate_gt: BigInt - totalGDAInflowRate_lt: BigInt - totalGDAInflowRate_gte: BigInt - totalGDAInflowRate_lte: BigInt - totalGDAInflowRate_in: [BigInt!] - totalGDAInflowRate_not_in: [BigInt!] totalOutflowRate: BigInt totalOutflowRate_not: BigInt totalOutflowRate_gt: BigInt @@ -1656,22 +1373,6 @@ input AccountTokenSnapshotLog_filter { totalAmountStreamedIn_lte: BigInt totalAmountStreamedIn_in: [BigInt!] totalAmountStreamedIn_not_in: [BigInt!] - totalCFAAmountStreamedIn: BigInt - totalCFAAmountStreamedIn_not: BigInt - totalCFAAmountStreamedIn_gt: BigInt - totalCFAAmountStreamedIn_lt: BigInt - totalCFAAmountStreamedIn_gte: BigInt - totalCFAAmountStreamedIn_lte: BigInt - totalCFAAmountStreamedIn_in: [BigInt!] - totalCFAAmountStreamedIn_not_in: [BigInt!] - totalGDAAmountStreamedIn: BigInt - totalGDAAmountStreamedIn_not: BigInt - totalGDAAmountStreamedIn_gt: BigInt - totalGDAAmountStreamedIn_lt: BigInt - totalGDAAmountStreamedIn_gte: BigInt - totalGDAAmountStreamedIn_lte: BigInt - totalGDAAmountStreamedIn_in: [BigInt!] - totalGDAAmountStreamedIn_not_in: [BigInt!] totalAmountStreamedOut: BigInt totalAmountStreamedOut_not: BigInt totalAmountStreamedOut_gt: BigInt @@ -1688,14 +1389,6 @@ input AccountTokenSnapshotLog_filter { totalCFAAmountStreamedOut_lte: BigInt totalCFAAmountStreamedOut_in: [BigInt!] totalCFAAmountStreamedOut_not_in: [BigInt!] - totalGDAAmountStreamedOut: BigInt - totalGDAAmountStreamedOut_not: BigInt - totalGDAAmountStreamedOut_gt: BigInt - totalGDAAmountStreamedOut_lt: BigInt - totalGDAAmountStreamedOut_gte: BigInt - totalGDAAmountStreamedOut_lte: BigInt - totalGDAAmountStreamedOut_in: [BigInt!] - totalGDAAmountStreamedOut_not_in: [BigInt!] totalAmountStreamed: BigInt totalAmountStreamed_not: BigInt totalAmountStreamed_gt: BigInt @@ -1712,14 +1405,6 @@ input AccountTokenSnapshotLog_filter { totalCFAAmountStreamed_lte: BigInt totalCFAAmountStreamed_in: [BigInt!] totalCFAAmountStreamed_not_in: [BigInt!] - totalGDAAmountStreamed: BigInt - totalGDAAmountStreamed_not: BigInt - totalGDAAmountStreamed_gt: BigInt - totalGDAAmountStreamed_lt: BigInt - totalGDAAmountStreamed_gte: BigInt - totalGDAAmountStreamed_lte: BigInt - totalGDAAmountStreamed_in: [BigInt!] - totalGDAAmountStreamed_not_in: [BigInt!] totalAmountTransferred: BigInt totalAmountTransferred_not: BigInt totalAmountTransferred_gt: BigInt @@ -1814,8 +1499,6 @@ enum AccountTokenSnapshotLog_orderBy { activeCFAOutgoingStreamCount activeGDAOutgoingStreamCount activeIncomingStreamCount - activeCFAIncomingStreamCount - activeGDAIncomingStreamCount totalNumberOfClosedStreams totalCFANumberOfClosedStreams totalGDANumberOfClosedStreams @@ -1823,8 +1506,6 @@ enum AccountTokenSnapshotLog_orderBy { inactiveCFAOutgoingStreamCount inactiveGDAOutgoingStreamCount inactiveIncomingStreamCount - inactiveCFAIncomingStreamCount - inactiveGDAIncomingStreamCount totalSubscriptionsWithUnits totalApprovedSubscriptions totalMembershipsWithUnits @@ -1835,22 +1516,15 @@ enum AccountTokenSnapshotLog_orderBy { totalGDADeposit totalNetFlowRate totalCFANetFlowRate - totalGDANetFlowRate totalInflowRate - totalCFAInflowRate - totalGDAInflowRate totalOutflowRate totalCFAOutflowRate totalGDAOutflowRate totalAmountStreamedIn - totalCFAAmountStreamedIn - totalGDAAmountStreamedIn totalAmountStreamedOut totalCFAAmountStreamedOut - totalGDAAmountStreamedOut totalAmountStreamed totalCFAAmountStreamed - totalGDAAmountStreamed totalAmountTransferred account account__id @@ -1883,8 +1557,6 @@ enum AccountTokenSnapshotLog_orderBy { accountTokenSnapshot__activeCFAOutgoingStreamCount accountTokenSnapshot__activeGDAOutgoingStreamCount accountTokenSnapshot__activeIncomingStreamCount - accountTokenSnapshot__activeCFAIncomingStreamCount - accountTokenSnapshot__activeGDAIncomingStreamCount accountTokenSnapshot__totalNumberOfClosedStreams accountTokenSnapshot__totalCFANumberOfClosedStreams accountTokenSnapshot__totalGDANumberOfClosedStreams @@ -1892,8 +1564,6 @@ enum AccountTokenSnapshotLog_orderBy { accountTokenSnapshot__inactiveCFAOutgoingStreamCount accountTokenSnapshot__inactiveGDAOutgoingStreamCount accountTokenSnapshot__inactiveIncomingStreamCount - accountTokenSnapshot__inactiveCFAIncomingStreamCount - accountTokenSnapshot__inactiveGDAIncomingStreamCount accountTokenSnapshot__totalSubscriptionsWithUnits accountTokenSnapshot__totalApprovedSubscriptions accountTokenSnapshot__totalMembershipsWithUnits @@ -1904,25 +1574,23 @@ enum AccountTokenSnapshotLog_orderBy { accountTokenSnapshot__totalGDADeposit accountTokenSnapshot__totalNetFlowRate accountTokenSnapshot__totalCFANetFlowRate - accountTokenSnapshot__totalGDANetFlowRate accountTokenSnapshot__totalInflowRate - accountTokenSnapshot__totalCFAInflowRate - accountTokenSnapshot__totalGDAInflowRate accountTokenSnapshot__totalOutflowRate accountTokenSnapshot__totalCFAOutflowRate accountTokenSnapshot__totalGDAOutflowRate accountTokenSnapshot__totalAmountStreamedInUntilUpdatedAt - accountTokenSnapshot__totalCFAAmountStreamedInUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedInUntilUpdatedAt accountTokenSnapshot__totalAmountStreamedOutUntilUpdatedAt accountTokenSnapshot__totalCFAAmountStreamedOutUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedOutUntilUpdatedAt accountTokenSnapshot__totalAmountStreamedUntilUpdatedAt accountTokenSnapshot__totalCFAAmountStreamedUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedUntilUpdatedAt accountTokenSnapshot__totalAmountTransferredUntilUpdatedAt } +enum Aggregation_interval { + hour + day +} + type AgreementClassRegisteredEvent implements Event { id: ID! transactionHash: Bytes! @@ -1932,7 +1600,8 @@ type AgreementClassRegisteredEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `code` """ addresses: [Bytes!]! @@ -2087,7 +1756,8 @@ type AgreementClassUpdatedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `code` """ addresses: [Bytes!]! @@ -2800,7 +2470,8 @@ type AppRegisteredEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `app` """ addresses: [Bytes!]! @@ -2943,22 +2614,44 @@ type ApprovalEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `isNFTApproval` ? `nft address` : `token` (superToken) + addresses[1] = `owner` + addresses[2] = `to` """ addresses: [Bytes!]! blockNumber: BigInt! logIndex: BigInt! order: BigInt! + + """ + The address that will be granting allowance to transfer ERC20/NFT. + + """ owner: Account! """ - The address that will be granted allowance to transfer the NFT. + The address that will be granted allowance to transfer ERC20/NFT. """ to: Account! """ + Indicates whether the event was emitted for the approval of an NFT. + + """ + isNFTApproval: Boolean! + + """ + If `amount` is non-zero, this event was emitted for the approval of an ERC20. + Tne amount of ERC20 tokens that will be granted allowance to transfer. + + """ + amount: BigInt! + + """ + If `tokenId` is non-zero, this event was emitted for the approval of an NFT. The id of the NFT that will be granted allowance to transfer. The id is: uint256(keccak256(abi.encode(block.chainid, superToken, sender, receiver))) @@ -3101,6 +2794,18 @@ input ApprovalEvent_filter { to_not_ends_with: String to_not_ends_with_nocase: String to_: Account_filter + isNFTApproval: Boolean + isNFTApproval_not: Boolean + isNFTApproval_in: [Boolean!] + isNFTApproval_not_in: [Boolean!] + amount: BigInt + amount_not: BigInt + amount_gt: BigInt + amount_lt: BigInt + amount_gte: BigInt + amount_lte: BigInt + amount_in: [BigInt!] + amount_not_in: [BigInt!] tokenId: BigInt tokenId_not: BigInt tokenId_gt: BigInt @@ -3141,6 +2846,8 @@ enum ApprovalEvent_orderBy { to__updatedAtTimestamp to__updatedAtBlockNumber to__isSuperApp + isNFTApproval + amount tokenId } @@ -3153,7 +2860,10 @@ type ApprovalForAllEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = NFT address + addresses[1] = `owner` + addresses[2] = `operator` """ addresses: [Bytes!]! @@ -3758,6 +3468,9 @@ enum BufferAdjustedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -3997,7 +3710,10 @@ type CFAv1LiquidationPeriodChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! @@ -4185,7 +3901,10 @@ type ConfigChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! @@ -4734,6 +4453,9 @@ enum DistributionClaimedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -4751,6 +4473,8 @@ enum DistributionClaimedEvent_orderBy { poolMember__totalAmountClaimed poolMember__poolTotalAmountDistributedUntilUpdatedAt poolMember__totalAmountReceivedUntilUpdatedAt + poolMember__syncedPerUnitSettledValue + poolMember__syncedPerUnitFlowRate } """ @@ -5386,6 +5110,9 @@ enum FlowDistributionUpdatedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -5655,8 +5382,6 @@ enum FlowOperator_orderBy { accountTokenSnapshot__activeCFAOutgoingStreamCount accountTokenSnapshot__activeGDAOutgoingStreamCount accountTokenSnapshot__activeIncomingStreamCount - accountTokenSnapshot__activeCFAIncomingStreamCount - accountTokenSnapshot__activeGDAIncomingStreamCount accountTokenSnapshot__totalNumberOfClosedStreams accountTokenSnapshot__totalCFANumberOfClosedStreams accountTokenSnapshot__totalGDANumberOfClosedStreams @@ -5664,8 +5389,6 @@ enum FlowOperator_orderBy { accountTokenSnapshot__inactiveCFAOutgoingStreamCount accountTokenSnapshot__inactiveGDAOutgoingStreamCount accountTokenSnapshot__inactiveIncomingStreamCount - accountTokenSnapshot__inactiveCFAIncomingStreamCount - accountTokenSnapshot__inactiveGDAIncomingStreamCount accountTokenSnapshot__totalSubscriptionsWithUnits accountTokenSnapshot__totalApprovedSubscriptions accountTokenSnapshot__totalMembershipsWithUnits @@ -5676,22 +5399,15 @@ enum FlowOperator_orderBy { accountTokenSnapshot__totalGDADeposit accountTokenSnapshot__totalNetFlowRate accountTokenSnapshot__totalCFANetFlowRate - accountTokenSnapshot__totalGDANetFlowRate accountTokenSnapshot__totalInflowRate - accountTokenSnapshot__totalCFAInflowRate - accountTokenSnapshot__totalGDAInflowRate accountTokenSnapshot__totalOutflowRate accountTokenSnapshot__totalCFAOutflowRate accountTokenSnapshot__totalGDAOutflowRate accountTokenSnapshot__totalAmountStreamedInUntilUpdatedAt - accountTokenSnapshot__totalCFAAmountStreamedInUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedInUntilUpdatedAt accountTokenSnapshot__totalAmountStreamedOutUntilUpdatedAt accountTokenSnapshot__totalCFAAmountStreamedOutUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedOutUntilUpdatedAt accountTokenSnapshot__totalAmountStreamedUntilUpdatedAt accountTokenSnapshot__totalCFAAmountStreamedUntilUpdatedAt - accountTokenSnapshot__totalGDAAmountStreamedUntilUpdatedAt accountTokenSnapshot__totalAmountTransferredUntilUpdatedAt flowOperatorUpdatedEvents } @@ -6301,7 +6017,9 @@ type GovernanceReplacedEvent implements Event { order: BigInt! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `oldGovernance` + addresses[1] = `newGovernance` """ addresses: [Bytes!]! @@ -8695,6 +8413,9 @@ enum InstantDistributionUpdatedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -8729,7 +8450,8 @@ type JailEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `app` """ addresses: [Bytes!]! @@ -9103,6 +8825,9 @@ enum MemberUnitsUpdatedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -9120,6 +8845,8 @@ enum MemberUnitsUpdatedEvent_orderBy { poolMember__totalAmountClaimed poolMember__poolTotalAmountDistributedUntilUpdatedAt poolMember__totalAmountReceivedUntilUpdatedAt + poolMember__syncedPerUnitSettledValue + poolMember__syncedPerUnitFlowRate } type MetadataUpdateEvent implements Event { @@ -9692,6 +9419,9 @@ type Pool { totalAmountInstantlyDistributedUntilUpdatedAt: BigInt! totalAmountFlowedDistributedUntilUpdatedAt: BigInt! totalAmountDistributedUntilUpdatedAt: BigInt! + totalFlowAdjustmentAmountDistributedUntilUpdatedAt: BigInt! + perUnitSettledValue: BigInt! + perUnitFlowRate: BigInt! """ A member is any account which has more than 0 units in the pool. @@ -9815,6 +9545,30 @@ input Pool_filter { totalAmountDistributedUntilUpdatedAt_lte: BigInt totalAmountDistributedUntilUpdatedAt_in: [BigInt!] totalAmountDistributedUntilUpdatedAt_not_in: [BigInt!] + totalFlowAdjustmentAmountDistributedUntilUpdatedAt: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_not: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_gt: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_lt: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_gte: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_lte: BigInt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_in: [BigInt!] + totalFlowAdjustmentAmountDistributedUntilUpdatedAt_not_in: [BigInt!] + perUnitSettledValue: BigInt + perUnitSettledValue_not: BigInt + perUnitSettledValue_gt: BigInt + perUnitSettledValue_lt: BigInt + perUnitSettledValue_gte: BigInt + perUnitSettledValue_lte: BigInt + perUnitSettledValue_in: [BigInt!] + perUnitSettledValue_not_in: [BigInt!] + perUnitFlowRate: BigInt + perUnitFlowRate_not: BigInt + perUnitFlowRate_gt: BigInt + perUnitFlowRate_lt: BigInt + perUnitFlowRate_gte: BigInt + perUnitFlowRate_lte: BigInt + perUnitFlowRate_in: [BigInt!] + perUnitFlowRate_not_in: [BigInt!] totalMembers: Int totalMembers_not: Int totalMembers_gt: Int @@ -9933,6 +9687,9 @@ enum Pool_orderBy { totalAmountInstantlyDistributedUntilUpdatedAt totalAmountFlowedDistributedUntilUpdatedAt totalAmountDistributedUntilUpdatedAt + totalFlowAdjustmentAmountDistributedUntilUpdatedAt + perUnitSettledValue + perUnitFlowRate totalMembers totalConnectedMembers totalDisconnectedMembers @@ -10198,6 +9955,9 @@ enum PoolConnectionUpdatedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -10215,6 +9975,8 @@ enum PoolConnectionUpdatedEvent_orderBy { poolMember__totalAmountClaimed poolMember__poolTotalAmountDistributedUntilUpdatedAt poolMember__totalAmountReceivedUntilUpdatedAt + poolMember__syncedPerUnitSettledValue + poolMember__syncedPerUnitFlowRate } type PoolCreatedEvent implements Event { @@ -10420,6 +10182,9 @@ enum PoolCreatedEvent_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -10613,6 +10378,9 @@ enum PoolDistributor_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -10639,6 +10407,8 @@ type PoolMember { totalAmountClaimed: BigInt! poolTotalAmountDistributedUntilUpdatedAt: BigInt! totalAmountReceivedUntilUpdatedAt: BigInt! + syncedPerUnitSettledValue: BigInt! + syncedPerUnitFlowRate: BigInt! account: Account! pool: Pool! poolConnectionUpdatedEvents(skip: Int = 0, first: Int = 100, orderBy: PoolConnectionUpdatedEvent_orderBy, orderDirection: OrderDirection, where: PoolConnectionUpdatedEvent_filter): [PoolConnectionUpdatedEvent!]! @@ -10723,6 +10493,22 @@ input PoolMember_filter { totalAmountReceivedUntilUpdatedAt_lte: BigInt totalAmountReceivedUntilUpdatedAt_in: [BigInt!] totalAmountReceivedUntilUpdatedAt_not_in: [BigInt!] + syncedPerUnitSettledValue: BigInt + syncedPerUnitSettledValue_not: BigInt + syncedPerUnitSettledValue_gt: BigInt + syncedPerUnitSettledValue_lt: BigInt + syncedPerUnitSettledValue_gte: BigInt + syncedPerUnitSettledValue_lte: BigInt + syncedPerUnitSettledValue_in: [BigInt!] + syncedPerUnitSettledValue_not_in: [BigInt!] + syncedPerUnitFlowRate: BigInt + syncedPerUnitFlowRate_not: BigInt + syncedPerUnitFlowRate_gt: BigInt + syncedPerUnitFlowRate_lt: BigInt + syncedPerUnitFlowRate_gte: BigInt + syncedPerUnitFlowRate_lte: BigInt + syncedPerUnitFlowRate_in: [BigInt!] + syncedPerUnitFlowRate_not_in: [BigInt!] account: String account_not: String account_gt: String @@ -10786,6 +10572,8 @@ enum PoolMember_orderBy { totalAmountClaimed poolTotalAmountDistributedUntilUpdatedAt totalAmountReceivedUntilUpdatedAt + syncedPerUnitSettledValue + syncedPerUnitFlowRate account account__id account__createdAtTimestamp @@ -10805,6 +10593,9 @@ enum PoolMember_orderBy { pool__totalAmountInstantlyDistributedUntilUpdatedAt pool__totalAmountFlowedDistributedUntilUpdatedAt pool__totalAmountDistributedUntilUpdatedAt + pool__totalFlowAdjustmentAmountDistributedUntilUpdatedAt + pool__perUnitSettledValue + pool__perUnitFlowRate pool__totalMembers pool__totalConnectedMembers pool__totalDisconnectedMembers @@ -10831,7 +10622,10 @@ type PPPConfigurationChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! @@ -14010,7 +13804,11 @@ type RewardAddressChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` + addresses[3] = `rewardAddress` """ addresses: [Bytes!]! @@ -14194,7 +13992,9 @@ type RoleAdminChangedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `previousAdminRole` + addresses[1] = `newAdminRole` """ addresses: [Bytes!]! @@ -14361,7 +14161,9 @@ type RoleGrantedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `account` + addresses[1] = `sender` """ addresses: [Bytes!]! @@ -14528,7 +14330,9 @@ type RoleRevokedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `account` + addresses[1] = `sender` """ addresses: [Bytes!]! @@ -15115,6 +14919,12 @@ type SFMeta { """ branch: String! + + """ + The subgraph package.json semver version of the current deployment. + + """ + packageVersion: String! } input SFMeta_filter { @@ -15182,6 +14992,26 @@ input SFMeta_filter { branch_ends_with_nocase: String branch_not_ends_with: String branch_not_ends_with_nocase: String + packageVersion: String + packageVersion_not: String + packageVersion_gt: String + packageVersion_lt: String + packageVersion_gte: String + packageVersion_lte: String + packageVersion_in: [String!] + packageVersion_not_in: [String!] + packageVersion_contains: String + packageVersion_contains_nocase: String + packageVersion_not_contains: String + packageVersion_not_contains_nocase: String + packageVersion_starts_with: String + packageVersion_starts_with_nocase: String + packageVersion_not_starts_with: String + packageVersion_not_starts_with_nocase: String + packageVersion_ends_with: String + packageVersion_ends_with_nocase: String + packageVersion_not_ends_with: String + packageVersion_not_ends_with_nocase: String """Filter for the block changed event.""" _change_block: BlockChangedFilter @@ -15195,6 +15025,7 @@ enum SFMeta_orderBy { blockNumber configuration branch + packageVersion } """ @@ -19847,7 +19678,8 @@ type SuperTokenFactoryUpdatedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `newFactory` """ addresses: [Bytes!]! @@ -19990,7 +19822,8 @@ type SuperTokenLogicCreatedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `tokenLogic` """ addresses: [Bytes!]! @@ -20133,7 +19966,9 @@ type SuperTokenLogicUpdatedEvent implements Event { name: String! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `token` + addresses[1] = `code` """ addresses: [Bytes!]! @@ -20294,7 +20129,10 @@ type SuperTokenMinimumDepositChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` """ addresses: [Bytes!]! @@ -21210,12 +21048,6 @@ type TokenStatistic { """ 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`. @@ -21450,14 +21282,6 @@ input TokenStatistic_filter { totalCFAAmountStreamedUntilUpdatedAt_lte: BigInt totalCFAAmountStreamedUntilUpdatedAt_in: [BigInt!] totalCFAAmountStreamedUntilUpdatedAt_not_in: [BigInt!] - totalGDAAmountStreamedUntilUpdatedAt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_not: BigInt - totalGDAAmountStreamedUntilUpdatedAt_gt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_lt: BigInt - totalGDAAmountStreamedUntilUpdatedAt_gte: BigInt - totalGDAAmountStreamedUntilUpdatedAt_lte: BigInt - totalGDAAmountStreamedUntilUpdatedAt_in: [BigInt!] - totalGDAAmountStreamedUntilUpdatedAt_not_in: [BigInt!] totalAmountTransferredUntilUpdatedAt: BigInt totalAmountTransferredUntilUpdatedAt_not: BigInt totalAmountTransferredUntilUpdatedAt_gt: BigInt @@ -21553,7 +21377,6 @@ enum TokenStatistic_orderBy { totalGDAOutflowRate totalAmountStreamedUntilUpdatedAt totalCFAAmountStreamedUntilUpdatedAt - totalGDAAmountStreamedUntilUpdatedAt totalAmountTransferredUntilUpdatedAt totalAmountDistributedUntilUpdatedAt totalSupply @@ -21718,12 +21541,6 @@ type TokenStatisticLog { """ totalCFAAmountStreamed: BigInt! - """ - The all-time total amount of `token` streamed (outflows) until the `timestamp`/`block` for the GDA. - - """ - totalGDAAmountStreamed: BigInt! - """ The all-time total amount of `token` transferred until the `timestamp`/`block`. @@ -22004,14 +21821,6 @@ input TokenStatisticLog_filter { totalCFAAmountStreamed_lte: BigInt totalCFAAmountStreamed_in: [BigInt!] totalCFAAmountStreamed_not_in: [BigInt!] - totalGDAAmountStreamed: BigInt - totalGDAAmountStreamed_not: BigInt - totalGDAAmountStreamed_gt: BigInt - totalGDAAmountStreamed_lt: BigInt - totalGDAAmountStreamed_gte: BigInt - totalGDAAmountStreamed_lte: BigInt - totalGDAAmountStreamed_in: [BigInt!] - totalGDAAmountStreamed_not_in: [BigInt!] totalAmountTransferred: BigInt totalAmountTransferred_not: BigInt totalAmountTransferred_gt: BigInt @@ -22131,7 +21940,6 @@ enum TokenStatisticLog_orderBy { totalGDAOutflowRate totalAmountStreamed totalCFAAmountStreamed - totalGDAAmountStreamed totalAmountTransferred totalAmountDistributed totalSupply @@ -22174,7 +21982,6 @@ enum TokenStatisticLog_orderBy { tokenStatistic__totalGDAOutflowRate tokenStatistic__totalAmountStreamedUntilUpdatedAt tokenStatistic__totalCFAAmountStreamedUntilUpdatedAt - tokenStatistic__totalGDAAmountStreamedUntilUpdatedAt tokenStatistic__totalAmountTransferredUntilUpdatedAt tokenStatistic__totalAmountDistributedUntilUpdatedAt tokenStatistic__totalSupply @@ -22611,7 +22418,11 @@ type TrustedForwarderChangedEvent implements Event { governanceAddress: Bytes! """ - Empty addresses array. + Contains the addresses that were impacted by this event: + addresses[0] = `governanceAddress` + addresses[1] = `host` + addresses[2] = `superToken` + addresses[3] = `forwarder` """ addresses: [Bytes!]! From 8131d699c9855097a6c6a9ed7066b5014bf0f15d Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 26 Mar 2024 09:59:14 +0200 Subject: [PATCH 11/15] update entities based on new subgraph --- .../src/subgraph/entities/pool/pool.ts | 10 ++- .../src/subgraph/entities/pool/pools.graphql | 85 ++++++++++--------- .../entities/poolMember/poolMember.ts | 4 + .../entities/poolMember/poolMembers.graphql | 66 +++++++------- 4 files changed, 89 insertions(+), 76 deletions(-) diff --git a/packages/sdk-core/src/subgraph/entities/pool/pool.ts b/packages/sdk-core/src/subgraph/entities/pool/pool.ts index 6ad1fc7746..7516d14c07 100644 --- a/packages/sdk-core/src/subgraph/entities/pool/pool.ts +++ b/packages/sdk-core/src/subgraph/entities/pool/pool.ts @@ -29,22 +29,22 @@ export interface Pool { totalAmountInstantlyDistributedUntilUpdatedAt: BigNumber; totalAmountFlowedDistributedUntilUpdatedAt: BigNumber; totalAmountDistributedUntilUpdatedAt: BigNumber; + totalFlowAdjustmentAmountDistributedUntilUpdatedAt: BigNumber; totalUnits: BigNumber; totalConnectedUnits: BigNumber; totalDisconnectedUnits: BigNumber; + perUnitSettledValue: BigNumber; + perUnitFlowRate: BigNumber; /** * A member is any account which has more than 0 units in the pool. - * */ totalMembers: number; /** * A connected member is any account which has more than 0 units in the pool and is connected. - * */ totalConnectedMembers: number; /** * A disconnected member is any account which has more than 0 units in the pool and is not connected. - * */ totalDisconnectedMembers: number; adjustmentFlowRate: BigNumber; @@ -110,6 +110,10 @@ export class PoolQueryHandler extends SubgraphQueryHandler< x.totalAmountFlowedDistributedUntilUpdatedAt, totalAmountDistributedUntilUpdatedAt: x.totalAmountDistributedUntilUpdatedAt, + totalFlowAdjustmentAmountDistributedUntilUpdatedAt: + x.totalFlowAdjustmentAmountDistributedUntilUpdatedAt, + perUnitFlowRate: x.perUnitFlowRate, + perUnitSettledValue: x.perUnitSettledValue, admin: x.admin.id, token: x.token.id, })); diff --git a/packages/sdk-core/src/subgraph/entities/pool/pools.graphql b/packages/sdk-core/src/subgraph/entities/pool/pools.graphql index f40661b6d4..1492b3e102 100644 --- a/packages/sdk-core/src/subgraph/entities/pool/pools.graphql +++ b/packages/sdk-core/src/subgraph/entities/pool/pools.graphql @@ -1,51 +1,54 @@ query getPool($id: ID!) { - pool(id: $id) { - ...PoolPart - } + pool(id: $id) { + ...PoolPart + } } query pools( - $first: Int = 10 - $orderBy: Pool_orderBy = id - $orderDirection: OrderDirection = asc - $skip: Int = 0 - $where: Pool_filter = {} - $block: Block_height + $first: Int = 10 + $orderBy: Pool_orderBy = id + $orderDirection: OrderDirection = asc + $skip: Int = 0 + $where: Pool_filter = {} + $block: Block_height ) { - pools( - first: $first - orderBy: $orderBy - orderDirection: $orderDirection - skip: $skip - where: $where - block: $block - ) { - ...PoolPart - } + pools( + first: $first + orderBy: $orderBy + orderDirection: $orderDirection + skip: $skip + where: $where + block: $block + ) { + ...PoolPart + } } fragment PoolPart on Pool { - id - createdAtTimestamp - createdAtBlockNumber - updatedAtTimestamp - updatedAtBlockNumber - flowRate - totalMembers - totalUnits - totalAmountDistributedUntilUpdatedAt - adjustmentFlowRate - totalAmountFlowedDistributedUntilUpdatedAt - totalAmountInstantlyDistributedUntilUpdatedAt - totalBuffer - totalConnectedMembers - totalConnectedUnits - totalDisconnectedMembers - totalDisconnectedUnits - admin { id - } - token { - id - } + createdAtTimestamp + createdAtBlockNumber + updatedAtTimestamp + updatedAtBlockNumber + admin { + id + } + token { + id + } + totalMembers + totalUnits + totalConnectedMembers + totalConnectedUnits + totalDisconnectedMembers + totalDisconnectedUnits + totalAmountInstantlyDistributedUntilUpdatedAt + flowRate + perUnitSettledValue + perUnitFlowRate + totalBuffer + totalAmountFlowedDistributedUntilUpdatedAt + totalAmountDistributedUntilUpdatedAt + adjustmentFlowRate + totalFlowAdjustmentAmountDistributedUntilUpdatedAt } diff --git a/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts b/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts index 3b679e58e7..553235723a 100644 --- a/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts +++ b/packages/sdk-core/src/subgraph/entities/poolMember/poolMember.ts @@ -32,6 +32,8 @@ export interface PoolMember { totalAmountReceivedUntilUpdatedAt: BigNumber; poolTotalAmountDistributedUntilUpdatedAt: BigNumber; pool: Address; + syncedPerUnitFlowRate: BigNumber; + syncedPerUnitSettledValue: BigNumber; } export type PoolMembersListQuery = SubgraphListQuery< @@ -70,6 +72,8 @@ export class PoolMemberQueryHandler extends SubgraphQueryHandler< updatedAtBlockNumber: Number(x.updatedAtBlockNumber), pool: x.pool.id, token: x.pool.token.id, + syncedPerUnitFlowRate: x.syncedPerUnitFlowRate, + syncedPerUnitSettledValue: x.syncedPerUnitSettledValue, })); requestDocument = PoolMembersDocument; diff --git a/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql b/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql index 035d12f85c..90e9cd5bec 100644 --- a/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql +++ b/packages/sdk-core/src/subgraph/entities/poolMember/poolMembers.graphql @@ -1,37 +1,39 @@ query poolMembers( - $first: Int = 10 - $skip: Int = 0 - $orderBy: PoolMember_orderBy = id - $orderDirection: OrderDirection = asc - $where: PoolMember_filter = {} - $block: Block_height + $first: Int = 10 + $skip: Int = 0 + $orderBy: PoolMember_orderBy = id + $orderDirection: OrderDirection = asc + $where: PoolMember_filter = {} + $block: Block_height ) { - poolMembers( - first: $first - orderBy: $orderBy - orderDirection: $orderDirection - skip: $skip - where: $where - block: $block - ) { - id - createdAtTimestamp - createdAtBlockNumber - updatedAtTimestamp - updatedAtBlockNumber - units - pool { - id - token { + poolMembers( + first: $first + orderBy: $orderBy + orderDirection: $orderDirection + skip: $skip + where: $where + block: $block + ) { id - } + createdAtTimestamp + createdAtBlockNumber + updatedAtTimestamp + updatedAtBlockNumber + units + pool { + id + token { + id + } + } + account { + id + } + isConnected + totalAmountClaimed + totalAmountReceivedUntilUpdatedAt + poolTotalAmountDistributedUntilUpdatedAt + syncedPerUnitFlowRate + syncedPerUnitSettledValue } - account { - id - } - isConnected - totalAmountClaimed - totalAmountReceivedUntilUpdatedAt - poolTotalAmountDistributedUntilUpdatedAt - } } From c43fe51a56549bea75f5397ef45e1e16890f56ad Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 26 Mar 2024 12:44:56 +0200 Subject: [PATCH 12/15] map name, isnfttransfer, isnftapproval --- packages/sdk-core/CHANGELOG.md | 2 + packages/sdk-core/src/events.ts | 2 + .../src/mapGetAllEventsQueryEvents.ts | 5 +-- .../src/subgraph/events/events.graphql | 44 +++++++++++++++++++ .../src/subgraph/queries/getAllEvents.graphql | 3 ++ 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/packages/sdk-core/CHANGELOG.md b/packages/sdk-core/CHANGELOG.md index 1206cfa0d7..cd4043c816 100644 --- a/packages/sdk-core/CHANGELOG.md +++ b/packages/sdk-core/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] ### Added + - Added `getTotalAmountReceivedByMember` ### Changed @@ -15,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Don't lock metadata version to a specific version, use semver (^). - Allow infinite pagination with 'skip: 0' value (previously had to be undefined) - Add subgraphs queries for Pools, PoolMembers and PoolDistributors +- Map `isNFTApproval` and `isNFTTransfer` onto events ## [0.6.12] - 2023-10-23 diff --git a/packages/sdk-core/src/events.ts b/packages/sdk-core/src/events.ts index 5328dd6a6f..ad2cd8aa0d 100644 --- a/packages/sdk-core/src/events.ts +++ b/packages/sdk-core/src/events.ts @@ -183,6 +183,7 @@ export interface TransferEvent extends EventBase { to: string; value: string; token: string; + isNFTTransfer: boolean; } export interface AgreementClassRegisteredEvent extends EventBase { @@ -468,6 +469,7 @@ export interface MemberUnitsUpdatedEvent extends EventBase { } export interface ApprovalEvent extends EventBase { name: "ApprovalEvent"; + isNFTApproval: boolean; } export interface ApprovalForAllEvent extends EventBase { name: "ApprovalForAllEvent"; diff --git a/packages/sdk-core/src/mapGetAllEventsQueryEvents.ts b/packages/sdk-core/src/mapGetAllEventsQueryEvents.ts index 131595cdbe..9d144e19af 100644 --- a/packages/sdk-core/src/mapGetAllEventsQueryEvents.ts +++ b/packages/sdk-core/src/mapGetAllEventsQueryEvents.ts @@ -598,6 +598,7 @@ export const mapGetAllEventsQueryEvents = ( to: x.to.id, token: x.token, value: x.value, + isNFTTransfer: x.isNFTTransfer, }); case "TrustedForwarderChangedEvent": return typeGuard({ @@ -760,6 +761,7 @@ export const mapGetAllEventsQueryEvents = ( order: Number(x.order), timestamp: Number(x.timestamp), logIndex: Number(x.logIndex), + isNFTApproval: x.isNFTApproval, }); case "ApprovalForAllEvent": return typeGuard({ @@ -786,9 +788,6 @@ export const mapGetAllEventsQueryEvents = ( default: // eslint-disable-next-line no-case-declarations const eventBase = x as events.EventBase; - console.warn( - `An unknown event [${eventBase.name}] was detected which couldn't be properly mapped. Please update to the latest version of @superfluid-finance/sdk-core.` - ); return typeGuard({ // force casted as empty string for the type system name: eventBase.name as "", diff --git a/packages/sdk-core/src/subgraph/events/events.graphql b/packages/sdk-core/src/subgraph/events/events.graphql index 59ee519b39..e72b88c012 100644 --- a/packages/sdk-core/src/subgraph/events/events.graphql +++ b/packages/sdk-core/src/subgraph/events/events.graphql @@ -14,6 +14,7 @@ query flowUpdatedEvents( where: $where block: $block ) { + name ...flowUpdatedEvent } } @@ -34,6 +35,7 @@ query flowOperatorUpdatedEvents( where: $where block: $block ) { + name ...flowOperatorUpdatedEvent } } @@ -54,6 +56,7 @@ query indexCreatedEvents( where: $where block: $block ) { + name ...indexCreatedEvent } } @@ -74,6 +77,7 @@ query indexDistributionClaimedEvents( where: $where block: $block ) { + name ...indexDistributionClaimedEvent } } @@ -94,6 +98,7 @@ query indexUpdatedEvents( where: $where block: $block ) { + name ...indexUpdatedEvent } } @@ -114,6 +119,7 @@ query indexSubscribedEvents( where: $where block: $block ) { + name ...indexSubscribedEvent } } @@ -134,6 +140,7 @@ query indexUnitsUpdatedEvents( where: $where block: $block ) { + name ...indexUnitsUpdatedEvent } } @@ -154,6 +161,7 @@ query indexUnsubscribedEvents( where: $where block: $block ) { + name ...indexUnsubscribedEvent } } @@ -174,6 +182,7 @@ query subscriptionApprovedEvents( where: $where block: $block ) { + name ...subscriptionApprovedEvent } } @@ -194,6 +203,7 @@ query subscriptionDistributionClaimedEvents( where: $where block: $block ) { + name ...subscriptionDistributionClaimedEvent } } @@ -214,6 +224,7 @@ query subscriptionRevokedEvents( where: $where block: $block ) { + name ...subscriptionRevokedEvent } } @@ -234,6 +245,7 @@ query subscriptionUnitsUpdatedEvents( where: $where block: $block ) { + name ...subscriptionUnitsUpdatedEvent } } @@ -254,6 +266,7 @@ query transferEvents( where: $where block: $block ) { + name ...transferEvent } } @@ -274,6 +287,7 @@ query tokenUpgradedEvents( where: $where block: $block ) { + name ...tokenUpgradedEvent } } @@ -294,6 +308,7 @@ query tokenDowngradedEvents( where: $where block: $block ) { + name ...tokenDowngradedEvent } } @@ -314,6 +329,7 @@ query agreementClassRegisteredEvents( where: $where block: $block ) { + name ...agreementClassRegisteredEvent } } @@ -334,6 +350,7 @@ query agreementClassUpdatedEvents( where: $where block: $block ) { + name ...agreementClassUpdatedEvent } } @@ -354,6 +371,7 @@ query appRegisteredEvents( where: $where block: $block ) { + name ...appRegisteredEvent } } @@ -374,6 +392,7 @@ query governanceReplacedEvents( where: $where block: $block ) { + name ...governanceReplacedEvent } } @@ -394,6 +413,7 @@ query jailEvents( where: $where block: $block ) { + name ...jailEvent } } @@ -414,6 +434,7 @@ query superTokenFactoryUpdatedEvents( where: $where block: $block ) { + name ...superTokenFactoryUpdatedEvent } } @@ -434,6 +455,7 @@ query superTokenLogicUpdatedEvents( where: $where block: $block ) { + name ...superTokenLogicUpdatedEvent } } @@ -454,6 +476,7 @@ query roleAdminChangedEvents( where: $where block: $block ) { + name ...roleAdminChangedEvent } } @@ -474,6 +497,7 @@ query roleGrantedEvents( where: $where block: $block ) { + name ...roleGrantedEvent } } @@ -494,6 +518,7 @@ query roleRevokedEvents( where: $where block: $block ) { + name ...roleRevokedEvent } } @@ -514,6 +539,7 @@ query setEvents( where: $where block: $block ) { + name ...setEvent } } @@ -534,6 +560,7 @@ query cfaV1LiquidationPeriodChangedEvents( where: $where block: $block ) { + name ...cfaV1LiquidationPeriodChangedEvent } } @@ -554,6 +581,7 @@ query configChangedEvents( where: $where block: $block ) { + name ...configChangedEvent } } @@ -574,6 +602,7 @@ query rewardAddressChangedEvents( where: $where block: $block ) { + name ...rewardAddressChangedEvent } } @@ -594,6 +623,7 @@ query superTokenMinimumDepositChangedEvents( where: $where block: $block ) { + name ...superTokenMinimumDepositChangedEvent } } @@ -614,6 +644,7 @@ query trustedForwarderChangedEvents( where: $where block: $block ) { + name ...trustedForwarderChangedEvent } } @@ -634,6 +665,7 @@ query agreementLiquidatedByEvents( where: $where block: $block ) { + name ...agreementLiquidatedByEvent } } @@ -654,6 +686,7 @@ query burnedEvents( where: $where block: $block ) { + name ...burnedEvent } } @@ -674,6 +707,7 @@ query mintedEvents( where: $where block: $block ) { + name ...mintedEvent } } @@ -694,6 +728,7 @@ query sentEvents( where: $where block: $block ) { + name ...sentEvent } } @@ -714,6 +749,7 @@ query customSuperTokenCreatedEvents( where: $where block: $block ) { + name ...customSuperTokenCreatedEvent } } @@ -734,6 +770,7 @@ query superTokenCreatedEvents( where: $where block: $block ) { + name ...superTokenCreatedEvent } } @@ -754,6 +791,7 @@ query superTokenLogicCreatedEvents( where: $where block: $block ) { + name ...superTokenLogicCreatedEvent } } @@ -774,6 +812,7 @@ query newPICEvents( where: $where block: $block ) { + name ...newPICEvent } } @@ -794,6 +833,7 @@ query exitRateChangedEvents( where: $where block: $block ) { + name ...newExitRateChangedEvent } } @@ -814,6 +854,7 @@ query bondIncreasedEvents( where: $where block: $block ) { + name ...newBondIncreasedEvent } } @@ -838,6 +879,7 @@ query events( blockNumber transactionHash timestamp + name ... on FlowUpdatedEvent { ...flowUpdatedEvent } @@ -1165,6 +1207,7 @@ fragment transferEvent on TransferEvent { ...eventFields value token + isNFTTransfer to { id } @@ -1436,6 +1479,7 @@ fragment memberUnitsUpdatedEvent on MemberUnitsUpdatedEvent { } fragment approvalEvent on ApprovalEvent { ...eventFields + isNFTApproval } fragment approvalForAllEvent on ApprovalForAllEvent { ...eventFields diff --git a/packages/sdk-core/src/subgraph/queries/getAllEvents.graphql b/packages/sdk-core/src/subgraph/queries/getAllEvents.graphql index 0a792a833d..3846b67f48 100644 --- a/packages/sdk-core/src/subgraph/queries/getAllEvents.graphql +++ b/packages/sdk-core/src/subgraph/queries/getAllEvents.graphql @@ -12,6 +12,7 @@ query getAllEvents( orderBy: $orderBy orderDirection: $orderDirection ) { + name ... on FlowUpdatedEvent { # we repeat `...eventFields` in each event so it throws an error in the mapper when an expected event isn't included here ...eventFields @@ -161,6 +162,7 @@ query getAllEvents( from { id } + isNFTTransfer } ... on TokenUpgradedEvent { ...eventFields @@ -396,6 +398,7 @@ query getAllEvents( ...eventFields } ... on ApprovalEvent { + isNFTApproval ...eventFields } ... on ApprovalForAllEvent { From 080497ef5cc7d9b42452043fce3d236f1122e51c Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 26 Mar 2024 15:49:31 +0200 Subject: [PATCH 13/15] fix merge issue --- packages/subgraph/src/mappings/superfluidPool.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/subgraph/src/mappings/superfluidPool.ts b/packages/subgraph/src/mappings/superfluidPool.ts index d4fcf1798e..f4740745c2 100644 --- a/packages/subgraph/src/mappings/superfluidPool.ts +++ b/packages/subgraph/src/mappings/superfluidPool.ts @@ -30,10 +30,10 @@ export function handleDistributionClaimed(event: DistributionClaimed): void { // settle pool and pool member pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); settlePDPoolMemberMU(pool, poolMember, event.block); - + // Update PoolMember poolMember.totalAmountClaimed = event.params.totalClaimed; - + pool.save(); poolMember.save(); @@ -61,11 +61,6 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { pool = updatePoolTotalAmountFlowedAndDistributed(event, pool); settlePDPoolMemberMU(pool, poolMember, event.block); -<<<<<<< HEAD - // @note TODO update the pool.perUnitFlowRate - // @note TODO update the poolMember.perUnitFlowRate -======= ->>>>>>> origin/dev const existingPoolFlowRate = pool.perUnitFlowRate.times(pool.totalUnits); let newPerUnitFlowRate: BigInt; let remainderRate: BigInt; @@ -90,7 +85,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { } // 0 units to > 0 units - const didPoolMemberBecomeActive = previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO) + const didPoolMemberBecomeActive = previousUnits.equals(BIG_INT_ZERO) && event.params.newUnits.gt(BIG_INT_ZERO); if (didPoolMemberBecomeActive) { pool.totalMembers = pool.totalMembers + 1; // if the member is connected with units now, we add one to connected @@ -116,7 +111,7 @@ export function handleMemberUnitsUpdated(event: MemberUnitsUpdated): void { } // > 0 units to 0 units - const didPoolMemberBecomeInactive = previousUnits.gt(BIG_INT_ZERO) && poolMember.units.equals(BIG_INT_ZERO) + const didPoolMemberBecomeInactive = previousUnits.gt(BIG_INT_ZERO) && poolMember.units.equals(BIG_INT_ZERO); if (didPoolMemberBecomeInactive) { pool.totalMembers = pool.totalMembers - 1; // if the member is connected with no units now, we subtract one from connected From 061e8fa3a06851bcbb1bbdaa2f6bf44a1422b765 Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 26 Mar 2024 15:54:45 +0200 Subject: [PATCH 14/15] remove unnecessary files --- packages/subgraph/config/hardhat.json | 1 - packages/subgraph/config/polygon-mainnet.json | 1 - 2 files changed, 2 deletions(-) delete mode 100644 packages/subgraph/config/hardhat.json delete mode 100644 packages/subgraph/config/polygon-mainnet.json diff --git a/packages/subgraph/config/hardhat.json b/packages/subgraph/config/hardhat.json deleted file mode 100644 index d9f3424abb..0000000000 --- a/packages/subgraph/config/hardhat.json +++ /dev/null @@ -1 +0,0 @@ -{"network":"mainnet","testNetwork":"hardhat","hostStartBlock":0,"hostAddress":"0x4374EEcaAD0Dcaa149CfFc160d5a0552B1D092b0","cfaAddress":"0x44BF2a9217A2970A1bCC7529Bf1d40828C594320","idaAddress":"0x0826223156fF61F9abf620D2f58A06177DA664Cc","gdaAddress":"0x1Ad83f2789e013a41eA18819F0e24a4d41477b4c","superTokenFactoryAddress":"0x9b9389FacF9d345676b178EfEe328334cA711A38","resolverV1Address":"0x0e528E13E32cfB153818F1e10c7aff11ec5B46A3","nativeAssetSuperTokenAddress":"0x68bFD28e2AB62C450C563E1687f5f4F6b008149f","constantOutflowNFTAddress":"0x765FEFc8D7b2A6ec1D83626c50781e8cdd7e8284","constantInflowNFTAddress":"0x0983210c9f6f968ACC2010ac4dc56124dcDe2EC2"} \ No newline at end of file diff --git a/packages/subgraph/config/polygon-mainnet.json b/packages/subgraph/config/polygon-mainnet.json deleted file mode 100644 index 8637fdd0b2..0000000000 --- a/packages/subgraph/config/polygon-mainnet.json +++ /dev/null @@ -1 +0,0 @@ -{"network":"matic","hostStartBlock":11650500,"hostAddress":"0x3E14dC1b13c488a8d5D310918780c983bD5982E7","cfaAddress":"0x6EeE6060f715257b970700bc2656De21dEdF074C","idaAddress":"0xB0aABBA4B2783A72C52956CDEF62d438ecA2d7a1","gdaAddress":"0x961dd5A052741B49B6CBf6759591f9D8576fCFb0","superTokenFactoryAddress":"0x2C90719f25B10Fc5646c82DA3240C76Fa5BcCF34","resolverV1Address":"0x8bDCb5613153f41B2856F71Bd7A7e0432F6dbe58","nativeAssetSuperTokenAddress":"0x3aD736904E9e65189c3000c7DD2c8AC8bB7cD4e3","constantOutflowNFTAddress":"0x554e2bbaCF43FD87417b7201A9F1649a3ED89d68","constantInflowNFTAddress":"0x55909bB8cd8276887Aae35118d60b19755201c68"} \ No newline at end of file From 30a7e1a8c03f4863830a485cbb7a89585bf2cfcc Mon Sep 17 00:00:00 2001 From: Kaspar Kallas Date: Tue, 26 Mar 2024 15:58:28 +0200 Subject: [PATCH 15/15] update gitignore --- packages/subgraph/.gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/subgraph/.gitignore b/packages/subgraph/.gitignore index ece682f377..1cd9202169 100644 --- a/packages/subgraph/.gitignore +++ b/packages/subgraph/.gitignore @@ -9,4 +9,6 @@ src/addresses.ts **/*.wasm **/*.latest.json tests/.bin -hosted-service-networks.json \ No newline at end of file +hosted-service-networks.json +config/*.json +!config/mock.json \ No newline at end of file