-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sdk-core][sdk-redux] add GDA pool subgraph entity queries (#1840)
* add gda pool subgraph entity queries * improve infinity paging api * add some robustness to transaction serialization * reduce tx tracking timeout from 10 mins to 3 mins * remove unnecessary toLowerCase * changeset * [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 <[email protected]> * [SUBGRAPH] approval mapping (#1878) * approval mapping * missing addresses * missing addresses cont. * no-op, trigger build * fix tests --------- Co-authored-by: Kaspar Kallas <[email protected]> * [subgraph] Fix Correctness of GDA Entities (#1890) --------- Co-authored-by: 0xdavinchee <[email protected]> * add getTotalAmountReceivedByPoolMember to sdk-core (#1902) * update entities based on new subgraph * map name, isnfttransfer, isnftapproval * fix merge issue * remove unnecessary files * update gitignore --------- Co-authored-by: 0xdavinchee <[email protected]>
- Loading branch information
1 parent
24a549c
commit d58178f
Showing
26 changed files
with
810 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
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<Pool_Filter, Pool_OrderBy>; | ||
|
||
export interface Pool { | ||
id: Address; | ||
createdAtTimestamp: Timestamp; | ||
createdAtBlockNumber: BlockNumber; | ||
updatedAtTimestamp: Timestamp; | ||
updatedAtBlockNumber: BlockNumber; | ||
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; | ||
flowRate: BigNumber; | ||
totalBuffer: BigNumber; | ||
token: Address; | ||
admin: Address; | ||
} | ||
|
||
export type SubgraphPool = NonNullable<Required<GetPoolQuery>["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, | ||
totalFlowAdjustmentAmountDistributedUntilUpdatedAt: | ||
x.totalFlowAdjustmentAmountDistributedUntilUpdatedAt, | ||
perUnitFlowRate: x.perUnitFlowRate, | ||
perUnitSettledValue: x.perUnitSettledValue, | ||
admin: x.admin.id, | ||
token: x.token.id, | ||
})); | ||
|
||
requestDocument = PoolsDocument; | ||
} |
54 changes: 54 additions & 0 deletions
54
packages/sdk-core/src/subgraph/entities/pool/pools.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 | ||
admin { | ||
id | ||
} | ||
token { | ||
id | ||
} | ||
totalMembers | ||
totalUnits | ||
totalConnectedMembers | ||
totalConnectedUnits | ||
totalDisconnectedMembers | ||
totalDisconnectedUnits | ||
totalAmountInstantlyDistributedUntilUpdatedAt | ||
flowRate | ||
perUnitSettledValue | ||
perUnitFlowRate | ||
totalBuffer | ||
totalAmountFlowedDistributedUntilUpdatedAt | ||
totalAmountDistributedUntilUpdatedAt | ||
adjustmentFlowRate | ||
totalFlowAdjustmentAmountDistributedUntilUpdatedAt | ||
} |
81 changes: 81 additions & 0 deletions
81
packages/sdk-core/src/subgraph/entities/poolDistributor/poolDistributor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Oops, something went wrong.