predikt/oracle/backend/scripts/reclaim-mana-undo.ts
caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

71 lines
2.0 KiB
TypeScript

import { runScript } from './run-script'
import { runTxn } from 'shared/src/txn/run-txn'
import { ReclaimManaTxn } from 'common/src/txn'
import { convertTxn } from 'common/supabase/txns'
if (require.main === module) {
runScript(async ({ pg, firestore }) => {
// const usernamesToNotUndo = [
// 'BetonLove',
// 'OracleBugs',
// 'VersusBot',
// 'manifoldtestnewuserc32ebf',
// 'OracleDream',
// 'honey', // already undid reclaim
// ]
const usersToUndoReclaim = await pg.manyOrNone(`
select from_id, username from txns
join users on users.id = txns.from_id
where
category ='RECLAIM_MANA'
and amount < 1500
and amount > 0
and (users.data->'creatorTraders'->>'allTime')::numeric > 0
order by amount desc`)
console.log(
'usernames to undo reclaim:',
usersToUndoReclaim.map(({ username }) => username)
)
const usersIdsToUndoReclaim = usersToUndoReclaim.map(
({ from_id }) => from_id as string
)
const reclaimTxns = await pg.map(
`SELECT * FROM txns
WHERE
from_id IN ($1:list)
AND category = 'RECLAIM_MANA'`,
[usersIdsToUndoReclaim],
(r) => convertTxn(r) as ReclaimManaTxn
)
for (const reclaimTxn of reclaimTxns) {
const hasNegativeTxn = await pg.oneOrNone(
`SELECT * FROM txns
WHERE from_id = $1
AND category = 'RECLAIM_MANA'
AND amount < 0
limit 1`,
[reclaimTxn.fromId]
)
if (hasNegativeTxn) {
console.log('has negative txn', hasNegativeTxn, reclaimTxn)
continue
}
const { amount, fromId } = reclaimTxn
const result = await firestore.runTransaction(async (txn) => {
return runTxn(txn, {
fromId,
fromType: 'USER',
toId: 'BANK',
toType: 'BANK',
amount: -amount,
category: 'RECLAIM_MANA',
token: 'M$',
})
})
console.log('Result:', result)
}
})
}