Skip to content

Commit

Permalink
improve rewards cutoff criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Dec 18, 2024
1 parent 42621df commit 60fbacb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions worker/earn.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function earn ({ name }) {
*/

// get earners { userId, id, type, rank, proportion, foreverReferrerId, oneDayReferrerId }
// has to earn at least 125000 msats to be eligible (so that they get at least 1 sat after referrals)
const earners = await models.$queryRaw`
WITH earners AS (
SELECT users.id AS "userId", users."referrerId" AS "foreverReferrerId",
Expand All @@ -62,7 +63,7 @@ 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
AND uv.proportion >= 0.0000125
ORDER BY proportion DESC
)
SELECT earners.*,
Expand All @@ -85,7 +86,7 @@ export async function earn ({ name }) {
let total = 0

const notifications = {}
for (const [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(earner.proportion * sum)) - foreverReferrerEarnings - oneDayReferrerEarnings
Expand All @@ -107,7 +108,7 @@ export async function earn ({ name }) {
'oneDayReferrer', earner.oneDayReferrerId,
'oneDayReferrerEarnings', oneDayReferrerEarnings)

if (earnerEarnings > 0) {
if (earnerEarnings > 1000) {
stmts.push(...earnStmts({
msats: earnerEarnings,
userId: earner.userId,
Expand Down Expand Up @@ -139,7 +140,7 @@ export async function earn ({ name }) {
}
}

if (earner.foreverReferrerId && foreverReferrerEarnings > 0) {
if (earner.foreverReferrerId && foreverReferrerEarnings > 1000) {
stmts.push(...earnStmts({
msats: foreverReferrerEarnings,
userId: earner.foreverReferrerId,
Expand All @@ -152,7 +153,7 @@ export async function earn ({ name }) {
oneDayReferrerEarnings += foreverReferrerEarnings
}

if (earner.oneDayReferrerId && oneDayReferrerEarnings > 0) {
if (earner.oneDayReferrerId && oneDayReferrerEarnings > 1000) {
stmts.push(...earnStmts({
msats: oneDayReferrerEarnings,
userId: earner.oneDayReferrerId,
Expand Down

0 comments on commit 60fbacb

Please sign in to comment.