automate daily rewards

This commit is contained in:
k00b 2025-01-13 19:59:05 -06:00
parent 5c1129c98f
commit d688e9fce8
3 changed files with 33 additions and 2 deletions

View File

@ -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;

View File

@ -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
@ -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
})
}

View File

@ -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'
@ -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))