From d688e9fce8f5bd13dfd14affea3a9b2a9d7842a5 Mon Sep 17 00:00:00 2001 From: k00b Date: Mon, 13 Jan 2025 19:59:05 -0600 Subject: [PATCH] automate daily rewards --- .../migration.sql | 17 +++++++++++++++++ worker/earn.js | 15 ++++++++++++++- worker/index.js | 3 ++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20250113235235_daily_rewards_refill_job/migration.sql diff --git a/prisma/migrations/20250113235235_daily_rewards_refill_job/migration.sql b/prisma/migrations/20250113235235_daily_rewards_refill_job/migration.sql new file mode 100644 index 000000000..e52866bfe --- /dev/null +++ b/prisma/migrations/20250113235235_daily_rewards_refill_job/migration.sql @@ -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; diff --git a/worker/earn.js b/worker/earn.js index 019cf9bb1..5790548a4 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -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 + }) +} diff --git a/worker/index.js b/worker/index.js index 16d48c59c..dfb6c4f97 100644 --- a/worker/index.js +++ b/worker/index.js @@ -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))