migration script now re-simulates individual markets specified in command line
This commit is contained in:
parent
d32147b536
commit
8331e7afc5
|
@ -17,9 +17,14 @@ const serviceAccount = require('../../../../../../Downloads/mantic-markets-fireb
|
||||||
admin.initializeApp({
|
admin.initializeApp({
|
||||||
credential: admin.credential.cert(serviceAccount),
|
credential: admin.credential.cert(serviceAccount),
|
||||||
})
|
})
|
||||||
|
|
||||||
const firestore = admin.firestore()
|
const firestore = admin.firestore()
|
||||||
|
|
||||||
async function recalculateContract(contractRef: DocRef, contract: Contract) {
|
async function recalculateContract(
|
||||||
|
contractRef: DocRef,
|
||||||
|
contract: Contract,
|
||||||
|
isCommit = false
|
||||||
|
) {
|
||||||
const startPool = (contract as any).startPool as
|
const startPool = (contract as any).startPool as
|
||||||
| undefined
|
| undefined
|
||||||
| { YES: number; NO: number }
|
| { YES: number; NO: number }
|
||||||
|
@ -113,8 +118,8 @@ async function recalculateContract(contractRef: DocRef, contract: Contract) {
|
||||||
getSellBetInfo(fakeUser, soldBet, fakeContract, bet.id)
|
getSellBetInfo(fakeUser, soldBet, fakeContract, bet.id)
|
||||||
|
|
||||||
newBet.createdTime = bet.createdTime
|
newBet.createdTime = bet.createdTime
|
||||||
// console.log('sale bet', newBet)
|
console.log('sale bet', newBet)
|
||||||
transaction.update(betsRef.doc(bet.id), newBet)
|
if (isCommit) transaction.update(betsRef.doc(bet.id), newBet)
|
||||||
|
|
||||||
pool = newPool
|
pool = newPool
|
||||||
totalShares = newTotalShares
|
totalShares = newTotalShares
|
||||||
|
@ -152,10 +157,10 @@ async function recalculateContract(contractRef: DocRef, contract: Contract) {
|
||||||
probAfter,
|
probAfter,
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('bet', betUpdate)
|
console.log('bet', betUpdate)
|
||||||
// console.log('update', { pool, totalBets, totalShares })
|
console.log('update', { pool, totalBets, totalShares })
|
||||||
|
|
||||||
transaction.update(betsRef.doc(bet.id), betUpdate)
|
if (isCommit) transaction.update(betsRef.doc(bet.id), betUpdate)
|
||||||
}
|
}
|
||||||
|
|
||||||
const contractUpdate: Partial<Contract> = {
|
const contractUpdate: Partial<Contract> = {
|
||||||
|
@ -166,7 +171,7 @@ async function recalculateContract(contractRef: DocRef, contract: Contract) {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('final', contractUpdate)
|
console.log('final', contractUpdate)
|
||||||
transaction.update(contractRef, contractUpdate)
|
if (isCommit) transaction.update(contractRef, contractUpdate)
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('updated', contract.slug)
|
console.log('updated', contract.slug)
|
||||||
|
@ -174,21 +179,24 @@ async function recalculateContract(contractRef: DocRef, contract: Contract) {
|
||||||
console.log()
|
console.log()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recalculateContractTotals() {
|
async function main() {
|
||||||
console.log('Migrating ante calculations to DPM-2')
|
const slug = process.argv[2]
|
||||||
|
const isCommit = process.argv[3] === 'commit'
|
||||||
|
|
||||||
const snapshot = await firestore.collection('contracts').get()
|
const snap = await firestore
|
||||||
const contracts = snapshot.docs.map((doc) => doc.data() as Contract)
|
.collection('contracts')
|
||||||
|
.where('slug', '==', slug)
|
||||||
|
.get()
|
||||||
|
|
||||||
console.log('Loaded', contracts.length, 'contracts')
|
const contract = snap.docs[0]?.data() as Contract
|
||||||
|
if (!contract) {
|
||||||
for (const contract of contracts) {
|
console.log('No contract found for', slug)
|
||||||
// if (contract.slug !== 'will-polymarket-list-any-new-market') continue
|
return
|
||||||
const contractRef = firestore.doc(`contracts/${contract.id}`)
|
|
||||||
|
|
||||||
await recalculateContract(contractRef, contract)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contractRef = firestore.doc(`contracts/${contract.id}`)
|
||||||
|
|
||||||
|
await recalculateContract(contractRef, contract, isCommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module)
|
if (require.main === module) main().then(() => process.exit())
|
||||||
recalculateContractTotals().then(() => process.exit())
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user