Skip to content

Commit

Permalink
automate daily rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Jan 14, 2025
1 parent 5c1129c commit d688e9f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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

0 comments on commit d688e9f

Please sign in to comment.