Skip to content

Commit

Permalink
Merge pull request #1817 from stackernews/daily-rewards-refill-job
Browse files Browse the repository at this point in the history
bounty updates and auto-rewards refill
  • Loading branch information
huumn authored Jan 14, 2025
2 parents c40ef5a + d688e9f commit 3ce9d73
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/info/cc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function CCInfo (props) {
<ul className='line-height-md'>
<li>to receive sats, you must attach an <Link href='/wallets'>external receiving wallet</Link></li>
<li>zappers may have chosen to send you CCs instead of sats</li>
<li>if the zaps are split on post, recepients will receive CCs regardless of their configured receiving wallet</li>
<li>if the zaps are split on a post, recepients will receive CCs regardless of their configured receiving wallet</li>
<li>there could be an issue paying your receiving wallet
<ul>
<li>check your <Link href='/wallets/logs'>wallet logs</Link> for clues</li>
Expand Down
37 changes: 37 additions & 0 deletions prisma/migrations/20250113233026_weekly_posts_update/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE OR REPLACE FUNCTION update_weekly_posts_job()
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
UPDATE pgboss.schedule
SET data = jsonb_build_object(
'title', 'Meme Monday - Best Bitcoin Meme Gets 5,000 CCs',
'text', E'Time for another round of Meme Monday!\n\nWe have another 5,000 CCs up for grabs for this week''s winner.\n\nThe CCs will be given to the stacker with the best Bitcoin meme as voted by the "top" filter on this thread at 10am CT tomorrow.\n\nTo post an image on SN, check out our docs [here](https://stacker.news/faq#how-do-i-post-images-on-stacker-news).\n\nSend your best 👇',
'bounty', 5000,
'subName', 'memes')
WHERE name = 'weeklyPost-meme-mon';

UPDATE pgboss.schedule
SET data = jsonb_build_object(
'title', 'What are you working on this week?',
'text', E'Calling all stackers!\n\nLeave a comment below to let the SN community know what you''re working on this week. It doesn''t matter how big or small your project is, or how much progress you''ve made.\n\nJust share what you''re up to, and let the community know if you want any feedback or help.',
'subName', 'meta')
WHERE name = 'weeklyPost-what-wed';

UPDATE pgboss.schedule
SET data = jsonb_build_object(
'title', 'Fun Fact Friday - Best Fun Fact Gets 5,000 CCs',
'text', E'Let''s hear all your best fun facts, any topic counts!\n\nThe best comment as voted by the "top" filter at 10am CT tomorrow gets 5,000 CCs.\n\nBonus CCs for including a source link to your fun fact!\n\nSend your best 👇',
'bounty', 5000,
'subName', 'meta')
WHERE name = 'weeklyPost-fact-fri';

return 0;
EXCEPTION WHEN OTHERS THEN
return 0;
END;
$$;

SELECT update_weekly_posts_job();
DROP FUNCTION IF EXISTS update_weekly_posts_job;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE OR REPLACE FUNCTION schedule_daily_rewards_refill_job()
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
-- 10 minutes after midnight
INSERT INTO pgboss.schedule (name, cron, timezone)
VALUES ('earnRefill', '10 0 * * *', 'America/Chicago') ON CONFLICT DO NOTHING;
return 0;
EXCEPTION WHEN OTHERS THEN
return 0;
END;
$$;

SELECT schedule_daily_rewards_refill_job();
DROP FUNCTION IF EXISTS schedule_daily_rewards_refill_job;
15 changes: 14 additions & 1 deletion worker/earn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { notifyEarner } from '@/lib/webPush'
import createPrisma from '@/lib/create-prisma'
import { SN_NO_REWARDS_IDS } from '@/lib/constants'
import { PAID_ACTION_PAYMENT_METHODS, SN_NO_REWARDS_IDS, USER_ID } from '@/lib/constants'
import performPaidAction from '@/api/paidAction'

const TOTAL_UPPER_BOUND_MSATS = 1_000_000_000

Expand Down Expand Up @@ -187,3 +188,15 @@ function earnStmts (data, { models }) {
}
})]
}

const DAILY_STIMULUS_SATS = 75_000
export async function earnRefill ({ models, lnd }) {
return await performPaidAction('DONATE',
{ sats: DAILY_STIMULUS_SATS },
{
models,
me: { id: USER_ID.sn },
lnd,
forcePaymentMethod: PAID_ACTION_PAYMENT_METHODS.FEE_CREDIT
})
}
3 changes: 2 additions & 1 deletion worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './wallet'
import { repin } from './repin'
import { trust } from './trust'
import { earn } from './earn'
import { earn, earnRefill } from './earn'
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import { indexItem, indexAllItems } from './search'
import { timestampItem } from './ots'
Expand Down Expand Up @@ -129,6 +129,7 @@ async function work () {
await boss.work('trust', jobWrapper(trust))
await boss.work('timestampItem', jobWrapper(timestampItem))
await boss.work('earn', jobWrapper(earn))
await boss.work('earnRefill', jobWrapper(earnRefill))
await boss.work('streak', jobWrapper(computeStreaks))
await boss.work('checkStreak', jobWrapper(checkStreak))
await boss.work('nip57', jobWrapper(nip57))
Expand Down
2 changes: 1 addition & 1 deletion worker/weeklyPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import gql from 'graphql-tag'

export async function autoPost ({ data: item, models, apollo, lnd, boss }) {
return await performPaidAction('ITEM_CREATE',
{ ...item, subName: 'meta', userId: USER_ID.sn, apiKey: true },
{ subName: 'meta', ...item, userId: USER_ID.sn, apiKey: true },
{
models,
me: { id: USER_ID.sn },
Expand Down

0 comments on commit 3ce9d73

Please sign in to comment.