-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8c7712
commit 1406d68
Showing
8 changed files
with
153 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
const CHAIN_ID = { | ||
goerli: 5, | ||
mumbai: 80001 | ||
mumbai: 80001, | ||
}; | ||
|
||
export const TWAB_CONTROLLER_SUBGRAPH_URIS = { | ||
[CHAIN_ID.goerli]: `https://api.thegraph.com/subgraphs/name/pooltogether/v5-eth-goerli-twab-controller`, | ||
[CHAIN_ID.mumbai]: `https://api.thegraph.com/subgraphs/name/pooltogether/v5-polygon-mumbai-twab-control` | ||
[CHAIN_ID.mumbai]: `https://api.thegraph.com/subgraphs/name/pooltogether/v5-polygon-mumbai-twab-control`, | ||
}; | ||
|
||
export const PRIZE_POOL_SUBGRAPH_URIS = { | ||
[CHAIN_ID.goerli]: `https://api.thegraph.com/subgraphs/name/pooltogether/v5-eth-goerli-prize-pool`, | ||
[CHAIN_ID.mumbai]: `https://api.thegraph.com/subgraphs/name/pooltogether/v5-polygon-mumbai-prize-pool`, | ||
}; |
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,80 @@ | ||
import { Provider } from "@ethersproject/providers"; | ||
import { ContractCallContext } from "ethereum-multicall"; | ||
|
||
import { MulticallResults, Claim, ContractsBlob, Vault } from "../types"; | ||
import { getComplexMulticallResults } from "./multicall"; | ||
|
||
/** | ||
* Returns claims | ||
* @param readProvider a read-capable provider for the chain that should be queried | ||
* @param contracts blob of contracts to pull PrizePool abi/etc from | ||
* @param vaults vaults to query through | ||
* @param tiersArray an easily iterable range of numbers for each tier available (ie. [0, 1, 2]) | ||
* @returns | ||
*/ | ||
export const filterClaimedPrizes = async ( | ||
readProvider: Provider, | ||
contracts: ContractsBlob, | ||
vaults: Vault[], | ||
tiersArray: number[] | ||
): Promise<Claim[]> => { | ||
const prizePoolContractBlob = contracts.contracts.find( | ||
(contract) => contract.type === "PrizePool" | ||
); | ||
if (!prizePoolContractBlob) { | ||
throw new Error("Contracts: No prize pool found in provided contracts blob"); | ||
} | ||
|
||
const calls: ContractCallContext["calls"] = []; | ||
|
||
vaults.forEach((vault) => { | ||
vault.accounts.forEach((account) => { | ||
const address = account.id.split("-")[1]; | ||
|
||
tiersArray.forEach((tierNum) => { | ||
calls.push({ | ||
reference: `${vault.id}-${address}-${tierNum}`, | ||
methodName: "isWinner", | ||
methodParameters: [vault.id, address, tierNum], | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
const prizePoolAddress: string | undefined = prizePoolContractBlob?.address; | ||
|
||
const queries: ContractCallContext[] = [ | ||
{ | ||
reference: prizePoolAddress, | ||
contractAddress: prizePoolAddress, | ||
abi: prizePoolContractBlob.abi, | ||
calls, | ||
}, | ||
]; | ||
|
||
const multicallResults: MulticallResults = await getComplexMulticallResults( | ||
readProvider, | ||
queries | ||
); | ||
|
||
// Builds the array of claims | ||
return getClaims(prizePoolAddress, multicallResults); | ||
}; | ||
|
||
const getClaims = (prizePoolAddress: string, multicallResults: MulticallResults): Claim[] => { | ||
const claims: Claim[] = []; | ||
|
||
Object.entries(multicallResults[prizePoolAddress]).forEach((vaultUserTierResult) => { | ||
const key = vaultUserTierResult[0]; | ||
const value = vaultUserTierResult[1]; | ||
const isWinner = value[0]; | ||
|
||
const [vault, winner, tier] = key.split("-"); | ||
|
||
if (isWinner) { | ||
claims.push({ vault, tier: Number(tier), winner }); | ||
} | ||
}); | ||
|
||
return claims; | ||
}; |
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,56 @@ | ||
import { gql, GraphQLClient } from "graphql-request"; | ||
|
||
import { PRIZE_POOL_SUBGRAPH_URIS } from "./constants"; | ||
import { ClaimedPrize } from "../types"; | ||
|
||
/** | ||
* Subgraphs to query for depositors | ||
*/ | ||
export const getPrizePoolSubgraphUri = (chainId: number) => { | ||
return PRIZE_POOL_SUBGRAPH_URIS[chainId]; | ||
}; | ||
|
||
export const getPrizePoolSubgraphClient = (chainId: number) => { | ||
const uri = getPrizePoolSubgraphUri(chainId); | ||
|
||
return new GraphQLClient(uri); | ||
}; | ||
|
||
/** | ||
* Pulls from the subgraph all of the claimed prizes for a specific draw | ||
* | ||
* @returns {Promise} Promise of an array of ClaimedPrize objects | ||
*/ | ||
export const getSubgraphClaimedPrizes = async ( | ||
chainId: number, | ||
drawId: string | ||
): Promise<ClaimedPrize[]> => { | ||
const client = getPrizePoolSubgraphClient(chainId); | ||
|
||
const query = drawQuery(); | ||
const variables = { id: drawId }; | ||
|
||
// @ts-ignore: ignore types from GraphQL client lib | ||
const claimedPrizesResponse: any = await client.request(query, variables).catch((e) => { | ||
console.error(e.message); | ||
throw e; | ||
}); | ||
|
||
return claimedPrizesResponse?.draw?.prizeClaims || []; | ||
}; | ||
|
||
const drawQuery = () => { | ||
return gql` | ||
query drawQuery($id: String!) { | ||
draw(id: $id) { | ||
id | ||
prizeClaims { | ||
id | ||
payout | ||
fee | ||
timestamp | ||
} | ||
} | ||
} | ||
`; | ||
}; |
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