balance limit changes

This commit is contained in:
keyan 2023-12-04 09:35:54 -06:00
parent f465c6d881
commit f31598d08d
4 changed files with 12 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import { SELECT } from './item'
import { lnAddrOptions, lnurlPayDescriptionHash } from '../../lib/lnurl' import { lnAddrOptions, lnurlPayDescriptionHash } from '../../lib/lnurl'
import { msatsToSats, msatsToSatsDecimal } from '../../lib/format' import { msatsToSats, msatsToSatsDecimal } from '../../lib/format'
import { amountSchema, lnAddrSchema, ssValidate, withdrawlSchema } from '../../lib/validate' 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' import { datePivot } from '../../lib/time'
export async function getInvoice (parent, { id }, { me, models, lnd }) { export async function getInvoice (parent, { id }, { me, models, lnd }) {
@ -260,7 +260,7 @@ export default {
let expirePivot = { seconds: expireSecs } let expirePivot = { seconds: expireSecs }
let invLimit = INV_PENDING_LIMIT 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 let id = me?.id
if (!me) { if (!me) {
expirePivot = { seconds: Math.min(expireSecs, 180) } expirePivot = { seconds: Math.min(expireSecs, 180) }

View File

@ -23,9 +23,10 @@ export const MAX_POLL_CHOICE_LENGTH = 40
export const ITEM_SPAM_INTERVAL = '10m' export const ITEM_SPAM_INTERVAL = '10m'
export const ANON_ITEM_SPAM_INTERVAL = '0' export const ANON_ITEM_SPAM_INTERVAL = '0'
export const INV_PENDING_LIMIT = 10 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_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 MAX_POLL_NUM_CHOICES = 10
export const MIN_POLL_NUM_CHOICES = 2 export const MIN_POLL_NUM_CHOICES = 2
export const POLL_COST = 1 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 RESERVED_MAX_USER_ID = 615
export const GLOBAL_SEED = 616 export const GLOBAL_SEED = 616
export const FREEBIE_BASE_COST_THRESHOLD = 10 export const FREEBIE_BASE_COST_THRESHOLD = 10
export const USER_IDS_BALANCE_NO_LIMIT = [...SN_USER_IDS, AD_USER_ID]
export const FOUND_BLURBS = [ 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.', '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.',

View File

@ -1,13 +1,12 @@
import serialize from '../api/resolvers/serial.js' import serialize from '../api/resolvers/serial.js'
import { sendUserNotification } from '../api/webPush/index.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' import { msatsToSats, numWithUnits } from '../lib/format.js'
const ITEM_EACH_REWARD = 4.0 const ITEM_EACH_REWARD = 4.0
const UPVOTE_EACH_REWARD = 4.0 const UPVOTE_EACH_REWARD = 4.0
const TOP_PERCENTILE = 33 const TOP_PERCENTILE = 33
const TOTAL_UPPER_BOUND_MSATS = 1000000000 const TOTAL_UPPER_BOUND_MSATS = 1000000000
const REDUCE_REWARDS = [616, 6030, 946, 4502]
export function earn ({ models }) { export function earn ({ models }) {
return async function ({ name }) { return async function ({ name }) {
@ -115,7 +114,7 @@ export function earn ({ models }) {
-- early multiplier: 10/ln(early_rank + e) -- early multiplier: 10/ln(early_rank + e)
-- we also weight by trust in a step wise fashion -- we also weight by trust in a step wise fashion
upvoter_ratios AS ( 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 "parentId" IS NULL as "isPost", CASE WHEN "parentId" IS NULL THEN 'TIP_POST' ELSE 'TIP_COMMENT' END as type
FROM ( FROM (
SELECT *, SELECT *,

View File

@ -1,5 +1,5 @@
import * as math from 'mathjs' 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 }) { export function trust ({ boss, models }) {
return async function () { return async function () {
@ -28,7 +28,6 @@ const MIN_SUCCESS = 1
const DISAGREE_MULT = 10 const DISAGREE_MULT = 10
// https://en.wikipedia.org/wiki/Normal_distribution#Quantile_function // https://en.wikipedia.org/wiki/Normal_distribution#Quantile_function
const Z_CONFIDENCE = 6.109410204869 // 99.9999999% confidence const Z_CONFIDENCE = 6.109410204869 // 99.9999999% confidence
const SEEDS = [616, 6030, 946, 4502]
const GLOBAL_ROOT = 616 const GLOBAL_ROOT = 616
const SEED_WEIGHT = 0.25 const SEED_WEIGHT = 0.25
const AGAINST_MSAT_MIN = 1000 const AGAINST_MSAT_MIN = 1000
@ -74,7 +73,7 @@ function trustGivenGraph (graph) {
console.timeLog('trust', 'transforming result') 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 isOutlier = (fromIdx, idx) => [...seedIdxs, fromIdx].includes(idx)
const sqapply = (mat, fn) => { const sqapply = (mat, fn) => {
let idx = 0 let idx = 0
@ -156,10 +155,10 @@ async function getGraph (models) {
confidence(before - disagree, b_total - after, ${Z_CONFIDENCE}) confidence(before - disagree, b_total - after, ${Z_CONFIDENCE})
ELSE 0 END AS trust ELSE 0 END AS trust
FROM user_pair FROM user_pair
WHERE b_id <> ANY (${SEEDS}) WHERE b_id <> ANY (${SN_USER_IDS})
UNION ALL UNION ALL
SELECT a_id AS id, seed_id AS oid, ${MAX_TRUST}::numeric as trust 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 GROUP BY a_id, a_total, seed_id
UNION ALL UNION ALL
SELECT a_id AS id, a_id AS oid, ${MAX_TRUST}::float as trust SELECT a_id AS id, a_id AS oid, ${MAX_TRUST}::float as trust