Proposed: refactor all financial logic into generic functions. Then to migrate all the financial infrastructure we simply convert those ~6 function definitions to supabase
type Transaction = firebase transaction
(for now. after migration it will be supabase)
doTransaction(async (t: Transaction) => any)
this is the parent function for any financial transaction, in which you can do any of the following:
logTxn(t: Transaction, txn: Txn)
addToBalance(t: Transaction, userId: string, amount: number, affectsProfit = false)
negative to sub
updateLiquidity(t: Transaction, contractId: string, liquidity: liquidityDoc)
giveShares
updatePool
not sure if this one is needed
[mqp] I have no opinion on whether we should refactor stuff to be in terms of functions like this, since I didn’t read all the code that does all this stuff, but if we do, they definitely need to be batch functions (e.g. logTxns(t: DBTransaction, ...txns: Txn[])
), not one-at-a-time functions, or we will produce disastrous code.
[c] agreed