-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add four new stat variables, stake simulator #1699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+932
−237
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
441ec60
feat: add three new variables, style svgs sizes, separate stats, crea…
kemuru b82ea0d
feat: refactor stat names, values, add homeblock query, add chart ico…
kemuru 3171cb2
feat: add accordion, style divider
kemuru c8b793f
feat: open accordion on default
kemuru e90eeed
Merge branch 'dev' into feat/add-stats-court-page
kemuru 2af88c1
fix: fix some types
kemuru aff2336
fix: slight styling detail and use title as key instead of index
kemuru 46edcb8
chore: update subgraph package json
kemuru 9925c37
fix: adjust homepageblockquery hook, stats adjustments, add pnk for 1…
kemuru 2bc6665
Merge branch 'dev' into feat/add-stats-court-page
kemuru 9e53b00
chore: reorder stats
kemuru b722d5e
Merge branch 'dev' into feat/add-stats-court-page
kemuru bb4f76a
feat: first iteration of stake simulator, abstract jurorbalance, comm…
kemuru 9e492d6
Merge branch 'dev' into feat/add-stats-court-page
kemuru a97b1f3
Merge branch 'dev' into feat/add-stats-court-page
kemuru 9e3fbff
feat: style simulator popup according to figma, adjust position in mo…
kemuru 8a97cfb
feat: new icons for stats, improve wording, reorder imports, style ad…
kemuru 40e8011
Merge branch 'dev' into feat/add-stats-court-page
kemuru 638c5ba
feat: add tooltips to the 4 stat variables, typing, wording adjustment
kemuru 5245f2d
fix: few comments by coderabbitai
kemuru 5ebfe32
feat: styling issues in stats section
kemuru 1e41b0b
Merge branch 'dev' into feat/add-stats-court-page
kemuru 39df777
Merge branch 'dev' into feat/add-stats-court-page
kemuru e219edc
Merge branch 'dev' into feat/add-stats-court-page
kemuru 7e5779c
Merge branch 'dev' into feat/add-stats-court-page
kemuru 418f8aa
feat: add new stake simulator design, add new juror effectivestake me…
kemuru f0931b1
chore: update subgraph package json version
kemuru 1f9b155
chore: update package json version
kemuru 86162f0
chore: remove payback metric
kemuru 44b00b3
fix: more correct calculations
kemuru 0f16c7a
fix: handle undefined values
kemuru fd3aa44
fix: simulator didnt work if wallet is not connected
kemuru 0cba9be
Merge branch 'dev' into feat/add-stats-court-page
kemuru f23a29d
fix: abstract divider, few style issues
kemuru 024bdba
chore: abstract beautifystatnumber
kemuru 723cf91
fix: beautify tweak
kemuru dafcad2
fix: memoize some values to prevent recalculations
kemuru 16e8547
fix: new wallets cant see simulator
kemuru b9321c2
Merge branch 'dev' into feat/add-stats-court-page
kemuru f5010b2
Merge branch 'dev' into feat/add-stats-court-page
kemuru 4ceb55a
chore: new dice icon
kemuru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,120 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { useGraphqlBatcher } from "context/GraphqlBatcher"; | ||
import { useMemo } from "react"; | ||
|
||
import { graphql } from "src/graphql"; | ||
import { CourtAllTimeQuery } from "src/graphql/graphql"; | ||
export type { CourtAllTimeQuery }; | ||
|
||
const courtAllTimeQuery = graphql(` | ||
query CourtAllTime { | ||
presentCourts: courts(orderBy: id, orderDirection: asc) { | ||
id | ||
parent { | ||
id | ||
} | ||
name | ||
numberDisputes | ||
numberVotes | ||
feeForJuror | ||
stake | ||
} | ||
} | ||
`); | ||
|
||
export const useCourtAllTimeQuery = () => { | ||
const { graphqlBatcher } = useGraphqlBatcher(); | ||
|
||
const usedQuery = useQuery({ | ||
queryKey: [`courtAllTimeQuery`], | ||
staleTime: Infinity, | ||
queryFn: async () => { | ||
const data = await graphqlBatcher.fetch({ | ||
id: crypto.randomUUID(), | ||
document: courtAllTimeQuery, | ||
}); | ||
return data; | ||
}, | ||
}); | ||
|
||
const courtActivityStats = useMemo(() => { | ||
if (usedQuery.data && !usedQuery.isFetching) { | ||
// 1. court with most disputes | ||
// we only iterate through past courts, since more courts might exist at the present | ||
// these diffCourts have: average stakes, and dispute diff | ||
const diffCourts = usedQuery.data.presentCourts.map((c) => ({ | ||
...c, | ||
numberDisputes: c.numberDisputes, | ||
treeNumberDisputes: c.numberDisputes, | ||
numberVotes: c.numberVotes, | ||
treeNumberVotes: c.numberVotes, | ||
stake: c.stake, | ||
})); | ||
|
||
const mostDisputedCourt = diffCourts.sort((a, b) => b.numberDisputes - a.numberDisputes)[0]; | ||
// 2. biggest chances of getting drawn | ||
// fact a: getting drawn in a parent court also subjects you to its rewards | ||
// fact b: staking in children, stakes in parents. but subgraph at this date doesn't reflect this | ||
// so, stakes trickle up, rewards/disputes trickle down | ||
|
||
for (const parent of diffCourts) { | ||
for (const child of diffCourts) { | ||
if (parent.id === child.parent?.id) { | ||
child.treeNumberVotes = String(Number(parent.treeNumberVotes) + Number(child.treeNumberVotes)); | ||
child.treeNumberDisputes = String(Number(parent.treeNumberDisputes) + Number(child.treeNumberDisputes)); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
diffCourts.reverse(); | ||
for (const child of diffCourts) { | ||
for (const parent of diffCourts) { | ||
if (parent.id === child.parent?.id) { | ||
parent.stake = String(BigInt(parent.stake) + BigInt(child.stake)); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
diffCourts.reverse(); | ||
for (const c of diffCourts) { | ||
c.votesPerPnk = Number(c.numberVotes) / (Number(c.stake) / 1e18); | ||
c.treeVotesPerPnk = c.votesPerPnk; | ||
c.disputesPerPnk = Number(c.numberDisputes) / (Number(c.stake) / 1e18); | ||
c.treeDisputesPerPnk = c.disputesPerPnk; | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
for (const parent of diffCourts) { | ||
for (const child of diffCourts) { | ||
if (parent.id === child.parent?.id) { | ||
child.treeVotesPerPnk += parent.votesPerPnk; | ||
child.treeDisputesPerPnk += parent.disputesPerPnk; | ||
} | ||
} | ||
} | ||
const bestDrawingChancesCourt = diffCourts.sort((a, b) => b.treeVotesPerPnk - a.treeVotesPerPnk)[0]; | ||
// 3. expected reward | ||
// since we isolated the exclusive disputes from the cumulative disputes | ||
// we can calculate the "isolated reward" of every court | ||
// after that's done, then just trickle the rewards down | ||
|
||
for (const c of diffCourts) { | ||
c.expectedRewardPerPnk = c.votesPerPnk * c.feeForJuror; | ||
c.treeExpectedRewardPerPnk = c.expectedRewardPerPnk; | ||
} | ||
for (const parent of diffCourts) { | ||
for (const child of diffCourts) { | ||
if (parent.id === child.parent?.id) { | ||
child.treeExpectedRewardPerPnk = parent.treeExpectedRewardPerPnk + child.treeExpectedRewardPerPnk; | ||
} | ||
} | ||
} | ||
const bestExpectedRewardCourt = diffCourts.sort( | ||
(a, b) => b.treeExpectedRewardPerPnk - a.treeExpectedRewardPerPnk | ||
)[0]; | ||
|
||
return { mostDisputedCourt, bestDrawingChancesCourt, bestExpectedRewardCourt, diffCourts }; | ||
} else { | ||
return undefined; | ||
} | ||
}, [usedQuery]); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return courtActivityStats; | ||
}; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.