drizzle liquidity: add velocity; dev script; run every minute
This commit is contained in:
parent
18683dbdf9
commit
8ac6896b75
|
@ -9,30 +9,37 @@ import { formatMoney } from '../../common/util/format'
|
||||||
|
|
||||||
const firestore = admin.firestore()
|
const firestore = admin.firestore()
|
||||||
|
|
||||||
export const drizzleLiquidity = functions.pubsub
|
export const drizzleLiquidity = async () => {
|
||||||
.schedule('every 2 minutes')
|
const snap = await firestore
|
||||||
.onRun(async () => {
|
.collection('contracts')
|
||||||
const snap = await firestore
|
.where('subsidyPool', '>', 1e-7)
|
||||||
.collection('contracts')
|
.get()
|
||||||
.where('subsidyPool', '>', 1e-7)
|
|
||||||
.get()
|
|
||||||
const contractIds = snap.docs.map((doc) => doc.id)
|
|
||||||
|
|
||||||
await batchedWaitAll(
|
const contractIds = snap.docs.map((doc) => doc.id)
|
||||||
contractIds.map((cid) => () => drizzleMarket(cid)),
|
console.log('found', contractIds.length, 'markets to drizzle')
|
||||||
10
|
console.log()
|
||||||
)
|
|
||||||
})
|
await batchedWaitAll(
|
||||||
|
contractIds.map((cid) => () => drizzleMarket(cid)),
|
||||||
|
10
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const drizzleLiquidityScheduler = functions.pubsub
|
||||||
|
.schedule('* * * * *') // every minute
|
||||||
|
.onRun(drizzleLiquidity)
|
||||||
|
|
||||||
const drizzleMarket = async (contractId: string) => {
|
const drizzleMarket = async (contractId: string) => {
|
||||||
await firestore.runTransaction(async (trans) => {
|
await firestore.runTransaction(async (trans) => {
|
||||||
const snap = await trans.get(firestore.doc(`contracts/${contractId}`))
|
const snap = await trans.get(firestore.doc(`contracts/${contractId}`))
|
||||||
const contract = snap.data() as CPMMContract
|
const contract = snap.data() as CPMMContract
|
||||||
const { subsidyPool, pool, p, slug, } = contract
|
const { subsidyPool, pool, p, slug, popularityScore } = contract
|
||||||
if (subsidyPool ?? 0 < 1e-7) return
|
if ((subsidyPool ?? 0) < 1e-7) return
|
||||||
|
|
||||||
const r = Math.random()
|
const r = Math.random()
|
||||||
const amount = subsidyPool <= 1 ? subsidyPool : r * 0.02 * subsidyPool
|
const logPopularity = Math.log10((popularityScore ?? 0) + 1)
|
||||||
|
const v = Math.max(1, Math.min(4, logPopularity))
|
||||||
|
const amount = subsidyPool <= 1 ? subsidyPool : r * v * 0.02 * subsidyPool
|
||||||
|
|
||||||
const { newPool, newP } = addCpmmLiquidity(pool, p, amount)
|
const { newPool, newP } = addCpmmLiquidity(pool, p, amount)
|
||||||
|
|
||||||
|
@ -57,5 +64,6 @@ const drizzleMarket = async (contractId: string) => {
|
||||||
'pool to',
|
'pool to',
|
||||||
slug
|
slug
|
||||||
)
|
)
|
||||||
|
console.log()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
8
functions/src/scripts/drizzle.ts
Normal file
8
functions/src/scripts/drizzle.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { initAdmin } from './script-init'
|
||||||
|
initAdmin()
|
||||||
|
|
||||||
|
import { drizzleLiquidity } from '../drizzle-liquidity'
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
drizzleLiquidity().then(() => process.exit())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user