diff --git a/common/add-liquidity.ts b/common/add-liquidity.ts index 573b609d..0421bcb5 100644 --- a/common/add-liquidity.ts +++ b/common/add-liquidity.ts @@ -29,7 +29,5 @@ export const getNewLiquidityProvision = ( const newTotalLiquidity = (totalLiquidity ?? 0) + amount - const newBalance = user.balance - amount - - return { newLiquidityProvision, newPool, newP, newBalance, newTotalLiquidity } + return { newLiquidityProvision, newPool, newP, newTotalLiquidity } } diff --git a/functions/src/add-liquidity.ts b/functions/src/add-liquidity.ts index e37804d3..34d3f7c6 100644 --- a/functions/src/add-liquidity.ts +++ b/functions/src/add-liquidity.ts @@ -54,18 +54,13 @@ export const addLiquidity = functions.runWith({ minInstances: 1 }).https.onCall( .collection(`contracts/${contractId}/liquidity`) .doc() - const { - newLiquidityProvision, - newPool, - newP, - newBalance, - newTotalLiquidity, - } = getNewLiquidityProvision( - user, - amount, - contract, - newLiquidityProvisionDoc.id - ) + const { newLiquidityProvision, newPool, newP, newTotalLiquidity } = + getNewLiquidityProvision( + user, + amount, + contract, + newLiquidityProvisionDoc.id + ) if (newP !== undefined && !isFinite(newP)) { return { @@ -83,11 +78,17 @@ export const addLiquidity = functions.runWith({ minInstances: 1 }).https.onCall( }) ) + const newBalance = user.balance - amount + const newTotalDeposits = user.totalDeposits - amount + if (!isFinite(newBalance)) { throw new Error('Invalid user balance for ' + user.username) } - transaction.update(userDoc, { balance: newBalance }) + transaction.update(userDoc, { + balance: newBalance, + totalDeposits: newTotalDeposits, + }) transaction.create(newLiquidityProvisionDoc, newLiquidityProvision) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index c3b70734..fb084d56 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -17,6 +17,7 @@ export const sendMarketResolutionEmail = async ( investment: number, payout: number, creator: User, + creatorPayout: number, contract: Contract, resolution: string, resolutionProbability?: number, @@ -42,6 +43,11 @@ export const sendMarketResolutionEmail = async ( const subject = `Resolved ${outcome}: ${contract.question}` + const creatorPayoutText = + userId === creator.id + ? ` (plus ${formatMoney(creatorPayout)} in commissions)` + : '' + const templateData: market_resolved_template = { userId: user.id, name: user.name, @@ -49,7 +55,7 @@ export const sendMarketResolutionEmail = async ( question: contract.question, outcome, investment: `${Math.floor(investment)}`, - payout: `${Math.floor(payout)}`, + payout: `${Math.floor(payout)}${creatorPayoutText}`, url: `https://${DOMAIN}/${creator.username}/${contract.slug}`, } diff --git a/functions/src/resolve-market.ts b/functions/src/resolve-market.ts index efc8e92f..0ef416a7 100644 --- a/functions/src/resolve-market.ts +++ b/functions/src/resolve-market.ts @@ -146,6 +146,7 @@ export const resolveMarket = functions openBets, userPayoutsWithoutLoans, creator, + creatorPayout, contract, outcome, resolutionProbability, @@ -172,6 +173,7 @@ const sendResolutionEmails = async ( openBets: Bet[], userPayouts: { [userId: string]: number }, creator: User, + creatorPayout: number, contract: Contract, outcome: string, resolutionProbability?: number, @@ -201,6 +203,7 @@ const sendResolutionEmails = async ( investment, payout, creator, + creatorPayout, contract, outcome, resolutionProbability, diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 26d5e710..a4898524 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -241,9 +241,11 @@ export function NewContract(props: { question: string; tag?: string }) {