predikt/oracle/backend/scripts/resolve-dates-no.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

66 lines
2.0 KiB
TypeScript

import { runScript } from 'run-script'
import { Answer } from 'common/answer'
import { CPMMMultiContract } from 'common/contract'
import { manifoldLoveUserId } from 'common/love/constants'
import { resolveMarketHelper } from 'shared/resolve-market-helpers'
import { getUser } from 'shared/utils'
if (require.main === module) {
runScript(async ({ pg, firestore }) => {
const contracts = await pg.map<CPMMMultiContract>(
`
select data
from contracts
where data ->> 'loverUserId1' is not null
and outcome_type = 'MULTIPLE_CHOICE'
and resolution is null
and (data -> 'answers' -> 0 ->> 'text') LIKE '%Dec 11%'
and (data -> 'answers' -> 0 ->> 'resolution') is null
`,
[],
(r) => r.data
)
console.log(contracts.length, 'contracts to resolve')
const manifoldLoveUser = await getUser(manifoldLoveUserId)
if (!manifoldLoveUser) throw new Error('Oracle Love user not found')
for (const contract of contracts) {
let lastResolution = 'YES'
for (const answerId of contract.answers.map((a) => a.id)) {
// Fetch latest answers.
const answersSnap = await firestore
.collection(`contracts/${contract.id}/answersCpmm`)
.get()
const answers = answersSnap.docs.map((doc) => doc.data() as Answer)
contract.answers = answers
const answer = answers.find((a) => a.id === answerId)
if (!answer) throw new Error('Answer not found')
if (answer.resolution) {
lastResolution = answer.resolution
continue
}
const outcome = lastResolution === 'YES' ? 'NO' : 'CANCEL'
console.log('Resolving ' + answer.text + ' to ' + outcome)
await resolveMarketHelper(
contract,
manifoldLoveUser,
manifoldLoveUser,
{
answerId: answer.id,
outcome,
}
)
lastResolution = outcome
}
console.log('Resolved contract', contract.question)
}
})
}