From 22edf57b4fe47d27bb1494f8a7e50cf3607d13a8 Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Fri, 13 Sep 2024 18:03:52 -0700 Subject: [PATCH] Remove creator fee (#2857) --- backend/api/src/place-bet.ts | 36 ++++++++++--------- common/src/fees.ts | 9 +++++ web/components/bet/fees.tsx | 8 +++-- .../contract/creator-fees-display.tsx | 8 +++-- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/backend/api/src/place-bet.ts b/backend/api/src/place-bet.ts index 9036f67a5c..2628b4ab51 100644 --- a/backend/api/src/place-bet.ts +++ b/backend/api/src/place-bet.ts @@ -16,7 +16,7 @@ import { Answer } from 'common/answer' import { CpmmState, getCpmmProbability } from 'common/calculate-cpmm' import { ValidatedAPIParams } from 'common/api/schema' import { onCreateBets } from 'api/on-create-bet' -import { BANNED_TRADING_USER_IDS } from 'common/envs/constants' +import { BANNED_TRADING_USER_IDS, TWOMBA_ENABLED } from 'common/envs/constants' import * as crypto from 'crypto' import { formatMoneyWithDecimals } from 'common/util/format' import { @@ -248,7 +248,7 @@ export const fetchContractBetDataAndValidate = async ( const queries = ` select * from users where id = $1; select ${contractColumnsToSelect} from contracts where id = $2; - select * from answers + select * from answers where contract_id = $2 and ( ($3 is null or id in ($3:list)) or (select (data->'shouldAnswersSumToOne')::boolean from contracts where id = $2) @@ -546,22 +546,24 @@ export const executeNewBetResult = async ( ) log(`Updated user ${user.username} balance - auth ${user.id}.`) - const totalCreatorFee = - newBet.fees.creatorFee + - sumBy(otherBetResults, (r) => r.bet.fees.creatorFee) - if (totalCreatorFee !== 0) { - await incrementBalance(pgTrans, contract.creatorId, { - balance: totalCreatorFee, - totalDeposits: totalCreatorFee, - }) + if (!TWOMBA_ENABLED) { + const totalCreatorFee = + newBet.fees.creatorFee + + sumBy(otherBetResults, (r) => r.bet.fees.creatorFee) + if (totalCreatorFee !== 0) { + await incrementBalance(pgTrans, contract.creatorId, { + balance: totalCreatorFee, + totalDeposits: totalCreatorFee, + }) - log( - `Updated creator ${ - contract.creatorUsername - } with fee gain ${formatMoneyWithDecimals(totalCreatorFee)} - ${ - contract.creatorId - }.` - ) + log( + `Updated creator ${ + contract.creatorUsername + } with fee gain ${formatMoneyWithDecimals(totalCreatorFee)} - ${ + contract.creatorId + }.` + ) + } } const answerUpdates: { diff --git a/common/src/fees.ts b/common/src/fees.ts index f7002b2ca3..ad59b0dc1f 100644 --- a/common/src/fees.ts +++ b/common/src/fees.ts @@ -1,4 +1,5 @@ import { addObjects } from 'common/util/object' +import { TWOMBA_ENABLED } from './envs/constants' export const FEE_START_TIME = 1713292320000 @@ -12,6 +13,14 @@ export const getFeesSplit = ( totalFees: number, previouslyCollectedFees: Fees ) => { + if (TWOMBA_ENABLED) { + return { + creatorFee: 0, + platformFee: totalFees, + liquidityFee: 0, + } + } + const before1k = Math.max( 0, CREATORS_EARN_WHOLE_FEE_UP_TO - previouslyCollectedFees.creatorFee diff --git a/web/components/bet/fees.tsx b/web/components/bet/fees.tsx index 4ccc1b838f..a596938a93 100644 --- a/web/components/bet/fees.tsx +++ b/web/components/bet/fees.tsx @@ -1,4 +1,4 @@ -import { TRADE_TERM } from 'common/envs/constants' +import { TRADE_TERM, TWOMBA_ENABLED } from 'common/envs/constants' import { InfoTooltip } from '../widgets/info-tooltip' import { MoneyDisplay } from './money-display' @@ -20,7 +20,11 @@ export const FeeDisplay = (props: { diff --git a/web/components/contract/creator-fees-display.tsx b/web/components/contract/creator-fees-display.tsx index 5c86269deb..98d70e5af1 100644 --- a/web/components/contract/creator-fees-display.tsx +++ b/web/components/contract/creator-fees-display.tsx @@ -10,6 +10,10 @@ export const CreatorFeesDisplay = (props: { const { contract, className } = props const { collectedFees } = contract const isCashContract = contract.token === 'CASH' + + // cash contracts have no creator fees + if (isCashContract) return null + return ( {formatWithToken({ amount: collectedFees.creatorFee, - token: isCashContract ? 'CASH' : 'M$', - toDecimal: isCashContract ? 4 : 2, + token: 'M$', + toDecimal: 2, })}{' '} earned