From f31598d08d7a2d89d9f14d71f6f17ac5eddc3590 Mon Sep 17 00:00:00 2001 From: keyan Date: Mon, 4 Dec 2023 09:35:54 -0600 Subject: [PATCH] balance limit changes --- api/resolvers/wallet.js | 4 ++-- lib/constants.js | 6 ++++-- worker/earn.js | 5 ++--- worker/trust.js | 9 ++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index 89f4ee9c..cc40a147 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -8,7 +8,7 @@ import { SELECT } from './item' import { lnAddrOptions, lnurlPayDescriptionHash } from '../../lib/lnurl' import { msatsToSats, msatsToSatsDecimal } from '../../lib/format' import { amountSchema, lnAddrSchema, ssValidate, withdrawlSchema } from '../../lib/validate' -import { ANON_BALANCE_LIMIT_MSATS, ANON_INV_PENDING_LIMIT, ANON_USER_ID, BALANCE_LIMIT_MSATS, INV_PENDING_LIMIT } from '../../lib/constants' +import { ANON_BALANCE_LIMIT_MSATS, ANON_INV_PENDING_LIMIT, ANON_USER_ID, BALANCE_LIMIT_MSATS, INV_PENDING_LIMIT, USER_IDS_BALANCE_NO_LIMIT } from '../../lib/constants' import { datePivot } from '../../lib/time' export async function getInvoice (parent, { id }, { me, models, lnd }) { @@ -260,7 +260,7 @@ export default { let expirePivot = { seconds: expireSecs } let invLimit = INV_PENDING_LIMIT - let balanceLimit = BALANCE_LIMIT_MSATS + let balanceLimit = hodlInvoice || USER_IDS_BALANCE_NO_LIMIT.includes(Number(me.id)) ? 0 : BALANCE_LIMIT_MSATS let id = me?.id if (!me) { expirePivot = { seconds: Math.min(expireSecs, 180) } diff --git a/lib/constants.js b/lib/constants.js index af92d894..3b450e4f 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -23,9 +23,10 @@ export const MAX_POLL_CHOICE_LENGTH = 40 export const ITEM_SPAM_INTERVAL = '10m' export const ANON_ITEM_SPAM_INTERVAL = '0' export const INV_PENDING_LIMIT = 10 -export const BALANCE_LIMIT_MSATS = 1000000000 // 1m sat +export const BALANCE_LIMIT_MSATS = 500000000 // 500k sat +export const SN_USER_IDS = [616, 6030, 946, 4502] export const ANON_INV_PENDING_LIMIT = 100 -export const ANON_BALANCE_LIMIT_MSATS = 0 // disabl +export const ANON_BALANCE_LIMIT_MSATS = 0 // disable export const MAX_POLL_NUM_CHOICES = 10 export const MIN_POLL_NUM_CHOICES = 2 export const POLL_COST = 1 @@ -58,6 +59,7 @@ export const LNURLP_COMMENT_MAX_LENGTH = 1000 export const RESERVED_MAX_USER_ID = 615 export const GLOBAL_SEED = 616 export const FREEBIE_BASE_COST_THRESHOLD = 10 +export const USER_IDS_BALANCE_NO_LIMIT = [...SN_USER_IDS, AD_USER_ID] export const FOUND_BLURBS = [ 'The harsh frontier is no place for the unprepared. This hat will protect you from the sun, dust, and other elements Mother Nature throws your way.', diff --git a/worker/earn.js b/worker/earn.js index 39097b1d..fd96a3fe 100644 --- a/worker/earn.js +++ b/worker/earn.js @@ -1,13 +1,12 @@ import serialize from '../api/resolvers/serial.js' import { sendUserNotification } from '../api/webPush/index.js' -import { ANON_USER_ID } from '../lib/constants.js' +import { ANON_USER_ID, SN_USER_IDS } from '../lib/constants.js' import { msatsToSats, numWithUnits } from '../lib/format.js' const ITEM_EACH_REWARD = 4.0 const UPVOTE_EACH_REWARD = 4.0 const TOP_PERCENTILE = 33 const TOTAL_UPPER_BOUND_MSATS = 1000000000 -const REDUCE_REWARDS = [616, 6030, 946, 4502] export function earn ({ models }) { return async function ({ name }) { @@ -115,7 +114,7 @@ export function earn ({ models }) { -- early multiplier: 10/ln(early_rank + e) -- we also weight by trust in a step wise fashion upvoter_ratios AS ( - SELECT "userId", sum(early_multiplier*tipped_ratio*ratio*CASE WHEN users.id = ANY (${REDUCE_REWARDS}) THEN 0.2 ELSE CEIL(users.trust*2)+1 END) as upvoter_ratio, + SELECT "userId", sum(early_multiplier*tipped_ratio*ratio*CASE WHEN users.id = ANY (${SN_USER_IDS}) THEN 0.2 ELSE CEIL(users.trust*2)+1 END) as upvoter_ratio, "parentId" IS NULL as "isPost", CASE WHEN "parentId" IS NULL THEN 'TIP_POST' ELSE 'TIP_COMMENT' END as type FROM ( SELECT *, diff --git a/worker/trust.js b/worker/trust.js index 6dd26096..02edcd74 100644 --- a/worker/trust.js +++ b/worker/trust.js @@ -1,5 +1,5 @@ import * as math from 'mathjs' -import { ANON_USER_ID } from '../lib/constants.js' +import { ANON_USER_ID, SN_USER_IDS } from '../lib/constants.js' export function trust ({ boss, models }) { return async function () { @@ -28,7 +28,6 @@ const MIN_SUCCESS = 1 const DISAGREE_MULT = 10 // https://en.wikipedia.org/wiki/Normal_distribution#Quantile_function const Z_CONFIDENCE = 6.109410204869 // 99.9999999% confidence -const SEEDS = [616, 6030, 946, 4502] const GLOBAL_ROOT = 616 const SEED_WEIGHT = 0.25 const AGAINST_MSAT_MIN = 1000 @@ -74,7 +73,7 @@ function trustGivenGraph (graph) { console.timeLog('trust', 'transforming result') - const seedIdxs = SEEDS.map(id => posByUserId[id]) + const seedIdxs = SN_USER_IDS.map(id => posByUserId[id]) const isOutlier = (fromIdx, idx) => [...seedIdxs, fromIdx].includes(idx) const sqapply = (mat, fn) => { let idx = 0 @@ -156,10 +155,10 @@ async function getGraph (models) { confidence(before - disagree, b_total - after, ${Z_CONFIDENCE}) ELSE 0 END AS trust FROM user_pair - WHERE b_id <> ANY (${SEEDS}) + WHERE b_id <> ANY (${SN_USER_IDS}) UNION ALL SELECT a_id AS id, seed_id AS oid, ${MAX_TRUST}::numeric as trust - FROM user_pair, unnest(${SEEDS}::int[]) seed_id + FROM user_pair, unnest(${SN_USER_IDS}::int[]) seed_id GROUP BY a_id, a_total, seed_id UNION ALL SELECT a_id AS id, a_id AS oid, ${MAX_TRUST}::float as trust