Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated market resolution #404

Merged

Conversation

Martin-Milbradt
Copy link
Contributor

@Martin-Milbradt Martin-Milbradt commented Jun 2, 2022

This feature will brings automatic resolutions to abandoned markets.

Automatic resolution means that unresolved markets get resolved as 'MKT' (paying out investors according to the current odds) at a specified date. By default that date is 1 week after the market closes but it can be modified by the market creator.

Features

  • Market info panel: The auto resolution time (editable) and the auto resolution 'MKT' is displayed
  • Editing close date: The auto resolution time is set to close date + 1 week if it would be less otherwise
  • Contract: The auto resolution time is added
  • Firestore rules: The market creator is allowed to change the auto resolution time
  • Market creation: The auto resolution time is set as close date + 1 week
  • LiteMarket: Added auto resolution time and auto resolution
  • Firebase: Every hour is checked whether markets should be auto resolved
  • Firebase: Existing contracts get an auto resolution time (current date + 2 weeks for closed contracts, close date + 1 week otherwise)

Already done on prod

  • Update firebase rules (add autoResolutionTime to update)
  • Add a close time manually to old contracts lacking it
  • Run add-auto-resolution.ts (/.js) on db

ToDo prod db

  • Deploy updated version of createmarket to db
  • Deploy updated version of resolveMarket to db (refactoring)
  • Deploy autoResolveMarkets to db
  • Reset auto resolution times (initial setup was on 2022-06-10)

Possible features for later PRs

  • eMails 1 day before auto resolve
  • Notification that markets auto close now for creators with closed unresolved markets
  • Change the "Market Info" interface to look nicer and allow edits of the close date
  • Changeable auto resolution type (if requested)
  • Removable auto resolution time
  • Make close time required

Untested

  • Numeric markets are not tested because they are disabled.

Should this be done in the repo or should everyone using VS Code do that himself globally on his machine(s)?
# Conflicts:
#	web/components/choices-toggle-group.tsx
#	web/pages/create.tsx
# Conflicts:
#	common/contract.ts
#	functions/src/create-contract.ts
#	web/pages/create.tsx
This reverts commit 22f59ad.
…solution

# Conflicts:
#	web/components/contract/contract-info-dialog.tsx
Copy link
Collaborator

@jahooma jahooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few more things to fix, but otherwise approved!

I'll rerun the script to update autoResolutionTime for all contracts, and merge this PR in — hopefully later today if you make the small fixes suggested.

Thanks!

functions/src/resolve-market.ts Outdated Show resolved Hide resolved
functions/src/resolve-market.ts Outdated Show resolved Hide resolved
web/components/contract/contract-info-dialog.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@jahooma jahooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR was reverted because of a few bugs I found.

@@ -113,6 +116,7 @@ export const createmarket = newEndpoint(['POST'], async (req, auth) => {
ante,
closeTime.getTime(),
tags ?? [],
autoResolutionTime,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not in the right order, autoResolutionTime should be the last parameter. (To make this more robust, we could switch to taking all the parameters as an object instead of a param list. Not sure if that should be part of this change.)

firestore
.collection('contracts')
.where('isResolved', '==', false)
.where('closeTime', '>', Date.now())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closeTime should be '<' Date.now() if the market is closed!

.collection('contracts')
.where('isResolved', '==', false)
.where('closeTime', '>', Date.now())
.where('autoResolutionTime', '<', Date.now())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firebase does not allow two queries with not equal operators. Advice is to move the closeTime query into a filter operation after loading the contracts.

)

export const autoResolveMarkets = functions.pubsub
.schedule('every 1 minutes')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs .runWith({ secrets: ['MAILGUN_KEY'] }) since it sends emails.

@Martin-Milbradt Martin-Milbradt mentioned this pull request Jun 15, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants