From 22860e1d948cb11e1d6f77d5fcd0114e97d278a5 Mon Sep 17 00:00:00 2001 From: solimander Date: Mon, 22 Jan 2024 13:46:22 -0700 Subject: [PATCH] Add reclaim functions to subgraph client --- packages/prop-house-sdk-react/package.json | 4 +- packages/prop-house-sdk/package.json | 2 +- packages/prop-house-sdk/src/gql/evm/gql.ts | 8 + .../prop-house-sdk/src/gql/evm/graphql.ts | 139 ++++++++++++++++++ packages/prop-house-sdk/src/gql/index.ts | 1 + .../prop-house-sdk/src/gql/queries.evm.ts | 34 +++++ .../prop-house-sdk/src/gql/query-wrapper.ts | 44 ++++++ packages/prop-house-sdk/src/gql/types.ts | 9 ++ yarn.lock | 31 ++++ 9 files changed, 269 insertions(+), 3 deletions(-) diff --git a/packages/prop-house-sdk-react/package.json b/packages/prop-house-sdk-react/package.json index b621b5f76..c5770740d 100644 --- a/packages/prop-house-sdk-react/package.json +++ b/packages/prop-house-sdk-react/package.json @@ -1,6 +1,6 @@ { "name": "@prophouse/sdk-react", - "version": "1.0.19", + "version": "1.0.21", "description": "Useful tools for interacting with the Prop House protocol from React applications", "author": "solimander", "homepage": "https://prop.house", @@ -18,7 +18,7 @@ "wagmi": ">=0.9.2" }, "dependencies": { - "@prophouse/sdk": "1.0.24" + "@prophouse/sdk": "1.0.26" }, "devDependencies": { "react": "^17.0.2", diff --git a/packages/prop-house-sdk/package.json b/packages/prop-house-sdk/package.json index 6cc6b53b2..71e871b6f 100644 --- a/packages/prop-house-sdk/package.json +++ b/packages/prop-house-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@prophouse/sdk", - "version": "1.0.25", + "version": "1.0.27", "description": "Useful tools for interacting with the Prop House protocol", "author": "solimander", "homepage": "https://prop.house", diff --git a/packages/prop-house-sdk/src/gql/evm/gql.ts b/packages/prop-house-sdk/src/gql/evm/gql.ts index cf41f978e..328f6c896 100644 --- a/packages/prop-house-sdk/src/gql/evm/gql.ts +++ b/packages/prop-house-sdk/src/gql/evm/gql.ts @@ -41,6 +41,8 @@ const documents = { types.ManyDepositsDocument, '\n query manyClaims(\n $first: Int!\n $skip: Int!\n $orderBy: Claim_orderBy\n $orderDirection: OrderDirection\n $where: Claim_filter\n ) {\n claims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n claimedAt\n recipient\n proposalId\n round {\n id\n }\n asset {\n assetType\n token\n identifier\n }\n amount\n }\n }\n': types.ManyClaimsDocument, + '\n query manyReclaims(\n $first: Int!\n $skip: Int!\n $orderBy: Reclaim_orderBy\n $orderDirection: OrderDirection\n $where: Reclaim_filter\n ) {\n reclaims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n reclaimer {\n id\n }\n reclaimedAt\n asset {\n assetType\n token\n identifier\n }\n amount\n round {\n id\n }\n }\n }\n': + types.ManyReclaimsDocument, }; /** @@ -141,6 +143,12 @@ export function graphql( export function graphql( source: '\n query manyClaims(\n $first: Int!\n $skip: Int!\n $orderBy: Claim_orderBy\n $orderDirection: OrderDirection\n $where: Claim_filter\n ) {\n claims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n claimedAt\n recipient\n proposalId\n round {\n id\n }\n asset {\n assetType\n token\n identifier\n }\n amount\n }\n }\n', ): (typeof documents)['\n query manyClaims(\n $first: Int!\n $skip: Int!\n $orderBy: Claim_orderBy\n $orderDirection: OrderDirection\n $where: Claim_filter\n ) {\n claims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n claimedAt\n recipient\n proposalId\n round {\n id\n }\n asset {\n assetType\n token\n identifier\n }\n amount\n }\n }\n']; +/** + * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. + */ +export function graphql( + source: '\n query manyReclaims(\n $first: Int!\n $skip: Int!\n $orderBy: Reclaim_orderBy\n $orderDirection: OrderDirection\n $where: Reclaim_filter\n ) {\n reclaims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n reclaimer {\n id\n }\n reclaimedAt\n asset {\n assetType\n token\n identifier\n }\n amount\n round {\n id\n }\n }\n }\n', +): (typeof documents)['\n query manyReclaims(\n $first: Int!\n $skip: Int!\n $orderBy: Reclaim_orderBy\n $orderDirection: OrderDirection\n $where: Reclaim_filter\n ) {\n reclaims(\n first: $first\n skip: $skip\n orderBy: $orderBy\n orderDirection: $orderDirection\n where: $where\n ) {\n id\n txHash\n reclaimer {\n id\n }\n reclaimedAt\n asset {\n assetType\n token\n identifier\n }\n amount\n round {\n id\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; diff --git a/packages/prop-house-sdk/src/gql/evm/graphql.ts b/packages/prop-house-sdk/src/gql/evm/graphql.ts index ba70ae346..1ae3fb450 100644 --- a/packages/prop-house-sdk/src/gql/evm/graphql.ts +++ b/packages/prop-house-sdk/src/gql/evm/graphql.ts @@ -852,6 +852,7 @@ export type GovPowerStrategyVotingStrategyRoundsArgs = { export enum GovPowerStrategyType { Allowlist = 'ALLOWLIST', BalanceOf = 'BALANCE_OF', + BalanceOfErc20 = 'BALANCE_OF_ERC20', BalanceOfErc1155 = 'BALANCE_OF_ERC1155', CheckpointableErc721 = 'CHECKPOINTABLE_ERC721', Unknown = 'UNKNOWN', @@ -3739,6 +3740,28 @@ export type ManyClaimsQuery = { }>; }; +export type ManyReclaimsQueryVariables = Exact<{ + first: Scalars['Int']; + skip: Scalars['Int']; + orderBy?: InputMaybe; + orderDirection?: InputMaybe; + where?: InputMaybe; +}>; + +export type ManyReclaimsQuery = { + __typename?: 'Query'; + reclaims: Array<{ + __typename?: 'Reclaim'; + id: string; + txHash: any; + reclaimedAt: any; + amount: any; + reclaimer: { __typename?: 'Account'; id: string }; + asset: { __typename?: 'Asset'; assetType: AssetType; token: any; identifier: any }; + round: { __typename?: 'Round'; id: string }; + }>; +}; + export const HouseFieldsFragmentDoc = { kind: 'Document', definitions: [ @@ -5572,3 +5595,119 @@ export const ManyClaimsDocument = { }, ], } as unknown as DocumentNode; +export const ManyReclaimsDocument = { + kind: 'Document', + definitions: [ + { + kind: 'OperationDefinition', + operation: 'query', + name: { kind: 'Name', value: 'manyReclaims' }, + variableDefinitions: [ + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, + }, + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'skip' } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, + }, + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'orderBy' } }, + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Reclaim_orderBy' } }, + }, + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'orderDirection' } }, + type: { kind: 'NamedType', name: { kind: 'Name', value: 'OrderDirection' } }, + }, + { + kind: 'VariableDefinition', + variable: { kind: 'Variable', name: { kind: 'Name', value: 'where' } }, + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Reclaim_filter' } }, + }, + ], + selectionSet: { + kind: 'SelectionSet', + selections: [ + { + kind: 'Field', + name: { kind: 'Name', value: 'reclaims' }, + arguments: [ + { + kind: 'Argument', + name: { kind: 'Name', value: 'first' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, + }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'skip' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'skip' } }, + }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'orderBy' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'orderBy' } }, + }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'orderDirection' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'orderDirection' } }, + }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'where' }, + value: { kind: 'Variable', name: { kind: 'Name', value: 'where' } }, + }, + ], + selectionSet: { + kind: 'SelectionSet', + selections: [ + { kind: 'Field', name: { kind: 'Name', value: 'id' } }, + { kind: 'Field', name: { kind: 'Name', value: 'txHash' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'reclaimer' }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'id' } }], + }, + }, + { kind: 'Field', name: { kind: 'Name', value: 'reclaimedAt' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'asset' }, + selectionSet: { + kind: 'SelectionSet', + selections: [ + { kind: 'Field', name: { kind: 'Name', value: 'assetType' } }, + { kind: 'Field', name: { kind: 'Name', value: 'token' } }, + { kind: 'Field', name: { kind: 'Name', value: 'identifier' } }, + ], + }, + }, + { kind: 'Field', name: { kind: 'Name', value: 'amount' } }, + { + kind: 'Field', + name: { kind: 'Name', value: 'round' }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'id' } }], + }, + }, + ], + }, + }, + ], + }, + }, + ], +} as unknown as DocumentNode; diff --git a/packages/prop-house-sdk/src/gql/index.ts b/packages/prop-house-sdk/src/gql/index.ts index fb5823421..85e4e5ae5 100644 --- a/packages/prop-house-sdk/src/gql/index.ts +++ b/packages/prop-house-sdk/src/gql/index.ts @@ -50,4 +50,5 @@ export { Vote, Deposit, Claim, + Reclaim, } from './types'; diff --git a/packages/prop-house-sdk/src/gql/queries.evm.ts b/packages/prop-house-sdk/src/gql/queries.evm.ts index 5251449a4..dcf239384 100644 --- a/packages/prop-house-sdk/src/gql/queries.evm.ts +++ b/packages/prop-house-sdk/src/gql/queries.evm.ts @@ -287,3 +287,37 @@ export const ManyClaimsQuery = graphql(` } } `); + +export const ManyReclaimsQuery = graphql(` + query manyReclaims( + $first: Int! + $skip: Int! + $orderBy: Reclaim_orderBy + $orderDirection: OrderDirection + $where: Reclaim_filter + ) { + reclaims( + first: $first + skip: $skip + orderBy: $orderBy + orderDirection: $orderDirection + where: $where + ) { + id + txHash + reclaimer { + id + } + reclaimedAt + asset { + assetType + token + identifier + } + amount + round { + id + } + } + } +`); diff --git a/packages/prop-house-sdk/src/gql/query-wrapper.ts b/packages/prop-house-sdk/src/gql/query-wrapper.ts index 153c2bbac..c4f1410f9 100644 --- a/packages/prop-house-sdk/src/gql/query-wrapper.ts +++ b/packages/prop-house-sdk/src/gql/query-wrapper.ts @@ -16,6 +16,8 @@ import { Deposit_Filter, Claim_Filter, RoundEventState, + Reclaim_OrderBy, + Reclaim_Filter, } from './evm/graphql'; import { HouseQuery, @@ -28,6 +30,7 @@ import { ManyGovPowerStrategiesQuery, RoundQuery, RoundWithHouseInfoQuery, + ManyReclaimsQuery, } from './queries.evm'; import { getDefaultConfig, @@ -56,6 +59,7 @@ import { RoundBalance, Claim, Deposit, + Reclaim, } from './types'; import { GlobalStatsQuery, @@ -622,6 +626,46 @@ export class QueryWrapper { }); } + /** + * Get paginated reclaims in the provided round address + * @param roundAddress The round address + * @param config Filtering, pagination, and ordering configuration + */ + public async getRoundReclaims( + roundAddress: Address, + config: Partial> = {}, + ) { + return this.getReclaims({ + ...config, + where: { + ...config.where, + round: roundAddress.toLowerCase(), + }, + }); + } + + /** + * Get paginated reclaims + * @param config Filtering, pagination, and ordering configuration + */ + public async getReclaims(config: Partial> = {}): Promise { + const { reclaims } = await this._gql.evm.request( + ManyReclaimsQuery, + toPaginated(this.merge(getDefaultConfig(Reclaim_OrderBy.ReclaimedAt), config)), + ); + return reclaims.map(reclaim => ({ + id: reclaim.id, + txHash: reclaim.txHash, + reclaimedAt: reclaim.reclaimedAt, + reclaimer: reclaim.reclaimer.id, + round: reclaim.round.id, + asset: this.toAsset({ + asset: reclaim.asset, + amount: reclaim.amount, + }), + })); + } + /** * Get paginated proposals * @param config Filtering, pagination, and ordering configuration diff --git a/packages/prop-house-sdk/src/gql/types.ts b/packages/prop-house-sdk/src/gql/types.ts index 2177c8f9a..998a77e72 100644 --- a/packages/prop-house-sdk/src/gql/types.ts +++ b/packages/prop-house-sdk/src/gql/types.ts @@ -178,3 +178,12 @@ export interface Claim { round: string; asset: Asset; } + +export interface Reclaim { + id: string; + txHash: string; + reclaimedAt: string; + reclaimer: string; + round: string; + asset: Asset; +} diff --git a/yarn.lock b/yarn.lock index 243801ded..8978bde16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6023,6 +6023,37 @@ starknet "5.19.5" time-ts "^0.1.0" +"@prophouse/sdk@1.0.26": + version "1.0.26" + resolved "https://registry.npmjs.org/@prophouse/sdk/-/sdk-1.0.26.tgz#4b4c305e0c35e1374f1307c67cef28309913370d" + integrity sha512-L6kkFD2i5f3aWqqleItDEdto5WyikI92IRBjZgfGXQbqjRvaeFlKMrgrBV5p0pT+I+lPCQ4QhkdGIaYlev69fQ== + dependencies: + "@ethersproject/abi" "~5.7.0" + "@ethersproject/abstract-provider" "~5.7.0" + "@ethersproject/abstract-signer" "~5.7.0" + "@ethersproject/address" "~5.7.0" + "@ethersproject/bignumber" "~5.7.0" + "@ethersproject/bytes" "~5.7.0" + "@ethersproject/constants" "~5.7.0" + "@ethersproject/contracts" "~5.7.0" + "@ethersproject/keccak256" "~5.7.0" + "@ethersproject/providers" "~5.7.0" + "@ethersproject/solidity" "~5.7.0" + "@ethersproject/strings" "~5.7.0" + "@ethersproject/wallet" "^5.7.0" + "@pinata/sdk" "^2.1.0" + "@prophouse/protocol" "1.0.8" + bn.js "^5.2.1" + ethereumjs-fork-block "^4.2.4" + ethereumjs-fork-common "^3.1.3" + graphql "^16.5.0" + graphql-request "5.0.0" + merkletreejs "^0.3.11" + micro-starknet "^0.2.3" + randombytes "^2.1.0" + starknet "5.19.5" + time-ts "^0.1.0" + "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf"