Skip to content

Commit

Permalink
untested rewards/leaderboard changes
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Dec 17, 2024
1 parent 97694be commit f47a70f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/resolvers/rewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default {
const [{ to, from }] = await models.$queryRaw`
SELECT date_trunc('day', (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago' as from,
(date_trunc('day', (now() AT TIME ZONE 'America/Chicago')) AT TIME ZONE 'America/Chicago') + interval '1 day - 1 second' as to`
return await topUsers(parent, { when: 'custom', to: new Date(to).getTime().toString(), from: new Date(from).getTime().toString(), limit: 100 }, { models, ...context })
return await topUsers(parent, { when: 'custom', to: new Date(to).getTime().toString(), from: new Date(from).getTime().toString(), limit: 500 }, { models, ...context })
},
total: async (parent, args, { models }) => {
if (!parent.total) {
Expand Down
2 changes: 1 addition & 1 deletion api/resolvers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function topUsers (parent, { cursor, when, by, from, to, limit = LI
}

const users = (await models.$queryRawUnsafe(`
SELECT *
SELECT *, ${column === 'proportion' ? 'proportion' : ''}
FROM
(SELECT users.*,
COALESCE(floor(sum(msats_spent)/1000), 0) as spent,
Expand Down
2 changes: 1 addition & 1 deletion api/typeDefs/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default gql`
bioId: Int
photoId: Int
since: Int
proportion: Float
optional: UserOptional!
privates: UserPrivates
Expand Down
8 changes: 4 additions & 4 deletions components/user-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ export function User ({ user, rank, statComps, className = 'mb-2', Embellish, ny
<div className={styles.other}>
{statComps.map((Comp, i) => <Comp key={i} user={user} />)}
</div>}
{Embellish && <Embellish rank={rank} />}
{Embellish && <Embellish rank={rank} user={user} />}
</UserBase>
</>
)
}

function UserHidden ({ rank, Embellish }) {
function UserHidden ({ rank, user, Embellish }) {
return (
<>
{rank
Expand All @@ -133,7 +133,7 @@ function UserHidden ({ rank, Embellish }) {
<div className={`${styles.title} text-muted d-inline-flex align-items-center`}>
stacker is in hiding
</div>
{Embellish && <Embellish rank={rank} />}
{Embellish && <Embellish rank={rank} user={user} />}
</div>
</div>
</>
Expand All @@ -148,7 +148,7 @@ export function ListUsers ({ users, rank, statComps = DEFAULT_STAT_COMPONENTS, E
{users.map((user, i) => (
user
? <User key={user.id} user={user} rank={rank && i + 1} statComps={statComps} Embellish={Embellish} nymActionDropdown={nymActionDropdown} />
: <UserHidden key={i} rank={rank && i + 1} Embellish={Embellish} />
: <UserHidden key={i} rank={rank && i + 1} user={user} Embellish={Embellish} />
))}
</div>
)
Expand Down
8 changes: 4 additions & 4 deletions pages/rewards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useToast } from '@/components/toast'
import { useLightning } from '@/components/lightning'
import { ListUsers } from '@/components/user-list'
import { Col, Row } from 'react-bootstrap'
import { proportions } from '@/lib/madness'
import { useData } from '@/components/use-data'
import { GrowthPieChartSkeleton } from '@/components/charts-skeletons'
import { useMemo } from 'react'
Expand Down Expand Up @@ -50,6 +49,7 @@ ${ITEM_FULL_FIELDS}
photoId
ncomments
nposts
proportion
optional {
streak
Expand Down Expand Up @@ -117,9 +117,9 @@ export default function Rewards ({ ssrData }) {

if (!dat) return <PageLoading />

function EstimatedReward ({ rank }) {
const referrerReward = Math.floor(total * proportions[rank - 1] * 0.2)
const reward = Math.floor(total * proportions[rank - 1]) - referrerReward
function EstimatedReward ({ rank, user }) {
const referrerReward = Math.max(Math.floor(total * user.proportion * 0.2), 0)
const reward = Math.max(Math.floor(total * user.proportion) - referrerReward, 0)

return (
<div className='text-muted fst-italic'>
Expand Down
13 changes: 6 additions & 7 deletions worker/earn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { notifyEarner } from '@/lib/webPush'
import createPrisma from '@/lib/create-prisma'
import { proportions } from '@/lib/madness'
import { SN_NO_REWARDS_IDS } from '@/lib/constants'

const TOTAL_UPPER_BOUND_MSATS = 1_000_000_000
Expand Down Expand Up @@ -40,15 +39,15 @@ export async function earn ({ name }) {

/*
How earnings (used to) work:
1/3: top 21% posts over last 36 hours, scored on a relative basis
1/3: top 21% comments over last 36 hours, scored on a relative basis
1/3: top 50% posts over last 36 hours, scored on a relative basis
1/3: top 50% comments over last 36 hours, scored on a relative basis
1/3: top upvoters of top posts/comments, scored on:
- their trust
- how much they tipped
- how early they upvoted it
- how the post/comment scored
Now: 80% of earnings go to top 100 stackers by value, and 10% each to their forever and one day referrers
Now: 80% of earnings go to top stackers by relative value, and 10% each to their forever and one day referrers
*/

// get earners { userId, id, type, rank, proportion, foreverReferrerId, oneDayReferrerId }
Expand All @@ -63,8 +62,8 @@ export async function earn ({ name }) {
'day') uv
JOIN users ON users.id = uv.id
WHERE NOT (users.id = ANY (${SN_NO_REWARDS_IDS}))
AND uv.proportion > 0.00000001
ORDER BY proportion DESC
LIMIT 100
)
SELECT earners.*,
COALESCE(
Expand All @@ -86,10 +85,10 @@ export async function earn ({ name }) {
let total = 0

const notifications = {}
for (const [i, earner] of earners.entries()) {
for (const [earner] of earners.entries()) {
const foreverReferrerEarnings = Math.floor(parseFloat(earner.proportion * sum * 0.1)) // 10% of earnings
let oneDayReferrerEarnings = Math.floor(parseFloat(earner.proportion * sum * 0.1)) // 10% of earnings
const earnerEarnings = Math.floor(parseFloat(proportions[i] * sum)) - foreverReferrerEarnings - oneDayReferrerEarnings
const earnerEarnings = Math.floor(parseFloat(earner.proportion * sum)) - foreverReferrerEarnings - oneDayReferrerEarnings

total += earnerEarnings + foreverReferrerEarnings + oneDayReferrerEarnings
if (total > sum) {
Expand Down

0 comments on commit f47a70f

Please sign in to comment.