Skip to content

Commit

Permalink
Remove creator fee (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
sipec authored Sep 14, 2024
1 parent 686eb17 commit 22edf57
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
36 changes: 19 additions & 17 deletions backend/api/src/place-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: {
Expand Down
9 changes: 9 additions & 0 deletions common/src/fees.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addObjects } from 'common/util/object'
import { TWOMBA_ENABLED } from './envs/constants'

export const FEE_START_TIME = 1713292320000

Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions web/components/bet/fees.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -20,7 +20,11 @@ export const FeeDisplay = (props: {
<InfoTooltip
text={`${(amount ? (100 * totalFees) / amount : 0).toFixed(
2
)}% fee. Goes to the market creator up to 1000, then is split 50-50 with Manifold. Fees range from 0% to 7% of your ${TRADE_TERM} amount increasing the more unlikely your ${TRADE_TERM} is to pay out.`}
)}% fee. Goes to ${
TWOMBA_ENABLED
? ''
: 'the market creator up to 1000, then is split 50-50 with '
}Manifold. Fees range from 0% to 7% of your ${TRADE_TERM} amount increasing the more unlikely your ${TRADE_TERM} is to pay out.`}
className="text-ink-600 ml-1 mt-0.5"
size="sm"
/>
Expand Down
8 changes: 6 additions & 2 deletions web/components/contract/creator-fees-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Tooltip
text={'Fees earned from trade volume'}
Expand All @@ -19,8 +23,8 @@ export const CreatorFeesDisplay = (props: {
>
{formatWithToken({
amount: collectedFees.creatorFee,
token: isCashContract ? 'CASH' : 'M$',
toDecimal: isCashContract ? 4 : 2,
token: 'M$',
toDecimal: 2,
})}{' '}
earned
</Tooltip>
Expand Down

0 comments on commit 22edf57

Please sign in to comment.