Skip to content

Commit

Permalink
fixed vault total supply twabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ncookiez committed Apr 22, 2024
1 parent bc543f3 commit 5841379
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/hyperstructure-client-js/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@generationsoftware/hyperstructure-client-js",
"description": "Lightweight library for interacting with PoolTogether contracts",
"version": "1.12.0",
"version": "1.12.1",
"license": "MIT",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion packages/hyperstructure-client-js/src/PrizePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,15 @@ export class PrizePool {
const source = 'Prize Pool [getVaultTotalSupplyTwab]'
await validateClientNetwork(this.chainId, this.publicClient, source)

const lastDrawId = (await this.getLastAwardedDrawId()) || 1
const startDrawId = numDraws > lastDrawId ? 1 : lastDrawId - Math.floor(numDraws) + 1

const totalSupplyTwabs = await getPrizePoolTotalSupplyTwabs(
this.publicClient,
this.address,
vaultAddresses,
numDraws
startDrawId,
lastDrawId
)

return totalSupplyTwabs
Expand Down
2 changes: 1 addition & 1 deletion packages/hyperstructure-react-hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@generationsoftware/hyperstructure-react-hooks",
"description": "React hooks library for interacting with PoolTogether contracts",
"version": "1.16.1",
"version": "1.16.2",
"license": "MIT",
"main": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions shared/utilities/utils/prizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,25 @@ export const getPrizePoolContributionPercentages = async (
* @param publicClient a public Viem client for the prize pool's chain
* @param prizePoolAddress the prize pool's address
* @param vaultAddresses the addresses for any vaults to get total supply TWAB for
* @param numDraws the number of draws to look back on
* @param startDrawId the draw to start at (inclusive)
* @param endDrawId the draw to end at (inclusive)
* @returns
*/
export const getPrizePoolTotalSupplyTwabs = async (
publicClient: PublicClient,
prizePoolAddress: Address,
vaultAddresses: Address[],
numDraws: number
startDrawId: number,
endDrawId: number
): Promise<{ [vaultId: string]: bigint }> => {
const totalSupplyTwabs: { [vaultId: string]: bigint } = {}

const chainId = await publicClient.getChainId()

if (vaultAddresses.length > 0 && numDraws >= 0) {
if (vaultAddresses.length > 0 && startDrawId <= endDrawId) {
const calls = vaultAddresses.map((vaultAddress) => ({
functionName: 'getVaultUserBalanceAndTotalSupplyTwab',
args: [vaultAddress, zeroAddress, Math.floor(numDraws)]
args: [vaultAddress, zeroAddress, startDrawId, endDrawId]
}))

const multicallResults = await getSimpleMulticallResults(
Expand Down

0 comments on commit 5841379

Please sign in to comment.